]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.7-201311102306.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.7-201311102306.patch
CommitLineData
e163697f
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..bb527b3 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) || GRKERNSEC_OLD_ARM_USERLAND
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..130793a 100644
59650--- a/fs/proc/proc_sysctl.c
59651+++ b/fs/proc/proc_sysctl.c
59652@@ -11,13 +11,18 @@
59653 #include <linux/namei.h>
59654 #include <linux/mm.h>
59655 #include <linux/module.h>
59656+#include <linux/nsproxy.h>
59657 #include "internal.h"
59658
59659+extern int gr_handle_chroot_sysctl(const int op);
59660+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59661+ const int op);
59662+
59663 static const struct dentry_operations proc_sys_dentry_operations;
59664 static const struct file_operations proc_sys_file_operations;
59665-static const struct inode_operations proc_sys_inode_operations;
59666+const struct inode_operations proc_sys_inode_operations;
59667 static const struct file_operations proc_sys_dir_file_operations;
59668-static const struct inode_operations proc_sys_dir_operations;
59669+const struct inode_operations proc_sys_dir_operations;
59670
59671 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59672 {
59673@@ -467,6 +472,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59674
59675 err = NULL;
59676 d_set_d_op(dentry, &proc_sys_dentry_operations);
59677+
59678+ gr_handle_proc_create(dentry, inode);
59679+
59680 d_add(dentry, inode);
59681
59682 out:
59683@@ -482,6 +490,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59684 struct inode *inode = file_inode(filp);
59685 struct ctl_table_header *head = grab_header(inode);
59686 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59687+ int op = write ? MAY_WRITE : MAY_READ;
59688 ssize_t error;
59689 size_t res;
59690
59691@@ -493,7 +502,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59692 * and won't be until we finish.
59693 */
59694 error = -EPERM;
59695- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59696+ if (sysctl_perm(head, table, op))
59697 goto out;
59698
59699 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59700@@ -501,6 +510,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59701 if (!table->proc_handler)
59702 goto out;
59703
59704+#ifdef CONFIG_GRKERNSEC
59705+ error = -EPERM;
59706+ if (gr_handle_chroot_sysctl(op))
59707+ goto out;
59708+ dget(filp->f_path.dentry);
59709+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59710+ dput(filp->f_path.dentry);
59711+ goto out;
59712+ }
59713+ dput(filp->f_path.dentry);
59714+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59715+ goto out;
59716+ if (write) {
59717+ if (current->nsproxy->net_ns != table->extra2) {
59718+ if (!capable(CAP_SYS_ADMIN))
59719+ goto out;
59720+ } else if (!nsown_capable(CAP_NET_ADMIN))
59721+ goto out;
59722+ }
59723+#endif
59724+
59725 /* careful: calling conventions are nasty here */
59726 res = count;
59727 error = table->proc_handler(table, write, buf, &res, ppos);
59728@@ -598,6 +628,9 @@ static bool proc_sys_fill_cache(struct file *file,
59729 return false;
59730 } else {
59731 d_set_d_op(child, &proc_sys_dentry_operations);
59732+
59733+ gr_handle_proc_create(child, inode);
59734+
59735 d_add(child, inode);
59736 }
59737 } else {
59738@@ -641,6 +674,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59739 if ((*pos)++ < ctx->pos)
59740 return true;
59741
59742+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59743+ return 0;
59744+
59745 if (unlikely(S_ISLNK(table->mode)))
59746 res = proc_sys_link_fill_cache(file, ctx, head, table);
59747 else
59748@@ -734,6 +770,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59749 if (IS_ERR(head))
59750 return PTR_ERR(head);
59751
59752+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59753+ return -ENOENT;
59754+
59755 generic_fillattr(inode, stat);
59756 if (table)
59757 stat->mode = (stat->mode & S_IFMT) | table->mode;
59758@@ -756,13 +795,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59759 .llseek = generic_file_llseek,
59760 };
59761
59762-static const struct inode_operations proc_sys_inode_operations = {
59763+const struct inode_operations proc_sys_inode_operations = {
59764 .permission = proc_sys_permission,
59765 .setattr = proc_sys_setattr,
59766 .getattr = proc_sys_getattr,
59767 };
59768
59769-static const struct inode_operations proc_sys_dir_operations = {
59770+const struct inode_operations proc_sys_dir_operations = {
59771 .lookup = proc_sys_lookup,
59772 .permission = proc_sys_permission,
59773 .setattr = proc_sys_setattr,
59774@@ -839,7 +878,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59775 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59776 const char *name, int namelen)
59777 {
59778- struct ctl_table *table;
59779+ ctl_table_no_const *table;
59780 struct ctl_dir *new;
59781 struct ctl_node *node;
59782 char *new_name;
59783@@ -851,7 +890,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59784 return NULL;
59785
59786 node = (struct ctl_node *)(new + 1);
59787- table = (struct ctl_table *)(node + 1);
59788+ table = (ctl_table_no_const *)(node + 1);
59789 new_name = (char *)(table + 2);
59790 memcpy(new_name, name, namelen);
59791 new_name[namelen] = '\0';
59792@@ -1020,7 +1059,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59793 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59794 struct ctl_table_root *link_root)
59795 {
59796- struct ctl_table *link_table, *entry, *link;
59797+ ctl_table_no_const *link_table, *link;
59798+ struct ctl_table *entry;
59799 struct ctl_table_header *links;
59800 struct ctl_node *node;
59801 char *link_name;
59802@@ -1043,7 +1083,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59803 return NULL;
59804
59805 node = (struct ctl_node *)(links + 1);
59806- link_table = (struct ctl_table *)(node + nr_entries);
59807+ link_table = (ctl_table_no_const *)(node + nr_entries);
59808 link_name = (char *)&link_table[nr_entries + 1];
59809
59810 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59811@@ -1291,8 +1331,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59812 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59813 struct ctl_table *table)
59814 {
59815- struct ctl_table *ctl_table_arg = NULL;
59816- struct ctl_table *entry, *files;
59817+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59818+ struct ctl_table *entry;
59819 int nr_files = 0;
59820 int nr_dirs = 0;
59821 int err = -ENOMEM;
59822@@ -1304,10 +1344,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59823 nr_files++;
59824 }
59825
59826- files = table;
59827 /* If there are mixed files and directories we need a new table */
59828 if (nr_dirs && nr_files) {
59829- struct ctl_table *new;
59830+ ctl_table_no_const *new;
59831 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59832 GFP_KERNEL);
59833 if (!files)
59834@@ -1325,7 +1364,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59835 /* Register everything except a directory full of subdirectories */
59836 if (nr_files || !nr_dirs) {
59837 struct ctl_table_header *header;
59838- header = __register_sysctl_table(set, path, files);
59839+ header = __register_sysctl_table(set, path, files ? files : table);
59840 if (!header) {
59841 kfree(ctl_table_arg);
59842 goto out;
59843diff --git a/fs/proc/root.c b/fs/proc/root.c
59844index 0e0e83c..005ba6a 100644
59845--- a/fs/proc/root.c
59846+++ b/fs/proc/root.c
59847@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59848 #ifdef CONFIG_PROC_DEVICETREE
59849 proc_device_tree_init();
59850 #endif
59851+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59852+#ifdef CONFIG_GRKERNSEC_PROC_USER
59853+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59854+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59855+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59856+#endif
59857+#else
59858 proc_mkdir("bus", NULL);
59859+#endif
59860 proc_sys_init();
59861 }
59862
59863diff --git a/fs/proc/self.c b/fs/proc/self.c
59864index 6b6a993..807cccc 100644
59865--- a/fs/proc/self.c
59866+++ b/fs/proc/self.c
59867@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59868 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59869 void *cookie)
59870 {
59871- char *s = nd_get_link(nd);
59872+ const char *s = nd_get_link(nd);
59873 if (!IS_ERR(s))
59874 kfree(s);
59875 }
59876diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59877index 107d026..c715aeb 100644
59878--- a/fs/proc/task_mmu.c
59879+++ b/fs/proc/task_mmu.c
59880@@ -12,12 +12,19 @@
59881 #include <linux/swap.h>
59882 #include <linux/swapops.h>
59883 #include <linux/mmu_notifier.h>
59884+#include <linux/grsecurity.h>
59885
59886 #include <asm/elf.h>
59887 #include <asm/uaccess.h>
59888 #include <asm/tlbflush.h>
59889 #include "internal.h"
59890
59891+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59892+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59893+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59894+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59895+#endif
59896+
59897 void task_mem(struct seq_file *m, struct mm_struct *mm)
59898 {
59899 unsigned long data, text, lib, swap;
59900@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59901 "VmExe:\t%8lu kB\n"
59902 "VmLib:\t%8lu kB\n"
59903 "VmPTE:\t%8lu kB\n"
59904- "VmSwap:\t%8lu kB\n",
59905- hiwater_vm << (PAGE_SHIFT-10),
59906+ "VmSwap:\t%8lu kB\n"
59907+
59908+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59909+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59910+#endif
59911+
59912+ ,hiwater_vm << (PAGE_SHIFT-10),
59913 total_vm << (PAGE_SHIFT-10),
59914 mm->locked_vm << (PAGE_SHIFT-10),
59915 mm->pinned_vm << (PAGE_SHIFT-10),
59916@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59917 data << (PAGE_SHIFT-10),
59918 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59919 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59920- swap << (PAGE_SHIFT-10));
59921+ swap << (PAGE_SHIFT-10)
59922+
59923+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59924+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59925+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59926+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59927+#else
59928+ , mm->context.user_cs_base
59929+ , mm->context.user_cs_limit
59930+#endif
59931+#endif
59932+
59933+ );
59934 }
59935
59936 unsigned long task_vsize(struct mm_struct *mm)
59937@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59938 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59939 }
59940
59941- /* We don't show the stack guard page in /proc/maps */
59942+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59943+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59944+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59945+#else
59946 start = vma->vm_start;
59947- if (stack_guard_page_start(vma, start))
59948- start += PAGE_SIZE;
59949 end = vma->vm_end;
59950- if (stack_guard_page_end(vma, end))
59951- end -= PAGE_SIZE;
59952+#endif
59953
59954 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59955 start,
59956@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59957 flags & VM_WRITE ? 'w' : '-',
59958 flags & VM_EXEC ? 'x' : '-',
59959 flags & VM_MAYSHARE ? 's' : 'p',
59960+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59961+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59962+#else
59963 pgoff,
59964+#endif
59965 MAJOR(dev), MINOR(dev), ino, &len);
59966
59967 /*
59968@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59969 */
59970 if (file) {
59971 pad_len_spaces(m, len);
59972- seq_path(m, &file->f_path, "\n");
59973+ seq_path(m, &file->f_path, "\n\\");
59974 goto done;
59975 }
59976
59977@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59978 * Thread stack in /proc/PID/task/TID/maps or
59979 * the main process stack.
59980 */
59981- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59982- vma->vm_end >= mm->start_stack)) {
59983+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59984+ (vma->vm_start <= mm->start_stack &&
59985+ vma->vm_end >= mm->start_stack)) {
59986 name = "[stack]";
59987 } else {
59988 /* Thread stack in /proc/PID/maps */
59989@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59990 struct proc_maps_private *priv = m->private;
59991 struct task_struct *task = priv->task;
59992
59993+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59994+ if (current->exec_id != m->exec_id) {
59995+ gr_log_badprocpid("maps");
59996+ return 0;
59997+ }
59998+#endif
59999+
60000 show_map_vma(m, vma, is_pid);
60001
60002 if (m->count < m->size) /* vma is copied successfully */
60003@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60004 .private = &mss,
60005 };
60006
60007+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60008+ if (current->exec_id != m->exec_id) {
60009+ gr_log_badprocpid("smaps");
60010+ return 0;
60011+ }
60012+#endif
60013 memset(&mss, 0, sizeof mss);
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-
60019+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60020+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60021+#endif
60022+ mss.vma = vma;
60023+ /* mmap_sem is held in m_start */
60024+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60025+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60026+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60027+ }
60028+#endif
60029 show_map_vma(m, vma, is_pid);
60030
60031 seq_printf(m,
60032@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60033 "KernelPageSize: %8lu kB\n"
60034 "MMUPageSize: %8lu kB\n"
60035 "Locked: %8lu kB\n",
60036+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60037+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60038+#else
60039 (vma->vm_end - vma->vm_start) >> 10,
60040+#endif
60041 mss.resident >> 10,
60042 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60043 mss.shared_clean >> 10,
60044@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60045 int n;
60046 char buffer[50];
60047
60048+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60049+ if (current->exec_id != m->exec_id) {
60050+ gr_log_badprocpid("numa_maps");
60051+ return 0;
60052+ }
60053+#endif
60054+
60055 if (!mm)
60056 return 0;
60057
60058@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60059 mpol_to_str(buffer, sizeof(buffer), pol);
60060 mpol_cond_put(pol);
60061
60062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60063+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60064+#else
60065 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60066+#endif
60067
60068 if (file) {
60069 seq_printf(m, " file=");
60070- seq_path(m, &file->f_path, "\n\t= ");
60071+ seq_path(m, &file->f_path, "\n\t\\= ");
60072 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60073 seq_printf(m, " heap");
60074 } else {
60075diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60076index 56123a6..5a2f6ec 100644
60077--- a/fs/proc/task_nommu.c
60078+++ b/fs/proc/task_nommu.c
60079@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60080 else
60081 bytes += kobjsize(mm);
60082
60083- if (current->fs && current->fs->users > 1)
60084+ if (current->fs && atomic_read(&current->fs->users) > 1)
60085 sbytes += kobjsize(current->fs);
60086 else
60087 bytes += kobjsize(current->fs);
60088@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60089
60090 if (file) {
60091 pad_len_spaces(m, len);
60092- seq_path(m, &file->f_path, "");
60093+ seq_path(m, &file->f_path, "\n\\");
60094 } else if (mm) {
60095 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60096
60097diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60098index a1a16eb..6be46ed 100644
60099--- a/fs/proc/vmcore.c
60100+++ b/fs/proc/vmcore.c
60101@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60102 nr_bytes = count;
60103
60104 /* If pfn is not ram, return zeros for sparse dump files */
60105- if (pfn_is_ram(pfn) == 0)
60106- memset(buf, 0, nr_bytes);
60107- else {
60108+ if (pfn_is_ram(pfn) == 0) {
60109+ if (userbuf) {
60110+ if (clear_user((char __force_user *)buf, nr_bytes))
60111+ return -EFAULT;
60112+ } else
60113+ memset(buf, 0, nr_bytes);
60114+ } else {
60115 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60116 offset, userbuf);
60117 if (tmp < 0)
60118@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60119 if (*fpos < m->offset + m->size) {
60120 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60121 start = m->paddr + *fpos - m->offset;
60122- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60123+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60124 if (tmp < 0)
60125 return tmp;
60126 buflen -= tsz;
60127diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60128index b00fcc9..e0c6381 100644
60129--- a/fs/qnx6/qnx6.h
60130+++ b/fs/qnx6/qnx6.h
60131@@ -74,7 +74,7 @@ enum {
60132 BYTESEX_BE,
60133 };
60134
60135-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60136+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60137 {
60138 if (sbi->s_bytesex == BYTESEX_LE)
60139 return le64_to_cpu((__force __le64)n);
60140@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60141 return (__force __fs64)cpu_to_be64(n);
60142 }
60143
60144-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60145+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60146 {
60147 if (sbi->s_bytesex == BYTESEX_LE)
60148 return le32_to_cpu((__force __le32)n);
60149diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60150index 16e8abb..2dcf914 100644
60151--- a/fs/quota/netlink.c
60152+++ b/fs/quota/netlink.c
60153@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60154 void quota_send_warning(struct kqid qid, dev_t dev,
60155 const char warntype)
60156 {
60157- static atomic_t seq;
60158+ static atomic_unchecked_t seq;
60159 struct sk_buff *skb;
60160 void *msg_head;
60161 int ret;
60162@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60163 "VFS: Not enough memory to send quota warning.\n");
60164 return;
60165 }
60166- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60167+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60168 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60169 if (!msg_head) {
60170 printk(KERN_ERR
60171diff --git a/fs/read_write.c b/fs/read_write.c
60172index 122a384..0b7ecf2 100644
60173--- a/fs/read_write.c
60174+++ b/fs/read_write.c
60175@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60176
60177 old_fs = get_fs();
60178 set_fs(get_ds());
60179- p = (__force const char __user *)buf;
60180+ p = (const char __force_user *)buf;
60181 if (count > MAX_RW_COUNT)
60182 count = MAX_RW_COUNT;
60183 if (file->f_op->write)
60184diff --git a/fs/readdir.c b/fs/readdir.c
60185index 93d71e5..6a14be8 100644
60186--- a/fs/readdir.c
60187+++ b/fs/readdir.c
60188@@ -17,6 +17,7 @@
60189 #include <linux/security.h>
60190 #include <linux/syscalls.h>
60191 #include <linux/unistd.h>
60192+#include <linux/namei.h>
60193
60194 #include <asm/uaccess.h>
60195
60196@@ -69,6 +70,7 @@ struct old_linux_dirent {
60197 struct readdir_callback {
60198 struct dir_context ctx;
60199 struct old_linux_dirent __user * dirent;
60200+ struct file * file;
60201 int result;
60202 };
60203
60204@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60205 buf->result = -EOVERFLOW;
60206 return -EOVERFLOW;
60207 }
60208+
60209+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60210+ return 0;
60211+
60212 buf->result++;
60213 dirent = buf->dirent;
60214 if (!access_ok(VERIFY_WRITE, dirent,
60215@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60216 if (!f.file)
60217 return -EBADF;
60218
60219+ buf.file = f.file;
60220 error = iterate_dir(f.file, &buf.ctx);
60221 if (buf.result)
60222 error = buf.result;
60223@@ -142,6 +149,7 @@ struct getdents_callback {
60224 struct dir_context ctx;
60225 struct linux_dirent __user * current_dir;
60226 struct linux_dirent __user * previous;
60227+ struct file * file;
60228 int count;
60229 int error;
60230 };
60231@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60232 buf->error = -EOVERFLOW;
60233 return -EOVERFLOW;
60234 }
60235+
60236+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60237+ return 0;
60238+
60239 dirent = buf->previous;
60240 if (dirent) {
60241 if (__put_user(offset, &dirent->d_off))
60242@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60243 if (!f.file)
60244 return -EBADF;
60245
60246+ buf.file = f.file;
60247 error = iterate_dir(f.file, &buf.ctx);
60248 if (error >= 0)
60249 error = buf.error;
60250@@ -226,6 +239,7 @@ struct getdents_callback64 {
60251 struct dir_context ctx;
60252 struct linux_dirent64 __user * current_dir;
60253 struct linux_dirent64 __user * previous;
60254+ struct file *file;
60255 int count;
60256 int error;
60257 };
60258@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60259 buf->error = -EINVAL; /* only used if we fail.. */
60260 if (reclen > buf->count)
60261 return -EINVAL;
60262+
60263+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60264+ return 0;
60265+
60266 dirent = buf->previous;
60267 if (dirent) {
60268 if (__put_user(offset, &dirent->d_off))
60269@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60270 if (!f.file)
60271 return -EBADF;
60272
60273+ buf.file = f.file;
60274 error = iterate_dir(f.file, &buf.ctx);
60275 if (error >= 0)
60276 error = buf.error;
60277diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60278index 2b7882b..1c5ef48 100644
60279--- a/fs/reiserfs/do_balan.c
60280+++ b/fs/reiserfs/do_balan.c
60281@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60282 return;
60283 }
60284
60285- atomic_inc(&(fs_generation(tb->tb_sb)));
60286+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60287 do_balance_starts(tb);
60288
60289 /* balance leaf returns 0 except if combining L R and S into
60290diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60291index a958444..42b2323 100644
60292--- a/fs/reiserfs/procfs.c
60293+++ b/fs/reiserfs/procfs.c
60294@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60295 "SMALL_TAILS " : "NO_TAILS ",
60296 replay_only(sb) ? "REPLAY_ONLY " : "",
60297 convert_reiserfs(sb) ? "CONV " : "",
60298- atomic_read(&r->s_generation_counter),
60299+ atomic_read_unchecked(&r->s_generation_counter),
60300 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60301 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60302 SF(s_good_search_by_key_reada), SF(s_bmaps),
60303diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60304index 3df5ce6..8c0f4b0 100644
60305--- a/fs/reiserfs/reiserfs.h
60306+++ b/fs/reiserfs/reiserfs.h
60307@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60308 /* Comment? -Hans */
60309 wait_queue_head_t s_wait;
60310 /* To be obsoleted soon by per buffer seals.. -Hans */
60311- atomic_t s_generation_counter; // increased by one every time the
60312+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60313 // tree gets re-balanced
60314 unsigned long s_properties; /* File system properties. Currently holds
60315 on-disk FS format */
60316@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60317 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60318
60319 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60320-#define get_generation(s) atomic_read (&fs_generation(s))
60321+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60322 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60323 #define __fs_changed(gen,s) (gen != get_generation (s))
60324 #define fs_changed(gen,s) \
60325diff --git a/fs/select.c b/fs/select.c
60326index 35d4adc7..d6c60db 100644
60327--- a/fs/select.c
60328+++ b/fs/select.c
60329@@ -20,6 +20,7 @@
60330 #include <linux/export.h>
60331 #include <linux/slab.h>
60332 #include <linux/poll.h>
60333+#include <linux/security.h>
60334 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60335 #include <linux/file.h>
60336 #include <linux/fdtable.h>
60337@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60338 struct poll_list *walk = head;
60339 unsigned long todo = nfds;
60340
60341+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60342 if (nfds > rlimit(RLIMIT_NOFILE))
60343 return -EINVAL;
60344
60345diff --git a/fs/seq_file.c b/fs/seq_file.c
60346index 3135c25..d0395dd 100644
60347--- a/fs/seq_file.c
60348+++ b/fs/seq_file.c
60349@@ -10,6 +10,7 @@
60350 #include <linux/seq_file.h>
60351 #include <linux/slab.h>
60352 #include <linux/cred.h>
60353+#include <linux/sched.h>
60354
60355 #include <asm/uaccess.h>
60356 #include <asm/page.h>
60357@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60358 #ifdef CONFIG_USER_NS
60359 p->user_ns = file->f_cred->user_ns;
60360 #endif
60361+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60362+ p->exec_id = current->exec_id;
60363+#endif
60364
60365 /*
60366 * Wrappers around seq_open(e.g. swaps_open) need to be
60367@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60368 return 0;
60369 }
60370 if (!m->buf) {
60371- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60372+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60373 if (!m->buf)
60374 return -ENOMEM;
60375 }
60376@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60377 Eoverflow:
60378 m->op->stop(m, p);
60379 kfree(m->buf);
60380- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60381+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60382 return !m->buf ? -ENOMEM : -EAGAIN;
60383 }
60384
60385@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60386
60387 /* grab buffer if we didn't have one */
60388 if (!m->buf) {
60389- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60390+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60391 if (!m->buf)
60392 goto Enomem;
60393 }
60394@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60395 goto Fill;
60396 m->op->stop(m, p);
60397 kfree(m->buf);
60398- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60399+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60400 if (!m->buf)
60401 goto Enomem;
60402 m->count = 0;
60403@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60404 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60405 void *data)
60406 {
60407- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60408+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60409 int res = -ENOMEM;
60410
60411 if (op) {
60412diff --git a/fs/splice.c b/fs/splice.c
60413index 3b7ee65..87fc2e4 100644
60414--- a/fs/splice.c
60415+++ b/fs/splice.c
60416@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60417 pipe_lock(pipe);
60418
60419 for (;;) {
60420- if (!pipe->readers) {
60421+ if (!atomic_read(&pipe->readers)) {
60422 send_sig(SIGPIPE, current, 0);
60423 if (!ret)
60424 ret = -EPIPE;
60425@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60426 page_nr++;
60427 ret += buf->len;
60428
60429- if (pipe->files)
60430+ if (atomic_read(&pipe->files))
60431 do_wakeup = 1;
60432
60433 if (!--spd->nr_pages)
60434@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60435 do_wakeup = 0;
60436 }
60437
60438- pipe->waiting_writers++;
60439+ atomic_inc(&pipe->waiting_writers);
60440 pipe_wait(pipe);
60441- pipe->waiting_writers--;
60442+ atomic_dec(&pipe->waiting_writers);
60443 }
60444
60445 pipe_unlock(pipe);
60446@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60447 old_fs = get_fs();
60448 set_fs(get_ds());
60449 /* The cast to a user pointer is valid due to the set_fs() */
60450- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60451+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60452 set_fs(old_fs);
60453
60454 return res;
60455@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60456 old_fs = get_fs();
60457 set_fs(get_ds());
60458 /* The cast to a user pointer is valid due to the set_fs() */
60459- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60460+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60461 set_fs(old_fs);
60462
60463 return res;
60464@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60465 goto err;
60466
60467 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60468- vec[i].iov_base = (void __user *) page_address(page);
60469+ vec[i].iov_base = (void __force_user *) page_address(page);
60470 vec[i].iov_len = this_len;
60471 spd.pages[i] = page;
60472 spd.nr_pages++;
60473@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60474 ops->release(pipe, buf);
60475 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60476 pipe->nrbufs--;
60477- if (pipe->files)
60478+ if (atomic_read(&pipe->files))
60479 sd->need_wakeup = true;
60480 }
60481
60482@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60483 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60484 {
60485 while (!pipe->nrbufs) {
60486- if (!pipe->writers)
60487+ if (!atomic_read(&pipe->writers))
60488 return 0;
60489
60490- if (!pipe->waiting_writers && sd->num_spliced)
60491+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60492 return 0;
60493
60494 if (sd->flags & SPLICE_F_NONBLOCK)
60495@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60496 * out of the pipe right after the splice_to_pipe(). So set
60497 * PIPE_READERS appropriately.
60498 */
60499- pipe->readers = 1;
60500+ atomic_set(&pipe->readers, 1);
60501
60502 current->splice_pipe = pipe;
60503 }
60504@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60505
60506 partial[buffers].offset = off;
60507 partial[buffers].len = plen;
60508+ partial[buffers].private = 0;
60509
60510 off = 0;
60511 len -= plen;
60512@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60513 ret = -ERESTARTSYS;
60514 break;
60515 }
60516- if (!pipe->writers)
60517+ if (!atomic_read(&pipe->writers))
60518 break;
60519- if (!pipe->waiting_writers) {
60520+ if (!atomic_read(&pipe->waiting_writers)) {
60521 if (flags & SPLICE_F_NONBLOCK) {
60522 ret = -EAGAIN;
60523 break;
60524@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60525 pipe_lock(pipe);
60526
60527 while (pipe->nrbufs >= pipe->buffers) {
60528- if (!pipe->readers) {
60529+ if (!atomic_read(&pipe->readers)) {
60530 send_sig(SIGPIPE, current, 0);
60531 ret = -EPIPE;
60532 break;
60533@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60534 ret = -ERESTARTSYS;
60535 break;
60536 }
60537- pipe->waiting_writers++;
60538+ atomic_inc(&pipe->waiting_writers);
60539 pipe_wait(pipe);
60540- pipe->waiting_writers--;
60541+ atomic_dec(&pipe->waiting_writers);
60542 }
60543
60544 pipe_unlock(pipe);
60545@@ -1862,14 +1863,14 @@ retry:
60546 pipe_double_lock(ipipe, opipe);
60547
60548 do {
60549- if (!opipe->readers) {
60550+ if (!atomic_read(&opipe->readers)) {
60551 send_sig(SIGPIPE, current, 0);
60552 if (!ret)
60553 ret = -EPIPE;
60554 break;
60555 }
60556
60557- if (!ipipe->nrbufs && !ipipe->writers)
60558+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60559 break;
60560
60561 /*
60562@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60563 pipe_double_lock(ipipe, opipe);
60564
60565 do {
60566- if (!opipe->readers) {
60567+ if (!atomic_read(&opipe->readers)) {
60568 send_sig(SIGPIPE, current, 0);
60569 if (!ret)
60570 ret = -EPIPE;
60571@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60572 * return EAGAIN if we have the potential of some data in the
60573 * future, otherwise just return 0
60574 */
60575- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60576+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60577 ret = -EAGAIN;
60578
60579 pipe_unlock(ipipe);
60580diff --git a/fs/stat.c b/fs/stat.c
60581index 04ce1ac..a13dd1e 100644
60582--- a/fs/stat.c
60583+++ b/fs/stat.c
60584@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60585 stat->gid = inode->i_gid;
60586 stat->rdev = inode->i_rdev;
60587 stat->size = i_size_read(inode);
60588- stat->atime = inode->i_atime;
60589- stat->mtime = inode->i_mtime;
60590+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60591+ stat->atime = inode->i_ctime;
60592+ stat->mtime = inode->i_ctime;
60593+ } else {
60594+ stat->atime = inode->i_atime;
60595+ stat->mtime = inode->i_mtime;
60596+ }
60597 stat->ctime = inode->i_ctime;
60598 stat->blksize = (1 << inode->i_blkbits);
60599 stat->blocks = inode->i_blocks;
60600@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60601 if (retval)
60602 return retval;
60603
60604- if (inode->i_op->getattr)
60605- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60606+ if (inode->i_op->getattr) {
60607+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60608+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60609+ stat->atime = stat->ctime;
60610+ stat->mtime = stat->ctime;
60611+ }
60612+ return retval;
60613+ }
60614
60615 generic_fillattr(inode, stat);
60616 return 0;
60617diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60618index 15c68f9..36a8b3e 100644
60619--- a/fs/sysfs/bin.c
60620+++ b/fs/sysfs/bin.c
60621@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60622 return ret;
60623 }
60624
60625-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60626- void *buf, int len, int write)
60627+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60628+ void *buf, size_t len, int write)
60629 {
60630 struct file *file = vma->vm_file;
60631 struct bin_buffer *bb = file->private_data;
60632 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60633- int ret;
60634+ ssize_t ret;
60635
60636 if (!bb->vm_ops)
60637 return -EINVAL;
60638diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60639index e068e74..92edeb8 100644
60640--- a/fs/sysfs/dir.c
60641+++ b/fs/sysfs/dir.c
60642@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60643 *
60644 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60645 */
60646-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60647+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60648 {
60649 unsigned long hash = init_name_hash();
60650 unsigned int len = strlen(name);
60651@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60652 struct sysfs_dirent *sd;
60653 int rc;
60654
60655+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60656+ const char *parent_name = parent_sd->s_name;
60657+
60658+ mode = S_IFDIR | S_IRWXU;
60659+
60660+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60661+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60662+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60663+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60664+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60665+#endif
60666+
60667 /* allocate */
60668 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60669 if (!sd)
60670diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60671index d2bb7ed..fe8c331 100644
60672--- a/fs/sysfs/file.c
60673+++ b/fs/sysfs/file.c
60674@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60675
60676 struct sysfs_open_dirent {
60677 atomic_t refcnt;
60678- atomic_t event;
60679+ atomic_unchecked_t event;
60680 wait_queue_head_t poll;
60681 struct list_head buffers; /* goes through sysfs_buffer.list */
60682 };
60683@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60684 if (!sysfs_get_active(attr_sd))
60685 return -ENODEV;
60686
60687- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60688+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60689 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60690
60691 sysfs_put_active(attr_sd);
60692@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60693 return -ENOMEM;
60694
60695 atomic_set(&new_od->refcnt, 0);
60696- atomic_set(&new_od->event, 1);
60697+ atomic_set_unchecked(&new_od->event, 1);
60698 init_waitqueue_head(&new_od->poll);
60699 INIT_LIST_HEAD(&new_od->buffers);
60700 goto retry;
60701@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60702
60703 sysfs_put_active(attr_sd);
60704
60705- if (buffer->event != atomic_read(&od->event))
60706+ if (buffer->event != atomic_read_unchecked(&od->event))
60707 goto trigger;
60708
60709 return DEFAULT_POLLMASK;
60710@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60711 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60712 od = sd->s_attr.open;
60713 if (od) {
60714- atomic_inc(&od->event);
60715+ atomic_inc_unchecked(&od->event);
60716 wake_up_interruptible(&od->poll);
60717 }
60718 }
60719diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60720index 8c940df..25b733e 100644
60721--- a/fs/sysfs/symlink.c
60722+++ b/fs/sysfs/symlink.c
60723@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60724
60725 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60726 {
60727- char *page = nd_get_link(nd);
60728+ const char *page = nd_get_link(nd);
60729 if (!IS_ERR(page))
60730 free_page((unsigned long)page);
60731 }
60732diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60733index 69d4889..a810bd4 100644
60734--- a/fs/sysv/sysv.h
60735+++ b/fs/sysv/sysv.h
60736@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60737 #endif
60738 }
60739
60740-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60741+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60742 {
60743 if (sbi->s_bytesex == BYTESEX_PDP)
60744 return PDP_swab((__force __u32)n);
60745diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60746index e18b988..f1d4ad0f 100644
60747--- a/fs/ubifs/io.c
60748+++ b/fs/ubifs/io.c
60749@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60750 return err;
60751 }
60752
60753-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60754+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60755 {
60756 int err;
60757
60758diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60759index c175b4d..8f36a16 100644
60760--- a/fs/udf/misc.c
60761+++ b/fs/udf/misc.c
60762@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60763
60764 u8 udf_tag_checksum(const struct tag *t)
60765 {
60766- u8 *data = (u8 *)t;
60767+ const u8 *data = (const u8 *)t;
60768 u8 checksum = 0;
60769 int i;
60770 for (i = 0; i < sizeof(struct tag); ++i)
60771diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60772index 8d974c4..b82f6ec 100644
60773--- a/fs/ufs/swab.h
60774+++ b/fs/ufs/swab.h
60775@@ -22,7 +22,7 @@ enum {
60776 BYTESEX_BE
60777 };
60778
60779-static inline u64
60780+static inline u64 __intentional_overflow(-1)
60781 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60782 {
60783 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60784@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60785 return (__force __fs64)cpu_to_be64(n);
60786 }
60787
60788-static inline u32
60789+static inline u32 __intentional_overflow(-1)
60790 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60791 {
60792 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60793diff --git a/fs/utimes.c b/fs/utimes.c
60794index f4fb7ec..3fe03c0 100644
60795--- a/fs/utimes.c
60796+++ b/fs/utimes.c
60797@@ -1,6 +1,7 @@
60798 #include <linux/compiler.h>
60799 #include <linux/file.h>
60800 #include <linux/fs.h>
60801+#include <linux/security.h>
60802 #include <linux/linkage.h>
60803 #include <linux/mount.h>
60804 #include <linux/namei.h>
60805@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60806 goto mnt_drop_write_and_out;
60807 }
60808 }
60809+
60810+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60811+ error = -EACCES;
60812+ goto mnt_drop_write_and_out;
60813+ }
60814+
60815 mutex_lock(&inode->i_mutex);
60816 error = notify_change(path->dentry, &newattrs);
60817 mutex_unlock(&inode->i_mutex);
60818diff --git a/fs/xattr.c b/fs/xattr.c
60819index 3377dff..4d074d9 100644
60820--- a/fs/xattr.c
60821+++ b/fs/xattr.c
60822@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60823 return rc;
60824 }
60825
60826+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60827+ssize_t
60828+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60829+{
60830+ struct inode *inode = dentry->d_inode;
60831+ ssize_t error;
60832+
60833+ error = inode_permission(inode, MAY_EXEC);
60834+ if (error)
60835+ return error;
60836+
60837+ if (inode->i_op->getxattr)
60838+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60839+ else
60840+ error = -EOPNOTSUPP;
60841+
60842+ return error;
60843+}
60844+EXPORT_SYMBOL(pax_getxattr);
60845+#endif
60846+
60847 ssize_t
60848 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60849 {
60850@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60851 * Extended attribute SET operations
60852 */
60853 static long
60854-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60855+setxattr(struct path *path, const char __user *name, const void __user *value,
60856 size_t size, int flags)
60857 {
60858 int error;
60859@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60860 posix_acl_fix_xattr_from_user(kvalue, size);
60861 }
60862
60863- error = vfs_setxattr(d, kname, kvalue, size, flags);
60864+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60865+ error = -EACCES;
60866+ goto out;
60867+ }
60868+
60869+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60870 out:
60871 if (vvalue)
60872 vfree(vvalue);
60873@@ -377,7 +403,7 @@ retry:
60874 return error;
60875 error = mnt_want_write(path.mnt);
60876 if (!error) {
60877- error = setxattr(path.dentry, name, value, size, flags);
60878+ error = setxattr(&path, name, value, size, flags);
60879 mnt_drop_write(path.mnt);
60880 }
60881 path_put(&path);
60882@@ -401,7 +427,7 @@ retry:
60883 return error;
60884 error = mnt_want_write(path.mnt);
60885 if (!error) {
60886- error = setxattr(path.dentry, name, value, size, flags);
60887+ error = setxattr(&path, name, value, size, flags);
60888 mnt_drop_write(path.mnt);
60889 }
60890 path_put(&path);
60891@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60892 const void __user *,value, size_t, size, int, flags)
60893 {
60894 struct fd f = fdget(fd);
60895- struct dentry *dentry;
60896 int error = -EBADF;
60897
60898 if (!f.file)
60899 return error;
60900- dentry = f.file->f_path.dentry;
60901- audit_inode(NULL, dentry, 0);
60902+ audit_inode(NULL, f.file->f_path.dentry, 0);
60903 error = mnt_want_write_file(f.file);
60904 if (!error) {
60905- error = setxattr(dentry, name, value, size, flags);
60906+ error = setxattr(&f.file->f_path, name, value, size, flags);
60907 mnt_drop_write_file(f.file);
60908 }
60909 fdput(f);
60910diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60911index 9fbea87..6b19972 100644
60912--- a/fs/xattr_acl.c
60913+++ b/fs/xattr_acl.c
60914@@ -76,8 +76,8 @@ struct posix_acl *
60915 posix_acl_from_xattr(struct user_namespace *user_ns,
60916 const void *value, size_t size)
60917 {
60918- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60919- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60920+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60921+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60922 int count;
60923 struct posix_acl *acl;
60924 struct posix_acl_entry *acl_e;
60925diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60926index 05c698c..6b918af 100644
60927--- a/fs/xfs/xfs_bmap.c
60928+++ b/fs/xfs/xfs_bmap.c
60929@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60930
60931 #else
60932 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60933-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60934+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60935 #endif /* DEBUG */
60936
60937 /*
60938diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60939index 97676a3..399a75d 100644
60940--- a/fs/xfs/xfs_dir2_sf.c
60941+++ b/fs/xfs/xfs_dir2_sf.c
60942@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60943
60944 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60945 ctx->pos = off & 0x7fffffff;
60946- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60947+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60948+ char name[sfep->namelen];
60949+ memcpy(name, sfep->name, sfep->namelen);
60950+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60951+ return 0;
60952+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60953 ino, DT_UNKNOWN))
60954 return 0;
60955 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60956diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60957index 6e2bca5..6ce80d3 100644
60958--- a/fs/xfs/xfs_ioctl.c
60959+++ b/fs/xfs/xfs_ioctl.c
60960@@ -127,7 +127,7 @@ xfs_find_handle(
60961 }
60962
60963 error = -EFAULT;
60964- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60965+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60966 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60967 goto out_put;
60968
60969diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60970index 96dda62..d6c6a52 100644
60971--- a/fs/xfs/xfs_iops.c
60972+++ b/fs/xfs/xfs_iops.c
60973@@ -395,7 +395,7 @@ xfs_vn_put_link(
60974 struct nameidata *nd,
60975 void *p)
60976 {
60977- char *s = nd_get_link(nd);
60978+ const char *s = nd_get_link(nd);
60979
60980 if (!IS_ERR(s))
60981 kfree(s);
60982diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60983new file mode 100644
60984index 0000000..6d8c857
60985--- /dev/null
60986+++ b/grsecurity/Kconfig
60987@@ -0,0 +1,1094 @@
60988+#
60989+# grecurity configuration
60990+#
60991+menu "Memory Protections"
60992+depends on GRKERNSEC
60993+
60994+config GRKERNSEC_KMEM
60995+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60996+ default y if GRKERNSEC_CONFIG_AUTO
60997+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60998+ help
60999+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61000+ be written to or read from to modify or leak the contents of the running
61001+ kernel. /dev/port will also not be allowed to be opened and support
61002+ for /dev/cpu/*/msr will be removed. If you have module
61003+ support disabled, enabling this will close up five ways that are
61004+ currently used to insert malicious code into the running kernel.
61005+
61006+ Even with all these features enabled, we still highly recommend that
61007+ you use the RBAC system, as it is still possible for an attacker to
61008+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61009+
61010+ If you are not using XFree86, you may be able to stop this additional
61011+ case by enabling the 'Disable privileged I/O' option. Though nothing
61012+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61013+ but only to video memory, which is the only writing we allow in this
61014+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61015+ not be allowed to mprotect it with PROT_WRITE later.
61016+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61017+ from working.
61018+
61019+ It is highly recommended that you say Y here if you meet all the
61020+ conditions above.
61021+
61022+config GRKERNSEC_VM86
61023+ bool "Restrict VM86 mode"
61024+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61025+ depends on X86_32
61026+
61027+ help
61028+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61029+ make use of a special execution mode on 32bit x86 processors called
61030+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61031+ video cards and will still work with this option enabled. The purpose
61032+ of the option is to prevent exploitation of emulation errors in
61033+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61034+ Nearly all users should be able to enable this option.
61035+
61036+config GRKERNSEC_IO
61037+ bool "Disable privileged I/O"
61038+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61039+ depends on X86
61040+ select RTC_CLASS
61041+ select RTC_INTF_DEV
61042+ select RTC_DRV_CMOS
61043+
61044+ help
61045+ If you say Y here, all ioperm and iopl calls will return an error.
61046+ Ioperm and iopl can be used to modify the running kernel.
61047+ Unfortunately, some programs need this access to operate properly,
61048+ the most notable of which are XFree86 and hwclock. hwclock can be
61049+ remedied by having RTC support in the kernel, so real-time
61050+ clock support is enabled if this option is enabled, to ensure
61051+ that hwclock operates correctly. XFree86 still will not
61052+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61053+ IF YOU USE XFree86. If you use XFree86 and you still want to
61054+ protect your kernel against modification, use the RBAC system.
61055+
61056+config GRKERNSEC_JIT_HARDEN
61057+ bool "Harden BPF JIT against spray attacks"
61058+ default y if GRKERNSEC_CONFIG_AUTO
61059+ depends on BPF_JIT
61060+ help
61061+ If you say Y here, the native code generated by the kernel's Berkeley
61062+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61063+ attacks that attempt to fit attacker-beneficial instructions in
61064+ 32bit immediate fields of JIT-generated native instructions. The
61065+ attacker will generally aim to cause an unintended instruction sequence
61066+ of JIT-generated native code to execute by jumping into the middle of
61067+ a generated instruction. This feature effectively randomizes the 32bit
61068+ immediate constants present in the generated code to thwart such attacks.
61069+
61070+ If you're using KERNEXEC, it's recommended that you enable this option
61071+ to supplement the hardening of the kernel.
61072+
61073+config GRKERNSEC_PERF_HARDEN
61074+ bool "Disable unprivileged PERF_EVENTS usage by default"
61075+ default y if GRKERNSEC_CONFIG_AUTO
61076+ depends on PERF_EVENTS
61077+ help
61078+ If you say Y here, the range of acceptable values for the
61079+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61080+ default to a new value: 3. When the sysctl is set to this value, no
61081+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61082+
61083+ Though PERF_EVENTS can be used legitimately for performance monitoring
61084+ and low-level application profiling, it is forced on regardless of
61085+ configuration, has been at fault for several vulnerabilities, and
61086+ creates new opportunities for side channels and other information leaks.
61087+
61088+ This feature puts PERF_EVENTS into a secure default state and permits
61089+ the administrator to change out of it temporarily if unprivileged
61090+ application profiling is needed.
61091+
61092+config GRKERNSEC_RAND_THREADSTACK
61093+ bool "Insert random gaps between thread stacks"
61094+ default y if GRKERNSEC_CONFIG_AUTO
61095+ depends on PAX_RANDMMAP && !PPC
61096+ help
61097+ If you say Y here, a random-sized gap will be enforced between allocated
61098+ thread stacks. Glibc's NPTL and other threading libraries that
61099+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61100+ The implementation currently provides 8 bits of entropy for the gap.
61101+
61102+ Many distributions do not compile threaded remote services with the
61103+ -fstack-check argument to GCC, causing the variable-sized stack-based
61104+ allocator, alloca(), to not probe the stack on allocation. This
61105+ permits an unbounded alloca() to skip over any guard page and potentially
61106+ modify another thread's stack reliably. An enforced random gap
61107+ reduces the reliability of such an attack and increases the chance
61108+ that such a read/write to another thread's stack instead lands in
61109+ an unmapped area, causing a crash and triggering grsecurity's
61110+ anti-bruteforcing logic.
61111+
61112+config GRKERNSEC_PROC_MEMMAP
61113+ bool "Harden ASLR against information leaks and entropy reduction"
61114+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61115+ depends on PAX_NOEXEC || PAX_ASLR
61116+ help
61117+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61118+ give no information about the addresses of its mappings if
61119+ PaX features that rely on random addresses are enabled on the task.
61120+ In addition to sanitizing this information and disabling other
61121+ dangerous sources of information, this option causes reads of sensitive
61122+ /proc/<pid> entries where the file descriptor was opened in a different
61123+ task than the one performing the read. Such attempts are logged.
61124+ This option also limits argv/env strings for suid/sgid binaries
61125+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61126+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61127+ binaries to prevent alternative mmap layouts from being abused.
61128+
61129+ If you use PaX it is essential that you say Y here as it closes up
61130+ several holes that make full ASLR useless locally.
61131+
61132+config GRKERNSEC_BRUTE
61133+ bool "Deter exploit bruteforcing"
61134+ default y if GRKERNSEC_CONFIG_AUTO
61135+ help
61136+ If you say Y here, attempts to bruteforce exploits against forking
61137+ daemons such as apache or sshd, as well as against suid/sgid binaries
61138+ will be deterred. When a child of a forking daemon is killed by PaX
61139+ or crashes due to an illegal instruction or other suspicious signal,
61140+ the parent process will be delayed 30 seconds upon every subsequent
61141+ fork until the administrator is able to assess the situation and
61142+ restart the daemon.
61143+ In the suid/sgid case, the attempt is logged, the user has all their
61144+ existing instances of the suid/sgid binary terminated and will
61145+ be unable to execute any suid/sgid binaries for 15 minutes.
61146+
61147+ It is recommended that you also enable signal logging in the auditing
61148+ section so that logs are generated when a process triggers a suspicious
61149+ signal.
61150+ If the sysctl option is enabled, a sysctl option with name
61151+ "deter_bruteforce" is created.
61152+
61153+
61154+config GRKERNSEC_MODHARDEN
61155+ bool "Harden module auto-loading"
61156+ default y if GRKERNSEC_CONFIG_AUTO
61157+ depends on MODULES
61158+ help
61159+ If you say Y here, module auto-loading in response to use of some
61160+ feature implemented by an unloaded module will be restricted to
61161+ root users. Enabling this option helps defend against attacks
61162+ by unprivileged users who abuse the auto-loading behavior to
61163+ cause a vulnerable module to load that is then exploited.
61164+
61165+ If this option prevents a legitimate use of auto-loading for a
61166+ non-root user, the administrator can execute modprobe manually
61167+ with the exact name of the module mentioned in the alert log.
61168+ Alternatively, the administrator can add the module to the list
61169+ of modules loaded at boot by modifying init scripts.
61170+
61171+ Modification of init scripts will most likely be needed on
61172+ Ubuntu servers with encrypted home directory support enabled,
61173+ as the first non-root user logging in will cause the ecb(aes),
61174+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61175+
61176+config GRKERNSEC_HIDESYM
61177+ bool "Hide kernel symbols"
61178+ default y if GRKERNSEC_CONFIG_AUTO
61179+ select PAX_USERCOPY_SLABS
61180+ help
61181+ If you say Y here, getting information on loaded modules, and
61182+ displaying all kernel symbols through a syscall will be restricted
61183+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61184+ /proc/kallsyms will be restricted to the root user. The RBAC
61185+ system can hide that entry even from root.
61186+
61187+ This option also prevents leaking of kernel addresses through
61188+ several /proc entries.
61189+
61190+ Note that this option is only effective provided the following
61191+ conditions are met:
61192+ 1) The kernel using grsecurity is not precompiled by some distribution
61193+ 2) You have also enabled GRKERNSEC_DMESG
61194+ 3) You are using the RBAC system and hiding other files such as your
61195+ kernel image and System.map. Alternatively, enabling this option
61196+ causes the permissions on /boot, /lib/modules, and the kernel
61197+ source directory to change at compile time to prevent
61198+ reading by non-root users.
61199+ If the above conditions are met, this option will aid in providing a
61200+ useful protection against local kernel exploitation of overflows
61201+ and arbitrary read/write vulnerabilities.
61202+
61203+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61204+ in addition to this feature.
61205+
61206+config GRKERNSEC_KERN_LOCKOUT
61207+ bool "Active kernel exploit response"
61208+ default y if GRKERNSEC_CONFIG_AUTO
61209+ depends on X86 || ARM || PPC || SPARC
61210+ help
61211+ If you say Y here, when a PaX alert is triggered due to suspicious
61212+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61213+ or an OOPS occurs due to bad memory accesses, instead of just
61214+ terminating the offending process (and potentially allowing
61215+ a subsequent exploit from the same user), we will take one of two
61216+ actions:
61217+ If the user was root, we will panic the system
61218+ If the user was non-root, we will log the attempt, terminate
61219+ all processes owned by the user, then prevent them from creating
61220+ any new processes until the system is restarted
61221+ This deters repeated kernel exploitation/bruteforcing attempts
61222+ and is useful for later forensics.
61223+
61224+config GRKERNSEC_OLD_ARM_USERLAND
61225+ bool "Old ARM userland compatibility"
61226+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
61227+ help
61228+ If you say Y here, stubs of executable code to perform such operations
61229+ as "compare-exchange" will be placed at fixed locations in the ARM vector
61230+ table. This is unfortunately needed for old ARM userland meant to run
61231+ across a wide range of processors. Without this option enabled,
61232+ the get_tls and data memory barrier stubs will be emulated by the kernel,
61233+ which is enough for Linaro userlands or other userlands designed for v6
61234+ and newer ARM CPUs. It's recommended that you try without this option enabled
61235+ first, and only enable it if your userland does not boot (it will likely fail
61236+ at init time).
61237+
61238+endmenu
61239+menu "Role Based Access Control Options"
61240+depends on GRKERNSEC
61241+
61242+config GRKERNSEC_RBAC_DEBUG
61243+ bool
61244+
61245+config GRKERNSEC_NO_RBAC
61246+ bool "Disable RBAC system"
61247+ help
61248+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61249+ preventing the RBAC system from being enabled. You should only say Y
61250+ here if you have no intention of using the RBAC system, so as to prevent
61251+ an attacker with root access from misusing the RBAC system to hide files
61252+ and processes when loadable module support and /dev/[k]mem have been
61253+ locked down.
61254+
61255+config GRKERNSEC_ACL_HIDEKERN
61256+ bool "Hide kernel processes"
61257+ help
61258+ If you say Y here, all kernel threads will be hidden to all
61259+ processes but those whose subject has the "view hidden processes"
61260+ flag.
61261+
61262+config GRKERNSEC_ACL_MAXTRIES
61263+ int "Maximum tries before password lockout"
61264+ default 3
61265+ help
61266+ This option enforces the maximum number of times a user can attempt
61267+ to authorize themselves with the grsecurity RBAC system before being
61268+ denied the ability to attempt authorization again for a specified time.
61269+ The lower the number, the harder it will be to brute-force a password.
61270+
61271+config GRKERNSEC_ACL_TIMEOUT
61272+ int "Time to wait after max password tries, in seconds"
61273+ default 30
61274+ help
61275+ This option specifies the time the user must wait after attempting to
61276+ authorize to the RBAC system with the maximum number of invalid
61277+ passwords. The higher the number, the harder it will be to brute-force
61278+ a password.
61279+
61280+endmenu
61281+menu "Filesystem Protections"
61282+depends on GRKERNSEC
61283+
61284+config GRKERNSEC_PROC
61285+ bool "Proc restrictions"
61286+ default y if GRKERNSEC_CONFIG_AUTO
61287+ help
61288+ If you say Y here, the permissions of the /proc filesystem
61289+ will be altered to enhance system security and privacy. You MUST
61290+ choose either a user only restriction or a user and group restriction.
61291+ Depending upon the option you choose, you can either restrict users to
61292+ see only the processes they themselves run, or choose a group that can
61293+ view all processes and files normally restricted to root if you choose
61294+ the "restrict to user only" option. NOTE: If you're running identd or
61295+ ntpd as a non-root user, you will have to run it as the group you
61296+ specify here.
61297+
61298+config GRKERNSEC_PROC_USER
61299+ bool "Restrict /proc to user only"
61300+ depends on GRKERNSEC_PROC
61301+ help
61302+ If you say Y here, non-root users will only be able to view their own
61303+ processes, and restricts them from viewing network-related information,
61304+ and viewing kernel symbol and module information.
61305+
61306+config GRKERNSEC_PROC_USERGROUP
61307+ bool "Allow special group"
61308+ default y if GRKERNSEC_CONFIG_AUTO
61309+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61310+ help
61311+ If you say Y here, you will be able to select a group that will be
61312+ able to view all processes and network-related information. If you've
61313+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61314+ remain hidden. This option is useful if you want to run identd as
61315+ a non-root user. The group you select may also be chosen at boot time
61316+ via "grsec_proc_gid=" on the kernel commandline.
61317+
61318+config GRKERNSEC_PROC_GID
61319+ int "GID for special group"
61320+ depends on GRKERNSEC_PROC_USERGROUP
61321+ default 1001
61322+
61323+config GRKERNSEC_PROC_ADD
61324+ bool "Additional restrictions"
61325+ default y if GRKERNSEC_CONFIG_AUTO
61326+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61327+ help
61328+ If you say Y here, additional restrictions will be placed on
61329+ /proc that keep normal users from viewing device information and
61330+ slabinfo information that could be useful for exploits.
61331+
61332+config GRKERNSEC_LINK
61333+ bool "Linking restrictions"
61334+ default y if GRKERNSEC_CONFIG_AUTO
61335+ help
61336+ If you say Y here, /tmp race exploits will be prevented, since users
61337+ will no longer be able to follow symlinks owned by other users in
61338+ world-writable +t directories (e.g. /tmp), unless the owner of the
61339+ symlink is the owner of the directory. users will also not be
61340+ able to hardlink to files they do not own. If the sysctl option is
61341+ enabled, a sysctl option with name "linking_restrictions" is created.
61342+
61343+config GRKERNSEC_SYMLINKOWN
61344+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61345+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61346+ help
61347+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61348+ that prevents it from being used as a security feature. As Apache
61349+ verifies the symlink by performing a stat() against the target of
61350+ the symlink before it is followed, an attacker can setup a symlink
61351+ to point to a same-owned file, then replace the symlink with one
61352+ that targets another user's file just after Apache "validates" the
61353+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61354+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61355+ will be in place for the group you specify. If the sysctl option
61356+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61357+ created.
61358+
61359+config GRKERNSEC_SYMLINKOWN_GID
61360+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61361+ depends on GRKERNSEC_SYMLINKOWN
61362+ default 1006
61363+ help
61364+ Setting this GID determines what group kernel-enforced
61365+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61366+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61367+
61368+config GRKERNSEC_FIFO
61369+ bool "FIFO restrictions"
61370+ default y if GRKERNSEC_CONFIG_AUTO
61371+ help
61372+ If you say Y here, users will not be able to write to FIFOs they don't
61373+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61374+ the FIFO is the same owner of the directory it's held in. If the sysctl
61375+ option is enabled, a sysctl option with name "fifo_restrictions" is
61376+ created.
61377+
61378+config GRKERNSEC_SYSFS_RESTRICT
61379+ bool "Sysfs/debugfs restriction"
61380+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61381+ depends on SYSFS
61382+ help
61383+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61384+ any filesystem normally mounted under it (e.g. debugfs) will be
61385+ mostly accessible only by root. These filesystems generally provide access
61386+ to hardware and debug information that isn't appropriate for unprivileged
61387+ users of the system. Sysfs and debugfs have also become a large source
61388+ of new vulnerabilities, ranging from infoleaks to local compromise.
61389+ There has been very little oversight with an eye toward security involved
61390+ in adding new exporters of information to these filesystems, so their
61391+ use is discouraged.
61392+ For reasons of compatibility, a few directories have been whitelisted
61393+ for access by non-root users:
61394+ /sys/fs/selinux
61395+ /sys/fs/fuse
61396+ /sys/devices/system/cpu
61397+
61398+config GRKERNSEC_ROFS
61399+ bool "Runtime read-only mount protection"
61400+ depends on SYSCTL
61401+ help
61402+ If you say Y here, a sysctl option with name "romount_protect" will
61403+ be created. By setting this option to 1 at runtime, filesystems
61404+ will be protected in the following ways:
61405+ * No new writable mounts will be allowed
61406+ * Existing read-only mounts won't be able to be remounted read/write
61407+ * Write operations will be denied on all block devices
61408+ This option acts independently of grsec_lock: once it is set to 1,
61409+ it cannot be turned off. Therefore, please be mindful of the resulting
61410+ behavior if this option is enabled in an init script on a read-only
61411+ filesystem. This feature is mainly intended for secure embedded systems.
61412+
61413+config GRKERNSEC_DEVICE_SIDECHANNEL
61414+ bool "Eliminate stat/notify-based device sidechannels"
61415+ default y if GRKERNSEC_CONFIG_AUTO
61416+ help
61417+ If you say Y here, timing analyses on block or character
61418+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61419+ will be thwarted for unprivileged users. If a process without
61420+ CAP_MKNOD stats such a device, the last access and last modify times
61421+ will match the device's create time. No access or modify events
61422+ will be triggered through inotify/dnotify/fanotify for such devices.
61423+ This feature will prevent attacks that may at a minimum
61424+ allow an attacker to determine the administrator's password length.
61425+
61426+config GRKERNSEC_CHROOT
61427+ bool "Chroot jail restrictions"
61428+ default y if GRKERNSEC_CONFIG_AUTO
61429+ help
61430+ If you say Y here, you will be able to choose several options that will
61431+ make breaking out of a chrooted jail much more difficult. If you
61432+ encounter no software incompatibilities with the following options, it
61433+ is recommended that you enable each one.
61434+
61435+config GRKERNSEC_CHROOT_MOUNT
61436+ bool "Deny mounts"
61437+ default y if GRKERNSEC_CONFIG_AUTO
61438+ depends on GRKERNSEC_CHROOT
61439+ help
61440+ If you say Y here, processes inside a chroot will not be able to
61441+ mount or remount filesystems. If the sysctl option is enabled, a
61442+ sysctl option with name "chroot_deny_mount" is created.
61443+
61444+config GRKERNSEC_CHROOT_DOUBLE
61445+ bool "Deny double-chroots"
61446+ default y if GRKERNSEC_CONFIG_AUTO
61447+ depends on GRKERNSEC_CHROOT
61448+ help
61449+ If you say Y here, processes inside a chroot will not be able to chroot
61450+ again outside the chroot. This is a widely used method of breaking
61451+ out of a chroot jail and should not be allowed. If the sysctl
61452+ option is enabled, a sysctl option with name
61453+ "chroot_deny_chroot" is created.
61454+
61455+config GRKERNSEC_CHROOT_PIVOT
61456+ bool "Deny pivot_root in chroot"
61457+ default y if GRKERNSEC_CONFIG_AUTO
61458+ depends on GRKERNSEC_CHROOT
61459+ help
61460+ If you say Y here, processes inside a chroot will not be able to use
61461+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61462+ works similar to chroot in that it changes the root filesystem. This
61463+ function could be misused in a chrooted process to attempt to break out
61464+ of the chroot, and therefore should not be allowed. If the sysctl
61465+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61466+ created.
61467+
61468+config GRKERNSEC_CHROOT_CHDIR
61469+ bool "Enforce chdir(\"/\") on all chroots"
61470+ default y if GRKERNSEC_CONFIG_AUTO
61471+ depends on GRKERNSEC_CHROOT
61472+ help
61473+ If you say Y here, the current working directory of all newly-chrooted
61474+ applications will be set to the the root directory of the chroot.
61475+ The man page on chroot(2) states:
61476+ Note that this call does not change the current working
61477+ directory, so that `.' can be outside the tree rooted at
61478+ `/'. In particular, the super-user can escape from a
61479+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61480+
61481+ It is recommended that you say Y here, since it's not known to break
61482+ any software. If the sysctl option is enabled, a sysctl option with
61483+ name "chroot_enforce_chdir" is created.
61484+
61485+config GRKERNSEC_CHROOT_CHMOD
61486+ bool "Deny (f)chmod +s"
61487+ default y if GRKERNSEC_CONFIG_AUTO
61488+ depends on GRKERNSEC_CHROOT
61489+ help
61490+ If you say Y here, processes inside a chroot will not be able to chmod
61491+ or fchmod files to make them have suid or sgid bits. This protects
61492+ against another published method of breaking a chroot. If the sysctl
61493+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61494+ created.
61495+
61496+config GRKERNSEC_CHROOT_FCHDIR
61497+ bool "Deny fchdir out of chroot"
61498+ default y if GRKERNSEC_CONFIG_AUTO
61499+ depends on GRKERNSEC_CHROOT
61500+ help
61501+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61502+ to a file descriptor of the chrooting process that points to a directory
61503+ outside the filesystem will be stopped. If the sysctl option
61504+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61505+
61506+config GRKERNSEC_CHROOT_MKNOD
61507+ bool "Deny mknod"
61508+ default y if GRKERNSEC_CONFIG_AUTO
61509+ depends on GRKERNSEC_CHROOT
61510+ help
61511+ If you say Y here, processes inside a chroot will not be allowed to
61512+ mknod. The problem with using mknod inside a chroot is that it
61513+ would allow an attacker to create a device entry that is the same
61514+ as one on the physical root of your system, which could range from
61515+ anything from the console device to a device for your harddrive (which
61516+ they could then use to wipe the drive or steal data). It is recommended
61517+ that you say Y here, unless you run into software incompatibilities.
61518+ If the sysctl option is enabled, a sysctl option with name
61519+ "chroot_deny_mknod" is created.
61520+
61521+config GRKERNSEC_CHROOT_SHMAT
61522+ bool "Deny shmat() out of chroot"
61523+ default y if GRKERNSEC_CONFIG_AUTO
61524+ depends on GRKERNSEC_CHROOT
61525+ help
61526+ If you say Y here, processes inside a chroot will not be able to attach
61527+ to shared memory segments that were created outside of the chroot jail.
61528+ It is recommended that you say Y here. If the sysctl option is enabled,
61529+ a sysctl option with name "chroot_deny_shmat" is created.
61530+
61531+config GRKERNSEC_CHROOT_UNIX
61532+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
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
61537+ connect to abstract (meaning not belonging to a filesystem) Unix
61538+ domain sockets that were bound outside of a chroot. It is recommended
61539+ that you say Y here. If the sysctl option is enabled, a sysctl option
61540+ with name "chroot_deny_unix" is created.
61541+
61542+config GRKERNSEC_CHROOT_FINDTASK
61543+ bool "Protect outside processes"
61544+ default y if GRKERNSEC_CONFIG_AUTO
61545+ depends on GRKERNSEC_CHROOT
61546+ help
61547+ If you say Y here, processes inside a chroot will not be able to
61548+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61549+ getsid, or view any process outside of the chroot. If the sysctl
61550+ option is enabled, a sysctl option with name "chroot_findtask" is
61551+ created.
61552+
61553+config GRKERNSEC_CHROOT_NICE
61554+ bool "Restrict priority changes"
61555+ default y if GRKERNSEC_CONFIG_AUTO
61556+ depends on GRKERNSEC_CHROOT
61557+ help
61558+ If you say Y here, processes inside a chroot will not be able to raise
61559+ the priority of processes in the chroot, or alter the priority of
61560+ processes outside the chroot. This provides more security than simply
61561+ removing CAP_SYS_NICE from the process' capability set. If the
61562+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61563+ is created.
61564+
61565+config GRKERNSEC_CHROOT_SYSCTL
61566+ bool "Deny sysctl writes"
61567+ default y if GRKERNSEC_CONFIG_AUTO
61568+ depends on GRKERNSEC_CHROOT
61569+ help
61570+ If you say Y here, an attacker in a chroot will not be able to
61571+ write to sysctl entries, either by sysctl(2) or through a /proc
61572+ interface. It is strongly recommended that you say Y here. If the
61573+ sysctl option is enabled, a sysctl option with name
61574+ "chroot_deny_sysctl" is created.
61575+
61576+config GRKERNSEC_CHROOT_CAPS
61577+ bool "Capability restrictions"
61578+ default y if GRKERNSEC_CONFIG_AUTO
61579+ depends on GRKERNSEC_CHROOT
61580+ help
61581+ If you say Y here, the capabilities on all processes within a
61582+ chroot jail will be lowered to stop module insertion, raw i/o,
61583+ system and net admin tasks, rebooting the system, modifying immutable
61584+ files, modifying IPC owned by another, and changing the system time.
61585+ This is left an option because it can break some apps. Disable this
61586+ if your chrooted apps are having problems performing those kinds of
61587+ tasks. If the sysctl option is enabled, a sysctl option with
61588+ name "chroot_caps" is created.
61589+
61590+config GRKERNSEC_CHROOT_INITRD
61591+ bool "Exempt initrd tasks from restrictions"
61592+ default y if GRKERNSEC_CONFIG_AUTO
61593+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61594+ help
61595+ If you say Y here, tasks started prior to init will be exempted from
61596+ grsecurity's chroot restrictions. This option is mainly meant to
61597+ resolve Plymouth's performing privileged operations unnecessarily
61598+ in a chroot.
61599+
61600+endmenu
61601+menu "Kernel Auditing"
61602+depends on GRKERNSEC
61603+
61604+config GRKERNSEC_AUDIT_GROUP
61605+ bool "Single group for auditing"
61606+ help
61607+ If you say Y here, the exec and chdir logging features will only operate
61608+ on a group you specify. This option is recommended if you only want to
61609+ watch certain users instead of having a large amount of logs from the
61610+ entire system. If the sysctl option is enabled, a sysctl option with
61611+ name "audit_group" is created.
61612+
61613+config GRKERNSEC_AUDIT_GID
61614+ int "GID for auditing"
61615+ depends on GRKERNSEC_AUDIT_GROUP
61616+ default 1007
61617+
61618+config GRKERNSEC_EXECLOG
61619+ bool "Exec logging"
61620+ help
61621+ If you say Y here, all execve() calls will be logged (since the
61622+ other exec*() calls are frontends to execve(), all execution
61623+ will be logged). Useful for shell-servers that like to keep track
61624+ of their users. If the sysctl option is enabled, a sysctl option with
61625+ name "exec_logging" is created.
61626+ WARNING: This option when enabled will produce a LOT of logs, especially
61627+ on an active system.
61628+
61629+config GRKERNSEC_RESLOG
61630+ bool "Resource logging"
61631+ default y if GRKERNSEC_CONFIG_AUTO
61632+ help
61633+ If you say Y here, all attempts to overstep resource limits will
61634+ be logged with the resource name, the requested size, and the current
61635+ limit. It is highly recommended that you say Y here. If the sysctl
61636+ option is enabled, a sysctl option with name "resource_logging" is
61637+ created. If the RBAC system is enabled, the sysctl value is ignored.
61638+
61639+config GRKERNSEC_CHROOT_EXECLOG
61640+ bool "Log execs within chroot"
61641+ help
61642+ If you say Y here, all executions inside a chroot jail will be logged
61643+ to syslog. This can cause a large amount of logs if certain
61644+ applications (eg. djb's daemontools) are installed on the system, and
61645+ is therefore left as an option. If the sysctl option is enabled, a
61646+ sysctl option with name "chroot_execlog" is created.
61647+
61648+config GRKERNSEC_AUDIT_PTRACE
61649+ bool "Ptrace logging"
61650+ help
61651+ If you say Y here, all attempts to attach to a process via ptrace
61652+ will be logged. If the sysctl option is enabled, a sysctl option
61653+ with name "audit_ptrace" is created.
61654+
61655+config GRKERNSEC_AUDIT_CHDIR
61656+ bool "Chdir logging"
61657+ help
61658+ If you say Y here, all chdir() calls will be logged. If the sysctl
61659+ option is enabled, a sysctl option with name "audit_chdir" is created.
61660+
61661+config GRKERNSEC_AUDIT_MOUNT
61662+ bool "(Un)Mount logging"
61663+ help
61664+ If you say Y here, all mounts and unmounts will be logged. If the
61665+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61666+ created.
61667+
61668+config GRKERNSEC_SIGNAL
61669+ bool "Signal logging"
61670+ default y if GRKERNSEC_CONFIG_AUTO
61671+ help
61672+ If you say Y here, certain important signals will be logged, such as
61673+ SIGSEGV, which will as a result inform you of when a error in a program
61674+ occurred, which in some cases could mean a possible exploit attempt.
61675+ If the sysctl option is enabled, a sysctl option with name
61676+ "signal_logging" is created.
61677+
61678+config GRKERNSEC_FORKFAIL
61679+ bool "Fork failure logging"
61680+ help
61681+ If you say Y here, all failed fork() attempts will be logged.
61682+ This could suggest a fork bomb, or someone attempting to overstep
61683+ their process limit. If the sysctl option is enabled, a sysctl option
61684+ with name "forkfail_logging" is created.
61685+
61686+config GRKERNSEC_TIME
61687+ bool "Time change logging"
61688+ default y if GRKERNSEC_CONFIG_AUTO
61689+ help
61690+ If you say Y here, any changes of the system clock will be logged.
61691+ If the sysctl option is enabled, a sysctl option with name
61692+ "timechange_logging" is created.
61693+
61694+config GRKERNSEC_PROC_IPADDR
61695+ bool "/proc/<pid>/ipaddr support"
61696+ default y if GRKERNSEC_CONFIG_AUTO
61697+ help
61698+ If you say Y here, a new entry will be added to each /proc/<pid>
61699+ directory that contains the IP address of the person using the task.
61700+ The IP is carried across local TCP and AF_UNIX stream sockets.
61701+ This information can be useful for IDS/IPSes to perform remote response
61702+ to a local attack. The entry is readable by only the owner of the
61703+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61704+ the RBAC system), and thus does not create privacy concerns.
61705+
61706+config GRKERNSEC_RWXMAP_LOG
61707+ bool 'Denied RWX mmap/mprotect logging'
61708+ default y if GRKERNSEC_CONFIG_AUTO
61709+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61710+ help
61711+ If you say Y here, calls to mmap() and mprotect() with explicit
61712+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61713+ denied by the PAX_MPROTECT feature. This feature will also
61714+ log other problematic scenarios that can occur when PAX_MPROTECT
61715+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61716+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61717+ is created.
61718+
61719+endmenu
61720+
61721+menu "Executable Protections"
61722+depends on GRKERNSEC
61723+
61724+config GRKERNSEC_DMESG
61725+ bool "Dmesg(8) restriction"
61726+ default y if GRKERNSEC_CONFIG_AUTO
61727+ help
61728+ If you say Y here, non-root users will not be able to use dmesg(8)
61729+ to view the contents of the kernel's circular log buffer.
61730+ The kernel's log buffer often contains kernel addresses and other
61731+ identifying information useful to an attacker in fingerprinting a
61732+ system for a targeted exploit.
61733+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61734+ created.
61735+
61736+config GRKERNSEC_HARDEN_PTRACE
61737+ bool "Deter ptrace-based process snooping"
61738+ default y if GRKERNSEC_CONFIG_AUTO
61739+ help
61740+ If you say Y here, TTY sniffers and other malicious monitoring
61741+ programs implemented through ptrace will be defeated. If you
61742+ have been using the RBAC system, this option has already been
61743+ enabled for several years for all users, with the ability to make
61744+ fine-grained exceptions.
61745+
61746+ This option only affects the ability of non-root users to ptrace
61747+ processes that are not a descendent of the ptracing process.
61748+ This means that strace ./binary and gdb ./binary will still work,
61749+ but attaching to arbitrary processes will not. If the sysctl
61750+ option is enabled, a sysctl option with name "harden_ptrace" is
61751+ created.
61752+
61753+config GRKERNSEC_PTRACE_READEXEC
61754+ bool "Require read access to ptrace sensitive binaries"
61755+ default y if GRKERNSEC_CONFIG_AUTO
61756+ help
61757+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61758+ binaries. This option is useful in environments that
61759+ remove the read bits (e.g. file mode 4711) from suid binaries to
61760+ prevent infoleaking of their contents. This option adds
61761+ consistency to the use of that file mode, as the binary could normally
61762+ be read out when run without privileges while ptracing.
61763+
61764+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61765+ is created.
61766+
61767+config GRKERNSEC_SETXID
61768+ bool "Enforce consistent multithreaded privileges"
61769+ default y if GRKERNSEC_CONFIG_AUTO
61770+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61771+ help
61772+ If you say Y here, a change from a root uid to a non-root uid
61773+ in a multithreaded application will cause the resulting uids,
61774+ gids, supplementary groups, and capabilities in that thread
61775+ to be propagated to the other threads of the process. In most
61776+ cases this is unnecessary, as glibc will emulate this behavior
61777+ on behalf of the application. Other libcs do not act in the
61778+ same way, allowing the other threads of the process to continue
61779+ running with root privileges. If the sysctl option is enabled,
61780+ a sysctl option with name "consistent_setxid" is created.
61781+
61782+config GRKERNSEC_TPE
61783+ bool "Trusted Path Execution (TPE)"
61784+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61785+ help
61786+ If you say Y here, you will be able to choose a gid to add to the
61787+ supplementary groups of users you want to mark as "untrusted."
61788+ These users will not be able to execute any files that are not in
61789+ root-owned directories writable only by root. If the sysctl option
61790+ is enabled, a sysctl option with name "tpe" is created.
61791+
61792+config GRKERNSEC_TPE_ALL
61793+ bool "Partially restrict all non-root users"
61794+ depends on GRKERNSEC_TPE
61795+ help
61796+ If you say Y here, all non-root users will be covered under
61797+ a weaker TPE restriction. This is separate from, and in addition to,
61798+ the main TPE options that you have selected elsewhere. Thus, if a
61799+ "trusted" GID is chosen, this restriction applies to even that GID.
61800+ Under this restriction, all non-root users will only be allowed to
61801+ execute files in directories they own that are not group or
61802+ world-writable, or in directories owned by root and writable only by
61803+ root. If the sysctl option is enabled, a sysctl option with name
61804+ "tpe_restrict_all" is created.
61805+
61806+config GRKERNSEC_TPE_INVERT
61807+ bool "Invert GID option"
61808+ depends on GRKERNSEC_TPE
61809+ help
61810+ If you say Y here, the group you specify in the TPE configuration will
61811+ decide what group TPE restrictions will be *disabled* for. This
61812+ option is useful if you want TPE restrictions to be applied to most
61813+ users on the system. If the sysctl option is enabled, a sysctl option
61814+ with name "tpe_invert" is created. Unlike other sysctl options, this
61815+ entry will default to on for backward-compatibility.
61816+
61817+config GRKERNSEC_TPE_GID
61818+ int
61819+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61820+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61821+
61822+config GRKERNSEC_TPE_UNTRUSTED_GID
61823+ int "GID for TPE-untrusted users"
61824+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61825+ default 1005
61826+ help
61827+ Setting this GID determines what group TPE restrictions will be
61828+ *enabled* for. If the sysctl option is enabled, a sysctl option
61829+ with name "tpe_gid" is created.
61830+
61831+config GRKERNSEC_TPE_TRUSTED_GID
61832+ int "GID for TPE-trusted users"
61833+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61834+ default 1005
61835+ help
61836+ Setting this GID determines what group TPE restrictions will be
61837+ *disabled* for. If the sysctl option is enabled, a sysctl option
61838+ with name "tpe_gid" is created.
61839+
61840+endmenu
61841+menu "Network Protections"
61842+depends on GRKERNSEC
61843+
61844+config GRKERNSEC_RANDNET
61845+ bool "Larger entropy pools"
61846+ default y if GRKERNSEC_CONFIG_AUTO
61847+ help
61848+ If you say Y here, the entropy pools used for many features of Linux
61849+ and grsecurity will be doubled in size. Since several grsecurity
61850+ features use additional randomness, it is recommended that you say Y
61851+ here. Saying Y here has a similar effect as modifying
61852+ /proc/sys/kernel/random/poolsize.
61853+
61854+config GRKERNSEC_BLACKHOLE
61855+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61856+ default y if GRKERNSEC_CONFIG_AUTO
61857+ depends on NET
61858+ help
61859+ If you say Y here, neither TCP resets nor ICMP
61860+ destination-unreachable packets will be sent in response to packets
61861+ sent to ports for which no associated listening process exists.
61862+ This feature supports both IPV4 and IPV6 and exempts the
61863+ loopback interface from blackholing. Enabling this feature
61864+ makes a host more resilient to DoS attacks and reduces network
61865+ visibility against scanners.
61866+
61867+ The blackhole feature as-implemented is equivalent to the FreeBSD
61868+ blackhole feature, as it prevents RST responses to all packets, not
61869+ just SYNs. Under most application behavior this causes no
61870+ problems, but applications (like haproxy) may not close certain
61871+ connections in a way that cleanly terminates them on the remote
61872+ end, leaving the remote host in LAST_ACK state. Because of this
61873+ side-effect and to prevent intentional LAST_ACK DoSes, this
61874+ feature also adds automatic mitigation against such attacks.
61875+ The mitigation drastically reduces the amount of time a socket
61876+ can spend in LAST_ACK state. If you're using haproxy and not
61877+ all servers it connects to have this option enabled, consider
61878+ disabling this feature on the haproxy host.
61879+
61880+ If the sysctl option is enabled, two sysctl options with names
61881+ "ip_blackhole" and "lastack_retries" will be created.
61882+ While "ip_blackhole" takes the standard zero/non-zero on/off
61883+ toggle, "lastack_retries" uses the same kinds of values as
61884+ "tcp_retries1" and "tcp_retries2". The default value of 4
61885+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61886+ state.
61887+
61888+config GRKERNSEC_NO_SIMULT_CONNECT
61889+ bool "Disable TCP Simultaneous Connect"
61890+ default y if GRKERNSEC_CONFIG_AUTO
61891+ depends on NET
61892+ help
61893+ If you say Y here, a feature by Willy Tarreau will be enabled that
61894+ removes a weakness in Linux's strict implementation of TCP that
61895+ allows two clients to connect to each other without either entering
61896+ a listening state. The weakness allows an attacker to easily prevent
61897+ a client from connecting to a known server provided the source port
61898+ for the connection is guessed correctly.
61899+
61900+ As the weakness could be used to prevent an antivirus or IPS from
61901+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61902+ it should be eliminated by enabling this option. Though Linux is
61903+ one of few operating systems supporting simultaneous connect, it
61904+ has no legitimate use in practice and is rarely supported by firewalls.
61905+
61906+config GRKERNSEC_SOCKET
61907+ bool "Socket restrictions"
61908+ depends on NET
61909+ help
61910+ If you say Y here, you will be able to choose from several options.
61911+ If you assign a GID on your system and add it to the supplementary
61912+ groups of users you want to restrict socket access to, this patch
61913+ will perform up to three things, based on the option(s) you choose.
61914+
61915+config GRKERNSEC_SOCKET_ALL
61916+ bool "Deny any sockets to group"
61917+ depends on GRKERNSEC_SOCKET
61918+ help
61919+ If you say Y here, you will be able to choose a GID of whose users will
61920+ be unable to connect to other hosts from your machine or run server
61921+ applications from your machine. If the sysctl option is enabled, a
61922+ sysctl option with name "socket_all" is created.
61923+
61924+config GRKERNSEC_SOCKET_ALL_GID
61925+ int "GID to deny all sockets for"
61926+ depends on GRKERNSEC_SOCKET_ALL
61927+ default 1004
61928+ help
61929+ Here you can choose the GID to disable socket access for. Remember to
61930+ add the users you want socket access disabled for to the GID
61931+ specified here. If the sysctl option is enabled, a sysctl option
61932+ with name "socket_all_gid" is created.
61933+
61934+config GRKERNSEC_SOCKET_CLIENT
61935+ bool "Deny client sockets to group"
61936+ depends on GRKERNSEC_SOCKET
61937+ help
61938+ If you say Y here, you will be able to choose a GID of whose users will
61939+ be unable to connect to other hosts from your machine, but will be
61940+ able to run servers. If this option is enabled, all users in the group
61941+ you specify will have to use passive mode when initiating ftp transfers
61942+ from the shell on your machine. If the sysctl option is enabled, a
61943+ sysctl option with name "socket_client" is created.
61944+
61945+config GRKERNSEC_SOCKET_CLIENT_GID
61946+ int "GID to deny client sockets for"
61947+ depends on GRKERNSEC_SOCKET_CLIENT
61948+ default 1003
61949+ help
61950+ Here you can choose the GID to disable client socket access for.
61951+ Remember to add the users you want client socket access disabled for to
61952+ the GID specified here. If the sysctl option is enabled, a sysctl
61953+ option with name "socket_client_gid" is created.
61954+
61955+config GRKERNSEC_SOCKET_SERVER
61956+ bool "Deny server sockets to group"
61957+ depends on GRKERNSEC_SOCKET
61958+ help
61959+ If you say Y here, you will be able to choose a GID of whose users will
61960+ be unable to run server applications from your machine. If the sysctl
61961+ option is enabled, a sysctl option with name "socket_server" is created.
61962+
61963+config GRKERNSEC_SOCKET_SERVER_GID
61964+ int "GID to deny server sockets for"
61965+ depends on GRKERNSEC_SOCKET_SERVER
61966+ default 1002
61967+ help
61968+ Here you can choose the GID to disable server socket access for.
61969+ Remember to add the users you want server socket access disabled for to
61970+ the GID specified here. If the sysctl option is enabled, a sysctl
61971+ option with name "socket_server_gid" is created.
61972+
61973+endmenu
61974+
61975+menu "Physical Protections"
61976+depends on GRKERNSEC
61977+
61978+config GRKERNSEC_DENYUSB
61979+ bool "Deny new USB connections after toggle"
61980+ default y if GRKERNSEC_CONFIG_AUTO
61981+ depends on SYSCTL && USB_SUPPORT
61982+ help
61983+ If you say Y here, a new sysctl option with name "deny_new_usb"
61984+ will be created. Setting its value to 1 will prevent any new
61985+ USB devices from being recognized by the OS. Any attempted USB
61986+ device insertion will be logged. This option is intended to be
61987+ used against custom USB devices designed to exploit vulnerabilities
61988+ in various USB device drivers.
61989+
61990+ For greatest effectiveness, this sysctl should be set after any
61991+ relevant init scripts. This option is safe to enable in distros
61992+ as each user can choose whether or not to toggle the sysctl.
61993+
61994+config GRKERNSEC_DENYUSB_FORCE
61995+ bool "Reject all USB devices not connected at boot"
61996+ select USB
61997+ depends on GRKERNSEC_DENYUSB
61998+ help
61999+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62000+ that doesn't involve a sysctl entry. This option should only be
62001+ enabled if you're sure you want to deny all new USB connections
62002+ at runtime and don't want to modify init scripts. This should not
62003+ be enabled by distros. It forces the core USB code to be built
62004+ into the kernel image so that all devices connected at boot time
62005+ can be recognized and new USB device connections can be prevented
62006+ prior to init running.
62007+
62008+endmenu
62009+
62010+menu "Sysctl Support"
62011+depends on GRKERNSEC && SYSCTL
62012+
62013+config GRKERNSEC_SYSCTL
62014+ bool "Sysctl support"
62015+ default y if GRKERNSEC_CONFIG_AUTO
62016+ help
62017+ If you say Y here, you will be able to change the options that
62018+ grsecurity runs with at bootup, without having to recompile your
62019+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62020+ to enable (1) or disable (0) various features. All the sysctl entries
62021+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62022+ All features enabled in the kernel configuration are disabled at boot
62023+ if you do not say Y to the "Turn on features by default" option.
62024+ All options should be set at startup, and the grsec_lock entry should
62025+ be set to a non-zero value after all the options are set.
62026+ *THIS IS EXTREMELY IMPORTANT*
62027+
62028+config GRKERNSEC_SYSCTL_DISTRO
62029+ bool "Extra sysctl support for distro makers (READ HELP)"
62030+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62031+ help
62032+ If you say Y here, additional sysctl options will be created
62033+ for features that affect processes running as root. Therefore,
62034+ it is critical when using this option that the grsec_lock entry be
62035+ enabled after boot. Only distros with prebuilt kernel packages
62036+ with this option enabled that can ensure grsec_lock is enabled
62037+ after boot should use this option.
62038+ *Failure to set grsec_lock after boot makes all grsec features
62039+ this option covers useless*
62040+
62041+ Currently this option creates the following sysctl entries:
62042+ "Disable Privileged I/O": "disable_priv_io"
62043+
62044+config GRKERNSEC_SYSCTL_ON
62045+ bool "Turn on features by default"
62046+ default y if GRKERNSEC_CONFIG_AUTO
62047+ depends on GRKERNSEC_SYSCTL
62048+ help
62049+ If you say Y here, instead of having all features enabled in the
62050+ kernel configuration disabled at boot time, the features will be
62051+ enabled at boot time. It is recommended you say Y here unless
62052+ there is some reason you would want all sysctl-tunable features to
62053+ be disabled by default. As mentioned elsewhere, it is important
62054+ to enable the grsec_lock entry once you have finished modifying
62055+ the sysctl entries.
62056+
62057+endmenu
62058+menu "Logging Options"
62059+depends on GRKERNSEC
62060+
62061+config GRKERNSEC_FLOODTIME
62062+ int "Seconds in between log messages (minimum)"
62063+ default 10
62064+ help
62065+ This option allows you to enforce the number of seconds between
62066+ grsecurity log messages. The default should be suitable for most
62067+ people, however, if you choose to change it, choose a value small enough
62068+ to allow informative logs to be produced, but large enough to
62069+ prevent flooding.
62070+
62071+config GRKERNSEC_FLOODBURST
62072+ int "Number of messages in a burst (maximum)"
62073+ default 6
62074+ help
62075+ This option allows you to choose the maximum number of messages allowed
62076+ within the flood time interval you chose in a separate option. The
62077+ default should be suitable for most people, however if you find that
62078+ many of your logs are being interpreted as flooding, you may want to
62079+ raise this value.
62080+
62081+endmenu
62082diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62083new file mode 100644
62084index 0000000..b0b77d5
62085--- /dev/null
62086+++ b/grsecurity/Makefile
62087@@ -0,0 +1,43 @@
62088+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62089+# during 2001-2009 it has been completely redesigned by Brad Spengler
62090+# into an RBAC system
62091+#
62092+# All code in this directory and various hooks inserted throughout the kernel
62093+# are copyright Brad Spengler - Open Source Security, Inc., and released
62094+# under the GPL v2 or higher
62095+
62096+KBUILD_CFLAGS += -Werror
62097+
62098+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62099+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62100+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62101+ grsec_usb.o
62102+
62103+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62104+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62105+ gracl_learn.o grsec_log.o
62106+ifdef CONFIG_COMPAT
62107+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62108+endif
62109+
62110+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62111+
62112+ifdef CONFIG_NET
62113+obj-y += grsec_sock.o
62114+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62115+endif
62116+
62117+ifndef CONFIG_GRKERNSEC
62118+obj-y += grsec_disabled.o
62119+endif
62120+
62121+ifdef CONFIG_GRKERNSEC_HIDESYM
62122+extra-y := grsec_hidesym.o
62123+$(obj)/grsec_hidesym.o:
62124+ @-chmod -f 500 /boot
62125+ @-chmod -f 500 /lib/modules
62126+ @-chmod -f 500 /lib64/modules
62127+ @-chmod -f 500 /lib32/modules
62128+ @-chmod -f 700 .
62129+ @echo ' grsec: protected kernel image paths'
62130+endif
62131diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62132new file mode 100644
62133index 0000000..c0793fd
62134--- /dev/null
62135+++ b/grsecurity/gracl.c
62136@@ -0,0 +1,4178 @@
62137+#include <linux/kernel.h>
62138+#include <linux/module.h>
62139+#include <linux/sched.h>
62140+#include <linux/mm.h>
62141+#include <linux/file.h>
62142+#include <linux/fs.h>
62143+#include <linux/namei.h>
62144+#include <linux/mount.h>
62145+#include <linux/tty.h>
62146+#include <linux/proc_fs.h>
62147+#include <linux/lglock.h>
62148+#include <linux/slab.h>
62149+#include <linux/vmalloc.h>
62150+#include <linux/types.h>
62151+#include <linux/sysctl.h>
62152+#include <linux/netdevice.h>
62153+#include <linux/ptrace.h>
62154+#include <linux/gracl.h>
62155+#include <linux/gralloc.h>
62156+#include <linux/security.h>
62157+#include <linux/grinternal.h>
62158+#include <linux/pid_namespace.h>
62159+#include <linux/stop_machine.h>
62160+#include <linux/fdtable.h>
62161+#include <linux/percpu.h>
62162+#include <linux/lglock.h>
62163+#include <linux/hugetlb.h>
62164+#include <linux/posix-timers.h>
62165+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62166+#include <linux/magic.h>
62167+#include <linux/pagemap.h>
62168+#include "../fs/btrfs/async-thread.h"
62169+#include "../fs/btrfs/ctree.h"
62170+#include "../fs/btrfs/btrfs_inode.h"
62171+#endif
62172+#include "../fs/mount.h"
62173+
62174+#include <asm/uaccess.h>
62175+#include <asm/errno.h>
62176+#include <asm/mman.h>
62177+
62178+extern struct lglock vfsmount_lock;
62179+
62180+static struct acl_role_db acl_role_set;
62181+static struct name_db name_set;
62182+static struct inodev_db inodev_set;
62183+
62184+/* for keeping track of userspace pointers used for subjects, so we
62185+ can share references in the kernel as well
62186+*/
62187+
62188+static struct path real_root;
62189+
62190+static struct acl_subj_map_db subj_map_set;
62191+
62192+static struct acl_role_label *default_role;
62193+
62194+static struct acl_role_label *role_list;
62195+
62196+static u16 acl_sp_role_value;
62197+
62198+extern char *gr_shared_page[4];
62199+static DEFINE_MUTEX(gr_dev_mutex);
62200+DEFINE_RWLOCK(gr_inode_lock);
62201+
62202+struct gr_arg *gr_usermode;
62203+
62204+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62205+
62206+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62207+extern void gr_clear_learn_entries(void);
62208+
62209+unsigned char *gr_system_salt;
62210+unsigned char *gr_system_sum;
62211+
62212+static struct sprole_pw **acl_special_roles = NULL;
62213+static __u16 num_sprole_pws = 0;
62214+
62215+static struct acl_role_label *kernel_role = NULL;
62216+
62217+static unsigned int gr_auth_attempts = 0;
62218+static unsigned long gr_auth_expires = 0UL;
62219+
62220+#ifdef CONFIG_NET
62221+extern struct vfsmount *sock_mnt;
62222+#endif
62223+
62224+extern struct vfsmount *pipe_mnt;
62225+extern struct vfsmount *shm_mnt;
62226+
62227+#ifdef CONFIG_HUGETLBFS
62228+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62229+#endif
62230+
62231+static struct acl_object_label *fakefs_obj_rw;
62232+static struct acl_object_label *fakefs_obj_rwx;
62233+
62234+extern int gr_init_uidset(void);
62235+extern void gr_free_uidset(void);
62236+extern void gr_remove_uid(uid_t uid);
62237+extern int gr_find_uid(uid_t uid);
62238+
62239+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62240+{
62241+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62242+ return -EFAULT;
62243+
62244+ return 0;
62245+}
62246+
62247+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62248+{
62249+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62250+ return -EFAULT;
62251+
62252+ return 0;
62253+}
62254+
62255+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62256+{
62257+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62258+ return -EFAULT;
62259+
62260+ return 0;
62261+}
62262+
62263+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62264+{
62265+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62266+ return -EFAULT;
62267+
62268+ return 0;
62269+}
62270+
62271+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62272+{
62273+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62274+ return -EFAULT;
62275+
62276+ return 0;
62277+}
62278+
62279+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62280+{
62281+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62282+ return -EFAULT;
62283+
62284+ return 0;
62285+}
62286+
62287+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62288+{
62289+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62290+ return -EFAULT;
62291+
62292+ return 0;
62293+}
62294+
62295+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62296+{
62297+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62298+ return -EFAULT;
62299+
62300+ return 0;
62301+}
62302+
62303+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62304+{
62305+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62306+ return -EFAULT;
62307+
62308+ return 0;
62309+}
62310+
62311+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62312+{
62313+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62314+ return -EFAULT;
62315+
62316+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62317+ return -EINVAL;
62318+
62319+ return 0;
62320+}
62321+
62322+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62323+{
62324+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62325+ return -EFAULT;
62326+
62327+ return 0;
62328+}
62329+
62330+static size_t get_gr_arg_wrapper_size_normal(void)
62331+{
62332+ return sizeof(struct gr_arg_wrapper);
62333+}
62334+
62335+#ifdef CONFIG_COMPAT
62336+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62337+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62338+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62339+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62340+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62341+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62342+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62343+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62344+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62345+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62346+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62347+extern size_t get_gr_arg_wrapper_size_compat(void);
62348+
62349+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62350+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62351+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62352+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62353+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62354+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62355+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62356+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62357+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62358+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62359+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62360+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62361+
62362+#else
62363+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62364+#define copy_gr_arg copy_gr_arg_normal
62365+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62366+#define copy_acl_object_label copy_acl_object_label_normal
62367+#define copy_acl_subject_label copy_acl_subject_label_normal
62368+#define copy_acl_role_label copy_acl_role_label_normal
62369+#define copy_acl_ip_label copy_acl_ip_label_normal
62370+#define copy_pointer_from_array copy_pointer_from_array_normal
62371+#define copy_sprole_pw copy_sprole_pw_normal
62372+#define copy_role_transition copy_role_transition_normal
62373+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62374+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62375+#endif
62376+
62377+__inline__ int
62378+gr_acl_is_enabled(void)
62379+{
62380+ return (gr_status & GR_READY);
62381+}
62382+
62383+static inline dev_t __get_dev(const struct dentry *dentry)
62384+{
62385+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62386+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62387+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62388+ else
62389+#endif
62390+ return dentry->d_sb->s_dev;
62391+}
62392+
62393+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62394+{
62395+ return __get_dev(dentry);
62396+}
62397+
62398+static char gr_task_roletype_to_char(struct task_struct *task)
62399+{
62400+ switch (task->role->roletype &
62401+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62402+ GR_ROLE_SPECIAL)) {
62403+ case GR_ROLE_DEFAULT:
62404+ return 'D';
62405+ case GR_ROLE_USER:
62406+ return 'U';
62407+ case GR_ROLE_GROUP:
62408+ return 'G';
62409+ case GR_ROLE_SPECIAL:
62410+ return 'S';
62411+ }
62412+
62413+ return 'X';
62414+}
62415+
62416+char gr_roletype_to_char(void)
62417+{
62418+ return gr_task_roletype_to_char(current);
62419+}
62420+
62421+__inline__ int
62422+gr_acl_tpe_check(void)
62423+{
62424+ if (unlikely(!(gr_status & GR_READY)))
62425+ return 0;
62426+ if (current->role->roletype & GR_ROLE_TPE)
62427+ return 1;
62428+ else
62429+ return 0;
62430+}
62431+
62432+int
62433+gr_handle_rawio(const struct inode *inode)
62434+{
62435+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62436+ if (inode && S_ISBLK(inode->i_mode) &&
62437+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62438+ !capable(CAP_SYS_RAWIO))
62439+ return 1;
62440+#endif
62441+ return 0;
62442+}
62443+
62444+static int
62445+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62446+{
62447+ if (likely(lena != lenb))
62448+ return 0;
62449+
62450+ return !memcmp(a, b, lena);
62451+}
62452+
62453+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62454+{
62455+ *buflen -= namelen;
62456+ if (*buflen < 0)
62457+ return -ENAMETOOLONG;
62458+ *buffer -= namelen;
62459+ memcpy(*buffer, str, namelen);
62460+ return 0;
62461+}
62462+
62463+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62464+{
62465+ return prepend(buffer, buflen, name->name, name->len);
62466+}
62467+
62468+static int prepend_path(const struct path *path, struct path *root,
62469+ char **buffer, int *buflen)
62470+{
62471+ struct dentry *dentry = path->dentry;
62472+ struct vfsmount *vfsmnt = path->mnt;
62473+ struct mount *mnt = real_mount(vfsmnt);
62474+ bool slash = false;
62475+ int error = 0;
62476+
62477+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62478+ struct dentry * parent;
62479+
62480+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62481+ /* Global root? */
62482+ if (!mnt_has_parent(mnt)) {
62483+ goto out;
62484+ }
62485+ dentry = mnt->mnt_mountpoint;
62486+ mnt = mnt->mnt_parent;
62487+ vfsmnt = &mnt->mnt;
62488+ continue;
62489+ }
62490+ parent = dentry->d_parent;
62491+ prefetch(parent);
62492+ spin_lock(&dentry->d_lock);
62493+ error = prepend_name(buffer, buflen, &dentry->d_name);
62494+ spin_unlock(&dentry->d_lock);
62495+ if (!error)
62496+ error = prepend(buffer, buflen, "/", 1);
62497+ if (error)
62498+ break;
62499+
62500+ slash = true;
62501+ dentry = parent;
62502+ }
62503+
62504+out:
62505+ if (!error && !slash)
62506+ error = prepend(buffer, buflen, "/", 1);
62507+
62508+ return error;
62509+}
62510+
62511+/* this must be called with vfsmount_lock and rename_lock held */
62512+
62513+static char *__our_d_path(const struct path *path, struct path *root,
62514+ char *buf, int buflen)
62515+{
62516+ char *res = buf + buflen;
62517+ int error;
62518+
62519+ prepend(&res, &buflen, "\0", 1);
62520+ error = prepend_path(path, root, &res, &buflen);
62521+ if (error)
62522+ return ERR_PTR(error);
62523+
62524+ return res;
62525+}
62526+
62527+static char *
62528+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62529+{
62530+ char *retval;
62531+
62532+ retval = __our_d_path(path, root, buf, buflen);
62533+ if (unlikely(IS_ERR(retval)))
62534+ retval = strcpy(buf, "<path too long>");
62535+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62536+ retval[1] = '\0';
62537+
62538+ return retval;
62539+}
62540+
62541+static char *
62542+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62543+ char *buf, int buflen)
62544+{
62545+ struct path path;
62546+ char *res;
62547+
62548+ path.dentry = (struct dentry *)dentry;
62549+ path.mnt = (struct vfsmount *)vfsmnt;
62550+
62551+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62552+ by the RBAC system */
62553+ res = gen_full_path(&path, &real_root, buf, buflen);
62554+
62555+ return res;
62556+}
62557+
62558+static char *
62559+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62560+ char *buf, int buflen)
62561+{
62562+ char *res;
62563+ struct path path;
62564+ struct path root;
62565+ struct task_struct *reaper = init_pid_ns.child_reaper;
62566+
62567+ path.dentry = (struct dentry *)dentry;
62568+ path.mnt = (struct vfsmount *)vfsmnt;
62569+
62570+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62571+ get_fs_root(reaper->fs, &root);
62572+
62573+ br_read_lock(&vfsmount_lock);
62574+ write_seqlock(&rename_lock);
62575+ res = gen_full_path(&path, &root, buf, buflen);
62576+ write_sequnlock(&rename_lock);
62577+ br_read_unlock(&vfsmount_lock);
62578+
62579+ path_put(&root);
62580+ return res;
62581+}
62582+
62583+static char *
62584+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62585+{
62586+ char *ret;
62587+ br_read_lock(&vfsmount_lock);
62588+ write_seqlock(&rename_lock);
62589+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62590+ PAGE_SIZE);
62591+ write_sequnlock(&rename_lock);
62592+ br_read_unlock(&vfsmount_lock);
62593+ return ret;
62594+}
62595+
62596+static char *
62597+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62598+{
62599+ char *ret;
62600+ char *buf;
62601+ int buflen;
62602+
62603+ br_read_lock(&vfsmount_lock);
62604+ write_seqlock(&rename_lock);
62605+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62606+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62607+ buflen = (int)(ret - buf);
62608+ if (buflen >= 5)
62609+ prepend(&ret, &buflen, "/proc", 5);
62610+ else
62611+ ret = strcpy(buf, "<path too long>");
62612+ write_sequnlock(&rename_lock);
62613+ br_read_unlock(&vfsmount_lock);
62614+ return ret;
62615+}
62616+
62617+char *
62618+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62619+{
62620+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62621+ PAGE_SIZE);
62622+}
62623+
62624+char *
62625+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62626+{
62627+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62628+ PAGE_SIZE);
62629+}
62630+
62631+char *
62632+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62633+{
62634+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62635+ PAGE_SIZE);
62636+}
62637+
62638+char *
62639+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62640+{
62641+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62642+ PAGE_SIZE);
62643+}
62644+
62645+char *
62646+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62647+{
62648+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62649+ PAGE_SIZE);
62650+}
62651+
62652+__inline__ __u32
62653+to_gr_audit(const __u32 reqmode)
62654+{
62655+ /* masks off auditable permission flags, then shifts them to create
62656+ auditing flags, and adds the special case of append auditing if
62657+ we're requesting write */
62658+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62659+}
62660+
62661+struct acl_subject_label *
62662+lookup_subject_map(const struct acl_subject_label *userp)
62663+{
62664+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62665+ struct subject_map *match;
62666+
62667+ match = subj_map_set.s_hash[index];
62668+
62669+ while (match && match->user != userp)
62670+ match = match->next;
62671+
62672+ if (match != NULL)
62673+ return match->kernel;
62674+ else
62675+ return NULL;
62676+}
62677+
62678+static void
62679+insert_subj_map_entry(struct subject_map *subjmap)
62680+{
62681+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62682+ struct subject_map **curr;
62683+
62684+ subjmap->prev = NULL;
62685+
62686+ curr = &subj_map_set.s_hash[index];
62687+ if (*curr != NULL)
62688+ (*curr)->prev = subjmap;
62689+
62690+ subjmap->next = *curr;
62691+ *curr = subjmap;
62692+
62693+ return;
62694+}
62695+
62696+static struct acl_role_label *
62697+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62698+ const gid_t gid)
62699+{
62700+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62701+ struct acl_role_label *match;
62702+ struct role_allowed_ip *ipp;
62703+ unsigned int x;
62704+ u32 curr_ip = task->signal->curr_ip;
62705+
62706+ task->signal->saved_ip = curr_ip;
62707+
62708+ match = acl_role_set.r_hash[index];
62709+
62710+ while (match) {
62711+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62712+ for (x = 0; x < match->domain_child_num; x++) {
62713+ if (match->domain_children[x] == uid)
62714+ goto found;
62715+ }
62716+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62717+ break;
62718+ match = match->next;
62719+ }
62720+found:
62721+ if (match == NULL) {
62722+ try_group:
62723+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62724+ match = acl_role_set.r_hash[index];
62725+
62726+ while (match) {
62727+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62728+ for (x = 0; x < match->domain_child_num; x++) {
62729+ if (match->domain_children[x] == gid)
62730+ goto found2;
62731+ }
62732+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62733+ break;
62734+ match = match->next;
62735+ }
62736+found2:
62737+ if (match == NULL)
62738+ match = default_role;
62739+ if (match->allowed_ips == NULL)
62740+ return match;
62741+ else {
62742+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62743+ if (likely
62744+ ((ntohl(curr_ip) & ipp->netmask) ==
62745+ (ntohl(ipp->addr) & ipp->netmask)))
62746+ return match;
62747+ }
62748+ match = default_role;
62749+ }
62750+ } else if (match->allowed_ips == NULL) {
62751+ return match;
62752+ } else {
62753+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62754+ if (likely
62755+ ((ntohl(curr_ip) & ipp->netmask) ==
62756+ (ntohl(ipp->addr) & ipp->netmask)))
62757+ return match;
62758+ }
62759+ goto try_group;
62760+ }
62761+
62762+ return match;
62763+}
62764+
62765+struct acl_subject_label *
62766+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62767+ const struct acl_role_label *role)
62768+{
62769+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62770+ struct acl_subject_label *match;
62771+
62772+ match = role->subj_hash[index];
62773+
62774+ while (match && (match->inode != ino || match->device != dev ||
62775+ (match->mode & GR_DELETED))) {
62776+ match = match->next;
62777+ }
62778+
62779+ if (match && !(match->mode & GR_DELETED))
62780+ return match;
62781+ else
62782+ return NULL;
62783+}
62784+
62785+struct acl_subject_label *
62786+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62787+ const struct acl_role_label *role)
62788+{
62789+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62790+ struct acl_subject_label *match;
62791+
62792+ match = role->subj_hash[index];
62793+
62794+ while (match && (match->inode != ino || match->device != dev ||
62795+ !(match->mode & GR_DELETED))) {
62796+ match = match->next;
62797+ }
62798+
62799+ if (match && (match->mode & GR_DELETED))
62800+ return match;
62801+ else
62802+ return NULL;
62803+}
62804+
62805+static struct acl_object_label *
62806+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62807+ const struct acl_subject_label *subj)
62808+{
62809+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62810+ struct acl_object_label *match;
62811+
62812+ match = subj->obj_hash[index];
62813+
62814+ while (match && (match->inode != ino || match->device != dev ||
62815+ (match->mode & GR_DELETED))) {
62816+ match = match->next;
62817+ }
62818+
62819+ if (match && !(match->mode & GR_DELETED))
62820+ return match;
62821+ else
62822+ return NULL;
62823+}
62824+
62825+static struct acl_object_label *
62826+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62827+ const struct acl_subject_label *subj)
62828+{
62829+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62830+ struct acl_object_label *match;
62831+
62832+ match = subj->obj_hash[index];
62833+
62834+ while (match && (match->inode != ino || match->device != dev ||
62835+ !(match->mode & GR_DELETED))) {
62836+ match = match->next;
62837+ }
62838+
62839+ if (match && (match->mode & GR_DELETED))
62840+ return match;
62841+
62842+ match = subj->obj_hash[index];
62843+
62844+ while (match && (match->inode != ino || match->device != dev ||
62845+ (match->mode & GR_DELETED))) {
62846+ match = match->next;
62847+ }
62848+
62849+ if (match && !(match->mode & GR_DELETED))
62850+ return match;
62851+ else
62852+ return NULL;
62853+}
62854+
62855+static struct name_entry *
62856+lookup_name_entry(const char *name)
62857+{
62858+ unsigned int len = strlen(name);
62859+ unsigned int key = full_name_hash(name, len);
62860+ unsigned int index = key % name_set.n_size;
62861+ struct name_entry *match;
62862+
62863+ match = name_set.n_hash[index];
62864+
62865+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62866+ match = match->next;
62867+
62868+ return match;
62869+}
62870+
62871+static struct name_entry *
62872+lookup_name_entry_create(const char *name)
62873+{
62874+ unsigned int len = strlen(name);
62875+ unsigned int key = full_name_hash(name, len);
62876+ unsigned int index = key % name_set.n_size;
62877+ struct name_entry *match;
62878+
62879+ match = name_set.n_hash[index];
62880+
62881+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62882+ !match->deleted))
62883+ match = match->next;
62884+
62885+ if (match && match->deleted)
62886+ return match;
62887+
62888+ match = name_set.n_hash[index];
62889+
62890+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62891+ match->deleted))
62892+ match = match->next;
62893+
62894+ if (match && !match->deleted)
62895+ return match;
62896+ else
62897+ return NULL;
62898+}
62899+
62900+static struct inodev_entry *
62901+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62902+{
62903+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62904+ struct inodev_entry *match;
62905+
62906+ match = inodev_set.i_hash[index];
62907+
62908+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62909+ match = match->next;
62910+
62911+ return match;
62912+}
62913+
62914+static void
62915+insert_inodev_entry(struct inodev_entry *entry)
62916+{
62917+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62918+ inodev_set.i_size);
62919+ struct inodev_entry **curr;
62920+
62921+ entry->prev = NULL;
62922+
62923+ curr = &inodev_set.i_hash[index];
62924+ if (*curr != NULL)
62925+ (*curr)->prev = entry;
62926+
62927+ entry->next = *curr;
62928+ *curr = entry;
62929+
62930+ return;
62931+}
62932+
62933+static void
62934+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62935+{
62936+ unsigned int index =
62937+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62938+ struct acl_role_label **curr;
62939+ struct acl_role_label *tmp, *tmp2;
62940+
62941+ curr = &acl_role_set.r_hash[index];
62942+
62943+ /* simple case, slot is empty, just set it to our role */
62944+ if (*curr == NULL) {
62945+ *curr = role;
62946+ } else {
62947+ /* example:
62948+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62949+ 2 -> 3
62950+ */
62951+ /* first check to see if we can already be reached via this slot */
62952+ tmp = *curr;
62953+ while (tmp && tmp != role)
62954+ tmp = tmp->next;
62955+ if (tmp == role) {
62956+ /* we don't need to add ourselves to this slot's chain */
62957+ return;
62958+ }
62959+ /* we need to add ourselves to this chain, two cases */
62960+ if (role->next == NULL) {
62961+ /* simple case, append the current chain to our role */
62962+ role->next = *curr;
62963+ *curr = role;
62964+ } else {
62965+ /* 1 -> 2 -> 3 -> 4
62966+ 2 -> 3 -> 4
62967+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62968+ */
62969+ /* trickier case: walk our role's chain until we find
62970+ the role for the start of the current slot's chain */
62971+ tmp = role;
62972+ tmp2 = *curr;
62973+ while (tmp->next && tmp->next != tmp2)
62974+ tmp = tmp->next;
62975+ if (tmp->next == tmp2) {
62976+ /* from example above, we found 3, so just
62977+ replace this slot's chain with ours */
62978+ *curr = role;
62979+ } else {
62980+ /* we didn't find a subset of our role's chain
62981+ in the current slot's chain, so append their
62982+ chain to ours, and set us as the first role in
62983+ the slot's chain
62984+
62985+ we could fold this case with the case above,
62986+ but making it explicit for clarity
62987+ */
62988+ tmp->next = tmp2;
62989+ *curr = role;
62990+ }
62991+ }
62992+ }
62993+
62994+ return;
62995+}
62996+
62997+static void
62998+insert_acl_role_label(struct acl_role_label *role)
62999+{
63000+ int i;
63001+
63002+ if (role_list == NULL) {
63003+ role_list = role;
63004+ role->prev = NULL;
63005+ } else {
63006+ role->prev = role_list;
63007+ role_list = role;
63008+ }
63009+
63010+ /* used for hash chains */
63011+ role->next = NULL;
63012+
63013+ if (role->roletype & GR_ROLE_DOMAIN) {
63014+ for (i = 0; i < role->domain_child_num; i++)
63015+ __insert_acl_role_label(role, role->domain_children[i]);
63016+ } else
63017+ __insert_acl_role_label(role, role->uidgid);
63018+}
63019+
63020+static int
63021+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63022+{
63023+ struct name_entry **curr, *nentry;
63024+ struct inodev_entry *ientry;
63025+ unsigned int len = strlen(name);
63026+ unsigned int key = full_name_hash(name, len);
63027+ unsigned int index = key % name_set.n_size;
63028+
63029+ curr = &name_set.n_hash[index];
63030+
63031+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63032+ curr = &((*curr)->next);
63033+
63034+ if (*curr != NULL)
63035+ return 1;
63036+
63037+ nentry = acl_alloc(sizeof (struct name_entry));
63038+ if (nentry == NULL)
63039+ return 0;
63040+ ientry = acl_alloc(sizeof (struct inodev_entry));
63041+ if (ientry == NULL)
63042+ return 0;
63043+ ientry->nentry = nentry;
63044+
63045+ nentry->key = key;
63046+ nentry->name = name;
63047+ nentry->inode = inode;
63048+ nentry->device = device;
63049+ nentry->len = len;
63050+ nentry->deleted = deleted;
63051+
63052+ nentry->prev = NULL;
63053+ curr = &name_set.n_hash[index];
63054+ if (*curr != NULL)
63055+ (*curr)->prev = nentry;
63056+ nentry->next = *curr;
63057+ *curr = nentry;
63058+
63059+ /* insert us into the table searchable by inode/dev */
63060+ insert_inodev_entry(ientry);
63061+
63062+ return 1;
63063+}
63064+
63065+static void
63066+insert_acl_obj_label(struct acl_object_label *obj,
63067+ struct acl_subject_label *subj)
63068+{
63069+ unsigned int index =
63070+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63071+ struct acl_object_label **curr;
63072+
63073+
63074+ obj->prev = NULL;
63075+
63076+ curr = &subj->obj_hash[index];
63077+ if (*curr != NULL)
63078+ (*curr)->prev = obj;
63079+
63080+ obj->next = *curr;
63081+ *curr = obj;
63082+
63083+ return;
63084+}
63085+
63086+static void
63087+insert_acl_subj_label(struct acl_subject_label *obj,
63088+ struct acl_role_label *role)
63089+{
63090+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63091+ struct acl_subject_label **curr;
63092+
63093+ obj->prev = NULL;
63094+
63095+ curr = &role->subj_hash[index];
63096+ if (*curr != NULL)
63097+ (*curr)->prev = obj;
63098+
63099+ obj->next = *curr;
63100+ *curr = obj;
63101+
63102+ return;
63103+}
63104+
63105+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63106+
63107+static void *
63108+create_table(__u32 * len, int elementsize)
63109+{
63110+ unsigned int table_sizes[] = {
63111+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63112+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63113+ 4194301, 8388593, 16777213, 33554393, 67108859
63114+ };
63115+ void *newtable = NULL;
63116+ unsigned int pwr = 0;
63117+
63118+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63119+ table_sizes[pwr] <= *len)
63120+ pwr++;
63121+
63122+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63123+ return newtable;
63124+
63125+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63126+ newtable =
63127+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63128+ else
63129+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63130+
63131+ *len = table_sizes[pwr];
63132+
63133+ return newtable;
63134+}
63135+
63136+static int
63137+init_variables(const struct gr_arg *arg)
63138+{
63139+ struct task_struct *reaper = init_pid_ns.child_reaper;
63140+ unsigned int stacksize;
63141+
63142+ subj_map_set.s_size = arg->role_db.num_subjects;
63143+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63144+ name_set.n_size = arg->role_db.num_objects;
63145+ inodev_set.i_size = arg->role_db.num_objects;
63146+
63147+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63148+ !name_set.n_size || !inodev_set.i_size)
63149+ return 1;
63150+
63151+ if (!gr_init_uidset())
63152+ return 1;
63153+
63154+ /* set up the stack that holds allocation info */
63155+
63156+ stacksize = arg->role_db.num_pointers + 5;
63157+
63158+ if (!acl_alloc_stack_init(stacksize))
63159+ return 1;
63160+
63161+ /* grab reference for the real root dentry and vfsmount */
63162+ get_fs_root(reaper->fs, &real_root);
63163+
63164+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63165+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63166+#endif
63167+
63168+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63169+ if (fakefs_obj_rw == NULL)
63170+ return 1;
63171+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63172+
63173+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63174+ if (fakefs_obj_rwx == NULL)
63175+ return 1;
63176+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63177+
63178+ subj_map_set.s_hash =
63179+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63180+ acl_role_set.r_hash =
63181+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63182+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63183+ inodev_set.i_hash =
63184+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63185+
63186+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63187+ !name_set.n_hash || !inodev_set.i_hash)
63188+ return 1;
63189+
63190+ memset(subj_map_set.s_hash, 0,
63191+ sizeof(struct subject_map *) * subj_map_set.s_size);
63192+ memset(acl_role_set.r_hash, 0,
63193+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63194+ memset(name_set.n_hash, 0,
63195+ sizeof (struct name_entry *) * name_set.n_size);
63196+ memset(inodev_set.i_hash, 0,
63197+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63198+
63199+ return 0;
63200+}
63201+
63202+/* free information not needed after startup
63203+ currently contains user->kernel pointer mappings for subjects
63204+*/
63205+
63206+static void
63207+free_init_variables(void)
63208+{
63209+ __u32 i;
63210+
63211+ if (subj_map_set.s_hash) {
63212+ for (i = 0; i < subj_map_set.s_size; i++) {
63213+ if (subj_map_set.s_hash[i]) {
63214+ kfree(subj_map_set.s_hash[i]);
63215+ subj_map_set.s_hash[i] = NULL;
63216+ }
63217+ }
63218+
63219+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63220+ PAGE_SIZE)
63221+ kfree(subj_map_set.s_hash);
63222+ else
63223+ vfree(subj_map_set.s_hash);
63224+ }
63225+
63226+ return;
63227+}
63228+
63229+static void
63230+free_variables(void)
63231+{
63232+ struct acl_subject_label *s;
63233+ struct acl_role_label *r;
63234+ struct task_struct *task, *task2;
63235+ unsigned int x;
63236+
63237+ gr_clear_learn_entries();
63238+
63239+ read_lock(&tasklist_lock);
63240+ do_each_thread(task2, task) {
63241+ task->acl_sp_role = 0;
63242+ task->acl_role_id = 0;
63243+ task->acl = NULL;
63244+ task->role = NULL;
63245+ } while_each_thread(task2, task);
63246+ read_unlock(&tasklist_lock);
63247+
63248+ /* release the reference to the real root dentry and vfsmount */
63249+ path_put(&real_root);
63250+ memset(&real_root, 0, sizeof(real_root));
63251+
63252+ /* free all object hash tables */
63253+
63254+ FOR_EACH_ROLE_START(r)
63255+ if (r->subj_hash == NULL)
63256+ goto next_role;
63257+ FOR_EACH_SUBJECT_START(r, s, x)
63258+ if (s->obj_hash == NULL)
63259+ break;
63260+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63261+ kfree(s->obj_hash);
63262+ else
63263+ vfree(s->obj_hash);
63264+ FOR_EACH_SUBJECT_END(s, x)
63265+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63266+ if (s->obj_hash == NULL)
63267+ break;
63268+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63269+ kfree(s->obj_hash);
63270+ else
63271+ vfree(s->obj_hash);
63272+ FOR_EACH_NESTED_SUBJECT_END(s)
63273+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63274+ kfree(r->subj_hash);
63275+ else
63276+ vfree(r->subj_hash);
63277+ r->subj_hash = NULL;
63278+next_role:
63279+ FOR_EACH_ROLE_END(r)
63280+
63281+ acl_free_all();
63282+
63283+ if (acl_role_set.r_hash) {
63284+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63285+ PAGE_SIZE)
63286+ kfree(acl_role_set.r_hash);
63287+ else
63288+ vfree(acl_role_set.r_hash);
63289+ }
63290+ if (name_set.n_hash) {
63291+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63292+ PAGE_SIZE)
63293+ kfree(name_set.n_hash);
63294+ else
63295+ vfree(name_set.n_hash);
63296+ }
63297+
63298+ if (inodev_set.i_hash) {
63299+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63300+ PAGE_SIZE)
63301+ kfree(inodev_set.i_hash);
63302+ else
63303+ vfree(inodev_set.i_hash);
63304+ }
63305+
63306+ gr_free_uidset();
63307+
63308+ memset(&name_set, 0, sizeof (struct name_db));
63309+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63310+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63311+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63312+
63313+ default_role = NULL;
63314+ kernel_role = NULL;
63315+ role_list = NULL;
63316+
63317+ return;
63318+}
63319+
63320+static struct acl_subject_label *
63321+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63322+
63323+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63324+{
63325+ unsigned int len = strnlen_user(*name, maxlen);
63326+ char *tmp;
63327+
63328+ if (!len || len >= maxlen)
63329+ return -EINVAL;
63330+
63331+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63332+ return -ENOMEM;
63333+
63334+ if (copy_from_user(tmp, *name, len))
63335+ return -EFAULT;
63336+
63337+ tmp[len-1] = '\0';
63338+ *name = tmp;
63339+
63340+ return 0;
63341+}
63342+
63343+static int
63344+copy_user_glob(struct acl_object_label *obj)
63345+{
63346+ struct acl_object_label *g_tmp, **guser;
63347+ int error;
63348+
63349+ if (obj->globbed == NULL)
63350+ return 0;
63351+
63352+ guser = &obj->globbed;
63353+ while (*guser) {
63354+ g_tmp = (struct acl_object_label *)
63355+ acl_alloc(sizeof (struct acl_object_label));
63356+ if (g_tmp == NULL)
63357+ return -ENOMEM;
63358+
63359+ if (copy_acl_object_label(g_tmp, *guser))
63360+ return -EFAULT;
63361+
63362+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63363+ if (error)
63364+ return error;
63365+
63366+ *guser = g_tmp;
63367+ guser = &(g_tmp->next);
63368+ }
63369+
63370+ return 0;
63371+}
63372+
63373+static int
63374+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63375+ struct acl_role_label *role)
63376+{
63377+ struct acl_object_label *o_tmp;
63378+ int ret;
63379+
63380+ while (userp) {
63381+ if ((o_tmp = (struct acl_object_label *)
63382+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63383+ return -ENOMEM;
63384+
63385+ if (copy_acl_object_label(o_tmp, userp))
63386+ return -EFAULT;
63387+
63388+ userp = o_tmp->prev;
63389+
63390+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63391+ if (ret)
63392+ return ret;
63393+
63394+ insert_acl_obj_label(o_tmp, subj);
63395+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63396+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63397+ return -ENOMEM;
63398+
63399+ ret = copy_user_glob(o_tmp);
63400+ if (ret)
63401+ return ret;
63402+
63403+ if (o_tmp->nested) {
63404+ int already_copied;
63405+
63406+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63407+ if (IS_ERR(o_tmp->nested))
63408+ return PTR_ERR(o_tmp->nested);
63409+
63410+ /* insert into nested subject list if we haven't copied this one yet
63411+ to prevent duplicate entries */
63412+ if (!already_copied) {
63413+ o_tmp->nested->next = role->hash->first;
63414+ role->hash->first = o_tmp->nested;
63415+ }
63416+ }
63417+ }
63418+
63419+ return 0;
63420+}
63421+
63422+static __u32
63423+count_user_subjs(struct acl_subject_label *userp)
63424+{
63425+ struct acl_subject_label s_tmp;
63426+ __u32 num = 0;
63427+
63428+ while (userp) {
63429+ if (copy_acl_subject_label(&s_tmp, userp))
63430+ break;
63431+
63432+ userp = s_tmp.prev;
63433+ }
63434+
63435+ return num;
63436+}
63437+
63438+static int
63439+copy_user_allowedips(struct acl_role_label *rolep)
63440+{
63441+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63442+
63443+ ruserip = rolep->allowed_ips;
63444+
63445+ while (ruserip) {
63446+ rlast = rtmp;
63447+
63448+ if ((rtmp = (struct role_allowed_ip *)
63449+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63450+ return -ENOMEM;
63451+
63452+ if (copy_role_allowed_ip(rtmp, ruserip))
63453+ return -EFAULT;
63454+
63455+ ruserip = rtmp->prev;
63456+
63457+ if (!rlast) {
63458+ rtmp->prev = NULL;
63459+ rolep->allowed_ips = rtmp;
63460+ } else {
63461+ rlast->next = rtmp;
63462+ rtmp->prev = rlast;
63463+ }
63464+
63465+ if (!ruserip)
63466+ rtmp->next = NULL;
63467+ }
63468+
63469+ return 0;
63470+}
63471+
63472+static int
63473+copy_user_transitions(struct acl_role_label *rolep)
63474+{
63475+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63476+ int error;
63477+
63478+ rusertp = rolep->transitions;
63479+
63480+ while (rusertp) {
63481+ rlast = rtmp;
63482+
63483+ if ((rtmp = (struct role_transition *)
63484+ acl_alloc(sizeof (struct role_transition))) == NULL)
63485+ return -ENOMEM;
63486+
63487+ if (copy_role_transition(rtmp, rusertp))
63488+ return -EFAULT;
63489+
63490+ rusertp = rtmp->prev;
63491+
63492+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63493+ if (error)
63494+ return error;
63495+
63496+ if (!rlast) {
63497+ rtmp->prev = NULL;
63498+ rolep->transitions = rtmp;
63499+ } else {
63500+ rlast->next = rtmp;
63501+ rtmp->prev = rlast;
63502+ }
63503+
63504+ if (!rusertp)
63505+ rtmp->next = NULL;
63506+ }
63507+
63508+ return 0;
63509+}
63510+
63511+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63512+{
63513+ struct acl_object_label o_tmp;
63514+ __u32 num = 0;
63515+
63516+ while (userp) {
63517+ if (copy_acl_object_label(&o_tmp, userp))
63518+ break;
63519+
63520+ userp = o_tmp.prev;
63521+ num++;
63522+ }
63523+
63524+ return num;
63525+}
63526+
63527+static struct acl_subject_label *
63528+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63529+{
63530+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63531+ __u32 num_objs;
63532+ struct acl_ip_label **i_tmp, *i_utmp2;
63533+ struct gr_hash_struct ghash;
63534+ struct subject_map *subjmap;
63535+ unsigned int i_num;
63536+ int err;
63537+
63538+ if (already_copied != NULL)
63539+ *already_copied = 0;
63540+
63541+ s_tmp = lookup_subject_map(userp);
63542+
63543+ /* we've already copied this subject into the kernel, just return
63544+ the reference to it, and don't copy it over again
63545+ */
63546+ if (s_tmp) {
63547+ if (already_copied != NULL)
63548+ *already_copied = 1;
63549+ return(s_tmp);
63550+ }
63551+
63552+ if ((s_tmp = (struct acl_subject_label *)
63553+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63554+ return ERR_PTR(-ENOMEM);
63555+
63556+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63557+ if (subjmap == NULL)
63558+ return ERR_PTR(-ENOMEM);
63559+
63560+ subjmap->user = userp;
63561+ subjmap->kernel = s_tmp;
63562+ insert_subj_map_entry(subjmap);
63563+
63564+ if (copy_acl_subject_label(s_tmp, userp))
63565+ return ERR_PTR(-EFAULT);
63566+
63567+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63568+ if (err)
63569+ return ERR_PTR(err);
63570+
63571+ if (!strcmp(s_tmp->filename, "/"))
63572+ role->root_label = s_tmp;
63573+
63574+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63575+ return ERR_PTR(-EFAULT);
63576+
63577+ /* copy user and group transition tables */
63578+
63579+ if (s_tmp->user_trans_num) {
63580+ uid_t *uidlist;
63581+
63582+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63583+ if (uidlist == NULL)
63584+ return ERR_PTR(-ENOMEM);
63585+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63586+ return ERR_PTR(-EFAULT);
63587+
63588+ s_tmp->user_transitions = uidlist;
63589+ }
63590+
63591+ if (s_tmp->group_trans_num) {
63592+ gid_t *gidlist;
63593+
63594+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63595+ if (gidlist == NULL)
63596+ return ERR_PTR(-ENOMEM);
63597+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63598+ return ERR_PTR(-EFAULT);
63599+
63600+ s_tmp->group_transitions = gidlist;
63601+ }
63602+
63603+ /* set up object hash table */
63604+ num_objs = count_user_objs(ghash.first);
63605+
63606+ s_tmp->obj_hash_size = num_objs;
63607+ s_tmp->obj_hash =
63608+ (struct acl_object_label **)
63609+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63610+
63611+ if (!s_tmp->obj_hash)
63612+ return ERR_PTR(-ENOMEM);
63613+
63614+ memset(s_tmp->obj_hash, 0,
63615+ s_tmp->obj_hash_size *
63616+ sizeof (struct acl_object_label *));
63617+
63618+ /* add in objects */
63619+ err = copy_user_objs(ghash.first, s_tmp, role);
63620+
63621+ if (err)
63622+ return ERR_PTR(err);
63623+
63624+ /* set pointer for parent subject */
63625+ if (s_tmp->parent_subject) {
63626+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63627+
63628+ if (IS_ERR(s_tmp2))
63629+ return s_tmp2;
63630+
63631+ s_tmp->parent_subject = s_tmp2;
63632+ }
63633+
63634+ /* add in ip acls */
63635+
63636+ if (!s_tmp->ip_num) {
63637+ s_tmp->ips = NULL;
63638+ goto insert;
63639+ }
63640+
63641+ i_tmp =
63642+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63643+ sizeof (struct acl_ip_label *));
63644+
63645+ if (!i_tmp)
63646+ return ERR_PTR(-ENOMEM);
63647+
63648+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63649+ *(i_tmp + i_num) =
63650+ (struct acl_ip_label *)
63651+ acl_alloc(sizeof (struct acl_ip_label));
63652+ if (!*(i_tmp + i_num))
63653+ return ERR_PTR(-ENOMEM);
63654+
63655+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63656+ return ERR_PTR(-EFAULT);
63657+
63658+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63659+ return ERR_PTR(-EFAULT);
63660+
63661+ if ((*(i_tmp + i_num))->iface == NULL)
63662+ continue;
63663+
63664+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63665+ if (err)
63666+ return ERR_PTR(err);
63667+ }
63668+
63669+ s_tmp->ips = i_tmp;
63670+
63671+insert:
63672+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63673+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63674+ return ERR_PTR(-ENOMEM);
63675+
63676+ return s_tmp;
63677+}
63678+
63679+static int
63680+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63681+{
63682+ struct acl_subject_label s_pre;
63683+ struct acl_subject_label * ret;
63684+ int err;
63685+
63686+ while (userp) {
63687+ if (copy_acl_subject_label(&s_pre, userp))
63688+ return -EFAULT;
63689+
63690+ ret = do_copy_user_subj(userp, role, NULL);
63691+
63692+ err = PTR_ERR(ret);
63693+ if (IS_ERR(ret))
63694+ return err;
63695+
63696+ insert_acl_subj_label(ret, role);
63697+
63698+ userp = s_pre.prev;
63699+ }
63700+
63701+ return 0;
63702+}
63703+
63704+static int
63705+copy_user_acl(struct gr_arg *arg)
63706+{
63707+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63708+ struct acl_subject_label *subj_list;
63709+ struct sprole_pw *sptmp;
63710+ struct gr_hash_struct *ghash;
63711+ uid_t *domainlist;
63712+ unsigned int r_num;
63713+ int err = 0;
63714+ __u16 i;
63715+ __u32 num_subjs;
63716+
63717+ /* we need a default and kernel role */
63718+ if (arg->role_db.num_roles < 2)
63719+ return -EINVAL;
63720+
63721+ /* copy special role authentication info from userspace */
63722+
63723+ num_sprole_pws = arg->num_sprole_pws;
63724+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63725+
63726+ if (!acl_special_roles && num_sprole_pws)
63727+ return -ENOMEM;
63728+
63729+ for (i = 0; i < num_sprole_pws; i++) {
63730+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63731+ if (!sptmp)
63732+ return -ENOMEM;
63733+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63734+ return -EFAULT;
63735+
63736+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63737+ if (err)
63738+ return err;
63739+
63740+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63741+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63742+#endif
63743+
63744+ acl_special_roles[i] = sptmp;
63745+ }
63746+
63747+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63748+
63749+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63750+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63751+
63752+ if (!r_tmp)
63753+ return -ENOMEM;
63754+
63755+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63756+ return -EFAULT;
63757+
63758+ if (copy_acl_role_label(r_tmp, r_utmp2))
63759+ return -EFAULT;
63760+
63761+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63762+ if (err)
63763+ return err;
63764+
63765+ if (!strcmp(r_tmp->rolename, "default")
63766+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63767+ default_role = r_tmp;
63768+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63769+ kernel_role = r_tmp;
63770+ }
63771+
63772+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63773+ return -ENOMEM;
63774+
63775+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63776+ return -EFAULT;
63777+
63778+ r_tmp->hash = ghash;
63779+
63780+ num_subjs = count_user_subjs(r_tmp->hash->first);
63781+
63782+ r_tmp->subj_hash_size = num_subjs;
63783+ r_tmp->subj_hash =
63784+ (struct acl_subject_label **)
63785+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63786+
63787+ if (!r_tmp->subj_hash)
63788+ return -ENOMEM;
63789+
63790+ err = copy_user_allowedips(r_tmp);
63791+ if (err)
63792+ return err;
63793+
63794+ /* copy domain info */
63795+ if (r_tmp->domain_children != NULL) {
63796+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63797+ if (domainlist == NULL)
63798+ return -ENOMEM;
63799+
63800+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63801+ return -EFAULT;
63802+
63803+ r_tmp->domain_children = domainlist;
63804+ }
63805+
63806+ err = copy_user_transitions(r_tmp);
63807+ if (err)
63808+ return err;
63809+
63810+ memset(r_tmp->subj_hash, 0,
63811+ r_tmp->subj_hash_size *
63812+ sizeof (struct acl_subject_label *));
63813+
63814+ /* acquire the list of subjects, then NULL out
63815+ the list prior to parsing the subjects for this role,
63816+ as during this parsing the list is replaced with a list
63817+ of *nested* subjects for the role
63818+ */
63819+ subj_list = r_tmp->hash->first;
63820+
63821+ /* set nested subject list to null */
63822+ r_tmp->hash->first = NULL;
63823+
63824+ err = copy_user_subjs(subj_list, r_tmp);
63825+
63826+ if (err)
63827+ return err;
63828+
63829+ insert_acl_role_label(r_tmp);
63830+ }
63831+
63832+ if (default_role == NULL || kernel_role == NULL)
63833+ return -EINVAL;
63834+
63835+ return err;
63836+}
63837+
63838+static int
63839+gracl_init(struct gr_arg *args)
63840+{
63841+ int error = 0;
63842+
63843+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63844+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63845+
63846+ if (init_variables(args)) {
63847+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63848+ error = -ENOMEM;
63849+ free_variables();
63850+ goto out;
63851+ }
63852+
63853+ error = copy_user_acl(args);
63854+ free_init_variables();
63855+ if (error) {
63856+ free_variables();
63857+ goto out;
63858+ }
63859+
63860+ if ((error = gr_set_acls(0))) {
63861+ free_variables();
63862+ goto out;
63863+ }
63864+
63865+ pax_open_kernel();
63866+ gr_status |= GR_READY;
63867+ pax_close_kernel();
63868+
63869+ out:
63870+ return error;
63871+}
63872+
63873+/* derived from glibc fnmatch() 0: match, 1: no match*/
63874+
63875+static int
63876+glob_match(const char *p, const char *n)
63877+{
63878+ char c;
63879+
63880+ while ((c = *p++) != '\0') {
63881+ switch (c) {
63882+ case '?':
63883+ if (*n == '\0')
63884+ return 1;
63885+ else if (*n == '/')
63886+ return 1;
63887+ break;
63888+ case '\\':
63889+ if (*n != c)
63890+ return 1;
63891+ break;
63892+ case '*':
63893+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63894+ if (*n == '/')
63895+ return 1;
63896+ else if (c == '?') {
63897+ if (*n == '\0')
63898+ return 1;
63899+ else
63900+ ++n;
63901+ }
63902+ }
63903+ if (c == '\0') {
63904+ return 0;
63905+ } else {
63906+ const char *endp;
63907+
63908+ if ((endp = strchr(n, '/')) == NULL)
63909+ endp = n + strlen(n);
63910+
63911+ if (c == '[') {
63912+ for (--p; n < endp; ++n)
63913+ if (!glob_match(p, n))
63914+ return 0;
63915+ } else if (c == '/') {
63916+ while (*n != '\0' && *n != '/')
63917+ ++n;
63918+ if (*n == '/' && !glob_match(p, n + 1))
63919+ return 0;
63920+ } else {
63921+ for (--p; n < endp; ++n)
63922+ if (*n == c && !glob_match(p, n))
63923+ return 0;
63924+ }
63925+
63926+ return 1;
63927+ }
63928+ case '[':
63929+ {
63930+ int not;
63931+ char cold;
63932+
63933+ if (*n == '\0' || *n == '/')
63934+ return 1;
63935+
63936+ not = (*p == '!' || *p == '^');
63937+ if (not)
63938+ ++p;
63939+
63940+ c = *p++;
63941+ for (;;) {
63942+ unsigned char fn = (unsigned char)*n;
63943+
63944+ if (c == '\0')
63945+ return 1;
63946+ else {
63947+ if (c == fn)
63948+ goto matched;
63949+ cold = c;
63950+ c = *p++;
63951+
63952+ if (c == '-' && *p != ']') {
63953+ unsigned char cend = *p++;
63954+
63955+ if (cend == '\0')
63956+ return 1;
63957+
63958+ if (cold <= fn && fn <= cend)
63959+ goto matched;
63960+
63961+ c = *p++;
63962+ }
63963+ }
63964+
63965+ if (c == ']')
63966+ break;
63967+ }
63968+ if (!not)
63969+ return 1;
63970+ break;
63971+ matched:
63972+ while (c != ']') {
63973+ if (c == '\0')
63974+ return 1;
63975+
63976+ c = *p++;
63977+ }
63978+ if (not)
63979+ return 1;
63980+ }
63981+ break;
63982+ default:
63983+ if (c != *n)
63984+ return 1;
63985+ }
63986+
63987+ ++n;
63988+ }
63989+
63990+ if (*n == '\0')
63991+ return 0;
63992+
63993+ if (*n == '/')
63994+ return 0;
63995+
63996+ return 1;
63997+}
63998+
63999+static struct acl_object_label *
64000+chk_glob_label(struct acl_object_label *globbed,
64001+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64002+{
64003+ struct acl_object_label *tmp;
64004+
64005+ if (*path == NULL)
64006+ *path = gr_to_filename_nolock(dentry, mnt);
64007+
64008+ tmp = globbed;
64009+
64010+ while (tmp) {
64011+ if (!glob_match(tmp->filename, *path))
64012+ return tmp;
64013+ tmp = tmp->next;
64014+ }
64015+
64016+ return NULL;
64017+}
64018+
64019+static struct acl_object_label *
64020+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64021+ const ino_t curr_ino, const dev_t curr_dev,
64022+ const struct acl_subject_label *subj, char **path, const int checkglob)
64023+{
64024+ struct acl_subject_label *tmpsubj;
64025+ struct acl_object_label *retval;
64026+ struct acl_object_label *retval2;
64027+
64028+ tmpsubj = (struct acl_subject_label *) subj;
64029+ read_lock(&gr_inode_lock);
64030+ do {
64031+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64032+ if (retval) {
64033+ if (checkglob && retval->globbed) {
64034+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64035+ if (retval2)
64036+ retval = retval2;
64037+ }
64038+ break;
64039+ }
64040+ } while ((tmpsubj = tmpsubj->parent_subject));
64041+ read_unlock(&gr_inode_lock);
64042+
64043+ return retval;
64044+}
64045+
64046+static __inline__ struct acl_object_label *
64047+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64048+ struct dentry *curr_dentry,
64049+ const struct acl_subject_label *subj, char **path, const int checkglob)
64050+{
64051+ int newglob = checkglob;
64052+ ino_t inode;
64053+ dev_t device;
64054+
64055+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64056+ as we don't want a / * rule to match instead of the / object
64057+ don't do this for create lookups that call this function though, since they're looking up
64058+ on the parent and thus need globbing checks on all paths
64059+ */
64060+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64061+ newglob = GR_NO_GLOB;
64062+
64063+ spin_lock(&curr_dentry->d_lock);
64064+ inode = curr_dentry->d_inode->i_ino;
64065+ device = __get_dev(curr_dentry);
64066+ spin_unlock(&curr_dentry->d_lock);
64067+
64068+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64069+}
64070+
64071+#ifdef CONFIG_HUGETLBFS
64072+static inline bool
64073+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64074+{
64075+ int i;
64076+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64077+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64078+ return true;
64079+ }
64080+
64081+ return false;
64082+}
64083+#endif
64084+
64085+static struct acl_object_label *
64086+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64087+ const struct acl_subject_label *subj, char *path, const int checkglob)
64088+{
64089+ struct dentry *dentry = (struct dentry *) l_dentry;
64090+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64091+ struct mount *real_mnt = real_mount(mnt);
64092+ struct acl_object_label *retval;
64093+ struct dentry *parent;
64094+
64095+ br_read_lock(&vfsmount_lock);
64096+ write_seqlock(&rename_lock);
64097+
64098+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64099+#ifdef CONFIG_NET
64100+ mnt == sock_mnt ||
64101+#endif
64102+#ifdef CONFIG_HUGETLBFS
64103+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64104+#endif
64105+ /* ignore Eric Biederman */
64106+ IS_PRIVATE(l_dentry->d_inode))) {
64107+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64108+ goto out;
64109+ }
64110+
64111+ for (;;) {
64112+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64113+ break;
64114+
64115+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64116+ if (!mnt_has_parent(real_mnt))
64117+ break;
64118+
64119+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64120+ if (retval != NULL)
64121+ goto out;
64122+
64123+ dentry = real_mnt->mnt_mountpoint;
64124+ real_mnt = real_mnt->mnt_parent;
64125+ mnt = &real_mnt->mnt;
64126+ continue;
64127+ }
64128+
64129+ parent = dentry->d_parent;
64130+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64131+ if (retval != NULL)
64132+ goto out;
64133+
64134+ dentry = parent;
64135+ }
64136+
64137+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64138+
64139+ /* real_root is pinned so we don't have to hold a reference */
64140+ if (retval == NULL)
64141+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64142+out:
64143+ write_sequnlock(&rename_lock);
64144+ br_read_unlock(&vfsmount_lock);
64145+
64146+ BUG_ON(retval == NULL);
64147+
64148+ return retval;
64149+}
64150+
64151+static __inline__ struct acl_object_label *
64152+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64153+ const struct acl_subject_label *subj)
64154+{
64155+ char *path = NULL;
64156+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64157+}
64158+
64159+static __inline__ struct acl_object_label *
64160+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64161+ const struct acl_subject_label *subj)
64162+{
64163+ char *path = NULL;
64164+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64165+}
64166+
64167+static __inline__ struct acl_object_label *
64168+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64169+ const struct acl_subject_label *subj, char *path)
64170+{
64171+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64172+}
64173+
64174+static struct acl_subject_label *
64175+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64176+ const struct acl_role_label *role)
64177+{
64178+ struct dentry *dentry = (struct dentry *) l_dentry;
64179+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64180+ struct mount *real_mnt = real_mount(mnt);
64181+ struct acl_subject_label *retval;
64182+ struct dentry *parent;
64183+
64184+ br_read_lock(&vfsmount_lock);
64185+ write_seqlock(&rename_lock);
64186+
64187+ for (;;) {
64188+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64189+ break;
64190+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64191+ if (!mnt_has_parent(real_mnt))
64192+ break;
64193+
64194+ spin_lock(&dentry->d_lock);
64195+ read_lock(&gr_inode_lock);
64196+ retval =
64197+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64198+ __get_dev(dentry), role);
64199+ read_unlock(&gr_inode_lock);
64200+ spin_unlock(&dentry->d_lock);
64201+ if (retval != NULL)
64202+ goto out;
64203+
64204+ dentry = real_mnt->mnt_mountpoint;
64205+ real_mnt = real_mnt->mnt_parent;
64206+ mnt = &real_mnt->mnt;
64207+ continue;
64208+ }
64209+
64210+ spin_lock(&dentry->d_lock);
64211+ read_lock(&gr_inode_lock);
64212+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64213+ __get_dev(dentry), role);
64214+ read_unlock(&gr_inode_lock);
64215+ parent = dentry->d_parent;
64216+ spin_unlock(&dentry->d_lock);
64217+
64218+ if (retval != NULL)
64219+ goto out;
64220+
64221+ dentry = parent;
64222+ }
64223+
64224+ spin_lock(&dentry->d_lock);
64225+ read_lock(&gr_inode_lock);
64226+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64227+ __get_dev(dentry), role);
64228+ read_unlock(&gr_inode_lock);
64229+ spin_unlock(&dentry->d_lock);
64230+
64231+ if (unlikely(retval == NULL)) {
64232+ /* real_root is pinned, we don't need to hold a reference */
64233+ read_lock(&gr_inode_lock);
64234+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64235+ __get_dev(real_root.dentry), role);
64236+ read_unlock(&gr_inode_lock);
64237+ }
64238+out:
64239+ write_sequnlock(&rename_lock);
64240+ br_read_unlock(&vfsmount_lock);
64241+
64242+ BUG_ON(retval == NULL);
64243+
64244+ return retval;
64245+}
64246+
64247+static void
64248+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64249+{
64250+ struct task_struct *task = current;
64251+ const struct cred *cred = current_cred();
64252+
64253+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64254+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64255+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64256+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64257+
64258+ return;
64259+}
64260+
64261+static void
64262+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64263+{
64264+ struct task_struct *task = current;
64265+ const struct cred *cred = current_cred();
64266+
64267+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64268+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64269+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64270+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64271+
64272+ return;
64273+}
64274+
64275+static void
64276+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64277+{
64278+ struct task_struct *task = current;
64279+ const struct cred *cred = current_cred();
64280+
64281+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64282+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64283+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64284+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64285+
64286+ return;
64287+}
64288+
64289+__u32
64290+gr_search_file(const struct dentry * dentry, const __u32 mode,
64291+ const struct vfsmount * mnt)
64292+{
64293+ __u32 retval = mode;
64294+ struct acl_subject_label *curracl;
64295+ struct acl_object_label *currobj;
64296+
64297+ if (unlikely(!(gr_status & GR_READY)))
64298+ return (mode & ~GR_AUDITS);
64299+
64300+ curracl = current->acl;
64301+
64302+ currobj = chk_obj_label(dentry, mnt, curracl);
64303+ retval = currobj->mode & mode;
64304+
64305+ /* if we're opening a specified transfer file for writing
64306+ (e.g. /dev/initctl), then transfer our role to init
64307+ */
64308+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64309+ current->role->roletype & GR_ROLE_PERSIST)) {
64310+ struct task_struct *task = init_pid_ns.child_reaper;
64311+
64312+ if (task->role != current->role) {
64313+ task->acl_sp_role = 0;
64314+ task->acl_role_id = current->acl_role_id;
64315+ task->role = current->role;
64316+ rcu_read_lock();
64317+ read_lock(&grsec_exec_file_lock);
64318+ gr_apply_subject_to_task(task);
64319+ read_unlock(&grsec_exec_file_lock);
64320+ rcu_read_unlock();
64321+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64322+ }
64323+ }
64324+
64325+ if (unlikely
64326+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64327+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64328+ __u32 new_mode = mode;
64329+
64330+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64331+
64332+ retval = new_mode;
64333+
64334+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64335+ new_mode |= GR_INHERIT;
64336+
64337+ if (!(mode & GR_NOLEARN))
64338+ gr_log_learn(dentry, mnt, new_mode);
64339+ }
64340+
64341+ return retval;
64342+}
64343+
64344+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64345+ const struct dentry *parent,
64346+ const struct vfsmount *mnt)
64347+{
64348+ struct name_entry *match;
64349+ struct acl_object_label *matchpo;
64350+ struct acl_subject_label *curracl;
64351+ char *path;
64352+
64353+ if (unlikely(!(gr_status & GR_READY)))
64354+ return NULL;
64355+
64356+ preempt_disable();
64357+ path = gr_to_filename_rbac(new_dentry, mnt);
64358+ match = lookup_name_entry_create(path);
64359+
64360+ curracl = current->acl;
64361+
64362+ if (match) {
64363+ read_lock(&gr_inode_lock);
64364+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64365+ read_unlock(&gr_inode_lock);
64366+
64367+ if (matchpo) {
64368+ preempt_enable();
64369+ return matchpo;
64370+ }
64371+ }
64372+
64373+ // lookup parent
64374+
64375+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64376+
64377+ preempt_enable();
64378+ return matchpo;
64379+}
64380+
64381+__u32
64382+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64383+ const struct vfsmount * mnt, const __u32 mode)
64384+{
64385+ struct acl_object_label *matchpo;
64386+ __u32 retval;
64387+
64388+ if (unlikely(!(gr_status & GR_READY)))
64389+ return (mode & ~GR_AUDITS);
64390+
64391+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64392+
64393+ retval = matchpo->mode & mode;
64394+
64395+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64396+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64397+ __u32 new_mode = mode;
64398+
64399+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64400+
64401+ gr_log_learn(new_dentry, mnt, new_mode);
64402+ return new_mode;
64403+ }
64404+
64405+ return retval;
64406+}
64407+
64408+__u32
64409+gr_check_link(const struct dentry * new_dentry,
64410+ const struct dentry * parent_dentry,
64411+ const struct vfsmount * parent_mnt,
64412+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64413+{
64414+ struct acl_object_label *obj;
64415+ __u32 oldmode, newmode;
64416+ __u32 needmode;
64417+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64418+ GR_DELETE | GR_INHERIT;
64419+
64420+ if (unlikely(!(gr_status & GR_READY)))
64421+ return (GR_CREATE | GR_LINK);
64422+
64423+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64424+ oldmode = obj->mode;
64425+
64426+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64427+ newmode = obj->mode;
64428+
64429+ needmode = newmode & checkmodes;
64430+
64431+ // old name for hardlink must have at least the permissions of the new name
64432+ if ((oldmode & needmode) != needmode)
64433+ goto bad;
64434+
64435+ // if old name had restrictions/auditing, make sure the new name does as well
64436+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64437+
64438+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64439+ if (is_privileged_binary(old_dentry))
64440+ needmode |= GR_SETID;
64441+
64442+ if ((newmode & needmode) != needmode)
64443+ goto bad;
64444+
64445+ // enforce minimum permissions
64446+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64447+ return newmode;
64448+bad:
64449+ needmode = oldmode;
64450+ if (is_privileged_binary(old_dentry))
64451+ needmode |= GR_SETID;
64452+
64453+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64454+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64455+ return (GR_CREATE | GR_LINK);
64456+ } else if (newmode & GR_SUPPRESS)
64457+ return GR_SUPPRESS;
64458+ else
64459+ return 0;
64460+}
64461+
64462+int
64463+gr_check_hidden_task(const struct task_struct *task)
64464+{
64465+ if (unlikely(!(gr_status & GR_READY)))
64466+ return 0;
64467+
64468+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64469+ return 1;
64470+
64471+ return 0;
64472+}
64473+
64474+int
64475+gr_check_protected_task(const struct task_struct *task)
64476+{
64477+ if (unlikely(!(gr_status & GR_READY) || !task))
64478+ return 0;
64479+
64480+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64481+ task->acl != current->acl)
64482+ return 1;
64483+
64484+ return 0;
64485+}
64486+
64487+int
64488+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64489+{
64490+ struct task_struct *p;
64491+ int ret = 0;
64492+
64493+ if (unlikely(!(gr_status & GR_READY) || !pid))
64494+ return ret;
64495+
64496+ read_lock(&tasklist_lock);
64497+ do_each_pid_task(pid, type, p) {
64498+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64499+ p->acl != current->acl) {
64500+ ret = 1;
64501+ goto out;
64502+ }
64503+ } while_each_pid_task(pid, type, p);
64504+out:
64505+ read_unlock(&tasklist_lock);
64506+
64507+ return ret;
64508+}
64509+
64510+void
64511+gr_copy_label(struct task_struct *tsk)
64512+{
64513+ tsk->signal->used_accept = 0;
64514+ tsk->acl_sp_role = 0;
64515+ tsk->acl_role_id = current->acl_role_id;
64516+ tsk->acl = current->acl;
64517+ tsk->role = current->role;
64518+ tsk->signal->curr_ip = current->signal->curr_ip;
64519+ tsk->signal->saved_ip = current->signal->saved_ip;
64520+ if (current->exec_file)
64521+ get_file(current->exec_file);
64522+ tsk->exec_file = current->exec_file;
64523+ tsk->is_writable = current->is_writable;
64524+ if (unlikely(current->signal->used_accept)) {
64525+ current->signal->curr_ip = 0;
64526+ current->signal->saved_ip = 0;
64527+ }
64528+
64529+ return;
64530+}
64531+
64532+static void
64533+gr_set_proc_res(struct task_struct *task)
64534+{
64535+ struct acl_subject_label *proc;
64536+ unsigned short i;
64537+
64538+ proc = task->acl;
64539+
64540+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64541+ return;
64542+
64543+ for (i = 0; i < RLIM_NLIMITS; i++) {
64544+ if (!(proc->resmask & (1U << i)))
64545+ continue;
64546+
64547+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64548+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64549+
64550+ if (i == RLIMIT_CPU)
64551+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64552+ }
64553+
64554+ return;
64555+}
64556+
64557+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64558+
64559+int
64560+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64561+{
64562+ unsigned int i;
64563+ __u16 num;
64564+ uid_t *uidlist;
64565+ uid_t curuid;
64566+ int realok = 0;
64567+ int effectiveok = 0;
64568+ int fsok = 0;
64569+ uid_t globalreal, globaleffective, globalfs;
64570+
64571+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64572+ struct user_struct *user;
64573+
64574+ if (!uid_valid(real))
64575+ goto skipit;
64576+
64577+ /* find user based on global namespace */
64578+
64579+ globalreal = GR_GLOBAL_UID(real);
64580+
64581+ user = find_user(make_kuid(&init_user_ns, globalreal));
64582+ if (user == NULL)
64583+ goto skipit;
64584+
64585+ if (gr_process_kernel_setuid_ban(user)) {
64586+ /* for find_user */
64587+ free_uid(user);
64588+ return 1;
64589+ }
64590+
64591+ /* for find_user */
64592+ free_uid(user);
64593+
64594+skipit:
64595+#endif
64596+
64597+ if (unlikely(!(gr_status & GR_READY)))
64598+ return 0;
64599+
64600+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64601+ gr_log_learn_uid_change(real, effective, fs);
64602+
64603+ num = current->acl->user_trans_num;
64604+ uidlist = current->acl->user_transitions;
64605+
64606+ if (uidlist == NULL)
64607+ return 0;
64608+
64609+ if (!uid_valid(real)) {
64610+ realok = 1;
64611+ globalreal = (uid_t)-1;
64612+ } else {
64613+ globalreal = GR_GLOBAL_UID(real);
64614+ }
64615+ if (!uid_valid(effective)) {
64616+ effectiveok = 1;
64617+ globaleffective = (uid_t)-1;
64618+ } else {
64619+ globaleffective = GR_GLOBAL_UID(effective);
64620+ }
64621+ if (!uid_valid(fs)) {
64622+ fsok = 1;
64623+ globalfs = (uid_t)-1;
64624+ } else {
64625+ globalfs = GR_GLOBAL_UID(fs);
64626+ }
64627+
64628+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64629+ for (i = 0; i < num; i++) {
64630+ curuid = uidlist[i];
64631+ if (globalreal == curuid)
64632+ realok = 1;
64633+ if (globaleffective == curuid)
64634+ effectiveok = 1;
64635+ if (globalfs == curuid)
64636+ fsok = 1;
64637+ }
64638+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64639+ for (i = 0; i < num; i++) {
64640+ curuid = uidlist[i];
64641+ if (globalreal == curuid)
64642+ break;
64643+ if (globaleffective == curuid)
64644+ break;
64645+ if (globalfs == curuid)
64646+ break;
64647+ }
64648+ /* not in deny list */
64649+ if (i == num) {
64650+ realok = 1;
64651+ effectiveok = 1;
64652+ fsok = 1;
64653+ }
64654+ }
64655+
64656+ if (realok && effectiveok && fsok)
64657+ return 0;
64658+ else {
64659+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64660+ return 1;
64661+ }
64662+}
64663+
64664+int
64665+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64666+{
64667+ unsigned int i;
64668+ __u16 num;
64669+ gid_t *gidlist;
64670+ gid_t curgid;
64671+ int realok = 0;
64672+ int effectiveok = 0;
64673+ int fsok = 0;
64674+ gid_t globalreal, globaleffective, globalfs;
64675+
64676+ if (unlikely(!(gr_status & GR_READY)))
64677+ return 0;
64678+
64679+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64680+ gr_log_learn_gid_change(real, effective, fs);
64681+
64682+ num = current->acl->group_trans_num;
64683+ gidlist = current->acl->group_transitions;
64684+
64685+ if (gidlist == NULL)
64686+ return 0;
64687+
64688+ if (!gid_valid(real)) {
64689+ realok = 1;
64690+ globalreal = (gid_t)-1;
64691+ } else {
64692+ globalreal = GR_GLOBAL_GID(real);
64693+ }
64694+ if (!gid_valid(effective)) {
64695+ effectiveok = 1;
64696+ globaleffective = (gid_t)-1;
64697+ } else {
64698+ globaleffective = GR_GLOBAL_GID(effective);
64699+ }
64700+ if (!gid_valid(fs)) {
64701+ fsok = 1;
64702+ globalfs = (gid_t)-1;
64703+ } else {
64704+ globalfs = GR_GLOBAL_GID(fs);
64705+ }
64706+
64707+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64708+ for (i = 0; i < num; i++) {
64709+ curgid = gidlist[i];
64710+ if (globalreal == curgid)
64711+ realok = 1;
64712+ if (globaleffective == curgid)
64713+ effectiveok = 1;
64714+ if (globalfs == curgid)
64715+ fsok = 1;
64716+ }
64717+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64718+ for (i = 0; i < num; i++) {
64719+ curgid = gidlist[i];
64720+ if (globalreal == curgid)
64721+ break;
64722+ if (globaleffective == curgid)
64723+ break;
64724+ if (globalfs == curgid)
64725+ break;
64726+ }
64727+ /* not in deny list */
64728+ if (i == num) {
64729+ realok = 1;
64730+ effectiveok = 1;
64731+ fsok = 1;
64732+ }
64733+ }
64734+
64735+ if (realok && effectiveok && fsok)
64736+ return 0;
64737+ else {
64738+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64739+ return 1;
64740+ }
64741+}
64742+
64743+extern int gr_acl_is_capable(const int cap);
64744+
64745+void
64746+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64747+{
64748+ struct acl_role_label *role = task->role;
64749+ struct acl_subject_label *subj = NULL;
64750+ struct acl_object_label *obj;
64751+ struct file *filp;
64752+ uid_t uid;
64753+ gid_t gid;
64754+
64755+ if (unlikely(!(gr_status & GR_READY)))
64756+ return;
64757+
64758+ uid = GR_GLOBAL_UID(kuid);
64759+ gid = GR_GLOBAL_GID(kgid);
64760+
64761+ filp = task->exec_file;
64762+
64763+ /* kernel process, we'll give them the kernel role */
64764+ if (unlikely(!filp)) {
64765+ task->role = kernel_role;
64766+ task->acl = kernel_role->root_label;
64767+ return;
64768+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64769+ role = lookup_acl_role_label(task, uid, gid);
64770+
64771+ /* don't change the role if we're not a privileged process */
64772+ if (role && task->role != role &&
64773+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64774+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64775+ return;
64776+
64777+ /* perform subject lookup in possibly new role
64778+ we can use this result below in the case where role == task->role
64779+ */
64780+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64781+
64782+ /* if we changed uid/gid, but result in the same role
64783+ and are using inheritance, don't lose the inherited subject
64784+ if current subject is other than what normal lookup
64785+ would result in, we arrived via inheritance, don't
64786+ lose subject
64787+ */
64788+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64789+ (subj == task->acl)))
64790+ task->acl = subj;
64791+
64792+ task->role = role;
64793+
64794+ task->is_writable = 0;
64795+
64796+ /* ignore additional mmap checks for processes that are writable
64797+ by the default ACL */
64798+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64799+ if (unlikely(obj->mode & GR_WRITE))
64800+ task->is_writable = 1;
64801+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64802+ if (unlikely(obj->mode & GR_WRITE))
64803+ task->is_writable = 1;
64804+
64805+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64806+ 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);
64807+#endif
64808+
64809+ gr_set_proc_res(task);
64810+
64811+ return;
64812+}
64813+
64814+int
64815+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64816+ const int unsafe_flags)
64817+{
64818+ struct task_struct *task = current;
64819+ struct acl_subject_label *newacl;
64820+ struct acl_object_label *obj;
64821+ __u32 retmode;
64822+
64823+ if (unlikely(!(gr_status & GR_READY)))
64824+ return 0;
64825+
64826+ newacl = chk_subj_label(dentry, mnt, task->role);
64827+
64828+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64829+ did an exec
64830+ */
64831+ rcu_read_lock();
64832+ read_lock(&tasklist_lock);
64833+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64834+ (task->parent->acl->mode & GR_POVERRIDE))) {
64835+ read_unlock(&tasklist_lock);
64836+ rcu_read_unlock();
64837+ goto skip_check;
64838+ }
64839+ read_unlock(&tasklist_lock);
64840+ rcu_read_unlock();
64841+
64842+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64843+ !(task->role->roletype & GR_ROLE_GOD) &&
64844+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64845+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64846+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64847+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64848+ else
64849+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64850+ return -EACCES;
64851+ }
64852+
64853+skip_check:
64854+
64855+ obj = chk_obj_label(dentry, mnt, task->acl);
64856+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64857+
64858+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64859+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64860+ if (obj->nested)
64861+ task->acl = obj->nested;
64862+ else
64863+ task->acl = newacl;
64864+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64865+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64866+
64867+ task->is_writable = 0;
64868+
64869+ /* ignore additional mmap checks for processes that are writable
64870+ by the default ACL */
64871+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64872+ if (unlikely(obj->mode & GR_WRITE))
64873+ task->is_writable = 1;
64874+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64875+ if (unlikely(obj->mode & GR_WRITE))
64876+ task->is_writable = 1;
64877+
64878+ gr_set_proc_res(task);
64879+
64880+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64881+ 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);
64882+#endif
64883+ return 0;
64884+}
64885+
64886+/* always called with valid inodev ptr */
64887+static void
64888+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64889+{
64890+ struct acl_object_label *matchpo;
64891+ struct acl_subject_label *matchps;
64892+ struct acl_subject_label *subj;
64893+ struct acl_role_label *role;
64894+ unsigned int x;
64895+
64896+ FOR_EACH_ROLE_START(role)
64897+ FOR_EACH_SUBJECT_START(role, subj, x)
64898+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64899+ matchpo->mode |= GR_DELETED;
64900+ FOR_EACH_SUBJECT_END(subj,x)
64901+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64902+ /* nested subjects aren't in the role's subj_hash table */
64903+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64904+ matchpo->mode |= GR_DELETED;
64905+ FOR_EACH_NESTED_SUBJECT_END(subj)
64906+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64907+ matchps->mode |= GR_DELETED;
64908+ FOR_EACH_ROLE_END(role)
64909+
64910+ inodev->nentry->deleted = 1;
64911+
64912+ return;
64913+}
64914+
64915+void
64916+gr_handle_delete(const ino_t ino, const dev_t dev)
64917+{
64918+ struct inodev_entry *inodev;
64919+
64920+ if (unlikely(!(gr_status & GR_READY)))
64921+ return;
64922+
64923+ write_lock(&gr_inode_lock);
64924+ inodev = lookup_inodev_entry(ino, dev);
64925+ if (inodev != NULL)
64926+ do_handle_delete(inodev, ino, dev);
64927+ write_unlock(&gr_inode_lock);
64928+
64929+ return;
64930+}
64931+
64932+static void
64933+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64934+ const ino_t newinode, const dev_t newdevice,
64935+ struct acl_subject_label *subj)
64936+{
64937+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64938+ struct acl_object_label *match;
64939+
64940+ match = subj->obj_hash[index];
64941+
64942+ while (match && (match->inode != oldinode ||
64943+ match->device != olddevice ||
64944+ !(match->mode & GR_DELETED)))
64945+ match = match->next;
64946+
64947+ if (match && (match->inode == oldinode)
64948+ && (match->device == olddevice)
64949+ && (match->mode & GR_DELETED)) {
64950+ if (match->prev == NULL) {
64951+ subj->obj_hash[index] = match->next;
64952+ if (match->next != NULL)
64953+ match->next->prev = NULL;
64954+ } else {
64955+ match->prev->next = match->next;
64956+ if (match->next != NULL)
64957+ match->next->prev = match->prev;
64958+ }
64959+ match->prev = NULL;
64960+ match->next = NULL;
64961+ match->inode = newinode;
64962+ match->device = newdevice;
64963+ match->mode &= ~GR_DELETED;
64964+
64965+ insert_acl_obj_label(match, subj);
64966+ }
64967+
64968+ return;
64969+}
64970+
64971+static void
64972+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64973+ const ino_t newinode, const dev_t newdevice,
64974+ struct acl_role_label *role)
64975+{
64976+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64977+ struct acl_subject_label *match;
64978+
64979+ match = role->subj_hash[index];
64980+
64981+ while (match && (match->inode != oldinode ||
64982+ match->device != olddevice ||
64983+ !(match->mode & GR_DELETED)))
64984+ match = match->next;
64985+
64986+ if (match && (match->inode == oldinode)
64987+ && (match->device == olddevice)
64988+ && (match->mode & GR_DELETED)) {
64989+ if (match->prev == NULL) {
64990+ role->subj_hash[index] = match->next;
64991+ if (match->next != NULL)
64992+ match->next->prev = NULL;
64993+ } else {
64994+ match->prev->next = match->next;
64995+ if (match->next != NULL)
64996+ match->next->prev = match->prev;
64997+ }
64998+ match->prev = NULL;
64999+ match->next = NULL;
65000+ match->inode = newinode;
65001+ match->device = newdevice;
65002+ match->mode &= ~GR_DELETED;
65003+
65004+ insert_acl_subj_label(match, role);
65005+ }
65006+
65007+ return;
65008+}
65009+
65010+static void
65011+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65012+ const ino_t newinode, const dev_t newdevice)
65013+{
65014+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65015+ struct inodev_entry *match;
65016+
65017+ match = inodev_set.i_hash[index];
65018+
65019+ while (match && (match->nentry->inode != oldinode ||
65020+ match->nentry->device != olddevice || !match->nentry->deleted))
65021+ match = match->next;
65022+
65023+ if (match && (match->nentry->inode == oldinode)
65024+ && (match->nentry->device == olddevice) &&
65025+ match->nentry->deleted) {
65026+ if (match->prev == NULL) {
65027+ inodev_set.i_hash[index] = match->next;
65028+ if (match->next != NULL)
65029+ match->next->prev = NULL;
65030+ } else {
65031+ match->prev->next = match->next;
65032+ if (match->next != NULL)
65033+ match->next->prev = match->prev;
65034+ }
65035+ match->prev = NULL;
65036+ match->next = NULL;
65037+ match->nentry->inode = newinode;
65038+ match->nentry->device = newdevice;
65039+ match->nentry->deleted = 0;
65040+
65041+ insert_inodev_entry(match);
65042+ }
65043+
65044+ return;
65045+}
65046+
65047+static void
65048+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65049+{
65050+ struct acl_subject_label *subj;
65051+ struct acl_role_label *role;
65052+ unsigned int x;
65053+
65054+ FOR_EACH_ROLE_START(role)
65055+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65056+
65057+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65058+ if ((subj->inode == ino) && (subj->device == dev)) {
65059+ subj->inode = ino;
65060+ subj->device = dev;
65061+ }
65062+ /* nested subjects aren't in the role's subj_hash table */
65063+ update_acl_obj_label(matchn->inode, matchn->device,
65064+ ino, dev, subj);
65065+ FOR_EACH_NESTED_SUBJECT_END(subj)
65066+ FOR_EACH_SUBJECT_START(role, subj, x)
65067+ update_acl_obj_label(matchn->inode, matchn->device,
65068+ ino, dev, subj);
65069+ FOR_EACH_SUBJECT_END(subj,x)
65070+ FOR_EACH_ROLE_END(role)
65071+
65072+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65073+
65074+ return;
65075+}
65076+
65077+static void
65078+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65079+ const struct vfsmount *mnt)
65080+{
65081+ ino_t ino = dentry->d_inode->i_ino;
65082+ dev_t dev = __get_dev(dentry);
65083+
65084+ __do_handle_create(matchn, ino, dev);
65085+
65086+ return;
65087+}
65088+
65089+void
65090+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65091+{
65092+ struct name_entry *matchn;
65093+
65094+ if (unlikely(!(gr_status & GR_READY)))
65095+ return;
65096+
65097+ preempt_disable();
65098+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65099+
65100+ if (unlikely((unsigned long)matchn)) {
65101+ write_lock(&gr_inode_lock);
65102+ do_handle_create(matchn, dentry, mnt);
65103+ write_unlock(&gr_inode_lock);
65104+ }
65105+ preempt_enable();
65106+
65107+ return;
65108+}
65109+
65110+void
65111+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65112+{
65113+ struct name_entry *matchn;
65114+
65115+ if (unlikely(!(gr_status & GR_READY)))
65116+ return;
65117+
65118+ preempt_disable();
65119+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65120+
65121+ if (unlikely((unsigned long)matchn)) {
65122+ write_lock(&gr_inode_lock);
65123+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65124+ write_unlock(&gr_inode_lock);
65125+ }
65126+ preempt_enable();
65127+
65128+ return;
65129+}
65130+
65131+void
65132+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65133+ struct dentry *old_dentry,
65134+ struct dentry *new_dentry,
65135+ struct vfsmount *mnt, const __u8 replace)
65136+{
65137+ struct name_entry *matchn;
65138+ struct inodev_entry *inodev;
65139+ struct inode *inode = new_dentry->d_inode;
65140+ ino_t old_ino = old_dentry->d_inode->i_ino;
65141+ dev_t old_dev = __get_dev(old_dentry);
65142+
65143+ /* vfs_rename swaps the name and parent link for old_dentry and
65144+ new_dentry
65145+ at this point, old_dentry has the new name, parent link, and inode
65146+ for the renamed file
65147+ if a file is being replaced by a rename, new_dentry has the inode
65148+ and name for the replaced file
65149+ */
65150+
65151+ if (unlikely(!(gr_status & GR_READY)))
65152+ return;
65153+
65154+ preempt_disable();
65155+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65156+
65157+ /* we wouldn't have to check d_inode if it weren't for
65158+ NFS silly-renaming
65159+ */
65160+
65161+ write_lock(&gr_inode_lock);
65162+ if (unlikely(replace && inode)) {
65163+ ino_t new_ino = inode->i_ino;
65164+ dev_t new_dev = __get_dev(new_dentry);
65165+
65166+ inodev = lookup_inodev_entry(new_ino, new_dev);
65167+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65168+ do_handle_delete(inodev, new_ino, new_dev);
65169+ }
65170+
65171+ inodev = lookup_inodev_entry(old_ino, old_dev);
65172+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65173+ do_handle_delete(inodev, old_ino, old_dev);
65174+
65175+ if (unlikely((unsigned long)matchn))
65176+ do_handle_create(matchn, old_dentry, mnt);
65177+
65178+ write_unlock(&gr_inode_lock);
65179+ preempt_enable();
65180+
65181+ return;
65182+}
65183+
65184+static int
65185+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65186+ unsigned char **sum)
65187+{
65188+ struct acl_role_label *r;
65189+ struct role_allowed_ip *ipp;
65190+ struct role_transition *trans;
65191+ unsigned int i;
65192+ int found = 0;
65193+ u32 curr_ip = current->signal->curr_ip;
65194+
65195+ current->signal->saved_ip = curr_ip;
65196+
65197+ /* check transition table */
65198+
65199+ for (trans = current->role->transitions; trans; trans = trans->next) {
65200+ if (!strcmp(rolename, trans->rolename)) {
65201+ found = 1;
65202+ break;
65203+ }
65204+ }
65205+
65206+ if (!found)
65207+ return 0;
65208+
65209+ /* handle special roles that do not require authentication
65210+ and check ip */
65211+
65212+ FOR_EACH_ROLE_START(r)
65213+ if (!strcmp(rolename, r->rolename) &&
65214+ (r->roletype & GR_ROLE_SPECIAL)) {
65215+ found = 0;
65216+ if (r->allowed_ips != NULL) {
65217+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65218+ if ((ntohl(curr_ip) & ipp->netmask) ==
65219+ (ntohl(ipp->addr) & ipp->netmask))
65220+ found = 1;
65221+ }
65222+ } else
65223+ found = 2;
65224+ if (!found)
65225+ return 0;
65226+
65227+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65228+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65229+ *salt = NULL;
65230+ *sum = NULL;
65231+ return 1;
65232+ }
65233+ }
65234+ FOR_EACH_ROLE_END(r)
65235+
65236+ for (i = 0; i < num_sprole_pws; i++) {
65237+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65238+ *salt = acl_special_roles[i]->salt;
65239+ *sum = acl_special_roles[i]->sum;
65240+ return 1;
65241+ }
65242+ }
65243+
65244+ return 0;
65245+}
65246+
65247+static void
65248+assign_special_role(char *rolename)
65249+{
65250+ struct acl_object_label *obj;
65251+ struct acl_role_label *r;
65252+ struct acl_role_label *assigned = NULL;
65253+ struct task_struct *tsk;
65254+ struct file *filp;
65255+
65256+ FOR_EACH_ROLE_START(r)
65257+ if (!strcmp(rolename, r->rolename) &&
65258+ (r->roletype & GR_ROLE_SPECIAL)) {
65259+ assigned = r;
65260+ break;
65261+ }
65262+ FOR_EACH_ROLE_END(r)
65263+
65264+ if (!assigned)
65265+ return;
65266+
65267+ read_lock(&tasklist_lock);
65268+ read_lock(&grsec_exec_file_lock);
65269+
65270+ tsk = current->real_parent;
65271+ if (tsk == NULL)
65272+ goto out_unlock;
65273+
65274+ filp = tsk->exec_file;
65275+ if (filp == NULL)
65276+ goto out_unlock;
65277+
65278+ tsk->is_writable = 0;
65279+
65280+ tsk->acl_sp_role = 1;
65281+ tsk->acl_role_id = ++acl_sp_role_value;
65282+ tsk->role = assigned;
65283+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65284+
65285+ /* ignore additional mmap checks for processes that are writable
65286+ by the default ACL */
65287+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65288+ if (unlikely(obj->mode & GR_WRITE))
65289+ tsk->is_writable = 1;
65290+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65291+ if (unlikely(obj->mode & GR_WRITE))
65292+ tsk->is_writable = 1;
65293+
65294+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65295+ 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));
65296+#endif
65297+
65298+out_unlock:
65299+ read_unlock(&grsec_exec_file_lock);
65300+ read_unlock(&tasklist_lock);
65301+ return;
65302+}
65303+
65304+int gr_check_secure_terminal(struct task_struct *task)
65305+{
65306+ struct task_struct *p, *p2, *p3;
65307+ struct files_struct *files;
65308+ struct fdtable *fdt;
65309+ struct file *our_file = NULL, *file;
65310+ int i;
65311+
65312+ if (task->signal->tty == NULL)
65313+ return 1;
65314+
65315+ files = get_files_struct(task);
65316+ if (files != NULL) {
65317+ rcu_read_lock();
65318+ fdt = files_fdtable(files);
65319+ for (i=0; i < fdt->max_fds; i++) {
65320+ file = fcheck_files(files, i);
65321+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65322+ get_file(file);
65323+ our_file = file;
65324+ }
65325+ }
65326+ rcu_read_unlock();
65327+ put_files_struct(files);
65328+ }
65329+
65330+ if (our_file == NULL)
65331+ return 1;
65332+
65333+ read_lock(&tasklist_lock);
65334+ do_each_thread(p2, p) {
65335+ files = get_files_struct(p);
65336+ if (files == NULL ||
65337+ (p->signal && p->signal->tty == task->signal->tty)) {
65338+ if (files != NULL)
65339+ put_files_struct(files);
65340+ continue;
65341+ }
65342+ rcu_read_lock();
65343+ fdt = files_fdtable(files);
65344+ for (i=0; i < fdt->max_fds; i++) {
65345+ file = fcheck_files(files, i);
65346+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65347+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65348+ p3 = task;
65349+ while (task_pid_nr(p3) > 0) {
65350+ if (p3 == p)
65351+ break;
65352+ p3 = p3->real_parent;
65353+ }
65354+ if (p3 == p)
65355+ break;
65356+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65357+ gr_handle_alertkill(p);
65358+ rcu_read_unlock();
65359+ put_files_struct(files);
65360+ read_unlock(&tasklist_lock);
65361+ fput(our_file);
65362+ return 0;
65363+ }
65364+ }
65365+ rcu_read_unlock();
65366+ put_files_struct(files);
65367+ } while_each_thread(p2, p);
65368+ read_unlock(&tasklist_lock);
65369+
65370+ fput(our_file);
65371+ return 1;
65372+}
65373+
65374+static int gr_rbac_disable(void *unused)
65375+{
65376+ pax_open_kernel();
65377+ gr_status &= ~GR_READY;
65378+ pax_close_kernel();
65379+
65380+ return 0;
65381+}
65382+
65383+ssize_t
65384+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65385+{
65386+ struct gr_arg_wrapper uwrap;
65387+ unsigned char *sprole_salt = NULL;
65388+ unsigned char *sprole_sum = NULL;
65389+ int error = 0;
65390+ int error2 = 0;
65391+ size_t req_count = 0;
65392+
65393+ mutex_lock(&gr_dev_mutex);
65394+
65395+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65396+ error = -EPERM;
65397+ goto out;
65398+ }
65399+
65400+#ifdef CONFIG_COMPAT
65401+ pax_open_kernel();
65402+ if (is_compat_task()) {
65403+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65404+ copy_gr_arg = &copy_gr_arg_compat;
65405+ copy_acl_object_label = &copy_acl_object_label_compat;
65406+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65407+ copy_acl_role_label = &copy_acl_role_label_compat;
65408+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65409+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65410+ copy_role_transition = &copy_role_transition_compat;
65411+ copy_sprole_pw = &copy_sprole_pw_compat;
65412+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65413+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65414+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65415+ } else {
65416+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65417+ copy_gr_arg = &copy_gr_arg_normal;
65418+ copy_acl_object_label = &copy_acl_object_label_normal;
65419+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65420+ copy_acl_role_label = &copy_acl_role_label_normal;
65421+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65422+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65423+ copy_role_transition = &copy_role_transition_normal;
65424+ copy_sprole_pw = &copy_sprole_pw_normal;
65425+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65426+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65427+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65428+ }
65429+ pax_close_kernel();
65430+#endif
65431+
65432+ req_count = get_gr_arg_wrapper_size();
65433+
65434+ if (count != req_count) {
65435+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65436+ error = -EINVAL;
65437+ goto out;
65438+ }
65439+
65440+
65441+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65442+ gr_auth_expires = 0;
65443+ gr_auth_attempts = 0;
65444+ }
65445+
65446+ error = copy_gr_arg_wrapper(buf, &uwrap);
65447+ if (error)
65448+ goto out;
65449+
65450+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65451+ if (error)
65452+ goto out;
65453+
65454+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65455+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65456+ time_after(gr_auth_expires, get_seconds())) {
65457+ error = -EBUSY;
65458+ goto out;
65459+ }
65460+
65461+ /* if non-root trying to do anything other than use a special role,
65462+ do not attempt authentication, do not count towards authentication
65463+ locking
65464+ */
65465+
65466+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65467+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65468+ gr_is_global_nonroot(current_uid())) {
65469+ error = -EPERM;
65470+ goto out;
65471+ }
65472+
65473+ /* ensure pw and special role name are null terminated */
65474+
65475+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65476+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65477+
65478+ /* Okay.
65479+ * We have our enough of the argument structure..(we have yet
65480+ * to copy_from_user the tables themselves) . Copy the tables
65481+ * only if we need them, i.e. for loading operations. */
65482+
65483+ switch (gr_usermode->mode) {
65484+ case GR_STATUS:
65485+ if (gr_status & GR_READY) {
65486+ error = 1;
65487+ if (!gr_check_secure_terminal(current))
65488+ error = 3;
65489+ } else
65490+ error = 2;
65491+ goto out;
65492+ case GR_SHUTDOWN:
65493+ if ((gr_status & GR_READY)
65494+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65495+ stop_machine(gr_rbac_disable, NULL, NULL);
65496+ free_variables();
65497+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65498+ memset(gr_system_salt, 0, GR_SALT_LEN);
65499+ memset(gr_system_sum, 0, GR_SHA_LEN);
65500+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65501+ } else if (gr_status & GR_READY) {
65502+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65503+ error = -EPERM;
65504+ } else {
65505+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65506+ error = -EAGAIN;
65507+ }
65508+ break;
65509+ case GR_ENABLE:
65510+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65511+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65512+ else {
65513+ if (gr_status & GR_READY)
65514+ error = -EAGAIN;
65515+ else
65516+ error = error2;
65517+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65518+ }
65519+ break;
65520+ case GR_RELOAD:
65521+ if (!(gr_status & GR_READY)) {
65522+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65523+ error = -EAGAIN;
65524+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65525+ stop_machine(gr_rbac_disable, NULL, NULL);
65526+ free_variables();
65527+ error2 = gracl_init(gr_usermode);
65528+ if (!error2)
65529+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65530+ else {
65531+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65532+ error = error2;
65533+ }
65534+ } else {
65535+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65536+ error = -EPERM;
65537+ }
65538+ break;
65539+ case GR_SEGVMOD:
65540+ if (unlikely(!(gr_status & GR_READY))) {
65541+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65542+ error = -EAGAIN;
65543+ break;
65544+ }
65545+
65546+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65547+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65548+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65549+ struct acl_subject_label *segvacl;
65550+ segvacl =
65551+ lookup_acl_subj_label(gr_usermode->segv_inode,
65552+ gr_usermode->segv_device,
65553+ current->role);
65554+ if (segvacl) {
65555+ segvacl->crashes = 0;
65556+ segvacl->expires = 0;
65557+ }
65558+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65559+ gr_remove_uid(gr_usermode->segv_uid);
65560+ }
65561+ } else {
65562+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65563+ error = -EPERM;
65564+ }
65565+ break;
65566+ case GR_SPROLE:
65567+ case GR_SPROLEPAM:
65568+ if (unlikely(!(gr_status & GR_READY))) {
65569+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65570+ error = -EAGAIN;
65571+ break;
65572+ }
65573+
65574+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65575+ current->role->expires = 0;
65576+ current->role->auth_attempts = 0;
65577+ }
65578+
65579+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65580+ time_after(current->role->expires, get_seconds())) {
65581+ error = -EBUSY;
65582+ goto out;
65583+ }
65584+
65585+ if (lookup_special_role_auth
65586+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65587+ && ((!sprole_salt && !sprole_sum)
65588+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65589+ char *p = "";
65590+ assign_special_role(gr_usermode->sp_role);
65591+ read_lock(&tasklist_lock);
65592+ if (current->real_parent)
65593+ p = current->real_parent->role->rolename;
65594+ read_unlock(&tasklist_lock);
65595+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65596+ p, acl_sp_role_value);
65597+ } else {
65598+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65599+ error = -EPERM;
65600+ if(!(current->role->auth_attempts++))
65601+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65602+
65603+ goto out;
65604+ }
65605+ break;
65606+ case GR_UNSPROLE:
65607+ if (unlikely(!(gr_status & GR_READY))) {
65608+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65609+ error = -EAGAIN;
65610+ break;
65611+ }
65612+
65613+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65614+ char *p = "";
65615+ int i = 0;
65616+
65617+ read_lock(&tasklist_lock);
65618+ if (current->real_parent) {
65619+ p = current->real_parent->role->rolename;
65620+ i = current->real_parent->acl_role_id;
65621+ }
65622+ read_unlock(&tasklist_lock);
65623+
65624+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65625+ gr_set_acls(1);
65626+ } else {
65627+ error = -EPERM;
65628+ goto out;
65629+ }
65630+ break;
65631+ default:
65632+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65633+ error = -EINVAL;
65634+ break;
65635+ }
65636+
65637+ if (error != -EPERM)
65638+ goto out;
65639+
65640+ if(!(gr_auth_attempts++))
65641+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65642+
65643+ out:
65644+ mutex_unlock(&gr_dev_mutex);
65645+
65646+ if (!error)
65647+ error = req_count;
65648+
65649+ return error;
65650+}
65651+
65652+/* must be called with
65653+ rcu_read_lock();
65654+ read_lock(&tasklist_lock);
65655+ read_lock(&grsec_exec_file_lock);
65656+*/
65657+int gr_apply_subject_to_task(struct task_struct *task)
65658+{
65659+ struct acl_object_label *obj;
65660+ char *tmpname;
65661+ struct acl_subject_label *tmpsubj;
65662+ struct file *filp;
65663+ struct name_entry *nmatch;
65664+
65665+ filp = task->exec_file;
65666+ if (filp == NULL)
65667+ return 0;
65668+
65669+ /* the following is to apply the correct subject
65670+ on binaries running when the RBAC system
65671+ is enabled, when the binaries have been
65672+ replaced or deleted since their execution
65673+ -----
65674+ when the RBAC system starts, the inode/dev
65675+ from exec_file will be one the RBAC system
65676+ is unaware of. It only knows the inode/dev
65677+ of the present file on disk, or the absence
65678+ of it.
65679+ */
65680+ preempt_disable();
65681+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65682+
65683+ nmatch = lookup_name_entry(tmpname);
65684+ preempt_enable();
65685+ tmpsubj = NULL;
65686+ if (nmatch) {
65687+ if (nmatch->deleted)
65688+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65689+ else
65690+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65691+ if (tmpsubj != NULL)
65692+ task->acl = tmpsubj;
65693+ }
65694+ if (tmpsubj == NULL)
65695+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65696+ task->role);
65697+ if (task->acl) {
65698+ task->is_writable = 0;
65699+ /* ignore additional mmap checks for processes that are writable
65700+ by the default ACL */
65701+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65702+ if (unlikely(obj->mode & GR_WRITE))
65703+ task->is_writable = 1;
65704+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65705+ if (unlikely(obj->mode & GR_WRITE))
65706+ task->is_writable = 1;
65707+
65708+ gr_set_proc_res(task);
65709+
65710+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65711+ 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);
65712+#endif
65713+ } else {
65714+ return 1;
65715+ }
65716+
65717+ return 0;
65718+}
65719+
65720+int
65721+gr_set_acls(const int type)
65722+{
65723+ struct task_struct *task, *task2;
65724+ struct acl_role_label *role = current->role;
65725+ __u16 acl_role_id = current->acl_role_id;
65726+ const struct cred *cred;
65727+ int ret;
65728+
65729+ rcu_read_lock();
65730+ read_lock(&tasklist_lock);
65731+ read_lock(&grsec_exec_file_lock);
65732+ do_each_thread(task2, task) {
65733+ /* check to see if we're called from the exit handler,
65734+ if so, only replace ACLs that have inherited the admin
65735+ ACL */
65736+
65737+ if (type && (task->role != role ||
65738+ task->acl_role_id != acl_role_id))
65739+ continue;
65740+
65741+ task->acl_role_id = 0;
65742+ task->acl_sp_role = 0;
65743+
65744+ if (task->exec_file) {
65745+ cred = __task_cred(task);
65746+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65747+ ret = gr_apply_subject_to_task(task);
65748+ if (ret) {
65749+ read_unlock(&grsec_exec_file_lock);
65750+ read_unlock(&tasklist_lock);
65751+ rcu_read_unlock();
65752+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65753+ return ret;
65754+ }
65755+ } else {
65756+ // it's a kernel process
65757+ task->role = kernel_role;
65758+ task->acl = kernel_role->root_label;
65759+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65760+ task->acl->mode &= ~GR_PROCFIND;
65761+#endif
65762+ }
65763+ } while_each_thread(task2, task);
65764+ read_unlock(&grsec_exec_file_lock);
65765+ read_unlock(&tasklist_lock);
65766+ rcu_read_unlock();
65767+
65768+ return 0;
65769+}
65770+
65771+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65772+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65773+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65774+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65775+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65776+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65777+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65778+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65779+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65780+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65781+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65782+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65783+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65784+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65785+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65786+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65787+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65788+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65789+};
65790+
65791+void
65792+gr_learn_resource(const struct task_struct *task,
65793+ const int res, const unsigned long wanted, const int gt)
65794+{
65795+ struct acl_subject_label *acl;
65796+ const struct cred *cred;
65797+
65798+ if (unlikely((gr_status & GR_READY) &&
65799+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65800+ goto skip_reslog;
65801+
65802+ gr_log_resource(task, res, wanted, gt);
65803+skip_reslog:
65804+
65805+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65806+ return;
65807+
65808+ acl = task->acl;
65809+
65810+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65811+ !(acl->resmask & (1U << (unsigned short) res))))
65812+ return;
65813+
65814+ if (wanted >= acl->res[res].rlim_cur) {
65815+ unsigned long res_add;
65816+
65817+ res_add = wanted + res_learn_bumps[res];
65818+
65819+ acl->res[res].rlim_cur = res_add;
65820+
65821+ if (wanted > acl->res[res].rlim_max)
65822+ acl->res[res].rlim_max = res_add;
65823+
65824+ /* only log the subject filename, since resource logging is supported for
65825+ single-subject learning only */
65826+ rcu_read_lock();
65827+ cred = __task_cred(task);
65828+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65829+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65830+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65831+ "", (unsigned long) res, &task->signal->saved_ip);
65832+ rcu_read_unlock();
65833+ }
65834+
65835+ return;
65836+}
65837+EXPORT_SYMBOL(gr_learn_resource);
65838+#endif
65839+
65840+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65841+void
65842+pax_set_initial_flags(struct linux_binprm *bprm)
65843+{
65844+ struct task_struct *task = current;
65845+ struct acl_subject_label *proc;
65846+ unsigned long flags;
65847+
65848+ if (unlikely(!(gr_status & GR_READY)))
65849+ return;
65850+
65851+ flags = pax_get_flags(task);
65852+
65853+ proc = task->acl;
65854+
65855+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65856+ flags &= ~MF_PAX_PAGEEXEC;
65857+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65858+ flags &= ~MF_PAX_SEGMEXEC;
65859+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65860+ flags &= ~MF_PAX_RANDMMAP;
65861+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65862+ flags &= ~MF_PAX_EMUTRAMP;
65863+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65864+ flags &= ~MF_PAX_MPROTECT;
65865+
65866+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65867+ flags |= MF_PAX_PAGEEXEC;
65868+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65869+ flags |= MF_PAX_SEGMEXEC;
65870+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65871+ flags |= MF_PAX_RANDMMAP;
65872+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65873+ flags |= MF_PAX_EMUTRAMP;
65874+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65875+ flags |= MF_PAX_MPROTECT;
65876+
65877+ pax_set_flags(task, flags);
65878+
65879+ return;
65880+}
65881+#endif
65882+
65883+int
65884+gr_handle_proc_ptrace(struct task_struct *task)
65885+{
65886+ struct file *filp;
65887+ struct task_struct *tmp = task;
65888+ struct task_struct *curtemp = current;
65889+ __u32 retmode;
65890+
65891+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65892+ if (unlikely(!(gr_status & GR_READY)))
65893+ return 0;
65894+#endif
65895+
65896+ read_lock(&tasklist_lock);
65897+ read_lock(&grsec_exec_file_lock);
65898+ filp = task->exec_file;
65899+
65900+ while (task_pid_nr(tmp) > 0) {
65901+ if (tmp == curtemp)
65902+ break;
65903+ tmp = tmp->real_parent;
65904+ }
65905+
65906+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65907+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65908+ read_unlock(&grsec_exec_file_lock);
65909+ read_unlock(&tasklist_lock);
65910+ return 1;
65911+ }
65912+
65913+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65914+ if (!(gr_status & GR_READY)) {
65915+ read_unlock(&grsec_exec_file_lock);
65916+ read_unlock(&tasklist_lock);
65917+ return 0;
65918+ }
65919+#endif
65920+
65921+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65922+ read_unlock(&grsec_exec_file_lock);
65923+ read_unlock(&tasklist_lock);
65924+
65925+ if (retmode & GR_NOPTRACE)
65926+ return 1;
65927+
65928+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65929+ && (current->acl != task->acl || (current->acl != current->role->root_label
65930+ && task_pid_nr(current) != task_pid_nr(task))))
65931+ return 1;
65932+
65933+ return 0;
65934+}
65935+
65936+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65937+{
65938+ if (unlikely(!(gr_status & GR_READY)))
65939+ return;
65940+
65941+ if (!(current->role->roletype & GR_ROLE_GOD))
65942+ return;
65943+
65944+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65945+ p->role->rolename, gr_task_roletype_to_char(p),
65946+ p->acl->filename);
65947+}
65948+
65949+int
65950+gr_handle_ptrace(struct task_struct *task, const long request)
65951+{
65952+ struct task_struct *tmp = task;
65953+ struct task_struct *curtemp = current;
65954+ __u32 retmode;
65955+
65956+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65957+ if (unlikely(!(gr_status & GR_READY)))
65958+ return 0;
65959+#endif
65960+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65961+ read_lock(&tasklist_lock);
65962+ while (task_pid_nr(tmp) > 0) {
65963+ if (tmp == curtemp)
65964+ break;
65965+ tmp = tmp->real_parent;
65966+ }
65967+
65968+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65969+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65970+ read_unlock(&tasklist_lock);
65971+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65972+ return 1;
65973+ }
65974+ read_unlock(&tasklist_lock);
65975+ }
65976+
65977+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65978+ if (!(gr_status & GR_READY))
65979+ return 0;
65980+#endif
65981+
65982+ read_lock(&grsec_exec_file_lock);
65983+ if (unlikely(!task->exec_file)) {
65984+ read_unlock(&grsec_exec_file_lock);
65985+ return 0;
65986+ }
65987+
65988+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65989+ read_unlock(&grsec_exec_file_lock);
65990+
65991+ if (retmode & GR_NOPTRACE) {
65992+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65993+ return 1;
65994+ }
65995+
65996+ if (retmode & GR_PTRACERD) {
65997+ switch (request) {
65998+ case PTRACE_SEIZE:
65999+ case PTRACE_POKETEXT:
66000+ case PTRACE_POKEDATA:
66001+ case PTRACE_POKEUSR:
66002+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66003+ case PTRACE_SETREGS:
66004+ case PTRACE_SETFPREGS:
66005+#endif
66006+#ifdef CONFIG_X86
66007+ case PTRACE_SETFPXREGS:
66008+#endif
66009+#ifdef CONFIG_ALTIVEC
66010+ case PTRACE_SETVRREGS:
66011+#endif
66012+ return 1;
66013+ default:
66014+ return 0;
66015+ }
66016+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66017+ !(current->role->roletype & GR_ROLE_GOD) &&
66018+ (current->acl != task->acl)) {
66019+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66020+ return 1;
66021+ }
66022+
66023+ return 0;
66024+}
66025+
66026+static int is_writable_mmap(const struct file *filp)
66027+{
66028+ struct task_struct *task = current;
66029+ struct acl_object_label *obj, *obj2;
66030+
66031+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66032+ !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))) {
66033+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66034+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66035+ task->role->root_label);
66036+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66037+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66038+ return 1;
66039+ }
66040+ }
66041+ return 0;
66042+}
66043+
66044+int
66045+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66046+{
66047+ __u32 mode;
66048+
66049+ if (unlikely(!file || !(prot & PROT_EXEC)))
66050+ return 1;
66051+
66052+ if (is_writable_mmap(file))
66053+ return 0;
66054+
66055+ mode =
66056+ gr_search_file(file->f_path.dentry,
66057+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66058+ file->f_path.mnt);
66059+
66060+ if (!gr_tpe_allow(file))
66061+ return 0;
66062+
66063+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66064+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66065+ return 0;
66066+ } else if (unlikely(!(mode & GR_EXEC))) {
66067+ return 0;
66068+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66069+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66070+ return 1;
66071+ }
66072+
66073+ return 1;
66074+}
66075+
66076+int
66077+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66078+{
66079+ __u32 mode;
66080+
66081+ if (unlikely(!file || !(prot & PROT_EXEC)))
66082+ return 1;
66083+
66084+ if (is_writable_mmap(file))
66085+ return 0;
66086+
66087+ mode =
66088+ gr_search_file(file->f_path.dentry,
66089+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66090+ file->f_path.mnt);
66091+
66092+ if (!gr_tpe_allow(file))
66093+ return 0;
66094+
66095+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66096+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66097+ return 0;
66098+ } else if (unlikely(!(mode & GR_EXEC))) {
66099+ return 0;
66100+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66101+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66102+ return 1;
66103+ }
66104+
66105+ return 1;
66106+}
66107+
66108+void
66109+gr_acl_handle_psacct(struct task_struct *task, const long code)
66110+{
66111+ unsigned long runtime;
66112+ unsigned long cputime;
66113+ unsigned int wday, cday;
66114+ __u8 whr, chr;
66115+ __u8 wmin, cmin;
66116+ __u8 wsec, csec;
66117+ struct timespec timeval;
66118+
66119+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66120+ !(task->acl->mode & GR_PROCACCT)))
66121+ return;
66122+
66123+ do_posix_clock_monotonic_gettime(&timeval);
66124+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66125+ wday = runtime / (3600 * 24);
66126+ runtime -= wday * (3600 * 24);
66127+ whr = runtime / 3600;
66128+ runtime -= whr * 3600;
66129+ wmin = runtime / 60;
66130+ runtime -= wmin * 60;
66131+ wsec = runtime;
66132+
66133+ cputime = (task->utime + task->stime) / HZ;
66134+ cday = cputime / (3600 * 24);
66135+ cputime -= cday * (3600 * 24);
66136+ chr = cputime / 3600;
66137+ cputime -= chr * 3600;
66138+ cmin = cputime / 60;
66139+ cputime -= cmin * 60;
66140+ csec = cputime;
66141+
66142+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66143+
66144+ return;
66145+}
66146+
66147+void gr_set_kernel_label(struct task_struct *task)
66148+{
66149+ if (gr_status & GR_READY) {
66150+ task->role = kernel_role;
66151+ task->acl = kernel_role->root_label;
66152+ }
66153+ return;
66154+}
66155+
66156+#ifdef CONFIG_TASKSTATS
66157+int gr_is_taskstats_denied(int pid)
66158+{
66159+ struct task_struct *task;
66160+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66161+ const struct cred *cred;
66162+#endif
66163+ int ret = 0;
66164+
66165+ /* restrict taskstats viewing to un-chrooted root users
66166+ who have the 'view' subject flag if the RBAC system is enabled
66167+ */
66168+
66169+ rcu_read_lock();
66170+ read_lock(&tasklist_lock);
66171+ task = find_task_by_vpid(pid);
66172+ if (task) {
66173+#ifdef CONFIG_GRKERNSEC_CHROOT
66174+ if (proc_is_chrooted(task))
66175+ ret = -EACCES;
66176+#endif
66177+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66178+ cred = __task_cred(task);
66179+#ifdef CONFIG_GRKERNSEC_PROC_USER
66180+ if (gr_is_global_nonroot(cred->uid))
66181+ ret = -EACCES;
66182+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66183+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66184+ ret = -EACCES;
66185+#endif
66186+#endif
66187+ if (gr_status & GR_READY) {
66188+ if (!(task->acl->mode & GR_VIEW))
66189+ ret = -EACCES;
66190+ }
66191+ } else
66192+ ret = -ENOENT;
66193+
66194+ read_unlock(&tasklist_lock);
66195+ rcu_read_unlock();
66196+
66197+ return ret;
66198+}
66199+#endif
66200+
66201+/* AUXV entries are filled via a descendant of search_binary_handler
66202+ after we've already applied the subject for the target
66203+*/
66204+int gr_acl_enable_at_secure(void)
66205+{
66206+ if (unlikely(!(gr_status & GR_READY)))
66207+ return 0;
66208+
66209+ if (current->acl->mode & GR_ATSECURE)
66210+ return 1;
66211+
66212+ return 0;
66213+}
66214+
66215+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66216+{
66217+ struct task_struct *task = current;
66218+ struct dentry *dentry = file->f_path.dentry;
66219+ struct vfsmount *mnt = file->f_path.mnt;
66220+ struct acl_object_label *obj, *tmp;
66221+ struct acl_subject_label *subj;
66222+ unsigned int bufsize;
66223+ int is_not_root;
66224+ char *path;
66225+ dev_t dev = __get_dev(dentry);
66226+
66227+ if (unlikely(!(gr_status & GR_READY)))
66228+ return 1;
66229+
66230+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66231+ return 1;
66232+
66233+ /* ignore Eric Biederman */
66234+ if (IS_PRIVATE(dentry->d_inode))
66235+ return 1;
66236+
66237+ subj = task->acl;
66238+ read_lock(&gr_inode_lock);
66239+ do {
66240+ obj = lookup_acl_obj_label(ino, dev, subj);
66241+ if (obj != NULL) {
66242+ read_unlock(&gr_inode_lock);
66243+ return (obj->mode & GR_FIND) ? 1 : 0;
66244+ }
66245+ } while ((subj = subj->parent_subject));
66246+ read_unlock(&gr_inode_lock);
66247+
66248+ /* this is purely an optimization since we're looking for an object
66249+ for the directory we're doing a readdir on
66250+ if it's possible for any globbed object to match the entry we're
66251+ filling into the directory, then the object we find here will be
66252+ an anchor point with attached globbed objects
66253+ */
66254+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66255+ if (obj->globbed == NULL)
66256+ return (obj->mode & GR_FIND) ? 1 : 0;
66257+
66258+ is_not_root = ((obj->filename[0] == '/') &&
66259+ (obj->filename[1] == '\0')) ? 0 : 1;
66260+ bufsize = PAGE_SIZE - namelen - is_not_root;
66261+
66262+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66263+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66264+ return 1;
66265+
66266+ preempt_disable();
66267+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66268+ bufsize);
66269+
66270+ bufsize = strlen(path);
66271+
66272+ /* if base is "/", don't append an additional slash */
66273+ if (is_not_root)
66274+ *(path + bufsize) = '/';
66275+ memcpy(path + bufsize + is_not_root, name, namelen);
66276+ *(path + bufsize + namelen + is_not_root) = '\0';
66277+
66278+ tmp = obj->globbed;
66279+ while (tmp) {
66280+ if (!glob_match(tmp->filename, path)) {
66281+ preempt_enable();
66282+ return (tmp->mode & GR_FIND) ? 1 : 0;
66283+ }
66284+ tmp = tmp->next;
66285+ }
66286+ preempt_enable();
66287+ return (obj->mode & GR_FIND) ? 1 : 0;
66288+}
66289+
66290+void gr_put_exec_file(struct task_struct *task)
66291+{
66292+ struct file *filp;
66293+
66294+ write_lock(&grsec_exec_file_lock);
66295+ filp = task->exec_file;
66296+ task->exec_file = NULL;
66297+ write_unlock(&grsec_exec_file_lock);
66298+
66299+ if (filp)
66300+ fput(filp);
66301+
66302+ return;
66303+}
66304+
66305+
66306+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66307+EXPORT_SYMBOL(gr_acl_is_enabled);
66308+#endif
66309+EXPORT_SYMBOL(gr_set_kernel_label);
66310+#ifdef CONFIG_SECURITY
66311+EXPORT_SYMBOL(gr_check_user_change);
66312+EXPORT_SYMBOL(gr_check_group_change);
66313+#endif
66314+
66315diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66316new file mode 100644
66317index 0000000..34fefda
66318--- /dev/null
66319+++ b/grsecurity/gracl_alloc.c
66320@@ -0,0 +1,105 @@
66321+#include <linux/kernel.h>
66322+#include <linux/mm.h>
66323+#include <linux/slab.h>
66324+#include <linux/vmalloc.h>
66325+#include <linux/gracl.h>
66326+#include <linux/grsecurity.h>
66327+
66328+static unsigned long alloc_stack_next = 1;
66329+static unsigned long alloc_stack_size = 1;
66330+static void **alloc_stack;
66331+
66332+static __inline__ int
66333+alloc_pop(void)
66334+{
66335+ if (alloc_stack_next == 1)
66336+ return 0;
66337+
66338+ kfree(alloc_stack[alloc_stack_next - 2]);
66339+
66340+ alloc_stack_next--;
66341+
66342+ return 1;
66343+}
66344+
66345+static __inline__ int
66346+alloc_push(void *buf)
66347+{
66348+ if (alloc_stack_next >= alloc_stack_size)
66349+ return 1;
66350+
66351+ alloc_stack[alloc_stack_next - 1] = buf;
66352+
66353+ alloc_stack_next++;
66354+
66355+ return 0;
66356+}
66357+
66358+void *
66359+acl_alloc(unsigned long len)
66360+{
66361+ void *ret = NULL;
66362+
66363+ if (!len || len > PAGE_SIZE)
66364+ goto out;
66365+
66366+ ret = kmalloc(len, GFP_KERNEL);
66367+
66368+ if (ret) {
66369+ if (alloc_push(ret)) {
66370+ kfree(ret);
66371+ ret = NULL;
66372+ }
66373+ }
66374+
66375+out:
66376+ return ret;
66377+}
66378+
66379+void *
66380+acl_alloc_num(unsigned long num, unsigned long len)
66381+{
66382+ if (!len || (num > (PAGE_SIZE / len)))
66383+ return NULL;
66384+
66385+ return acl_alloc(num * len);
66386+}
66387+
66388+void
66389+acl_free_all(void)
66390+{
66391+ if (gr_acl_is_enabled() || !alloc_stack)
66392+ return;
66393+
66394+ while (alloc_pop()) ;
66395+
66396+ if (alloc_stack) {
66397+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66398+ kfree(alloc_stack);
66399+ else
66400+ vfree(alloc_stack);
66401+ }
66402+
66403+ alloc_stack = NULL;
66404+ alloc_stack_size = 1;
66405+ alloc_stack_next = 1;
66406+
66407+ return;
66408+}
66409+
66410+int
66411+acl_alloc_stack_init(unsigned long size)
66412+{
66413+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66414+ alloc_stack =
66415+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66416+ else
66417+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66418+
66419+ alloc_stack_size = size;
66420+
66421+ if (!alloc_stack)
66422+ return 0;
66423+ else
66424+ return 1;
66425+}
66426diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66427new file mode 100644
66428index 0000000..bdd51ea
66429--- /dev/null
66430+++ b/grsecurity/gracl_cap.c
66431@@ -0,0 +1,110 @@
66432+#include <linux/kernel.h>
66433+#include <linux/module.h>
66434+#include <linux/sched.h>
66435+#include <linux/gracl.h>
66436+#include <linux/grsecurity.h>
66437+#include <linux/grinternal.h>
66438+
66439+extern const char *captab_log[];
66440+extern int captab_log_entries;
66441+
66442+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66443+{
66444+ struct acl_subject_label *curracl;
66445+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66446+ kernel_cap_t cap_audit = __cap_empty_set;
66447+
66448+ if (!gr_acl_is_enabled())
66449+ return 1;
66450+
66451+ curracl = task->acl;
66452+
66453+ cap_drop = curracl->cap_lower;
66454+ cap_mask = curracl->cap_mask;
66455+ cap_audit = curracl->cap_invert_audit;
66456+
66457+ while ((curracl = curracl->parent_subject)) {
66458+ /* if the cap isn't specified in the current computed mask but is specified in the
66459+ current level subject, and is lowered in the current level subject, then add
66460+ it to the set of dropped capabilities
66461+ otherwise, add the current level subject's mask to the current computed mask
66462+ */
66463+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66464+ cap_raise(cap_mask, cap);
66465+ if (cap_raised(curracl->cap_lower, cap))
66466+ cap_raise(cap_drop, cap);
66467+ if (cap_raised(curracl->cap_invert_audit, cap))
66468+ cap_raise(cap_audit, cap);
66469+ }
66470+ }
66471+
66472+ if (!cap_raised(cap_drop, cap)) {
66473+ if (cap_raised(cap_audit, cap))
66474+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66475+ return 1;
66476+ }
66477+
66478+ curracl = task->acl;
66479+
66480+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66481+ && cap_raised(cred->cap_effective, cap)) {
66482+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66483+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66484+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66485+ gr_to_filename(task->exec_file->f_path.dentry,
66486+ task->exec_file->f_path.mnt) : curracl->filename,
66487+ curracl->filename, 0UL,
66488+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66489+ return 1;
66490+ }
66491+
66492+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66493+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66494+
66495+ return 0;
66496+}
66497+
66498+int
66499+gr_acl_is_capable(const int cap)
66500+{
66501+ return gr_task_acl_is_capable(current, current_cred(), cap);
66502+}
66503+
66504+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66505+{
66506+ struct acl_subject_label *curracl;
66507+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66508+
66509+ if (!gr_acl_is_enabled())
66510+ return 1;
66511+
66512+ curracl = task->acl;
66513+
66514+ cap_drop = curracl->cap_lower;
66515+ cap_mask = curracl->cap_mask;
66516+
66517+ while ((curracl = curracl->parent_subject)) {
66518+ /* if the cap isn't specified in the current computed mask but is specified in the
66519+ current level subject, and is lowered in the current level subject, then add
66520+ it to the set of dropped capabilities
66521+ otherwise, add the current level subject's mask to the current computed mask
66522+ */
66523+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66524+ cap_raise(cap_mask, cap);
66525+ if (cap_raised(curracl->cap_lower, cap))
66526+ cap_raise(cap_drop, cap);
66527+ }
66528+ }
66529+
66530+ if (!cap_raised(cap_drop, cap))
66531+ return 1;
66532+
66533+ return 0;
66534+}
66535+
66536+int
66537+gr_acl_is_capable_nolog(const int cap)
66538+{
66539+ return gr_task_acl_is_capable_nolog(current, cap);
66540+}
66541+
66542diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66543new file mode 100644
66544index 0000000..a43dd06
66545--- /dev/null
66546+++ b/grsecurity/gracl_compat.c
66547@@ -0,0 +1,269 @@
66548+#include <linux/kernel.h>
66549+#include <linux/gracl.h>
66550+#include <linux/compat.h>
66551+#include <linux/gracl_compat.h>
66552+
66553+#include <asm/uaccess.h>
66554+
66555+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66556+{
66557+ struct gr_arg_wrapper_compat uwrapcompat;
66558+
66559+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66560+ return -EFAULT;
66561+
66562+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66563+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66564+ return -EINVAL;
66565+
66566+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66567+ uwrap->version = uwrapcompat.version;
66568+ uwrap->size = sizeof(struct gr_arg);
66569+
66570+ return 0;
66571+}
66572+
66573+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66574+{
66575+ struct gr_arg_compat argcompat;
66576+
66577+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66578+ return -EFAULT;
66579+
66580+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66581+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66582+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66583+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66584+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66585+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66586+
66587+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66588+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66589+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66590+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66591+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66592+ arg->segv_device = argcompat.segv_device;
66593+ arg->segv_inode = argcompat.segv_inode;
66594+ arg->segv_uid = argcompat.segv_uid;
66595+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66596+ arg->mode = argcompat.mode;
66597+
66598+ return 0;
66599+}
66600+
66601+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66602+{
66603+ struct acl_object_label_compat objcompat;
66604+
66605+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66606+ return -EFAULT;
66607+
66608+ obj->filename = compat_ptr(objcompat.filename);
66609+ obj->inode = objcompat.inode;
66610+ obj->device = objcompat.device;
66611+ obj->mode = objcompat.mode;
66612+
66613+ obj->nested = compat_ptr(objcompat.nested);
66614+ obj->globbed = compat_ptr(objcompat.globbed);
66615+
66616+ obj->prev = compat_ptr(objcompat.prev);
66617+ obj->next = compat_ptr(objcompat.next);
66618+
66619+ return 0;
66620+}
66621+
66622+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66623+{
66624+ unsigned int i;
66625+ struct acl_subject_label_compat subjcompat;
66626+
66627+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66628+ return -EFAULT;
66629+
66630+ subj->filename = compat_ptr(subjcompat.filename);
66631+ subj->inode = subjcompat.inode;
66632+ subj->device = subjcompat.device;
66633+ subj->mode = subjcompat.mode;
66634+ subj->cap_mask = subjcompat.cap_mask;
66635+ subj->cap_lower = subjcompat.cap_lower;
66636+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66637+
66638+ for (i = 0; i < GR_NLIMITS; i++) {
66639+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66640+ subj->res[i].rlim_cur = RLIM_INFINITY;
66641+ else
66642+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66643+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66644+ subj->res[i].rlim_max = RLIM_INFINITY;
66645+ else
66646+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66647+ }
66648+ subj->resmask = subjcompat.resmask;
66649+
66650+ subj->user_trans_type = subjcompat.user_trans_type;
66651+ subj->group_trans_type = subjcompat.group_trans_type;
66652+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66653+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66654+ subj->user_trans_num = subjcompat.user_trans_num;
66655+ subj->group_trans_num = subjcompat.group_trans_num;
66656+
66657+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66658+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66659+ subj->ip_type = subjcompat.ip_type;
66660+ subj->ips = compat_ptr(subjcompat.ips);
66661+ subj->ip_num = subjcompat.ip_num;
66662+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66663+
66664+ subj->crashes = subjcompat.crashes;
66665+ subj->expires = subjcompat.expires;
66666+
66667+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66668+ subj->hash = compat_ptr(subjcompat.hash);
66669+ subj->prev = compat_ptr(subjcompat.prev);
66670+ subj->next = compat_ptr(subjcompat.next);
66671+
66672+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66673+ subj->obj_hash_size = subjcompat.obj_hash_size;
66674+ subj->pax_flags = subjcompat.pax_flags;
66675+
66676+ return 0;
66677+}
66678+
66679+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66680+{
66681+ struct acl_role_label_compat rolecompat;
66682+
66683+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66684+ return -EFAULT;
66685+
66686+ role->rolename = compat_ptr(rolecompat.rolename);
66687+ role->uidgid = rolecompat.uidgid;
66688+ role->roletype = rolecompat.roletype;
66689+
66690+ role->auth_attempts = rolecompat.auth_attempts;
66691+ role->expires = rolecompat.expires;
66692+
66693+ role->root_label = compat_ptr(rolecompat.root_label);
66694+ role->hash = compat_ptr(rolecompat.hash);
66695+
66696+ role->prev = compat_ptr(rolecompat.prev);
66697+ role->next = compat_ptr(rolecompat.next);
66698+
66699+ role->transitions = compat_ptr(rolecompat.transitions);
66700+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66701+ role->domain_children = compat_ptr(rolecompat.domain_children);
66702+ role->domain_child_num = rolecompat.domain_child_num;
66703+
66704+ role->umask = rolecompat.umask;
66705+
66706+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66707+ role->subj_hash_size = rolecompat.subj_hash_size;
66708+
66709+ return 0;
66710+}
66711+
66712+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66713+{
66714+ struct role_allowed_ip_compat roleip_compat;
66715+
66716+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66717+ return -EFAULT;
66718+
66719+ roleip->addr = roleip_compat.addr;
66720+ roleip->netmask = roleip_compat.netmask;
66721+
66722+ roleip->prev = compat_ptr(roleip_compat.prev);
66723+ roleip->next = compat_ptr(roleip_compat.next);
66724+
66725+ return 0;
66726+}
66727+
66728+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66729+{
66730+ struct role_transition_compat trans_compat;
66731+
66732+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66733+ return -EFAULT;
66734+
66735+ trans->rolename = compat_ptr(trans_compat.rolename);
66736+
66737+ trans->prev = compat_ptr(trans_compat.prev);
66738+ trans->next = compat_ptr(trans_compat.next);
66739+
66740+ return 0;
66741+
66742+}
66743+
66744+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66745+{
66746+ struct gr_hash_struct_compat hash_compat;
66747+
66748+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66749+ return -EFAULT;
66750+
66751+ hash->table = compat_ptr(hash_compat.table);
66752+ hash->nametable = compat_ptr(hash_compat.nametable);
66753+ hash->first = compat_ptr(hash_compat.first);
66754+
66755+ hash->table_size = hash_compat.table_size;
66756+ hash->used_size = hash_compat.used_size;
66757+
66758+ hash->type = hash_compat.type;
66759+
66760+ return 0;
66761+}
66762+
66763+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66764+{
66765+ compat_uptr_t ptrcompat;
66766+
66767+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66768+ return -EFAULT;
66769+
66770+ *(void **)ptr = compat_ptr(ptrcompat);
66771+
66772+ return 0;
66773+}
66774+
66775+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66776+{
66777+ struct acl_ip_label_compat ip_compat;
66778+
66779+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66780+ return -EFAULT;
66781+
66782+ ip->iface = compat_ptr(ip_compat.iface);
66783+ ip->addr = ip_compat.addr;
66784+ ip->netmask = ip_compat.netmask;
66785+ ip->low = ip_compat.low;
66786+ ip->high = ip_compat.high;
66787+ ip->mode = ip_compat.mode;
66788+ ip->type = ip_compat.type;
66789+
66790+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66791+
66792+ ip->prev = compat_ptr(ip_compat.prev);
66793+ ip->next = compat_ptr(ip_compat.next);
66794+
66795+ return 0;
66796+}
66797+
66798+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66799+{
66800+ struct sprole_pw_compat pw_compat;
66801+
66802+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66803+ return -EFAULT;
66804+
66805+ pw->rolename = compat_ptr(pw_compat.rolename);
66806+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66807+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66808+
66809+ return 0;
66810+}
66811+
66812+size_t get_gr_arg_wrapper_size_compat(void)
66813+{
66814+ return sizeof(struct gr_arg_wrapper_compat);
66815+}
66816+
66817diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66818new file mode 100644
66819index 0000000..a340c17
66820--- /dev/null
66821+++ b/grsecurity/gracl_fs.c
66822@@ -0,0 +1,431 @@
66823+#include <linux/kernel.h>
66824+#include <linux/sched.h>
66825+#include <linux/types.h>
66826+#include <linux/fs.h>
66827+#include <linux/file.h>
66828+#include <linux/stat.h>
66829+#include <linux/grsecurity.h>
66830+#include <linux/grinternal.h>
66831+#include <linux/gracl.h>
66832+
66833+umode_t
66834+gr_acl_umask(void)
66835+{
66836+ if (unlikely(!gr_acl_is_enabled()))
66837+ return 0;
66838+
66839+ return current->role->umask;
66840+}
66841+
66842+__u32
66843+gr_acl_handle_hidden_file(const struct dentry * dentry,
66844+ const struct vfsmount * mnt)
66845+{
66846+ __u32 mode;
66847+
66848+ if (unlikely(!dentry->d_inode))
66849+ return GR_FIND;
66850+
66851+ mode =
66852+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66853+
66854+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66855+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66856+ return mode;
66857+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66858+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66859+ return 0;
66860+ } else if (unlikely(!(mode & GR_FIND)))
66861+ return 0;
66862+
66863+ return GR_FIND;
66864+}
66865+
66866+__u32
66867+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66868+ int acc_mode)
66869+{
66870+ __u32 reqmode = GR_FIND;
66871+ __u32 mode;
66872+
66873+ if (unlikely(!dentry->d_inode))
66874+ return reqmode;
66875+
66876+ if (acc_mode & MAY_APPEND)
66877+ reqmode |= GR_APPEND;
66878+ else if (acc_mode & MAY_WRITE)
66879+ reqmode |= GR_WRITE;
66880+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66881+ reqmode |= GR_READ;
66882+
66883+ mode =
66884+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66885+ mnt);
66886+
66887+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66888+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66889+ reqmode & GR_READ ? " reading" : "",
66890+ reqmode & GR_WRITE ? " writing" : reqmode &
66891+ GR_APPEND ? " appending" : "");
66892+ return reqmode;
66893+ } else
66894+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66895+ {
66896+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66897+ reqmode & GR_READ ? " reading" : "",
66898+ reqmode & GR_WRITE ? " writing" : reqmode &
66899+ GR_APPEND ? " appending" : "");
66900+ return 0;
66901+ } else if (unlikely((mode & reqmode) != reqmode))
66902+ return 0;
66903+
66904+ return reqmode;
66905+}
66906+
66907+__u32
66908+gr_acl_handle_creat(const struct dentry * dentry,
66909+ const struct dentry * p_dentry,
66910+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66911+ const int imode)
66912+{
66913+ __u32 reqmode = GR_WRITE | GR_CREATE;
66914+ __u32 mode;
66915+
66916+ if (acc_mode & MAY_APPEND)
66917+ reqmode |= GR_APPEND;
66918+ // if a directory was required or the directory already exists, then
66919+ // don't count this open as a read
66920+ if ((acc_mode & MAY_READ) &&
66921+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66922+ reqmode |= GR_READ;
66923+ if ((open_flags & O_CREAT) &&
66924+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66925+ reqmode |= GR_SETID;
66926+
66927+ mode =
66928+ gr_check_create(dentry, p_dentry, p_mnt,
66929+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66930+
66931+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66932+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66933+ reqmode & GR_READ ? " reading" : "",
66934+ reqmode & GR_WRITE ? " writing" : reqmode &
66935+ GR_APPEND ? " appending" : "");
66936+ return reqmode;
66937+ } else
66938+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66939+ {
66940+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66941+ reqmode & GR_READ ? " reading" : "",
66942+ reqmode & GR_WRITE ? " writing" : reqmode &
66943+ GR_APPEND ? " appending" : "");
66944+ return 0;
66945+ } else if (unlikely((mode & reqmode) != reqmode))
66946+ return 0;
66947+
66948+ return reqmode;
66949+}
66950+
66951+__u32
66952+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66953+ const int fmode)
66954+{
66955+ __u32 mode, reqmode = GR_FIND;
66956+
66957+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66958+ reqmode |= GR_EXEC;
66959+ if (fmode & S_IWOTH)
66960+ reqmode |= GR_WRITE;
66961+ if (fmode & S_IROTH)
66962+ reqmode |= GR_READ;
66963+
66964+ mode =
66965+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66966+ mnt);
66967+
66968+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66969+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66970+ reqmode & GR_READ ? " reading" : "",
66971+ reqmode & GR_WRITE ? " writing" : "",
66972+ reqmode & GR_EXEC ? " executing" : "");
66973+ return reqmode;
66974+ } else
66975+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66976+ {
66977+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66978+ reqmode & GR_READ ? " reading" : "",
66979+ reqmode & GR_WRITE ? " writing" : "",
66980+ reqmode & GR_EXEC ? " executing" : "");
66981+ return 0;
66982+ } else if (unlikely((mode & reqmode) != reqmode))
66983+ return 0;
66984+
66985+ return reqmode;
66986+}
66987+
66988+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66989+{
66990+ __u32 mode;
66991+
66992+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66993+
66994+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66995+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66996+ return mode;
66997+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66998+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66999+ return 0;
67000+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67001+ return 0;
67002+
67003+ return (reqmode);
67004+}
67005+
67006+__u32
67007+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67008+{
67009+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67010+}
67011+
67012+__u32
67013+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67014+{
67015+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67016+}
67017+
67018+__u32
67019+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67020+{
67021+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67022+}
67023+
67024+__u32
67025+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67026+{
67027+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67028+}
67029+
67030+__u32
67031+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67032+ umode_t *modeptr)
67033+{
67034+ umode_t mode;
67035+
67036+ *modeptr &= ~gr_acl_umask();
67037+ mode = *modeptr;
67038+
67039+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67040+ return 1;
67041+
67042+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67043+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67044+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67045+ GR_CHMOD_ACL_MSG);
67046+ } else {
67047+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67048+ }
67049+}
67050+
67051+__u32
67052+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67053+{
67054+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67055+}
67056+
67057+__u32
67058+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67059+{
67060+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67061+}
67062+
67063+__u32
67064+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67065+{
67066+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67067+}
67068+
67069+__u32
67070+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67071+{
67072+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67073+ GR_UNIXCONNECT_ACL_MSG);
67074+}
67075+
67076+/* hardlinks require at minimum create and link permission,
67077+ any additional privilege required is based on the
67078+ privilege of the file being linked to
67079+*/
67080+__u32
67081+gr_acl_handle_link(const struct dentry * new_dentry,
67082+ const struct dentry * parent_dentry,
67083+ const struct vfsmount * parent_mnt,
67084+ const struct dentry * old_dentry,
67085+ const struct vfsmount * old_mnt, const struct filename *to)
67086+{
67087+ __u32 mode;
67088+ __u32 needmode = GR_CREATE | GR_LINK;
67089+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67090+
67091+ mode =
67092+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67093+ old_mnt);
67094+
67095+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67096+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67097+ return mode;
67098+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67099+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67100+ return 0;
67101+ } else if (unlikely((mode & needmode) != needmode))
67102+ return 0;
67103+
67104+ return 1;
67105+}
67106+
67107+__u32
67108+gr_acl_handle_symlink(const struct dentry * new_dentry,
67109+ const struct dentry * parent_dentry,
67110+ const struct vfsmount * parent_mnt, const struct filename *from)
67111+{
67112+ __u32 needmode = GR_WRITE | GR_CREATE;
67113+ __u32 mode;
67114+
67115+ mode =
67116+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67117+ GR_CREATE | GR_AUDIT_CREATE |
67118+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67119+
67120+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67121+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67122+ return mode;
67123+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67124+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67125+ return 0;
67126+ } else if (unlikely((mode & needmode) != needmode))
67127+ return 0;
67128+
67129+ return (GR_WRITE | GR_CREATE);
67130+}
67131+
67132+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)
67133+{
67134+ __u32 mode;
67135+
67136+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67137+
67138+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67139+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67140+ return mode;
67141+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67142+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67143+ return 0;
67144+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67145+ return 0;
67146+
67147+ return (reqmode);
67148+}
67149+
67150+__u32
67151+gr_acl_handle_mknod(const struct dentry * new_dentry,
67152+ const struct dentry * parent_dentry,
67153+ const struct vfsmount * parent_mnt,
67154+ const int mode)
67155+{
67156+ __u32 reqmode = GR_WRITE | GR_CREATE;
67157+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67158+ reqmode |= GR_SETID;
67159+
67160+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67161+ reqmode, GR_MKNOD_ACL_MSG);
67162+}
67163+
67164+__u32
67165+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67166+ const struct dentry *parent_dentry,
67167+ const struct vfsmount *parent_mnt)
67168+{
67169+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67170+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67171+}
67172+
67173+#define RENAME_CHECK_SUCCESS(old, new) \
67174+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67175+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67176+
67177+int
67178+gr_acl_handle_rename(struct dentry *new_dentry,
67179+ struct dentry *parent_dentry,
67180+ const struct vfsmount *parent_mnt,
67181+ struct dentry *old_dentry,
67182+ struct inode *old_parent_inode,
67183+ struct vfsmount *old_mnt, const struct filename *newname)
67184+{
67185+ __u32 comp1, comp2;
67186+ int error = 0;
67187+
67188+ if (unlikely(!gr_acl_is_enabled()))
67189+ return 0;
67190+
67191+ if (!new_dentry->d_inode) {
67192+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67193+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67194+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67195+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67196+ GR_DELETE | GR_AUDIT_DELETE |
67197+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67198+ GR_SUPPRESS, old_mnt);
67199+ } else {
67200+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67201+ GR_CREATE | GR_DELETE |
67202+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67203+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67204+ GR_SUPPRESS, parent_mnt);
67205+ comp2 =
67206+ gr_search_file(old_dentry,
67207+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67208+ GR_DELETE | GR_AUDIT_DELETE |
67209+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67210+ }
67211+
67212+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67213+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67214+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67215+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67216+ && !(comp2 & GR_SUPPRESS)) {
67217+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67218+ error = -EACCES;
67219+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67220+ error = -EACCES;
67221+
67222+ return error;
67223+}
67224+
67225+void
67226+gr_acl_handle_exit(void)
67227+{
67228+ u16 id;
67229+ char *rolename;
67230+
67231+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67232+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67233+ id = current->acl_role_id;
67234+ rolename = current->role->rolename;
67235+ gr_set_acls(1);
67236+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67237+ }
67238+
67239+ gr_put_exec_file(current);
67240+ return;
67241+}
67242+
67243+int
67244+gr_acl_handle_procpidmem(const struct task_struct *task)
67245+{
67246+ if (unlikely(!gr_acl_is_enabled()))
67247+ return 0;
67248+
67249+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67250+ return -EACCES;
67251+
67252+ return 0;
67253+}
67254diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67255new file mode 100644
67256index 0000000..f056b81
67257--- /dev/null
67258+++ b/grsecurity/gracl_ip.c
67259@@ -0,0 +1,386 @@
67260+#include <linux/kernel.h>
67261+#include <asm/uaccess.h>
67262+#include <asm/errno.h>
67263+#include <net/sock.h>
67264+#include <linux/file.h>
67265+#include <linux/fs.h>
67266+#include <linux/net.h>
67267+#include <linux/in.h>
67268+#include <linux/skbuff.h>
67269+#include <linux/ip.h>
67270+#include <linux/udp.h>
67271+#include <linux/types.h>
67272+#include <linux/sched.h>
67273+#include <linux/netdevice.h>
67274+#include <linux/inetdevice.h>
67275+#include <linux/gracl.h>
67276+#include <linux/grsecurity.h>
67277+#include <linux/grinternal.h>
67278+
67279+#define GR_BIND 0x01
67280+#define GR_CONNECT 0x02
67281+#define GR_INVERT 0x04
67282+#define GR_BINDOVERRIDE 0x08
67283+#define GR_CONNECTOVERRIDE 0x10
67284+#define GR_SOCK_FAMILY 0x20
67285+
67286+static const char * gr_protocols[IPPROTO_MAX] = {
67287+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67288+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67289+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67290+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67291+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67292+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67293+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67294+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67295+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67296+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67297+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67298+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67299+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67300+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67301+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67302+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67303+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67304+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67305+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67306+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67307+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67308+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67309+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67310+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67311+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67312+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67313+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67314+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67315+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67316+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67317+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67318+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67319+ };
67320+
67321+static const char * gr_socktypes[SOCK_MAX] = {
67322+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67323+ "unknown:7", "unknown:8", "unknown:9", "packet"
67324+ };
67325+
67326+static const char * gr_sockfamilies[AF_MAX+1] = {
67327+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67328+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67329+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67330+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67331+ };
67332+
67333+const char *
67334+gr_proto_to_name(unsigned char proto)
67335+{
67336+ return gr_protocols[proto];
67337+}
67338+
67339+const char *
67340+gr_socktype_to_name(unsigned char type)
67341+{
67342+ return gr_socktypes[type];
67343+}
67344+
67345+const char *
67346+gr_sockfamily_to_name(unsigned char family)
67347+{
67348+ return gr_sockfamilies[family];
67349+}
67350+
67351+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67352+
67353+int
67354+gr_search_socket(const int domain, const int type, const int protocol)
67355+{
67356+ struct acl_subject_label *curr;
67357+ const struct cred *cred = current_cred();
67358+
67359+ if (unlikely(!gr_acl_is_enabled()))
67360+ goto exit;
67361+
67362+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67363+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67364+ goto exit; // let the kernel handle it
67365+
67366+ curr = current->acl;
67367+
67368+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67369+ /* the family is allowed, if this is PF_INET allow it only if
67370+ the extra sock type/protocol checks pass */
67371+ if (domain == PF_INET)
67372+ goto inet_check;
67373+ goto exit;
67374+ } else {
67375+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67376+ __u32 fakeip = 0;
67377+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67378+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67379+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67380+ gr_to_filename(current->exec_file->f_path.dentry,
67381+ current->exec_file->f_path.mnt) :
67382+ curr->filename, curr->filename,
67383+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67384+ &current->signal->saved_ip);
67385+ goto exit;
67386+ }
67387+ goto exit_fail;
67388+ }
67389+
67390+inet_check:
67391+ /* the rest of this checking is for IPv4 only */
67392+ if (!curr->ips)
67393+ goto exit;
67394+
67395+ if ((curr->ip_type & (1U << type)) &&
67396+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67397+ goto exit;
67398+
67399+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67400+ /* we don't place acls on raw sockets , and sometimes
67401+ dgram/ip sockets are opened for ioctl and not
67402+ bind/connect, so we'll fake a bind learn log */
67403+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67404+ __u32 fakeip = 0;
67405+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67406+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67407+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67408+ gr_to_filename(current->exec_file->f_path.dentry,
67409+ current->exec_file->f_path.mnt) :
67410+ curr->filename, curr->filename,
67411+ &fakeip, 0, type,
67412+ protocol, GR_CONNECT, &current->signal->saved_ip);
67413+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67414+ __u32 fakeip = 0;
67415+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67416+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67417+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67418+ gr_to_filename(current->exec_file->f_path.dentry,
67419+ current->exec_file->f_path.mnt) :
67420+ curr->filename, curr->filename,
67421+ &fakeip, 0, type,
67422+ protocol, GR_BIND, &current->signal->saved_ip);
67423+ }
67424+ /* we'll log when they use connect or bind */
67425+ goto exit;
67426+ }
67427+
67428+exit_fail:
67429+ if (domain == PF_INET)
67430+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67431+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67432+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67433+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67434+ gr_socktype_to_name(type), protocol);
67435+
67436+ return 0;
67437+exit:
67438+ return 1;
67439+}
67440+
67441+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)
67442+{
67443+ if ((ip->mode & mode) &&
67444+ (ip_port >= ip->low) &&
67445+ (ip_port <= ip->high) &&
67446+ ((ntohl(ip_addr) & our_netmask) ==
67447+ (ntohl(our_addr) & our_netmask))
67448+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67449+ && (ip->type & (1U << type))) {
67450+ if (ip->mode & GR_INVERT)
67451+ return 2; // specifically denied
67452+ else
67453+ return 1; // allowed
67454+ }
67455+
67456+ return 0; // not specifically allowed, may continue parsing
67457+}
67458+
67459+static int
67460+gr_search_connectbind(const int full_mode, struct sock *sk,
67461+ struct sockaddr_in *addr, const int type)
67462+{
67463+ char iface[IFNAMSIZ] = {0};
67464+ struct acl_subject_label *curr;
67465+ struct acl_ip_label *ip;
67466+ struct inet_sock *isk;
67467+ struct net_device *dev;
67468+ struct in_device *idev;
67469+ unsigned long i;
67470+ int ret;
67471+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67472+ __u32 ip_addr = 0;
67473+ __u32 our_addr;
67474+ __u32 our_netmask;
67475+ char *p;
67476+ __u16 ip_port = 0;
67477+ const struct cred *cred = current_cred();
67478+
67479+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67480+ return 0;
67481+
67482+ curr = current->acl;
67483+ isk = inet_sk(sk);
67484+
67485+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67486+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67487+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67488+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67489+ struct sockaddr_in saddr;
67490+ int err;
67491+
67492+ saddr.sin_family = AF_INET;
67493+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67494+ saddr.sin_port = isk->inet_sport;
67495+
67496+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67497+ if (err)
67498+ return err;
67499+
67500+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67501+ if (err)
67502+ return err;
67503+ }
67504+
67505+ if (!curr->ips)
67506+ return 0;
67507+
67508+ ip_addr = addr->sin_addr.s_addr;
67509+ ip_port = ntohs(addr->sin_port);
67510+
67511+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67512+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67513+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67514+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67515+ gr_to_filename(current->exec_file->f_path.dentry,
67516+ current->exec_file->f_path.mnt) :
67517+ curr->filename, curr->filename,
67518+ &ip_addr, ip_port, type,
67519+ sk->sk_protocol, mode, &current->signal->saved_ip);
67520+ return 0;
67521+ }
67522+
67523+ for (i = 0; i < curr->ip_num; i++) {
67524+ ip = *(curr->ips + i);
67525+ if (ip->iface != NULL) {
67526+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67527+ p = strchr(iface, ':');
67528+ if (p != NULL)
67529+ *p = '\0';
67530+ dev = dev_get_by_name(sock_net(sk), iface);
67531+ if (dev == NULL)
67532+ continue;
67533+ idev = in_dev_get(dev);
67534+ if (idev == NULL) {
67535+ dev_put(dev);
67536+ continue;
67537+ }
67538+ rcu_read_lock();
67539+ for_ifa(idev) {
67540+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67541+ our_addr = ifa->ifa_address;
67542+ our_netmask = 0xffffffff;
67543+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67544+ if (ret == 1) {
67545+ rcu_read_unlock();
67546+ in_dev_put(idev);
67547+ dev_put(dev);
67548+ return 0;
67549+ } else if (ret == 2) {
67550+ rcu_read_unlock();
67551+ in_dev_put(idev);
67552+ dev_put(dev);
67553+ goto denied;
67554+ }
67555+ }
67556+ } endfor_ifa(idev);
67557+ rcu_read_unlock();
67558+ in_dev_put(idev);
67559+ dev_put(dev);
67560+ } else {
67561+ our_addr = ip->addr;
67562+ our_netmask = ip->netmask;
67563+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67564+ if (ret == 1)
67565+ return 0;
67566+ else if (ret == 2)
67567+ goto denied;
67568+ }
67569+ }
67570+
67571+denied:
67572+ if (mode == GR_BIND)
67573+ 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));
67574+ else if (mode == GR_CONNECT)
67575+ 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));
67576+
67577+ return -EACCES;
67578+}
67579+
67580+int
67581+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67582+{
67583+ /* always allow disconnection of dgram sockets with connect */
67584+ if (addr->sin_family == AF_UNSPEC)
67585+ return 0;
67586+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67587+}
67588+
67589+int
67590+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67591+{
67592+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67593+}
67594+
67595+int gr_search_listen(struct socket *sock)
67596+{
67597+ struct sock *sk = sock->sk;
67598+ struct sockaddr_in addr;
67599+
67600+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67601+ addr.sin_port = inet_sk(sk)->inet_sport;
67602+
67603+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67604+}
67605+
67606+int gr_search_accept(struct socket *sock)
67607+{
67608+ struct sock *sk = sock->sk;
67609+ struct sockaddr_in addr;
67610+
67611+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67612+ addr.sin_port = inet_sk(sk)->inet_sport;
67613+
67614+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67615+}
67616+
67617+int
67618+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67619+{
67620+ if (addr)
67621+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67622+ else {
67623+ struct sockaddr_in sin;
67624+ const struct inet_sock *inet = inet_sk(sk);
67625+
67626+ sin.sin_addr.s_addr = inet->inet_daddr;
67627+ sin.sin_port = inet->inet_dport;
67628+
67629+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67630+ }
67631+}
67632+
67633+int
67634+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67635+{
67636+ struct sockaddr_in sin;
67637+
67638+ if (unlikely(skb->len < sizeof (struct udphdr)))
67639+ return 0; // skip this packet
67640+
67641+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67642+ sin.sin_port = udp_hdr(skb)->source;
67643+
67644+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67645+}
67646diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67647new file mode 100644
67648index 0000000..25f54ef
67649--- /dev/null
67650+++ b/grsecurity/gracl_learn.c
67651@@ -0,0 +1,207 @@
67652+#include <linux/kernel.h>
67653+#include <linux/mm.h>
67654+#include <linux/sched.h>
67655+#include <linux/poll.h>
67656+#include <linux/string.h>
67657+#include <linux/file.h>
67658+#include <linux/types.h>
67659+#include <linux/vmalloc.h>
67660+#include <linux/grinternal.h>
67661+
67662+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67663+ size_t count, loff_t *ppos);
67664+extern int gr_acl_is_enabled(void);
67665+
67666+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67667+static int gr_learn_attached;
67668+
67669+/* use a 512k buffer */
67670+#define LEARN_BUFFER_SIZE (512 * 1024)
67671+
67672+static DEFINE_SPINLOCK(gr_learn_lock);
67673+static DEFINE_MUTEX(gr_learn_user_mutex);
67674+
67675+/* we need to maintain two buffers, so that the kernel context of grlearn
67676+ uses a semaphore around the userspace copying, and the other kernel contexts
67677+ use a spinlock when copying into the buffer, since they cannot sleep
67678+*/
67679+static char *learn_buffer;
67680+static char *learn_buffer_user;
67681+static int learn_buffer_len;
67682+static int learn_buffer_user_len;
67683+
67684+static ssize_t
67685+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67686+{
67687+ DECLARE_WAITQUEUE(wait, current);
67688+ ssize_t retval = 0;
67689+
67690+ add_wait_queue(&learn_wait, &wait);
67691+ set_current_state(TASK_INTERRUPTIBLE);
67692+ do {
67693+ mutex_lock(&gr_learn_user_mutex);
67694+ spin_lock(&gr_learn_lock);
67695+ if (learn_buffer_len)
67696+ break;
67697+ spin_unlock(&gr_learn_lock);
67698+ mutex_unlock(&gr_learn_user_mutex);
67699+ if (file->f_flags & O_NONBLOCK) {
67700+ retval = -EAGAIN;
67701+ goto out;
67702+ }
67703+ if (signal_pending(current)) {
67704+ retval = -ERESTARTSYS;
67705+ goto out;
67706+ }
67707+
67708+ schedule();
67709+ } while (1);
67710+
67711+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67712+ learn_buffer_user_len = learn_buffer_len;
67713+ retval = learn_buffer_len;
67714+ learn_buffer_len = 0;
67715+
67716+ spin_unlock(&gr_learn_lock);
67717+
67718+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67719+ retval = -EFAULT;
67720+
67721+ mutex_unlock(&gr_learn_user_mutex);
67722+out:
67723+ set_current_state(TASK_RUNNING);
67724+ remove_wait_queue(&learn_wait, &wait);
67725+ return retval;
67726+}
67727+
67728+static unsigned int
67729+poll_learn(struct file * file, poll_table * wait)
67730+{
67731+ poll_wait(file, &learn_wait, wait);
67732+
67733+ if (learn_buffer_len)
67734+ return (POLLIN | POLLRDNORM);
67735+
67736+ return 0;
67737+}
67738+
67739+void
67740+gr_clear_learn_entries(void)
67741+{
67742+ char *tmp;
67743+
67744+ mutex_lock(&gr_learn_user_mutex);
67745+ spin_lock(&gr_learn_lock);
67746+ tmp = learn_buffer;
67747+ learn_buffer = NULL;
67748+ spin_unlock(&gr_learn_lock);
67749+ if (tmp)
67750+ vfree(tmp);
67751+ if (learn_buffer_user != NULL) {
67752+ vfree(learn_buffer_user);
67753+ learn_buffer_user = NULL;
67754+ }
67755+ learn_buffer_len = 0;
67756+ mutex_unlock(&gr_learn_user_mutex);
67757+
67758+ return;
67759+}
67760+
67761+void
67762+gr_add_learn_entry(const char *fmt, ...)
67763+{
67764+ va_list args;
67765+ unsigned int len;
67766+
67767+ if (!gr_learn_attached)
67768+ return;
67769+
67770+ spin_lock(&gr_learn_lock);
67771+
67772+ /* leave a gap at the end so we know when it's "full" but don't have to
67773+ compute the exact length of the string we're trying to append
67774+ */
67775+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67776+ spin_unlock(&gr_learn_lock);
67777+ wake_up_interruptible(&learn_wait);
67778+ return;
67779+ }
67780+ if (learn_buffer == NULL) {
67781+ spin_unlock(&gr_learn_lock);
67782+ return;
67783+ }
67784+
67785+ va_start(args, fmt);
67786+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67787+ va_end(args);
67788+
67789+ learn_buffer_len += len + 1;
67790+
67791+ spin_unlock(&gr_learn_lock);
67792+ wake_up_interruptible(&learn_wait);
67793+
67794+ return;
67795+}
67796+
67797+static int
67798+open_learn(struct inode *inode, struct file *file)
67799+{
67800+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67801+ return -EBUSY;
67802+ if (file->f_mode & FMODE_READ) {
67803+ int retval = 0;
67804+ mutex_lock(&gr_learn_user_mutex);
67805+ if (learn_buffer == NULL)
67806+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67807+ if (learn_buffer_user == NULL)
67808+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67809+ if (learn_buffer == NULL) {
67810+ retval = -ENOMEM;
67811+ goto out_error;
67812+ }
67813+ if (learn_buffer_user == NULL) {
67814+ retval = -ENOMEM;
67815+ goto out_error;
67816+ }
67817+ learn_buffer_len = 0;
67818+ learn_buffer_user_len = 0;
67819+ gr_learn_attached = 1;
67820+out_error:
67821+ mutex_unlock(&gr_learn_user_mutex);
67822+ return retval;
67823+ }
67824+ return 0;
67825+}
67826+
67827+static int
67828+close_learn(struct inode *inode, struct file *file)
67829+{
67830+ if (file->f_mode & FMODE_READ) {
67831+ char *tmp = NULL;
67832+ mutex_lock(&gr_learn_user_mutex);
67833+ spin_lock(&gr_learn_lock);
67834+ tmp = learn_buffer;
67835+ learn_buffer = NULL;
67836+ spin_unlock(&gr_learn_lock);
67837+ if (tmp)
67838+ vfree(tmp);
67839+ if (learn_buffer_user != NULL) {
67840+ vfree(learn_buffer_user);
67841+ learn_buffer_user = NULL;
67842+ }
67843+ learn_buffer_len = 0;
67844+ learn_buffer_user_len = 0;
67845+ gr_learn_attached = 0;
67846+ mutex_unlock(&gr_learn_user_mutex);
67847+ }
67848+
67849+ return 0;
67850+}
67851+
67852+const struct file_operations grsec_fops = {
67853+ .read = read_learn,
67854+ .write = write_grsec_handler,
67855+ .open = open_learn,
67856+ .release = close_learn,
67857+ .poll = poll_learn,
67858+};
67859diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67860new file mode 100644
67861index 0000000..39645c9
67862--- /dev/null
67863+++ b/grsecurity/gracl_res.c
67864@@ -0,0 +1,68 @@
67865+#include <linux/kernel.h>
67866+#include <linux/sched.h>
67867+#include <linux/gracl.h>
67868+#include <linux/grinternal.h>
67869+
67870+static const char *restab_log[] = {
67871+ [RLIMIT_CPU] = "RLIMIT_CPU",
67872+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67873+ [RLIMIT_DATA] = "RLIMIT_DATA",
67874+ [RLIMIT_STACK] = "RLIMIT_STACK",
67875+ [RLIMIT_CORE] = "RLIMIT_CORE",
67876+ [RLIMIT_RSS] = "RLIMIT_RSS",
67877+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67878+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67879+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67880+ [RLIMIT_AS] = "RLIMIT_AS",
67881+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67882+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67883+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67884+ [RLIMIT_NICE] = "RLIMIT_NICE",
67885+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67886+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67887+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67888+};
67889+
67890+void
67891+gr_log_resource(const struct task_struct *task,
67892+ const int res, const unsigned long wanted, const int gt)
67893+{
67894+ const struct cred *cred;
67895+ unsigned long rlim;
67896+
67897+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67898+ return;
67899+
67900+ // not yet supported resource
67901+ if (unlikely(!restab_log[res]))
67902+ return;
67903+
67904+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67905+ rlim = task_rlimit_max(task, res);
67906+ else
67907+ rlim = task_rlimit(task, res);
67908+
67909+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67910+ return;
67911+
67912+ rcu_read_lock();
67913+ cred = __task_cred(task);
67914+
67915+ if (res == RLIMIT_NPROC &&
67916+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67917+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67918+ goto out_rcu_unlock;
67919+ else if (res == RLIMIT_MEMLOCK &&
67920+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67921+ goto out_rcu_unlock;
67922+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67923+ goto out_rcu_unlock;
67924+ rcu_read_unlock();
67925+
67926+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67927+
67928+ return;
67929+out_rcu_unlock:
67930+ rcu_read_unlock();
67931+ return;
67932+}
67933diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67934new file mode 100644
67935index 0000000..3c38bfe
67936--- /dev/null
67937+++ b/grsecurity/gracl_segv.c
67938@@ -0,0 +1,305 @@
67939+#include <linux/kernel.h>
67940+#include <linux/mm.h>
67941+#include <asm/uaccess.h>
67942+#include <asm/errno.h>
67943+#include <asm/mman.h>
67944+#include <net/sock.h>
67945+#include <linux/file.h>
67946+#include <linux/fs.h>
67947+#include <linux/net.h>
67948+#include <linux/in.h>
67949+#include <linux/slab.h>
67950+#include <linux/types.h>
67951+#include <linux/sched.h>
67952+#include <linux/timer.h>
67953+#include <linux/gracl.h>
67954+#include <linux/grsecurity.h>
67955+#include <linux/grinternal.h>
67956+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67957+#include <linux/magic.h>
67958+#include <linux/pagemap.h>
67959+#include "../fs/btrfs/async-thread.h"
67960+#include "../fs/btrfs/ctree.h"
67961+#include "../fs/btrfs/btrfs_inode.h"
67962+#endif
67963+
67964+static struct crash_uid *uid_set;
67965+static unsigned short uid_used;
67966+static DEFINE_SPINLOCK(gr_uid_lock);
67967+extern rwlock_t gr_inode_lock;
67968+extern struct acl_subject_label *
67969+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67970+ struct acl_role_label *role);
67971+
67972+static inline dev_t __get_dev(const struct dentry *dentry)
67973+{
67974+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67975+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67976+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67977+ else
67978+#endif
67979+ return dentry->d_sb->s_dev;
67980+}
67981+
67982+int
67983+gr_init_uidset(void)
67984+{
67985+ uid_set =
67986+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67987+ uid_used = 0;
67988+
67989+ return uid_set ? 1 : 0;
67990+}
67991+
67992+void
67993+gr_free_uidset(void)
67994+{
67995+ if (uid_set)
67996+ kfree(uid_set);
67997+
67998+ return;
67999+}
68000+
68001+int
68002+gr_find_uid(const uid_t uid)
68003+{
68004+ struct crash_uid *tmp = uid_set;
68005+ uid_t buid;
68006+ int low = 0, high = uid_used - 1, mid;
68007+
68008+ while (high >= low) {
68009+ mid = (low + high) >> 1;
68010+ buid = tmp[mid].uid;
68011+ if (buid == uid)
68012+ return mid;
68013+ if (buid > uid)
68014+ high = mid - 1;
68015+ if (buid < uid)
68016+ low = mid + 1;
68017+ }
68018+
68019+ return -1;
68020+}
68021+
68022+static __inline__ void
68023+gr_insertsort(void)
68024+{
68025+ unsigned short i, j;
68026+ struct crash_uid index;
68027+
68028+ for (i = 1; i < uid_used; i++) {
68029+ index = uid_set[i];
68030+ j = i;
68031+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68032+ uid_set[j] = uid_set[j - 1];
68033+ j--;
68034+ }
68035+ uid_set[j] = index;
68036+ }
68037+
68038+ return;
68039+}
68040+
68041+static __inline__ void
68042+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68043+{
68044+ int loc;
68045+ uid_t uid = GR_GLOBAL_UID(kuid);
68046+
68047+ if (uid_used == GR_UIDTABLE_MAX)
68048+ return;
68049+
68050+ loc = gr_find_uid(uid);
68051+
68052+ if (loc >= 0) {
68053+ uid_set[loc].expires = expires;
68054+ return;
68055+ }
68056+
68057+ uid_set[uid_used].uid = uid;
68058+ uid_set[uid_used].expires = expires;
68059+ uid_used++;
68060+
68061+ gr_insertsort();
68062+
68063+ return;
68064+}
68065+
68066+void
68067+gr_remove_uid(const unsigned short loc)
68068+{
68069+ unsigned short i;
68070+
68071+ for (i = loc + 1; i < uid_used; i++)
68072+ uid_set[i - 1] = uid_set[i];
68073+
68074+ uid_used--;
68075+
68076+ return;
68077+}
68078+
68079+int
68080+gr_check_crash_uid(const kuid_t kuid)
68081+{
68082+ int loc;
68083+ int ret = 0;
68084+ uid_t uid;
68085+
68086+ if (unlikely(!gr_acl_is_enabled()))
68087+ return 0;
68088+
68089+ uid = GR_GLOBAL_UID(kuid);
68090+
68091+ spin_lock(&gr_uid_lock);
68092+ loc = gr_find_uid(uid);
68093+
68094+ if (loc < 0)
68095+ goto out_unlock;
68096+
68097+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68098+ gr_remove_uid(loc);
68099+ else
68100+ ret = 1;
68101+
68102+out_unlock:
68103+ spin_unlock(&gr_uid_lock);
68104+ return ret;
68105+}
68106+
68107+static __inline__ int
68108+proc_is_setxid(const struct cred *cred)
68109+{
68110+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68111+ !uid_eq(cred->uid, cred->fsuid))
68112+ return 1;
68113+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68114+ !gid_eq(cred->gid, cred->fsgid))
68115+ return 1;
68116+
68117+ return 0;
68118+}
68119+
68120+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68121+
68122+void
68123+gr_handle_crash(struct task_struct *task, const int sig)
68124+{
68125+ struct acl_subject_label *curr;
68126+ struct task_struct *tsk, *tsk2;
68127+ const struct cred *cred;
68128+ const struct cred *cred2;
68129+
68130+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68131+ return;
68132+
68133+ if (unlikely(!gr_acl_is_enabled()))
68134+ return;
68135+
68136+ curr = task->acl;
68137+
68138+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68139+ return;
68140+
68141+ if (time_before_eq(curr->expires, get_seconds())) {
68142+ curr->expires = 0;
68143+ curr->crashes = 0;
68144+ }
68145+
68146+ curr->crashes++;
68147+
68148+ if (!curr->expires)
68149+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68150+
68151+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68152+ time_after(curr->expires, get_seconds())) {
68153+ rcu_read_lock();
68154+ cred = __task_cred(task);
68155+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68156+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68157+ spin_lock(&gr_uid_lock);
68158+ gr_insert_uid(cred->uid, curr->expires);
68159+ spin_unlock(&gr_uid_lock);
68160+ curr->expires = 0;
68161+ curr->crashes = 0;
68162+ read_lock(&tasklist_lock);
68163+ do_each_thread(tsk2, tsk) {
68164+ cred2 = __task_cred(tsk);
68165+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68166+ gr_fake_force_sig(SIGKILL, tsk);
68167+ } while_each_thread(tsk2, tsk);
68168+ read_unlock(&tasklist_lock);
68169+ } else {
68170+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68171+ read_lock(&tasklist_lock);
68172+ read_lock(&grsec_exec_file_lock);
68173+ do_each_thread(tsk2, tsk) {
68174+ if (likely(tsk != task)) {
68175+ // if this thread has the same subject as the one that triggered
68176+ // RES_CRASH and it's the same binary, kill it
68177+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68178+ gr_fake_force_sig(SIGKILL, tsk);
68179+ }
68180+ } while_each_thread(tsk2, tsk);
68181+ read_unlock(&grsec_exec_file_lock);
68182+ read_unlock(&tasklist_lock);
68183+ }
68184+ rcu_read_unlock();
68185+ }
68186+
68187+ return;
68188+}
68189+
68190+int
68191+gr_check_crash_exec(const struct file *filp)
68192+{
68193+ struct acl_subject_label *curr;
68194+
68195+ if (unlikely(!gr_acl_is_enabled()))
68196+ return 0;
68197+
68198+ read_lock(&gr_inode_lock);
68199+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68200+ __get_dev(filp->f_path.dentry),
68201+ current->role);
68202+ read_unlock(&gr_inode_lock);
68203+
68204+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68205+ (!curr->crashes && !curr->expires))
68206+ return 0;
68207+
68208+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68209+ time_after(curr->expires, get_seconds()))
68210+ return 1;
68211+ else if (time_before_eq(curr->expires, get_seconds())) {
68212+ curr->crashes = 0;
68213+ curr->expires = 0;
68214+ }
68215+
68216+ return 0;
68217+}
68218+
68219+void
68220+gr_handle_alertkill(struct task_struct *task)
68221+{
68222+ struct acl_subject_label *curracl;
68223+ __u32 curr_ip;
68224+ struct task_struct *p, *p2;
68225+
68226+ if (unlikely(!gr_acl_is_enabled()))
68227+ return;
68228+
68229+ curracl = task->acl;
68230+ curr_ip = task->signal->curr_ip;
68231+
68232+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68233+ read_lock(&tasklist_lock);
68234+ do_each_thread(p2, p) {
68235+ if (p->signal->curr_ip == curr_ip)
68236+ gr_fake_force_sig(SIGKILL, p);
68237+ } while_each_thread(p2, p);
68238+ read_unlock(&tasklist_lock);
68239+ } else if (curracl->mode & GR_KILLPROC)
68240+ gr_fake_force_sig(SIGKILL, task);
68241+
68242+ return;
68243+}
68244diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68245new file mode 100644
68246index 0000000..98011b0
68247--- /dev/null
68248+++ b/grsecurity/gracl_shm.c
68249@@ -0,0 +1,40 @@
68250+#include <linux/kernel.h>
68251+#include <linux/mm.h>
68252+#include <linux/sched.h>
68253+#include <linux/file.h>
68254+#include <linux/ipc.h>
68255+#include <linux/gracl.h>
68256+#include <linux/grsecurity.h>
68257+#include <linux/grinternal.h>
68258+
68259+int
68260+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68261+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68262+{
68263+ struct task_struct *task;
68264+
68265+ if (!gr_acl_is_enabled())
68266+ return 1;
68267+
68268+ rcu_read_lock();
68269+ read_lock(&tasklist_lock);
68270+
68271+ task = find_task_by_vpid(shm_cprid);
68272+
68273+ if (unlikely(!task))
68274+ task = find_task_by_vpid(shm_lapid);
68275+
68276+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68277+ (task_pid_nr(task) == shm_lapid)) &&
68278+ (task->acl->mode & GR_PROTSHM) &&
68279+ (task->acl != current->acl))) {
68280+ read_unlock(&tasklist_lock);
68281+ rcu_read_unlock();
68282+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68283+ return 0;
68284+ }
68285+ read_unlock(&tasklist_lock);
68286+ rcu_read_unlock();
68287+
68288+ return 1;
68289+}
68290diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68291new file mode 100644
68292index 0000000..bc0be01
68293--- /dev/null
68294+++ b/grsecurity/grsec_chdir.c
68295@@ -0,0 +1,19 @@
68296+#include <linux/kernel.h>
68297+#include <linux/sched.h>
68298+#include <linux/fs.h>
68299+#include <linux/file.h>
68300+#include <linux/grsecurity.h>
68301+#include <linux/grinternal.h>
68302+
68303+void
68304+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68305+{
68306+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68307+ if ((grsec_enable_chdir && grsec_enable_group &&
68308+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68309+ !grsec_enable_group)) {
68310+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68311+ }
68312+#endif
68313+ return;
68314+}
68315diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68316new file mode 100644
68317index 0000000..bd6e105
68318--- /dev/null
68319+++ b/grsecurity/grsec_chroot.c
68320@@ -0,0 +1,370 @@
68321+#include <linux/kernel.h>
68322+#include <linux/module.h>
68323+#include <linux/sched.h>
68324+#include <linux/file.h>
68325+#include <linux/fs.h>
68326+#include <linux/mount.h>
68327+#include <linux/types.h>
68328+#include "../fs/mount.h"
68329+#include <linux/grsecurity.h>
68330+#include <linux/grinternal.h>
68331+
68332+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68333+static int gr_init_ran;
68334+#endif
68335+
68336+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68337+{
68338+#ifdef CONFIG_GRKERNSEC
68339+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68340+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68341+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68342+ && gr_init_ran
68343+#endif
68344+ )
68345+ task->gr_is_chrooted = 1;
68346+ else {
68347+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68348+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68349+ gr_init_ran = 1;
68350+#endif
68351+ task->gr_is_chrooted = 0;
68352+ }
68353+
68354+ task->gr_chroot_dentry = path->dentry;
68355+#endif
68356+ return;
68357+}
68358+
68359+void gr_clear_chroot_entries(struct task_struct *task)
68360+{
68361+#ifdef CONFIG_GRKERNSEC
68362+ task->gr_is_chrooted = 0;
68363+ task->gr_chroot_dentry = NULL;
68364+#endif
68365+ return;
68366+}
68367+
68368+int
68369+gr_handle_chroot_unix(const pid_t pid)
68370+{
68371+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68372+ struct task_struct *p;
68373+
68374+ if (unlikely(!grsec_enable_chroot_unix))
68375+ return 1;
68376+
68377+ if (likely(!proc_is_chrooted(current)))
68378+ return 1;
68379+
68380+ rcu_read_lock();
68381+ read_lock(&tasklist_lock);
68382+ p = find_task_by_vpid_unrestricted(pid);
68383+ if (unlikely(p && !have_same_root(current, p))) {
68384+ read_unlock(&tasklist_lock);
68385+ rcu_read_unlock();
68386+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68387+ return 0;
68388+ }
68389+ read_unlock(&tasklist_lock);
68390+ rcu_read_unlock();
68391+#endif
68392+ return 1;
68393+}
68394+
68395+int
68396+gr_handle_chroot_nice(void)
68397+{
68398+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68399+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68400+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68401+ return -EPERM;
68402+ }
68403+#endif
68404+ return 0;
68405+}
68406+
68407+int
68408+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68409+{
68410+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68411+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68412+ && proc_is_chrooted(current)) {
68413+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68414+ return -EACCES;
68415+ }
68416+#endif
68417+ return 0;
68418+}
68419+
68420+int
68421+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68422+{
68423+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68424+ struct task_struct *p;
68425+ int ret = 0;
68426+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68427+ return ret;
68428+
68429+ read_lock(&tasklist_lock);
68430+ do_each_pid_task(pid, type, p) {
68431+ if (!have_same_root(current, p)) {
68432+ ret = 1;
68433+ goto out;
68434+ }
68435+ } while_each_pid_task(pid, type, p);
68436+out:
68437+ read_unlock(&tasklist_lock);
68438+ return ret;
68439+#endif
68440+ return 0;
68441+}
68442+
68443+int
68444+gr_pid_is_chrooted(struct task_struct *p)
68445+{
68446+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68447+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68448+ return 0;
68449+
68450+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68451+ !have_same_root(current, p)) {
68452+ return 1;
68453+ }
68454+#endif
68455+ return 0;
68456+}
68457+
68458+EXPORT_SYMBOL(gr_pid_is_chrooted);
68459+
68460+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68461+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68462+{
68463+ struct path path, currentroot;
68464+ int ret = 0;
68465+
68466+ path.dentry = (struct dentry *)u_dentry;
68467+ path.mnt = (struct vfsmount *)u_mnt;
68468+ get_fs_root(current->fs, &currentroot);
68469+ if (path_is_under(&path, &currentroot))
68470+ ret = 1;
68471+ path_put(&currentroot);
68472+
68473+ return ret;
68474+}
68475+#endif
68476+
68477+int
68478+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68479+{
68480+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68481+ if (!grsec_enable_chroot_fchdir)
68482+ return 1;
68483+
68484+ if (!proc_is_chrooted(current))
68485+ return 1;
68486+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68487+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68488+ return 0;
68489+ }
68490+#endif
68491+ return 1;
68492+}
68493+
68494+int
68495+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68496+ const time_t shm_createtime)
68497+{
68498+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68499+ struct task_struct *p;
68500+ time_t starttime;
68501+
68502+ if (unlikely(!grsec_enable_chroot_shmat))
68503+ return 1;
68504+
68505+ if (likely(!proc_is_chrooted(current)))
68506+ return 1;
68507+
68508+ rcu_read_lock();
68509+ read_lock(&tasklist_lock);
68510+
68511+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68512+ starttime = p->start_time.tv_sec;
68513+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68514+ if (have_same_root(current, p)) {
68515+ goto allow;
68516+ } else {
68517+ read_unlock(&tasklist_lock);
68518+ rcu_read_unlock();
68519+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68520+ return 0;
68521+ }
68522+ }
68523+ /* creator exited, pid reuse, fall through to next check */
68524+ }
68525+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68526+ if (unlikely(!have_same_root(current, p))) {
68527+ read_unlock(&tasklist_lock);
68528+ rcu_read_unlock();
68529+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68530+ return 0;
68531+ }
68532+ }
68533+
68534+allow:
68535+ read_unlock(&tasklist_lock);
68536+ rcu_read_unlock();
68537+#endif
68538+ return 1;
68539+}
68540+
68541+void
68542+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68543+{
68544+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68545+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68546+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68547+#endif
68548+ return;
68549+}
68550+
68551+int
68552+gr_handle_chroot_mknod(const struct dentry *dentry,
68553+ const struct vfsmount *mnt, const int mode)
68554+{
68555+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68556+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68557+ proc_is_chrooted(current)) {
68558+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68559+ return -EPERM;
68560+ }
68561+#endif
68562+ return 0;
68563+}
68564+
68565+int
68566+gr_handle_chroot_mount(const struct dentry *dentry,
68567+ const struct vfsmount *mnt, const char *dev_name)
68568+{
68569+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68570+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68571+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68572+ return -EPERM;
68573+ }
68574+#endif
68575+ return 0;
68576+}
68577+
68578+int
68579+gr_handle_chroot_pivot(void)
68580+{
68581+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68582+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68583+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68584+ return -EPERM;
68585+ }
68586+#endif
68587+ return 0;
68588+}
68589+
68590+int
68591+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68592+{
68593+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68594+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68595+ !gr_is_outside_chroot(dentry, mnt)) {
68596+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68597+ return -EPERM;
68598+ }
68599+#endif
68600+ return 0;
68601+}
68602+
68603+extern const char *captab_log[];
68604+extern int captab_log_entries;
68605+
68606+int
68607+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68608+{
68609+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68610+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68611+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68612+ if (cap_raised(chroot_caps, cap)) {
68613+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68614+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68615+ }
68616+ return 0;
68617+ }
68618+ }
68619+#endif
68620+ return 1;
68621+}
68622+
68623+int
68624+gr_chroot_is_capable(const int cap)
68625+{
68626+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68627+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68628+#endif
68629+ return 1;
68630+}
68631+
68632+int
68633+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68634+{
68635+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68636+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68637+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68638+ if (cap_raised(chroot_caps, cap)) {
68639+ return 0;
68640+ }
68641+ }
68642+#endif
68643+ return 1;
68644+}
68645+
68646+int
68647+gr_chroot_is_capable_nolog(const int cap)
68648+{
68649+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68650+ return gr_task_chroot_is_capable_nolog(current, cap);
68651+#endif
68652+ return 1;
68653+}
68654+
68655+int
68656+gr_handle_chroot_sysctl(const int op)
68657+{
68658+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68659+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68660+ proc_is_chrooted(current))
68661+ return -EACCES;
68662+#endif
68663+ return 0;
68664+}
68665+
68666+void
68667+gr_handle_chroot_chdir(const struct path *path)
68668+{
68669+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68670+ if (grsec_enable_chroot_chdir)
68671+ set_fs_pwd(current->fs, path);
68672+#endif
68673+ return;
68674+}
68675+
68676+int
68677+gr_handle_chroot_chmod(const struct dentry *dentry,
68678+ const struct vfsmount *mnt, const int mode)
68679+{
68680+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68681+ /* allow chmod +s on directories, but not files */
68682+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68683+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68684+ proc_is_chrooted(current)) {
68685+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68686+ return -EPERM;
68687+ }
68688+#endif
68689+ return 0;
68690+}
68691diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68692new file mode 100644
68693index 0000000..ce65ceb
68694--- /dev/null
68695+++ b/grsecurity/grsec_disabled.c
68696@@ -0,0 +1,434 @@
68697+#include <linux/kernel.h>
68698+#include <linux/module.h>
68699+#include <linux/sched.h>
68700+#include <linux/file.h>
68701+#include <linux/fs.h>
68702+#include <linux/kdev_t.h>
68703+#include <linux/net.h>
68704+#include <linux/in.h>
68705+#include <linux/ip.h>
68706+#include <linux/skbuff.h>
68707+#include <linux/sysctl.h>
68708+
68709+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68710+void
68711+pax_set_initial_flags(struct linux_binprm *bprm)
68712+{
68713+ return;
68714+}
68715+#endif
68716+
68717+#ifdef CONFIG_SYSCTL
68718+__u32
68719+gr_handle_sysctl(const struct ctl_table * table, const int op)
68720+{
68721+ return 0;
68722+}
68723+#endif
68724+
68725+#ifdef CONFIG_TASKSTATS
68726+int gr_is_taskstats_denied(int pid)
68727+{
68728+ return 0;
68729+}
68730+#endif
68731+
68732+int
68733+gr_acl_is_enabled(void)
68734+{
68735+ return 0;
68736+}
68737+
68738+void
68739+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68740+{
68741+ return;
68742+}
68743+
68744+int
68745+gr_handle_rawio(const struct inode *inode)
68746+{
68747+ return 0;
68748+}
68749+
68750+void
68751+gr_acl_handle_psacct(struct task_struct *task, const long code)
68752+{
68753+ return;
68754+}
68755+
68756+int
68757+gr_handle_ptrace(struct task_struct *task, const long request)
68758+{
68759+ return 0;
68760+}
68761+
68762+int
68763+gr_handle_proc_ptrace(struct task_struct *task)
68764+{
68765+ return 0;
68766+}
68767+
68768+int
68769+gr_set_acls(const int type)
68770+{
68771+ return 0;
68772+}
68773+
68774+int
68775+gr_check_hidden_task(const struct task_struct *tsk)
68776+{
68777+ return 0;
68778+}
68779+
68780+int
68781+gr_check_protected_task(const struct task_struct *task)
68782+{
68783+ return 0;
68784+}
68785+
68786+int
68787+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68788+{
68789+ return 0;
68790+}
68791+
68792+void
68793+gr_copy_label(struct task_struct *tsk)
68794+{
68795+ return;
68796+}
68797+
68798+void
68799+gr_set_pax_flags(struct task_struct *task)
68800+{
68801+ return;
68802+}
68803+
68804+int
68805+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68806+ const int unsafe_share)
68807+{
68808+ return 0;
68809+}
68810+
68811+void
68812+gr_handle_delete(const ino_t ino, const dev_t dev)
68813+{
68814+ return;
68815+}
68816+
68817+void
68818+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68819+{
68820+ return;
68821+}
68822+
68823+void
68824+gr_handle_crash(struct task_struct *task, const int sig)
68825+{
68826+ return;
68827+}
68828+
68829+int
68830+gr_check_crash_exec(const struct file *filp)
68831+{
68832+ return 0;
68833+}
68834+
68835+int
68836+gr_check_crash_uid(const kuid_t uid)
68837+{
68838+ return 0;
68839+}
68840+
68841+void
68842+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68843+ struct dentry *old_dentry,
68844+ struct dentry *new_dentry,
68845+ struct vfsmount *mnt, const __u8 replace)
68846+{
68847+ return;
68848+}
68849+
68850+int
68851+gr_search_socket(const int family, const int type, const int protocol)
68852+{
68853+ return 1;
68854+}
68855+
68856+int
68857+gr_search_connectbind(const int mode, const struct socket *sock,
68858+ const struct sockaddr_in *addr)
68859+{
68860+ return 0;
68861+}
68862+
68863+void
68864+gr_handle_alertkill(struct task_struct *task)
68865+{
68866+ return;
68867+}
68868+
68869+__u32
68870+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68871+{
68872+ return 1;
68873+}
68874+
68875+__u32
68876+gr_acl_handle_hidden_file(const struct dentry * dentry,
68877+ const struct vfsmount * mnt)
68878+{
68879+ return 1;
68880+}
68881+
68882+__u32
68883+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68884+ int acc_mode)
68885+{
68886+ return 1;
68887+}
68888+
68889+__u32
68890+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68891+{
68892+ return 1;
68893+}
68894+
68895+__u32
68896+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68897+{
68898+ return 1;
68899+}
68900+
68901+int
68902+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68903+ unsigned int *vm_flags)
68904+{
68905+ return 1;
68906+}
68907+
68908+__u32
68909+gr_acl_handle_truncate(const struct dentry * dentry,
68910+ const struct vfsmount * mnt)
68911+{
68912+ return 1;
68913+}
68914+
68915+__u32
68916+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68917+{
68918+ return 1;
68919+}
68920+
68921+__u32
68922+gr_acl_handle_access(const struct dentry * dentry,
68923+ const struct vfsmount * mnt, const int fmode)
68924+{
68925+ return 1;
68926+}
68927+
68928+__u32
68929+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68930+ umode_t *mode)
68931+{
68932+ return 1;
68933+}
68934+
68935+__u32
68936+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68937+{
68938+ return 1;
68939+}
68940+
68941+__u32
68942+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68943+{
68944+ return 1;
68945+}
68946+
68947+void
68948+grsecurity_init(void)
68949+{
68950+ return;
68951+}
68952+
68953+umode_t gr_acl_umask(void)
68954+{
68955+ return 0;
68956+}
68957+
68958+__u32
68959+gr_acl_handle_mknod(const struct dentry * new_dentry,
68960+ const struct dentry * parent_dentry,
68961+ const struct vfsmount * parent_mnt,
68962+ const int mode)
68963+{
68964+ return 1;
68965+}
68966+
68967+__u32
68968+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68969+ const struct dentry * parent_dentry,
68970+ const struct vfsmount * parent_mnt)
68971+{
68972+ return 1;
68973+}
68974+
68975+__u32
68976+gr_acl_handle_symlink(const struct dentry * new_dentry,
68977+ const struct dentry * parent_dentry,
68978+ const struct vfsmount * parent_mnt, const struct filename *from)
68979+{
68980+ return 1;
68981+}
68982+
68983+__u32
68984+gr_acl_handle_link(const struct dentry * new_dentry,
68985+ const struct dentry * parent_dentry,
68986+ const struct vfsmount * parent_mnt,
68987+ const struct dentry * old_dentry,
68988+ const struct vfsmount * old_mnt, const struct filename *to)
68989+{
68990+ return 1;
68991+}
68992+
68993+int
68994+gr_acl_handle_rename(const struct dentry *new_dentry,
68995+ const struct dentry *parent_dentry,
68996+ const struct vfsmount *parent_mnt,
68997+ const struct dentry *old_dentry,
68998+ const struct inode *old_parent_inode,
68999+ const struct vfsmount *old_mnt, const struct filename *newname)
69000+{
69001+ return 0;
69002+}
69003+
69004+int
69005+gr_acl_handle_filldir(const struct file *file, const char *name,
69006+ const int namelen, const ino_t ino)
69007+{
69008+ return 1;
69009+}
69010+
69011+int
69012+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69013+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69014+{
69015+ return 1;
69016+}
69017+
69018+int
69019+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69020+{
69021+ return 0;
69022+}
69023+
69024+int
69025+gr_search_accept(const struct socket *sock)
69026+{
69027+ return 0;
69028+}
69029+
69030+int
69031+gr_search_listen(const struct socket *sock)
69032+{
69033+ return 0;
69034+}
69035+
69036+int
69037+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69038+{
69039+ return 0;
69040+}
69041+
69042+__u32
69043+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69044+{
69045+ return 1;
69046+}
69047+
69048+__u32
69049+gr_acl_handle_creat(const struct dentry * dentry,
69050+ const struct dentry * p_dentry,
69051+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69052+ const int imode)
69053+{
69054+ return 1;
69055+}
69056+
69057+void
69058+gr_acl_handle_exit(void)
69059+{
69060+ return;
69061+}
69062+
69063+int
69064+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69065+{
69066+ return 1;
69067+}
69068+
69069+void
69070+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69071+{
69072+ return;
69073+}
69074+
69075+int
69076+gr_acl_handle_procpidmem(const struct task_struct *task)
69077+{
69078+ return 0;
69079+}
69080+
69081+int
69082+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69083+{
69084+ return 0;
69085+}
69086+
69087+int
69088+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69089+{
69090+ return 0;
69091+}
69092+
69093+void
69094+gr_set_kernel_label(struct task_struct *task)
69095+{
69096+ return;
69097+}
69098+
69099+int
69100+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69101+{
69102+ return 0;
69103+}
69104+
69105+int
69106+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69107+{
69108+ return 0;
69109+}
69110+
69111+int gr_acl_enable_at_secure(void)
69112+{
69113+ return 0;
69114+}
69115+
69116+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69117+{
69118+ return dentry->d_sb->s_dev;
69119+}
69120+
69121+void gr_put_exec_file(struct task_struct *task)
69122+{
69123+ return;
69124+}
69125+
69126+EXPORT_SYMBOL(gr_set_kernel_label);
69127+#ifdef CONFIG_SECURITY
69128+EXPORT_SYMBOL(gr_check_user_change);
69129+EXPORT_SYMBOL(gr_check_group_change);
69130+#endif
69131diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69132new file mode 100644
69133index 0000000..387032b
69134--- /dev/null
69135+++ b/grsecurity/grsec_exec.c
69136@@ -0,0 +1,187 @@
69137+#include <linux/kernel.h>
69138+#include <linux/sched.h>
69139+#include <linux/file.h>
69140+#include <linux/binfmts.h>
69141+#include <linux/fs.h>
69142+#include <linux/types.h>
69143+#include <linux/grdefs.h>
69144+#include <linux/grsecurity.h>
69145+#include <linux/grinternal.h>
69146+#include <linux/capability.h>
69147+#include <linux/module.h>
69148+#include <linux/compat.h>
69149+
69150+#include <asm/uaccess.h>
69151+
69152+#ifdef CONFIG_GRKERNSEC_EXECLOG
69153+static char gr_exec_arg_buf[132];
69154+static DEFINE_MUTEX(gr_exec_arg_mutex);
69155+#endif
69156+
69157+struct user_arg_ptr {
69158+#ifdef CONFIG_COMPAT
69159+ bool is_compat;
69160+#endif
69161+ union {
69162+ const char __user *const __user *native;
69163+#ifdef CONFIG_COMPAT
69164+ const compat_uptr_t __user *compat;
69165+#endif
69166+ } ptr;
69167+};
69168+
69169+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69170+
69171+void
69172+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69173+{
69174+#ifdef CONFIG_GRKERNSEC_EXECLOG
69175+ char *grarg = gr_exec_arg_buf;
69176+ unsigned int i, x, execlen = 0;
69177+ char c;
69178+
69179+ if (!((grsec_enable_execlog && grsec_enable_group &&
69180+ in_group_p(grsec_audit_gid))
69181+ || (grsec_enable_execlog && !grsec_enable_group)))
69182+ return;
69183+
69184+ mutex_lock(&gr_exec_arg_mutex);
69185+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69186+
69187+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69188+ const char __user *p;
69189+ unsigned int len;
69190+
69191+ p = get_user_arg_ptr(argv, i);
69192+ if (IS_ERR(p))
69193+ goto log;
69194+
69195+ len = strnlen_user(p, 128 - execlen);
69196+ if (len > 128 - execlen)
69197+ len = 128 - execlen;
69198+ else if (len > 0)
69199+ len--;
69200+ if (copy_from_user(grarg + execlen, p, len))
69201+ goto log;
69202+
69203+ /* rewrite unprintable characters */
69204+ for (x = 0; x < len; x++) {
69205+ c = *(grarg + execlen + x);
69206+ if (c < 32 || c > 126)
69207+ *(grarg + execlen + x) = ' ';
69208+ }
69209+
69210+ execlen += len;
69211+ *(grarg + execlen) = ' ';
69212+ *(grarg + execlen + 1) = '\0';
69213+ execlen++;
69214+ }
69215+
69216+ log:
69217+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69218+ bprm->file->f_path.mnt, grarg);
69219+ mutex_unlock(&gr_exec_arg_mutex);
69220+#endif
69221+ return;
69222+}
69223+
69224+#ifdef CONFIG_GRKERNSEC
69225+extern int gr_acl_is_capable(const int cap);
69226+extern int gr_acl_is_capable_nolog(const int cap);
69227+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69228+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69229+extern int gr_chroot_is_capable(const int cap);
69230+extern int gr_chroot_is_capable_nolog(const int cap);
69231+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69232+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69233+#endif
69234+
69235+const char *captab_log[] = {
69236+ "CAP_CHOWN",
69237+ "CAP_DAC_OVERRIDE",
69238+ "CAP_DAC_READ_SEARCH",
69239+ "CAP_FOWNER",
69240+ "CAP_FSETID",
69241+ "CAP_KILL",
69242+ "CAP_SETGID",
69243+ "CAP_SETUID",
69244+ "CAP_SETPCAP",
69245+ "CAP_LINUX_IMMUTABLE",
69246+ "CAP_NET_BIND_SERVICE",
69247+ "CAP_NET_BROADCAST",
69248+ "CAP_NET_ADMIN",
69249+ "CAP_NET_RAW",
69250+ "CAP_IPC_LOCK",
69251+ "CAP_IPC_OWNER",
69252+ "CAP_SYS_MODULE",
69253+ "CAP_SYS_RAWIO",
69254+ "CAP_SYS_CHROOT",
69255+ "CAP_SYS_PTRACE",
69256+ "CAP_SYS_PACCT",
69257+ "CAP_SYS_ADMIN",
69258+ "CAP_SYS_BOOT",
69259+ "CAP_SYS_NICE",
69260+ "CAP_SYS_RESOURCE",
69261+ "CAP_SYS_TIME",
69262+ "CAP_SYS_TTY_CONFIG",
69263+ "CAP_MKNOD",
69264+ "CAP_LEASE",
69265+ "CAP_AUDIT_WRITE",
69266+ "CAP_AUDIT_CONTROL",
69267+ "CAP_SETFCAP",
69268+ "CAP_MAC_OVERRIDE",
69269+ "CAP_MAC_ADMIN",
69270+ "CAP_SYSLOG",
69271+ "CAP_WAKE_ALARM"
69272+};
69273+
69274+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69275+
69276+int gr_is_capable(const int cap)
69277+{
69278+#ifdef CONFIG_GRKERNSEC
69279+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69280+ return 1;
69281+ return 0;
69282+#else
69283+ return 1;
69284+#endif
69285+}
69286+
69287+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69288+{
69289+#ifdef CONFIG_GRKERNSEC
69290+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69291+ return 1;
69292+ return 0;
69293+#else
69294+ return 1;
69295+#endif
69296+}
69297+
69298+int gr_is_capable_nolog(const int cap)
69299+{
69300+#ifdef CONFIG_GRKERNSEC
69301+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69302+ return 1;
69303+ return 0;
69304+#else
69305+ return 1;
69306+#endif
69307+}
69308+
69309+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69310+{
69311+#ifdef CONFIG_GRKERNSEC
69312+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69313+ return 1;
69314+ return 0;
69315+#else
69316+ return 1;
69317+#endif
69318+}
69319+
69320+EXPORT_SYMBOL(gr_is_capable);
69321+EXPORT_SYMBOL(gr_is_capable_nolog);
69322+EXPORT_SYMBOL(gr_task_is_capable);
69323+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69324diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69325new file mode 100644
69326index 0000000..06cc6ea
69327--- /dev/null
69328+++ b/grsecurity/grsec_fifo.c
69329@@ -0,0 +1,24 @@
69330+#include <linux/kernel.h>
69331+#include <linux/sched.h>
69332+#include <linux/fs.h>
69333+#include <linux/file.h>
69334+#include <linux/grinternal.h>
69335+
69336+int
69337+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69338+ const struct dentry *dir, const int flag, const int acc_mode)
69339+{
69340+#ifdef CONFIG_GRKERNSEC_FIFO
69341+ const struct cred *cred = current_cred();
69342+
69343+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69344+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69345+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69346+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69347+ if (!inode_permission(dentry->d_inode, acc_mode))
69348+ 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));
69349+ return -EACCES;
69350+ }
69351+#endif
69352+ return 0;
69353+}
69354diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69355new file mode 100644
69356index 0000000..8ca18bf
69357--- /dev/null
69358+++ b/grsecurity/grsec_fork.c
69359@@ -0,0 +1,23 @@
69360+#include <linux/kernel.h>
69361+#include <linux/sched.h>
69362+#include <linux/grsecurity.h>
69363+#include <linux/grinternal.h>
69364+#include <linux/errno.h>
69365+
69366+void
69367+gr_log_forkfail(const int retval)
69368+{
69369+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69370+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69371+ switch (retval) {
69372+ case -EAGAIN:
69373+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69374+ break;
69375+ case -ENOMEM:
69376+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69377+ break;
69378+ }
69379+ }
69380+#endif
69381+ return;
69382+}
69383diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69384new file mode 100644
69385index 0000000..99a0cb9
69386--- /dev/null
69387+++ b/grsecurity/grsec_init.c
69388@@ -0,0 +1,283 @@
69389+#include <linux/kernel.h>
69390+#include <linux/sched.h>
69391+#include <linux/mm.h>
69392+#include <linux/gracl.h>
69393+#include <linux/slab.h>
69394+#include <linux/vmalloc.h>
69395+#include <linux/percpu.h>
69396+#include <linux/module.h>
69397+
69398+int grsec_enable_ptrace_readexec;
69399+int grsec_enable_setxid;
69400+int grsec_enable_symlinkown;
69401+kgid_t grsec_symlinkown_gid;
69402+int grsec_enable_brute;
69403+int grsec_enable_link;
69404+int grsec_enable_dmesg;
69405+int grsec_enable_harden_ptrace;
69406+int grsec_enable_fifo;
69407+int grsec_enable_execlog;
69408+int grsec_enable_signal;
69409+int grsec_enable_forkfail;
69410+int grsec_enable_audit_ptrace;
69411+int grsec_enable_time;
69412+int grsec_enable_group;
69413+kgid_t grsec_audit_gid;
69414+int grsec_enable_chdir;
69415+int grsec_enable_mount;
69416+int grsec_enable_rofs;
69417+int grsec_deny_new_usb;
69418+int grsec_enable_chroot_findtask;
69419+int grsec_enable_chroot_mount;
69420+int grsec_enable_chroot_shmat;
69421+int grsec_enable_chroot_fchdir;
69422+int grsec_enable_chroot_double;
69423+int grsec_enable_chroot_pivot;
69424+int grsec_enable_chroot_chdir;
69425+int grsec_enable_chroot_chmod;
69426+int grsec_enable_chroot_mknod;
69427+int grsec_enable_chroot_nice;
69428+int grsec_enable_chroot_execlog;
69429+int grsec_enable_chroot_caps;
69430+int grsec_enable_chroot_sysctl;
69431+int grsec_enable_chroot_unix;
69432+int grsec_enable_tpe;
69433+kgid_t grsec_tpe_gid;
69434+int grsec_enable_blackhole;
69435+#ifdef CONFIG_IPV6_MODULE
69436+EXPORT_SYMBOL(grsec_enable_blackhole);
69437+#endif
69438+int grsec_lastack_retries;
69439+int grsec_enable_tpe_all;
69440+int grsec_enable_tpe_invert;
69441+int grsec_enable_socket_all;
69442+kgid_t grsec_socket_all_gid;
69443+int grsec_enable_socket_client;
69444+kgid_t grsec_socket_client_gid;
69445+int grsec_enable_socket_server;
69446+kgid_t grsec_socket_server_gid;
69447+int grsec_resource_logging;
69448+int grsec_disable_privio;
69449+int grsec_enable_log_rwxmaps;
69450+int grsec_lock;
69451+
69452+DEFINE_SPINLOCK(grsec_alert_lock);
69453+unsigned long grsec_alert_wtime = 0;
69454+unsigned long grsec_alert_fyet = 0;
69455+
69456+DEFINE_SPINLOCK(grsec_audit_lock);
69457+
69458+DEFINE_RWLOCK(grsec_exec_file_lock);
69459+
69460+char *gr_shared_page[4];
69461+
69462+char *gr_alert_log_fmt;
69463+char *gr_audit_log_fmt;
69464+char *gr_alert_log_buf;
69465+char *gr_audit_log_buf;
69466+
69467+extern struct gr_arg *gr_usermode;
69468+extern unsigned char *gr_system_salt;
69469+extern unsigned char *gr_system_sum;
69470+
69471+void __init
69472+grsecurity_init(void)
69473+{
69474+ int j;
69475+ /* create the per-cpu shared pages */
69476+
69477+#ifdef CONFIG_X86
69478+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69479+#endif
69480+
69481+ for (j = 0; j < 4; j++) {
69482+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69483+ if (gr_shared_page[j] == NULL) {
69484+ panic("Unable to allocate grsecurity shared page");
69485+ return;
69486+ }
69487+ }
69488+
69489+ /* allocate log buffers */
69490+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69491+ if (!gr_alert_log_fmt) {
69492+ panic("Unable to allocate grsecurity alert log format buffer");
69493+ return;
69494+ }
69495+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69496+ if (!gr_audit_log_fmt) {
69497+ panic("Unable to allocate grsecurity audit log format buffer");
69498+ return;
69499+ }
69500+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69501+ if (!gr_alert_log_buf) {
69502+ panic("Unable to allocate grsecurity alert log buffer");
69503+ return;
69504+ }
69505+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69506+ if (!gr_audit_log_buf) {
69507+ panic("Unable to allocate grsecurity audit log buffer");
69508+ return;
69509+ }
69510+
69511+ /* allocate memory for authentication structure */
69512+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69513+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69514+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69515+
69516+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69517+ panic("Unable to allocate grsecurity authentication structure");
69518+ return;
69519+ }
69520+
69521+
69522+#ifdef CONFIG_GRKERNSEC_IO
69523+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69524+ grsec_disable_privio = 1;
69525+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69526+ grsec_disable_privio = 1;
69527+#else
69528+ grsec_disable_privio = 0;
69529+#endif
69530+#endif
69531+
69532+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69533+ /* for backward compatibility, tpe_invert always defaults to on if
69534+ enabled in the kernel
69535+ */
69536+ grsec_enable_tpe_invert = 1;
69537+#endif
69538+
69539+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69540+#ifndef CONFIG_GRKERNSEC_SYSCTL
69541+ grsec_lock = 1;
69542+#endif
69543+
69544+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69545+ grsec_enable_log_rwxmaps = 1;
69546+#endif
69547+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69548+ grsec_enable_group = 1;
69549+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69550+#endif
69551+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69552+ grsec_enable_ptrace_readexec = 1;
69553+#endif
69554+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69555+ grsec_enable_chdir = 1;
69556+#endif
69557+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69558+ grsec_enable_harden_ptrace = 1;
69559+#endif
69560+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69561+ grsec_enable_mount = 1;
69562+#endif
69563+#ifdef CONFIG_GRKERNSEC_LINK
69564+ grsec_enable_link = 1;
69565+#endif
69566+#ifdef CONFIG_GRKERNSEC_BRUTE
69567+ grsec_enable_brute = 1;
69568+#endif
69569+#ifdef CONFIG_GRKERNSEC_DMESG
69570+ grsec_enable_dmesg = 1;
69571+#endif
69572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69573+ grsec_enable_blackhole = 1;
69574+ grsec_lastack_retries = 4;
69575+#endif
69576+#ifdef CONFIG_GRKERNSEC_FIFO
69577+ grsec_enable_fifo = 1;
69578+#endif
69579+#ifdef CONFIG_GRKERNSEC_EXECLOG
69580+ grsec_enable_execlog = 1;
69581+#endif
69582+#ifdef CONFIG_GRKERNSEC_SETXID
69583+ grsec_enable_setxid = 1;
69584+#endif
69585+#ifdef CONFIG_GRKERNSEC_SIGNAL
69586+ grsec_enable_signal = 1;
69587+#endif
69588+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69589+ grsec_enable_forkfail = 1;
69590+#endif
69591+#ifdef CONFIG_GRKERNSEC_TIME
69592+ grsec_enable_time = 1;
69593+#endif
69594+#ifdef CONFIG_GRKERNSEC_RESLOG
69595+ grsec_resource_logging = 1;
69596+#endif
69597+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69598+ grsec_enable_chroot_findtask = 1;
69599+#endif
69600+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69601+ grsec_enable_chroot_unix = 1;
69602+#endif
69603+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69604+ grsec_enable_chroot_mount = 1;
69605+#endif
69606+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69607+ grsec_enable_chroot_fchdir = 1;
69608+#endif
69609+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69610+ grsec_enable_chroot_shmat = 1;
69611+#endif
69612+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69613+ grsec_enable_audit_ptrace = 1;
69614+#endif
69615+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69616+ grsec_enable_chroot_double = 1;
69617+#endif
69618+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69619+ grsec_enable_chroot_pivot = 1;
69620+#endif
69621+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69622+ grsec_enable_chroot_chdir = 1;
69623+#endif
69624+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69625+ grsec_enable_chroot_chmod = 1;
69626+#endif
69627+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69628+ grsec_enable_chroot_mknod = 1;
69629+#endif
69630+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69631+ grsec_enable_chroot_nice = 1;
69632+#endif
69633+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69634+ grsec_enable_chroot_execlog = 1;
69635+#endif
69636+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69637+ grsec_enable_chroot_caps = 1;
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69640+ grsec_enable_chroot_sysctl = 1;
69641+#endif
69642+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69643+ grsec_enable_symlinkown = 1;
69644+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69645+#endif
69646+#ifdef CONFIG_GRKERNSEC_TPE
69647+ grsec_enable_tpe = 1;
69648+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69649+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69650+ grsec_enable_tpe_all = 1;
69651+#endif
69652+#endif
69653+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69654+ grsec_enable_socket_all = 1;
69655+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69656+#endif
69657+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69658+ grsec_enable_socket_client = 1;
69659+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69660+#endif
69661+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69662+ grsec_enable_socket_server = 1;
69663+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69664+#endif
69665+#endif
69666+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69667+ grsec_deny_new_usb = 1;
69668+#endif
69669+
69670+ return;
69671+}
69672diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69673new file mode 100644
69674index 0000000..5e05e20
69675--- /dev/null
69676+++ b/grsecurity/grsec_link.c
69677@@ -0,0 +1,58 @@
69678+#include <linux/kernel.h>
69679+#include <linux/sched.h>
69680+#include <linux/fs.h>
69681+#include <linux/file.h>
69682+#include <linux/grinternal.h>
69683+
69684+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69685+{
69686+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69687+ const struct inode *link_inode = link->dentry->d_inode;
69688+
69689+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69690+ /* ignore root-owned links, e.g. /proc/self */
69691+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69692+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69693+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69694+ return 1;
69695+ }
69696+#endif
69697+ return 0;
69698+}
69699+
69700+int
69701+gr_handle_follow_link(const struct inode *parent,
69702+ const struct inode *inode,
69703+ const struct dentry *dentry, const struct vfsmount *mnt)
69704+{
69705+#ifdef CONFIG_GRKERNSEC_LINK
69706+ const struct cred *cred = current_cred();
69707+
69708+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69709+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69710+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69711+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69712+ return -EACCES;
69713+ }
69714+#endif
69715+ return 0;
69716+}
69717+
69718+int
69719+gr_handle_hardlink(const struct dentry *dentry,
69720+ const struct vfsmount *mnt,
69721+ struct inode *inode, const int mode, const struct filename *to)
69722+{
69723+#ifdef CONFIG_GRKERNSEC_LINK
69724+ const struct cred *cred = current_cred();
69725+
69726+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69727+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69728+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69729+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69730+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69731+ return -EPERM;
69732+ }
69733+#endif
69734+ return 0;
69735+}
69736diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69737new file mode 100644
69738index 0000000..dbe0a6b
69739--- /dev/null
69740+++ b/grsecurity/grsec_log.c
69741@@ -0,0 +1,341 @@
69742+#include <linux/kernel.h>
69743+#include <linux/sched.h>
69744+#include <linux/file.h>
69745+#include <linux/tty.h>
69746+#include <linux/fs.h>
69747+#include <linux/mm.h>
69748+#include <linux/grinternal.h>
69749+
69750+#ifdef CONFIG_TREE_PREEMPT_RCU
69751+#define DISABLE_PREEMPT() preempt_disable()
69752+#define ENABLE_PREEMPT() preempt_enable()
69753+#else
69754+#define DISABLE_PREEMPT()
69755+#define ENABLE_PREEMPT()
69756+#endif
69757+
69758+#define BEGIN_LOCKS(x) \
69759+ DISABLE_PREEMPT(); \
69760+ rcu_read_lock(); \
69761+ read_lock(&tasklist_lock); \
69762+ read_lock(&grsec_exec_file_lock); \
69763+ if (x != GR_DO_AUDIT) \
69764+ spin_lock(&grsec_alert_lock); \
69765+ else \
69766+ spin_lock(&grsec_audit_lock)
69767+
69768+#define END_LOCKS(x) \
69769+ if (x != GR_DO_AUDIT) \
69770+ spin_unlock(&grsec_alert_lock); \
69771+ else \
69772+ spin_unlock(&grsec_audit_lock); \
69773+ read_unlock(&grsec_exec_file_lock); \
69774+ read_unlock(&tasklist_lock); \
69775+ rcu_read_unlock(); \
69776+ ENABLE_PREEMPT(); \
69777+ if (x == GR_DONT_AUDIT) \
69778+ gr_handle_alertkill(current)
69779+
69780+enum {
69781+ FLOODING,
69782+ NO_FLOODING
69783+};
69784+
69785+extern char *gr_alert_log_fmt;
69786+extern char *gr_audit_log_fmt;
69787+extern char *gr_alert_log_buf;
69788+extern char *gr_audit_log_buf;
69789+
69790+static int gr_log_start(int audit)
69791+{
69792+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69793+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69794+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69795+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69796+ unsigned long curr_secs = get_seconds();
69797+
69798+ if (audit == GR_DO_AUDIT)
69799+ goto set_fmt;
69800+
69801+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69802+ grsec_alert_wtime = curr_secs;
69803+ grsec_alert_fyet = 0;
69804+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69805+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69806+ grsec_alert_fyet++;
69807+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69808+ grsec_alert_wtime = curr_secs;
69809+ grsec_alert_fyet++;
69810+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69811+ return FLOODING;
69812+ }
69813+ else return FLOODING;
69814+
69815+set_fmt:
69816+#endif
69817+ memset(buf, 0, PAGE_SIZE);
69818+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69819+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69820+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69821+ } else if (current->signal->curr_ip) {
69822+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69823+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69824+ } else if (gr_acl_is_enabled()) {
69825+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69826+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69827+ } else {
69828+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69829+ strcpy(buf, fmt);
69830+ }
69831+
69832+ return NO_FLOODING;
69833+}
69834+
69835+static void gr_log_middle(int audit, const char *msg, va_list ap)
69836+ __attribute__ ((format (printf, 2, 0)));
69837+
69838+static void gr_log_middle(int audit, const char *msg, va_list ap)
69839+{
69840+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69841+ unsigned int len = strlen(buf);
69842+
69843+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69844+
69845+ return;
69846+}
69847+
69848+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69849+ __attribute__ ((format (printf, 2, 3)));
69850+
69851+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69852+{
69853+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69854+ unsigned int len = strlen(buf);
69855+ va_list ap;
69856+
69857+ va_start(ap, msg);
69858+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69859+ va_end(ap);
69860+
69861+ return;
69862+}
69863+
69864+static void gr_log_end(int audit, int append_default)
69865+{
69866+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69867+ if (append_default) {
69868+ struct task_struct *task = current;
69869+ struct task_struct *parent = task->real_parent;
69870+ const struct cred *cred = __task_cred(task);
69871+ const struct cred *pcred = __task_cred(parent);
69872+ unsigned int len = strlen(buf);
69873+
69874+ 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));
69875+ }
69876+
69877+ printk("%s\n", buf);
69878+
69879+ return;
69880+}
69881+
69882+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69883+{
69884+ int logtype;
69885+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69886+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69887+ void *voidptr = NULL;
69888+ int num1 = 0, num2 = 0;
69889+ unsigned long ulong1 = 0, ulong2 = 0;
69890+ struct dentry *dentry = NULL;
69891+ struct vfsmount *mnt = NULL;
69892+ struct file *file = NULL;
69893+ struct task_struct *task = NULL;
69894+ struct vm_area_struct *vma = NULL;
69895+ const struct cred *cred, *pcred;
69896+ va_list ap;
69897+
69898+ BEGIN_LOCKS(audit);
69899+ logtype = gr_log_start(audit);
69900+ if (logtype == FLOODING) {
69901+ END_LOCKS(audit);
69902+ return;
69903+ }
69904+ va_start(ap, argtypes);
69905+ switch (argtypes) {
69906+ case GR_TTYSNIFF:
69907+ task = va_arg(ap, struct task_struct *);
69908+ 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));
69909+ break;
69910+ case GR_SYSCTL_HIDDEN:
69911+ str1 = va_arg(ap, char *);
69912+ gr_log_middle_varargs(audit, msg, result, str1);
69913+ break;
69914+ case GR_RBAC:
69915+ dentry = va_arg(ap, struct dentry *);
69916+ mnt = va_arg(ap, struct vfsmount *);
69917+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69918+ break;
69919+ case GR_RBAC_STR:
69920+ dentry = va_arg(ap, struct dentry *);
69921+ mnt = va_arg(ap, struct vfsmount *);
69922+ str1 = va_arg(ap, char *);
69923+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69924+ break;
69925+ case GR_STR_RBAC:
69926+ str1 = va_arg(ap, char *);
69927+ dentry = va_arg(ap, struct dentry *);
69928+ mnt = va_arg(ap, struct vfsmount *);
69929+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69930+ break;
69931+ case GR_RBAC_MODE2:
69932+ dentry = va_arg(ap, struct dentry *);
69933+ mnt = va_arg(ap, struct vfsmount *);
69934+ str1 = va_arg(ap, char *);
69935+ str2 = va_arg(ap, char *);
69936+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69937+ break;
69938+ case GR_RBAC_MODE3:
69939+ dentry = va_arg(ap, struct dentry *);
69940+ mnt = va_arg(ap, struct vfsmount *);
69941+ str1 = va_arg(ap, char *);
69942+ str2 = va_arg(ap, char *);
69943+ str3 = va_arg(ap, char *);
69944+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69945+ break;
69946+ case GR_FILENAME:
69947+ dentry = va_arg(ap, struct dentry *);
69948+ mnt = va_arg(ap, struct vfsmount *);
69949+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69950+ break;
69951+ case GR_STR_FILENAME:
69952+ str1 = va_arg(ap, char *);
69953+ dentry = va_arg(ap, struct dentry *);
69954+ mnt = va_arg(ap, struct vfsmount *);
69955+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69956+ break;
69957+ case GR_FILENAME_STR:
69958+ dentry = va_arg(ap, struct dentry *);
69959+ mnt = va_arg(ap, struct vfsmount *);
69960+ str1 = va_arg(ap, char *);
69961+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69962+ break;
69963+ case GR_FILENAME_TWO_INT:
69964+ dentry = va_arg(ap, struct dentry *);
69965+ mnt = va_arg(ap, struct vfsmount *);
69966+ num1 = va_arg(ap, int);
69967+ num2 = va_arg(ap, int);
69968+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69969+ break;
69970+ case GR_FILENAME_TWO_INT_STR:
69971+ dentry = va_arg(ap, struct dentry *);
69972+ mnt = va_arg(ap, struct vfsmount *);
69973+ num1 = va_arg(ap, int);
69974+ num2 = va_arg(ap, int);
69975+ str1 = va_arg(ap, char *);
69976+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69977+ break;
69978+ case GR_TEXTREL:
69979+ file = va_arg(ap, struct file *);
69980+ ulong1 = va_arg(ap, unsigned long);
69981+ ulong2 = va_arg(ap, unsigned long);
69982+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69983+ break;
69984+ case GR_PTRACE:
69985+ task = va_arg(ap, struct task_struct *);
69986+ 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));
69987+ break;
69988+ case GR_RESOURCE:
69989+ task = va_arg(ap, struct task_struct *);
69990+ cred = __task_cred(task);
69991+ pcred = __task_cred(task->real_parent);
69992+ ulong1 = va_arg(ap, unsigned long);
69993+ str1 = va_arg(ap, char *);
69994+ ulong2 = va_arg(ap, unsigned long);
69995+ 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));
69996+ break;
69997+ case GR_CAP:
69998+ task = va_arg(ap, struct task_struct *);
69999+ cred = __task_cred(task);
70000+ pcred = __task_cred(task->real_parent);
70001+ str1 = va_arg(ap, char *);
70002+ 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));
70003+ break;
70004+ case GR_SIG:
70005+ str1 = va_arg(ap, char *);
70006+ voidptr = va_arg(ap, void *);
70007+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70008+ break;
70009+ case GR_SIG2:
70010+ task = va_arg(ap, struct task_struct *);
70011+ cred = __task_cred(task);
70012+ pcred = __task_cred(task->real_parent);
70013+ num1 = va_arg(ap, int);
70014+ 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));
70015+ break;
70016+ case GR_CRASH1:
70017+ task = va_arg(ap, struct task_struct *);
70018+ cred = __task_cred(task);
70019+ pcred = __task_cred(task->real_parent);
70020+ ulong1 = va_arg(ap, unsigned long);
70021+ 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);
70022+ break;
70023+ case GR_CRASH2:
70024+ task = va_arg(ap, struct task_struct *);
70025+ cred = __task_cred(task);
70026+ pcred = __task_cred(task->real_parent);
70027+ ulong1 = va_arg(ap, unsigned long);
70028+ 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);
70029+ break;
70030+ case GR_RWXMAP:
70031+ file = va_arg(ap, struct file *);
70032+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70033+ break;
70034+ case GR_RWXMAPVMA:
70035+ vma = va_arg(ap, struct vm_area_struct *);
70036+ if (vma->vm_file)
70037+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70038+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70039+ str1 = "<stack>";
70040+ else if (vma->vm_start <= current->mm->brk &&
70041+ vma->vm_end >= current->mm->start_brk)
70042+ str1 = "<heap>";
70043+ else
70044+ str1 = "<anonymous mapping>";
70045+ gr_log_middle_varargs(audit, msg, str1);
70046+ break;
70047+ case GR_PSACCT:
70048+ {
70049+ unsigned int wday, cday;
70050+ __u8 whr, chr;
70051+ __u8 wmin, cmin;
70052+ __u8 wsec, csec;
70053+ char cur_tty[64] = { 0 };
70054+ char parent_tty[64] = { 0 };
70055+
70056+ task = va_arg(ap, struct task_struct *);
70057+ wday = va_arg(ap, unsigned int);
70058+ cday = va_arg(ap, unsigned int);
70059+ whr = va_arg(ap, int);
70060+ chr = va_arg(ap, int);
70061+ wmin = va_arg(ap, int);
70062+ cmin = va_arg(ap, int);
70063+ wsec = va_arg(ap, int);
70064+ csec = va_arg(ap, int);
70065+ ulong1 = va_arg(ap, unsigned long);
70066+ cred = __task_cred(task);
70067+ pcred = __task_cred(task->real_parent);
70068+
70069+ 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));
70070+ }
70071+ break;
70072+ default:
70073+ gr_log_middle(audit, msg, ap);
70074+ }
70075+ va_end(ap);
70076+ // these don't need DEFAULTSECARGS printed on the end
70077+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70078+ gr_log_end(audit, 0);
70079+ else
70080+ gr_log_end(audit, 1);
70081+ END_LOCKS(audit);
70082+}
70083diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70084new file mode 100644
70085index 0000000..f536303
70086--- /dev/null
70087+++ b/grsecurity/grsec_mem.c
70088@@ -0,0 +1,40 @@
70089+#include <linux/kernel.h>
70090+#include <linux/sched.h>
70091+#include <linux/mm.h>
70092+#include <linux/mman.h>
70093+#include <linux/grinternal.h>
70094+
70095+void
70096+gr_handle_ioperm(void)
70097+{
70098+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70099+ return;
70100+}
70101+
70102+void
70103+gr_handle_iopl(void)
70104+{
70105+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70106+ return;
70107+}
70108+
70109+void
70110+gr_handle_mem_readwrite(u64 from, u64 to)
70111+{
70112+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70113+ return;
70114+}
70115+
70116+void
70117+gr_handle_vm86(void)
70118+{
70119+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70120+ return;
70121+}
70122+
70123+void
70124+gr_log_badprocpid(const char *entry)
70125+{
70126+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70127+ return;
70128+}
70129diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70130new file mode 100644
70131index 0000000..2131422
70132--- /dev/null
70133+++ b/grsecurity/grsec_mount.c
70134@@ -0,0 +1,62 @@
70135+#include <linux/kernel.h>
70136+#include <linux/sched.h>
70137+#include <linux/mount.h>
70138+#include <linux/grsecurity.h>
70139+#include <linux/grinternal.h>
70140+
70141+void
70142+gr_log_remount(const char *devname, const int retval)
70143+{
70144+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70145+ if (grsec_enable_mount && (retval >= 0))
70146+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70147+#endif
70148+ return;
70149+}
70150+
70151+void
70152+gr_log_unmount(const char *devname, const int retval)
70153+{
70154+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70155+ if (grsec_enable_mount && (retval >= 0))
70156+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70157+#endif
70158+ return;
70159+}
70160+
70161+void
70162+gr_log_mount(const char *from, const char *to, const int retval)
70163+{
70164+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70165+ if (grsec_enable_mount && (retval >= 0))
70166+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70167+#endif
70168+ return;
70169+}
70170+
70171+int
70172+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70173+{
70174+#ifdef CONFIG_GRKERNSEC_ROFS
70175+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70176+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70177+ return -EPERM;
70178+ } else
70179+ return 0;
70180+#endif
70181+ return 0;
70182+}
70183+
70184+int
70185+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70186+{
70187+#ifdef CONFIG_GRKERNSEC_ROFS
70188+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70189+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70190+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70191+ return -EPERM;
70192+ } else
70193+ return 0;
70194+#endif
70195+ return 0;
70196+}
70197diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70198new file mode 100644
70199index 0000000..6ee9d50
70200--- /dev/null
70201+++ b/grsecurity/grsec_pax.c
70202@@ -0,0 +1,45 @@
70203+#include <linux/kernel.h>
70204+#include <linux/sched.h>
70205+#include <linux/mm.h>
70206+#include <linux/file.h>
70207+#include <linux/grinternal.h>
70208+#include <linux/grsecurity.h>
70209+
70210+void
70211+gr_log_textrel(struct vm_area_struct * vma)
70212+{
70213+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70214+ if (grsec_enable_log_rwxmaps)
70215+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70216+#endif
70217+ return;
70218+}
70219+
70220+void gr_log_ptgnustack(struct file *file)
70221+{
70222+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70223+ if (grsec_enable_log_rwxmaps)
70224+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70225+#endif
70226+ return;
70227+}
70228+
70229+void
70230+gr_log_rwxmmap(struct file *file)
70231+{
70232+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70233+ if (grsec_enable_log_rwxmaps)
70234+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70235+#endif
70236+ return;
70237+}
70238+
70239+void
70240+gr_log_rwxmprotect(struct vm_area_struct *vma)
70241+{
70242+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70243+ if (grsec_enable_log_rwxmaps)
70244+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70245+#endif
70246+ return;
70247+}
70248diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70249new file mode 100644
70250index 0000000..f7f29aa
70251--- /dev/null
70252+++ b/grsecurity/grsec_ptrace.c
70253@@ -0,0 +1,30 @@
70254+#include <linux/kernel.h>
70255+#include <linux/sched.h>
70256+#include <linux/grinternal.h>
70257+#include <linux/security.h>
70258+
70259+void
70260+gr_audit_ptrace(struct task_struct *task)
70261+{
70262+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70263+ if (grsec_enable_audit_ptrace)
70264+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70265+#endif
70266+ return;
70267+}
70268+
70269+int
70270+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70271+{
70272+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70273+ const struct dentry *dentry = file->f_path.dentry;
70274+ const struct vfsmount *mnt = file->f_path.mnt;
70275+
70276+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70277+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70278+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70279+ return -EACCES;
70280+ }
70281+#endif
70282+ return 0;
70283+}
70284diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70285new file mode 100644
70286index 0000000..4e29cc7
70287--- /dev/null
70288+++ b/grsecurity/grsec_sig.c
70289@@ -0,0 +1,246 @@
70290+#include <linux/kernel.h>
70291+#include <linux/sched.h>
70292+#include <linux/fs.h>
70293+#include <linux/delay.h>
70294+#include <linux/grsecurity.h>
70295+#include <linux/grinternal.h>
70296+#include <linux/hardirq.h>
70297+
70298+char *signames[] = {
70299+ [SIGSEGV] = "Segmentation fault",
70300+ [SIGILL] = "Illegal instruction",
70301+ [SIGABRT] = "Abort",
70302+ [SIGBUS] = "Invalid alignment/Bus error"
70303+};
70304+
70305+void
70306+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70307+{
70308+#ifdef CONFIG_GRKERNSEC_SIGNAL
70309+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70310+ (sig == SIGABRT) || (sig == SIGBUS))) {
70311+ if (task_pid_nr(t) == task_pid_nr(current)) {
70312+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70313+ } else {
70314+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70315+ }
70316+ }
70317+#endif
70318+ return;
70319+}
70320+
70321+int
70322+gr_handle_signal(const struct task_struct *p, const int sig)
70323+{
70324+#ifdef CONFIG_GRKERNSEC
70325+ /* ignore the 0 signal for protected task checks */
70326+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70327+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70328+ return -EPERM;
70329+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70330+ return -EPERM;
70331+ }
70332+#endif
70333+ return 0;
70334+}
70335+
70336+#ifdef CONFIG_GRKERNSEC
70337+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70338+
70339+int gr_fake_force_sig(int sig, struct task_struct *t)
70340+{
70341+ unsigned long int flags;
70342+ int ret, blocked, ignored;
70343+ struct k_sigaction *action;
70344+
70345+ spin_lock_irqsave(&t->sighand->siglock, flags);
70346+ action = &t->sighand->action[sig-1];
70347+ ignored = action->sa.sa_handler == SIG_IGN;
70348+ blocked = sigismember(&t->blocked, sig);
70349+ if (blocked || ignored) {
70350+ action->sa.sa_handler = SIG_DFL;
70351+ if (blocked) {
70352+ sigdelset(&t->blocked, sig);
70353+ recalc_sigpending_and_wake(t);
70354+ }
70355+ }
70356+ if (action->sa.sa_handler == SIG_DFL)
70357+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70358+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70359+
70360+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70361+
70362+ return ret;
70363+}
70364+#endif
70365+
70366+#ifdef CONFIG_GRKERNSEC_BRUTE
70367+#define GR_USER_BAN_TIME (15 * 60)
70368+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70369+
70370+static int __get_dumpable(unsigned long mm_flags)
70371+{
70372+ int ret;
70373+
70374+ ret = mm_flags & MMF_DUMPABLE_MASK;
70375+ return (ret >= 2) ? 2 : ret;
70376+}
70377+#endif
70378+
70379+void gr_handle_brute_attach(unsigned long mm_flags)
70380+{
70381+#ifdef CONFIG_GRKERNSEC_BRUTE
70382+ struct task_struct *p = current;
70383+ kuid_t uid = GLOBAL_ROOT_UID;
70384+ int daemon = 0;
70385+
70386+ if (!grsec_enable_brute)
70387+ return;
70388+
70389+ rcu_read_lock();
70390+ read_lock(&tasklist_lock);
70391+ read_lock(&grsec_exec_file_lock);
70392+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70393+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70394+ p->real_parent->brute = 1;
70395+ daemon = 1;
70396+ } else {
70397+ const struct cred *cred = __task_cred(p), *cred2;
70398+ struct task_struct *tsk, *tsk2;
70399+
70400+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70401+ struct user_struct *user;
70402+
70403+ uid = cred->uid;
70404+
70405+ /* this is put upon execution past expiration */
70406+ user = find_user(uid);
70407+ if (user == NULL)
70408+ goto unlock;
70409+ user->suid_banned = 1;
70410+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70411+ if (user->suid_ban_expires == ~0UL)
70412+ user->suid_ban_expires--;
70413+
70414+ /* only kill other threads of the same binary, from the same user */
70415+ do_each_thread(tsk2, tsk) {
70416+ cred2 = __task_cred(tsk);
70417+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70418+ gr_fake_force_sig(SIGKILL, tsk);
70419+ } while_each_thread(tsk2, tsk);
70420+ }
70421+ }
70422+unlock:
70423+ read_unlock(&grsec_exec_file_lock);
70424+ read_unlock(&tasklist_lock);
70425+ rcu_read_unlock();
70426+
70427+ if (gr_is_global_nonroot(uid))
70428+ 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);
70429+ else if (daemon)
70430+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70431+
70432+#endif
70433+ return;
70434+}
70435+
70436+void gr_handle_brute_check(void)
70437+{
70438+#ifdef CONFIG_GRKERNSEC_BRUTE
70439+ struct task_struct *p = current;
70440+
70441+ if (unlikely(p->brute)) {
70442+ if (!grsec_enable_brute)
70443+ p->brute = 0;
70444+ else if (time_before(get_seconds(), p->brute_expires))
70445+ msleep(30 * 1000);
70446+ }
70447+#endif
70448+ return;
70449+}
70450+
70451+void gr_handle_kernel_exploit(void)
70452+{
70453+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70454+ const struct cred *cred;
70455+ struct task_struct *tsk, *tsk2;
70456+ struct user_struct *user;
70457+ kuid_t uid;
70458+
70459+ if (in_irq() || in_serving_softirq() || in_nmi())
70460+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70461+
70462+ uid = current_uid();
70463+
70464+ if (gr_is_global_root(uid))
70465+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70466+ else {
70467+ /* kill all the processes of this user, hold a reference
70468+ to their creds struct, and prevent them from creating
70469+ another process until system reset
70470+ */
70471+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70472+ GR_GLOBAL_UID(uid));
70473+ /* we intentionally leak this ref */
70474+ user = get_uid(current->cred->user);
70475+ if (user)
70476+ user->kernel_banned = 1;
70477+
70478+ /* kill all processes of this user */
70479+ read_lock(&tasklist_lock);
70480+ do_each_thread(tsk2, tsk) {
70481+ cred = __task_cred(tsk);
70482+ if (uid_eq(cred->uid, uid))
70483+ gr_fake_force_sig(SIGKILL, tsk);
70484+ } while_each_thread(tsk2, tsk);
70485+ read_unlock(&tasklist_lock);
70486+ }
70487+#endif
70488+}
70489+
70490+#ifdef CONFIG_GRKERNSEC_BRUTE
70491+static bool suid_ban_expired(struct user_struct *user)
70492+{
70493+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70494+ user->suid_banned = 0;
70495+ user->suid_ban_expires = 0;
70496+ free_uid(user);
70497+ return true;
70498+ }
70499+
70500+ return false;
70501+}
70502+#endif
70503+
70504+int gr_process_kernel_exec_ban(void)
70505+{
70506+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70507+ if (unlikely(current->cred->user->kernel_banned))
70508+ return -EPERM;
70509+#endif
70510+ return 0;
70511+}
70512+
70513+int gr_process_kernel_setuid_ban(struct user_struct *user)
70514+{
70515+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70516+ if (unlikely(user->kernel_banned))
70517+ gr_fake_force_sig(SIGKILL, current);
70518+#endif
70519+ return 0;
70520+}
70521+
70522+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70523+{
70524+#ifdef CONFIG_GRKERNSEC_BRUTE
70525+ struct user_struct *user = current->cred->user;
70526+ if (unlikely(user->suid_banned)) {
70527+ if (suid_ban_expired(user))
70528+ return 0;
70529+ /* disallow execution of suid binaries only */
70530+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70531+ return -EPERM;
70532+ }
70533+#endif
70534+ return 0;
70535+}
70536diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70537new file mode 100644
70538index 0000000..4030d57
70539--- /dev/null
70540+++ b/grsecurity/grsec_sock.c
70541@@ -0,0 +1,244 @@
70542+#include <linux/kernel.h>
70543+#include <linux/module.h>
70544+#include <linux/sched.h>
70545+#include <linux/file.h>
70546+#include <linux/net.h>
70547+#include <linux/in.h>
70548+#include <linux/ip.h>
70549+#include <net/sock.h>
70550+#include <net/inet_sock.h>
70551+#include <linux/grsecurity.h>
70552+#include <linux/grinternal.h>
70553+#include <linux/gracl.h>
70554+
70555+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70556+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70557+
70558+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70559+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70560+
70561+#ifdef CONFIG_UNIX_MODULE
70562+EXPORT_SYMBOL(gr_acl_handle_unix);
70563+EXPORT_SYMBOL(gr_acl_handle_mknod);
70564+EXPORT_SYMBOL(gr_handle_chroot_unix);
70565+EXPORT_SYMBOL(gr_handle_create);
70566+#endif
70567+
70568+#ifdef CONFIG_GRKERNSEC
70569+#define gr_conn_table_size 32749
70570+struct conn_table_entry {
70571+ struct conn_table_entry *next;
70572+ struct signal_struct *sig;
70573+};
70574+
70575+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70576+DEFINE_SPINLOCK(gr_conn_table_lock);
70577+
70578+extern const char * gr_socktype_to_name(unsigned char type);
70579+extern const char * gr_proto_to_name(unsigned char proto);
70580+extern const char * gr_sockfamily_to_name(unsigned char family);
70581+
70582+static __inline__ int
70583+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70584+{
70585+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70586+}
70587+
70588+static __inline__ int
70589+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70590+ __u16 sport, __u16 dport)
70591+{
70592+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70593+ sig->gr_sport == sport && sig->gr_dport == dport))
70594+ return 1;
70595+ else
70596+ return 0;
70597+}
70598+
70599+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70600+{
70601+ struct conn_table_entry **match;
70602+ unsigned int index;
70603+
70604+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70605+ sig->gr_sport, sig->gr_dport,
70606+ gr_conn_table_size);
70607+
70608+ newent->sig = sig;
70609+
70610+ match = &gr_conn_table[index];
70611+ newent->next = *match;
70612+ *match = newent;
70613+
70614+ return;
70615+}
70616+
70617+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70618+{
70619+ struct conn_table_entry *match, *last = NULL;
70620+ unsigned int index;
70621+
70622+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70623+ sig->gr_sport, sig->gr_dport,
70624+ gr_conn_table_size);
70625+
70626+ match = gr_conn_table[index];
70627+ while (match && !conn_match(match->sig,
70628+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70629+ sig->gr_dport)) {
70630+ last = match;
70631+ match = match->next;
70632+ }
70633+
70634+ if (match) {
70635+ if (last)
70636+ last->next = match->next;
70637+ else
70638+ gr_conn_table[index] = NULL;
70639+ kfree(match);
70640+ }
70641+
70642+ return;
70643+}
70644+
70645+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70646+ __u16 sport, __u16 dport)
70647+{
70648+ struct conn_table_entry *match;
70649+ unsigned int index;
70650+
70651+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70652+
70653+ match = gr_conn_table[index];
70654+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70655+ match = match->next;
70656+
70657+ if (match)
70658+ return match->sig;
70659+ else
70660+ return NULL;
70661+}
70662+
70663+#endif
70664+
70665+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70666+{
70667+#ifdef CONFIG_GRKERNSEC
70668+ struct signal_struct *sig = task->signal;
70669+ struct conn_table_entry *newent;
70670+
70671+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70672+ if (newent == NULL)
70673+ return;
70674+ /* no bh lock needed since we are called with bh disabled */
70675+ spin_lock(&gr_conn_table_lock);
70676+ gr_del_task_from_ip_table_nolock(sig);
70677+ sig->gr_saddr = inet->inet_rcv_saddr;
70678+ sig->gr_daddr = inet->inet_daddr;
70679+ sig->gr_sport = inet->inet_sport;
70680+ sig->gr_dport = inet->inet_dport;
70681+ gr_add_to_task_ip_table_nolock(sig, newent);
70682+ spin_unlock(&gr_conn_table_lock);
70683+#endif
70684+ return;
70685+}
70686+
70687+void gr_del_task_from_ip_table(struct task_struct *task)
70688+{
70689+#ifdef CONFIG_GRKERNSEC
70690+ spin_lock_bh(&gr_conn_table_lock);
70691+ gr_del_task_from_ip_table_nolock(task->signal);
70692+ spin_unlock_bh(&gr_conn_table_lock);
70693+#endif
70694+ return;
70695+}
70696+
70697+void
70698+gr_attach_curr_ip(const struct sock *sk)
70699+{
70700+#ifdef CONFIG_GRKERNSEC
70701+ struct signal_struct *p, *set;
70702+ const struct inet_sock *inet = inet_sk(sk);
70703+
70704+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70705+ return;
70706+
70707+ set = current->signal;
70708+
70709+ spin_lock_bh(&gr_conn_table_lock);
70710+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70711+ inet->inet_dport, inet->inet_sport);
70712+ if (unlikely(p != NULL)) {
70713+ set->curr_ip = p->curr_ip;
70714+ set->used_accept = 1;
70715+ gr_del_task_from_ip_table_nolock(p);
70716+ spin_unlock_bh(&gr_conn_table_lock);
70717+ return;
70718+ }
70719+ spin_unlock_bh(&gr_conn_table_lock);
70720+
70721+ set->curr_ip = inet->inet_daddr;
70722+ set->used_accept = 1;
70723+#endif
70724+ return;
70725+}
70726+
70727+int
70728+gr_handle_sock_all(const int family, const int type, const int protocol)
70729+{
70730+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70731+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70732+ (family != AF_UNIX)) {
70733+ if (family == AF_INET)
70734+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70735+ else
70736+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70737+ return -EACCES;
70738+ }
70739+#endif
70740+ return 0;
70741+}
70742+
70743+int
70744+gr_handle_sock_server(const struct sockaddr *sck)
70745+{
70746+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70747+ if (grsec_enable_socket_server &&
70748+ in_group_p(grsec_socket_server_gid) &&
70749+ sck && (sck->sa_family != AF_UNIX) &&
70750+ (sck->sa_family != AF_LOCAL)) {
70751+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70752+ return -EACCES;
70753+ }
70754+#endif
70755+ return 0;
70756+}
70757+
70758+int
70759+gr_handle_sock_server_other(const struct sock *sck)
70760+{
70761+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70762+ if (grsec_enable_socket_server &&
70763+ in_group_p(grsec_socket_server_gid) &&
70764+ sck && (sck->sk_family != AF_UNIX) &&
70765+ (sck->sk_family != AF_LOCAL)) {
70766+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70767+ return -EACCES;
70768+ }
70769+#endif
70770+ return 0;
70771+}
70772+
70773+int
70774+gr_handle_sock_client(const struct sockaddr *sck)
70775+{
70776+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70777+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70778+ sck && (sck->sa_family != AF_UNIX) &&
70779+ (sck->sa_family != AF_LOCAL)) {
70780+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70781+ return -EACCES;
70782+ }
70783+#endif
70784+ return 0;
70785+}
70786diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70787new file mode 100644
70788index 0000000..a147ae7
70789--- /dev/null
70790+++ b/grsecurity/grsec_sysctl.c
70791@@ -0,0 +1,470 @@
70792+#include <linux/kernel.h>
70793+#include <linux/sched.h>
70794+#include <linux/sysctl.h>
70795+#include <linux/grsecurity.h>
70796+#include <linux/grinternal.h>
70797+
70798+int
70799+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70800+{
70801+#ifdef CONFIG_GRKERNSEC_SYSCTL
70802+ if (dirname == NULL || name == NULL)
70803+ return 0;
70804+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70805+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70806+ return -EACCES;
70807+ }
70808+#endif
70809+ return 0;
70810+}
70811+
70812+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70813+static int __maybe_unused __read_only one = 1;
70814+#endif
70815+
70816+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70817+ defined(CONFIG_GRKERNSEC_DENYUSB)
70818+struct ctl_table grsecurity_table[] = {
70819+#ifdef CONFIG_GRKERNSEC_SYSCTL
70820+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70821+#ifdef CONFIG_GRKERNSEC_IO
70822+ {
70823+ .procname = "disable_priv_io",
70824+ .data = &grsec_disable_privio,
70825+ .maxlen = sizeof(int),
70826+ .mode = 0600,
70827+ .proc_handler = &proc_dointvec,
70828+ },
70829+#endif
70830+#endif
70831+#ifdef CONFIG_GRKERNSEC_LINK
70832+ {
70833+ .procname = "linking_restrictions",
70834+ .data = &grsec_enable_link,
70835+ .maxlen = sizeof(int),
70836+ .mode = 0600,
70837+ .proc_handler = &proc_dointvec,
70838+ },
70839+#endif
70840+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70841+ {
70842+ .procname = "enforce_symlinksifowner",
70843+ .data = &grsec_enable_symlinkown,
70844+ .maxlen = sizeof(int),
70845+ .mode = 0600,
70846+ .proc_handler = &proc_dointvec,
70847+ },
70848+ {
70849+ .procname = "symlinkown_gid",
70850+ .data = &grsec_symlinkown_gid,
70851+ .maxlen = sizeof(int),
70852+ .mode = 0600,
70853+ .proc_handler = &proc_dointvec,
70854+ },
70855+#endif
70856+#ifdef CONFIG_GRKERNSEC_BRUTE
70857+ {
70858+ .procname = "deter_bruteforce",
70859+ .data = &grsec_enable_brute,
70860+ .maxlen = sizeof(int),
70861+ .mode = 0600,
70862+ .proc_handler = &proc_dointvec,
70863+ },
70864+#endif
70865+#ifdef CONFIG_GRKERNSEC_FIFO
70866+ {
70867+ .procname = "fifo_restrictions",
70868+ .data = &grsec_enable_fifo,
70869+ .maxlen = sizeof(int),
70870+ .mode = 0600,
70871+ .proc_handler = &proc_dointvec,
70872+ },
70873+#endif
70874+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70875+ {
70876+ .procname = "ptrace_readexec",
70877+ .data = &grsec_enable_ptrace_readexec,
70878+ .maxlen = sizeof(int),
70879+ .mode = 0600,
70880+ .proc_handler = &proc_dointvec,
70881+ },
70882+#endif
70883+#ifdef CONFIG_GRKERNSEC_SETXID
70884+ {
70885+ .procname = "consistent_setxid",
70886+ .data = &grsec_enable_setxid,
70887+ .maxlen = sizeof(int),
70888+ .mode = 0600,
70889+ .proc_handler = &proc_dointvec,
70890+ },
70891+#endif
70892+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70893+ {
70894+ .procname = "ip_blackhole",
70895+ .data = &grsec_enable_blackhole,
70896+ .maxlen = sizeof(int),
70897+ .mode = 0600,
70898+ .proc_handler = &proc_dointvec,
70899+ },
70900+ {
70901+ .procname = "lastack_retries",
70902+ .data = &grsec_lastack_retries,
70903+ .maxlen = sizeof(int),
70904+ .mode = 0600,
70905+ .proc_handler = &proc_dointvec,
70906+ },
70907+#endif
70908+#ifdef CONFIG_GRKERNSEC_EXECLOG
70909+ {
70910+ .procname = "exec_logging",
70911+ .data = &grsec_enable_execlog,
70912+ .maxlen = sizeof(int),
70913+ .mode = 0600,
70914+ .proc_handler = &proc_dointvec,
70915+ },
70916+#endif
70917+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70918+ {
70919+ .procname = "rwxmap_logging",
70920+ .data = &grsec_enable_log_rwxmaps,
70921+ .maxlen = sizeof(int),
70922+ .mode = 0600,
70923+ .proc_handler = &proc_dointvec,
70924+ },
70925+#endif
70926+#ifdef CONFIG_GRKERNSEC_SIGNAL
70927+ {
70928+ .procname = "signal_logging",
70929+ .data = &grsec_enable_signal,
70930+ .maxlen = sizeof(int),
70931+ .mode = 0600,
70932+ .proc_handler = &proc_dointvec,
70933+ },
70934+#endif
70935+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70936+ {
70937+ .procname = "forkfail_logging",
70938+ .data = &grsec_enable_forkfail,
70939+ .maxlen = sizeof(int),
70940+ .mode = 0600,
70941+ .proc_handler = &proc_dointvec,
70942+ },
70943+#endif
70944+#ifdef CONFIG_GRKERNSEC_TIME
70945+ {
70946+ .procname = "timechange_logging",
70947+ .data = &grsec_enable_time,
70948+ .maxlen = sizeof(int),
70949+ .mode = 0600,
70950+ .proc_handler = &proc_dointvec,
70951+ },
70952+#endif
70953+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70954+ {
70955+ .procname = "chroot_deny_shmat",
70956+ .data = &grsec_enable_chroot_shmat,
70957+ .maxlen = sizeof(int),
70958+ .mode = 0600,
70959+ .proc_handler = &proc_dointvec,
70960+ },
70961+#endif
70962+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70963+ {
70964+ .procname = "chroot_deny_unix",
70965+ .data = &grsec_enable_chroot_unix,
70966+ .maxlen = sizeof(int),
70967+ .mode = 0600,
70968+ .proc_handler = &proc_dointvec,
70969+ },
70970+#endif
70971+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70972+ {
70973+ .procname = "chroot_deny_mount",
70974+ .data = &grsec_enable_chroot_mount,
70975+ .maxlen = sizeof(int),
70976+ .mode = 0600,
70977+ .proc_handler = &proc_dointvec,
70978+ },
70979+#endif
70980+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70981+ {
70982+ .procname = "chroot_deny_fchdir",
70983+ .data = &grsec_enable_chroot_fchdir,
70984+ .maxlen = sizeof(int),
70985+ .mode = 0600,
70986+ .proc_handler = &proc_dointvec,
70987+ },
70988+#endif
70989+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70990+ {
70991+ .procname = "chroot_deny_chroot",
70992+ .data = &grsec_enable_chroot_double,
70993+ .maxlen = sizeof(int),
70994+ .mode = 0600,
70995+ .proc_handler = &proc_dointvec,
70996+ },
70997+#endif
70998+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70999+ {
71000+ .procname = "chroot_deny_pivot",
71001+ .data = &grsec_enable_chroot_pivot,
71002+ .maxlen = sizeof(int),
71003+ .mode = 0600,
71004+ .proc_handler = &proc_dointvec,
71005+ },
71006+#endif
71007+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71008+ {
71009+ .procname = "chroot_enforce_chdir",
71010+ .data = &grsec_enable_chroot_chdir,
71011+ .maxlen = sizeof(int),
71012+ .mode = 0600,
71013+ .proc_handler = &proc_dointvec,
71014+ },
71015+#endif
71016+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71017+ {
71018+ .procname = "chroot_deny_chmod",
71019+ .data = &grsec_enable_chroot_chmod,
71020+ .maxlen = sizeof(int),
71021+ .mode = 0600,
71022+ .proc_handler = &proc_dointvec,
71023+ },
71024+#endif
71025+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71026+ {
71027+ .procname = "chroot_deny_mknod",
71028+ .data = &grsec_enable_chroot_mknod,
71029+ .maxlen = sizeof(int),
71030+ .mode = 0600,
71031+ .proc_handler = &proc_dointvec,
71032+ },
71033+#endif
71034+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71035+ {
71036+ .procname = "chroot_restrict_nice",
71037+ .data = &grsec_enable_chroot_nice,
71038+ .maxlen = sizeof(int),
71039+ .mode = 0600,
71040+ .proc_handler = &proc_dointvec,
71041+ },
71042+#endif
71043+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71044+ {
71045+ .procname = "chroot_execlog",
71046+ .data = &grsec_enable_chroot_execlog,
71047+ .maxlen = sizeof(int),
71048+ .mode = 0600,
71049+ .proc_handler = &proc_dointvec,
71050+ },
71051+#endif
71052+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71053+ {
71054+ .procname = "chroot_caps",
71055+ .data = &grsec_enable_chroot_caps,
71056+ .maxlen = sizeof(int),
71057+ .mode = 0600,
71058+ .proc_handler = &proc_dointvec,
71059+ },
71060+#endif
71061+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71062+ {
71063+ .procname = "chroot_deny_sysctl",
71064+ .data = &grsec_enable_chroot_sysctl,
71065+ .maxlen = sizeof(int),
71066+ .mode = 0600,
71067+ .proc_handler = &proc_dointvec,
71068+ },
71069+#endif
71070+#ifdef CONFIG_GRKERNSEC_TPE
71071+ {
71072+ .procname = "tpe",
71073+ .data = &grsec_enable_tpe,
71074+ .maxlen = sizeof(int),
71075+ .mode = 0600,
71076+ .proc_handler = &proc_dointvec,
71077+ },
71078+ {
71079+ .procname = "tpe_gid",
71080+ .data = &grsec_tpe_gid,
71081+ .maxlen = sizeof(int),
71082+ .mode = 0600,
71083+ .proc_handler = &proc_dointvec,
71084+ },
71085+#endif
71086+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71087+ {
71088+ .procname = "tpe_invert",
71089+ .data = &grsec_enable_tpe_invert,
71090+ .maxlen = sizeof(int),
71091+ .mode = 0600,
71092+ .proc_handler = &proc_dointvec,
71093+ },
71094+#endif
71095+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71096+ {
71097+ .procname = "tpe_restrict_all",
71098+ .data = &grsec_enable_tpe_all,
71099+ .maxlen = sizeof(int),
71100+ .mode = 0600,
71101+ .proc_handler = &proc_dointvec,
71102+ },
71103+#endif
71104+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71105+ {
71106+ .procname = "socket_all",
71107+ .data = &grsec_enable_socket_all,
71108+ .maxlen = sizeof(int),
71109+ .mode = 0600,
71110+ .proc_handler = &proc_dointvec,
71111+ },
71112+ {
71113+ .procname = "socket_all_gid",
71114+ .data = &grsec_socket_all_gid,
71115+ .maxlen = sizeof(int),
71116+ .mode = 0600,
71117+ .proc_handler = &proc_dointvec,
71118+ },
71119+#endif
71120+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71121+ {
71122+ .procname = "socket_client",
71123+ .data = &grsec_enable_socket_client,
71124+ .maxlen = sizeof(int),
71125+ .mode = 0600,
71126+ .proc_handler = &proc_dointvec,
71127+ },
71128+ {
71129+ .procname = "socket_client_gid",
71130+ .data = &grsec_socket_client_gid,
71131+ .maxlen = sizeof(int),
71132+ .mode = 0600,
71133+ .proc_handler = &proc_dointvec,
71134+ },
71135+#endif
71136+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71137+ {
71138+ .procname = "socket_server",
71139+ .data = &grsec_enable_socket_server,
71140+ .maxlen = sizeof(int),
71141+ .mode = 0600,
71142+ .proc_handler = &proc_dointvec,
71143+ },
71144+ {
71145+ .procname = "socket_server_gid",
71146+ .data = &grsec_socket_server_gid,
71147+ .maxlen = sizeof(int),
71148+ .mode = 0600,
71149+ .proc_handler = &proc_dointvec,
71150+ },
71151+#endif
71152+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71153+ {
71154+ .procname = "audit_group",
71155+ .data = &grsec_enable_group,
71156+ .maxlen = sizeof(int),
71157+ .mode = 0600,
71158+ .proc_handler = &proc_dointvec,
71159+ },
71160+ {
71161+ .procname = "audit_gid",
71162+ .data = &grsec_audit_gid,
71163+ .maxlen = sizeof(int),
71164+ .mode = 0600,
71165+ .proc_handler = &proc_dointvec,
71166+ },
71167+#endif
71168+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71169+ {
71170+ .procname = "audit_chdir",
71171+ .data = &grsec_enable_chdir,
71172+ .maxlen = sizeof(int),
71173+ .mode = 0600,
71174+ .proc_handler = &proc_dointvec,
71175+ },
71176+#endif
71177+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71178+ {
71179+ .procname = "audit_mount",
71180+ .data = &grsec_enable_mount,
71181+ .maxlen = sizeof(int),
71182+ .mode = 0600,
71183+ .proc_handler = &proc_dointvec,
71184+ },
71185+#endif
71186+#ifdef CONFIG_GRKERNSEC_DMESG
71187+ {
71188+ .procname = "dmesg",
71189+ .data = &grsec_enable_dmesg,
71190+ .maxlen = sizeof(int),
71191+ .mode = 0600,
71192+ .proc_handler = &proc_dointvec,
71193+ },
71194+#endif
71195+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71196+ {
71197+ .procname = "chroot_findtask",
71198+ .data = &grsec_enable_chroot_findtask,
71199+ .maxlen = sizeof(int),
71200+ .mode = 0600,
71201+ .proc_handler = &proc_dointvec,
71202+ },
71203+#endif
71204+#ifdef CONFIG_GRKERNSEC_RESLOG
71205+ {
71206+ .procname = "resource_logging",
71207+ .data = &grsec_resource_logging,
71208+ .maxlen = sizeof(int),
71209+ .mode = 0600,
71210+ .proc_handler = &proc_dointvec,
71211+ },
71212+#endif
71213+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71214+ {
71215+ .procname = "audit_ptrace",
71216+ .data = &grsec_enable_audit_ptrace,
71217+ .maxlen = sizeof(int),
71218+ .mode = 0600,
71219+ .proc_handler = &proc_dointvec,
71220+ },
71221+#endif
71222+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71223+ {
71224+ .procname = "harden_ptrace",
71225+ .data = &grsec_enable_harden_ptrace,
71226+ .maxlen = sizeof(int),
71227+ .mode = 0600,
71228+ .proc_handler = &proc_dointvec,
71229+ },
71230+#endif
71231+ {
71232+ .procname = "grsec_lock",
71233+ .data = &grsec_lock,
71234+ .maxlen = sizeof(int),
71235+ .mode = 0600,
71236+ .proc_handler = &proc_dointvec,
71237+ },
71238+#endif
71239+#ifdef CONFIG_GRKERNSEC_ROFS
71240+ {
71241+ .procname = "romount_protect",
71242+ .data = &grsec_enable_rofs,
71243+ .maxlen = sizeof(int),
71244+ .mode = 0600,
71245+ .proc_handler = &proc_dointvec_minmax,
71246+ .extra1 = &one,
71247+ .extra2 = &one,
71248+ },
71249+#endif
71250+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71251+ {
71252+ .procname = "deny_new_usb",
71253+ .data = &grsec_deny_new_usb,
71254+ .maxlen = sizeof(int),
71255+ .mode = 0600,
71256+ .proc_handler = &proc_dointvec,
71257+ },
71258+#endif
71259+ { }
71260+};
71261+#endif
71262diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71263new file mode 100644
71264index 0000000..0dc13c3
71265--- /dev/null
71266+++ b/grsecurity/grsec_time.c
71267@@ -0,0 +1,16 @@
71268+#include <linux/kernel.h>
71269+#include <linux/sched.h>
71270+#include <linux/grinternal.h>
71271+#include <linux/module.h>
71272+
71273+void
71274+gr_log_timechange(void)
71275+{
71276+#ifdef CONFIG_GRKERNSEC_TIME
71277+ if (grsec_enable_time)
71278+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71279+#endif
71280+ return;
71281+}
71282+
71283+EXPORT_SYMBOL(gr_log_timechange);
71284diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71285new file mode 100644
71286index 0000000..ee57dcf
71287--- /dev/null
71288+++ b/grsecurity/grsec_tpe.c
71289@@ -0,0 +1,73 @@
71290+#include <linux/kernel.h>
71291+#include <linux/sched.h>
71292+#include <linux/file.h>
71293+#include <linux/fs.h>
71294+#include <linux/grinternal.h>
71295+
71296+extern int gr_acl_tpe_check(void);
71297+
71298+int
71299+gr_tpe_allow(const struct file *file)
71300+{
71301+#ifdef CONFIG_GRKERNSEC
71302+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71303+ const struct cred *cred = current_cred();
71304+ char *msg = NULL;
71305+ char *msg2 = NULL;
71306+
71307+ // never restrict root
71308+ if (gr_is_global_root(cred->uid))
71309+ return 1;
71310+
71311+ if (grsec_enable_tpe) {
71312+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71313+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71314+ msg = "not being in trusted group";
71315+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71316+ msg = "being in untrusted group";
71317+#else
71318+ if (in_group_p(grsec_tpe_gid))
71319+ msg = "being in untrusted group";
71320+#endif
71321+ }
71322+ if (!msg && gr_acl_tpe_check())
71323+ msg = "being in untrusted role";
71324+
71325+ // not in any affected group/role
71326+ if (!msg)
71327+ goto next_check;
71328+
71329+ if (gr_is_global_nonroot(inode->i_uid))
71330+ msg2 = "file in non-root-owned directory";
71331+ else if (inode->i_mode & S_IWOTH)
71332+ msg2 = "file in world-writable directory";
71333+ else if (inode->i_mode & S_IWGRP)
71334+ msg2 = "file in group-writable directory";
71335+
71336+ if (msg && msg2) {
71337+ char fullmsg[70] = {0};
71338+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71339+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71340+ return 0;
71341+ }
71342+ msg = NULL;
71343+next_check:
71344+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71345+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71346+ return 1;
71347+
71348+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71349+ msg = "directory not owned by user";
71350+ else if (inode->i_mode & S_IWOTH)
71351+ msg = "file in world-writable directory";
71352+ else if (inode->i_mode & S_IWGRP)
71353+ msg = "file in group-writable directory";
71354+
71355+ if (msg) {
71356+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71357+ return 0;
71358+ }
71359+#endif
71360+#endif
71361+ return 1;
71362+}
71363diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71364new file mode 100644
71365index 0000000..ae02d8e
71366--- /dev/null
71367+++ b/grsecurity/grsec_usb.c
71368@@ -0,0 +1,15 @@
71369+#include <linux/kernel.h>
71370+#include <linux/grinternal.h>
71371+#include <linux/module.h>
71372+
71373+int gr_handle_new_usb(void)
71374+{
71375+#ifdef CONFIG_GRKERNSEC_DENYUSB
71376+ if (grsec_deny_new_usb) {
71377+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71378+ return 1;
71379+ }
71380+#endif
71381+ return 0;
71382+}
71383+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71384diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71385new file mode 100644
71386index 0000000..9f7b1ac
71387--- /dev/null
71388+++ b/grsecurity/grsum.c
71389@@ -0,0 +1,61 @@
71390+#include <linux/err.h>
71391+#include <linux/kernel.h>
71392+#include <linux/sched.h>
71393+#include <linux/mm.h>
71394+#include <linux/scatterlist.h>
71395+#include <linux/crypto.h>
71396+#include <linux/gracl.h>
71397+
71398+
71399+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71400+#error "crypto and sha256 must be built into the kernel"
71401+#endif
71402+
71403+int
71404+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71405+{
71406+ char *p;
71407+ struct crypto_hash *tfm;
71408+ struct hash_desc desc;
71409+ struct scatterlist sg;
71410+ unsigned char temp_sum[GR_SHA_LEN];
71411+ volatile int retval = 0;
71412+ volatile int dummy = 0;
71413+ unsigned int i;
71414+
71415+ sg_init_table(&sg, 1);
71416+
71417+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71418+ if (IS_ERR(tfm)) {
71419+ /* should never happen, since sha256 should be built in */
71420+ return 1;
71421+ }
71422+
71423+ desc.tfm = tfm;
71424+ desc.flags = 0;
71425+
71426+ crypto_hash_init(&desc);
71427+
71428+ p = salt;
71429+ sg_set_buf(&sg, p, GR_SALT_LEN);
71430+ crypto_hash_update(&desc, &sg, sg.length);
71431+
71432+ p = entry->pw;
71433+ sg_set_buf(&sg, p, strlen(p));
71434+
71435+ crypto_hash_update(&desc, &sg, sg.length);
71436+
71437+ crypto_hash_final(&desc, temp_sum);
71438+
71439+ memset(entry->pw, 0, GR_PW_LEN);
71440+
71441+ for (i = 0; i < GR_SHA_LEN; i++)
71442+ if (sum[i] != temp_sum[i])
71443+ retval = 1;
71444+ else
71445+ dummy = 1; // waste a cycle
71446+
71447+ crypto_free_hash(tfm);
71448+
71449+ return retval;
71450+}
71451diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71452index 77ff547..181834f 100644
71453--- a/include/asm-generic/4level-fixup.h
71454+++ b/include/asm-generic/4level-fixup.h
71455@@ -13,8 +13,10 @@
71456 #define pmd_alloc(mm, pud, address) \
71457 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71458 NULL: pmd_offset(pud, address))
71459+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71460
71461 #define pud_alloc(mm, pgd, address) (pgd)
71462+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71463 #define pud_offset(pgd, start) (pgd)
71464 #define pud_none(pud) 0
71465 #define pud_bad(pud) 0
71466diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71467index b7babf0..04ad282 100644
71468--- a/include/asm-generic/atomic-long.h
71469+++ b/include/asm-generic/atomic-long.h
71470@@ -22,6 +22,12 @@
71471
71472 typedef atomic64_t atomic_long_t;
71473
71474+#ifdef CONFIG_PAX_REFCOUNT
71475+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71476+#else
71477+typedef atomic64_t atomic_long_unchecked_t;
71478+#endif
71479+
71480 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71481
71482 static inline long atomic_long_read(atomic_long_t *l)
71483@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71484 return (long)atomic64_read(v);
71485 }
71486
71487+#ifdef CONFIG_PAX_REFCOUNT
71488+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71489+{
71490+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71491+
71492+ return (long)atomic64_read_unchecked(v);
71493+}
71494+#endif
71495+
71496 static inline void atomic_long_set(atomic_long_t *l, long i)
71497 {
71498 atomic64_t *v = (atomic64_t *)l;
71499@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71500 atomic64_set(v, i);
71501 }
71502
71503+#ifdef CONFIG_PAX_REFCOUNT
71504+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71505+{
71506+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71507+
71508+ atomic64_set_unchecked(v, i);
71509+}
71510+#endif
71511+
71512 static inline void atomic_long_inc(atomic_long_t *l)
71513 {
71514 atomic64_t *v = (atomic64_t *)l;
71515@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71516 atomic64_inc(v);
71517 }
71518
71519+#ifdef CONFIG_PAX_REFCOUNT
71520+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71521+{
71522+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71523+
71524+ atomic64_inc_unchecked(v);
71525+}
71526+#endif
71527+
71528 static inline void atomic_long_dec(atomic_long_t *l)
71529 {
71530 atomic64_t *v = (atomic64_t *)l;
71531@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71532 atomic64_dec(v);
71533 }
71534
71535+#ifdef CONFIG_PAX_REFCOUNT
71536+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71537+{
71538+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71539+
71540+ atomic64_dec_unchecked(v);
71541+}
71542+#endif
71543+
71544 static inline void atomic_long_add(long i, atomic_long_t *l)
71545 {
71546 atomic64_t *v = (atomic64_t *)l;
71547@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71548 atomic64_add(i, v);
71549 }
71550
71551+#ifdef CONFIG_PAX_REFCOUNT
71552+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71553+{
71554+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71555+
71556+ atomic64_add_unchecked(i, v);
71557+}
71558+#endif
71559+
71560 static inline void atomic_long_sub(long i, atomic_long_t *l)
71561 {
71562 atomic64_t *v = (atomic64_t *)l;
71563@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71564 atomic64_sub(i, v);
71565 }
71566
71567+#ifdef CONFIG_PAX_REFCOUNT
71568+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71569+{
71570+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71571+
71572+ atomic64_sub_unchecked(i, v);
71573+}
71574+#endif
71575+
71576 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71577 {
71578 atomic64_t *v = (atomic64_t *)l;
71579@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71580 return (long)atomic64_add_return(i, v);
71581 }
71582
71583+#ifdef CONFIG_PAX_REFCOUNT
71584+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71585+{
71586+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71587+
71588+ return (long)atomic64_add_return_unchecked(i, v);
71589+}
71590+#endif
71591+
71592 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71593 {
71594 atomic64_t *v = (atomic64_t *)l;
71595@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71596 return (long)atomic64_inc_return(v);
71597 }
71598
71599+#ifdef CONFIG_PAX_REFCOUNT
71600+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71601+{
71602+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71603+
71604+ return (long)atomic64_inc_return_unchecked(v);
71605+}
71606+#endif
71607+
71608 static inline long atomic_long_dec_return(atomic_long_t *l)
71609 {
71610 atomic64_t *v = (atomic64_t *)l;
71611@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71612
71613 typedef atomic_t atomic_long_t;
71614
71615+#ifdef CONFIG_PAX_REFCOUNT
71616+typedef atomic_unchecked_t atomic_long_unchecked_t;
71617+#else
71618+typedef atomic_t atomic_long_unchecked_t;
71619+#endif
71620+
71621 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71622 static inline long atomic_long_read(atomic_long_t *l)
71623 {
71624@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71625 return (long)atomic_read(v);
71626 }
71627
71628+#ifdef CONFIG_PAX_REFCOUNT
71629+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71630+{
71631+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71632+
71633+ return (long)atomic_read_unchecked(v);
71634+}
71635+#endif
71636+
71637 static inline void atomic_long_set(atomic_long_t *l, long i)
71638 {
71639 atomic_t *v = (atomic_t *)l;
71640@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71641 atomic_set(v, i);
71642 }
71643
71644+#ifdef CONFIG_PAX_REFCOUNT
71645+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71646+{
71647+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71648+
71649+ atomic_set_unchecked(v, i);
71650+}
71651+#endif
71652+
71653 static inline void atomic_long_inc(atomic_long_t *l)
71654 {
71655 atomic_t *v = (atomic_t *)l;
71656@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71657 atomic_inc(v);
71658 }
71659
71660+#ifdef CONFIG_PAX_REFCOUNT
71661+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71662+{
71663+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71664+
71665+ atomic_inc_unchecked(v);
71666+}
71667+#endif
71668+
71669 static inline void atomic_long_dec(atomic_long_t *l)
71670 {
71671 atomic_t *v = (atomic_t *)l;
71672@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71673 atomic_dec(v);
71674 }
71675
71676+#ifdef CONFIG_PAX_REFCOUNT
71677+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71678+{
71679+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71680+
71681+ atomic_dec_unchecked(v);
71682+}
71683+#endif
71684+
71685 static inline void atomic_long_add(long i, atomic_long_t *l)
71686 {
71687 atomic_t *v = (atomic_t *)l;
71688@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71689 atomic_add(i, v);
71690 }
71691
71692+#ifdef CONFIG_PAX_REFCOUNT
71693+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71694+{
71695+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71696+
71697+ atomic_add_unchecked(i, v);
71698+}
71699+#endif
71700+
71701 static inline void atomic_long_sub(long i, atomic_long_t *l)
71702 {
71703 atomic_t *v = (atomic_t *)l;
71704@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71705 atomic_sub(i, v);
71706 }
71707
71708+#ifdef CONFIG_PAX_REFCOUNT
71709+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71710+{
71711+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71712+
71713+ atomic_sub_unchecked(i, v);
71714+}
71715+#endif
71716+
71717 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71718 {
71719 atomic_t *v = (atomic_t *)l;
71720@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71721 return (long)atomic_add_return(i, v);
71722 }
71723
71724+#ifdef CONFIG_PAX_REFCOUNT
71725+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71726+{
71727+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71728+
71729+ return (long)atomic_add_return_unchecked(i, v);
71730+}
71731+
71732+#endif
71733+
71734 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71735 {
71736 atomic_t *v = (atomic_t *)l;
71737@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71738 return (long)atomic_inc_return(v);
71739 }
71740
71741+#ifdef CONFIG_PAX_REFCOUNT
71742+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71743+{
71744+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71745+
71746+ return (long)atomic_inc_return_unchecked(v);
71747+}
71748+#endif
71749+
71750 static inline long atomic_long_dec_return(atomic_long_t *l)
71751 {
71752 atomic_t *v = (atomic_t *)l;
71753@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71754
71755 #endif /* BITS_PER_LONG == 64 */
71756
71757+#ifdef CONFIG_PAX_REFCOUNT
71758+static inline void pax_refcount_needs_these_functions(void)
71759+{
71760+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71761+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71762+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71763+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71764+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71765+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71766+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71767+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71768+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71769+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71770+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71771+#ifdef CONFIG_X86
71772+ atomic_clear_mask_unchecked(0, NULL);
71773+ atomic_set_mask_unchecked(0, NULL);
71774+#endif
71775+
71776+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71777+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71778+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71779+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71780+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71781+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71782+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71783+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71784+}
71785+#else
71786+#define atomic_read_unchecked(v) atomic_read(v)
71787+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71788+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71789+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71790+#define atomic_inc_unchecked(v) atomic_inc(v)
71791+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71792+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71793+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71794+#define atomic_dec_unchecked(v) atomic_dec(v)
71795+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71796+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71797+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71798+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71799+
71800+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71801+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71802+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71803+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71804+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71805+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71806+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71807+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71808+#endif
71809+
71810 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71811diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71812index 33bd2de..f31bff97 100644
71813--- a/include/asm-generic/atomic.h
71814+++ b/include/asm-generic/atomic.h
71815@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71816 * Atomically clears the bits set in @mask from @v
71817 */
71818 #ifndef atomic_clear_mask
71819-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71820+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71821 {
71822 unsigned long flags;
71823
71824diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71825index b18ce4f..2ee2843 100644
71826--- a/include/asm-generic/atomic64.h
71827+++ b/include/asm-generic/atomic64.h
71828@@ -16,6 +16,8 @@ typedef struct {
71829 long long counter;
71830 } atomic64_t;
71831
71832+typedef atomic64_t atomic64_unchecked_t;
71833+
71834 #define ATOMIC64_INIT(i) { (i) }
71835
71836 extern long long atomic64_read(const atomic64_t *v);
71837@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71838 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71839 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71840
71841+#define atomic64_read_unchecked(v) atomic64_read(v)
71842+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71843+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71844+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71845+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71846+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71847+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71848+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71849+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71850+
71851 #endif /* _ASM_GENERIC_ATOMIC64_H */
71852diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71853index 1bfcfe5..e04c5c9 100644
71854--- a/include/asm-generic/cache.h
71855+++ b/include/asm-generic/cache.h
71856@@ -6,7 +6,7 @@
71857 * cache lines need to provide their own cache.h.
71858 */
71859
71860-#define L1_CACHE_SHIFT 5
71861-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71862+#define L1_CACHE_SHIFT 5UL
71863+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71864
71865 #endif /* __ASM_GENERIC_CACHE_H */
71866diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71867index 0d68a1e..b74a761 100644
71868--- a/include/asm-generic/emergency-restart.h
71869+++ b/include/asm-generic/emergency-restart.h
71870@@ -1,7 +1,7 @@
71871 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71872 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71873
71874-static inline void machine_emergency_restart(void)
71875+static inline __noreturn void machine_emergency_restart(void)
71876 {
71877 machine_restart(NULL);
71878 }
71879diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71880index 90f99c7..00ce236 100644
71881--- a/include/asm-generic/kmap_types.h
71882+++ b/include/asm-generic/kmap_types.h
71883@@ -2,9 +2,9 @@
71884 #define _ASM_GENERIC_KMAP_TYPES_H
71885
71886 #ifdef __WITH_KM_FENCE
71887-# define KM_TYPE_NR 41
71888+# define KM_TYPE_NR 42
71889 #else
71890-# define KM_TYPE_NR 20
71891+# define KM_TYPE_NR 21
71892 #endif
71893
71894 #endif
71895diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71896index 9ceb03b..62b0b8f 100644
71897--- a/include/asm-generic/local.h
71898+++ b/include/asm-generic/local.h
71899@@ -23,24 +23,37 @@ typedef struct
71900 atomic_long_t a;
71901 } local_t;
71902
71903+typedef struct {
71904+ atomic_long_unchecked_t a;
71905+} local_unchecked_t;
71906+
71907 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71908
71909 #define local_read(l) atomic_long_read(&(l)->a)
71910+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71911 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71912+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71913 #define local_inc(l) atomic_long_inc(&(l)->a)
71914+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71915 #define local_dec(l) atomic_long_dec(&(l)->a)
71916+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71917 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71918+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71919 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71920+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71921
71922 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71923 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71924 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71925 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71926 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71927+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71928 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71929 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71930+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71931
71932 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71933+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71934 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71935 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71936 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71937diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71938index 725612b..9cc513a 100644
71939--- a/include/asm-generic/pgtable-nopmd.h
71940+++ b/include/asm-generic/pgtable-nopmd.h
71941@@ -1,14 +1,19 @@
71942 #ifndef _PGTABLE_NOPMD_H
71943 #define _PGTABLE_NOPMD_H
71944
71945-#ifndef __ASSEMBLY__
71946-
71947 #include <asm-generic/pgtable-nopud.h>
71948
71949-struct mm_struct;
71950-
71951 #define __PAGETABLE_PMD_FOLDED
71952
71953+#define PMD_SHIFT PUD_SHIFT
71954+#define PTRS_PER_PMD 1
71955+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71956+#define PMD_MASK (~(PMD_SIZE-1))
71957+
71958+#ifndef __ASSEMBLY__
71959+
71960+struct mm_struct;
71961+
71962 /*
71963 * Having the pmd type consist of a pud gets the size right, and allows
71964 * us to conceptually access the pud entry that this pmd is folded into
71965@@ -16,11 +21,6 @@ struct mm_struct;
71966 */
71967 typedef struct { pud_t pud; } pmd_t;
71968
71969-#define PMD_SHIFT PUD_SHIFT
71970-#define PTRS_PER_PMD 1
71971-#define PMD_SIZE (1UL << PMD_SHIFT)
71972-#define PMD_MASK (~(PMD_SIZE-1))
71973-
71974 /*
71975 * The "pud_xxx()" functions here are trivial for a folded two-level
71976 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71977diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71978index 810431d..0ec4804f 100644
71979--- a/include/asm-generic/pgtable-nopud.h
71980+++ b/include/asm-generic/pgtable-nopud.h
71981@@ -1,10 +1,15 @@
71982 #ifndef _PGTABLE_NOPUD_H
71983 #define _PGTABLE_NOPUD_H
71984
71985-#ifndef __ASSEMBLY__
71986-
71987 #define __PAGETABLE_PUD_FOLDED
71988
71989+#define PUD_SHIFT PGDIR_SHIFT
71990+#define PTRS_PER_PUD 1
71991+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71992+#define PUD_MASK (~(PUD_SIZE-1))
71993+
71994+#ifndef __ASSEMBLY__
71995+
71996 /*
71997 * Having the pud type consist of a pgd gets the size right, and allows
71998 * us to conceptually access the pgd entry that this pud is folded into
71999@@ -12,11 +17,6 @@
72000 */
72001 typedef struct { pgd_t pgd; } pud_t;
72002
72003-#define PUD_SHIFT PGDIR_SHIFT
72004-#define PTRS_PER_PUD 1
72005-#define PUD_SIZE (1UL << PUD_SHIFT)
72006-#define PUD_MASK (~(PUD_SIZE-1))
72007-
72008 /*
72009 * The "pgd_xxx()" functions here are trivial for a folded two-level
72010 * setup: the pud is never bad, and a pud always exists (as it's folded
72011@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72012 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72013
72014 #define pgd_populate(mm, pgd, pud) do { } while (0)
72015+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72016 /*
72017 * (puds are folded into pgds so this doesn't get actually called,
72018 * but the define is needed for a generic inline function.)
72019diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72020index 0807ddf..cd67747 100644
72021--- a/include/asm-generic/pgtable.h
72022+++ b/include/asm-generic/pgtable.h
72023@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72024 }
72025 #endif /* CONFIG_NUMA_BALANCING */
72026
72027+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72028+#ifdef CONFIG_PAX_KERNEXEC
72029+#error KERNEXEC requires pax_open_kernel
72030+#else
72031+static inline unsigned long pax_open_kernel(void) { return 0; }
72032+#endif
72033+#endif
72034+
72035+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72036+#ifdef CONFIG_PAX_KERNEXEC
72037+#error KERNEXEC requires pax_close_kernel
72038+#else
72039+static inline unsigned long pax_close_kernel(void) { return 0; }
72040+#endif
72041+#endif
72042+
72043 #endif /* CONFIG_MMU */
72044
72045 #endif /* !__ASSEMBLY__ */
72046diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72047index dc1269c..48a4f51 100644
72048--- a/include/asm-generic/uaccess.h
72049+++ b/include/asm-generic/uaccess.h
72050@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72051 return __clear_user(to, n);
72052 }
72053
72054+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72055+#ifdef CONFIG_PAX_MEMORY_UDEREF
72056+#error UDEREF requires pax_open_userland
72057+#else
72058+static inline unsigned long pax_open_userland(void) { return 0; }
72059+#endif
72060+#endif
72061+
72062+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72063+#ifdef CONFIG_PAX_MEMORY_UDEREF
72064+#error UDEREF requires pax_close_userland
72065+#else
72066+static inline unsigned long pax_close_userland(void) { return 0; }
72067+#endif
72068+#endif
72069+
72070 #endif /* __ASM_GENERIC_UACCESS_H */
72071diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72072index 69732d2..cbe16d9 100644
72073--- a/include/asm-generic/vmlinux.lds.h
72074+++ b/include/asm-generic/vmlinux.lds.h
72075@@ -227,6 +227,7 @@
72076 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72077 VMLINUX_SYMBOL(__start_rodata) = .; \
72078 *(.rodata) *(.rodata.*) \
72079+ *(.data..read_only) \
72080 *(__vermagic) /* Kernel version magic */ \
72081 . = ALIGN(8); \
72082 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72083@@ -710,17 +711,18 @@
72084 * section in the linker script will go there too. @phdr should have
72085 * a leading colon.
72086 *
72087- * Note that this macros defines __per_cpu_load as an absolute symbol.
72088+ * Note that this macros defines per_cpu_load as an absolute symbol.
72089 * If there is no need to put the percpu section at a predetermined
72090 * address, use PERCPU_SECTION.
72091 */
72092 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72093- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72094- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72095+ per_cpu_load = .; \
72096+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72097 - LOAD_OFFSET) { \
72098+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72099 PERCPU_INPUT(cacheline) \
72100 } phdr \
72101- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72102+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72103
72104 /**
72105 * PERCPU_SECTION - define output section for percpu area, simple version
72106diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72107index 418d270..bfd2794 100644
72108--- a/include/crypto/algapi.h
72109+++ b/include/crypto/algapi.h
72110@@ -34,7 +34,7 @@ struct crypto_type {
72111 unsigned int maskclear;
72112 unsigned int maskset;
72113 unsigned int tfmsize;
72114-};
72115+} __do_const;
72116
72117 struct crypto_instance {
72118 struct crypto_alg alg;
72119diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72120index 12083dc..39740ec 100644
72121--- a/include/drm/drmP.h
72122+++ b/include/drm/drmP.h
72123@@ -69,6 +69,7 @@
72124 #include <linux/workqueue.h>
72125 #include <linux/poll.h>
72126 #include <asm/pgalloc.h>
72127+#include <asm/local.h>
72128 #include <drm/drm.h>
72129 #include <drm/drm_sarea.h>
72130
72131@@ -293,10 +294,12 @@ do { \
72132 * \param cmd command.
72133 * \param arg argument.
72134 */
72135-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72136+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72137+ struct drm_file *file_priv);
72138+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72139 struct drm_file *file_priv);
72140
72141-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72142+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72143 unsigned long arg);
72144
72145 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72146@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72147 struct drm_ioctl_desc {
72148 unsigned int cmd;
72149 int flags;
72150- drm_ioctl_t *func;
72151+ drm_ioctl_t func;
72152 unsigned int cmd_drv;
72153 const char *name;
72154-};
72155+} __do_const;
72156
72157 /**
72158 * Creates a driver or general drm_ioctl_desc array entry for the given
72159@@ -1015,7 +1018,7 @@ struct drm_info_list {
72160 int (*show)(struct seq_file*, void*); /** show callback */
72161 u32 driver_features; /**< Required driver features for this entry */
72162 void *data;
72163-};
72164+} __do_const;
72165
72166 /**
72167 * debugfs node structure. This structure represents a debugfs file.
72168@@ -1088,7 +1091,7 @@ struct drm_device {
72169
72170 /** \name Usage Counters */
72171 /*@{ */
72172- int open_count; /**< Outstanding files open */
72173+ local_t open_count; /**< Outstanding files open */
72174 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72175 atomic_t vma_count; /**< Outstanding vma areas open */
72176 int buf_use; /**< Buffers in use -- cannot alloc */
72177@@ -1099,7 +1102,7 @@ struct drm_device {
72178 /*@{ */
72179 unsigned long counters;
72180 enum drm_stat_type types[15];
72181- atomic_t counts[15];
72182+ atomic_unchecked_t counts[15];
72183 /*@} */
72184
72185 struct list_head filelist;
72186diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72187index f43d556..94d9343 100644
72188--- a/include/drm/drm_crtc_helper.h
72189+++ b/include/drm/drm_crtc_helper.h
72190@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72191 struct drm_connector *connector);
72192 /* disable encoder when not in use - more explicit than dpms off */
72193 void (*disable)(struct drm_encoder *encoder);
72194-};
72195+} __no_const;
72196
72197 /**
72198 * drm_connector_helper_funcs - helper operations for connectors
72199diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72200index 72dcbe8..8db58d7 100644
72201--- a/include/drm/ttm/ttm_memory.h
72202+++ b/include/drm/ttm/ttm_memory.h
72203@@ -48,7 +48,7 @@
72204
72205 struct ttm_mem_shrink {
72206 int (*do_shrink) (struct ttm_mem_shrink *);
72207-};
72208+} __no_const;
72209
72210 /**
72211 * struct ttm_mem_global - Global memory accounting structure.
72212diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72213index 4b840e8..155d235 100644
72214--- a/include/keys/asymmetric-subtype.h
72215+++ b/include/keys/asymmetric-subtype.h
72216@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72217 /* Verify the signature on a key of this subtype (optional) */
72218 int (*verify_signature)(const struct key *key,
72219 const struct public_key_signature *sig);
72220-};
72221+} __do_const;
72222
72223 /**
72224 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72225diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72226index c1da539..1dcec55 100644
72227--- a/include/linux/atmdev.h
72228+++ b/include/linux/atmdev.h
72229@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72230 #endif
72231
72232 struct k_atm_aal_stats {
72233-#define __HANDLE_ITEM(i) atomic_t i
72234+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72235 __AAL_STAT_ITEMS
72236 #undef __HANDLE_ITEM
72237 };
72238@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72239 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72240 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72241 struct module *owner;
72242-};
72243+} __do_const ;
72244
72245 struct atmphy_ops {
72246 int (*start)(struct atm_dev *dev);
72247diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72248index 70cf138..0418ee2 100644
72249--- a/include/linux/binfmts.h
72250+++ b/include/linux/binfmts.h
72251@@ -73,8 +73,10 @@ struct linux_binfmt {
72252 int (*load_binary)(struct linux_binprm *);
72253 int (*load_shlib)(struct file *);
72254 int (*core_dump)(struct coredump_params *cprm);
72255+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72256+ void (*handle_mmap)(struct file *);
72257 unsigned long min_coredump; /* minimal dump size */
72258-};
72259+} __do_const;
72260
72261 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72262
72263diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72264index 2fdb4a4..54aad7e 100644
72265--- a/include/linux/blkdev.h
72266+++ b/include/linux/blkdev.h
72267@@ -1526,7 +1526,7 @@ struct block_device_operations {
72268 /* this callback is with swap_lock and sometimes page table lock held */
72269 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72270 struct module *owner;
72271-};
72272+} __do_const;
72273
72274 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72275 unsigned long);
72276diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72277index 7c2e030..b72475d 100644
72278--- a/include/linux/blktrace_api.h
72279+++ b/include/linux/blktrace_api.h
72280@@ -23,7 +23,7 @@ struct blk_trace {
72281 struct dentry *dir;
72282 struct dentry *dropped_file;
72283 struct dentry *msg_file;
72284- atomic_t dropped;
72285+ atomic_unchecked_t dropped;
72286 };
72287
72288 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72289diff --git a/include/linux/cache.h b/include/linux/cache.h
72290index 4c57065..40346da 100644
72291--- a/include/linux/cache.h
72292+++ b/include/linux/cache.h
72293@@ -16,6 +16,14 @@
72294 #define __read_mostly
72295 #endif
72296
72297+#ifndef __read_only
72298+#ifdef CONFIG_PAX_KERNEXEC
72299+#error KERNEXEC requires __read_only
72300+#else
72301+#define __read_only __read_mostly
72302+#endif
72303+#endif
72304+
72305 #ifndef ____cacheline_aligned
72306 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72307 #endif
72308diff --git a/include/linux/capability.h b/include/linux/capability.h
72309index d9a4f7f4..19f77d6 100644
72310--- a/include/linux/capability.h
72311+++ b/include/linux/capability.h
72312@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72313 extern bool nsown_capable(int cap);
72314 extern bool inode_capable(const struct inode *inode, int cap);
72315 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72316+extern bool capable_nolog(int cap);
72317+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72318+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72319
72320 /* audit system wants to get cap info from files as well */
72321 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72322
72323+extern int is_privileged_binary(const struct dentry *dentry);
72324+
72325 #endif /* !_LINUX_CAPABILITY_H */
72326diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72327index 8609d57..86e4d79 100644
72328--- a/include/linux/cdrom.h
72329+++ b/include/linux/cdrom.h
72330@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72331
72332 /* driver specifications */
72333 const int capability; /* capability flags */
72334- int n_minors; /* number of active minor devices */
72335 /* handle uniform packets for scsi type devices (scsi,atapi) */
72336 int (*generic_packet) (struct cdrom_device_info *,
72337 struct packet_command *);
72338diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72339index 4ce9056..86caac6 100644
72340--- a/include/linux/cleancache.h
72341+++ b/include/linux/cleancache.h
72342@@ -31,7 +31,7 @@ struct cleancache_ops {
72343 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72344 void (*invalidate_inode)(int, struct cleancache_filekey);
72345 void (*invalidate_fs)(int);
72346-};
72347+} __no_const;
72348
72349 extern struct cleancache_ops *
72350 cleancache_register_ops(struct cleancache_ops *ops);
72351diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72352index 1ec14a7..d0654a2 100644
72353--- a/include/linux/clk-provider.h
72354+++ b/include/linux/clk-provider.h
72355@@ -132,6 +132,7 @@ struct clk_ops {
72356 unsigned long);
72357 void (*init)(struct clk_hw *hw);
72358 };
72359+typedef struct clk_ops __no_const clk_ops_no_const;
72360
72361 /**
72362 * struct clk_init_data - holds init data that's common to all clocks and is
72363diff --git a/include/linux/compat.h b/include/linux/compat.h
72364index ec1aee4..1077986 100644
72365--- a/include/linux/compat.h
72366+++ b/include/linux/compat.h
72367@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72368 compat_size_t __user *len_ptr);
72369
72370 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72371-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72372+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72373 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72374 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72375 compat_ssize_t msgsz, int msgflg);
72376@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72377 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72378 compat_ulong_t addr, compat_ulong_t data);
72379 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72380- compat_long_t addr, compat_long_t data);
72381+ compat_ulong_t addr, compat_ulong_t data);
72382
72383 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72384 /*
72385diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72386index ded4299..da50e3b 100644
72387--- a/include/linux/compiler-gcc4.h
72388+++ b/include/linux/compiler-gcc4.h
72389@@ -39,9 +39,29 @@
72390 # define __compiletime_warning(message) __attribute__((warning(message)))
72391 # define __compiletime_error(message) __attribute__((error(message)))
72392 #endif /* __CHECKER__ */
72393+
72394+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72395+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72396+#define __bos0(ptr) __bos((ptr), 0)
72397+#define __bos1(ptr) __bos((ptr), 1)
72398 #endif /* GCC_VERSION >= 40300 */
72399
72400 #if GCC_VERSION >= 40500
72401+
72402+#ifdef CONSTIFY_PLUGIN
72403+#define __no_const __attribute__((no_const))
72404+#define __do_const __attribute__((do_const))
72405+#endif
72406+
72407+#ifdef SIZE_OVERFLOW_PLUGIN
72408+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72409+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72410+#endif
72411+
72412+#ifdef LATENT_ENTROPY_PLUGIN
72413+#define __latent_entropy __attribute__((latent_entropy))
72414+#endif
72415+
72416 /*
72417 * Mark a position in code as unreachable. This can be used to
72418 * suppress control flow warnings after asm blocks that transfer
72419diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72420index 92669cd..1771a15 100644
72421--- a/include/linux/compiler.h
72422+++ b/include/linux/compiler.h
72423@@ -5,11 +5,14 @@
72424
72425 #ifdef __CHECKER__
72426 # define __user __attribute__((noderef, address_space(1)))
72427+# define __force_user __force __user
72428 # define __kernel __attribute__((address_space(0)))
72429+# define __force_kernel __force __kernel
72430 # define __safe __attribute__((safe))
72431 # define __force __attribute__((force))
72432 # define __nocast __attribute__((nocast))
72433 # define __iomem __attribute__((noderef, address_space(2)))
72434+# define __force_iomem __force __iomem
72435 # define __must_hold(x) __attribute__((context(x,1,1)))
72436 # define __acquires(x) __attribute__((context(x,0,1)))
72437 # define __releases(x) __attribute__((context(x,1,0)))
72438@@ -17,20 +20,37 @@
72439 # define __release(x) __context__(x,-1)
72440 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72441 # define __percpu __attribute__((noderef, address_space(3)))
72442+# define __force_percpu __force __percpu
72443 #ifdef CONFIG_SPARSE_RCU_POINTER
72444 # define __rcu __attribute__((noderef, address_space(4)))
72445+# define __force_rcu __force __rcu
72446 #else
72447 # define __rcu
72448+# define __force_rcu
72449 #endif
72450 extern void __chk_user_ptr(const volatile void __user *);
72451 extern void __chk_io_ptr(const volatile void __iomem *);
72452 #else
72453-# define __user
72454-# define __kernel
72455+# ifdef CHECKER_PLUGIN
72456+//# define __user
72457+//# define __force_user
72458+//# define __kernel
72459+//# define __force_kernel
72460+# else
72461+# ifdef STRUCTLEAK_PLUGIN
72462+# define __user __attribute__((user))
72463+# else
72464+# define __user
72465+# endif
72466+# define __force_user
72467+# define __kernel
72468+# define __force_kernel
72469+# endif
72470 # define __safe
72471 # define __force
72472 # define __nocast
72473 # define __iomem
72474+# define __force_iomem
72475 # define __chk_user_ptr(x) (void)0
72476 # define __chk_io_ptr(x) (void)0
72477 # define __builtin_warning(x, y...) (1)
72478@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72479 # define __release(x) (void)0
72480 # define __cond_lock(x,c) (c)
72481 # define __percpu
72482+# define __force_percpu
72483 # define __rcu
72484+# define __force_rcu
72485 #endif
72486
72487 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72488@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72489 # define __attribute_const__ /* unimplemented */
72490 #endif
72491
72492+#ifndef __no_const
72493+# define __no_const
72494+#endif
72495+
72496+#ifndef __do_const
72497+# define __do_const
72498+#endif
72499+
72500+#ifndef __size_overflow
72501+# define __size_overflow(...)
72502+#endif
72503+
72504+#ifndef __intentional_overflow
72505+# define __intentional_overflow(...)
72506+#endif
72507+
72508+#ifndef __latent_entropy
72509+# define __latent_entropy
72510+#endif
72511+
72512 /*
72513 * Tell gcc if a function is cold. The compiler will assume any path
72514 * directly leading to the call is unlikely.
72515@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72516 #define __cold
72517 #endif
72518
72519+#ifndef __alloc_size
72520+#define __alloc_size(...)
72521+#endif
72522+
72523+#ifndef __bos
72524+#define __bos(ptr, arg)
72525+#endif
72526+
72527+#ifndef __bos0
72528+#define __bos0(ptr)
72529+#endif
72530+
72531+#ifndef __bos1
72532+#define __bos1(ptr)
72533+#endif
72534+
72535 /* Simple shorthand for a section definition */
72536 #ifndef __section
72537 # define __section(S) __attribute__ ((__section__(#S)))
72538@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72539 * use is to mediate communication between process-level code and irq/NMI
72540 * handlers, all running on the same CPU.
72541 */
72542-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72543+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72544+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72545
72546 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72547 #ifdef CONFIG_KPROBES
72548diff --git a/include/linux/completion.h b/include/linux/completion.h
72549index 3cd574d..adce5fa 100644
72550--- a/include/linux/completion.h
72551+++ b/include/linux/completion.h
72552@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72553 extern void wait_for_completion(struct completion *);
72554 extern void wait_for_completion_io(struct completion *);
72555 extern int wait_for_completion_interruptible(struct completion *x);
72556-extern int wait_for_completion_killable(struct completion *x);
72557+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72558 extern unsigned long wait_for_completion_timeout(struct completion *x,
72559 unsigned long timeout);
72560 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72561 unsigned long timeout);
72562 extern long wait_for_completion_interruptible_timeout(
72563- struct completion *x, unsigned long timeout);
72564+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72565 extern long wait_for_completion_killable_timeout(
72566- struct completion *x, unsigned long timeout);
72567+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72568 extern bool try_wait_for_completion(struct completion *x);
72569 extern bool completion_done(struct completion *x);
72570
72571diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72572index 34025df..d94bbbc 100644
72573--- a/include/linux/configfs.h
72574+++ b/include/linux/configfs.h
72575@@ -125,7 +125,7 @@ struct configfs_attribute {
72576 const char *ca_name;
72577 struct module *ca_owner;
72578 umode_t ca_mode;
72579-};
72580+} __do_const;
72581
72582 /*
72583 * Users often need to create attribute structures for their configurable
72584diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72585index 90d5a15..950cb80 100644
72586--- a/include/linux/cpufreq.h
72587+++ b/include/linux/cpufreq.h
72588@@ -266,7 +266,7 @@ struct cpufreq_driver {
72589 int (*suspend) (struct cpufreq_policy *policy);
72590 int (*resume) (struct cpufreq_policy *policy);
72591 struct freq_attr **attr;
72592-};
72593+} __do_const;
72594
72595 /* flags */
72596
72597@@ -325,6 +325,7 @@ struct global_attr {
72598 ssize_t (*store)(struct kobject *a, struct attribute *b,
72599 const char *c, size_t count);
72600 };
72601+typedef struct global_attr __no_const global_attr_no_const;
72602
72603 #define define_one_global_ro(_name) \
72604 static struct global_attr _name = \
72605diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72606index 0bc4b74..973b368 100644
72607--- a/include/linux/cpuidle.h
72608+++ b/include/linux/cpuidle.h
72609@@ -52,7 +52,8 @@ struct cpuidle_state {
72610 int index);
72611
72612 int (*enter_dead) (struct cpuidle_device *dev, int index);
72613-};
72614+} __do_const;
72615+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72616
72617 /* Idle State Flags */
72618 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72619@@ -191,7 +192,7 @@ struct cpuidle_governor {
72620 void (*reflect) (struct cpuidle_device *dev, int index);
72621
72622 struct module *owner;
72623-};
72624+} __do_const;
72625
72626 #ifdef CONFIG_CPU_IDLE
72627
72628diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72629index d08e4d2..95fad61 100644
72630--- a/include/linux/cpumask.h
72631+++ b/include/linux/cpumask.h
72632@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72633 }
72634
72635 /* Valid inputs for n are -1 and 0. */
72636-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72637+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72638 {
72639 return n+1;
72640 }
72641
72642-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72643+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72644 {
72645 return n+1;
72646 }
72647
72648-static inline unsigned int cpumask_next_and(int n,
72649+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72650 const struct cpumask *srcp,
72651 const struct cpumask *andp)
72652 {
72653@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72654 *
72655 * Returns >= nr_cpu_ids if no further cpus set.
72656 */
72657-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72658+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72659 {
72660 /* -1 is a legal arg here. */
72661 if (n != -1)
72662@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72663 *
72664 * Returns >= nr_cpu_ids if no further cpus unset.
72665 */
72666-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72667+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72668 {
72669 /* -1 is a legal arg here. */
72670 if (n != -1)
72671@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72672 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72673 }
72674
72675-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72676+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72677 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72678
72679 /**
72680diff --git a/include/linux/cred.h b/include/linux/cred.h
72681index 04421e8..6bce4ef 100644
72682--- a/include/linux/cred.h
72683+++ b/include/linux/cred.h
72684@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72685 static inline void validate_process_creds(void)
72686 {
72687 }
72688+static inline void validate_task_creds(struct task_struct *task)
72689+{
72690+}
72691 #endif
72692
72693 /**
72694diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72695index b92eadf..b4ecdc1 100644
72696--- a/include/linux/crypto.h
72697+++ b/include/linux/crypto.h
72698@@ -373,7 +373,7 @@ struct cipher_tfm {
72699 const u8 *key, unsigned int keylen);
72700 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72701 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72702-};
72703+} __no_const;
72704
72705 struct hash_tfm {
72706 int (*init)(struct hash_desc *desc);
72707@@ -394,13 +394,13 @@ struct compress_tfm {
72708 int (*cot_decompress)(struct crypto_tfm *tfm,
72709 const u8 *src, unsigned int slen,
72710 u8 *dst, unsigned int *dlen);
72711-};
72712+} __no_const;
72713
72714 struct rng_tfm {
72715 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72716 unsigned int dlen);
72717 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72718-};
72719+} __no_const;
72720
72721 #define crt_ablkcipher crt_u.ablkcipher
72722 #define crt_aead crt_u.aead
72723diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72724index 653589e..4ef254a 100644
72725--- a/include/linux/ctype.h
72726+++ b/include/linux/ctype.h
72727@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72728 * Fast implementation of tolower() for internal usage. Do not use in your
72729 * code.
72730 */
72731-static inline char _tolower(const char c)
72732+static inline unsigned char _tolower(const unsigned char c)
72733 {
72734 return c | 0x20;
72735 }
72736diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72737index 7925bf0..d5143d2 100644
72738--- a/include/linux/decompress/mm.h
72739+++ b/include/linux/decompress/mm.h
72740@@ -77,7 +77,7 @@ static void free(void *where)
72741 * warnings when not needed (indeed large_malloc / large_free are not
72742 * needed by inflate */
72743
72744-#define malloc(a) kmalloc(a, GFP_KERNEL)
72745+#define malloc(a) kmalloc((a), GFP_KERNEL)
72746 #define free(a) kfree(a)
72747
72748 #define large_malloc(a) vmalloc(a)
72749diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72750index 5f1ab92..39c35ae 100644
72751--- a/include/linux/devfreq.h
72752+++ b/include/linux/devfreq.h
72753@@ -114,7 +114,7 @@ struct devfreq_governor {
72754 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72755 int (*event_handler)(struct devfreq *devfreq,
72756 unsigned int event, void *data);
72757-};
72758+} __do_const;
72759
72760 /**
72761 * struct devfreq - Device devfreq structure
72762diff --git a/include/linux/device.h b/include/linux/device.h
72763index 22b546a..a573dc9 100644
72764--- a/include/linux/device.h
72765+++ b/include/linux/device.h
72766@@ -305,7 +305,7 @@ struct subsys_interface {
72767 struct list_head node;
72768 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72769 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72770-};
72771+} __do_const;
72772
72773 int subsys_interface_register(struct subsys_interface *sif);
72774 void subsys_interface_unregister(struct subsys_interface *sif);
72775@@ -493,7 +493,7 @@ struct device_type {
72776 void (*release)(struct device *dev);
72777
72778 const struct dev_pm_ops *pm;
72779-};
72780+} __do_const;
72781
72782 /* interface for exporting device attributes */
72783 struct device_attribute {
72784@@ -503,11 +503,12 @@ struct device_attribute {
72785 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72786 const char *buf, size_t count);
72787 };
72788+typedef struct device_attribute __no_const device_attribute_no_const;
72789
72790 struct dev_ext_attribute {
72791 struct device_attribute attr;
72792 void *var;
72793-};
72794+} __do_const;
72795
72796 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72797 char *buf);
72798diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72799index 94af418..b1ca7a2 100644
72800--- a/include/linux/dma-mapping.h
72801+++ b/include/linux/dma-mapping.h
72802@@ -54,7 +54,7 @@ struct dma_map_ops {
72803 u64 (*get_required_mask)(struct device *dev);
72804 #endif
72805 int is_phys;
72806-};
72807+} __do_const;
72808
72809 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72810
72811diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72812index cb286b1..923d066 100644
72813--- a/include/linux/dmaengine.h
72814+++ b/include/linux/dmaengine.h
72815@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72816 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72817 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72818
72819-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72820+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72821 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72822-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72823+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72824 struct dma_pinned_list *pinned_list, struct page *page,
72825 unsigned int offset, size_t len);
72826
72827diff --git a/include/linux/efi.h b/include/linux/efi.h
72828index 5f8f176..62a0556 100644
72829--- a/include/linux/efi.h
72830+++ b/include/linux/efi.h
72831@@ -745,6 +745,7 @@ struct efivar_operations {
72832 efi_set_variable_t *set_variable;
72833 efi_query_variable_store_t *query_variable_store;
72834 };
72835+typedef struct efivar_operations __no_const efivar_operations_no_const;
72836
72837 struct efivars {
72838 /*
72839diff --git a/include/linux/elf.h b/include/linux/elf.h
72840index 40a3c0e..4c45a38 100644
72841--- a/include/linux/elf.h
72842+++ b/include/linux/elf.h
72843@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72844 #define elf_note elf32_note
72845 #define elf_addr_t Elf32_Off
72846 #define Elf_Half Elf32_Half
72847+#define elf_dyn Elf32_Dyn
72848
72849 #else
72850
72851@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72852 #define elf_note elf64_note
72853 #define elf_addr_t Elf64_Off
72854 #define Elf_Half Elf64_Half
72855+#define elf_dyn Elf64_Dyn
72856
72857 #endif
72858
72859diff --git a/include/linux/err.h b/include/linux/err.h
72860index 221fcfb..f29e5e2 100644
72861--- a/include/linux/err.h
72862+++ b/include/linux/err.h
72863@@ -19,12 +19,12 @@
72864
72865 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72866
72867-static inline void * __must_check ERR_PTR(long error)
72868+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72869 {
72870 return (void *) error;
72871 }
72872
72873-static inline long __must_check PTR_ERR(__force const void *ptr)
72874+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72875 {
72876 return (long) ptr;
72877 }
72878diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72879index fcb51c8..bdafcf6 100644
72880--- a/include/linux/extcon.h
72881+++ b/include/linux/extcon.h
72882@@ -134,7 +134,7 @@ struct extcon_dev {
72883 /* /sys/class/extcon/.../mutually_exclusive/... */
72884 struct attribute_group attr_g_muex;
72885 struct attribute **attrs_muex;
72886- struct device_attribute *d_attrs_muex;
72887+ device_attribute_no_const *d_attrs_muex;
72888 };
72889
72890 /**
72891diff --git a/include/linux/fb.h b/include/linux/fb.h
72892index ffac70a..ca3e711 100644
72893--- a/include/linux/fb.h
72894+++ b/include/linux/fb.h
72895@@ -304,7 +304,7 @@ struct fb_ops {
72896 /* called at KDB enter and leave time to prepare the console */
72897 int (*fb_debug_enter)(struct fb_info *info);
72898 int (*fb_debug_leave)(struct fb_info *info);
72899-};
72900+} __do_const;
72901
72902 #ifdef CONFIG_FB_TILEBLITTING
72903 #define FB_TILE_CURSOR_NONE 0
72904diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72905index 085197b..0fa6f0b 100644
72906--- a/include/linux/fdtable.h
72907+++ b/include/linux/fdtable.h
72908@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72909 void put_files_struct(struct files_struct *fs);
72910 void reset_files_struct(struct files_struct *);
72911 int unshare_files(struct files_struct **);
72912-struct files_struct *dup_fd(struct files_struct *, int *);
72913+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72914 void do_close_on_exec(struct files_struct *);
72915 int iterate_fd(struct files_struct *, unsigned,
72916 int (*)(const void *, struct file *, unsigned),
72917diff --git a/include/linux/filter.h b/include/linux/filter.h
72918index a6ac848..a104a76 100644
72919--- a/include/linux/filter.h
72920+++ b/include/linux/filter.h
72921@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72922
72923 struct sk_buff;
72924 struct sock;
72925+struct bpf_jit_work;
72926
72927 struct sk_filter
72928 {
72929@@ -27,6 +28,9 @@ struct sk_filter
72930 unsigned int len; /* Number of filter blocks */
72931 unsigned int (*bpf_func)(const struct sk_buff *skb,
72932 const struct sock_filter *filter);
72933+#ifdef CONFIG_BPF_JIT
72934+ struct bpf_jit_work *work;
72935+#endif
72936 struct rcu_head rcu;
72937 struct sock_filter insns[0];
72938 };
72939diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72940index 8293262..2b3b8bd 100644
72941--- a/include/linux/frontswap.h
72942+++ b/include/linux/frontswap.h
72943@@ -11,7 +11,7 @@ struct frontswap_ops {
72944 int (*load)(unsigned, pgoff_t, struct page *);
72945 void (*invalidate_page)(unsigned, pgoff_t);
72946 void (*invalidate_area)(unsigned);
72947-};
72948+} __no_const;
72949
72950 extern bool frontswap_enabled;
72951 extern struct frontswap_ops *
72952diff --git a/include/linux/fs.h b/include/linux/fs.h
72953index 9818747..788bfbd 100644
72954--- a/include/linux/fs.h
72955+++ b/include/linux/fs.h
72956@@ -1554,7 +1554,8 @@ struct file_operations {
72957 long (*fallocate)(struct file *file, int mode, loff_t offset,
72958 loff_t len);
72959 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72960-};
72961+} __do_const;
72962+typedef struct file_operations __no_const file_operations_no_const;
72963
72964 struct inode_operations {
72965 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72966@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72967 return !IS_DEADDIR(inode);
72968 }
72969
72970+static inline bool is_sidechannel_device(const struct inode *inode)
72971+{
72972+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72973+ umode_t mode = inode->i_mode;
72974+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72975+#else
72976+ return false;
72977+#endif
72978+}
72979+
72980 #endif /* _LINUX_FS_H */
72981diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72982index 2b93a9a..855d94a 100644
72983--- a/include/linux/fs_struct.h
72984+++ b/include/linux/fs_struct.h
72985@@ -6,7 +6,7 @@
72986 #include <linux/seqlock.h>
72987
72988 struct fs_struct {
72989- int users;
72990+ atomic_t users;
72991 spinlock_t lock;
72992 seqcount_t seq;
72993 int umask;
72994diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72995index a9ff9a3..1ba1788 100644
72996--- a/include/linux/fscache-cache.h
72997+++ b/include/linux/fscache-cache.h
72998@@ -113,7 +113,7 @@ struct fscache_operation {
72999 fscache_operation_release_t release;
73000 };
73001
73002-extern atomic_t fscache_op_debug_id;
73003+extern atomic_unchecked_t fscache_op_debug_id;
73004 extern void fscache_op_work_func(struct work_struct *work);
73005
73006 extern void fscache_enqueue_operation(struct fscache_operation *);
73007@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73008 INIT_WORK(&op->work, fscache_op_work_func);
73009 atomic_set(&op->usage, 1);
73010 op->state = FSCACHE_OP_ST_INITIALISED;
73011- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73012+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73013 op->processor = processor;
73014 op->release = release;
73015 INIT_LIST_HEAD(&op->pend_link);
73016diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73017index 7a08623..4c07b0f 100644
73018--- a/include/linux/fscache.h
73019+++ b/include/linux/fscache.h
73020@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73021 * - this is mandatory for any object that may have data
73022 */
73023 void (*now_uncached)(void *cookie_netfs_data);
73024-};
73025+} __do_const;
73026
73027 /*
73028 * fscache cached network filesystem type
73029diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73030index 1c804b0..1432c2b 100644
73031--- a/include/linux/fsnotify.h
73032+++ b/include/linux/fsnotify.h
73033@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73034 struct inode *inode = file_inode(file);
73035 __u32 mask = FS_ACCESS;
73036
73037+ if (is_sidechannel_device(inode))
73038+ return;
73039+
73040 if (S_ISDIR(inode->i_mode))
73041 mask |= FS_ISDIR;
73042
73043@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73044 struct inode *inode = file_inode(file);
73045 __u32 mask = FS_MODIFY;
73046
73047+ if (is_sidechannel_device(inode))
73048+ return;
73049+
73050 if (S_ISDIR(inode->i_mode))
73051 mask |= FS_ISDIR;
73052
73053@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73054 */
73055 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73056 {
73057- return kstrdup(name, GFP_KERNEL);
73058+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73059 }
73060
73061 /*
73062diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73063index 9f3c275..8bdff5d 100644
73064--- a/include/linux/genhd.h
73065+++ b/include/linux/genhd.h
73066@@ -194,7 +194,7 @@ struct gendisk {
73067 struct kobject *slave_dir;
73068
73069 struct timer_rand_state *random;
73070- atomic_t sync_io; /* RAID */
73071+ atomic_unchecked_t sync_io; /* RAID */
73072 struct disk_events *ev;
73073 #ifdef CONFIG_BLK_DEV_INTEGRITY
73074 struct blk_integrity *integrity;
73075@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73076 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73077
73078 /* drivers/char/random.c */
73079-extern void add_disk_randomness(struct gendisk *disk);
73080+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73081 extern void rand_initialize_disk(struct gendisk *disk);
73082
73083 static inline sector_t get_start_sect(struct block_device *bdev)
73084diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73085index 023bc34..b02b46a 100644
73086--- a/include/linux/genl_magic_func.h
73087+++ b/include/linux/genl_magic_func.h
73088@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73089 },
73090
73091 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73092-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73093+static struct genl_ops ZZZ_genl_ops[] = {
73094 #include GENL_MAGIC_INCLUDE_FILE
73095 };
73096
73097diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73098index 9b4dd49..61fd41d 100644
73099--- a/include/linux/gfp.h
73100+++ b/include/linux/gfp.h
73101@@ -35,6 +35,13 @@ struct vm_area_struct;
73102 #define ___GFP_NO_KSWAPD 0x400000u
73103 #define ___GFP_OTHER_NODE 0x800000u
73104 #define ___GFP_WRITE 0x1000000u
73105+
73106+#ifdef CONFIG_PAX_USERCOPY_SLABS
73107+#define ___GFP_USERCOPY 0x2000000u
73108+#else
73109+#define ___GFP_USERCOPY 0
73110+#endif
73111+
73112 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73113
73114 /*
73115@@ -92,6 +99,7 @@ struct vm_area_struct;
73116 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73117 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73118 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73119+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73120
73121 /*
73122 * This may seem redundant, but it's a way of annotating false positives vs.
73123@@ -99,7 +107,7 @@ struct vm_area_struct;
73124 */
73125 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73126
73127-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73128+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73129 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73130
73131 /* This equals 0, but use constants in case they ever change */
73132@@ -153,6 +161,8 @@ struct vm_area_struct;
73133 /* 4GB DMA on some platforms */
73134 #define GFP_DMA32 __GFP_DMA32
73135
73136+#define GFP_USERCOPY __GFP_USERCOPY
73137+
73138 /* Convert GFP flags to their corresponding migrate type */
73139 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73140 {
73141diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73142new file mode 100644
73143index 0000000..ebe6d72
73144--- /dev/null
73145+++ b/include/linux/gracl.h
73146@@ -0,0 +1,319 @@
73147+#ifndef GR_ACL_H
73148+#define GR_ACL_H
73149+
73150+#include <linux/grdefs.h>
73151+#include <linux/resource.h>
73152+#include <linux/capability.h>
73153+#include <linux/dcache.h>
73154+#include <asm/resource.h>
73155+
73156+/* Major status information */
73157+
73158+#define GR_VERSION "grsecurity 2.9.1"
73159+#define GRSECURITY_VERSION 0x2901
73160+
73161+enum {
73162+ GR_SHUTDOWN = 0,
73163+ GR_ENABLE = 1,
73164+ GR_SPROLE = 2,
73165+ GR_RELOAD = 3,
73166+ GR_SEGVMOD = 4,
73167+ GR_STATUS = 5,
73168+ GR_UNSPROLE = 6,
73169+ GR_PASSSET = 7,
73170+ GR_SPROLEPAM = 8,
73171+};
73172+
73173+/* Password setup definitions
73174+ * kernel/grhash.c */
73175+enum {
73176+ GR_PW_LEN = 128,
73177+ GR_SALT_LEN = 16,
73178+ GR_SHA_LEN = 32,
73179+};
73180+
73181+enum {
73182+ GR_SPROLE_LEN = 64,
73183+};
73184+
73185+enum {
73186+ GR_NO_GLOB = 0,
73187+ GR_REG_GLOB,
73188+ GR_CREATE_GLOB
73189+};
73190+
73191+#define GR_NLIMITS 32
73192+
73193+/* Begin Data Structures */
73194+
73195+struct sprole_pw {
73196+ unsigned char *rolename;
73197+ unsigned char salt[GR_SALT_LEN];
73198+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73199+};
73200+
73201+struct name_entry {
73202+ __u32 key;
73203+ ino_t inode;
73204+ dev_t device;
73205+ char *name;
73206+ __u16 len;
73207+ __u8 deleted;
73208+ struct name_entry *prev;
73209+ struct name_entry *next;
73210+};
73211+
73212+struct inodev_entry {
73213+ struct name_entry *nentry;
73214+ struct inodev_entry *prev;
73215+ struct inodev_entry *next;
73216+};
73217+
73218+struct acl_role_db {
73219+ struct acl_role_label **r_hash;
73220+ __u32 r_size;
73221+};
73222+
73223+struct inodev_db {
73224+ struct inodev_entry **i_hash;
73225+ __u32 i_size;
73226+};
73227+
73228+struct name_db {
73229+ struct name_entry **n_hash;
73230+ __u32 n_size;
73231+};
73232+
73233+struct crash_uid {
73234+ uid_t uid;
73235+ unsigned long expires;
73236+};
73237+
73238+struct gr_hash_struct {
73239+ void **table;
73240+ void **nametable;
73241+ void *first;
73242+ __u32 table_size;
73243+ __u32 used_size;
73244+ int type;
73245+};
73246+
73247+/* Userspace Grsecurity ACL data structures */
73248+
73249+struct acl_subject_label {
73250+ char *filename;
73251+ ino_t inode;
73252+ dev_t device;
73253+ __u32 mode;
73254+ kernel_cap_t cap_mask;
73255+ kernel_cap_t cap_lower;
73256+ kernel_cap_t cap_invert_audit;
73257+
73258+ struct rlimit res[GR_NLIMITS];
73259+ __u32 resmask;
73260+
73261+ __u8 user_trans_type;
73262+ __u8 group_trans_type;
73263+ uid_t *user_transitions;
73264+ gid_t *group_transitions;
73265+ __u16 user_trans_num;
73266+ __u16 group_trans_num;
73267+
73268+ __u32 sock_families[2];
73269+ __u32 ip_proto[8];
73270+ __u32 ip_type;
73271+ struct acl_ip_label **ips;
73272+ __u32 ip_num;
73273+ __u32 inaddr_any_override;
73274+
73275+ __u32 crashes;
73276+ unsigned long expires;
73277+
73278+ struct acl_subject_label *parent_subject;
73279+ struct gr_hash_struct *hash;
73280+ struct acl_subject_label *prev;
73281+ struct acl_subject_label *next;
73282+
73283+ struct acl_object_label **obj_hash;
73284+ __u32 obj_hash_size;
73285+ __u16 pax_flags;
73286+};
73287+
73288+struct role_allowed_ip {
73289+ __u32 addr;
73290+ __u32 netmask;
73291+
73292+ struct role_allowed_ip *prev;
73293+ struct role_allowed_ip *next;
73294+};
73295+
73296+struct role_transition {
73297+ char *rolename;
73298+
73299+ struct role_transition *prev;
73300+ struct role_transition *next;
73301+};
73302+
73303+struct acl_role_label {
73304+ char *rolename;
73305+ uid_t uidgid;
73306+ __u16 roletype;
73307+
73308+ __u16 auth_attempts;
73309+ unsigned long expires;
73310+
73311+ struct acl_subject_label *root_label;
73312+ struct gr_hash_struct *hash;
73313+
73314+ struct acl_role_label *prev;
73315+ struct acl_role_label *next;
73316+
73317+ struct role_transition *transitions;
73318+ struct role_allowed_ip *allowed_ips;
73319+ uid_t *domain_children;
73320+ __u16 domain_child_num;
73321+
73322+ umode_t umask;
73323+
73324+ struct acl_subject_label **subj_hash;
73325+ __u32 subj_hash_size;
73326+};
73327+
73328+struct user_acl_role_db {
73329+ struct acl_role_label **r_table;
73330+ __u32 num_pointers; /* Number of allocations to track */
73331+ __u32 num_roles; /* Number of roles */
73332+ __u32 num_domain_children; /* Number of domain children */
73333+ __u32 num_subjects; /* Number of subjects */
73334+ __u32 num_objects; /* Number of objects */
73335+};
73336+
73337+struct acl_object_label {
73338+ char *filename;
73339+ ino_t inode;
73340+ dev_t device;
73341+ __u32 mode;
73342+
73343+ struct acl_subject_label *nested;
73344+ struct acl_object_label *globbed;
73345+
73346+ /* next two structures not used */
73347+
73348+ struct acl_object_label *prev;
73349+ struct acl_object_label *next;
73350+};
73351+
73352+struct acl_ip_label {
73353+ char *iface;
73354+ __u32 addr;
73355+ __u32 netmask;
73356+ __u16 low, high;
73357+ __u8 mode;
73358+ __u32 type;
73359+ __u32 proto[8];
73360+
73361+ /* next two structures not used */
73362+
73363+ struct acl_ip_label *prev;
73364+ struct acl_ip_label *next;
73365+};
73366+
73367+struct gr_arg {
73368+ struct user_acl_role_db role_db;
73369+ unsigned char pw[GR_PW_LEN];
73370+ unsigned char salt[GR_SALT_LEN];
73371+ unsigned char sum[GR_SHA_LEN];
73372+ unsigned char sp_role[GR_SPROLE_LEN];
73373+ struct sprole_pw *sprole_pws;
73374+ dev_t segv_device;
73375+ ino_t segv_inode;
73376+ uid_t segv_uid;
73377+ __u16 num_sprole_pws;
73378+ __u16 mode;
73379+};
73380+
73381+struct gr_arg_wrapper {
73382+ struct gr_arg *arg;
73383+ __u32 version;
73384+ __u32 size;
73385+};
73386+
73387+struct subject_map {
73388+ struct acl_subject_label *user;
73389+ struct acl_subject_label *kernel;
73390+ struct subject_map *prev;
73391+ struct subject_map *next;
73392+};
73393+
73394+struct acl_subj_map_db {
73395+ struct subject_map **s_hash;
73396+ __u32 s_size;
73397+};
73398+
73399+/* End Data Structures Section */
73400+
73401+/* Hash functions generated by empirical testing by Brad Spengler
73402+ Makes good use of the low bits of the inode. Generally 0-1 times
73403+ in loop for successful match. 0-3 for unsuccessful match.
73404+ Shift/add algorithm with modulus of table size and an XOR*/
73405+
73406+static __inline__ unsigned int
73407+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73408+{
73409+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73410+}
73411+
73412+ static __inline__ unsigned int
73413+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73414+{
73415+ return ((const unsigned long)userp % sz);
73416+}
73417+
73418+static __inline__ unsigned int
73419+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73420+{
73421+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73422+}
73423+
73424+static __inline__ unsigned int
73425+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73426+{
73427+ return full_name_hash((const unsigned char *)name, len) % sz;
73428+}
73429+
73430+#define FOR_EACH_ROLE_START(role) \
73431+ role = role_list; \
73432+ while (role) {
73433+
73434+#define FOR_EACH_ROLE_END(role) \
73435+ role = role->prev; \
73436+ }
73437+
73438+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73439+ subj = NULL; \
73440+ iter = 0; \
73441+ while (iter < role->subj_hash_size) { \
73442+ if (subj == NULL) \
73443+ subj = role->subj_hash[iter]; \
73444+ if (subj == NULL) { \
73445+ iter++; \
73446+ continue; \
73447+ }
73448+
73449+#define FOR_EACH_SUBJECT_END(subj,iter) \
73450+ subj = subj->next; \
73451+ if (subj == NULL) \
73452+ iter++; \
73453+ }
73454+
73455+
73456+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73457+ subj = role->hash->first; \
73458+ while (subj != NULL) {
73459+
73460+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73461+ subj = subj->next; \
73462+ }
73463+
73464+#endif
73465+
73466diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73467new file mode 100644
73468index 0000000..33ebd1f
73469--- /dev/null
73470+++ b/include/linux/gracl_compat.h
73471@@ -0,0 +1,156 @@
73472+#ifndef GR_ACL_COMPAT_H
73473+#define GR_ACL_COMPAT_H
73474+
73475+#include <linux/resource.h>
73476+#include <asm/resource.h>
73477+
73478+struct sprole_pw_compat {
73479+ compat_uptr_t rolename;
73480+ unsigned char salt[GR_SALT_LEN];
73481+ unsigned char sum[GR_SHA_LEN];
73482+};
73483+
73484+struct gr_hash_struct_compat {
73485+ compat_uptr_t table;
73486+ compat_uptr_t nametable;
73487+ compat_uptr_t first;
73488+ __u32 table_size;
73489+ __u32 used_size;
73490+ int type;
73491+};
73492+
73493+struct acl_subject_label_compat {
73494+ compat_uptr_t filename;
73495+ compat_ino_t inode;
73496+ __u32 device;
73497+ __u32 mode;
73498+ kernel_cap_t cap_mask;
73499+ kernel_cap_t cap_lower;
73500+ kernel_cap_t cap_invert_audit;
73501+
73502+ struct compat_rlimit res[GR_NLIMITS];
73503+ __u32 resmask;
73504+
73505+ __u8 user_trans_type;
73506+ __u8 group_trans_type;
73507+ compat_uptr_t user_transitions;
73508+ compat_uptr_t group_transitions;
73509+ __u16 user_trans_num;
73510+ __u16 group_trans_num;
73511+
73512+ __u32 sock_families[2];
73513+ __u32 ip_proto[8];
73514+ __u32 ip_type;
73515+ compat_uptr_t ips;
73516+ __u32 ip_num;
73517+ __u32 inaddr_any_override;
73518+
73519+ __u32 crashes;
73520+ compat_ulong_t expires;
73521+
73522+ compat_uptr_t parent_subject;
73523+ compat_uptr_t hash;
73524+ compat_uptr_t prev;
73525+ compat_uptr_t next;
73526+
73527+ compat_uptr_t obj_hash;
73528+ __u32 obj_hash_size;
73529+ __u16 pax_flags;
73530+};
73531+
73532+struct role_allowed_ip_compat {
73533+ __u32 addr;
73534+ __u32 netmask;
73535+
73536+ compat_uptr_t prev;
73537+ compat_uptr_t next;
73538+};
73539+
73540+struct role_transition_compat {
73541+ compat_uptr_t rolename;
73542+
73543+ compat_uptr_t prev;
73544+ compat_uptr_t next;
73545+};
73546+
73547+struct acl_role_label_compat {
73548+ compat_uptr_t rolename;
73549+ uid_t uidgid;
73550+ __u16 roletype;
73551+
73552+ __u16 auth_attempts;
73553+ compat_ulong_t expires;
73554+
73555+ compat_uptr_t root_label;
73556+ compat_uptr_t hash;
73557+
73558+ compat_uptr_t prev;
73559+ compat_uptr_t next;
73560+
73561+ compat_uptr_t transitions;
73562+ compat_uptr_t allowed_ips;
73563+ compat_uptr_t domain_children;
73564+ __u16 domain_child_num;
73565+
73566+ umode_t umask;
73567+
73568+ compat_uptr_t subj_hash;
73569+ __u32 subj_hash_size;
73570+};
73571+
73572+struct user_acl_role_db_compat {
73573+ compat_uptr_t r_table;
73574+ __u32 num_pointers;
73575+ __u32 num_roles;
73576+ __u32 num_domain_children;
73577+ __u32 num_subjects;
73578+ __u32 num_objects;
73579+};
73580+
73581+struct acl_object_label_compat {
73582+ compat_uptr_t filename;
73583+ compat_ino_t inode;
73584+ __u32 device;
73585+ __u32 mode;
73586+
73587+ compat_uptr_t nested;
73588+ compat_uptr_t globbed;
73589+
73590+ compat_uptr_t prev;
73591+ compat_uptr_t next;
73592+};
73593+
73594+struct acl_ip_label_compat {
73595+ compat_uptr_t iface;
73596+ __u32 addr;
73597+ __u32 netmask;
73598+ __u16 low, high;
73599+ __u8 mode;
73600+ __u32 type;
73601+ __u32 proto[8];
73602+
73603+ compat_uptr_t prev;
73604+ compat_uptr_t next;
73605+};
73606+
73607+struct gr_arg_compat {
73608+ struct user_acl_role_db_compat role_db;
73609+ unsigned char pw[GR_PW_LEN];
73610+ unsigned char salt[GR_SALT_LEN];
73611+ unsigned char sum[GR_SHA_LEN];
73612+ unsigned char sp_role[GR_SPROLE_LEN];
73613+ compat_uptr_t sprole_pws;
73614+ __u32 segv_device;
73615+ compat_ino_t segv_inode;
73616+ uid_t segv_uid;
73617+ __u16 num_sprole_pws;
73618+ __u16 mode;
73619+};
73620+
73621+struct gr_arg_wrapper_compat {
73622+ compat_uptr_t arg;
73623+ __u32 version;
73624+ __u32 size;
73625+};
73626+
73627+#endif
73628diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73629new file mode 100644
73630index 0000000..323ecf2
73631--- /dev/null
73632+++ b/include/linux/gralloc.h
73633@@ -0,0 +1,9 @@
73634+#ifndef __GRALLOC_H
73635+#define __GRALLOC_H
73636+
73637+void acl_free_all(void);
73638+int acl_alloc_stack_init(unsigned long size);
73639+void *acl_alloc(unsigned long len);
73640+void *acl_alloc_num(unsigned long num, unsigned long len);
73641+
73642+#endif
73643diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73644new file mode 100644
73645index 0000000..be66033
73646--- /dev/null
73647+++ b/include/linux/grdefs.h
73648@@ -0,0 +1,140 @@
73649+#ifndef GRDEFS_H
73650+#define GRDEFS_H
73651+
73652+/* Begin grsecurity status declarations */
73653+
73654+enum {
73655+ GR_READY = 0x01,
73656+ GR_STATUS_INIT = 0x00 // disabled state
73657+};
73658+
73659+/* Begin ACL declarations */
73660+
73661+/* Role flags */
73662+
73663+enum {
73664+ GR_ROLE_USER = 0x0001,
73665+ GR_ROLE_GROUP = 0x0002,
73666+ GR_ROLE_DEFAULT = 0x0004,
73667+ GR_ROLE_SPECIAL = 0x0008,
73668+ GR_ROLE_AUTH = 0x0010,
73669+ GR_ROLE_NOPW = 0x0020,
73670+ GR_ROLE_GOD = 0x0040,
73671+ GR_ROLE_LEARN = 0x0080,
73672+ GR_ROLE_TPE = 0x0100,
73673+ GR_ROLE_DOMAIN = 0x0200,
73674+ GR_ROLE_PAM = 0x0400,
73675+ GR_ROLE_PERSIST = 0x0800
73676+};
73677+
73678+/* ACL Subject and Object mode flags */
73679+enum {
73680+ GR_DELETED = 0x80000000
73681+};
73682+
73683+/* ACL Object-only mode flags */
73684+enum {
73685+ GR_READ = 0x00000001,
73686+ GR_APPEND = 0x00000002,
73687+ GR_WRITE = 0x00000004,
73688+ GR_EXEC = 0x00000008,
73689+ GR_FIND = 0x00000010,
73690+ GR_INHERIT = 0x00000020,
73691+ GR_SETID = 0x00000040,
73692+ GR_CREATE = 0x00000080,
73693+ GR_DELETE = 0x00000100,
73694+ GR_LINK = 0x00000200,
73695+ GR_AUDIT_READ = 0x00000400,
73696+ GR_AUDIT_APPEND = 0x00000800,
73697+ GR_AUDIT_WRITE = 0x00001000,
73698+ GR_AUDIT_EXEC = 0x00002000,
73699+ GR_AUDIT_FIND = 0x00004000,
73700+ GR_AUDIT_INHERIT= 0x00008000,
73701+ GR_AUDIT_SETID = 0x00010000,
73702+ GR_AUDIT_CREATE = 0x00020000,
73703+ GR_AUDIT_DELETE = 0x00040000,
73704+ GR_AUDIT_LINK = 0x00080000,
73705+ GR_PTRACERD = 0x00100000,
73706+ GR_NOPTRACE = 0x00200000,
73707+ GR_SUPPRESS = 0x00400000,
73708+ GR_NOLEARN = 0x00800000,
73709+ GR_INIT_TRANSFER= 0x01000000
73710+};
73711+
73712+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73713+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73714+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73715+
73716+/* ACL subject-only mode flags */
73717+enum {
73718+ GR_KILL = 0x00000001,
73719+ GR_VIEW = 0x00000002,
73720+ GR_PROTECTED = 0x00000004,
73721+ GR_LEARN = 0x00000008,
73722+ GR_OVERRIDE = 0x00000010,
73723+ /* just a placeholder, this mode is only used in userspace */
73724+ GR_DUMMY = 0x00000020,
73725+ GR_PROTSHM = 0x00000040,
73726+ GR_KILLPROC = 0x00000080,
73727+ GR_KILLIPPROC = 0x00000100,
73728+ /* just a placeholder, this mode is only used in userspace */
73729+ GR_NOTROJAN = 0x00000200,
73730+ GR_PROTPROCFD = 0x00000400,
73731+ GR_PROCACCT = 0x00000800,
73732+ GR_RELAXPTRACE = 0x00001000,
73733+ //GR_NESTED = 0x00002000,
73734+ GR_INHERITLEARN = 0x00004000,
73735+ GR_PROCFIND = 0x00008000,
73736+ GR_POVERRIDE = 0x00010000,
73737+ GR_KERNELAUTH = 0x00020000,
73738+ GR_ATSECURE = 0x00040000,
73739+ GR_SHMEXEC = 0x00080000
73740+};
73741+
73742+enum {
73743+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73744+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73745+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73746+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73747+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73748+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73749+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73750+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73751+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73752+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73753+};
73754+
73755+enum {
73756+ GR_ID_USER = 0x01,
73757+ GR_ID_GROUP = 0x02,
73758+};
73759+
73760+enum {
73761+ GR_ID_ALLOW = 0x01,
73762+ GR_ID_DENY = 0x02,
73763+};
73764+
73765+#define GR_CRASH_RES 31
73766+#define GR_UIDTABLE_MAX 500
73767+
73768+/* begin resource learning section */
73769+enum {
73770+ GR_RLIM_CPU_BUMP = 60,
73771+ GR_RLIM_FSIZE_BUMP = 50000,
73772+ GR_RLIM_DATA_BUMP = 10000,
73773+ GR_RLIM_STACK_BUMP = 1000,
73774+ GR_RLIM_CORE_BUMP = 10000,
73775+ GR_RLIM_RSS_BUMP = 500000,
73776+ GR_RLIM_NPROC_BUMP = 1,
73777+ GR_RLIM_NOFILE_BUMP = 5,
73778+ GR_RLIM_MEMLOCK_BUMP = 50000,
73779+ GR_RLIM_AS_BUMP = 500000,
73780+ GR_RLIM_LOCKS_BUMP = 2,
73781+ GR_RLIM_SIGPENDING_BUMP = 5,
73782+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73783+ GR_RLIM_NICE_BUMP = 1,
73784+ GR_RLIM_RTPRIO_BUMP = 1,
73785+ GR_RLIM_RTTIME_BUMP = 1000000
73786+};
73787+
73788+#endif
73789diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73790new file mode 100644
73791index 0000000..e337683
73792--- /dev/null
73793+++ b/include/linux/grinternal.h
73794@@ -0,0 +1,229 @@
73795+#ifndef __GRINTERNAL_H
73796+#define __GRINTERNAL_H
73797+
73798+#ifdef CONFIG_GRKERNSEC
73799+
73800+#include <linux/fs.h>
73801+#include <linux/mnt_namespace.h>
73802+#include <linux/nsproxy.h>
73803+#include <linux/gracl.h>
73804+#include <linux/grdefs.h>
73805+#include <linux/grmsg.h>
73806+
73807+void gr_add_learn_entry(const char *fmt, ...)
73808+ __attribute__ ((format (printf, 1, 2)));
73809+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73810+ const struct vfsmount *mnt);
73811+__u32 gr_check_create(const struct dentry *new_dentry,
73812+ const struct dentry *parent,
73813+ const struct vfsmount *mnt, const __u32 mode);
73814+int gr_check_protected_task(const struct task_struct *task);
73815+__u32 to_gr_audit(const __u32 reqmode);
73816+int gr_set_acls(const int type);
73817+int gr_apply_subject_to_task(struct task_struct *task);
73818+int gr_acl_is_enabled(void);
73819+char gr_roletype_to_char(void);
73820+
73821+void gr_handle_alertkill(struct task_struct *task);
73822+char *gr_to_filename(const struct dentry *dentry,
73823+ const struct vfsmount *mnt);
73824+char *gr_to_filename1(const struct dentry *dentry,
73825+ const struct vfsmount *mnt);
73826+char *gr_to_filename2(const struct dentry *dentry,
73827+ const struct vfsmount *mnt);
73828+char *gr_to_filename3(const struct dentry *dentry,
73829+ const struct vfsmount *mnt);
73830+
73831+extern int grsec_enable_ptrace_readexec;
73832+extern int grsec_enable_harden_ptrace;
73833+extern int grsec_enable_link;
73834+extern int grsec_enable_fifo;
73835+extern int grsec_enable_execve;
73836+extern int grsec_enable_shm;
73837+extern int grsec_enable_execlog;
73838+extern int grsec_enable_signal;
73839+extern int grsec_enable_audit_ptrace;
73840+extern int grsec_enable_forkfail;
73841+extern int grsec_enable_time;
73842+extern int grsec_enable_rofs;
73843+extern int grsec_deny_new_usb;
73844+extern int grsec_enable_chroot_shmat;
73845+extern int grsec_enable_chroot_mount;
73846+extern int grsec_enable_chroot_double;
73847+extern int grsec_enable_chroot_pivot;
73848+extern int grsec_enable_chroot_chdir;
73849+extern int grsec_enable_chroot_chmod;
73850+extern int grsec_enable_chroot_mknod;
73851+extern int grsec_enable_chroot_fchdir;
73852+extern int grsec_enable_chroot_nice;
73853+extern int grsec_enable_chroot_execlog;
73854+extern int grsec_enable_chroot_caps;
73855+extern int grsec_enable_chroot_sysctl;
73856+extern int grsec_enable_chroot_unix;
73857+extern int grsec_enable_symlinkown;
73858+extern kgid_t grsec_symlinkown_gid;
73859+extern int grsec_enable_tpe;
73860+extern kgid_t grsec_tpe_gid;
73861+extern int grsec_enable_tpe_all;
73862+extern int grsec_enable_tpe_invert;
73863+extern int grsec_enable_socket_all;
73864+extern kgid_t grsec_socket_all_gid;
73865+extern int grsec_enable_socket_client;
73866+extern kgid_t grsec_socket_client_gid;
73867+extern int grsec_enable_socket_server;
73868+extern kgid_t grsec_socket_server_gid;
73869+extern kgid_t grsec_audit_gid;
73870+extern int grsec_enable_group;
73871+extern int grsec_enable_log_rwxmaps;
73872+extern int grsec_enable_mount;
73873+extern int grsec_enable_chdir;
73874+extern int grsec_resource_logging;
73875+extern int grsec_enable_blackhole;
73876+extern int grsec_lastack_retries;
73877+extern int grsec_enable_brute;
73878+extern int grsec_lock;
73879+
73880+extern spinlock_t grsec_alert_lock;
73881+extern unsigned long grsec_alert_wtime;
73882+extern unsigned long grsec_alert_fyet;
73883+
73884+extern spinlock_t grsec_audit_lock;
73885+
73886+extern rwlock_t grsec_exec_file_lock;
73887+
73888+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73889+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73890+ (tsk)->exec_file->f_path.mnt) : "/")
73891+
73892+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73893+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73894+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73895+
73896+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73897+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73898+ (tsk)->exec_file->f_path.mnt) : "/")
73899+
73900+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73901+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73902+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73903+
73904+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73905+
73906+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73907+
73908+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73909+{
73910+ if (file1 && file2) {
73911+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73912+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73913+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73914+ return true;
73915+ }
73916+
73917+ return false;
73918+}
73919+
73920+#define GR_CHROOT_CAPS {{ \
73921+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73922+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73923+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73924+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73925+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73926+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73927+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73928+
73929+#define security_learn(normal_msg,args...) \
73930+({ \
73931+ read_lock(&grsec_exec_file_lock); \
73932+ gr_add_learn_entry(normal_msg "\n", ## args); \
73933+ read_unlock(&grsec_exec_file_lock); \
73934+})
73935+
73936+enum {
73937+ GR_DO_AUDIT,
73938+ GR_DONT_AUDIT,
73939+ /* used for non-audit messages that we shouldn't kill the task on */
73940+ GR_DONT_AUDIT_GOOD
73941+};
73942+
73943+enum {
73944+ GR_TTYSNIFF,
73945+ GR_RBAC,
73946+ GR_RBAC_STR,
73947+ GR_STR_RBAC,
73948+ GR_RBAC_MODE2,
73949+ GR_RBAC_MODE3,
73950+ GR_FILENAME,
73951+ GR_SYSCTL_HIDDEN,
73952+ GR_NOARGS,
73953+ GR_ONE_INT,
73954+ GR_ONE_INT_TWO_STR,
73955+ GR_ONE_STR,
73956+ GR_STR_INT,
73957+ GR_TWO_STR_INT,
73958+ GR_TWO_INT,
73959+ GR_TWO_U64,
73960+ GR_THREE_INT,
73961+ GR_FIVE_INT_TWO_STR,
73962+ GR_TWO_STR,
73963+ GR_THREE_STR,
73964+ GR_FOUR_STR,
73965+ GR_STR_FILENAME,
73966+ GR_FILENAME_STR,
73967+ GR_FILENAME_TWO_INT,
73968+ GR_FILENAME_TWO_INT_STR,
73969+ GR_TEXTREL,
73970+ GR_PTRACE,
73971+ GR_RESOURCE,
73972+ GR_CAP,
73973+ GR_SIG,
73974+ GR_SIG2,
73975+ GR_CRASH1,
73976+ GR_CRASH2,
73977+ GR_PSACCT,
73978+ GR_RWXMAP,
73979+ GR_RWXMAPVMA
73980+};
73981+
73982+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73983+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73984+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73985+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73986+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73987+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73988+#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)
73989+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73990+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73991+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73992+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73993+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73994+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73995+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73996+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73997+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73998+#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)
73999+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74000+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74001+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74002+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74003+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74004+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74005+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74006+#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)
74007+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74008+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74009+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74010+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74011+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74012+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74013+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74014+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74015+#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)
74016+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74017+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74018+
74019+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74020+
74021+#endif
74022+
74023+#endif
74024diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74025new file mode 100644
74026index 0000000..a4396b5
74027--- /dev/null
74028+++ b/include/linux/grmsg.h
74029@@ -0,0 +1,113 @@
74030+#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"
74031+#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"
74032+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74033+#define GR_STOPMOD_MSG "denied modification of module state by "
74034+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74035+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74036+#define GR_IOPERM_MSG "denied use of ioperm() by "
74037+#define GR_IOPL_MSG "denied use of iopl() by "
74038+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74039+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74040+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74041+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74042+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74043+#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"
74044+#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"
74045+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74046+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74047+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74048+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74049+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74050+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74051+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74052+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74053+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74054+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74055+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74056+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74057+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74058+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74059+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74060+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74061+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74062+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74063+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74064+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74065+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74066+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74067+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74068+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74069+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74070+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74071+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74072+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74073+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74074+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74075+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74076+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74077+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74078+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74079+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74080+#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"
74081+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74082+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74083+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74084+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74085+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74086+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74087+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74088+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74089+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74090+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74091+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74092+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74093+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74094+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74095+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74096+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74097+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74098+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74099+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74100+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74101+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74102+#define GR_NICE_CHROOT_MSG "denied priority change by "
74103+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74104+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74105+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74106+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74107+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74108+#define GR_TIME_MSG "time set by "
74109+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74110+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74111+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74112+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74113+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74114+#define GR_BIND_MSG "denied bind() by "
74115+#define GR_CONNECT_MSG "denied connect() by "
74116+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74117+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74118+#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"
74119+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74120+#define GR_CAP_ACL_MSG "use of %s denied for "
74121+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74122+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74123+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74124+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74125+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74126+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74127+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74128+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74129+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74130+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74131+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74132+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74133+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74134+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74135+#define GR_VM86_MSG "denied use of vm86 by "
74136+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74137+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74138+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74139+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74140+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74141+#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 "
74142+#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 "
74143diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74144new file mode 100644
74145index 0000000..d6f5a21
74146--- /dev/null
74147+++ b/include/linux/grsecurity.h
74148@@ -0,0 +1,244 @@
74149+#ifndef GR_SECURITY_H
74150+#define GR_SECURITY_H
74151+#include <linux/fs.h>
74152+#include <linux/fs_struct.h>
74153+#include <linux/binfmts.h>
74154+#include <linux/gracl.h>
74155+
74156+/* notify of brain-dead configs */
74157+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74158+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74159+#endif
74160+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74161+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74162+#endif
74163+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74164+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74165+#endif
74166+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74167+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74168+#endif
74169+
74170+int gr_handle_new_usb(void);
74171+
74172+void gr_handle_brute_attach(unsigned long mm_flags);
74173+void gr_handle_brute_check(void);
74174+void gr_handle_kernel_exploit(void);
74175+
74176+char gr_roletype_to_char(void);
74177+
74178+int gr_acl_enable_at_secure(void);
74179+
74180+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74181+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74182+
74183+void gr_del_task_from_ip_table(struct task_struct *p);
74184+
74185+int gr_pid_is_chrooted(struct task_struct *p);
74186+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74187+int gr_handle_chroot_nice(void);
74188+int gr_handle_chroot_sysctl(const int op);
74189+int gr_handle_chroot_setpriority(struct task_struct *p,
74190+ const int niceval);
74191+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74192+int gr_handle_chroot_chroot(const struct dentry *dentry,
74193+ const struct vfsmount *mnt);
74194+void gr_handle_chroot_chdir(const struct path *path);
74195+int gr_handle_chroot_chmod(const struct dentry *dentry,
74196+ const struct vfsmount *mnt, const int mode);
74197+int gr_handle_chroot_mknod(const struct dentry *dentry,
74198+ const struct vfsmount *mnt, const int mode);
74199+int gr_handle_chroot_mount(const struct dentry *dentry,
74200+ const struct vfsmount *mnt,
74201+ const char *dev_name);
74202+int gr_handle_chroot_pivot(void);
74203+int gr_handle_chroot_unix(const pid_t pid);
74204+
74205+int gr_handle_rawio(const struct inode *inode);
74206+
74207+void gr_handle_ioperm(void);
74208+void gr_handle_iopl(void);
74209+
74210+umode_t gr_acl_umask(void);
74211+
74212+int gr_tpe_allow(const struct file *file);
74213+
74214+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74215+void gr_clear_chroot_entries(struct task_struct *task);
74216+
74217+void gr_log_forkfail(const int retval);
74218+void gr_log_timechange(void);
74219+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74220+void gr_log_chdir(const struct dentry *dentry,
74221+ const struct vfsmount *mnt);
74222+void gr_log_chroot_exec(const struct dentry *dentry,
74223+ const struct vfsmount *mnt);
74224+void gr_log_remount(const char *devname, const int retval);
74225+void gr_log_unmount(const char *devname, const int retval);
74226+void gr_log_mount(const char *from, const char *to, const int retval);
74227+void gr_log_textrel(struct vm_area_struct *vma);
74228+void gr_log_ptgnustack(struct file *file);
74229+void gr_log_rwxmmap(struct file *file);
74230+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74231+
74232+int gr_handle_follow_link(const struct inode *parent,
74233+ const struct inode *inode,
74234+ const struct dentry *dentry,
74235+ const struct vfsmount *mnt);
74236+int gr_handle_fifo(const struct dentry *dentry,
74237+ const struct vfsmount *mnt,
74238+ const struct dentry *dir, const int flag,
74239+ const int acc_mode);
74240+int gr_handle_hardlink(const struct dentry *dentry,
74241+ const struct vfsmount *mnt,
74242+ struct inode *inode,
74243+ const int mode, const struct filename *to);
74244+
74245+int gr_is_capable(const int cap);
74246+int gr_is_capable_nolog(const int cap);
74247+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74248+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74249+
74250+void gr_copy_label(struct task_struct *tsk);
74251+void gr_handle_crash(struct task_struct *task, const int sig);
74252+int gr_handle_signal(const struct task_struct *p, const int sig);
74253+int gr_check_crash_uid(const kuid_t uid);
74254+int gr_check_protected_task(const struct task_struct *task);
74255+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74256+int gr_acl_handle_mmap(const struct file *file,
74257+ const unsigned long prot);
74258+int gr_acl_handle_mprotect(const struct file *file,
74259+ const unsigned long prot);
74260+int gr_check_hidden_task(const struct task_struct *tsk);
74261+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74262+ const struct vfsmount *mnt);
74263+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74264+ const struct vfsmount *mnt);
74265+__u32 gr_acl_handle_access(const struct dentry *dentry,
74266+ const struct vfsmount *mnt, const int fmode);
74267+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74268+ const struct vfsmount *mnt, umode_t *mode);
74269+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74270+ const struct vfsmount *mnt);
74271+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74272+ const struct vfsmount *mnt);
74273+int gr_handle_ptrace(struct task_struct *task, const long request);
74274+int gr_handle_proc_ptrace(struct task_struct *task);
74275+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74276+ const struct vfsmount *mnt);
74277+int gr_check_crash_exec(const struct file *filp);
74278+int gr_acl_is_enabled(void);
74279+void gr_set_kernel_label(struct task_struct *task);
74280+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74281+ const kgid_t gid);
74282+int gr_set_proc_label(const struct dentry *dentry,
74283+ const struct vfsmount *mnt,
74284+ const int unsafe_flags);
74285+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74286+ const struct vfsmount *mnt);
74287+__u32 gr_acl_handle_open(const struct dentry *dentry,
74288+ const struct vfsmount *mnt, int acc_mode);
74289+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74290+ const struct dentry *p_dentry,
74291+ const struct vfsmount *p_mnt,
74292+ int open_flags, int acc_mode, const int imode);
74293+void gr_handle_create(const struct dentry *dentry,
74294+ const struct vfsmount *mnt);
74295+void gr_handle_proc_create(const struct dentry *dentry,
74296+ const struct inode *inode);
74297+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74298+ const struct dentry *parent_dentry,
74299+ const struct vfsmount *parent_mnt,
74300+ const int mode);
74301+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74302+ const struct dentry *parent_dentry,
74303+ const struct vfsmount *parent_mnt);
74304+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74305+ const struct vfsmount *mnt);
74306+void gr_handle_delete(const ino_t ino, const dev_t dev);
74307+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74308+ const struct vfsmount *mnt);
74309+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74310+ const struct dentry *parent_dentry,
74311+ const struct vfsmount *parent_mnt,
74312+ const struct filename *from);
74313+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74314+ const struct dentry *parent_dentry,
74315+ const struct vfsmount *parent_mnt,
74316+ const struct dentry *old_dentry,
74317+ const struct vfsmount *old_mnt, const struct filename *to);
74318+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74319+int gr_acl_handle_rename(struct dentry *new_dentry,
74320+ struct dentry *parent_dentry,
74321+ const struct vfsmount *parent_mnt,
74322+ struct dentry *old_dentry,
74323+ struct inode *old_parent_inode,
74324+ struct vfsmount *old_mnt, const struct filename *newname);
74325+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74326+ struct dentry *old_dentry,
74327+ struct dentry *new_dentry,
74328+ struct vfsmount *mnt, const __u8 replace);
74329+__u32 gr_check_link(const struct dentry *new_dentry,
74330+ const struct dentry *parent_dentry,
74331+ const struct vfsmount *parent_mnt,
74332+ const struct dentry *old_dentry,
74333+ const struct vfsmount *old_mnt);
74334+int gr_acl_handle_filldir(const struct file *file, const char *name,
74335+ const unsigned int namelen, const ino_t ino);
74336+
74337+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74338+ const struct vfsmount *mnt);
74339+void gr_acl_handle_exit(void);
74340+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74341+int gr_acl_handle_procpidmem(const struct task_struct *task);
74342+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74343+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74344+void gr_audit_ptrace(struct task_struct *task);
74345+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74346+void gr_put_exec_file(struct task_struct *task);
74347+
74348+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74349+
74350+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74351+extern void gr_learn_resource(const struct task_struct *task, const int res,
74352+ const unsigned long wanted, const int gt);
74353+#else
74354+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74355+ const unsigned long wanted, const int gt)
74356+{
74357+}
74358+#endif
74359+
74360+#ifdef CONFIG_GRKERNSEC_RESLOG
74361+extern void gr_log_resource(const struct task_struct *task, const int res,
74362+ const unsigned long wanted, const int gt);
74363+#else
74364+static inline void gr_log_resource(const struct task_struct *task, const int res,
74365+ const unsigned long wanted, const int gt)
74366+{
74367+}
74368+#endif
74369+
74370+#ifdef CONFIG_GRKERNSEC
74371+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74372+void gr_handle_vm86(void);
74373+void gr_handle_mem_readwrite(u64 from, u64 to);
74374+
74375+void gr_log_badprocpid(const char *entry);
74376+
74377+extern int grsec_enable_dmesg;
74378+extern int grsec_disable_privio;
74379+
74380+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74381+extern kgid_t grsec_proc_gid;
74382+#endif
74383+
74384+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74385+extern int grsec_enable_chroot_findtask;
74386+#endif
74387+#ifdef CONFIG_GRKERNSEC_SETXID
74388+extern int grsec_enable_setxid;
74389+#endif
74390+#endif
74391+
74392+#endif
74393diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74394new file mode 100644
74395index 0000000..e7ffaaf
74396--- /dev/null
74397+++ b/include/linux/grsock.h
74398@@ -0,0 +1,19 @@
74399+#ifndef __GRSOCK_H
74400+#define __GRSOCK_H
74401+
74402+extern void gr_attach_curr_ip(const struct sock *sk);
74403+extern int gr_handle_sock_all(const int family, const int type,
74404+ const int protocol);
74405+extern int gr_handle_sock_server(const struct sockaddr *sck);
74406+extern int gr_handle_sock_server_other(const struct sock *sck);
74407+extern int gr_handle_sock_client(const struct sockaddr *sck);
74408+extern int gr_search_connect(struct socket * sock,
74409+ struct sockaddr_in * addr);
74410+extern int gr_search_bind(struct socket * sock,
74411+ struct sockaddr_in * addr);
74412+extern int gr_search_listen(struct socket * sock);
74413+extern int gr_search_accept(struct socket * sock);
74414+extern int gr_search_socket(const int domain, const int type,
74415+ const int protocol);
74416+
74417+#endif
74418diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74419index 7fb31da..08b5114 100644
74420--- a/include/linux/highmem.h
74421+++ b/include/linux/highmem.h
74422@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74423 kunmap_atomic(kaddr);
74424 }
74425
74426+static inline void sanitize_highpage(struct page *page)
74427+{
74428+ void *kaddr;
74429+ unsigned long flags;
74430+
74431+ local_irq_save(flags);
74432+ kaddr = kmap_atomic(page);
74433+ clear_page(kaddr);
74434+ kunmap_atomic(kaddr);
74435+ local_irq_restore(flags);
74436+}
74437+
74438 static inline void zero_user_segments(struct page *page,
74439 unsigned start1, unsigned end1,
74440 unsigned start2, unsigned end2)
74441diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74442index 1c7b89a..7f52502 100644
74443--- a/include/linux/hwmon-sysfs.h
74444+++ b/include/linux/hwmon-sysfs.h
74445@@ -25,7 +25,8 @@
74446 struct sensor_device_attribute{
74447 struct device_attribute dev_attr;
74448 int index;
74449-};
74450+} __do_const;
74451+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74452 #define to_sensor_dev_attr(_dev_attr) \
74453 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74454
74455@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74456 struct device_attribute dev_attr;
74457 u8 index;
74458 u8 nr;
74459-};
74460+} __do_const;
74461 #define to_sensor_dev_attr_2(_dev_attr) \
74462 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74463
74464diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74465index e988fa9..ff9f17e 100644
74466--- a/include/linux/i2c.h
74467+++ b/include/linux/i2c.h
74468@@ -366,6 +366,7 @@ struct i2c_algorithm {
74469 /* To determine what the adapter supports */
74470 u32 (*functionality) (struct i2c_adapter *);
74471 };
74472+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74473
74474 /**
74475 * struct i2c_bus_recovery_info - I2C bus recovery information
74476diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74477index d23c3c2..eb63c81 100644
74478--- a/include/linux/i2o.h
74479+++ b/include/linux/i2o.h
74480@@ -565,7 +565,7 @@ struct i2o_controller {
74481 struct i2o_device *exec; /* Executive */
74482 #if BITS_PER_LONG == 64
74483 spinlock_t context_list_lock; /* lock for context_list */
74484- atomic_t context_list_counter; /* needed for unique contexts */
74485+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74486 struct list_head context_list; /* list of context id's
74487 and pointers */
74488 #endif
74489diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74490index aff7ad8..3942bbd 100644
74491--- a/include/linux/if_pppox.h
74492+++ b/include/linux/if_pppox.h
74493@@ -76,7 +76,7 @@ struct pppox_proto {
74494 int (*ioctl)(struct socket *sock, unsigned int cmd,
74495 unsigned long arg);
74496 struct module *owner;
74497-};
74498+} __do_const;
74499
74500 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74501 extern void unregister_pppox_proto(int proto_num);
74502diff --git a/include/linux/init.h b/include/linux/init.h
74503index e73f2b7..cc996e0 100644
74504--- a/include/linux/init.h
74505+++ b/include/linux/init.h
74506@@ -39,9 +39,17 @@
74507 * Also note, that this data cannot be "const".
74508 */
74509
74510+#define add_init_latent_entropy __latent_entropy
74511+
74512+#ifdef CONFIG_MEMORY_HOTPLUG
74513+#define add_meminit_latent_entropy
74514+#else
74515+#define add_meminit_latent_entropy __latent_entropy
74516+#endif
74517+
74518 /* These are for everybody (although not all archs will actually
74519 discard it in modules) */
74520-#define __init __section(.init.text) __cold notrace
74521+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74522 #define __initdata __section(.init.data)
74523 #define __initconst __constsection(.init.rodata)
74524 #define __exitdata __section(.exit.data)
74525@@ -102,7 +110,7 @@
74526 #define __cpuexitconst
74527
74528 /* Used for MEMORY_HOTPLUG */
74529-#define __meminit __section(.meminit.text) __cold notrace
74530+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74531 #define __meminitdata __section(.meminit.data)
74532 #define __meminitconst __constsection(.meminit.rodata)
74533 #define __memexit __section(.memexit.text) __exitused __cold notrace
74534diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74535index 5cd0f09..c9f67cc 100644
74536--- a/include/linux/init_task.h
74537+++ b/include/linux/init_task.h
74538@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74539
74540 #define INIT_TASK_COMM "swapper"
74541
74542+#ifdef CONFIG_X86
74543+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74544+#else
74545+#define INIT_TASK_THREAD_INFO
74546+#endif
74547+
74548 /*
74549 * INIT_TASK is used to set up the first task table, touch at
74550 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74551@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74552 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74553 .comm = INIT_TASK_COMM, \
74554 .thread = INIT_THREAD, \
74555+ INIT_TASK_THREAD_INFO \
74556 .fs = &init_fs, \
74557 .files = &init_files, \
74558 .signal = &init_signals, \
74559diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74560index 5fa5afe..ac55b25 100644
74561--- a/include/linux/interrupt.h
74562+++ b/include/linux/interrupt.h
74563@@ -430,7 +430,7 @@ enum
74564 /* map softirq index to softirq name. update 'softirq_to_name' in
74565 * kernel/softirq.c when adding a new softirq.
74566 */
74567-extern char *softirq_to_name[NR_SOFTIRQS];
74568+extern const char * const softirq_to_name[NR_SOFTIRQS];
74569
74570 /* softirq mask and active fields moved to irq_cpustat_t in
74571 * asm/hardirq.h to get better cache usage. KAO
74572@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74573
74574 struct softirq_action
74575 {
74576- void (*action)(struct softirq_action *);
74577-};
74578+ void (*action)(void);
74579+} __no_const;
74580
74581 asmlinkage void do_softirq(void);
74582 asmlinkage void __do_softirq(void);
74583-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74584+extern void open_softirq(int nr, void (*action)(void));
74585 extern void softirq_init(void);
74586 extern void __raise_softirq_irqoff(unsigned int nr);
74587
74588diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74589index 3aeb730..2177f39 100644
74590--- a/include/linux/iommu.h
74591+++ b/include/linux/iommu.h
74592@@ -113,7 +113,7 @@ struct iommu_ops {
74593 u32 (*domain_get_windows)(struct iommu_domain *domain);
74594
74595 unsigned long pgsize_bitmap;
74596-};
74597+} __do_const;
74598
74599 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74600 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74601diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74602index 89b7c24..382af74 100644
74603--- a/include/linux/ioport.h
74604+++ b/include/linux/ioport.h
74605@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74606 int adjust_resource(struct resource *res, resource_size_t start,
74607 resource_size_t size);
74608 resource_size_t resource_alignment(struct resource *res);
74609-static inline resource_size_t resource_size(const struct resource *res)
74610+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74611 {
74612 return res->end - res->start + 1;
74613 }
74614diff --git a/include/linux/irq.h b/include/linux/irq.h
74615index f04d3ba..bcf2cfb 100644
74616--- a/include/linux/irq.h
74617+++ b/include/linux/irq.h
74618@@ -333,7 +333,8 @@ struct irq_chip {
74619 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74620
74621 unsigned long flags;
74622-};
74623+} __do_const;
74624+typedef struct irq_chip __no_const irq_chip_no_const;
74625
74626 /*
74627 * irq_chip specific flags
74628diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74629index 3e203eb..3fe68d0 100644
74630--- a/include/linux/irqchip/arm-gic.h
74631+++ b/include/linux/irqchip/arm-gic.h
74632@@ -59,9 +59,11 @@
74633
74634 #ifndef __ASSEMBLY__
74635
74636+#include <linux/irq.h>
74637+
74638 struct device_node;
74639
74640-extern struct irq_chip gic_arch_extn;
74641+extern irq_chip_no_const gic_arch_extn;
74642
74643 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74644 u32 offset, struct device_node *);
74645diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74646index 6883e19..e854fcb 100644
74647--- a/include/linux/kallsyms.h
74648+++ b/include/linux/kallsyms.h
74649@@ -15,7 +15,8 @@
74650
74651 struct module;
74652
74653-#ifdef CONFIG_KALLSYMS
74654+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74655+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74656 /* Lookup the address for a symbol. Returns 0 if not found. */
74657 unsigned long kallsyms_lookup_name(const char *name);
74658
74659@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74660 /* Stupid that this does nothing, but I didn't create this mess. */
74661 #define __print_symbol(fmt, addr)
74662 #endif /*CONFIG_KALLSYMS*/
74663+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74664+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74665+extern unsigned long kallsyms_lookup_name(const char *name);
74666+extern void __print_symbol(const char *fmt, unsigned long address);
74667+extern int sprint_backtrace(char *buffer, unsigned long address);
74668+extern int sprint_symbol(char *buffer, unsigned long address);
74669+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74670+const char *kallsyms_lookup(unsigned long addr,
74671+ unsigned long *symbolsize,
74672+ unsigned long *offset,
74673+ char **modname, char *namebuf);
74674+extern int kallsyms_lookup_size_offset(unsigned long addr,
74675+ unsigned long *symbolsize,
74676+ unsigned long *offset);
74677+#endif
74678
74679 /* This macro allows us to keep printk typechecking */
74680 static __printf(1, 2)
74681diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74682index 518a53a..5e28358 100644
74683--- a/include/linux/key-type.h
74684+++ b/include/linux/key-type.h
74685@@ -125,7 +125,7 @@ struct key_type {
74686 /* internal fields */
74687 struct list_head link; /* link in types list */
74688 struct lock_class_key lock_class; /* key->sem lock class */
74689-};
74690+} __do_const;
74691
74692 extern struct key_type key_type_keyring;
74693
74694diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74695index c6e091b..a940adf 100644
74696--- a/include/linux/kgdb.h
74697+++ b/include/linux/kgdb.h
74698@@ -52,7 +52,7 @@ extern int kgdb_connected;
74699 extern int kgdb_io_module_registered;
74700
74701 extern atomic_t kgdb_setting_breakpoint;
74702-extern atomic_t kgdb_cpu_doing_single_step;
74703+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74704
74705 extern struct task_struct *kgdb_usethread;
74706 extern struct task_struct *kgdb_contthread;
74707@@ -254,7 +254,7 @@ struct kgdb_arch {
74708 void (*correct_hw_break)(void);
74709
74710 void (*enable_nmi)(bool on);
74711-};
74712+} __do_const;
74713
74714 /**
74715 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74716@@ -279,7 +279,7 @@ struct kgdb_io {
74717 void (*pre_exception) (void);
74718 void (*post_exception) (void);
74719 int is_console;
74720-};
74721+} __do_const;
74722
74723 extern struct kgdb_arch arch_kgdb_ops;
74724
74725diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74726index 0555cc6..b16a7a4 100644
74727--- a/include/linux/kmod.h
74728+++ b/include/linux/kmod.h
74729@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74730 * usually useless though. */
74731 extern __printf(2, 3)
74732 int __request_module(bool wait, const char *name, ...);
74733+extern __printf(3, 4)
74734+int ___request_module(bool wait, char *param_name, const char *name, ...);
74735 #define request_module(mod...) __request_module(true, mod)
74736 #define request_module_nowait(mod...) __request_module(false, mod)
74737 #define try_then_request_module(x, mod...) \
74738diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74739index 939b112..ed6ed51 100644
74740--- a/include/linux/kobject.h
74741+++ b/include/linux/kobject.h
74742@@ -111,7 +111,7 @@ struct kobj_type {
74743 struct attribute **default_attrs;
74744 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74745 const void *(*namespace)(struct kobject *kobj);
74746-};
74747+} __do_const;
74748
74749 struct kobj_uevent_env {
74750 char *envp[UEVENT_NUM_ENVP];
74751@@ -134,6 +134,7 @@ struct kobj_attribute {
74752 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74753 const char *buf, size_t count);
74754 };
74755+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74756
74757 extern const struct sysfs_ops kobj_sysfs_ops;
74758
74759diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74760index f66b065..c2c29b4 100644
74761--- a/include/linux/kobject_ns.h
74762+++ b/include/linux/kobject_ns.h
74763@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74764 const void *(*netlink_ns)(struct sock *sk);
74765 const void *(*initial_ns)(void);
74766 void (*drop_ns)(void *);
74767-};
74768+} __do_const;
74769
74770 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74771 int kobj_ns_type_registered(enum kobj_ns_type type);
74772diff --git a/include/linux/kref.h b/include/linux/kref.h
74773index 484604d..0f6c5b6 100644
74774--- a/include/linux/kref.h
74775+++ b/include/linux/kref.h
74776@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74777 static inline int kref_sub(struct kref *kref, unsigned int count,
74778 void (*release)(struct kref *kref))
74779 {
74780- WARN_ON(release == NULL);
74781+ BUG_ON(release == NULL);
74782
74783 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74784 release(kref);
74785diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74786index a63d83e..77fd685 100644
74787--- a/include/linux/kvm_host.h
74788+++ b/include/linux/kvm_host.h
74789@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74790 {
74791 }
74792 #endif
74793-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74794+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74795 struct module *module);
74796 void kvm_exit(void);
74797
74798@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74799 struct kvm_guest_debug *dbg);
74800 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74801
74802-int kvm_arch_init(void *opaque);
74803+int kvm_arch_init(const void *opaque);
74804 void kvm_arch_exit(void);
74805
74806 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74807diff --git a/include/linux/libata.h b/include/linux/libata.h
74808index 4ea55bb..dcd2601 100644
74809--- a/include/linux/libata.h
74810+++ b/include/linux/libata.h
74811@@ -924,7 +924,7 @@ struct ata_port_operations {
74812 * fields must be pointers.
74813 */
74814 const struct ata_port_operations *inherits;
74815-};
74816+} __do_const;
74817
74818 struct ata_port_info {
74819 unsigned long flags;
74820diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74821index d3e8ad2..a949f68 100644
74822--- a/include/linux/linkage.h
74823+++ b/include/linux/linkage.h
74824@@ -31,6 +31,7 @@
74825 #endif
74826
74827 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74828+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74829 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74830
74831 /*
74832diff --git a/include/linux/list.h b/include/linux/list.h
74833index f4d8a2f..38e6e46 100644
74834--- a/include/linux/list.h
74835+++ b/include/linux/list.h
74836@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74837 extern void list_del(struct list_head *entry);
74838 #endif
74839
74840+extern void __pax_list_add(struct list_head *new,
74841+ struct list_head *prev,
74842+ struct list_head *next);
74843+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74844+{
74845+ __pax_list_add(new, head, head->next);
74846+}
74847+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74848+{
74849+ __pax_list_add(new, head->prev, head);
74850+}
74851+extern void pax_list_del(struct list_head *entry);
74852+
74853 /**
74854 * list_replace - replace old entry by new one
74855 * @old : the element to be replaced
74856@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74857 INIT_LIST_HEAD(entry);
74858 }
74859
74860+extern void pax_list_del_init(struct list_head *entry);
74861+
74862 /**
74863 * list_move - delete from one list and add as another's head
74864 * @list: the entry to move
74865diff --git a/include/linux/math64.h b/include/linux/math64.h
74866index 2913b86..8dcbb1e 100644
74867--- a/include/linux/math64.h
74868+++ b/include/linux/math64.h
74869@@ -15,7 +15,7 @@
74870 * This is commonly provided by 32bit archs to provide an optimized 64bit
74871 * divide.
74872 */
74873-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74874+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74875 {
74876 *remainder = dividend % divisor;
74877 return dividend / divisor;
74878@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74879 /**
74880 * div64_u64 - unsigned 64bit divide with 64bit divisor
74881 */
74882-static inline u64 div64_u64(u64 dividend, u64 divisor)
74883+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74884 {
74885 return dividend / divisor;
74886 }
74887@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74888 #define div64_ul(x, y) div_u64((x), (y))
74889
74890 #ifndef div_u64_rem
74891-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74892+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74893 {
74894 *remainder = do_div(dividend, divisor);
74895 return dividend;
74896@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74897 * divide.
74898 */
74899 #ifndef div_u64
74900-static inline u64 div_u64(u64 dividend, u32 divisor)
74901+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74902 {
74903 u32 remainder;
74904 return div_u64_rem(dividend, divisor, &remainder);
74905diff --git a/include/linux/mm.h b/include/linux/mm.h
74906index f022460..6ecf4f9 100644
74907--- a/include/linux/mm.h
74908+++ b/include/linux/mm.h
74909@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74910 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74911 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74912 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74913+
74914+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74915+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74916+#endif
74917+
74918 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74919
74920 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74921@@ -208,8 +213,8 @@ struct vm_operations_struct {
74922 /* called by access_process_vm when get_user_pages() fails, typically
74923 * for use by special VMAs that can switch between memory and hardware
74924 */
74925- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74926- void *buf, int len, int write);
74927+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74928+ void *buf, size_t len, int write);
74929 #ifdef CONFIG_NUMA
74930 /*
74931 * set_policy() op must add a reference to any non-NULL @new mempolicy
74932@@ -239,6 +244,7 @@ struct vm_operations_struct {
74933 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74934 unsigned long size, pgoff_t pgoff);
74935 };
74936+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74937
74938 struct mmu_gather;
74939 struct inode;
74940@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74941 unsigned long *pfn);
74942 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74943 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74944-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74945- void *buf, int len, int write);
74946+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74947+ void *buf, size_t len, int write);
74948
74949 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74950 loff_t const holebegin, loff_t const holelen)
74951@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74952 }
74953 #endif
74954
74955-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74956-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74957- void *buf, int len, int write);
74958+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74959+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74960+ void *buf, size_t len, int write);
74961
74962 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74963 unsigned long start, unsigned long nr_pages,
74964@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74965 int set_page_dirty_lock(struct page *page);
74966 int clear_page_dirty_for_io(struct page *page);
74967
74968-/* Is the vma a continuation of the stack vma above it? */
74969-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74970-{
74971- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74972-}
74973-
74974-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74975- unsigned long addr)
74976-{
74977- return (vma->vm_flags & VM_GROWSDOWN) &&
74978- (vma->vm_start == addr) &&
74979- !vma_growsdown(vma->vm_prev, addr);
74980-}
74981-
74982-/* Is the vma a continuation of the stack vma below it? */
74983-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74984-{
74985- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74986-}
74987-
74988-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74989- unsigned long addr)
74990-{
74991- return (vma->vm_flags & VM_GROWSUP) &&
74992- (vma->vm_end == addr) &&
74993- !vma_growsup(vma->vm_next, addr);
74994-}
74995-
74996 extern pid_t
74997 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74998
74999@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75000 }
75001 #endif
75002
75003+#ifdef CONFIG_MMU
75004+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75005+#else
75006+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75007+{
75008+ return __pgprot(0);
75009+}
75010+#endif
75011+
75012 int vma_wants_writenotify(struct vm_area_struct *vma);
75013
75014 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75015@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75016 {
75017 return 0;
75018 }
75019+
75020+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75021+ unsigned long address)
75022+{
75023+ return 0;
75024+}
75025 #else
75026 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75027+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75028 #endif
75029
75030 #ifdef __PAGETABLE_PMD_FOLDED
75031@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75032 {
75033 return 0;
75034 }
75035+
75036+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75037+ unsigned long address)
75038+{
75039+ return 0;
75040+}
75041 #else
75042 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75043+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75044 #endif
75045
75046 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75047@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75048 NULL: pud_offset(pgd, address);
75049 }
75050
75051+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75052+{
75053+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75054+ NULL: pud_offset(pgd, address);
75055+}
75056+
75057 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75058 {
75059 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75060 NULL: pmd_offset(pud, address);
75061 }
75062+
75063+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75064+{
75065+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75066+ NULL: pmd_offset(pud, address);
75067+}
75068 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75069
75070 #if USE_SPLIT_PTLOCKS
75071@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75072 unsigned long len, unsigned long prot, unsigned long flags,
75073 unsigned long pgoff, unsigned long *populate);
75074 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75075+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75076
75077 #ifdef CONFIG_MMU
75078 extern int __mm_populate(unsigned long addr, unsigned long len,
75079@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75080 unsigned long high_limit;
75081 unsigned long align_mask;
75082 unsigned long align_offset;
75083+ unsigned long threadstack_offset;
75084 };
75085
75086-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75087-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75088+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75089+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75090
75091 /*
75092 * Search for an unmapped address range.
75093@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75094 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75095 */
75096 static inline unsigned long
75097-vm_unmapped_area(struct vm_unmapped_area_info *info)
75098+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75099 {
75100 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75101 return unmapped_area(info);
75102@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75103 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75104 struct vm_area_struct **pprev);
75105
75106+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75107+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75108+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75109+
75110 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75111 NULL if none. Assume start_addr < end_addr. */
75112 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75113@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75114 return vma;
75115 }
75116
75117-#ifdef CONFIG_MMU
75118-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75119-#else
75120-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75121-{
75122- return __pgprot(0);
75123-}
75124-#endif
75125-
75126 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75127 unsigned long change_prot_numa(struct vm_area_struct *vma,
75128 unsigned long start, unsigned long end);
75129@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75130 static inline void vm_stat_account(struct mm_struct *mm,
75131 unsigned long flags, struct file *file, long pages)
75132 {
75133+
75134+#ifdef CONFIG_PAX_RANDMMAP
75135+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75136+#endif
75137+
75138 mm->total_vm += pages;
75139 }
75140 #endif /* CONFIG_PROC_FS */
75141@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75142 extern int sysctl_memory_failure_early_kill;
75143 extern int sysctl_memory_failure_recovery;
75144 extern void shake_page(struct page *p, int access);
75145-extern atomic_long_t num_poisoned_pages;
75146+extern atomic_long_unchecked_t num_poisoned_pages;
75147 extern int soft_offline_page(struct page *page, int flags);
75148
75149 extern void dump_page(struct page *page);
75150@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75151 static inline void setup_nr_node_ids(void) {}
75152 #endif
75153
75154+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75155+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75156+#else
75157+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75158+#endif
75159+
75160 #endif /* __KERNEL__ */
75161 #endif /* _LINUX_MM_H */
75162diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75163index faf4b7c..1e70c6e 100644
75164--- a/include/linux/mm_types.h
75165+++ b/include/linux/mm_types.h
75166@@ -289,6 +289,8 @@ struct vm_area_struct {
75167 #ifdef CONFIG_NUMA
75168 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75169 #endif
75170+
75171+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75172 };
75173
75174 struct core_thread {
75175@@ -435,6 +437,24 @@ struct mm_struct {
75176 int first_nid;
75177 #endif
75178 struct uprobes_state uprobes_state;
75179+
75180+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75181+ unsigned long pax_flags;
75182+#endif
75183+
75184+#ifdef CONFIG_PAX_DLRESOLVE
75185+ unsigned long call_dl_resolve;
75186+#endif
75187+
75188+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75189+ unsigned long call_syscall;
75190+#endif
75191+
75192+#ifdef CONFIG_PAX_ASLR
75193+ unsigned long delta_mmap; /* randomized offset */
75194+ unsigned long delta_stack; /* randomized offset */
75195+#endif
75196+
75197 };
75198
75199 /* first nid will either be a valid NID or one of these values */
75200diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75201index c5d5278..f0b68c8 100644
75202--- a/include/linux/mmiotrace.h
75203+++ b/include/linux/mmiotrace.h
75204@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75205 /* Called from ioremap.c */
75206 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75207 void __iomem *addr);
75208-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75209+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75210
75211 /* For anyone to insert markers. Remember trailing newline. */
75212 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75213@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75214 {
75215 }
75216
75217-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75218+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75219 {
75220 }
75221
75222diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75223index af4a3b7..9ad8889 100644
75224--- a/include/linux/mmzone.h
75225+++ b/include/linux/mmzone.h
75226@@ -396,7 +396,7 @@ struct zone {
75227 unsigned long flags; /* zone flags, see below */
75228
75229 /* Zone statistics */
75230- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75231+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75232
75233 /*
75234 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75235diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75236index 45e9214..a7227d6 100644
75237--- a/include/linux/mod_devicetable.h
75238+++ b/include/linux/mod_devicetable.h
75239@@ -13,7 +13,7 @@
75240 typedef unsigned long kernel_ulong_t;
75241 #endif
75242
75243-#define PCI_ANY_ID (~0)
75244+#define PCI_ANY_ID ((__u16)~0)
75245
75246 struct pci_device_id {
75247 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75248@@ -139,7 +139,7 @@ struct usb_device_id {
75249 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75250 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75251
75252-#define HID_ANY_ID (~0)
75253+#define HID_ANY_ID (~0U)
75254 #define HID_BUS_ANY 0xffff
75255 #define HID_GROUP_ANY 0x0000
75256
75257@@ -467,7 +467,7 @@ struct dmi_system_id {
75258 const char *ident;
75259 struct dmi_strmatch matches[4];
75260 void *driver_data;
75261-};
75262+} __do_const;
75263 /*
75264 * struct dmi_device_id appears during expansion of
75265 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75266diff --git a/include/linux/module.h b/include/linux/module.h
75267index 46f1ea0..a34ca37 100644
75268--- a/include/linux/module.h
75269+++ b/include/linux/module.h
75270@@ -17,9 +17,11 @@
75271 #include <linux/moduleparam.h>
75272 #include <linux/tracepoint.h>
75273 #include <linux/export.h>
75274+#include <linux/fs.h>
75275
75276 #include <linux/percpu.h>
75277 #include <asm/module.h>
75278+#include <asm/pgtable.h>
75279
75280 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75281 #define MODULE_SIG_STRING "~Module signature appended~\n"
75282@@ -54,12 +56,13 @@ struct module_attribute {
75283 int (*test)(struct module *);
75284 void (*free)(struct module *);
75285 };
75286+typedef struct module_attribute __no_const module_attribute_no_const;
75287
75288 struct module_version_attribute {
75289 struct module_attribute mattr;
75290 const char *module_name;
75291 const char *version;
75292-} __attribute__ ((__aligned__(sizeof(void *))));
75293+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75294
75295 extern ssize_t __modver_version_show(struct module_attribute *,
75296 struct module_kobject *, char *);
75297@@ -232,7 +235,7 @@ struct module
75298
75299 /* Sysfs stuff. */
75300 struct module_kobject mkobj;
75301- struct module_attribute *modinfo_attrs;
75302+ module_attribute_no_const *modinfo_attrs;
75303 const char *version;
75304 const char *srcversion;
75305 struct kobject *holders_dir;
75306@@ -281,19 +284,16 @@ struct module
75307 int (*init)(void);
75308
75309 /* If this is non-NULL, vfree after init() returns */
75310- void *module_init;
75311+ void *module_init_rx, *module_init_rw;
75312
75313 /* Here is the actual code + data, vfree'd on unload. */
75314- void *module_core;
75315+ void *module_core_rx, *module_core_rw;
75316
75317 /* Here are the sizes of the init and core sections */
75318- unsigned int init_size, core_size;
75319+ unsigned int init_size_rw, core_size_rw;
75320
75321 /* The size of the executable code in each section. */
75322- unsigned int init_text_size, core_text_size;
75323-
75324- /* Size of RO sections of the module (text+rodata) */
75325- unsigned int init_ro_size, core_ro_size;
75326+ unsigned int init_size_rx, core_size_rx;
75327
75328 /* Arch-specific module values */
75329 struct mod_arch_specific arch;
75330@@ -349,6 +349,10 @@ struct module
75331 #ifdef CONFIG_EVENT_TRACING
75332 struct ftrace_event_call **trace_events;
75333 unsigned int num_trace_events;
75334+ struct file_operations trace_id;
75335+ struct file_operations trace_enable;
75336+ struct file_operations trace_format;
75337+ struct file_operations trace_filter;
75338 #endif
75339 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75340 unsigned int num_ftrace_callsites;
75341@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75342 bool is_module_percpu_address(unsigned long addr);
75343 bool is_module_text_address(unsigned long addr);
75344
75345+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75346+{
75347+
75348+#ifdef CONFIG_PAX_KERNEXEC
75349+ if (ktla_ktva(addr) >= (unsigned long)start &&
75350+ ktla_ktva(addr) < (unsigned long)start + size)
75351+ return 1;
75352+#endif
75353+
75354+ return ((void *)addr >= start && (void *)addr < start + size);
75355+}
75356+
75357+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75358+{
75359+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75360+}
75361+
75362+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75363+{
75364+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75365+}
75366+
75367+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75368+{
75369+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75370+}
75371+
75372+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75373+{
75374+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75375+}
75376+
75377 static inline int within_module_core(unsigned long addr, const struct module *mod)
75378 {
75379- return (unsigned long)mod->module_core <= addr &&
75380- addr < (unsigned long)mod->module_core + mod->core_size;
75381+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75382 }
75383
75384 static inline int within_module_init(unsigned long addr, const struct module *mod)
75385 {
75386- return (unsigned long)mod->module_init <= addr &&
75387- addr < (unsigned long)mod->module_init + mod->init_size;
75388+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75389 }
75390
75391 /* Search for module by name: must hold module_mutex. */
75392diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75393index 560ca53..ef621ef 100644
75394--- a/include/linux/moduleloader.h
75395+++ b/include/linux/moduleloader.h
75396@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75397 sections. Returns NULL on failure. */
75398 void *module_alloc(unsigned long size);
75399
75400+#ifdef CONFIG_PAX_KERNEXEC
75401+void *module_alloc_exec(unsigned long size);
75402+#else
75403+#define module_alloc_exec(x) module_alloc(x)
75404+#endif
75405+
75406 /* Free memory returned from module_alloc. */
75407 void module_free(struct module *mod, void *module_region);
75408
75409+#ifdef CONFIG_PAX_KERNEXEC
75410+void module_free_exec(struct module *mod, void *module_region);
75411+#else
75412+#define module_free_exec(x, y) module_free((x), (y))
75413+#endif
75414+
75415 /*
75416 * Apply the given relocation to the (simplified) ELF. Return -error
75417 * or 0.
75418@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75419 unsigned int relsec,
75420 struct module *me)
75421 {
75422+#ifdef CONFIG_MODULES
75423 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75424+#endif
75425 return -ENOEXEC;
75426 }
75427 #endif
75428@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75429 unsigned int relsec,
75430 struct module *me)
75431 {
75432+#ifdef CONFIG_MODULES
75433 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75434+#endif
75435 return -ENOEXEC;
75436 }
75437 #endif
75438diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75439index 27d9da3..5d94aa3 100644
75440--- a/include/linux/moduleparam.h
75441+++ b/include/linux/moduleparam.h
75442@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75443 * @len is usually just sizeof(string).
75444 */
75445 #define module_param_string(name, string, len, perm) \
75446- static const struct kparam_string __param_string_##name \
75447+ static const struct kparam_string __param_string_##name __used \
75448 = { len, string }; \
75449 __module_param_call(MODULE_PARAM_PREFIX, name, \
75450 &param_ops_string, \
75451@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75452 */
75453 #define module_param_array_named(name, array, type, nump, perm) \
75454 param_check_##type(name, &(array)[0]); \
75455- static const struct kparam_array __param_arr_##name \
75456+ static const struct kparam_array __param_arr_##name __used \
75457 = { .max = ARRAY_SIZE(array), .num = nump, \
75458 .ops = &param_ops_##type, \
75459 .elemsize = sizeof(array[0]), .elem = array }; \
75460diff --git a/include/linux/namei.h b/include/linux/namei.h
75461index 5a5ff57..5ae5070 100644
75462--- a/include/linux/namei.h
75463+++ b/include/linux/namei.h
75464@@ -19,7 +19,7 @@ struct nameidata {
75465 unsigned seq;
75466 int last_type;
75467 unsigned depth;
75468- char *saved_names[MAX_NESTED_LINKS + 1];
75469+ const char *saved_names[MAX_NESTED_LINKS + 1];
75470 };
75471
75472 /*
75473@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75474
75475 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75476
75477-static inline void nd_set_link(struct nameidata *nd, char *path)
75478+static inline void nd_set_link(struct nameidata *nd, const char *path)
75479 {
75480 nd->saved_names[nd->depth] = path;
75481 }
75482
75483-static inline char *nd_get_link(struct nameidata *nd)
75484+static inline const char *nd_get_link(const struct nameidata *nd)
75485 {
75486 return nd->saved_names[nd->depth];
75487 }
75488diff --git a/include/linux/net.h b/include/linux/net.h
75489index 4f27575..fc8a65f 100644
75490--- a/include/linux/net.h
75491+++ b/include/linux/net.h
75492@@ -183,7 +183,7 @@ struct net_proto_family {
75493 int (*create)(struct net *net, struct socket *sock,
75494 int protocol, int kern);
75495 struct module *owner;
75496-};
75497+} __do_const;
75498
75499 struct iovec;
75500 struct kvec;
75501diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75502index 9a41568..203d903 100644
75503--- a/include/linux/netdevice.h
75504+++ b/include/linux/netdevice.h
75505@@ -1061,6 +1061,7 @@ struct net_device_ops {
75506 int (*ndo_change_carrier)(struct net_device *dev,
75507 bool new_carrier);
75508 };
75509+typedef struct net_device_ops __no_const net_device_ops_no_const;
75510
75511 /*
75512 * The DEVICE structure.
75513@@ -1131,7 +1132,7 @@ struct net_device {
75514 int iflink;
75515
75516 struct net_device_stats stats;
75517- atomic_long_t rx_dropped; /* dropped packets by core network
75518+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75519 * Do not use this in drivers.
75520 */
75521
75522diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75523index de70f7b..2675e91 100644
75524--- a/include/linux/netfilter.h
75525+++ b/include/linux/netfilter.h
75526@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75527 #endif
75528 /* Use the module struct to lock set/get code in place */
75529 struct module *owner;
75530-};
75531+} __do_const;
75532
75533 /* Function to register/unregister hook points. */
75534 int nf_register_hook(struct nf_hook_ops *reg);
75535diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75536index d80e275..c3510b8 100644
75537--- a/include/linux/netfilter/ipset/ip_set.h
75538+++ b/include/linux/netfilter/ipset/ip_set.h
75539@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75540 /* Return true if "b" set is the same as "a"
75541 * according to the create set parameters */
75542 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75543-};
75544+} __do_const;
75545
75546 /* The core set type structure */
75547 struct ip_set_type {
75548diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75549index cadb740..d7c37c0 100644
75550--- a/include/linux/netfilter/nfnetlink.h
75551+++ b/include/linux/netfilter/nfnetlink.h
75552@@ -16,7 +16,7 @@ struct nfnl_callback {
75553 const struct nlattr * const cda[]);
75554 const struct nla_policy *policy; /* netlink attribute policy */
75555 const u_int16_t attr_count; /* number of nlattr's */
75556-};
75557+} __do_const;
75558
75559 struct nfnetlink_subsystem {
75560 const char *name;
75561diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75562new file mode 100644
75563index 0000000..33f4af8
75564--- /dev/null
75565+++ b/include/linux/netfilter/xt_gradm.h
75566@@ -0,0 +1,9 @@
75567+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75568+#define _LINUX_NETFILTER_XT_GRADM_H 1
75569+
75570+struct xt_gradm_mtinfo {
75571+ __u16 flags;
75572+ __u16 invflags;
75573+};
75574+
75575+#endif
75576diff --git a/include/linux/nls.h b/include/linux/nls.h
75577index 5dc635f..35f5e11 100644
75578--- a/include/linux/nls.h
75579+++ b/include/linux/nls.h
75580@@ -31,7 +31,7 @@ struct nls_table {
75581 const unsigned char *charset2upper;
75582 struct module *owner;
75583 struct nls_table *next;
75584-};
75585+} __do_const;
75586
75587 /* this value hold the maximum octet of charset */
75588 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75589diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75590index d14a4c3..a078786 100644
75591--- a/include/linux/notifier.h
75592+++ b/include/linux/notifier.h
75593@@ -54,7 +54,8 @@ struct notifier_block {
75594 notifier_fn_t notifier_call;
75595 struct notifier_block __rcu *next;
75596 int priority;
75597-};
75598+} __do_const;
75599+typedef struct notifier_block __no_const notifier_block_no_const;
75600
75601 struct atomic_notifier_head {
75602 spinlock_t lock;
75603diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75604index a4c5624..79d6d88 100644
75605--- a/include/linux/oprofile.h
75606+++ b/include/linux/oprofile.h
75607@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75608 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75609 char const * name, ulong * val);
75610
75611-/** Create a file for read-only access to an atomic_t. */
75612+/** Create a file for read-only access to an atomic_unchecked_t. */
75613 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75614- char const * name, atomic_t * val);
75615+ char const * name, atomic_unchecked_t * val);
75616
75617 /** create a directory */
75618 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75619diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75620index 8db71dc..a76bf2c 100644
75621--- a/include/linux/pci_hotplug.h
75622+++ b/include/linux/pci_hotplug.h
75623@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75624 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75625 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75626 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75627-};
75628+} __do_const;
75629+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75630
75631 /**
75632 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75633diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75634index c43f6ea..2d4416f 100644
75635--- a/include/linux/perf_event.h
75636+++ b/include/linux/perf_event.h
75637@@ -328,8 +328,8 @@ struct perf_event {
75638
75639 enum perf_event_active_state state;
75640 unsigned int attach_state;
75641- local64_t count;
75642- atomic64_t child_count;
75643+ local64_t count; /* PaX: fix it one day */
75644+ atomic64_unchecked_t child_count;
75645
75646 /*
75647 * These are the total time in nanoseconds that the event
75648@@ -380,8 +380,8 @@ struct perf_event {
75649 * These accumulate total time (in nanoseconds) that children
75650 * events have been enabled and running, respectively.
75651 */
75652- atomic64_t child_total_time_enabled;
75653- atomic64_t child_total_time_running;
75654+ atomic64_unchecked_t child_total_time_enabled;
75655+ atomic64_unchecked_t child_total_time_running;
75656
75657 /*
75658 * Protect attach/detach and child_list:
75659@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75660 entry->ip[entry->nr++] = ip;
75661 }
75662
75663-extern int sysctl_perf_event_paranoid;
75664+extern int sysctl_perf_event_legitimately_concerned;
75665 extern int sysctl_perf_event_mlock;
75666 extern int sysctl_perf_event_sample_rate;
75667 extern int sysctl_perf_cpu_time_max_percent;
75668@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75669 loff_t *ppos);
75670
75671
75672+static inline bool perf_paranoid_any(void)
75673+{
75674+ return sysctl_perf_event_legitimately_concerned > 2;
75675+}
75676+
75677 static inline bool perf_paranoid_tracepoint_raw(void)
75678 {
75679- return sysctl_perf_event_paranoid > -1;
75680+ return sysctl_perf_event_legitimately_concerned > -1;
75681 }
75682
75683 static inline bool perf_paranoid_cpu(void)
75684 {
75685- return sysctl_perf_event_paranoid > 0;
75686+ return sysctl_perf_event_legitimately_concerned > 0;
75687 }
75688
75689 static inline bool perf_paranoid_kernel(void)
75690 {
75691- return sysctl_perf_event_paranoid > 1;
75692+ return sysctl_perf_event_legitimately_concerned > 1;
75693 }
75694
75695 extern void perf_event_init(void);
75696@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75697 struct device_attribute attr;
75698 u64 id;
75699 const char *event_str;
75700-};
75701+} __do_const;
75702
75703 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75704 static struct perf_pmu_events_attr _var = { \
75705diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75706index b8809fe..ae4ccd0 100644
75707--- a/include/linux/pipe_fs_i.h
75708+++ b/include/linux/pipe_fs_i.h
75709@@ -47,10 +47,10 @@ struct pipe_inode_info {
75710 struct mutex mutex;
75711 wait_queue_head_t wait;
75712 unsigned int nrbufs, curbuf, buffers;
75713- unsigned int readers;
75714- unsigned int writers;
75715- unsigned int files;
75716- unsigned int waiting_writers;
75717+ atomic_t readers;
75718+ atomic_t writers;
75719+ atomic_t files;
75720+ atomic_t waiting_writers;
75721 unsigned int r_counter;
75722 unsigned int w_counter;
75723 struct page *tmp_page;
75724diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75725index 5f28cae..3d23723 100644
75726--- a/include/linux/platform_data/usb-ehci-s5p.h
75727+++ b/include/linux/platform_data/usb-ehci-s5p.h
75728@@ -14,7 +14,7 @@
75729 struct s5p_ehci_platdata {
75730 int (*phy_init)(struct platform_device *pdev, int type);
75731 int (*phy_exit)(struct platform_device *pdev, int type);
75732-};
75733+} __no_const;
75734
75735 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75736
75737diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75738index c256c59..8ea94c7 100644
75739--- a/include/linux/platform_data/usb-ohci-exynos.h
75740+++ b/include/linux/platform_data/usb-ohci-exynos.h
75741@@ -14,7 +14,7 @@
75742 struct exynos4_ohci_platdata {
75743 int (*phy_init)(struct platform_device *pdev, int type);
75744 int (*phy_exit)(struct platform_device *pdev, int type);
75745-};
75746+} __no_const;
75747
75748 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75749
75750diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75751index 7c1d252..c5c773e 100644
75752--- a/include/linux/pm_domain.h
75753+++ b/include/linux/pm_domain.h
75754@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75755
75756 struct gpd_cpu_data {
75757 unsigned int saved_exit_latency;
75758- struct cpuidle_state *idle_state;
75759+ cpuidle_state_no_const *idle_state;
75760 };
75761
75762 struct generic_pm_domain {
75763diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75764index 6fa7cea..7bf6415 100644
75765--- a/include/linux/pm_runtime.h
75766+++ b/include/linux/pm_runtime.h
75767@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75768
75769 static inline void pm_runtime_mark_last_busy(struct device *dev)
75770 {
75771- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75772+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75773 }
75774
75775 #else /* !CONFIG_PM_RUNTIME */
75776diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75777index 195aafc..49a7bc2 100644
75778--- a/include/linux/pnp.h
75779+++ b/include/linux/pnp.h
75780@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75781 struct pnp_fixup {
75782 char id[7];
75783 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75784-};
75785+} __do_const;
75786
75787 /* config parameters */
75788 #define PNP_CONFIG_NORMAL 0x0001
75789diff --git a/include/linux/poison.h b/include/linux/poison.h
75790index 2110a81..13a11bb 100644
75791--- a/include/linux/poison.h
75792+++ b/include/linux/poison.h
75793@@ -19,8 +19,8 @@
75794 * under normal circumstances, used to verify that nobody uses
75795 * non-initialized list entries.
75796 */
75797-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75798-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75799+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75800+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75801
75802 /********** include/linux/timer.h **********/
75803 /*
75804diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75805index d8b187c3..9a9257a 100644
75806--- a/include/linux/power/smartreflex.h
75807+++ b/include/linux/power/smartreflex.h
75808@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75809 int (*notify)(struct omap_sr *sr, u32 status);
75810 u8 notify_flags;
75811 u8 class_type;
75812-};
75813+} __do_const;
75814
75815 /**
75816 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75817diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75818index 4ea1d37..80f4b33 100644
75819--- a/include/linux/ppp-comp.h
75820+++ b/include/linux/ppp-comp.h
75821@@ -84,7 +84,7 @@ struct compressor {
75822 struct module *owner;
75823 /* Extra skb space needed by the compressor algorithm */
75824 unsigned int comp_extra;
75825-};
75826+} __do_const;
75827
75828 /*
75829 * The return value from decompress routine is the length of the
75830diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75831index f5d4723..a6ea2fa 100644
75832--- a/include/linux/preempt.h
75833+++ b/include/linux/preempt.h
75834@@ -18,8 +18,13 @@
75835 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75836 #endif
75837
75838+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75839+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75840+
75841 #define inc_preempt_count() add_preempt_count(1)
75842+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75843 #define dec_preempt_count() sub_preempt_count(1)
75844+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75845
75846 #define preempt_count() (current_thread_info()->preempt_count)
75847
75848@@ -64,6 +69,12 @@ do { \
75849 barrier(); \
75850 } while (0)
75851
75852+#define raw_preempt_disable() \
75853+do { \
75854+ raw_inc_preempt_count(); \
75855+ barrier(); \
75856+} while (0)
75857+
75858 #define sched_preempt_enable_no_resched() \
75859 do { \
75860 barrier(); \
75861@@ -72,6 +83,12 @@ do { \
75862
75863 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75864
75865+#define raw_preempt_enable_no_resched() \
75866+do { \
75867+ barrier(); \
75868+ raw_dec_preempt_count(); \
75869+} while (0)
75870+
75871 #define preempt_enable() \
75872 do { \
75873 preempt_enable_no_resched(); \
75874@@ -116,8 +133,10 @@ do { \
75875 * region.
75876 */
75877 #define preempt_disable() barrier()
75878+#define raw_preempt_disable() barrier()
75879 #define sched_preempt_enable_no_resched() barrier()
75880 #define preempt_enable_no_resched() barrier()
75881+#define raw_preempt_enable_no_resched() barrier()
75882 #define preempt_enable() barrier()
75883
75884 #define preempt_disable_notrace() barrier()
75885diff --git a/include/linux/printk.h b/include/linux/printk.h
75886index 22c7052..ad3fa0a 100644
75887--- a/include/linux/printk.h
75888+++ b/include/linux/printk.h
75889@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75890 void early_printk(const char *s, ...) { }
75891 #endif
75892
75893+extern int kptr_restrict;
75894+
75895 #ifdef CONFIG_PRINTK
75896 asmlinkage __printf(5, 0)
75897 int vprintk_emit(int facility, int level,
75898@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75899
75900 extern int printk_delay_msec;
75901 extern int dmesg_restrict;
75902-extern int kptr_restrict;
75903
75904 extern void wake_up_klogd(void);
75905
75906diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75907index 608e60a..c26f864 100644
75908--- a/include/linux/proc_fs.h
75909+++ b/include/linux/proc_fs.h
75910@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75911 return proc_create_data(name, mode, parent, proc_fops, NULL);
75912 }
75913
75914+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75915+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75916+{
75917+#ifdef CONFIG_GRKERNSEC_PROC_USER
75918+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75919+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75920+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75921+#else
75922+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75923+#endif
75924+}
75925+
75926+
75927 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75928 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75929 extern void *PDE_DATA(const struct inode *);
75930diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75931index 34a1e10..03a6d03 100644
75932--- a/include/linux/proc_ns.h
75933+++ b/include/linux/proc_ns.h
75934@@ -14,7 +14,7 @@ struct proc_ns_operations {
75935 void (*put)(void *ns);
75936 int (*install)(struct nsproxy *nsproxy, void *ns);
75937 unsigned int (*inum)(void *ns);
75938-};
75939+} __do_const;
75940
75941 struct proc_ns {
75942 void *ns;
75943diff --git a/include/linux/random.h b/include/linux/random.h
75944index 6312dd9..2561947 100644
75945--- a/include/linux/random.h
75946+++ b/include/linux/random.h
75947@@ -10,9 +10,19 @@
75948
75949
75950 extern void add_device_randomness(const void *, unsigned int);
75951+
75952+static inline void add_latent_entropy(void)
75953+{
75954+
75955+#ifdef LATENT_ENTROPY_PLUGIN
75956+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75957+#endif
75958+
75959+}
75960+
75961 extern void add_input_randomness(unsigned int type, unsigned int code,
75962- unsigned int value);
75963-extern void add_interrupt_randomness(int irq, int irq_flags);
75964+ unsigned int value) __latent_entropy;
75965+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75966
75967 extern void get_random_bytes(void *buf, int nbytes);
75968 extern void get_random_bytes_arch(void *buf, int nbytes);
75969@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
75970 u32 prandom_u32_state(struct rnd_state *);
75971 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75972
75973+static inline unsigned long pax_get_random_long(void)
75974+{
75975+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75976+}
75977+
75978 /*
75979 * Handle minimum values for seeds
75980 */
75981diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75982index 4106721..132d42c 100644
75983--- a/include/linux/rculist.h
75984+++ b/include/linux/rculist.h
75985@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75986 struct list_head *prev, struct list_head *next);
75987 #endif
75988
75989+extern void __pax_list_add_rcu(struct list_head *new,
75990+ struct list_head *prev, struct list_head *next);
75991+
75992 /**
75993 * list_add_rcu - add a new entry to rcu-protected list
75994 * @new: new entry to be added
75995@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75996 __list_add_rcu(new, head, head->next);
75997 }
75998
75999+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76000+{
76001+ __pax_list_add_rcu(new, head, head->next);
76002+}
76003+
76004 /**
76005 * list_add_tail_rcu - add a new entry to rcu-protected list
76006 * @new: new entry to be added
76007@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76008 __list_add_rcu(new, head->prev, head);
76009 }
76010
76011+static inline void pax_list_add_tail_rcu(struct list_head *new,
76012+ struct list_head *head)
76013+{
76014+ __pax_list_add_rcu(new, head->prev, head);
76015+}
76016+
76017 /**
76018 * list_del_rcu - deletes entry from list without re-initialization
76019 * @entry: the element to delete from the list.
76020@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76021 entry->prev = LIST_POISON2;
76022 }
76023
76024+extern void pax_list_del_rcu(struct list_head *entry);
76025+
76026 /**
76027 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76028 * @n: the element to delete from the hash list.
76029diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76030index 8e00f9f..9449b55 100644
76031--- a/include/linux/reboot.h
76032+++ b/include/linux/reboot.h
76033@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76034 * Architecture-specific implementations of sys_reboot commands.
76035 */
76036
76037-extern void machine_restart(char *cmd);
76038-extern void machine_halt(void);
76039-extern void machine_power_off(void);
76040+extern void machine_restart(char *cmd) __noreturn;
76041+extern void machine_halt(void) __noreturn;
76042+extern void machine_power_off(void) __noreturn;
76043
76044 extern void machine_shutdown(void);
76045 struct pt_regs;
76046@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76047 */
76048
76049 extern void kernel_restart_prepare(char *cmd);
76050-extern void kernel_restart(char *cmd);
76051-extern void kernel_halt(void);
76052-extern void kernel_power_off(void);
76053+extern void kernel_restart(char *cmd) __noreturn;
76054+extern void kernel_halt(void) __noreturn;
76055+extern void kernel_power_off(void) __noreturn;
76056
76057 extern int C_A_D; /* for sysctl */
76058 void ctrl_alt_del(void);
76059@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76060 * Emergency restart, callable from an interrupt handler.
76061 */
76062
76063-extern void emergency_restart(void);
76064+extern void emergency_restart(void) __noreturn;
76065 #include <asm/emergency-restart.h>
76066
76067 #endif /* _LINUX_REBOOT_H */
76068diff --git a/include/linux/regset.h b/include/linux/regset.h
76069index 8e0c9fe..ac4d221 100644
76070--- a/include/linux/regset.h
76071+++ b/include/linux/regset.h
76072@@ -161,7 +161,8 @@ struct user_regset {
76073 unsigned int align;
76074 unsigned int bias;
76075 unsigned int core_note_type;
76076-};
76077+} __do_const;
76078+typedef struct user_regset __no_const user_regset_no_const;
76079
76080 /**
76081 * struct user_regset_view - available regsets
76082diff --git a/include/linux/relay.h b/include/linux/relay.h
76083index d7c8359..818daf5 100644
76084--- a/include/linux/relay.h
76085+++ b/include/linux/relay.h
76086@@ -157,7 +157,7 @@ struct rchan_callbacks
76087 * The callback should return 0 if successful, negative if not.
76088 */
76089 int (*remove_buf_file)(struct dentry *dentry);
76090-};
76091+} __no_const;
76092
76093 /*
76094 * CONFIG_RELAY kernel API, kernel/relay.c
76095diff --git a/include/linux/rio.h b/include/linux/rio.h
76096index b71d573..2f940bd 100644
76097--- a/include/linux/rio.h
76098+++ b/include/linux/rio.h
76099@@ -355,7 +355,7 @@ struct rio_ops {
76100 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76101 u64 rstart, u32 size, u32 flags);
76102 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76103-};
76104+} __no_const;
76105
76106 #define RIO_RESOURCE_MEM 0x00000100
76107 #define RIO_RESOURCE_DOORBELL 0x00000200
76108diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76109index 6dacb93..6174423 100644
76110--- a/include/linux/rmap.h
76111+++ b/include/linux/rmap.h
76112@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76113 void anon_vma_init(void); /* create anon_vma_cachep */
76114 int anon_vma_prepare(struct vm_area_struct *);
76115 void unlink_anon_vmas(struct vm_area_struct *);
76116-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76117-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76118+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76119+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76120
76121 static inline void anon_vma_merge(struct vm_area_struct *vma,
76122 struct vm_area_struct *next)
76123diff --git a/include/linux/sched.h b/include/linux/sched.h
76124index 078066d..4090b3b 100644
76125--- a/include/linux/sched.h
76126+++ b/include/linux/sched.h
76127@@ -62,6 +62,7 @@ struct bio_list;
76128 struct fs_struct;
76129 struct perf_event_context;
76130 struct blk_plug;
76131+struct linux_binprm;
76132
76133 /*
76134 * List of flags we want to share for kernel threads,
76135@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76136 extern int in_sched_functions(unsigned long addr);
76137
76138 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76139-extern signed long schedule_timeout(signed long timeout);
76140+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76141 extern signed long schedule_timeout_interruptible(signed long timeout);
76142 extern signed long schedule_timeout_killable(signed long timeout);
76143 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76144@@ -314,6 +315,19 @@ struct nsproxy;
76145 struct user_namespace;
76146
76147 #ifdef CONFIG_MMU
76148+
76149+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76150+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76151+#else
76152+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76153+{
76154+ return 0;
76155+}
76156+#endif
76157+
76158+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76159+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76160+
76161 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76162 extern unsigned long
76163 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76164@@ -589,6 +603,17 @@ struct signal_struct {
76165 #ifdef CONFIG_TASKSTATS
76166 struct taskstats *stats;
76167 #endif
76168+
76169+#ifdef CONFIG_GRKERNSEC
76170+ u32 curr_ip;
76171+ u32 saved_ip;
76172+ u32 gr_saddr;
76173+ u32 gr_daddr;
76174+ u16 gr_sport;
76175+ u16 gr_dport;
76176+ u8 used_accept:1;
76177+#endif
76178+
76179 #ifdef CONFIG_AUDIT
76180 unsigned audit_tty;
76181 unsigned audit_tty_log_passwd;
76182@@ -669,6 +694,14 @@ struct user_struct {
76183 struct key *session_keyring; /* UID's default session keyring */
76184 #endif
76185
76186+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76187+ unsigned char kernel_banned;
76188+#endif
76189+#ifdef CONFIG_GRKERNSEC_BRUTE
76190+ unsigned char suid_banned;
76191+ unsigned long suid_ban_expires;
76192+#endif
76193+
76194 /* Hash table maintenance information */
76195 struct hlist_node uidhash_node;
76196 kuid_t uid;
76197@@ -1151,8 +1184,8 @@ struct task_struct {
76198 struct list_head thread_group;
76199
76200 struct completion *vfork_done; /* for vfork() */
76201- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76202- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76203+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76204+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76205
76206 cputime_t utime, stime, utimescaled, stimescaled;
76207 cputime_t gtime;
76208@@ -1177,11 +1210,6 @@ struct task_struct {
76209 struct task_cputime cputime_expires;
76210 struct list_head cpu_timers[3];
76211
76212-/* process credentials */
76213- const struct cred __rcu *real_cred; /* objective and real subjective task
76214- * credentials (COW) */
76215- const struct cred __rcu *cred; /* effective (overridable) subjective task
76216- * credentials (COW) */
76217 char comm[TASK_COMM_LEN]; /* executable name excluding path
76218 - access with [gs]et_task_comm (which lock
76219 it with task_lock())
76220@@ -1198,6 +1226,10 @@ struct task_struct {
76221 #endif
76222 /* CPU-specific state of this task */
76223 struct thread_struct thread;
76224+/* thread_info moved to task_struct */
76225+#ifdef CONFIG_X86
76226+ struct thread_info tinfo;
76227+#endif
76228 /* filesystem information */
76229 struct fs_struct *fs;
76230 /* open file information */
76231@@ -1271,6 +1303,10 @@ struct task_struct {
76232 gfp_t lockdep_reclaim_gfp;
76233 #endif
76234
76235+/* process credentials */
76236+ const struct cred __rcu *real_cred; /* objective and real subjective task
76237+ * credentials (COW) */
76238+
76239 /* journalling filesystem info */
76240 void *journal_info;
76241
76242@@ -1309,6 +1345,10 @@ struct task_struct {
76243 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76244 struct list_head cg_list;
76245 #endif
76246+
76247+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76248+ * credentials (COW) */
76249+
76250 #ifdef CONFIG_FUTEX
76251 struct robust_list_head __user *robust_list;
76252 #ifdef CONFIG_COMPAT
76253@@ -1406,8 +1446,76 @@ struct task_struct {
76254 unsigned int sequential_io;
76255 unsigned int sequential_io_avg;
76256 #endif
76257+
76258+#ifdef CONFIG_GRKERNSEC
76259+ /* grsecurity */
76260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76261+ u64 exec_id;
76262+#endif
76263+#ifdef CONFIG_GRKERNSEC_SETXID
76264+ const struct cred *delayed_cred;
76265+#endif
76266+ struct dentry *gr_chroot_dentry;
76267+ struct acl_subject_label *acl;
76268+ struct acl_role_label *role;
76269+ struct file *exec_file;
76270+ unsigned long brute_expires;
76271+ u16 acl_role_id;
76272+ /* is this the task that authenticated to the special role */
76273+ u8 acl_sp_role;
76274+ u8 is_writable;
76275+ u8 brute;
76276+ u8 gr_is_chrooted;
76277+#endif
76278+
76279 };
76280
76281+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76282+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76283+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76284+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76285+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76286+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76287+
76288+#ifdef CONFIG_PAX_SOFTMODE
76289+extern int pax_softmode;
76290+#endif
76291+
76292+extern int pax_check_flags(unsigned long *);
76293+
76294+/* if tsk != current then task_lock must be held on it */
76295+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76296+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76297+{
76298+ if (likely(tsk->mm))
76299+ return tsk->mm->pax_flags;
76300+ else
76301+ return 0UL;
76302+}
76303+
76304+/* if tsk != current then task_lock must be held on it */
76305+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76306+{
76307+ if (likely(tsk->mm)) {
76308+ tsk->mm->pax_flags = flags;
76309+ return 0;
76310+ }
76311+ return -EINVAL;
76312+}
76313+#endif
76314+
76315+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76316+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76317+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76318+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76319+#endif
76320+
76321+struct path;
76322+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76323+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76324+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76325+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76326+
76327 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76328 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76329
76330@@ -1466,7 +1574,7 @@ struct pid_namespace;
76331 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76332 struct pid_namespace *ns);
76333
76334-static inline pid_t task_pid_nr(struct task_struct *tsk)
76335+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76336 {
76337 return tsk->pid;
76338 }
76339@@ -1916,7 +2024,9 @@ void yield(void);
76340 extern struct exec_domain default_exec_domain;
76341
76342 union thread_union {
76343+#ifndef CONFIG_X86
76344 struct thread_info thread_info;
76345+#endif
76346 unsigned long stack[THREAD_SIZE/sizeof(long)];
76347 };
76348
76349@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76350 */
76351
76352 extern struct task_struct *find_task_by_vpid(pid_t nr);
76353+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76354 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76355 struct pid_namespace *ns);
76356
76357@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76358 extern void exit_itimers(struct signal_struct *);
76359 extern void flush_itimer_signals(void);
76360
76361-extern void do_group_exit(int);
76362+extern __noreturn void do_group_exit(int);
76363
76364 extern int allow_signal(int);
76365 extern int disallow_signal(int);
76366@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76367
76368 #endif
76369
76370-static inline int object_is_on_stack(void *obj)
76371+static inline int object_starts_on_stack(void *obj)
76372 {
76373- void *stack = task_stack_page(current);
76374+ const void *stack = task_stack_page(current);
76375
76376 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76377 }
76378diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76379index bf8086b..962b035 100644
76380--- a/include/linux/sched/sysctl.h
76381+++ b/include/linux/sched/sysctl.h
76382@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76383 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76384
76385 extern int sysctl_max_map_count;
76386+extern unsigned long sysctl_heap_stack_gap;
76387
76388 extern unsigned int sysctl_sched_latency;
76389 extern unsigned int sysctl_sched_min_granularity;
76390diff --git a/include/linux/security.h b/include/linux/security.h
76391index 7ce53ae..8ee24a5 100644
76392--- a/include/linux/security.h
76393+++ b/include/linux/security.h
76394@@ -27,6 +27,7 @@
76395 #include <linux/slab.h>
76396 #include <linux/err.h>
76397 #include <linux/string.h>
76398+#include <linux/grsecurity.h>
76399
76400 struct linux_binprm;
76401 struct cred;
76402@@ -116,8 +117,6 @@ struct seq_file;
76403
76404 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76405
76406-void reset_security_ops(void);
76407-
76408 #ifdef CONFIG_MMU
76409 extern unsigned long mmap_min_addr;
76410 extern unsigned long dac_mmap_min_addr;
76411diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76412index 4e32edc..f8f2d18 100644
76413--- a/include/linux/seq_file.h
76414+++ b/include/linux/seq_file.h
76415@@ -26,6 +26,9 @@ struct seq_file {
76416 struct mutex lock;
76417 const struct seq_operations *op;
76418 int poll_event;
76419+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76420+ u64 exec_id;
76421+#endif
76422 #ifdef CONFIG_USER_NS
76423 struct user_namespace *user_ns;
76424 #endif
76425@@ -38,6 +41,7 @@ struct seq_operations {
76426 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76427 int (*show) (struct seq_file *m, void *v);
76428 };
76429+typedef struct seq_operations __no_const seq_operations_no_const;
76430
76431 #define SEQ_SKIP 1
76432
76433diff --git a/include/linux/shm.h b/include/linux/shm.h
76434index 429c199..4d42e38 100644
76435--- a/include/linux/shm.h
76436+++ b/include/linux/shm.h
76437@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76438
76439 /* The task created the shm object. NULL if the task is dead. */
76440 struct task_struct *shm_creator;
76441+#ifdef CONFIG_GRKERNSEC
76442+ time_t shm_createtime;
76443+ pid_t shm_lapid;
76444+#endif
76445 };
76446
76447 /* shm_mode upper byte flags */
76448diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76449index 6bd165b..4823435 100644
76450--- a/include/linux/skbuff.h
76451+++ b/include/linux/skbuff.h
76452@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76453 extern struct sk_buff *__alloc_skb(unsigned int size,
76454 gfp_t priority, int flags, int node);
76455 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76456-static inline struct sk_buff *alloc_skb(unsigned int size,
76457+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76458 gfp_t priority)
76459 {
76460 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76461@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76462 */
76463 static inline int skb_queue_empty(const struct sk_buff_head *list)
76464 {
76465- return list->next == (struct sk_buff *)list;
76466+ return list->next == (const struct sk_buff *)list;
76467 }
76468
76469 /**
76470@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76471 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76472 const struct sk_buff *skb)
76473 {
76474- return skb->next == (struct sk_buff *)list;
76475+ return skb->next == (const struct sk_buff *)list;
76476 }
76477
76478 /**
76479@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76480 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76481 const struct sk_buff *skb)
76482 {
76483- return skb->prev == (struct sk_buff *)list;
76484+ return skb->prev == (const struct sk_buff *)list;
76485 }
76486
76487 /**
76488@@ -1755,7 +1755,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76489 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76490 */
76491 #ifndef NET_SKB_PAD
76492-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76493+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76494 #endif
76495
76496 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76497@@ -2350,7 +2350,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76498 int noblock, int *err);
76499 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76500 struct poll_table_struct *wait);
76501-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76502+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76503 int offset, struct iovec *to,
76504 int size);
76505 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76506@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
76507 nf_bridge_put(skb->nf_bridge);
76508 skb->nf_bridge = NULL;
76509 #endif
76510+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76511+ skb->nf_trace = 0;
76512+#endif
76513 }
76514
76515 static inline void nf_reset_trace(struct sk_buff *skb)
76516diff --git a/include/linux/slab.h b/include/linux/slab.h
76517index 6c5cc0e..9ca0fd6 100644
76518--- a/include/linux/slab.h
76519+++ b/include/linux/slab.h
76520@@ -12,15 +12,29 @@
76521 #include <linux/gfp.h>
76522 #include <linux/types.h>
76523 #include <linux/workqueue.h>
76524-
76525+#include <linux/err.h>
76526
76527 /*
76528 * Flags to pass to kmem_cache_create().
76529 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76530 */
76531 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76532+
76533+#ifdef CONFIG_PAX_USERCOPY_SLABS
76534+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76535+#else
76536+#define SLAB_USERCOPY 0x00000000UL
76537+#endif
76538+
76539 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76540 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76541+
76542+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76543+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76544+#else
76545+#define SLAB_NO_SANITIZE 0x00000000UL
76546+#endif
76547+
76548 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76549 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76550 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76551@@ -89,10 +103,13 @@
76552 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76553 * Both make kfree a no-op.
76554 */
76555-#define ZERO_SIZE_PTR ((void *)16)
76556+#define ZERO_SIZE_PTR \
76557+({ \
76558+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76559+ (void *)(-MAX_ERRNO-1L); \
76560+})
76561
76562-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76563- (unsigned long)ZERO_SIZE_PTR)
76564+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76565
76566
76567 struct mem_cgroup;
76568@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76569 void kfree(const void *);
76570 void kzfree(const void *);
76571 size_t ksize(const void *);
76572+const char *check_heap_object(const void *ptr, unsigned long n);
76573+bool is_usercopy_object(const void *ptr);
76574
76575 /*
76576 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76577@@ -164,7 +183,7 @@ struct kmem_cache {
76578 unsigned int align; /* Alignment as calculated */
76579 unsigned long flags; /* Active flags on the slab */
76580 const char *name; /* Slab name for sysfs */
76581- int refcount; /* Use counter */
76582+ atomic_t refcount; /* Use counter */
76583 void (*ctor)(void *); /* Called on object slot creation */
76584 struct list_head list; /* List of all slab caches on the system */
76585 };
76586@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76587 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76588 #endif
76589
76590+#ifdef CONFIG_PAX_USERCOPY_SLABS
76591+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76592+#endif
76593+
76594 /*
76595 * Figure out which kmalloc slab an allocation of a certain size
76596 * belongs to.
76597@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76598 * 2 = 120 .. 192 bytes
76599 * n = 2^(n-1) .. 2^n -1
76600 */
76601-static __always_inline int kmalloc_index(size_t size)
76602+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76603 {
76604 if (!size)
76605 return 0;
76606@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76607 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76608 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76609 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76610-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76611+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76612 #define kmalloc_track_caller(size, flags) \
76613 __kmalloc_track_caller(size, flags, _RET_IP_)
76614 #else
76615@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76616 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76617 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76618 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76619-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76620+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76621 #define kmalloc_node_track_caller(size, flags, node) \
76622 __kmalloc_node_track_caller(size, flags, node, \
76623 _RET_IP_)
76624diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76625index cd40158..4e2f7af 100644
76626--- a/include/linux/slab_def.h
76627+++ b/include/linux/slab_def.h
76628@@ -50,7 +50,7 @@ struct kmem_cache {
76629 /* 4) cache creation/removal */
76630 const char *name;
76631 struct list_head list;
76632- int refcount;
76633+ atomic_t refcount;
76634 int object_size;
76635 int align;
76636
76637@@ -66,10 +66,14 @@ struct kmem_cache {
76638 unsigned long node_allocs;
76639 unsigned long node_frees;
76640 unsigned long node_overflow;
76641- atomic_t allochit;
76642- atomic_t allocmiss;
76643- atomic_t freehit;
76644- atomic_t freemiss;
76645+ atomic_unchecked_t allochit;
76646+ atomic_unchecked_t allocmiss;
76647+ atomic_unchecked_t freehit;
76648+ atomic_unchecked_t freemiss;
76649+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76650+ atomic_unchecked_t sanitized;
76651+ atomic_unchecked_t not_sanitized;
76652+#endif
76653
76654 /*
76655 * If debugging is enabled, then the allocator can add additional
76656@@ -103,7 +107,7 @@ struct kmem_cache {
76657 };
76658
76659 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76660-void *__kmalloc(size_t size, gfp_t flags);
76661+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76662
76663 #ifdef CONFIG_TRACING
76664 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76665@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76666 cachep = kmalloc_dma_caches[i];
76667 else
76668 #endif
76669+
76670+#ifdef CONFIG_PAX_USERCOPY_SLABS
76671+ if (flags & GFP_USERCOPY)
76672+ cachep = kmalloc_usercopy_caches[i];
76673+ else
76674+#endif
76675+
76676 cachep = kmalloc_caches[i];
76677
76678 ret = kmem_cache_alloc_trace(cachep, flags, size);
76679@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76680 }
76681
76682 #ifdef CONFIG_NUMA
76683-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76684+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76685 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76686
76687 #ifdef CONFIG_TRACING
76688@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76689 cachep = kmalloc_dma_caches[i];
76690 else
76691 #endif
76692+
76693+#ifdef CONFIG_PAX_USERCOPY_SLABS
76694+ if (flags & GFP_USERCOPY)
76695+ cachep = kmalloc_usercopy_caches[i];
76696+ else
76697+#endif
76698+
76699 cachep = kmalloc_caches[i];
76700
76701 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76702diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76703index 095a5a4..4b82027 100644
76704--- a/include/linux/slob_def.h
76705+++ b/include/linux/slob_def.h
76706@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76707 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76708 }
76709
76710-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76711+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76712
76713 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76714 {
76715@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76716 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76717 }
76718
76719-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76720+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76721 {
76722 return kmalloc(size, flags);
76723 }
76724diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76725index 027276f..092bfe8 100644
76726--- a/include/linux/slub_def.h
76727+++ b/include/linux/slub_def.h
76728@@ -80,7 +80,7 @@ struct kmem_cache {
76729 struct kmem_cache_order_objects max;
76730 struct kmem_cache_order_objects min;
76731 gfp_t allocflags; /* gfp flags to use on each alloc */
76732- int refcount; /* Refcount for slab cache destroy */
76733+ atomic_t refcount; /* Refcount for slab cache destroy */
76734 void (*ctor)(void *);
76735 int inuse; /* Offset to metadata */
76736 int align; /* Alignment */
76737@@ -105,7 +105,7 @@ struct kmem_cache {
76738 };
76739
76740 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76741-void *__kmalloc(size_t size, gfp_t flags);
76742+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76743
76744 static __always_inline void *
76745 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76746@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76747 }
76748 #endif
76749
76750-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76751+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76752 {
76753 unsigned int order = get_order(size);
76754 return kmalloc_order_trace(size, flags, order);
76755@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76756 }
76757
76758 #ifdef CONFIG_NUMA
76759-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76760+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76761 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76762
76763 #ifdef CONFIG_TRACING
76764diff --git a/include/linux/smp.h b/include/linux/smp.h
76765index c181399..09d7b92 100644
76766--- a/include/linux/smp.h
76767+++ b/include/linux/smp.h
76768@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76769 #endif
76770
76771 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76772+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76773 #define put_cpu() preempt_enable()
76774+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76775
76776 /*
76777 * Callback to arch code if there's nosmp or maxcpus=0 on the
76778diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76779index 54f91d3..be2c379 100644
76780--- a/include/linux/sock_diag.h
76781+++ b/include/linux/sock_diag.h
76782@@ -11,7 +11,7 @@ struct sock;
76783 struct sock_diag_handler {
76784 __u8 family;
76785 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76786-};
76787+} __do_const;
76788
76789 int sock_diag_register(const struct sock_diag_handler *h);
76790 void sock_diag_unregister(const struct sock_diag_handler *h);
76791diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76792index 680f9a3..f13aeb0 100644
76793--- a/include/linux/sonet.h
76794+++ b/include/linux/sonet.h
76795@@ -7,7 +7,7 @@
76796 #include <uapi/linux/sonet.h>
76797
76798 struct k_sonet_stats {
76799-#define __HANDLE_ITEM(i) atomic_t i
76800+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76801 __SONET_ITEMS
76802 #undef __HANDLE_ITEM
76803 };
76804diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76805index 07d8e53..dc934c9 100644
76806--- a/include/linux/sunrpc/addr.h
76807+++ b/include/linux/sunrpc/addr.h
76808@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76809 {
76810 switch (sap->sa_family) {
76811 case AF_INET:
76812- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76813+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76814 case AF_INET6:
76815- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76816+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76817 }
76818 return 0;
76819 }
76820@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76821 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76822 const struct sockaddr *src)
76823 {
76824- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76825+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76826 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76827
76828 dsin->sin_family = ssin->sin_family;
76829@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76830 if (sa->sa_family != AF_INET6)
76831 return 0;
76832
76833- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76834+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76835 }
76836
76837 #endif /* _LINUX_SUNRPC_ADDR_H */
76838diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76839index bfe11be..12bc8c4 100644
76840--- a/include/linux/sunrpc/clnt.h
76841+++ b/include/linux/sunrpc/clnt.h
76842@@ -96,7 +96,7 @@ struct rpc_procinfo {
76843 unsigned int p_timer; /* Which RTT timer to use */
76844 u32 p_statidx; /* Which procedure to account */
76845 const char * p_name; /* name of procedure */
76846-};
76847+} __do_const;
76848
76849 #ifdef __KERNEL__
76850
76851diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76852index 1f0216b..6a4fa50 100644
76853--- a/include/linux/sunrpc/svc.h
76854+++ b/include/linux/sunrpc/svc.h
76855@@ -411,7 +411,7 @@ struct svc_procedure {
76856 unsigned int pc_count; /* call count */
76857 unsigned int pc_cachetype; /* cache info (NFS) */
76858 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76859-};
76860+} __do_const;
76861
76862 /*
76863 * Function prototypes.
76864diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76865index 0b8e3e6..33e0a01 100644
76866--- a/include/linux/sunrpc/svc_rdma.h
76867+++ b/include/linux/sunrpc/svc_rdma.h
76868@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76869 extern unsigned int svcrdma_max_requests;
76870 extern unsigned int svcrdma_max_req_size;
76871
76872-extern atomic_t rdma_stat_recv;
76873-extern atomic_t rdma_stat_read;
76874-extern atomic_t rdma_stat_write;
76875-extern atomic_t rdma_stat_sq_starve;
76876-extern atomic_t rdma_stat_rq_starve;
76877-extern atomic_t rdma_stat_rq_poll;
76878-extern atomic_t rdma_stat_rq_prod;
76879-extern atomic_t rdma_stat_sq_poll;
76880-extern atomic_t rdma_stat_sq_prod;
76881+extern atomic_unchecked_t rdma_stat_recv;
76882+extern atomic_unchecked_t rdma_stat_read;
76883+extern atomic_unchecked_t rdma_stat_write;
76884+extern atomic_unchecked_t rdma_stat_sq_starve;
76885+extern atomic_unchecked_t rdma_stat_rq_starve;
76886+extern atomic_unchecked_t rdma_stat_rq_poll;
76887+extern atomic_unchecked_t rdma_stat_rq_prod;
76888+extern atomic_unchecked_t rdma_stat_sq_poll;
76889+extern atomic_unchecked_t rdma_stat_sq_prod;
76890
76891 #define RPCRDMA_VERSION 1
76892
76893diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76894index 8d71d65..f79586e 100644
76895--- a/include/linux/sunrpc/svcauth.h
76896+++ b/include/linux/sunrpc/svcauth.h
76897@@ -120,7 +120,7 @@ struct auth_ops {
76898 int (*release)(struct svc_rqst *rq);
76899 void (*domain_release)(struct auth_domain *);
76900 int (*set_client)(struct svc_rqst *rq);
76901-};
76902+} __do_const;
76903
76904 #define SVC_GARBAGE 1
76905 #define SVC_SYSERR 2
76906diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76907index a5ffd32..0935dea 100644
76908--- a/include/linux/swiotlb.h
76909+++ b/include/linux/swiotlb.h
76910@@ -60,7 +60,8 @@ extern void
76911
76912 extern void
76913 swiotlb_free_coherent(struct device *hwdev, size_t size,
76914- void *vaddr, dma_addr_t dma_handle);
76915+ void *vaddr, dma_addr_t dma_handle,
76916+ struct dma_attrs *attrs);
76917
76918 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76919 unsigned long offset, size_t size,
76920diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76921index 84662ec..5271947 100644
76922--- a/include/linux/syscalls.h
76923+++ b/include/linux/syscalls.h
76924@@ -97,8 +97,14 @@ struct sigaltstack;
76925 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76926
76927 #define __SC_DECL(t, a) t a
76928+#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))
76929 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76930-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76931+#define __SC_LONG(t, a) __typeof( \
76932+ __builtin_choose_expr( \
76933+ sizeof(t) > sizeof(int), \
76934+ (t) 0, \
76935+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76936+ )) a
76937 #define __SC_CAST(t, a) (t) a
76938 #define __SC_ARGS(t, a) a
76939 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76940@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76941 asmlinkage long sys_fsync(unsigned int fd);
76942 asmlinkage long sys_fdatasync(unsigned int fd);
76943 asmlinkage long sys_bdflush(int func, long data);
76944-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76945- char __user *type, unsigned long flags,
76946+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76947+ const char __user *type, unsigned long flags,
76948 void __user *data);
76949-asmlinkage long sys_umount(char __user *name, int flags);
76950-asmlinkage long sys_oldumount(char __user *name);
76951+asmlinkage long sys_umount(const char __user *name, int flags);
76952+asmlinkage long sys_oldumount(const char __user *name);
76953 asmlinkage long sys_truncate(const char __user *path, long length);
76954 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76955 asmlinkage long sys_stat(const char __user *filename,
76956@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76957 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76958 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76959 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76960- struct sockaddr __user *, int);
76961+ struct sockaddr __user *, int) __intentional_overflow(0);
76962 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76963 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76964 unsigned int vlen, unsigned flags);
76965diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76966index 27b3b0b..e093dd9 100644
76967--- a/include/linux/syscore_ops.h
76968+++ b/include/linux/syscore_ops.h
76969@@ -16,7 +16,7 @@ struct syscore_ops {
76970 int (*suspend)(void);
76971 void (*resume)(void);
76972 void (*shutdown)(void);
76973-};
76974+} __do_const;
76975
76976 extern void register_syscore_ops(struct syscore_ops *ops);
76977 extern void unregister_syscore_ops(struct syscore_ops *ops);
76978diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76979index 14a8ff2..af52bad 100644
76980--- a/include/linux/sysctl.h
76981+++ b/include/linux/sysctl.h
76982@@ -34,13 +34,13 @@ struct ctl_table_root;
76983 struct ctl_table_header;
76984 struct ctl_dir;
76985
76986-typedef struct ctl_table ctl_table;
76987-
76988 typedef int proc_handler (struct ctl_table *ctl, int write,
76989 void __user *buffer, size_t *lenp, loff_t *ppos);
76990
76991 extern int proc_dostring(struct ctl_table *, int,
76992 void __user *, size_t *, loff_t *);
76993+extern int proc_dostring_modpriv(struct ctl_table *, int,
76994+ void __user *, size_t *, loff_t *);
76995 extern int proc_dointvec(struct ctl_table *, int,
76996 void __user *, size_t *, loff_t *);
76997 extern int proc_dointvec_minmax(struct ctl_table *, int,
76998@@ -115,7 +115,9 @@ struct ctl_table
76999 struct ctl_table_poll *poll;
77000 void *extra1;
77001 void *extra2;
77002-};
77003+} __do_const;
77004+typedef struct ctl_table __no_const ctl_table_no_const;
77005+typedef struct ctl_table ctl_table;
77006
77007 struct ctl_node {
77008 struct rb_node node;
77009diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77010index 9e8a9b5..753de68 100644
77011--- a/include/linux/sysfs.h
77012+++ b/include/linux/sysfs.h
77013@@ -33,7 +33,8 @@ struct attribute {
77014 struct lock_class_key *key;
77015 struct lock_class_key skey;
77016 #endif
77017-};
77018+} __do_const;
77019+typedef struct attribute __no_const attribute_no_const;
77020
77021 /**
77022 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77023@@ -62,7 +63,8 @@ struct attribute_group {
77024 struct attribute *, int);
77025 struct attribute **attrs;
77026 struct bin_attribute **bin_attrs;
77027-};
77028+} __do_const;
77029+typedef struct attribute_group __no_const attribute_group_no_const;
77030
77031 /**
77032 * Use these macros to make defining attributes easier. See include/linux/device.h
77033@@ -123,7 +125,8 @@ struct bin_attribute {
77034 char *, loff_t, size_t);
77035 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77036 struct vm_area_struct *vma);
77037-};
77038+} __do_const;
77039+typedef struct bin_attribute __no_const bin_attribute_no_const;
77040
77041 /**
77042 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77043diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77044index 7faf933..9b85a0c 100644
77045--- a/include/linux/sysrq.h
77046+++ b/include/linux/sysrq.h
77047@@ -16,6 +16,7 @@
77048
77049 #include <linux/errno.h>
77050 #include <linux/types.h>
77051+#include <linux/compiler.h>
77052
77053 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77054 #define SYSRQ_DEFAULT_ENABLE 1
77055@@ -36,7 +37,7 @@ struct sysrq_key_op {
77056 char *help_msg;
77057 char *action_msg;
77058 int enable_mask;
77059-};
77060+} __do_const;
77061
77062 #ifdef CONFIG_MAGIC_SYSRQ
77063
77064diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77065index e7e0473..7989295 100644
77066--- a/include/linux/thread_info.h
77067+++ b/include/linux/thread_info.h
77068@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77069 #error "no set_restore_sigmask() provided and default one won't work"
77070 #endif
77071
77072+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77073+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77074+{
77075+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77076+ if (!__builtin_constant_p(n))
77077+#endif
77078+ __check_object_size(ptr, n, to_user);
77079+}
77080+
77081 #endif /* __KERNEL__ */
77082
77083 #endif /* _LINUX_THREAD_INFO_H */
77084diff --git a/include/linux/tty.h b/include/linux/tty.h
77085index 01ac30e..bf18a71 100644
77086--- a/include/linux/tty.h
77087+++ b/include/linux/tty.h
77088@@ -194,7 +194,7 @@ struct tty_port {
77089 const struct tty_port_operations *ops; /* Port operations */
77090 spinlock_t lock; /* Lock protecting tty field */
77091 int blocked_open; /* Waiting to open */
77092- int count; /* Usage count */
77093+ atomic_t count; /* Usage count */
77094 wait_queue_head_t open_wait; /* Open waiters */
77095 wait_queue_head_t close_wait; /* Close waiters */
77096 wait_queue_head_t delta_msr_wait; /* Modem status change */
77097@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77098 struct tty_struct *tty, struct file *filp);
77099 static inline int tty_port_users(struct tty_port *port)
77100 {
77101- return port->count + port->blocked_open;
77102+ return atomic_read(&port->count) + port->blocked_open;
77103 }
77104
77105 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77106diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77107index 756a609..b302dd6 100644
77108--- a/include/linux/tty_driver.h
77109+++ b/include/linux/tty_driver.h
77110@@ -285,7 +285,7 @@ struct tty_operations {
77111 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77112 #endif
77113 const struct file_operations *proc_fops;
77114-};
77115+} __do_const;
77116
77117 struct tty_driver {
77118 int magic; /* magic number for this structure */
77119diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77120index a1b0489..f02e17c 100644
77121--- a/include/linux/tty_ldisc.h
77122+++ b/include/linux/tty_ldisc.h
77123@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77124
77125 struct module *owner;
77126
77127- int refcount;
77128+ atomic_t refcount;
77129 };
77130
77131 struct tty_ldisc {
77132diff --git a/include/linux/types.h b/include/linux/types.h
77133index 4d118ba..c3ee9bf 100644
77134--- a/include/linux/types.h
77135+++ b/include/linux/types.h
77136@@ -176,10 +176,26 @@ typedef struct {
77137 int counter;
77138 } atomic_t;
77139
77140+#ifdef CONFIG_PAX_REFCOUNT
77141+typedef struct {
77142+ int counter;
77143+} atomic_unchecked_t;
77144+#else
77145+typedef atomic_t atomic_unchecked_t;
77146+#endif
77147+
77148 #ifdef CONFIG_64BIT
77149 typedef struct {
77150 long counter;
77151 } atomic64_t;
77152+
77153+#ifdef CONFIG_PAX_REFCOUNT
77154+typedef struct {
77155+ long counter;
77156+} atomic64_unchecked_t;
77157+#else
77158+typedef atomic64_t atomic64_unchecked_t;
77159+#endif
77160 #endif
77161
77162 struct list_head {
77163diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77164index 5ca0951..ab496a5 100644
77165--- a/include/linux/uaccess.h
77166+++ b/include/linux/uaccess.h
77167@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77168 long ret; \
77169 mm_segment_t old_fs = get_fs(); \
77170 \
77171- set_fs(KERNEL_DS); \
77172 pagefault_disable(); \
77173- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77174- pagefault_enable(); \
77175+ set_fs(KERNEL_DS); \
77176+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77177 set_fs(old_fs); \
77178+ pagefault_enable(); \
77179 ret; \
77180 })
77181
77182diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77183index 8e522cbc..aa8572d 100644
77184--- a/include/linux/uidgid.h
77185+++ b/include/linux/uidgid.h
77186@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77187
77188 #endif /* CONFIG_USER_NS */
77189
77190+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77191+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77192+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77193+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77194+
77195 #endif /* _LINUX_UIDGID_H */
77196diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77197index 99c1b4d..562e6f3 100644
77198--- a/include/linux/unaligned/access_ok.h
77199+++ b/include/linux/unaligned/access_ok.h
77200@@ -4,34 +4,34 @@
77201 #include <linux/kernel.h>
77202 #include <asm/byteorder.h>
77203
77204-static inline u16 get_unaligned_le16(const void *p)
77205+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77206 {
77207- return le16_to_cpup((__le16 *)p);
77208+ return le16_to_cpup((const __le16 *)p);
77209 }
77210
77211-static inline u32 get_unaligned_le32(const void *p)
77212+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77213 {
77214- return le32_to_cpup((__le32 *)p);
77215+ return le32_to_cpup((const __le32 *)p);
77216 }
77217
77218-static inline u64 get_unaligned_le64(const void *p)
77219+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77220 {
77221- return le64_to_cpup((__le64 *)p);
77222+ return le64_to_cpup((const __le64 *)p);
77223 }
77224
77225-static inline u16 get_unaligned_be16(const void *p)
77226+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77227 {
77228- return be16_to_cpup((__be16 *)p);
77229+ return be16_to_cpup((const __be16 *)p);
77230 }
77231
77232-static inline u32 get_unaligned_be32(const void *p)
77233+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77234 {
77235- return be32_to_cpup((__be32 *)p);
77236+ return be32_to_cpup((const __be32 *)p);
77237 }
77238
77239-static inline u64 get_unaligned_be64(const void *p)
77240+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77241 {
77242- return be64_to_cpup((__be64 *)p);
77243+ return be64_to_cpup((const __be64 *)p);
77244 }
77245
77246 static inline void put_unaligned_le16(u16 val, void *p)
77247diff --git a/include/linux/usb.h b/include/linux/usb.h
77248index 0eec268..4496526 100644
77249--- a/include/linux/usb.h
77250+++ b/include/linux/usb.h
77251@@ -560,7 +560,7 @@ struct usb_device {
77252 int maxchild;
77253
77254 u32 quirks;
77255- atomic_t urbnum;
77256+ atomic_unchecked_t urbnum;
77257
77258 unsigned long active_duration;
77259
77260@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77261
77262 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77263 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77264- void *data, __u16 size, int timeout);
77265+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77266 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77267 void *data, int len, int *actual_length, int timeout);
77268 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77269diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77270index e452ba6..78f8e80 100644
77271--- a/include/linux/usb/renesas_usbhs.h
77272+++ b/include/linux/usb/renesas_usbhs.h
77273@@ -39,7 +39,7 @@ enum {
77274 */
77275 struct renesas_usbhs_driver_callback {
77276 int (*notify_hotplug)(struct platform_device *pdev);
77277-};
77278+} __no_const;
77279
77280 /*
77281 * callback functions for platform
77282diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77283index 6f8fbcf..8259001 100644
77284--- a/include/linux/vermagic.h
77285+++ b/include/linux/vermagic.h
77286@@ -25,9 +25,35 @@
77287 #define MODULE_ARCH_VERMAGIC ""
77288 #endif
77289
77290+#ifdef CONFIG_PAX_REFCOUNT
77291+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77292+#else
77293+#define MODULE_PAX_REFCOUNT ""
77294+#endif
77295+
77296+#ifdef CONSTIFY_PLUGIN
77297+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77298+#else
77299+#define MODULE_CONSTIFY_PLUGIN ""
77300+#endif
77301+
77302+#ifdef STACKLEAK_PLUGIN
77303+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77304+#else
77305+#define MODULE_STACKLEAK_PLUGIN ""
77306+#endif
77307+
77308+#ifdef CONFIG_GRKERNSEC
77309+#define MODULE_GRSEC "GRSEC "
77310+#else
77311+#define MODULE_GRSEC ""
77312+#endif
77313+
77314 #define VERMAGIC_STRING \
77315 UTS_RELEASE " " \
77316 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77317 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77318- MODULE_ARCH_VERMAGIC
77319+ MODULE_ARCH_VERMAGIC \
77320+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77321+ MODULE_GRSEC
77322
77323diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77324index 4b8a891..c20e936 100644
77325--- a/include/linux/vmalloc.h
77326+++ b/include/linux/vmalloc.h
77327@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77328 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77329 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77330 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77331+
77332+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77333+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77334+#endif
77335+
77336 /* bits [20..32] reserved for arch specific ioremap internals */
77337
77338 /*
77339@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77340 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77341 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77342 unsigned long start, unsigned long end, gfp_t gfp_mask,
77343- pgprot_t prot, int node, const void *caller);
77344+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77345 extern void vfree(const void *addr);
77346
77347 extern void *vmap(struct page **pages, unsigned int count,
77348@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77349 extern void free_vm_area(struct vm_struct *area);
77350
77351 /* for /dev/kmem */
77352-extern long vread(char *buf, char *addr, unsigned long count);
77353-extern long vwrite(char *buf, char *addr, unsigned long count);
77354+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77355+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77356
77357 /*
77358 * Internals. Dont't use..
77359diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77360index c586679..f06b389 100644
77361--- a/include/linux/vmstat.h
77362+++ b/include/linux/vmstat.h
77363@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77364 /*
77365 * Zone based page accounting with per cpu differentials.
77366 */
77367-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77368+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77369
77370 static inline void zone_page_state_add(long x, struct zone *zone,
77371 enum zone_stat_item item)
77372 {
77373- atomic_long_add(x, &zone->vm_stat[item]);
77374- atomic_long_add(x, &vm_stat[item]);
77375+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77376+ atomic_long_add_unchecked(x, &vm_stat[item]);
77377 }
77378
77379 static inline unsigned long global_page_state(enum zone_stat_item item)
77380 {
77381- long x = atomic_long_read(&vm_stat[item]);
77382+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77383 #ifdef CONFIG_SMP
77384 if (x < 0)
77385 x = 0;
77386@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77387 static inline unsigned long zone_page_state(struct zone *zone,
77388 enum zone_stat_item item)
77389 {
77390- long x = atomic_long_read(&zone->vm_stat[item]);
77391+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77392 #ifdef CONFIG_SMP
77393 if (x < 0)
77394 x = 0;
77395@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77396 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77397 enum zone_stat_item item)
77398 {
77399- long x = atomic_long_read(&zone->vm_stat[item]);
77400+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77401
77402 #ifdef CONFIG_SMP
77403 int cpu;
77404@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77405
77406 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77407 {
77408- atomic_long_inc(&zone->vm_stat[item]);
77409- atomic_long_inc(&vm_stat[item]);
77410+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77411+ atomic_long_inc_unchecked(&vm_stat[item]);
77412 }
77413
77414 static inline void __inc_zone_page_state(struct page *page,
77415@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77416
77417 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77418 {
77419- atomic_long_dec(&zone->vm_stat[item]);
77420- atomic_long_dec(&vm_stat[item]);
77421+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77422+ atomic_long_dec_unchecked(&vm_stat[item]);
77423 }
77424
77425 static inline void __dec_zone_page_state(struct page *page,
77426diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77427index fdbafc6..49dfe4f 100644
77428--- a/include/linux/xattr.h
77429+++ b/include/linux/xattr.h
77430@@ -28,7 +28,7 @@ struct xattr_handler {
77431 size_t size, int handler_flags);
77432 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77433 size_t size, int flags, int handler_flags);
77434-};
77435+} __do_const;
77436
77437 struct xattr {
77438 char *name;
77439@@ -37,6 +37,9 @@ struct xattr {
77440 };
77441
77442 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77443+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77444+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77445+#endif
77446 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77447 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77448 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77449diff --git a/include/linux/yam.h b/include/linux/yam.h
77450index 7fe2822..512cdc2 100644
77451--- a/include/linux/yam.h
77452+++ b/include/linux/yam.h
77453@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77454
77455 struct yamdrv_ioctl_mcs {
77456 int cmd;
77457- int bitrate;
77458+ unsigned int bitrate;
77459 unsigned char bits[YAM_FPGA_SIZE];
77460 };
77461diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77462index 9c5a6b4..09c9438 100644
77463--- a/include/linux/zlib.h
77464+++ b/include/linux/zlib.h
77465@@ -31,6 +31,7 @@
77466 #define _ZLIB_H
77467
77468 #include <linux/zconf.h>
77469+#include <linux/compiler.h>
77470
77471 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77472 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77473@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77474
77475 /* basic functions */
77476
77477-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77478+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77479 /*
77480 Returns the number of bytes that needs to be allocated for a per-
77481 stream workspace with the specified parameters. A pointer to this
77482diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77483index c768c9f..bdcaa5a 100644
77484--- a/include/media/v4l2-dev.h
77485+++ b/include/media/v4l2-dev.h
77486@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77487 int (*mmap) (struct file *, struct vm_area_struct *);
77488 int (*open) (struct file *);
77489 int (*release) (struct file *);
77490-};
77491+} __do_const;
77492
77493 /*
77494 * Newer version of video_device, handled by videodev2.c
77495diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77496index c9b1593..a572459 100644
77497--- a/include/media/v4l2-device.h
77498+++ b/include/media/v4l2-device.h
77499@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77500 this function returns 0. If the name ends with a digit (e.g. cx18),
77501 then the name will be set to cx18-0 since cx180 looks really odd. */
77502 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77503- atomic_t *instance);
77504+ atomic_unchecked_t *instance);
77505
77506 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77507 Since the parent disappears this ensures that v4l2_dev doesn't have an
77508diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77509index d9fa68f..45c88d1 100644
77510--- a/include/net/9p/transport.h
77511+++ b/include/net/9p/transport.h
77512@@ -63,7 +63,7 @@ struct p9_trans_module {
77513 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77514 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77515 char *, char *, int , int, int, int);
77516-};
77517+} __do_const;
77518
77519 void v9fs_register_trans(struct p9_trans_module *m);
77520 void v9fs_unregister_trans(struct p9_trans_module *m);
77521diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77522index 1a966af..2767cf6 100644
77523--- a/include/net/bluetooth/l2cap.h
77524+++ b/include/net/bluetooth/l2cap.h
77525@@ -551,7 +551,7 @@ struct l2cap_ops {
77526 void (*defer) (struct l2cap_chan *chan);
77527 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77528 unsigned long len, int nb);
77529-};
77530+} __do_const;
77531
77532 struct l2cap_conn {
77533 struct hci_conn *hcon;
77534diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77535index f2ae33d..c457cf0 100644
77536--- a/include/net/caif/cfctrl.h
77537+++ b/include/net/caif/cfctrl.h
77538@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77539 void (*radioset_rsp)(void);
77540 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77541 struct cflayer *client_layer);
77542-};
77543+} __no_const;
77544
77545 /* Link Setup Parameters for CAIF-Links. */
77546 struct cfctrl_link_param {
77547@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77548 struct cfctrl {
77549 struct cfsrvl serv;
77550 struct cfctrl_rsp res;
77551- atomic_t req_seq_no;
77552- atomic_t rsp_seq_no;
77553+ atomic_unchecked_t req_seq_no;
77554+ atomic_unchecked_t rsp_seq_no;
77555 struct list_head list;
77556 /* Protects from simultaneous access to first_req list */
77557 spinlock_t info_list_lock;
77558diff --git a/include/net/flow.h b/include/net/flow.h
77559index 628e11b..4c475df 100644
77560--- a/include/net/flow.h
77561+++ b/include/net/flow.h
77562@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77563
77564 extern void flow_cache_flush(void);
77565 extern void flow_cache_flush_deferred(void);
77566-extern atomic_t flow_cache_genid;
77567+extern atomic_unchecked_t flow_cache_genid;
77568
77569 #endif
77570diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77571index 8e0b6c8..73cf605 100644
77572--- a/include/net/genetlink.h
77573+++ b/include/net/genetlink.h
77574@@ -120,7 +120,7 @@ struct genl_ops {
77575 struct netlink_callback *cb);
77576 int (*done)(struct netlink_callback *cb);
77577 struct list_head ops_list;
77578-};
77579+} __do_const;
77580
77581 extern int __genl_register_family(struct genl_family *family);
77582
77583diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77584index 734d9b5..48a9a4b 100644
77585--- a/include/net/gro_cells.h
77586+++ b/include/net/gro_cells.h
77587@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77588 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77589
77590 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77591- atomic_long_inc(&dev->rx_dropped);
77592+ atomic_long_inc_unchecked(&dev->rx_dropped);
77593 kfree_skb(skb);
77594 return;
77595 }
77596diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77597index de2c785..0588a6b 100644
77598--- a/include/net/inet_connection_sock.h
77599+++ b/include/net/inet_connection_sock.h
77600@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77601 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77602 int (*bind_conflict)(const struct sock *sk,
77603 const struct inet_bind_bucket *tb, bool relax);
77604-};
77605+} __do_const;
77606
77607 /** inet_connection_sock - INET connection oriented sock
77608 *
77609diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77610index 53f464d..0bd0b49 100644
77611--- a/include/net/inetpeer.h
77612+++ b/include/net/inetpeer.h
77613@@ -47,8 +47,8 @@ struct inet_peer {
77614 */
77615 union {
77616 struct {
77617- atomic_t rid; /* Frag reception counter */
77618- atomic_t ip_id_count; /* IP ID for the next packet */
77619+ atomic_unchecked_t rid; /* Frag reception counter */
77620+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77621 };
77622 struct rcu_head rcu;
77623 struct inet_peer *gc_next;
77624@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77625 /* can be called with or without local BH being disabled */
77626 static inline int inet_getid(struct inet_peer *p, int more)
77627 {
77628- int old, new;
77629+ int id;
77630 more++;
77631 inet_peer_refcheck(p);
77632- do {
77633- old = atomic_read(&p->ip_id_count);
77634- new = old + more;
77635- if (!new)
77636- new = 1;
77637- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77638- return new;
77639+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77640+ if (!id)
77641+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77642+ return id;
77643 }
77644
77645 #endif /* _NET_INETPEER_H */
77646diff --git a/include/net/ip.h b/include/net/ip.h
77647index edfa591..a643b82 100644
77648--- a/include/net/ip.h
77649+++ b/include/net/ip.h
77650@@ -202,7 +202,7 @@ extern struct local_ports {
77651 } sysctl_local_ports;
77652 extern void inet_get_local_port_range(int *low, int *high);
77653
77654-extern unsigned long *sysctl_local_reserved_ports;
77655+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77656 static inline int inet_is_reserved_local_port(int port)
77657 {
77658 return test_bit(port, sysctl_local_reserved_ports);
77659diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77660index cbf2be3..3683f6d 100644
77661--- a/include/net/ip_fib.h
77662+++ b/include/net/ip_fib.h
77663@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77664
77665 #define FIB_RES_SADDR(net, res) \
77666 ((FIB_RES_NH(res).nh_saddr_genid == \
77667- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77668+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77669 FIB_RES_NH(res).nh_saddr : \
77670 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77671 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77672diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77673index f0d70f0..185f15b 100644
77674--- a/include/net/ip_vs.h
77675+++ b/include/net/ip_vs.h
77676@@ -588,7 +588,7 @@ struct ip_vs_conn {
77677 struct ip_vs_conn *control; /* Master control connection */
77678 atomic_t n_control; /* Number of controlled ones */
77679 struct ip_vs_dest *dest; /* real server */
77680- atomic_t in_pkts; /* incoming packet counter */
77681+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77682
77683 /* packet transmitter for different forwarding methods. If it
77684 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77685@@ -737,7 +737,7 @@ struct ip_vs_dest {
77686 __be16 port; /* port number of the server */
77687 union nf_inet_addr addr; /* IP address of the server */
77688 volatile unsigned int flags; /* dest status flags */
77689- atomic_t conn_flags; /* flags to copy to conn */
77690+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77691 atomic_t weight; /* server weight */
77692
77693 atomic_t refcnt; /* reference counter */
77694@@ -993,11 +993,11 @@ struct netns_ipvs {
77695 /* ip_vs_lblc */
77696 int sysctl_lblc_expiration;
77697 struct ctl_table_header *lblc_ctl_header;
77698- struct ctl_table *lblc_ctl_table;
77699+ ctl_table_no_const *lblc_ctl_table;
77700 /* ip_vs_lblcr */
77701 int sysctl_lblcr_expiration;
77702 struct ctl_table_header *lblcr_ctl_header;
77703- struct ctl_table *lblcr_ctl_table;
77704+ ctl_table_no_const *lblcr_ctl_table;
77705 /* ip_vs_est */
77706 struct list_head est_list; /* estimator list */
77707 spinlock_t est_lock;
77708diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77709index 80ffde3..968b0f4 100644
77710--- a/include/net/irda/ircomm_tty.h
77711+++ b/include/net/irda/ircomm_tty.h
77712@@ -35,6 +35,7 @@
77713 #include <linux/termios.h>
77714 #include <linux/timer.h>
77715 #include <linux/tty.h> /* struct tty_struct */
77716+#include <asm/local.h>
77717
77718 #include <net/irda/irias_object.h>
77719 #include <net/irda/ircomm_core.h>
77720diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77721index 714cc9a..ea05f3e 100644
77722--- a/include/net/iucv/af_iucv.h
77723+++ b/include/net/iucv/af_iucv.h
77724@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77725 struct iucv_sock_list {
77726 struct hlist_head head;
77727 rwlock_t lock;
77728- atomic_t autobind_name;
77729+ atomic_unchecked_t autobind_name;
77730 };
77731
77732 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77733diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77734index df83f69..9b640b8 100644
77735--- a/include/net/llc_c_ac.h
77736+++ b/include/net/llc_c_ac.h
77737@@ -87,7 +87,7 @@
77738 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77739 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77740
77741-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77742+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77743
77744 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77745 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77746diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77747index 6ca3113..f8026dd 100644
77748--- a/include/net/llc_c_ev.h
77749+++ b/include/net/llc_c_ev.h
77750@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77751 return (struct llc_conn_state_ev *)skb->cb;
77752 }
77753
77754-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77755-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77756+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77757+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77758
77759 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77760 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77761diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77762index 0e79cfb..f46db31 100644
77763--- a/include/net/llc_c_st.h
77764+++ b/include/net/llc_c_st.h
77765@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77766 u8 next_state;
77767 llc_conn_ev_qfyr_t *ev_qualifiers;
77768 llc_conn_action_t *ev_actions;
77769-};
77770+} __do_const;
77771
77772 struct llc_conn_state {
77773 u8 current_state;
77774diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77775index 37a3bbd..55a4241 100644
77776--- a/include/net/llc_s_ac.h
77777+++ b/include/net/llc_s_ac.h
77778@@ -23,7 +23,7 @@
77779 #define SAP_ACT_TEST_IND 9
77780
77781 /* All action functions must look like this */
77782-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77783+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77784
77785 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77786 struct sk_buff *skb);
77787diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77788index 567c681..cd73ac0 100644
77789--- a/include/net/llc_s_st.h
77790+++ b/include/net/llc_s_st.h
77791@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77792 llc_sap_ev_t ev;
77793 u8 next_state;
77794 llc_sap_action_t *ev_actions;
77795-};
77796+} __do_const;
77797
77798 struct llc_sap_state {
77799 u8 curr_state;
77800diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77801index 551ba6a..11c99c1 100644
77802--- a/include/net/mac80211.h
77803+++ b/include/net/mac80211.h
77804@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77805 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77806 struct dentry *dir);
77807 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77808-};
77809+} __do_const;
77810
77811 static inline int rate_supported(struct ieee80211_sta *sta,
77812 enum ieee80211_band band,
77813diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77814index 7e748ad..5c6229b 100644
77815--- a/include/net/neighbour.h
77816+++ b/include/net/neighbour.h
77817@@ -123,7 +123,7 @@ struct neigh_ops {
77818 void (*error_report)(struct neighbour *, struct sk_buff *);
77819 int (*output)(struct neighbour *, struct sk_buff *);
77820 int (*connected_output)(struct neighbour *, struct sk_buff *);
77821-};
77822+} __do_const;
77823
77824 struct pneigh_entry {
77825 struct pneigh_entry *next;
77826diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77827index 84e37b1..8eba19a 100644
77828--- a/include/net/net_namespace.h
77829+++ b/include/net/net_namespace.h
77830@@ -119,8 +119,8 @@ struct net {
77831 struct netns_ipvs *ipvs;
77832 #endif
77833 struct sock *diag_nlsk;
77834- atomic_t rt_genid;
77835- atomic_t fnhe_genid;
77836+ atomic_unchecked_t rt_genid;
77837+ atomic_unchecked_t fnhe_genid;
77838 };
77839
77840 /*
77841@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77842 #define __net_init __init
77843 #define __net_exit __exit_refok
77844 #define __net_initdata __initdata
77845+#ifdef CONSTIFY_PLUGIN
77846 #define __net_initconst __initconst
77847+#else
77848+#define __net_initconst __initdata
77849+#endif
77850 #endif
77851
77852 struct pernet_operations {
77853@@ -287,7 +291,7 @@ struct pernet_operations {
77854 void (*exit_batch)(struct list_head *net_exit_list);
77855 int *id;
77856 size_t size;
77857-};
77858+} __do_const;
77859
77860 /*
77861 * Use these carefully. If you implement a network device and it
77862@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77863
77864 static inline int rt_genid(struct net *net)
77865 {
77866- return atomic_read(&net->rt_genid);
77867+ return atomic_read_unchecked(&net->rt_genid);
77868 }
77869
77870 static inline void rt_genid_bump(struct net *net)
77871 {
77872- atomic_inc(&net->rt_genid);
77873+ atomic_inc_unchecked(&net->rt_genid);
77874 }
77875
77876 static inline int fnhe_genid(struct net *net)
77877 {
77878- return atomic_read(&net->fnhe_genid);
77879+ return atomic_read_unchecked(&net->fnhe_genid);
77880 }
77881
77882 static inline void fnhe_genid_bump(struct net *net)
77883 {
77884- atomic_inc(&net->fnhe_genid);
77885+ atomic_inc_unchecked(&net->fnhe_genid);
77886 }
77887
77888 #endif /* __NET_NET_NAMESPACE_H */
77889diff --git a/include/net/netdma.h b/include/net/netdma.h
77890index 8ba8ce2..99b7fff 100644
77891--- a/include/net/netdma.h
77892+++ b/include/net/netdma.h
77893@@ -24,7 +24,7 @@
77894 #include <linux/dmaengine.h>
77895 #include <linux/skbuff.h>
77896
77897-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77898+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77899 struct sk_buff *skb, int offset, struct iovec *to,
77900 size_t len, struct dma_pinned_list *pinned_list);
77901
77902diff --git a/include/net/netlink.h b/include/net/netlink.h
77903index 9690b0f..87aded7 100644
77904--- a/include/net/netlink.h
77905+++ b/include/net/netlink.h
77906@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77907 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77908 {
77909 if (mark)
77910- skb_trim(skb, (unsigned char *) mark - skb->data);
77911+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77912 }
77913
77914 /**
77915diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77916index c9c0c53..53f24c3 100644
77917--- a/include/net/netns/conntrack.h
77918+++ b/include/net/netns/conntrack.h
77919@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77920 struct nf_proto_net {
77921 #ifdef CONFIG_SYSCTL
77922 struct ctl_table_header *ctl_table_header;
77923- struct ctl_table *ctl_table;
77924+ ctl_table_no_const *ctl_table;
77925 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77926 struct ctl_table_header *ctl_compat_header;
77927- struct ctl_table *ctl_compat_table;
77928+ ctl_table_no_const *ctl_compat_table;
77929 #endif
77930 #endif
77931 unsigned int users;
77932@@ -58,7 +58,7 @@ struct nf_ip_net {
77933 struct nf_icmp_net icmpv6;
77934 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77935 struct ctl_table_header *ctl_table_header;
77936- struct ctl_table *ctl_table;
77937+ ctl_table_no_const *ctl_table;
77938 #endif
77939 };
77940
77941diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77942index 2ba9de8..47bd6c7 100644
77943--- a/include/net/netns/ipv4.h
77944+++ b/include/net/netns/ipv4.h
77945@@ -67,7 +67,7 @@ struct netns_ipv4 {
77946 kgid_t sysctl_ping_group_range[2];
77947 long sysctl_tcp_mem[3];
77948
77949- atomic_t dev_addr_genid;
77950+ atomic_unchecked_t dev_addr_genid;
77951
77952 #ifdef CONFIG_IP_MROUTE
77953 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77954diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77955index 005e2c2..023d340 100644
77956--- a/include/net/netns/ipv6.h
77957+++ b/include/net/netns/ipv6.h
77958@@ -71,7 +71,7 @@ struct netns_ipv6 {
77959 struct fib_rules_ops *mr6_rules_ops;
77960 #endif
77961 #endif
77962- atomic_t dev_addr_genid;
77963+ atomic_unchecked_t dev_addr_genid;
77964 };
77965
77966 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77967diff --git a/include/net/ping.h b/include/net/ping.h
77968index 5db0224..0d65365 100644
77969--- a/include/net/ping.h
77970+++ b/include/net/ping.h
77971@@ -55,7 +55,7 @@ struct ping_iter_state {
77972 extern struct proto ping_prot;
77973 extern struct ping_table ping_table;
77974 #if IS_ENABLED(CONFIG_IPV6)
77975-extern struct pingv6_ops pingv6_ops;
77976+extern struct pingv6_ops *pingv6_ops;
77977 #endif
77978
77979 struct pingfakehdr {
77980diff --git a/include/net/protocol.h b/include/net/protocol.h
77981index 047c047..b9dad15 100644
77982--- a/include/net/protocol.h
77983+++ b/include/net/protocol.h
77984@@ -44,7 +44,7 @@ struct net_protocol {
77985 void (*err_handler)(struct sk_buff *skb, u32 info);
77986 unsigned int no_policy:1,
77987 netns_ok:1;
77988-};
77989+} __do_const;
77990
77991 #if IS_ENABLED(CONFIG_IPV6)
77992 struct inet6_protocol {
77993@@ -57,7 +57,7 @@ struct inet6_protocol {
77994 u8 type, u8 code, int offset,
77995 __be32 info);
77996 unsigned int flags; /* INET6_PROTO_xxx */
77997-};
77998+} __do_const;
77999
78000 #define INET6_PROTO_NOPOLICY 0x1
78001 #define INET6_PROTO_FINAL 0x2
78002diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78003index 7026648..584cc8c 100644
78004--- a/include/net/rtnetlink.h
78005+++ b/include/net/rtnetlink.h
78006@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78007 const struct net_device *dev);
78008 unsigned int (*get_num_tx_queues)(void);
78009 unsigned int (*get_num_rx_queues)(void);
78010-};
78011+} __do_const;
78012
78013 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78014 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78015diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78016index 2a82d13..62a31c2 100644
78017--- a/include/net/sctp/sm.h
78018+++ b/include/net/sctp/sm.h
78019@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78020 typedef struct {
78021 sctp_state_fn_t *fn;
78022 const char *name;
78023-} sctp_sm_table_entry_t;
78024+} __do_const sctp_sm_table_entry_t;
78025
78026 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78027 * currently in use.
78028@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78029 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78030
78031 /* Extern declarations for major data structures. */
78032-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78033+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78034
78035
78036 /* Get the size of a DATA chunk payload. */
78037diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78038index e745c92..3641448 100644
78039--- a/include/net/sctp/structs.h
78040+++ b/include/net/sctp/structs.h
78041@@ -516,7 +516,7 @@ struct sctp_pf {
78042 struct sctp_association *asoc);
78043 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78044 struct sctp_af *af;
78045-};
78046+} __do_const;
78047
78048
78049 /* Structure to track chunk fragments that have been acked, but peer
78050diff --git a/include/net/sock.h b/include/net/sock.h
78051index 04e148f..3b1c7e0 100644
78052--- a/include/net/sock.h
78053+++ b/include/net/sock.h
78054@@ -332,7 +332,7 @@ struct sock {
78055 unsigned int sk_napi_id;
78056 unsigned int sk_ll_usec;
78057 #endif
78058- atomic_t sk_drops;
78059+ atomic_unchecked_t sk_drops;
78060 int sk_rcvbuf;
78061
78062 struct sk_filter __rcu *sk_filter;
78063@@ -1805,7 +1805,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78064 }
78065
78066 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78067- char __user *from, char *to,
78068+ char __user *from, unsigned char *to,
78069 int copy, int offset)
78070 {
78071 if (skb->ip_summed == CHECKSUM_NONE) {
78072@@ -2067,7 +2067,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78073 }
78074 }
78075
78076-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78077+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78078
78079 /**
78080 * sk_page_frag - return an appropriate page_frag
78081diff --git a/include/net/tcp.h b/include/net/tcp.h
78082index 46cb8a4..32b7b4a 100644
78083--- a/include/net/tcp.h
78084+++ b/include/net/tcp.h
78085@@ -522,7 +522,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78086 extern void tcp_xmit_retransmit_queue(struct sock *);
78087 extern void tcp_simple_retransmit(struct sock *);
78088 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78089-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78090+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78091
78092 extern void tcp_send_probe0(struct sock *);
78093 extern void tcp_send_partial(struct sock *);
78094@@ -695,8 +695,8 @@ struct tcp_skb_cb {
78095 struct inet6_skb_parm h6;
78096 #endif
78097 } header; /* For incoming frames */
78098- __u32 seq; /* Starting sequence number */
78099- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78100+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78101+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78102 __u32 when; /* used to compute rtt's */
78103 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78104
78105@@ -710,7 +710,7 @@ struct tcp_skb_cb {
78106
78107 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78108 /* 1 byte hole */
78109- __u32 ack_seq; /* Sequence number ACK'd */
78110+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78111 };
78112
78113 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78114diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78115index e823786..53b0608 100644
78116--- a/include/net/xfrm.h
78117+++ b/include/net/xfrm.h
78118@@ -287,7 +287,6 @@ struct xfrm_dst;
78119 struct xfrm_policy_afinfo {
78120 unsigned short family;
78121 struct dst_ops *dst_ops;
78122- void (*garbage_collect)(struct net *net);
78123 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78124 const xfrm_address_t *saddr,
78125 const xfrm_address_t *daddr);
78126@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78127 struct net_device *dev,
78128 const struct flowi *fl);
78129 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78130-};
78131+} __do_const;
78132
78133 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78134 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78135@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78136 int (*transport_finish)(struct sk_buff *skb,
78137 int async);
78138 void (*local_error)(struct sk_buff *skb, u32 mtu);
78139-};
78140+} __do_const;
78141
78142 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78143 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78144@@ -427,7 +426,7 @@ struct xfrm_mode {
78145 struct module *owner;
78146 unsigned int encap;
78147 int flags;
78148-};
78149+} __do_const;
78150
78151 /* Flags for xfrm_mode. */
78152 enum {
78153@@ -524,7 +523,7 @@ struct xfrm_policy {
78154 struct timer_list timer;
78155
78156 struct flow_cache_object flo;
78157- atomic_t genid;
78158+ atomic_unchecked_t genid;
78159 u32 priority;
78160 u32 index;
78161 struct xfrm_mark mark;
78162@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78163 }
78164
78165 extern void xfrm_garbage_collect(struct net *net);
78166+extern void xfrm_garbage_collect_deferred(struct net *net);
78167
78168 #else
78169
78170@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78171 static inline void xfrm_garbage_collect(struct net *net)
78172 {
78173 }
78174+static inline void xfrm_garbage_collect_deferred(struct net *net)
78175+{
78176+}
78177 #endif
78178
78179 static __inline__
78180diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78181index 1a046b1..ee0bef0 100644
78182--- a/include/rdma/iw_cm.h
78183+++ b/include/rdma/iw_cm.h
78184@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78185 int backlog);
78186
78187 int (*destroy_listen)(struct iw_cm_id *cm_id);
78188-};
78189+} __no_const;
78190
78191 /**
78192 * iw_create_cm_id - Create an IW CM identifier.
78193diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78194index e1379b4..67eafbe 100644
78195--- a/include/scsi/libfc.h
78196+++ b/include/scsi/libfc.h
78197@@ -762,6 +762,7 @@ struct libfc_function_template {
78198 */
78199 void (*disc_stop_final) (struct fc_lport *);
78200 };
78201+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78202
78203 /**
78204 * struct fc_disc - Discovery context
78205@@ -866,7 +867,7 @@ struct fc_lport {
78206 struct fc_vport *vport;
78207
78208 /* Operational Information */
78209- struct libfc_function_template tt;
78210+ libfc_function_template_no_const tt;
78211 u8 link_up;
78212 u8 qfull;
78213 enum fc_lport_state state;
78214diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78215index a44954c..5da04b2 100644
78216--- a/include/scsi/scsi_device.h
78217+++ b/include/scsi/scsi_device.h
78218@@ -172,9 +172,9 @@ struct scsi_device {
78219 unsigned int max_device_blocked; /* what device_blocked counts down from */
78220 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78221
78222- atomic_t iorequest_cnt;
78223- atomic_t iodone_cnt;
78224- atomic_t ioerr_cnt;
78225+ atomic_unchecked_t iorequest_cnt;
78226+ atomic_unchecked_t iodone_cnt;
78227+ atomic_unchecked_t ioerr_cnt;
78228
78229 struct device sdev_gendev,
78230 sdev_dev;
78231diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78232index b797e8f..8e2c3aa 100644
78233--- a/include/scsi/scsi_transport_fc.h
78234+++ b/include/scsi/scsi_transport_fc.h
78235@@ -751,7 +751,8 @@ struct fc_function_template {
78236 unsigned long show_host_system_hostname:1;
78237
78238 unsigned long disable_target_scan:1;
78239-};
78240+} __do_const;
78241+typedef struct fc_function_template __no_const fc_function_template_no_const;
78242
78243
78244 /**
78245diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78246index 9031a26..750d592 100644
78247--- a/include/sound/compress_driver.h
78248+++ b/include/sound/compress_driver.h
78249@@ -128,7 +128,7 @@ struct snd_compr_ops {
78250 struct snd_compr_caps *caps);
78251 int (*get_codec_caps) (struct snd_compr_stream *stream,
78252 struct snd_compr_codec_caps *codec);
78253-};
78254+} __no_const;
78255
78256 /**
78257 * struct snd_compr: Compressed device
78258diff --git a/include/sound/soc.h b/include/sound/soc.h
78259index 6eabee7..58afb50 100644
78260--- a/include/sound/soc.h
78261+++ b/include/sound/soc.h
78262@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78263 /* probe ordering - for components with runtime dependencies */
78264 int probe_order;
78265 int remove_order;
78266-};
78267+} __do_const;
78268
78269 /* SoC platform interface */
78270 struct snd_soc_platform_driver {
78271@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78272 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78273 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78274 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78275-};
78276+} __do_const;
78277
78278 struct snd_soc_platform {
78279 const char *name;
78280diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78281index e34fc90..ecefa2c 100644
78282--- a/include/target/target_core_base.h
78283+++ b/include/target/target_core_base.h
78284@@ -643,7 +643,7 @@ struct se_device {
78285 spinlock_t stats_lock;
78286 /* Active commands on this virtual SE device */
78287 atomic_t simple_cmds;
78288- atomic_t dev_ordered_id;
78289+ atomic_unchecked_t dev_ordered_id;
78290 atomic_t dev_ordered_sync;
78291 atomic_t dev_qf_count;
78292 int export_count;
78293diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78294new file mode 100644
78295index 0000000..fb634b7
78296--- /dev/null
78297+++ b/include/trace/events/fs.h
78298@@ -0,0 +1,53 @@
78299+#undef TRACE_SYSTEM
78300+#define TRACE_SYSTEM fs
78301+
78302+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78303+#define _TRACE_FS_H
78304+
78305+#include <linux/fs.h>
78306+#include <linux/tracepoint.h>
78307+
78308+TRACE_EVENT(do_sys_open,
78309+
78310+ TP_PROTO(const char *filename, int flags, int mode),
78311+
78312+ TP_ARGS(filename, flags, mode),
78313+
78314+ TP_STRUCT__entry(
78315+ __string( filename, filename )
78316+ __field( int, flags )
78317+ __field( int, mode )
78318+ ),
78319+
78320+ TP_fast_assign(
78321+ __assign_str(filename, filename);
78322+ __entry->flags = flags;
78323+ __entry->mode = mode;
78324+ ),
78325+
78326+ TP_printk("\"%s\" %x %o",
78327+ __get_str(filename), __entry->flags, __entry->mode)
78328+);
78329+
78330+TRACE_EVENT(open_exec,
78331+
78332+ TP_PROTO(const char *filename),
78333+
78334+ TP_ARGS(filename),
78335+
78336+ TP_STRUCT__entry(
78337+ __string( filename, filename )
78338+ ),
78339+
78340+ TP_fast_assign(
78341+ __assign_str(filename, filename);
78342+ ),
78343+
78344+ TP_printk("\"%s\"",
78345+ __get_str(filename))
78346+);
78347+
78348+#endif /* _TRACE_FS_H */
78349+
78350+/* This part must be outside protection */
78351+#include <trace/define_trace.h>
78352diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78353index 1c09820..7f5ec79 100644
78354--- a/include/trace/events/irq.h
78355+++ b/include/trace/events/irq.h
78356@@ -36,7 +36,7 @@ struct softirq_action;
78357 */
78358 TRACE_EVENT(irq_handler_entry,
78359
78360- TP_PROTO(int irq, struct irqaction *action),
78361+ TP_PROTO(int irq, const struct irqaction *action),
78362
78363 TP_ARGS(irq, action),
78364
78365@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78366 */
78367 TRACE_EVENT(irq_handler_exit,
78368
78369- TP_PROTO(int irq, struct irqaction *action, int ret),
78370+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78371
78372 TP_ARGS(irq, action, ret),
78373
78374diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78375index 7caf44c..23c6f27 100644
78376--- a/include/uapi/linux/a.out.h
78377+++ b/include/uapi/linux/a.out.h
78378@@ -39,6 +39,14 @@ enum machine_type {
78379 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78380 };
78381
78382+/* Constants for the N_FLAGS field */
78383+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78384+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78385+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78386+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78387+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78388+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78389+
78390 #if !defined (N_MAGIC)
78391 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78392 #endif
78393diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78394index d876736..ccce5c0 100644
78395--- a/include/uapi/linux/byteorder/little_endian.h
78396+++ b/include/uapi/linux/byteorder/little_endian.h
78397@@ -42,51 +42,51 @@
78398
78399 static inline __le64 __cpu_to_le64p(const __u64 *p)
78400 {
78401- return (__force __le64)*p;
78402+ return (__force const __le64)*p;
78403 }
78404-static inline __u64 __le64_to_cpup(const __le64 *p)
78405+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78406 {
78407- return (__force __u64)*p;
78408+ return (__force const __u64)*p;
78409 }
78410 static inline __le32 __cpu_to_le32p(const __u32 *p)
78411 {
78412- return (__force __le32)*p;
78413+ return (__force const __le32)*p;
78414 }
78415 static inline __u32 __le32_to_cpup(const __le32 *p)
78416 {
78417- return (__force __u32)*p;
78418+ return (__force const __u32)*p;
78419 }
78420 static inline __le16 __cpu_to_le16p(const __u16 *p)
78421 {
78422- return (__force __le16)*p;
78423+ return (__force const __le16)*p;
78424 }
78425 static inline __u16 __le16_to_cpup(const __le16 *p)
78426 {
78427- return (__force __u16)*p;
78428+ return (__force const __u16)*p;
78429 }
78430 static inline __be64 __cpu_to_be64p(const __u64 *p)
78431 {
78432- return (__force __be64)__swab64p(p);
78433+ return (__force const __be64)__swab64p(p);
78434 }
78435 static inline __u64 __be64_to_cpup(const __be64 *p)
78436 {
78437- return __swab64p((__u64 *)p);
78438+ return __swab64p((const __u64 *)p);
78439 }
78440 static inline __be32 __cpu_to_be32p(const __u32 *p)
78441 {
78442- return (__force __be32)__swab32p(p);
78443+ return (__force const __be32)__swab32p(p);
78444 }
78445-static inline __u32 __be32_to_cpup(const __be32 *p)
78446+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78447 {
78448- return __swab32p((__u32 *)p);
78449+ return __swab32p((const __u32 *)p);
78450 }
78451 static inline __be16 __cpu_to_be16p(const __u16 *p)
78452 {
78453- return (__force __be16)__swab16p(p);
78454+ return (__force const __be16)__swab16p(p);
78455 }
78456 static inline __u16 __be16_to_cpup(const __be16 *p)
78457 {
78458- return __swab16p((__u16 *)p);
78459+ return __swab16p((const __u16 *)p);
78460 }
78461 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78462 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78463diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78464index ef6103b..d4e65dd 100644
78465--- a/include/uapi/linux/elf.h
78466+++ b/include/uapi/linux/elf.h
78467@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78468 #define PT_GNU_EH_FRAME 0x6474e550
78469
78470 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78471+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78472+
78473+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78474+
78475+/* Constants for the e_flags field */
78476+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78477+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78478+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78479+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78480+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78481+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78482
78483 /*
78484 * Extended Numbering
78485@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78486 #define DT_DEBUG 21
78487 #define DT_TEXTREL 22
78488 #define DT_JMPREL 23
78489+#define DT_FLAGS 30
78490+ #define DF_TEXTREL 0x00000004
78491 #define DT_ENCODING 32
78492 #define OLD_DT_LOOS 0x60000000
78493 #define DT_LOOS 0x6000000d
78494@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78495 #define PF_W 0x2
78496 #define PF_X 0x1
78497
78498+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78499+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78500+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78501+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78502+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78503+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78504+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78505+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78506+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78507+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78508+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78509+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78510+
78511 typedef struct elf32_phdr{
78512 Elf32_Word p_type;
78513 Elf32_Off p_offset;
78514@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78515 #define EI_OSABI 7
78516 #define EI_PAD 8
78517
78518+#define EI_PAX 14
78519+
78520 #define ELFMAG0 0x7f /* EI_MAG */
78521 #define ELFMAG1 'E'
78522 #define ELFMAG2 'L'
78523diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78524index aa169c4..6a2771d 100644
78525--- a/include/uapi/linux/personality.h
78526+++ b/include/uapi/linux/personality.h
78527@@ -30,6 +30,7 @@ enum {
78528 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78529 ADDR_NO_RANDOMIZE | \
78530 ADDR_COMPAT_LAYOUT | \
78531+ ADDR_LIMIT_3GB | \
78532 MMAP_PAGE_ZERO)
78533
78534 /*
78535diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78536index 7530e74..e714828 100644
78537--- a/include/uapi/linux/screen_info.h
78538+++ b/include/uapi/linux/screen_info.h
78539@@ -43,7 +43,8 @@ struct screen_info {
78540 __u16 pages; /* 0x32 */
78541 __u16 vesa_attributes; /* 0x34 */
78542 __u32 capabilities; /* 0x36 */
78543- __u8 _reserved[6]; /* 0x3a */
78544+ __u16 vesapm_size; /* 0x3a */
78545+ __u8 _reserved[4]; /* 0x3c */
78546 } __attribute__((packed));
78547
78548 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78549diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78550index 0e011eb..82681b1 100644
78551--- a/include/uapi/linux/swab.h
78552+++ b/include/uapi/linux/swab.h
78553@@ -43,7 +43,7 @@
78554 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78555 */
78556
78557-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78558+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78559 {
78560 #ifdef __HAVE_BUILTIN_BSWAP16__
78561 return __builtin_bswap16(val);
78562@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78563 #endif
78564 }
78565
78566-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78567+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78568 {
78569 #ifdef __HAVE_BUILTIN_BSWAP32__
78570 return __builtin_bswap32(val);
78571@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78572 #endif
78573 }
78574
78575-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78576+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78577 {
78578 #ifdef __HAVE_BUILTIN_BSWAP64__
78579 return __builtin_bswap64(val);
78580diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78581index 6d67213..8dab561 100644
78582--- a/include/uapi/linux/sysctl.h
78583+++ b/include/uapi/linux/sysctl.h
78584@@ -155,7 +155,11 @@ enum
78585 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78586 };
78587
78588-
78589+#ifdef CONFIG_PAX_SOFTMODE
78590+enum {
78591+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78592+};
78593+#endif
78594
78595 /* CTL_VM names: */
78596 enum
78597diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78598index e4629b9..6958086 100644
78599--- a/include/uapi/linux/xattr.h
78600+++ b/include/uapi/linux/xattr.h
78601@@ -63,5 +63,9 @@
78602 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78603 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78604
78605+/* User namespace */
78606+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78607+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78608+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78609
78610 #endif /* _UAPI_LINUX_XATTR_H */
78611diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78612index f9466fa..f4e2b81 100644
78613--- a/include/video/udlfb.h
78614+++ b/include/video/udlfb.h
78615@@ -53,10 +53,10 @@ struct dlfb_data {
78616 u32 pseudo_palette[256];
78617 int blank_mode; /*one of FB_BLANK_ */
78618 /* blit-only rendering path metrics, exposed through sysfs */
78619- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78620- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78621- atomic_t bytes_sent; /* to usb, after compression including overhead */
78622- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78623+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78624+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78625+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78626+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78627 };
78628
78629 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78630diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78631index 30f5362..8ed8ac9 100644
78632--- a/include/video/uvesafb.h
78633+++ b/include/video/uvesafb.h
78634@@ -122,6 +122,7 @@ struct uvesafb_par {
78635 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78636 u8 pmi_setpal; /* PMI for palette changes */
78637 u16 *pmi_base; /* protected mode interface location */
78638+ u8 *pmi_code; /* protected mode code location */
78639 void *pmi_start;
78640 void *pmi_pal;
78641 u8 *vbe_state_orig; /*
78642diff --git a/init/Kconfig b/init/Kconfig
78643index fed81b5..0d3b964 100644
78644--- a/init/Kconfig
78645+++ b/init/Kconfig
78646@@ -1069,6 +1069,7 @@ endif # CGROUPS
78647
78648 config CHECKPOINT_RESTORE
78649 bool "Checkpoint/restore support" if EXPERT
78650+ depends on !GRKERNSEC
78651 default n
78652 help
78653 Enables additional kernel features in a sake of checkpoint/restore.
78654@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78655
78656 config COMPAT_BRK
78657 bool "Disable heap randomization"
78658- default y
78659+ default n
78660 help
78661 Randomizing heap placement makes heap exploits harder, but it
78662 also breaks ancient binaries (including anything libc5 based).
78663@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78664 config STOP_MACHINE
78665 bool
78666 default y
78667- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78668+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78669 help
78670 Need stop_machine() primitive.
78671
78672diff --git a/init/Makefile b/init/Makefile
78673index 7bc47ee..6da2dc7 100644
78674--- a/init/Makefile
78675+++ b/init/Makefile
78676@@ -2,6 +2,9 @@
78677 # Makefile for the linux kernel.
78678 #
78679
78680+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78681+asflags-y := $(GCC_PLUGINS_AFLAGS)
78682+
78683 obj-y := main.o version.o mounts.o
78684 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78685 obj-y += noinitramfs.o
78686diff --git a/init/do_mounts.c b/init/do_mounts.c
78687index 816014c..c2054db 100644
78688--- a/init/do_mounts.c
78689+++ b/init/do_mounts.c
78690@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78691 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78692 {
78693 struct super_block *s;
78694- int err = sys_mount(name, "/root", fs, flags, data);
78695+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78696 if (err)
78697 return err;
78698
78699- sys_chdir("/root");
78700+ sys_chdir((const char __force_user *)"/root");
78701 s = current->fs->pwd.dentry->d_sb;
78702 ROOT_DEV = s->s_dev;
78703 printk(KERN_INFO
78704@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78705 va_start(args, fmt);
78706 vsprintf(buf, fmt, args);
78707 va_end(args);
78708- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78709+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78710 if (fd >= 0) {
78711 sys_ioctl(fd, FDEJECT, 0);
78712 sys_close(fd);
78713 }
78714 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78715- fd = sys_open("/dev/console", O_RDWR, 0);
78716+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78717 if (fd >= 0) {
78718 sys_ioctl(fd, TCGETS, (long)&termios);
78719 termios.c_lflag &= ~ICANON;
78720 sys_ioctl(fd, TCSETSF, (long)&termios);
78721- sys_read(fd, &c, 1);
78722+ sys_read(fd, (char __user *)&c, 1);
78723 termios.c_lflag |= ICANON;
78724 sys_ioctl(fd, TCSETSF, (long)&termios);
78725 sys_close(fd);
78726@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78727 mount_root();
78728 out:
78729 devtmpfs_mount("dev");
78730- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78731- sys_chroot(".");
78732+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78733+ sys_chroot((const char __force_user *)".");
78734 }
78735diff --git a/init/do_mounts.h b/init/do_mounts.h
78736index f5b978a..69dbfe8 100644
78737--- a/init/do_mounts.h
78738+++ b/init/do_mounts.h
78739@@ -15,15 +15,15 @@ extern int root_mountflags;
78740
78741 static inline int create_dev(char *name, dev_t dev)
78742 {
78743- sys_unlink(name);
78744- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78745+ sys_unlink((char __force_user *)name);
78746+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78747 }
78748
78749 #if BITS_PER_LONG == 32
78750 static inline u32 bstat(char *name)
78751 {
78752 struct stat64 stat;
78753- if (sys_stat64(name, &stat) != 0)
78754+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78755 return 0;
78756 if (!S_ISBLK(stat.st_mode))
78757 return 0;
78758@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78759 static inline u32 bstat(char *name)
78760 {
78761 struct stat stat;
78762- if (sys_newstat(name, &stat) != 0)
78763+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78764 return 0;
78765 if (!S_ISBLK(stat.st_mode))
78766 return 0;
78767diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78768index 3e0878e..8a9d7a0 100644
78769--- a/init/do_mounts_initrd.c
78770+++ b/init/do_mounts_initrd.c
78771@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78772 {
78773 sys_unshare(CLONE_FS | CLONE_FILES);
78774 /* stdin/stdout/stderr for /linuxrc */
78775- sys_open("/dev/console", O_RDWR, 0);
78776+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78777 sys_dup(0);
78778 sys_dup(0);
78779 /* move initrd over / and chdir/chroot in initrd root */
78780- sys_chdir("/root");
78781- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78782- sys_chroot(".");
78783+ sys_chdir((const char __force_user *)"/root");
78784+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78785+ sys_chroot((const char __force_user *)".");
78786 sys_setsid();
78787 return 0;
78788 }
78789@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78790 create_dev("/dev/root.old", Root_RAM0);
78791 /* mount initrd on rootfs' /root */
78792 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78793- sys_mkdir("/old", 0700);
78794- sys_chdir("/old");
78795+ sys_mkdir((const char __force_user *)"/old", 0700);
78796+ sys_chdir((const char __force_user *)"/old");
78797
78798 /* try loading default modules from initrd */
78799 load_default_modules();
78800@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78801 current->flags &= ~PF_FREEZER_SKIP;
78802
78803 /* move initrd to rootfs' /old */
78804- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78805+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78806 /* switch root and cwd back to / of rootfs */
78807- sys_chroot("..");
78808+ sys_chroot((const char __force_user *)"..");
78809
78810 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78811- sys_chdir("/old");
78812+ sys_chdir((const char __force_user *)"/old");
78813 return;
78814 }
78815
78816- sys_chdir("/");
78817+ sys_chdir((const char __force_user *)"/");
78818 ROOT_DEV = new_decode_dev(real_root_dev);
78819 mount_root();
78820
78821 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78822- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78823+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78824 if (!error)
78825 printk("okay\n");
78826 else {
78827- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78828+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78829 if (error == -ENOENT)
78830 printk("/initrd does not exist. Ignored.\n");
78831 else
78832 printk("failed\n");
78833 printk(KERN_NOTICE "Unmounting old root\n");
78834- sys_umount("/old", MNT_DETACH);
78835+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78836 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78837 if (fd < 0) {
78838 error = fd;
78839@@ -127,11 +127,11 @@ int __init initrd_load(void)
78840 * mounted in the normal path.
78841 */
78842 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78843- sys_unlink("/initrd.image");
78844+ sys_unlink((const char __force_user *)"/initrd.image");
78845 handle_initrd();
78846 return 1;
78847 }
78848 }
78849- sys_unlink("/initrd.image");
78850+ sys_unlink((const char __force_user *)"/initrd.image");
78851 return 0;
78852 }
78853diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78854index 8cb6db5..d729f50 100644
78855--- a/init/do_mounts_md.c
78856+++ b/init/do_mounts_md.c
78857@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78858 partitioned ? "_d" : "", minor,
78859 md_setup_args[ent].device_names);
78860
78861- fd = sys_open(name, 0, 0);
78862+ fd = sys_open((char __force_user *)name, 0, 0);
78863 if (fd < 0) {
78864 printk(KERN_ERR "md: open failed - cannot start "
78865 "array %s\n", name);
78866@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78867 * array without it
78868 */
78869 sys_close(fd);
78870- fd = sys_open(name, 0, 0);
78871+ fd = sys_open((char __force_user *)name, 0, 0);
78872 sys_ioctl(fd, BLKRRPART, 0);
78873 }
78874 sys_close(fd);
78875@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78876
78877 wait_for_device_probe();
78878
78879- fd = sys_open("/dev/md0", 0, 0);
78880+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78881 if (fd >= 0) {
78882 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78883 sys_close(fd);
78884diff --git a/init/init_task.c b/init/init_task.c
78885index ba0a7f36..2bcf1d5 100644
78886--- a/init/init_task.c
78887+++ b/init/init_task.c
78888@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78889 * Initial thread structure. Alignment of this is handled by a special
78890 * linker map entry.
78891 */
78892+#ifdef CONFIG_X86
78893+union thread_union init_thread_union __init_task_data;
78894+#else
78895 union thread_union init_thread_union __init_task_data =
78896 { INIT_THREAD_INFO(init_task) };
78897+#endif
78898diff --git a/init/initramfs.c b/init/initramfs.c
78899index a67ef9d..2d17ed9 100644
78900--- a/init/initramfs.c
78901+++ b/init/initramfs.c
78902@@ -84,7 +84,7 @@ static void __init free_hash(void)
78903 }
78904 }
78905
78906-static long __init do_utime(char *filename, time_t mtime)
78907+static long __init do_utime(char __force_user *filename, time_t mtime)
78908 {
78909 struct timespec t[2];
78910
78911@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78912 struct dir_entry *de, *tmp;
78913 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78914 list_del(&de->list);
78915- do_utime(de->name, de->mtime);
78916+ do_utime((char __force_user *)de->name, de->mtime);
78917 kfree(de->name);
78918 kfree(de);
78919 }
78920@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78921 if (nlink >= 2) {
78922 char *old = find_link(major, minor, ino, mode, collected);
78923 if (old)
78924- return (sys_link(old, collected) < 0) ? -1 : 1;
78925+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78926 }
78927 return 0;
78928 }
78929@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78930 {
78931 struct stat st;
78932
78933- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78934+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78935 if (S_ISDIR(st.st_mode))
78936- sys_rmdir(path);
78937+ sys_rmdir((char __force_user *)path);
78938 else
78939- sys_unlink(path);
78940+ sys_unlink((char __force_user *)path);
78941 }
78942 }
78943
78944@@ -315,7 +315,7 @@ static int __init do_name(void)
78945 int openflags = O_WRONLY|O_CREAT;
78946 if (ml != 1)
78947 openflags |= O_TRUNC;
78948- wfd = sys_open(collected, openflags, mode);
78949+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78950
78951 if (wfd >= 0) {
78952 sys_fchown(wfd, uid, gid);
78953@@ -327,17 +327,17 @@ static int __init do_name(void)
78954 }
78955 }
78956 } else if (S_ISDIR(mode)) {
78957- sys_mkdir(collected, mode);
78958- sys_chown(collected, uid, gid);
78959- sys_chmod(collected, mode);
78960+ sys_mkdir((char __force_user *)collected, mode);
78961+ sys_chown((char __force_user *)collected, uid, gid);
78962+ sys_chmod((char __force_user *)collected, mode);
78963 dir_add(collected, mtime);
78964 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78965 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78966 if (maybe_link() == 0) {
78967- sys_mknod(collected, mode, rdev);
78968- sys_chown(collected, uid, gid);
78969- sys_chmod(collected, mode);
78970- do_utime(collected, mtime);
78971+ sys_mknod((char __force_user *)collected, mode, rdev);
78972+ sys_chown((char __force_user *)collected, uid, gid);
78973+ sys_chmod((char __force_user *)collected, mode);
78974+ do_utime((char __force_user *)collected, mtime);
78975 }
78976 }
78977 return 0;
78978@@ -346,15 +346,15 @@ static int __init do_name(void)
78979 static int __init do_copy(void)
78980 {
78981 if (count >= body_len) {
78982- sys_write(wfd, victim, body_len);
78983+ sys_write(wfd, (char __force_user *)victim, body_len);
78984 sys_close(wfd);
78985- do_utime(vcollected, mtime);
78986+ do_utime((char __force_user *)vcollected, mtime);
78987 kfree(vcollected);
78988 eat(body_len);
78989 state = SkipIt;
78990 return 0;
78991 } else {
78992- sys_write(wfd, victim, count);
78993+ sys_write(wfd, (char __force_user *)victim, count);
78994 body_len -= count;
78995 eat(count);
78996 return 1;
78997@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78998 {
78999 collected[N_ALIGN(name_len) + body_len] = '\0';
79000 clean_path(collected, 0);
79001- sys_symlink(collected + N_ALIGN(name_len), collected);
79002- sys_lchown(collected, uid, gid);
79003- do_utime(collected, mtime);
79004+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79005+ sys_lchown((char __force_user *)collected, uid, gid);
79006+ do_utime((char __force_user *)collected, mtime);
79007 state = SkipIt;
79008 next_state = Reset;
79009 return 0;
79010@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79011 {
79012 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79013 if (err)
79014- panic(err); /* Failed to decompress INTERNAL initramfs */
79015+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79016 if (initrd_start) {
79017 #ifdef CONFIG_BLK_DEV_RAM
79018 int fd;
79019diff --git a/init/main.c b/init/main.c
79020index 586cd33..f1af30f 100644
79021--- a/init/main.c
79022+++ b/init/main.c
79023@@ -102,6 +102,8 @@ static inline void mark_rodata_ro(void) { }
79024 extern void tc_init(void);
79025 #endif
79026
79027+extern void grsecurity_init(void);
79028+
79029 /*
79030 * Debug helper: via this flag we know that we are in 'early bootup code'
79031 * where only the boot processor is running with IRQ disabled. This means
79032@@ -155,6 +157,74 @@ static int __init set_reset_devices(char *str)
79033
79034 __setup("reset_devices", set_reset_devices);
79035
79036+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79037+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79038+static int __init setup_grsec_proc_gid(char *str)
79039+{
79040+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79041+ return 1;
79042+}
79043+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79044+#endif
79045+
79046+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79047+unsigned long pax_user_shadow_base __read_only;
79048+EXPORT_SYMBOL(pax_user_shadow_base);
79049+extern char pax_enter_kernel_user[];
79050+extern char pax_exit_kernel_user[];
79051+#endif
79052+
79053+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79054+static int __init setup_pax_nouderef(char *str)
79055+{
79056+#ifdef CONFIG_X86_32
79057+ unsigned int cpu;
79058+ struct desc_struct *gdt;
79059+
79060+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79061+ gdt = get_cpu_gdt_table(cpu);
79062+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79063+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79064+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79065+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79066+ }
79067+ loadsegment(ds, __KERNEL_DS);
79068+ loadsegment(es, __KERNEL_DS);
79069+ loadsegment(ss, __KERNEL_DS);
79070+#else
79071+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79072+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79073+ clone_pgd_mask = ~(pgdval_t)0UL;
79074+ pax_user_shadow_base = 0UL;
79075+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79076+#endif
79077+
79078+ return 0;
79079+}
79080+early_param("pax_nouderef", setup_pax_nouderef);
79081+
79082+#ifdef CONFIG_X86_64
79083+static int __init setup_pax_weakuderef(char *str)
79084+{
79085+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79086+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79087+ return 1;
79088+}
79089+__setup("pax_weakuderef", setup_pax_weakuderef);
79090+#endif
79091+#endif
79092+
79093+#ifdef CONFIG_PAX_SOFTMODE
79094+int pax_softmode;
79095+
79096+static int __init setup_pax_softmode(char *str)
79097+{
79098+ get_option(&str, &pax_softmode);
79099+ return 1;
79100+}
79101+__setup("pax_softmode=", setup_pax_softmode);
79102+#endif
79103+
79104 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79105 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79106 static const char *panic_later, *panic_param;
79107@@ -680,25 +750,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79108 {
79109 int count = preempt_count();
79110 int ret;
79111- char msgbuf[64];
79112+ const char *msg1 = "", *msg2 = "";
79113
79114 if (initcall_debug)
79115 ret = do_one_initcall_debug(fn);
79116 else
79117 ret = fn();
79118
79119- msgbuf[0] = 0;
79120-
79121 if (preempt_count() != count) {
79122- sprintf(msgbuf, "preemption imbalance ");
79123+ msg1 = " preemption imbalance";
79124 preempt_count() = count;
79125 }
79126 if (irqs_disabled()) {
79127- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79128+ msg2 = " disabled interrupts";
79129 local_irq_enable();
79130 }
79131- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79132+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79133
79134+ add_latent_entropy();
79135 return ret;
79136 }
79137
79138@@ -805,8 +874,8 @@ static int run_init_process(const char *init_filename)
79139 {
79140 argv_init[0] = init_filename;
79141 return do_execve(init_filename,
79142- (const char __user *const __user *)argv_init,
79143- (const char __user *const __user *)envp_init);
79144+ (const char __user *const __force_user *)argv_init,
79145+ (const char __user *const __force_user *)envp_init);
79146 }
79147
79148 static noinline void __init kernel_init_freeable(void);
79149@@ -883,7 +952,7 @@ static noinline void __init kernel_init_freeable(void)
79150 do_basic_setup();
79151
79152 /* Open the /dev/console on the rootfs, this should never fail */
79153- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79154+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79155 pr_err("Warning: unable to open an initial console.\n");
79156
79157 (void) sys_dup(0);
79158@@ -896,11 +965,13 @@ static noinline void __init kernel_init_freeable(void)
79159 if (!ramdisk_execute_command)
79160 ramdisk_execute_command = "/init";
79161
79162- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79163+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79164 ramdisk_execute_command = NULL;
79165 prepare_namespace();
79166 }
79167
79168+ grsecurity_init();
79169+
79170 /*
79171 * Ok, we have completed the initial bootup, and
79172 * we're essentially up and running. Get rid of the
79173diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79174index 130dfec..cc88451 100644
79175--- a/ipc/ipc_sysctl.c
79176+++ b/ipc/ipc_sysctl.c
79177@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79178 static int proc_ipc_dointvec(ctl_table *table, int write,
79179 void __user *buffer, size_t *lenp, loff_t *ppos)
79180 {
79181- struct ctl_table ipc_table;
79182+ ctl_table_no_const ipc_table;
79183
79184 memcpy(&ipc_table, table, sizeof(ipc_table));
79185 ipc_table.data = get_ipc(table);
79186@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79187 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79188 void __user *buffer, size_t *lenp, loff_t *ppos)
79189 {
79190- struct ctl_table ipc_table;
79191+ ctl_table_no_const ipc_table;
79192
79193 memcpy(&ipc_table, table, sizeof(ipc_table));
79194 ipc_table.data = get_ipc(table);
79195@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79196 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79197 void __user *buffer, size_t *lenp, loff_t *ppos)
79198 {
79199- struct ctl_table ipc_table;
79200+ ctl_table_no_const ipc_table;
79201 size_t lenp_bef = *lenp;
79202 int rc;
79203
79204@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79205 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79206 void __user *buffer, size_t *lenp, loff_t *ppos)
79207 {
79208- struct ctl_table ipc_table;
79209+ ctl_table_no_const ipc_table;
79210 memcpy(&ipc_table, table, sizeof(ipc_table));
79211 ipc_table.data = get_ipc(table);
79212
79213@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79214 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79215 void __user *buffer, size_t *lenp, loff_t *ppos)
79216 {
79217- struct ctl_table ipc_table;
79218+ ctl_table_no_const ipc_table;
79219 size_t lenp_bef = *lenp;
79220 int oldval;
79221 int rc;
79222diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79223index 383d638..943fdbb 100644
79224--- a/ipc/mq_sysctl.c
79225+++ b/ipc/mq_sysctl.c
79226@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79227 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79228 void __user *buffer, size_t *lenp, loff_t *ppos)
79229 {
79230- struct ctl_table mq_table;
79231+ ctl_table_no_const mq_table;
79232 memcpy(&mq_table, table, sizeof(mq_table));
79233 mq_table.data = get_mq(table);
79234
79235diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79236index ae1996d..a35f2cc 100644
79237--- a/ipc/mqueue.c
79238+++ b/ipc/mqueue.c
79239@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79240 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79241 info->attr.mq_msgsize);
79242
79243+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79244 spin_lock(&mq_lock);
79245 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79246 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79247diff --git a/ipc/msg.c b/ipc/msg.c
79248index 558aa91..359e718 100644
79249--- a/ipc/msg.c
79250+++ b/ipc/msg.c
79251@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79252 return security_msg_queue_associate(msq, msgflg);
79253 }
79254
79255+static struct ipc_ops msg_ops = {
79256+ .getnew = newque,
79257+ .associate = msg_security,
79258+ .more_checks = NULL
79259+};
79260+
79261 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79262 {
79263 struct ipc_namespace *ns;
79264- struct ipc_ops msg_ops;
79265 struct ipc_params msg_params;
79266
79267 ns = current->nsproxy->ipc_ns;
79268
79269- msg_ops.getnew = newque;
79270- msg_ops.associate = msg_security;
79271- msg_ops.more_checks = NULL;
79272-
79273 msg_params.key = key;
79274 msg_params.flg = msgflg;
79275
79276diff --git a/ipc/sem.c b/ipc/sem.c
79277index 8e2bf30..a711151 100644
79278--- a/ipc/sem.c
79279+++ b/ipc/sem.c
79280@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79281 return 0;
79282 }
79283
79284+static struct ipc_ops sem_ops = {
79285+ .getnew = newary,
79286+ .associate = sem_security,
79287+ .more_checks = sem_more_checks
79288+};
79289+
79290 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79291 {
79292 struct ipc_namespace *ns;
79293- struct ipc_ops sem_ops;
79294 struct ipc_params sem_params;
79295
79296 ns = current->nsproxy->ipc_ns;
79297@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79298 if (nsems < 0 || nsems > ns->sc_semmsl)
79299 return -EINVAL;
79300
79301- sem_ops.getnew = newary;
79302- sem_ops.associate = sem_security;
79303- sem_ops.more_checks = sem_more_checks;
79304-
79305 sem_params.key = key;
79306 sem_params.flg = semflg;
79307 sem_params.u.nsems = nsems;
79308diff --git a/ipc/shm.c b/ipc/shm.c
79309index d697396..40e887d 100644
79310--- a/ipc/shm.c
79311+++ b/ipc/shm.c
79312@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79313 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79314 #endif
79315
79316+#ifdef CONFIG_GRKERNSEC
79317+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79318+ const time_t shm_createtime, const kuid_t cuid,
79319+ const int shmid);
79320+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79321+ const time_t shm_createtime);
79322+#endif
79323+
79324 void shm_init_ns(struct ipc_namespace *ns)
79325 {
79326 ns->shm_ctlmax = SHMMAX;
79327@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79328 shp->shm_lprid = 0;
79329 shp->shm_atim = shp->shm_dtim = 0;
79330 shp->shm_ctim = get_seconds();
79331+#ifdef CONFIG_GRKERNSEC
79332+ {
79333+ struct timespec timeval;
79334+ do_posix_clock_monotonic_gettime(&timeval);
79335+
79336+ shp->shm_createtime = timeval.tv_sec;
79337+ }
79338+#endif
79339 shp->shm_segsz = size;
79340 shp->shm_nattch = 0;
79341 shp->shm_file = file;
79342@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79343 return 0;
79344 }
79345
79346+static struct ipc_ops shm_ops = {
79347+ .getnew = newseg,
79348+ .associate = shm_security,
79349+ .more_checks = shm_more_checks
79350+};
79351+
79352 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79353 {
79354 struct ipc_namespace *ns;
79355- struct ipc_ops shm_ops;
79356 struct ipc_params shm_params;
79357
79358 ns = current->nsproxy->ipc_ns;
79359
79360- shm_ops.getnew = newseg;
79361- shm_ops.associate = shm_security;
79362- shm_ops.more_checks = shm_more_checks;
79363-
79364 shm_params.key = key;
79365 shm_params.flg = shmflg;
79366 shm_params.u.size = size;
79367@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79368 f_mode = FMODE_READ | FMODE_WRITE;
79369 }
79370 if (shmflg & SHM_EXEC) {
79371+
79372+#ifdef CONFIG_PAX_MPROTECT
79373+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79374+ goto out;
79375+#endif
79376+
79377 prot |= PROT_EXEC;
79378 acc_mode |= S_IXUGO;
79379 }
79380@@ -1100,10 +1123,22 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79381 if (err)
79382 goto out_unlock;
79383
79384+#ifdef CONFIG_GRKERNSEC
79385+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79386+ shp->shm_perm.cuid, shmid) ||
79387+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79388+ err = -EACCES;
79389+ goto out_unlock;
79390+ }
79391+#endif
79392+
79393 ipc_lock_object(&shp->shm_perm);
79394 path = shp->shm_file->f_path;
79395 path_get(&path);
79396 shp->shm_nattch++;
79397+#ifdef CONFIG_GRKERNSEC
79398+ shp->shm_lapid = current->pid;
79399+#endif
79400 size = i_size_read(path.dentry->d_inode);
79401 ipc_unlock_object(&shp->shm_perm);
79402 rcu_read_unlock();
79403diff --git a/kernel/acct.c b/kernel/acct.c
79404index 8d6e145..33e0b1e 100644
79405--- a/kernel/acct.c
79406+++ b/kernel/acct.c
79407@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79408 */
79409 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79410 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79411- file->f_op->write(file, (char *)&ac,
79412+ file->f_op->write(file, (char __force_user *)&ac,
79413 sizeof(acct_t), &file->f_pos);
79414 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79415 set_fs(fs);
79416diff --git a/kernel/audit.c b/kernel/audit.c
79417index 7b0e23a..5b27ab9 100644
79418--- a/kernel/audit.c
79419+++ b/kernel/audit.c
79420@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79421 3) suppressed due to audit_rate_limit
79422 4) suppressed due to audit_backlog_limit
79423 */
79424-static atomic_t audit_lost = ATOMIC_INIT(0);
79425+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79426
79427 /* The netlink socket. */
79428 static struct sock *audit_sock;
79429@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79430 unsigned long now;
79431 int print;
79432
79433- atomic_inc(&audit_lost);
79434+ atomic_inc_unchecked(&audit_lost);
79435
79436 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79437
79438@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79439 printk(KERN_WARNING
79440 "audit: audit_lost=%d audit_rate_limit=%d "
79441 "audit_backlog_limit=%d\n",
79442- atomic_read(&audit_lost),
79443+ atomic_read_unchecked(&audit_lost),
79444 audit_rate_limit,
79445 audit_backlog_limit);
79446 audit_panic(message);
79447@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79448
79449 switch (msg_type) {
79450 case AUDIT_GET:
79451+ status_set.mask = 0;
79452 status_set.enabled = audit_enabled;
79453 status_set.failure = audit_failure;
79454 status_set.pid = audit_pid;
79455 status_set.rate_limit = audit_rate_limit;
79456 status_set.backlog_limit = audit_backlog_limit;
79457- status_set.lost = atomic_read(&audit_lost);
79458+ status_set.lost = atomic_read_unchecked(&audit_lost);
79459 status_set.backlog = skb_queue_len(&audit_skb_queue);
79460 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79461 &status_set, sizeof(status_set));
79462 break;
79463 case AUDIT_SET:
79464- if (nlh->nlmsg_len < sizeof(struct audit_status))
79465+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79466 return -EINVAL;
79467 status_get = (struct audit_status *)data;
79468 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79469@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79470
79471 memset(&s, 0, sizeof(s));
79472 /* guard against past and future API changes */
79473- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79474+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79475 if ((s.enabled != 0 && s.enabled != 1) ||
79476 (s.log_passwd != 0 && s.log_passwd != 1))
79477 return -EINVAL;
79478diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79479index 9845cb3..3ec9369 100644
79480--- a/kernel/auditsc.c
79481+++ b/kernel/auditsc.c
79482@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79483 }
79484
79485 /* global counter which is incremented every time something logs in */
79486-static atomic_t session_id = ATOMIC_INIT(0);
79487+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79488
79489 /**
79490 * audit_set_loginuid - set current task's audit_context loginuid
79491@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79492 return -EPERM;
79493 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79494
79495- sessionid = atomic_inc_return(&session_id);
79496+ sessionid = atomic_inc_return_unchecked(&session_id);
79497 if (context && context->in_syscall) {
79498 struct audit_buffer *ab;
79499
79500diff --git a/kernel/capability.c b/kernel/capability.c
79501index f6c2ce5..982c0f9 100644
79502--- a/kernel/capability.c
79503+++ b/kernel/capability.c
79504@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79505 * before modification is attempted and the application
79506 * fails.
79507 */
79508+ if (tocopy > ARRAY_SIZE(kdata))
79509+ return -EFAULT;
79510+
79511 if (copy_to_user(dataptr, kdata, tocopy
79512 * sizeof(struct __user_cap_data_struct))) {
79513 return -EFAULT;
79514@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79515 int ret;
79516
79517 rcu_read_lock();
79518- ret = security_capable(__task_cred(t), ns, cap);
79519+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79520+ gr_task_is_capable(t, __task_cred(t), cap);
79521 rcu_read_unlock();
79522
79523- return (ret == 0);
79524+ return ret;
79525 }
79526
79527 /**
79528@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79529 int ret;
79530
79531 rcu_read_lock();
79532- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79533+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79534 rcu_read_unlock();
79535
79536- return (ret == 0);
79537+ return ret;
79538 }
79539
79540 /**
79541@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79542 BUG();
79543 }
79544
79545- if (security_capable(current_cred(), ns, cap) == 0) {
79546+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79547 current->flags |= PF_SUPERPRIV;
79548 return true;
79549 }
79550@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79551 }
79552 EXPORT_SYMBOL(ns_capable);
79553
79554+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79555+{
79556+ if (unlikely(!cap_valid(cap))) {
79557+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79558+ BUG();
79559+ }
79560+
79561+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79562+ current->flags |= PF_SUPERPRIV;
79563+ return true;
79564+ }
79565+ return false;
79566+}
79567+EXPORT_SYMBOL(ns_capable_nolog);
79568+
79569 /**
79570 * file_ns_capable - Determine if the file's opener had a capability in effect
79571 * @file: The file we want to check
79572@@ -432,6 +451,12 @@ bool capable(int cap)
79573 }
79574 EXPORT_SYMBOL(capable);
79575
79576+bool capable_nolog(int cap)
79577+{
79578+ return ns_capable_nolog(&init_user_ns, cap);
79579+}
79580+EXPORT_SYMBOL(capable_nolog);
79581+
79582 /**
79583 * nsown_capable - Check superior capability to one's own user_ns
79584 * @cap: The capability in question
79585@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79586
79587 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79588 }
79589+
79590+bool inode_capable_nolog(const struct inode *inode, int cap)
79591+{
79592+ struct user_namespace *ns = current_user_ns();
79593+
79594+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79595+}
79596diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79597index e919633..f46b08f 100644
79598--- a/kernel/cgroup.c
79599+++ b/kernel/cgroup.c
79600@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79601 struct css_set *cset = link->cset;
79602 struct task_struct *task;
79603 int count = 0;
79604- seq_printf(seq, "css_set %p\n", cset);
79605+ seq_printf(seq, "css_set %pK\n", cset);
79606 list_for_each_entry(task, &cset->tasks, cg_list) {
79607 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79608 seq_puts(seq, " ...\n");
79609diff --git a/kernel/compat.c b/kernel/compat.c
79610index 0a09e48..f44f3f0 100644
79611--- a/kernel/compat.c
79612+++ b/kernel/compat.c
79613@@ -13,6 +13,7 @@
79614
79615 #include <linux/linkage.h>
79616 #include <linux/compat.h>
79617+#include <linux/module.h>
79618 #include <linux/errno.h>
79619 #include <linux/time.h>
79620 #include <linux/signal.h>
79621@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79622 mm_segment_t oldfs;
79623 long ret;
79624
79625- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79626+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79627 oldfs = get_fs();
79628 set_fs(KERNEL_DS);
79629 ret = hrtimer_nanosleep_restart(restart);
79630@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79631 oldfs = get_fs();
79632 set_fs(KERNEL_DS);
79633 ret = hrtimer_nanosleep(&tu,
79634- rmtp ? (struct timespec __user *)&rmt : NULL,
79635+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79636 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79637 set_fs(oldfs);
79638
79639@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79640 mm_segment_t old_fs = get_fs();
79641
79642 set_fs(KERNEL_DS);
79643- ret = sys_sigpending((old_sigset_t __user *) &s);
79644+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79645 set_fs(old_fs);
79646 if (ret == 0)
79647 ret = put_user(s, set);
79648@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79649 mm_segment_t old_fs = get_fs();
79650
79651 set_fs(KERNEL_DS);
79652- ret = sys_old_getrlimit(resource, &r);
79653+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79654 set_fs(old_fs);
79655
79656 if (!ret) {
79657@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79658 set_fs (KERNEL_DS);
79659 ret = sys_wait4(pid,
79660 (stat_addr ?
79661- (unsigned int __user *) &status : NULL),
79662- options, (struct rusage __user *) &r);
79663+ (unsigned int __force_user *) &status : NULL),
79664+ options, (struct rusage __force_user *) &r);
79665 set_fs (old_fs);
79666
79667 if (ret > 0) {
79668@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79669 memset(&info, 0, sizeof(info));
79670
79671 set_fs(KERNEL_DS);
79672- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79673- uru ? (struct rusage __user *)&ru : NULL);
79674+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79675+ uru ? (struct rusage __force_user *)&ru : NULL);
79676 set_fs(old_fs);
79677
79678 if ((ret < 0) || (info.si_signo == 0))
79679@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79680 oldfs = get_fs();
79681 set_fs(KERNEL_DS);
79682 err = sys_timer_settime(timer_id, flags,
79683- (struct itimerspec __user *) &newts,
79684- (struct itimerspec __user *) &oldts);
79685+ (struct itimerspec __force_user *) &newts,
79686+ (struct itimerspec __force_user *) &oldts);
79687 set_fs(oldfs);
79688 if (!err && old && put_compat_itimerspec(old, &oldts))
79689 return -EFAULT;
79690@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79691 oldfs = get_fs();
79692 set_fs(KERNEL_DS);
79693 err = sys_timer_gettime(timer_id,
79694- (struct itimerspec __user *) &ts);
79695+ (struct itimerspec __force_user *) &ts);
79696 set_fs(oldfs);
79697 if (!err && put_compat_itimerspec(setting, &ts))
79698 return -EFAULT;
79699@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79700 oldfs = get_fs();
79701 set_fs(KERNEL_DS);
79702 err = sys_clock_settime(which_clock,
79703- (struct timespec __user *) &ts);
79704+ (struct timespec __force_user *) &ts);
79705 set_fs(oldfs);
79706 return err;
79707 }
79708@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79709 oldfs = get_fs();
79710 set_fs(KERNEL_DS);
79711 err = sys_clock_gettime(which_clock,
79712- (struct timespec __user *) &ts);
79713+ (struct timespec __force_user *) &ts);
79714 set_fs(oldfs);
79715 if (!err && put_compat_timespec(&ts, tp))
79716 return -EFAULT;
79717@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79718
79719 oldfs = get_fs();
79720 set_fs(KERNEL_DS);
79721- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79722+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79723 set_fs(oldfs);
79724
79725 err = compat_put_timex(utp, &txc);
79726@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79727 oldfs = get_fs();
79728 set_fs(KERNEL_DS);
79729 err = sys_clock_getres(which_clock,
79730- (struct timespec __user *) &ts);
79731+ (struct timespec __force_user *) &ts);
79732 set_fs(oldfs);
79733 if (!err && tp && put_compat_timespec(&ts, tp))
79734 return -EFAULT;
79735@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79736 long err;
79737 mm_segment_t oldfs;
79738 struct timespec tu;
79739- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79740+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79741
79742- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79743+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79744 oldfs = get_fs();
79745 set_fs(KERNEL_DS);
79746 err = clock_nanosleep_restart(restart);
79747@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79748 oldfs = get_fs();
79749 set_fs(KERNEL_DS);
79750 err = sys_clock_nanosleep(which_clock, flags,
79751- (struct timespec __user *) &in,
79752- (struct timespec __user *) &out);
79753+ (struct timespec __force_user *) &in,
79754+ (struct timespec __force_user *) &out);
79755 set_fs(oldfs);
79756
79757 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79758diff --git a/kernel/configs.c b/kernel/configs.c
79759index c18b1f1..b9a0132 100644
79760--- a/kernel/configs.c
79761+++ b/kernel/configs.c
79762@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79763 struct proc_dir_entry *entry;
79764
79765 /* create the current config file */
79766+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79767+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79768+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79769+ &ikconfig_file_ops);
79770+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79771+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79772+ &ikconfig_file_ops);
79773+#endif
79774+#else
79775 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79776 &ikconfig_file_ops);
79777+#endif
79778+
79779 if (!entry)
79780 return -ENOMEM;
79781
79782diff --git a/kernel/cred.c b/kernel/cred.c
79783index e0573a4..3874e41 100644
79784--- a/kernel/cred.c
79785+++ b/kernel/cred.c
79786@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79787 validate_creds(cred);
79788 alter_cred_subscribers(cred, -1);
79789 put_cred(cred);
79790+
79791+#ifdef CONFIG_GRKERNSEC_SETXID
79792+ cred = (struct cred *) tsk->delayed_cred;
79793+ if (cred != NULL) {
79794+ tsk->delayed_cred = NULL;
79795+ validate_creds(cred);
79796+ alter_cred_subscribers(cred, -1);
79797+ put_cred(cred);
79798+ }
79799+#endif
79800 }
79801
79802 /**
79803@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79804 * Always returns 0 thus allowing this function to be tail-called at the end
79805 * of, say, sys_setgid().
79806 */
79807-int commit_creds(struct cred *new)
79808+static int __commit_creds(struct cred *new)
79809 {
79810 struct task_struct *task = current;
79811 const struct cred *old = task->real_cred;
79812@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79813
79814 get_cred(new); /* we will require a ref for the subj creds too */
79815
79816+ gr_set_role_label(task, new->uid, new->gid);
79817+
79818 /* dumpability changes */
79819 if (!uid_eq(old->euid, new->euid) ||
79820 !gid_eq(old->egid, new->egid) ||
79821@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79822 put_cred(old);
79823 return 0;
79824 }
79825+#ifdef CONFIG_GRKERNSEC_SETXID
79826+extern int set_user(struct cred *new);
79827+
79828+void gr_delayed_cred_worker(void)
79829+{
79830+ const struct cred *new = current->delayed_cred;
79831+ struct cred *ncred;
79832+
79833+ current->delayed_cred = NULL;
79834+
79835+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79836+ // from doing get_cred on it when queueing this
79837+ put_cred(new);
79838+ return;
79839+ } else if (new == NULL)
79840+ return;
79841+
79842+ ncred = prepare_creds();
79843+ if (!ncred)
79844+ goto die;
79845+ // uids
79846+ ncred->uid = new->uid;
79847+ ncred->euid = new->euid;
79848+ ncred->suid = new->suid;
79849+ ncred->fsuid = new->fsuid;
79850+ // gids
79851+ ncred->gid = new->gid;
79852+ ncred->egid = new->egid;
79853+ ncred->sgid = new->sgid;
79854+ ncred->fsgid = new->fsgid;
79855+ // groups
79856+ if (set_groups(ncred, new->group_info) < 0) {
79857+ abort_creds(ncred);
79858+ goto die;
79859+ }
79860+ // caps
79861+ ncred->securebits = new->securebits;
79862+ ncred->cap_inheritable = new->cap_inheritable;
79863+ ncred->cap_permitted = new->cap_permitted;
79864+ ncred->cap_effective = new->cap_effective;
79865+ ncred->cap_bset = new->cap_bset;
79866+
79867+ if (set_user(ncred)) {
79868+ abort_creds(ncred);
79869+ goto die;
79870+ }
79871+
79872+ // from doing get_cred on it when queueing this
79873+ put_cred(new);
79874+
79875+ __commit_creds(ncred);
79876+ return;
79877+die:
79878+ // from doing get_cred on it when queueing this
79879+ put_cred(new);
79880+ do_group_exit(SIGKILL);
79881+}
79882+#endif
79883+
79884+int commit_creds(struct cred *new)
79885+{
79886+#ifdef CONFIG_GRKERNSEC_SETXID
79887+ int ret;
79888+ int schedule_it = 0;
79889+ struct task_struct *t;
79890+
79891+ /* we won't get called with tasklist_lock held for writing
79892+ and interrupts disabled as the cred struct in that case is
79893+ init_cred
79894+ */
79895+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79896+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79897+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79898+ schedule_it = 1;
79899+ }
79900+ ret = __commit_creds(new);
79901+ if (schedule_it) {
79902+ rcu_read_lock();
79903+ read_lock(&tasklist_lock);
79904+ for (t = next_thread(current); t != current;
79905+ t = next_thread(t)) {
79906+ if (t->delayed_cred == NULL) {
79907+ t->delayed_cred = get_cred(new);
79908+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79909+ set_tsk_need_resched(t);
79910+ }
79911+ }
79912+ read_unlock(&tasklist_lock);
79913+ rcu_read_unlock();
79914+ }
79915+ return ret;
79916+#else
79917+ return __commit_creds(new);
79918+#endif
79919+}
79920+
79921 EXPORT_SYMBOL(commit_creds);
79922
79923 /**
79924diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79925index 0506d44..2c20034 100644
79926--- a/kernel/debug/debug_core.c
79927+++ b/kernel/debug/debug_core.c
79928@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79929 */
79930 static atomic_t masters_in_kgdb;
79931 static atomic_t slaves_in_kgdb;
79932-static atomic_t kgdb_break_tasklet_var;
79933+static atomic_unchecked_t kgdb_break_tasklet_var;
79934 atomic_t kgdb_setting_breakpoint;
79935
79936 struct task_struct *kgdb_usethread;
79937@@ -133,7 +133,7 @@ int kgdb_single_step;
79938 static pid_t kgdb_sstep_pid;
79939
79940 /* to keep track of the CPU which is doing the single stepping*/
79941-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79942+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79943
79944 /*
79945 * If you are debugging a problem where roundup (the collection of
79946@@ -541,7 +541,7 @@ return_normal:
79947 * kernel will only try for the value of sstep_tries before
79948 * giving up and continuing on.
79949 */
79950- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79951+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79952 (kgdb_info[cpu].task &&
79953 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79954 atomic_set(&kgdb_active, -1);
79955@@ -635,8 +635,8 @@ cpu_master_loop:
79956 }
79957
79958 kgdb_restore:
79959- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79960- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79961+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79962+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79963 if (kgdb_info[sstep_cpu].task)
79964 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79965 else
79966@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79967 static void kgdb_tasklet_bpt(unsigned long ing)
79968 {
79969 kgdb_breakpoint();
79970- atomic_set(&kgdb_break_tasklet_var, 0);
79971+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79972 }
79973
79974 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79975
79976 void kgdb_schedule_breakpoint(void)
79977 {
79978- if (atomic_read(&kgdb_break_tasklet_var) ||
79979+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79980 atomic_read(&kgdb_active) != -1 ||
79981 atomic_read(&kgdb_setting_breakpoint))
79982 return;
79983- atomic_inc(&kgdb_break_tasklet_var);
79984+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79985 tasklet_schedule(&kgdb_tasklet_breakpoint);
79986 }
79987 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79988diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79989index 00eb8f7..d7e3244 100644
79990--- a/kernel/debug/kdb/kdb_main.c
79991+++ b/kernel/debug/kdb/kdb_main.c
79992@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79993 continue;
79994
79995 kdb_printf("%-20s%8u 0x%p ", mod->name,
79996- mod->core_size, (void *)mod);
79997+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79998 #ifdef CONFIG_MODULE_UNLOAD
79999 kdb_printf("%4ld ", module_refcount(mod));
80000 #endif
80001@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80002 kdb_printf(" (Loading)");
80003 else
80004 kdb_printf(" (Live)");
80005- kdb_printf(" 0x%p", mod->module_core);
80006+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80007
80008 #ifdef CONFIG_MODULE_UNLOAD
80009 {
80010diff --git a/kernel/events/core.c b/kernel/events/core.c
80011index f86599e..b18b180 100644
80012--- a/kernel/events/core.c
80013+++ b/kernel/events/core.c
80014@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80015 * 0 - disallow raw tracepoint access for unpriv
80016 * 1 - disallow cpu events for unpriv
80017 * 2 - disallow kernel profiling for unpriv
80018+ * 3 - disallow all unpriv perf event use
80019 */
80020-int sysctl_perf_event_paranoid __read_mostly = 1;
80021+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80022+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80023+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80024+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80025+#else
80026+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80027+#endif
80028
80029 /* Minimum for 512 kiB + 1 user control page */
80030 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80031@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80032 update_perf_cpu_limits();
80033 }
80034
80035-static atomic64_t perf_event_id;
80036+static atomic64_unchecked_t perf_event_id;
80037
80038 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80039 enum event_type_t event_type);
80040@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80041
80042 static inline u64 perf_event_count(struct perf_event *event)
80043 {
80044- return local64_read(&event->count) + atomic64_read(&event->child_count);
80045+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80046 }
80047
80048 static u64 perf_event_read(struct perf_event *event)
80049@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80050 mutex_lock(&event->child_mutex);
80051 total += perf_event_read(event);
80052 *enabled += event->total_time_enabled +
80053- atomic64_read(&event->child_total_time_enabled);
80054+ atomic64_read_unchecked(&event->child_total_time_enabled);
80055 *running += event->total_time_running +
80056- atomic64_read(&event->child_total_time_running);
80057+ atomic64_read_unchecked(&event->child_total_time_running);
80058
80059 list_for_each_entry(child, &event->child_list, child_list) {
80060 total += perf_event_read(child);
80061@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80062 userpg->offset -= local64_read(&event->hw.prev_count);
80063
80064 userpg->time_enabled = enabled +
80065- atomic64_read(&event->child_total_time_enabled);
80066+ atomic64_read_unchecked(&event->child_total_time_enabled);
80067
80068 userpg->time_running = running +
80069- atomic64_read(&event->child_total_time_running);
80070+ atomic64_read_unchecked(&event->child_total_time_running);
80071
80072 arch_perf_update_userpage(userpg, now);
80073
80074@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80075
80076 /* Data. */
80077 sp = perf_user_stack_pointer(regs);
80078- rem = __output_copy_user(handle, (void *) sp, dump_size);
80079+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80080 dyn_size = dump_size - rem;
80081
80082 perf_output_skip(handle, rem);
80083@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80084 values[n++] = perf_event_count(event);
80085 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80086 values[n++] = enabled +
80087- atomic64_read(&event->child_total_time_enabled);
80088+ atomic64_read_unchecked(&event->child_total_time_enabled);
80089 }
80090 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80091 values[n++] = running +
80092- atomic64_read(&event->child_total_time_running);
80093+ atomic64_read_unchecked(&event->child_total_time_running);
80094 }
80095 if (read_format & PERF_FORMAT_ID)
80096 values[n++] = primary_event_id(event);
80097@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80098 * need to add enough zero bytes after the string to handle
80099 * the 64bit alignment we do later.
80100 */
80101- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80102+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80103 if (!buf) {
80104 name = strncpy(tmp, "//enomem", sizeof(tmp));
80105 goto got_name;
80106 }
80107- name = d_path(&file->f_path, buf, PATH_MAX);
80108+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80109 if (IS_ERR(name)) {
80110 name = strncpy(tmp, "//toolong", sizeof(tmp));
80111 goto got_name;
80112@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80113 event->parent = parent_event;
80114
80115 event->ns = get_pid_ns(task_active_pid_ns(current));
80116- event->id = atomic64_inc_return(&perf_event_id);
80117+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80118
80119 event->state = PERF_EVENT_STATE_INACTIVE;
80120
80121@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80122 if (flags & ~PERF_FLAG_ALL)
80123 return -EINVAL;
80124
80125+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80126+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80127+ return -EACCES;
80128+#endif
80129+
80130 err = perf_copy_attr(attr_uptr, &attr);
80131 if (err)
80132 return err;
80133@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80134 /*
80135 * Add back the child's count to the parent's count:
80136 */
80137- atomic64_add(child_val, &parent_event->child_count);
80138- atomic64_add(child_event->total_time_enabled,
80139+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80140+ atomic64_add_unchecked(child_event->total_time_enabled,
80141 &parent_event->child_total_time_enabled);
80142- atomic64_add(child_event->total_time_running,
80143+ atomic64_add_unchecked(child_event->total_time_running,
80144 &parent_event->child_total_time_running);
80145
80146 /*
80147diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80148index ca65997..60df03d 100644
80149--- a/kernel/events/internal.h
80150+++ b/kernel/events/internal.h
80151@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80152 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80153 }
80154
80155-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80156-static inline unsigned int \
80157+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80158+static inline unsigned long \
80159 func_name(struct perf_output_handle *handle, \
80160- const void *buf, unsigned int len) \
80161+ const void user *buf, unsigned long len) \
80162 { \
80163 unsigned long size, written; \
80164 \
80165@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80166 return n;
80167 }
80168
80169-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80170+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80171
80172 #define MEMCPY_SKIP(dst, src, n) (n)
80173
80174-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80175+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80176
80177 #ifndef arch_perf_out_copy_user
80178 #define arch_perf_out_copy_user __copy_from_user_inatomic
80179 #endif
80180
80181-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80182+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80183
80184 /* Callchain handling */
80185 extern struct perf_callchain_entry *
80186diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80187index ad8e1bd..fed7ba9 100644
80188--- a/kernel/events/uprobes.c
80189+++ b/kernel/events/uprobes.c
80190@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80191 {
80192 struct page *page;
80193 uprobe_opcode_t opcode;
80194- int result;
80195+ long result;
80196
80197 pagefault_disable();
80198 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80199diff --git a/kernel/exit.c b/kernel/exit.c
80200index a949819..a5f127d 100644
80201--- a/kernel/exit.c
80202+++ b/kernel/exit.c
80203@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80204 struct task_struct *leader;
80205 int zap_leader;
80206 repeat:
80207+#ifdef CONFIG_NET
80208+ gr_del_task_from_ip_table(p);
80209+#endif
80210+
80211 /* don't need to get the RCU readlock here - the process is dead and
80212 * can't be modifying its own credentials. But shut RCU-lockdep up */
80213 rcu_read_lock();
80214@@ -329,7 +333,7 @@ int allow_signal(int sig)
80215 * know it'll be handled, so that they don't get converted to
80216 * SIGKILL or just silently dropped.
80217 */
80218- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80219+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80220 recalc_sigpending();
80221 spin_unlock_irq(&current->sighand->siglock);
80222 return 0;
80223@@ -698,6 +702,8 @@ void do_exit(long code)
80224 struct task_struct *tsk = current;
80225 int group_dead;
80226
80227+ set_fs(USER_DS);
80228+
80229 profile_task_exit(tsk);
80230
80231 WARN_ON(blk_needs_flush_plug(tsk));
80232@@ -714,7 +720,6 @@ void do_exit(long code)
80233 * mm_release()->clear_child_tid() from writing to a user-controlled
80234 * kernel address.
80235 */
80236- set_fs(USER_DS);
80237
80238 ptrace_event(PTRACE_EVENT_EXIT, code);
80239
80240@@ -773,6 +778,9 @@ void do_exit(long code)
80241 tsk->exit_code = code;
80242 taskstats_exit(tsk, group_dead);
80243
80244+ gr_acl_handle_psacct(tsk, code);
80245+ gr_acl_handle_exit();
80246+
80247 exit_mm(tsk);
80248
80249 if (group_dead)
80250@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80251 * Take down every thread in the group. This is called by fatal signals
80252 * as well as by sys_exit_group (below).
80253 */
80254-void
80255+__noreturn void
80256 do_group_exit(int exit_code)
80257 {
80258 struct signal_struct *sig = current->signal;
80259diff --git a/kernel/fork.c b/kernel/fork.c
80260index 200a7a2..43e52da 100644
80261--- a/kernel/fork.c
80262+++ b/kernel/fork.c
80263@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80264 *stackend = STACK_END_MAGIC; /* for overflow detection */
80265
80266 #ifdef CONFIG_CC_STACKPROTECTOR
80267- tsk->stack_canary = get_random_int();
80268+ tsk->stack_canary = pax_get_random_long();
80269 #endif
80270
80271 /*
80272@@ -345,13 +345,81 @@ free_tsk:
80273 }
80274
80275 #ifdef CONFIG_MMU
80276-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80277+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80278 {
80279- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80280- struct rb_node **rb_link, *rb_parent;
80281- int retval;
80282+ struct vm_area_struct *tmp;
80283 unsigned long charge;
80284 struct mempolicy *pol;
80285+ struct file *file;
80286+
80287+ charge = 0;
80288+ if (mpnt->vm_flags & VM_ACCOUNT) {
80289+ unsigned long len = vma_pages(mpnt);
80290+
80291+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80292+ goto fail_nomem;
80293+ charge = len;
80294+ }
80295+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80296+ if (!tmp)
80297+ goto fail_nomem;
80298+ *tmp = *mpnt;
80299+ tmp->vm_mm = mm;
80300+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80301+ pol = mpol_dup(vma_policy(mpnt));
80302+ if (IS_ERR(pol))
80303+ goto fail_nomem_policy;
80304+ vma_set_policy(tmp, pol);
80305+ if (anon_vma_fork(tmp, mpnt))
80306+ goto fail_nomem_anon_vma_fork;
80307+ tmp->vm_flags &= ~VM_LOCKED;
80308+ tmp->vm_next = tmp->vm_prev = NULL;
80309+ tmp->vm_mirror = NULL;
80310+ file = tmp->vm_file;
80311+ if (file) {
80312+ struct inode *inode = file_inode(file);
80313+ struct address_space *mapping = file->f_mapping;
80314+
80315+ get_file(file);
80316+ if (tmp->vm_flags & VM_DENYWRITE)
80317+ atomic_dec(&inode->i_writecount);
80318+ mutex_lock(&mapping->i_mmap_mutex);
80319+ if (tmp->vm_flags & VM_SHARED)
80320+ mapping->i_mmap_writable++;
80321+ flush_dcache_mmap_lock(mapping);
80322+ /* insert tmp into the share list, just after mpnt */
80323+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80324+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80325+ else
80326+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80327+ flush_dcache_mmap_unlock(mapping);
80328+ mutex_unlock(&mapping->i_mmap_mutex);
80329+ }
80330+
80331+ /*
80332+ * Clear hugetlb-related page reserves for children. This only
80333+ * affects MAP_PRIVATE mappings. Faults generated by the child
80334+ * are not guaranteed to succeed, even if read-only
80335+ */
80336+ if (is_vm_hugetlb_page(tmp))
80337+ reset_vma_resv_huge_pages(tmp);
80338+
80339+ return tmp;
80340+
80341+fail_nomem_anon_vma_fork:
80342+ mpol_put(pol);
80343+fail_nomem_policy:
80344+ kmem_cache_free(vm_area_cachep, tmp);
80345+fail_nomem:
80346+ vm_unacct_memory(charge);
80347+ return NULL;
80348+}
80349+
80350+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80351+{
80352+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80353+ struct rb_node **rb_link, *rb_parent;
80354+ int retval;
80355
80356 uprobe_start_dup_mmap();
80357 down_write(&oldmm->mmap_sem);
80358@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80359
80360 prev = NULL;
80361 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80362- struct file *file;
80363-
80364 if (mpnt->vm_flags & VM_DONTCOPY) {
80365 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80366 -vma_pages(mpnt));
80367 continue;
80368 }
80369- charge = 0;
80370- if (mpnt->vm_flags & VM_ACCOUNT) {
80371- unsigned long len = vma_pages(mpnt);
80372-
80373- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80374- goto fail_nomem;
80375- charge = len;
80376- }
80377- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80378- if (!tmp)
80379- goto fail_nomem;
80380- *tmp = *mpnt;
80381- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80382- pol = mpol_dup(vma_policy(mpnt));
80383- retval = PTR_ERR(pol);
80384- if (IS_ERR(pol))
80385- goto fail_nomem_policy;
80386- vma_set_policy(tmp, pol);
80387- tmp->vm_mm = mm;
80388- if (anon_vma_fork(tmp, mpnt))
80389- goto fail_nomem_anon_vma_fork;
80390- tmp->vm_flags &= ~VM_LOCKED;
80391- tmp->vm_next = tmp->vm_prev = NULL;
80392- file = tmp->vm_file;
80393- if (file) {
80394- struct inode *inode = file_inode(file);
80395- struct address_space *mapping = file->f_mapping;
80396-
80397- get_file(file);
80398- if (tmp->vm_flags & VM_DENYWRITE)
80399- atomic_dec(&inode->i_writecount);
80400- mutex_lock(&mapping->i_mmap_mutex);
80401- if (tmp->vm_flags & VM_SHARED)
80402- mapping->i_mmap_writable++;
80403- flush_dcache_mmap_lock(mapping);
80404- /* insert tmp into the share list, just after mpnt */
80405- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80406- vma_nonlinear_insert(tmp,
80407- &mapping->i_mmap_nonlinear);
80408- else
80409- vma_interval_tree_insert_after(tmp, mpnt,
80410- &mapping->i_mmap);
80411- flush_dcache_mmap_unlock(mapping);
80412- mutex_unlock(&mapping->i_mmap_mutex);
80413+ tmp = dup_vma(mm, oldmm, mpnt);
80414+ if (!tmp) {
80415+ retval = -ENOMEM;
80416+ goto out;
80417 }
80418
80419 /*
80420@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80421 if (retval)
80422 goto out;
80423 }
80424+
80425+#ifdef CONFIG_PAX_SEGMEXEC
80426+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80427+ struct vm_area_struct *mpnt_m;
80428+
80429+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80430+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80431+
80432+ if (!mpnt->vm_mirror)
80433+ continue;
80434+
80435+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80436+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80437+ mpnt->vm_mirror = mpnt_m;
80438+ } else {
80439+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80440+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80441+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80442+ mpnt->vm_mirror->vm_mirror = mpnt;
80443+ }
80444+ }
80445+ BUG_ON(mpnt_m);
80446+ }
80447+#endif
80448+
80449 /* a new mm has just been created */
80450 arch_dup_mmap(oldmm, mm);
80451 retval = 0;
80452@@ -471,14 +522,6 @@ out:
80453 up_write(&oldmm->mmap_sem);
80454 uprobe_end_dup_mmap();
80455 return retval;
80456-fail_nomem_anon_vma_fork:
80457- mpol_put(pol);
80458-fail_nomem_policy:
80459- kmem_cache_free(vm_area_cachep, tmp);
80460-fail_nomem:
80461- retval = -ENOMEM;
80462- vm_unacct_memory(charge);
80463- goto out;
80464 }
80465
80466 static inline int mm_alloc_pgd(struct mm_struct *mm)
80467@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80468 return ERR_PTR(err);
80469
80470 mm = get_task_mm(task);
80471- if (mm && mm != current->mm &&
80472- !ptrace_may_access(task, mode)) {
80473+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80474+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80475 mmput(mm);
80476 mm = ERR_PTR(-EACCES);
80477 }
80478@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80479 spin_unlock(&fs->lock);
80480 return -EAGAIN;
80481 }
80482- fs->users++;
80483+ atomic_inc(&fs->users);
80484 spin_unlock(&fs->lock);
80485 return 0;
80486 }
80487 tsk->fs = copy_fs_struct(fs);
80488 if (!tsk->fs)
80489 return -ENOMEM;
80490+ /* Carry through gr_chroot_dentry and is_chrooted instead
80491+ of recomputing it here. Already copied when the task struct
80492+ is duplicated. This allows pivot_root to not be treated as
80493+ a chroot
80494+ */
80495+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80496+
80497 return 0;
80498 }
80499
80500@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80501 * parts of the process environment (as per the clone
80502 * flags). The actual kick-off is left to the caller.
80503 */
80504-static struct task_struct *copy_process(unsigned long clone_flags,
80505+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80506 unsigned long stack_start,
80507 unsigned long stack_size,
80508 int __user *child_tidptr,
80509@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80510 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80511 #endif
80512 retval = -EAGAIN;
80513+
80514+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80515+
80516 if (atomic_read(&p->real_cred->user->processes) >=
80517 task_rlimit(p, RLIMIT_NPROC)) {
80518 if (p->real_cred->user != INIT_USER &&
80519@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80520 goto bad_fork_free_pid;
80521 }
80522
80523+ /* synchronizes with gr_set_acls()
80524+ we need to call this past the point of no return for fork()
80525+ */
80526+ gr_copy_label(p);
80527+
80528 if (likely(p->pid)) {
80529 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80530
80531@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80532 bad_fork_free:
80533 free_task(p);
80534 fork_out:
80535+ gr_log_forkfail(retval);
80536+
80537 return ERR_PTR(retval);
80538 }
80539
80540@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80541
80542 p = copy_process(clone_flags, stack_start, stack_size,
80543 child_tidptr, NULL, trace);
80544+ add_latent_entropy();
80545 /*
80546 * Do this prior waking up the new thread - the thread pointer
80547 * might get invalid after that point, if the thread exits quickly.
80548@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80549 if (clone_flags & CLONE_PARENT_SETTID)
80550 put_user(nr, parent_tidptr);
80551
80552+ gr_handle_brute_check();
80553+
80554 if (clone_flags & CLONE_VFORK) {
80555 p->vfork_done = &vfork;
80556 init_completion(&vfork);
80557@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80558 mm_cachep = kmem_cache_create("mm_struct",
80559 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80560 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80561- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80562+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80563 mmap_init();
80564 nsproxy_cache_init();
80565 }
80566@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80567 return 0;
80568
80569 /* don't need lock here; in the worst case we'll do useless copy */
80570- if (fs->users == 1)
80571+ if (atomic_read(&fs->users) == 1)
80572 return 0;
80573
80574 *new_fsp = copy_fs_struct(fs);
80575@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80576 fs = current->fs;
80577 spin_lock(&fs->lock);
80578 current->fs = new_fs;
80579- if (--fs->users)
80580+ gr_set_chroot_entries(current, &current->fs->root);
80581+ if (atomic_dec_return(&fs->users))
80582 new_fs = NULL;
80583 else
80584 new_fs = fs;
80585diff --git a/kernel/futex.c b/kernel/futex.c
80586index c3a1a55..e32b4a98 100644
80587--- a/kernel/futex.c
80588+++ b/kernel/futex.c
80589@@ -54,6 +54,7 @@
80590 #include <linux/mount.h>
80591 #include <linux/pagemap.h>
80592 #include <linux/syscalls.h>
80593+#include <linux/ptrace.h>
80594 #include <linux/signal.h>
80595 #include <linux/export.h>
80596 #include <linux/magic.h>
80597@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80598 struct page *page, *page_head;
80599 int err, ro = 0;
80600
80601+#ifdef CONFIG_PAX_SEGMEXEC
80602+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80603+ return -EFAULT;
80604+#endif
80605+
80606 /*
80607 * The futex address must be "naturally" aligned.
80608 */
80609@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80610
80611 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80612 {
80613- int ret;
80614+ unsigned long ret;
80615
80616 pagefault_disable();
80617 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80618@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80619 {
80620 u32 curval;
80621 int i;
80622+ mm_segment_t oldfs;
80623
80624 /*
80625 * This will fail and we want it. Some arch implementations do
80626@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80627 * implementation, the non-functional ones will return
80628 * -ENOSYS.
80629 */
80630+ oldfs = get_fs();
80631+ set_fs(USER_DS);
80632 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80633 futex_cmpxchg_enabled = 1;
80634+ set_fs(oldfs);
80635
80636 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80637 plist_head_init(&futex_queues[i].chain);
80638diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80639index f9f44fd..29885e4 100644
80640--- a/kernel/futex_compat.c
80641+++ b/kernel/futex_compat.c
80642@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80643 return 0;
80644 }
80645
80646-static void __user *futex_uaddr(struct robust_list __user *entry,
80647+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80648 compat_long_t futex_offset)
80649 {
80650 compat_uptr_t base = ptr_to_compat(entry);
80651diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80652index 9b22d03..6295b62 100644
80653--- a/kernel/gcov/base.c
80654+++ b/kernel/gcov/base.c
80655@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80656 }
80657
80658 #ifdef CONFIG_MODULES
80659-static inline int within(void *addr, void *start, unsigned long size)
80660-{
80661- return ((addr >= start) && (addr < start + size));
80662-}
80663-
80664 /* Update list and generate events when modules are unloaded. */
80665 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80666 void *data)
80667@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80668 prev = NULL;
80669 /* Remove entries located in module from linked list. */
80670 for (info = gcov_info_head; info; info = info->next) {
80671- if (within(info, mod->module_core, mod->core_size)) {
80672+ if (within_module_core_rw((unsigned long)info, mod)) {
80673 if (prev)
80674 prev->next = info->next;
80675 else
80676diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80677index 383319b..56ebb13 100644
80678--- a/kernel/hrtimer.c
80679+++ b/kernel/hrtimer.c
80680@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80681 local_irq_restore(flags);
80682 }
80683
80684-static void run_hrtimer_softirq(struct softirq_action *h)
80685+static __latent_entropy void run_hrtimer_softirq(void)
80686 {
80687 hrtimer_peek_ahead_timers();
80688 }
80689diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80690index 55fcce6..0e4cf34 100644
80691--- a/kernel/irq_work.c
80692+++ b/kernel/irq_work.c
80693@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80694 return NOTIFY_OK;
80695 }
80696
80697-static struct notifier_block cpu_notify;
80698+static struct notifier_block cpu_notify = {
80699+ .notifier_call = irq_work_cpu_notify,
80700+ .priority = 0,
80701+};
80702
80703 static __init int irq_work_init_cpu_notifier(void)
80704 {
80705- cpu_notify.notifier_call = irq_work_cpu_notify;
80706- cpu_notify.priority = 0;
80707 register_cpu_notifier(&cpu_notify);
80708 return 0;
80709 }
80710diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80711index 60f48fa..7f3a770 100644
80712--- a/kernel/jump_label.c
80713+++ b/kernel/jump_label.c
80714@@ -13,6 +13,7 @@
80715 #include <linux/sort.h>
80716 #include <linux/err.h>
80717 #include <linux/static_key.h>
80718+#include <linux/mm.h>
80719
80720 #ifdef HAVE_JUMP_LABEL
80721
80722@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80723
80724 size = (((unsigned long)stop - (unsigned long)start)
80725 / sizeof(struct jump_entry));
80726+ pax_open_kernel();
80727 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80728+ pax_close_kernel();
80729 }
80730
80731 static void jump_label_update(struct static_key *key, int enable);
80732@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80733 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80734 struct jump_entry *iter;
80735
80736+ pax_open_kernel();
80737 for (iter = iter_start; iter < iter_stop; iter++) {
80738 if (within_module_init(iter->code, mod))
80739 iter->code = 0;
80740 }
80741+ pax_close_kernel();
80742 }
80743
80744 static int
80745diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80746index 3127ad5..159d880 100644
80747--- a/kernel/kallsyms.c
80748+++ b/kernel/kallsyms.c
80749@@ -11,6 +11,9 @@
80750 * Changed the compression method from stem compression to "table lookup"
80751 * compression (see scripts/kallsyms.c for a more complete description)
80752 */
80753+#ifdef CONFIG_GRKERNSEC_HIDESYM
80754+#define __INCLUDED_BY_HIDESYM 1
80755+#endif
80756 #include <linux/kallsyms.h>
80757 #include <linux/module.h>
80758 #include <linux/init.h>
80759@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80760
80761 static inline int is_kernel_inittext(unsigned long addr)
80762 {
80763+ if (system_state != SYSTEM_BOOTING)
80764+ return 0;
80765+
80766 if (addr >= (unsigned long)_sinittext
80767 && addr <= (unsigned long)_einittext)
80768 return 1;
80769 return 0;
80770 }
80771
80772+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80773+#ifdef CONFIG_MODULES
80774+static inline int is_module_text(unsigned long addr)
80775+{
80776+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80777+ return 1;
80778+
80779+ addr = ktla_ktva(addr);
80780+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80781+}
80782+#else
80783+static inline int is_module_text(unsigned long addr)
80784+{
80785+ return 0;
80786+}
80787+#endif
80788+#endif
80789+
80790 static inline int is_kernel_text(unsigned long addr)
80791 {
80792 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80793@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80794
80795 static inline int is_kernel(unsigned long addr)
80796 {
80797+
80798+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80799+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80800+ return 1;
80801+
80802+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80803+#else
80804 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80805+#endif
80806+
80807 return 1;
80808 return in_gate_area_no_mm(addr);
80809 }
80810
80811 static int is_ksym_addr(unsigned long addr)
80812 {
80813+
80814+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80815+ if (is_module_text(addr))
80816+ return 0;
80817+#endif
80818+
80819 if (all_var)
80820 return is_kernel(addr);
80821
80822@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80823
80824 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80825 {
80826- iter->name[0] = '\0';
80827 iter->nameoff = get_symbol_offset(new_pos);
80828 iter->pos = new_pos;
80829 }
80830@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80831 {
80832 struct kallsym_iter *iter = m->private;
80833
80834+#ifdef CONFIG_GRKERNSEC_HIDESYM
80835+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80836+ return 0;
80837+#endif
80838+
80839 /* Some debugging symbols have no name. Ignore them. */
80840 if (!iter->name[0])
80841 return 0;
80842@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80843 */
80844 type = iter->exported ? toupper(iter->type) :
80845 tolower(iter->type);
80846+
80847 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80848 type, iter->name, iter->module_name);
80849 } else
80850@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80851 struct kallsym_iter *iter;
80852 int ret;
80853
80854- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80855+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80856 if (!iter)
80857 return -ENOMEM;
80858 reset_iter(iter, 0);
80859diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80860index e30ac0f..3528cac 100644
80861--- a/kernel/kcmp.c
80862+++ b/kernel/kcmp.c
80863@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80864 struct task_struct *task1, *task2;
80865 int ret;
80866
80867+#ifdef CONFIG_GRKERNSEC
80868+ return -ENOSYS;
80869+#endif
80870+
80871 rcu_read_lock();
80872
80873 /*
80874diff --git a/kernel/kexec.c b/kernel/kexec.c
80875index 59f7b55..4022f65 100644
80876--- a/kernel/kexec.c
80877+++ b/kernel/kexec.c
80878@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80879 unsigned long flags)
80880 {
80881 struct compat_kexec_segment in;
80882- struct kexec_segment out, __user *ksegments;
80883+ struct kexec_segment out;
80884+ struct kexec_segment __user *ksegments;
80885 unsigned long i, result;
80886
80887 /* Don't allow clients that don't understand the native
80888diff --git a/kernel/kmod.c b/kernel/kmod.c
80889index b086006..a27913b 100644
80890--- a/kernel/kmod.c
80891+++ b/kernel/kmod.c
80892@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80893 kfree(info->argv);
80894 }
80895
80896-static int call_modprobe(char *module_name, int wait)
80897+static int call_modprobe(char *module_name, char *module_param, int wait)
80898 {
80899 struct subprocess_info *info;
80900 static char *envp[] = {
80901@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80902 NULL
80903 };
80904
80905- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80906+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80907 if (!argv)
80908 goto out;
80909
80910@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80911 argv[1] = "-q";
80912 argv[2] = "--";
80913 argv[3] = module_name; /* check free_modprobe_argv() */
80914- argv[4] = NULL;
80915+ argv[4] = module_param;
80916+ argv[5] = NULL;
80917
80918 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80919 NULL, free_modprobe_argv, NULL);
80920@@ -129,9 +130,8 @@ out:
80921 * If module auto-loading support is disabled then this function
80922 * becomes a no-operation.
80923 */
80924-int __request_module(bool wait, const char *fmt, ...)
80925+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80926 {
80927- va_list args;
80928 char module_name[MODULE_NAME_LEN];
80929 unsigned int max_modprobes;
80930 int ret;
80931@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80932 if (!modprobe_path[0])
80933 return 0;
80934
80935- va_start(args, fmt);
80936- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80937- va_end(args);
80938+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80939 if (ret >= MODULE_NAME_LEN)
80940 return -ENAMETOOLONG;
80941
80942@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80943 if (ret)
80944 return ret;
80945
80946+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80947+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80948+ /* hack to workaround consolekit/udisks stupidity */
80949+ read_lock(&tasklist_lock);
80950+ if (!strcmp(current->comm, "mount") &&
80951+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80952+ read_unlock(&tasklist_lock);
80953+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80954+ return -EPERM;
80955+ }
80956+ read_unlock(&tasklist_lock);
80957+ }
80958+#endif
80959+
80960 /* If modprobe needs a service that is in a module, we get a recursive
80961 * loop. Limit the number of running kmod threads to max_threads/2 or
80962 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80963@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80964
80965 trace_module_request(module_name, wait, _RET_IP_);
80966
80967- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80968+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80969
80970 atomic_dec(&kmod_concurrent);
80971 return ret;
80972 }
80973+
80974+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80975+{
80976+ va_list args;
80977+ int ret;
80978+
80979+ va_start(args, fmt);
80980+ ret = ____request_module(wait, module_param, fmt, args);
80981+ va_end(args);
80982+
80983+ return ret;
80984+}
80985+
80986+int __request_module(bool wait, const char *fmt, ...)
80987+{
80988+ va_list args;
80989+ int ret;
80990+
80991+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80992+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80993+ char module_param[MODULE_NAME_LEN];
80994+
80995+ memset(module_param, 0, sizeof(module_param));
80996+
80997+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80998+
80999+ va_start(args, fmt);
81000+ ret = ____request_module(wait, module_param, fmt, args);
81001+ va_end(args);
81002+
81003+ return ret;
81004+ }
81005+#endif
81006+
81007+ va_start(args, fmt);
81008+ ret = ____request_module(wait, NULL, fmt, args);
81009+ va_end(args);
81010+
81011+ return ret;
81012+}
81013+
81014 EXPORT_SYMBOL(__request_module);
81015 #endif /* CONFIG_MODULES */
81016
81017@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81018 *
81019 * Thus the __user pointer cast is valid here.
81020 */
81021- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81022+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81023
81024 /*
81025 * If ret is 0, either ____call_usermodehelper failed and the
81026@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81027 static int proc_cap_handler(struct ctl_table *table, int write,
81028 void __user *buffer, size_t *lenp, loff_t *ppos)
81029 {
81030- struct ctl_table t;
81031+ ctl_table_no_const t;
81032 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81033 kernel_cap_t new_cap;
81034 int err, i;
81035diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81036index 6e33498..3133bd3 100644
81037--- a/kernel/kprobes.c
81038+++ b/kernel/kprobes.c
81039@@ -31,6 +31,9 @@
81040 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81041 * <prasanna@in.ibm.com> added function-return probes.
81042 */
81043+#ifdef CONFIG_GRKERNSEC_HIDESYM
81044+#define __INCLUDED_BY_HIDESYM 1
81045+#endif
81046 #include <linux/kprobes.h>
81047 #include <linux/hash.h>
81048 #include <linux/init.h>
81049@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81050 * kernel image and loaded module images reside. This is required
81051 * so x86_64 can correctly handle the %rip-relative fixups.
81052 */
81053- kip->insns = module_alloc(PAGE_SIZE);
81054+ kip->insns = module_alloc_exec(PAGE_SIZE);
81055 if (!kip->insns) {
81056 kfree(kip);
81057 return NULL;
81058@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81059 */
81060 if (!list_is_singular(&kip->list)) {
81061 list_del(&kip->list);
81062- module_free(NULL, kip->insns);
81063+ module_free_exec(NULL, kip->insns);
81064 kfree(kip);
81065 }
81066 return 1;
81067@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81068 {
81069 int i, err = 0;
81070 unsigned long offset = 0, size = 0;
81071- char *modname, namebuf[128];
81072+ char *modname, namebuf[KSYM_NAME_LEN];
81073 const char *symbol_name;
81074 void *addr;
81075 struct kprobe_blackpoint *kb;
81076@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81077 kprobe_type = "k";
81078
81079 if (sym)
81080- seq_printf(pi, "%p %s %s+0x%x %s ",
81081+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81082 p->addr, kprobe_type, sym, offset,
81083 (modname ? modname : " "));
81084 else
81085- seq_printf(pi, "%p %s %p ",
81086+ seq_printf(pi, "%pK %s %pK ",
81087 p->addr, kprobe_type, p->addr);
81088
81089 if (!pp)
81090@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81091 const char *sym = NULL;
81092 unsigned int i = *(loff_t *) v;
81093 unsigned long offset = 0;
81094- char *modname, namebuf[128];
81095+ char *modname, namebuf[KSYM_NAME_LEN];
81096
81097 head = &kprobe_table[i];
81098 preempt_disable();
81099diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81100index 6ada93c..dce7d5d 100644
81101--- a/kernel/ksysfs.c
81102+++ b/kernel/ksysfs.c
81103@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81104 {
81105 if (count+1 > UEVENT_HELPER_PATH_LEN)
81106 return -ENOENT;
81107+ if (!capable(CAP_SYS_ADMIN))
81108+ return -EPERM;
81109 memcpy(uevent_helper, buf, count);
81110 uevent_helper[count] = '\0';
81111 if (count && uevent_helper[count-1] == '\n')
81112@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81113 return count;
81114 }
81115
81116-static struct bin_attribute notes_attr = {
81117+static bin_attribute_no_const notes_attr __read_only = {
81118 .attr = {
81119 .name = "notes",
81120 .mode = S_IRUGO,
81121diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81122index e16c45b..6f49c48 100644
81123--- a/kernel/lockdep.c
81124+++ b/kernel/lockdep.c
81125@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81126 end = (unsigned long) &_end,
81127 addr = (unsigned long) obj;
81128
81129+#ifdef CONFIG_PAX_KERNEXEC
81130+ start = ktla_ktva(start);
81131+#endif
81132+
81133 /*
81134 * static variable?
81135 */
81136@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81137 if (!static_obj(lock->key)) {
81138 debug_locks_off();
81139 printk("INFO: trying to register non-static key.\n");
81140+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81141 printk("the code is fine but needs lockdep annotation.\n");
81142 printk("turning off the locking correctness validator.\n");
81143 dump_stack();
81144@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81145 if (!class)
81146 return 0;
81147 }
81148- atomic_inc((atomic_t *)&class->ops);
81149+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81150 if (very_verbose(class)) {
81151 printk("\nacquire class [%p] %s", class->key, class->name);
81152 if (class->name_version > 1)
81153diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81154index b2c71c5..7b88d63 100644
81155--- a/kernel/lockdep_proc.c
81156+++ b/kernel/lockdep_proc.c
81157@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81158 return 0;
81159 }
81160
81161- seq_printf(m, "%p", class->key);
81162+ seq_printf(m, "%pK", class->key);
81163 #ifdef CONFIG_DEBUG_LOCKDEP
81164 seq_printf(m, " OPS:%8ld", class->ops);
81165 #endif
81166@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81167
81168 list_for_each_entry(entry, &class->locks_after, entry) {
81169 if (entry->distance == 1) {
81170- seq_printf(m, " -> [%p] ", entry->class->key);
81171+ seq_printf(m, " -> [%pK] ", entry->class->key);
81172 print_name(m, entry->class);
81173 seq_puts(m, "\n");
81174 }
81175@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81176 if (!class->key)
81177 continue;
81178
81179- seq_printf(m, "[%p] ", class->key);
81180+ seq_printf(m, "[%pK] ", class->key);
81181 print_name(m, class);
81182 seq_puts(m, "\n");
81183 }
81184@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81185 if (!i)
81186 seq_line(m, '-', 40-namelen, namelen);
81187
81188- snprintf(ip, sizeof(ip), "[<%p>]",
81189+ snprintf(ip, sizeof(ip), "[<%pK>]",
81190 (void *)class->contention_point[i]);
81191 seq_printf(m, "%40s %14lu %29s %pS\n",
81192 name, stats->contention_point[i],
81193@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81194 if (!i)
81195 seq_line(m, '-', 40-namelen, namelen);
81196
81197- snprintf(ip, sizeof(ip), "[<%p>]",
81198+ snprintf(ip, sizeof(ip), "[<%pK>]",
81199 (void *)class->contending_point[i]);
81200 seq_printf(m, "%40s %14lu %29s %pS\n",
81201 name, stats->contending_point[i],
81202diff --git a/kernel/module.c b/kernel/module.c
81203index 2069158..71101bb 100644
81204--- a/kernel/module.c
81205+++ b/kernel/module.c
81206@@ -61,6 +61,7 @@
81207 #include <linux/pfn.h>
81208 #include <linux/bsearch.h>
81209 #include <linux/fips.h>
81210+#include <linux/grsecurity.h>
81211 #include <uapi/linux/module.h>
81212 #include "module-internal.h"
81213
81214@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81215
81216 /* Bounds of module allocation, for speeding __module_address.
81217 * Protected by module_mutex. */
81218-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81219+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81220+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81221
81222 int register_module_notifier(struct notifier_block * nb)
81223 {
81224@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81225 return true;
81226
81227 list_for_each_entry_rcu(mod, &modules, list) {
81228- struct symsearch arr[] = {
81229+ struct symsearch modarr[] = {
81230 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81231 NOT_GPL_ONLY, false },
81232 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81233@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81234 if (mod->state == MODULE_STATE_UNFORMED)
81235 continue;
81236
81237- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81238+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81239 return true;
81240 }
81241 return false;
81242@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81243 if (!pcpusec->sh_size)
81244 return 0;
81245
81246- if (align > PAGE_SIZE) {
81247+ if (align-1 >= PAGE_SIZE) {
81248 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81249 mod->name, align, PAGE_SIZE);
81250 align = PAGE_SIZE;
81251@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81252 static ssize_t show_coresize(struct module_attribute *mattr,
81253 struct module_kobject *mk, char *buffer)
81254 {
81255- return sprintf(buffer, "%u\n", mk->mod->core_size);
81256+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81257 }
81258
81259 static struct module_attribute modinfo_coresize =
81260@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81261 static ssize_t show_initsize(struct module_attribute *mattr,
81262 struct module_kobject *mk, char *buffer)
81263 {
81264- return sprintf(buffer, "%u\n", mk->mod->init_size);
81265+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81266 }
81267
81268 static struct module_attribute modinfo_initsize =
81269@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81270 */
81271 #ifdef CONFIG_SYSFS
81272
81273-#ifdef CONFIG_KALLSYMS
81274+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81275 static inline bool sect_empty(const Elf_Shdr *sect)
81276 {
81277 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81278@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81279 {
81280 unsigned int notes, loaded, i;
81281 struct module_notes_attrs *notes_attrs;
81282- struct bin_attribute *nattr;
81283+ bin_attribute_no_const *nattr;
81284
81285 /* failed to create section attributes, so can't create notes */
81286 if (!mod->sect_attrs)
81287@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81288 static int module_add_modinfo_attrs(struct module *mod)
81289 {
81290 struct module_attribute *attr;
81291- struct module_attribute *temp_attr;
81292+ module_attribute_no_const *temp_attr;
81293 int error = 0;
81294 int i;
81295
81296@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81297
81298 static void unset_module_core_ro_nx(struct module *mod)
81299 {
81300- set_page_attributes(mod->module_core + mod->core_text_size,
81301- mod->module_core + mod->core_size,
81302+ set_page_attributes(mod->module_core_rw,
81303+ mod->module_core_rw + mod->core_size_rw,
81304 set_memory_x);
81305- set_page_attributes(mod->module_core,
81306- mod->module_core + mod->core_ro_size,
81307+ set_page_attributes(mod->module_core_rx,
81308+ mod->module_core_rx + mod->core_size_rx,
81309 set_memory_rw);
81310 }
81311
81312 static void unset_module_init_ro_nx(struct module *mod)
81313 {
81314- set_page_attributes(mod->module_init + mod->init_text_size,
81315- mod->module_init + mod->init_size,
81316+ set_page_attributes(mod->module_init_rw,
81317+ mod->module_init_rw + mod->init_size_rw,
81318 set_memory_x);
81319- set_page_attributes(mod->module_init,
81320- mod->module_init + mod->init_ro_size,
81321+ set_page_attributes(mod->module_init_rx,
81322+ mod->module_init_rx + mod->init_size_rx,
81323 set_memory_rw);
81324 }
81325
81326@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81327 list_for_each_entry_rcu(mod, &modules, list) {
81328 if (mod->state == MODULE_STATE_UNFORMED)
81329 continue;
81330- if ((mod->module_core) && (mod->core_text_size)) {
81331- set_page_attributes(mod->module_core,
81332- mod->module_core + mod->core_text_size,
81333+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81334+ set_page_attributes(mod->module_core_rx,
81335+ mod->module_core_rx + mod->core_size_rx,
81336 set_memory_rw);
81337 }
81338- if ((mod->module_init) && (mod->init_text_size)) {
81339- set_page_attributes(mod->module_init,
81340- mod->module_init + mod->init_text_size,
81341+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81342+ set_page_attributes(mod->module_init_rx,
81343+ mod->module_init_rx + mod->init_size_rx,
81344 set_memory_rw);
81345 }
81346 }
81347@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81348 list_for_each_entry_rcu(mod, &modules, list) {
81349 if (mod->state == MODULE_STATE_UNFORMED)
81350 continue;
81351- if ((mod->module_core) && (mod->core_text_size)) {
81352- set_page_attributes(mod->module_core,
81353- mod->module_core + mod->core_text_size,
81354+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81355+ set_page_attributes(mod->module_core_rx,
81356+ mod->module_core_rx + mod->core_size_rx,
81357 set_memory_ro);
81358 }
81359- if ((mod->module_init) && (mod->init_text_size)) {
81360- set_page_attributes(mod->module_init,
81361- mod->module_init + mod->init_text_size,
81362+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81363+ set_page_attributes(mod->module_init_rx,
81364+ mod->module_init_rx + mod->init_size_rx,
81365 set_memory_ro);
81366 }
81367 }
81368@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81369
81370 /* This may be NULL, but that's OK */
81371 unset_module_init_ro_nx(mod);
81372- module_free(mod, mod->module_init);
81373+ module_free(mod, mod->module_init_rw);
81374+ module_free_exec(mod, mod->module_init_rx);
81375 kfree(mod->args);
81376 percpu_modfree(mod);
81377
81378 /* Free lock-classes: */
81379- lockdep_free_key_range(mod->module_core, mod->core_size);
81380+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81381+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81382
81383 /* Finally, free the core (containing the module structure) */
81384 unset_module_core_ro_nx(mod);
81385- module_free(mod, mod->module_core);
81386+ module_free_exec(mod, mod->module_core_rx);
81387+ module_free(mod, mod->module_core_rw);
81388
81389 #ifdef CONFIG_MPU
81390 update_protections(current->mm);
81391@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81392 int ret = 0;
81393 const struct kernel_symbol *ksym;
81394
81395+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81396+ int is_fs_load = 0;
81397+ int register_filesystem_found = 0;
81398+ char *p;
81399+
81400+ p = strstr(mod->args, "grsec_modharden_fs");
81401+ if (p) {
81402+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81403+ /* copy \0 as well */
81404+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81405+ is_fs_load = 1;
81406+ }
81407+#endif
81408+
81409 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81410 const char *name = info->strtab + sym[i].st_name;
81411
81412+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81413+ /* it's a real shame this will never get ripped and copied
81414+ upstream! ;(
81415+ */
81416+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81417+ register_filesystem_found = 1;
81418+#endif
81419+
81420 switch (sym[i].st_shndx) {
81421 case SHN_COMMON:
81422 /* We compiled with -fno-common. These are not
81423@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81424 ksym = resolve_symbol_wait(mod, info, name);
81425 /* Ok if resolved. */
81426 if (ksym && !IS_ERR(ksym)) {
81427+ pax_open_kernel();
81428 sym[i].st_value = ksym->value;
81429+ pax_close_kernel();
81430 break;
81431 }
81432
81433@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81434 secbase = (unsigned long)mod_percpu(mod);
81435 else
81436 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81437+ pax_open_kernel();
81438 sym[i].st_value += secbase;
81439+ pax_close_kernel();
81440 break;
81441 }
81442 }
81443
81444+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81445+ if (is_fs_load && !register_filesystem_found) {
81446+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81447+ ret = -EPERM;
81448+ }
81449+#endif
81450+
81451 return ret;
81452 }
81453
81454@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81455 || s->sh_entsize != ~0UL
81456 || strstarts(sname, ".init"))
81457 continue;
81458- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81459+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81460+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81461+ else
81462+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81463 pr_debug("\t%s\n", sname);
81464 }
81465- switch (m) {
81466- case 0: /* executable */
81467- mod->core_size = debug_align(mod->core_size);
81468- mod->core_text_size = mod->core_size;
81469- break;
81470- case 1: /* RO: text and ro-data */
81471- mod->core_size = debug_align(mod->core_size);
81472- mod->core_ro_size = mod->core_size;
81473- break;
81474- case 3: /* whole core */
81475- mod->core_size = debug_align(mod->core_size);
81476- break;
81477- }
81478 }
81479
81480 pr_debug("Init section allocation order:\n");
81481@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81482 || s->sh_entsize != ~0UL
81483 || !strstarts(sname, ".init"))
81484 continue;
81485- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81486- | INIT_OFFSET_MASK);
81487+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81488+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81489+ else
81490+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81491+ s->sh_entsize |= INIT_OFFSET_MASK;
81492 pr_debug("\t%s\n", sname);
81493 }
81494- switch (m) {
81495- case 0: /* executable */
81496- mod->init_size = debug_align(mod->init_size);
81497- mod->init_text_size = mod->init_size;
81498- break;
81499- case 1: /* RO: text and ro-data */
81500- mod->init_size = debug_align(mod->init_size);
81501- mod->init_ro_size = mod->init_size;
81502- break;
81503- case 3: /* whole init */
81504- mod->init_size = debug_align(mod->init_size);
81505- break;
81506- }
81507 }
81508 }
81509
81510@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81511
81512 /* Put symbol section at end of init part of module. */
81513 symsect->sh_flags |= SHF_ALLOC;
81514- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81515+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81516 info->index.sym) | INIT_OFFSET_MASK;
81517 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81518
81519@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81520 }
81521
81522 /* Append room for core symbols at end of core part. */
81523- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81524- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81525- mod->core_size += strtab_size;
81526+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81527+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81528+ mod->core_size_rx += strtab_size;
81529
81530 /* Put string table section at end of init part of module. */
81531 strsect->sh_flags |= SHF_ALLOC;
81532- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81533+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81534 info->index.str) | INIT_OFFSET_MASK;
81535 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81536 }
81537@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81538 /* Make sure we get permanent strtab: don't use info->strtab. */
81539 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81540
81541+ pax_open_kernel();
81542+
81543 /* Set types up while we still have access to sections. */
81544 for (i = 0; i < mod->num_symtab; i++)
81545 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81546
81547- mod->core_symtab = dst = mod->module_core + info->symoffs;
81548- mod->core_strtab = s = mod->module_core + info->stroffs;
81549+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81550+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81551 src = mod->symtab;
81552 for (ndst = i = 0; i < mod->num_symtab; i++) {
81553 if (i == 0 ||
81554@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81555 }
81556 }
81557 mod->core_num_syms = ndst;
81558+
81559+ pax_close_kernel();
81560 }
81561 #else
81562 static inline void layout_symtab(struct module *mod, struct load_info *info)
81563@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81564 return vmalloc_exec(size);
81565 }
81566
81567-static void *module_alloc_update_bounds(unsigned long size)
81568+static void *module_alloc_update_bounds_rw(unsigned long size)
81569 {
81570 void *ret = module_alloc(size);
81571
81572 if (ret) {
81573 mutex_lock(&module_mutex);
81574 /* Update module bounds. */
81575- if ((unsigned long)ret < module_addr_min)
81576- module_addr_min = (unsigned long)ret;
81577- if ((unsigned long)ret + size > module_addr_max)
81578- module_addr_max = (unsigned long)ret + size;
81579+ if ((unsigned long)ret < module_addr_min_rw)
81580+ module_addr_min_rw = (unsigned long)ret;
81581+ if ((unsigned long)ret + size > module_addr_max_rw)
81582+ module_addr_max_rw = (unsigned long)ret + size;
81583+ mutex_unlock(&module_mutex);
81584+ }
81585+ return ret;
81586+}
81587+
81588+static void *module_alloc_update_bounds_rx(unsigned long size)
81589+{
81590+ void *ret = module_alloc_exec(size);
81591+
81592+ if (ret) {
81593+ mutex_lock(&module_mutex);
81594+ /* Update module bounds. */
81595+ if ((unsigned long)ret < module_addr_min_rx)
81596+ module_addr_min_rx = (unsigned long)ret;
81597+ if ((unsigned long)ret + size > module_addr_max_rx)
81598+ module_addr_max_rx = (unsigned long)ret + size;
81599 mutex_unlock(&module_mutex);
81600 }
81601 return ret;
81602@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81603 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81604 {
81605 const char *modmagic = get_modinfo(info, "vermagic");
81606+ const char *license = get_modinfo(info, "license");
81607 int err;
81608
81609+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81610+ if (!license || !license_is_gpl_compatible(license))
81611+ return -ENOEXEC;
81612+#endif
81613+
81614 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81615 modmagic = NULL;
81616
81617@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81618 }
81619
81620 /* Set up license info based on the info section */
81621- set_license(mod, get_modinfo(info, "license"));
81622+ set_license(mod, license);
81623
81624 return 0;
81625 }
81626@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81627 void *ptr;
81628
81629 /* Do the allocs. */
81630- ptr = module_alloc_update_bounds(mod->core_size);
81631+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81632 /*
81633 * The pointer to this block is stored in the module structure
81634 * which is inside the block. Just mark it as not being a
81635@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81636 if (!ptr)
81637 return -ENOMEM;
81638
81639- memset(ptr, 0, mod->core_size);
81640- mod->module_core = ptr;
81641+ memset(ptr, 0, mod->core_size_rw);
81642+ mod->module_core_rw = ptr;
81643
81644- if (mod->init_size) {
81645- ptr = module_alloc_update_bounds(mod->init_size);
81646+ if (mod->init_size_rw) {
81647+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81648 /*
81649 * The pointer to this block is stored in the module structure
81650 * which is inside the block. This block doesn't need to be
81651@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81652 */
81653 kmemleak_ignore(ptr);
81654 if (!ptr) {
81655- module_free(mod, mod->module_core);
81656+ module_free(mod, mod->module_core_rw);
81657 return -ENOMEM;
81658 }
81659- memset(ptr, 0, mod->init_size);
81660- mod->module_init = ptr;
81661+ memset(ptr, 0, mod->init_size_rw);
81662+ mod->module_init_rw = ptr;
81663 } else
81664- mod->module_init = NULL;
81665+ mod->module_init_rw = NULL;
81666+
81667+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81668+ kmemleak_not_leak(ptr);
81669+ if (!ptr) {
81670+ if (mod->module_init_rw)
81671+ module_free(mod, mod->module_init_rw);
81672+ module_free(mod, mod->module_core_rw);
81673+ return -ENOMEM;
81674+ }
81675+
81676+ pax_open_kernel();
81677+ memset(ptr, 0, mod->core_size_rx);
81678+ pax_close_kernel();
81679+ mod->module_core_rx = ptr;
81680+
81681+ if (mod->init_size_rx) {
81682+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81683+ kmemleak_ignore(ptr);
81684+ if (!ptr && mod->init_size_rx) {
81685+ module_free_exec(mod, mod->module_core_rx);
81686+ if (mod->module_init_rw)
81687+ module_free(mod, mod->module_init_rw);
81688+ module_free(mod, mod->module_core_rw);
81689+ return -ENOMEM;
81690+ }
81691+
81692+ pax_open_kernel();
81693+ memset(ptr, 0, mod->init_size_rx);
81694+ pax_close_kernel();
81695+ mod->module_init_rx = ptr;
81696+ } else
81697+ mod->module_init_rx = NULL;
81698
81699 /* Transfer each section which specifies SHF_ALLOC */
81700 pr_debug("final section addresses:\n");
81701@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81702 if (!(shdr->sh_flags & SHF_ALLOC))
81703 continue;
81704
81705- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81706- dest = mod->module_init
81707- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81708- else
81709- dest = mod->module_core + shdr->sh_entsize;
81710+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81711+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81712+ dest = mod->module_init_rw
81713+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81714+ else
81715+ dest = mod->module_init_rx
81716+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81717+ } else {
81718+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81719+ dest = mod->module_core_rw + shdr->sh_entsize;
81720+ else
81721+ dest = mod->module_core_rx + shdr->sh_entsize;
81722+ }
81723+
81724+ if (shdr->sh_type != SHT_NOBITS) {
81725+
81726+#ifdef CONFIG_PAX_KERNEXEC
81727+#ifdef CONFIG_X86_64
81728+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81729+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81730+#endif
81731+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81732+ pax_open_kernel();
81733+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81734+ pax_close_kernel();
81735+ } else
81736+#endif
81737
81738- if (shdr->sh_type != SHT_NOBITS)
81739 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81740+ }
81741 /* Update sh_addr to point to copy in image. */
81742- shdr->sh_addr = (unsigned long)dest;
81743+
81744+#ifdef CONFIG_PAX_KERNEXEC
81745+ if (shdr->sh_flags & SHF_EXECINSTR)
81746+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81747+ else
81748+#endif
81749+
81750+ shdr->sh_addr = (unsigned long)dest;
81751 pr_debug("\t0x%lx %s\n",
81752 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81753 }
81754@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81755 * Do it before processing of module parameters, so the module
81756 * can provide parameter accessor functions of its own.
81757 */
81758- if (mod->module_init)
81759- flush_icache_range((unsigned long)mod->module_init,
81760- (unsigned long)mod->module_init
81761- + mod->init_size);
81762- flush_icache_range((unsigned long)mod->module_core,
81763- (unsigned long)mod->module_core + mod->core_size);
81764+ if (mod->module_init_rx)
81765+ flush_icache_range((unsigned long)mod->module_init_rx,
81766+ (unsigned long)mod->module_init_rx
81767+ + mod->init_size_rx);
81768+ flush_icache_range((unsigned long)mod->module_core_rx,
81769+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81770
81771 set_fs(old_fs);
81772 }
81773@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81774 static void module_deallocate(struct module *mod, struct load_info *info)
81775 {
81776 percpu_modfree(mod);
81777- module_free(mod, mod->module_init);
81778- module_free(mod, mod->module_core);
81779+ module_free_exec(mod, mod->module_init_rx);
81780+ module_free_exec(mod, mod->module_core_rx);
81781+ module_free(mod, mod->module_init_rw);
81782+ module_free(mod, mod->module_core_rw);
81783 }
81784
81785 int __weak module_finalize(const Elf_Ehdr *hdr,
81786@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81787 static int post_relocation(struct module *mod, const struct load_info *info)
81788 {
81789 /* Sort exception table now relocations are done. */
81790+ pax_open_kernel();
81791 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81792+ pax_close_kernel();
81793
81794 /* Copy relocated percpu area over. */
81795 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81796@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81797 MODULE_STATE_COMING, mod);
81798
81799 /* Set RO and NX regions for core */
81800- set_section_ro_nx(mod->module_core,
81801- mod->core_text_size,
81802- mod->core_ro_size,
81803- mod->core_size);
81804+ set_section_ro_nx(mod->module_core_rx,
81805+ mod->core_size_rx,
81806+ mod->core_size_rx,
81807+ mod->core_size_rx);
81808
81809 /* Set RO and NX regions for init */
81810- set_section_ro_nx(mod->module_init,
81811- mod->init_text_size,
81812- mod->init_ro_size,
81813- mod->init_size);
81814+ set_section_ro_nx(mod->module_init_rx,
81815+ mod->init_size_rx,
81816+ mod->init_size_rx,
81817+ mod->init_size_rx);
81818
81819 do_mod_ctors(mod);
81820 /* Start the module */
81821@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81822 mod->strtab = mod->core_strtab;
81823 #endif
81824 unset_module_init_ro_nx(mod);
81825- module_free(mod, mod->module_init);
81826- mod->module_init = NULL;
81827- mod->init_size = 0;
81828- mod->init_ro_size = 0;
81829- mod->init_text_size = 0;
81830+ module_free(mod, mod->module_init_rw);
81831+ module_free_exec(mod, mod->module_init_rx);
81832+ mod->module_init_rw = NULL;
81833+ mod->module_init_rx = NULL;
81834+ mod->init_size_rw = 0;
81835+ mod->init_size_rx = 0;
81836 mutex_unlock(&module_mutex);
81837 wake_up_all(&module_wq);
81838
81839@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81840 if (err)
81841 goto free_unload;
81842
81843+ /* Now copy in args */
81844+ mod->args = strndup_user(uargs, ~0UL >> 1);
81845+ if (IS_ERR(mod->args)) {
81846+ err = PTR_ERR(mod->args);
81847+ goto free_unload;
81848+ }
81849+
81850 /* Set up MODINFO_ATTR fields */
81851 setup_modinfo(mod, info);
81852
81853+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81854+ {
81855+ char *p, *p2;
81856+
81857+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81858+ 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);
81859+ err = -EPERM;
81860+ goto free_modinfo;
81861+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81862+ p += sizeof("grsec_modharden_normal") - 1;
81863+ p2 = strstr(p, "_");
81864+ if (p2) {
81865+ *p2 = '\0';
81866+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81867+ *p2 = '_';
81868+ }
81869+ err = -EPERM;
81870+ goto free_modinfo;
81871+ }
81872+ }
81873+#endif
81874+
81875 /* Fix up syms, so that st_value is a pointer to location. */
81876 err = simplify_symbols(mod, info);
81877 if (err < 0)
81878@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81879
81880 flush_module_icache(mod);
81881
81882- /* Now copy in args */
81883- mod->args = strndup_user(uargs, ~0UL >> 1);
81884- if (IS_ERR(mod->args)) {
81885- err = PTR_ERR(mod->args);
81886- goto free_arch_cleanup;
81887- }
81888-
81889 dynamic_debug_setup(info->debug, info->num_debug);
81890
81891 /* Finally it's fully formed, ready to start executing. */
81892@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81893 ddebug_cleanup:
81894 dynamic_debug_remove(info->debug);
81895 synchronize_sched();
81896- kfree(mod->args);
81897- free_arch_cleanup:
81898 module_arch_cleanup(mod);
81899 free_modinfo:
81900 free_modinfo(mod);
81901+ kfree(mod->args);
81902 free_unload:
81903 module_unload_free(mod);
81904 unlink_mod:
81905@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81906 unsigned long nextval;
81907
81908 /* At worse, next value is at end of module */
81909- if (within_module_init(addr, mod))
81910- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81911+ if (within_module_init_rx(addr, mod))
81912+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81913+ else if (within_module_init_rw(addr, mod))
81914+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81915+ else if (within_module_core_rx(addr, mod))
81916+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81917+ else if (within_module_core_rw(addr, mod))
81918+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81919 else
81920- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81921+ return NULL;
81922
81923 /* Scan for closest preceding symbol, and next symbol. (ELF
81924 starts real symbols at 1). */
81925@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81926 return 0;
81927
81928 seq_printf(m, "%s %u",
81929- mod->name, mod->init_size + mod->core_size);
81930+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81931 print_unload_info(m, mod);
81932
81933 /* Informative for users. */
81934@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81935 mod->state == MODULE_STATE_COMING ? "Loading":
81936 "Live");
81937 /* Used by oprofile and other similar tools. */
81938- seq_printf(m, " 0x%pK", mod->module_core);
81939+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81940
81941 /* Taints info */
81942 if (mod->taints)
81943@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81944
81945 static int __init proc_modules_init(void)
81946 {
81947+#ifndef CONFIG_GRKERNSEC_HIDESYM
81948+#ifdef CONFIG_GRKERNSEC_PROC_USER
81949+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81950+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81951+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81952+#else
81953 proc_create("modules", 0, NULL, &proc_modules_operations);
81954+#endif
81955+#else
81956+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81957+#endif
81958 return 0;
81959 }
81960 module_init(proc_modules_init);
81961@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81962 {
81963 struct module *mod;
81964
81965- if (addr < module_addr_min || addr > module_addr_max)
81966+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81967+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81968 return NULL;
81969
81970 list_for_each_entry_rcu(mod, &modules, list) {
81971 if (mod->state == MODULE_STATE_UNFORMED)
81972 continue;
81973- if (within_module_core(addr, mod)
81974- || within_module_init(addr, mod))
81975+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81976 return mod;
81977 }
81978 return NULL;
81979@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81980 */
81981 struct module *__module_text_address(unsigned long addr)
81982 {
81983- struct module *mod = __module_address(addr);
81984+ struct module *mod;
81985+
81986+#ifdef CONFIG_X86_32
81987+ addr = ktla_ktva(addr);
81988+#endif
81989+
81990+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81991+ return NULL;
81992+
81993+ mod = __module_address(addr);
81994+
81995 if (mod) {
81996 /* Make sure it's within the text section. */
81997- if (!within(addr, mod->module_init, mod->init_text_size)
81998- && !within(addr, mod->module_core, mod->core_text_size))
81999+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82000 mod = NULL;
82001 }
82002 return mod;
82003diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82004index 7e3443f..b2a1e6b 100644
82005--- a/kernel/mutex-debug.c
82006+++ b/kernel/mutex-debug.c
82007@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82008 }
82009
82010 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82011- struct thread_info *ti)
82012+ struct task_struct *task)
82013 {
82014 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82015
82016 /* Mark the current thread as blocked on the lock: */
82017- ti->task->blocked_on = waiter;
82018+ task->blocked_on = waiter;
82019 }
82020
82021 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82022- struct thread_info *ti)
82023+ struct task_struct *task)
82024 {
82025 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82026- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82027- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82028- ti->task->blocked_on = NULL;
82029+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82030+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82031+ task->blocked_on = NULL;
82032
82033 list_del_init(&waiter->list);
82034 waiter->task = NULL;
82035diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82036index 0799fd3..d06ae3b 100644
82037--- a/kernel/mutex-debug.h
82038+++ b/kernel/mutex-debug.h
82039@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82040 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82041 extern void debug_mutex_add_waiter(struct mutex *lock,
82042 struct mutex_waiter *waiter,
82043- struct thread_info *ti);
82044+ struct task_struct *task);
82045 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82046- struct thread_info *ti);
82047+ struct task_struct *task);
82048 extern void debug_mutex_unlock(struct mutex *lock);
82049 extern void debug_mutex_init(struct mutex *lock, const char *name,
82050 struct lock_class_key *key);
82051diff --git a/kernel/mutex.c b/kernel/mutex.c
82052index a52ee7bb..f361f16 100644
82053--- a/kernel/mutex.c
82054+++ b/kernel/mutex.c
82055@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82056 node->locked = 1;
82057 return;
82058 }
82059- ACCESS_ONCE(prev->next) = node;
82060+ ACCESS_ONCE_RW(prev->next) = node;
82061 smp_wmb();
82062 /* Wait until the lock holder passes the lock down */
82063 while (!ACCESS_ONCE(node->locked))
82064@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82065 while (!(next = ACCESS_ONCE(node->next)))
82066 arch_mutex_cpu_relax();
82067 }
82068- ACCESS_ONCE(next->locked) = 1;
82069+ ACCESS_ONCE_RW(next->locked) = 1;
82070 smp_wmb();
82071 }
82072
82073@@ -514,7 +514,7 @@ slowpath:
82074 spin_lock_mutex(&lock->wait_lock, flags);
82075
82076 debug_mutex_lock_common(lock, &waiter);
82077- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82078+ debug_mutex_add_waiter(lock, &waiter, task);
82079
82080 /* add waiting tasks to the end of the waitqueue (FIFO): */
82081 list_add_tail(&waiter.list, &lock->wait_list);
82082@@ -565,7 +565,7 @@ slowpath:
82083 done:
82084 lock_acquired(&lock->dep_map, ip);
82085 /* got the lock - rejoice! */
82086- mutex_remove_waiter(lock, &waiter, current_thread_info());
82087+ mutex_remove_waiter(lock, &waiter, task);
82088 mutex_set_owner(lock);
82089
82090 if (!__builtin_constant_p(ww_ctx == NULL)) {
82091@@ -604,7 +604,7 @@ done:
82092 return 0;
82093
82094 err:
82095- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82096+ mutex_remove_waiter(lock, &waiter, task);
82097 spin_unlock_mutex(&lock->wait_lock, flags);
82098 debug_mutex_free_waiter(&waiter);
82099 mutex_release(&lock->dep_map, 1, ip);
82100diff --git a/kernel/notifier.c b/kernel/notifier.c
82101index 2d5cc4c..d9ea600 100644
82102--- a/kernel/notifier.c
82103+++ b/kernel/notifier.c
82104@@ -5,6 +5,7 @@
82105 #include <linux/rcupdate.h>
82106 #include <linux/vmalloc.h>
82107 #include <linux/reboot.h>
82108+#include <linux/mm.h>
82109
82110 /*
82111 * Notifier list for kernel code which wants to be called
82112@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82113 while ((*nl) != NULL) {
82114 if (n->priority > (*nl)->priority)
82115 break;
82116- nl = &((*nl)->next);
82117+ nl = (struct notifier_block **)&((*nl)->next);
82118 }
82119- n->next = *nl;
82120+ pax_open_kernel();
82121+ *(const void **)&n->next = *nl;
82122 rcu_assign_pointer(*nl, n);
82123+ pax_close_kernel();
82124 return 0;
82125 }
82126
82127@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82128 return 0;
82129 if (n->priority > (*nl)->priority)
82130 break;
82131- nl = &((*nl)->next);
82132+ nl = (struct notifier_block **)&((*nl)->next);
82133 }
82134- n->next = *nl;
82135+ pax_open_kernel();
82136+ *(const void **)&n->next = *nl;
82137 rcu_assign_pointer(*nl, n);
82138+ pax_close_kernel();
82139 return 0;
82140 }
82141
82142@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82143 {
82144 while ((*nl) != NULL) {
82145 if ((*nl) == n) {
82146+ pax_open_kernel();
82147 rcu_assign_pointer(*nl, n->next);
82148+ pax_close_kernel();
82149 return 0;
82150 }
82151- nl = &((*nl)->next);
82152+ nl = (struct notifier_block **)&((*nl)->next);
82153 }
82154 return -ENOENT;
82155 }
82156diff --git a/kernel/panic.c b/kernel/panic.c
82157index 8018646..b6a5b4f 100644
82158--- a/kernel/panic.c
82159+++ b/kernel/panic.c
82160@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82161 disable_trace_on_warning();
82162
82163 pr_warn("------------[ cut here ]------------\n");
82164- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82165+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82166 raw_smp_processor_id(), current->pid, file, line, caller);
82167
82168 if (args)
82169@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82170 */
82171 void __stack_chk_fail(void)
82172 {
82173- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82174+ dump_stack();
82175+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82176 __builtin_return_address(0));
82177 }
82178 EXPORT_SYMBOL(__stack_chk_fail);
82179diff --git a/kernel/pid.c b/kernel/pid.c
82180index ebe5e80..5d6d634 100644
82181--- a/kernel/pid.c
82182+++ b/kernel/pid.c
82183@@ -33,6 +33,7 @@
82184 #include <linux/rculist.h>
82185 #include <linux/bootmem.h>
82186 #include <linux/hash.h>
82187+#include <linux/security.h>
82188 #include <linux/pid_namespace.h>
82189 #include <linux/init_task.h>
82190 #include <linux/syscalls.h>
82191@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82192
82193 int pid_max = PID_MAX_DEFAULT;
82194
82195-#define RESERVED_PIDS 300
82196+#define RESERVED_PIDS 500
82197
82198 int pid_max_min = RESERVED_PIDS + 1;
82199 int pid_max_max = PID_MAX_LIMIT;
82200@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82201 */
82202 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82203 {
82204+ struct task_struct *task;
82205+
82206 rcu_lockdep_assert(rcu_read_lock_held(),
82207 "find_task_by_pid_ns() needs rcu_read_lock()"
82208 " protection");
82209- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82210+
82211+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82212+
82213+ if (gr_pid_is_chrooted(task))
82214+ return NULL;
82215+
82216+ return task;
82217 }
82218
82219 struct task_struct *find_task_by_vpid(pid_t vnr)
82220@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82221 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82222 }
82223
82224+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82225+{
82226+ rcu_lockdep_assert(rcu_read_lock_held(),
82227+ "find_task_by_pid_ns() needs rcu_read_lock()"
82228+ " protection");
82229+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82230+}
82231+
82232 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82233 {
82234 struct pid *pid;
82235diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82236index 601bb36..f7e6f34 100644
82237--- a/kernel/pid_namespace.c
82238+++ b/kernel/pid_namespace.c
82239@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82240 void __user *buffer, size_t *lenp, loff_t *ppos)
82241 {
82242 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82243- struct ctl_table tmp = *table;
82244+ ctl_table_no_const tmp = *table;
82245
82246 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82247 return -EPERM;
82248diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82249index c7f31aa..2b44977 100644
82250--- a/kernel/posix-cpu-timers.c
82251+++ b/kernel/posix-cpu-timers.c
82252@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82253
82254 static __init int init_posix_cpu_timers(void)
82255 {
82256- struct k_clock process = {
82257+ static struct k_clock process = {
82258 .clock_getres = process_cpu_clock_getres,
82259 .clock_get = process_cpu_clock_get,
82260 .timer_create = process_cpu_timer_create,
82261 .nsleep = process_cpu_nsleep,
82262 .nsleep_restart = process_cpu_nsleep_restart,
82263 };
82264- struct k_clock thread = {
82265+ static struct k_clock thread = {
82266 .clock_getres = thread_cpu_clock_getres,
82267 .clock_get = thread_cpu_clock_get,
82268 .timer_create = thread_cpu_timer_create,
82269diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82270index 424c2d4..679242f 100644
82271--- a/kernel/posix-timers.c
82272+++ b/kernel/posix-timers.c
82273@@ -43,6 +43,7 @@
82274 #include <linux/hash.h>
82275 #include <linux/posix-clock.h>
82276 #include <linux/posix-timers.h>
82277+#include <linux/grsecurity.h>
82278 #include <linux/syscalls.h>
82279 #include <linux/wait.h>
82280 #include <linux/workqueue.h>
82281@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82282 * which we beg off on and pass to do_sys_settimeofday().
82283 */
82284
82285-static struct k_clock posix_clocks[MAX_CLOCKS];
82286+static struct k_clock *posix_clocks[MAX_CLOCKS];
82287
82288 /*
82289 * These ones are defined below.
82290@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82291 */
82292 static __init int init_posix_timers(void)
82293 {
82294- struct k_clock clock_realtime = {
82295+ static struct k_clock clock_realtime = {
82296 .clock_getres = hrtimer_get_res,
82297 .clock_get = posix_clock_realtime_get,
82298 .clock_set = posix_clock_realtime_set,
82299@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82300 .timer_get = common_timer_get,
82301 .timer_del = common_timer_del,
82302 };
82303- struct k_clock clock_monotonic = {
82304+ static struct k_clock clock_monotonic = {
82305 .clock_getres = hrtimer_get_res,
82306 .clock_get = posix_ktime_get_ts,
82307 .nsleep = common_nsleep,
82308@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82309 .timer_get = common_timer_get,
82310 .timer_del = common_timer_del,
82311 };
82312- struct k_clock clock_monotonic_raw = {
82313+ static struct k_clock clock_monotonic_raw = {
82314 .clock_getres = hrtimer_get_res,
82315 .clock_get = posix_get_monotonic_raw,
82316 };
82317- struct k_clock clock_realtime_coarse = {
82318+ static struct k_clock clock_realtime_coarse = {
82319 .clock_getres = posix_get_coarse_res,
82320 .clock_get = posix_get_realtime_coarse,
82321 };
82322- struct k_clock clock_monotonic_coarse = {
82323+ static struct k_clock clock_monotonic_coarse = {
82324 .clock_getres = posix_get_coarse_res,
82325 .clock_get = posix_get_monotonic_coarse,
82326 };
82327- struct k_clock clock_tai = {
82328+ static struct k_clock clock_tai = {
82329 .clock_getres = hrtimer_get_res,
82330 .clock_get = posix_get_tai,
82331 .nsleep = common_nsleep,
82332@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82333 .timer_get = common_timer_get,
82334 .timer_del = common_timer_del,
82335 };
82336- struct k_clock clock_boottime = {
82337+ static struct k_clock clock_boottime = {
82338 .clock_getres = hrtimer_get_res,
82339 .clock_get = posix_get_boottime,
82340 .nsleep = common_nsleep,
82341@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82342 return;
82343 }
82344
82345- posix_clocks[clock_id] = *new_clock;
82346+ posix_clocks[clock_id] = new_clock;
82347 }
82348 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82349
82350@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82351 return (id & CLOCKFD_MASK) == CLOCKFD ?
82352 &clock_posix_dynamic : &clock_posix_cpu;
82353
82354- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82355+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82356 return NULL;
82357- return &posix_clocks[id];
82358+ return posix_clocks[id];
82359 }
82360
82361 static int common_timer_create(struct k_itimer *new_timer)
82362@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82363 struct k_clock *kc = clockid_to_kclock(which_clock);
82364 struct k_itimer *new_timer;
82365 int error, new_timer_id;
82366- sigevent_t event;
82367+ sigevent_t event = { };
82368 int it_id_set = IT_ID_NOT_SET;
82369
82370 if (!kc)
82371@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82372 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82373 return -EFAULT;
82374
82375+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82376+ have their clock_set fptr set to a nosettime dummy function
82377+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82378+ call common_clock_set, which calls do_sys_settimeofday, which
82379+ we hook
82380+ */
82381+
82382 return kc->clock_set(which_clock, &new_tp);
82383 }
82384
82385diff --git a/kernel/power/process.c b/kernel/power/process.c
82386index 06ec886..9dba35e 100644
82387--- a/kernel/power/process.c
82388+++ b/kernel/power/process.c
82389@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82390 unsigned int elapsed_msecs;
82391 bool wakeup = false;
82392 int sleep_usecs = USEC_PER_MSEC;
82393+ bool timedout = false;
82394
82395 do_gettimeofday(&start);
82396
82397@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82398
82399 while (true) {
82400 todo = 0;
82401+ if (time_after(jiffies, end_time))
82402+ timedout = true;
82403 read_lock(&tasklist_lock);
82404 do_each_thread(g, p) {
82405 if (p == current || !freeze_task(p))
82406 continue;
82407
82408- if (!freezer_should_skip(p))
82409+ if (!freezer_should_skip(p)) {
82410 todo++;
82411+ if (timedout) {
82412+ printk(KERN_ERR "Task refusing to freeze:\n");
82413+ sched_show_task(p);
82414+ }
82415+ }
82416 } while_each_thread(g, p);
82417 read_unlock(&tasklist_lock);
82418
82419@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82420 todo += wq_busy;
82421 }
82422
82423- if (!todo || time_after(jiffies, end_time))
82424+ if (!todo || timedout)
82425 break;
82426
82427 if (pm_wakeup_pending()) {
82428diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82429index 5b5a708..ec7637e 100644
82430--- a/kernel/printk/printk.c
82431+++ b/kernel/printk/printk.c
82432@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82433 if (from_file && type != SYSLOG_ACTION_OPEN)
82434 return 0;
82435
82436+#ifdef CONFIG_GRKERNSEC_DMESG
82437+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82438+ return -EPERM;
82439+#endif
82440+
82441 if (syslog_action_restricted(type)) {
82442 if (capable(CAP_SYSLOG))
82443 return 0;
82444diff --git a/kernel/profile.c b/kernel/profile.c
82445index 6631e1e..310c266 100644
82446--- a/kernel/profile.c
82447+++ b/kernel/profile.c
82448@@ -37,7 +37,7 @@ struct profile_hit {
82449 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82450 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82451
82452-static atomic_t *prof_buffer;
82453+static atomic_unchecked_t *prof_buffer;
82454 static unsigned long prof_len, prof_shift;
82455
82456 int prof_on __read_mostly;
82457@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82458 hits[i].pc = 0;
82459 continue;
82460 }
82461- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82462+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82463 hits[i].hits = hits[i].pc = 0;
82464 }
82465 }
82466@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82467 * Add the current hit(s) and flush the write-queue out
82468 * to the global buffer:
82469 */
82470- atomic_add(nr_hits, &prof_buffer[pc]);
82471+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82472 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82473- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82474+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82475 hits[i].pc = hits[i].hits = 0;
82476 }
82477 out:
82478@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82479 {
82480 unsigned long pc;
82481 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82482- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82483+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82484 }
82485 #endif /* !CONFIG_SMP */
82486
82487@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82488 return -EFAULT;
82489 buf++; p++; count--; read++;
82490 }
82491- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82492+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82493 if (copy_to_user(buf, (void *)pnt, count))
82494 return -EFAULT;
82495 read += count;
82496@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82497 }
82498 #endif
82499 profile_discard_flip_buffers();
82500- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82501+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82502 return count;
82503 }
82504
82505diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82506index a146ee3..ffed4c3 100644
82507--- a/kernel/ptrace.c
82508+++ b/kernel/ptrace.c
82509@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82510 if (seize)
82511 flags |= PT_SEIZED;
82512 rcu_read_lock();
82513- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82514+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82515 flags |= PT_PTRACE_CAP;
82516 rcu_read_unlock();
82517 task->ptrace = flags;
82518@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82519 break;
82520 return -EIO;
82521 }
82522- if (copy_to_user(dst, buf, retval))
82523+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82524 return -EFAULT;
82525 copied += retval;
82526 src += retval;
82527@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82528 bool seized = child->ptrace & PT_SEIZED;
82529 int ret = -EIO;
82530 siginfo_t siginfo, *si;
82531- void __user *datavp = (void __user *) data;
82532+ void __user *datavp = (__force void __user *) data;
82533 unsigned long __user *datalp = datavp;
82534 unsigned long flags;
82535
82536@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82537 goto out;
82538 }
82539
82540+ if (gr_handle_ptrace(child, request)) {
82541+ ret = -EPERM;
82542+ goto out_put_task_struct;
82543+ }
82544+
82545 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82546 ret = ptrace_attach(child, request, addr, data);
82547 /*
82548 * Some architectures need to do book-keeping after
82549 * a ptrace attach.
82550 */
82551- if (!ret)
82552+ if (!ret) {
82553 arch_ptrace_attach(child);
82554+ gr_audit_ptrace(child);
82555+ }
82556 goto out_put_task_struct;
82557 }
82558
82559@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82560 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82561 if (copied != sizeof(tmp))
82562 return -EIO;
82563- return put_user(tmp, (unsigned long __user *)data);
82564+ return put_user(tmp, (__force unsigned long __user *)data);
82565 }
82566
82567 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82568@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82569 }
82570
82571 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82572- compat_long_t addr, compat_long_t data)
82573+ compat_ulong_t addr, compat_ulong_t data)
82574 {
82575 struct task_struct *child;
82576 long ret;
82577@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82578 goto out;
82579 }
82580
82581+ if (gr_handle_ptrace(child, request)) {
82582+ ret = -EPERM;
82583+ goto out_put_task_struct;
82584+ }
82585+
82586 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82587 ret = ptrace_attach(child, request, addr, data);
82588 /*
82589 * Some architectures need to do book-keeping after
82590 * a ptrace attach.
82591 */
82592- if (!ret)
82593+ if (!ret) {
82594 arch_ptrace_attach(child);
82595+ gr_audit_ptrace(child);
82596+ }
82597 goto out_put_task_struct;
82598 }
82599
82600diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82601index cce6ba8..7c758b1f 100644
82602--- a/kernel/rcupdate.c
82603+++ b/kernel/rcupdate.c
82604@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82605 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82606 */
82607 if (till_stall_check < 3) {
82608- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82609+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82610 till_stall_check = 3;
82611 } else if (till_stall_check > 300) {
82612- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82613+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82614 till_stall_check = 300;
82615 }
82616 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82617diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82618index aa34411..4832cd4 100644
82619--- a/kernel/rcutiny.c
82620+++ b/kernel/rcutiny.c
82621@@ -45,7 +45,7 @@
82622 /* Forward declarations for rcutiny_plugin.h. */
82623 struct rcu_ctrlblk;
82624 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82625-static void rcu_process_callbacks(struct softirq_action *unused);
82626+static void rcu_process_callbacks(void);
82627 static void __call_rcu(struct rcu_head *head,
82628 void (*func)(struct rcu_head *rcu),
82629 struct rcu_ctrlblk *rcp);
82630@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82631 false));
82632 }
82633
82634-static void rcu_process_callbacks(struct softirq_action *unused)
82635+static __latent_entropy void rcu_process_callbacks(void)
82636 {
82637 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82638 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82639diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82640index f4871e5..8ef5741 100644
82641--- a/kernel/rcutorture.c
82642+++ b/kernel/rcutorture.c
82643@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82644 { 0 };
82645 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82646 { 0 };
82647-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82648-static atomic_t n_rcu_torture_alloc;
82649-static atomic_t n_rcu_torture_alloc_fail;
82650-static atomic_t n_rcu_torture_free;
82651-static atomic_t n_rcu_torture_mberror;
82652-static atomic_t n_rcu_torture_error;
82653+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82654+static atomic_unchecked_t n_rcu_torture_alloc;
82655+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82656+static atomic_unchecked_t n_rcu_torture_free;
82657+static atomic_unchecked_t n_rcu_torture_mberror;
82658+static atomic_unchecked_t n_rcu_torture_error;
82659 static long n_rcu_torture_barrier_error;
82660 static long n_rcu_torture_boost_ktrerror;
82661 static long n_rcu_torture_boost_rterror;
82662@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82663
82664 spin_lock_bh(&rcu_torture_lock);
82665 if (list_empty(&rcu_torture_freelist)) {
82666- atomic_inc(&n_rcu_torture_alloc_fail);
82667+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82668 spin_unlock_bh(&rcu_torture_lock);
82669 return NULL;
82670 }
82671- atomic_inc(&n_rcu_torture_alloc);
82672+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82673 p = rcu_torture_freelist.next;
82674 list_del_init(p);
82675 spin_unlock_bh(&rcu_torture_lock);
82676@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82677 static void
82678 rcu_torture_free(struct rcu_torture *p)
82679 {
82680- atomic_inc(&n_rcu_torture_free);
82681+ atomic_inc_unchecked(&n_rcu_torture_free);
82682 spin_lock_bh(&rcu_torture_lock);
82683 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82684 spin_unlock_bh(&rcu_torture_lock);
82685@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82686 i = rp->rtort_pipe_count;
82687 if (i > RCU_TORTURE_PIPE_LEN)
82688 i = RCU_TORTURE_PIPE_LEN;
82689- atomic_inc(&rcu_torture_wcount[i]);
82690+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82691 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82692 rp->rtort_mbtest = 0;
82693 rcu_torture_free(rp);
82694@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82695 i = rp->rtort_pipe_count;
82696 if (i > RCU_TORTURE_PIPE_LEN)
82697 i = RCU_TORTURE_PIPE_LEN;
82698- atomic_inc(&rcu_torture_wcount[i]);
82699+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82700 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82701 rp->rtort_mbtest = 0;
82702 list_del(&rp->rtort_free);
82703@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82704 i = old_rp->rtort_pipe_count;
82705 if (i > RCU_TORTURE_PIPE_LEN)
82706 i = RCU_TORTURE_PIPE_LEN;
82707- atomic_inc(&rcu_torture_wcount[i]);
82708+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82709 old_rp->rtort_pipe_count++;
82710 cur_ops->deferred_free(old_rp);
82711 }
82712@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82713 return;
82714 }
82715 if (p->rtort_mbtest == 0)
82716- atomic_inc(&n_rcu_torture_mberror);
82717+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82718 spin_lock(&rand_lock);
82719 cur_ops->read_delay(&rand);
82720 n_rcu_torture_timers++;
82721@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82722 continue;
82723 }
82724 if (p->rtort_mbtest == 0)
82725- atomic_inc(&n_rcu_torture_mberror);
82726+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82727 cur_ops->read_delay(&rand);
82728 preempt_disable();
82729 pipe_count = p->rtort_pipe_count;
82730@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82731 rcu_torture_current,
82732 rcu_torture_current_version,
82733 list_empty(&rcu_torture_freelist),
82734- atomic_read(&n_rcu_torture_alloc),
82735- atomic_read(&n_rcu_torture_alloc_fail),
82736- atomic_read(&n_rcu_torture_free));
82737+ atomic_read_unchecked(&n_rcu_torture_alloc),
82738+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82739+ atomic_read_unchecked(&n_rcu_torture_free));
82740 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82741- atomic_read(&n_rcu_torture_mberror),
82742+ atomic_read_unchecked(&n_rcu_torture_mberror),
82743 n_rcu_torture_boost_ktrerror,
82744 n_rcu_torture_boost_rterror);
82745 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82746@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82747 n_barrier_attempts,
82748 n_rcu_torture_barrier_error);
82749 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82750- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82751+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82752 n_rcu_torture_barrier_error != 0 ||
82753 n_rcu_torture_boost_ktrerror != 0 ||
82754 n_rcu_torture_boost_rterror != 0 ||
82755 n_rcu_torture_boost_failure != 0 ||
82756 i > 1) {
82757 cnt += sprintf(&page[cnt], "!!! ");
82758- atomic_inc(&n_rcu_torture_error);
82759+ atomic_inc_unchecked(&n_rcu_torture_error);
82760 WARN_ON_ONCE(1);
82761 }
82762 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82763@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82764 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82765 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82766 cnt += sprintf(&page[cnt], " %d",
82767- atomic_read(&rcu_torture_wcount[i]));
82768+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82769 }
82770 cnt += sprintf(&page[cnt], "\n");
82771 if (cur_ops->stats)
82772@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82773
82774 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82775
82776- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82777+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82778 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82779 else if (n_online_successes != n_online_attempts ||
82780 n_offline_successes != n_offline_attempts)
82781@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82782
82783 rcu_torture_current = NULL;
82784 rcu_torture_current_version = 0;
82785- atomic_set(&n_rcu_torture_alloc, 0);
82786- atomic_set(&n_rcu_torture_alloc_fail, 0);
82787- atomic_set(&n_rcu_torture_free, 0);
82788- atomic_set(&n_rcu_torture_mberror, 0);
82789- atomic_set(&n_rcu_torture_error, 0);
82790+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82791+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82792+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82793+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82794+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82795 n_rcu_torture_barrier_error = 0;
82796 n_rcu_torture_boost_ktrerror = 0;
82797 n_rcu_torture_boost_rterror = 0;
82798 n_rcu_torture_boost_failure = 0;
82799 n_rcu_torture_boosts = 0;
82800 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82801- atomic_set(&rcu_torture_wcount[i], 0);
82802+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82803 for_each_possible_cpu(cpu) {
82804 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82805 per_cpu(rcu_torture_count, cpu)[i] = 0;
82806diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82807index 068de3a..5e7db2f 100644
82808--- a/kernel/rcutree.c
82809+++ b/kernel/rcutree.c
82810@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82811 rcu_prepare_for_idle(smp_processor_id());
82812 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82813 smp_mb__before_atomic_inc(); /* See above. */
82814- atomic_inc(&rdtp->dynticks);
82815+ atomic_inc_unchecked(&rdtp->dynticks);
82816 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82817- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82818+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82819
82820 /*
82821 * It is illegal to enter an extended quiescent state while
82822@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82823 int user)
82824 {
82825 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82826- atomic_inc(&rdtp->dynticks);
82827+ atomic_inc_unchecked(&rdtp->dynticks);
82828 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82829 smp_mb__after_atomic_inc(); /* See above. */
82830- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82831+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82832 rcu_cleanup_after_idle(smp_processor_id());
82833 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82834 if (!user && !is_idle_task(current)) {
82835@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82836 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82837
82838 if (rdtp->dynticks_nmi_nesting == 0 &&
82839- (atomic_read(&rdtp->dynticks) & 0x1))
82840+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82841 return;
82842 rdtp->dynticks_nmi_nesting++;
82843 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82844- atomic_inc(&rdtp->dynticks);
82845+ atomic_inc_unchecked(&rdtp->dynticks);
82846 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82847 smp_mb__after_atomic_inc(); /* See above. */
82848- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82849+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82850 }
82851
82852 /**
82853@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82854 return;
82855 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82856 smp_mb__before_atomic_inc(); /* See above. */
82857- atomic_inc(&rdtp->dynticks);
82858+ atomic_inc_unchecked(&rdtp->dynticks);
82859 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82860- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82861+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82862 }
82863
82864 /**
82865@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82866 int ret;
82867
82868 preempt_disable();
82869- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82870+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82871 preempt_enable();
82872 return ret;
82873 }
82874@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82875 */
82876 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82877 {
82878- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82879+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82880 return (rdp->dynticks_snap & 0x1) == 0;
82881 }
82882
82883@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82884 unsigned int curr;
82885 unsigned int snap;
82886
82887- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82888+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82889 snap = (unsigned int)rdp->dynticks_snap;
82890
82891 /*
82892@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82893 rdp = this_cpu_ptr(rsp->rda);
82894 rcu_preempt_check_blocked_tasks(rnp);
82895 rnp->qsmask = rnp->qsmaskinit;
82896- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82897+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82898 WARN_ON_ONCE(rnp->completed != rsp->completed);
82899- ACCESS_ONCE(rnp->completed) = rsp->completed;
82900+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82901 if (rnp == rdp->mynode)
82902 __note_gp_changes(rsp, rnp, rdp);
82903 rcu_preempt_boost_start_gp(rnp);
82904@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82905 */
82906 rcu_for_each_node_breadth_first(rsp, rnp) {
82907 raw_spin_lock_irq(&rnp->lock);
82908- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82909+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82910 rdp = this_cpu_ptr(rsp->rda);
82911 if (rnp == rdp->mynode)
82912 __note_gp_changes(rsp, rnp, rdp);
82913@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82914 rsp->qlen += rdp->qlen;
82915 rdp->n_cbs_orphaned += rdp->qlen;
82916 rdp->qlen_lazy = 0;
82917- ACCESS_ONCE(rdp->qlen) = 0;
82918+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82919 }
82920
82921 /*
82922@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82923 }
82924 smp_mb(); /* List handling before counting for rcu_barrier(). */
82925 rdp->qlen_lazy -= count_lazy;
82926- ACCESS_ONCE(rdp->qlen) -= count;
82927+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82928 rdp->n_cbs_invoked += count;
82929
82930 /* Reinstate batch limit if we have worked down the excess. */
82931@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82932 /*
82933 * Do RCU core processing for the current CPU.
82934 */
82935-static void rcu_process_callbacks(struct softirq_action *unused)
82936+static __latent_entropy void rcu_process_callbacks(void)
82937 {
82938 struct rcu_state *rsp;
82939
82940@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82941 local_irq_restore(flags);
82942 return;
82943 }
82944- ACCESS_ONCE(rdp->qlen)++;
82945+ ACCESS_ONCE_RW(rdp->qlen)++;
82946 if (lazy)
82947 rdp->qlen_lazy++;
82948 else
82949@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82950 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82951 * course be required on a 64-bit system.
82952 */
82953- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82954+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82955 (ulong)atomic_long_read(&rsp->expedited_done) +
82956 ULONG_MAX / 8)) {
82957 synchronize_sched();
82958- atomic_long_inc(&rsp->expedited_wrap);
82959+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82960 return;
82961 }
82962
82963@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82964 * Take a ticket. Note that atomic_inc_return() implies a
82965 * full memory barrier.
82966 */
82967- snap = atomic_long_inc_return(&rsp->expedited_start);
82968+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82969 firstsnap = snap;
82970 get_online_cpus();
82971 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82972@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82973 synchronize_sched_expedited_cpu_stop,
82974 NULL) == -EAGAIN) {
82975 put_online_cpus();
82976- atomic_long_inc(&rsp->expedited_tryfail);
82977+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82978
82979 /* Check to see if someone else did our work for us. */
82980 s = atomic_long_read(&rsp->expedited_done);
82981 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82982 /* ensure test happens before caller kfree */
82983 smp_mb__before_atomic_inc(); /* ^^^ */
82984- atomic_long_inc(&rsp->expedited_workdone1);
82985+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82986 return;
82987 }
82988
82989@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82990 udelay(trycount * num_online_cpus());
82991 } else {
82992 wait_rcu_gp(call_rcu_sched);
82993- atomic_long_inc(&rsp->expedited_normal);
82994+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82995 return;
82996 }
82997
82998@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82999 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83000 /* ensure test happens before caller kfree */
83001 smp_mb__before_atomic_inc(); /* ^^^ */
83002- atomic_long_inc(&rsp->expedited_workdone2);
83003+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83004 return;
83005 }
83006
83007@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83008 * period works for us.
83009 */
83010 get_online_cpus();
83011- snap = atomic_long_read(&rsp->expedited_start);
83012+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83013 smp_mb(); /* ensure read is before try_stop_cpus(). */
83014 }
83015- atomic_long_inc(&rsp->expedited_stoppedcpus);
83016+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83017
83018 /*
83019 * Everyone up to our most recent fetch is covered by our grace
83020@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83021 * than we did already did their update.
83022 */
83023 do {
83024- atomic_long_inc(&rsp->expedited_done_tries);
83025+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83026 s = atomic_long_read(&rsp->expedited_done);
83027 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83028 /* ensure test happens before caller kfree */
83029 smp_mb__before_atomic_inc(); /* ^^^ */
83030- atomic_long_inc(&rsp->expedited_done_lost);
83031+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83032 break;
83033 }
83034 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83035- atomic_long_inc(&rsp->expedited_done_exit);
83036+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83037
83038 put_online_cpus();
83039 }
83040@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83041 * ACCESS_ONCE() to prevent the compiler from speculating
83042 * the increment to precede the early-exit check.
83043 */
83044- ACCESS_ONCE(rsp->n_barrier_done)++;
83045+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83046 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83047 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83048 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83049@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83050
83051 /* Increment ->n_barrier_done to prevent duplicate work. */
83052 smp_mb(); /* Keep increment after above mechanism. */
83053- ACCESS_ONCE(rsp->n_barrier_done)++;
83054+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83055 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83056 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83057 smp_mb(); /* Keep increment before caller's subsequent code. */
83058@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83059 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83060 init_callback_list(rdp);
83061 rdp->qlen_lazy = 0;
83062- ACCESS_ONCE(rdp->qlen) = 0;
83063+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83064 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83065 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83066- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83067+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83068 rdp->cpu = cpu;
83069 rdp->rsp = rsp;
83070 rcu_boot_init_nocb_percpu_data(rdp);
83071@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83072 rdp->blimit = blimit;
83073 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83074 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83075- atomic_set(&rdp->dynticks->dynticks,
83076- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83077+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83078+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83079 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83080
83081 /* Add CPU to rcu_node bitmasks. */
83082diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83083index b383258..2440c1e 100644
83084--- a/kernel/rcutree.h
83085+++ b/kernel/rcutree.h
83086@@ -87,7 +87,7 @@ struct rcu_dynticks {
83087 long long dynticks_nesting; /* Track irq/process nesting level. */
83088 /* Process level is worth LLONG_MAX/2. */
83089 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83090- atomic_t dynticks; /* Even value for idle, else odd. */
83091+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83092 #ifdef CONFIG_RCU_FAST_NO_HZ
83093 bool all_lazy; /* Are all CPU's CBs lazy? */
83094 unsigned long nonlazy_posted;
83095@@ -419,17 +419,17 @@ struct rcu_state {
83096 /* _rcu_barrier(). */
83097 /* End of fields guarded by barrier_mutex. */
83098
83099- atomic_long_t expedited_start; /* Starting ticket. */
83100- atomic_long_t expedited_done; /* Done ticket. */
83101- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83102- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83103- atomic_long_t expedited_workdone1; /* # done by others #1. */
83104- atomic_long_t expedited_workdone2; /* # done by others #2. */
83105- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83106- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83107- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83108- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83109- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83110+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83111+ atomic_long_t expedited_done; /* Done ticket. */
83112+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83113+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83114+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83115+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83116+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83117+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83118+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83119+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83120+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83121
83122 unsigned long jiffies_force_qs; /* Time at which to invoke */
83123 /* force_quiescent_state(). */
83124diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83125index 769e12e..7b2139b 100644
83126--- a/kernel/rcutree_plugin.h
83127+++ b/kernel/rcutree_plugin.h
83128@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83129
83130 /* Clean up and exit. */
83131 smp_mb(); /* ensure expedited GP seen before counter increment. */
83132- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83133+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83134 unlock_mb_ret:
83135 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83136 mb_ret:
83137@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83138 free_cpumask_var(cm);
83139 }
83140
83141-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83142+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83143 .store = &rcu_cpu_kthread_task,
83144 .thread_should_run = rcu_cpu_kthread_should_run,
83145 .thread_fn = rcu_cpu_kthread,
83146@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83147 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83148 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83149 cpu, ticks_value, ticks_title,
83150- atomic_read(&rdtp->dynticks) & 0xfff,
83151+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83152 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83153 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83154 fast_no_hz);
83155@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83156
83157 /* Enqueue the callback on the nocb list and update counts. */
83158 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83159- ACCESS_ONCE(*old_rhpp) = rhp;
83160+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83161 atomic_long_add(rhcount, &rdp->nocb_q_count);
83162 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83163
83164@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83165 * Extract queued callbacks, update counts, and wait
83166 * for a grace period to elapse.
83167 */
83168- ACCESS_ONCE(rdp->nocb_head) = NULL;
83169+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83170 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83171 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83172 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83173- ACCESS_ONCE(rdp->nocb_p_count) += c;
83174- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83175+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83176+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83177 rcu_nocb_wait_gp(rdp);
83178
83179 /* Each pass through the following loop invokes a callback. */
83180@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83181 list = next;
83182 }
83183 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83184- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83185- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83186+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83187+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83188 rdp->n_nocbs_invoked += c;
83189 }
83190 return 0;
83191@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83192 t = kthread_run(rcu_nocb_kthread, rdp,
83193 "rcuo%c/%d", rsp->abbr, cpu);
83194 BUG_ON(IS_ERR(t));
83195- ACCESS_ONCE(rdp->nocb_kthread) = t;
83196+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83197 }
83198 }
83199
83200diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83201index cf6c174..a8f4b50 100644
83202--- a/kernel/rcutree_trace.c
83203+++ b/kernel/rcutree_trace.c
83204@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83205 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83206 rdp->passed_quiesce, rdp->qs_pending);
83207 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83208- atomic_read(&rdp->dynticks->dynticks),
83209+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83210 rdp->dynticks->dynticks_nesting,
83211 rdp->dynticks->dynticks_nmi_nesting,
83212 rdp->dynticks_fqs);
83213@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83214 struct rcu_state *rsp = (struct rcu_state *)m->private;
83215
83216 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",
83217- atomic_long_read(&rsp->expedited_start),
83218+ atomic_long_read_unchecked(&rsp->expedited_start),
83219 atomic_long_read(&rsp->expedited_done),
83220- atomic_long_read(&rsp->expedited_wrap),
83221- atomic_long_read(&rsp->expedited_tryfail),
83222- atomic_long_read(&rsp->expedited_workdone1),
83223- atomic_long_read(&rsp->expedited_workdone2),
83224- atomic_long_read(&rsp->expedited_normal),
83225- atomic_long_read(&rsp->expedited_stoppedcpus),
83226- atomic_long_read(&rsp->expedited_done_tries),
83227- atomic_long_read(&rsp->expedited_done_lost),
83228- atomic_long_read(&rsp->expedited_done_exit));
83229+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83230+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83231+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83232+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83233+ atomic_long_read_unchecked(&rsp->expedited_normal),
83234+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83235+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83236+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83237+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83238 return 0;
83239 }
83240
83241diff --git a/kernel/resource.c b/kernel/resource.c
83242index 3f285dc..5755f62 100644
83243--- a/kernel/resource.c
83244+++ b/kernel/resource.c
83245@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83246
83247 static int __init ioresources_init(void)
83248 {
83249+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83250+#ifdef CONFIG_GRKERNSEC_PROC_USER
83251+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83252+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83253+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83254+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83255+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83256+#endif
83257+#else
83258 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83259 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83260+#endif
83261 return 0;
83262 }
83263 __initcall(ioresources_init);
83264diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83265index 1d96dd0..994ff19 100644
83266--- a/kernel/rtmutex-tester.c
83267+++ b/kernel/rtmutex-tester.c
83268@@ -22,7 +22,7 @@
83269 #define MAX_RT_TEST_MUTEXES 8
83270
83271 static spinlock_t rttest_lock;
83272-static atomic_t rttest_event;
83273+static atomic_unchecked_t rttest_event;
83274
83275 struct test_thread_data {
83276 int opcode;
83277@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83278
83279 case RTTEST_LOCKCONT:
83280 td->mutexes[td->opdata] = 1;
83281- td->event = atomic_add_return(1, &rttest_event);
83282+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83283 return 0;
83284
83285 case RTTEST_RESET:
83286@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83287 return 0;
83288
83289 case RTTEST_RESETEVENT:
83290- atomic_set(&rttest_event, 0);
83291+ atomic_set_unchecked(&rttest_event, 0);
83292 return 0;
83293
83294 default:
83295@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83296 return ret;
83297
83298 td->mutexes[id] = 1;
83299- td->event = atomic_add_return(1, &rttest_event);
83300+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83301 rt_mutex_lock(&mutexes[id]);
83302- td->event = atomic_add_return(1, &rttest_event);
83303+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83304 td->mutexes[id] = 4;
83305 return 0;
83306
83307@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83308 return ret;
83309
83310 td->mutexes[id] = 1;
83311- td->event = atomic_add_return(1, &rttest_event);
83312+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83313 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83314- td->event = atomic_add_return(1, &rttest_event);
83315+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83316 td->mutexes[id] = ret ? 0 : 4;
83317 return ret ? -EINTR : 0;
83318
83319@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83320 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83321 return ret;
83322
83323- td->event = atomic_add_return(1, &rttest_event);
83324+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83325 rt_mutex_unlock(&mutexes[id]);
83326- td->event = atomic_add_return(1, &rttest_event);
83327+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83328 td->mutexes[id] = 0;
83329 return 0;
83330
83331@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83332 break;
83333
83334 td->mutexes[dat] = 2;
83335- td->event = atomic_add_return(1, &rttest_event);
83336+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83337 break;
83338
83339 default:
83340@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83341 return;
83342
83343 td->mutexes[dat] = 3;
83344- td->event = atomic_add_return(1, &rttest_event);
83345+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83346 break;
83347
83348 case RTTEST_LOCKNOWAIT:
83349@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83350 return;
83351
83352 td->mutexes[dat] = 1;
83353- td->event = atomic_add_return(1, &rttest_event);
83354+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83355 return;
83356
83357 default:
83358diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83359index 4a07353..66b5291 100644
83360--- a/kernel/sched/auto_group.c
83361+++ b/kernel/sched/auto_group.c
83362@@ -11,7 +11,7 @@
83363
83364 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83365 static struct autogroup autogroup_default;
83366-static atomic_t autogroup_seq_nr;
83367+static atomic_unchecked_t autogroup_seq_nr;
83368
83369 void __init autogroup_init(struct task_struct *init_task)
83370 {
83371@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83372
83373 kref_init(&ag->kref);
83374 init_rwsem(&ag->lock);
83375- ag->id = atomic_inc_return(&autogroup_seq_nr);
83376+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83377 ag->tg = tg;
83378 #ifdef CONFIG_RT_GROUP_SCHED
83379 /*
83380diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83381index 05c39f0..442e6fe 100644
83382--- a/kernel/sched/core.c
83383+++ b/kernel/sched/core.c
83384@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83385 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83386 * or number of jiffies left till timeout) if completed.
83387 */
83388-long __sched
83389+long __sched __intentional_overflow(-1)
83390 wait_for_completion_interruptible_timeout(struct completion *x,
83391 unsigned long timeout)
83392 {
83393@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83394 *
83395 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83396 */
83397-int __sched wait_for_completion_killable(struct completion *x)
83398+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83399 {
83400 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83401 if (t == -ERESTARTSYS)
83402@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83403 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83404 * or number of jiffies left till timeout) if completed.
83405 */
83406-long __sched
83407+long __sched __intentional_overflow(-1)
83408 wait_for_completion_killable_timeout(struct completion *x,
83409 unsigned long timeout)
83410 {
83411@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83412 /* convert nice value [19,-20] to rlimit style value [1,40] */
83413 int nice_rlim = 20 - nice;
83414
83415+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83416+
83417 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83418 capable(CAP_SYS_NICE));
83419 }
83420@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83421 if (nice > 19)
83422 nice = 19;
83423
83424- if (increment < 0 && !can_nice(current, nice))
83425+ if (increment < 0 && (!can_nice(current, nice) ||
83426+ gr_handle_chroot_nice()))
83427 return -EPERM;
83428
83429 retval = security_task_setnice(current, nice);
83430@@ -3344,6 +3347,7 @@ recheck:
83431 unsigned long rlim_rtprio =
83432 task_rlimit(p, RLIMIT_RTPRIO);
83433
83434+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83435 /* can't set/change the rt policy */
83436 if (policy != p->policy && !rlim_rtprio)
83437 return -EPERM;
83438@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83439
83440 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83441
83442-static struct ctl_table sd_ctl_dir[] = {
83443+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83444 {
83445 .procname = "sched_domain",
83446 .mode = 0555,
83447@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83448 {}
83449 };
83450
83451-static struct ctl_table *sd_alloc_ctl_entry(int n)
83452+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83453 {
83454- struct ctl_table *entry =
83455+ ctl_table_no_const *entry =
83456 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83457
83458 return entry;
83459 }
83460
83461-static void sd_free_ctl_entry(struct ctl_table **tablep)
83462+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83463 {
83464- struct ctl_table *entry;
83465+ ctl_table_no_const *entry;
83466
83467 /*
83468 * In the intermediate directories, both the child directory and
83469@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83470 * will always be set. In the lowest directory the names are
83471 * static strings and all have proc handlers.
83472 */
83473- for (entry = *tablep; entry->mode; entry++) {
83474- if (entry->child)
83475- sd_free_ctl_entry(&entry->child);
83476+ for (entry = tablep; entry->mode; entry++) {
83477+ if (entry->child) {
83478+ sd_free_ctl_entry(entry->child);
83479+ pax_open_kernel();
83480+ entry->child = NULL;
83481+ pax_close_kernel();
83482+ }
83483 if (entry->proc_handler == NULL)
83484 kfree(entry->procname);
83485 }
83486
83487- kfree(*tablep);
83488- *tablep = NULL;
83489+ kfree(tablep);
83490 }
83491
83492 static int min_load_idx = 0;
83493 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83494
83495 static void
83496-set_table_entry(struct ctl_table *entry,
83497+set_table_entry(ctl_table_no_const *entry,
83498 const char *procname, void *data, int maxlen,
83499 umode_t mode, proc_handler *proc_handler,
83500 bool load_idx)
83501@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83502 static struct ctl_table *
83503 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83504 {
83505- struct ctl_table *table = sd_alloc_ctl_entry(13);
83506+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83507
83508 if (table == NULL)
83509 return NULL;
83510@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83511 return table;
83512 }
83513
83514-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83515+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83516 {
83517- struct ctl_table *entry, *table;
83518+ ctl_table_no_const *entry, *table;
83519 struct sched_domain *sd;
83520 int domain_num = 0, i;
83521 char buf[32];
83522@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83523 static void register_sched_domain_sysctl(void)
83524 {
83525 int i, cpu_num = num_possible_cpus();
83526- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83527+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83528 char buf[32];
83529
83530 WARN_ON(sd_ctl_dir[0].child);
83531+ pax_open_kernel();
83532 sd_ctl_dir[0].child = entry;
83533+ pax_close_kernel();
83534
83535 if (entry == NULL)
83536 return;
83537@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83538 if (sd_sysctl_header)
83539 unregister_sysctl_table(sd_sysctl_header);
83540 sd_sysctl_header = NULL;
83541- if (sd_ctl_dir[0].child)
83542- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83543+ if (sd_ctl_dir[0].child) {
83544+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83545+ pax_open_kernel();
83546+ sd_ctl_dir[0].child = NULL;
83547+ pax_close_kernel();
83548+ }
83549 }
83550 #else
83551 static void register_sched_domain_sysctl(void)
83552diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83553index 31cbc15..ba68c15 100644
83554--- a/kernel/sched/fair.c
83555+++ b/kernel/sched/fair.c
83556@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83557
83558 static void reset_ptenuma_scan(struct task_struct *p)
83559 {
83560- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83561+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83562 p->mm->numa_scan_offset = 0;
83563 }
83564
83565@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83566 * run_rebalance_domains is triggered when needed from the scheduler tick.
83567 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83568 */
83569-static void run_rebalance_domains(struct softirq_action *h)
83570+static __latent_entropy void run_rebalance_domains(void)
83571 {
83572 int this_cpu = smp_processor_id();
83573 struct rq *this_rq = cpu_rq(this_cpu);
83574diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83575index ef0a7b2..1b728c1 100644
83576--- a/kernel/sched/sched.h
83577+++ b/kernel/sched/sched.h
83578@@ -1004,7 +1004,7 @@ struct sched_class {
83579 #ifdef CONFIG_FAIR_GROUP_SCHED
83580 void (*task_move_group) (struct task_struct *p, int on_rq);
83581 #endif
83582-};
83583+} __do_const;
83584
83585 #define sched_class_highest (&stop_sched_class)
83586 #define for_each_class(class) \
83587diff --git a/kernel/signal.c b/kernel/signal.c
83588index 50e4107..9409983 100644
83589--- a/kernel/signal.c
83590+++ b/kernel/signal.c
83591@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83592
83593 int print_fatal_signals __read_mostly;
83594
83595-static void __user *sig_handler(struct task_struct *t, int sig)
83596+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83597 {
83598 return t->sighand->action[sig - 1].sa.sa_handler;
83599 }
83600
83601-static int sig_handler_ignored(void __user *handler, int sig)
83602+static int sig_handler_ignored(__sighandler_t handler, int sig)
83603 {
83604 /* Is it explicitly or implicitly ignored? */
83605 return handler == SIG_IGN ||
83606@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83607
83608 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83609 {
83610- void __user *handler;
83611+ __sighandler_t handler;
83612
83613 handler = sig_handler(t, sig);
83614
83615@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83616 atomic_inc(&user->sigpending);
83617 rcu_read_unlock();
83618
83619+ if (!override_rlimit)
83620+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83621+
83622 if (override_rlimit ||
83623 atomic_read(&user->sigpending) <=
83624 task_rlimit(t, RLIMIT_SIGPENDING)) {
83625@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83626
83627 int unhandled_signal(struct task_struct *tsk, int sig)
83628 {
83629- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83630+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83631 if (is_global_init(tsk))
83632 return 1;
83633 if (handler != SIG_IGN && handler != SIG_DFL)
83634@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83635 }
83636 }
83637
83638+ /* allow glibc communication via tgkill to other threads in our
83639+ thread group */
83640+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83641+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83642+ && gr_handle_signal(t, sig))
83643+ return -EPERM;
83644+
83645 return security_task_kill(t, info, sig, 0);
83646 }
83647
83648@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83649 return send_signal(sig, info, p, 1);
83650 }
83651
83652-static int
83653+int
83654 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83655 {
83656 return send_signal(sig, info, t, 0);
83657@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83658 unsigned long int flags;
83659 int ret, blocked, ignored;
83660 struct k_sigaction *action;
83661+ int is_unhandled = 0;
83662
83663 spin_lock_irqsave(&t->sighand->siglock, flags);
83664 action = &t->sighand->action[sig-1];
83665@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83666 }
83667 if (action->sa.sa_handler == SIG_DFL)
83668 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83669+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83670+ is_unhandled = 1;
83671 ret = specific_send_sig_info(sig, info, t);
83672 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83673
83674+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83675+ normal operation */
83676+ if (is_unhandled) {
83677+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83678+ gr_handle_crash(t, sig);
83679+ }
83680+
83681 return ret;
83682 }
83683
83684@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83685 ret = check_kill_permission(sig, info, p);
83686 rcu_read_unlock();
83687
83688- if (!ret && sig)
83689+ if (!ret && sig) {
83690 ret = do_send_sig_info(sig, info, p, true);
83691+ if (!ret)
83692+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83693+ }
83694
83695 return ret;
83696 }
83697@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83698 int error = -ESRCH;
83699
83700 rcu_read_lock();
83701- p = find_task_by_vpid(pid);
83702+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83703+ /* allow glibc communication via tgkill to other threads in our
83704+ thread group */
83705+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83706+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83707+ p = find_task_by_vpid_unrestricted(pid);
83708+ else
83709+#endif
83710+ p = find_task_by_vpid(pid);
83711 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83712 error = check_kill_permission(sig, info, p);
83713 /*
83714@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83715 }
83716 seg = get_fs();
83717 set_fs(KERNEL_DS);
83718- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83719- (stack_t __force __user *) &uoss,
83720+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83721+ (stack_t __force_user *) &uoss,
83722 compat_user_stack_pointer());
83723 set_fs(seg);
83724 if (ret >= 0 && uoss_ptr) {
83725diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83726index eb89e18..a4e6792 100644
83727--- a/kernel/smpboot.c
83728+++ b/kernel/smpboot.c
83729@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83730 }
83731 smpboot_unpark_thread(plug_thread, cpu);
83732 }
83733- list_add(&plug_thread->list, &hotplug_threads);
83734+ pax_list_add(&plug_thread->list, &hotplug_threads);
83735 out:
83736 mutex_unlock(&smpboot_threads_lock);
83737 return ret;
83738@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83739 {
83740 get_online_cpus();
83741 mutex_lock(&smpboot_threads_lock);
83742- list_del(&plug_thread->list);
83743+ pax_list_del(&plug_thread->list);
83744 smpboot_destroy_threads(plug_thread);
83745 mutex_unlock(&smpboot_threads_lock);
83746 put_online_cpus();
83747diff --git a/kernel/softirq.c b/kernel/softirq.c
83748index adf6c00..5d89b73 100644
83749--- a/kernel/softirq.c
83750+++ b/kernel/softirq.c
83751@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83752 EXPORT_SYMBOL(irq_stat);
83753 #endif
83754
83755-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83756+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83757
83758 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83759
83760-char *softirq_to_name[NR_SOFTIRQS] = {
83761+const char * const softirq_to_name[NR_SOFTIRQS] = {
83762 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83763 "TASKLET", "SCHED", "HRTIMER", "RCU"
83764 };
83765@@ -248,7 +248,7 @@ restart:
83766 kstat_incr_softirqs_this_cpu(vec_nr);
83767
83768 trace_softirq_entry(vec_nr);
83769- h->action(h);
83770+ h->action();
83771 trace_softirq_exit(vec_nr);
83772 if (unlikely(prev_count != preempt_count())) {
83773 printk(KERN_ERR "huh, entered softirq %u %s %p"
83774@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83775 or_softirq_pending(1UL << nr);
83776 }
83777
83778-void open_softirq(int nr, void (*action)(struct softirq_action *))
83779+void __init open_softirq(int nr, void (*action)(void))
83780 {
83781 softirq_vec[nr].action = action;
83782 }
83783@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83784
83785 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83786
83787-static void tasklet_action(struct softirq_action *a)
83788+static __latent_entropy void tasklet_action(void)
83789 {
83790 struct tasklet_struct *list;
83791
83792@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83793 }
83794 }
83795
83796-static void tasklet_hi_action(struct softirq_action *a)
83797+static __latent_entropy void tasklet_hi_action(void)
83798 {
83799 struct tasklet_struct *list;
83800
83801@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83802 .notifier_call = cpu_callback
83803 };
83804
83805-static struct smp_hotplug_thread softirq_threads = {
83806+static struct smp_hotplug_thread softirq_threads __read_only = {
83807 .store = &ksoftirqd,
83808 .thread_should_run = ksoftirqd_should_run,
83809 .thread_fn = run_ksoftirqd,
83810diff --git a/kernel/srcu.c b/kernel/srcu.c
83811index 01d5ccb..cdcbee6 100644
83812--- a/kernel/srcu.c
83813+++ b/kernel/srcu.c
83814@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83815
83816 idx = ACCESS_ONCE(sp->completed) & 0x1;
83817 preempt_disable();
83818- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83819+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83820 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83821- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83822+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83823 preempt_enable();
83824 return idx;
83825 }
83826diff --git a/kernel/sys.c b/kernel/sys.c
83827index 771129b..dc0c7e3 100644
83828--- a/kernel/sys.c
83829+++ b/kernel/sys.c
83830@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83831 error = -EACCES;
83832 goto out;
83833 }
83834+
83835+ if (gr_handle_chroot_setpriority(p, niceval)) {
83836+ error = -EACCES;
83837+ goto out;
83838+ }
83839+
83840 no_nice = security_task_setnice(p, niceval);
83841 if (no_nice) {
83842 error = no_nice;
83843@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83844 goto error;
83845 }
83846
83847+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83848+ goto error;
83849+
83850 if (rgid != (gid_t) -1 ||
83851 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83852 new->sgid = new->egid;
83853@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83854 old = current_cred();
83855
83856 retval = -EPERM;
83857+
83858+ if (gr_check_group_change(kgid, kgid, kgid))
83859+ goto error;
83860+
83861 if (nsown_capable(CAP_SETGID))
83862 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83863 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83864@@ -404,7 +417,7 @@ error:
83865 /*
83866 * change the user struct in a credentials set to match the new UID
83867 */
83868-static int set_user(struct cred *new)
83869+int set_user(struct cred *new)
83870 {
83871 struct user_struct *new_user;
83872
83873@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83874 goto error;
83875 }
83876
83877+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83878+ goto error;
83879+
83880 if (!uid_eq(new->uid, old->uid)) {
83881 retval = set_user(new);
83882 if (retval < 0)
83883@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83884 old = current_cred();
83885
83886 retval = -EPERM;
83887+
83888+ if (gr_check_crash_uid(kuid))
83889+ goto error;
83890+ if (gr_check_user_change(kuid, kuid, kuid))
83891+ goto error;
83892+
83893 if (nsown_capable(CAP_SETUID)) {
83894 new->suid = new->uid = kuid;
83895 if (!uid_eq(kuid, old->uid)) {
83896@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83897 goto error;
83898 }
83899
83900+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83901+ goto error;
83902+
83903 if (ruid != (uid_t) -1) {
83904 new->uid = kruid;
83905 if (!uid_eq(kruid, old->uid)) {
83906@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83907 goto error;
83908 }
83909
83910+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83911+ goto error;
83912+
83913 if (rgid != (gid_t) -1)
83914 new->gid = krgid;
83915 if (egid != (gid_t) -1)
83916@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83917 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83918 nsown_capable(CAP_SETUID)) {
83919 if (!uid_eq(kuid, old->fsuid)) {
83920+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83921+ goto error;
83922+
83923 new->fsuid = kuid;
83924 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83925 goto change_okay;
83926 }
83927 }
83928
83929+error:
83930 abort_creds(new);
83931 return old_fsuid;
83932
83933@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83934 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83935 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83936 nsown_capable(CAP_SETGID)) {
83937+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83938+ goto error;
83939+
83940 if (!gid_eq(kgid, old->fsgid)) {
83941 new->fsgid = kgid;
83942 goto change_okay;
83943 }
83944 }
83945
83946+error:
83947 abort_creds(new);
83948 return old_fsgid;
83949
83950@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83951 return -EFAULT;
83952
83953 down_read(&uts_sem);
83954- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83955+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83956 __OLD_UTS_LEN);
83957 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83958- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83959+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83960 __OLD_UTS_LEN);
83961 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83962- error |= __copy_to_user(&name->release, &utsname()->release,
83963+ error |= __copy_to_user(name->release, &utsname()->release,
83964 __OLD_UTS_LEN);
83965 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83966- error |= __copy_to_user(&name->version, &utsname()->version,
83967+ error |= __copy_to_user(name->version, &utsname()->version,
83968 __OLD_UTS_LEN);
83969 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83970- error |= __copy_to_user(&name->machine, &utsname()->machine,
83971+ error |= __copy_to_user(name->machine, &utsname()->machine,
83972 __OLD_UTS_LEN);
83973 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83974 up_read(&uts_sem);
83975@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83976 */
83977 new_rlim->rlim_cur = 1;
83978 }
83979+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83980+ is changed to a lower value. Since tasks can be created by the same
83981+ user in between this limit change and an execve by this task, force
83982+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83983+ */
83984+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83985+ tsk->flags |= PF_NPROC_EXCEEDED;
83986 }
83987 if (!retval) {
83988 if (old_rlim)
83989diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83990index 07f6fc4..65fb3d4 100644
83991--- a/kernel/sysctl.c
83992+++ b/kernel/sysctl.c
83993@@ -93,7 +93,6 @@
83994
83995
83996 #if defined(CONFIG_SYSCTL)
83997-
83998 /* External variables not in a header file. */
83999 extern int sysctl_overcommit_memory;
84000 extern int sysctl_overcommit_ratio;
84001@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84002
84003 /* Constants used for minimum and maximum */
84004 #ifdef CONFIG_LOCKUP_DETECTOR
84005-static int sixty = 60;
84006+static int sixty __read_only = 60;
84007 #endif
84008
84009-static int zero;
84010-static int __maybe_unused one = 1;
84011-static int __maybe_unused two = 2;
84012-static int __maybe_unused three = 3;
84013-static unsigned long one_ul = 1;
84014-static int one_hundred = 100;
84015+static int neg_one __read_only = -1;
84016+static int zero __read_only = 0;
84017+static int __maybe_unused one __read_only = 1;
84018+static int __maybe_unused two __read_only = 2;
84019+static int __maybe_unused three __read_only = 3;
84020+static unsigned long one_ul __read_only = 1;
84021+static int one_hundred __read_only = 100;
84022 #ifdef CONFIG_PRINTK
84023-static int ten_thousand = 10000;
84024+static int ten_thousand __read_only = 10000;
84025 #endif
84026
84027 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84028@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84029 void __user *buffer, size_t *lenp, loff_t *ppos);
84030 #endif
84031
84032-#ifdef CONFIG_PRINTK
84033 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84034 void __user *buffer, size_t *lenp, loff_t *ppos);
84035-#endif
84036
84037 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84038 void __user *buffer, size_t *lenp, loff_t *ppos);
84039@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84040
84041 #endif
84042
84043+extern struct ctl_table grsecurity_table[];
84044+
84045 static struct ctl_table kern_table[];
84046 static struct ctl_table vm_table[];
84047 static struct ctl_table fs_table[];
84048@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84049 int sysctl_legacy_va_layout;
84050 #endif
84051
84052+#ifdef CONFIG_PAX_SOFTMODE
84053+static ctl_table pax_table[] = {
84054+ {
84055+ .procname = "softmode",
84056+ .data = &pax_softmode,
84057+ .maxlen = sizeof(unsigned int),
84058+ .mode = 0600,
84059+ .proc_handler = &proc_dointvec,
84060+ },
84061+
84062+ { }
84063+};
84064+#endif
84065+
84066 /* The default sysctl tables: */
84067
84068 static struct ctl_table sysctl_base_table[] = {
84069@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84070 #endif
84071
84072 static struct ctl_table kern_table[] = {
84073+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84074+ {
84075+ .procname = "grsecurity",
84076+ .mode = 0500,
84077+ .child = grsecurity_table,
84078+ },
84079+#endif
84080+
84081+#ifdef CONFIG_PAX_SOFTMODE
84082+ {
84083+ .procname = "pax",
84084+ .mode = 0500,
84085+ .child = pax_table,
84086+ },
84087+#endif
84088+
84089 {
84090 .procname = "sched_child_runs_first",
84091 .data = &sysctl_sched_child_runs_first,
84092@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84093 .data = &modprobe_path,
84094 .maxlen = KMOD_PATH_LEN,
84095 .mode = 0644,
84096- .proc_handler = proc_dostring,
84097+ .proc_handler = proc_dostring_modpriv,
84098 },
84099 {
84100 .procname = "modules_disabled",
84101@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84102 .extra1 = &zero,
84103 .extra2 = &one,
84104 },
84105+#endif
84106 {
84107 .procname = "kptr_restrict",
84108 .data = &kptr_restrict,
84109 .maxlen = sizeof(int),
84110 .mode = 0644,
84111 .proc_handler = proc_dointvec_minmax_sysadmin,
84112+#ifdef CONFIG_GRKERNSEC_HIDESYM
84113+ .extra1 = &two,
84114+#else
84115 .extra1 = &zero,
84116+#endif
84117 .extra2 = &two,
84118 },
84119-#endif
84120 {
84121 .procname = "ngroups_max",
84122 .data = &ngroups_max,
84123@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84124 */
84125 {
84126 .procname = "perf_event_paranoid",
84127- .data = &sysctl_perf_event_paranoid,
84128- .maxlen = sizeof(sysctl_perf_event_paranoid),
84129+ .data = &sysctl_perf_event_legitimately_concerned,
84130+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84131 .mode = 0644,
84132- .proc_handler = proc_dointvec,
84133+ /* go ahead, be a hero */
84134+ .proc_handler = proc_dointvec_minmax_sysadmin,
84135+ .extra1 = &neg_one,
84136+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84137+ .extra2 = &three,
84138+#else
84139+ .extra2 = &two,
84140+#endif
84141 },
84142 {
84143 .procname = "perf_event_mlock_kb",
84144@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84145 .proc_handler = proc_dointvec_minmax,
84146 .extra1 = &zero,
84147 },
84148+ {
84149+ .procname = "heap_stack_gap",
84150+ .data = &sysctl_heap_stack_gap,
84151+ .maxlen = sizeof(sysctl_heap_stack_gap),
84152+ .mode = 0644,
84153+ .proc_handler = proc_doulongvec_minmax,
84154+ },
84155 #else
84156 {
84157 .procname = "nr_trim_pages",
84158@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84159 buffer, lenp, ppos);
84160 }
84161
84162+int proc_dostring_modpriv(struct ctl_table *table, int write,
84163+ void __user *buffer, size_t *lenp, loff_t *ppos)
84164+{
84165+ if (write && !capable(CAP_SYS_MODULE))
84166+ return -EPERM;
84167+
84168+ return _proc_do_string(table->data, table->maxlen, write,
84169+ buffer, lenp, ppos);
84170+}
84171+
84172 static size_t proc_skip_spaces(char **buf)
84173 {
84174 size_t ret;
84175@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84176 len = strlen(tmp);
84177 if (len > *size)
84178 len = *size;
84179+ if (len > sizeof(tmp))
84180+ len = sizeof(tmp);
84181 if (copy_to_user(*buf, tmp, len))
84182 return -EFAULT;
84183 *size -= len;
84184@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84185 static int proc_taint(struct ctl_table *table, int write,
84186 void __user *buffer, size_t *lenp, loff_t *ppos)
84187 {
84188- struct ctl_table t;
84189+ ctl_table_no_const t;
84190 unsigned long tmptaint = get_taint();
84191 int err;
84192
84193@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84194 return err;
84195 }
84196
84197-#ifdef CONFIG_PRINTK
84198 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84199 void __user *buffer, size_t *lenp, loff_t *ppos)
84200 {
84201@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84202
84203 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84204 }
84205-#endif
84206
84207 struct do_proc_dointvec_minmax_conv_param {
84208 int *min;
84209@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84210 *i = val;
84211 } else {
84212 val = convdiv * (*i) / convmul;
84213- if (!first)
84214+ if (!first) {
84215 err = proc_put_char(&buffer, &left, '\t');
84216+ if (err)
84217+ break;
84218+ }
84219 err = proc_put_long(&buffer, &left, val, false);
84220 if (err)
84221 break;
84222@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84223 return -ENOSYS;
84224 }
84225
84226+int proc_dostring_modpriv(struct ctl_table *table, int write,
84227+ void __user *buffer, size_t *lenp, loff_t *ppos)
84228+{
84229+ return -ENOSYS;
84230+}
84231+
84232 int proc_dointvec(struct ctl_table *table, int write,
84233 void __user *buffer, size_t *lenp, loff_t *ppos)
84234 {
84235@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84236 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84237 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84238 EXPORT_SYMBOL(proc_dostring);
84239+EXPORT_SYMBOL(proc_dostring_modpriv);
84240 EXPORT_SYMBOL(proc_doulongvec_minmax);
84241 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84242diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84243index 145bb4d..b2aa969 100644
84244--- a/kernel/taskstats.c
84245+++ b/kernel/taskstats.c
84246@@ -28,9 +28,12 @@
84247 #include <linux/fs.h>
84248 #include <linux/file.h>
84249 #include <linux/pid_namespace.h>
84250+#include <linux/grsecurity.h>
84251 #include <net/genetlink.h>
84252 #include <linux/atomic.h>
84253
84254+extern int gr_is_taskstats_denied(int pid);
84255+
84256 /*
84257 * Maximum length of a cpumask that can be specified in
84258 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84259@@ -570,6 +573,9 @@ err:
84260
84261 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84262 {
84263+ if (gr_is_taskstats_denied(current->pid))
84264+ return -EACCES;
84265+
84266 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84267 return cmd_attr_register_cpumask(info);
84268 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84269diff --git a/kernel/time.c b/kernel/time.c
84270index 7c7964c..784a599 100644
84271--- a/kernel/time.c
84272+++ b/kernel/time.c
84273@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84274 return error;
84275
84276 if (tz) {
84277+ /* we log in do_settimeofday called below, so don't log twice
84278+ */
84279+ if (!tv)
84280+ gr_log_timechange();
84281+
84282 sys_tz = *tz;
84283 update_vsyscall_tz();
84284 if (firsttime) {
84285@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84286 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84287 * value to a scaled second value.
84288 */
84289-unsigned long
84290+unsigned long __intentional_overflow(-1)
84291 timespec_to_jiffies(const struct timespec *value)
84292 {
84293 unsigned long sec = value->tv_sec;
84294diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84295index eec50fc..65e5df6 100644
84296--- a/kernel/time/alarmtimer.c
84297+++ b/kernel/time/alarmtimer.c
84298@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84299 struct platform_device *pdev;
84300 int error = 0;
84301 int i;
84302- struct k_clock alarm_clock = {
84303+ static struct k_clock alarm_clock = {
84304 .clock_getres = alarm_clock_getres,
84305 .clock_get = alarm_clock_get,
84306 .timer_create = alarm_timer_create,
84307diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84308index 947ba25..20cbade 100644
84309--- a/kernel/time/timekeeping.c
84310+++ b/kernel/time/timekeeping.c
84311@@ -15,6 +15,7 @@
84312 #include <linux/init.h>
84313 #include <linux/mm.h>
84314 #include <linux/sched.h>
84315+#include <linux/grsecurity.h>
84316 #include <linux/syscore_ops.h>
84317 #include <linux/clocksource.h>
84318 #include <linux/jiffies.h>
84319@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84320 if (!timespec_valid_strict(tv))
84321 return -EINVAL;
84322
84323+ gr_log_timechange();
84324+
84325 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84326 write_seqcount_begin(&timekeeper_seq);
84327
84328diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84329index 61ed862..3b52c65 100644
84330--- a/kernel/time/timer_list.c
84331+++ b/kernel/time/timer_list.c
84332@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84333
84334 static void print_name_offset(struct seq_file *m, void *sym)
84335 {
84336+#ifdef CONFIG_GRKERNSEC_HIDESYM
84337+ SEQ_printf(m, "<%p>", NULL);
84338+#else
84339 char symname[KSYM_NAME_LEN];
84340
84341 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84342 SEQ_printf(m, "<%pK>", sym);
84343 else
84344 SEQ_printf(m, "%s", symname);
84345+#endif
84346 }
84347
84348 static void
84349@@ -119,7 +123,11 @@ next_one:
84350 static void
84351 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84352 {
84353+#ifdef CONFIG_GRKERNSEC_HIDESYM
84354+ SEQ_printf(m, " .base: %p\n", NULL);
84355+#else
84356 SEQ_printf(m, " .base: %pK\n", base);
84357+#endif
84358 SEQ_printf(m, " .index: %d\n",
84359 base->index);
84360 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84361@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84362 {
84363 struct proc_dir_entry *pe;
84364
84365+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84366+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84367+#else
84368 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84369+#endif
84370 if (!pe)
84371 return -ENOMEM;
84372 return 0;
84373diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84374index 0b537f2..40d6c20 100644
84375--- a/kernel/time/timer_stats.c
84376+++ b/kernel/time/timer_stats.c
84377@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84378 static unsigned long nr_entries;
84379 static struct entry entries[MAX_ENTRIES];
84380
84381-static atomic_t overflow_count;
84382+static atomic_unchecked_t overflow_count;
84383
84384 /*
84385 * The entries are in a hash-table, for fast lookup:
84386@@ -140,7 +140,7 @@ static void reset_entries(void)
84387 nr_entries = 0;
84388 memset(entries, 0, sizeof(entries));
84389 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84390- atomic_set(&overflow_count, 0);
84391+ atomic_set_unchecked(&overflow_count, 0);
84392 }
84393
84394 static struct entry *alloc_entry(void)
84395@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84396 if (likely(entry))
84397 entry->count++;
84398 else
84399- atomic_inc(&overflow_count);
84400+ atomic_inc_unchecked(&overflow_count);
84401
84402 out_unlock:
84403 raw_spin_unlock_irqrestore(lock, flags);
84404@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84405
84406 static void print_name_offset(struct seq_file *m, unsigned long addr)
84407 {
84408+#ifdef CONFIG_GRKERNSEC_HIDESYM
84409+ seq_printf(m, "<%p>", NULL);
84410+#else
84411 char symname[KSYM_NAME_LEN];
84412
84413 if (lookup_symbol_name(addr, symname) < 0)
84414- seq_printf(m, "<%p>", (void *)addr);
84415+ seq_printf(m, "<%pK>", (void *)addr);
84416 else
84417 seq_printf(m, "%s", symname);
84418+#endif
84419 }
84420
84421 static int tstats_show(struct seq_file *m, void *v)
84422@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84423
84424 seq_puts(m, "Timer Stats Version: v0.2\n");
84425 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84426- if (atomic_read(&overflow_count))
84427+ if (atomic_read_unchecked(&overflow_count))
84428 seq_printf(m, "Overflow: %d entries\n",
84429- atomic_read(&overflow_count));
84430+ atomic_read_unchecked(&overflow_count));
84431
84432 for (i = 0; i < nr_entries; i++) {
84433 entry = entries + i;
84434@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84435 {
84436 struct proc_dir_entry *pe;
84437
84438+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84439+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84440+#else
84441 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84442+#endif
84443 if (!pe)
84444 return -ENOMEM;
84445 return 0;
84446diff --git a/kernel/timer.c b/kernel/timer.c
84447index 4296d13..0164b04 100644
84448--- a/kernel/timer.c
84449+++ b/kernel/timer.c
84450@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84451 /*
84452 * This function runs timers and the timer-tq in bottom half context.
84453 */
84454-static void run_timer_softirq(struct softirq_action *h)
84455+static __latent_entropy void run_timer_softirq(void)
84456 {
84457 struct tvec_base *base = __this_cpu_read(tvec_bases);
84458
84459@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84460 *
84461 * In all cases the return value is guaranteed to be non-negative.
84462 */
84463-signed long __sched schedule_timeout(signed long timeout)
84464+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84465 {
84466 struct timer_list timer;
84467 unsigned long expire;
84468diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84469index b8b8560..75b1a09 100644
84470--- a/kernel/trace/blktrace.c
84471+++ b/kernel/trace/blktrace.c
84472@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84473 struct blk_trace *bt = filp->private_data;
84474 char buf[16];
84475
84476- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84477+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84478
84479 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84480 }
84481@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84482 return 1;
84483
84484 bt = buf->chan->private_data;
84485- atomic_inc(&bt->dropped);
84486+ atomic_inc_unchecked(&bt->dropped);
84487 return 0;
84488 }
84489
84490@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84491
84492 bt->dir = dir;
84493 bt->dev = dev;
84494- atomic_set(&bt->dropped, 0);
84495+ atomic_set_unchecked(&bt->dropped, 0);
84496
84497 ret = -EIO;
84498 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84499diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84500index a6d098c..bb8cf65 100644
84501--- a/kernel/trace/ftrace.c
84502+++ b/kernel/trace/ftrace.c
84503@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84504 if (unlikely(ftrace_disabled))
84505 return 0;
84506
84507+ ret = ftrace_arch_code_modify_prepare();
84508+ FTRACE_WARN_ON(ret);
84509+ if (ret)
84510+ return 0;
84511+
84512 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84513+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84514 if (ret) {
84515 ftrace_bug(ret, ip);
84516- return 0;
84517 }
84518- return 1;
84519+ return ret ? 0 : 1;
84520 }
84521
84522 /*
84523@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84524 if (!count)
84525 return 0;
84526
84527+ pax_open_kernel();
84528 sort(start, count, sizeof(*start),
84529 ftrace_cmp_ips, ftrace_swap_ips);
84530+ pax_close_kernel();
84531
84532 start_pg = ftrace_allocate_pages(count);
84533 if (!start_pg)
84534@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84535 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84536
84537 static int ftrace_graph_active;
84538-static struct notifier_block ftrace_suspend_notifier;
84539-
84540 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84541 {
84542 return 0;
84543@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84544 return NOTIFY_DONE;
84545 }
84546
84547+static struct notifier_block ftrace_suspend_notifier = {
84548+ .notifier_call = ftrace_suspend_notifier_call
84549+};
84550+
84551 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84552 trace_func_graph_ent_t entryfunc)
84553 {
84554@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84555 goto out;
84556 }
84557
84558- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84559 register_pm_notifier(&ftrace_suspend_notifier);
84560
84561 ftrace_graph_active++;
84562diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84563index cc2f66f..05edd54 100644
84564--- a/kernel/trace/ring_buffer.c
84565+++ b/kernel/trace/ring_buffer.c
84566@@ -352,9 +352,9 @@ struct buffer_data_page {
84567 */
84568 struct buffer_page {
84569 struct list_head list; /* list of buffer pages */
84570- local_t write; /* index for next write */
84571+ local_unchecked_t write; /* index for next write */
84572 unsigned read; /* index for next read */
84573- local_t entries; /* entries on this page */
84574+ local_unchecked_t entries; /* entries on this page */
84575 unsigned long real_end; /* real end of data */
84576 struct buffer_data_page *page; /* Actual data page */
84577 };
84578@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84579 unsigned long last_overrun;
84580 local_t entries_bytes;
84581 local_t entries;
84582- local_t overrun;
84583- local_t commit_overrun;
84584+ local_unchecked_t overrun;
84585+ local_unchecked_t commit_overrun;
84586 local_t dropped_events;
84587 local_t committing;
84588 local_t commits;
84589@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84590 *
84591 * We add a counter to the write field to denote this.
84592 */
84593- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84594- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84595+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84596+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84597
84598 /*
84599 * Just make sure we have seen our old_write and synchronize
84600@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84601 * cmpxchg to only update if an interrupt did not already
84602 * do it for us. If the cmpxchg fails, we don't care.
84603 */
84604- (void)local_cmpxchg(&next_page->write, old_write, val);
84605- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84606+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84607+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84608
84609 /*
84610 * No need to worry about races with clearing out the commit.
84611@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84612
84613 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84614 {
84615- return local_read(&bpage->entries) & RB_WRITE_MASK;
84616+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84617 }
84618
84619 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84620 {
84621- return local_read(&bpage->write) & RB_WRITE_MASK;
84622+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84623 }
84624
84625 static int
84626@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84627 * bytes consumed in ring buffer from here.
84628 * Increment overrun to account for the lost events.
84629 */
84630- local_add(page_entries, &cpu_buffer->overrun);
84631+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84632 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84633 }
84634
84635@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84636 * it is our responsibility to update
84637 * the counters.
84638 */
84639- local_add(entries, &cpu_buffer->overrun);
84640+ local_add_unchecked(entries, &cpu_buffer->overrun);
84641 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84642
84643 /*
84644@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84645 if (tail == BUF_PAGE_SIZE)
84646 tail_page->real_end = 0;
84647
84648- local_sub(length, &tail_page->write);
84649+ local_sub_unchecked(length, &tail_page->write);
84650 return;
84651 }
84652
84653@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84654 rb_event_set_padding(event);
84655
84656 /* Set the write back to the previous setting */
84657- local_sub(length, &tail_page->write);
84658+ local_sub_unchecked(length, &tail_page->write);
84659 return;
84660 }
84661
84662@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84663
84664 /* Set write to end of buffer */
84665 length = (tail + length) - BUF_PAGE_SIZE;
84666- local_sub(length, &tail_page->write);
84667+ local_sub_unchecked(length, &tail_page->write);
84668 }
84669
84670 /*
84671@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84672 * about it.
84673 */
84674 if (unlikely(next_page == commit_page)) {
84675- local_inc(&cpu_buffer->commit_overrun);
84676+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84677 goto out_reset;
84678 }
84679
84680@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84681 cpu_buffer->tail_page) &&
84682 (cpu_buffer->commit_page ==
84683 cpu_buffer->reader_page))) {
84684- local_inc(&cpu_buffer->commit_overrun);
84685+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84686 goto out_reset;
84687 }
84688 }
84689@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84690 length += RB_LEN_TIME_EXTEND;
84691
84692 tail_page = cpu_buffer->tail_page;
84693- write = local_add_return(length, &tail_page->write);
84694+ write = local_add_return_unchecked(length, &tail_page->write);
84695
84696 /* set write to only the index of the write */
84697 write &= RB_WRITE_MASK;
84698@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84699 kmemcheck_annotate_bitfield(event, bitfield);
84700 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84701
84702- local_inc(&tail_page->entries);
84703+ local_inc_unchecked(&tail_page->entries);
84704
84705 /*
84706 * If this is the first commit on the page, then update
84707@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84708
84709 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84710 unsigned long write_mask =
84711- local_read(&bpage->write) & ~RB_WRITE_MASK;
84712+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84713 unsigned long event_length = rb_event_length(event);
84714 /*
84715 * This is on the tail page. It is possible that
84716@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84717 */
84718 old_index += write_mask;
84719 new_index += write_mask;
84720- index = local_cmpxchg(&bpage->write, old_index, new_index);
84721+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84722 if (index == old_index) {
84723 /* update counters */
84724 local_sub(event_length, &cpu_buffer->entries_bytes);
84725@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84726
84727 /* Do the likely case first */
84728 if (likely(bpage->page == (void *)addr)) {
84729- local_dec(&bpage->entries);
84730+ local_dec_unchecked(&bpage->entries);
84731 return;
84732 }
84733
84734@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84735 start = bpage;
84736 do {
84737 if (bpage->page == (void *)addr) {
84738- local_dec(&bpage->entries);
84739+ local_dec_unchecked(&bpage->entries);
84740 return;
84741 }
84742 rb_inc_page(cpu_buffer, &bpage);
84743@@ -3139,7 +3139,7 @@ static inline unsigned long
84744 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84745 {
84746 return local_read(&cpu_buffer->entries) -
84747- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84748+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84749 }
84750
84751 /**
84752@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84753 return 0;
84754
84755 cpu_buffer = buffer->buffers[cpu];
84756- ret = local_read(&cpu_buffer->overrun);
84757+ ret = local_read_unchecked(&cpu_buffer->overrun);
84758
84759 return ret;
84760 }
84761@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84762 return 0;
84763
84764 cpu_buffer = buffer->buffers[cpu];
84765- ret = local_read(&cpu_buffer->commit_overrun);
84766+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84767
84768 return ret;
84769 }
84770@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84771 /* if you care about this being correct, lock the buffer */
84772 for_each_buffer_cpu(buffer, cpu) {
84773 cpu_buffer = buffer->buffers[cpu];
84774- overruns += local_read(&cpu_buffer->overrun);
84775+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84776 }
84777
84778 return overruns;
84779@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84780 /*
84781 * Reset the reader page to size zero.
84782 */
84783- local_set(&cpu_buffer->reader_page->write, 0);
84784- local_set(&cpu_buffer->reader_page->entries, 0);
84785+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84786+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84787 local_set(&cpu_buffer->reader_page->page->commit, 0);
84788 cpu_buffer->reader_page->real_end = 0;
84789
84790@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84791 * want to compare with the last_overrun.
84792 */
84793 smp_mb();
84794- overwrite = local_read(&(cpu_buffer->overrun));
84795+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84796
84797 /*
84798 * Here's the tricky part.
84799@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84800
84801 cpu_buffer->head_page
84802 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84803- local_set(&cpu_buffer->head_page->write, 0);
84804- local_set(&cpu_buffer->head_page->entries, 0);
84805+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84806+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84807 local_set(&cpu_buffer->head_page->page->commit, 0);
84808
84809 cpu_buffer->head_page->read = 0;
84810@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84811
84812 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84813 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84814- local_set(&cpu_buffer->reader_page->write, 0);
84815- local_set(&cpu_buffer->reader_page->entries, 0);
84816+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84817+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84818 local_set(&cpu_buffer->reader_page->page->commit, 0);
84819 cpu_buffer->reader_page->read = 0;
84820
84821 local_set(&cpu_buffer->entries_bytes, 0);
84822- local_set(&cpu_buffer->overrun, 0);
84823- local_set(&cpu_buffer->commit_overrun, 0);
84824+ local_set_unchecked(&cpu_buffer->overrun, 0);
84825+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84826 local_set(&cpu_buffer->dropped_events, 0);
84827 local_set(&cpu_buffer->entries, 0);
84828 local_set(&cpu_buffer->committing, 0);
84829@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84830 rb_init_page(bpage);
84831 bpage = reader->page;
84832 reader->page = *data_page;
84833- local_set(&reader->write, 0);
84834- local_set(&reader->entries, 0);
84835+ local_set_unchecked(&reader->write, 0);
84836+ local_set_unchecked(&reader->entries, 0);
84837 reader->read = 0;
84838 *data_page = bpage;
84839
84840diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84841index 496f94d..754aeea 100644
84842--- a/kernel/trace/trace.c
84843+++ b/kernel/trace/trace.c
84844@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84845 return 0;
84846 }
84847
84848-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84849+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84850 {
84851 /* do nothing if flag is already set */
84852 if (!!(trace_flags & mask) == !!enabled)
84853diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84854index afaae41..64871f8 100644
84855--- a/kernel/trace/trace.h
84856+++ b/kernel/trace/trace.h
84857@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84858 void trace_printk_init_buffers(void);
84859 void trace_printk_start_comm(void);
84860 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84861-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84862+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84863
84864 /*
84865 * Normal trace_printk() and friends allocates special buffers
84866diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84867index 26dc348..8708ca7 100644
84868--- a/kernel/trace/trace_clock.c
84869+++ b/kernel/trace/trace_clock.c
84870@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84871 return now;
84872 }
84873
84874-static atomic64_t trace_counter;
84875+static atomic64_unchecked_t trace_counter;
84876
84877 /*
84878 * trace_clock_counter(): simply an atomic counter.
84879@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84880 */
84881 u64 notrace trace_clock_counter(void)
84882 {
84883- return atomic64_add_return(1, &trace_counter);
84884+ return atomic64_inc_return_unchecked(&trace_counter);
84885 }
84886diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84887index 29a7ebc..eb473cf 100644
84888--- a/kernel/trace/trace_events.c
84889+++ b/kernel/trace/trace_events.c
84890@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84891 struct ftrace_module_file_ops {
84892 struct list_head list;
84893 struct module *mod;
84894- struct file_operations id;
84895- struct file_operations enable;
84896- struct file_operations format;
84897- struct file_operations filter;
84898 };
84899
84900 static struct ftrace_module_file_ops *
84901@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84902
84903 file_ops->mod = mod;
84904
84905- file_ops->id = ftrace_event_id_fops;
84906- file_ops->id.owner = mod;
84907-
84908- file_ops->enable = ftrace_enable_fops;
84909- file_ops->enable.owner = mod;
84910-
84911- file_ops->filter = ftrace_event_filter_fops;
84912- file_ops->filter.owner = mod;
84913-
84914- file_ops->format = ftrace_event_format_fops;
84915- file_ops->format.owner = mod;
84916+ pax_open_kernel();
84917+ mod->trace_id.owner = mod;
84918+ mod->trace_enable.owner = mod;
84919+ mod->trace_filter.owner = mod;
84920+ mod->trace_format.owner = mod;
84921+ pax_close_kernel();
84922
84923 list_add(&file_ops->list, &ftrace_module_file_list);
84924
84925@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84926 struct ftrace_module_file_ops *file_ops)
84927 {
84928 return __trace_add_new_event(call, tr,
84929- &file_ops->id, &file_ops->enable,
84930- &file_ops->filter, &file_ops->format);
84931+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84932+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84933 }
84934
84935 #else
84936diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84937index b3dcfb2..ebee344 100644
84938--- a/kernel/trace/trace_mmiotrace.c
84939+++ b/kernel/trace/trace_mmiotrace.c
84940@@ -24,7 +24,7 @@ struct header_iter {
84941 static struct trace_array *mmio_trace_array;
84942 static bool overrun_detected;
84943 static unsigned long prev_overruns;
84944-static atomic_t dropped_count;
84945+static atomic_unchecked_t dropped_count;
84946
84947 static void mmio_reset_data(struct trace_array *tr)
84948 {
84949@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84950
84951 static unsigned long count_overruns(struct trace_iterator *iter)
84952 {
84953- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84954+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84955 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84956
84957 if (over > prev_overruns)
84958@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84959 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84960 sizeof(*entry), 0, pc);
84961 if (!event) {
84962- atomic_inc(&dropped_count);
84963+ atomic_inc_unchecked(&dropped_count);
84964 return;
84965 }
84966 entry = ring_buffer_event_data(event);
84967@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84968 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84969 sizeof(*entry), 0, pc);
84970 if (!event) {
84971- atomic_inc(&dropped_count);
84972+ atomic_inc_unchecked(&dropped_count);
84973 return;
84974 }
84975 entry = ring_buffer_event_data(event);
84976diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84977index 34e7cba..6f9a729 100644
84978--- a/kernel/trace/trace_output.c
84979+++ b/kernel/trace/trace_output.c
84980@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84981
84982 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84983 if (!IS_ERR(p)) {
84984- p = mangle_path(s->buffer + s->len, p, "\n");
84985+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84986 if (p) {
84987 s->len = p - s->buffer;
84988 return 1;
84989@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84990 goto out;
84991 }
84992
84993+ pax_open_kernel();
84994 if (event->funcs->trace == NULL)
84995- event->funcs->trace = trace_nop_print;
84996+ *(void **)&event->funcs->trace = trace_nop_print;
84997 if (event->funcs->raw == NULL)
84998- event->funcs->raw = trace_nop_print;
84999+ *(void **)&event->funcs->raw = trace_nop_print;
85000 if (event->funcs->hex == NULL)
85001- event->funcs->hex = trace_nop_print;
85002+ *(void **)&event->funcs->hex = trace_nop_print;
85003 if (event->funcs->binary == NULL)
85004- event->funcs->binary = trace_nop_print;
85005+ *(void **)&event->funcs->binary = trace_nop_print;
85006+ pax_close_kernel();
85007
85008 key = event->type & (EVENT_HASHSIZE - 1);
85009
85010diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85011index b20428c..4845a10 100644
85012--- a/kernel/trace/trace_stack.c
85013+++ b/kernel/trace/trace_stack.c
85014@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85015 return;
85016
85017 /* we do not handle interrupt stacks yet */
85018- if (!object_is_on_stack(stack))
85019+ if (!object_starts_on_stack(stack))
85020 return;
85021
85022 local_irq_save(flags);
85023diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85024index 9064b91..1f5d2f8 100644
85025--- a/kernel/user_namespace.c
85026+++ b/kernel/user_namespace.c
85027@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85028 !kgid_has_mapping(parent_ns, group))
85029 return -EPERM;
85030
85031+#ifdef CONFIG_GRKERNSEC
85032+ /*
85033+ * This doesn't really inspire confidence:
85034+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85035+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85036+ * Increases kernel attack surface in areas developers
85037+ * previously cared little about ("low importance due
85038+ * to requiring "root" capability")
85039+ * To be removed when this code receives *proper* review
85040+ */
85041+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85042+ !capable(CAP_SETGID))
85043+ return -EPERM;
85044+#endif
85045+
85046 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85047 if (!ns)
85048 return -ENOMEM;
85049@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85050 if (atomic_read(&current->mm->mm_users) > 1)
85051 return -EINVAL;
85052
85053- if (current->fs->users != 1)
85054+ if (atomic_read(&current->fs->users) != 1)
85055 return -EINVAL;
85056
85057 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85058diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85059index 4f69f9a..7c6f8f8 100644
85060--- a/kernel/utsname_sysctl.c
85061+++ b/kernel/utsname_sysctl.c
85062@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85063 static int proc_do_uts_string(ctl_table *table, int write,
85064 void __user *buffer, size_t *lenp, loff_t *ppos)
85065 {
85066- struct ctl_table uts_table;
85067+ ctl_table_no_const uts_table;
85068 int r;
85069 memcpy(&uts_table, table, sizeof(uts_table));
85070 uts_table.data = get_uts(table, write);
85071diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85072index 1241d8c..d5cfc28 100644
85073--- a/kernel/watchdog.c
85074+++ b/kernel/watchdog.c
85075@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85076 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85077 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85078
85079-static struct smp_hotplug_thread watchdog_threads = {
85080+static struct smp_hotplug_thread watchdog_threads __read_only = {
85081 .store = &softlockup_watchdog,
85082 .thread_should_run = watchdog_should_run,
85083 .thread_fn = watchdog,
85084diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85085index e93f7b9..989fcd7 100644
85086--- a/kernel/workqueue.c
85087+++ b/kernel/workqueue.c
85088@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85089 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85090 worker_flags |= WORKER_REBOUND;
85091 worker_flags &= ~WORKER_UNBOUND;
85092- ACCESS_ONCE(worker->flags) = worker_flags;
85093+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85094 }
85095
85096 spin_unlock_irq(&pool->lock);
85097diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85098index 1501aa5..e771896 100644
85099--- a/lib/Kconfig.debug
85100+++ b/lib/Kconfig.debug
85101@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85102
85103 config DEBUG_WW_MUTEX_SLOWPATH
85104 bool "Wait/wound mutex debugging: Slowpath testing"
85105- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85106+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85107 select DEBUG_LOCK_ALLOC
85108 select DEBUG_SPINLOCK
85109 select DEBUG_MUTEXES
85110@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85111
85112 config DEBUG_LOCK_ALLOC
85113 bool "Lock debugging: detect incorrect freeing of live locks"
85114- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85115+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85116 select DEBUG_SPINLOCK
85117 select DEBUG_MUTEXES
85118 select LOCKDEP
85119@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85120
85121 config PROVE_LOCKING
85122 bool "Lock debugging: prove locking correctness"
85123- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85124+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85125 select LOCKDEP
85126 select DEBUG_SPINLOCK
85127 select DEBUG_MUTEXES
85128@@ -914,7 +914,7 @@ config LOCKDEP
85129
85130 config LOCK_STAT
85131 bool "Lock usage statistics"
85132- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85133+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85134 select LOCKDEP
85135 select DEBUG_SPINLOCK
85136 select DEBUG_MUTEXES
85137@@ -1357,6 +1357,7 @@ config LATENCYTOP
85138 depends on DEBUG_KERNEL
85139 depends on STACKTRACE_SUPPORT
85140 depends on PROC_FS
85141+ depends on !GRKERNSEC_HIDESYM
85142 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85143 select KALLSYMS
85144 select KALLSYMS_ALL
85145@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85146 config DEBUG_STRICT_USER_COPY_CHECKS
85147 bool "Strict user copy size checks"
85148 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85149- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85150+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85151 help
85152 Enabling this option turns a certain set of sanity checks for user
85153 copy operations into compile time failures.
85154@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85155
85156 config PROVIDE_OHCI1394_DMA_INIT
85157 bool "Remote debugging over FireWire early on boot"
85158- depends on PCI && X86
85159+ depends on PCI && X86 && !GRKERNSEC
85160 help
85161 If you want to debug problems which hang or crash the kernel early
85162 on boot and the crashing machine has a FireWire port, you can use
85163@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85164
85165 config FIREWIRE_OHCI_REMOTE_DMA
85166 bool "Remote debugging over FireWire with firewire-ohci"
85167- depends on FIREWIRE_OHCI
85168+ depends on FIREWIRE_OHCI && !GRKERNSEC
85169 help
85170 This option lets you use the FireWire bus for remote debugging
85171 with help of the firewire-ohci driver. It enables unfiltered
85172diff --git a/lib/Makefile b/lib/Makefile
85173index 7baccfd..3ceb95f 100644
85174--- a/lib/Makefile
85175+++ b/lib/Makefile
85176@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85177
85178 obj-$(CONFIG_BTREE) += btree.o
85179 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85180-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85181+obj-y += list_debug.o
85182 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85183
85184 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85185diff --git a/lib/bitmap.c b/lib/bitmap.c
85186index 06f7e4f..f3cf2b0 100644
85187--- a/lib/bitmap.c
85188+++ b/lib/bitmap.c
85189@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85190 {
85191 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85192 u32 chunk;
85193- const char __user __force *ubuf = (const char __user __force *)buf;
85194+ const char __user *ubuf = (const char __force_user *)buf;
85195
85196 bitmap_zero(maskp, nmaskbits);
85197
85198@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85199 {
85200 if (!access_ok(VERIFY_READ, ubuf, ulen))
85201 return -EFAULT;
85202- return __bitmap_parse((const char __force *)ubuf,
85203+ return __bitmap_parse((const char __force_kernel *)ubuf,
85204 ulen, 1, maskp, nmaskbits);
85205
85206 }
85207@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85208 {
85209 unsigned a, b;
85210 int c, old_c, totaldigits;
85211- const char __user __force *ubuf = (const char __user __force *)buf;
85212+ const char __user *ubuf = (const char __force_user *)buf;
85213 int exp_digit, in_range;
85214
85215 totaldigits = c = 0;
85216@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85217 {
85218 if (!access_ok(VERIFY_READ, ubuf, ulen))
85219 return -EFAULT;
85220- return __bitmap_parselist((const char __force *)ubuf,
85221+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85222 ulen, 1, maskp, nmaskbits);
85223 }
85224 EXPORT_SYMBOL(bitmap_parselist_user);
85225diff --git a/lib/bug.c b/lib/bug.c
85226index 1686034..a9c00c8 100644
85227--- a/lib/bug.c
85228+++ b/lib/bug.c
85229@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85230 return BUG_TRAP_TYPE_NONE;
85231
85232 bug = find_bug(bugaddr);
85233+ if (!bug)
85234+ return BUG_TRAP_TYPE_NONE;
85235
85236 file = NULL;
85237 line = 0;
85238diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85239index 37061ed..da83f48 100644
85240--- a/lib/debugobjects.c
85241+++ b/lib/debugobjects.c
85242@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85243 if (limit > 4)
85244 return;
85245
85246- is_on_stack = object_is_on_stack(addr);
85247+ is_on_stack = object_starts_on_stack(addr);
85248 if (is_on_stack == onstack)
85249 return;
85250
85251diff --git a/lib/devres.c b/lib/devres.c
85252index 8235331..5881053 100644
85253--- a/lib/devres.c
85254+++ b/lib/devres.c
85255@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85256 void devm_iounmap(struct device *dev, void __iomem *addr)
85257 {
85258 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85259- (void *)addr));
85260+ (void __force *)addr));
85261 iounmap(addr);
85262 }
85263 EXPORT_SYMBOL(devm_iounmap);
85264@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85265 {
85266 ioport_unmap(addr);
85267 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85268- devm_ioport_map_match, (void *)addr));
85269+ devm_ioport_map_match, (void __force *)addr));
85270 }
85271 EXPORT_SYMBOL(devm_ioport_unmap);
85272 #endif /* CONFIG_HAS_IOPORT */
85273diff --git a/lib/div64.c b/lib/div64.c
85274index a163b6c..9618fa5 100644
85275--- a/lib/div64.c
85276+++ b/lib/div64.c
85277@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85278 EXPORT_SYMBOL(__div64_32);
85279
85280 #ifndef div_s64_rem
85281-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85282+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85283 {
85284 u64 quotient;
85285
85286@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85287 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85288 */
85289 #ifndef div64_u64
85290-u64 div64_u64(u64 dividend, u64 divisor)
85291+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85292 {
85293 u32 high = divisor >> 32;
85294 u64 quot;
85295diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85296index d87a17a..ac0d79a 100644
85297--- a/lib/dma-debug.c
85298+++ b/lib/dma-debug.c
85299@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85300
85301 void dma_debug_add_bus(struct bus_type *bus)
85302 {
85303- struct notifier_block *nb;
85304+ notifier_block_no_const *nb;
85305
85306 if (global_disable)
85307 return;
85308@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85309
85310 static void check_for_stack(struct device *dev, void *addr)
85311 {
85312- if (object_is_on_stack(addr))
85313+ if (object_starts_on_stack(addr))
85314 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85315 "stack [addr=%p]\n", addr);
85316 }
85317diff --git a/lib/inflate.c b/lib/inflate.c
85318index 013a761..c28f3fc 100644
85319--- a/lib/inflate.c
85320+++ b/lib/inflate.c
85321@@ -269,7 +269,7 @@ static void free(void *where)
85322 malloc_ptr = free_mem_ptr;
85323 }
85324 #else
85325-#define malloc(a) kmalloc(a, GFP_KERNEL)
85326+#define malloc(a) kmalloc((a), GFP_KERNEL)
85327 #define free(a) kfree(a)
85328 #endif
85329
85330diff --git a/lib/ioremap.c b/lib/ioremap.c
85331index 0c9216c..863bd89 100644
85332--- a/lib/ioremap.c
85333+++ b/lib/ioremap.c
85334@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85335 unsigned long next;
85336
85337 phys_addr -= addr;
85338- pmd = pmd_alloc(&init_mm, pud, addr);
85339+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85340 if (!pmd)
85341 return -ENOMEM;
85342 do {
85343@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85344 unsigned long next;
85345
85346 phys_addr -= addr;
85347- pud = pud_alloc(&init_mm, pgd, addr);
85348+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85349 if (!pud)
85350 return -ENOMEM;
85351 do {
85352diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85353index bd2bea9..6b3c95e 100644
85354--- a/lib/is_single_threaded.c
85355+++ b/lib/is_single_threaded.c
85356@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85357 struct task_struct *p, *t;
85358 bool ret;
85359
85360+ if (!mm)
85361+ return true;
85362+
85363 if (atomic_read(&task->signal->live) != 1)
85364 return false;
85365
85366diff --git a/lib/kobject.c b/lib/kobject.c
85367index 4a1f33d..2f3ca75 100644
85368--- a/lib/kobject.c
85369+++ b/lib/kobject.c
85370@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85371
85372
85373 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85374-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85375+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85376
85377-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85378+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85379 {
85380 enum kobj_ns_type type = ops->type;
85381 int error;
85382diff --git a/lib/list_debug.c b/lib/list_debug.c
85383index c24c2f7..f0296f4 100644
85384--- a/lib/list_debug.c
85385+++ b/lib/list_debug.c
85386@@ -11,7 +11,9 @@
85387 #include <linux/bug.h>
85388 #include <linux/kernel.h>
85389 #include <linux/rculist.h>
85390+#include <linux/mm.h>
85391
85392+#ifdef CONFIG_DEBUG_LIST
85393 /*
85394 * Insert a new entry between two known consecutive entries.
85395 *
85396@@ -19,21 +21,40 @@
85397 * the prev/next entries already!
85398 */
85399
85400+static bool __list_add_debug(struct list_head *new,
85401+ struct list_head *prev,
85402+ struct list_head *next)
85403+{
85404+ if (unlikely(next->prev != prev)) {
85405+ printk(KERN_ERR "list_add corruption. next->prev should be "
85406+ "prev (%p), but was %p. (next=%p).\n",
85407+ prev, next->prev, next);
85408+ BUG();
85409+ return false;
85410+ }
85411+ if (unlikely(prev->next != next)) {
85412+ printk(KERN_ERR "list_add corruption. prev->next should be "
85413+ "next (%p), but was %p. (prev=%p).\n",
85414+ next, prev->next, prev);
85415+ BUG();
85416+ return false;
85417+ }
85418+ if (unlikely(new == prev || new == next)) {
85419+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
85420+ new, prev, next);
85421+ BUG();
85422+ return false;
85423+ }
85424+ return true;
85425+}
85426+
85427 void __list_add(struct list_head *new,
85428- struct list_head *prev,
85429- struct list_head *next)
85430+ struct list_head *prev,
85431+ struct list_head *next)
85432 {
85433- WARN(next->prev != prev,
85434- "list_add corruption. next->prev should be "
85435- "prev (%p), but was %p. (next=%p).\n",
85436- prev, next->prev, next);
85437- WARN(prev->next != next,
85438- "list_add corruption. prev->next should be "
85439- "next (%p), but was %p. (prev=%p).\n",
85440- next, prev->next, prev);
85441- WARN(new == prev || new == next,
85442- "list_add double add: new=%p, prev=%p, next=%p.\n",
85443- new, prev, next);
85444+ if (!__list_add_debug(new, prev, next))
85445+ return;
85446+
85447 next->prev = new;
85448 new->next = next;
85449 new->prev = prev;
85450@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
85451 }
85452 EXPORT_SYMBOL(__list_add);
85453
85454-void __list_del_entry(struct list_head *entry)
85455+static bool __list_del_entry_debug(struct list_head *entry)
85456 {
85457 struct list_head *prev, *next;
85458
85459 prev = entry->prev;
85460 next = entry->next;
85461
85462- if (WARN(next == LIST_POISON1,
85463- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
85464- entry, LIST_POISON1) ||
85465- WARN(prev == LIST_POISON2,
85466- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
85467- entry, LIST_POISON2) ||
85468- WARN(prev->next != entry,
85469- "list_del corruption. prev->next should be %p, "
85470- "but was %p\n", entry, prev->next) ||
85471- WARN(next->prev != entry,
85472- "list_del corruption. next->prev should be %p, "
85473- "but was %p\n", entry, next->prev))
85474+ if (unlikely(next == LIST_POISON1)) {
85475+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
85476+ entry, LIST_POISON1);
85477+ BUG();
85478+ return false;
85479+ }
85480+ if (unlikely(prev == LIST_POISON2)) {
85481+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
85482+ entry, LIST_POISON2);
85483+ BUG();
85484+ return false;
85485+ }
85486+ if (unlikely(entry->prev->next != entry)) {
85487+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
85488+ "but was %p\n", entry, prev->next);
85489+ BUG();
85490+ return false;
85491+ }
85492+ if (unlikely(entry->next->prev != entry)) {
85493+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
85494+ "but was %p\n", entry, next->prev);
85495+ BUG();
85496+ return false;
85497+ }
85498+ return true;
85499+}
85500+
85501+void __list_del_entry(struct list_head *entry)
85502+{
85503+ if (!__list_del_entry_debug(entry))
85504 return;
85505
85506- __list_del(prev, next);
85507+ __list_del(entry->prev, entry->next);
85508 }
85509 EXPORT_SYMBOL(__list_del_entry);
85510
85511@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
85512 void __list_add_rcu(struct list_head *new,
85513 struct list_head *prev, struct list_head *next)
85514 {
85515- WARN(next->prev != prev,
85516- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85517- prev, next->prev, next);
85518- WARN(prev->next != next,
85519- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85520- next, prev->next, prev);
85521+ if (!__list_add_debug(new, prev, next))
85522+ return;
85523+
85524 new->next = next;
85525 new->prev = prev;
85526 rcu_assign_pointer(list_next_rcu(prev), new);
85527 next->prev = new;
85528 }
85529 EXPORT_SYMBOL(__list_add_rcu);
85530+#endif
85531+
85532+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85533+{
85534+#ifdef CONFIG_DEBUG_LIST
85535+ if (!__list_add_debug(new, prev, next))
85536+ return;
85537+#endif
85538+
85539+ pax_open_kernel();
85540+ next->prev = new;
85541+ new->next = next;
85542+ new->prev = prev;
85543+ prev->next = new;
85544+ pax_close_kernel();
85545+}
85546+EXPORT_SYMBOL(__pax_list_add);
85547+
85548+void pax_list_del(struct list_head *entry)
85549+{
85550+#ifdef CONFIG_DEBUG_LIST
85551+ if (!__list_del_entry_debug(entry))
85552+ return;
85553+#endif
85554+
85555+ pax_open_kernel();
85556+ __list_del(entry->prev, entry->next);
85557+ entry->next = LIST_POISON1;
85558+ entry->prev = LIST_POISON2;
85559+ pax_close_kernel();
85560+}
85561+EXPORT_SYMBOL(pax_list_del);
85562+
85563+void pax_list_del_init(struct list_head *entry)
85564+{
85565+ pax_open_kernel();
85566+ __list_del(entry->prev, entry->next);
85567+ INIT_LIST_HEAD(entry);
85568+ pax_close_kernel();
85569+}
85570+EXPORT_SYMBOL(pax_list_del_init);
85571+
85572+void __pax_list_add_rcu(struct list_head *new,
85573+ struct list_head *prev, struct list_head *next)
85574+{
85575+#ifdef CONFIG_DEBUG_LIST
85576+ if (!__list_add_debug(new, prev, next))
85577+ return;
85578+#endif
85579+
85580+ pax_open_kernel();
85581+ new->next = next;
85582+ new->prev = prev;
85583+ rcu_assign_pointer(list_next_rcu(prev), new);
85584+ next->prev = new;
85585+ pax_close_kernel();
85586+}
85587+EXPORT_SYMBOL(__pax_list_add_rcu);
85588+
85589+void pax_list_del_rcu(struct list_head *entry)
85590+{
85591+#ifdef CONFIG_DEBUG_LIST
85592+ if (!__list_del_entry_debug(entry))
85593+ return;
85594+#endif
85595+
85596+ pax_open_kernel();
85597+ __list_del(entry->prev, entry->next);
85598+ entry->next = LIST_POISON1;
85599+ entry->prev = LIST_POISON2;
85600+ pax_close_kernel();
85601+}
85602+EXPORT_SYMBOL(pax_list_del_rcu);
85603diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85604index 7deeb62..144eb47 100644
85605--- a/lib/percpu-refcount.c
85606+++ b/lib/percpu-refcount.c
85607@@ -29,7 +29,7 @@
85608 * can't hit 0 before we've added up all the percpu refs.
85609 */
85610
85611-#define PCPU_COUNT_BIAS (1U << 31)
85612+#define PCPU_COUNT_BIAS (1U << 30)
85613
85614 /**
85615 * percpu_ref_init - initialize a percpu refcount
85616diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85617index e796429..6e38f9f 100644
85618--- a/lib/radix-tree.c
85619+++ b/lib/radix-tree.c
85620@@ -92,7 +92,7 @@ struct radix_tree_preload {
85621 int nr;
85622 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85623 };
85624-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85625+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85626
85627 static inline void *ptr_to_indirect(void *ptr)
85628 {
85629diff --git a/lib/scatterlist.c b/lib/scatterlist.c
85630index a685c8a..d16fa29 100644
85631--- a/lib/scatterlist.c
85632+++ b/lib/scatterlist.c
85633@@ -577,7 +577,8 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
85634 miter->__offset += miter->consumed;
85635 miter->__remaining -= miter->consumed;
85636
85637- if (miter->__flags & SG_MITER_TO_SG)
85638+ if ((miter->__flags & SG_MITER_TO_SG) &&
85639+ !PageSlab(miter->page))
85640 flush_kernel_dcache_page(miter->page);
85641
85642 if (miter->__flags & SG_MITER_ATOMIC) {
85643diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85644index bb2b201..46abaf9 100644
85645--- a/lib/strncpy_from_user.c
85646+++ b/lib/strncpy_from_user.c
85647@@ -21,7 +21,7 @@
85648 */
85649 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85650 {
85651- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85652+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85653 long res = 0;
85654
85655 /*
85656diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85657index a28df52..3d55877 100644
85658--- a/lib/strnlen_user.c
85659+++ b/lib/strnlen_user.c
85660@@ -26,7 +26,7 @@
85661 */
85662 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85663 {
85664- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85665+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85666 long align, res = 0;
85667 unsigned long c;
85668
85669diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85670index d23762e..e21eab2 100644
85671--- a/lib/swiotlb.c
85672+++ b/lib/swiotlb.c
85673@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85674
85675 void
85676 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85677- dma_addr_t dev_addr)
85678+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85679 {
85680 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85681
85682diff --git a/lib/usercopy.c b/lib/usercopy.c
85683index 4f5b1dd..7cab418 100644
85684--- a/lib/usercopy.c
85685+++ b/lib/usercopy.c
85686@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85687 WARN(1, "Buffer overflow detected!\n");
85688 }
85689 EXPORT_SYMBOL(copy_from_user_overflow);
85690+
85691+void copy_to_user_overflow(void)
85692+{
85693+ WARN(1, "Buffer overflow detected!\n");
85694+}
85695+EXPORT_SYMBOL(copy_to_user_overflow);
85696diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85697index 739a363..aa668d7 100644
85698--- a/lib/vsprintf.c
85699+++ b/lib/vsprintf.c
85700@@ -16,6 +16,9 @@
85701 * - scnprintf and vscnprintf
85702 */
85703
85704+#ifdef CONFIG_GRKERNSEC_HIDESYM
85705+#define __INCLUDED_BY_HIDESYM 1
85706+#endif
85707 #include <stdarg.h>
85708 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85709 #include <linux/types.h>
85710@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85711 return number(buf, end, *(const netdev_features_t *)addr, spec);
85712 }
85713
85714+#ifdef CONFIG_GRKERNSEC_HIDESYM
85715+int kptr_restrict __read_mostly = 2;
85716+#else
85717 int kptr_restrict __read_mostly;
85718+#endif
85719
85720 /*
85721 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85722@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85723 * - 'f' For simple symbolic function names without offset
85724 * - 'S' For symbolic direct pointers with offset
85725 * - 's' For symbolic direct pointers without offset
85726+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85727 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85728 * - 'B' For backtraced symbolic direct pointers with offset
85729 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85730@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85731
85732 if (!ptr && *fmt != 'K') {
85733 /*
85734- * Print (null) with the same width as a pointer so it makes
85735+ * Print (nil) with the same width as a pointer so it makes
85736 * tabular output look nice.
85737 */
85738 if (spec.field_width == -1)
85739 spec.field_width = default_width;
85740- return string(buf, end, "(null)", spec);
85741+ return string(buf, end, "(nil)", spec);
85742 }
85743
85744 switch (*fmt) {
85745@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85746 /* Fallthrough */
85747 case 'S':
85748 case 's':
85749+#ifdef CONFIG_GRKERNSEC_HIDESYM
85750+ break;
85751+#else
85752+ return symbol_string(buf, end, ptr, spec, fmt);
85753+#endif
85754+ case 'A':
85755 case 'B':
85756 return symbol_string(buf, end, ptr, spec, fmt);
85757 case 'R':
85758@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85759 va_end(va);
85760 return buf;
85761 }
85762+ case 'P':
85763+ break;
85764 case 'K':
85765 /*
85766 * %pK cannot be used in IRQ context because its test
85767@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85768 return number(buf, end,
85769 (unsigned long long) *((phys_addr_t *)ptr), spec);
85770 }
85771+
85772+#ifdef CONFIG_GRKERNSEC_HIDESYM
85773+ /* 'P' = approved pointers to copy to userland,
85774+ as in the /proc/kallsyms case, as we make it display nothing
85775+ for non-root users, and the real contents for root users
85776+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85777+ above
85778+ */
85779+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85780+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85781+ dump_stack();
85782+ ptr = NULL;
85783+ }
85784+#endif
85785+
85786 spec.flags |= SMALL;
85787 if (spec.field_width == -1) {
85788 spec.field_width = default_width;
85789@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85790 typeof(type) value; \
85791 if (sizeof(type) == 8) { \
85792 args = PTR_ALIGN(args, sizeof(u32)); \
85793- *(u32 *)&value = *(u32 *)args; \
85794- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85795+ *(u32 *)&value = *(const u32 *)args; \
85796+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85797 } else { \
85798 args = PTR_ALIGN(args, sizeof(type)); \
85799- value = *(typeof(type) *)args; \
85800+ value = *(const typeof(type) *)args; \
85801 } \
85802 args += sizeof(type); \
85803 value; \
85804@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85805 case FORMAT_TYPE_STR: {
85806 const char *str_arg = args;
85807 args += strlen(str_arg) + 1;
85808- str = string(str, end, (char *)str_arg, spec);
85809+ str = string(str, end, str_arg, spec);
85810 break;
85811 }
85812
85813diff --git a/localversion-grsec b/localversion-grsec
85814new file mode 100644
85815index 0000000..7cd6065
85816--- /dev/null
85817+++ b/localversion-grsec
85818@@ -0,0 +1 @@
85819+-grsec
85820diff --git a/mm/Kconfig b/mm/Kconfig
85821index 6509d27..3c15063 100644
85822--- a/mm/Kconfig
85823+++ b/mm/Kconfig
85824@@ -317,10 +317,11 @@ config KSM
85825 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85826
85827 config DEFAULT_MMAP_MIN_ADDR
85828- int "Low address space to protect from user allocation"
85829+ int "Low address space to protect from user allocation"
85830 depends on MMU
85831- default 4096
85832- help
85833+ default 32768 if ALPHA || ARM || PARISC || SPARC32
85834+ default 65536
85835+ help
85836 This is the portion of low virtual memory which should be protected
85837 from userspace allocation. Keeping a user from writing to low pages
85838 can help reduce the impact of kernel NULL pointer bugs.
85839@@ -351,7 +352,7 @@ config MEMORY_FAILURE
85840
85841 config HWPOISON_INJECT
85842 tristate "HWPoison pages injector"
85843- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85844+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85845 select PROC_PAGE_MONITOR
85846
85847 config NOMMU_INITIAL_TRIM_EXCESS
85848diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85849index e04454c..ca5be3e 100644
85850--- a/mm/backing-dev.c
85851+++ b/mm/backing-dev.c
85852@@ -12,7 +12,7 @@
85853 #include <linux/device.h>
85854 #include <trace/events/writeback.h>
85855
85856-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85857+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85858
85859 struct backing_dev_info default_backing_dev_info = {
85860 .name = "default",
85861@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85862 return err;
85863
85864 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85865- atomic_long_inc_return(&bdi_seq));
85866+ atomic_long_inc_return_unchecked(&bdi_seq));
85867 if (err) {
85868 bdi_destroy(bdi);
85869 return err;
85870diff --git a/mm/filemap.c b/mm/filemap.c
85871index 4b51ac1..5aa90ff 100644
85872--- a/mm/filemap.c
85873+++ b/mm/filemap.c
85874@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85875 struct address_space *mapping = file->f_mapping;
85876
85877 if (!mapping->a_ops->readpage)
85878- return -ENOEXEC;
85879+ return -ENODEV;
85880 file_accessed(file);
85881 vma->vm_ops = &generic_file_vm_ops;
85882 return 0;
85883@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85884
85885 while (bytes) {
85886 char __user *buf = iov->iov_base + base;
85887- int copy = min(bytes, iov->iov_len - base);
85888+ size_t copy = min(bytes, iov->iov_len - base);
85889
85890 base = 0;
85891 left = __copy_from_user_inatomic(vaddr, buf, copy);
85892@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85893 BUG_ON(!in_atomic());
85894 kaddr = kmap_atomic(page);
85895 if (likely(i->nr_segs == 1)) {
85896- int left;
85897+ size_t left;
85898 char __user *buf = i->iov->iov_base + i->iov_offset;
85899 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85900 copied = bytes - left;
85901@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85902
85903 kaddr = kmap(page);
85904 if (likely(i->nr_segs == 1)) {
85905- int left;
85906+ size_t left;
85907 char __user *buf = i->iov->iov_base + i->iov_offset;
85908 left = __copy_from_user(kaddr + offset, buf, bytes);
85909 copied = bytes - left;
85910@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85911 * zero-length segments (without overruning the iovec).
85912 */
85913 while (bytes || unlikely(i->count && !iov->iov_len)) {
85914- int copy;
85915+ size_t copy;
85916
85917 copy = min(bytes, iov->iov_len - base);
85918 BUG_ON(!i->count || i->count < copy);
85919@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85920 *pos = i_size_read(inode);
85921
85922 if (limit != RLIM_INFINITY) {
85923+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85924 if (*pos >= limit) {
85925 send_sig(SIGXFSZ, current, 0);
85926 return -EFBIG;
85927diff --git a/mm/fremap.c b/mm/fremap.c
85928index 5bff081..d8189a9 100644
85929--- a/mm/fremap.c
85930+++ b/mm/fremap.c
85931@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85932 retry:
85933 vma = find_vma(mm, start);
85934
85935+#ifdef CONFIG_PAX_SEGMEXEC
85936+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85937+ goto out;
85938+#endif
85939+
85940 /*
85941 * Make sure the vma is shared, that it supports prefaulting,
85942 * and that the remapped range is valid and fully within
85943diff --git a/mm/highmem.c b/mm/highmem.c
85944index b32b70c..e512eb0 100644
85945--- a/mm/highmem.c
85946+++ b/mm/highmem.c
85947@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85948 * So no dangers, even with speculative execution.
85949 */
85950 page = pte_page(pkmap_page_table[i]);
85951+ pax_open_kernel();
85952 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85953-
85954+ pax_close_kernel();
85955 set_page_address(page, NULL);
85956 need_flush = 1;
85957 }
85958@@ -198,9 +199,11 @@ start:
85959 }
85960 }
85961 vaddr = PKMAP_ADDR(last_pkmap_nr);
85962+
85963+ pax_open_kernel();
85964 set_pte_at(&init_mm, vaddr,
85965 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85966-
85967+ pax_close_kernel();
85968 pkmap_count[last_pkmap_nr] = 1;
85969 set_page_address(page, (void *)vaddr);
85970
85971diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85972index b60f330..ee7de7e 100644
85973--- a/mm/hugetlb.c
85974+++ b/mm/hugetlb.c
85975@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85976 struct hstate *h = &default_hstate;
85977 unsigned long tmp;
85978 int ret;
85979+ ctl_table_no_const hugetlb_table;
85980
85981 tmp = h->max_huge_pages;
85982
85983 if (write && h->order >= MAX_ORDER)
85984 return -EINVAL;
85985
85986- table->data = &tmp;
85987- table->maxlen = sizeof(unsigned long);
85988- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85989+ hugetlb_table = *table;
85990+ hugetlb_table.data = &tmp;
85991+ hugetlb_table.maxlen = sizeof(unsigned long);
85992+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85993 if (ret)
85994 goto out;
85995
85996@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85997 struct hstate *h = &default_hstate;
85998 unsigned long tmp;
85999 int ret;
86000+ ctl_table_no_const hugetlb_table;
86001
86002 tmp = h->nr_overcommit_huge_pages;
86003
86004 if (write && h->order >= MAX_ORDER)
86005 return -EINVAL;
86006
86007- table->data = &tmp;
86008- table->maxlen = sizeof(unsigned long);
86009- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86010+ hugetlb_table = *table;
86011+ hugetlb_table.data = &tmp;
86012+ hugetlb_table.maxlen = sizeof(unsigned long);
86013+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86014 if (ret)
86015 goto out;
86016
86017@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86018 return 1;
86019 }
86020
86021+#ifdef CONFIG_PAX_SEGMEXEC
86022+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86023+{
86024+ struct mm_struct *mm = vma->vm_mm;
86025+ struct vm_area_struct *vma_m;
86026+ unsigned long address_m;
86027+ pte_t *ptep_m;
86028+
86029+ vma_m = pax_find_mirror_vma(vma);
86030+ if (!vma_m)
86031+ return;
86032+
86033+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86034+ address_m = address + SEGMEXEC_TASK_SIZE;
86035+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86036+ get_page(page_m);
86037+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86038+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86039+}
86040+#endif
86041+
86042 /*
86043 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86044 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86045@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86046 make_huge_pte(vma, new_page, 1));
86047 page_remove_rmap(old_page);
86048 hugepage_add_new_anon_rmap(new_page, vma, address);
86049+
86050+#ifdef CONFIG_PAX_SEGMEXEC
86051+ pax_mirror_huge_pte(vma, address, new_page);
86052+#endif
86053+
86054 /* Make the old page be freed below */
86055 new_page = old_page;
86056 }
86057@@ -2821,6 +2851,10 @@ retry:
86058 && (vma->vm_flags & VM_SHARED)));
86059 set_huge_pte_at(mm, address, ptep, new_pte);
86060
86061+#ifdef CONFIG_PAX_SEGMEXEC
86062+ pax_mirror_huge_pte(vma, address, page);
86063+#endif
86064+
86065 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86066 /* Optimization, do the COW without a second fault */
86067 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86068@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86069 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86070 struct hstate *h = hstate_vma(vma);
86071
86072+#ifdef CONFIG_PAX_SEGMEXEC
86073+ struct vm_area_struct *vma_m;
86074+#endif
86075+
86076 address &= huge_page_mask(h);
86077
86078 ptep = huge_pte_offset(mm, address);
86079@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86080 VM_FAULT_SET_HINDEX(hstate_index(h));
86081 }
86082
86083+#ifdef CONFIG_PAX_SEGMEXEC
86084+ vma_m = pax_find_mirror_vma(vma);
86085+ if (vma_m) {
86086+ unsigned long address_m;
86087+
86088+ if (vma->vm_start > vma_m->vm_start) {
86089+ address_m = address;
86090+ address -= SEGMEXEC_TASK_SIZE;
86091+ vma = vma_m;
86092+ h = hstate_vma(vma);
86093+ } else
86094+ address_m = address + SEGMEXEC_TASK_SIZE;
86095+
86096+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86097+ return VM_FAULT_OOM;
86098+ address_m &= HPAGE_MASK;
86099+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86100+ }
86101+#endif
86102+
86103 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86104 if (!ptep)
86105 return VM_FAULT_OOM;
86106diff --git a/mm/internal.h b/mm/internal.h
86107index 4390ac6..fc60373c 100644
86108--- a/mm/internal.h
86109+++ b/mm/internal.h
86110@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86111 * in mm/page_alloc.c
86112 */
86113 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86114+extern void free_compound_page(struct page *page);
86115 extern void prep_compound_page(struct page *page, unsigned long order);
86116 #ifdef CONFIG_MEMORY_FAILURE
86117 extern bool is_free_buddy_page(struct page *page);
86118@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86119
86120 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86121 unsigned long, unsigned long,
86122- unsigned long, unsigned long);
86123+ unsigned long, unsigned long) __intentional_overflow(-1);
86124
86125 extern void set_pageblock_order(void);
86126 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86127diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86128index c8d7f31..2dbeffd 100644
86129--- a/mm/kmemleak.c
86130+++ b/mm/kmemleak.c
86131@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86132
86133 for (i = 0; i < object->trace_len; i++) {
86134 void *ptr = (void *)object->trace[i];
86135- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86136+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86137 }
86138 }
86139
86140@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86141 return -ENOMEM;
86142 }
86143
86144- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86145+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86146 &kmemleak_fops);
86147 if (!dentry)
86148 pr_warning("Failed to create the debugfs kmemleak file\n");
86149diff --git a/mm/maccess.c b/mm/maccess.c
86150index d53adf9..03a24bf 100644
86151--- a/mm/maccess.c
86152+++ b/mm/maccess.c
86153@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86154 set_fs(KERNEL_DS);
86155 pagefault_disable();
86156 ret = __copy_from_user_inatomic(dst,
86157- (__force const void __user *)src, size);
86158+ (const void __force_user *)src, size);
86159 pagefault_enable();
86160 set_fs(old_fs);
86161
86162@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86163
86164 set_fs(KERNEL_DS);
86165 pagefault_disable();
86166- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86167+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86168 pagefault_enable();
86169 set_fs(old_fs);
86170
86171diff --git a/mm/madvise.c b/mm/madvise.c
86172index 7055883..aafb1ed 100644
86173--- a/mm/madvise.c
86174+++ b/mm/madvise.c
86175@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86176 pgoff_t pgoff;
86177 unsigned long new_flags = vma->vm_flags;
86178
86179+#ifdef CONFIG_PAX_SEGMEXEC
86180+ struct vm_area_struct *vma_m;
86181+#endif
86182+
86183 switch (behavior) {
86184 case MADV_NORMAL:
86185 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86186@@ -126,6 +130,13 @@ success:
86187 /*
86188 * vm_flags is protected by the mmap_sem held in write mode.
86189 */
86190+
86191+#ifdef CONFIG_PAX_SEGMEXEC
86192+ vma_m = pax_find_mirror_vma(vma);
86193+ if (vma_m)
86194+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86195+#endif
86196+
86197 vma->vm_flags = new_flags;
86198
86199 out:
86200@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86201 struct vm_area_struct ** prev,
86202 unsigned long start, unsigned long end)
86203 {
86204+
86205+#ifdef CONFIG_PAX_SEGMEXEC
86206+ struct vm_area_struct *vma_m;
86207+#endif
86208+
86209 *prev = vma;
86210 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86211 return -EINVAL;
86212@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86213 zap_page_range(vma, start, end - start, &details);
86214 } else
86215 zap_page_range(vma, start, end - start, NULL);
86216+
86217+#ifdef CONFIG_PAX_SEGMEXEC
86218+ vma_m = pax_find_mirror_vma(vma);
86219+ if (vma_m) {
86220+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86221+ struct zap_details details = {
86222+ .nonlinear_vma = vma_m,
86223+ .last_index = ULONG_MAX,
86224+ };
86225+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86226+ } else
86227+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86228+ }
86229+#endif
86230+
86231 return 0;
86232 }
86233
86234@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86235 if (end < start)
86236 return error;
86237
86238+#ifdef CONFIG_PAX_SEGMEXEC
86239+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86240+ if (end > SEGMEXEC_TASK_SIZE)
86241+ return error;
86242+ } else
86243+#endif
86244+
86245+ if (end > TASK_SIZE)
86246+ return error;
86247+
86248 error = 0;
86249 if (end == start)
86250 return error;
86251diff --git a/mm/memcontrol.c b/mm/memcontrol.c
86252index aa44621..99011b3 100644
86253--- a/mm/memcontrol.c
86254+++ b/mm/memcontrol.c
86255@@ -2772,6 +2772,8 @@ done:
86256 return 0;
86257 nomem:
86258 *ptr = NULL;
86259+ if (gfp_mask & __GFP_NOFAIL)
86260+ return 0;
86261 return -ENOMEM;
86262 bypass:
86263 *ptr = root_mem_cgroup;
86264diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86265index 2c13aa7..64cbc3f 100644
86266--- a/mm/memory-failure.c
86267+++ b/mm/memory-failure.c
86268@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86269
86270 int sysctl_memory_failure_recovery __read_mostly = 1;
86271
86272-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86273+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86274
86275 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86276
86277@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86278 pfn, t->comm, t->pid);
86279 si.si_signo = SIGBUS;
86280 si.si_errno = 0;
86281- si.si_addr = (void *)addr;
86282+ si.si_addr = (void __user *)addr;
86283 #ifdef __ARCH_SI_TRAPNO
86284 si.si_trapno = trapno;
86285 #endif
86286@@ -760,7 +760,7 @@ static struct page_state {
86287 unsigned long res;
86288 char *msg;
86289 int (*action)(struct page *p, unsigned long pfn);
86290-} error_states[] = {
86291+} __do_const error_states[] = {
86292 { reserved, reserved, "reserved kernel", me_kernel },
86293 /*
86294 * free pages are specially detected outside this table:
86295@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86296 nr_pages = 1 << compound_order(hpage);
86297 else /* normal page or thp */
86298 nr_pages = 1;
86299- atomic_long_add(nr_pages, &num_poisoned_pages);
86300+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86301
86302 /*
86303 * We need/can do nothing about count=0 pages.
86304@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86305 if (!PageHWPoison(hpage)
86306 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86307 || (p != hpage && TestSetPageHWPoison(hpage))) {
86308- atomic_long_sub(nr_pages, &num_poisoned_pages);
86309+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86310 return 0;
86311 }
86312 set_page_hwpoison_huge_page(hpage);
86313@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86314 }
86315 if (hwpoison_filter(p)) {
86316 if (TestClearPageHWPoison(p))
86317- atomic_long_sub(nr_pages, &num_poisoned_pages);
86318+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86319 unlock_page(hpage);
86320 put_page(hpage);
86321 return 0;
86322@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86323 return 0;
86324 }
86325 if (TestClearPageHWPoison(p))
86326- atomic_long_sub(nr_pages, &num_poisoned_pages);
86327+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86328 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86329 return 0;
86330 }
86331@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86332 */
86333 if (TestClearPageHWPoison(page)) {
86334 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86335- atomic_long_sub(nr_pages, &num_poisoned_pages);
86336+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86337 freeit = 1;
86338 if (PageHuge(page))
86339 clear_page_hwpoison_huge_page(page);
86340@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86341 } else {
86342 set_page_hwpoison_huge_page(hpage);
86343 dequeue_hwpoisoned_huge_page(hpage);
86344- atomic_long_add(1 << compound_trans_order(hpage),
86345+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86346 &num_poisoned_pages);
86347 }
86348 return ret;
86349@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86350 if (PageHuge(page)) {
86351 set_page_hwpoison_huge_page(hpage);
86352 dequeue_hwpoisoned_huge_page(hpage);
86353- atomic_long_add(1 << compound_trans_order(hpage),
86354+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86355 &num_poisoned_pages);
86356 } else {
86357 SetPageHWPoison(page);
86358- atomic_long_inc(&num_poisoned_pages);
86359+ atomic_long_inc_unchecked(&num_poisoned_pages);
86360 }
86361 }
86362 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86363@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86364 put_page(page);
86365 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86366 SetPageHWPoison(page);
86367- atomic_long_inc(&num_poisoned_pages);
86368+ atomic_long_inc_unchecked(&num_poisoned_pages);
86369 return 0;
86370 }
86371
86372@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86373 if (!is_free_buddy_page(page))
86374 pr_info("soft offline: %#lx: page leaked\n",
86375 pfn);
86376- atomic_long_inc(&num_poisoned_pages);
86377+ atomic_long_inc_unchecked(&num_poisoned_pages);
86378 }
86379 } else {
86380 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86381diff --git a/mm/memory.c b/mm/memory.c
86382index 440986e..94b45d5 100644
86383--- a/mm/memory.c
86384+++ b/mm/memory.c
86385@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86386 free_pte_range(tlb, pmd, addr);
86387 } while (pmd++, addr = next, addr != end);
86388
86389+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86390 start &= PUD_MASK;
86391 if (start < floor)
86392 return;
86393@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86394 pmd = pmd_offset(pud, start);
86395 pud_clear(pud);
86396 pmd_free_tlb(tlb, pmd, start);
86397+#endif
86398+
86399 }
86400
86401 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86402@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86403 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86404 } while (pud++, addr = next, addr != end);
86405
86406+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86407 start &= PGDIR_MASK;
86408 if (start < floor)
86409 return;
86410@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86411 pud = pud_offset(pgd, start);
86412 pgd_clear(pgd);
86413 pud_free_tlb(tlb, pud, start);
86414+#endif
86415+
86416 }
86417
86418 /*
86419@@ -1647,12 +1653,6 @@ no_page_table:
86420 return page;
86421 }
86422
86423-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86424-{
86425- return stack_guard_page_start(vma, addr) ||
86426- stack_guard_page_end(vma, addr+PAGE_SIZE);
86427-}
86428-
86429 /**
86430 * __get_user_pages() - pin user pages in memory
86431 * @tsk: task_struct of target task
86432@@ -1739,10 +1739,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86433
86434 i = 0;
86435
86436- do {
86437+ while (nr_pages) {
86438 struct vm_area_struct *vma;
86439
86440- vma = find_extend_vma(mm, start);
86441+ vma = find_vma(mm, start);
86442 if (!vma && in_gate_area(mm, start)) {
86443 unsigned long pg = start & PAGE_MASK;
86444 pgd_t *pgd;
86445@@ -1791,7 +1791,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86446 goto next_page;
86447 }
86448
86449- if (!vma ||
86450+ if (!vma || start < vma->vm_start ||
86451 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86452 !(vm_flags & vma->vm_flags))
86453 return i ? : -EFAULT;
86454@@ -1820,11 +1820,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86455 int ret;
86456 unsigned int fault_flags = 0;
86457
86458- /* For mlock, just skip the stack guard page. */
86459- if (foll_flags & FOLL_MLOCK) {
86460- if (stack_guard_page(vma, start))
86461- goto next_page;
86462- }
86463 if (foll_flags & FOLL_WRITE)
86464 fault_flags |= FAULT_FLAG_WRITE;
86465 if (nonblocking)
86466@@ -1904,7 +1899,7 @@ next_page:
86467 start += page_increm * PAGE_SIZE;
86468 nr_pages -= page_increm;
86469 } while (nr_pages && start < vma->vm_end);
86470- } while (nr_pages);
86471+ }
86472 return i;
86473 }
86474 EXPORT_SYMBOL(__get_user_pages);
86475@@ -2111,6 +2106,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86476 page_add_file_rmap(page);
86477 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86478
86479+#ifdef CONFIG_PAX_SEGMEXEC
86480+ pax_mirror_file_pte(vma, addr, page, ptl);
86481+#endif
86482+
86483 retval = 0;
86484 pte_unmap_unlock(pte, ptl);
86485 return retval;
86486@@ -2155,9 +2154,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86487 if (!page_count(page))
86488 return -EINVAL;
86489 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86490+
86491+#ifdef CONFIG_PAX_SEGMEXEC
86492+ struct vm_area_struct *vma_m;
86493+#endif
86494+
86495 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86496 BUG_ON(vma->vm_flags & VM_PFNMAP);
86497 vma->vm_flags |= VM_MIXEDMAP;
86498+
86499+#ifdef CONFIG_PAX_SEGMEXEC
86500+ vma_m = pax_find_mirror_vma(vma);
86501+ if (vma_m)
86502+ vma_m->vm_flags |= VM_MIXEDMAP;
86503+#endif
86504+
86505 }
86506 return insert_page(vma, addr, page, vma->vm_page_prot);
86507 }
86508@@ -2240,6 +2251,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86509 unsigned long pfn)
86510 {
86511 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86512+ BUG_ON(vma->vm_mirror);
86513
86514 if (addr < vma->vm_start || addr >= vma->vm_end)
86515 return -EFAULT;
86516@@ -2487,7 +2499,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86517
86518 BUG_ON(pud_huge(*pud));
86519
86520- pmd = pmd_alloc(mm, pud, addr);
86521+ pmd = (mm == &init_mm) ?
86522+ pmd_alloc_kernel(mm, pud, addr) :
86523+ pmd_alloc(mm, pud, addr);
86524 if (!pmd)
86525 return -ENOMEM;
86526 do {
86527@@ -2507,7 +2521,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86528 unsigned long next;
86529 int err;
86530
86531- pud = pud_alloc(mm, pgd, addr);
86532+ pud = (mm == &init_mm) ?
86533+ pud_alloc_kernel(mm, pgd, addr) :
86534+ pud_alloc(mm, pgd, addr);
86535 if (!pud)
86536 return -ENOMEM;
86537 do {
86538@@ -2595,6 +2611,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86539 copy_user_highpage(dst, src, va, vma);
86540 }
86541
86542+#ifdef CONFIG_PAX_SEGMEXEC
86543+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86544+{
86545+ struct mm_struct *mm = vma->vm_mm;
86546+ spinlock_t *ptl;
86547+ pte_t *pte, entry;
86548+
86549+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86550+ entry = *pte;
86551+ if (!pte_present(entry)) {
86552+ if (!pte_none(entry)) {
86553+ BUG_ON(pte_file(entry));
86554+ free_swap_and_cache(pte_to_swp_entry(entry));
86555+ pte_clear_not_present_full(mm, address, pte, 0);
86556+ }
86557+ } else {
86558+ struct page *page;
86559+
86560+ flush_cache_page(vma, address, pte_pfn(entry));
86561+ entry = ptep_clear_flush(vma, address, pte);
86562+ BUG_ON(pte_dirty(entry));
86563+ page = vm_normal_page(vma, address, entry);
86564+ if (page) {
86565+ update_hiwater_rss(mm);
86566+ if (PageAnon(page))
86567+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86568+ else
86569+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86570+ page_remove_rmap(page);
86571+ page_cache_release(page);
86572+ }
86573+ }
86574+ pte_unmap_unlock(pte, ptl);
86575+}
86576+
86577+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86578+ *
86579+ * the ptl of the lower mapped page is held on entry and is not released on exit
86580+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86581+ */
86582+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86583+{
86584+ struct mm_struct *mm = vma->vm_mm;
86585+ unsigned long address_m;
86586+ spinlock_t *ptl_m;
86587+ struct vm_area_struct *vma_m;
86588+ pmd_t *pmd_m;
86589+ pte_t *pte_m, entry_m;
86590+
86591+ BUG_ON(!page_m || !PageAnon(page_m));
86592+
86593+ vma_m = pax_find_mirror_vma(vma);
86594+ if (!vma_m)
86595+ return;
86596+
86597+ BUG_ON(!PageLocked(page_m));
86598+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86599+ address_m = address + SEGMEXEC_TASK_SIZE;
86600+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86601+ pte_m = pte_offset_map(pmd_m, address_m);
86602+ ptl_m = pte_lockptr(mm, pmd_m);
86603+ if (ptl != ptl_m) {
86604+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86605+ if (!pte_none(*pte_m))
86606+ goto out;
86607+ }
86608+
86609+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86610+ page_cache_get(page_m);
86611+ page_add_anon_rmap(page_m, vma_m, address_m);
86612+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86613+ set_pte_at(mm, address_m, pte_m, entry_m);
86614+ update_mmu_cache(vma_m, address_m, pte_m);
86615+out:
86616+ if (ptl != ptl_m)
86617+ spin_unlock(ptl_m);
86618+ pte_unmap(pte_m);
86619+ unlock_page(page_m);
86620+}
86621+
86622+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86623+{
86624+ struct mm_struct *mm = vma->vm_mm;
86625+ unsigned long address_m;
86626+ spinlock_t *ptl_m;
86627+ struct vm_area_struct *vma_m;
86628+ pmd_t *pmd_m;
86629+ pte_t *pte_m, entry_m;
86630+
86631+ BUG_ON(!page_m || PageAnon(page_m));
86632+
86633+ vma_m = pax_find_mirror_vma(vma);
86634+ if (!vma_m)
86635+ return;
86636+
86637+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86638+ address_m = address + SEGMEXEC_TASK_SIZE;
86639+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86640+ pte_m = pte_offset_map(pmd_m, address_m);
86641+ ptl_m = pte_lockptr(mm, pmd_m);
86642+ if (ptl != ptl_m) {
86643+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86644+ if (!pte_none(*pte_m))
86645+ goto out;
86646+ }
86647+
86648+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86649+ page_cache_get(page_m);
86650+ page_add_file_rmap(page_m);
86651+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86652+ set_pte_at(mm, address_m, pte_m, entry_m);
86653+ update_mmu_cache(vma_m, address_m, pte_m);
86654+out:
86655+ if (ptl != ptl_m)
86656+ spin_unlock(ptl_m);
86657+ pte_unmap(pte_m);
86658+}
86659+
86660+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86661+{
86662+ struct mm_struct *mm = vma->vm_mm;
86663+ unsigned long address_m;
86664+ spinlock_t *ptl_m;
86665+ struct vm_area_struct *vma_m;
86666+ pmd_t *pmd_m;
86667+ pte_t *pte_m, entry_m;
86668+
86669+ vma_m = pax_find_mirror_vma(vma);
86670+ if (!vma_m)
86671+ return;
86672+
86673+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86674+ address_m = address + SEGMEXEC_TASK_SIZE;
86675+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86676+ pte_m = pte_offset_map(pmd_m, address_m);
86677+ ptl_m = pte_lockptr(mm, pmd_m);
86678+ if (ptl != ptl_m) {
86679+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86680+ if (!pte_none(*pte_m))
86681+ goto out;
86682+ }
86683+
86684+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86685+ set_pte_at(mm, address_m, pte_m, entry_m);
86686+out:
86687+ if (ptl != ptl_m)
86688+ spin_unlock(ptl_m);
86689+ pte_unmap(pte_m);
86690+}
86691+
86692+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86693+{
86694+ struct page *page_m;
86695+ pte_t entry;
86696+
86697+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86698+ goto out;
86699+
86700+ entry = *pte;
86701+ page_m = vm_normal_page(vma, address, entry);
86702+ if (!page_m)
86703+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86704+ else if (PageAnon(page_m)) {
86705+ if (pax_find_mirror_vma(vma)) {
86706+ pte_unmap_unlock(pte, ptl);
86707+ lock_page(page_m);
86708+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86709+ if (pte_same(entry, *pte))
86710+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86711+ else
86712+ unlock_page(page_m);
86713+ }
86714+ } else
86715+ pax_mirror_file_pte(vma, address, page_m, ptl);
86716+
86717+out:
86718+ pte_unmap_unlock(pte, ptl);
86719+}
86720+#endif
86721+
86722 /*
86723 * This routine handles present pages, when users try to write
86724 * to a shared page. It is done by copying the page to a new address
86725@@ -2811,6 +3007,12 @@ gotten:
86726 */
86727 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86728 if (likely(pte_same(*page_table, orig_pte))) {
86729+
86730+#ifdef CONFIG_PAX_SEGMEXEC
86731+ if (pax_find_mirror_vma(vma))
86732+ BUG_ON(!trylock_page(new_page));
86733+#endif
86734+
86735 if (old_page) {
86736 if (!PageAnon(old_page)) {
86737 dec_mm_counter_fast(mm, MM_FILEPAGES);
86738@@ -2862,6 +3064,10 @@ gotten:
86739 page_remove_rmap(old_page);
86740 }
86741
86742+#ifdef CONFIG_PAX_SEGMEXEC
86743+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86744+#endif
86745+
86746 /* Free the old page.. */
86747 new_page = old_page;
86748 ret |= VM_FAULT_WRITE;
86749@@ -3139,6 +3345,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86750 swap_free(entry);
86751 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86752 try_to_free_swap(page);
86753+
86754+#ifdef CONFIG_PAX_SEGMEXEC
86755+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86756+#endif
86757+
86758 unlock_page(page);
86759 if (page != swapcache) {
86760 /*
86761@@ -3162,6 +3373,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86762
86763 /* No need to invalidate - it was non-present before */
86764 update_mmu_cache(vma, address, page_table);
86765+
86766+#ifdef CONFIG_PAX_SEGMEXEC
86767+ pax_mirror_anon_pte(vma, address, page, ptl);
86768+#endif
86769+
86770 unlock:
86771 pte_unmap_unlock(page_table, ptl);
86772 out:
86773@@ -3181,40 +3397,6 @@ out_release:
86774 }
86775
86776 /*
86777- * This is like a special single-page "expand_{down|up}wards()",
86778- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86779- * doesn't hit another vma.
86780- */
86781-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86782-{
86783- address &= PAGE_MASK;
86784- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86785- struct vm_area_struct *prev = vma->vm_prev;
86786-
86787- /*
86788- * Is there a mapping abutting this one below?
86789- *
86790- * That's only ok if it's the same stack mapping
86791- * that has gotten split..
86792- */
86793- if (prev && prev->vm_end == address)
86794- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86795-
86796- expand_downwards(vma, address - PAGE_SIZE);
86797- }
86798- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86799- struct vm_area_struct *next = vma->vm_next;
86800-
86801- /* As VM_GROWSDOWN but s/below/above/ */
86802- if (next && next->vm_start == address + PAGE_SIZE)
86803- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86804-
86805- expand_upwards(vma, address + PAGE_SIZE);
86806- }
86807- return 0;
86808-}
86809-
86810-/*
86811 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86812 * but allow concurrent faults), and pte mapped but not yet locked.
86813 * We return with mmap_sem still held, but pte unmapped and unlocked.
86814@@ -3223,27 +3405,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86815 unsigned long address, pte_t *page_table, pmd_t *pmd,
86816 unsigned int flags)
86817 {
86818- struct page *page;
86819+ struct page *page = NULL;
86820 spinlock_t *ptl;
86821 pte_t entry;
86822
86823- pte_unmap(page_table);
86824-
86825- /* Check if we need to add a guard page to the stack */
86826- if (check_stack_guard_page(vma, address) < 0)
86827- return VM_FAULT_SIGBUS;
86828-
86829- /* Use the zero-page for reads */
86830 if (!(flags & FAULT_FLAG_WRITE)) {
86831 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86832 vma->vm_page_prot));
86833- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86834+ ptl = pte_lockptr(mm, pmd);
86835+ spin_lock(ptl);
86836 if (!pte_none(*page_table))
86837 goto unlock;
86838 goto setpte;
86839 }
86840
86841 /* Allocate our own private page. */
86842+ pte_unmap(page_table);
86843+
86844 if (unlikely(anon_vma_prepare(vma)))
86845 goto oom;
86846 page = alloc_zeroed_user_highpage_movable(vma, address);
86847@@ -3267,6 +3445,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86848 if (!pte_none(*page_table))
86849 goto release;
86850
86851+#ifdef CONFIG_PAX_SEGMEXEC
86852+ if (pax_find_mirror_vma(vma))
86853+ BUG_ON(!trylock_page(page));
86854+#endif
86855+
86856 inc_mm_counter_fast(mm, MM_ANONPAGES);
86857 page_add_new_anon_rmap(page, vma, address);
86858 setpte:
86859@@ -3274,6 +3457,12 @@ setpte:
86860
86861 /* No need to invalidate - it was non-present before */
86862 update_mmu_cache(vma, address, page_table);
86863+
86864+#ifdef CONFIG_PAX_SEGMEXEC
86865+ if (page)
86866+ pax_mirror_anon_pte(vma, address, page, ptl);
86867+#endif
86868+
86869 unlock:
86870 pte_unmap_unlock(page_table, ptl);
86871 return 0;
86872@@ -3417,6 +3606,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86873 */
86874 /* Only go through if we didn't race with anybody else... */
86875 if (likely(pte_same(*page_table, orig_pte))) {
86876+
86877+#ifdef CONFIG_PAX_SEGMEXEC
86878+ if (anon && pax_find_mirror_vma(vma))
86879+ BUG_ON(!trylock_page(page));
86880+#endif
86881+
86882 flush_icache_page(vma, page);
86883 entry = mk_pte(page, vma->vm_page_prot);
86884 if (flags & FAULT_FLAG_WRITE)
86885@@ -3438,6 +3633,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86886
86887 /* no need to invalidate: a not-present page won't be cached */
86888 update_mmu_cache(vma, address, page_table);
86889+
86890+#ifdef CONFIG_PAX_SEGMEXEC
86891+ if (anon)
86892+ pax_mirror_anon_pte(vma, address, page, ptl);
86893+ else
86894+ pax_mirror_file_pte(vma, address, page, ptl);
86895+#endif
86896+
86897 } else {
86898 if (cow_page)
86899 mem_cgroup_uncharge_page(cow_page);
86900@@ -3759,6 +3962,12 @@ int handle_pte_fault(struct mm_struct *mm,
86901 if (flags & FAULT_FLAG_WRITE)
86902 flush_tlb_fix_spurious_fault(vma, address);
86903 }
86904+
86905+#ifdef CONFIG_PAX_SEGMEXEC
86906+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86907+ return 0;
86908+#endif
86909+
86910 unlock:
86911 pte_unmap_unlock(pte, ptl);
86912 return 0;
86913@@ -3775,6 +3984,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86914 pmd_t *pmd;
86915 pte_t *pte;
86916
86917+#ifdef CONFIG_PAX_SEGMEXEC
86918+ struct vm_area_struct *vma_m;
86919+#endif
86920+
86921 __set_current_state(TASK_RUNNING);
86922
86923 count_vm_event(PGFAULT);
86924@@ -3786,6 +3999,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86925 if (unlikely(is_vm_hugetlb_page(vma)))
86926 return hugetlb_fault(mm, vma, address, flags);
86927
86928+#ifdef CONFIG_PAX_SEGMEXEC
86929+ vma_m = pax_find_mirror_vma(vma);
86930+ if (vma_m) {
86931+ unsigned long address_m;
86932+ pgd_t *pgd_m;
86933+ pud_t *pud_m;
86934+ pmd_t *pmd_m;
86935+
86936+ if (vma->vm_start > vma_m->vm_start) {
86937+ address_m = address;
86938+ address -= SEGMEXEC_TASK_SIZE;
86939+ vma = vma_m;
86940+ } else
86941+ address_m = address + SEGMEXEC_TASK_SIZE;
86942+
86943+ pgd_m = pgd_offset(mm, address_m);
86944+ pud_m = pud_alloc(mm, pgd_m, address_m);
86945+ if (!pud_m)
86946+ return VM_FAULT_OOM;
86947+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86948+ if (!pmd_m)
86949+ return VM_FAULT_OOM;
86950+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86951+ return VM_FAULT_OOM;
86952+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86953+ }
86954+#endif
86955+
86956 retry:
86957 pgd = pgd_offset(mm, address);
86958 pud = pud_alloc(mm, pgd, address);
86959@@ -3884,6 +4125,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86960 spin_unlock(&mm->page_table_lock);
86961 return 0;
86962 }
86963+
86964+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86965+{
86966+ pud_t *new = pud_alloc_one(mm, address);
86967+ if (!new)
86968+ return -ENOMEM;
86969+
86970+ smp_wmb(); /* See comment in __pte_alloc */
86971+
86972+ spin_lock(&mm->page_table_lock);
86973+ if (pgd_present(*pgd)) /* Another has populated it */
86974+ pud_free(mm, new);
86975+ else
86976+ pgd_populate_kernel(mm, pgd, new);
86977+ spin_unlock(&mm->page_table_lock);
86978+ return 0;
86979+}
86980 #endif /* __PAGETABLE_PUD_FOLDED */
86981
86982 #ifndef __PAGETABLE_PMD_FOLDED
86983@@ -3914,6 +4172,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86984 spin_unlock(&mm->page_table_lock);
86985 return 0;
86986 }
86987+
86988+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86989+{
86990+ pmd_t *new = pmd_alloc_one(mm, address);
86991+ if (!new)
86992+ return -ENOMEM;
86993+
86994+ smp_wmb(); /* See comment in __pte_alloc */
86995+
86996+ spin_lock(&mm->page_table_lock);
86997+#ifndef __ARCH_HAS_4LEVEL_HACK
86998+ if (pud_present(*pud)) /* Another has populated it */
86999+ pmd_free(mm, new);
87000+ else
87001+ pud_populate_kernel(mm, pud, new);
87002+#else
87003+ if (pgd_present(*pud)) /* Another has populated it */
87004+ pmd_free(mm, new);
87005+ else
87006+ pgd_populate_kernel(mm, pud, new);
87007+#endif /* __ARCH_HAS_4LEVEL_HACK */
87008+ spin_unlock(&mm->page_table_lock);
87009+ return 0;
87010+}
87011 #endif /* __PAGETABLE_PMD_FOLDED */
87012
87013 #if !defined(__HAVE_ARCH_GATE_AREA)
87014@@ -3927,7 +4209,7 @@ static int __init gate_vma_init(void)
87015 gate_vma.vm_start = FIXADDR_USER_START;
87016 gate_vma.vm_end = FIXADDR_USER_END;
87017 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87018- gate_vma.vm_page_prot = __P101;
87019+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87020
87021 return 0;
87022 }
87023@@ -4061,8 +4343,8 @@ out:
87024 return ret;
87025 }
87026
87027-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87028- void *buf, int len, int write)
87029+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87030+ void *buf, size_t len, int write)
87031 {
87032 resource_size_t phys_addr;
87033 unsigned long prot = 0;
87034@@ -4087,8 +4369,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87035 * Access another process' address space as given in mm. If non-NULL, use the
87036 * given task for page fault accounting.
87037 */
87038-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87039- unsigned long addr, void *buf, int len, int write)
87040+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87041+ unsigned long addr, void *buf, size_t len, int write)
87042 {
87043 struct vm_area_struct *vma;
87044 void *old_buf = buf;
87045@@ -4096,7 +4378,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87046 down_read(&mm->mmap_sem);
87047 /* ignore errors, just check how much was successfully transferred */
87048 while (len) {
87049- int bytes, ret, offset;
87050+ ssize_t bytes, ret, offset;
87051 void *maddr;
87052 struct page *page = NULL;
87053
87054@@ -4155,8 +4437,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87055 *
87056 * The caller must hold a reference on @mm.
87057 */
87058-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87059- void *buf, int len, int write)
87060+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87061+ void *buf, size_t len, int write)
87062 {
87063 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87064 }
87065@@ -4166,11 +4448,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87066 * Source/target buffer must be kernel space,
87067 * Do not walk the page table directly, use get_user_pages
87068 */
87069-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87070- void *buf, int len, int write)
87071+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87072+ void *buf, size_t len, int write)
87073 {
87074 struct mm_struct *mm;
87075- int ret;
87076+ ssize_t ret;
87077
87078 mm = get_task_mm(tsk);
87079 if (!mm)
87080diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87081index 4baf12e..5497066 100644
87082--- a/mm/mempolicy.c
87083+++ b/mm/mempolicy.c
87084@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87085 unsigned long vmstart;
87086 unsigned long vmend;
87087
87088+#ifdef CONFIG_PAX_SEGMEXEC
87089+ struct vm_area_struct *vma_m;
87090+#endif
87091+
87092 vma = find_vma(mm, start);
87093 if (!vma || vma->vm_start > start)
87094 return -EFAULT;
87095@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87096 err = vma_replace_policy(vma, new_pol);
87097 if (err)
87098 goto out;
87099+
87100+#ifdef CONFIG_PAX_SEGMEXEC
87101+ vma_m = pax_find_mirror_vma(vma);
87102+ if (vma_m) {
87103+ err = vma_replace_policy(vma_m, new_pol);
87104+ if (err)
87105+ goto out;
87106+ }
87107+#endif
87108+
87109 }
87110
87111 out:
87112@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87113
87114 if (end < start)
87115 return -EINVAL;
87116+
87117+#ifdef CONFIG_PAX_SEGMEXEC
87118+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87119+ if (end > SEGMEXEC_TASK_SIZE)
87120+ return -EINVAL;
87121+ } else
87122+#endif
87123+
87124+ if (end > TASK_SIZE)
87125+ return -EINVAL;
87126+
87127 if (end == start)
87128 return 0;
87129
87130@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87131 */
87132 tcred = __task_cred(task);
87133 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87134- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87135- !capable(CAP_SYS_NICE)) {
87136+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87137 rcu_read_unlock();
87138 err = -EPERM;
87139 goto out_put;
87140@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87141 goto out;
87142 }
87143
87144+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87145+ if (mm != current->mm &&
87146+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87147+ mmput(mm);
87148+ err = -EPERM;
87149+ goto out;
87150+ }
87151+#endif
87152+
87153 err = do_migrate_pages(mm, old, new,
87154 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87155
87156diff --git a/mm/migrate.c b/mm/migrate.c
87157index 81af4e6..2285307 100644
87158--- a/mm/migrate.c
87159+++ b/mm/migrate.c
87160@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87161 */
87162 tcred = __task_cred(task);
87163 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87164- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87165- !capable(CAP_SYS_NICE)) {
87166+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87167 rcu_read_unlock();
87168 err = -EPERM;
87169 goto out;
87170diff --git a/mm/mlock.c b/mm/mlock.c
87171index 79b7cf7..37472bf 100644
87172--- a/mm/mlock.c
87173+++ b/mm/mlock.c
87174@@ -13,6 +13,7 @@
87175 #include <linux/pagemap.h>
87176 #include <linux/mempolicy.h>
87177 #include <linux/syscalls.h>
87178+#include <linux/security.h>
87179 #include <linux/sched.h>
87180 #include <linux/export.h>
87181 #include <linux/rmap.h>
87182@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87183 {
87184 unsigned long nstart, end, tmp;
87185 struct vm_area_struct * vma, * prev;
87186- int error;
87187+ int error = 0;
87188
87189 VM_BUG_ON(start & ~PAGE_MASK);
87190 VM_BUG_ON(len != PAGE_ALIGN(len));
87191@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87192 return -EINVAL;
87193 if (end == start)
87194 return 0;
87195+ if (end > TASK_SIZE)
87196+ return -EINVAL;
87197+
87198 vma = find_vma(current->mm, start);
87199 if (!vma || vma->vm_start > start)
87200 return -ENOMEM;
87201@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87202 for (nstart = start ; ; ) {
87203 vm_flags_t newflags;
87204
87205+#ifdef CONFIG_PAX_SEGMEXEC
87206+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87207+ break;
87208+#endif
87209+
87210 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87211
87212 newflags = vma->vm_flags & ~VM_LOCKED;
87213@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87214 lock_limit >>= PAGE_SHIFT;
87215
87216 /* check against resource limits */
87217+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87218 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87219 error = do_mlock(start, len, 1);
87220 up_write(&current->mm->mmap_sem);
87221@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87222 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87223 vm_flags_t newflags;
87224
87225+#ifdef CONFIG_PAX_SEGMEXEC
87226+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87227+ break;
87228+#endif
87229+
87230 newflags = vma->vm_flags & ~VM_LOCKED;
87231 if (flags & MCL_CURRENT)
87232 newflags |= VM_LOCKED;
87233
87234 /* Ignore errors */
87235 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87236+ cond_resched();
87237 }
87238 out:
87239 return 0;
87240@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87241 lock_limit >>= PAGE_SHIFT;
87242
87243 ret = -ENOMEM;
87244+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87245 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87246 capable(CAP_IPC_LOCK))
87247 ret = do_mlockall(flags);
87248diff --git a/mm/mmap.c b/mm/mmap.c
87249index f9c97d1..3468d3b 100644
87250--- a/mm/mmap.c
87251+++ b/mm/mmap.c
87252@@ -36,6 +36,7 @@
87253 #include <linux/sched/sysctl.h>
87254 #include <linux/notifier.h>
87255 #include <linux/memory.h>
87256+#include <linux/random.h>
87257
87258 #include <asm/uaccess.h>
87259 #include <asm/cacheflush.h>
87260@@ -52,6 +53,16 @@
87261 #define arch_rebalance_pgtables(addr, len) (addr)
87262 #endif
87263
87264+static inline void verify_mm_writelocked(struct mm_struct *mm)
87265+{
87266+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87267+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87268+ up_read(&mm->mmap_sem);
87269+ BUG();
87270+ }
87271+#endif
87272+}
87273+
87274 static void unmap_region(struct mm_struct *mm,
87275 struct vm_area_struct *vma, struct vm_area_struct *prev,
87276 unsigned long start, unsigned long end);
87277@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87278 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87279 *
87280 */
87281-pgprot_t protection_map[16] = {
87282+pgprot_t protection_map[16] __read_only = {
87283 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87284 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87285 };
87286
87287-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87288+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87289 {
87290- return __pgprot(pgprot_val(protection_map[vm_flags &
87291+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87292 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87293 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87294+
87295+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87296+ if (!(__supported_pte_mask & _PAGE_NX) &&
87297+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87298+ (vm_flags & (VM_READ | VM_WRITE)))
87299+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87300+#endif
87301+
87302+ return prot;
87303 }
87304 EXPORT_SYMBOL(vm_get_page_prot);
87305
87306@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87307 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87308 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87309 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87310+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87311 /*
87312 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87313 * other variables. It can be updated by several CPUs frequently.
87314@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87315 struct vm_area_struct *next = vma->vm_next;
87316
87317 might_sleep();
87318+ BUG_ON(vma->vm_mirror);
87319 if (vma->vm_ops && vma->vm_ops->close)
87320 vma->vm_ops->close(vma);
87321 if (vma->vm_file)
87322@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87323 * not page aligned -Ram Gupta
87324 */
87325 rlim = rlimit(RLIMIT_DATA);
87326+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87327 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87328 (mm->end_data - mm->start_data) > rlim)
87329 goto out;
87330@@ -933,6 +956,12 @@ static int
87331 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87332 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87333 {
87334+
87335+#ifdef CONFIG_PAX_SEGMEXEC
87336+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87337+ return 0;
87338+#endif
87339+
87340 if (is_mergeable_vma(vma, file, vm_flags) &&
87341 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87342 if (vma->vm_pgoff == vm_pgoff)
87343@@ -952,6 +981,12 @@ static int
87344 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87345 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87346 {
87347+
87348+#ifdef CONFIG_PAX_SEGMEXEC
87349+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87350+ return 0;
87351+#endif
87352+
87353 if (is_mergeable_vma(vma, file, vm_flags) &&
87354 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87355 pgoff_t vm_pglen;
87356@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87357 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87358 struct vm_area_struct *prev, unsigned long addr,
87359 unsigned long end, unsigned long vm_flags,
87360- struct anon_vma *anon_vma, struct file *file,
87361+ struct anon_vma *anon_vma, struct file *file,
87362 pgoff_t pgoff, struct mempolicy *policy)
87363 {
87364 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87365 struct vm_area_struct *area, *next;
87366 int err;
87367
87368+#ifdef CONFIG_PAX_SEGMEXEC
87369+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87370+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87371+
87372+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87373+#endif
87374+
87375 /*
87376 * We later require that vma->vm_flags == vm_flags,
87377 * so this tests vma->vm_flags & VM_SPECIAL, too.
87378@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87379 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87380 next = next->vm_next;
87381
87382+#ifdef CONFIG_PAX_SEGMEXEC
87383+ if (prev)
87384+ prev_m = pax_find_mirror_vma(prev);
87385+ if (area)
87386+ area_m = pax_find_mirror_vma(area);
87387+ if (next)
87388+ next_m = pax_find_mirror_vma(next);
87389+#endif
87390+
87391 /*
87392 * Can it merge with the predecessor?
87393 */
87394@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87395 /* cases 1, 6 */
87396 err = vma_adjust(prev, prev->vm_start,
87397 next->vm_end, prev->vm_pgoff, NULL);
87398- } else /* cases 2, 5, 7 */
87399+
87400+#ifdef CONFIG_PAX_SEGMEXEC
87401+ if (!err && prev_m)
87402+ err = vma_adjust(prev_m, prev_m->vm_start,
87403+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87404+#endif
87405+
87406+ } else { /* cases 2, 5, 7 */
87407 err = vma_adjust(prev, prev->vm_start,
87408 end, prev->vm_pgoff, NULL);
87409+
87410+#ifdef CONFIG_PAX_SEGMEXEC
87411+ if (!err && prev_m)
87412+ err = vma_adjust(prev_m, prev_m->vm_start,
87413+ end_m, prev_m->vm_pgoff, NULL);
87414+#endif
87415+
87416+ }
87417 if (err)
87418 return NULL;
87419 khugepaged_enter_vma_merge(prev);
87420@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87421 mpol_equal(policy, vma_policy(next)) &&
87422 can_vma_merge_before(next, vm_flags,
87423 anon_vma, file, pgoff+pglen)) {
87424- if (prev && addr < prev->vm_end) /* case 4 */
87425+ if (prev && addr < prev->vm_end) { /* case 4 */
87426 err = vma_adjust(prev, prev->vm_start,
87427 addr, prev->vm_pgoff, NULL);
87428- else /* cases 3, 8 */
87429+
87430+#ifdef CONFIG_PAX_SEGMEXEC
87431+ if (!err && prev_m)
87432+ err = vma_adjust(prev_m, prev_m->vm_start,
87433+ addr_m, prev_m->vm_pgoff, NULL);
87434+#endif
87435+
87436+ } else { /* cases 3, 8 */
87437 err = vma_adjust(area, addr, next->vm_end,
87438 next->vm_pgoff - pglen, NULL);
87439+
87440+#ifdef CONFIG_PAX_SEGMEXEC
87441+ if (!err && area_m)
87442+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87443+ next_m->vm_pgoff - pglen, NULL);
87444+#endif
87445+
87446+ }
87447 if (err)
87448 return NULL;
87449 khugepaged_enter_vma_merge(area);
87450@@ -1165,8 +1246,10 @@ none:
87451 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87452 struct file *file, long pages)
87453 {
87454- const unsigned long stack_flags
87455- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87456+
87457+#ifdef CONFIG_PAX_RANDMMAP
87458+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87459+#endif
87460
87461 mm->total_vm += pages;
87462
87463@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87464 mm->shared_vm += pages;
87465 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87466 mm->exec_vm += pages;
87467- } else if (flags & stack_flags)
87468+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87469 mm->stack_vm += pages;
87470 }
87471 #endif /* CONFIG_PROC_FS */
87472@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87473 * (the exception is when the underlying filesystem is noexec
87474 * mounted, in which case we dont add PROT_EXEC.)
87475 */
87476- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87477+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87478 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87479 prot |= PROT_EXEC;
87480
87481@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87482 /* Obtain the address to map to. we verify (or select) it and ensure
87483 * that it represents a valid section of the address space.
87484 */
87485- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87486+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87487 if (addr & ~PAGE_MASK)
87488 return addr;
87489
87490@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87491 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87492 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87493
87494+#ifdef CONFIG_PAX_MPROTECT
87495+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87496+
87497+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87498+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87499+ mm->binfmt->handle_mmap)
87500+ mm->binfmt->handle_mmap(file);
87501+#endif
87502+
87503+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87504+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87505+ gr_log_rwxmmap(file);
87506+
87507+#ifdef CONFIG_PAX_EMUPLT
87508+ vm_flags &= ~VM_EXEC;
87509+#else
87510+ return -EPERM;
87511+#endif
87512+
87513+ }
87514+
87515+ if (!(vm_flags & VM_EXEC))
87516+ vm_flags &= ~VM_MAYEXEC;
87517+#else
87518+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87519+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87520+#endif
87521+ else
87522+ vm_flags &= ~VM_MAYWRITE;
87523+ }
87524+#endif
87525+
87526+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87527+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87528+ vm_flags &= ~VM_PAGEEXEC;
87529+#endif
87530+
87531 if (flags & MAP_LOCKED)
87532 if (!can_do_mlock())
87533 return -EPERM;
87534@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87535 locked += mm->locked_vm;
87536 lock_limit = rlimit(RLIMIT_MEMLOCK);
87537 lock_limit >>= PAGE_SHIFT;
87538+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87539 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87540 return -EAGAIN;
87541 }
87542@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87543 vm_flags |= VM_NORESERVE;
87544 }
87545
87546+ if (!gr_acl_handle_mmap(file, prot))
87547+ return -EACCES;
87548+
87549 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87550 if (!IS_ERR_VALUE(addr) &&
87551 ((vm_flags & VM_LOCKED) ||
87552@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87553 vm_flags_t vm_flags = vma->vm_flags;
87554
87555 /* If it was private or non-writable, the write bit is already clear */
87556- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87557+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87558 return 0;
87559
87560 /* The backer wishes to know when pages are first written to? */
87561@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87562 unsigned long charged = 0;
87563 struct inode *inode = file ? file_inode(file) : NULL;
87564
87565+#ifdef CONFIG_PAX_SEGMEXEC
87566+ struct vm_area_struct *vma_m = NULL;
87567+#endif
87568+
87569+ /*
87570+ * mm->mmap_sem is required to protect against another thread
87571+ * changing the mappings in case we sleep.
87572+ */
87573+ verify_mm_writelocked(mm);
87574+
87575 /* Check against address space limit. */
87576+
87577+#ifdef CONFIG_PAX_RANDMMAP
87578+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87579+#endif
87580+
87581 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87582 unsigned long nr_pages;
87583
87584@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87585
87586 /* Clear old maps */
87587 error = -ENOMEM;
87588-munmap_back:
87589 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87590 if (do_munmap(mm, addr, len))
87591 return -ENOMEM;
87592- goto munmap_back;
87593+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87594 }
87595
87596 /*
87597@@ -1536,6 +1674,16 @@ munmap_back:
87598 goto unacct_error;
87599 }
87600
87601+#ifdef CONFIG_PAX_SEGMEXEC
87602+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87603+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87604+ if (!vma_m) {
87605+ error = -ENOMEM;
87606+ goto free_vma;
87607+ }
87608+ }
87609+#endif
87610+
87611 vma->vm_mm = mm;
87612 vma->vm_start = addr;
87613 vma->vm_end = addr + len;
87614@@ -1560,6 +1708,13 @@ munmap_back:
87615 if (error)
87616 goto unmap_and_free_vma;
87617
87618+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87619+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87620+ vma->vm_flags |= VM_PAGEEXEC;
87621+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87622+ }
87623+#endif
87624+
87625 /* Can addr have changed??
87626 *
87627 * Answer: Yes, several device drivers can do it in their
87628@@ -1598,6 +1753,11 @@ munmap_back:
87629 vma_link(mm, vma, prev, rb_link, rb_parent);
87630 file = vma->vm_file;
87631
87632+#ifdef CONFIG_PAX_SEGMEXEC
87633+ if (vma_m)
87634+ BUG_ON(pax_mirror_vma(vma_m, vma));
87635+#endif
87636+
87637 /* Once vma denies write, undo our temporary denial count */
87638 if (correct_wcount)
87639 atomic_inc(&inode->i_writecount);
87640@@ -1605,6 +1765,7 @@ out:
87641 perf_event_mmap(vma);
87642
87643 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87644+ track_exec_limit(mm, addr, addr + len, vm_flags);
87645 if (vm_flags & VM_LOCKED) {
87646 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87647 vma == get_gate_vma(current->mm)))
87648@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87649 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87650 charged = 0;
87651 free_vma:
87652+
87653+#ifdef CONFIG_PAX_SEGMEXEC
87654+ if (vma_m)
87655+ kmem_cache_free(vm_area_cachep, vma_m);
87656+#endif
87657+
87658 kmem_cache_free(vm_area_cachep, vma);
87659 unacct_error:
87660 if (charged)
87661@@ -1635,7 +1802,63 @@ unacct_error:
87662 return error;
87663 }
87664
87665-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87666+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87667+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87668+{
87669+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87670+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87671+
87672+ return 0;
87673+}
87674+#endif
87675+
87676+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87677+{
87678+ if (!vma) {
87679+#ifdef CONFIG_STACK_GROWSUP
87680+ if (addr > sysctl_heap_stack_gap)
87681+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87682+ else
87683+ vma = find_vma(current->mm, 0);
87684+ if (vma && (vma->vm_flags & VM_GROWSUP))
87685+ return false;
87686+#endif
87687+ return true;
87688+ }
87689+
87690+ if (addr + len > vma->vm_start)
87691+ return false;
87692+
87693+ if (vma->vm_flags & VM_GROWSDOWN)
87694+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87695+#ifdef CONFIG_STACK_GROWSUP
87696+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87697+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87698+#endif
87699+ else if (offset)
87700+ return offset <= vma->vm_start - addr - len;
87701+
87702+ return true;
87703+}
87704+
87705+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87706+{
87707+ if (vma->vm_start < len)
87708+ return -ENOMEM;
87709+
87710+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87711+ if (offset <= vma->vm_start - len)
87712+ return vma->vm_start - len - offset;
87713+ else
87714+ return -ENOMEM;
87715+ }
87716+
87717+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87718+ return vma->vm_start - len - sysctl_heap_stack_gap;
87719+ return -ENOMEM;
87720+}
87721+
87722+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87723 {
87724 /*
87725 * We implement the search by looking for an rbtree node that
87726@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87727 }
87728 }
87729
87730- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87731+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87732 check_current:
87733 /* Check if current node has a suitable gap */
87734 if (gap_start > high_limit)
87735 return -ENOMEM;
87736+
87737+ if (gap_end - gap_start > info->threadstack_offset)
87738+ gap_start += info->threadstack_offset;
87739+ else
87740+ gap_start = gap_end;
87741+
87742+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87743+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87744+ gap_start += sysctl_heap_stack_gap;
87745+ else
87746+ gap_start = gap_end;
87747+ }
87748+ if (vma->vm_flags & VM_GROWSDOWN) {
87749+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87750+ gap_end -= sysctl_heap_stack_gap;
87751+ else
87752+ gap_end = gap_start;
87753+ }
87754 if (gap_end >= low_limit && gap_end - gap_start >= length)
87755 goto found;
87756
87757@@ -1737,7 +1978,7 @@ found:
87758 return gap_start;
87759 }
87760
87761-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87762+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87763 {
87764 struct mm_struct *mm = current->mm;
87765 struct vm_area_struct *vma;
87766@@ -1791,6 +2032,24 @@ check_current:
87767 gap_end = vma->vm_start;
87768 if (gap_end < low_limit)
87769 return -ENOMEM;
87770+
87771+ if (gap_end - gap_start > info->threadstack_offset)
87772+ gap_end -= info->threadstack_offset;
87773+ else
87774+ gap_end = gap_start;
87775+
87776+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87777+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87778+ gap_start += sysctl_heap_stack_gap;
87779+ else
87780+ gap_start = gap_end;
87781+ }
87782+ if (vma->vm_flags & VM_GROWSDOWN) {
87783+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87784+ gap_end -= sysctl_heap_stack_gap;
87785+ else
87786+ gap_end = gap_start;
87787+ }
87788 if (gap_start <= high_limit && gap_end - gap_start >= length)
87789 goto found;
87790
87791@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87792 struct mm_struct *mm = current->mm;
87793 struct vm_area_struct *vma;
87794 struct vm_unmapped_area_info info;
87795+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87796
87797 if (len > TASK_SIZE)
87798 return -ENOMEM;
87799@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87800 if (flags & MAP_FIXED)
87801 return addr;
87802
87803+#ifdef CONFIG_PAX_RANDMMAP
87804+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87805+#endif
87806+
87807 if (addr) {
87808 addr = PAGE_ALIGN(addr);
87809 vma = find_vma(mm, addr);
87810- if (TASK_SIZE - len >= addr &&
87811- (!vma || addr + len <= vma->vm_start))
87812+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87813 return addr;
87814 }
87815
87816 info.flags = 0;
87817 info.length = len;
87818 info.low_limit = TASK_UNMAPPED_BASE;
87819+
87820+#ifdef CONFIG_PAX_RANDMMAP
87821+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87822+ info.low_limit += mm->delta_mmap;
87823+#endif
87824+
87825 info.high_limit = TASK_SIZE;
87826 info.align_mask = 0;
87827+ info.threadstack_offset = offset;
87828 return vm_unmapped_area(&info);
87829 }
87830 #endif
87831@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87832 struct mm_struct *mm = current->mm;
87833 unsigned long addr = addr0;
87834 struct vm_unmapped_area_info info;
87835+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87836
87837 /* requested length too big for entire address space */
87838 if (len > TASK_SIZE)
87839@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87840 if (flags & MAP_FIXED)
87841 return addr;
87842
87843+#ifdef CONFIG_PAX_RANDMMAP
87844+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87845+#endif
87846+
87847 /* requesting a specific address */
87848 if (addr) {
87849 addr = PAGE_ALIGN(addr);
87850 vma = find_vma(mm, addr);
87851- if (TASK_SIZE - len >= addr &&
87852- (!vma || addr + len <= vma->vm_start))
87853+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87854 return addr;
87855 }
87856
87857@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87858 info.low_limit = PAGE_SIZE;
87859 info.high_limit = mm->mmap_base;
87860 info.align_mask = 0;
87861+ info.threadstack_offset = offset;
87862 addr = vm_unmapped_area(&info);
87863
87864 /*
87865@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87866 VM_BUG_ON(addr != -ENOMEM);
87867 info.flags = 0;
87868 info.low_limit = TASK_UNMAPPED_BASE;
87869+
87870+#ifdef CONFIG_PAX_RANDMMAP
87871+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87872+ info.low_limit += mm->delta_mmap;
87873+#endif
87874+
87875 info.high_limit = TASK_SIZE;
87876 addr = vm_unmapped_area(&info);
87877 }
87878@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87879 return vma;
87880 }
87881
87882+#ifdef CONFIG_PAX_SEGMEXEC
87883+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87884+{
87885+ struct vm_area_struct *vma_m;
87886+
87887+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87888+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87889+ BUG_ON(vma->vm_mirror);
87890+ return NULL;
87891+ }
87892+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87893+ vma_m = vma->vm_mirror;
87894+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87895+ BUG_ON(vma->vm_file != vma_m->vm_file);
87896+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87897+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87898+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87899+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87900+ return vma_m;
87901+}
87902+#endif
87903+
87904 /*
87905 * Verify that the stack growth is acceptable and
87906 * update accounting. This is shared with both the
87907@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87908 return -ENOMEM;
87909
87910 /* Stack limit test */
87911+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87912 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87913 return -ENOMEM;
87914
87915@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87916 locked = mm->locked_vm + grow;
87917 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87918 limit >>= PAGE_SHIFT;
87919+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87920 if (locked > limit && !capable(CAP_IPC_LOCK))
87921 return -ENOMEM;
87922 }
87923@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87924 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87925 * vma is the last one with address > vma->vm_end. Have to extend vma.
87926 */
87927+#ifndef CONFIG_IA64
87928+static
87929+#endif
87930 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87931 {
87932 int error;
87933+ bool locknext;
87934
87935 if (!(vma->vm_flags & VM_GROWSUP))
87936 return -EFAULT;
87937
87938+ /* Also guard against wrapping around to address 0. */
87939+ if (address < PAGE_ALIGN(address+1))
87940+ address = PAGE_ALIGN(address+1);
87941+ else
87942+ return -ENOMEM;
87943+
87944 /*
87945 * We must make sure the anon_vma is allocated
87946 * so that the anon_vma locking is not a noop.
87947 */
87948 if (unlikely(anon_vma_prepare(vma)))
87949 return -ENOMEM;
87950+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87951+ if (locknext && anon_vma_prepare(vma->vm_next))
87952+ return -ENOMEM;
87953 vma_lock_anon_vma(vma);
87954+ if (locknext)
87955+ vma_lock_anon_vma(vma->vm_next);
87956
87957 /*
87958 * vma->vm_start/vm_end cannot change under us because the caller
87959 * is required to hold the mmap_sem in read mode. We need the
87960- * anon_vma lock to serialize against concurrent expand_stacks.
87961- * Also guard against wrapping around to address 0.
87962+ * anon_vma locks to serialize against concurrent expand_stacks
87963+ * and expand_upwards.
87964 */
87965- if (address < PAGE_ALIGN(address+4))
87966- address = PAGE_ALIGN(address+4);
87967- else {
87968- vma_unlock_anon_vma(vma);
87969- return -ENOMEM;
87970- }
87971 error = 0;
87972
87973 /* Somebody else might have raced and expanded it already */
87974- if (address > vma->vm_end) {
87975+ 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)
87976+ error = -ENOMEM;
87977+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87978 unsigned long size, grow;
87979
87980 size = address - vma->vm_start;
87981@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87982 }
87983 }
87984 }
87985+ if (locknext)
87986+ vma_unlock_anon_vma(vma->vm_next);
87987 vma_unlock_anon_vma(vma);
87988 khugepaged_enter_vma_merge(vma);
87989 validate_mm(vma->vm_mm);
87990@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87991 unsigned long address)
87992 {
87993 int error;
87994+ bool lockprev = false;
87995+ struct vm_area_struct *prev;
87996
87997 /*
87998 * We must make sure the anon_vma is allocated
87999@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
88000 if (error)
88001 return error;
88002
88003+ prev = vma->vm_prev;
88004+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
88005+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
88006+#endif
88007+ if (lockprev && anon_vma_prepare(prev))
88008+ return -ENOMEM;
88009+ if (lockprev)
88010+ vma_lock_anon_vma(prev);
88011+
88012 vma_lock_anon_vma(vma);
88013
88014 /*
88015@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88016 */
88017
88018 /* Somebody else might have raced and expanded it already */
88019- if (address < vma->vm_start) {
88020+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88021+ error = -ENOMEM;
88022+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88023 unsigned long size, grow;
88024
88025+#ifdef CONFIG_PAX_SEGMEXEC
88026+ struct vm_area_struct *vma_m;
88027+
88028+ vma_m = pax_find_mirror_vma(vma);
88029+#endif
88030+
88031 size = vma->vm_end - address;
88032 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88033
88034@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88035 vma->vm_pgoff -= grow;
88036 anon_vma_interval_tree_post_update_vma(vma);
88037 vma_gap_update(vma);
88038+
88039+#ifdef CONFIG_PAX_SEGMEXEC
88040+ if (vma_m) {
88041+ anon_vma_interval_tree_pre_update_vma(vma_m);
88042+ vma_m->vm_start -= grow << PAGE_SHIFT;
88043+ vma_m->vm_pgoff -= grow;
88044+ anon_vma_interval_tree_post_update_vma(vma_m);
88045+ vma_gap_update(vma_m);
88046+ }
88047+#endif
88048+
88049 spin_unlock(&vma->vm_mm->page_table_lock);
88050
88051+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88052 perf_event_mmap(vma);
88053 }
88054 }
88055 }
88056 vma_unlock_anon_vma(vma);
88057+ if (lockprev)
88058+ vma_unlock_anon_vma(prev);
88059 khugepaged_enter_vma_merge(vma);
88060 validate_mm(vma->vm_mm);
88061 return error;
88062@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88063 do {
88064 long nrpages = vma_pages(vma);
88065
88066+#ifdef CONFIG_PAX_SEGMEXEC
88067+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88068+ vma = remove_vma(vma);
88069+ continue;
88070+ }
88071+#endif
88072+
88073 if (vma->vm_flags & VM_ACCOUNT)
88074 nr_accounted += nrpages;
88075 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88076@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88077 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88078 vma->vm_prev = NULL;
88079 do {
88080+
88081+#ifdef CONFIG_PAX_SEGMEXEC
88082+ if (vma->vm_mirror) {
88083+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88084+ vma->vm_mirror->vm_mirror = NULL;
88085+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88086+ vma->vm_mirror = NULL;
88087+ }
88088+#endif
88089+
88090 vma_rb_erase(vma, &mm->mm_rb);
88091 mm->map_count--;
88092 tail_vma = vma;
88093@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88094 struct vm_area_struct *new;
88095 int err = -ENOMEM;
88096
88097+#ifdef CONFIG_PAX_SEGMEXEC
88098+ struct vm_area_struct *vma_m, *new_m = NULL;
88099+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88100+#endif
88101+
88102 if (is_vm_hugetlb_page(vma) && (addr &
88103 ~(huge_page_mask(hstate_vma(vma)))))
88104 return -EINVAL;
88105
88106+#ifdef CONFIG_PAX_SEGMEXEC
88107+ vma_m = pax_find_mirror_vma(vma);
88108+#endif
88109+
88110 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88111 if (!new)
88112 goto out_err;
88113
88114+#ifdef CONFIG_PAX_SEGMEXEC
88115+ if (vma_m) {
88116+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88117+ if (!new_m) {
88118+ kmem_cache_free(vm_area_cachep, new);
88119+ goto out_err;
88120+ }
88121+ }
88122+#endif
88123+
88124 /* most fields are the same, copy all, and then fixup */
88125 *new = *vma;
88126
88127@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88128 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88129 }
88130
88131+#ifdef CONFIG_PAX_SEGMEXEC
88132+ if (vma_m) {
88133+ *new_m = *vma_m;
88134+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88135+ new_m->vm_mirror = new;
88136+ new->vm_mirror = new_m;
88137+
88138+ if (new_below)
88139+ new_m->vm_end = addr_m;
88140+ else {
88141+ new_m->vm_start = addr_m;
88142+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88143+ }
88144+ }
88145+#endif
88146+
88147 pol = mpol_dup(vma_policy(vma));
88148 if (IS_ERR(pol)) {
88149 err = PTR_ERR(pol);
88150@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88151 else
88152 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88153
88154+#ifdef CONFIG_PAX_SEGMEXEC
88155+ if (!err && vma_m) {
88156+ if (anon_vma_clone(new_m, vma_m))
88157+ goto out_free_mpol;
88158+
88159+ mpol_get(pol);
88160+ vma_set_policy(new_m, pol);
88161+
88162+ if (new_m->vm_file)
88163+ get_file(new_m->vm_file);
88164+
88165+ if (new_m->vm_ops && new_m->vm_ops->open)
88166+ new_m->vm_ops->open(new_m);
88167+
88168+ if (new_below)
88169+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88170+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88171+ else
88172+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88173+
88174+ if (err) {
88175+ if (new_m->vm_ops && new_m->vm_ops->close)
88176+ new_m->vm_ops->close(new_m);
88177+ if (new_m->vm_file)
88178+ fput(new_m->vm_file);
88179+ mpol_put(pol);
88180+ }
88181+ }
88182+#endif
88183+
88184 /* Success. */
88185 if (!err)
88186 return 0;
88187@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88188 new->vm_ops->close(new);
88189 if (new->vm_file)
88190 fput(new->vm_file);
88191- unlink_anon_vmas(new);
88192 out_free_mpol:
88193 mpol_put(pol);
88194 out_free_vma:
88195+
88196+#ifdef CONFIG_PAX_SEGMEXEC
88197+ if (new_m) {
88198+ unlink_anon_vmas(new_m);
88199+ kmem_cache_free(vm_area_cachep, new_m);
88200+ }
88201+#endif
88202+
88203+ unlink_anon_vmas(new);
88204 kmem_cache_free(vm_area_cachep, new);
88205 out_err:
88206 return err;
88207@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88208 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88209 unsigned long addr, int new_below)
88210 {
88211+
88212+#ifdef CONFIG_PAX_SEGMEXEC
88213+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88214+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88215+ if (mm->map_count >= sysctl_max_map_count-1)
88216+ return -ENOMEM;
88217+ } else
88218+#endif
88219+
88220 if (mm->map_count >= sysctl_max_map_count)
88221 return -ENOMEM;
88222
88223@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88224 * work. This now handles partial unmappings.
88225 * Jeremy Fitzhardinge <jeremy@goop.org>
88226 */
88227+#ifdef CONFIG_PAX_SEGMEXEC
88228 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88229 {
88230+ int ret = __do_munmap(mm, start, len);
88231+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88232+ return ret;
88233+
88234+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88235+}
88236+
88237+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88238+#else
88239+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88240+#endif
88241+{
88242 unsigned long end;
88243 struct vm_area_struct *vma, *prev, *last;
88244
88245+ /*
88246+ * mm->mmap_sem is required to protect against another thread
88247+ * changing the mappings in case we sleep.
88248+ */
88249+ verify_mm_writelocked(mm);
88250+
88251 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88252 return -EINVAL;
88253
88254@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88255 /* Fix up all other VM information */
88256 remove_vma_list(mm, vma);
88257
88258+ track_exec_limit(mm, start, end, 0UL);
88259+
88260 return 0;
88261 }
88262
88263@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88264 int ret;
88265 struct mm_struct *mm = current->mm;
88266
88267+
88268+#ifdef CONFIG_PAX_SEGMEXEC
88269+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88270+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88271+ return -EINVAL;
88272+#endif
88273+
88274 down_write(&mm->mmap_sem);
88275 ret = do_munmap(mm, start, len);
88276 up_write(&mm->mmap_sem);
88277@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88278 return vm_munmap(addr, len);
88279 }
88280
88281-static inline void verify_mm_writelocked(struct mm_struct *mm)
88282-{
88283-#ifdef CONFIG_DEBUG_VM
88284- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88285- WARN_ON(1);
88286- up_read(&mm->mmap_sem);
88287- }
88288-#endif
88289-}
88290-
88291 /*
88292 * this is really a simplified "do_mmap". it only handles
88293 * anonymous maps. eventually we may be able to do some
88294@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88295 struct rb_node ** rb_link, * rb_parent;
88296 pgoff_t pgoff = addr >> PAGE_SHIFT;
88297 int error;
88298+ unsigned long charged;
88299
88300 len = PAGE_ALIGN(len);
88301 if (!len)
88302@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88303
88304 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88305
88306+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88307+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88308+ flags &= ~VM_EXEC;
88309+
88310+#ifdef CONFIG_PAX_MPROTECT
88311+ if (mm->pax_flags & MF_PAX_MPROTECT)
88312+ flags &= ~VM_MAYEXEC;
88313+#endif
88314+
88315+ }
88316+#endif
88317+
88318 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88319 if (error & ~PAGE_MASK)
88320 return error;
88321
88322+ charged = len >> PAGE_SHIFT;
88323+
88324 /*
88325 * mlock MCL_FUTURE?
88326 */
88327 if (mm->def_flags & VM_LOCKED) {
88328 unsigned long locked, lock_limit;
88329- locked = len >> PAGE_SHIFT;
88330+ locked = charged;
88331 locked += mm->locked_vm;
88332 lock_limit = rlimit(RLIMIT_MEMLOCK);
88333 lock_limit >>= PAGE_SHIFT;
88334@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88335 /*
88336 * Clear old maps. this also does some error checking for us
88337 */
88338- munmap_back:
88339 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88340 if (do_munmap(mm, addr, len))
88341 return -ENOMEM;
88342- goto munmap_back;
88343+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88344 }
88345
88346 /* Check against address space limits *after* clearing old maps... */
88347- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88348+ if (!may_expand_vm(mm, charged))
88349 return -ENOMEM;
88350
88351 if (mm->map_count > sysctl_max_map_count)
88352 return -ENOMEM;
88353
88354- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88355+ if (security_vm_enough_memory_mm(mm, charged))
88356 return -ENOMEM;
88357
88358 /* Can we just expand an old private anonymous mapping? */
88359@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88360 */
88361 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88362 if (!vma) {
88363- vm_unacct_memory(len >> PAGE_SHIFT);
88364+ vm_unacct_memory(charged);
88365 return -ENOMEM;
88366 }
88367
88368@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88369 vma_link(mm, vma, prev, rb_link, rb_parent);
88370 out:
88371 perf_event_mmap(vma);
88372- mm->total_vm += len >> PAGE_SHIFT;
88373+ mm->total_vm += charged;
88374 if (flags & VM_LOCKED)
88375- mm->locked_vm += (len >> PAGE_SHIFT);
88376+ mm->locked_vm += charged;
88377+ track_exec_limit(mm, addr, addr + len, flags);
88378 return addr;
88379 }
88380
88381@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88382 while (vma) {
88383 if (vma->vm_flags & VM_ACCOUNT)
88384 nr_accounted += vma_pages(vma);
88385+ vma->vm_mirror = NULL;
88386 vma = remove_vma(vma);
88387 }
88388 vm_unacct_memory(nr_accounted);
88389@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88390 struct vm_area_struct *prev;
88391 struct rb_node **rb_link, *rb_parent;
88392
88393+#ifdef CONFIG_PAX_SEGMEXEC
88394+ struct vm_area_struct *vma_m = NULL;
88395+#endif
88396+
88397+ if (security_mmap_addr(vma->vm_start))
88398+ return -EPERM;
88399+
88400 /*
88401 * The vm_pgoff of a purely anonymous vma should be irrelevant
88402 * until its first write fault, when page's anon_vma and index
88403@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88404 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88405 return -ENOMEM;
88406
88407+#ifdef CONFIG_PAX_SEGMEXEC
88408+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88409+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88410+ if (!vma_m)
88411+ return -ENOMEM;
88412+ }
88413+#endif
88414+
88415 vma_link(mm, vma, prev, rb_link, rb_parent);
88416+
88417+#ifdef CONFIG_PAX_SEGMEXEC
88418+ if (vma_m)
88419+ BUG_ON(pax_mirror_vma(vma_m, vma));
88420+#endif
88421+
88422 return 0;
88423 }
88424
88425@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88426 struct mempolicy *pol;
88427 bool faulted_in_anon_vma = true;
88428
88429+ BUG_ON(vma->vm_mirror);
88430+
88431 /*
88432 * If anonymous vma has not yet been faulted, update new pgoff
88433 * to match new location, to increase its chance of merging.
88434@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88435 return NULL;
88436 }
88437
88438+#ifdef CONFIG_PAX_SEGMEXEC
88439+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88440+{
88441+ struct vm_area_struct *prev_m;
88442+ struct rb_node **rb_link_m, *rb_parent_m;
88443+ struct mempolicy *pol_m;
88444+
88445+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88446+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88447+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88448+ *vma_m = *vma;
88449+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88450+ if (anon_vma_clone(vma_m, vma))
88451+ return -ENOMEM;
88452+ pol_m = vma_policy(vma_m);
88453+ mpol_get(pol_m);
88454+ vma_set_policy(vma_m, pol_m);
88455+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88456+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88457+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88458+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88459+ if (vma_m->vm_file)
88460+ get_file(vma_m->vm_file);
88461+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88462+ vma_m->vm_ops->open(vma_m);
88463+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88464+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88465+ vma_m->vm_mirror = vma;
88466+ vma->vm_mirror = vma_m;
88467+ return 0;
88468+}
88469+#endif
88470+
88471 /*
88472 * Return true if the calling process may expand its vm space by the passed
88473 * number of pages
88474@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88475
88476 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88477
88478+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88479 if (cur + npages > lim)
88480 return 0;
88481 return 1;
88482@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88483 vma->vm_start = addr;
88484 vma->vm_end = addr + len;
88485
88486+#ifdef CONFIG_PAX_MPROTECT
88487+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88488+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88489+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88490+ return -EPERM;
88491+ if (!(vm_flags & VM_EXEC))
88492+ vm_flags &= ~VM_MAYEXEC;
88493+#else
88494+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88495+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88496+#endif
88497+ else
88498+ vm_flags &= ~VM_MAYWRITE;
88499+ }
88500+#endif
88501+
88502 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88503 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88504
88505diff --git a/mm/mprotect.c b/mm/mprotect.c
88506index a3af058..bc2cb14 100644
88507--- a/mm/mprotect.c
88508+++ b/mm/mprotect.c
88509@@ -23,10 +23,18 @@
88510 #include <linux/mmu_notifier.h>
88511 #include <linux/migrate.h>
88512 #include <linux/perf_event.h>
88513+#include <linux/sched/sysctl.h>
88514+
88515+#ifdef CONFIG_PAX_MPROTECT
88516+#include <linux/elf.h>
88517+#include <linux/binfmts.h>
88518+#endif
88519+
88520 #include <asm/uaccess.h>
88521 #include <asm/pgtable.h>
88522 #include <asm/cacheflush.h>
88523 #include <asm/tlbflush.h>
88524+#include <asm/mmu_context.h>
88525
88526 #ifndef pgprot_modify
88527 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88528@@ -236,6 +244,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88529 return pages;
88530 }
88531
88532+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88533+/* called while holding the mmap semaphor for writing except stack expansion */
88534+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88535+{
88536+ unsigned long oldlimit, newlimit = 0UL;
88537+
88538+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88539+ return;
88540+
88541+ spin_lock(&mm->page_table_lock);
88542+ oldlimit = mm->context.user_cs_limit;
88543+ if ((prot & VM_EXEC) && oldlimit < end)
88544+ /* USER_CS limit moved up */
88545+ newlimit = end;
88546+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88547+ /* USER_CS limit moved down */
88548+ newlimit = start;
88549+
88550+ if (newlimit) {
88551+ mm->context.user_cs_limit = newlimit;
88552+
88553+#ifdef CONFIG_SMP
88554+ wmb();
88555+ cpus_clear(mm->context.cpu_user_cs_mask);
88556+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88557+#endif
88558+
88559+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88560+ }
88561+ spin_unlock(&mm->page_table_lock);
88562+ if (newlimit == end) {
88563+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88564+
88565+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88566+ if (is_vm_hugetlb_page(vma))
88567+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88568+ else
88569+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88570+ }
88571+}
88572+#endif
88573+
88574 int
88575 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88576 unsigned long start, unsigned long end, unsigned long newflags)
88577@@ -248,11 +298,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88578 int error;
88579 int dirty_accountable = 0;
88580
88581+#ifdef CONFIG_PAX_SEGMEXEC
88582+ struct vm_area_struct *vma_m = NULL;
88583+ unsigned long start_m, end_m;
88584+
88585+ start_m = start + SEGMEXEC_TASK_SIZE;
88586+ end_m = end + SEGMEXEC_TASK_SIZE;
88587+#endif
88588+
88589 if (newflags == oldflags) {
88590 *pprev = vma;
88591 return 0;
88592 }
88593
88594+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88595+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88596+
88597+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88598+ return -ENOMEM;
88599+
88600+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88601+ return -ENOMEM;
88602+ }
88603+
88604 /*
88605 * If we make a private mapping writable we increase our commit;
88606 * but (without finer accounting) cannot reduce our commit if we
88607@@ -269,6 +337,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88608 }
88609 }
88610
88611+#ifdef CONFIG_PAX_SEGMEXEC
88612+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88613+ if (start != vma->vm_start) {
88614+ error = split_vma(mm, vma, start, 1);
88615+ if (error)
88616+ goto fail;
88617+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88618+ *pprev = (*pprev)->vm_next;
88619+ }
88620+
88621+ if (end != vma->vm_end) {
88622+ error = split_vma(mm, vma, end, 0);
88623+ if (error)
88624+ goto fail;
88625+ }
88626+
88627+ if (pax_find_mirror_vma(vma)) {
88628+ error = __do_munmap(mm, start_m, end_m - start_m);
88629+ if (error)
88630+ goto fail;
88631+ } else {
88632+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88633+ if (!vma_m) {
88634+ error = -ENOMEM;
88635+ goto fail;
88636+ }
88637+ vma->vm_flags = newflags;
88638+ error = pax_mirror_vma(vma_m, vma);
88639+ if (error) {
88640+ vma->vm_flags = oldflags;
88641+ goto fail;
88642+ }
88643+ }
88644+ }
88645+#endif
88646+
88647 /*
88648 * First try to merge with previous and/or next vma.
88649 */
88650@@ -299,9 +403,21 @@ success:
88651 * vm_flags and vm_page_prot are protected by the mmap_sem
88652 * held in write mode.
88653 */
88654+
88655+#ifdef CONFIG_PAX_SEGMEXEC
88656+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88657+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88658+#endif
88659+
88660 vma->vm_flags = newflags;
88661+
88662+#ifdef CONFIG_PAX_MPROTECT
88663+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88664+ mm->binfmt->handle_mprotect(vma, newflags);
88665+#endif
88666+
88667 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88668- vm_get_page_prot(newflags));
88669+ vm_get_page_prot(vma->vm_flags));
88670
88671 if (vma_wants_writenotify(vma)) {
88672 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88673@@ -340,6 +456,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88674 end = start + len;
88675 if (end <= start)
88676 return -ENOMEM;
88677+
88678+#ifdef CONFIG_PAX_SEGMEXEC
88679+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88680+ if (end > SEGMEXEC_TASK_SIZE)
88681+ return -EINVAL;
88682+ } else
88683+#endif
88684+
88685+ if (end > TASK_SIZE)
88686+ return -EINVAL;
88687+
88688 if (!arch_validate_prot(prot))
88689 return -EINVAL;
88690
88691@@ -347,7 +474,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88692 /*
88693 * Does the application expect PROT_READ to imply PROT_EXEC:
88694 */
88695- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88696+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88697 prot |= PROT_EXEC;
88698
88699 vm_flags = calc_vm_prot_bits(prot);
88700@@ -379,6 +506,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88701 if (start > vma->vm_start)
88702 prev = vma;
88703
88704+#ifdef CONFIG_PAX_MPROTECT
88705+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88706+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88707+#endif
88708+
88709 for (nstart = start ; ; ) {
88710 unsigned long newflags;
88711
88712@@ -389,6 +521,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88713
88714 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88715 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88716+ if (prot & (PROT_WRITE | PROT_EXEC))
88717+ gr_log_rwxmprotect(vma);
88718+
88719+ error = -EACCES;
88720+ goto out;
88721+ }
88722+
88723+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88724 error = -EACCES;
88725 goto out;
88726 }
88727@@ -403,6 +543,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88728 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88729 if (error)
88730 goto out;
88731+
88732+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88733+
88734 nstart = tmp;
88735
88736 if (nstart < prev->vm_end)
88737diff --git a/mm/mremap.c b/mm/mremap.c
88738index 0843feb..4f5b2e6 100644
88739--- a/mm/mremap.c
88740+++ b/mm/mremap.c
88741@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88742 continue;
88743 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88744 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88745+
88746+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88747+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88748+ pte = pte_exprotect(pte);
88749+#endif
88750+
88751 pte = move_soft_dirty_pte(pte);
88752 set_pte_at(mm, new_addr, new_pte, pte);
88753 }
88754@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88755 if (is_vm_hugetlb_page(vma))
88756 goto Einval;
88757
88758+#ifdef CONFIG_PAX_SEGMEXEC
88759+ if (pax_find_mirror_vma(vma))
88760+ goto Einval;
88761+#endif
88762+
88763 /* We can't remap across vm area boundaries */
88764 if (old_len > vma->vm_end - addr)
88765 goto Efault;
88766@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88767 unsigned long ret = -EINVAL;
88768 unsigned long charged = 0;
88769 unsigned long map_flags;
88770+ unsigned long pax_task_size = TASK_SIZE;
88771
88772 if (new_addr & ~PAGE_MASK)
88773 goto out;
88774
88775- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88776+#ifdef CONFIG_PAX_SEGMEXEC
88777+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88778+ pax_task_size = SEGMEXEC_TASK_SIZE;
88779+#endif
88780+
88781+ pax_task_size -= PAGE_SIZE;
88782+
88783+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88784 goto out;
88785
88786 /* Check if the location we're moving into overlaps the
88787 * old location at all, and fail if it does.
88788 */
88789- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88790- goto out;
88791-
88792- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88793+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88794 goto out;
88795
88796 ret = do_munmap(mm, new_addr, new_len);
88797@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88798 unsigned long ret = -EINVAL;
88799 unsigned long charged = 0;
88800 bool locked = false;
88801+ unsigned long pax_task_size = TASK_SIZE;
88802
88803 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88804 return ret;
88805@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88806 if (!new_len)
88807 return ret;
88808
88809+#ifdef CONFIG_PAX_SEGMEXEC
88810+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88811+ pax_task_size = SEGMEXEC_TASK_SIZE;
88812+#endif
88813+
88814+ pax_task_size -= PAGE_SIZE;
88815+
88816+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88817+ old_len > pax_task_size || addr > pax_task_size-old_len)
88818+ return ret;
88819+
88820 down_write(&current->mm->mmap_sem);
88821
88822 if (flags & MREMAP_FIXED) {
88823@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88824 new_addr = addr;
88825 }
88826 ret = addr;
88827+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88828 goto out;
88829 }
88830 }
88831@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88832 goto out;
88833 }
88834
88835+ map_flags = vma->vm_flags;
88836 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88837+ if (!(ret & ~PAGE_MASK)) {
88838+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88839+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88840+ }
88841 }
88842 out:
88843 if (ret & ~PAGE_MASK)
88844diff --git a/mm/nommu.c b/mm/nommu.c
88845index ecd1f15..77039bd 100644
88846--- a/mm/nommu.c
88847+++ b/mm/nommu.c
88848@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88849 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88850 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88851 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88852-int heap_stack_gap = 0;
88853
88854 atomic_long_t mmap_pages_allocated;
88855
88856@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88857 EXPORT_SYMBOL(find_vma);
88858
88859 /*
88860- * find a VMA
88861- * - we don't extend stack VMAs under NOMMU conditions
88862- */
88863-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88864-{
88865- return find_vma(mm, addr);
88866-}
88867-
88868-/*
88869 * expand a stack to a given address
88870 * - not supported under NOMMU conditions
88871 */
88872@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88873
88874 /* most fields are the same, copy all, and then fixup */
88875 *new = *vma;
88876+ INIT_LIST_HEAD(&new->anon_vma_chain);
88877 *region = *vma->vm_region;
88878 new->vm_region = region;
88879
88880@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88881 }
88882 EXPORT_SYMBOL(generic_file_remap_pages);
88883
88884-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88885- unsigned long addr, void *buf, int len, int write)
88886+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88887+ unsigned long addr, void *buf, size_t len, int write)
88888 {
88889 struct vm_area_struct *vma;
88890
88891@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88892 *
88893 * The caller must hold a reference on @mm.
88894 */
88895-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88896- void *buf, int len, int write)
88897+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88898+ void *buf, size_t len, int write)
88899 {
88900 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88901 }
88902@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88903 * Access another process' address space.
88904 * - source/target buffer must be kernel space
88905 */
88906-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88907+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88908 {
88909 struct mm_struct *mm;
88910
88911diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88912index 241a746..41cd05d 100644
88913--- a/mm/page-writeback.c
88914+++ b/mm/page-writeback.c
88915@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88916 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88917 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88918 */
88919-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88920+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88921 unsigned long thresh,
88922 unsigned long bg_thresh,
88923 unsigned long dirty,
88924diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88925index b100255..fba1254 100644
88926--- a/mm/page_alloc.c
88927+++ b/mm/page_alloc.c
88928@@ -60,6 +60,7 @@
88929 #include <linux/page-debug-flags.h>
88930 #include <linux/hugetlb.h>
88931 #include <linux/sched/rt.h>
88932+#include <linux/random.h>
88933
88934 #include <asm/sections.h>
88935 #include <asm/tlbflush.h>
88936@@ -353,7 +354,7 @@ out:
88937 * This usage means that zero-order pages may not be compound.
88938 */
88939
88940-static void free_compound_page(struct page *page)
88941+void free_compound_page(struct page *page)
88942 {
88943 __free_pages_ok(page, compound_order(page));
88944 }
88945@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88946 int i;
88947 int bad = 0;
88948
88949+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88950+ unsigned long index = 1UL << order;
88951+#endif
88952+
88953 trace_mm_page_free(page, order);
88954 kmemcheck_free_shadow(page, order);
88955
88956@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88957 debug_check_no_obj_freed(page_address(page),
88958 PAGE_SIZE << order);
88959 }
88960+
88961+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88962+ for (; index; --index)
88963+ sanitize_highpage(page + index - 1);
88964+#endif
88965+
88966 arch_free_page(page, order);
88967 kernel_map_pages(page, 1 << order, 0);
88968
88969@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88970 local_irq_restore(flags);
88971 }
88972
88973+#ifdef CONFIG_PAX_LATENT_ENTROPY
88974+bool __meminitdata extra_latent_entropy;
88975+
88976+static int __init setup_pax_extra_latent_entropy(char *str)
88977+{
88978+ extra_latent_entropy = true;
88979+ return 0;
88980+}
88981+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88982+
88983+volatile u64 latent_entropy;
88984+EXPORT_SYMBOL(latent_entropy);
88985+#endif
88986+
88987 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88988 {
88989 unsigned int nr_pages = 1 << order;
88990@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88991 set_page_count(p, 0);
88992 }
88993
88994+#ifdef CONFIG_PAX_LATENT_ENTROPY
88995+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88996+ u64 hash = 0;
88997+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88998+ const u64 *data = lowmem_page_address(page);
88999+
89000+ for (index = 0; index < end; index++)
89001+ hash ^= hash + data[index];
89002+ latent_entropy ^= hash;
89003+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89004+ }
89005+#endif
89006+
89007 page_zone(page)->managed_pages += 1 << order;
89008 set_page_refcounted(page);
89009 __free_pages(page, order);
89010@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89011 arch_alloc_page(page, order);
89012 kernel_map_pages(page, 1 << order, 1);
89013
89014+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89015 if (gfp_flags & __GFP_ZERO)
89016 prep_zero_page(page, order, gfp_flags);
89017+#endif
89018
89019 if (order && (gfp_flags & __GFP_COMP))
89020 prep_compound_page(page, order);
89021diff --git a/mm/page_io.c b/mm/page_io.c
89022index ba05b64..ef2f314 100644
89023--- a/mm/page_io.c
89024+++ b/mm/page_io.c
89025@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89026 struct file *swap_file = sis->swap_file;
89027 struct address_space *mapping = swap_file->f_mapping;
89028 struct iovec iov = {
89029- .iov_base = kmap(page),
89030+ .iov_base = (void __force_user *)kmap(page),
89031 .iov_len = PAGE_SIZE,
89032 };
89033
89034diff --git a/mm/percpu.c b/mm/percpu.c
89035index 8c8e08f..73a5cda 100644
89036--- a/mm/percpu.c
89037+++ b/mm/percpu.c
89038@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89039 static unsigned int pcpu_high_unit_cpu __read_mostly;
89040
89041 /* the address of the first chunk which starts with the kernel static area */
89042-void *pcpu_base_addr __read_mostly;
89043+void *pcpu_base_addr __read_only;
89044 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89045
89046 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89047diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89048index fd26d04..0cea1b0 100644
89049--- a/mm/process_vm_access.c
89050+++ b/mm/process_vm_access.c
89051@@ -13,6 +13,7 @@
89052 #include <linux/uio.h>
89053 #include <linux/sched.h>
89054 #include <linux/highmem.h>
89055+#include <linux/security.h>
89056 #include <linux/ptrace.h>
89057 #include <linux/slab.h>
89058 #include <linux/syscalls.h>
89059@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89060 size_t iov_l_curr_offset = 0;
89061 ssize_t iov_len;
89062
89063+ return -ENOSYS; // PaX: until properly audited
89064+
89065 /*
89066 * Work out how many pages of struct pages we're going to need
89067 * when eventually calling get_user_pages
89068 */
89069 for (i = 0; i < riovcnt; i++) {
89070 iov_len = rvec[i].iov_len;
89071- if (iov_len > 0) {
89072- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89073- + iov_len)
89074- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89075- / PAGE_SIZE + 1;
89076- nr_pages = max(nr_pages, nr_pages_iov);
89077- }
89078+ if (iov_len <= 0)
89079+ continue;
89080+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89081+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89082+ nr_pages = max(nr_pages, nr_pages_iov);
89083 }
89084
89085 if (nr_pages == 0)
89086@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89087 goto free_proc_pages;
89088 }
89089
89090+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89091+ rc = -EPERM;
89092+ goto put_task_struct;
89093+ }
89094+
89095 mm = mm_access(task, PTRACE_MODE_ATTACH);
89096 if (!mm || IS_ERR(mm)) {
89097 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89098diff --git a/mm/rmap.c b/mm/rmap.c
89099index b2e29ac..4168491 100644
89100--- a/mm/rmap.c
89101+++ b/mm/rmap.c
89102@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89103 struct anon_vma *anon_vma = vma->anon_vma;
89104 struct anon_vma_chain *avc;
89105
89106+#ifdef CONFIG_PAX_SEGMEXEC
89107+ struct anon_vma_chain *avc_m = NULL;
89108+#endif
89109+
89110 might_sleep();
89111 if (unlikely(!anon_vma)) {
89112 struct mm_struct *mm = vma->vm_mm;
89113@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89114 if (!avc)
89115 goto out_enomem;
89116
89117+#ifdef CONFIG_PAX_SEGMEXEC
89118+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89119+ if (!avc_m)
89120+ goto out_enomem_free_avc;
89121+#endif
89122+
89123 anon_vma = find_mergeable_anon_vma(vma);
89124 allocated = NULL;
89125 if (!anon_vma) {
89126@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89127 /* page_table_lock to protect against threads */
89128 spin_lock(&mm->page_table_lock);
89129 if (likely(!vma->anon_vma)) {
89130+
89131+#ifdef CONFIG_PAX_SEGMEXEC
89132+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89133+
89134+ if (vma_m) {
89135+ BUG_ON(vma_m->anon_vma);
89136+ vma_m->anon_vma = anon_vma;
89137+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89138+ avc_m = NULL;
89139+ }
89140+#endif
89141+
89142 vma->anon_vma = anon_vma;
89143 anon_vma_chain_link(vma, avc, anon_vma);
89144 allocated = NULL;
89145@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89146
89147 if (unlikely(allocated))
89148 put_anon_vma(allocated);
89149+
89150+#ifdef CONFIG_PAX_SEGMEXEC
89151+ if (unlikely(avc_m))
89152+ anon_vma_chain_free(avc_m);
89153+#endif
89154+
89155 if (unlikely(avc))
89156 anon_vma_chain_free(avc);
89157 }
89158 return 0;
89159
89160 out_enomem_free_avc:
89161+
89162+#ifdef CONFIG_PAX_SEGMEXEC
89163+ if (avc_m)
89164+ anon_vma_chain_free(avc_m);
89165+#endif
89166+
89167 anon_vma_chain_free(avc);
89168 out_enomem:
89169 return -ENOMEM;
89170@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89171 * Attach the anon_vmas from src to dst.
89172 * Returns 0 on success, -ENOMEM on failure.
89173 */
89174-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89175+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89176 {
89177 struct anon_vma_chain *avc, *pavc;
89178 struct anon_vma *root = NULL;
89179@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89180 * the corresponding VMA in the parent process is attached to.
89181 * Returns 0 on success, non-zero on failure.
89182 */
89183-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89184+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89185 {
89186 struct anon_vma_chain *avc;
89187 struct anon_vma *anon_vma;
89188@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89189 void __init anon_vma_init(void)
89190 {
89191 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89192- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89193- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89194+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89195+ anon_vma_ctor);
89196+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89197+ SLAB_PANIC|SLAB_NO_SANITIZE);
89198 }
89199
89200 /*
89201diff --git a/mm/shmem.c b/mm/shmem.c
89202index e43dc55..930e3a2 100644
89203--- a/mm/shmem.c
89204+++ b/mm/shmem.c
89205@@ -33,7 +33,7 @@
89206 #include <linux/swap.h>
89207 #include <linux/aio.h>
89208
89209-static struct vfsmount *shm_mnt;
89210+struct vfsmount *shm_mnt;
89211
89212 #ifdef CONFIG_SHMEM
89213 /*
89214@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89215 #define BOGO_DIRENT_SIZE 20
89216
89217 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89218-#define SHORT_SYMLINK_LEN 128
89219+#define SHORT_SYMLINK_LEN 64
89220
89221 /*
89222 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89223@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89224 static int shmem_xattr_validate(const char *name)
89225 {
89226 struct { const char *prefix; size_t len; } arr[] = {
89227+
89228+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89229+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89230+#endif
89231+
89232 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89233 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89234 };
89235@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89236 if (err)
89237 return err;
89238
89239+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89240+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89241+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89242+ return -EOPNOTSUPP;
89243+ if (size > 8)
89244+ return -EINVAL;
89245+ }
89246+#endif
89247+
89248 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89249 }
89250
89251@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89252 int err = -ENOMEM;
89253
89254 /* Round up to L1_CACHE_BYTES to resist false sharing */
89255- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89256- L1_CACHE_BYTES), GFP_KERNEL);
89257+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89258 if (!sbinfo)
89259 return -ENOMEM;
89260
89261diff --git a/mm/slab.c b/mm/slab.c
89262index 2580db0..0523956 100644
89263--- a/mm/slab.c
89264+++ b/mm/slab.c
89265@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89266 if ((x)->max_freeable < i) \
89267 (x)->max_freeable = i; \
89268 } while (0)
89269-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89270-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89271-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89272-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89273+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89274+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89275+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89276+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89277+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89278+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89279 #else
89280 #define STATS_INC_ACTIVE(x) do { } while (0)
89281 #define STATS_DEC_ACTIVE(x) do { } while (0)
89282@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89283 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89284 #define STATS_INC_FREEHIT(x) do { } while (0)
89285 #define STATS_INC_FREEMISS(x) do { } while (0)
89286+#define STATS_INC_SANITIZED(x) do { } while (0)
89287+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89288 #endif
89289
89290 #if DEBUG
89291@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89292 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89293 */
89294 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89295- const struct slab *slab, void *obj)
89296+ const struct slab *slab, const void *obj)
89297 {
89298 u32 offset = (obj - slab->s_mem);
89299 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89300@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89301 */
89302
89303 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89304- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89305+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89306
89307 if (INDEX_AC != INDEX_NODE)
89308 kmalloc_caches[INDEX_NODE] =
89309 create_kmalloc_cache("kmalloc-node",
89310- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89311+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89312
89313 slab_early_init = 0;
89314
89315@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89316 struct array_cache *ac = cpu_cache_get(cachep);
89317
89318 check_irq_off();
89319+
89320+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89321+ if (pax_sanitize_slab) {
89322+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89323+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89324+
89325+ if (cachep->ctor)
89326+ cachep->ctor(objp);
89327+
89328+ STATS_INC_SANITIZED(cachep);
89329+ } else
89330+ STATS_INC_NOT_SANITIZED(cachep);
89331+ }
89332+#endif
89333+
89334 kmemleak_free_recursive(objp, cachep->flags);
89335 objp = cache_free_debugcheck(cachep, objp, caller);
89336
89337@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89338
89339 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89340 return;
89341+ VM_BUG_ON(!virt_addr_valid(objp));
89342 local_irq_save(flags);
89343 kfree_debugcheck(objp);
89344 c = virt_to_cache(objp);
89345@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89346 }
89347 /* cpu stats */
89348 {
89349- unsigned long allochit = atomic_read(&cachep->allochit);
89350- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89351- unsigned long freehit = atomic_read(&cachep->freehit);
89352- unsigned long freemiss = atomic_read(&cachep->freemiss);
89353+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89354+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89355+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89356+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89357
89358 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89359 allochit, allocmiss, freehit, freemiss);
89360 }
89361+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89362+ {
89363+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89364+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89365+
89366+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89367+ }
89368+#endif
89369 #endif
89370 }
89371
89372@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89373 static int __init slab_proc_init(void)
89374 {
89375 #ifdef CONFIG_DEBUG_SLAB_LEAK
89376- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89377+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89378 #endif
89379 return 0;
89380 }
89381 module_init(slab_proc_init);
89382 #endif
89383
89384+bool is_usercopy_object(const void *ptr)
89385+{
89386+ struct page *page;
89387+ struct kmem_cache *cachep;
89388+
89389+ if (ZERO_OR_NULL_PTR(ptr))
89390+ return false;
89391+
89392+ if (!slab_is_available())
89393+ return false;
89394+
89395+ if (!virt_addr_valid(ptr))
89396+ return false;
89397+
89398+ page = virt_to_head_page(ptr);
89399+
89400+ if (!PageSlab(page))
89401+ return false;
89402+
89403+ cachep = page->slab_cache;
89404+ return cachep->flags & SLAB_USERCOPY;
89405+}
89406+
89407+#ifdef CONFIG_PAX_USERCOPY
89408+const char *check_heap_object(const void *ptr, unsigned long n)
89409+{
89410+ struct page *page;
89411+ struct kmem_cache *cachep;
89412+ struct slab *slabp;
89413+ unsigned int objnr;
89414+ unsigned long offset;
89415+
89416+ if (ZERO_OR_NULL_PTR(ptr))
89417+ return "<null>";
89418+
89419+ if (!virt_addr_valid(ptr))
89420+ return NULL;
89421+
89422+ page = virt_to_head_page(ptr);
89423+
89424+ if (!PageSlab(page))
89425+ return NULL;
89426+
89427+ cachep = page->slab_cache;
89428+ if (!(cachep->flags & SLAB_USERCOPY))
89429+ return cachep->name;
89430+
89431+ slabp = page->slab_page;
89432+ objnr = obj_to_index(cachep, slabp, ptr);
89433+ BUG_ON(objnr >= cachep->num);
89434+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89435+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89436+ return NULL;
89437+
89438+ return cachep->name;
89439+}
89440+#endif
89441+
89442 /**
89443 * ksize - get the actual amount of memory allocated for a given object
89444 * @objp: Pointer to the object
89445diff --git a/mm/slab.h b/mm/slab.h
89446index a535033..2f98fe5 100644
89447--- a/mm/slab.h
89448+++ b/mm/slab.h
89449@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89450 /* The slab cache that manages slab cache information */
89451 extern struct kmem_cache *kmem_cache;
89452
89453+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89454+#ifdef CONFIG_X86_64
89455+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89456+#else
89457+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89458+#endif
89459+extern bool pax_sanitize_slab;
89460+#endif
89461+
89462 unsigned long calculate_alignment(unsigned long flags,
89463 unsigned long align, unsigned long size);
89464
89465@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89466
89467 /* Legal flag mask for kmem_cache_create(), for various configurations */
89468 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89469- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89470+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89471+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89472
89473 #if defined(CONFIG_DEBUG_SLAB)
89474 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89475@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89476 return s;
89477
89478 page = virt_to_head_page(x);
89479+
89480+ BUG_ON(!PageSlab(page));
89481+
89482 cachep = page->slab_cache;
89483 if (slab_equal_or_root(cachep, s))
89484 return cachep;
89485diff --git a/mm/slab_common.c b/mm/slab_common.c
89486index 538bade..36fed99 100644
89487--- a/mm/slab_common.c
89488+++ b/mm/slab_common.c
89489@@ -22,11 +22,22 @@
89490
89491 #include "slab.h"
89492
89493-enum slab_state slab_state;
89494+enum slab_state slab_state __read_only;
89495 LIST_HEAD(slab_caches);
89496 DEFINE_MUTEX(slab_mutex);
89497 struct kmem_cache *kmem_cache;
89498
89499+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89500+bool pax_sanitize_slab __read_only = true;
89501+static int __init pax_sanitize_slab_setup(char *str)
89502+{
89503+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89504+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89505+ return 1;
89506+}
89507+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89508+#endif
89509+
89510 #ifdef CONFIG_DEBUG_VM
89511 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89512 size_t size)
89513@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89514
89515 err = __kmem_cache_create(s, flags);
89516 if (!err) {
89517- s->refcount = 1;
89518+ atomic_set(&s->refcount, 1);
89519 list_add(&s->list, &slab_caches);
89520 memcg_cache_list_add(memcg, s);
89521 } else {
89522@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89523
89524 get_online_cpus();
89525 mutex_lock(&slab_mutex);
89526- s->refcount--;
89527- if (!s->refcount) {
89528+ if (atomic_dec_and_test(&s->refcount)) {
89529 list_del(&s->list);
89530
89531 if (!__kmem_cache_shutdown(s)) {
89532@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89533 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89534 name, size, err);
89535
89536- s->refcount = -1; /* Exempt from merging for now */
89537+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89538 }
89539
89540 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89541@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89542
89543 create_boot_cache(s, name, size, flags);
89544 list_add(&s->list, &slab_caches);
89545- s->refcount = 1;
89546+ atomic_set(&s->refcount, 1);
89547 return s;
89548 }
89549
89550@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89551 EXPORT_SYMBOL(kmalloc_dma_caches);
89552 #endif
89553
89554+#ifdef CONFIG_PAX_USERCOPY_SLABS
89555+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89556+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89557+#endif
89558+
89559 /*
89560 * Conversion table for small slabs sizes / 8 to the index in the
89561 * kmalloc array. This is necessary for slabs < 192 since we have non power
89562@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89563 return kmalloc_dma_caches[index];
89564
89565 #endif
89566+
89567+#ifdef CONFIG_PAX_USERCOPY_SLABS
89568+ if (unlikely((flags & GFP_USERCOPY)))
89569+ return kmalloc_usercopy_caches[index];
89570+
89571+#endif
89572+
89573 return kmalloc_caches[index];
89574 }
89575
89576@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89577 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89578 if (!kmalloc_caches[i]) {
89579 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89580- 1 << i, flags);
89581+ 1 << i, SLAB_USERCOPY | flags);
89582 }
89583
89584 /*
89585@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89586 * earlier power of two caches
89587 */
89588 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89589- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89590+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89591
89592 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89593- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89594+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89595 }
89596
89597 /* Kmalloc array is now usable */
89598@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89599 }
89600 }
89601 #endif
89602+
89603+#ifdef CONFIG_PAX_USERCOPY_SLABS
89604+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89605+ struct kmem_cache *s = kmalloc_caches[i];
89606+
89607+ if (s) {
89608+ int size = kmalloc_size(i);
89609+ char *n = kasprintf(GFP_NOWAIT,
89610+ "usercopy-kmalloc-%d", size);
89611+
89612+ BUG_ON(!n);
89613+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89614+ size, SLAB_USERCOPY | flags);
89615+ }
89616+ }
89617+#endif
89618+
89619 }
89620 #endif /* !CONFIG_SLOB */
89621
89622@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89623 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89624 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89625 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89626+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89627+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89628+#endif
89629 #endif
89630 seq_putc(m, '\n');
89631 }
89632diff --git a/mm/slob.c b/mm/slob.c
89633index 91bd3f2..e2f549e 100644
89634--- a/mm/slob.c
89635+++ b/mm/slob.c
89636@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89637 /*
89638 * Return the size of a slob block.
89639 */
89640-static slobidx_t slob_units(slob_t *s)
89641+static slobidx_t slob_units(const slob_t *s)
89642 {
89643 if (s->units > 0)
89644 return s->units;
89645@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89646 /*
89647 * Return the next free slob block pointer after this one.
89648 */
89649-static slob_t *slob_next(slob_t *s)
89650+static slob_t *slob_next(const slob_t *s)
89651 {
89652 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89653 slobidx_t next;
89654@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89655 /*
89656 * Returns true if s is the last free block in its page.
89657 */
89658-static int slob_last(slob_t *s)
89659+static int slob_last(const slob_t *s)
89660 {
89661 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89662 }
89663
89664-static void *slob_new_pages(gfp_t gfp, int order, int node)
89665+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89666 {
89667- void *page;
89668+ struct page *page;
89669
89670 #ifdef CONFIG_NUMA
89671 if (node != NUMA_NO_NODE)
89672@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89673 if (!page)
89674 return NULL;
89675
89676- return page_address(page);
89677+ __SetPageSlab(page);
89678+ return page;
89679 }
89680
89681-static void slob_free_pages(void *b, int order)
89682+static void slob_free_pages(struct page *sp, int order)
89683 {
89684 if (current->reclaim_state)
89685 current->reclaim_state->reclaimed_slab += 1 << order;
89686- free_pages((unsigned long)b, order);
89687+ __ClearPageSlab(sp);
89688+ page_mapcount_reset(sp);
89689+ sp->private = 0;
89690+ __free_pages(sp, order);
89691 }
89692
89693 /*
89694@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89695
89696 /* Not enough space: must allocate a new page */
89697 if (!b) {
89698- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89699- if (!b)
89700+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89701+ if (!sp)
89702 return NULL;
89703- sp = virt_to_page(b);
89704- __SetPageSlab(sp);
89705+ b = page_address(sp);
89706
89707 spin_lock_irqsave(&slob_lock, flags);
89708 sp->units = SLOB_UNITS(PAGE_SIZE);
89709 sp->freelist = b;
89710+ sp->private = 0;
89711 INIT_LIST_HEAD(&sp->list);
89712 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89713 set_slob_page_free(sp, slob_list);
89714@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89715 if (slob_page_free(sp))
89716 clear_slob_page_free(sp);
89717 spin_unlock_irqrestore(&slob_lock, flags);
89718- __ClearPageSlab(sp);
89719- page_mapcount_reset(sp);
89720- slob_free_pages(b, 0);
89721+ slob_free_pages(sp, 0);
89722 return;
89723 }
89724
89725+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89726+ if (pax_sanitize_slab)
89727+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89728+#endif
89729+
89730 if (!slob_page_free(sp)) {
89731 /* This slob page is about to become partially free. Easy! */
89732 sp->units = units;
89733@@ -424,11 +431,10 @@ out:
89734 */
89735
89736 static __always_inline void *
89737-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89738+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89739 {
89740- unsigned int *m;
89741- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89742- void *ret;
89743+ slob_t *m;
89744+ void *ret = NULL;
89745
89746 gfp &= gfp_allowed_mask;
89747
89748@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89749
89750 if (!m)
89751 return NULL;
89752- *m = size;
89753+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89754+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89755+ m[0].units = size;
89756+ m[1].units = align;
89757 ret = (void *)m + align;
89758
89759 trace_kmalloc_node(caller, ret,
89760 size, size + align, gfp, node);
89761 } else {
89762 unsigned int order = get_order(size);
89763+ struct page *page;
89764
89765 if (likely(order))
89766 gfp |= __GFP_COMP;
89767- ret = slob_new_pages(gfp, order, node);
89768+ page = slob_new_pages(gfp, order, node);
89769+ if (page) {
89770+ ret = page_address(page);
89771+ page->private = size;
89772+ }
89773
89774 trace_kmalloc_node(caller, ret,
89775 size, PAGE_SIZE << order, gfp, node);
89776 }
89777
89778- kmemleak_alloc(ret, size, 1, gfp);
89779+ return ret;
89780+}
89781+
89782+static __always_inline void *
89783+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89784+{
89785+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89786+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89787+
89788+ if (!ZERO_OR_NULL_PTR(ret))
89789+ kmemleak_alloc(ret, size, 1, gfp);
89790 return ret;
89791 }
89792
89793@@ -493,34 +517,112 @@ void kfree(const void *block)
89794 return;
89795 kmemleak_free(block);
89796
89797+ VM_BUG_ON(!virt_addr_valid(block));
89798 sp = virt_to_page(block);
89799- if (PageSlab(sp)) {
89800+ VM_BUG_ON(!PageSlab(sp));
89801+ if (!sp->private) {
89802 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89803- unsigned int *m = (unsigned int *)(block - align);
89804- slob_free(m, *m + align);
89805- } else
89806+ slob_t *m = (slob_t *)(block - align);
89807+ slob_free(m, m[0].units + align);
89808+ } else {
89809+ __ClearPageSlab(sp);
89810+ page_mapcount_reset(sp);
89811+ sp->private = 0;
89812 __free_pages(sp, compound_order(sp));
89813+ }
89814 }
89815 EXPORT_SYMBOL(kfree);
89816
89817+bool is_usercopy_object(const void *ptr)
89818+{
89819+ if (!slab_is_available())
89820+ return false;
89821+
89822+ // PAX: TODO
89823+
89824+ return false;
89825+}
89826+
89827+#ifdef CONFIG_PAX_USERCOPY
89828+const char *check_heap_object(const void *ptr, unsigned long n)
89829+{
89830+ struct page *page;
89831+ const slob_t *free;
89832+ const void *base;
89833+ unsigned long flags;
89834+
89835+ if (ZERO_OR_NULL_PTR(ptr))
89836+ return "<null>";
89837+
89838+ if (!virt_addr_valid(ptr))
89839+ return NULL;
89840+
89841+ page = virt_to_head_page(ptr);
89842+ if (!PageSlab(page))
89843+ return NULL;
89844+
89845+ if (page->private) {
89846+ base = page;
89847+ if (base <= ptr && n <= page->private - (ptr - base))
89848+ return NULL;
89849+ return "<slob>";
89850+ }
89851+
89852+ /* some tricky double walking to find the chunk */
89853+ spin_lock_irqsave(&slob_lock, flags);
89854+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89855+ free = page->freelist;
89856+
89857+ while (!slob_last(free) && (void *)free <= ptr) {
89858+ base = free + slob_units(free);
89859+ free = slob_next(free);
89860+ }
89861+
89862+ while (base < (void *)free) {
89863+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89864+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89865+ int offset;
89866+
89867+ if (ptr < base + align)
89868+ break;
89869+
89870+ offset = ptr - base - align;
89871+ if (offset >= m) {
89872+ base += size;
89873+ continue;
89874+ }
89875+
89876+ if (n > m - offset)
89877+ break;
89878+
89879+ spin_unlock_irqrestore(&slob_lock, flags);
89880+ return NULL;
89881+ }
89882+
89883+ spin_unlock_irqrestore(&slob_lock, flags);
89884+ return "<slob>";
89885+}
89886+#endif
89887+
89888 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89889 size_t ksize(const void *block)
89890 {
89891 struct page *sp;
89892 int align;
89893- unsigned int *m;
89894+ slob_t *m;
89895
89896 BUG_ON(!block);
89897 if (unlikely(block == ZERO_SIZE_PTR))
89898 return 0;
89899
89900 sp = virt_to_page(block);
89901- if (unlikely(!PageSlab(sp)))
89902- return PAGE_SIZE << compound_order(sp);
89903+ VM_BUG_ON(!PageSlab(sp));
89904+ if (sp->private)
89905+ return sp->private;
89906
89907 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89908- m = (unsigned int *)(block - align);
89909- return SLOB_UNITS(*m) * SLOB_UNIT;
89910+ m = (slob_t *)(block - align);
89911+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89912 }
89913 EXPORT_SYMBOL(ksize);
89914
89915@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89916
89917 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89918 {
89919- void *b;
89920+ void *b = NULL;
89921
89922 flags &= gfp_allowed_mask;
89923
89924 lockdep_trace_alloc(flags);
89925
89926+#ifdef CONFIG_PAX_USERCOPY_SLABS
89927+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89928+#else
89929 if (c->size < PAGE_SIZE) {
89930 b = slob_alloc(c->size, flags, c->align, node);
89931 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89932 SLOB_UNITS(c->size) * SLOB_UNIT,
89933 flags, node);
89934 } else {
89935- b = slob_new_pages(flags, get_order(c->size), node);
89936+ struct page *sp;
89937+
89938+ sp = slob_new_pages(flags, get_order(c->size), node);
89939+ if (sp) {
89940+ b = page_address(sp);
89941+ sp->private = c->size;
89942+ }
89943 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89944 PAGE_SIZE << get_order(c->size),
89945 flags, node);
89946 }
89947+#endif
89948
89949 if (b && c->ctor)
89950 c->ctor(b);
89951@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89952
89953 static void __kmem_cache_free(void *b, int size)
89954 {
89955- if (size < PAGE_SIZE)
89956+ struct page *sp;
89957+
89958+ sp = virt_to_page(b);
89959+ BUG_ON(!PageSlab(sp));
89960+ if (!sp->private)
89961 slob_free(b, size);
89962 else
89963- slob_free_pages(b, get_order(size));
89964+ slob_free_pages(sp, get_order(size));
89965 }
89966
89967 static void kmem_rcu_free(struct rcu_head *head)
89968@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89969
89970 void kmem_cache_free(struct kmem_cache *c, void *b)
89971 {
89972+ int size = c->size;
89973+
89974+#ifdef CONFIG_PAX_USERCOPY_SLABS
89975+ if (size + c->align < PAGE_SIZE) {
89976+ size += c->align;
89977+ b -= c->align;
89978+ }
89979+#endif
89980+
89981 kmemleak_free_recursive(b, c->flags);
89982 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89983 struct slob_rcu *slob_rcu;
89984- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89985- slob_rcu->size = c->size;
89986+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89987+ slob_rcu->size = size;
89988 call_rcu(&slob_rcu->head, kmem_rcu_free);
89989 } else {
89990- __kmem_cache_free(b, c->size);
89991+ __kmem_cache_free(b, size);
89992 }
89993
89994+#ifdef CONFIG_PAX_USERCOPY_SLABS
89995+ trace_kfree(_RET_IP_, b);
89996+#else
89997 trace_kmem_cache_free(_RET_IP_, b);
89998+#endif
89999+
90000 }
90001 EXPORT_SYMBOL(kmem_cache_free);
90002
90003diff --git a/mm/slub.c b/mm/slub.c
90004index e3ba1f2..bd45dac 100644
90005--- a/mm/slub.c
90006+++ b/mm/slub.c
90007@@ -207,7 +207,7 @@ struct track {
90008
90009 enum track_item { TRACK_ALLOC, TRACK_FREE };
90010
90011-#ifdef CONFIG_SYSFS
90012+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90013 static int sysfs_slab_add(struct kmem_cache *);
90014 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90015 static void sysfs_slab_remove(struct kmem_cache *);
90016@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90017 if (!t->addr)
90018 return;
90019
90020- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90021+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90022 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90023 #ifdef CONFIG_STACKTRACE
90024 {
90025@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90026
90027 slab_free_hook(s, x);
90028
90029+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90030+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90031+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90032+ if (s->ctor)
90033+ s->ctor(x);
90034+ }
90035+#endif
90036+
90037 redo:
90038 /*
90039 * Determine the currently cpus per cpu slab.
90040@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90041 * Merge control. If this is set then no merging of slab caches will occur.
90042 * (Could be removed. This was introduced to pacify the merge skeptics.)
90043 */
90044-static int slub_nomerge;
90045+static int slub_nomerge = 1;
90046
90047 /*
90048 * Calculate the order of allocation given an slab object size.
90049@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90050 s->inuse = size;
90051
90052 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90053+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90054+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90055+#endif
90056 s->ctor)) {
90057 /*
90058 * Relocate free pointer after the object if it is not
90059@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90060 EXPORT_SYMBOL(__kmalloc_node);
90061 #endif
90062
90063+bool is_usercopy_object(const void *ptr)
90064+{
90065+ struct page *page;
90066+ struct kmem_cache *s;
90067+
90068+ if (ZERO_OR_NULL_PTR(ptr))
90069+ return false;
90070+
90071+ if (!slab_is_available())
90072+ return false;
90073+
90074+ if (!virt_addr_valid(ptr))
90075+ return false;
90076+
90077+ page = virt_to_head_page(ptr);
90078+
90079+ if (!PageSlab(page))
90080+ return false;
90081+
90082+ s = page->slab_cache;
90083+ return s->flags & SLAB_USERCOPY;
90084+}
90085+
90086+#ifdef CONFIG_PAX_USERCOPY
90087+const char *check_heap_object(const void *ptr, unsigned long n)
90088+{
90089+ struct page *page;
90090+ struct kmem_cache *s;
90091+ unsigned long offset;
90092+
90093+ if (ZERO_OR_NULL_PTR(ptr))
90094+ return "<null>";
90095+
90096+ if (!virt_addr_valid(ptr))
90097+ return NULL;
90098+
90099+ page = virt_to_head_page(ptr);
90100+
90101+ if (!PageSlab(page))
90102+ return NULL;
90103+
90104+ s = page->slab_cache;
90105+ if (!(s->flags & SLAB_USERCOPY))
90106+ return s->name;
90107+
90108+ offset = (ptr - page_address(page)) % s->size;
90109+ if (offset <= s->object_size && n <= s->object_size - offset)
90110+ return NULL;
90111+
90112+ return s->name;
90113+}
90114+#endif
90115+
90116 size_t ksize(const void *object)
90117 {
90118 struct page *page;
90119@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90120 if (unlikely(ZERO_OR_NULL_PTR(x)))
90121 return;
90122
90123+ VM_BUG_ON(!virt_addr_valid(x));
90124 page = virt_to_head_page(x);
90125 if (unlikely(!PageSlab(page))) {
90126 BUG_ON(!PageCompound(page));
90127@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90128 /*
90129 * We may have set a slab to be unmergeable during bootstrap.
90130 */
90131- if (s->refcount < 0)
90132+ if (atomic_read(&s->refcount) < 0)
90133 return 1;
90134
90135 return 0;
90136@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90137
90138 s = find_mergeable(memcg, size, align, flags, name, ctor);
90139 if (s) {
90140- s->refcount++;
90141+ atomic_inc(&s->refcount);
90142 /*
90143 * Adjust the object sizes so that we clear
90144 * the complete object on kzalloc.
90145@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90146 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90147
90148 if (sysfs_slab_alias(s, name)) {
90149- s->refcount--;
90150+ atomic_dec(&s->refcount);
90151 s = NULL;
90152 }
90153 }
90154@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90155 }
90156 #endif
90157
90158-#ifdef CONFIG_SYSFS
90159+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90160 static int count_inuse(struct page *page)
90161 {
90162 return page->inuse;
90163@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90164 validate_slab_cache(kmalloc_caches[9]);
90165 }
90166 #else
90167-#ifdef CONFIG_SYSFS
90168+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90169 static void resiliency_test(void) {};
90170 #endif
90171 #endif
90172
90173-#ifdef CONFIG_SYSFS
90174+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90175 enum slab_stat_type {
90176 SL_ALL, /* All slabs */
90177 SL_PARTIAL, /* Only partially allocated slabs */
90178@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90179
90180 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90181 {
90182- return sprintf(buf, "%d\n", s->refcount - 1);
90183+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90184 }
90185 SLAB_ATTR_RO(aliases);
90186
90187@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90188 SLAB_ATTR_RO(cache_dma);
90189 #endif
90190
90191+#ifdef CONFIG_PAX_USERCOPY_SLABS
90192+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90193+{
90194+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90195+}
90196+SLAB_ATTR_RO(usercopy);
90197+#endif
90198+
90199 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90200 {
90201 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90202@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90203 #ifdef CONFIG_ZONE_DMA
90204 &cache_dma_attr.attr,
90205 #endif
90206+#ifdef CONFIG_PAX_USERCOPY_SLABS
90207+ &usercopy_attr.attr,
90208+#endif
90209 #ifdef CONFIG_NUMA
90210 &remote_node_defrag_ratio_attr.attr,
90211 #endif
90212@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90213 return name;
90214 }
90215
90216+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90217 static int sysfs_slab_add(struct kmem_cache *s)
90218 {
90219 int err;
90220@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90221 }
90222
90223 s->kobj.kset = slab_kset;
90224- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90225+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90226 if (err) {
90227 kobject_put(&s->kobj);
90228 return err;
90229@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90230 kobject_del(&s->kobj);
90231 kobject_put(&s->kobj);
90232 }
90233+#endif
90234
90235 /*
90236 * Need to buffer aliases during bootup until sysfs becomes
90237@@ -5213,6 +5291,7 @@ struct saved_alias {
90238
90239 static struct saved_alias *alias_list;
90240
90241+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90242 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90243 {
90244 struct saved_alias *al;
90245@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90246 alias_list = al;
90247 return 0;
90248 }
90249+#endif
90250
90251 static int __init slab_sysfs_init(void)
90252 {
90253diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90254index 27eeab3..7c3f7f2 100644
90255--- a/mm/sparse-vmemmap.c
90256+++ b/mm/sparse-vmemmap.c
90257@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90258 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90259 if (!p)
90260 return NULL;
90261- pud_populate(&init_mm, pud, p);
90262+ pud_populate_kernel(&init_mm, pud, p);
90263 }
90264 return pud;
90265 }
90266@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90267 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90268 if (!p)
90269 return NULL;
90270- pgd_populate(&init_mm, pgd, p);
90271+ pgd_populate_kernel(&init_mm, pgd, p);
90272 }
90273 return pgd;
90274 }
90275diff --git a/mm/sparse.c b/mm/sparse.c
90276index 308d503..3dbbd04 100644
90277--- a/mm/sparse.c
90278+++ b/mm/sparse.c
90279@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90280
90281 for (i = 0; i < PAGES_PER_SECTION; i++) {
90282 if (PageHWPoison(&memmap[i])) {
90283- atomic_long_sub(1, &num_poisoned_pages);
90284+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90285 ClearPageHWPoison(&memmap[i]);
90286 }
90287 }
90288diff --git a/mm/swap.c b/mm/swap.c
90289index c899502..d4dc2cd 100644
90290--- a/mm/swap.c
90291+++ b/mm/swap.c
90292@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90293
90294 __page_cache_release(page);
90295 dtor = get_compound_page_dtor(page);
90296+ if (!PageHuge(page))
90297+ BUG_ON(dtor != free_compound_page);
90298 (*dtor)(page);
90299 }
90300
90301diff --git a/mm/swapfile.c b/mm/swapfile.c
90302index 6cf2e60..d204b3e 100644
90303--- a/mm/swapfile.c
90304+++ b/mm/swapfile.c
90305@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90306
90307 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90308 /* Activity counter to indicate that a swapon or swapoff has occurred */
90309-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90310+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90311
90312 static inline unsigned char swap_count(unsigned char ent)
90313 {
90314@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90315 }
90316 filp_close(swap_file, NULL);
90317 err = 0;
90318- atomic_inc(&proc_poll_event);
90319+ atomic_inc_unchecked(&proc_poll_event);
90320 wake_up_interruptible(&proc_poll_wait);
90321
90322 out_dput:
90323@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90324
90325 poll_wait(file, &proc_poll_wait, wait);
90326
90327- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90328- seq->poll_event = atomic_read(&proc_poll_event);
90329+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90330+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90331 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90332 }
90333
90334@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90335 return ret;
90336
90337 seq = file->private_data;
90338- seq->poll_event = atomic_read(&proc_poll_event);
90339+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90340 return 0;
90341 }
90342
90343@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90344 (frontswap_map) ? "FS" : "");
90345
90346 mutex_unlock(&swapon_mutex);
90347- atomic_inc(&proc_poll_event);
90348+ atomic_inc_unchecked(&proc_poll_event);
90349 wake_up_interruptible(&proc_poll_wait);
90350
90351 if (S_ISREG(inode->i_mode))
90352diff --git a/mm/util.c b/mm/util.c
90353index 7441c41..c3de793 100644
90354--- a/mm/util.c
90355+++ b/mm/util.c
90356@@ -294,6 +294,12 @@ done:
90357 void arch_pick_mmap_layout(struct mm_struct *mm)
90358 {
90359 mm->mmap_base = TASK_UNMAPPED_BASE;
90360+
90361+#ifdef CONFIG_PAX_RANDMMAP
90362+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90363+ mm->mmap_base += mm->delta_mmap;
90364+#endif
90365+
90366 mm->get_unmapped_area = arch_get_unmapped_area;
90367 }
90368 #endif
90369diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90370index 13a5495..6707d97 100644
90371--- a/mm/vmalloc.c
90372+++ b/mm/vmalloc.c
90373@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90374
90375 pte = pte_offset_kernel(pmd, addr);
90376 do {
90377- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90378- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90379+
90380+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90381+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90382+ BUG_ON(!pte_exec(*pte));
90383+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90384+ continue;
90385+ }
90386+#endif
90387+
90388+ {
90389+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90390+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90391+ }
90392 } while (pte++, addr += PAGE_SIZE, addr != end);
90393 }
90394
90395@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90396 pte = pte_alloc_kernel(pmd, addr);
90397 if (!pte)
90398 return -ENOMEM;
90399+
90400+ pax_open_kernel();
90401 do {
90402 struct page *page = pages[*nr];
90403
90404- if (WARN_ON(!pte_none(*pte)))
90405+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90406+ if (pgprot_val(prot) & _PAGE_NX)
90407+#endif
90408+
90409+ if (!pte_none(*pte)) {
90410+ pax_close_kernel();
90411+ WARN_ON(1);
90412 return -EBUSY;
90413- if (WARN_ON(!page))
90414+ }
90415+ if (!page) {
90416+ pax_close_kernel();
90417+ WARN_ON(1);
90418 return -ENOMEM;
90419+ }
90420 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90421 (*nr)++;
90422 } while (pte++, addr += PAGE_SIZE, addr != end);
90423+ pax_close_kernel();
90424 return 0;
90425 }
90426
90427@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90428 pmd_t *pmd;
90429 unsigned long next;
90430
90431- pmd = pmd_alloc(&init_mm, pud, addr);
90432+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90433 if (!pmd)
90434 return -ENOMEM;
90435 do {
90436@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90437 pud_t *pud;
90438 unsigned long next;
90439
90440- pud = pud_alloc(&init_mm, pgd, addr);
90441+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90442 if (!pud)
90443 return -ENOMEM;
90444 do {
90445@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90446 if (addr >= MODULES_VADDR && addr < MODULES_END)
90447 return 1;
90448 #endif
90449+
90450+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90451+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90452+ return 1;
90453+#endif
90454+
90455 return is_vmalloc_addr(x);
90456 }
90457
90458@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90459
90460 if (!pgd_none(*pgd)) {
90461 pud_t *pud = pud_offset(pgd, addr);
90462+#ifdef CONFIG_X86
90463+ if (!pud_large(*pud))
90464+#endif
90465 if (!pud_none(*pud)) {
90466 pmd_t *pmd = pmd_offset(pud, addr);
90467+#ifdef CONFIG_X86
90468+ if (!pmd_large(*pmd))
90469+#endif
90470 if (!pmd_none(*pmd)) {
90471 pte_t *ptep, pte;
90472
90473@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90474 * Allocate a region of KVA of the specified size and alignment, within the
90475 * vstart and vend.
90476 */
90477-static struct vmap_area *alloc_vmap_area(unsigned long size,
90478+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90479 unsigned long align,
90480 unsigned long vstart, unsigned long vend,
90481 int node, gfp_t gfp_mask)
90482@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90483 struct vm_struct *area;
90484
90485 BUG_ON(in_interrupt());
90486+
90487+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90488+ if (flags & VM_KERNEXEC) {
90489+ if (start != VMALLOC_START || end != VMALLOC_END)
90490+ return NULL;
90491+ start = (unsigned long)MODULES_EXEC_VADDR;
90492+ end = (unsigned long)MODULES_EXEC_END;
90493+ }
90494+#endif
90495+
90496 if (flags & VM_IOREMAP)
90497 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90498
90499@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90500 if (count > totalram_pages)
90501 return NULL;
90502
90503+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90504+ if (!(pgprot_val(prot) & _PAGE_NX))
90505+ flags |= VM_KERNEXEC;
90506+#endif
90507+
90508 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90509 __builtin_return_address(0));
90510 if (!area)
90511@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90512 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90513 goto fail;
90514
90515+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90516+ if (!(pgprot_val(prot) & _PAGE_NX))
90517+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90518+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90519+ else
90520+#endif
90521+
90522 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90523 start, end, node, gfp_mask, caller);
90524 if (!area)
90525@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90526 * For tight control over page level allocator and protection flags
90527 * use __vmalloc() instead.
90528 */
90529-
90530 void *vmalloc_exec(unsigned long size)
90531 {
90532- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90533+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90534 NUMA_NO_NODE, __builtin_return_address(0));
90535 }
90536
90537@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90538 {
90539 struct vm_struct *area;
90540
90541+ BUG_ON(vma->vm_mirror);
90542+
90543 size = PAGE_ALIGN(size);
90544
90545 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90546@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90547 v->addr, v->addr + v->size, v->size);
90548
90549 if (v->caller)
90550+#ifdef CONFIG_GRKERNSEC_HIDESYM
90551+ seq_printf(m, " %pK", v->caller);
90552+#else
90553 seq_printf(m, " %pS", v->caller);
90554+#endif
90555
90556 if (v->nr_pages)
90557 seq_printf(m, " pages=%d", v->nr_pages);
90558diff --git a/mm/vmstat.c b/mm/vmstat.c
90559index 20c2ef4..15e7ab7 100644
90560--- a/mm/vmstat.c
90561+++ b/mm/vmstat.c
90562@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90563 *
90564 * vm_stat contains the global counters
90565 */
90566-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90567+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90568 EXPORT_SYMBOL(vm_stat);
90569
90570 #ifdef CONFIG_SMP
90571@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90572 v = p->vm_stat_diff[i];
90573 p->vm_stat_diff[i] = 0;
90574 local_irq_restore(flags);
90575- atomic_long_add(v, &zone->vm_stat[i]);
90576+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90577 global_diff[i] += v;
90578 #ifdef CONFIG_NUMA
90579 /* 3 seconds idle till flush */
90580@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90581
90582 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90583 if (global_diff[i])
90584- atomic_long_add(global_diff[i], &vm_stat[i]);
90585+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90586 }
90587
90588 /*
90589@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90590 if (pset->vm_stat_diff[i]) {
90591 int v = pset->vm_stat_diff[i];
90592 pset->vm_stat_diff[i] = 0;
90593- atomic_long_add(v, &zone->vm_stat[i]);
90594- atomic_long_add(v, &vm_stat[i]);
90595+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90596+ atomic_long_add_unchecked(v, &vm_stat[i]);
90597 }
90598 }
90599 #endif
90600@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90601 start_cpu_timer(cpu);
90602 #endif
90603 #ifdef CONFIG_PROC_FS
90604- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90605- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90606- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90607- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90608+ {
90609+ mode_t gr_mode = S_IRUGO;
90610+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90611+ gr_mode = S_IRUSR;
90612+#endif
90613+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90614+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90615+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90616+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90617+#else
90618+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90619+#endif
90620+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90621+ }
90622 #endif
90623 return 0;
90624 }
90625diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90626index 2fb2d88..8c06e40 100644
90627--- a/net/8021q/vlan.c
90628+++ b/net/8021q/vlan.c
90629@@ -469,7 +469,7 @@ out:
90630 return NOTIFY_DONE;
90631 }
90632
90633-static struct notifier_block vlan_notifier_block __read_mostly = {
90634+static struct notifier_block vlan_notifier_block = {
90635 .notifier_call = vlan_device_event,
90636 };
90637
90638@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90639 err = -EPERM;
90640 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90641 break;
90642- if ((args.u.name_type >= 0) &&
90643- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90644+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90645 struct vlan_net *vn;
90646
90647 vn = net_generic(net, vlan_net_id);
90648diff --git a/net/9p/mod.c b/net/9p/mod.c
90649index 6ab36ae..6f1841b 100644
90650--- a/net/9p/mod.c
90651+++ b/net/9p/mod.c
90652@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90653 void v9fs_register_trans(struct p9_trans_module *m)
90654 {
90655 spin_lock(&v9fs_trans_lock);
90656- list_add_tail(&m->list, &v9fs_trans_list);
90657+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90658 spin_unlock(&v9fs_trans_lock);
90659 }
90660 EXPORT_SYMBOL(v9fs_register_trans);
90661@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90662 void v9fs_unregister_trans(struct p9_trans_module *m)
90663 {
90664 spin_lock(&v9fs_trans_lock);
90665- list_del_init(&m->list);
90666+ pax_list_del_init((struct list_head *)&m->list);
90667 spin_unlock(&v9fs_trans_lock);
90668 }
90669 EXPORT_SYMBOL(v9fs_unregister_trans);
90670diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90671index 3ffda1b..fceac96 100644
90672--- a/net/9p/trans_fd.c
90673+++ b/net/9p/trans_fd.c
90674@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90675 oldfs = get_fs();
90676 set_fs(get_ds());
90677 /* The cast to a user pointer is valid due to the set_fs() */
90678- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90679+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90680 set_fs(oldfs);
90681
90682 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90683diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90684index 876fbe8..8bbea9f 100644
90685--- a/net/atm/atm_misc.c
90686+++ b/net/atm/atm_misc.c
90687@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90688 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90689 return 1;
90690 atm_return(vcc, truesize);
90691- atomic_inc(&vcc->stats->rx_drop);
90692+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90693 return 0;
90694 }
90695 EXPORT_SYMBOL(atm_charge);
90696@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90697 }
90698 }
90699 atm_return(vcc, guess);
90700- atomic_inc(&vcc->stats->rx_drop);
90701+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90702 return NULL;
90703 }
90704 EXPORT_SYMBOL(atm_alloc_charge);
90705@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90706
90707 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90708 {
90709-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90710+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90711 __SONET_ITEMS
90712 #undef __HANDLE_ITEM
90713 }
90714@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90715
90716 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90717 {
90718-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90719+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90720 __SONET_ITEMS
90721 #undef __HANDLE_ITEM
90722 }
90723diff --git a/net/atm/lec.h b/net/atm/lec.h
90724index 4149db1..f2ab682 100644
90725--- a/net/atm/lec.h
90726+++ b/net/atm/lec.h
90727@@ -48,7 +48,7 @@ struct lane2_ops {
90728 const u8 *tlvs, u32 sizeoftlvs);
90729 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90730 const u8 *tlvs, u32 sizeoftlvs);
90731-};
90732+} __no_const;
90733
90734 /*
90735 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90736diff --git a/net/atm/proc.c b/net/atm/proc.c
90737index bbb6461..cf04016 100644
90738--- a/net/atm/proc.c
90739+++ b/net/atm/proc.c
90740@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90741 const struct k_atm_aal_stats *stats)
90742 {
90743 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90744- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90745- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90746- atomic_read(&stats->rx_drop));
90747+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90748+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90749+ atomic_read_unchecked(&stats->rx_drop));
90750 }
90751
90752 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90753diff --git a/net/atm/resources.c b/net/atm/resources.c
90754index 0447d5d..3cf4728 100644
90755--- a/net/atm/resources.c
90756+++ b/net/atm/resources.c
90757@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90758 static void copy_aal_stats(struct k_atm_aal_stats *from,
90759 struct atm_aal_stats *to)
90760 {
90761-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90762+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90763 __AAL_STAT_ITEMS
90764 #undef __HANDLE_ITEM
90765 }
90766@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90767 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90768 struct atm_aal_stats *to)
90769 {
90770-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90771+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90772 __AAL_STAT_ITEMS
90773 #undef __HANDLE_ITEM
90774 }
90775diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90776index 919a5ce..cc6b444 100644
90777--- a/net/ax25/sysctl_net_ax25.c
90778+++ b/net/ax25/sysctl_net_ax25.c
90779@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90780 {
90781 char path[sizeof("net/ax25/") + IFNAMSIZ];
90782 int k;
90783- struct ctl_table *table;
90784+ ctl_table_no_const *table;
90785
90786 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90787 if (!table)
90788diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90789index 62da527..aa27535 100644
90790--- a/net/batman-adv/bat_iv_ogm.c
90791+++ b/net/batman-adv/bat_iv_ogm.c
90792@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90793
90794 /* randomize initial seqno to avoid collision */
90795 get_random_bytes(&random_seqno, sizeof(random_seqno));
90796- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90797+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90798
90799 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90800 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90801@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90802 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90803
90804 /* change sequence number to network order */
90805- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90806+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90807 batadv_ogm_packet->seqno = htonl(seqno);
90808- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90809+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90810
90811 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90812 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90813@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90814 return;
90815
90816 /* could be changed by schedule_own_packet() */
90817- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90818+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90819
90820 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90821 has_directlink_flag = 1;
90822diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90823index c478e6b..469fd2f 100644
90824--- a/net/batman-adv/hard-interface.c
90825+++ b/net/batman-adv/hard-interface.c
90826@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90827 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90828 dev_add_pack(&hard_iface->batman_adv_ptype);
90829
90830- atomic_set(&hard_iface->frag_seqno, 1);
90831+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90832 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90833 hard_iface->net_dev->name);
90834
90835diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90836index 33b6144..3212ac5 100644
90837--- a/net/batman-adv/soft-interface.c
90838+++ b/net/batman-adv/soft-interface.c
90839@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90840 primary_if->net_dev->dev_addr, ETH_ALEN);
90841
90842 /* set broadcast sequence number */
90843- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90844+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90845 bcast_packet->seqno = htonl(seqno);
90846
90847 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90848@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90849 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90850
90851 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90852- atomic_set(&bat_priv->bcast_seqno, 1);
90853+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90854 atomic_set(&bat_priv->tt.vn, 0);
90855 atomic_set(&bat_priv->tt.local_changes, 0);
90856 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90857diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90858index b2c94e1..3d47e07 100644
90859--- a/net/batman-adv/types.h
90860+++ b/net/batman-adv/types.h
90861@@ -51,7 +51,7 @@
90862 struct batadv_hard_iface_bat_iv {
90863 unsigned char *ogm_buff;
90864 int ogm_buff_len;
90865- atomic_t ogm_seqno;
90866+ atomic_unchecked_t ogm_seqno;
90867 };
90868
90869 /**
90870@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90871 int16_t if_num;
90872 char if_status;
90873 struct net_device *net_dev;
90874- atomic_t frag_seqno;
90875+ atomic_unchecked_t frag_seqno;
90876 uint8_t num_bcasts;
90877 struct kobject *hardif_obj;
90878 atomic_t refcount;
90879@@ -560,7 +560,7 @@ struct batadv_priv {
90880 #ifdef CONFIG_BATMAN_ADV_DEBUG
90881 atomic_t log_level;
90882 #endif
90883- atomic_t bcast_seqno;
90884+ atomic_unchecked_t bcast_seqno;
90885 atomic_t bcast_queue_left;
90886 atomic_t batman_queue_left;
90887 char num_ifaces;
90888diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90889index 857e1b8..5ad07b2 100644
90890--- a/net/batman-adv/unicast.c
90891+++ b/net/batman-adv/unicast.c
90892@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90893 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90894 frag2->flags = large_tail;
90895
90896- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90897+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90898 frag1->seqno = htons(seqno - 1);
90899 frag2->seqno = htons(seqno);
90900
90901diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90902index 9bd7d95..6c4884f 100644
90903--- a/net/bluetooth/hci_sock.c
90904+++ b/net/bluetooth/hci_sock.c
90905@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90906 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90907 }
90908
90909- len = min_t(unsigned int, len, sizeof(uf));
90910+ len = min((size_t)len, sizeof(uf));
90911 if (copy_from_user(&uf, optval, len)) {
90912 err = -EFAULT;
90913 break;
90914diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90915index 8c3499b..2661c6a 100644
90916--- a/net/bluetooth/l2cap_core.c
90917+++ b/net/bluetooth/l2cap_core.c
90918@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90919 break;
90920
90921 case L2CAP_CONF_RFC:
90922- if (olen == sizeof(rfc))
90923- memcpy(&rfc, (void *)val, olen);
90924+ if (olen != sizeof(rfc))
90925+ break;
90926+
90927+ memcpy(&rfc, (void *)val, olen);
90928
90929 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90930 rfc.mode != chan->mode)
90931diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90932index 0098af8..fb5a31f 100644
90933--- a/net/bluetooth/l2cap_sock.c
90934+++ b/net/bluetooth/l2cap_sock.c
90935@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90936 struct sock *sk = sock->sk;
90937 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90938 struct l2cap_options opts;
90939- int len, err = 0;
90940+ int err = 0;
90941+ size_t len = optlen;
90942 u32 opt;
90943
90944 BT_DBG("sk %p", sk);
90945@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90946 opts.max_tx = chan->max_tx;
90947 opts.txwin_size = chan->tx_win;
90948
90949- len = min_t(unsigned int, sizeof(opts), optlen);
90950+ len = min(sizeof(opts), len);
90951 if (copy_from_user((char *) &opts, optval, len)) {
90952 err = -EFAULT;
90953 break;
90954@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90955 struct bt_security sec;
90956 struct bt_power pwr;
90957 struct l2cap_conn *conn;
90958- int len, err = 0;
90959+ int err = 0;
90960+ size_t len = optlen;
90961 u32 opt;
90962
90963 BT_DBG("sk %p", sk);
90964@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90965
90966 sec.level = BT_SECURITY_LOW;
90967
90968- len = min_t(unsigned int, sizeof(sec), optlen);
90969+ len = min(sizeof(sec), len);
90970 if (copy_from_user((char *) &sec, optval, len)) {
90971 err = -EFAULT;
90972 break;
90973@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90974
90975 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90976
90977- len = min_t(unsigned int, sizeof(pwr), optlen);
90978+ len = min(sizeof(pwr), len);
90979 if (copy_from_user((char *) &pwr, optval, len)) {
90980 err = -EFAULT;
90981 break;
90982diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90983index 30b3721..c1bd0a0 100644
90984--- a/net/bluetooth/rfcomm/sock.c
90985+++ b/net/bluetooth/rfcomm/sock.c
90986@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90987 struct sock *sk = sock->sk;
90988 struct bt_security sec;
90989 int err = 0;
90990- size_t len;
90991+ size_t len = optlen;
90992 u32 opt;
90993
90994 BT_DBG("sk %p", sk);
90995@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90996
90997 sec.level = BT_SECURITY_LOW;
90998
90999- len = min_t(unsigned int, sizeof(sec), optlen);
91000+ len = min(sizeof(sec), len);
91001 if (copy_from_user((char *) &sec, optval, len)) {
91002 err = -EFAULT;
91003 break;
91004diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91005index b6e44ad..5b0d514 100644
91006--- a/net/bluetooth/rfcomm/tty.c
91007+++ b/net/bluetooth/rfcomm/tty.c
91008@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91009 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91010
91011 spin_lock_irqsave(&dev->port.lock, flags);
91012- if (dev->port.count > 0) {
91013+ if (atomic_read(&dev->port.count) > 0) {
91014 spin_unlock_irqrestore(&dev->port.lock, flags);
91015 return;
91016 }
91017@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91018 return -ENODEV;
91019
91020 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91021- dev->channel, dev->port.count);
91022+ dev->channel, atomic_read(&dev->port.count));
91023
91024 spin_lock_irqsave(&dev->port.lock, flags);
91025- if (++dev->port.count > 1) {
91026+ if (atomic_inc_return(&dev->port.count) > 1) {
91027 spin_unlock_irqrestore(&dev->port.lock, flags);
91028 return 0;
91029 }
91030@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91031 return;
91032
91033 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91034- dev->port.count);
91035+ atomic_read(&dev->port.count));
91036
91037 spin_lock_irqsave(&dev->port.lock, flags);
91038- if (!--dev->port.count) {
91039+ if (!atomic_dec_return(&dev->port.count)) {
91040 spin_unlock_irqrestore(&dev->port.lock, flags);
91041 if (dev->tty_dev->parent)
91042 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91043diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
91044index 5180938..7c470c3 100644
91045--- a/net/bridge/netfilter/ebt_ulog.c
91046+++ b/net/bridge/netfilter/ebt_ulog.c
91047@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91048 ub->qlen++;
91049
91050 pm = nlmsg_data(nlh);
91051+ memset(pm, 0, sizeof(*pm));
91052
91053 /* Fill in the ulog data */
91054 pm->version = EBT_ULOG_VERSION;
91055@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91056 pm->hook = hooknr;
91057 if (uloginfo->prefix != NULL)
91058 strcpy(pm->prefix, uloginfo->prefix);
91059- else
91060- *(pm->prefix) = '\0';
91061
91062 if (in) {
91063 strcpy(pm->physindev, in->name);
91064@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91065 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
91066 else
91067 strcpy(pm->indev, in->name);
91068- } else
91069- pm->indev[0] = pm->physindev[0] = '\0';
91070+ }
91071
91072 if (out) {
91073 /* If out exists, then out is a bridge port */
91074 strcpy(pm->physoutdev, out->name);
91075 /* rcu_read_lock()ed by nf_hook_slow */
91076 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
91077- } else
91078- pm->outdev[0] = pm->physoutdev[0] = '\0';
91079+ }
91080
91081 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
91082 BUG();
91083diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91084index ac78024..161a80c 100644
91085--- a/net/bridge/netfilter/ebtables.c
91086+++ b/net/bridge/netfilter/ebtables.c
91087@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91088 tmp.valid_hooks = t->table->valid_hooks;
91089 }
91090 mutex_unlock(&ebt_mutex);
91091- if (copy_to_user(user, &tmp, *len) != 0){
91092+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91093 BUGPRINT("c2u Didn't work\n");
91094 ret = -EFAULT;
91095 break;
91096@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91097 goto out;
91098 tmp.valid_hooks = t->valid_hooks;
91099
91100- if (copy_to_user(user, &tmp, *len) != 0) {
91101+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91102 ret = -EFAULT;
91103 break;
91104 }
91105@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91106 tmp.entries_size = t->table->entries_size;
91107 tmp.valid_hooks = t->table->valid_hooks;
91108
91109- if (copy_to_user(user, &tmp, *len) != 0) {
91110+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91111 ret = -EFAULT;
91112 break;
91113 }
91114diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91115index 0f45522..dab651f 100644
91116--- a/net/caif/cfctrl.c
91117+++ b/net/caif/cfctrl.c
91118@@ -10,6 +10,7 @@
91119 #include <linux/spinlock.h>
91120 #include <linux/slab.h>
91121 #include <linux/pkt_sched.h>
91122+#include <linux/sched.h>
91123 #include <net/caif/caif_layer.h>
91124 #include <net/caif/cfpkt.h>
91125 #include <net/caif/cfctrl.h>
91126@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91127 memset(&dev_info, 0, sizeof(dev_info));
91128 dev_info.id = 0xff;
91129 cfsrvl_init(&this->serv, 0, &dev_info, false);
91130- atomic_set(&this->req_seq_no, 1);
91131- atomic_set(&this->rsp_seq_no, 1);
91132+ atomic_set_unchecked(&this->req_seq_no, 1);
91133+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91134 this->serv.layer.receive = cfctrl_recv;
91135 sprintf(this->serv.layer.name, "ctrl");
91136 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91137@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91138 struct cfctrl_request_info *req)
91139 {
91140 spin_lock_bh(&ctrl->info_list_lock);
91141- atomic_inc(&ctrl->req_seq_no);
91142- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91143+ atomic_inc_unchecked(&ctrl->req_seq_no);
91144+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91145 list_add_tail(&req->list, &ctrl->list);
91146 spin_unlock_bh(&ctrl->info_list_lock);
91147 }
91148@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91149 if (p != first)
91150 pr_warn("Requests are not received in order\n");
91151
91152- atomic_set(&ctrl->rsp_seq_no,
91153+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91154 p->sequence_no);
91155 list_del(&p->list);
91156 goto out;
91157diff --git a/net/can/af_can.c b/net/can/af_can.c
91158index 3ab8dd2..b9aef13 100644
91159--- a/net/can/af_can.c
91160+++ b/net/can/af_can.c
91161@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91162 };
91163
91164 /* notifier block for netdevice event */
91165-static struct notifier_block can_netdev_notifier __read_mostly = {
91166+static struct notifier_block can_netdev_notifier = {
91167 .notifier_call = can_notifier,
91168 };
91169
91170diff --git a/net/can/gw.c b/net/can/gw.c
91171index 2f291f9..98c986a 100644
91172--- a/net/can/gw.c
91173+++ b/net/can/gw.c
91174@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91175 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91176
91177 static HLIST_HEAD(cgw_list);
91178-static struct notifier_block notifier;
91179
91180 static struct kmem_cache *cgw_cache __read_mostly;
91181
91182@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91183 return err;
91184 }
91185
91186+static struct notifier_block notifier = {
91187+ .notifier_call = cgw_notifier
91188+};
91189+
91190 static __init int cgw_module_init(void)
91191 {
91192 /* sanitize given module parameter */
91193@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91194 return -ENOMEM;
91195
91196 /* set notifier */
91197- notifier.notifier_call = cgw_notifier;
91198 register_netdevice_notifier(&notifier);
91199
91200 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91201diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91202index eb0a46a..5f3bae8 100644
91203--- a/net/ceph/messenger.c
91204+++ b/net/ceph/messenger.c
91205@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91206 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91207
91208 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91209-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91210+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91211
91212 static struct page *zero_page; /* used in certain error cases */
91213
91214@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91215 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91216 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91217
91218- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91219+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91220 s = addr_str[i];
91221
91222 switch (ss->ss_family) {
91223diff --git a/net/compat.c b/net/compat.c
91224index 8903258..24e30e5 100644
91225--- a/net/compat.c
91226+++ b/net/compat.c
91227@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91228 return -EFAULT;
91229 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
91230 return -EINVAL;
91231- kmsg->msg_name = compat_ptr(tmp1);
91232- kmsg->msg_iov = compat_ptr(tmp2);
91233- kmsg->msg_control = compat_ptr(tmp3);
91234+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91235+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91236+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91237 return 0;
91238 }
91239
91240@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91241
91242 if (kern_msg->msg_namelen) {
91243 if (mode == VERIFY_READ) {
91244- int err = move_addr_to_kernel(kern_msg->msg_name,
91245+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91246 kern_msg->msg_namelen,
91247 kern_address);
91248 if (err < 0)
91249@@ -98,7 +98,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91250 kern_msg->msg_name = NULL;
91251
91252 tot_len = iov_from_user_compat_to_kern(kern_iov,
91253- (struct compat_iovec __user *)kern_msg->msg_iov,
91254+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91255 kern_msg->msg_iovlen);
91256 if (tot_len >= 0)
91257 kern_msg->msg_iov = kern_iov;
91258@@ -118,20 +118,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91259
91260 #define CMSG_COMPAT_FIRSTHDR(msg) \
91261 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91262- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91263+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91264 (struct compat_cmsghdr __user *)NULL)
91265
91266 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91267 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91268 (ucmlen) <= (unsigned long) \
91269 ((mhdr)->msg_controllen - \
91270- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91271+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91272
91273 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91274 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91275 {
91276 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91277- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91278+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91279 msg->msg_controllen)
91280 return NULL;
91281 return (struct compat_cmsghdr __user *)ptr;
91282@@ -221,7 +221,7 @@ Efault:
91283
91284 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91285 {
91286- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91287+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91288 struct compat_cmsghdr cmhdr;
91289 struct compat_timeval ctv;
91290 struct compat_timespec cts[3];
91291@@ -277,7 +277,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91292
91293 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91294 {
91295- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91296+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91297 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91298 int fdnum = scm->fp->count;
91299 struct file **fp = scm->fp->fp;
91300@@ -365,7 +365,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91301 return -EFAULT;
91302 old_fs = get_fs();
91303 set_fs(KERNEL_DS);
91304- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91305+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91306 set_fs(old_fs);
91307
91308 return err;
91309@@ -426,7 +426,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91310 len = sizeof(ktime);
91311 old_fs = get_fs();
91312 set_fs(KERNEL_DS);
91313- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91314+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91315 set_fs(old_fs);
91316
91317 if (!err) {
91318@@ -569,7 +569,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91319 case MCAST_JOIN_GROUP:
91320 case MCAST_LEAVE_GROUP:
91321 {
91322- struct compat_group_req __user *gr32 = (void *)optval;
91323+ struct compat_group_req __user *gr32 = (void __user *)optval;
91324 struct group_req __user *kgr =
91325 compat_alloc_user_space(sizeof(struct group_req));
91326 u32 interface;
91327@@ -590,7 +590,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91328 case MCAST_BLOCK_SOURCE:
91329 case MCAST_UNBLOCK_SOURCE:
91330 {
91331- struct compat_group_source_req __user *gsr32 = (void *)optval;
91332+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91333 struct group_source_req __user *kgsr = compat_alloc_user_space(
91334 sizeof(struct group_source_req));
91335 u32 interface;
91336@@ -611,7 +611,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91337 }
91338 case MCAST_MSFILTER:
91339 {
91340- struct compat_group_filter __user *gf32 = (void *)optval;
91341+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91342 struct group_filter __user *kgf;
91343 u32 interface, fmode, numsrc;
91344
91345@@ -649,7 +649,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91346 char __user *optval, int __user *optlen,
91347 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91348 {
91349- struct compat_group_filter __user *gf32 = (void *)optval;
91350+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91351 struct group_filter __user *kgf;
91352 int __user *koptlen;
91353 u32 interface, fmode, numsrc;
91354@@ -807,7 +807,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91355
91356 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91357 return -EINVAL;
91358- if (copy_from_user(a, args, nas[call]))
91359+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91360 return -EFAULT;
91361 a0 = a[0];
91362 a1 = a[1];
91363diff --git a/net/core/datagram.c b/net/core/datagram.c
91364index 8ab48cd..57b1a80 100644
91365--- a/net/core/datagram.c
91366+++ b/net/core/datagram.c
91367@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91368 }
91369
91370 kfree_skb(skb);
91371- atomic_inc(&sk->sk_drops);
91372+ atomic_inc_unchecked(&sk->sk_drops);
91373 sk_mem_reclaim_partial(sk);
91374
91375 return err;
91376diff --git a/net/core/dev.c b/net/core/dev.c
91377index 26755dd..2a232de 100644
91378--- a/net/core/dev.c
91379+++ b/net/core/dev.c
91380@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91381 {
91382 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91383 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91384- atomic_long_inc(&dev->rx_dropped);
91385+ atomic_long_inc_unchecked(&dev->rx_dropped);
91386 kfree_skb(skb);
91387 return NET_RX_DROP;
91388 }
91389 }
91390
91391 if (unlikely(!is_skb_forwardable(dev, skb))) {
91392- atomic_long_inc(&dev->rx_dropped);
91393+ atomic_long_inc_unchecked(&dev->rx_dropped);
91394 kfree_skb(skb);
91395 return NET_RX_DROP;
91396 }
91397@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91398
91399 struct dev_gso_cb {
91400 void (*destructor)(struct sk_buff *skb);
91401-};
91402+} __no_const;
91403
91404 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91405
91406@@ -3206,7 +3206,7 @@ enqueue:
91407
91408 local_irq_restore(flags);
91409
91410- atomic_long_inc(&skb->dev->rx_dropped);
91411+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91412 kfree_skb(skb);
91413 return NET_RX_DROP;
91414 }
91415@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91416 }
91417 EXPORT_SYMBOL(netif_rx_ni);
91418
91419-static void net_tx_action(struct softirq_action *h)
91420+static __latent_entropy void net_tx_action(void)
91421 {
91422 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91423
91424@@ -3612,7 +3612,7 @@ ncls:
91425 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91426 } else {
91427 drop:
91428- atomic_long_inc(&skb->dev->rx_dropped);
91429+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91430 kfree_skb(skb);
91431 /* Jamal, now you will not able to escape explaining
91432 * me how you were going to use this. :-)
91433@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91434 }
91435 EXPORT_SYMBOL(netif_napi_del);
91436
91437-static void net_rx_action(struct softirq_action *h)
91438+static __latent_entropy void net_rx_action(void)
91439 {
91440 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91441 unsigned long time_limit = jiffies + 2;
91442@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91443 } else {
91444 netdev_stats_to_stats64(storage, &dev->stats);
91445 }
91446- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91447+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91448 return storage;
91449 }
91450 EXPORT_SYMBOL(dev_get_stats);
91451diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91452index 5b7d0e1..cb960fc 100644
91453--- a/net/core/dev_ioctl.c
91454+++ b/net/core/dev_ioctl.c
91455@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91456 if (no_module && capable(CAP_NET_ADMIN))
91457 no_module = request_module("netdev-%s", name);
91458 if (no_module && capable(CAP_SYS_MODULE)) {
91459+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91460+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91461+#else
91462 if (!request_module("%s", name))
91463 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91464 name);
91465+#endif
91466 }
91467 }
91468 EXPORT_SYMBOL(dev_load);
91469diff --git a/net/core/flow.c b/net/core/flow.c
91470index dfa602c..3103d88 100644
91471--- a/net/core/flow.c
91472+++ b/net/core/flow.c
91473@@ -61,7 +61,7 @@ struct flow_cache {
91474 struct timer_list rnd_timer;
91475 };
91476
91477-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91478+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91479 EXPORT_SYMBOL(flow_cache_genid);
91480 static struct flow_cache flow_cache_global;
91481 static struct kmem_cache *flow_cachep __read_mostly;
91482@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91483
91484 static int flow_entry_valid(struct flow_cache_entry *fle)
91485 {
91486- if (atomic_read(&flow_cache_genid) != fle->genid)
91487+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91488 return 0;
91489 if (fle->object && !fle->object->ops->check(fle->object))
91490 return 0;
91491@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91492 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91493 fcp->hash_count++;
91494 }
91495- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91496+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91497 flo = fle->object;
91498 if (!flo)
91499 goto ret_object;
91500@@ -279,7 +279,7 @@ nocache:
91501 }
91502 flo = resolver(net, key, family, dir, flo, ctx);
91503 if (fle) {
91504- fle->genid = atomic_read(&flow_cache_genid);
91505+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91506 if (!IS_ERR(flo))
91507 fle->object = flo;
91508 else
91509diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
91510index 52d0f83..4a1d064 100644
91511--- a/net/core/flow_dissector.c
91512+++ b/net/core/flow_dissector.c
91513@@ -40,7 +40,7 @@ again:
91514 struct iphdr _iph;
91515 ip:
91516 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
91517- if (!iph)
91518+ if (!iph || iph->ihl < 5)
91519 return false;
91520
91521 if (ip_is_fragment(iph))
91522diff --git a/net/core/iovec.c b/net/core/iovec.c
91523index de178e4..1dabd8b 100644
91524--- a/net/core/iovec.c
91525+++ b/net/core/iovec.c
91526@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91527 if (m->msg_namelen) {
91528 if (mode == VERIFY_READ) {
91529 void __user *namep;
91530- namep = (void __user __force *) m->msg_name;
91531+ namep = (void __force_user *) m->msg_name;
91532 err = move_addr_to_kernel(namep, m->msg_namelen,
91533 address);
91534 if (err < 0)
91535@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91536 }
91537
91538 size = m->msg_iovlen * sizeof(struct iovec);
91539- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91540+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91541 return -EFAULT;
91542
91543 m->msg_iov = iov;
91544diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91545index 60533db..14842cc 100644
91546--- a/net/core/neighbour.c
91547+++ b/net/core/neighbour.c
91548@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91549 void __user *buffer, size_t *lenp, loff_t *ppos)
91550 {
91551 int size, ret;
91552- struct ctl_table tmp = *ctl;
91553+ ctl_table_no_const tmp = *ctl;
91554
91555 tmp.extra1 = &zero;
91556 tmp.extra2 = &unres_qlen_max;
91557diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91558index 2bf8329..7960607 100644
91559--- a/net/core/net-procfs.c
91560+++ b/net/core/net-procfs.c
91561@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91562 else
91563 seq_printf(seq, "%04x", ntohs(pt->type));
91564
91565+#ifdef CONFIG_GRKERNSEC_HIDESYM
91566+ seq_printf(seq, " %-8s %pf\n",
91567+ pt->dev ? pt->dev->name : "", NULL);
91568+#else
91569 seq_printf(seq, " %-8s %pf\n",
91570 pt->dev ? pt->dev->name : "", pt->func);
91571+#endif
91572 }
91573
91574 return 0;
91575diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91576index 981fed3..536af34 100644
91577--- a/net/core/net-sysfs.c
91578+++ b/net/core/net-sysfs.c
91579@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91580 }
91581 EXPORT_SYMBOL(netdev_class_remove_file);
91582
91583-int netdev_kobject_init(void)
91584+int __init netdev_kobject_init(void)
91585 {
91586 kobj_ns_type_register(&net_ns_type_operations);
91587 return class_register(&net_class);
91588diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91589index f9765203..9feaef8 100644
91590--- a/net/core/net_namespace.c
91591+++ b/net/core/net_namespace.c
91592@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91593 int error;
91594 LIST_HEAD(net_exit_list);
91595
91596- list_add_tail(&ops->list, list);
91597+ pax_list_add_tail((struct list_head *)&ops->list, list);
91598 if (ops->init || (ops->id && ops->size)) {
91599 for_each_net(net) {
91600 error = ops_init(ops, net);
91601@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91602
91603 out_undo:
91604 /* If I have an error cleanup all namespaces I initialized */
91605- list_del(&ops->list);
91606+ pax_list_del((struct list_head *)&ops->list);
91607 ops_exit_list(ops, &net_exit_list);
91608 ops_free_list(ops, &net_exit_list);
91609 return error;
91610@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91611 struct net *net;
91612 LIST_HEAD(net_exit_list);
91613
91614- list_del(&ops->list);
91615+ pax_list_del((struct list_head *)&ops->list);
91616 for_each_net(net)
91617 list_add_tail(&net->exit_list, &net_exit_list);
91618 ops_exit_list(ops, &net_exit_list);
91619@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91620 mutex_lock(&net_mutex);
91621 error = register_pernet_operations(&pernet_list, ops);
91622 if (!error && (first_device == &pernet_list))
91623- first_device = &ops->list;
91624+ first_device = (struct list_head *)&ops->list;
91625 mutex_unlock(&net_mutex);
91626 return error;
91627 }
91628diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91629index fc75c9e..8c8e9be 100644
91630--- a/net/core/netpoll.c
91631+++ b/net/core/netpoll.c
91632@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91633 struct udphdr *udph;
91634 struct iphdr *iph;
91635 struct ethhdr *eth;
91636- static atomic_t ip_ident;
91637+ static atomic_unchecked_t ip_ident;
91638 struct ipv6hdr *ip6h;
91639
91640 udp_len = len + sizeof(*udph);
91641@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91642 put_unaligned(0x45, (unsigned char *)iph);
91643 iph->tos = 0;
91644 put_unaligned(htons(ip_len), &(iph->tot_len));
91645- iph->id = htons(atomic_inc_return(&ip_ident));
91646+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91647 iph->frag_off = 0;
91648 iph->ttl = 64;
91649 iph->protocol = IPPROTO_UDP;
91650diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91651index ca198c1d1..125372f 100644
91652--- a/net/core/rtnetlink.c
91653+++ b/net/core/rtnetlink.c
91654@@ -58,7 +58,7 @@ struct rtnl_link {
91655 rtnl_doit_func doit;
91656 rtnl_dumpit_func dumpit;
91657 rtnl_calcit_func calcit;
91658-};
91659+} __no_const;
91660
91661 static DEFINE_MUTEX(rtnl_mutex);
91662
91663@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91664 if (rtnl_link_ops_get(ops->kind))
91665 return -EEXIST;
91666
91667- if (!ops->dellink)
91668- ops->dellink = unregister_netdevice_queue;
91669+ if (!ops->dellink) {
91670+ pax_open_kernel();
91671+ *(void **)&ops->dellink = unregister_netdevice_queue;
91672+ pax_close_kernel();
91673+ }
91674
91675- list_add_tail(&ops->list, &link_ops);
91676+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91677 return 0;
91678 }
91679 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91680@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91681 for_each_net(net) {
91682 __rtnl_kill_links(net, ops);
91683 }
91684- list_del(&ops->list);
91685+ pax_list_del((struct list_head *)&ops->list);
91686 }
91687 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91688
91689diff --git a/net/core/scm.c b/net/core/scm.c
91690index b4da80b..98d6bdb 100644
91691--- a/net/core/scm.c
91692+++ b/net/core/scm.c
91693@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91694 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91695 {
91696 struct cmsghdr __user *cm
91697- = (__force struct cmsghdr __user *)msg->msg_control;
91698+ = (struct cmsghdr __force_user *)msg->msg_control;
91699 struct cmsghdr cmhdr;
91700 int cmlen = CMSG_LEN(len);
91701 int err;
91702@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91703 err = -EFAULT;
91704 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91705 goto out;
91706- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91707+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91708 goto out;
91709 cmlen = CMSG_SPACE(len);
91710 if (msg->msg_controllen < cmlen)
91711@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91712 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91713 {
91714 struct cmsghdr __user *cm
91715- = (__force struct cmsghdr __user*)msg->msg_control;
91716+ = (struct cmsghdr __force_user *)msg->msg_control;
91717
91718 int fdmax = 0;
91719 int fdnum = scm->fp->count;
91720@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91721 if (fdnum < fdmax)
91722 fdmax = fdnum;
91723
91724- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91725+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91726 i++, cmfptr++)
91727 {
91728 struct socket *sock;
91729diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91730index 2c3d0f5..f5a326f 100644
91731--- a/net/core/skbuff.c
91732+++ b/net/core/skbuff.c
91733@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91734 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91735 sizeof(struct sk_buff),
91736 0,
91737- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91738+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91739+ SLAB_NO_SANITIZE,
91740 NULL);
91741 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91742 (2*sizeof(struct sk_buff)) +
91743 sizeof(atomic_t),
91744 0,
91745- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91746+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91747+ SLAB_NO_SANITIZE,
91748 NULL);
91749 }
91750
91751diff --git a/net/core/sock.c b/net/core/sock.c
91752index 8729d91..4a20427 100644
91753--- a/net/core/sock.c
91754+++ b/net/core/sock.c
91755@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91756 struct sk_buff_head *list = &sk->sk_receive_queue;
91757
91758 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91759- atomic_inc(&sk->sk_drops);
91760+ atomic_inc_unchecked(&sk->sk_drops);
91761 trace_sock_rcvqueue_full(sk, skb);
91762 return -ENOMEM;
91763 }
91764@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91765 return err;
91766
91767 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91768- atomic_inc(&sk->sk_drops);
91769+ atomic_inc_unchecked(&sk->sk_drops);
91770 return -ENOBUFS;
91771 }
91772
91773@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91774 skb_dst_force(skb);
91775
91776 spin_lock_irqsave(&list->lock, flags);
91777- skb->dropcount = atomic_read(&sk->sk_drops);
91778+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91779 __skb_queue_tail(list, skb);
91780 spin_unlock_irqrestore(&list->lock, flags);
91781
91782@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91783 skb->dev = NULL;
91784
91785 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91786- atomic_inc(&sk->sk_drops);
91787+ atomic_inc_unchecked(&sk->sk_drops);
91788 goto discard_and_relse;
91789 }
91790 if (nested)
91791@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91792 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91793 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91794 bh_unlock_sock(sk);
91795- atomic_inc(&sk->sk_drops);
91796+ atomic_inc_unchecked(&sk->sk_drops);
91797 goto discard_and_relse;
91798 }
91799
91800@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91801 struct timeval tm;
91802 } v;
91803
91804- int lv = sizeof(int);
91805- int len;
91806+ unsigned int lv = sizeof(int);
91807+ unsigned int len;
91808
91809 if (get_user(len, optlen))
91810 return -EFAULT;
91811- if (len < 0)
91812+ if (len > INT_MAX)
91813 return -EINVAL;
91814
91815 memset(&v, 0, sizeof(v));
91816@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91817
91818 case SO_PEERNAME:
91819 {
91820- char address[128];
91821+ char address[_K_SS_MAXSIZE];
91822
91823 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91824 return -ENOTCONN;
91825- if (lv < len)
91826+ if (lv < len || sizeof address < len)
91827 return -EINVAL;
91828 if (copy_to_user(optval, address, len))
91829 return -EFAULT;
91830@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91831
91832 if (len > lv)
91833 len = lv;
91834- if (copy_to_user(optval, &v, len))
91835+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91836 return -EFAULT;
91837 lenout:
91838 if (put_user(len, optlen))
91839@@ -2304,7 +2304,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91840 */
91841 smp_wmb();
91842 atomic_set(&sk->sk_refcnt, 1);
91843- atomic_set(&sk->sk_drops, 0);
91844+ atomic_set_unchecked(&sk->sk_drops, 0);
91845 }
91846 EXPORT_SYMBOL(sock_init_data);
91847
91848diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91849index a0e9cf6..ef7f9ed 100644
91850--- a/net/core/sock_diag.c
91851+++ b/net/core/sock_diag.c
91852@@ -9,26 +9,33 @@
91853 #include <linux/inet_diag.h>
91854 #include <linux/sock_diag.h>
91855
91856-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91857+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91858 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91859 static DEFINE_MUTEX(sock_diag_table_mutex);
91860
91861 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91862 {
91863+#ifndef CONFIG_GRKERNSEC_HIDESYM
91864 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91865 cookie[1] != INET_DIAG_NOCOOKIE) &&
91866 ((u32)(unsigned long)sk != cookie[0] ||
91867 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91868 return -ESTALE;
91869 else
91870+#endif
91871 return 0;
91872 }
91873 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91874
91875 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91876 {
91877+#ifdef CONFIG_GRKERNSEC_HIDESYM
91878+ cookie[0] = 0;
91879+ cookie[1] = 0;
91880+#else
91881 cookie[0] = (u32)(unsigned long)sk;
91882 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91883+#endif
91884 }
91885 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91886
91887@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91888 mutex_lock(&sock_diag_table_mutex);
91889 if (sock_diag_handlers[hndl->family])
91890 err = -EBUSY;
91891- else
91892+ else {
91893+ pax_open_kernel();
91894 sock_diag_handlers[hndl->family] = hndl;
91895+ pax_close_kernel();
91896+ }
91897 mutex_unlock(&sock_diag_table_mutex);
91898
91899 return err;
91900@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91901
91902 mutex_lock(&sock_diag_table_mutex);
91903 BUG_ON(sock_diag_handlers[family] != hnld);
91904+ pax_open_kernel();
91905 sock_diag_handlers[family] = NULL;
91906+ pax_close_kernel();
91907 mutex_unlock(&sock_diag_table_mutex);
91908 }
91909 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91910diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91911index 31107ab..ae03d5a 100644
91912--- a/net/core/sysctl_net_core.c
91913+++ b/net/core/sysctl_net_core.c
91914@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91915 {
91916 unsigned int orig_size, size;
91917 int ret, i;
91918- struct ctl_table tmp = {
91919+ ctl_table_no_const tmp = {
91920 .data = &size,
91921 .maxlen = sizeof(size),
91922 .mode = table->mode
91923@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91924
91925 static __net_init int sysctl_core_net_init(struct net *net)
91926 {
91927- struct ctl_table *tbl;
91928+ ctl_table_no_const *tbl = NULL;
91929
91930 net->core.sysctl_somaxconn = SOMAXCONN;
91931
91932- tbl = netns_core_table;
91933 if (!net_eq(net, &init_net)) {
91934- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91935+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91936 if (tbl == NULL)
91937 goto err_dup;
91938
91939@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91940 if (net->user_ns != &init_user_ns) {
91941 tbl[0].procname = NULL;
91942 }
91943- }
91944-
91945- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91946+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91947+ } else
91948+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91949 if (net->core.sysctl_hdr == NULL)
91950 goto err_reg;
91951
91952 return 0;
91953
91954 err_reg:
91955- if (tbl != netns_core_table)
91956- kfree(tbl);
91957+ kfree(tbl);
91958 err_dup:
91959 return -ENOMEM;
91960 }
91961@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91962 kfree(tbl);
91963 }
91964
91965-static __net_initdata struct pernet_operations sysctl_core_ops = {
91966+static __net_initconst struct pernet_operations sysctl_core_ops = {
91967 .init = sysctl_core_net_init,
91968 .exit = sysctl_core_net_exit,
91969 };
91970diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91971index dd4d506..fb2fb87 100644
91972--- a/net/decnet/af_decnet.c
91973+++ b/net/decnet/af_decnet.c
91974@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91975 .sysctl_rmem = sysctl_decnet_rmem,
91976 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91977 .obj_size = sizeof(struct dn_sock),
91978+ .slab_flags = SLAB_USERCOPY,
91979 };
91980
91981 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91982diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91983index 5325b54..a0d4d69 100644
91984--- a/net/decnet/sysctl_net_decnet.c
91985+++ b/net/decnet/sysctl_net_decnet.c
91986@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91987
91988 if (len > *lenp) len = *lenp;
91989
91990- if (copy_to_user(buffer, addr, len))
91991+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91992 return -EFAULT;
91993
91994 *lenp = len;
91995@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91996
91997 if (len > *lenp) len = *lenp;
91998
91999- if (copy_to_user(buffer, devname, len))
92000+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
92001 return -EFAULT;
92002
92003 *lenp = len;
92004diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
92005index 3b9d5f2..d7015c6 100644
92006--- a/net/ieee802154/6lowpan.c
92007+++ b/net/ieee802154/6lowpan.c
92008@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
92009 hc06_ptr += 3;
92010 } else {
92011 /* compress nothing */
92012- memcpy(hc06_ptr, &hdr, 4);
92013+ memcpy(hc06_ptr, hdr, 4);
92014 /* replace the top byte with new ECN | DSCP format */
92015 *hc06_ptr = tmp;
92016 hc06_ptr += 4;
92017diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
92018index dd6b523..dfe558f 100644
92019--- a/net/ipv4/af_inet.c
92020+++ b/net/ipv4/af_inet.c
92021@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
92022
92023 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
92024
92025- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
92026- if (!sysctl_local_reserved_ports)
92027- goto out;
92028-
92029 rc = proto_register(&tcp_prot, 1);
92030 if (rc)
92031- goto out_free_reserved_ports;
92032+ goto out;
92033
92034 rc = proto_register(&udp_prot, 1);
92035 if (rc)
92036@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
92037 proto_unregister(&udp_prot);
92038 out_unregister_tcp_proto:
92039 proto_unregister(&tcp_prot);
92040-out_free_reserved_ports:
92041- kfree(sysctl_local_reserved_ports);
92042 goto out;
92043 }
92044
92045diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92046index 34ca6d5..b6421e8 100644
92047--- a/net/ipv4/devinet.c
92048+++ b/net/ipv4/devinet.c
92049@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92050 idx = 0;
92051 head = &net->dev_index_head[h];
92052 rcu_read_lock();
92053- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92054+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92055 net->dev_base_seq;
92056 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92057 if (idx < s_idx)
92058@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92059 idx = 0;
92060 head = &net->dev_index_head[h];
92061 rcu_read_lock();
92062- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92063+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92064 net->dev_base_seq;
92065 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92066 if (idx < s_idx)
92067@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92068 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92069 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92070
92071-static struct devinet_sysctl_table {
92072+static const struct devinet_sysctl_table {
92073 struct ctl_table_header *sysctl_header;
92074 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92075 } devinet_sysctl = {
92076@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92077 int err;
92078 struct ipv4_devconf *all, *dflt;
92079 #ifdef CONFIG_SYSCTL
92080- struct ctl_table *tbl = ctl_forward_entry;
92081+ ctl_table_no_const *tbl = NULL;
92082 struct ctl_table_header *forw_hdr;
92083 #endif
92084
92085@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92086 goto err_alloc_dflt;
92087
92088 #ifdef CONFIG_SYSCTL
92089- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92090+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92091 if (tbl == NULL)
92092 goto err_alloc_ctl;
92093
92094@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92095 goto err_reg_dflt;
92096
92097 err = -ENOMEM;
92098- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92099+ if (!net_eq(net, &init_net))
92100+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92101+ else
92102+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92103 if (forw_hdr == NULL)
92104 goto err_reg_ctl;
92105 net->ipv4.forw_hdr = forw_hdr;
92106@@ -2240,8 +2243,7 @@ err_reg_ctl:
92107 err_reg_dflt:
92108 __devinet_sysctl_unregister(all);
92109 err_reg_all:
92110- if (tbl != ctl_forward_entry)
92111- kfree(tbl);
92112+ kfree(tbl);
92113 err_alloc_ctl:
92114 #endif
92115 if (dflt != &ipv4_devconf_dflt)
92116diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92117index b3f627a..b0f3e99 100644
92118--- a/net/ipv4/fib_frontend.c
92119+++ b/net/ipv4/fib_frontend.c
92120@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92121 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92122 fib_sync_up(dev);
92123 #endif
92124- atomic_inc(&net->ipv4.dev_addr_genid);
92125+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92126 rt_cache_flush(dev_net(dev));
92127 break;
92128 case NETDEV_DOWN:
92129 fib_del_ifaddr(ifa, NULL);
92130- atomic_inc(&net->ipv4.dev_addr_genid);
92131+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92132 if (ifa->ifa_dev->ifa_list == NULL) {
92133 /* Last address was deleted from this interface.
92134 * Disable IP.
92135@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92136 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92137 fib_sync_up(dev);
92138 #endif
92139- atomic_inc(&net->ipv4.dev_addr_genid);
92140+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92141 rt_cache_flush(net);
92142 break;
92143 case NETDEV_DOWN:
92144diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92145index d5dbca5..6251d5f 100644
92146--- a/net/ipv4/fib_semantics.c
92147+++ b/net/ipv4/fib_semantics.c
92148@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92149 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92150 nh->nh_gw,
92151 nh->nh_parent->fib_scope);
92152- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92153+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92154
92155 return nh->nh_saddr;
92156 }
92157diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92158index 6acb541..9ea617d 100644
92159--- a/net/ipv4/inet_connection_sock.c
92160+++ b/net/ipv4/inet_connection_sock.c
92161@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92162 .range = { 32768, 61000 },
92163 };
92164
92165-unsigned long *sysctl_local_reserved_ports;
92166+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92167 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92168
92169 void inet_get_local_port_range(int *low, int *high)
92170diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92171index 96da9c7..b956690 100644
92172--- a/net/ipv4/inet_hashtables.c
92173+++ b/net/ipv4/inet_hashtables.c
92174@@ -18,12 +18,15 @@
92175 #include <linux/sched.h>
92176 #include <linux/slab.h>
92177 #include <linux/wait.h>
92178+#include <linux/security.h>
92179
92180 #include <net/inet_connection_sock.h>
92181 #include <net/inet_hashtables.h>
92182 #include <net/secure_seq.h>
92183 #include <net/ip.h>
92184
92185+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92186+
92187 /*
92188 * Allocate and initialize a new local port bind bucket.
92189 * The bindhash mutex for snum's hash chain must be held here.
92190@@ -554,6 +557,8 @@ ok:
92191 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92192 spin_unlock(&head->lock);
92193
92194+ gr_update_task_in_ip_table(current, inet_sk(sk));
92195+
92196 if (tw) {
92197 inet_twsk_deschedule(tw, death_row);
92198 while (twrefcnt) {
92199diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92200index 33d5537..da337a4 100644
92201--- a/net/ipv4/inetpeer.c
92202+++ b/net/ipv4/inetpeer.c
92203@@ -503,8 +503,8 @@ relookup:
92204 if (p) {
92205 p->daddr = *daddr;
92206 atomic_set(&p->refcnt, 1);
92207- atomic_set(&p->rid, 0);
92208- atomic_set(&p->ip_id_count,
92209+ atomic_set_unchecked(&p->rid, 0);
92210+ atomic_set_unchecked(&p->ip_id_count,
92211 (daddr->family == AF_INET) ?
92212 secure_ip_id(daddr->addr.a4) :
92213 secure_ipv6_id(daddr->addr.a6));
92214diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92215index b66910a..cfe416e 100644
92216--- a/net/ipv4/ip_fragment.c
92217+++ b/net/ipv4/ip_fragment.c
92218@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92219 return 0;
92220
92221 start = qp->rid;
92222- end = atomic_inc_return(&peer->rid);
92223+ end = atomic_inc_return_unchecked(&peer->rid);
92224 qp->rid = end;
92225
92226 rc = qp->q.fragments && (end - start) > max;
92227@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92228
92229 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92230 {
92231- struct ctl_table *table;
92232+ ctl_table_no_const *table = NULL;
92233 struct ctl_table_header *hdr;
92234
92235- table = ip4_frags_ns_ctl_table;
92236 if (!net_eq(net, &init_net)) {
92237- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92238+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92239 if (table == NULL)
92240 goto err_alloc;
92241
92242@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92243 /* Don't export sysctls to unprivileged users */
92244 if (net->user_ns != &init_user_ns)
92245 table[0].procname = NULL;
92246- }
92247+ hdr = register_net_sysctl(net, "net/ipv4", table);
92248+ } else
92249+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92250
92251- hdr = register_net_sysctl(net, "net/ipv4", table);
92252 if (hdr == NULL)
92253 goto err_reg;
92254
92255@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92256 return 0;
92257
92258 err_reg:
92259- if (!net_eq(net, &init_net))
92260- kfree(table);
92261+ kfree(table);
92262 err_alloc:
92263 return -ENOMEM;
92264 }
92265diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92266index 8d6939e..19d0a95 100644
92267--- a/net/ipv4/ip_gre.c
92268+++ b/net/ipv4/ip_gre.c
92269@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92270 module_param(log_ecn_error, bool, 0644);
92271 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92272
92273-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92274+static struct rtnl_link_ops ipgre_link_ops;
92275 static int ipgre_tunnel_init(struct net_device *dev);
92276
92277 static int ipgre_net_id __read_mostly;
92278@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92279 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92280 };
92281
92282-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92283+static struct rtnl_link_ops ipgre_link_ops = {
92284 .kind = "gre",
92285 .maxtype = IFLA_GRE_MAX,
92286 .policy = ipgre_policy,
92287@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92288 .fill_info = ipgre_fill_info,
92289 };
92290
92291-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92292+static struct rtnl_link_ops ipgre_tap_ops = {
92293 .kind = "gretap",
92294 .maxtype = IFLA_GRE_MAX,
92295 .policy = ipgre_policy,
92296diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92297index d9c4f11..02b82dbc 100644
92298--- a/net/ipv4/ip_sockglue.c
92299+++ b/net/ipv4/ip_sockglue.c
92300@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92301 len = min_t(unsigned int, len, opt->optlen);
92302 if (put_user(len, optlen))
92303 return -EFAULT;
92304- if (copy_to_user(optval, opt->__data, len))
92305+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92306+ copy_to_user(optval, opt->__data, len))
92307 return -EFAULT;
92308 return 0;
92309 }
92310@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92311 if (sk->sk_type != SOCK_STREAM)
92312 return -ENOPROTOOPT;
92313
92314- msg.msg_control = optval;
92315+ msg.msg_control = (void __force_kernel *)optval;
92316 msg.msg_controllen = len;
92317 msg.msg_flags = flags;
92318
92319diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92320index 0656041..d6ecb60 100644
92321--- a/net/ipv4/ip_vti.c
92322+++ b/net/ipv4/ip_vti.c
92323@@ -47,7 +47,7 @@
92324 #define HASH_SIZE 16
92325 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92326
92327-static struct rtnl_link_ops vti_link_ops __read_mostly;
92328+static struct rtnl_link_ops vti_link_ops;
92329
92330 static int vti_net_id __read_mostly;
92331 struct vti_net {
92332@@ -848,7 +848,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92333 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92334 };
92335
92336-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92337+static struct rtnl_link_ops vti_link_ops = {
92338 .kind = "vti",
92339 .maxtype = IFLA_VTI_MAX,
92340 .policy = vti_policy,
92341diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92342index efa1138..20dbba0 100644
92343--- a/net/ipv4/ipconfig.c
92344+++ b/net/ipv4/ipconfig.c
92345@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92346
92347 mm_segment_t oldfs = get_fs();
92348 set_fs(get_ds());
92349- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92350+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92351 set_fs(oldfs);
92352 return res;
92353 }
92354@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92355
92356 mm_segment_t oldfs = get_fs();
92357 set_fs(get_ds());
92358- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92359+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92360 set_fs(oldfs);
92361 return res;
92362 }
92363@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92364
92365 mm_segment_t oldfs = get_fs();
92366 set_fs(get_ds());
92367- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92368+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92369 set_fs(oldfs);
92370 return res;
92371 }
92372diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92373index b3ac3c3..ec6bd95 100644
92374--- a/net/ipv4/ipip.c
92375+++ b/net/ipv4/ipip.c
92376@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92377 static int ipip_net_id __read_mostly;
92378
92379 static int ipip_tunnel_init(struct net_device *dev);
92380-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92381+static struct rtnl_link_ops ipip_link_ops;
92382
92383 static int ipip_err(struct sk_buff *skb, u32 info)
92384 {
92385@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92386 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92387 };
92388
92389-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92390+static struct rtnl_link_ops ipip_link_ops = {
92391 .kind = "ipip",
92392 .maxtype = IFLA_IPTUN_MAX,
92393 .policy = ipip_policy,
92394diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92395index 85a4f21..1beb1f5 100644
92396--- a/net/ipv4/netfilter/arp_tables.c
92397+++ b/net/ipv4/netfilter/arp_tables.c
92398@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92399 #endif
92400
92401 static int get_info(struct net *net, void __user *user,
92402- const int *len, int compat)
92403+ int len, int compat)
92404 {
92405 char name[XT_TABLE_MAXNAMELEN];
92406 struct xt_table *t;
92407 int ret;
92408
92409- if (*len != sizeof(struct arpt_getinfo)) {
92410- duprintf("length %u != %Zu\n", *len,
92411+ if (len != sizeof(struct arpt_getinfo)) {
92412+ duprintf("length %u != %Zu\n", len,
92413 sizeof(struct arpt_getinfo));
92414 return -EINVAL;
92415 }
92416@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92417 info.size = private->size;
92418 strcpy(info.name, name);
92419
92420- if (copy_to_user(user, &info, *len) != 0)
92421+ if (copy_to_user(user, &info, len) != 0)
92422 ret = -EFAULT;
92423 else
92424 ret = 0;
92425@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92426
92427 switch (cmd) {
92428 case ARPT_SO_GET_INFO:
92429- ret = get_info(sock_net(sk), user, len, 1);
92430+ ret = get_info(sock_net(sk), user, *len, 1);
92431 break;
92432 case ARPT_SO_GET_ENTRIES:
92433 ret = compat_get_entries(sock_net(sk), user, len);
92434@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92435
92436 switch (cmd) {
92437 case ARPT_SO_GET_INFO:
92438- ret = get_info(sock_net(sk), user, len, 0);
92439+ ret = get_info(sock_net(sk), user, *len, 0);
92440 break;
92441
92442 case ARPT_SO_GET_ENTRIES:
92443diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92444index d23118d..6ad7277 100644
92445--- a/net/ipv4/netfilter/ip_tables.c
92446+++ b/net/ipv4/netfilter/ip_tables.c
92447@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92448 #endif
92449
92450 static int get_info(struct net *net, void __user *user,
92451- const int *len, int compat)
92452+ int len, int compat)
92453 {
92454 char name[XT_TABLE_MAXNAMELEN];
92455 struct xt_table *t;
92456 int ret;
92457
92458- if (*len != sizeof(struct ipt_getinfo)) {
92459- duprintf("length %u != %zu\n", *len,
92460+ if (len != sizeof(struct ipt_getinfo)) {
92461+ duprintf("length %u != %zu\n", len,
92462 sizeof(struct ipt_getinfo));
92463 return -EINVAL;
92464 }
92465@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92466 info.size = private->size;
92467 strcpy(info.name, name);
92468
92469- if (copy_to_user(user, &info, *len) != 0)
92470+ if (copy_to_user(user, &info, len) != 0)
92471 ret = -EFAULT;
92472 else
92473 ret = 0;
92474@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92475
92476 switch (cmd) {
92477 case IPT_SO_GET_INFO:
92478- ret = get_info(sock_net(sk), user, len, 1);
92479+ ret = get_info(sock_net(sk), user, *len, 1);
92480 break;
92481 case IPT_SO_GET_ENTRIES:
92482 ret = compat_get_entries(sock_net(sk), user, len);
92483@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92484
92485 switch (cmd) {
92486 case IPT_SO_GET_INFO:
92487- ret = get_info(sock_net(sk), user, len, 0);
92488+ ret = get_info(sock_net(sk), user, *len, 0);
92489 break;
92490
92491 case IPT_SO_GET_ENTRIES:
92492diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92493index cbc2215..9cb993c 100644
92494--- a/net/ipv4/netfilter/ipt_ULOG.c
92495+++ b/net/ipv4/netfilter/ipt_ULOG.c
92496@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92497 ub->qlen++;
92498
92499 pm = nlmsg_data(nlh);
92500+ memset(pm, 0, sizeof(*pm));
92501
92502 /* We might not have a timestamp, get one */
92503 if (skb->tstamp.tv64 == 0)
92504@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92505 }
92506 else if (loginfo->prefix[0] != '\0')
92507 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92508- else
92509- *(pm->prefix) = '\0';
92510
92511 if (in && in->hard_header_len > 0 &&
92512 skb->mac_header != skb->network_header &&
92513@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92514
92515 if (in)
92516 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92517- else
92518- pm->indev_name[0] = '\0';
92519
92520 if (out)
92521 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92522- else
92523- pm->outdev_name[0] = '\0';
92524
92525 /* copy_len <= skb->len, so can't fail. */
92526 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92527diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92528index 746427c..80eab72 100644
92529--- a/net/ipv4/ping.c
92530+++ b/net/ipv4/ping.c
92531@@ -55,7 +55,7 @@
92532
92533
92534 struct ping_table ping_table;
92535-struct pingv6_ops pingv6_ops;
92536+struct pingv6_ops *pingv6_ops;
92537 EXPORT_SYMBOL_GPL(pingv6_ops);
92538
92539 static u16 ping_port_rover;
92540@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92541 return -ENODEV;
92542 }
92543 }
92544- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92545+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92546 scoped);
92547 rcu_read_unlock();
92548
92549@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92550 }
92551 #if IS_ENABLED(CONFIG_IPV6)
92552 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92553- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92554+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92555 #endif
92556 }
92557
92558@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92559 info, (u8 *)icmph);
92560 #if IS_ENABLED(CONFIG_IPV6)
92561 } else if (family == AF_INET6) {
92562- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92563+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92564 info, (u8 *)icmph);
92565 #endif
92566 }
92567@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92568 return ip_recv_error(sk, msg, len);
92569 #if IS_ENABLED(CONFIG_IPV6)
92570 } else if (family == AF_INET6) {
92571- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92572+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92573 #endif
92574 }
92575 }
92576@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92577 IP6CB(skb)->iif);
92578
92579 if (inet6_sk(sk)->rxopt.all)
92580- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92581+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92582 #endif
92583 } else {
92584 BUG();
92585@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92586 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92587 0, sock_i_ino(sp),
92588 atomic_read(&sp->sk_refcnt), sp,
92589- atomic_read(&sp->sk_drops), len);
92590+ atomic_read_unchecked(&sp->sk_drops), len);
92591 }
92592
92593 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92594diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92595index 6fb2337..9cd6b20 100644
92596--- a/net/ipv4/raw.c
92597+++ b/net/ipv4/raw.c
92598@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92599 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92600 {
92601 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92602- atomic_inc(&sk->sk_drops);
92603+ atomic_inc_unchecked(&sk->sk_drops);
92604 kfree_skb(skb);
92605 return NET_RX_DROP;
92606 }
92607@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92608
92609 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92610 {
92611+ struct icmp_filter filter;
92612+
92613 if (optlen > sizeof(struct icmp_filter))
92614 optlen = sizeof(struct icmp_filter);
92615- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92616+ if (copy_from_user(&filter, optval, optlen))
92617 return -EFAULT;
92618+ raw_sk(sk)->filter = filter;
92619 return 0;
92620 }
92621
92622 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92623 {
92624 int len, ret = -EFAULT;
92625+ struct icmp_filter filter;
92626
92627 if (get_user(len, optlen))
92628 goto out;
92629@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92630 if (len > sizeof(struct icmp_filter))
92631 len = sizeof(struct icmp_filter);
92632 ret = -EFAULT;
92633- if (put_user(len, optlen) ||
92634- copy_to_user(optval, &raw_sk(sk)->filter, len))
92635+ filter = raw_sk(sk)->filter;
92636+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92637 goto out;
92638 ret = 0;
92639 out: return ret;
92640@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92641 0, 0L, 0,
92642 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92643 0, sock_i_ino(sp),
92644- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92645+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92646 }
92647
92648 static int raw_seq_show(struct seq_file *seq, void *v)
92649diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92650index 2de16d9..da558c7 100644
92651--- a/net/ipv4/route.c
92652+++ b/net/ipv4/route.c
92653@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92654 .maxlen = sizeof(int),
92655 .mode = 0200,
92656 .proc_handler = ipv4_sysctl_rtcache_flush,
92657+ .extra1 = &init_net,
92658 },
92659 { },
92660 };
92661
92662 static __net_init int sysctl_route_net_init(struct net *net)
92663 {
92664- struct ctl_table *tbl;
92665+ ctl_table_no_const *tbl = NULL;
92666
92667- tbl = ipv4_route_flush_table;
92668 if (!net_eq(net, &init_net)) {
92669- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92670+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92671 if (tbl == NULL)
92672 goto err_dup;
92673
92674 /* Don't export sysctls to unprivileged users */
92675 if (net->user_ns != &init_user_ns)
92676 tbl[0].procname = NULL;
92677- }
92678- tbl[0].extra1 = net;
92679+ tbl[0].extra1 = net;
92680+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92681+ } else
92682+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92683
92684- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92685 if (net->ipv4.route_hdr == NULL)
92686 goto err_reg;
92687 return 0;
92688
92689 err_reg:
92690- if (tbl != ipv4_route_flush_table)
92691- kfree(tbl);
92692+ kfree(tbl);
92693 err_dup:
92694 return -ENOMEM;
92695 }
92696@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92697
92698 static __net_init int rt_genid_init(struct net *net)
92699 {
92700- atomic_set(&net->rt_genid, 0);
92701- atomic_set(&net->fnhe_genid, 0);
92702+ atomic_set_unchecked(&net->rt_genid, 0);
92703+ atomic_set_unchecked(&net->fnhe_genid, 0);
92704 get_random_bytes(&net->ipv4.dev_addr_genid,
92705 sizeof(net->ipv4.dev_addr_genid));
92706 return 0;
92707diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92708index 6900b8b..7832c6b 100644
92709--- a/net/ipv4/sysctl_net_ipv4.c
92710+++ b/net/ipv4/sysctl_net_ipv4.c
92711@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92712 {
92713 int ret;
92714 int range[2];
92715- struct ctl_table tmp = {
92716+ ctl_table_no_const tmp = {
92717 .data = &range,
92718 .maxlen = sizeof(range),
92719 .mode = table->mode,
92720@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92721 int ret;
92722 gid_t urange[2];
92723 kgid_t low, high;
92724- struct ctl_table tmp = {
92725+ ctl_table_no_const tmp = {
92726 .data = &urange,
92727 .maxlen = sizeof(urange),
92728 .mode = table->mode,
92729@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92730 void __user *buffer, size_t *lenp, loff_t *ppos)
92731 {
92732 char val[TCP_CA_NAME_MAX];
92733- struct ctl_table tbl = {
92734+ ctl_table_no_const tbl = {
92735 .data = val,
92736 .maxlen = TCP_CA_NAME_MAX,
92737 };
92738@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92739 void __user *buffer, size_t *lenp,
92740 loff_t *ppos)
92741 {
92742- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92743+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92744 int ret;
92745
92746 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92747@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92748 void __user *buffer, size_t *lenp,
92749 loff_t *ppos)
92750 {
92751- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92752+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92753 int ret;
92754
92755 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92756@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92757 struct mem_cgroup *memcg;
92758 #endif
92759
92760- struct ctl_table tmp = {
92761+ ctl_table_no_const tmp = {
92762 .data = &vec,
92763 .maxlen = sizeof(vec),
92764 .mode = ctl->mode,
92765 };
92766
92767 if (!write) {
92768- ctl->data = &net->ipv4.sysctl_tcp_mem;
92769- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92770+ ctl_table_no_const tcp_mem = *ctl;
92771+
92772+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92773+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92774 }
92775
92776 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92777@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92778 void __user *buffer, size_t *lenp,
92779 loff_t *ppos)
92780 {
92781- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92782+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92783 struct tcp_fastopen_context *ctxt;
92784 int ret;
92785 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92786@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
92787 },
92788 {
92789 .procname = "ip_local_reserved_ports",
92790- .data = NULL, /* initialized in sysctl_ipv4_init */
92791+ .data = sysctl_local_reserved_ports,
92792 .maxlen = 65536,
92793 .mode = 0644,
92794 .proc_handler = proc_do_large_bitmap,
92795@@ -857,11 +859,10 @@ static struct ctl_table ipv4_net_table[] = {
92796
92797 static __net_init int ipv4_sysctl_init_net(struct net *net)
92798 {
92799- struct ctl_table *table;
92800+ ctl_table_no_const *table = NULL;
92801
92802- table = ipv4_net_table;
92803 if (!net_eq(net, &init_net)) {
92804- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92805+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92806 if (table == NULL)
92807 goto err_alloc;
92808
92809@@ -896,15 +897,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92810
92811 tcp_init_mem(net);
92812
92813- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92814+ if (!net_eq(net, &init_net))
92815+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92816+ else
92817+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92818 if (net->ipv4.ipv4_hdr == NULL)
92819 goto err_reg;
92820
92821 return 0;
92822
92823 err_reg:
92824- if (!net_eq(net, &init_net))
92825- kfree(table);
92826+ kfree(table);
92827 err_alloc:
92828 return -ENOMEM;
92829 }
92830@@ -926,16 +929,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92831 static __init int sysctl_ipv4_init(void)
92832 {
92833 struct ctl_table_header *hdr;
92834- struct ctl_table *i;
92835-
92836- for (i = ipv4_table; i->procname; i++) {
92837- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92838- i->data = sysctl_local_reserved_ports;
92839- break;
92840- }
92841- }
92842- if (!i->procname)
92843- return -EINVAL;
92844
92845 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92846 if (hdr == NULL)
92847diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92848index 723951a..61cf1cc 100644
92849--- a/net/ipv4/tcp_input.c
92850+++ b/net/ipv4/tcp_input.c
92851@@ -4412,7 +4412,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92852 * simplifies code)
92853 */
92854 static void
92855-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92856+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92857 struct sk_buff *head, struct sk_buff *tail,
92858 u32 start, u32 end)
92859 {
92860@@ -5498,6 +5498,7 @@ discard:
92861 tcp_paws_reject(&tp->rx_opt, 0))
92862 goto discard_and_undo;
92863
92864+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92865 if (th->syn) {
92866 /* We see SYN without ACK. It is attempt of
92867 * simultaneous connect with crossed SYNs.
92868@@ -5548,6 +5549,7 @@ discard:
92869 goto discard;
92870 #endif
92871 }
92872+#endif
92873 /* "fifth, if neither of the SYN or RST bits is set then
92874 * drop the segment and return."
92875 */
92876@@ -5593,7 +5595,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92877 goto discard;
92878
92879 if (th->syn) {
92880- if (th->fin)
92881+ if (th->fin || th->urg || th->psh)
92882 goto discard;
92883 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92884 return 1;
92885diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92886index b299da5..097db06 100644
92887--- a/net/ipv4/tcp_ipv4.c
92888+++ b/net/ipv4/tcp_ipv4.c
92889@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92890 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92891
92892
92893+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92894+extern int grsec_enable_blackhole;
92895+#endif
92896+
92897 #ifdef CONFIG_TCP_MD5SIG
92898 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92899 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92900@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92901 return 0;
92902
92903 reset:
92904+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92905+ if (!grsec_enable_blackhole)
92906+#endif
92907 tcp_v4_send_reset(rsk, skb);
92908 discard:
92909 kfree_skb(skb);
92910@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92911 TCP_SKB_CB(skb)->sacked = 0;
92912
92913 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92914- if (!sk)
92915+ if (!sk) {
92916+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92917+ ret = 1;
92918+#endif
92919 goto no_tcp_socket;
92920-
92921+ }
92922 process:
92923- if (sk->sk_state == TCP_TIME_WAIT)
92924+ if (sk->sk_state == TCP_TIME_WAIT) {
92925+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92926+ ret = 2;
92927+#endif
92928 goto do_time_wait;
92929+ }
92930
92931 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92932 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92933@@ -2034,6 +2048,10 @@ csum_error:
92934 bad_packet:
92935 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92936 } else {
92937+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92938+ if (!grsec_enable_blackhole || (ret == 1 &&
92939+ (skb->dev->flags & IFF_LOOPBACK)))
92940+#endif
92941 tcp_v4_send_reset(NULL, skb);
92942 }
92943
92944diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92945index ab1c086..2a8d76b 100644
92946--- a/net/ipv4/tcp_minisocks.c
92947+++ b/net/ipv4/tcp_minisocks.c
92948@@ -27,6 +27,10 @@
92949 #include <net/inet_common.h>
92950 #include <net/xfrm.h>
92951
92952+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92953+extern int grsec_enable_blackhole;
92954+#endif
92955+
92956 int sysctl_tcp_syncookies __read_mostly = 1;
92957 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92958
92959@@ -715,7 +719,10 @@ embryonic_reset:
92960 * avoid becoming vulnerable to outside attack aiming at
92961 * resetting legit local connections.
92962 */
92963- req->rsk_ops->send_reset(sk, skb);
92964+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92965+ if (!grsec_enable_blackhole)
92966+#endif
92967+ req->rsk_ops->send_reset(sk, skb);
92968 } else if (fastopen) { /* received a valid RST pkt */
92969 reqsk_fastopen_remove(sk, req, true);
92970 tcp_reset(sk);
92971diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92972index d4943f6..e7a74a5 100644
92973--- a/net/ipv4/tcp_probe.c
92974+++ b/net/ipv4/tcp_probe.c
92975@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92976 if (cnt + width >= len)
92977 break;
92978
92979- if (copy_to_user(buf + cnt, tbuf, width))
92980+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92981 return -EFAULT;
92982 cnt += width;
92983 }
92984diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92985index 4b85e6f..22f9ac9 100644
92986--- a/net/ipv4/tcp_timer.c
92987+++ b/net/ipv4/tcp_timer.c
92988@@ -22,6 +22,10 @@
92989 #include <linux/gfp.h>
92990 #include <net/tcp.h>
92991
92992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92993+extern int grsec_lastack_retries;
92994+#endif
92995+
92996 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92997 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92998 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92999@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
93000 }
93001 }
93002
93003+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93004+ if ((sk->sk_state == TCP_LAST_ACK) &&
93005+ (grsec_lastack_retries > 0) &&
93006+ (grsec_lastack_retries < retry_until))
93007+ retry_until = grsec_lastack_retries;
93008+#endif
93009+
93010 if (retransmits_timed_out(sk, retry_until,
93011 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
93012 /* Has it gone just too far? */
93013diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
93014index 766e6ba..aff2f8d 100644
93015--- a/net/ipv4/udp.c
93016+++ b/net/ipv4/udp.c
93017@@ -87,6 +87,7 @@
93018 #include <linux/types.h>
93019 #include <linux/fcntl.h>
93020 #include <linux/module.h>
93021+#include <linux/security.h>
93022 #include <linux/socket.h>
93023 #include <linux/sockios.h>
93024 #include <linux/igmp.h>
93025@@ -112,6 +113,10 @@
93026 #include <net/busy_poll.h>
93027 #include "udp_impl.h"
93028
93029+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93030+extern int grsec_enable_blackhole;
93031+#endif
93032+
93033 struct udp_table udp_table __read_mostly;
93034 EXPORT_SYMBOL(udp_table);
93035
93036@@ -595,6 +600,9 @@ found:
93037 return s;
93038 }
93039
93040+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93041+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93042+
93043 /*
93044 * This routine is called by the ICMP module when it gets some
93045 * sort of error condition. If err < 0 then the socket should
93046@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93047 dport = usin->sin_port;
93048 if (dport == 0)
93049 return -EINVAL;
93050+
93051+ err = gr_search_udp_sendmsg(sk, usin);
93052+ if (err)
93053+ return err;
93054 } else {
93055 if (sk->sk_state != TCP_ESTABLISHED)
93056 return -EDESTADDRREQ;
93057+
93058+ err = gr_search_udp_sendmsg(sk, NULL);
93059+ if (err)
93060+ return err;
93061+
93062 daddr = inet->inet_daddr;
93063 dport = inet->inet_dport;
93064 /* Open fast path for connected socket.
93065@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93066 IS_UDPLITE(sk));
93067 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93068 IS_UDPLITE(sk));
93069- atomic_inc(&sk->sk_drops);
93070+ atomic_inc_unchecked(&sk->sk_drops);
93071 __skb_unlink(skb, rcvq);
93072 __skb_queue_tail(&list_kill, skb);
93073 }
93074@@ -1223,6 +1240,10 @@ try_again:
93075 if (!skb)
93076 goto out;
93077
93078+ err = gr_search_udp_recvmsg(sk, skb);
93079+ if (err)
93080+ goto out_free;
93081+
93082 ulen = skb->len - sizeof(struct udphdr);
93083 copied = len;
93084 if (copied > ulen)
93085@@ -1256,7 +1277,7 @@ try_again:
93086 if (unlikely(err)) {
93087 trace_kfree_skb(skb, udp_recvmsg);
93088 if (!peeked) {
93089- atomic_inc(&sk->sk_drops);
93090+ atomic_inc_unchecked(&sk->sk_drops);
93091 UDP_INC_STATS_USER(sock_net(sk),
93092 UDP_MIB_INERRORS, is_udplite);
93093 }
93094@@ -1543,7 +1564,7 @@ csum_error:
93095 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93096 drop:
93097 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93098- atomic_inc(&sk->sk_drops);
93099+ atomic_inc_unchecked(&sk->sk_drops);
93100 kfree_skb(skb);
93101 return -1;
93102 }
93103@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93104 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93105
93106 if (!skb1) {
93107- atomic_inc(&sk->sk_drops);
93108+ atomic_inc_unchecked(&sk->sk_drops);
93109 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93110 IS_UDPLITE(sk));
93111 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93112@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93113 goto csum_error;
93114
93115 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93116+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93117+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93118+#endif
93119 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93120
93121 /*
93122@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93123 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93124 0, sock_i_ino(sp),
93125 atomic_read(&sp->sk_refcnt), sp,
93126- atomic_read(&sp->sk_drops), len);
93127+ atomic_read_unchecked(&sp->sk_drops), len);
93128 }
93129
93130 int udp4_seq_show(struct seq_file *seq, void *v)
93131diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93132index 9a459be..c7bc04c 100644
93133--- a/net/ipv4/xfrm4_policy.c
93134+++ b/net/ipv4/xfrm4_policy.c
93135@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93136 fl4->flowi4_tos = iph->tos;
93137 }
93138
93139-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93140+static int xfrm4_garbage_collect(struct dst_ops *ops)
93141 {
93142 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93143
93144- xfrm4_policy_afinfo.garbage_collect(net);
93145+ xfrm_garbage_collect_deferred(net);
93146 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93147 }
93148
93149@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93150
93151 static int __net_init xfrm4_net_init(struct net *net)
93152 {
93153- struct ctl_table *table;
93154+ ctl_table_no_const *table = NULL;
93155 struct ctl_table_header *hdr;
93156
93157- table = xfrm4_policy_table;
93158 if (!net_eq(net, &init_net)) {
93159- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93160+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93161 if (!table)
93162 goto err_alloc;
93163
93164 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93165- }
93166-
93167- hdr = register_net_sysctl(net, "net/ipv4", table);
93168+ hdr = register_net_sysctl(net, "net/ipv4", table);
93169+ } else
93170+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93171 if (!hdr)
93172 goto err_reg;
93173
93174@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93175 return 0;
93176
93177 err_reg:
93178- if (!net_eq(net, &init_net))
93179- kfree(table);
93180+ kfree(table);
93181 err_alloc:
93182 return -ENOMEM;
93183 }
93184diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93185index 0f99f7b..9375cf5 100644
93186--- a/net/ipv6/addrconf.c
93187+++ b/net/ipv6/addrconf.c
93188@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93189 idx = 0;
93190 head = &net->dev_index_head[h];
93191 rcu_read_lock();
93192- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93193+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93194 net->dev_base_seq;
93195 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93196 if (idx < s_idx)
93197@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93198 p.iph.ihl = 5;
93199 p.iph.protocol = IPPROTO_IPV6;
93200 p.iph.ttl = 64;
93201- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93202+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93203
93204 if (ops->ndo_do_ioctl) {
93205 mm_segment_t oldfs = get_fs();
93206@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93207 s_ip_idx = ip_idx = cb->args[2];
93208
93209 rcu_read_lock();
93210- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93211+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93212 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93213 idx = 0;
93214 head = &net->dev_index_head[h];
93215@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93216 dst_free(&ifp->rt->dst);
93217 break;
93218 }
93219- atomic_inc(&net->ipv6.dev_addr_genid);
93220+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93221 }
93222
93223 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93224@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93225 int *valp = ctl->data;
93226 int val = *valp;
93227 loff_t pos = *ppos;
93228- struct ctl_table lctl;
93229+ ctl_table_no_const lctl;
93230 int ret;
93231
93232 /*
93233@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93234 int *valp = ctl->data;
93235 int val = *valp;
93236 loff_t pos = *ppos;
93237- struct ctl_table lctl;
93238+ ctl_table_no_const lctl;
93239 int ret;
93240
93241 /*
93242diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93243index 197e6f4..16d8396 100644
93244--- a/net/ipv6/datagram.c
93245+++ b/net/ipv6/datagram.c
93246@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93247 0,
93248 sock_i_ino(sp),
93249 atomic_read(&sp->sk_refcnt), sp,
93250- atomic_read(&sp->sk_drops));
93251+ atomic_read_unchecked(&sp->sk_drops));
93252 }
93253diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93254index 7cfc8d2..c5394b6 100644
93255--- a/net/ipv6/icmp.c
93256+++ b/net/ipv6/icmp.c
93257@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93258
93259 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93260 {
93261- struct ctl_table *table;
93262+ ctl_table_no_const *table;
93263
93264 table = kmemdup(ipv6_icmp_table_template,
93265 sizeof(ipv6_icmp_table_template),
93266diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93267index 8bc717b..76fbb5d 100644
93268--- a/net/ipv6/ip6_gre.c
93269+++ b/net/ipv6/ip6_gre.c
93270@@ -74,7 +74,7 @@ struct ip6gre_net {
93271 struct net_device *fb_tunnel_dev;
93272 };
93273
93274-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93275+static struct rtnl_link_ops ip6gre_link_ops;
93276 static int ip6gre_tunnel_init(struct net_device *dev);
93277 static void ip6gre_tunnel_setup(struct net_device *dev);
93278 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93279@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93280 }
93281
93282
93283-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93284+static struct inet6_protocol ip6gre_protocol = {
93285 .handler = ip6gre_rcv,
93286 .err_handler = ip6gre_err,
93287 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93288@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93289 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93290 };
93291
93292-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93293+static struct rtnl_link_ops ip6gre_link_ops = {
93294 .kind = "ip6gre",
93295 .maxtype = IFLA_GRE_MAX,
93296 .policy = ip6gre_policy,
93297@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93298 .fill_info = ip6gre_fill_info,
93299 };
93300
93301-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93302+static struct rtnl_link_ops ip6gre_tap_ops = {
93303 .kind = "ip6gretap",
93304 .maxtype = IFLA_GRE_MAX,
93305 .policy = ip6gre_policy,
93306diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93307index cf5d490..30946f0 100644
93308--- a/net/ipv6/ip6_tunnel.c
93309+++ b/net/ipv6/ip6_tunnel.c
93310@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93311
93312 static int ip6_tnl_dev_init(struct net_device *dev);
93313 static void ip6_tnl_dev_setup(struct net_device *dev);
93314-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93315+static struct rtnl_link_ops ip6_link_ops;
93316
93317 static int ip6_tnl_net_id __read_mostly;
93318 struct ip6_tnl_net {
93319@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93320 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93321 };
93322
93323-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93324+static struct rtnl_link_ops ip6_link_ops = {
93325 .kind = "ip6tnl",
93326 .maxtype = IFLA_IPTUN_MAX,
93327 .policy = ip6_tnl_policy,
93328diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93329index d1e2e8e..51c19ae 100644
93330--- a/net/ipv6/ipv6_sockglue.c
93331+++ b/net/ipv6/ipv6_sockglue.c
93332@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93333 if (sk->sk_type != SOCK_STREAM)
93334 return -ENOPROTOOPT;
93335
93336- msg.msg_control = optval;
93337+ msg.msg_control = (void __force_kernel *)optval;
93338 msg.msg_controllen = len;
93339 msg.msg_flags = flags;
93340
93341diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93342index 44400c2..8e11f52 100644
93343--- a/net/ipv6/netfilter/ip6_tables.c
93344+++ b/net/ipv6/netfilter/ip6_tables.c
93345@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93346 #endif
93347
93348 static int get_info(struct net *net, void __user *user,
93349- const int *len, int compat)
93350+ int len, int compat)
93351 {
93352 char name[XT_TABLE_MAXNAMELEN];
93353 struct xt_table *t;
93354 int ret;
93355
93356- if (*len != sizeof(struct ip6t_getinfo)) {
93357- duprintf("length %u != %zu\n", *len,
93358+ if (len != sizeof(struct ip6t_getinfo)) {
93359+ duprintf("length %u != %zu\n", len,
93360 sizeof(struct ip6t_getinfo));
93361 return -EINVAL;
93362 }
93363@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93364 info.size = private->size;
93365 strcpy(info.name, name);
93366
93367- if (copy_to_user(user, &info, *len) != 0)
93368+ if (copy_to_user(user, &info, len) != 0)
93369 ret = -EFAULT;
93370 else
93371 ret = 0;
93372@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93373
93374 switch (cmd) {
93375 case IP6T_SO_GET_INFO:
93376- ret = get_info(sock_net(sk), user, len, 1);
93377+ ret = get_info(sock_net(sk), user, *len, 1);
93378 break;
93379 case IP6T_SO_GET_ENTRIES:
93380 ret = compat_get_entries(sock_net(sk), user, len);
93381@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93382
93383 switch (cmd) {
93384 case IP6T_SO_GET_INFO:
93385- ret = get_info(sock_net(sk), user, len, 0);
93386+ ret = get_info(sock_net(sk), user, *len, 0);
93387 break;
93388
93389 case IP6T_SO_GET_ENTRIES:
93390diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93391index dffdc1a..ccc6678 100644
93392--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93393+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93394@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93395
93396 static int nf_ct_frag6_sysctl_register(struct net *net)
93397 {
93398- struct ctl_table *table;
93399+ ctl_table_no_const *table = NULL;
93400 struct ctl_table_header *hdr;
93401
93402- table = nf_ct_frag6_sysctl_table;
93403 if (!net_eq(net, &init_net)) {
93404- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93405+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93406 GFP_KERNEL);
93407 if (table == NULL)
93408 goto err_alloc;
93409@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93410 table[0].data = &net->nf_frag.frags.timeout;
93411 table[1].data = &net->nf_frag.frags.low_thresh;
93412 table[2].data = &net->nf_frag.frags.high_thresh;
93413- }
93414-
93415- hdr = register_net_sysctl(net, "net/netfilter", table);
93416+ hdr = register_net_sysctl(net, "net/netfilter", table);
93417+ } else
93418+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93419 if (hdr == NULL)
93420 goto err_reg;
93421
93422@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93423 return 0;
93424
93425 err_reg:
93426- if (!net_eq(net, &init_net))
93427- kfree(table);
93428+ kfree(table);
93429 err_alloc:
93430 return -ENOMEM;
93431 }
93432diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93433index ab92a36..bb4a528 100644
93434--- a/net/ipv6/output_core.c
93435+++ b/net/ipv6/output_core.c
93436@@ -8,8 +8,8 @@
93437
93438 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93439 {
93440- static atomic_t ipv6_fragmentation_id;
93441- int old, new;
93442+ static atomic_unchecked_t ipv6_fragmentation_id;
93443+ int id;
93444
93445 #if IS_ENABLED(CONFIG_IPV6)
93446 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93447@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93448 }
93449 }
93450 #endif
93451- do {
93452- old = atomic_read(&ipv6_fragmentation_id);
93453- new = old + 1;
93454- if (!new)
93455- new = 1;
93456- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93457- fhdr->identification = htonl(new);
93458+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93459+ if (!id)
93460+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93461+ fhdr->identification = htonl(id);
93462 }
93463 EXPORT_SYMBOL(ipv6_select_ident);
93464
93465diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93466index 18f19df..b46ada1 100644
93467--- a/net/ipv6/ping.c
93468+++ b/net/ipv6/ping.c
93469@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93470 };
93471 #endif
93472
93473+static struct pingv6_ops real_pingv6_ops = {
93474+ .ipv6_recv_error = ipv6_recv_error,
93475+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93476+ .icmpv6_err_convert = icmpv6_err_convert,
93477+ .ipv6_icmp_error = ipv6_icmp_error,
93478+ .ipv6_chk_addr = ipv6_chk_addr,
93479+};
93480+
93481+static struct pingv6_ops dummy_pingv6_ops = {
93482+ .ipv6_recv_error = dummy_ipv6_recv_error,
93483+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93484+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93485+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93486+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93487+};
93488+
93489 int __init pingv6_init(void)
93490 {
93491 #ifdef CONFIG_PROC_FS
93492@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93493 if (ret)
93494 return ret;
93495 #endif
93496- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93497- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93498- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93499- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93500- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93501+ pingv6_ops = &real_pingv6_ops;
93502 return inet6_register_protosw(&pingv6_protosw);
93503 }
93504
93505@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93506 */
93507 void pingv6_exit(void)
93508 {
93509- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93510- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93511- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93512- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93513- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93514+ pingv6_ops = &dummy_pingv6_ops;
93515 #ifdef CONFIG_PROC_FS
93516 unregister_pernet_subsys(&ping_v6_net_ops);
93517 #endif
93518diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93519index cdaed47..515edde9 100644
93520--- a/net/ipv6/raw.c
93521+++ b/net/ipv6/raw.c
93522@@ -108,7 +108,7 @@ found:
93523 */
93524 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93525 {
93526- struct icmp6hdr *_hdr;
93527+ struct icmp6hdr _hdr;
93528 const struct icmp6hdr *hdr;
93529
93530 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93531@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93532 {
93533 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93534 skb_checksum_complete(skb)) {
93535- atomic_inc(&sk->sk_drops);
93536+ atomic_inc_unchecked(&sk->sk_drops);
93537 kfree_skb(skb);
93538 return NET_RX_DROP;
93539 }
93540@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93541 struct raw6_sock *rp = raw6_sk(sk);
93542
93543 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93544- atomic_inc(&sk->sk_drops);
93545+ atomic_inc_unchecked(&sk->sk_drops);
93546 kfree_skb(skb);
93547 return NET_RX_DROP;
93548 }
93549@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93550
93551 if (inet->hdrincl) {
93552 if (skb_checksum_complete(skb)) {
93553- atomic_inc(&sk->sk_drops);
93554+ atomic_inc_unchecked(&sk->sk_drops);
93555 kfree_skb(skb);
93556 return NET_RX_DROP;
93557 }
93558@@ -602,7 +602,7 @@ out:
93559 return err;
93560 }
93561
93562-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93563+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93564 struct flowi6 *fl6, struct dst_entry **dstp,
93565 unsigned int flags)
93566 {
93567@@ -915,12 +915,15 @@ do_confirm:
93568 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93569 char __user *optval, int optlen)
93570 {
93571+ struct icmp6_filter filter;
93572+
93573 switch (optname) {
93574 case ICMPV6_FILTER:
93575 if (optlen > sizeof(struct icmp6_filter))
93576 optlen = sizeof(struct icmp6_filter);
93577- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93578+ if (copy_from_user(&filter, optval, optlen))
93579 return -EFAULT;
93580+ raw6_sk(sk)->filter = filter;
93581 return 0;
93582 default:
93583 return -ENOPROTOOPT;
93584@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93585 char __user *optval, int __user *optlen)
93586 {
93587 int len;
93588+ struct icmp6_filter filter;
93589
93590 switch (optname) {
93591 case ICMPV6_FILTER:
93592@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93593 len = sizeof(struct icmp6_filter);
93594 if (put_user(len, optlen))
93595 return -EFAULT;
93596- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93597+ filter = raw6_sk(sk)->filter;
93598+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93599 return -EFAULT;
93600 return 0;
93601 default:
93602diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93603index 1aeb473..bea761c 100644
93604--- a/net/ipv6/reassembly.c
93605+++ b/net/ipv6/reassembly.c
93606@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93607
93608 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93609 {
93610- struct ctl_table *table;
93611+ ctl_table_no_const *table = NULL;
93612 struct ctl_table_header *hdr;
93613
93614- table = ip6_frags_ns_ctl_table;
93615 if (!net_eq(net, &init_net)) {
93616- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93617+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93618 if (table == NULL)
93619 goto err_alloc;
93620
93621@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93622 /* Don't export sysctls to unprivileged users */
93623 if (net->user_ns != &init_user_ns)
93624 table[0].procname = NULL;
93625- }
93626+ hdr = register_net_sysctl(net, "net/ipv6", table);
93627+ } else
93628+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93629
93630- hdr = register_net_sysctl(net, "net/ipv6", table);
93631 if (hdr == NULL)
93632 goto err_reg;
93633
93634@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93635 return 0;
93636
93637 err_reg:
93638- if (!net_eq(net, &init_net))
93639- kfree(table);
93640+ kfree(table);
93641 err_alloc:
93642 return -ENOMEM;
93643 }
93644diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93645index 1e32d5c..cbe3b46 100644
93646--- a/net/ipv6/route.c
93647+++ b/net/ipv6/route.c
93648@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
93649
93650 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93651 {
93652- struct ctl_table *table;
93653+ ctl_table_no_const *table;
93654
93655 table = kmemdup(ipv6_route_table_template,
93656 sizeof(ipv6_route_table_template),
93657diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93658index a51ad07..a90bc19 100644
93659--- a/net/ipv6/sit.c
93660+++ b/net/ipv6/sit.c
93661@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93662 static void ipip6_dev_free(struct net_device *dev);
93663 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93664 __be32 *v4dst);
93665-static struct rtnl_link_ops sit_link_ops __read_mostly;
93666+static struct rtnl_link_ops sit_link_ops;
93667
93668 static int sit_net_id __read_mostly;
93669 struct sit_net {
93670@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93671 #endif
93672 };
93673
93674-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93675+static struct rtnl_link_ops sit_link_ops = {
93676 .kind = "sit",
93677 .maxtype = IFLA_IPTUN_MAX,
93678 .policy = ipip6_policy,
93679diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93680index 107b2f1..72741a9 100644
93681--- a/net/ipv6/sysctl_net_ipv6.c
93682+++ b/net/ipv6/sysctl_net_ipv6.c
93683@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93684
93685 static int __net_init ipv6_sysctl_net_init(struct net *net)
93686 {
93687- struct ctl_table *ipv6_table;
93688+ ctl_table_no_const *ipv6_table;
93689 struct ctl_table *ipv6_route_table;
93690 struct ctl_table *ipv6_icmp_table;
93691 int err;
93692diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93693index 6e1649d..75ddb4c 100644
93694--- a/net/ipv6/tcp_ipv6.c
93695+++ b/net/ipv6/tcp_ipv6.c
93696@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93697 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93698 }
93699
93700+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93701+extern int grsec_enable_blackhole;
93702+#endif
93703+
93704 static void tcp_v6_hash(struct sock *sk)
93705 {
93706 if (sk->sk_state != TCP_CLOSE) {
93707@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93708 return 0;
93709
93710 reset:
93711+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93712+ if (!grsec_enable_blackhole)
93713+#endif
93714 tcp_v6_send_reset(sk, skb);
93715 discard:
93716 if (opt_skb)
93717@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93718 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93719 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93720 if (np->rxopt.bits.rxtclass)
93721- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93722+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93723 if (ipv6_opt_accepted(sk, opt_skb)) {
93724 skb_set_owner_r(opt_skb, sk);
93725 opt_skb = xchg(&np->pktoptions, opt_skb);
93726@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93727 TCP_SKB_CB(skb)->sacked = 0;
93728
93729 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93730- if (!sk)
93731+ if (!sk) {
93732+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93733+ ret = 1;
93734+#endif
93735 goto no_tcp_socket;
93736+ }
93737
93738 process:
93739- if (sk->sk_state == TCP_TIME_WAIT)
93740+ if (sk->sk_state == TCP_TIME_WAIT) {
93741+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93742+ ret = 2;
93743+#endif
93744 goto do_time_wait;
93745+ }
93746
93747 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93748 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93749@@ -1538,6 +1553,10 @@ csum_error:
93750 bad_packet:
93751 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93752 } else {
93753+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93754+ if (!grsec_enable_blackhole || (ret == 1 &&
93755+ (skb->dev->flags & IFF_LOOPBACK)))
93756+#endif
93757 tcp_v6_send_reset(NULL, skb);
93758 }
93759
93760diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93761index f405815..45a68a6 100644
93762--- a/net/ipv6/udp.c
93763+++ b/net/ipv6/udp.c
93764@@ -53,6 +53,10 @@
93765 #include <trace/events/skb.h>
93766 #include "udp_impl.h"
93767
93768+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93769+extern int grsec_enable_blackhole;
93770+#endif
93771+
93772 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93773 {
93774 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93775@@ -420,7 +424,7 @@ try_again:
93776 if (unlikely(err)) {
93777 trace_kfree_skb(skb, udpv6_recvmsg);
93778 if (!peeked) {
93779- atomic_inc(&sk->sk_drops);
93780+ atomic_inc_unchecked(&sk->sk_drops);
93781 if (is_udp4)
93782 UDP_INC_STATS_USER(sock_net(sk),
93783 UDP_MIB_INERRORS,
93784@@ -666,7 +670,7 @@ csum_error:
93785 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93786 drop:
93787 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93788- atomic_inc(&sk->sk_drops);
93789+ atomic_inc_unchecked(&sk->sk_drops);
93790 kfree_skb(skb);
93791 return -1;
93792 }
93793@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93794 if (likely(skb1 == NULL))
93795 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93796 if (!skb1) {
93797- atomic_inc(&sk->sk_drops);
93798+ atomic_inc_unchecked(&sk->sk_drops);
93799 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93800 IS_UDPLITE(sk));
93801 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93802@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93803 goto csum_error;
93804
93805 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93806+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93807+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93808+#endif
93809 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93810
93811 kfree_skb(skb);
93812diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93813index 23ed03d..6532e67 100644
93814--- a/net/ipv6/xfrm6_policy.c
93815+++ b/net/ipv6/xfrm6_policy.c
93816@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93817 }
93818 }
93819
93820-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93821+static int xfrm6_garbage_collect(struct dst_ops *ops)
93822 {
93823 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93824
93825- xfrm6_policy_afinfo.garbage_collect(net);
93826+ xfrm_garbage_collect_deferred(net);
93827 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93828 }
93829
93830@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93831
93832 static int __net_init xfrm6_net_init(struct net *net)
93833 {
93834- struct ctl_table *table;
93835+ ctl_table_no_const *table = NULL;
93836 struct ctl_table_header *hdr;
93837
93838- table = xfrm6_policy_table;
93839 if (!net_eq(net, &init_net)) {
93840- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93841+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93842 if (!table)
93843 goto err_alloc;
93844
93845 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93846- }
93847+ hdr = register_net_sysctl(net, "net/ipv6", table);
93848+ } else
93849+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93850
93851- hdr = register_net_sysctl(net, "net/ipv6", table);
93852 if (!hdr)
93853 goto err_reg;
93854
93855@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93856 return 0;
93857
93858 err_reg:
93859- if (!net_eq(net, &init_net))
93860- kfree(table);
93861+ kfree(table);
93862 err_alloc:
93863 return -ENOMEM;
93864 }
93865diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93866index 41ac7938..75e3bb1 100644
93867--- a/net/irda/ircomm/ircomm_tty.c
93868+++ b/net/irda/ircomm/ircomm_tty.c
93869@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93870 add_wait_queue(&port->open_wait, &wait);
93871
93872 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93873- __FILE__, __LINE__, tty->driver->name, port->count);
93874+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93875
93876 spin_lock_irqsave(&port->lock, flags);
93877 if (!tty_hung_up_p(filp))
93878- port->count--;
93879+ atomic_dec(&port->count);
93880 port->blocked_open++;
93881 spin_unlock_irqrestore(&port->lock, flags);
93882
93883@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93884 }
93885
93886 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93887- __FILE__, __LINE__, tty->driver->name, port->count);
93888+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93889
93890 schedule();
93891 }
93892@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93893
93894 spin_lock_irqsave(&port->lock, flags);
93895 if (!tty_hung_up_p(filp))
93896- port->count++;
93897+ atomic_inc(&port->count);
93898 port->blocked_open--;
93899 spin_unlock_irqrestore(&port->lock, flags);
93900
93901 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93902- __FILE__, __LINE__, tty->driver->name, port->count);
93903+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93904
93905 if (!retval)
93906 port->flags |= ASYNC_NORMAL_ACTIVE;
93907@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93908
93909 /* ++ is not atomic, so this should be protected - Jean II */
93910 spin_lock_irqsave(&self->port.lock, flags);
93911- self->port.count++;
93912+ atomic_inc(&self->port.count);
93913 spin_unlock_irqrestore(&self->port.lock, flags);
93914 tty_port_tty_set(&self->port, tty);
93915
93916 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93917- self->line, self->port.count);
93918+ self->line, atomic_read(&self->port.count));
93919
93920 /* Not really used by us, but lets do it anyway */
93921 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93922@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93923 tty_kref_put(port->tty);
93924 }
93925 port->tty = NULL;
93926- port->count = 0;
93927+ atomic_set(&port->count, 0);
93928 spin_unlock_irqrestore(&port->lock, flags);
93929
93930 wake_up_interruptible(&port->open_wait);
93931@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93932 seq_putc(m, '\n');
93933
93934 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93935- seq_printf(m, "Open count: %d\n", self->port.count);
93936+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93937 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93938 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93939
93940diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93941index 168aff5..9d43132 100644
93942--- a/net/iucv/af_iucv.c
93943+++ b/net/iucv/af_iucv.c
93944@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93945
93946 write_lock_bh(&iucv_sk_list.lock);
93947
93948- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93949+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93950 while (__iucv_get_sock_by_name(name)) {
93951 sprintf(name, "%08x",
93952- atomic_inc_return(&iucv_sk_list.autobind_name));
93953+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93954 }
93955
93956 write_unlock_bh(&iucv_sk_list.lock);
93957diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93958index cd5b8ec..f205e6b 100644
93959--- a/net/iucv/iucv.c
93960+++ b/net/iucv/iucv.c
93961@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93962 return NOTIFY_OK;
93963 }
93964
93965-static struct notifier_block __refdata iucv_cpu_notifier = {
93966+static struct notifier_block iucv_cpu_notifier = {
93967 .notifier_call = iucv_cpu_notify,
93968 };
93969
93970diff --git a/net/key/af_key.c b/net/key/af_key.c
93971index ab8bd2c..3a3eb81 100644
93972--- a/net/key/af_key.c
93973+++ b/net/key/af_key.c
93974@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
93975
93976 x->id.proto = proto;
93977 x->id.spi = sa->sadb_sa_spi;
93978- x->props.replay_window = sa->sadb_sa_replay;
93979+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
93980+ (sizeof(x->replay.bitmap) * 8));
93981 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
93982 x->props.flags |= XFRM_STATE_NOECN;
93983 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
93984@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93985 static u32 get_acqseq(void)
93986 {
93987 u32 res;
93988- static atomic_t acqseq;
93989+ static atomic_unchecked_t acqseq;
93990
93991 do {
93992- res = atomic_inc_return(&acqseq);
93993+ res = atomic_inc_return_unchecked(&acqseq);
93994 } while (!res);
93995 return res;
93996 }
93997diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
93998index b076e83..793e6ff 100644
93999--- a/net/l2tp/l2tp_core.c
94000+++ b/net/l2tp/l2tp_core.c
94001@@ -501,6 +501,7 @@ out:
94002 static inline int l2tp_verify_udp_checksum(struct sock *sk,
94003 struct sk_buff *skb)
94004 {
94005+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
94006 struct udphdr *uh = udp_hdr(skb);
94007 u16 ulen = ntohs(uh->len);
94008 __wsum psum;
94009diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94010index 43dd752..63a23bc 100644
94011--- a/net/mac80211/cfg.c
94012+++ b/net/mac80211/cfg.c
94013@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94014 ret = ieee80211_vif_use_channel(sdata, chandef,
94015 IEEE80211_CHANCTX_EXCLUSIVE);
94016 }
94017- } else if (local->open_count == local->monitors) {
94018+ } else if (local_read(&local->open_count) == local->monitors) {
94019 local->_oper_chandef = *chandef;
94020 ieee80211_hw_config(local, 0);
94021 }
94022@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94023 else
94024 local->probe_req_reg--;
94025
94026- if (!local->open_count)
94027+ if (!local_read(&local->open_count))
94028 break;
94029
94030 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94031@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94032 if (chanctx_conf) {
94033 *chandef = chanctx_conf->def;
94034 ret = 0;
94035- } else if (local->open_count > 0 &&
94036- local->open_count == local->monitors &&
94037+ } else if (local_read(&local->open_count) > 0 &&
94038+ local_read(&local->open_count) == local->monitors &&
94039 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94040 if (local->use_chanctx)
94041 *chandef = local->monitor_chandef;
94042diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94043index 8412a30..6e00181 100644
94044--- a/net/mac80211/ieee80211_i.h
94045+++ b/net/mac80211/ieee80211_i.h
94046@@ -28,6 +28,7 @@
94047 #include <net/ieee80211_radiotap.h>
94048 #include <net/cfg80211.h>
94049 #include <net/mac80211.h>
94050+#include <asm/local.h>
94051 #include "key.h"
94052 #include "sta_info.h"
94053 #include "debug.h"
94054@@ -907,7 +908,7 @@ struct ieee80211_local {
94055 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94056 spinlock_t queue_stop_reason_lock;
94057
94058- int open_count;
94059+ local_t open_count;
94060 int monitors, cooked_mntrs;
94061 /* number of interfaces with corresponding FIF_ flags */
94062 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94063diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94064index cc11759..11d5541 100644
94065--- a/net/mac80211/iface.c
94066+++ b/net/mac80211/iface.c
94067@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94068 break;
94069 }
94070
94071- if (local->open_count == 0) {
94072+ if (local_read(&local->open_count) == 0) {
94073 res = drv_start(local);
94074 if (res)
94075 goto err_del_bss;
94076@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94077 res = drv_add_interface(local, sdata);
94078 if (res)
94079 goto err_stop;
94080- } else if (local->monitors == 0 && local->open_count == 0) {
94081+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94082 res = ieee80211_add_virtual_monitor(local);
94083 if (res)
94084 goto err_stop;
94085@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94086 atomic_inc(&local->iff_promiscs);
94087
94088 if (coming_up)
94089- local->open_count++;
94090+ local_inc(&local->open_count);
94091
94092 if (hw_reconf_flags)
94093 ieee80211_hw_config(local, hw_reconf_flags);
94094@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94095 err_del_interface:
94096 drv_remove_interface(local, sdata);
94097 err_stop:
94098- if (!local->open_count)
94099+ if (!local_read(&local->open_count))
94100 drv_stop(local);
94101 err_del_bss:
94102 sdata->bss = NULL;
94103@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94104 }
94105
94106 if (going_down)
94107- local->open_count--;
94108+ local_dec(&local->open_count);
94109
94110 switch (sdata->vif.type) {
94111 case NL80211_IFTYPE_AP_VLAN:
94112@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94113 }
94114 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94115
94116- if (local->open_count == 0)
94117+ if (local_read(&local->open_count) == 0)
94118 ieee80211_clear_tx_pending(local);
94119
94120 /*
94121@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94122
94123 ieee80211_recalc_ps(local, -1);
94124
94125- if (local->open_count == 0) {
94126+ if (local_read(&local->open_count) == 0) {
94127 ieee80211_stop_device(local);
94128
94129 /* no reconfiguring after stop! */
94130@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94131 ieee80211_configure_filter(local);
94132 ieee80211_hw_config(local, hw_reconf_flags);
94133
94134- if (local->monitors == local->open_count)
94135+ if (local->monitors == local_read(&local->open_count))
94136 ieee80211_add_virtual_monitor(local);
94137 }
94138
94139diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94140index 091088a..daf43c7 100644
94141--- a/net/mac80211/main.c
94142+++ b/net/mac80211/main.c
94143@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94144 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94145 IEEE80211_CONF_CHANGE_POWER);
94146
94147- if (changed && local->open_count) {
94148+ if (changed && local_read(&local->open_count)) {
94149 ret = drv_config(local, changed);
94150 /*
94151 * Goal:
94152diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94153index 3401262..d5cd68d 100644
94154--- a/net/mac80211/pm.c
94155+++ b/net/mac80211/pm.c
94156@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94157 struct ieee80211_sub_if_data *sdata;
94158 struct sta_info *sta;
94159
94160- if (!local->open_count)
94161+ if (!local_read(&local->open_count))
94162 goto suspend;
94163
94164 ieee80211_scan_cancel(local);
94165@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94166 cancel_work_sync(&local->dynamic_ps_enable_work);
94167 del_timer_sync(&local->dynamic_ps_timer);
94168
94169- local->wowlan = wowlan && local->open_count;
94170+ local->wowlan = wowlan && local_read(&local->open_count);
94171 if (local->wowlan) {
94172 int err = drv_suspend(local, wowlan);
94173 if (err < 0) {
94174@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94175 WARN_ON(!list_empty(&local->chanctx_list));
94176
94177 /* stop hardware - this must stop RX */
94178- if (local->open_count)
94179+ if (local_read(&local->open_count))
94180 ieee80211_stop_device(local);
94181
94182 suspend:
94183diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94184index 30d58d2..449ac8e 100644
94185--- a/net/mac80211/rate.c
94186+++ b/net/mac80211/rate.c
94187@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94188
94189 ASSERT_RTNL();
94190
94191- if (local->open_count)
94192+ if (local_read(&local->open_count))
94193 return -EBUSY;
94194
94195 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94196diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94197index c97a065..ff61928 100644
94198--- a/net/mac80211/rc80211_pid_debugfs.c
94199+++ b/net/mac80211/rc80211_pid_debugfs.c
94200@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94201
94202 spin_unlock_irqrestore(&events->lock, status);
94203
94204- if (copy_to_user(buf, pb, p))
94205+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94206 return -EFAULT;
94207
94208 return p;
94209diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94210index 2265445..ba14971 100644
94211--- a/net/mac80211/util.c
94212+++ b/net/mac80211/util.c
94213@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94214 }
94215 #endif
94216 /* everything else happens only if HW was up & running */
94217- if (!local->open_count)
94218+ if (!local_read(&local->open_count))
94219 goto wake_up;
94220
94221 /*
94222@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94223 local->in_reconfig = false;
94224 barrier();
94225
94226- if (local->monitors == local->open_count && local->monitors > 0)
94227+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94228 ieee80211_add_virtual_monitor(local);
94229
94230 /*
94231diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94232index 56d22ca..87c778f 100644
94233--- a/net/netfilter/Kconfig
94234+++ b/net/netfilter/Kconfig
94235@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94236
94237 To compile it as a module, choose M here. If unsure, say N.
94238
94239+config NETFILTER_XT_MATCH_GRADM
94240+ tristate '"gradm" match support'
94241+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94242+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94243+ ---help---
94244+ The gradm match allows to match on grsecurity RBAC being enabled.
94245+ It is useful when iptables rules are applied early on bootup to
94246+ prevent connections to the machine (except from a trusted host)
94247+ while the RBAC system is disabled.
94248+
94249 config NETFILTER_XT_MATCH_HASHLIMIT
94250 tristate '"hashlimit" match support'
94251 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94252diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94253index a1abf87..dbcb7ee 100644
94254--- a/net/netfilter/Makefile
94255+++ b/net/netfilter/Makefile
94256@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94257 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94258 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94259 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94260+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94261 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94262 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94263 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94264diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94265index f771390..145b765 100644
94266--- a/net/netfilter/ipset/ip_set_core.c
94267+++ b/net/netfilter/ipset/ip_set_core.c
94268@@ -1820,7 +1820,7 @@ done:
94269 return ret;
94270 }
94271
94272-static struct nf_sockopt_ops so_set __read_mostly = {
94273+static struct nf_sockopt_ops so_set = {
94274 .pf = PF_INET,
94275 .get_optmin = SO_IP_SET,
94276 .get_optmax = SO_IP_SET + 1,
94277diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94278index 4c8e5c0..5a79b4d 100644
94279--- a/net/netfilter/ipvs/ip_vs_conn.c
94280+++ b/net/netfilter/ipvs/ip_vs_conn.c
94281@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94282 /* Increase the refcnt counter of the dest */
94283 ip_vs_dest_hold(dest);
94284
94285- conn_flags = atomic_read(&dest->conn_flags);
94286+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94287 if (cp->protocol != IPPROTO_UDP)
94288 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94289 flags = cp->flags;
94290@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94291
94292 cp->control = NULL;
94293 atomic_set(&cp->n_control, 0);
94294- atomic_set(&cp->in_pkts, 0);
94295+ atomic_set_unchecked(&cp->in_pkts, 0);
94296
94297 cp->packet_xmit = NULL;
94298 cp->app = NULL;
94299@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94300
94301 /* Don't drop the entry if its number of incoming packets is not
94302 located in [0, 8] */
94303- i = atomic_read(&cp->in_pkts);
94304+ i = atomic_read_unchecked(&cp->in_pkts);
94305 if (i > 8 || i < 0) return 0;
94306
94307 if (!todrop_rate[i]) return 0;
94308diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94309index 4f69e83..da2d8bf 100644
94310--- a/net/netfilter/ipvs/ip_vs_core.c
94311+++ b/net/netfilter/ipvs/ip_vs_core.c
94312@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94313 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94314 /* do not touch skb anymore */
94315
94316- atomic_inc(&cp->in_pkts);
94317+ atomic_inc_unchecked(&cp->in_pkts);
94318 ip_vs_conn_put(cp);
94319 return ret;
94320 }
94321@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94322 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94323 pkts = sysctl_sync_threshold(ipvs);
94324 else
94325- pkts = atomic_add_return(1, &cp->in_pkts);
94326+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94327
94328 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94329 ip_vs_sync_conn(net, cp, pkts);
94330diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94331index c8148e4..eff604f 100644
94332--- a/net/netfilter/ipvs/ip_vs_ctl.c
94333+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94334@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94335 */
94336 ip_vs_rs_hash(ipvs, dest);
94337 }
94338- atomic_set(&dest->conn_flags, conn_flags);
94339+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94340
94341 /* bind the service */
94342 if (!dest->svc) {
94343@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94344 * align with netns init in ip_vs_control_net_init()
94345 */
94346
94347-static struct ctl_table vs_vars[] = {
94348+static ctl_table_no_const vs_vars[] __read_only = {
94349 {
94350 .procname = "amemthresh",
94351 .maxlen = sizeof(int),
94352@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94353 " %-7s %-6d %-10d %-10d\n",
94354 &dest->addr.in6,
94355 ntohs(dest->port),
94356- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94357+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94358 atomic_read(&dest->weight),
94359 atomic_read(&dest->activeconns),
94360 atomic_read(&dest->inactconns));
94361@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94362 "%-7s %-6d %-10d %-10d\n",
94363 ntohl(dest->addr.ip),
94364 ntohs(dest->port),
94365- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94366+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94367 atomic_read(&dest->weight),
94368 atomic_read(&dest->activeconns),
94369 atomic_read(&dest->inactconns));
94370@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94371
94372 entry.addr = dest->addr.ip;
94373 entry.port = dest->port;
94374- entry.conn_flags = atomic_read(&dest->conn_flags);
94375+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94376 entry.weight = atomic_read(&dest->weight);
94377 entry.u_threshold = dest->u_threshold;
94378 entry.l_threshold = dest->l_threshold;
94379@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94380 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94381 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94382 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94383- (atomic_read(&dest->conn_flags) &
94384+ (atomic_read_unchecked(&dest->conn_flags) &
94385 IP_VS_CONN_F_FWD_MASK)) ||
94386 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94387 atomic_read(&dest->weight)) ||
94388@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94389 {
94390 int idx;
94391 struct netns_ipvs *ipvs = net_ipvs(net);
94392- struct ctl_table *tbl;
94393+ ctl_table_no_const *tbl;
94394
94395 atomic_set(&ipvs->dropentry, 0);
94396 spin_lock_init(&ipvs->dropentry_lock);
94397diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94398index 1383b0e..a486da1 100644
94399--- a/net/netfilter/ipvs/ip_vs_lblc.c
94400+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94401@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94402 * IPVS LBLC sysctl table
94403 */
94404 #ifdef CONFIG_SYSCTL
94405-static struct ctl_table vs_vars_table[] = {
94406+static ctl_table_no_const vs_vars_table[] __read_only = {
94407 {
94408 .procname = "lblc_expiration",
94409 .data = NULL,
94410diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94411index 3cd85b2..dfab2b8 100644
94412--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94413+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94414@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94415 * IPVS LBLCR sysctl table
94416 */
94417
94418-static struct ctl_table vs_vars_table[] = {
94419+static ctl_table_no_const vs_vars_table[] __read_only = {
94420 {
94421 .procname = "lblcr_expiration",
94422 .data = NULL,
94423diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94424index f448471..995f131 100644
94425--- a/net/netfilter/ipvs/ip_vs_sync.c
94426+++ b/net/netfilter/ipvs/ip_vs_sync.c
94427@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94428 cp = cp->control;
94429 if (cp) {
94430 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94431- pkts = atomic_add_return(1, &cp->in_pkts);
94432+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94433 else
94434 pkts = sysctl_sync_threshold(ipvs);
94435 ip_vs_sync_conn(net, cp->control, pkts);
94436@@ -771,7 +771,7 @@ control:
94437 if (!cp)
94438 return;
94439 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94440- pkts = atomic_add_return(1, &cp->in_pkts);
94441+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94442 else
94443 pkts = sysctl_sync_threshold(ipvs);
94444 goto sloop;
94445@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94446
94447 if (opt)
94448 memcpy(&cp->in_seq, opt, sizeof(*opt));
94449- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94450+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94451 cp->state = state;
94452 cp->old_state = cp->state;
94453 /*
94454diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94455index c47444e..b0961c6 100644
94456--- a/net/netfilter/ipvs/ip_vs_xmit.c
94457+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94458@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94459 else
94460 rc = NF_ACCEPT;
94461 /* do not touch skb anymore */
94462- atomic_inc(&cp->in_pkts);
94463+ atomic_inc_unchecked(&cp->in_pkts);
94464 goto out;
94465 }
94466
94467@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94468 else
94469 rc = NF_ACCEPT;
94470 /* do not touch skb anymore */
94471- atomic_inc(&cp->in_pkts);
94472+ atomic_inc_unchecked(&cp->in_pkts);
94473 goto out;
94474 }
94475
94476diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94477index 2d3030a..7ba1c0a 100644
94478--- a/net/netfilter/nf_conntrack_acct.c
94479+++ b/net/netfilter/nf_conntrack_acct.c
94480@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94481 #ifdef CONFIG_SYSCTL
94482 static int nf_conntrack_acct_init_sysctl(struct net *net)
94483 {
94484- struct ctl_table *table;
94485+ ctl_table_no_const *table;
94486
94487 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94488 GFP_KERNEL);
94489diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94490index 0283bae..5febcb0 100644
94491--- a/net/netfilter/nf_conntrack_core.c
94492+++ b/net/netfilter/nf_conntrack_core.c
94493@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94494 #define DYING_NULLS_VAL ((1<<30)+1)
94495 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94496
94497+#ifdef CONFIG_GRKERNSEC_HIDESYM
94498+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94499+#endif
94500+
94501 int nf_conntrack_init_net(struct net *net)
94502 {
94503 int ret;
94504@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94505 goto err_stat;
94506 }
94507
94508+#ifdef CONFIG_GRKERNSEC_HIDESYM
94509+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94510+#else
94511 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94512+#endif
94513 if (!net->ct.slabname) {
94514 ret = -ENOMEM;
94515 goto err_slabname;
94516diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94517index 1df1761..ce8b88a 100644
94518--- a/net/netfilter/nf_conntrack_ecache.c
94519+++ b/net/netfilter/nf_conntrack_ecache.c
94520@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94521 #ifdef CONFIG_SYSCTL
94522 static int nf_conntrack_event_init_sysctl(struct net *net)
94523 {
94524- struct ctl_table *table;
94525+ ctl_table_no_const *table;
94526
94527 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94528 GFP_KERNEL);
94529diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94530index 974a2a4..52cc6ff 100644
94531--- a/net/netfilter/nf_conntrack_helper.c
94532+++ b/net/netfilter/nf_conntrack_helper.c
94533@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94534
94535 static int nf_conntrack_helper_init_sysctl(struct net *net)
94536 {
94537- struct ctl_table *table;
94538+ ctl_table_no_const *table;
94539
94540 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94541 GFP_KERNEL);
94542diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94543index 0ab9636..cea3c6a 100644
94544--- a/net/netfilter/nf_conntrack_proto.c
94545+++ b/net/netfilter/nf_conntrack_proto.c
94546@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94547
94548 static void
94549 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94550- struct ctl_table **table,
94551+ ctl_table_no_const **table,
94552 unsigned int users)
94553 {
94554 if (users > 0)
94555diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94556index a99b6c3..cb372f9 100644
94557--- a/net/netfilter/nf_conntrack_proto_dccp.c
94558+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94559@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94560 const char *msg;
94561 u_int8_t state;
94562
94563- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94564+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94565 BUG_ON(dh == NULL);
94566
94567 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94568@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94569 out_invalid:
94570 if (LOG_INVALID(net, IPPROTO_DCCP))
94571 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94572- NULL, msg);
94573+ NULL, "%s", msg);
94574 return false;
94575 }
94576
94577@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94578 u_int8_t type, old_state, new_state;
94579 enum ct_dccp_roles role;
94580
94581- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94582+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94583 BUG_ON(dh == NULL);
94584 type = dh->dccph_type;
94585
94586@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94587 unsigned int cscov;
94588 const char *msg;
94589
94590- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94591+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94592 if (dh == NULL) {
94593 msg = "nf_ct_dccp: short packet ";
94594 goto out_invalid;
94595@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94596
94597 out_invalid:
94598 if (LOG_INVALID(net, IPPROTO_DCCP))
94599- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94600+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94601 return -NF_ACCEPT;
94602 }
94603
94604diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94605index f641751..d3c5b51 100644
94606--- a/net/netfilter/nf_conntrack_standalone.c
94607+++ b/net/netfilter/nf_conntrack_standalone.c
94608@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94609
94610 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94611 {
94612- struct ctl_table *table;
94613+ ctl_table_no_const *table;
94614
94615 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94616 GFP_KERNEL);
94617diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94618index 902fb0a..87f7fdb 100644
94619--- a/net/netfilter/nf_conntrack_timestamp.c
94620+++ b/net/netfilter/nf_conntrack_timestamp.c
94621@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94622 #ifdef CONFIG_SYSCTL
94623 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94624 {
94625- struct ctl_table *table;
94626+ ctl_table_no_const *table;
94627
94628 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94629 GFP_KERNEL);
94630diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94631index 85296d4..8becdec 100644
94632--- a/net/netfilter/nf_log.c
94633+++ b/net/netfilter/nf_log.c
94634@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94635
94636 #ifdef CONFIG_SYSCTL
94637 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94638-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94639+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94640
94641 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94642 void __user *buffer, size_t *lenp, loff_t *ppos)
94643@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94644 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94645 mutex_unlock(&nf_log_mutex);
94646 } else {
94647+ ctl_table_no_const nf_log_table = *table;
94648+
94649 mutex_lock(&nf_log_mutex);
94650 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94651 lockdep_is_held(&nf_log_mutex));
94652 if (!logger)
94653- table->data = "NONE";
94654+ nf_log_table.data = "NONE";
94655 else
94656- table->data = logger->name;
94657- r = proc_dostring(table, write, buffer, lenp, ppos);
94658+ nf_log_table.data = logger->name;
94659+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94660 mutex_unlock(&nf_log_mutex);
94661 }
94662
94663diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94664index f042ae5..30ea486 100644
94665--- a/net/netfilter/nf_sockopt.c
94666+++ b/net/netfilter/nf_sockopt.c
94667@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94668 }
94669 }
94670
94671- list_add(&reg->list, &nf_sockopts);
94672+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94673 out:
94674 mutex_unlock(&nf_sockopt_mutex);
94675 return ret;
94676@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94677 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94678 {
94679 mutex_lock(&nf_sockopt_mutex);
94680- list_del(&reg->list);
94681+ pax_list_del((struct list_head *)&reg->list);
94682 mutex_unlock(&nf_sockopt_mutex);
94683 }
94684 EXPORT_SYMBOL(nf_unregister_sockopt);
94685diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94686index d92cc31..e46f350 100644
94687--- a/net/netfilter/nfnetlink_log.c
94688+++ b/net/netfilter/nfnetlink_log.c
94689@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94690 struct nfnl_log_net {
94691 spinlock_t instances_lock;
94692 struct hlist_head instance_table[INSTANCE_BUCKETS];
94693- atomic_t global_seq;
94694+ atomic_unchecked_t global_seq;
94695 };
94696
94697 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94698@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94699 /* global sequence number */
94700 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94701 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94702- htonl(atomic_inc_return(&log->global_seq))))
94703+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94704 goto nla_put_failure;
94705
94706 if (data_len) {
94707diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94708new file mode 100644
94709index 0000000..c566332
94710--- /dev/null
94711+++ b/net/netfilter/xt_gradm.c
94712@@ -0,0 +1,51 @@
94713+/*
94714+ * gradm match for netfilter
94715