]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.1-201309262056.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.1-201309262056.patch
CommitLineData
20954299
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 efd2396..682975d 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELEASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1224,6 +1290,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1363,17 +1431,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1383,11 +1455,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 43594d5..da71e62 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1791,7 +1791,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index 04aeb02..73b70dd 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2095index 2b8114f..8fe9bcf 100644
2096--- a/arch/arm/include/asm/thread_info.h
2097+++ b/arch/arm/include/asm/thread_info.h
2098@@ -77,9 +77,9 @@ struct thread_info {
2099 .flags = 0, \
2100 .preempt_count = INIT_PREEMPT_COUNT, \
2101 .addr_limit = KERNEL_DS, \
2102- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2103- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2104- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2105+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2106+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2107+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2108 .restart_block = { \
2109 .fn = do_no_restart_syscall, \
2110 }, \
2111@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2112 #define TIF_SYSCALL_AUDIT 9
2113 #define TIF_SYSCALL_TRACEPOINT 10
2114 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2115-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2116+/* within 8 bits of TIF_SYSCALL_TRACE
2117+ * to meet flexible second operand requirements
2118+ */
2119+#define TIF_GRSEC_SETXID 12
2120+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2121 #define TIF_USING_IWMMXT 17
2122 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2123 #define TIF_RESTORE_SIGMASK 20
2124@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2125 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2126 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2127 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2128+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2129
2130 /* Checks for any syscall work in entry-common.S */
2131 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2132- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2133+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2134
2135 /*
2136 * Change these and you break ASM code in entry-common.S
2137diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2138index 7e1f760..de33b13 100644
2139--- a/arch/arm/include/asm/uaccess.h
2140+++ b/arch/arm/include/asm/uaccess.h
2141@@ -18,6 +18,7 @@
2142 #include <asm/domain.h>
2143 #include <asm/unified.h>
2144 #include <asm/compiler.h>
2145+#include <asm/pgtable.h>
2146
2147 #define VERIFY_READ 0
2148 #define VERIFY_WRITE 1
2149@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2150 static inline void set_fs(mm_segment_t fs)
2151 {
2152 current_thread_info()->addr_limit = fs;
2153- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2154+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2155 }
2156
2157 #define segment_eq(a,b) ((a) == (b))
2158
2159+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2160+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2161+
2162+static inline void pax_open_userland(void)
2163+{
2164+
2165+#ifdef CONFIG_PAX_MEMORY_UDEREF
2166+ if (segment_eq(get_fs(), USER_DS)) {
2167+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2168+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2169+ }
2170+#endif
2171+
2172+}
2173+
2174+static inline void pax_close_userland(void)
2175+{
2176+
2177+#ifdef CONFIG_PAX_MEMORY_UDEREF
2178+ if (segment_eq(get_fs(), USER_DS)) {
2179+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2180+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2181+ }
2182+#endif
2183+
2184+}
2185+
2186 #define __addr_ok(addr) ({ \
2187 unsigned long flag; \
2188 __asm__("cmp %2, %0; movlo %0, #0" \
2189@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2190
2191 #define get_user(x,p) \
2192 ({ \
2193+ int __e; \
2194 might_fault(); \
2195- __get_user_check(x,p); \
2196+ pax_open_userland(); \
2197+ __e = __get_user_check(x,p); \
2198+ pax_close_userland(); \
2199+ __e; \
2200 })
2201
2202 extern int __put_user_1(void *, unsigned int);
2203@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2204
2205 #define put_user(x,p) \
2206 ({ \
2207+ int __e; \
2208 might_fault(); \
2209- __put_user_check(x,p); \
2210+ pax_open_userland(); \
2211+ __e = __put_user_check(x,p); \
2212+ pax_close_userland(); \
2213+ __e; \
2214 })
2215
2216 #else /* CONFIG_MMU */
2217@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2218 #define __get_user(x,ptr) \
2219 ({ \
2220 long __gu_err = 0; \
2221+ pax_open_userland(); \
2222 __get_user_err((x),(ptr),__gu_err); \
2223+ pax_close_userland(); \
2224 __gu_err; \
2225 })
2226
2227 #define __get_user_error(x,ptr,err) \
2228 ({ \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),err); \
2231+ pax_close_userland(); \
2232 (void) 0; \
2233 })
2234
2235@@ -312,13 +352,17 @@ do { \
2236 #define __put_user(x,ptr) \
2237 ({ \
2238 long __pu_err = 0; \
2239+ pax_open_userland(); \
2240 __put_user_err((x),(ptr),__pu_err); \
2241+ pax_close_userland(); \
2242 __pu_err; \
2243 })
2244
2245 #define __put_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -418,11 +462,44 @@ do { \
2254
2255
2256 #ifdef CONFIG_MMU
2257-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2258-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2259+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2261+
2262+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2263+{
2264+ unsigned long ret;
2265+
2266+ check_object_size(to, n, false);
2267+ pax_open_userland();
2268+ ret = ___copy_from_user(to, from, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2274+{
2275+ unsigned long ret;
2276+
2277+ check_object_size(from, n, true);
2278+ pax_open_userland();
2279+ ret = ___copy_to_user(to, from, n);
2280+ pax_close_userland();
2281+ return ret;
2282+}
2283+
2284 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2285-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2286+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2287 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2288+
2289+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+ pax_open_userland();
2293+ ret = ___clear_user(addr, n);
2294+ pax_close_userland();
2295+ return ret;
2296+}
2297+
2298 #else
2299 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2300 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2301@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2302
2303 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2304 {
2305+ if ((long)n < 0)
2306+ return n;
2307+
2308 if (access_ok(VERIFY_READ, from, n))
2309 n = __copy_from_user(to, from, n);
2310 else /* security hole - plug it */
2311@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2312
2313 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2314 {
2315+ if ((long)n < 0)
2316+ return n;
2317+
2318 if (access_ok(VERIFY_WRITE, to, n))
2319 n = __copy_to_user(to, from, n);
2320 return n;
2321diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2322index 5af0ed1..cea83883 100644
2323--- a/arch/arm/include/uapi/asm/ptrace.h
2324+++ b/arch/arm/include/uapi/asm/ptrace.h
2325@@ -92,7 +92,7 @@
2326 * ARMv7 groups of PSR bits
2327 */
2328 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2329-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2330+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2331 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2332 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2333
2334diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2335index 60d3b73..e5a0f22 100644
2336--- a/arch/arm/kernel/armksyms.c
2337+++ b/arch/arm/kernel/armksyms.c
2338@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2339
2340 /* networking */
2341 EXPORT_SYMBOL(csum_partial);
2342-EXPORT_SYMBOL(csum_partial_copy_from_user);
2343+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2344 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2345 EXPORT_SYMBOL(__csum_ipv6_magic);
2346
2347@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2348 #ifdef CONFIG_MMU
2349 EXPORT_SYMBOL(copy_page);
2350
2351-EXPORT_SYMBOL(__copy_from_user);
2352-EXPORT_SYMBOL(__copy_to_user);
2353-EXPORT_SYMBOL(__clear_user);
2354+EXPORT_SYMBOL(___copy_from_user);
2355+EXPORT_SYMBOL(___copy_to_user);
2356+EXPORT_SYMBOL(___clear_user);
2357
2358 EXPORT_SYMBOL(__get_user_1);
2359 EXPORT_SYMBOL(__get_user_2);
2360diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2361index 9cbe70c..a7b5e34 100644
2362--- a/arch/arm/kernel/entry-armv.S
2363+++ b/arch/arm/kernel/entry-armv.S
2364@@ -47,6 +47,87 @@
2365 9997:
2366 .endm
2367
2368+ .macro pax_enter_kernel
2369+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2370+ @ make aligned space for saved DACR
2371+ sub sp, sp, #8
2372+ @ save regs
2373+ stmdb sp!, {r1, r2}
2374+ @ read DACR from cpu_domain into r1
2375+ mov r2, sp
2376+ @ assume 8K pages, since we have to split the immediate in two
2377+ bic r2, r2, #(0x1fc0)
2378+ bic r2, r2, #(0x3f)
2379+ ldr r1, [r2, #TI_CPU_DOMAIN]
2380+ @ store old DACR on stack
2381+ str r1, [sp, #8]
2382+#ifdef CONFIG_PAX_KERNEXEC
2383+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2384+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2385+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2386+#endif
2387+#ifdef CONFIG_PAX_MEMORY_UDEREF
2388+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2389+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2390+#endif
2391+ @ write r1 to current_thread_info()->cpu_domain
2392+ str r1, [r2, #TI_CPU_DOMAIN]
2393+ @ write r1 to DACR
2394+ mcr p15, 0, r1, c3, c0, 0
2395+ @ instruction sync
2396+ instr_sync
2397+ @ restore regs
2398+ ldmia sp!, {r1, r2}
2399+#endif
2400+ .endm
2401+
2402+ .macro pax_open_userland
2403+#ifdef CONFIG_PAX_MEMORY_UDEREF
2404+ @ save regs
2405+ stmdb sp!, {r0, r1}
2406+ @ read DACR from cpu_domain into r1
2407+ mov r0, sp
2408+ @ assume 8K pages, since we have to split the immediate in two
2409+ bic r0, r0, #(0x1fc0)
2410+ bic r0, r0, #(0x3f)
2411+ ldr r1, [r0, #TI_CPU_DOMAIN]
2412+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r0, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r0, r1}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_close_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ @ write r1 to current_thread_info()->cpu_domain
2439+ str r1, [r0, #TI_CPU_DOMAIN]
2440+ @ write r1 to DACR
2441+ mcr p15, 0, r1, c3, c0, 0
2442+ @ instruction sync
2443+ instr_sync
2444+ @ restore regs
2445+ ldmia sp!, {r0, r1}
2446+#endif
2447+ .endm
2448+
2449 .macro pabt_helper
2450 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2451 #ifdef MULTI_PABORT
2452@@ -89,11 +170,15 @@
2453 * Invalid mode handlers
2454 */
2455 .macro inv_entry, reason
2456+
2457+ pax_enter_kernel
2458+
2459 sub sp, sp, #S_FRAME_SIZE
2460 ARM( stmib sp, {r1 - lr} )
2461 THUMB( stmia sp, {r0 - r12} )
2462 THUMB( str sp, [sp, #S_SP] )
2463 THUMB( str lr, [sp, #S_LR] )
2464+
2465 mov r1, #\reason
2466 .endm
2467
2468@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2469 .macro svc_entry, stack_hole=0
2470 UNWIND(.fnstart )
2471 UNWIND(.save {r0 - pc} )
2472+
2473+ pax_enter_kernel
2474+
2475 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2476+
2477 #ifdef CONFIG_THUMB2_KERNEL
2478 SPFIX( str r0, [sp] ) @ temporarily saved
2479 SPFIX( mov r0, sp )
2480@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2481 ldmia r0, {r3 - r5}
2482 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2483 mov r6, #-1 @ "" "" "" ""
2484+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2485+ @ offset sp by 8 as done in pax_enter_kernel
2486+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2487+#else
2488 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2489+#endif
2490 SPFIX( addeq r2, r2, #4 )
2491 str r3, [sp, #-4]! @ save the "real" r0 copied
2492 @ from the exception stack
2493@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2494 .macro usr_entry
2495 UNWIND(.fnstart )
2496 UNWIND(.cantunwind ) @ don't unwind the user space
2497+
2498+ pax_enter_kernel_user
2499+
2500 sub sp, sp, #S_FRAME_SIZE
2501 ARM( stmib sp, {r1 - r12} )
2502 THUMB( stmia sp, {r0 - r12} )
2503@@ -415,7 +512,9 @@ __und_usr:
2504 tst r3, #PSR_T_BIT @ Thumb mode?
2505 bne __und_usr_thumb
2506 sub r4, r2, #4 @ ARM instr at LR - 4
2507+ pax_open_userland
2508 1: ldrt r0, [r4]
2509+ pax_close_userland
2510 #ifdef CONFIG_CPU_ENDIAN_BE8
2511 rev r0, r0 @ little endian instruction
2512 #endif
2513@@ -450,10 +549,14 @@ __und_usr_thumb:
2514 */
2515 .arch armv6t2
2516 #endif
2517+ pax_open_userland
2518 2: ldrht r5, [r4]
2519+ pax_close_userland
2520 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2521 blo __und_usr_fault_16 @ 16bit undefined instruction
2522+ pax_open_userland
2523 3: ldrht r0, [r2]
2524+ pax_close_userland
2525 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2526 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2527 orr r0, r0, r5, lsl #16
2528@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2529 */
2530 .pushsection .fixup, "ax"
2531 .align 2
2532-4: mov pc, r9
2533+4: pax_close_userland
2534+ mov pc, r9
2535 .popsection
2536 .pushsection __ex_table,"a"
2537 .long 1b, 4b
2538@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2539 THUMB( str lr, [ip], #4 )
2540 ldr r4, [r2, #TI_TP_VALUE]
2541 ldr r5, [r2, #TI_TP_VALUE + 4]
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 switch_tls r1, r4, r5, r3, r7
2547@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index 94104bf..e425391 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2611 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2612 #endif
2613
2614+ /*
2615+ * do this here to avoid a performance hit of wrapping the code above
2616+ * that directly dereferences userland to parse the SWI instruction
2617+ */
2618+ pax_enter_kernel_user
2619+
2620 adr tbl, sys_call_table @ load syscall table pointer
2621
2622 #if defined(CONFIG_OABI_COMPAT)
2623diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2624index de23a9b..94c37c4 100644
2625--- a/arch/arm/kernel/entry-header.S
2626+++ b/arch/arm/kernel/entry-header.S
2627@@ -184,6 +184,60 @@
2628 msr cpsr_c, \rtemp @ switch back to the SVC mode
2629 .endm
2630
2631+ .macro pax_enter_kernel_user
2632+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+#ifdef CONFIG_PAX_MEMORY_UDEREF
2642+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2643+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2644+#endif
2645+#ifdef CONFIG_PAX_KERNEXEC
2646+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2647+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2648+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2649+#endif
2650+ @ write r1 to current_thread_info()->cpu_domain
2651+ str r1, [r0, #TI_CPU_DOMAIN]
2652+ @ write r1 to DACR
2653+ mcr p15, 0, r1, c3, c0, 0
2654+ @ instruction sync
2655+ instr_sync
2656+ @ restore regs
2657+ ldmia sp!, {r0, r1}
2658+#endif
2659+ .endm
2660+
2661+ .macro pax_exit_kernel
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read old DACR from stack into r1
2666+ ldr r1, [sp, #(8 + S_SP)]
2667+ sub r1, r1, #8
2668+ ldr r1, [r1]
2669+
2670+ @ write r1 to current_thread_info()->cpu_domain
2671+ mov r0, sp
2672+ @ assume 8K pages, since we have to split the immediate in two
2673+ bic r0, r0, #(0x1fc0)
2674+ bic r0, r0, #(0x3f)
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685 #ifndef CONFIG_THUMB2_KERNEL
2686 .macro svc_exit, rpsr, irq = 0
2687 .if \irq != 0
2688@@ -203,6 +257,9 @@
2689 blne trace_hardirqs_off
2690 #endif
2691 .endif
2692+
2693+ pax_exit_kernel
2694+
2695 msr spsr_cxsf, \rpsr
2696 #if defined(CONFIG_CPU_V6)
2697 ldr r0, [sp]
2698@@ -266,6 +323,9 @@
2699 blne trace_hardirqs_off
2700 #endif
2701 .endif
2702+
2703+ pax_exit_kernel
2704+
2705 ldr lr, [sp, #S_SP] @ top of the stack
2706 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2707 clrex @ clear the exclusive monitor
2708diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2709index 918875d..cd5fa27 100644
2710--- a/arch/arm/kernel/fiq.c
2711+++ b/arch/arm/kernel/fiq.c
2712@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2713 void *base = vectors_page;
2714 unsigned offset = FIQ_OFFSET;
2715
2716+ pax_open_kernel();
2717 memcpy(base + offset, start, length);
2718+ pax_close_kernel();
2719+
2720 if (!cache_is_vipt_nonaliasing())
2721 flush_icache_range((unsigned long)base + offset, offset +
2722 length);
2723diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2724index 2c7cc1e..ab2e911 100644
2725--- a/arch/arm/kernel/head.S
2726+++ b/arch/arm/kernel/head.S
2727@@ -52,7 +52,9 @@
2728 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2729
2730 .macro pgtbl, rd, phys
2731- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2732+ mov \rd, #TEXT_OFFSET
2733+ sub \rd, #PG_DIR_SIZE
2734+ add \rd, \rd, \phys
2735 .endm
2736
2737 /*
2738@@ -432,7 +434,7 @@ __enable_mmu:
2739 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2740 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2741 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2742- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2743+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2744 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2745 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2746 #endif
2747diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2748index 85c3fb6..054c2dc 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,39 @@
2752 #endif
2753
2754 #ifdef CONFIG_MMU
2755-void *module_alloc(unsigned long size)
2756+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2757 {
2758+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2759+ return NULL;
2760 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2761- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2762+ GFP_KERNEL, prot, -1,
2763 __builtin_return_address(0));
2764 }
2765+
2766+void *module_alloc(unsigned long size)
2767+{
2768+
2769+#ifdef CONFIG_PAX_KERNEXEC
2770+ return __module_alloc(size, PAGE_KERNEL);
2771+#else
2772+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2773+#endif
2774+
2775+}
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+void module_free_exec(struct module *mod, void *module_region)
2779+{
2780+ module_free(mod, module_region);
2781+}
2782+EXPORT_SYMBOL(module_free_exec);
2783+
2784+void *module_alloc_exec(unsigned long size)
2785+{
2786+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2787+}
2788+EXPORT_SYMBOL(module_alloc_exec);
2789+#endif
2790 #endif
2791
2792 int
2793diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2794index 07314af..c46655c 100644
2795--- a/arch/arm/kernel/patch.c
2796+++ b/arch/arm/kernel/patch.c
2797@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2798 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2799 int size;
2800
2801+ pax_open_kernel();
2802 if (thumb2 && __opcode_is_thumb16(insn)) {
2803 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2804 size = sizeof(u16);
2805@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 *(u32 *)addr = insn;
2807 size = sizeof(u32);
2808 }
2809+ pax_close_kernel();
2810
2811 flush_icache_range((uintptr_t)(addr),
2812 (uintptr_t)(addr) + size);
2813diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2814index 94f6b05..efd7312 100644
2815--- a/arch/arm/kernel/process.c
2816+++ b/arch/arm/kernel/process.c
2817@@ -217,6 +217,7 @@ void machine_power_off(void)
2818
2819 if (pm_power_off)
2820 pm_power_off();
2821+ BUG();
2822 }
2823
2824 /*
2825@@ -230,7 +231,7 @@ void machine_power_off(void)
2826 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2827 * to use. Implementing such co-ordination would be essentially impossible.
2828 */
2829-void machine_restart(char *cmd)
2830+__noreturn void machine_restart(char *cmd)
2831 {
2832 local_irq_disable();
2833 smp_send_stop();
2834@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2835
2836 show_regs_print_info(KERN_DEFAULT);
2837
2838- print_symbol("PC is at %s\n", instruction_pointer(regs));
2839- print_symbol("LR is at %s\n", regs->ARM_lr);
2840+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2841+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2842 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2843 "sp : %08lx ip : %08lx fp : %08lx\n",
2844 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2845@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2846 return 0;
2847 }
2848
2849-unsigned long arch_randomize_brk(struct mm_struct *mm)
2850-{
2851- unsigned long range_end = mm->brk + 0x02000000;
2852- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2853-}
2854-
2855 #ifdef CONFIG_MMU
2856 #ifdef CONFIG_KUSER_HELPERS
2857 /*
2858@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2859
2860 static int __init gate_vma_init(void)
2861 {
2862- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2863+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2864 return 0;
2865 }
2866 arch_initcall(gate_vma_init);
2867@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2868
2869 const char *arch_vma_name(struct vm_area_struct *vma)
2870 {
2871- return is_gate_vma(vma) ? "[vectors]" :
2872- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2873- "[sigpage]" : NULL;
2874+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2875 }
2876
2877-static struct page *signal_page;
2878-extern struct page *get_signal_page(void);
2879-
2880 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2881 {
2882 struct mm_struct *mm = current->mm;
2883- unsigned long addr;
2884- int ret;
2885-
2886- if (!signal_page)
2887- signal_page = get_signal_page();
2888- if (!signal_page)
2889- return -ENOMEM;
2890
2891 down_write(&mm->mmap_sem);
2892- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2893- if (IS_ERR_VALUE(addr)) {
2894- ret = addr;
2895- goto up_fail;
2896- }
2897-
2898- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2899- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2900- &signal_page);
2901-
2902- if (ret == 0)
2903- mm->context.sigpage = addr;
2904-
2905- up_fail:
2906+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2907 up_write(&mm->mmap_sem);
2908- return ret;
2909+ return 0;
2910 }
2911 #endif
2912diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2913index 4693188..4596c5e 100644
2914--- a/arch/arm/kernel/psci.c
2915+++ b/arch/arm/kernel/psci.c
2916@@ -24,7 +24,7 @@
2917 #include <asm/opcodes-virt.h>
2918 #include <asm/psci.h>
2919
2920-struct psci_operations psci_ops;
2921+struct psci_operations psci_ops __read_only;
2922
2923 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2924
2925diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2926index 0dd3b79..e018f64 100644
2927--- a/arch/arm/kernel/ptrace.c
2928+++ b/arch/arm/kernel/ptrace.c
2929@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2930 return current_thread_info()->syscall;
2931 }
2932
2933+#ifdef CONFIG_GRKERNSEC_SETXID
2934+extern void gr_delayed_cred_worker(void);
2935+#endif
2936+
2937 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2938 {
2939 current_thread_info()->syscall = scno;
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2943+ gr_delayed_cred_worker();
2944+#endif
2945+
2946 /* Do the secure computing check first; failures should be fast. */
2947 if (secure_computing(scno) == -1)
2948 return -1;
2949diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2950index afc2489..6372bc8 100644
2951--- a/arch/arm/kernel/setup.c
2952+++ b/arch/arm/kernel/setup.c
2953@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2954 unsigned int elf_hwcap __read_mostly;
2955 EXPORT_SYMBOL(elf_hwcap);
2956
2957+pteval_t __supported_pte_mask __read_only;
2958+pmdval_t __supported_pmd_mask __read_only;
2959
2960 #ifdef MULTI_CPU
2961-struct processor processor __read_mostly;
2962+struct processor processor;
2963 #endif
2964 #ifdef MULTI_TLB
2965-struct cpu_tlb_fns cpu_tlb __read_mostly;
2966+struct cpu_tlb_fns cpu_tlb __read_only;
2967 #endif
2968 #ifdef MULTI_USER
2969-struct cpu_user_fns cpu_user __read_mostly;
2970+struct cpu_user_fns cpu_user __read_only;
2971 #endif
2972 #ifdef MULTI_CACHE
2973-struct cpu_cache_fns cpu_cache __read_mostly;
2974+struct cpu_cache_fns cpu_cache __read_only;
2975 #endif
2976 #ifdef CONFIG_OUTER_CACHE
2977-struct outer_cache_fns outer_cache __read_mostly;
2978+struct outer_cache_fns outer_cache __read_only;
2979 EXPORT_SYMBOL(outer_cache);
2980 #endif
2981
2982@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2983 asm("mrc p15, 0, %0, c0, c1, 4"
2984 : "=r" (mmfr0));
2985 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2986- (mmfr0 & 0x000000f0) >= 0x00000030)
2987+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2988 cpu_arch = CPU_ARCH_ARMv7;
2989- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2990+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2991+ __supported_pte_mask |= L_PTE_PXN;
2992+ __supported_pmd_mask |= PMD_PXNTABLE;
2993+ }
2994+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2995 (mmfr0 & 0x000000f0) == 0x00000020)
2996 cpu_arch = CPU_ARCH_ARMv6;
2997 else
2998@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2999 __cpu_architecture = __get_cpu_architecture();
3000
3001 #ifdef MULTI_CPU
3002- processor = *list->proc;
3003+ memcpy((void *)&processor, list->proc, sizeof processor);
3004 #endif
3005 #ifdef MULTI_TLB
3006 cpu_tlb = *list->tlb;
3007diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3008index ab33042..11248a8 100644
3009--- a/arch/arm/kernel/signal.c
3010+++ b/arch/arm/kernel/signal.c
3011@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3012 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3013 };
3014
3015-static unsigned long signal_return_offset;
3016-
3017 #ifdef CONFIG_CRUNCH
3018 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3019 {
3020@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3021 * except when the MPU has protected the vectors
3022 * page from PL0
3023 */
3024- retcode = mm->context.sigpage + signal_return_offset +
3025- (idx << 2) + thumb;
3026+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3027 } else
3028 #endif
3029 {
3030@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3031 } while (thread_flags & _TIF_WORK_MASK);
3032 return 0;
3033 }
3034-
3035-struct page *get_signal_page(void)
3036-{
3037- unsigned long ptr;
3038- unsigned offset;
3039- struct page *page;
3040- void *addr;
3041-
3042- page = alloc_pages(GFP_KERNEL, 0);
3043-
3044- if (!page)
3045- return NULL;
3046-
3047- addr = page_address(page);
3048-
3049- /* Give the signal return code some randomness */
3050- offset = 0x200 + (get_random_int() & 0x7fc);
3051- signal_return_offset = offset;
3052-
3053- /*
3054- * Copy signal return handlers into the vector page, and
3055- * set sigreturn to be a pointer to these.
3056- */
3057- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3058-
3059- ptr = (unsigned long)addr + offset;
3060- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3061-
3062- return page;
3063-}
3064diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3065index 2dc1934..ecf0e21 100644
3066--- a/arch/arm/kernel/smp.c
3067+++ b/arch/arm/kernel/smp.c
3068@@ -71,7 +71,7 @@ enum ipi_msg_type {
3069
3070 static DECLARE_COMPLETION(cpu_running);
3071
3072-static struct smp_operations smp_ops;
3073+static struct smp_operations smp_ops __read_only;
3074
3075 void __init smp_set_ops(struct smp_operations *ops)
3076 {
3077diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3078index ab517fc..9adf2fa 100644
3079--- a/arch/arm/kernel/traps.c
3080+++ b/arch/arm/kernel/traps.c
3081@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3082 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3083 {
3084 #ifdef CONFIG_KALLSYMS
3085- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3086+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3087 #else
3088 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3089 #endif
3090@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3091 static int die_owner = -1;
3092 static unsigned int die_nest_count;
3093
3094+extern void gr_handle_kernel_exploit(void);
3095+
3096 static unsigned long oops_begin(void)
3097 {
3098 int cpu;
3099@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3100 panic("Fatal exception in interrupt");
3101 if (panic_on_oops)
3102 panic("Fatal exception");
3103+
3104+ gr_handle_kernel_exploit();
3105+
3106 if (signr)
3107 do_exit(signr);
3108 }
3109@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3110 * The user helper at 0xffff0fe0 must be used instead.
3111 * (see entry-armv.S for details)
3112 */
3113+ pax_open_kernel();
3114 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3115+ pax_close_kernel();
3116 }
3117 return 0;
3118
3119@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3120 kuser_init(vectors_base);
3121
3122 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3123- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3124+
3125+#ifndef CONFIG_PAX_MEMORY_UDEREF
3126+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3127+#endif
3128+
3129 #else /* ifndef CONFIG_CPU_V7M */
3130 /*
3131 * on V7-M there is no need to copy the vector table to a dedicated
3132diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3133index 7bcee5c..e2f3249 100644
3134--- a/arch/arm/kernel/vmlinux.lds.S
3135+++ b/arch/arm/kernel/vmlinux.lds.S
3136@@ -8,7 +8,11 @@
3137 #include <asm/thread_info.h>
3138 #include <asm/memory.h>
3139 #include <asm/page.h>
3140-
3141+
3142+#ifdef CONFIG_PAX_KERNEXEC
3143+#include <asm/pgtable.h>
3144+#endif
3145+
3146 #define PROC_INFO \
3147 . = ALIGN(4); \
3148 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3149@@ -34,7 +38,7 @@
3150 #endif
3151
3152 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3153- defined(CONFIG_GENERIC_BUG)
3154+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3155 #define ARM_EXIT_KEEP(x) x
3156 #define ARM_EXIT_DISCARD(x)
3157 #else
3158@@ -90,6 +94,11 @@ SECTIONS
3159 _text = .;
3160 HEAD_TEXT
3161 }
3162+
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+ . = ALIGN(1<<SECTION_SHIFT);
3165+#endif
3166+
3167 .text : { /* Real text segment */
3168 _stext = .; /* Text and read-only data */
3169 __exception_text_start = .;
3170@@ -112,6 +121,8 @@ SECTIONS
3171 ARM_CPU_KEEP(PROC_INFO)
3172 }
3173
3174+ _etext = .; /* End of text section */
3175+
3176 RO_DATA(PAGE_SIZE)
3177
3178 . = ALIGN(4);
3179@@ -142,7 +153,9 @@ SECTIONS
3180
3181 NOTES
3182
3183- _etext = .; /* End of text and rodata section */
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187
3188 #ifndef CONFIG_XIP_KERNEL
3189 . = ALIGN(PAGE_SIZE);
3190@@ -220,6 +233,11 @@ SECTIONS
3191 . = PAGE_OFFSET + TEXT_OFFSET;
3192 #else
3193 __init_end = .;
3194+
3195+#ifdef CONFIG_PAX_KERNEXEC
3196+ . = ALIGN(1<<SECTION_SHIFT);
3197+#endif
3198+
3199 . = ALIGN(THREAD_SIZE);
3200 __data_loc = .;
3201 #endif
3202diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3203index 741f66a..8a5615c 100644
3204--- a/arch/arm/kvm/arm.c
3205+++ b/arch/arm/kvm/arm.c
3206@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3207 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3208
3209 /* The VMID used in the VTTBR */
3210-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3211+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3212 static u8 kvm_next_vmid;
3213 static DEFINE_SPINLOCK(kvm_vmid_lock);
3214
3215@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3216 */
3217 static bool need_new_vmid_gen(struct kvm *kvm)
3218 {
3219- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3220+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3221 }
3222
3223 /**
3224@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3225
3226 /* First user of a new VMID generation? */
3227 if (unlikely(kvm_next_vmid == 0)) {
3228- atomic64_inc(&kvm_vmid_gen);
3229+ atomic64_inc_unchecked(&kvm_vmid_gen);
3230 kvm_next_vmid = 1;
3231
3232 /*
3233@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3234 kvm_call_hyp(__kvm_flush_vm_context);
3235 }
3236
3237- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3238+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3239 kvm->arch.vmid = kvm_next_vmid;
3240 kvm_next_vmid++;
3241
3242diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3243index 14a0d98..7771a7d 100644
3244--- a/arch/arm/lib/clear_user.S
3245+++ b/arch/arm/lib/clear_user.S
3246@@ -12,14 +12,14 @@
3247
3248 .text
3249
3250-/* Prototype: int __clear_user(void *addr, size_t sz)
3251+/* Prototype: int ___clear_user(void *addr, size_t sz)
3252 * Purpose : clear some user memory
3253 * Params : addr - user memory address to clear
3254 * : sz - number of bytes to clear
3255 * Returns : number of bytes NOT cleared
3256 */
3257 ENTRY(__clear_user_std)
3258-WEAK(__clear_user)
3259+WEAK(___clear_user)
3260 stmfd sp!, {r1, lr}
3261 mov r2, #0
3262 cmp r1, #4
3263@@ -44,7 +44,7 @@ WEAK(__clear_user)
3264 USER( strnebt r2, [r0])
3265 mov r0, #0
3266 ldmfd sp!, {r1, pc}
3267-ENDPROC(__clear_user)
3268+ENDPROC(___clear_user)
3269 ENDPROC(__clear_user_std)
3270
3271 .pushsection .fixup,"ax"
3272diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3273index 66a477a..bee61d3 100644
3274--- a/arch/arm/lib/copy_from_user.S
3275+++ b/arch/arm/lib/copy_from_user.S
3276@@ -16,7 +16,7 @@
3277 /*
3278 * Prototype:
3279 *
3280- * size_t __copy_from_user(void *to, const void *from, size_t n)
3281+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3282 *
3283 * Purpose:
3284 *
3285@@ -84,11 +84,11 @@
3286
3287 .text
3288
3289-ENTRY(__copy_from_user)
3290+ENTRY(___copy_from_user)
3291
3292 #include "copy_template.S"
3293
3294-ENDPROC(__copy_from_user)
3295+ENDPROC(___copy_from_user)
3296
3297 .pushsection .fixup,"ax"
3298 .align 0
3299diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3300index 6ee2f67..d1cce76 100644
3301--- a/arch/arm/lib/copy_page.S
3302+++ b/arch/arm/lib/copy_page.S
3303@@ -10,6 +10,7 @@
3304 * ASM optimised string functions
3305 */
3306 #include <linux/linkage.h>
3307+#include <linux/const.h>
3308 #include <asm/assembler.h>
3309 #include <asm/asm-offsets.h>
3310 #include <asm/cache.h>
3311diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3312index d066df6..df28194 100644
3313--- a/arch/arm/lib/copy_to_user.S
3314+++ b/arch/arm/lib/copy_to_user.S
3315@@ -16,7 +16,7 @@
3316 /*
3317 * Prototype:
3318 *
3319- * size_t __copy_to_user(void *to, const void *from, size_t n)
3320+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3321 *
3322 * Purpose:
3323 *
3324@@ -88,11 +88,11 @@
3325 .text
3326
3327 ENTRY(__copy_to_user_std)
3328-WEAK(__copy_to_user)
3329+WEAK(___copy_to_user)
3330
3331 #include "copy_template.S"
3332
3333-ENDPROC(__copy_to_user)
3334+ENDPROC(___copy_to_user)
3335 ENDPROC(__copy_to_user_std)
3336
3337 .pushsection .fixup,"ax"
3338diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3339index 7d08b43..f7ca7ea 100644
3340--- a/arch/arm/lib/csumpartialcopyuser.S
3341+++ b/arch/arm/lib/csumpartialcopyuser.S
3342@@ -57,8 +57,8 @@
3343 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3344 */
3345
3346-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3347-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3348+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3349+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3350
3351 #include "csumpartialcopygeneric.S"
3352
3353diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3354index 5306de3..aed6d03 100644
3355--- a/arch/arm/lib/delay.c
3356+++ b/arch/arm/lib/delay.c
3357@@ -28,7 +28,7 @@
3358 /*
3359 * Default to the loop-based delay implementation.
3360 */
3361-struct arm_delay_ops arm_delay_ops = {
3362+struct arm_delay_ops arm_delay_ops __read_only = {
3363 .delay = __loop_delay,
3364 .const_udelay = __loop_const_udelay,
3365 .udelay = __loop_udelay,
3366diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3367index 025f742..a9e5b3b 100644
3368--- a/arch/arm/lib/uaccess_with_memcpy.c
3369+++ b/arch/arm/lib/uaccess_with_memcpy.c
3370@@ -104,7 +104,7 @@ out:
3371 }
3372
3373 unsigned long
3374-__copy_to_user(void __user *to, const void *from, unsigned long n)
3375+___copy_to_user(void __user *to, const void *from, unsigned long n)
3376 {
3377 /*
3378 * This test is stubbed out of the main function above to keep
3379@@ -155,7 +155,7 @@ out:
3380 return n;
3381 }
3382
3383-unsigned long __clear_user(void __user *addr, unsigned long n)
3384+unsigned long ___clear_user(void __user *addr, unsigned long n)
3385 {
3386 /* See rational for this in __copy_to_user() above. */
3387 if (n < 64)
3388diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3389index e9238b5..6ed904a 100644
3390--- a/arch/arm/mach-kirkwood/common.c
3391+++ b/arch/arm/mach-kirkwood/common.c
3392@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3393 clk_gate_ops.disable(hw);
3394 }
3395
3396-static struct clk_ops clk_gate_fn_ops;
3397+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3398+{
3399+ return clk_gate_ops.is_enabled(hw);
3400+}
3401+
3402+static struct clk_ops clk_gate_fn_ops = {
3403+ .enable = clk_gate_fn_enable,
3404+ .disable = clk_gate_fn_disable,
3405+ .is_enabled = clk_gate_fn_is_enabled,
3406+};
3407
3408 static struct clk __init *clk_register_gate_fn(struct device *dev,
3409 const char *name,
3410@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3411 gate_fn->fn_en = fn_en;
3412 gate_fn->fn_dis = fn_dis;
3413
3414- /* ops is the gate ops, but with our enable/disable functions */
3415- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3416- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3417- clk_gate_fn_ops = clk_gate_ops;
3418- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3419- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3420- }
3421-
3422 clk = clk_register(dev, &gate_fn->gate.hw);
3423
3424 if (IS_ERR(clk))
3425diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3426index 827d1500..2885dc6 100644
3427--- a/arch/arm/mach-omap2/board-n8x0.c
3428+++ b/arch/arm/mach-omap2/board-n8x0.c
3429@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3430 }
3431 #endif
3432
3433-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3434+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3435 .late_init = n8x0_menelaus_late_init,
3436 };
3437
3438diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3439index f3fdd6a..3564800 100644
3440--- a/arch/arm/mach-omap2/gpmc.c
3441+++ b/arch/arm/mach-omap2/gpmc.c
3442@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3443 };
3444
3445 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3446-static struct irq_chip gpmc_irq_chip;
3447 static unsigned gpmc_irq_start;
3448
3449 static struct resource gpmc_mem_root;
3450@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3451
3452 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3453
3454+static struct irq_chip gpmc_irq_chip = {
3455+ .name = "gpmc",
3456+ .irq_startup = gpmc_irq_noop_ret,
3457+ .irq_enable = gpmc_irq_enable,
3458+ .irq_disable = gpmc_irq_disable,
3459+ .irq_shutdown = gpmc_irq_noop,
3460+ .irq_ack = gpmc_irq_noop,
3461+ .irq_mask = gpmc_irq_noop,
3462+ .irq_unmask = gpmc_irq_noop,
3463+
3464+};
3465+
3466 static int gpmc_setup_irq(void)
3467 {
3468 int i;
3469@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3470 return gpmc_irq_start;
3471 }
3472
3473- gpmc_irq_chip.name = "gpmc";
3474- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3475- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3476- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3477- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3478- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3479- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3480- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3481-
3482 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3483 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3484
3485diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3486index f991016..145ebeb 100644
3487--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3488+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3489@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3490 int (*finish_suspend)(unsigned long cpu_state);
3491 void (*resume)(void);
3492 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3493-};
3494+} __no_const;
3495
3496 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3497 static struct powerdomain *mpuss_pd;
3498@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3499 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3500 {}
3501
3502-struct cpu_pm_ops omap_pm_ops = {
3503+static struct cpu_pm_ops omap_pm_ops __read_only = {
3504 .finish_suspend = default_finish_suspend,
3505 .resume = dummy_cpu_resume,
3506 .scu_prepare = dummy_scu_prepare,
3507diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3508index 813c615..ce467c6 100644
3509--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3510+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3511@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3512 return NOTIFY_OK;
3513 }
3514
3515-static struct notifier_block __refdata irq_hotplug_notifier = {
3516+static struct notifier_block irq_hotplug_notifier = {
3517 .notifier_call = irq_cpu_hotplug_notify,
3518 };
3519
3520diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3521index f99f68e..e573e20 100644
3522--- a/arch/arm/mach-omap2/omap_device.c
3523+++ b/arch/arm/mach-omap2/omap_device.c
3524@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3525 struct platform_device __init *omap_device_build(const char *pdev_name,
3526 int pdev_id,
3527 struct omap_hwmod *oh,
3528- void *pdata, int pdata_len)
3529+ const void *pdata, int pdata_len)
3530 {
3531 struct omap_hwmod *ohs[] = { oh };
3532
3533@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3534 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3535 int pdev_id,
3536 struct omap_hwmod **ohs,
3537- int oh_cnt, void *pdata,
3538+ int oh_cnt, const void *pdata,
3539 int pdata_len)
3540 {
3541 int ret = -ENOMEM;
3542diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3543index 17ca1ae..beba869 100644
3544--- a/arch/arm/mach-omap2/omap_device.h
3545+++ b/arch/arm/mach-omap2/omap_device.h
3546@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3547 /* Core code interface */
3548
3549 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3550- struct omap_hwmod *oh, void *pdata,
3551+ struct omap_hwmod *oh, const void *pdata,
3552 int pdata_len);
3553
3554 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3555 struct omap_hwmod **oh, int oh_cnt,
3556- void *pdata, int pdata_len);
3557+ const void *pdata, int pdata_len);
3558
3559 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3560 struct omap_hwmod **ohs, int oh_cnt);
3561diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3562index 7f4db12..0243012 100644
3563--- a/arch/arm/mach-omap2/omap_hwmod.c
3564+++ b/arch/arm/mach-omap2/omap_hwmod.c
3565@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3566 int (*init_clkdm)(struct omap_hwmod *oh);
3567 void (*update_context_lost)(struct omap_hwmod *oh);
3568 int (*get_context_lost)(struct omap_hwmod *oh);
3569-};
3570+} __no_const;
3571
3572 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3573-static struct omap_hwmod_soc_ops soc_ops;
3574+static struct omap_hwmod_soc_ops soc_ops __read_only;
3575
3576 /* omap_hwmod_list contains all registered struct omap_hwmods */
3577 static LIST_HEAD(omap_hwmod_list);
3578diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3579index d15c7bb..b2d1f0c 100644
3580--- a/arch/arm/mach-omap2/wd_timer.c
3581+++ b/arch/arm/mach-omap2/wd_timer.c
3582@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3583 struct omap_hwmod *oh;
3584 char *oh_name = "wd_timer2";
3585 char *dev_name = "omap_wdt";
3586- struct omap_wd_timer_platform_data pdata;
3587+ static struct omap_wd_timer_platform_data pdata = {
3588+ .read_reset_sources = prm_read_reset_sources
3589+ };
3590
3591 if (!cpu_class_is_omap2() || of_have_populated_dt())
3592 return 0;
3593@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3594 return -EINVAL;
3595 }
3596
3597- pdata.read_reset_sources = prm_read_reset_sources;
3598-
3599 pdev = omap_device_build(dev_name, id, oh, &pdata,
3600 sizeof(struct omap_wd_timer_platform_data));
3601 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3602diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3603index 706aa42..f85e9131 100644
3604--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3605+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3606@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3607 bool entered_lp2 = false;
3608
3609 if (tegra_pending_sgi())
3610- ACCESS_ONCE(abort_flag) = true;
3611+ ACCESS_ONCE_RW(abort_flag) = true;
3612
3613 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3614
3615diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3616index cad3ca86..1d79e0f 100644
3617--- a/arch/arm/mach-ux500/setup.h
3618+++ b/arch/arm/mach-ux500/setup.h
3619@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3620 .type = MT_DEVICE, \
3621 }
3622
3623-#define __MEM_DEV_DESC(x, sz) { \
3624- .virtual = IO_ADDRESS(x), \
3625- .pfn = __phys_to_pfn(x), \
3626- .length = sz, \
3627- .type = MT_MEMORY, \
3628-}
3629-
3630 extern struct smp_operations ux500_smp_ops;
3631 extern void ux500_cpu_die(unsigned int cpu);
3632
3633diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3634index cd2c88e..7430282 100644
3635--- a/arch/arm/mm/Kconfig
3636+++ b/arch/arm/mm/Kconfig
3637@@ -446,7 +446,7 @@ config CPU_32v5
3638
3639 config CPU_32v6
3640 bool
3641- select CPU_USE_DOMAINS if CPU_V6 && MMU
3642+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3643 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3644
3645 config CPU_32v6K
3646@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3647
3648 config CPU_USE_DOMAINS
3649 bool
3650+ depends on !ARM_LPAE && !PAX_KERNEXEC
3651 help
3652 This option enables or disables the use of domain switching
3653 via the set_fs() function.
3654@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3655 config KUSER_HELPERS
3656 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3657 default y
3658+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3659 help
3660 Warning: disabling this option may break user programs.
3661
3662@@ -812,7 +814,7 @@ config KUSER_HELPERS
3663 See Documentation/arm/kernel_user_helpers.txt for details.
3664
3665 However, the fixed address nature of these helpers can be used
3666- by ROP (return orientated programming) authors when creating
3667+ by ROP (Return Oriented Programming) authors when creating
3668 exploits.
3669
3670 If all of the binaries and libraries which run on your platform
3671diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3672index 6f4585b..7b6f52b 100644
3673--- a/arch/arm/mm/alignment.c
3674+++ b/arch/arm/mm/alignment.c
3675@@ -211,10 +211,12 @@ union offset_union {
3676 #define __get16_unaligned_check(ins,val,addr) \
3677 do { \
3678 unsigned int err = 0, v, a = addr; \
3679+ pax_open_userland(); \
3680 __get8_unaligned_check(ins,v,a,err); \
3681 val = v << ((BE) ? 8 : 0); \
3682 __get8_unaligned_check(ins,v,a,err); \
3683 val |= v << ((BE) ? 0 : 8); \
3684+ pax_close_userland(); \
3685 if (err) \
3686 goto fault; \
3687 } while (0)
3688@@ -228,6 +230,7 @@ union offset_union {
3689 #define __get32_unaligned_check(ins,val,addr) \
3690 do { \
3691 unsigned int err = 0, v, a = addr; \
3692+ pax_open_userland(); \
3693 __get8_unaligned_check(ins,v,a,err); \
3694 val = v << ((BE) ? 24 : 0); \
3695 __get8_unaligned_check(ins,v,a,err); \
3696@@ -236,6 +239,7 @@ union offset_union {
3697 val |= v << ((BE) ? 8 : 16); \
3698 __get8_unaligned_check(ins,v,a,err); \
3699 val |= v << ((BE) ? 0 : 24); \
3700+ pax_close_userland(); \
3701 if (err) \
3702 goto fault; \
3703 } while (0)
3704@@ -249,6 +253,7 @@ union offset_union {
3705 #define __put16_unaligned_check(ins,val,addr) \
3706 do { \
3707 unsigned int err = 0, v = val, a = addr; \
3708+ pax_open_userland(); \
3709 __asm__( FIRST_BYTE_16 \
3710 ARM( "1: "ins" %1, [%2], #1\n" ) \
3711 THUMB( "1: "ins" %1, [%2]\n" ) \
3712@@ -268,6 +273,7 @@ union offset_union {
3713 " .popsection\n" \
3714 : "=r" (err), "=&r" (v), "=&r" (a) \
3715 : "0" (err), "1" (v), "2" (a)); \
3716+ pax_close_userland(); \
3717 if (err) \
3718 goto fault; \
3719 } while (0)
3720@@ -281,6 +287,7 @@ union offset_union {
3721 #define __put32_unaligned_check(ins,val,addr) \
3722 do { \
3723 unsigned int err = 0, v = val, a = addr; \
3724+ pax_open_userland(); \
3725 __asm__( FIRST_BYTE_32 \
3726 ARM( "1: "ins" %1, [%2], #1\n" ) \
3727 THUMB( "1: "ins" %1, [%2]\n" ) \
3728@@ -310,6 +317,7 @@ union offset_union {
3729 " .popsection\n" \
3730 : "=r" (err), "=&r" (v), "=&r" (a) \
3731 : "0" (err), "1" (v), "2" (a)); \
3732+ pax_close_userland(); \
3733 if (err) \
3734 goto fault; \
3735 } while (0)
3736diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3737index 4a05444..d21968c 100644
3738--- a/arch/arm/mm/context.c
3739+++ b/arch/arm/mm/context.c
3740@@ -43,7 +43,7 @@
3741 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3742
3743 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3744-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3745+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3746 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3747
3748 static DEFINE_PER_CPU(atomic64_t, active_asids);
3749@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3750 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3751 {
3752 u64 asid = atomic64_read(&mm->context.id);
3753- u64 generation = atomic64_read(&asid_generation);
3754+ u64 generation = atomic64_read_unchecked(&asid_generation);
3755
3756 if (asid != 0 && is_reserved_asid(asid)) {
3757 /*
3758@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3759 */
3760 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3761 if (asid == NUM_USER_ASIDS) {
3762- generation = atomic64_add_return(ASID_FIRST_VERSION,
3763+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3764 &asid_generation);
3765 flush_context(cpu);
3766 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3767@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3768 cpu_set_reserved_ttbr0();
3769
3770 asid = atomic64_read(&mm->context.id);
3771- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3772+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3773 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3774 goto switch_mm_fastpath;
3775
3776 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3777 /* Check that our ASID belongs to the current generation. */
3778 asid = atomic64_read(&mm->context.id);
3779- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3780+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3781 asid = new_context(mm, cpu);
3782 atomic64_set(&mm->context.id, asid);
3783 }
3784diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3785index c97f794..6461880 100644
3786--- a/arch/arm/mm/fault.c
3787+++ b/arch/arm/mm/fault.c
3788@@ -25,6 +25,7 @@
3789 #include <asm/system_misc.h>
3790 #include <asm/system_info.h>
3791 #include <asm/tlbflush.h>
3792+#include <asm/sections.h>
3793
3794 #include "fault.h"
3795
3796@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3797 if (fixup_exception(regs))
3798 return;
3799
3800+#ifdef CONFIG_PAX_KERNEXEC
3801+ if ((fsr & FSR_WRITE) &&
3802+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3803+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3804+ {
3805+ if (current->signal->curr_ip)
3806+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3807+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3808+ else
3809+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3810+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3811+ }
3812+#endif
3813+
3814 /*
3815 * No handler, we'll have to terminate things with extreme prejudice.
3816 */
3817@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3818 }
3819 #endif
3820
3821+#ifdef CONFIG_PAX_PAGEEXEC
3822+ if (fsr & FSR_LNX_PF) {
3823+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3824+ do_group_exit(SIGKILL);
3825+ }
3826+#endif
3827+
3828 tsk->thread.address = addr;
3829 tsk->thread.error_code = fsr;
3830 tsk->thread.trap_no = 14;
3831@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3832 }
3833 #endif /* CONFIG_MMU */
3834
3835+#ifdef CONFIG_PAX_PAGEEXEC
3836+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3837+{
3838+ long i;
3839+
3840+ printk(KERN_ERR "PAX: bytes at PC: ");
3841+ for (i = 0; i < 20; i++) {
3842+ unsigned char c;
3843+ if (get_user(c, (__force unsigned char __user *)pc+i))
3844+ printk(KERN_CONT "?? ");
3845+ else
3846+ printk(KERN_CONT "%02x ", c);
3847+ }
3848+ printk("\n");
3849+
3850+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3851+ for (i = -1; i < 20; i++) {
3852+ unsigned long c;
3853+ if (get_user(c, (__force unsigned long __user *)sp+i))
3854+ printk(KERN_CONT "???????? ");
3855+ else
3856+ printk(KERN_CONT "%08lx ", c);
3857+ }
3858+ printk("\n");
3859+}
3860+#endif
3861+
3862 /*
3863 * First Level Translation Fault Handler
3864 *
3865@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3866 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3867 struct siginfo info;
3868
3869+#ifdef CONFIG_PAX_MEMORY_UDEREF
3870+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3871+ if (current->signal->curr_ip)
3872+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3873+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3874+ else
3875+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3876+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3877+ goto die;
3878+ }
3879+#endif
3880+
3881 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3882 return;
3883
3884+die:
3885 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3886 inf->name, fsr, addr);
3887
3888@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3889 ifsr_info[nr].name = name;
3890 }
3891
3892+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3893+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3894+
3895 asmlinkage void __exception
3896 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3897 {
3898 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3899 struct siginfo info;
3900+ unsigned long pc = instruction_pointer(regs);
3901+
3902+ if (user_mode(regs)) {
3903+ unsigned long sigpage = current->mm->context.sigpage;
3904+
3905+ if (sigpage <= pc && pc < sigpage + 7*4) {
3906+ if (pc < sigpage + 3*4)
3907+ sys_sigreturn(regs);
3908+ else
3909+ sys_rt_sigreturn(regs);
3910+ return;
3911+ }
3912+ if (pc == 0xffff0f60UL) {
3913+ /*
3914+ * PaX: __kuser_cmpxchg64 emulation
3915+ */
3916+ // TODO
3917+ //regs->ARM_pc = regs->ARM_lr;
3918+ //return;
3919+ }
3920+ if (pc == 0xffff0fa0UL) {
3921+ /*
3922+ * PaX: __kuser_memory_barrier emulation
3923+ */
3924+ // dmb(); implied by the exception
3925+ regs->ARM_pc = regs->ARM_lr;
3926+ return;
3927+ }
3928+ if (pc == 0xffff0fc0UL) {
3929+ /*
3930+ * PaX: __kuser_cmpxchg emulation
3931+ */
3932+ // TODO
3933+ //regs->ARM_pc = regs->ARM_lr;
3934+ //return;
3935+ }
3936+ if (pc == 0xffff0fe0UL) {
3937+ /*
3938+ * PaX: __kuser_get_tls emulation
3939+ */
3940+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3941+ regs->ARM_pc = regs->ARM_lr;
3942+ return;
3943+ }
3944+ }
3945+
3946+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3947+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3948+ if (current->signal->curr_ip)
3949+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3950+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3951+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3952+ else
3953+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3954+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3955+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3956+ goto die;
3957+ }
3958+#endif
3959+
3960+#ifdef CONFIG_PAX_REFCOUNT
3961+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3962+ unsigned int bkpt;
3963+
3964+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3965+ current->thread.error_code = ifsr;
3966+ current->thread.trap_no = 0;
3967+ pax_report_refcount_overflow(regs);
3968+ fixup_exception(regs);
3969+ return;
3970+ }
3971+ }
3972+#endif
3973
3974 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3975 return;
3976
3977+die:
3978 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3979 inf->name, ifsr, addr);
3980
3981diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3982index cf08bdf..772656c 100644
3983--- a/arch/arm/mm/fault.h
3984+++ b/arch/arm/mm/fault.h
3985@@ -3,6 +3,7 @@
3986
3987 /*
3988 * Fault status register encodings. We steal bit 31 for our own purposes.
3989+ * Set when the FSR value is from an instruction fault.
3990 */
3991 #define FSR_LNX_PF (1 << 31)
3992 #define FSR_WRITE (1 << 11)
3993@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3994 }
3995 #endif
3996
3997+/* valid for LPAE and !LPAE */
3998+static inline int is_xn_fault(unsigned int fsr)
3999+{
4000+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4001+}
4002+
4003+static inline int is_domain_fault(unsigned int fsr)
4004+{
4005+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4006+}
4007+
4008 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4009 unsigned long search_exception_table(unsigned long addr);
4010
4011diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4012index 15225d8..25e2e3c 100644
4013--- a/arch/arm/mm/init.c
4014+++ b/arch/arm/mm/init.c
4015@@ -30,6 +30,8 @@
4016 #include <asm/setup.h>
4017 #include <asm/tlb.h>
4018 #include <asm/fixmap.h>
4019+#include <asm/system_info.h>
4020+#include <asm/cp15.h>
4021
4022 #include <asm/mach/arch.h>
4023 #include <asm/mach/map.h>
4024@@ -683,7 +685,46 @@ void free_initmem(void)
4025 {
4026 #ifdef CONFIG_HAVE_TCM
4027 extern char __tcm_start, __tcm_end;
4028+#endif
4029
4030+#ifdef CONFIG_PAX_KERNEXEC
4031+ unsigned long addr;
4032+ pgd_t *pgd;
4033+ pud_t *pud;
4034+ pmd_t *pmd;
4035+ int cpu_arch = cpu_architecture();
4036+ unsigned int cr = get_cr();
4037+
4038+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4039+ /* make pages tables, etc before .text NX */
4040+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4041+ pgd = pgd_offset_k(addr);
4042+ pud = pud_offset(pgd, addr);
4043+ pmd = pmd_offset(pud, addr);
4044+ __section_update(pmd, addr, PMD_SECT_XN);
4045+ }
4046+ /* make init NX */
4047+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4048+ pgd = pgd_offset_k(addr);
4049+ pud = pud_offset(pgd, addr);
4050+ pmd = pmd_offset(pud, addr);
4051+ __section_update(pmd, addr, PMD_SECT_XN);
4052+ }
4053+ /* make kernel code/rodata RX */
4054+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4055+ pgd = pgd_offset_k(addr);
4056+ pud = pud_offset(pgd, addr);
4057+ pmd = pmd_offset(pud, addr);
4058+#ifdef CONFIG_ARM_LPAE
4059+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4060+#else
4061+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4062+#endif
4063+ }
4064+ }
4065+#endif
4066+
4067+#ifdef CONFIG_HAVE_TCM
4068 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4069 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4070 #endif
4071diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4072index f123d6e..04bf569 100644
4073--- a/arch/arm/mm/ioremap.c
4074+++ b/arch/arm/mm/ioremap.c
4075@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4076 unsigned int mtype;
4077
4078 if (cached)
4079- mtype = MT_MEMORY;
4080+ mtype = MT_MEMORY_RX;
4081 else
4082- mtype = MT_MEMORY_NONCACHED;
4083+ mtype = MT_MEMORY_NONCACHED_RX;
4084
4085 return __arm_ioremap_caller(phys_addr, size, mtype,
4086 __builtin_return_address(0));
4087diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4088index 0c63562..7128a90 100644
4089--- a/arch/arm/mm/mmap.c
4090+++ b/arch/arm/mm/mmap.c
4091@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4092 struct vm_area_struct *vma;
4093 int do_align = 0;
4094 int aliasing = cache_is_vipt_aliasing();
4095+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4096 struct vm_unmapped_area_info info;
4097
4098 /*
4099@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4100 if (len > TASK_SIZE)
4101 return -ENOMEM;
4102
4103+#ifdef CONFIG_PAX_RANDMMAP
4104+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4105+#endif
4106+
4107 if (addr) {
4108 if (do_align)
4109 addr = COLOUR_ALIGN(addr, pgoff);
4110@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4111 addr = PAGE_ALIGN(addr);
4112
4113 vma = find_vma(mm, addr);
4114- if (TASK_SIZE - len >= addr &&
4115- (!vma || addr + len <= vma->vm_start))
4116+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4117 return addr;
4118 }
4119
4120@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4121 info.high_limit = TASK_SIZE;
4122 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4123 info.align_offset = pgoff << PAGE_SHIFT;
4124+ info.threadstack_offset = offset;
4125 return vm_unmapped_area(&info);
4126 }
4127
4128@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4129 unsigned long addr = addr0;
4130 int do_align = 0;
4131 int aliasing = cache_is_vipt_aliasing();
4132+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4133 struct vm_unmapped_area_info info;
4134
4135 /*
4136@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4137 return addr;
4138 }
4139
4140+#ifdef CONFIG_PAX_RANDMMAP
4141+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4142+#endif
4143+
4144 /* requesting a specific address */
4145 if (addr) {
4146 if (do_align)
4147@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4148 else
4149 addr = PAGE_ALIGN(addr);
4150 vma = find_vma(mm, addr);
4151- if (TASK_SIZE - len >= addr &&
4152- (!vma || addr + len <= vma->vm_start))
4153+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4154 return addr;
4155 }
4156
4157@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4158 info.high_limit = mm->mmap_base;
4159 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4160 info.align_offset = pgoff << PAGE_SHIFT;
4161+ info.threadstack_offset = offset;
4162 addr = vm_unmapped_area(&info);
4163
4164 /*
4165@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4166 {
4167 unsigned long random_factor = 0UL;
4168
4169+#ifdef CONFIG_PAX_RANDMMAP
4170+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4171+#endif
4172+
4173 /* 8 bits of randomness in 20 address space bits */
4174 if ((current->flags & PF_RANDOMIZE) &&
4175 !(current->personality & ADDR_NO_RANDOMIZE))
4176@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4177
4178 if (mmap_is_legacy()) {
4179 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4180+
4181+#ifdef CONFIG_PAX_RANDMMAP
4182+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4183+ mm->mmap_base += mm->delta_mmap;
4184+#endif
4185+
4186 mm->get_unmapped_area = arch_get_unmapped_area;
4187 } else {
4188 mm->mmap_base = mmap_base(random_factor);
4189+
4190+#ifdef CONFIG_PAX_RANDMMAP
4191+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4192+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4193+#endif
4194+
4195 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4196 }
4197 }
4198diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4199index 53cdbd3..670f177 100644
4200--- a/arch/arm/mm/mmu.c
4201+++ b/arch/arm/mm/mmu.c
4202@@ -36,6 +36,22 @@
4203 #include "mm.h"
4204 #include "tcm.h"
4205
4206+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4207+void modify_domain(unsigned int dom, unsigned int type)
4208+{
4209+ struct thread_info *thread = current_thread_info();
4210+ unsigned int domain = thread->cpu_domain;
4211+ /*
4212+ * DOMAIN_MANAGER might be defined to some other value,
4213+ * use the arch-defined constant
4214+ */
4215+ domain &= ~domain_val(dom, 3);
4216+ thread->cpu_domain = domain | domain_val(dom, type);
4217+ set_domain(thread->cpu_domain);
4218+}
4219+EXPORT_SYMBOL(modify_domain);
4220+#endif
4221+
4222 /*
4223 * empty_zero_page is a special page that is used for
4224 * zero-initialized data and COW.
4225@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4226
4227 #endif /* ifdef CONFIG_CPU_CP15 / else */
4228
4229-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4230+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4231 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4232
4233-static struct mem_type mem_types[] = {
4234+#ifdef CONFIG_PAX_KERNEXEC
4235+#define L_PTE_KERNEXEC L_PTE_RDONLY
4236+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4237+#else
4238+#define L_PTE_KERNEXEC L_PTE_DIRTY
4239+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4240+#endif
4241+
4242+static struct mem_type mem_types[] __read_only = {
4243 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4244 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4245 L_PTE_SHARED,
4246@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4247 [MT_UNCACHED] = {
4248 .prot_pte = PROT_PTE_DEVICE,
4249 .prot_l1 = PMD_TYPE_TABLE,
4250- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4251+ .prot_sect = PROT_SECT_DEVICE,
4252 .domain = DOMAIN_IO,
4253 },
4254 [MT_CACHECLEAN] = {
4255- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4256+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4257 .domain = DOMAIN_KERNEL,
4258 },
4259 #ifndef CONFIG_ARM_LPAE
4260 [MT_MINICLEAN] = {
4261- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4262+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4263 .domain = DOMAIN_KERNEL,
4264 },
4265 #endif
4266@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4267 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4268 L_PTE_RDONLY,
4269 .prot_l1 = PMD_TYPE_TABLE,
4270- .domain = DOMAIN_USER,
4271+ .domain = DOMAIN_VECTORS,
4272 },
4273 [MT_HIGH_VECTORS] = {
4274 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4275 L_PTE_USER | L_PTE_RDONLY,
4276 .prot_l1 = PMD_TYPE_TABLE,
4277- .domain = DOMAIN_USER,
4278+ .domain = DOMAIN_VECTORS,
4279 },
4280- [MT_MEMORY] = {
4281+ [MT_MEMORY_RWX] = {
4282 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4283 .prot_l1 = PMD_TYPE_TABLE,
4284 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4285 .domain = DOMAIN_KERNEL,
4286 },
4287+ [MT_MEMORY_RW] = {
4288+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4289+ .prot_l1 = PMD_TYPE_TABLE,
4290+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4291+ .domain = DOMAIN_KERNEL,
4292+ },
4293+ [MT_MEMORY_RX] = {
4294+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4295+ .prot_l1 = PMD_TYPE_TABLE,
4296+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4297+ .domain = DOMAIN_KERNEL,
4298+ },
4299 [MT_ROM] = {
4300- .prot_sect = PMD_TYPE_SECT,
4301+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4302 .domain = DOMAIN_KERNEL,
4303 },
4304- [MT_MEMORY_NONCACHED] = {
4305+ [MT_MEMORY_NONCACHED_RW] = {
4306 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4307 L_PTE_MT_BUFFERABLE,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4310 .domain = DOMAIN_KERNEL,
4311 },
4312+ [MT_MEMORY_NONCACHED_RX] = {
4313+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4314+ L_PTE_MT_BUFFERABLE,
4315+ .prot_l1 = PMD_TYPE_TABLE,
4316+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4317+ .domain = DOMAIN_KERNEL,
4318+ },
4319 [MT_MEMORY_DTCM] = {
4320- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4321- L_PTE_XN,
4322+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4323 .prot_l1 = PMD_TYPE_TABLE,
4324- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4325+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4326 .domain = DOMAIN_KERNEL,
4327 },
4328 [MT_MEMORY_ITCM] = {
4329@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4330 },
4331 [MT_MEMORY_SO] = {
4332 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4333- L_PTE_MT_UNCACHED | L_PTE_XN,
4334+ L_PTE_MT_UNCACHED,
4335 .prot_l1 = PMD_TYPE_TABLE,
4336 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4337- PMD_SECT_UNCACHED | PMD_SECT_XN,
4338+ PMD_SECT_UNCACHED,
4339 .domain = DOMAIN_KERNEL,
4340 },
4341 [MT_MEMORY_DMA_READY] = {
4342@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4343 * to prevent speculative instruction fetches.
4344 */
4345 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4346+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4347 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4348+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4349 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4350+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4351 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4352+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4353+
4354+ /* Mark other regions on ARMv6+ as execute-never */
4355+
4356+#ifdef CONFIG_PAX_KERNEXEC
4357+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4358+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4359+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4360+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4361+#ifndef CONFIG_ARM_LPAE
4362+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4363+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4364+#endif
4365+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4366+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4367+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4368+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4369+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4371+#endif
4372+
4373+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4374+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4375 }
4376 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4377 /*
4378@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4379 * from SVC mode and no access from userspace.
4380 */
4381 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4382+#ifdef CONFIG_PAX_KERNEXEC
4383+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4384+#endif
4385 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4386 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4387 #endif
4388@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4389 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4390 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4391 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4392- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4393- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4394+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4395+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4396+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4397+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4398+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4399+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4400 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4401- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4402- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4403+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4405+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4406+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4407 }
4408 }
4409
4410@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4411 if (cpu_arch >= CPU_ARCH_ARMv6) {
4412 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4413 /* Non-cacheable Normal is XCB = 001 */
4414- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4415+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4416+ PMD_SECT_BUFFERED;
4417+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4418 PMD_SECT_BUFFERED;
4419 } else {
4420 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4421- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4422+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4423+ PMD_SECT_TEX(1);
4424+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4425 PMD_SECT_TEX(1);
4426 }
4427 } else {
4428- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4429+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4431 }
4432
4433 #ifdef CONFIG_ARM_LPAE
4434@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4435 vecs_pgprot |= PTE_EXT_AF;
4436 #endif
4437
4438+ user_pgprot |= __supported_pte_mask;
4439+
4440 for (i = 0; i < 16; i++) {
4441 pteval_t v = pgprot_val(protection_map[i]);
4442 protection_map[i] = __pgprot(v | user_pgprot);
4443@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4444
4445 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4446 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4447- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4448- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4449+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4450+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4451+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4452+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4453+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4454+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4455 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4456- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4457+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4458+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4459 mem_types[MT_ROM].prot_sect |= cp->pmd;
4460
4461 switch (cp->pmd) {
4462@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4463 * called function. This means you can't use any function or debugging
4464 * method which may touch any device, otherwise the kernel _will_ crash.
4465 */
4466+
4467+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4468+
4469 static void __init devicemaps_init(struct machine_desc *mdesc)
4470 {
4471 struct map_desc map;
4472 unsigned long addr;
4473- void *vectors;
4474
4475- /*
4476- * Allocate the vector page early.
4477- */
4478- vectors = early_alloc(PAGE_SIZE * 2);
4479-
4480- early_trap_init(vectors);
4481+ early_trap_init(&vectors);
4482
4483 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4484 pmd_clear(pmd_off_k(addr));
4485@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4486 * location (0xffff0000). If we aren't using high-vectors, also
4487 * create a mapping at the low-vectors virtual address.
4488 */
4489- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4490+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4491 map.virtual = 0xffff0000;
4492 map.length = PAGE_SIZE;
4493 #ifdef CONFIG_KUSER_HELPERS
4494@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4495 map.pfn = __phys_to_pfn(start);
4496 map.virtual = __phys_to_virt(start);
4497 map.length = end - start;
4498- map.type = MT_MEMORY;
4499
4500+#ifdef CONFIG_PAX_KERNEXEC
4501+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4502+ struct map_desc kernel;
4503+ struct map_desc initmap;
4504+
4505+ /* when freeing initmem we will make this RW */
4506+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4507+ initmap.virtual = (unsigned long)__init_begin;
4508+ initmap.length = _sdata - __init_begin;
4509+ initmap.type = MT_MEMORY_RWX;
4510+ create_mapping(&initmap);
4511+
4512+ /* when freeing initmem we will make this RX */
4513+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4514+ kernel.virtual = (unsigned long)_stext;
4515+ kernel.length = __init_begin - _stext;
4516+ kernel.type = MT_MEMORY_RWX;
4517+ create_mapping(&kernel);
4518+
4519+ if (map.virtual < (unsigned long)_stext) {
4520+ map.length = (unsigned long)_stext - map.virtual;
4521+ map.type = MT_MEMORY_RWX;
4522+ create_mapping(&map);
4523+ }
4524+
4525+ map.pfn = __phys_to_pfn(__pa(_sdata));
4526+ map.virtual = (unsigned long)_sdata;
4527+ map.length = end - __pa(_sdata);
4528+ }
4529+#endif
4530+
4531+ map.type = MT_MEMORY_RW;
4532 create_mapping(&map);
4533 }
4534 }
4535diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4536index a5bc92d..0bb4730 100644
4537--- a/arch/arm/plat-omap/sram.c
4538+++ b/arch/arm/plat-omap/sram.c
4539@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4540 * Looks like we need to preserve some bootloader code at the
4541 * beginning of SRAM for jumping to flash for reboot to work...
4542 */
4543+ pax_open_kernel();
4544 memset_io(omap_sram_base + omap_sram_skip, 0,
4545 omap_sram_size - omap_sram_skip);
4546+ pax_close_kernel();
4547 }
4548diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4549index ce6d763..cfea917 100644
4550--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4551+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4552@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4553 int (*started)(unsigned ch);
4554 int (*flush)(unsigned ch);
4555 int (*stop)(unsigned ch);
4556-};
4557+} __no_const;
4558
4559 extern void *samsung_dmadev_get_ops(void);
4560 extern void *s3c_dma_get_ops(void);
4561diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4562index c3a58a1..78fbf54 100644
4563--- a/arch/avr32/include/asm/cache.h
4564+++ b/arch/avr32/include/asm/cache.h
4565@@ -1,8 +1,10 @@
4566 #ifndef __ASM_AVR32_CACHE_H
4567 #define __ASM_AVR32_CACHE_H
4568
4569+#include <linux/const.h>
4570+
4571 #define L1_CACHE_SHIFT 5
4572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4574
4575 /*
4576 * Memory returned by kmalloc() may be used for DMA, so we must make
4577diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4578index d232888..87c8df1 100644
4579--- a/arch/avr32/include/asm/elf.h
4580+++ b/arch/avr32/include/asm/elf.h
4581@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4582 the loader. We need to make sure that it is out of the way of the program
4583 that it will "exec", and that there is sufficient room for the brk. */
4584
4585-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4586+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4587
4588+#ifdef CONFIG_PAX_ASLR
4589+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4590+
4591+#define PAX_DELTA_MMAP_LEN 15
4592+#define PAX_DELTA_STACK_LEN 15
4593+#endif
4594
4595 /* This yields a mask that user programs can use to figure out what
4596 instruction set this CPU supports. This could be done in user space,
4597diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4598index 479330b..53717a8 100644
4599--- a/arch/avr32/include/asm/kmap_types.h
4600+++ b/arch/avr32/include/asm/kmap_types.h
4601@@ -2,9 +2,9 @@
4602 #define __ASM_AVR32_KMAP_TYPES_H
4603
4604 #ifdef CONFIG_DEBUG_HIGHMEM
4605-# define KM_TYPE_NR 29
4606+# define KM_TYPE_NR 30
4607 #else
4608-# define KM_TYPE_NR 14
4609+# define KM_TYPE_NR 15
4610 #endif
4611
4612 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4613diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4614index b2f2d2d..d1c85cb 100644
4615--- a/arch/avr32/mm/fault.c
4616+++ b/arch/avr32/mm/fault.c
4617@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4618
4619 int exception_trace = 1;
4620
4621+#ifdef CONFIG_PAX_PAGEEXEC
4622+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4623+{
4624+ unsigned long i;
4625+
4626+ printk(KERN_ERR "PAX: bytes at PC: ");
4627+ for (i = 0; i < 20; i++) {
4628+ unsigned char c;
4629+ if (get_user(c, (unsigned char *)pc+i))
4630+ printk(KERN_CONT "???????? ");
4631+ else
4632+ printk(KERN_CONT "%02x ", c);
4633+ }
4634+ printk("\n");
4635+}
4636+#endif
4637+
4638 /*
4639 * This routine handles page faults. It determines the address and the
4640 * problem, and then passes it off to one of the appropriate routines.
4641@@ -174,6 +191,16 @@ bad_area:
4642 up_read(&mm->mmap_sem);
4643
4644 if (user_mode(regs)) {
4645+
4646+#ifdef CONFIG_PAX_PAGEEXEC
4647+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4648+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4649+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4650+ do_group_exit(SIGKILL);
4651+ }
4652+ }
4653+#endif
4654+
4655 if (exception_trace && printk_ratelimit())
4656 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4657 "sp %08lx ecr %lu\n",
4658diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4659index 568885a..f8008df 100644
4660--- a/arch/blackfin/include/asm/cache.h
4661+++ b/arch/blackfin/include/asm/cache.h
4662@@ -7,6 +7,7 @@
4663 #ifndef __ARCH_BLACKFIN_CACHE_H
4664 #define __ARCH_BLACKFIN_CACHE_H
4665
4666+#include <linux/const.h>
4667 #include <linux/linkage.h> /* for asmlinkage */
4668
4669 /*
4670@@ -14,7 +15,7 @@
4671 * Blackfin loads 32 bytes for cache
4672 */
4673 #define L1_CACHE_SHIFT 5
4674-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4675+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4676 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4677
4678 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4679diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4680index aea2718..3639a60 100644
4681--- a/arch/cris/include/arch-v10/arch/cache.h
4682+++ b/arch/cris/include/arch-v10/arch/cache.h
4683@@ -1,8 +1,9 @@
4684 #ifndef _ASM_ARCH_CACHE_H
4685 #define _ASM_ARCH_CACHE_H
4686
4687+#include <linux/const.h>
4688 /* Etrax 100LX have 32-byte cache-lines. */
4689-#define L1_CACHE_BYTES 32
4690 #define L1_CACHE_SHIFT 5
4691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4692
4693 #endif /* _ASM_ARCH_CACHE_H */
4694diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4695index 7caf25d..ee65ac5 100644
4696--- a/arch/cris/include/arch-v32/arch/cache.h
4697+++ b/arch/cris/include/arch-v32/arch/cache.h
4698@@ -1,11 +1,12 @@
4699 #ifndef _ASM_CRIS_ARCH_CACHE_H
4700 #define _ASM_CRIS_ARCH_CACHE_H
4701
4702+#include <linux/const.h>
4703 #include <arch/hwregs/dma.h>
4704
4705 /* A cache-line is 32 bytes. */
4706-#define L1_CACHE_BYTES 32
4707 #define L1_CACHE_SHIFT 5
4708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4709
4710 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4711
4712diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4713index b86329d..6709906 100644
4714--- a/arch/frv/include/asm/atomic.h
4715+++ b/arch/frv/include/asm/atomic.h
4716@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4717 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4718 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4719
4720+#define atomic64_read_unchecked(v) atomic64_read(v)
4721+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4722+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4723+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4724+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4725+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4726+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4727+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4728+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4729+
4730 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4731 {
4732 int c, old;
4733diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4734index 2797163..c2a401d 100644
4735--- a/arch/frv/include/asm/cache.h
4736+++ b/arch/frv/include/asm/cache.h
4737@@ -12,10 +12,11 @@
4738 #ifndef __ASM_CACHE_H
4739 #define __ASM_CACHE_H
4740
4741+#include <linux/const.h>
4742
4743 /* bytes per L1 cache line */
4744 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4749 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4750diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4751index 43901f2..0d8b865 100644
4752--- a/arch/frv/include/asm/kmap_types.h
4753+++ b/arch/frv/include/asm/kmap_types.h
4754@@ -2,6 +2,6 @@
4755 #ifndef _ASM_KMAP_TYPES_H
4756 #define _ASM_KMAP_TYPES_H
4757
4758-#define KM_TYPE_NR 17
4759+#define KM_TYPE_NR 18
4760
4761 #endif
4762diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4763index 836f147..4cf23f5 100644
4764--- a/arch/frv/mm/elf-fdpic.c
4765+++ b/arch/frv/mm/elf-fdpic.c
4766@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4767 {
4768 struct vm_area_struct *vma;
4769 struct vm_unmapped_area_info info;
4770+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4771
4772 if (len > TASK_SIZE)
4773 return -ENOMEM;
4774@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4775 if (addr) {
4776 addr = PAGE_ALIGN(addr);
4777 vma = find_vma(current->mm, addr);
4778- if (TASK_SIZE - len >= addr &&
4779- (!vma || addr + len <= vma->vm_start))
4780+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4781 goto success;
4782 }
4783
4784@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4785 info.high_limit = (current->mm->start_stack - 0x00200000);
4786 info.align_mask = 0;
4787 info.align_offset = 0;
4788+ info.threadstack_offset = offset;
4789 addr = vm_unmapped_area(&info);
4790 if (!(addr & ~PAGE_MASK))
4791 goto success;
4792diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4793index f4ca594..adc72fd6 100644
4794--- a/arch/hexagon/include/asm/cache.h
4795+++ b/arch/hexagon/include/asm/cache.h
4796@@ -21,9 +21,11 @@
4797 #ifndef __ASM_CACHE_H
4798 #define __ASM_CACHE_H
4799
4800+#include <linux/const.h>
4801+
4802 /* Bytes per L1 cache line */
4803-#define L1_CACHE_SHIFT (5)
4804-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4805+#define L1_CACHE_SHIFT 5
4806+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4807
4808 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4809 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4810diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4811index 6e6fe18..a6ae668 100644
4812--- a/arch/ia64/include/asm/atomic.h
4813+++ b/arch/ia64/include/asm/atomic.h
4814@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4815 #define atomic64_inc(v) atomic64_add(1, (v))
4816 #define atomic64_dec(v) atomic64_sub(1, (v))
4817
4818+#define atomic64_read_unchecked(v) atomic64_read(v)
4819+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4820+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4821+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4822+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4823+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4824+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4825+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4826+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4827+
4828 /* Atomic operations are already serializing */
4829 #define smp_mb__before_atomic_dec() barrier()
4830 #define smp_mb__after_atomic_dec() barrier()
4831diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4832index 988254a..e1ee885 100644
4833--- a/arch/ia64/include/asm/cache.h
4834+++ b/arch/ia64/include/asm/cache.h
4835@@ -1,6 +1,7 @@
4836 #ifndef _ASM_IA64_CACHE_H
4837 #define _ASM_IA64_CACHE_H
4838
4839+#include <linux/const.h>
4840
4841 /*
4842 * Copyright (C) 1998-2000 Hewlett-Packard Co
4843@@ -9,7 +10,7 @@
4844
4845 /* Bytes per L1 (data) cache line. */
4846 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4847-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4848+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4849
4850 #ifdef CONFIG_SMP
4851 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4852diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4853index 5a83c5c..4d7f553 100644
4854--- a/arch/ia64/include/asm/elf.h
4855+++ b/arch/ia64/include/asm/elf.h
4856@@ -42,6 +42,13 @@
4857 */
4858 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4859
4860+#ifdef CONFIG_PAX_ASLR
4861+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4862+
4863+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4864+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4865+#endif
4866+
4867 #define PT_IA_64_UNWIND 0x70000001
4868
4869 /* IA-64 relocations: */
4870diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4871index 96a8d92..617a1cf 100644
4872--- a/arch/ia64/include/asm/pgalloc.h
4873+++ b/arch/ia64/include/asm/pgalloc.h
4874@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4875 pgd_val(*pgd_entry) = __pa(pud);
4876 }
4877
4878+static inline void
4879+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4880+{
4881+ pgd_populate(mm, pgd_entry, pud);
4882+}
4883+
4884 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4885 {
4886 return quicklist_alloc(0, GFP_KERNEL, NULL);
4887@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4888 pud_val(*pud_entry) = __pa(pmd);
4889 }
4890
4891+static inline void
4892+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4893+{
4894+ pud_populate(mm, pud_entry, pmd);
4895+}
4896+
4897 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4898 {
4899 return quicklist_alloc(0, GFP_KERNEL, NULL);
4900diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4901index 7935115..c0eca6a 100644
4902--- a/arch/ia64/include/asm/pgtable.h
4903+++ b/arch/ia64/include/asm/pgtable.h
4904@@ -12,7 +12,7 @@
4905 * David Mosberger-Tang <davidm@hpl.hp.com>
4906 */
4907
4908-
4909+#include <linux/const.h>
4910 #include <asm/mman.h>
4911 #include <asm/page.h>
4912 #include <asm/processor.h>
4913@@ -142,6 +142,17 @@
4914 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4915 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4916 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4917+
4918+#ifdef CONFIG_PAX_PAGEEXEC
4919+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4920+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4921+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4922+#else
4923+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4924+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4925+# define PAGE_COPY_NOEXEC PAGE_COPY
4926+#endif
4927+
4928 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4929 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4930 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4931diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4932index 54ff557..70c88b7 100644
4933--- a/arch/ia64/include/asm/spinlock.h
4934+++ b/arch/ia64/include/asm/spinlock.h
4935@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4936 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4937
4938 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4939- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4940+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4941 }
4942
4943 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4944diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4945index 449c8c0..18965fb 100644
4946--- a/arch/ia64/include/asm/uaccess.h
4947+++ b/arch/ia64/include/asm/uaccess.h
4948@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4949 static inline unsigned long
4950 __copy_to_user (void __user *to, const void *from, unsigned long count)
4951 {
4952+ if (count > INT_MAX)
4953+ return count;
4954+
4955+ if (!__builtin_constant_p(count))
4956+ check_object_size(from, count, true);
4957+
4958 return __copy_user(to, (__force void __user *) from, count);
4959 }
4960
4961 static inline unsigned long
4962 __copy_from_user (void *to, const void __user *from, unsigned long count)
4963 {
4964+ if (count > INT_MAX)
4965+ return count;
4966+
4967+ if (!__builtin_constant_p(count))
4968+ check_object_size(to, count, false);
4969+
4970 return __copy_user((__force void __user *) to, from, count);
4971 }
4972
4973@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4974 ({ \
4975 void __user *__cu_to = (to); \
4976 const void *__cu_from = (from); \
4977- long __cu_len = (n); \
4978+ unsigned long __cu_len = (n); \
4979 \
4980- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4981+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4982+ if (!__builtin_constant_p(n)) \
4983+ check_object_size(__cu_from, __cu_len, true); \
4984 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4985+ } \
4986 __cu_len; \
4987 })
4988
4989@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4990 ({ \
4991 void *__cu_to = (to); \
4992 const void __user *__cu_from = (from); \
4993- long __cu_len = (n); \
4994+ unsigned long __cu_len = (n); \
4995 \
4996 __chk_user_ptr(__cu_from); \
4997- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4998+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4999+ if (!__builtin_constant_p(n)) \
5000+ check_object_size(__cu_to, __cu_len, false); \
5001 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5002+ } \
5003 __cu_len; \
5004 })
5005
5006diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5007index 24603be..948052d 100644
5008--- a/arch/ia64/kernel/module.c
5009+++ b/arch/ia64/kernel/module.c
5010@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5011 void
5012 module_free (struct module *mod, void *module_region)
5013 {
5014- if (mod && mod->arch.init_unw_table &&
5015- module_region == mod->module_init) {
5016+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5017 unw_remove_unwind_table(mod->arch.init_unw_table);
5018 mod->arch.init_unw_table = NULL;
5019 }
5020@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5021 }
5022
5023 static inline int
5024+in_init_rx (const struct module *mod, uint64_t addr)
5025+{
5026+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5027+}
5028+
5029+static inline int
5030+in_init_rw (const struct module *mod, uint64_t addr)
5031+{
5032+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5033+}
5034+
5035+static inline int
5036 in_init (const struct module *mod, uint64_t addr)
5037 {
5038- return addr - (uint64_t) mod->module_init < mod->init_size;
5039+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5040+}
5041+
5042+static inline int
5043+in_core_rx (const struct module *mod, uint64_t addr)
5044+{
5045+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5046+}
5047+
5048+static inline int
5049+in_core_rw (const struct module *mod, uint64_t addr)
5050+{
5051+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5052 }
5053
5054 static inline int
5055 in_core (const struct module *mod, uint64_t addr)
5056 {
5057- return addr - (uint64_t) mod->module_core < mod->core_size;
5058+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5059 }
5060
5061 static inline int
5062@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5063 break;
5064
5065 case RV_BDREL:
5066- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5067+ if (in_init_rx(mod, val))
5068+ val -= (uint64_t) mod->module_init_rx;
5069+ else if (in_init_rw(mod, val))
5070+ val -= (uint64_t) mod->module_init_rw;
5071+ else if (in_core_rx(mod, val))
5072+ val -= (uint64_t) mod->module_core_rx;
5073+ else if (in_core_rw(mod, val))
5074+ val -= (uint64_t) mod->module_core_rw;
5075 break;
5076
5077 case RV_LTV:
5078@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5079 * addresses have been selected...
5080 */
5081 uint64_t gp;
5082- if (mod->core_size > MAX_LTOFF)
5083+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5084 /*
5085 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5086 * at the end of the module.
5087 */
5088- gp = mod->core_size - MAX_LTOFF / 2;
5089+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5090 else
5091- gp = mod->core_size / 2;
5092- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5093+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5094+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5095 mod->arch.gp = gp;
5096 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5097 }
5098diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5099index ab33328..f39506c 100644
5100--- a/arch/ia64/kernel/palinfo.c
5101+++ b/arch/ia64/kernel/palinfo.c
5102@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5103 return NOTIFY_OK;
5104 }
5105
5106-static struct notifier_block __refdata palinfo_cpu_notifier =
5107+static struct notifier_block palinfo_cpu_notifier =
5108 {
5109 .notifier_call = palinfo_cpu_callback,
5110 .priority = 0,
5111diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5112index 41e33f8..65180b2 100644
5113--- a/arch/ia64/kernel/sys_ia64.c
5114+++ b/arch/ia64/kernel/sys_ia64.c
5115@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5116 unsigned long align_mask = 0;
5117 struct mm_struct *mm = current->mm;
5118 struct vm_unmapped_area_info info;
5119+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5120
5121 if (len > RGN_MAP_LIMIT)
5122 return -ENOMEM;
5123@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5124 if (REGION_NUMBER(addr) == RGN_HPAGE)
5125 addr = 0;
5126 #endif
5127+
5128+#ifdef CONFIG_PAX_RANDMMAP
5129+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5130+ addr = mm->free_area_cache;
5131+ else
5132+#endif
5133+
5134 if (!addr)
5135 addr = TASK_UNMAPPED_BASE;
5136
5137@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5138 info.high_limit = TASK_SIZE;
5139 info.align_mask = align_mask;
5140 info.align_offset = 0;
5141+ info.threadstack_offset = offset;
5142 return vm_unmapped_area(&info);
5143 }
5144
5145diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5146index 0ccb28f..8992469 100644
5147--- a/arch/ia64/kernel/vmlinux.lds.S
5148+++ b/arch/ia64/kernel/vmlinux.lds.S
5149@@ -198,7 +198,7 @@ SECTIONS {
5150 /* Per-cpu data: */
5151 . = ALIGN(PERCPU_PAGE_SIZE);
5152 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5153- __phys_per_cpu_start = __per_cpu_load;
5154+ __phys_per_cpu_start = per_cpu_load;
5155 /*
5156 * ensure percpu data fits
5157 * into percpu page size
5158diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5159index 6cf0341..d352594 100644
5160--- a/arch/ia64/mm/fault.c
5161+++ b/arch/ia64/mm/fault.c
5162@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5163 return pte_present(pte);
5164 }
5165
5166+#ifdef CONFIG_PAX_PAGEEXEC
5167+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5168+{
5169+ unsigned long i;
5170+
5171+ printk(KERN_ERR "PAX: bytes at PC: ");
5172+ for (i = 0; i < 8; i++) {
5173+ unsigned int c;
5174+ if (get_user(c, (unsigned int *)pc+i))
5175+ printk(KERN_CONT "???????? ");
5176+ else
5177+ printk(KERN_CONT "%08x ", c);
5178+ }
5179+ printk("\n");
5180+}
5181+#endif
5182+
5183 # define VM_READ_BIT 0
5184 # define VM_WRITE_BIT 1
5185 # define VM_EXEC_BIT 2
5186@@ -149,8 +166,21 @@ retry:
5187 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5188 goto bad_area;
5189
5190- if ((vma->vm_flags & mask) != mask)
5191+ if ((vma->vm_flags & mask) != mask) {
5192+
5193+#ifdef CONFIG_PAX_PAGEEXEC
5194+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5195+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5196+ goto bad_area;
5197+
5198+ up_read(&mm->mmap_sem);
5199+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5200+ do_group_exit(SIGKILL);
5201+ }
5202+#endif
5203+
5204 goto bad_area;
5205+ }
5206
5207 /*
5208 * If for any reason at all we couldn't handle the fault, make
5209diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5210index 76069c1..c2aa816 100644
5211--- a/arch/ia64/mm/hugetlbpage.c
5212+++ b/arch/ia64/mm/hugetlbpage.c
5213@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5214 unsigned long pgoff, unsigned long flags)
5215 {
5216 struct vm_unmapped_area_info info;
5217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5218
5219 if (len > RGN_MAP_LIMIT)
5220 return -ENOMEM;
5221@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5222 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5223 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5224 info.align_offset = 0;
5225+ info.threadstack_offset = offset;
5226 return vm_unmapped_area(&info);
5227 }
5228
5229diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5230index b6f7f43..c04320d 100644
5231--- a/arch/ia64/mm/init.c
5232+++ b/arch/ia64/mm/init.c
5233@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5234 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5235 vma->vm_end = vma->vm_start + PAGE_SIZE;
5236 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5237+
5238+#ifdef CONFIG_PAX_PAGEEXEC
5239+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5240+ vma->vm_flags &= ~VM_EXEC;
5241+
5242+#ifdef CONFIG_PAX_MPROTECT
5243+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5244+ vma->vm_flags &= ~VM_MAYEXEC;
5245+#endif
5246+
5247+ }
5248+#endif
5249+
5250 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5251 down_write(&current->mm->mmap_sem);
5252 if (insert_vm_struct(current->mm, vma)) {
5253diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5254index 40b3ee9..8c2c112 100644
5255--- a/arch/m32r/include/asm/cache.h
5256+++ b/arch/m32r/include/asm/cache.h
5257@@ -1,8 +1,10 @@
5258 #ifndef _ASM_M32R_CACHE_H
5259 #define _ASM_M32R_CACHE_H
5260
5261+#include <linux/const.h>
5262+
5263 /* L1 cache line size */
5264 #define L1_CACHE_SHIFT 4
5265-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5266+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5267
5268 #endif /* _ASM_M32R_CACHE_H */
5269diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5270index 82abd15..d95ae5d 100644
5271--- a/arch/m32r/lib/usercopy.c
5272+++ b/arch/m32r/lib/usercopy.c
5273@@ -14,6 +14,9 @@
5274 unsigned long
5275 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5276 {
5277+ if ((long)n < 0)
5278+ return n;
5279+
5280 prefetch(from);
5281 if (access_ok(VERIFY_WRITE, to, n))
5282 __copy_user(to,from,n);
5283@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5284 unsigned long
5285 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5286 {
5287+ if ((long)n < 0)
5288+ return n;
5289+
5290 prefetchw(to);
5291 if (access_ok(VERIFY_READ, from, n))
5292 __copy_user_zeroing(to,from,n);
5293diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5294index 0395c51..5f26031 100644
5295--- a/arch/m68k/include/asm/cache.h
5296+++ b/arch/m68k/include/asm/cache.h
5297@@ -4,9 +4,11 @@
5298 #ifndef __ARCH_M68K_CACHE_H
5299 #define __ARCH_M68K_CACHE_H
5300
5301+#include <linux/const.h>
5302+
5303 /* bytes per L1 cache line */
5304 #define L1_CACHE_SHIFT 4
5305-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5306+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5307
5308 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5309
5310diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5311index 3c52fa6..11b2ad8 100644
5312--- a/arch/metag/mm/hugetlbpage.c
5313+++ b/arch/metag/mm/hugetlbpage.c
5314@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5315 info.high_limit = TASK_SIZE;
5316 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5317 info.align_offset = 0;
5318+ info.threadstack_offset = 0;
5319 return vm_unmapped_area(&info);
5320 }
5321
5322diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5323index 4efe96a..60e8699 100644
5324--- a/arch/microblaze/include/asm/cache.h
5325+++ b/arch/microblaze/include/asm/cache.h
5326@@ -13,11 +13,12 @@
5327 #ifndef _ASM_MICROBLAZE_CACHE_H
5328 #define _ASM_MICROBLAZE_CACHE_H
5329
5330+#include <linux/const.h>
5331 #include <asm/registers.h>
5332
5333 #define L1_CACHE_SHIFT 5
5334 /* word-granular cache in microblaze */
5335-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5336+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5337
5338 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5339
5340diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5341index 08b6079..8b554d2 100644
5342--- a/arch/mips/include/asm/atomic.h
5343+++ b/arch/mips/include/asm/atomic.h
5344@@ -21,15 +21,39 @@
5345 #include <asm/cmpxchg.h>
5346 #include <asm/war.h>
5347
5348+#ifdef CONFIG_GENERIC_ATOMIC64
5349+#include <asm-generic/atomic64.h>
5350+#endif
5351+
5352 #define ATOMIC_INIT(i) { (i) }
5353
5354+#ifdef CONFIG_64BIT
5355+#define _ASM_EXTABLE(from, to) \
5356+" .section __ex_table,\"a\"\n" \
5357+" .dword " #from ", " #to"\n" \
5358+" .previous\n"
5359+#else
5360+#define _ASM_EXTABLE(from, to) \
5361+" .section __ex_table,\"a\"\n" \
5362+" .word " #from ", " #to"\n" \
5363+" .previous\n"
5364+#endif
5365+
5366 /*
5367 * atomic_read - read atomic variable
5368 * @v: pointer of type atomic_t
5369 *
5370 * Atomically reads the value of @v.
5371 */
5372-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5373+static inline int atomic_read(const atomic_t *v)
5374+{
5375+ return (*(volatile const int *) &v->counter);
5376+}
5377+
5378+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5379+{
5380+ return (*(volatile const int *) &v->counter);
5381+}
5382
5383 /*
5384 * atomic_set - set atomic variable
5385@@ -38,7 +62,15 @@
5386 *
5387 * Atomically sets the value of @v to @i.
5388 */
5389-#define atomic_set(v, i) ((v)->counter = (i))
5390+static inline void atomic_set(atomic_t *v, int i)
5391+{
5392+ v->counter = i;
5393+}
5394+
5395+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5396+{
5397+ v->counter = i;
5398+}
5399
5400 /*
5401 * atomic_add - add integer to atomic variable
5402@@ -47,7 +79,67 @@
5403 *
5404 * Atomically adds @i to @v.
5405 */
5406-static __inline__ void atomic_add(int i, atomic_t * v)
5407+static __inline__ void atomic_add(int i, atomic_t *v)
5408+{
5409+ int temp;
5410+
5411+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5412+ __asm__ __volatile__(
5413+ " .set mips3 \n"
5414+ "1: ll %0, %1 # atomic_add \n"
5415+#ifdef CONFIG_PAX_REFCOUNT
5416+ /* Exception on overflow. */
5417+ "2: add %0, %2 \n"
5418+#else
5419+ " addu %0, %2 \n"
5420+#endif
5421+ " sc %0, %1 \n"
5422+ " beqzl %0, 1b \n"
5423+#ifdef CONFIG_PAX_REFCOUNT
5424+ "3: \n"
5425+ _ASM_EXTABLE(2b, 3b)
5426+#endif
5427+ " .set mips0 \n"
5428+ : "=&r" (temp), "+m" (v->counter)
5429+ : "Ir" (i));
5430+ } else if (kernel_uses_llsc) {
5431+ __asm__ __volatile__(
5432+ " .set mips3 \n"
5433+ "1: ll %0, %1 # atomic_add \n"
5434+#ifdef CONFIG_PAX_REFCOUNT
5435+ /* Exception on overflow. */
5436+ "2: add %0, %2 \n"
5437+#else
5438+ " addu %0, %2 \n"
5439+#endif
5440+ " sc %0, %1 \n"
5441+ " beqz %0, 1b \n"
5442+#ifdef CONFIG_PAX_REFCOUNT
5443+ "3: \n"
5444+ _ASM_EXTABLE(2b, 3b)
5445+#endif
5446+ " .set mips0 \n"
5447+ : "=&r" (temp), "+m" (v->counter)
5448+ : "Ir" (i));
5449+ } else {
5450+ unsigned long flags;
5451+
5452+ raw_local_irq_save(flags);
5453+ __asm__ __volatile__(
5454+#ifdef CONFIG_PAX_REFCOUNT
5455+ /* Exception on overflow. */
5456+ "1: add %0, %1 \n"
5457+ "2: \n"
5458+ _ASM_EXTABLE(1b, 2b)
5459+#else
5460+ " addu %0, %1 \n"
5461+#endif
5462+ : "+r" (v->counter) : "Ir" (i));
5463+ raw_local_irq_restore(flags);
5464+ }
5465+}
5466+
5467+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5468 {
5469 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5470 int temp;
5471@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5472 *
5473 * Atomically subtracts @i from @v.
5474 */
5475-static __inline__ void atomic_sub(int i, atomic_t * v)
5476+static __inline__ void atomic_sub(int i, atomic_t *v)
5477+{
5478+ int temp;
5479+
5480+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5481+ __asm__ __volatile__(
5482+ " .set mips3 \n"
5483+ "1: ll %0, %1 # atomic64_sub \n"
5484+#ifdef CONFIG_PAX_REFCOUNT
5485+ /* Exception on overflow. */
5486+ "2: sub %0, %2 \n"
5487+#else
5488+ " subu %0, %2 \n"
5489+#endif
5490+ " sc %0, %1 \n"
5491+ " beqzl %0, 1b \n"
5492+#ifdef CONFIG_PAX_REFCOUNT
5493+ "3: \n"
5494+ _ASM_EXTABLE(2b, 3b)
5495+#endif
5496+ " .set mips0 \n"
5497+ : "=&r" (temp), "+m" (v->counter)
5498+ : "Ir" (i));
5499+ } else if (kernel_uses_llsc) {
5500+ __asm__ __volatile__(
5501+ " .set mips3 \n"
5502+ "1: ll %0, %1 # atomic64_sub \n"
5503+#ifdef CONFIG_PAX_REFCOUNT
5504+ /* Exception on overflow. */
5505+ "2: sub %0, %2 \n"
5506+#else
5507+ " subu %0, %2 \n"
5508+#endif
5509+ " sc %0, %1 \n"
5510+ " beqz %0, 1b \n"
5511+#ifdef CONFIG_PAX_REFCOUNT
5512+ "3: \n"
5513+ _ASM_EXTABLE(2b, 3b)
5514+#endif
5515+ " .set mips0 \n"
5516+ : "=&r" (temp), "+m" (v->counter)
5517+ : "Ir" (i));
5518+ } else {
5519+ unsigned long flags;
5520+
5521+ raw_local_irq_save(flags);
5522+ __asm__ __volatile__(
5523+#ifdef CONFIG_PAX_REFCOUNT
5524+ /* Exception on overflow. */
5525+ "1: sub %0, %1 \n"
5526+ "2: \n"
5527+ _ASM_EXTABLE(1b, 2b)
5528+#else
5529+ " subu %0, %1 \n"
5530+#endif
5531+ : "+r" (v->counter) : "Ir" (i));
5532+ raw_local_irq_restore(flags);
5533+ }
5534+}
5535+
5536+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5537 {
5538 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5539 int temp;
5540@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5541 /*
5542 * Same as above, but return the result value
5543 */
5544-static __inline__ int atomic_add_return(int i, atomic_t * v)
5545+static __inline__ int atomic_add_return(int i, atomic_t *v)
5546+{
5547+ int result;
5548+ int temp;
5549+
5550+ smp_mb__before_llsc();
5551+
5552+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5553+ __asm__ __volatile__(
5554+ " .set mips3 \n"
5555+ "1: ll %1, %2 # atomic_add_return \n"
5556+#ifdef CONFIG_PAX_REFCOUNT
5557+ "2: add %0, %1, %3 \n"
5558+#else
5559+ " addu %0, %1, %3 \n"
5560+#endif
5561+ " sc %0, %2 \n"
5562+ " beqzl %0, 1b \n"
5563+#ifdef CONFIG_PAX_REFCOUNT
5564+ " b 4f \n"
5565+ " .set noreorder \n"
5566+ "3: b 5f \n"
5567+ " move %0, %1 \n"
5568+ " .set reorder \n"
5569+ _ASM_EXTABLE(2b, 3b)
5570+#endif
5571+ "4: addu %0, %1, %3 \n"
5572+#ifdef CONFIG_PAX_REFCOUNT
5573+ "5: \n"
5574+#endif
5575+ " .set mips0 \n"
5576+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5577+ : "Ir" (i));
5578+ } else if (kernel_uses_llsc) {
5579+ __asm__ __volatile__(
5580+ " .set mips3 \n"
5581+ "1: ll %1, %2 # atomic_add_return \n"
5582+#ifdef CONFIG_PAX_REFCOUNT
5583+ "2: add %0, %1, %3 \n"
5584+#else
5585+ " addu %0, %1, %3 \n"
5586+#endif
5587+ " sc %0, %2 \n"
5588+ " bnez %0, 4f \n"
5589+ " b 1b \n"
5590+#ifdef CONFIG_PAX_REFCOUNT
5591+ " .set noreorder \n"
5592+ "3: b 5f \n"
5593+ " move %0, %1 \n"
5594+ " .set reorder \n"
5595+ _ASM_EXTABLE(2b, 3b)
5596+#endif
5597+ "4: addu %0, %1, %3 \n"
5598+#ifdef CONFIG_PAX_REFCOUNT
5599+ "5: \n"
5600+#endif
5601+ " .set mips0 \n"
5602+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5603+ : "Ir" (i));
5604+ } else {
5605+ unsigned long flags;
5606+
5607+ raw_local_irq_save(flags);
5608+ __asm__ __volatile__(
5609+ " lw %0, %1 \n"
5610+#ifdef CONFIG_PAX_REFCOUNT
5611+ /* Exception on overflow. */
5612+ "1: add %0, %2 \n"
5613+#else
5614+ " addu %0, %2 \n"
5615+#endif
5616+ " sw %0, %1 \n"
5617+#ifdef CONFIG_PAX_REFCOUNT
5618+ /* Note: Dest reg is not modified on overflow */
5619+ "2: \n"
5620+ _ASM_EXTABLE(1b, 2b)
5621+#endif
5622+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5623+ raw_local_irq_restore(flags);
5624+ }
5625+
5626+ smp_llsc_mb();
5627+
5628+ return result;
5629+}
5630+
5631+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5632 {
5633 int result;
5634
5635@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5636 return result;
5637 }
5638
5639-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5640+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5641+{
5642+ int result;
5643+ int temp;
5644+
5645+ smp_mb__before_llsc();
5646+
5647+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5648+ __asm__ __volatile__(
5649+ " .set mips3 \n"
5650+ "1: ll %1, %2 # atomic_sub_return \n"
5651+#ifdef CONFIG_PAX_REFCOUNT
5652+ "2: sub %0, %1, %3 \n"
5653+#else
5654+ " subu %0, %1, %3 \n"
5655+#endif
5656+ " sc %0, %2 \n"
5657+ " beqzl %0, 1b \n"
5658+#ifdef CONFIG_PAX_REFCOUNT
5659+ " b 4f \n"
5660+ " .set noreorder \n"
5661+ "3: b 5f \n"
5662+ " move %0, %1 \n"
5663+ " .set reorder \n"
5664+ _ASM_EXTABLE(2b, 3b)
5665+#endif
5666+ "4: subu %0, %1, %3 \n"
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ "5: \n"
5669+#endif
5670+ " .set mips0 \n"
5671+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5672+ : "Ir" (i), "m" (v->counter)
5673+ : "memory");
5674+ } else if (kernel_uses_llsc) {
5675+ __asm__ __volatile__(
5676+ " .set mips3 \n"
5677+ "1: ll %1, %2 # atomic_sub_return \n"
5678+#ifdef CONFIG_PAX_REFCOUNT
5679+ "2: sub %0, %1, %3 \n"
5680+#else
5681+ " subu %0, %1, %3 \n"
5682+#endif
5683+ " sc %0, %2 \n"
5684+ " bnez %0, 4f \n"
5685+ " b 1b \n"
5686+#ifdef CONFIG_PAX_REFCOUNT
5687+ " .set noreorder \n"
5688+ "3: b 5f \n"
5689+ " move %0, %1 \n"
5690+ " .set reorder \n"
5691+ _ASM_EXTABLE(2b, 3b)
5692+#endif
5693+ "4: subu %0, %1, %3 \n"
5694+#ifdef CONFIG_PAX_REFCOUNT
5695+ "5: \n"
5696+#endif
5697+ " .set mips0 \n"
5698+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5699+ : "Ir" (i));
5700+ } else {
5701+ unsigned long flags;
5702+
5703+ raw_local_irq_save(flags);
5704+ __asm__ __volatile__(
5705+ " lw %0, %1 \n"
5706+#ifdef CONFIG_PAX_REFCOUNT
5707+ /* Exception on overflow. */
5708+ "1: sub %0, %2 \n"
5709+#else
5710+ " subu %0, %2 \n"
5711+#endif
5712+ " sw %0, %1 \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ /* Note: Dest reg is not modified on overflow */
5715+ "2: \n"
5716+ _ASM_EXTABLE(1b, 2b)
5717+#endif
5718+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5719+ raw_local_irq_restore(flags);
5720+ }
5721+
5722+ smp_llsc_mb();
5723+
5724+ return result;
5725+}
5726+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5727 {
5728 int result;
5729
5730@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5731 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5732 * The function returns the old value of @v minus @i.
5733 */
5734-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5735+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5736 {
5737 int result;
5738
5739@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5740 return result;
5741 }
5742
5743-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5744-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5745+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5746+{
5747+ return cmpxchg(&v->counter, old, new);
5748+}
5749+
5750+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5751+ int new)
5752+{
5753+ return cmpxchg(&(v->counter), old, new);
5754+}
5755+
5756+static inline int atomic_xchg(atomic_t *v, int new)
5757+{
5758+ return xchg(&v->counter, new);
5759+}
5760+
5761+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5762+{
5763+ return xchg(&(v->counter), new);
5764+}
5765
5766 /**
5767 * __atomic_add_unless - add unless the number is a given value
5768@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5769
5770 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5771 #define atomic_inc_return(v) atomic_add_return(1, (v))
5772+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5773+{
5774+ return atomic_add_return_unchecked(1, v);
5775+}
5776
5777 /*
5778 * atomic_sub_and_test - subtract value from variable and test result
5779@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5780 * other cases.
5781 */
5782 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5783+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5784+{
5785+ return atomic_add_return_unchecked(1, v) == 0;
5786+}
5787
5788 /*
5789 * atomic_dec_and_test - decrement by 1 and test
5790@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5791 * Atomically increments @v by 1.
5792 */
5793 #define atomic_inc(v) atomic_add(1, (v))
5794+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5795+{
5796+ atomic_add_unchecked(1, v);
5797+}
5798
5799 /*
5800 * atomic_dec - decrement and test
5801@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5802 * Atomically decrements @v by 1.
5803 */
5804 #define atomic_dec(v) atomic_sub(1, (v))
5805+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5806+{
5807+ atomic_sub_unchecked(1, v);
5808+}
5809
5810 /*
5811 * atomic_add_negative - add and test if negative
5812@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5813 * @v: pointer of type atomic64_t
5814 *
5815 */
5816-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5817+static inline long atomic64_read(const atomic64_t *v)
5818+{
5819+ return (*(volatile const long *) &v->counter);
5820+}
5821+
5822+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5823+{
5824+ return (*(volatile const long *) &v->counter);
5825+}
5826
5827 /*
5828 * atomic64_set - set atomic variable
5829 * @v: pointer of type atomic64_t
5830 * @i: required value
5831 */
5832-#define atomic64_set(v, i) ((v)->counter = (i))
5833+static inline void atomic64_set(atomic64_t *v, long i)
5834+{
5835+ v->counter = i;
5836+}
5837+
5838+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5839+{
5840+ v->counter = i;
5841+}
5842
5843 /*
5844 * atomic64_add - add integer to atomic variable
5845@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5846 *
5847 * Atomically adds @i to @v.
5848 */
5849-static __inline__ void atomic64_add(long i, atomic64_t * v)
5850+static __inline__ void atomic64_add(long i, atomic64_t *v)
5851+{
5852+ long temp;
5853+
5854+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5855+ __asm__ __volatile__(
5856+ " .set mips3 \n"
5857+ "1: lld %0, %1 # atomic64_add \n"
5858+#ifdef CONFIG_PAX_REFCOUNT
5859+ /* Exception on overflow. */
5860+ "2: dadd %0, %2 \n"
5861+#else
5862+ " daddu %0, %2 \n"
5863+#endif
5864+ " scd %0, %1 \n"
5865+ " beqzl %0, 1b \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ "3: \n"
5868+ _ASM_EXTABLE(2b, 3b)
5869+#endif
5870+ " .set mips0 \n"
5871+ : "=&r" (temp), "+m" (v->counter)
5872+ : "Ir" (i));
5873+ } else if (kernel_uses_llsc) {
5874+ __asm__ __volatile__(
5875+ " .set mips3 \n"
5876+ "1: lld %0, %1 # atomic64_add \n"
5877+#ifdef CONFIG_PAX_REFCOUNT
5878+ /* Exception on overflow. */
5879+ "2: dadd %0, %2 \n"
5880+#else
5881+ " daddu %0, %2 \n"
5882+#endif
5883+ " scd %0, %1 \n"
5884+ " beqz %0, 1b \n"
5885+#ifdef CONFIG_PAX_REFCOUNT
5886+ "3: \n"
5887+ _ASM_EXTABLE(2b, 3b)
5888+#endif
5889+ " .set mips0 \n"
5890+ : "=&r" (temp), "+m" (v->counter)
5891+ : "Ir" (i));
5892+ } else {
5893+ unsigned long flags;
5894+
5895+ raw_local_irq_save(flags);
5896+ __asm__ __volatile__(
5897+#ifdef CONFIG_PAX_REFCOUNT
5898+ /* Exception on overflow. */
5899+ "1: dadd %0, %1 \n"
5900+ "2: \n"
5901+ _ASM_EXTABLE(1b, 2b)
5902+#else
5903+ " daddu %0, %1 \n"
5904+#endif
5905+ : "+r" (v->counter) : "Ir" (i));
5906+ raw_local_irq_restore(flags);
5907+ }
5908+}
5909+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5910 {
5911 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5912 long temp;
5913@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5914 *
5915 * Atomically subtracts @i from @v.
5916 */
5917-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5918+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5919+{
5920+ long temp;
5921+
5922+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5923+ __asm__ __volatile__(
5924+ " .set mips3 \n"
5925+ "1: lld %0, %1 # atomic64_sub \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Exception on overflow. */
5928+ "2: dsub %0, %2 \n"
5929+#else
5930+ " dsubu %0, %2 \n"
5931+#endif
5932+ " scd %0, %1 \n"
5933+ " beqzl %0, 1b \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ "3: \n"
5936+ _ASM_EXTABLE(2b, 3b)
5937+#endif
5938+ " .set mips0 \n"
5939+ : "=&r" (temp), "+m" (v->counter)
5940+ : "Ir" (i));
5941+ } else if (kernel_uses_llsc) {
5942+ __asm__ __volatile__(
5943+ " .set mips3 \n"
5944+ "1: lld %0, %1 # atomic64_sub \n"
5945+#ifdef CONFIG_PAX_REFCOUNT
5946+ /* Exception on overflow. */
5947+ "2: dsub %0, %2 \n"
5948+#else
5949+ " dsubu %0, %2 \n"
5950+#endif
5951+ " scd %0, %1 \n"
5952+ " beqz %0, 1b \n"
5953+#ifdef CONFIG_PAX_REFCOUNT
5954+ "3: \n"
5955+ _ASM_EXTABLE(2b, 3b)
5956+#endif
5957+ " .set mips0 \n"
5958+ : "=&r" (temp), "+m" (v->counter)
5959+ : "Ir" (i));
5960+ } else {
5961+ unsigned long flags;
5962+
5963+ raw_local_irq_save(flags);
5964+ __asm__ __volatile__(
5965+#ifdef CONFIG_PAX_REFCOUNT
5966+ /* Exception on overflow. */
5967+ "1: dsub %0, %1 \n"
5968+ "2: \n"
5969+ _ASM_EXTABLE(1b, 2b)
5970+#else
5971+ " dsubu %0, %1 \n"
5972+#endif
5973+ : "+r" (v->counter) : "Ir" (i));
5974+ raw_local_irq_restore(flags);
5975+ }
5976+}
5977+
5978+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5979 {
5980 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5981 long temp;
5982@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5983 /*
5984 * Same as above, but return the result value
5985 */
5986-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5987+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5988+{
5989+ long result;
5990+ long temp;
5991+
5992+ smp_mb__before_llsc();
5993+
5994+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5995+ __asm__ __volatile__(
5996+ " .set mips3 \n"
5997+ "1: lld %1, %2 # atomic64_add_return \n"
5998+#ifdef CONFIG_PAX_REFCOUNT
5999+ "2: dadd %0, %1, %3 \n"
6000+#else
6001+ " daddu %0, %1, %3 \n"
6002+#endif
6003+ " scd %0, %2 \n"
6004+ " beqzl %0, 1b \n"
6005+#ifdef CONFIG_PAX_REFCOUNT
6006+ " b 4f \n"
6007+ " .set noreorder \n"
6008+ "3: b 5f \n"
6009+ " move %0, %1 \n"
6010+ " .set reorder \n"
6011+ _ASM_EXTABLE(2b, 3b)
6012+#endif
6013+ "4: daddu %0, %1, %3 \n"
6014+#ifdef CONFIG_PAX_REFCOUNT
6015+ "5: \n"
6016+#endif
6017+ " .set mips0 \n"
6018+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6019+ : "Ir" (i));
6020+ } else if (kernel_uses_llsc) {
6021+ __asm__ __volatile__(
6022+ " .set mips3 \n"
6023+ "1: lld %1, %2 # atomic64_add_return \n"
6024+#ifdef CONFIG_PAX_REFCOUNT
6025+ "2: dadd %0, %1, %3 \n"
6026+#else
6027+ " daddu %0, %1, %3 \n"
6028+#endif
6029+ " scd %0, %2 \n"
6030+ " bnez %0, 4f \n"
6031+ " b 1b \n"
6032+#ifdef CONFIG_PAX_REFCOUNT
6033+ " .set noreorder \n"
6034+ "3: b 5f \n"
6035+ " move %0, %1 \n"
6036+ " .set reorder \n"
6037+ _ASM_EXTABLE(2b, 3b)
6038+#endif
6039+ "4: daddu %0, %1, %3 \n"
6040+#ifdef CONFIG_PAX_REFCOUNT
6041+ "5: \n"
6042+#endif
6043+ " .set mips0 \n"
6044+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6045+ : "Ir" (i), "m" (v->counter)
6046+ : "memory");
6047+ } else {
6048+ unsigned long flags;
6049+
6050+ raw_local_irq_save(flags);
6051+ __asm__ __volatile__(
6052+ " ld %0, %1 \n"
6053+#ifdef CONFIG_PAX_REFCOUNT
6054+ /* Exception on overflow. */
6055+ "1: dadd %0, %2 \n"
6056+#else
6057+ " daddu %0, %2 \n"
6058+#endif
6059+ " sd %0, %1 \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ /* Note: Dest reg is not modified on overflow */
6062+ "2: \n"
6063+ _ASM_EXTABLE(1b, 2b)
6064+#endif
6065+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6066+ raw_local_irq_restore(flags);
6067+ }
6068+
6069+ smp_llsc_mb();
6070+
6071+ return result;
6072+}
6073+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6074 {
6075 long result;
6076
6077@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6078 return result;
6079 }
6080
6081-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6082+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6083+{
6084+ long result;
6085+ long temp;
6086+
6087+ smp_mb__before_llsc();
6088+
6089+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6090+ long temp;
6091+
6092+ __asm__ __volatile__(
6093+ " .set mips3 \n"
6094+ "1: lld %1, %2 # atomic64_sub_return \n"
6095+#ifdef CONFIG_PAX_REFCOUNT
6096+ "2: dsub %0, %1, %3 \n"
6097+#else
6098+ " dsubu %0, %1, %3 \n"
6099+#endif
6100+ " scd %0, %2 \n"
6101+ " beqzl %0, 1b \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ " b 4f \n"
6104+ " .set noreorder \n"
6105+ "3: b 5f \n"
6106+ " move %0, %1 \n"
6107+ " .set reorder \n"
6108+ _ASM_EXTABLE(2b, 3b)
6109+#endif
6110+ "4: dsubu %0, %1, %3 \n"
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ "5: \n"
6113+#endif
6114+ " .set mips0 \n"
6115+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6116+ : "Ir" (i), "m" (v->counter)
6117+ : "memory");
6118+ } else if (kernel_uses_llsc) {
6119+ __asm__ __volatile__(
6120+ " .set mips3 \n"
6121+ "1: lld %1, %2 # atomic64_sub_return \n"
6122+#ifdef CONFIG_PAX_REFCOUNT
6123+ "2: dsub %0, %1, %3 \n"
6124+#else
6125+ " dsubu %0, %1, %3 \n"
6126+#endif
6127+ " scd %0, %2 \n"
6128+ " bnez %0, 4f \n"
6129+ " b 1b \n"
6130+#ifdef CONFIG_PAX_REFCOUNT
6131+ " .set noreorder \n"
6132+ "3: b 5f \n"
6133+ " move %0, %1 \n"
6134+ " .set reorder \n"
6135+ _ASM_EXTABLE(2b, 3b)
6136+#endif
6137+ "4: dsubu %0, %1, %3 \n"
6138+#ifdef CONFIG_PAX_REFCOUNT
6139+ "5: \n"
6140+#endif
6141+ " .set mips0 \n"
6142+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6143+ : "Ir" (i), "m" (v->counter)
6144+ : "memory");
6145+ } else {
6146+ unsigned long flags;
6147+
6148+ raw_local_irq_save(flags);
6149+ __asm__ __volatile__(
6150+ " ld %0, %1 \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ /* Exception on overflow. */
6153+ "1: dsub %0, %2 \n"
6154+#else
6155+ " dsubu %0, %2 \n"
6156+#endif
6157+ " sd %0, %1 \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Note: Dest reg is not modified on overflow */
6160+ "2: \n"
6161+ _ASM_EXTABLE(1b, 2b)
6162+#endif
6163+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6164+ raw_local_irq_restore(flags);
6165+ }
6166+
6167+ smp_llsc_mb();
6168+
6169+ return result;
6170+}
6171+
6172+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6173 {
6174 long result;
6175
6176@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6177 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6178 * The function returns the old value of @v minus @i.
6179 */
6180-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6181+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6182 {
6183 long result;
6184
6185@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6186 return result;
6187 }
6188
6189-#define atomic64_cmpxchg(v, o, n) \
6190- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6191-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6192+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6193+{
6194+ return cmpxchg(&v->counter, old, new);
6195+}
6196+
6197+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6198+ long new)
6199+{
6200+ return cmpxchg(&(v->counter), old, new);
6201+}
6202+
6203+static inline long atomic64_xchg(atomic64_t *v, long new)
6204+{
6205+ return xchg(&v->counter, new);
6206+}
6207+
6208+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6209+{
6210+ return xchg(&(v->counter), new);
6211+}
6212
6213 /**
6214 * atomic64_add_unless - add unless the number is a given value
6215@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6216
6217 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6218 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6219+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6220
6221 /*
6222 * atomic64_sub_and_test - subtract value from variable and test result
6223@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6224 * other cases.
6225 */
6226 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6227+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6228
6229 /*
6230 * atomic64_dec_and_test - decrement by 1 and test
6231@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6232 * Atomically increments @v by 1.
6233 */
6234 #define atomic64_inc(v) atomic64_add(1, (v))
6235+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6236
6237 /*
6238 * atomic64_dec - decrement and test
6239@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6240 * Atomically decrements @v by 1.
6241 */
6242 #define atomic64_dec(v) atomic64_sub(1, (v))
6243+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6244
6245 /*
6246 * atomic64_add_negative - add and test if negative
6247diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6248index b4db69f..8f3b093 100644
6249--- a/arch/mips/include/asm/cache.h
6250+++ b/arch/mips/include/asm/cache.h
6251@@ -9,10 +9,11 @@
6252 #ifndef _ASM_CACHE_H
6253 #define _ASM_CACHE_H
6254
6255+#include <linux/const.h>
6256 #include <kmalloc.h>
6257
6258 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6259-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6260+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6261
6262 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6263 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6264diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6265index cf3ae24..238d22f 100644
6266--- a/arch/mips/include/asm/elf.h
6267+++ b/arch/mips/include/asm/elf.h
6268@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6269 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6270 #endif
6271
6272+#ifdef CONFIG_PAX_ASLR
6273+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6274+
6275+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6276+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6277+#endif
6278+
6279 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6280 struct linux_binprm;
6281 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6282 int uses_interp);
6283
6284-struct mm_struct;
6285-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6286-#define arch_randomize_brk arch_randomize_brk
6287-
6288 #endif /* _ASM_ELF_H */
6289diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6290index c1f6afa..38cc6e9 100644
6291--- a/arch/mips/include/asm/exec.h
6292+++ b/arch/mips/include/asm/exec.h
6293@@ -12,6 +12,6 @@
6294 #ifndef _ASM_EXEC_H
6295 #define _ASM_EXEC_H
6296
6297-extern unsigned long arch_align_stack(unsigned long sp);
6298+#define arch_align_stack(x) ((x) & ~0xfUL)
6299
6300 #endif /* _ASM_EXEC_H */
6301diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6302index d44622c..64990d2 100644
6303--- a/arch/mips/include/asm/local.h
6304+++ b/arch/mips/include/asm/local.h
6305@@ -12,15 +12,25 @@ typedef struct
6306 atomic_long_t a;
6307 } local_t;
6308
6309+typedef struct {
6310+ atomic_long_unchecked_t a;
6311+} local_unchecked_t;
6312+
6313 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6314
6315 #define local_read(l) atomic_long_read(&(l)->a)
6316+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6317 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6318+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6319
6320 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6321+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6322 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6323+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6324 #define local_inc(l) atomic_long_inc(&(l)->a)
6325+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6326 #define local_dec(l) atomic_long_dec(&(l)->a)
6327+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6328
6329 /*
6330 * Same as above, but return the result value
6331@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6332 return result;
6333 }
6334
6335+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6336+{
6337+ unsigned long result;
6338+
6339+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6340+ unsigned long temp;
6341+
6342+ __asm__ __volatile__(
6343+ " .set mips3 \n"
6344+ "1:" __LL "%1, %2 # local_add_return \n"
6345+ " addu %0, %1, %3 \n"
6346+ __SC "%0, %2 \n"
6347+ " beqzl %0, 1b \n"
6348+ " addu %0, %1, %3 \n"
6349+ " .set mips0 \n"
6350+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6351+ : "Ir" (i), "m" (l->a.counter)
6352+ : "memory");
6353+ } else if (kernel_uses_llsc) {
6354+ unsigned long temp;
6355+
6356+ __asm__ __volatile__(
6357+ " .set mips3 \n"
6358+ "1:" __LL "%1, %2 # local_add_return \n"
6359+ " addu %0, %1, %3 \n"
6360+ __SC "%0, %2 \n"
6361+ " beqz %0, 1b \n"
6362+ " addu %0, %1, %3 \n"
6363+ " .set mips0 \n"
6364+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6365+ : "Ir" (i), "m" (l->a.counter)
6366+ : "memory");
6367+ } else {
6368+ unsigned long flags;
6369+
6370+ local_irq_save(flags);
6371+ result = l->a.counter;
6372+ result += i;
6373+ l->a.counter = result;
6374+ local_irq_restore(flags);
6375+ }
6376+
6377+ return result;
6378+}
6379+
6380 static __inline__ long local_sub_return(long i, local_t * l)
6381 {
6382 unsigned long result;
6383@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6384
6385 #define local_cmpxchg(l, o, n) \
6386 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6387+#define local_cmpxchg_unchecked(l, o, n) \
6388+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6389 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6390
6391 /**
6392diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6393index f6be474..12ad554 100644
6394--- a/arch/mips/include/asm/page.h
6395+++ b/arch/mips/include/asm/page.h
6396@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6397 #ifdef CONFIG_CPU_MIPS32
6398 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6399 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6400- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6401+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6402 #else
6403 typedef struct { unsigned long long pte; } pte_t;
6404 #define pte_val(x) ((x).pte)
6405diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6406index 881d18b..cea38bc 100644
6407--- a/arch/mips/include/asm/pgalloc.h
6408+++ b/arch/mips/include/asm/pgalloc.h
6409@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6410 {
6411 set_pud(pud, __pud((unsigned long)pmd));
6412 }
6413+
6414+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6415+{
6416+ pud_populate(mm, pud, pmd);
6417+}
6418 #endif
6419
6420 /*
6421diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6422index 25da651..ae2a259 100644
6423--- a/arch/mips/include/asm/smtc_proc.h
6424+++ b/arch/mips/include/asm/smtc_proc.h
6425@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6426
6427 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6428
6429-extern atomic_t smtc_fpu_recoveries;
6430+extern atomic_unchecked_t smtc_fpu_recoveries;
6431
6432 #endif /* __ASM_SMTC_PROC_H */
6433diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6434index 61215a3..213ee0e 100644
6435--- a/arch/mips/include/asm/thread_info.h
6436+++ b/arch/mips/include/asm/thread_info.h
6437@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6438 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6439 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6440 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6441+/* li takes a 32bit immediate */
6442+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6443 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6444
6445 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6446@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6447 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6448 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6449 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6450+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6451
6452-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6453- _TIF_SYSCALL_AUDIT)
6454+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6455
6456 /* work to do in syscall_trace_leave() */
6457-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6458- _TIF_SYSCALL_AUDIT)
6459+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6460
6461 /* work to do on interrupt/exception return */
6462 #define _TIF_WORK_MASK \
6463 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6464 /* work to do on any return to u-space */
6465-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6466- _TIF_WORK_SYSCALL_EXIT)
6467+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6468
6469 #endif /* __KERNEL__ */
6470
6471diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6472index 1188e00..41cf144 100644
6473--- a/arch/mips/kernel/binfmt_elfn32.c
6474+++ b/arch/mips/kernel/binfmt_elfn32.c
6475@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6476 #undef ELF_ET_DYN_BASE
6477 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6478
6479+#ifdef CONFIG_PAX_ASLR
6480+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6481+
6482+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6483+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6484+#endif
6485+
6486 #include <asm/processor.h>
6487 #include <linux/module.h>
6488 #include <linux/elfcore.h>
6489diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6490index 202e581..689ca79 100644
6491--- a/arch/mips/kernel/binfmt_elfo32.c
6492+++ b/arch/mips/kernel/binfmt_elfo32.c
6493@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6494 #undef ELF_ET_DYN_BASE
6495 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6496
6497+#ifdef CONFIG_PAX_ASLR
6498+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6499+
6500+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6501+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6502+#endif
6503+
6504 #include <asm/processor.h>
6505
6506 /*
6507diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6508index d1fea7a..45602ea 100644
6509--- a/arch/mips/kernel/irq.c
6510+++ b/arch/mips/kernel/irq.c
6511@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6512 printk("unexpected IRQ # %d\n", irq);
6513 }
6514
6515-atomic_t irq_err_count;
6516+atomic_unchecked_t irq_err_count;
6517
6518 int arch_show_interrupts(struct seq_file *p, int prec)
6519 {
6520- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6521+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6522 return 0;
6523 }
6524
6525 asmlinkage void spurious_interrupt(void)
6526 {
6527- atomic_inc(&irq_err_count);
6528+ atomic_inc_unchecked(&irq_err_count);
6529 }
6530
6531 void __init init_IRQ(void)
6532diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6533index ddc7610..8c58f17 100644
6534--- a/arch/mips/kernel/process.c
6535+++ b/arch/mips/kernel/process.c
6536@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6537 out:
6538 return pc;
6539 }
6540-
6541-/*
6542- * Don't forget that the stack pointer must be aligned on a 8 bytes
6543- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6544- */
6545-unsigned long arch_align_stack(unsigned long sp)
6546-{
6547- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6548- sp -= get_random_int() & ~PAGE_MASK;
6549-
6550- return sp & ALMASK;
6551-}
6552diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6553index 8ae1ebe..1bcbf47 100644
6554--- a/arch/mips/kernel/ptrace.c
6555+++ b/arch/mips/kernel/ptrace.c
6556@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6557 return arch;
6558 }
6559
6560+#ifdef CONFIG_GRKERNSEC_SETXID
6561+extern void gr_delayed_cred_worker(void);
6562+#endif
6563+
6564 /*
6565 * Notification of system call entry/exit
6566 * - triggered by current->work.syscall_trace
6567@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6568 /* do the secure computing check first */
6569 secure_computing_strict(regs->regs[2]);
6570
6571+#ifdef CONFIG_GRKERNSEC_SETXID
6572+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6573+ gr_delayed_cred_worker();
6574+#endif
6575+
6576 if (!(current->ptrace & PT_PTRACED))
6577 goto out;
6578
6579diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6580index c10aa84..9ec2e60 100644
6581--- a/arch/mips/kernel/smtc-proc.c
6582+++ b/arch/mips/kernel/smtc-proc.c
6583@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6584
6585 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6586
6587-atomic_t smtc_fpu_recoveries;
6588+atomic_unchecked_t smtc_fpu_recoveries;
6589
6590 static int smtc_proc_show(struct seq_file *m, void *v)
6591 {
6592@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6593 for(i = 0; i < NR_CPUS; i++)
6594 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6595 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6596- atomic_read(&smtc_fpu_recoveries));
6597+ atomic_read_unchecked(&smtc_fpu_recoveries));
6598 return 0;
6599 }
6600
6601@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6602 smtc_cpu_stats[i].selfipis = 0;
6603 }
6604
6605- atomic_set(&smtc_fpu_recoveries, 0);
6606+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6607
6608 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6609 }
6610diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6611index dfc1b91..11a2c07 100644
6612--- a/arch/mips/kernel/smtc.c
6613+++ b/arch/mips/kernel/smtc.c
6614@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6615 }
6616 smtc_ipi_qdump();
6617 printk("%d Recoveries of \"stolen\" FPU\n",
6618- atomic_read(&smtc_fpu_recoveries));
6619+ atomic_read_unchecked(&smtc_fpu_recoveries));
6620 }
6621
6622
6623diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6624index 84536bf..79caa4d 100644
6625--- a/arch/mips/kernel/sync-r4k.c
6626+++ b/arch/mips/kernel/sync-r4k.c
6627@@ -21,8 +21,8 @@
6628 #include <asm/mipsregs.h>
6629
6630 static atomic_t count_start_flag = ATOMIC_INIT(0);
6631-static atomic_t count_count_start = ATOMIC_INIT(0);
6632-static atomic_t count_count_stop = ATOMIC_INIT(0);
6633+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6634+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6635 static atomic_t count_reference = ATOMIC_INIT(0);
6636
6637 #define COUNTON 100
6638@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6639
6640 for (i = 0; i < NR_LOOPS; i++) {
6641 /* slaves loop on '!= 2' */
6642- while (atomic_read(&count_count_start) != 1)
6643+ while (atomic_read_unchecked(&count_count_start) != 1)
6644 mb();
6645- atomic_set(&count_count_stop, 0);
6646+ atomic_set_unchecked(&count_count_stop, 0);
6647 smp_wmb();
6648
6649 /* this lets the slaves write their count register */
6650- atomic_inc(&count_count_start);
6651+ atomic_inc_unchecked(&count_count_start);
6652
6653 /*
6654 * Everyone initialises count in the last loop:
6655@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6656 /*
6657 * Wait for all slaves to leave the synchronization point:
6658 */
6659- while (atomic_read(&count_count_stop) != 1)
6660+ while (atomic_read_unchecked(&count_count_stop) != 1)
6661 mb();
6662- atomic_set(&count_count_start, 0);
6663+ atomic_set_unchecked(&count_count_start, 0);
6664 smp_wmb();
6665- atomic_inc(&count_count_stop);
6666+ atomic_inc_unchecked(&count_count_stop);
6667 }
6668 /* Arrange for an interrupt in a short while */
6669 write_c0_compare(read_c0_count() + COUNTON);
6670@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6671 initcount = atomic_read(&count_reference);
6672
6673 for (i = 0; i < NR_LOOPS; i++) {
6674- atomic_inc(&count_count_start);
6675- while (atomic_read(&count_count_start) != 2)
6676+ atomic_inc_unchecked(&count_count_start);
6677+ while (atomic_read_unchecked(&count_count_start) != 2)
6678 mb();
6679
6680 /*
6681@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6682 if (i == NR_LOOPS-1)
6683 write_c0_count(initcount);
6684
6685- atomic_inc(&count_count_stop);
6686- while (atomic_read(&count_count_stop) != 2)
6687+ atomic_inc_unchecked(&count_count_stop);
6688+ while (atomic_read_unchecked(&count_count_stop) != 2)
6689 mb();
6690 }
6691 /* Arrange for an interrupt in a short while */
6692diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6693index aec3408..74d79d3 100644
6694--- a/arch/mips/kernel/traps.c
6695+++ b/arch/mips/kernel/traps.c
6696@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6697 siginfo_t info;
6698
6699 prev_state = exception_enter();
6700- die_if_kernel("Integer overflow", regs);
6701+ if (unlikely(!user_mode(regs))) {
6702+
6703+#ifdef CONFIG_PAX_REFCOUNT
6704+ if (fixup_exception(regs)) {
6705+ pax_report_refcount_overflow(regs);
6706+ exception_exit(prev_state);
6707+ return;
6708+ }
6709+#endif
6710+
6711+ die("Integer overflow", regs);
6712+ }
6713
6714 info.si_code = FPE_INTOVF;
6715 info.si_signo = SIGFPE;
6716diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6717index 85df1cd..4f0a4de 100644
6718--- a/arch/mips/mm/fault.c
6719+++ b/arch/mips/mm/fault.c
6720@@ -28,6 +28,23 @@
6721 #include <asm/highmem.h> /* For VMALLOC_END */
6722 #include <linux/kdebug.h>
6723
6724+#ifdef CONFIG_PAX_PAGEEXEC
6725+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6726+{
6727+ unsigned long i;
6728+
6729+ printk(KERN_ERR "PAX: bytes at PC: ");
6730+ for (i = 0; i < 5; i++) {
6731+ unsigned int c;
6732+ if (get_user(c, (unsigned int *)pc+i))
6733+ printk(KERN_CONT "???????? ");
6734+ else
6735+ printk(KERN_CONT "%08x ", c);
6736+ }
6737+ printk("\n");
6738+}
6739+#endif
6740+
6741 /*
6742 * This routine handles page faults. It determines the address,
6743 * and the problem, and then passes it off to one of the appropriate
6744@@ -197,6 +214,14 @@ bad_area:
6745 bad_area_nosemaphore:
6746 /* User mode accesses just cause a SIGSEGV */
6747 if (user_mode(regs)) {
6748+
6749+#ifdef CONFIG_PAX_PAGEEXEC
6750+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6751+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6752+ do_group_exit(SIGKILL);
6753+ }
6754+#endif
6755+
6756 tsk->thread.cp0_badvaddr = address;
6757 tsk->thread.error_code = write;
6758 #if 0
6759diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6760index f1baadd..8537544 100644
6761--- a/arch/mips/mm/mmap.c
6762+++ b/arch/mips/mm/mmap.c
6763@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6764 struct vm_area_struct *vma;
6765 unsigned long addr = addr0;
6766 int do_color_align;
6767+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6768 struct vm_unmapped_area_info info;
6769
6770 if (unlikely(len > TASK_SIZE))
6771@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6772 do_color_align = 1;
6773
6774 /* requesting a specific address */
6775+
6776+#ifdef CONFIG_PAX_RANDMMAP
6777+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6778+#endif
6779+
6780 if (addr) {
6781 if (do_color_align)
6782 addr = COLOUR_ALIGN(addr, pgoff);
6783@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6784 addr = PAGE_ALIGN(addr);
6785
6786 vma = find_vma(mm, addr);
6787- if (TASK_SIZE - len >= addr &&
6788- (!vma || addr + len <= vma->vm_start))
6789+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6790 return addr;
6791 }
6792
6793 info.length = len;
6794 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6795 info.align_offset = pgoff << PAGE_SHIFT;
6796+ info.threadstack_offset = offset;
6797
6798 if (dir == DOWN) {
6799 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6800@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6801 {
6802 unsigned long random_factor = 0UL;
6803
6804+#ifdef CONFIG_PAX_RANDMMAP
6805+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6806+#endif
6807+
6808 if (current->flags & PF_RANDOMIZE) {
6809 random_factor = get_random_int();
6810 random_factor = random_factor << PAGE_SHIFT;
6811@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6812
6813 if (mmap_is_legacy()) {
6814 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6815+
6816+#ifdef CONFIG_PAX_RANDMMAP
6817+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6818+ mm->mmap_base += mm->delta_mmap;
6819+#endif
6820+
6821 mm->get_unmapped_area = arch_get_unmapped_area;
6822 } else {
6823 mm->mmap_base = mmap_base(random_factor);
6824+
6825+#ifdef CONFIG_PAX_RANDMMAP
6826+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6827+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6828+#endif
6829+
6830 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6831 }
6832 }
6833
6834-static inline unsigned long brk_rnd(void)
6835-{
6836- unsigned long rnd = get_random_int();
6837-
6838- rnd = rnd << PAGE_SHIFT;
6839- /* 8MB for 32bit, 256MB for 64bit */
6840- if (TASK_IS_32BIT_ADDR)
6841- rnd = rnd & 0x7ffffful;
6842- else
6843- rnd = rnd & 0xffffffful;
6844-
6845- return rnd;
6846-}
6847-
6848-unsigned long arch_randomize_brk(struct mm_struct *mm)
6849-{
6850- unsigned long base = mm->brk;
6851- unsigned long ret;
6852-
6853- ret = PAGE_ALIGN(base + brk_rnd());
6854-
6855- if (ret < mm->brk)
6856- return mm->brk;
6857-
6858- return ret;
6859-}
6860-
6861 int __virt_addr_valid(const volatile void *kaddr)
6862 {
6863 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6864diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6865index a2358b4..7cead4f 100644
6866--- a/arch/mips/sgi-ip27/ip27-nmi.c
6867+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6868@@ -187,9 +187,9 @@ void
6869 cont_nmi_dump(void)
6870 {
6871 #ifndef REAL_NMI_SIGNAL
6872- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6873+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6874
6875- atomic_inc(&nmied_cpus);
6876+ atomic_inc_unchecked(&nmied_cpus);
6877 #endif
6878 /*
6879 * Only allow 1 cpu to proceed
6880@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6881 udelay(10000);
6882 }
6883 #else
6884- while (atomic_read(&nmied_cpus) != num_online_cpus());
6885+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6886 #endif
6887
6888 /*
6889diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6890index 967d144..db12197 100644
6891--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6892+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6893@@ -11,12 +11,14 @@
6894 #ifndef _ASM_PROC_CACHE_H
6895 #define _ASM_PROC_CACHE_H
6896
6897+#include <linux/const.h>
6898+
6899 /* L1 cache */
6900
6901 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6902 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6903-#define L1_CACHE_BYTES 16 /* bytes per entry */
6904 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6905+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6906 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6907
6908 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6909diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6910index bcb5df2..84fabd2 100644
6911--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6912+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6913@@ -16,13 +16,15 @@
6914 #ifndef _ASM_PROC_CACHE_H
6915 #define _ASM_PROC_CACHE_H
6916
6917+#include <linux/const.h>
6918+
6919 /*
6920 * L1 cache
6921 */
6922 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6923 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6924-#define L1_CACHE_BYTES 32 /* bytes per entry */
6925 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6926+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6927 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6928
6929 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6930diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6931index 4ce7a01..449202a 100644
6932--- a/arch/openrisc/include/asm/cache.h
6933+++ b/arch/openrisc/include/asm/cache.h
6934@@ -19,11 +19,13 @@
6935 #ifndef __ASM_OPENRISC_CACHE_H
6936 #define __ASM_OPENRISC_CACHE_H
6937
6938+#include <linux/const.h>
6939+
6940 /* FIXME: How can we replace these with values from the CPU...
6941 * they shouldn't be hard-coded!
6942 */
6943
6944-#define L1_CACHE_BYTES 16
6945 #define L1_CACHE_SHIFT 4
6946+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6947
6948 #endif /* __ASM_OPENRISC_CACHE_H */
6949diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6950index 472886c..00e7df9 100644
6951--- a/arch/parisc/include/asm/atomic.h
6952+++ b/arch/parisc/include/asm/atomic.h
6953@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6954 return dec;
6955 }
6956
6957+#define atomic64_read_unchecked(v) atomic64_read(v)
6958+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6959+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6960+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6961+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6962+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6963+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6964+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6965+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6966+
6967 #endif /* !CONFIG_64BIT */
6968
6969
6970diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6971index 47f11c7..3420df2 100644
6972--- a/arch/parisc/include/asm/cache.h
6973+++ b/arch/parisc/include/asm/cache.h
6974@@ -5,6 +5,7 @@
6975 #ifndef __ARCH_PARISC_CACHE_H
6976 #define __ARCH_PARISC_CACHE_H
6977
6978+#include <linux/const.h>
6979
6980 /*
6981 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6982@@ -15,13 +16,13 @@
6983 * just ruin performance.
6984 */
6985 #ifdef CONFIG_PA20
6986-#define L1_CACHE_BYTES 64
6987 #define L1_CACHE_SHIFT 6
6988 #else
6989-#define L1_CACHE_BYTES 32
6990 #define L1_CACHE_SHIFT 5
6991 #endif
6992
6993+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6994+
6995 #ifndef __ASSEMBLY__
6996
6997 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6998diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6999index ad2b503..bdf1651 100644
7000--- a/arch/parisc/include/asm/elf.h
7001+++ b/arch/parisc/include/asm/elf.h
7002@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7003
7004 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7005
7006+#ifdef CONFIG_PAX_ASLR
7007+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7008+
7009+#define PAX_DELTA_MMAP_LEN 16
7010+#define PAX_DELTA_STACK_LEN 16
7011+#endif
7012+
7013 /* This yields a mask that user programs can use to figure out what
7014 instruction set this CPU supports. This could be done in user space,
7015 but it's not easy, and we've already done it here. */
7016diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7017index fc987a1..6e068ef 100644
7018--- a/arch/parisc/include/asm/pgalloc.h
7019+++ b/arch/parisc/include/asm/pgalloc.h
7020@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7021 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7022 }
7023
7024+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7025+{
7026+ pgd_populate(mm, pgd, pmd);
7027+}
7028+
7029 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7030 {
7031 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7032@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7033 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7034 #define pmd_free(mm, x) do { } while (0)
7035 #define pgd_populate(mm, pmd, pte) BUG()
7036+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7037
7038 #endif
7039
7040diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7041index 34899b5..02dd060 100644
7042--- a/arch/parisc/include/asm/pgtable.h
7043+++ b/arch/parisc/include/asm/pgtable.h
7044@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7045 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7046 #define PAGE_COPY PAGE_EXECREAD
7047 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7048+
7049+#ifdef CONFIG_PAX_PAGEEXEC
7050+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7051+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7052+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7053+#else
7054+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7055+# define PAGE_COPY_NOEXEC PAGE_COPY
7056+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7057+#endif
7058+
7059 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7060 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7061 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7062diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7063index e0a8235..ce2f1e1 100644
7064--- a/arch/parisc/include/asm/uaccess.h
7065+++ b/arch/parisc/include/asm/uaccess.h
7066@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7067 const void __user *from,
7068 unsigned long n)
7069 {
7070- int sz = __compiletime_object_size(to);
7071+ size_t sz = __compiletime_object_size(to);
7072 int ret = -EFAULT;
7073
7074- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7075+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7076 ret = __copy_from_user(to, from, n);
7077 else
7078 copy_from_user_overflow();
7079diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7080index 2a625fb..9908930 100644
7081--- a/arch/parisc/kernel/module.c
7082+++ b/arch/parisc/kernel/module.c
7083@@ -98,16 +98,38 @@
7084
7085 /* three functions to determine where in the module core
7086 * or init pieces the location is */
7087+static inline int in_init_rx(struct module *me, void *loc)
7088+{
7089+ return (loc >= me->module_init_rx &&
7090+ loc < (me->module_init_rx + me->init_size_rx));
7091+}
7092+
7093+static inline int in_init_rw(struct module *me, void *loc)
7094+{
7095+ return (loc >= me->module_init_rw &&
7096+ loc < (me->module_init_rw + me->init_size_rw));
7097+}
7098+
7099 static inline int in_init(struct module *me, void *loc)
7100 {
7101- return (loc >= me->module_init &&
7102- loc <= (me->module_init + me->init_size));
7103+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7104+}
7105+
7106+static inline int in_core_rx(struct module *me, void *loc)
7107+{
7108+ return (loc >= me->module_core_rx &&
7109+ loc < (me->module_core_rx + me->core_size_rx));
7110+}
7111+
7112+static inline int in_core_rw(struct module *me, void *loc)
7113+{
7114+ return (loc >= me->module_core_rw &&
7115+ loc < (me->module_core_rw + me->core_size_rw));
7116 }
7117
7118 static inline int in_core(struct module *me, void *loc)
7119 {
7120- return (loc >= me->module_core &&
7121- loc <= (me->module_core + me->core_size));
7122+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7123 }
7124
7125 static inline int in_local(struct module *me, void *loc)
7126@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7127 }
7128
7129 /* align things a bit */
7130- me->core_size = ALIGN(me->core_size, 16);
7131- me->arch.got_offset = me->core_size;
7132- me->core_size += gots * sizeof(struct got_entry);
7133+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7134+ me->arch.got_offset = me->core_size_rw;
7135+ me->core_size_rw += gots * sizeof(struct got_entry);
7136
7137- me->core_size = ALIGN(me->core_size, 16);
7138- me->arch.fdesc_offset = me->core_size;
7139- me->core_size += fdescs * sizeof(Elf_Fdesc);
7140+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7141+ me->arch.fdesc_offset = me->core_size_rw;
7142+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7143
7144 me->arch.got_max = gots;
7145 me->arch.fdesc_max = fdescs;
7146@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7147
7148 BUG_ON(value == 0);
7149
7150- got = me->module_core + me->arch.got_offset;
7151+ got = me->module_core_rw + me->arch.got_offset;
7152 for (i = 0; got[i].addr; i++)
7153 if (got[i].addr == value)
7154 goto out;
7155@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7156 #ifdef CONFIG_64BIT
7157 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7158 {
7159- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7160+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7161
7162 if (!value) {
7163 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7164@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7165
7166 /* Create new one */
7167 fdesc->addr = value;
7168- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7169+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7170 return (Elf_Addr)fdesc;
7171 }
7172 #endif /* CONFIG_64BIT */
7173@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7174
7175 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7176 end = table + sechdrs[me->arch.unwind_section].sh_size;
7177- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7178+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7179
7180 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7181 me->arch.unwind_section, table, end, gp);
7182diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7183index 5dfd248..64914ac 100644
7184--- a/arch/parisc/kernel/sys_parisc.c
7185+++ b/arch/parisc/kernel/sys_parisc.c
7186@@ -33,9 +33,11 @@
7187 #include <linux/utsname.h>
7188 #include <linux/personality.h>
7189
7190-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7191+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7192+ unsigned long flags)
7193 {
7194 struct vm_unmapped_area_info info;
7195+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7196
7197 info.flags = 0;
7198 info.length = len;
7199@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7200 info.high_limit = TASK_SIZE;
7201 info.align_mask = 0;
7202 info.align_offset = 0;
7203+ info.threadstack_offset = offset;
7204 return vm_unmapped_area(&info);
7205 }
7206
7207@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7208 return (unsigned long) mapping >> 8;
7209 }
7210
7211-static unsigned long get_shared_area(struct address_space *mapping,
7212- unsigned long addr, unsigned long len, unsigned long pgoff)
7213+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7214+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7215 {
7216 struct vm_unmapped_area_info info;
7217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7218
7219 info.flags = 0;
7220 info.length = len;
7221@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7222 info.high_limit = TASK_SIZE;
7223 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7224 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7225+ info.threadstack_offset = offset;
7226 return vm_unmapped_area(&info);
7227 }
7228
7229@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7230 return -EINVAL;
7231 return addr;
7232 }
7233- if (!addr)
7234+ if (!addr) {
7235 addr = TASK_UNMAPPED_BASE;
7236
7237+#ifdef CONFIG_PAX_RANDMMAP
7238+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7239+ addr += current->mm->delta_mmap;
7240+#endif
7241+
7242+ }
7243+
7244 if (filp) {
7245- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7246+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7247 } else if(flags & MAP_SHARED) {
7248- addr = get_shared_area(NULL, addr, len, pgoff);
7249+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7250 } else {
7251- addr = get_unshared_area(addr, len);
7252+ addr = get_unshared_area(filp, addr, len, flags);
7253 }
7254 return addr;
7255 }
7256diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7257index 04e47c6..7a8faf6 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 22a1098..6255eb9 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 %i5, 0, %o5 ! IEU1
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 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 0c4e35e..745d3e4 100644
10309--- a/arch/sparc/lib/ksyms.c
10310+++ b/arch/sparc/lib/ksyms.c
10311@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
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/process.c b/arch/um/kernel/process.c
11483index bbcef52..6a2a483 100644
11484--- a/arch/um/kernel/process.c
11485+++ b/arch/um/kernel/process.c
11486@@ -367,22 +367,6 @@ int singlestepping(void * t)
11487 return 2;
11488 }
11489
11490-/*
11491- * Only x86 and x86_64 have an arch_align_stack().
11492- * All other arches have "#define arch_align_stack(x) (x)"
11493- * in their asm/system.h
11494- * As this is included in UML from asm-um/system-generic.h,
11495- * we can use it to behave as the subarch does.
11496- */
11497-#ifndef arch_align_stack
11498-unsigned long arch_align_stack(unsigned long sp)
11499-{
11500- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11501- sp -= get_random_int() % 8192;
11502- return sp & ~0xf;
11503-}
11504-#endif
11505-
11506 unsigned long get_wchan(struct task_struct *p)
11507 {
11508 unsigned long stack_page, sp, ip;
11509diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11510index ad8f795..2c7eec6 100644
11511--- a/arch/unicore32/include/asm/cache.h
11512+++ b/arch/unicore32/include/asm/cache.h
11513@@ -12,8 +12,10 @@
11514 #ifndef __UNICORE_CACHE_H__
11515 #define __UNICORE_CACHE_H__
11516
11517-#define L1_CACHE_SHIFT (5)
11518-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11519+#include <linux/const.h>
11520+
11521+#define L1_CACHE_SHIFT 5
11522+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11523
11524 /*
11525 * Memory returned by kmalloc() may be used for DMA, so we must make
11526diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11527index b32ebf9..5704f98 100644
11528--- a/arch/x86/Kconfig
11529+++ b/arch/x86/Kconfig
11530@@ -248,7 +248,7 @@ config X86_HT
11531
11532 config X86_32_LAZY_GS
11533 def_bool y
11534- depends on X86_32 && !CC_STACKPROTECTOR
11535+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11536
11537 config ARCH_HWEIGHT_CFLAGS
11538 string
11539@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11540
11541 config X86_MSR
11542 tristate "/dev/cpu/*/msr - Model-specific register support"
11543+ depends on !GRKERNSEC_KMEM
11544 ---help---
11545 This device gives privileged processes access to the x86
11546 Model-Specific Registers (MSRs). It is a character device with
11547@@ -1111,7 +1112,7 @@ choice
11548
11549 config NOHIGHMEM
11550 bool "off"
11551- depends on !X86_NUMAQ
11552+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11553 ---help---
11554 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11555 However, the address space of 32-bit x86 processors is only 4
11556@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11557
11558 config HIGHMEM4G
11559 bool "4GB"
11560- depends on !X86_NUMAQ
11561+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11562 ---help---
11563 Select this if you have a 32-bit processor and between 1 and 4
11564 gigabytes of physical RAM.
11565@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11566 hex
11567 default 0xB0000000 if VMSPLIT_3G_OPT
11568 default 0x80000000 if VMSPLIT_2G
11569- default 0x78000000 if VMSPLIT_2G_OPT
11570+ default 0x70000000 if VMSPLIT_2G_OPT
11571 default 0x40000000 if VMSPLIT_1G
11572 default 0xC0000000
11573 depends on X86_32
11574@@ -1599,6 +1600,7 @@ config SECCOMP
11575
11576 config CC_STACKPROTECTOR
11577 bool "Enable -fstack-protector buffer overflow detection"
11578+ depends on X86_64 || !PAX_MEMORY_UDEREF
11579 ---help---
11580 This option turns on the -fstack-protector GCC feature. This
11581 feature puts, at the beginning of functions, a canary value on
11582@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11583 config PHYSICAL_ALIGN
11584 hex "Alignment value to which kernel should be aligned" if X86_32
11585 default "0x1000000"
11586+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11587+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11588 range 0x2000 0x1000000
11589 ---help---
11590 This value puts the alignment restrictions on physical address
11591@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11592 If unsure, say N.
11593
11594 config COMPAT_VDSO
11595- def_bool y
11596+ def_bool n
11597 prompt "Compat VDSO support"
11598 depends on X86_32 || IA32_EMULATION
11599+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11600 ---help---
11601 Map the 32-bit VDSO to the predictable old-style address too.
11602
11603diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11604index c026cca..14657ae 100644
11605--- a/arch/x86/Kconfig.cpu
11606+++ b/arch/x86/Kconfig.cpu
11607@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11608
11609 config X86_F00F_BUG
11610 def_bool y
11611- depends on M586MMX || M586TSC || M586 || M486
11612+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11613
11614 config X86_INVD_BUG
11615 def_bool y
11616@@ -327,7 +327,7 @@ config X86_INVD_BUG
11617
11618 config X86_ALIGNMENT_16
11619 def_bool y
11620- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11621+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11622
11623 config X86_INTEL_USERCOPY
11624 def_bool y
11625@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11626 # generates cmov.
11627 config X86_CMOV
11628 def_bool y
11629- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11630+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11631
11632 config X86_MINIMUM_CPU_FAMILY
11633 int
11634diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11635index 78d91af..8ceb94b 100644
11636--- a/arch/x86/Kconfig.debug
11637+++ b/arch/x86/Kconfig.debug
11638@@ -74,7 +74,7 @@ config X86_PTDUMP
11639 config DEBUG_RODATA
11640 bool "Write protect kernel read-only data structures"
11641 default y
11642- depends on DEBUG_KERNEL
11643+ depends on DEBUG_KERNEL && BROKEN
11644 ---help---
11645 Mark the kernel read-only data as write-protected in the pagetables,
11646 in order to catch accidental (and incorrect) writes to such const
11647@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11648
11649 config DEBUG_SET_MODULE_RONX
11650 bool "Set loadable kernel module data as NX and text as RO"
11651- depends on MODULES
11652+ depends on MODULES && BROKEN
11653 ---help---
11654 This option helps catch unintended modifications to loadable
11655 kernel module's text and read-only data. It also prevents execution
11656diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11657index 07639c6..6f2c901 100644
11658--- a/arch/x86/Makefile
11659+++ b/arch/x86/Makefile
11660@@ -54,6 +54,7 @@ else
11661 UTS_MACHINE := x86_64
11662 CHECKFLAGS += -D__x86_64__ -m64
11663
11664+ biarch := $(call cc-option,-m64)
11665 KBUILD_AFLAGS += -m64
11666 KBUILD_CFLAGS += -m64
11667
11668@@ -241,3 +242,12 @@ define archhelp
11669 echo ' FDINITRD=file initrd for the booted kernel'
11670 echo ' kvmconfig - Enable additional options for guest kernel support'
11671 endef
11672+
11673+define OLD_LD
11674+
11675+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11676+*** Please upgrade your binutils to 2.18 or newer
11677+endef
11678+
11679+archprepare:
11680+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11681diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11682index 379814b..add62ce 100644
11683--- a/arch/x86/boot/Makefile
11684+++ b/arch/x86/boot/Makefile
11685@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11686 $(call cc-option, -fno-stack-protector) \
11687 $(call cc-option, -mpreferred-stack-boundary=2)
11688 KBUILD_CFLAGS += $(call cc-option, -m32)
11689+ifdef CONSTIFY_PLUGIN
11690+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11691+endif
11692 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11693 GCOV_PROFILE := n
11694
11695diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11696index 878e4b9..20537ab 100644
11697--- a/arch/x86/boot/bitops.h
11698+++ b/arch/x86/boot/bitops.h
11699@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11700 u8 v;
11701 const u32 *p = (const u32 *)addr;
11702
11703- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11704+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11705 return v;
11706 }
11707
11708@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11709
11710 static inline void set_bit(int nr, void *addr)
11711 {
11712- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11713+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11714 }
11715
11716 #endif /* BOOT_BITOPS_H */
11717diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11718index 5b75319..331a4ca 100644
11719--- a/arch/x86/boot/boot.h
11720+++ b/arch/x86/boot/boot.h
11721@@ -85,7 +85,7 @@ static inline void io_delay(void)
11722 static inline u16 ds(void)
11723 {
11724 u16 seg;
11725- asm("movw %%ds,%0" : "=rm" (seg));
11726+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11727 return seg;
11728 }
11729
11730@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11731 static inline int memcmp(const void *s1, const void *s2, size_t len)
11732 {
11733 u8 diff;
11734- asm("repe; cmpsb; setnz %0"
11735+ asm volatile("repe; cmpsb; setnz %0"
11736 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11737 return diff;
11738 }
11739diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11740index dcd90df..c830d7d 100644
11741--- a/arch/x86/boot/compressed/Makefile
11742+++ b/arch/x86/boot/compressed/Makefile
11743@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11744 KBUILD_CFLAGS += $(cflags-y)
11745 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11746 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11747+ifdef CONSTIFY_PLUGIN
11748+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11749+endif
11750
11751 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11752 GCOV_PROFILE := n
11753diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11754index b7388a4..03844ec 100644
11755--- a/arch/x86/boot/compressed/eboot.c
11756+++ b/arch/x86/boot/compressed/eboot.c
11757@@ -150,7 +150,6 @@ again:
11758 *addr = max_addr;
11759 }
11760
11761-free_pool:
11762 efi_call_phys1(sys_table->boottime->free_pool, map);
11763
11764 fail:
11765@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11766 if (i == map_size / desc_size)
11767 status = EFI_NOT_FOUND;
11768
11769-free_pool:
11770 efi_call_phys1(sys_table->boottime->free_pool, map);
11771 fail:
11772 return status;
11773diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11774index a53440e..c3dbf1e 100644
11775--- a/arch/x86/boot/compressed/efi_stub_32.S
11776+++ b/arch/x86/boot/compressed/efi_stub_32.S
11777@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11778 * parameter 2, ..., param n. To make things easy, we save the return
11779 * address of efi_call_phys in a global variable.
11780 */
11781- popl %ecx
11782- movl %ecx, saved_return_addr(%edx)
11783- /* get the function pointer into ECX*/
11784- popl %ecx
11785- movl %ecx, efi_rt_function_ptr(%edx)
11786+ popl saved_return_addr(%edx)
11787+ popl efi_rt_function_ptr(%edx)
11788
11789 /*
11790 * 3. Call the physical function.
11791 */
11792- call *%ecx
11793+ call *efi_rt_function_ptr(%edx)
11794
11795 /*
11796 * 4. Balance the stack. And because EAX contain the return value,
11797@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11798 1: popl %edx
11799 subl $1b, %edx
11800
11801- movl efi_rt_function_ptr(%edx), %ecx
11802- pushl %ecx
11803+ pushl efi_rt_function_ptr(%edx)
11804
11805 /*
11806 * 10. Push the saved return address onto the stack and return.
11807 */
11808- movl saved_return_addr(%edx), %ecx
11809- pushl %ecx
11810- ret
11811+ jmpl *saved_return_addr(%edx)
11812 ENDPROC(efi_call_phys)
11813 .previous
11814
11815diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11816index 1e3184f..0d11e2e 100644
11817--- a/arch/x86/boot/compressed/head_32.S
11818+++ b/arch/x86/boot/compressed/head_32.S
11819@@ -118,7 +118,7 @@ preferred_addr:
11820 notl %eax
11821 andl %eax, %ebx
11822 #else
11823- movl $LOAD_PHYSICAL_ADDR, %ebx
11824+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11825 #endif
11826
11827 /* Target address to relocate to for decompression */
11828@@ -204,7 +204,7 @@ relocated:
11829 * and where it was actually loaded.
11830 */
11831 movl %ebp, %ebx
11832- subl $LOAD_PHYSICAL_ADDR, %ebx
11833+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11834 jz 2f /* Nothing to be done if loaded at compiled addr. */
11835 /*
11836 * Process relocations.
11837@@ -212,8 +212,7 @@ relocated:
11838
11839 1: subl $4, %edi
11840 movl (%edi), %ecx
11841- testl %ecx, %ecx
11842- jz 2f
11843+ jecxz 2f
11844 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11845 jmp 1b
11846 2:
11847diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11848index 06e71c2..88a98264 100644
11849--- a/arch/x86/boot/compressed/head_64.S
11850+++ b/arch/x86/boot/compressed/head_64.S
11851@@ -95,7 +95,7 @@ ENTRY(startup_32)
11852 notl %eax
11853 andl %eax, %ebx
11854 #else
11855- movl $LOAD_PHYSICAL_ADDR, %ebx
11856+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11857 #endif
11858
11859 /* Target address to relocate to for decompression */
11860@@ -270,7 +270,7 @@ preferred_addr:
11861 notq %rax
11862 andq %rax, %rbp
11863 #else
11864- movq $LOAD_PHYSICAL_ADDR, %rbp
11865+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11866 #endif
11867
11868 /* Target address to relocate to for decompression */
11869@@ -361,8 +361,8 @@ gdt:
11870 .long gdt
11871 .word 0
11872 .quad 0x0000000000000000 /* NULL descriptor */
11873- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11874- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11875+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11876+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11877 .quad 0x0080890000000000 /* TS descriptor */
11878 .quad 0x0000000000000000 /* TS continued */
11879 gdt_end:
11880diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11881index 0319c88..7c1931f 100644
11882--- a/arch/x86/boot/compressed/misc.c
11883+++ b/arch/x86/boot/compressed/misc.c
11884@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11885 case PT_LOAD:
11886 #ifdef CONFIG_RELOCATABLE
11887 dest = output;
11888- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11889+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11890 #else
11891 dest = (void *)(phdr->p_paddr);
11892 #endif
11893@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11894 error("Destination address too large");
11895 #endif
11896 #ifndef CONFIG_RELOCATABLE
11897- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11898+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11899 error("Wrong destination address");
11900 #endif
11901
11902diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11903index 4d3ff03..e4972ff 100644
11904--- a/arch/x86/boot/cpucheck.c
11905+++ b/arch/x86/boot/cpucheck.c
11906@@ -74,7 +74,7 @@ static int has_fpu(void)
11907 u16 fcw = -1, fsw = -1;
11908 u32 cr0;
11909
11910- asm("movl %%cr0,%0" : "=r" (cr0));
11911+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11912 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11913 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11914 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11915@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11916 {
11917 u32 f0, f1;
11918
11919- asm("pushfl ; "
11920+ asm volatile("pushfl ; "
11921 "pushfl ; "
11922 "popl %0 ; "
11923 "movl %0,%1 ; "
11924@@ -115,7 +115,7 @@ static void get_flags(void)
11925 set_bit(X86_FEATURE_FPU, cpu.flags);
11926
11927 if (has_eflag(X86_EFLAGS_ID)) {
11928- asm("cpuid"
11929+ asm volatile("cpuid"
11930 : "=a" (max_intel_level),
11931 "=b" (cpu_vendor[0]),
11932 "=d" (cpu_vendor[1]),
11933@@ -124,7 +124,7 @@ static void get_flags(void)
11934
11935 if (max_intel_level >= 0x00000001 &&
11936 max_intel_level <= 0x0000ffff) {
11937- asm("cpuid"
11938+ asm volatile("cpuid"
11939 : "=a" (tfms),
11940 "=c" (cpu.flags[4]),
11941 "=d" (cpu.flags[0])
11942@@ -136,7 +136,7 @@ static void get_flags(void)
11943 cpu.model += ((tfms >> 16) & 0xf) << 4;
11944 }
11945
11946- asm("cpuid"
11947+ asm volatile("cpuid"
11948 : "=a" (max_amd_level)
11949 : "a" (0x80000000)
11950 : "ebx", "ecx", "edx");
11951@@ -144,7 +144,7 @@ static void get_flags(void)
11952 if (max_amd_level >= 0x80000001 &&
11953 max_amd_level <= 0x8000ffff) {
11954 u32 eax = 0x80000001;
11955- asm("cpuid"
11956+ asm volatile("cpuid"
11957 : "+a" (eax),
11958 "=c" (cpu.flags[6]),
11959 "=d" (cpu.flags[1])
11960@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11961 u32 ecx = MSR_K7_HWCR;
11962 u32 eax, edx;
11963
11964- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11965+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11966 eax &= ~(1 << 15);
11967- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11968+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11969
11970 get_flags(); /* Make sure it really did something */
11971 err = check_flags();
11972@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11973 u32 ecx = MSR_VIA_FCR;
11974 u32 eax, edx;
11975
11976- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11977+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11978 eax |= (1<<1)|(1<<7);
11979- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11980+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11981
11982 set_bit(X86_FEATURE_CX8, cpu.flags);
11983 err = check_flags();
11984@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11985 u32 eax, edx;
11986 u32 level = 1;
11987
11988- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11989- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11990- asm("cpuid"
11991+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11992+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11993+ asm volatile("cpuid"
11994 : "+a" (level), "=d" (cpu.flags[0])
11995 : : "ecx", "ebx");
11996- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11997+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11998
11999 err = check_flags();
12000 }
12001diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12002index 9ec06a1..2c25e79 100644
12003--- a/arch/x86/boot/header.S
12004+++ b/arch/x86/boot/header.S
12005@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12006 # single linked list of
12007 # struct setup_data
12008
12009-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12010+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12011
12012 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12013+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12014+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12015+#else
12016 #define VO_INIT_SIZE (VO__end - VO__text)
12017+#endif
12018 #if ZO_INIT_SIZE > VO_INIT_SIZE
12019 #define INIT_SIZE ZO_INIT_SIZE
12020 #else
12021diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12022index db75d07..8e6d0af 100644
12023--- a/arch/x86/boot/memory.c
12024+++ b/arch/x86/boot/memory.c
12025@@ -19,7 +19,7 @@
12026
12027 static int detect_memory_e820(void)
12028 {
12029- int count = 0;
12030+ unsigned int count = 0;
12031 struct biosregs ireg, oreg;
12032 struct e820entry *desc = boot_params.e820_map;
12033 static struct e820entry buf; /* static so it is zeroed */
12034diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12035index 11e8c6e..fdbb1ed 100644
12036--- a/arch/x86/boot/video-vesa.c
12037+++ b/arch/x86/boot/video-vesa.c
12038@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12039
12040 boot_params.screen_info.vesapm_seg = oreg.es;
12041 boot_params.screen_info.vesapm_off = oreg.di;
12042+ boot_params.screen_info.vesapm_size = oreg.cx;
12043 }
12044
12045 /*
12046diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12047index 43eda28..5ab5fdb 100644
12048--- a/arch/x86/boot/video.c
12049+++ b/arch/x86/boot/video.c
12050@@ -96,7 +96,7 @@ static void store_mode_params(void)
12051 static unsigned int get_entry(void)
12052 {
12053 char entry_buf[4];
12054- int i, len = 0;
12055+ unsigned int i, len = 0;
12056 int key;
12057 unsigned int v;
12058
12059diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12060index 9105655..5e37f27 100644
12061--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12062+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12063@@ -8,6 +8,8 @@
12064 * including this sentence is retained in full.
12065 */
12066
12067+#include <asm/alternative-asm.h>
12068+
12069 .extern crypto_ft_tab
12070 .extern crypto_it_tab
12071 .extern crypto_fl_tab
12072@@ -70,6 +72,8 @@
12073 je B192; \
12074 leaq 32(r9),r9;
12075
12076+#define ret pax_force_retaddr 0, 1; ret
12077+
12078 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12079 movq r1,r2; \
12080 movq r3,r4; \
12081diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12082index 477e9d7..3ab339f 100644
12083--- a/arch/x86/crypto/aesni-intel_asm.S
12084+++ b/arch/x86/crypto/aesni-intel_asm.S
12085@@ -31,6 +31,7 @@
12086
12087 #include <linux/linkage.h>
12088 #include <asm/inst.h>
12089+#include <asm/alternative-asm.h>
12090
12091 #ifdef __x86_64__
12092 .data
12093@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12094 pop %r14
12095 pop %r13
12096 pop %r12
12097+ pax_force_retaddr 0, 1
12098 ret
12099 ENDPROC(aesni_gcm_dec)
12100
12101@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12102 pop %r14
12103 pop %r13
12104 pop %r12
12105+ pax_force_retaddr 0, 1
12106 ret
12107 ENDPROC(aesni_gcm_enc)
12108
12109@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12110 pxor %xmm1, %xmm0
12111 movaps %xmm0, (TKEYP)
12112 add $0x10, TKEYP
12113+ pax_force_retaddr_bts
12114 ret
12115 ENDPROC(_key_expansion_128)
12116 ENDPROC(_key_expansion_256a)
12117@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12118 shufps $0b01001110, %xmm2, %xmm1
12119 movaps %xmm1, 0x10(TKEYP)
12120 add $0x20, TKEYP
12121+ pax_force_retaddr_bts
12122 ret
12123 ENDPROC(_key_expansion_192a)
12124
12125@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12126
12127 movaps %xmm0, (TKEYP)
12128 add $0x10, TKEYP
12129+ pax_force_retaddr_bts
12130 ret
12131 ENDPROC(_key_expansion_192b)
12132
12133@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12134 pxor %xmm1, %xmm2
12135 movaps %xmm2, (TKEYP)
12136 add $0x10, TKEYP
12137+ pax_force_retaddr_bts
12138 ret
12139 ENDPROC(_key_expansion_256b)
12140
12141@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12142 #ifndef __x86_64__
12143 popl KEYP
12144 #endif
12145+ pax_force_retaddr 0, 1
12146 ret
12147 ENDPROC(aesni_set_key)
12148
12149@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12150 popl KLEN
12151 popl KEYP
12152 #endif
12153+ pax_force_retaddr 0, 1
12154 ret
12155 ENDPROC(aesni_enc)
12156
12157@@ -1974,6 +1983,7 @@ _aesni_enc1:
12158 AESENC KEY STATE
12159 movaps 0x70(TKEYP), KEY
12160 AESENCLAST KEY STATE
12161+ pax_force_retaddr_bts
12162 ret
12163 ENDPROC(_aesni_enc1)
12164
12165@@ -2083,6 +2093,7 @@ _aesni_enc4:
12166 AESENCLAST KEY STATE2
12167 AESENCLAST KEY STATE3
12168 AESENCLAST KEY STATE4
12169+ pax_force_retaddr_bts
12170 ret
12171 ENDPROC(_aesni_enc4)
12172
12173@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12174 popl KLEN
12175 popl KEYP
12176 #endif
12177+ pax_force_retaddr 0, 1
12178 ret
12179 ENDPROC(aesni_dec)
12180
12181@@ -2164,6 +2176,7 @@ _aesni_dec1:
12182 AESDEC KEY STATE
12183 movaps 0x70(TKEYP), KEY
12184 AESDECLAST KEY STATE
12185+ pax_force_retaddr_bts
12186 ret
12187 ENDPROC(_aesni_dec1)
12188
12189@@ -2273,6 +2286,7 @@ _aesni_dec4:
12190 AESDECLAST KEY STATE2
12191 AESDECLAST KEY STATE3
12192 AESDECLAST KEY STATE4
12193+ pax_force_retaddr_bts
12194 ret
12195 ENDPROC(_aesni_dec4)
12196
12197@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12198 popl KEYP
12199 popl LEN
12200 #endif
12201+ pax_force_retaddr 0, 1
12202 ret
12203 ENDPROC(aesni_ecb_enc)
12204
12205@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12206 popl KEYP
12207 popl LEN
12208 #endif
12209+ pax_force_retaddr 0, 1
12210 ret
12211 ENDPROC(aesni_ecb_dec)
12212
12213@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12214 popl LEN
12215 popl IVP
12216 #endif
12217+ pax_force_retaddr 0, 1
12218 ret
12219 ENDPROC(aesni_cbc_enc)
12220
12221@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12222 popl LEN
12223 popl IVP
12224 #endif
12225+ pax_force_retaddr 0, 1
12226 ret
12227 ENDPROC(aesni_cbc_dec)
12228
12229@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12230 mov $1, TCTR_LOW
12231 MOVQ_R64_XMM TCTR_LOW INC
12232 MOVQ_R64_XMM CTR TCTR_LOW
12233+ pax_force_retaddr_bts
12234 ret
12235 ENDPROC(_aesni_inc_init)
12236
12237@@ -2579,6 +2598,7 @@ _aesni_inc:
12238 .Linc_low:
12239 movaps CTR, IV
12240 PSHUFB_XMM BSWAP_MASK IV
12241+ pax_force_retaddr_bts
12242 ret
12243 ENDPROC(_aesni_inc)
12244
12245@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12246 .Lctr_enc_ret:
12247 movups IV, (IVP)
12248 .Lctr_enc_just_ret:
12249+ pax_force_retaddr 0, 1
12250 ret
12251 ENDPROC(aesni_ctr_enc)
12252
12253@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12254 pxor INC, STATE4
12255 movdqu STATE4, 0x70(OUTP)
12256
12257+ pax_force_retaddr 0, 1
12258 ret
12259 ENDPROC(aesni_xts_crypt8)
12260
12261diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12262index 246c670..4d1ed00 100644
12263--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12264+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12265@@ -21,6 +21,7 @@
12266 */
12267
12268 #include <linux/linkage.h>
12269+#include <asm/alternative-asm.h>
12270
12271 .file "blowfish-x86_64-asm.S"
12272 .text
12273@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12274 jnz .L__enc_xor;
12275
12276 write_block();
12277+ pax_force_retaddr 0, 1
12278 ret;
12279 .L__enc_xor:
12280 xor_block();
12281+ pax_force_retaddr 0, 1
12282 ret;
12283 ENDPROC(__blowfish_enc_blk)
12284
12285@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12286
12287 movq %r11, %rbp;
12288
12289+ pax_force_retaddr 0, 1
12290 ret;
12291 ENDPROC(blowfish_dec_blk)
12292
12293@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12294
12295 popq %rbx;
12296 popq %rbp;
12297+ pax_force_retaddr 0, 1
12298 ret;
12299
12300 .L__enc_xor4:
12301@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12302
12303 popq %rbx;
12304 popq %rbp;
12305+ pax_force_retaddr 0, 1
12306 ret;
12307 ENDPROC(__blowfish_enc_blk_4way)
12308
12309@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12310 popq %rbx;
12311 popq %rbp;
12312
12313+ pax_force_retaddr 0, 1
12314 ret;
12315 ENDPROC(blowfish_dec_blk_4way)
12316diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12317index ce71f92..2dd5b1e 100644
12318--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12319+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12320@@ -16,6 +16,7 @@
12321 */
12322
12323 #include <linux/linkage.h>
12324+#include <asm/alternative-asm.h>
12325
12326 #define CAMELLIA_TABLE_BYTE_LEN 272
12327
12328@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12329 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12330 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12331 %rcx, (%r9));
12332+ pax_force_retaddr_bts
12333 ret;
12334 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12335
12336@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12337 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12338 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12339 %rax, (%r9));
12340+ pax_force_retaddr_bts
12341 ret;
12342 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12343
12344@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12345 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12346 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12347
12348+ pax_force_retaddr_bts
12349 ret;
12350
12351 .align 8
12352@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12353 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12354 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12355
12356+ pax_force_retaddr_bts
12357 ret;
12358
12359 .align 8
12360@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12361 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12362 %xmm8, %rsi);
12363
12364+ pax_force_retaddr 0, 1
12365 ret;
12366 ENDPROC(camellia_ecb_enc_16way)
12367
12368@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12369 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12370 %xmm8, %rsi);
12371
12372+ pax_force_retaddr 0, 1
12373 ret;
12374 ENDPROC(camellia_ecb_dec_16way)
12375
12376@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12377 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12378 %xmm8, %rsi);
12379
12380+ pax_force_retaddr 0, 1
12381 ret;
12382 ENDPROC(camellia_cbc_dec_16way)
12383
12384@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12385 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12386 %xmm8, %rsi);
12387
12388+ pax_force_retaddr 0, 1
12389 ret;
12390 ENDPROC(camellia_ctr_16way)
12391
12392@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12393 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12394 %xmm8, %rsi);
12395
12396+ pax_force_retaddr 0, 1
12397 ret;
12398 ENDPROC(camellia_xts_crypt_16way)
12399
12400diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12401index 0e0b886..8fc756a 100644
12402--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12403+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12404@@ -11,6 +11,7 @@
12405 */
12406
12407 #include <linux/linkage.h>
12408+#include <asm/alternative-asm.h>
12409
12410 #define CAMELLIA_TABLE_BYTE_LEN 272
12411
12412@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12413 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12414 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12415 %rcx, (%r9));
12416+ pax_force_retaddr_bts
12417 ret;
12418 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12419
12420@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12421 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12422 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12423 %rax, (%r9));
12424+ pax_force_retaddr_bts
12425 ret;
12426 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12427
12428@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12429 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12430 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12431
12432+ pax_force_retaddr_bts
12433 ret;
12434
12435 .align 8
12436@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12437 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12438 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12439
12440+ pax_force_retaddr_bts
12441 ret;
12442
12443 .align 8
12444@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12445
12446 vzeroupper;
12447
12448+ pax_force_retaddr 0, 1
12449 ret;
12450 ENDPROC(camellia_ecb_enc_32way)
12451
12452@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12453
12454 vzeroupper;
12455
12456+ pax_force_retaddr 0, 1
12457 ret;
12458 ENDPROC(camellia_ecb_dec_32way)
12459
12460@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12461
12462 vzeroupper;
12463
12464+ pax_force_retaddr 0, 1
12465 ret;
12466 ENDPROC(camellia_cbc_dec_32way)
12467
12468@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12469
12470 vzeroupper;
12471
12472+ pax_force_retaddr 0, 1
12473 ret;
12474 ENDPROC(camellia_ctr_32way)
12475
12476@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12477
12478 vzeroupper;
12479
12480+ pax_force_retaddr 0, 1
12481 ret;
12482 ENDPROC(camellia_xts_crypt_32way)
12483
12484diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12485index 310319c..ce174a4 100644
12486--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12487+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12488@@ -21,6 +21,7 @@
12489 */
12490
12491 #include <linux/linkage.h>
12492+#include <asm/alternative-asm.h>
12493
12494 .file "camellia-x86_64-asm_64.S"
12495 .text
12496@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12497 enc_outunpack(mov, RT1);
12498
12499 movq RRBP, %rbp;
12500+ pax_force_retaddr 0, 1
12501 ret;
12502
12503 .L__enc_xor:
12504 enc_outunpack(xor, RT1);
12505
12506 movq RRBP, %rbp;
12507+ pax_force_retaddr 0, 1
12508 ret;
12509 ENDPROC(__camellia_enc_blk)
12510
12511@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12512 dec_outunpack();
12513
12514 movq RRBP, %rbp;
12515+ pax_force_retaddr 0, 1
12516 ret;
12517 ENDPROC(camellia_dec_blk)
12518
12519@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12520
12521 movq RRBP, %rbp;
12522 popq %rbx;
12523+ pax_force_retaddr 0, 1
12524 ret;
12525
12526 .L__enc2_xor:
12527@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12528
12529 movq RRBP, %rbp;
12530 popq %rbx;
12531+ pax_force_retaddr 0, 1
12532 ret;
12533 ENDPROC(__camellia_enc_blk_2way)
12534
12535@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12536
12537 movq RRBP, %rbp;
12538 movq RXOR, %rbx;
12539+ pax_force_retaddr 0, 1
12540 ret;
12541 ENDPROC(camellia_dec_blk_2way)
12542diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12543index c35fd5d..c1ee236 100644
12544--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12545+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12546@@ -24,6 +24,7 @@
12547 */
12548
12549 #include <linux/linkage.h>
12550+#include <asm/alternative-asm.h>
12551
12552 .file "cast5-avx-x86_64-asm_64.S"
12553
12554@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12555 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12556 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12557
12558+ pax_force_retaddr 0, 1
12559 ret;
12560 ENDPROC(__cast5_enc_blk16)
12561
12562@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12563 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12564 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12565
12566+ pax_force_retaddr 0, 1
12567 ret;
12568
12569 .L__skip_dec:
12570@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12571 vmovdqu RR4, (6*4*4)(%r11);
12572 vmovdqu RL4, (7*4*4)(%r11);
12573
12574+ pax_force_retaddr
12575 ret;
12576 ENDPROC(cast5_ecb_enc_16way)
12577
12578@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12579 vmovdqu RR4, (6*4*4)(%r11);
12580 vmovdqu RL4, (7*4*4)(%r11);
12581
12582+ pax_force_retaddr
12583 ret;
12584 ENDPROC(cast5_ecb_dec_16way)
12585
12586@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12587
12588 popq %r12;
12589
12590+ pax_force_retaddr
12591 ret;
12592 ENDPROC(cast5_cbc_dec_16way)
12593
12594@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12595
12596 popq %r12;
12597
12598+ pax_force_retaddr
12599 ret;
12600 ENDPROC(cast5_ctr_16way)
12601diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12602index e3531f8..18ded3a 100644
12603--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12604+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12605@@ -24,6 +24,7 @@
12606 */
12607
12608 #include <linux/linkage.h>
12609+#include <asm/alternative-asm.h>
12610 #include "glue_helper-asm-avx.S"
12611
12612 .file "cast6-avx-x86_64-asm_64.S"
12613@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12614 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12615 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12616
12617+ pax_force_retaddr 0, 1
12618 ret;
12619 ENDPROC(__cast6_enc_blk8)
12620
12621@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12622 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12623 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12624
12625+ pax_force_retaddr 0, 1
12626 ret;
12627 ENDPROC(__cast6_dec_blk8)
12628
12629@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12630
12631 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12632
12633+ pax_force_retaddr
12634 ret;
12635 ENDPROC(cast6_ecb_enc_8way)
12636
12637@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12638
12639 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12640
12641+ pax_force_retaddr
12642 ret;
12643 ENDPROC(cast6_ecb_dec_8way)
12644
12645@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12646
12647 popq %r12;
12648
12649+ pax_force_retaddr
12650 ret;
12651 ENDPROC(cast6_cbc_dec_8way)
12652
12653@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12654
12655 popq %r12;
12656
12657+ pax_force_retaddr
12658 ret;
12659 ENDPROC(cast6_ctr_8way)
12660
12661@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12662 /* dst <= regs xor IVs(in dst) */
12663 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12664
12665+ pax_force_retaddr
12666 ret;
12667 ENDPROC(cast6_xts_enc_8way)
12668
12669@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12670 /* dst <= regs xor IVs(in dst) */
12671 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12672
12673+ pax_force_retaddr
12674 ret;
12675 ENDPROC(cast6_xts_dec_8way)
12676diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12677index dbc4339..3d868c5 100644
12678--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12679+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12680@@ -45,6 +45,7 @@
12681
12682 #include <asm/inst.h>
12683 #include <linux/linkage.h>
12684+#include <asm/alternative-asm.h>
12685
12686 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12687
12688@@ -312,6 +313,7 @@ do_return:
12689 popq %rsi
12690 popq %rdi
12691 popq %rbx
12692+ pax_force_retaddr 0, 1
12693 ret
12694
12695 ################################################################
12696diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12697index 586f41a..d02851e 100644
12698--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12699+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12700@@ -18,6 +18,7 @@
12701
12702 #include <linux/linkage.h>
12703 #include <asm/inst.h>
12704+#include <asm/alternative-asm.h>
12705
12706 .data
12707
12708@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12709 psrlq $1, T2
12710 pxor T2, T1
12711 pxor T1, DATA
12712+ pax_force_retaddr
12713 ret
12714 ENDPROC(__clmul_gf128mul_ble)
12715
12716@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12717 call __clmul_gf128mul_ble
12718 PSHUFB_XMM BSWAP DATA
12719 movups DATA, (%rdi)
12720+ pax_force_retaddr
12721 ret
12722 ENDPROC(clmul_ghash_mul)
12723
12724@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12725 PSHUFB_XMM BSWAP DATA
12726 movups DATA, (%rdi)
12727 .Lupdate_just_ret:
12728+ pax_force_retaddr
12729 ret
12730 ENDPROC(clmul_ghash_update)
12731
12732@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12733 pand .Lpoly, %xmm1
12734 pxor %xmm1, %xmm0
12735 movups %xmm0, (%rdi)
12736+ pax_force_retaddr
12737 ret
12738 ENDPROC(clmul_ghash_setkey)
12739diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12740index 9279e0b..9270820 100644
12741--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12742+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12743@@ -1,4 +1,5 @@
12744 #include <linux/linkage.h>
12745+#include <asm/alternative-asm.h>
12746
12747 # enter salsa20_encrypt_bytes
12748 ENTRY(salsa20_encrypt_bytes)
12749@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12750 add %r11,%rsp
12751 mov %rdi,%rax
12752 mov %rsi,%rdx
12753+ pax_force_retaddr 0, 1
12754 ret
12755 # bytesatleast65:
12756 ._bytesatleast65:
12757@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12758 add %r11,%rsp
12759 mov %rdi,%rax
12760 mov %rsi,%rdx
12761+ pax_force_retaddr
12762 ret
12763 ENDPROC(salsa20_keysetup)
12764
12765@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12766 add %r11,%rsp
12767 mov %rdi,%rax
12768 mov %rsi,%rdx
12769+ pax_force_retaddr
12770 ret
12771 ENDPROC(salsa20_ivsetup)
12772diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12773index 2f202f4..d9164d6 100644
12774--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12775+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12776@@ -24,6 +24,7 @@
12777 */
12778
12779 #include <linux/linkage.h>
12780+#include <asm/alternative-asm.h>
12781 #include "glue_helper-asm-avx.S"
12782
12783 .file "serpent-avx-x86_64-asm_64.S"
12784@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12785 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12786 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12787
12788+ pax_force_retaddr
12789 ret;
12790 ENDPROC(__serpent_enc_blk8_avx)
12791
12792@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12793 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12794 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12795
12796+ pax_force_retaddr
12797 ret;
12798 ENDPROC(__serpent_dec_blk8_avx)
12799
12800@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12801
12802 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12803
12804+ pax_force_retaddr
12805 ret;
12806 ENDPROC(serpent_ecb_enc_8way_avx)
12807
12808@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12809
12810 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12811
12812+ pax_force_retaddr
12813 ret;
12814 ENDPROC(serpent_ecb_dec_8way_avx)
12815
12816@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12817
12818 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12819
12820+ pax_force_retaddr
12821 ret;
12822 ENDPROC(serpent_cbc_dec_8way_avx)
12823
12824@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12825
12826 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12827
12828+ pax_force_retaddr
12829 ret;
12830 ENDPROC(serpent_ctr_8way_avx)
12831
12832@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12833 /* dst <= regs xor IVs(in dst) */
12834 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12835
12836+ pax_force_retaddr
12837 ret;
12838 ENDPROC(serpent_xts_enc_8way_avx)
12839
12840@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12841 /* dst <= regs xor IVs(in dst) */
12842 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12843
12844+ pax_force_retaddr
12845 ret;
12846 ENDPROC(serpent_xts_dec_8way_avx)
12847diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12848index b222085..abd483c 100644
12849--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12850+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12851@@ -15,6 +15,7 @@
12852 */
12853
12854 #include <linux/linkage.h>
12855+#include <asm/alternative-asm.h>
12856 #include "glue_helper-asm-avx2.S"
12857
12858 .file "serpent-avx2-asm_64.S"
12859@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12860 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12861 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12862
12863+ pax_force_retaddr
12864 ret;
12865 ENDPROC(__serpent_enc_blk16)
12866
12867@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12868 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12869 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12870
12871+ pax_force_retaddr
12872 ret;
12873 ENDPROC(__serpent_dec_blk16)
12874
12875@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12876
12877 vzeroupper;
12878
12879+ pax_force_retaddr
12880 ret;
12881 ENDPROC(serpent_ecb_enc_16way)
12882
12883@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12884
12885 vzeroupper;
12886
12887+ pax_force_retaddr
12888 ret;
12889 ENDPROC(serpent_ecb_dec_16way)
12890
12891@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12892
12893 vzeroupper;
12894
12895+ pax_force_retaddr
12896 ret;
12897 ENDPROC(serpent_cbc_dec_16way)
12898
12899@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12900
12901 vzeroupper;
12902
12903+ pax_force_retaddr
12904 ret;
12905 ENDPROC(serpent_ctr_16way)
12906
12907@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12908
12909 vzeroupper;
12910
12911+ pax_force_retaddr
12912 ret;
12913 ENDPROC(serpent_xts_enc_16way)
12914
12915@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12916
12917 vzeroupper;
12918
12919+ pax_force_retaddr
12920 ret;
12921 ENDPROC(serpent_xts_dec_16way)
12922diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12923index acc066c..1559cc4 100644
12924--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12925+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12926@@ -25,6 +25,7 @@
12927 */
12928
12929 #include <linux/linkage.h>
12930+#include <asm/alternative-asm.h>
12931
12932 .file "serpent-sse2-x86_64-asm_64.S"
12933 .text
12934@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12935 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12936 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12937
12938+ pax_force_retaddr
12939 ret;
12940
12941 .L__enc_xor8:
12942 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12943 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12944
12945+ pax_force_retaddr
12946 ret;
12947 ENDPROC(__serpent_enc_blk_8way)
12948
12949@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12950 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12951 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12952
12953+ pax_force_retaddr
12954 ret;
12955 ENDPROC(serpent_dec_blk_8way)
12956diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12957index a410950..3356d42 100644
12958--- a/arch/x86/crypto/sha1_ssse3_asm.S
12959+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12960@@ -29,6 +29,7 @@
12961 */
12962
12963 #include <linux/linkage.h>
12964+#include <asm/alternative-asm.h>
12965
12966 #define CTX %rdi // arg1
12967 #define BUF %rsi // arg2
12968@@ -104,6 +105,7 @@
12969 pop %r12
12970 pop %rbp
12971 pop %rbx
12972+ pax_force_retaddr 0, 1
12973 ret
12974
12975 ENDPROC(\name)
12976diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12977index 642f156..4ab07b9 100644
12978--- a/arch/x86/crypto/sha256-avx-asm.S
12979+++ b/arch/x86/crypto/sha256-avx-asm.S
12980@@ -49,6 +49,7 @@
12981
12982 #ifdef CONFIG_AS_AVX
12983 #include <linux/linkage.h>
12984+#include <asm/alternative-asm.h>
12985
12986 ## assume buffers not aligned
12987 #define VMOVDQ vmovdqu
12988@@ -460,6 +461,7 @@ done_hash:
12989 popq %r13
12990 popq %rbp
12991 popq %rbx
12992+ pax_force_retaddr 0, 1
12993 ret
12994 ENDPROC(sha256_transform_avx)
12995
12996diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
12997index 9e86944..2e7f95a 100644
12998--- a/arch/x86/crypto/sha256-avx2-asm.S
12999+++ b/arch/x86/crypto/sha256-avx2-asm.S
13000@@ -50,6 +50,7 @@
13001
13002 #ifdef CONFIG_AS_AVX2
13003 #include <linux/linkage.h>
13004+#include <asm/alternative-asm.h>
13005
13006 ## assume buffers not aligned
13007 #define VMOVDQ vmovdqu
13008@@ -720,6 +721,7 @@ done_hash:
13009 popq %r12
13010 popq %rbp
13011 popq %rbx
13012+ pax_force_retaddr 0, 1
13013 ret
13014 ENDPROC(sha256_transform_rorx)
13015
13016diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13017index f833b74..c36ed14 100644
13018--- a/arch/x86/crypto/sha256-ssse3-asm.S
13019+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13020@@ -47,6 +47,7 @@
13021 ########################################################################
13022
13023 #include <linux/linkage.h>
13024+#include <asm/alternative-asm.h>
13025
13026 ## assume buffers not aligned
13027 #define MOVDQ movdqu
13028@@ -471,6 +472,7 @@ done_hash:
13029 popq %rbp
13030 popq %rbx
13031
13032+ pax_force_retaddr 0, 1
13033 ret
13034 ENDPROC(sha256_transform_ssse3)
13035
13036diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13037index 974dde9..4533d34 100644
13038--- a/arch/x86/crypto/sha512-avx-asm.S
13039+++ b/arch/x86/crypto/sha512-avx-asm.S
13040@@ -49,6 +49,7 @@
13041
13042 #ifdef CONFIG_AS_AVX
13043 #include <linux/linkage.h>
13044+#include <asm/alternative-asm.h>
13045
13046 .text
13047
13048@@ -364,6 +365,7 @@ updateblock:
13049 mov frame_RSPSAVE(%rsp), %rsp
13050
13051 nowork:
13052+ pax_force_retaddr 0, 1
13053 ret
13054 ENDPROC(sha512_transform_avx)
13055
13056diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13057index 568b961..061ef1d 100644
13058--- a/arch/x86/crypto/sha512-avx2-asm.S
13059+++ b/arch/x86/crypto/sha512-avx2-asm.S
13060@@ -51,6 +51,7 @@
13061
13062 #ifdef CONFIG_AS_AVX2
13063 #include <linux/linkage.h>
13064+#include <asm/alternative-asm.h>
13065
13066 .text
13067
13068@@ -678,6 +679,7 @@ done_hash:
13069
13070 # Restore Stack Pointer
13071 mov frame_RSPSAVE(%rsp), %rsp
13072+ pax_force_retaddr 0, 1
13073 ret
13074 ENDPROC(sha512_transform_rorx)
13075
13076diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13077index fb56855..e23914f 100644
13078--- a/arch/x86/crypto/sha512-ssse3-asm.S
13079+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13080@@ -48,6 +48,7 @@
13081 ########################################################################
13082
13083 #include <linux/linkage.h>
13084+#include <asm/alternative-asm.h>
13085
13086 .text
13087
13088@@ -363,6 +364,7 @@ updateblock:
13089 mov frame_RSPSAVE(%rsp), %rsp
13090
13091 nowork:
13092+ pax_force_retaddr 0, 1
13093 ret
13094 ENDPROC(sha512_transform_ssse3)
13095
13096diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13097index 0505813..63b1d00 100644
13098--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13099+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13100@@ -24,6 +24,7 @@
13101 */
13102
13103 #include <linux/linkage.h>
13104+#include <asm/alternative-asm.h>
13105 #include "glue_helper-asm-avx.S"
13106
13107 .file "twofish-avx-x86_64-asm_64.S"
13108@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13109 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13110 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13111
13112+ pax_force_retaddr 0, 1
13113 ret;
13114 ENDPROC(__twofish_enc_blk8)
13115
13116@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13117 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13118 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13119
13120+ pax_force_retaddr 0, 1
13121 ret;
13122 ENDPROC(__twofish_dec_blk8)
13123
13124@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13125
13126 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13127
13128+ pax_force_retaddr 0, 1
13129 ret;
13130 ENDPROC(twofish_ecb_enc_8way)
13131
13132@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13133
13134 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13135
13136+ pax_force_retaddr 0, 1
13137 ret;
13138 ENDPROC(twofish_ecb_dec_8way)
13139
13140@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13141
13142 popq %r12;
13143
13144+ pax_force_retaddr 0, 1
13145 ret;
13146 ENDPROC(twofish_cbc_dec_8way)
13147
13148@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13149
13150 popq %r12;
13151
13152+ pax_force_retaddr 0, 1
13153 ret;
13154 ENDPROC(twofish_ctr_8way)
13155
13156@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13157 /* dst <= regs xor IVs(in dst) */
13158 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13159
13160+ pax_force_retaddr 0, 1
13161 ret;
13162 ENDPROC(twofish_xts_enc_8way)
13163
13164@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13165 /* dst <= regs xor IVs(in dst) */
13166 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13167
13168+ pax_force_retaddr 0, 1
13169 ret;
13170 ENDPROC(twofish_xts_dec_8way)
13171diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13172index 1c3b7ce..b365c5e 100644
13173--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13174+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13175@@ -21,6 +21,7 @@
13176 */
13177
13178 #include <linux/linkage.h>
13179+#include <asm/alternative-asm.h>
13180
13181 .file "twofish-x86_64-asm-3way.S"
13182 .text
13183@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13184 popq %r13;
13185 popq %r14;
13186 popq %r15;
13187+ pax_force_retaddr 0, 1
13188 ret;
13189
13190 .L__enc_xor3:
13191@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13192 popq %r13;
13193 popq %r14;
13194 popq %r15;
13195+ pax_force_retaddr 0, 1
13196 ret;
13197 ENDPROC(__twofish_enc_blk_3way)
13198
13199@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13200 popq %r13;
13201 popq %r14;
13202 popq %r15;
13203+ pax_force_retaddr 0, 1
13204 ret;
13205 ENDPROC(twofish_dec_blk_3way)
13206diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13207index a039d21..29e7615 100644
13208--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13209+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13210@@ -22,6 +22,7 @@
13211
13212 #include <linux/linkage.h>
13213 #include <asm/asm-offsets.h>
13214+#include <asm/alternative-asm.h>
13215
13216 #define a_offset 0
13217 #define b_offset 4
13218@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13219
13220 popq R1
13221 movq $1,%rax
13222+ pax_force_retaddr 0, 1
13223 ret
13224 ENDPROC(twofish_enc_blk)
13225
13226@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13227
13228 popq R1
13229 movq $1,%rax
13230+ pax_force_retaddr 0, 1
13231 ret
13232 ENDPROC(twofish_dec_blk)
13233diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13234index bae3aba..c1788c1 100644
13235--- a/arch/x86/ia32/ia32_aout.c
13236+++ b/arch/x86/ia32/ia32_aout.c
13237@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13238 unsigned long dump_start, dump_size;
13239 struct user32 dump;
13240
13241+ memset(&dump, 0, sizeof(dump));
13242+
13243 fs = get_fs();
13244 set_fs(KERNEL_DS);
13245 has_dumped = 1;
13246diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13247index bccfca6..a312009 100644
13248--- a/arch/x86/ia32/ia32_signal.c
13249+++ b/arch/x86/ia32/ia32_signal.c
13250@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13251 sp -= frame_size;
13252 /* Align the stack pointer according to the i386 ABI,
13253 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13254- sp = ((sp + 4) & -16ul) - 4;
13255+ sp = ((sp - 12) & -16ul) - 4;
13256 return (void __user *) sp;
13257 }
13258
13259@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13260 * These are actually not used anymore, but left because some
13261 * gdb versions depend on them as a marker.
13262 */
13263- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13264+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13265 } put_user_catch(err);
13266
13267 if (err)
13268@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13269 0xb8,
13270 __NR_ia32_rt_sigreturn,
13271 0x80cd,
13272- 0,
13273+ 0
13274 };
13275
13276 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13277@@ -457,20 +457,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13278 else
13279 put_user_ex(0, &frame->uc.uc_flags);
13280 put_user_ex(0, &frame->uc.uc_link);
13281- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
13282+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
13283
13284 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13285 restorer = ksig->ka.sa.sa_restorer;
13286+ else if (current->mm->context.vdso)
13287+ /* Return stub is in 32bit vsyscall page */
13288+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13289 else
13290- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13291- rt_sigreturn);
13292+ restorer = &frame->retcode;
13293 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13294
13295 /*
13296 * Not actually used anymore, but left because some gdb
13297 * versions need it.
13298 */
13299- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13300+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13301 } put_user_catch(err);
13302
13303 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13304diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13305index 474dc1b..9297c58 100644
13306--- a/arch/x86/ia32/ia32entry.S
13307+++ b/arch/x86/ia32/ia32entry.S
13308@@ -15,8 +15,10 @@
13309 #include <asm/irqflags.h>
13310 #include <asm/asm.h>
13311 #include <asm/smap.h>
13312+#include <asm/pgtable.h>
13313 #include <linux/linkage.h>
13314 #include <linux/err.h>
13315+#include <asm/alternative-asm.h>
13316
13317 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13318 #include <linux/elf-em.h>
13319@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13320 ENDPROC(native_irq_enable_sysexit)
13321 #endif
13322
13323+ .macro pax_enter_kernel_user
13324+ pax_set_fptr_mask
13325+#ifdef CONFIG_PAX_MEMORY_UDEREF
13326+ call pax_enter_kernel_user
13327+#endif
13328+ .endm
13329+
13330+ .macro pax_exit_kernel_user
13331+#ifdef CONFIG_PAX_MEMORY_UDEREF
13332+ call pax_exit_kernel_user
13333+#endif
13334+#ifdef CONFIG_PAX_RANDKSTACK
13335+ pushq %rax
13336+ pushq %r11
13337+ call pax_randomize_kstack
13338+ popq %r11
13339+ popq %rax
13340+#endif
13341+ .endm
13342+
13343+ .macro pax_erase_kstack
13344+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13345+ call pax_erase_kstack
13346+#endif
13347+ .endm
13348+
13349 /*
13350 * 32bit SYSENTER instruction entry.
13351 *
13352@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13353 CFI_REGISTER rsp,rbp
13354 SWAPGS_UNSAFE_STACK
13355 movq PER_CPU_VAR(kernel_stack), %rsp
13356- addq $(KERNEL_STACK_OFFSET),%rsp
13357- /*
13358- * No need to follow this irqs on/off section: the syscall
13359- * disabled irqs, here we enable it straight after entry:
13360- */
13361- ENABLE_INTERRUPTS(CLBR_NONE)
13362 movl %ebp,%ebp /* zero extension */
13363 pushq_cfi $__USER32_DS
13364 /*CFI_REL_OFFSET ss,0*/
13365@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13366 CFI_REL_OFFSET rsp,0
13367 pushfq_cfi
13368 /*CFI_REL_OFFSET rflags,0*/
13369- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13370- CFI_REGISTER rip,r10
13371+ orl $X86_EFLAGS_IF,(%rsp)
13372+ GET_THREAD_INFO(%r11)
13373+ movl TI_sysenter_return(%r11), %r11d
13374+ CFI_REGISTER rip,r11
13375 pushq_cfi $__USER32_CS
13376 /*CFI_REL_OFFSET cs,0*/
13377 movl %eax, %eax
13378- pushq_cfi %r10
13379+ pushq_cfi %r11
13380 CFI_REL_OFFSET rip,0
13381 pushq_cfi %rax
13382 cld
13383 SAVE_ARGS 0,1,0
13384+ pax_enter_kernel_user
13385+
13386+#ifdef CONFIG_PAX_RANDKSTACK
13387+ pax_erase_kstack
13388+#endif
13389+
13390+ /*
13391+ * No need to follow this irqs on/off section: the syscall
13392+ * disabled irqs, here we enable it straight after entry:
13393+ */
13394+ ENABLE_INTERRUPTS(CLBR_NONE)
13395 /* no need to do an access_ok check here because rbp has been
13396 32bit zero extended */
13397+
13398+#ifdef CONFIG_PAX_MEMORY_UDEREF
13399+ addq pax_user_shadow_base,%rbp
13400+ ASM_PAX_OPEN_USERLAND
13401+#endif
13402+
13403 ASM_STAC
13404 1: movl (%rbp),%ebp
13405 _ASM_EXTABLE(1b,ia32_badarg)
13406 ASM_CLAC
13407- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13408- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13409+
13410+#ifdef CONFIG_PAX_MEMORY_UDEREF
13411+ ASM_PAX_CLOSE_USERLAND
13412+#endif
13413+
13414+ GET_THREAD_INFO(%r11)
13415+ orl $TS_COMPAT,TI_status(%r11)
13416+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13417 CFI_REMEMBER_STATE
13418 jnz sysenter_tracesys
13419 cmpq $(IA32_NR_syscalls-1),%rax
13420@@ -162,12 +209,15 @@ sysenter_do_call:
13421 sysenter_dispatch:
13422 call *ia32_sys_call_table(,%rax,8)
13423 movq %rax,RAX-ARGOFFSET(%rsp)
13424+ GET_THREAD_INFO(%r11)
13425 DISABLE_INTERRUPTS(CLBR_NONE)
13426 TRACE_IRQS_OFF
13427- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13428+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13429 jnz sysexit_audit
13430 sysexit_from_sys_call:
13431- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13432+ pax_exit_kernel_user
13433+ pax_erase_kstack
13434+ andl $~TS_COMPAT,TI_status(%r11)
13435 /* clear IF, that popfq doesn't enable interrupts early */
13436 andl $~0x200,EFLAGS-R11(%rsp)
13437 movl RIP-R11(%rsp),%edx /* User %eip */
13438@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13439 movl %eax,%esi /* 2nd arg: syscall number */
13440 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13441 call __audit_syscall_entry
13442+
13443+ pax_erase_kstack
13444+
13445 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13446 cmpq $(IA32_NR_syscalls-1),%rax
13447 ja ia32_badsys
13448@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13449 .endm
13450
13451 .macro auditsys_exit exit
13452- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13453+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13454 jnz ia32_ret_from_sys_call
13455 TRACE_IRQS_ON
13456 ENABLE_INTERRUPTS(CLBR_NONE)
13457@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13458 1: setbe %al /* 1 if error, 0 if not */
13459 movzbl %al,%edi /* zero-extend that into %edi */
13460 call __audit_syscall_exit
13461+ GET_THREAD_INFO(%r11)
13462 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13463 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13464 DISABLE_INTERRUPTS(CLBR_NONE)
13465 TRACE_IRQS_OFF
13466- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13467+ testl %edi,TI_flags(%r11)
13468 jz \exit
13469 CLEAR_RREGS -ARGOFFSET
13470 jmp int_with_check
13471@@ -237,7 +291,7 @@ sysexit_audit:
13472
13473 sysenter_tracesys:
13474 #ifdef CONFIG_AUDITSYSCALL
13475- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13476+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13477 jz sysenter_auditsys
13478 #endif
13479 SAVE_REST
13480@@ -249,6 +303,9 @@ sysenter_tracesys:
13481 RESTORE_REST
13482 cmpq $(IA32_NR_syscalls-1),%rax
13483 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13484+
13485+ pax_erase_kstack
13486+
13487 jmp sysenter_do_call
13488 CFI_ENDPROC
13489 ENDPROC(ia32_sysenter_target)
13490@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13491 ENTRY(ia32_cstar_target)
13492 CFI_STARTPROC32 simple
13493 CFI_SIGNAL_FRAME
13494- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13495+ CFI_DEF_CFA rsp,0
13496 CFI_REGISTER rip,rcx
13497 /*CFI_REGISTER rflags,r11*/
13498 SWAPGS_UNSAFE_STACK
13499 movl %esp,%r8d
13500 CFI_REGISTER rsp,r8
13501 movq PER_CPU_VAR(kernel_stack),%rsp
13502+ SAVE_ARGS 8*6,0,0
13503+ pax_enter_kernel_user
13504+
13505+#ifdef CONFIG_PAX_RANDKSTACK
13506+ pax_erase_kstack
13507+#endif
13508+
13509 /*
13510 * No need to follow this irqs on/off section: the syscall
13511 * disabled irqs and here we enable it straight after entry:
13512 */
13513 ENABLE_INTERRUPTS(CLBR_NONE)
13514- SAVE_ARGS 8,0,0
13515 movl %eax,%eax /* zero extension */
13516 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13517 movq %rcx,RIP-ARGOFFSET(%rsp)
13518@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13519 /* no need to do an access_ok check here because r8 has been
13520 32bit zero extended */
13521 /* hardware stack frame is complete now */
13522+
13523+#ifdef CONFIG_PAX_MEMORY_UDEREF
13524+ ASM_PAX_OPEN_USERLAND
13525+ movq pax_user_shadow_base,%r8
13526+ addq RSP-ARGOFFSET(%rsp),%r8
13527+#endif
13528+
13529 ASM_STAC
13530 1: movl (%r8),%r9d
13531 _ASM_EXTABLE(1b,ia32_badarg)
13532 ASM_CLAC
13533- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13534- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13535+
13536+#ifdef CONFIG_PAX_MEMORY_UDEREF
13537+ ASM_PAX_CLOSE_USERLAND
13538+#endif
13539+
13540+ GET_THREAD_INFO(%r11)
13541+ orl $TS_COMPAT,TI_status(%r11)
13542+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13543 CFI_REMEMBER_STATE
13544 jnz cstar_tracesys
13545 cmpq $IA32_NR_syscalls-1,%rax
13546@@ -319,12 +395,15 @@ cstar_do_call:
13547 cstar_dispatch:
13548 call *ia32_sys_call_table(,%rax,8)
13549 movq %rax,RAX-ARGOFFSET(%rsp)
13550+ GET_THREAD_INFO(%r11)
13551 DISABLE_INTERRUPTS(CLBR_NONE)
13552 TRACE_IRQS_OFF
13553- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13554+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13555 jnz sysretl_audit
13556 sysretl_from_sys_call:
13557- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13558+ pax_exit_kernel_user
13559+ pax_erase_kstack
13560+ andl $~TS_COMPAT,TI_status(%r11)
13561 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13562 movl RIP-ARGOFFSET(%rsp),%ecx
13563 CFI_REGISTER rip,rcx
13564@@ -352,7 +431,7 @@ sysretl_audit:
13565
13566 cstar_tracesys:
13567 #ifdef CONFIG_AUDITSYSCALL
13568- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13569+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13570 jz cstar_auditsys
13571 #endif
13572 xchgl %r9d,%ebp
13573@@ -366,11 +445,19 @@ cstar_tracesys:
13574 xchgl %ebp,%r9d
13575 cmpq $(IA32_NR_syscalls-1),%rax
13576 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13577+
13578+ pax_erase_kstack
13579+
13580 jmp cstar_do_call
13581 END(ia32_cstar_target)
13582
13583 ia32_badarg:
13584 ASM_CLAC
13585+
13586+#ifdef CONFIG_PAX_MEMORY_UDEREF
13587+ ASM_PAX_CLOSE_USERLAND
13588+#endif
13589+
13590 movq $-EFAULT,%rax
13591 jmp ia32_sysret
13592 CFI_ENDPROC
13593@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13594 CFI_REL_OFFSET rip,RIP-RIP
13595 PARAVIRT_ADJUST_EXCEPTION_FRAME
13596 SWAPGS
13597- /*
13598- * No need to follow this irqs on/off section: the syscall
13599- * disabled irqs and here we enable it straight after entry:
13600- */
13601- ENABLE_INTERRUPTS(CLBR_NONE)
13602 movl %eax,%eax
13603 pushq_cfi %rax
13604 cld
13605 /* note the registers are not zero extended to the sf.
13606 this could be a problem. */
13607 SAVE_ARGS 0,1,0
13608- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13609- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13610+ pax_enter_kernel_user
13611+
13612+#ifdef CONFIG_PAX_RANDKSTACK
13613+ pax_erase_kstack
13614+#endif
13615+
13616+ /*
13617+ * No need to follow this irqs on/off section: the syscall
13618+ * disabled irqs and here we enable it straight after entry:
13619+ */
13620+ ENABLE_INTERRUPTS(CLBR_NONE)
13621+ GET_THREAD_INFO(%r11)
13622+ orl $TS_COMPAT,TI_status(%r11)
13623+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13624 jnz ia32_tracesys
13625 cmpq $(IA32_NR_syscalls-1),%rax
13626 ja ia32_badsys
13627@@ -442,6 +536,9 @@ ia32_tracesys:
13628 RESTORE_REST
13629 cmpq $(IA32_NR_syscalls-1),%rax
13630 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13631+
13632+ pax_erase_kstack
13633+
13634 jmp ia32_do_call
13635 END(ia32_syscall)
13636
13637diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13638index 8e0ceec..af13504 100644
13639--- a/arch/x86/ia32/sys_ia32.c
13640+++ b/arch/x86/ia32/sys_ia32.c
13641@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13642 */
13643 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13644 {
13645- typeof(ubuf->st_uid) uid = 0;
13646- typeof(ubuf->st_gid) gid = 0;
13647+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13648+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13649 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13650 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13651 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13652diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13653index 372231c..a5aa1a1 100644
13654--- a/arch/x86/include/asm/alternative-asm.h
13655+++ b/arch/x86/include/asm/alternative-asm.h
13656@@ -18,6 +18,45 @@
13657 .endm
13658 #endif
13659
13660+#ifdef KERNEXEC_PLUGIN
13661+ .macro pax_force_retaddr_bts rip=0
13662+ btsq $63,\rip(%rsp)
13663+ .endm
13664+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13665+ .macro pax_force_retaddr rip=0, reload=0
13666+ btsq $63,\rip(%rsp)
13667+ .endm
13668+ .macro pax_force_fptr ptr
13669+ btsq $63,\ptr
13670+ .endm
13671+ .macro pax_set_fptr_mask
13672+ .endm
13673+#endif
13674+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13675+ .macro pax_force_retaddr rip=0, reload=0
13676+ .if \reload
13677+ pax_set_fptr_mask
13678+ .endif
13679+ orq %r10,\rip(%rsp)
13680+ .endm
13681+ .macro pax_force_fptr ptr
13682+ orq %r10,\ptr
13683+ .endm
13684+ .macro pax_set_fptr_mask
13685+ movabs $0x8000000000000000,%r10
13686+ .endm
13687+#endif
13688+#else
13689+ .macro pax_force_retaddr rip=0, reload=0
13690+ .endm
13691+ .macro pax_force_fptr ptr
13692+ .endm
13693+ .macro pax_force_retaddr_bts rip=0
13694+ .endm
13695+ .macro pax_set_fptr_mask
13696+ .endm
13697+#endif
13698+
13699 .macro altinstruction_entry orig alt feature orig_len alt_len
13700 .long \orig - .
13701 .long \alt - .
13702diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13703index 58ed6d9..f1cbe58 100644
13704--- a/arch/x86/include/asm/alternative.h
13705+++ b/arch/x86/include/asm/alternative.h
13706@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13707 ".pushsection .discard,\"aw\",@progbits\n" \
13708 DISCARD_ENTRY(1) \
13709 ".popsection\n" \
13710- ".pushsection .altinstr_replacement, \"ax\"\n" \
13711+ ".pushsection .altinstr_replacement, \"a\"\n" \
13712 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13713 ".popsection"
13714
13715@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13716 DISCARD_ENTRY(1) \
13717 DISCARD_ENTRY(2) \
13718 ".popsection\n" \
13719- ".pushsection .altinstr_replacement, \"ax\"\n" \
13720+ ".pushsection .altinstr_replacement, \"a\"\n" \
13721 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13722 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13723 ".popsection"
13724diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13725index f8119b5..7209d5b 100644
13726--- a/arch/x86/include/asm/apic.h
13727+++ b/arch/x86/include/asm/apic.h
13728@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13729
13730 #ifdef CONFIG_X86_LOCAL_APIC
13731
13732-extern unsigned int apic_verbosity;
13733+extern int apic_verbosity;
13734 extern int local_apic_timer_c2_ok;
13735
13736 extern int disable_apic;
13737diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13738index 20370c6..a2eb9b0 100644
13739--- a/arch/x86/include/asm/apm.h
13740+++ b/arch/x86/include/asm/apm.h
13741@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13742 __asm__ __volatile__(APM_DO_ZERO_SEGS
13743 "pushl %%edi\n\t"
13744 "pushl %%ebp\n\t"
13745- "lcall *%%cs:apm_bios_entry\n\t"
13746+ "lcall *%%ss:apm_bios_entry\n\t"
13747 "setc %%al\n\t"
13748 "popl %%ebp\n\t"
13749 "popl %%edi\n\t"
13750@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13751 __asm__ __volatile__(APM_DO_ZERO_SEGS
13752 "pushl %%edi\n\t"
13753 "pushl %%ebp\n\t"
13754- "lcall *%%cs:apm_bios_entry\n\t"
13755+ "lcall *%%ss:apm_bios_entry\n\t"
13756 "setc %%bl\n\t"
13757 "popl %%ebp\n\t"
13758 "popl %%edi\n\t"
13759diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13760index 722aa3b..3a0bb27 100644
13761--- a/arch/x86/include/asm/atomic.h
13762+++ b/arch/x86/include/asm/atomic.h
13763@@ -22,7 +22,18 @@
13764 */
13765 static inline int atomic_read(const atomic_t *v)
13766 {
13767- return (*(volatile int *)&(v)->counter);
13768+ return (*(volatile const int *)&(v)->counter);
13769+}
13770+
13771+/**
13772+ * atomic_read_unchecked - read atomic variable
13773+ * @v: pointer of type atomic_unchecked_t
13774+ *
13775+ * Atomically reads the value of @v.
13776+ */
13777+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13778+{
13779+ return (*(volatile const int *)&(v)->counter);
13780 }
13781
13782 /**
13783@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13784 }
13785
13786 /**
13787+ * atomic_set_unchecked - set atomic variable
13788+ * @v: pointer of type atomic_unchecked_t
13789+ * @i: required value
13790+ *
13791+ * Atomically sets the value of @v to @i.
13792+ */
13793+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13794+{
13795+ v->counter = i;
13796+}
13797+
13798+/**
13799 * atomic_add - add integer to atomic variable
13800 * @i: integer value to add
13801 * @v: pointer of type atomic_t
13802@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13803 */
13804 static inline void atomic_add(int i, atomic_t *v)
13805 {
13806- asm volatile(LOCK_PREFIX "addl %1,%0"
13807+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13808+
13809+#ifdef CONFIG_PAX_REFCOUNT
13810+ "jno 0f\n"
13811+ LOCK_PREFIX "subl %1,%0\n"
13812+ "int $4\n0:\n"
13813+ _ASM_EXTABLE(0b, 0b)
13814+#endif
13815+
13816+ : "+m" (v->counter)
13817+ : "ir" (i));
13818+}
13819+
13820+/**
13821+ * atomic_add_unchecked - add integer to atomic variable
13822+ * @i: integer value to add
13823+ * @v: pointer of type atomic_unchecked_t
13824+ *
13825+ * Atomically adds @i to @v.
13826+ */
13827+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13828+{
13829+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13830 : "+m" (v->counter)
13831 : "ir" (i));
13832 }
13833@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13834 */
13835 static inline void atomic_sub(int i, atomic_t *v)
13836 {
13837- asm volatile(LOCK_PREFIX "subl %1,%0"
13838+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13839+
13840+#ifdef CONFIG_PAX_REFCOUNT
13841+ "jno 0f\n"
13842+ LOCK_PREFIX "addl %1,%0\n"
13843+ "int $4\n0:\n"
13844+ _ASM_EXTABLE(0b, 0b)
13845+#endif
13846+
13847+ : "+m" (v->counter)
13848+ : "ir" (i));
13849+}
13850+
13851+/**
13852+ * atomic_sub_unchecked - subtract integer from atomic variable
13853+ * @i: integer value to subtract
13854+ * @v: pointer of type atomic_unchecked_t
13855+ *
13856+ * Atomically subtracts @i from @v.
13857+ */
13858+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13859+{
13860+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13861 : "+m" (v->counter)
13862 : "ir" (i));
13863 }
13864@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13865 {
13866 unsigned char c;
13867
13868- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13869+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13870+
13871+#ifdef CONFIG_PAX_REFCOUNT
13872+ "jno 0f\n"
13873+ LOCK_PREFIX "addl %2,%0\n"
13874+ "int $4\n0:\n"
13875+ _ASM_EXTABLE(0b, 0b)
13876+#endif
13877+
13878+ "sete %1\n"
13879 : "+m" (v->counter), "=qm" (c)
13880 : "ir" (i) : "memory");
13881 return c;
13882@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13883 */
13884 static inline void atomic_inc(atomic_t *v)
13885 {
13886- asm volatile(LOCK_PREFIX "incl %0"
13887+ asm volatile(LOCK_PREFIX "incl %0\n"
13888+
13889+#ifdef CONFIG_PAX_REFCOUNT
13890+ "jno 0f\n"
13891+ LOCK_PREFIX "decl %0\n"
13892+ "int $4\n0:\n"
13893+ _ASM_EXTABLE(0b, 0b)
13894+#endif
13895+
13896+ : "+m" (v->counter));
13897+}
13898+
13899+/**
13900+ * atomic_inc_unchecked - increment atomic variable
13901+ * @v: pointer of type atomic_unchecked_t
13902+ *
13903+ * Atomically increments @v by 1.
13904+ */
13905+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13906+{
13907+ asm volatile(LOCK_PREFIX "incl %0\n"
13908 : "+m" (v->counter));
13909 }
13910
13911@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13912 */
13913 static inline void atomic_dec(atomic_t *v)
13914 {
13915- asm volatile(LOCK_PREFIX "decl %0"
13916+ asm volatile(LOCK_PREFIX "decl %0\n"
13917+
13918+#ifdef CONFIG_PAX_REFCOUNT
13919+ "jno 0f\n"
13920+ LOCK_PREFIX "incl %0\n"
13921+ "int $4\n0:\n"
13922+ _ASM_EXTABLE(0b, 0b)
13923+#endif
13924+
13925+ : "+m" (v->counter));
13926+}
13927+
13928+/**
13929+ * atomic_dec_unchecked - decrement atomic variable
13930+ * @v: pointer of type atomic_unchecked_t
13931+ *
13932+ * Atomically decrements @v by 1.
13933+ */
13934+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13935+{
13936+ asm volatile(LOCK_PREFIX "decl %0\n"
13937 : "+m" (v->counter));
13938 }
13939
13940@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13941 {
13942 unsigned char c;
13943
13944- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13945+ asm volatile(LOCK_PREFIX "decl %0\n"
13946+
13947+#ifdef CONFIG_PAX_REFCOUNT
13948+ "jno 0f\n"
13949+ LOCK_PREFIX "incl %0\n"
13950+ "int $4\n0:\n"
13951+ _ASM_EXTABLE(0b, 0b)
13952+#endif
13953+
13954+ "sete %1\n"
13955 : "+m" (v->counter), "=qm" (c)
13956 : : "memory");
13957 return c != 0;
13958@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13959 {
13960 unsigned char c;
13961
13962- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13963+ asm volatile(LOCK_PREFIX "incl %0\n"
13964+
13965+#ifdef CONFIG_PAX_REFCOUNT
13966+ "jno 0f\n"
13967+ LOCK_PREFIX "decl %0\n"
13968+ "int $4\n0:\n"
13969+ _ASM_EXTABLE(0b, 0b)
13970+#endif
13971+
13972+ "sete %1\n"
13973+ : "+m" (v->counter), "=qm" (c)
13974+ : : "memory");
13975+ return c != 0;
13976+}
13977+
13978+/**
13979+ * atomic_inc_and_test_unchecked - increment and test
13980+ * @v: pointer of type atomic_unchecked_t
13981+ *
13982+ * Atomically increments @v by 1
13983+ * and returns true if the result is zero, or false for all
13984+ * other cases.
13985+ */
13986+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13987+{
13988+ unsigned char c;
13989+
13990+ asm volatile(LOCK_PREFIX "incl %0\n"
13991+ "sete %1\n"
13992 : "+m" (v->counter), "=qm" (c)
13993 : : "memory");
13994 return c != 0;
13995@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13996 {
13997 unsigned char c;
13998
13999- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14000+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14001+
14002+#ifdef CONFIG_PAX_REFCOUNT
14003+ "jno 0f\n"
14004+ LOCK_PREFIX "subl %2,%0\n"
14005+ "int $4\n0:\n"
14006+ _ASM_EXTABLE(0b, 0b)
14007+#endif
14008+
14009+ "sets %1\n"
14010 : "+m" (v->counter), "=qm" (c)
14011 : "ir" (i) : "memory");
14012 return c;
14013@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14014 */
14015 static inline int atomic_add_return(int i, atomic_t *v)
14016 {
14017+ return i + xadd_check_overflow(&v->counter, i);
14018+}
14019+
14020+/**
14021+ * atomic_add_return_unchecked - add integer and return
14022+ * @i: integer value to add
14023+ * @v: pointer of type atomic_unchecked_t
14024+ *
14025+ * Atomically adds @i to @v and returns @i + @v
14026+ */
14027+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14028+{
14029 return i + xadd(&v->counter, i);
14030 }
14031
14032@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14033 }
14034
14035 #define atomic_inc_return(v) (atomic_add_return(1, v))
14036+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14037+{
14038+ return atomic_add_return_unchecked(1, v);
14039+}
14040 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14041
14042 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14043@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14044 return cmpxchg(&v->counter, old, new);
14045 }
14046
14047+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14048+{
14049+ return cmpxchg(&v->counter, old, new);
14050+}
14051+
14052 static inline int atomic_xchg(atomic_t *v, int new)
14053 {
14054 return xchg(&v->counter, new);
14055 }
14056
14057+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14058+{
14059+ return xchg(&v->counter, new);
14060+}
14061+
14062 /**
14063 * __atomic_add_unless - add unless the number is already a given value
14064 * @v: pointer of type atomic_t
14065@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14066 */
14067 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14068 {
14069- int c, old;
14070+ int c, old, new;
14071 c = atomic_read(v);
14072 for (;;) {
14073- if (unlikely(c == (u)))
14074+ if (unlikely(c == u))
14075 break;
14076- old = atomic_cmpxchg((v), c, c + (a));
14077+
14078+ asm volatile("addl %2,%0\n"
14079+
14080+#ifdef CONFIG_PAX_REFCOUNT
14081+ "jno 0f\n"
14082+ "subl %2,%0\n"
14083+ "int $4\n0:\n"
14084+ _ASM_EXTABLE(0b, 0b)
14085+#endif
14086+
14087+ : "=r" (new)
14088+ : "0" (c), "ir" (a));
14089+
14090+ old = atomic_cmpxchg(v, c, new);
14091 if (likely(old == c))
14092 break;
14093 c = old;
14094@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14095 }
14096
14097 /**
14098+ * atomic_inc_not_zero_hint - increment if not null
14099+ * @v: pointer of type atomic_t
14100+ * @hint: probable value of the atomic before the increment
14101+ *
14102+ * This version of atomic_inc_not_zero() gives a hint of probable
14103+ * value of the atomic. This helps processor to not read the memory
14104+ * before doing the atomic read/modify/write cycle, lowering
14105+ * number of bus transactions on some arches.
14106+ *
14107+ * Returns: 0 if increment was not done, 1 otherwise.
14108+ */
14109+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14110+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14111+{
14112+ int val, c = hint, new;
14113+
14114+ /* sanity test, should be removed by compiler if hint is a constant */
14115+ if (!hint)
14116+ return __atomic_add_unless(v, 1, 0);
14117+
14118+ do {
14119+ asm volatile("incl %0\n"
14120+
14121+#ifdef CONFIG_PAX_REFCOUNT
14122+ "jno 0f\n"
14123+ "decl %0\n"
14124+ "int $4\n0:\n"
14125+ _ASM_EXTABLE(0b, 0b)
14126+#endif
14127+
14128+ : "=r" (new)
14129+ : "0" (c));
14130+
14131+ val = atomic_cmpxchg(v, c, new);
14132+ if (val == c)
14133+ return 1;
14134+ c = val;
14135+ } while (c);
14136+
14137+ return 0;
14138+}
14139+
14140+/**
14141 * atomic_inc_short - increment of a short integer
14142 * @v: pointer to type int
14143 *
14144@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14145 #endif
14146
14147 /* These are x86-specific, used by some header files */
14148-#define atomic_clear_mask(mask, addr) \
14149- asm volatile(LOCK_PREFIX "andl %0,%1" \
14150- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14151+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14152+{
14153+ asm volatile(LOCK_PREFIX "andl %1,%0"
14154+ : "+m" (v->counter)
14155+ : "r" (~(mask))
14156+ : "memory");
14157+}
14158
14159-#define atomic_set_mask(mask, addr) \
14160- asm volatile(LOCK_PREFIX "orl %0,%1" \
14161- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14162- : "memory")
14163+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14164+{
14165+ asm volatile(LOCK_PREFIX "andl %1,%0"
14166+ : "+m" (v->counter)
14167+ : "r" (~(mask))
14168+ : "memory");
14169+}
14170+
14171+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14172+{
14173+ asm volatile(LOCK_PREFIX "orl %1,%0"
14174+ : "+m" (v->counter)
14175+ : "r" (mask)
14176+ : "memory");
14177+}
14178+
14179+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14180+{
14181+ asm volatile(LOCK_PREFIX "orl %1,%0"
14182+ : "+m" (v->counter)
14183+ : "r" (mask)
14184+ : "memory");
14185+}
14186
14187 /* Atomic operations are already serializing on x86 */
14188 #define smp_mb__before_atomic_dec() barrier()
14189diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14190index b154de7..aadebd8 100644
14191--- a/arch/x86/include/asm/atomic64_32.h
14192+++ b/arch/x86/include/asm/atomic64_32.h
14193@@ -12,6 +12,14 @@ typedef struct {
14194 u64 __aligned(8) counter;
14195 } atomic64_t;
14196
14197+#ifdef CONFIG_PAX_REFCOUNT
14198+typedef struct {
14199+ u64 __aligned(8) counter;
14200+} atomic64_unchecked_t;
14201+#else
14202+typedef atomic64_t atomic64_unchecked_t;
14203+#endif
14204+
14205 #define ATOMIC64_INIT(val) { (val) }
14206
14207 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14208@@ -37,21 +45,31 @@ typedef struct {
14209 ATOMIC64_DECL_ONE(sym##_386)
14210
14211 ATOMIC64_DECL_ONE(add_386);
14212+ATOMIC64_DECL_ONE(add_unchecked_386);
14213 ATOMIC64_DECL_ONE(sub_386);
14214+ATOMIC64_DECL_ONE(sub_unchecked_386);
14215 ATOMIC64_DECL_ONE(inc_386);
14216+ATOMIC64_DECL_ONE(inc_unchecked_386);
14217 ATOMIC64_DECL_ONE(dec_386);
14218+ATOMIC64_DECL_ONE(dec_unchecked_386);
14219 #endif
14220
14221 #define alternative_atomic64(f, out, in...) \
14222 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14223
14224 ATOMIC64_DECL(read);
14225+ATOMIC64_DECL(read_unchecked);
14226 ATOMIC64_DECL(set);
14227+ATOMIC64_DECL(set_unchecked);
14228 ATOMIC64_DECL(xchg);
14229 ATOMIC64_DECL(add_return);
14230+ATOMIC64_DECL(add_return_unchecked);
14231 ATOMIC64_DECL(sub_return);
14232+ATOMIC64_DECL(sub_return_unchecked);
14233 ATOMIC64_DECL(inc_return);
14234+ATOMIC64_DECL(inc_return_unchecked);
14235 ATOMIC64_DECL(dec_return);
14236+ATOMIC64_DECL(dec_return_unchecked);
14237 ATOMIC64_DECL(dec_if_positive);
14238 ATOMIC64_DECL(inc_not_zero);
14239 ATOMIC64_DECL(add_unless);
14240@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14241 }
14242
14243 /**
14244+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14245+ * @p: pointer to type atomic64_unchecked_t
14246+ * @o: expected value
14247+ * @n: new value
14248+ *
14249+ * Atomically sets @v to @n if it was equal to @o and returns
14250+ * the old value.
14251+ */
14252+
14253+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14254+{
14255+ return cmpxchg64(&v->counter, o, n);
14256+}
14257+
14258+/**
14259 * atomic64_xchg - xchg atomic64 variable
14260 * @v: pointer to type atomic64_t
14261 * @n: value to assign
14262@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14263 }
14264
14265 /**
14266+ * atomic64_set_unchecked - set atomic64 variable
14267+ * @v: pointer to type atomic64_unchecked_t
14268+ * @n: value to assign
14269+ *
14270+ * Atomically sets the value of @v to @n.
14271+ */
14272+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14273+{
14274+ unsigned high = (unsigned)(i >> 32);
14275+ unsigned low = (unsigned)i;
14276+ alternative_atomic64(set, /* no output */,
14277+ "S" (v), "b" (low), "c" (high)
14278+ : "eax", "edx", "memory");
14279+}
14280+
14281+/**
14282 * atomic64_read - read atomic64 variable
14283 * @v: pointer to type atomic64_t
14284 *
14285@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14286 }
14287
14288 /**
14289+ * atomic64_read_unchecked - read atomic64 variable
14290+ * @v: pointer to type atomic64_unchecked_t
14291+ *
14292+ * Atomically reads the value of @v and returns it.
14293+ */
14294+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14295+{
14296+ long long r;
14297+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14298+ return r;
14299+ }
14300+
14301+/**
14302 * atomic64_add_return - add and return
14303 * @i: integer value to add
14304 * @v: pointer to type atomic64_t
14305@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14306 return i;
14307 }
14308
14309+/**
14310+ * atomic64_add_return_unchecked - add and return
14311+ * @i: integer value to add
14312+ * @v: pointer to type atomic64_unchecked_t
14313+ *
14314+ * Atomically adds @i to @v and returns @i + *@v
14315+ */
14316+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14317+{
14318+ alternative_atomic64(add_return_unchecked,
14319+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14320+ ASM_NO_INPUT_CLOBBER("memory"));
14321+ return i;
14322+}
14323+
14324 /*
14325 * Other variants with different arithmetic operators:
14326 */
14327@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14328 return a;
14329 }
14330
14331+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14332+{
14333+ long long a;
14334+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14335+ "S" (v) : "memory", "ecx");
14336+ return a;
14337+}
14338+
14339 static inline long long atomic64_dec_return(atomic64_t *v)
14340 {
14341 long long a;
14342@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14343 }
14344
14345 /**
14346+ * atomic64_add_unchecked - add integer to atomic64 variable
14347+ * @i: integer value to add
14348+ * @v: pointer to type atomic64_unchecked_t
14349+ *
14350+ * Atomically adds @i to @v.
14351+ */
14352+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14353+{
14354+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14355+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14356+ ASM_NO_INPUT_CLOBBER("memory"));
14357+ return i;
14358+}
14359+
14360+/**
14361 * atomic64_sub - subtract the atomic64 variable
14362 * @i: integer value to subtract
14363 * @v: pointer to type atomic64_t
14364diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14365index 0e1cbfc..5623683 100644
14366--- a/arch/x86/include/asm/atomic64_64.h
14367+++ b/arch/x86/include/asm/atomic64_64.h
14368@@ -18,7 +18,19 @@
14369 */
14370 static inline long atomic64_read(const atomic64_t *v)
14371 {
14372- return (*(volatile long *)&(v)->counter);
14373+ return (*(volatile const long *)&(v)->counter);
14374+}
14375+
14376+/**
14377+ * atomic64_read_unchecked - read atomic64 variable
14378+ * @v: pointer of type atomic64_unchecked_t
14379+ *
14380+ * Atomically reads the value of @v.
14381+ * Doesn't imply a read memory barrier.
14382+ */
14383+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14384+{
14385+ return (*(volatile const long *)&(v)->counter);
14386 }
14387
14388 /**
14389@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14390 }
14391
14392 /**
14393+ * atomic64_set_unchecked - set atomic64 variable
14394+ * @v: pointer to type atomic64_unchecked_t
14395+ * @i: required value
14396+ *
14397+ * Atomically sets the value of @v to @i.
14398+ */
14399+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14400+{
14401+ v->counter = i;
14402+}
14403+
14404+/**
14405 * atomic64_add - add integer to atomic64 variable
14406 * @i: integer value to add
14407 * @v: pointer to type atomic64_t
14408@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14409 */
14410 static inline void atomic64_add(long i, atomic64_t *v)
14411 {
14412+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14413+
14414+#ifdef CONFIG_PAX_REFCOUNT
14415+ "jno 0f\n"
14416+ LOCK_PREFIX "subq %1,%0\n"
14417+ "int $4\n0:\n"
14418+ _ASM_EXTABLE(0b, 0b)
14419+#endif
14420+
14421+ : "=m" (v->counter)
14422+ : "er" (i), "m" (v->counter));
14423+}
14424+
14425+/**
14426+ * atomic64_add_unchecked - add integer to atomic64 variable
14427+ * @i: integer value to add
14428+ * @v: pointer to type atomic64_unchecked_t
14429+ *
14430+ * Atomically adds @i to @v.
14431+ */
14432+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14433+{
14434 asm volatile(LOCK_PREFIX "addq %1,%0"
14435 : "=m" (v->counter)
14436 : "er" (i), "m" (v->counter));
14437@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14438 */
14439 static inline void atomic64_sub(long i, atomic64_t *v)
14440 {
14441- asm volatile(LOCK_PREFIX "subq %1,%0"
14442+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14443+
14444+#ifdef CONFIG_PAX_REFCOUNT
14445+ "jno 0f\n"
14446+ LOCK_PREFIX "addq %1,%0\n"
14447+ "int $4\n0:\n"
14448+ _ASM_EXTABLE(0b, 0b)
14449+#endif
14450+
14451+ : "=m" (v->counter)
14452+ : "er" (i), "m" (v->counter));
14453+}
14454+
14455+/**
14456+ * atomic64_sub_unchecked - subtract the atomic64 variable
14457+ * @i: integer value to subtract
14458+ * @v: pointer to type atomic64_unchecked_t
14459+ *
14460+ * Atomically subtracts @i from @v.
14461+ */
14462+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14463+{
14464+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14465 : "=m" (v->counter)
14466 : "er" (i), "m" (v->counter));
14467 }
14468@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14469 {
14470 unsigned char c;
14471
14472- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14473+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14474+
14475+#ifdef CONFIG_PAX_REFCOUNT
14476+ "jno 0f\n"
14477+ LOCK_PREFIX "addq %2,%0\n"
14478+ "int $4\n0:\n"
14479+ _ASM_EXTABLE(0b, 0b)
14480+#endif
14481+
14482+ "sete %1\n"
14483 : "=m" (v->counter), "=qm" (c)
14484 : "er" (i), "m" (v->counter) : "memory");
14485 return c;
14486@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14487 */
14488 static inline void atomic64_inc(atomic64_t *v)
14489 {
14490+ asm volatile(LOCK_PREFIX "incq %0\n"
14491+
14492+#ifdef CONFIG_PAX_REFCOUNT
14493+ "jno 0f\n"
14494+ LOCK_PREFIX "decq %0\n"
14495+ "int $4\n0:\n"
14496+ _ASM_EXTABLE(0b, 0b)
14497+#endif
14498+
14499+ : "=m" (v->counter)
14500+ : "m" (v->counter));
14501+}
14502+
14503+/**
14504+ * atomic64_inc_unchecked - increment atomic64 variable
14505+ * @v: pointer to type atomic64_unchecked_t
14506+ *
14507+ * Atomically increments @v by 1.
14508+ */
14509+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14510+{
14511 asm volatile(LOCK_PREFIX "incq %0"
14512 : "=m" (v->counter)
14513 : "m" (v->counter));
14514@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14515 */
14516 static inline void atomic64_dec(atomic64_t *v)
14517 {
14518- asm volatile(LOCK_PREFIX "decq %0"
14519+ asm volatile(LOCK_PREFIX "decq %0\n"
14520+
14521+#ifdef CONFIG_PAX_REFCOUNT
14522+ "jno 0f\n"
14523+ LOCK_PREFIX "incq %0\n"
14524+ "int $4\n0:\n"
14525+ _ASM_EXTABLE(0b, 0b)
14526+#endif
14527+
14528+ : "=m" (v->counter)
14529+ : "m" (v->counter));
14530+}
14531+
14532+/**
14533+ * atomic64_dec_unchecked - decrement atomic64 variable
14534+ * @v: pointer to type atomic64_t
14535+ *
14536+ * Atomically decrements @v by 1.
14537+ */
14538+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14539+{
14540+ asm volatile(LOCK_PREFIX "decq %0\n"
14541 : "=m" (v->counter)
14542 : "m" (v->counter));
14543 }
14544@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14545 {
14546 unsigned char c;
14547
14548- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14549+ asm volatile(LOCK_PREFIX "decq %0\n"
14550+
14551+#ifdef CONFIG_PAX_REFCOUNT
14552+ "jno 0f\n"
14553+ LOCK_PREFIX "incq %0\n"
14554+ "int $4\n0:\n"
14555+ _ASM_EXTABLE(0b, 0b)
14556+#endif
14557+
14558+ "sete %1\n"
14559 : "=m" (v->counter), "=qm" (c)
14560 : "m" (v->counter) : "memory");
14561 return c != 0;
14562@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14563 {
14564 unsigned char c;
14565
14566- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14567+ asm volatile(LOCK_PREFIX "incq %0\n"
14568+
14569+#ifdef CONFIG_PAX_REFCOUNT
14570+ "jno 0f\n"
14571+ LOCK_PREFIX "decq %0\n"
14572+ "int $4\n0:\n"
14573+ _ASM_EXTABLE(0b, 0b)
14574+#endif
14575+
14576+ "sete %1\n"
14577 : "=m" (v->counter), "=qm" (c)
14578 : "m" (v->counter) : "memory");
14579 return c != 0;
14580@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14581 {
14582 unsigned char c;
14583
14584- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14585+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14586+
14587+#ifdef CONFIG_PAX_REFCOUNT
14588+ "jno 0f\n"
14589+ LOCK_PREFIX "subq %2,%0\n"
14590+ "int $4\n0:\n"
14591+ _ASM_EXTABLE(0b, 0b)
14592+#endif
14593+
14594+ "sets %1\n"
14595 : "=m" (v->counter), "=qm" (c)
14596 : "er" (i), "m" (v->counter) : "memory");
14597 return c;
14598@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14599 */
14600 static inline long atomic64_add_return(long i, atomic64_t *v)
14601 {
14602+ return i + xadd_check_overflow(&v->counter, i);
14603+}
14604+
14605+/**
14606+ * atomic64_add_return_unchecked - add and return
14607+ * @i: integer value to add
14608+ * @v: pointer to type atomic64_unchecked_t
14609+ *
14610+ * Atomically adds @i to @v and returns @i + @v
14611+ */
14612+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14613+{
14614 return i + xadd(&v->counter, i);
14615 }
14616
14617@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14618 }
14619
14620 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14621+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14622+{
14623+ return atomic64_add_return_unchecked(1, v);
14624+}
14625 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14626
14627 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14628@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14629 return cmpxchg(&v->counter, old, new);
14630 }
14631
14632+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14633+{
14634+ return cmpxchg(&v->counter, old, new);
14635+}
14636+
14637 static inline long atomic64_xchg(atomic64_t *v, long new)
14638 {
14639 return xchg(&v->counter, new);
14640@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14641 */
14642 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14643 {
14644- long c, old;
14645+ long c, old, new;
14646 c = atomic64_read(v);
14647 for (;;) {
14648- if (unlikely(c == (u)))
14649+ if (unlikely(c == u))
14650 break;
14651- old = atomic64_cmpxchg((v), c, c + (a));
14652+
14653+ asm volatile("add %2,%0\n"
14654+
14655+#ifdef CONFIG_PAX_REFCOUNT
14656+ "jno 0f\n"
14657+ "sub %2,%0\n"
14658+ "int $4\n0:\n"
14659+ _ASM_EXTABLE(0b, 0b)
14660+#endif
14661+
14662+ : "=r" (new)
14663+ : "0" (c), "ir" (a));
14664+
14665+ old = atomic64_cmpxchg(v, c, new);
14666 if (likely(old == c))
14667 break;
14668 c = old;
14669 }
14670- return c != (u);
14671+ return c != u;
14672 }
14673
14674 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14675diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14676index 6dfd019..28e188d 100644
14677--- a/arch/x86/include/asm/bitops.h
14678+++ b/arch/x86/include/asm/bitops.h
14679@@ -40,7 +40,7 @@
14680 * a mask operation on a byte.
14681 */
14682 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14683-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14684+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14685 #define CONST_MASK(nr) (1 << ((nr) & 7))
14686
14687 /**
14688@@ -486,7 +486,7 @@ static inline int fls(int x)
14689 * at position 64.
14690 */
14691 #ifdef CONFIG_X86_64
14692-static __always_inline int fls64(__u64 x)
14693+static __always_inline long fls64(__u64 x)
14694 {
14695 int bitpos = -1;
14696 /*
14697diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14698index 4fa687a..60f2d39 100644
14699--- a/arch/x86/include/asm/boot.h
14700+++ b/arch/x86/include/asm/boot.h
14701@@ -6,10 +6,15 @@
14702 #include <uapi/asm/boot.h>
14703
14704 /* Physical address where kernel should be loaded. */
14705-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14706+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14707 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14708 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14709
14710+#ifndef __ASSEMBLY__
14711+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14712+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14713+#endif
14714+
14715 /* Minimum kernel alignment, as a power of two */
14716 #ifdef CONFIG_X86_64
14717 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14718diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14719index 48f99f1..d78ebf9 100644
14720--- a/arch/x86/include/asm/cache.h
14721+++ b/arch/x86/include/asm/cache.h
14722@@ -5,12 +5,13 @@
14723
14724 /* L1 cache line size */
14725 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14726-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14727+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14728
14729 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14730+#define __read_only __attribute__((__section__(".data..read_only")))
14731
14732 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14733-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14734+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14735
14736 #ifdef CONFIG_X86_VSMP
14737 #ifdef CONFIG_SMP
14738diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14739index 9863ee3..4a1f8e1 100644
14740--- a/arch/x86/include/asm/cacheflush.h
14741+++ b/arch/x86/include/asm/cacheflush.h
14742@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14743 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14744
14745 if (pg_flags == _PGMT_DEFAULT)
14746- return -1;
14747+ return ~0UL;
14748 else if (pg_flags == _PGMT_WC)
14749 return _PAGE_CACHE_WC;
14750 else if (pg_flags == _PGMT_UC_MINUS)
14751diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14752index 46fc474..b02b0f9 100644
14753--- a/arch/x86/include/asm/checksum_32.h
14754+++ b/arch/x86/include/asm/checksum_32.h
14755@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14756 int len, __wsum sum,
14757 int *src_err_ptr, int *dst_err_ptr);
14758
14759+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14760+ int len, __wsum sum,
14761+ int *src_err_ptr, int *dst_err_ptr);
14762+
14763+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14764+ int len, __wsum sum,
14765+ int *src_err_ptr, int *dst_err_ptr);
14766+
14767 /*
14768 * Note: when you get a NULL pointer exception here this means someone
14769 * passed in an incorrect kernel address to one of these functions.
14770@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14771 int *err_ptr)
14772 {
14773 might_sleep();
14774- return csum_partial_copy_generic((__force void *)src, dst,
14775+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
14776 len, sum, err_ptr, NULL);
14777 }
14778
14779@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14780 {
14781 might_sleep();
14782 if (access_ok(VERIFY_WRITE, dst, len))
14783- return csum_partial_copy_generic(src, (__force void *)dst,
14784+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
14785 len, sum, NULL, err_ptr);
14786
14787 if (len)
14788diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14789index d47786a..ce1b05d 100644
14790--- a/arch/x86/include/asm/cmpxchg.h
14791+++ b/arch/x86/include/asm/cmpxchg.h
14792@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14793 __compiletime_error("Bad argument size for cmpxchg");
14794 extern void __xadd_wrong_size(void)
14795 __compiletime_error("Bad argument size for xadd");
14796+extern void __xadd_check_overflow_wrong_size(void)
14797+ __compiletime_error("Bad argument size for xadd_check_overflow");
14798 extern void __add_wrong_size(void)
14799 __compiletime_error("Bad argument size for add");
14800+extern void __add_check_overflow_wrong_size(void)
14801+ __compiletime_error("Bad argument size for add_check_overflow");
14802
14803 /*
14804 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14805@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14806 __ret; \
14807 })
14808
14809+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14810+ ({ \
14811+ __typeof__ (*(ptr)) __ret = (arg); \
14812+ switch (sizeof(*(ptr))) { \
14813+ case __X86_CASE_L: \
14814+ asm volatile (lock #op "l %0, %1\n" \
14815+ "jno 0f\n" \
14816+ "mov %0,%1\n" \
14817+ "int $4\n0:\n" \
14818+ _ASM_EXTABLE(0b, 0b) \
14819+ : "+r" (__ret), "+m" (*(ptr)) \
14820+ : : "memory", "cc"); \
14821+ break; \
14822+ case __X86_CASE_Q: \
14823+ asm volatile (lock #op "q %q0, %1\n" \
14824+ "jno 0f\n" \
14825+ "mov %0,%1\n" \
14826+ "int $4\n0:\n" \
14827+ _ASM_EXTABLE(0b, 0b) \
14828+ : "+r" (__ret), "+m" (*(ptr)) \
14829+ : : "memory", "cc"); \
14830+ break; \
14831+ default: \
14832+ __ ## op ## _check_overflow_wrong_size(); \
14833+ } \
14834+ __ret; \
14835+ })
14836+
14837 /*
14838 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14839 * Since this is generally used to protect other memory information, we
14840@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14841 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14842 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14843
14844+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14845+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14846+
14847 #define __add(ptr, inc, lock) \
14848 ({ \
14849 __typeof__ (*(ptr)) __ret = (inc); \
14850diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14851index 59c6c40..5e0b22c 100644
14852--- a/arch/x86/include/asm/compat.h
14853+++ b/arch/x86/include/asm/compat.h
14854@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14855 typedef u32 compat_uint_t;
14856 typedef u32 compat_ulong_t;
14857 typedef u64 __attribute__((aligned(4))) compat_u64;
14858-typedef u32 compat_uptr_t;
14859+typedef u32 __user compat_uptr_t;
14860
14861 struct compat_timespec {
14862 compat_time_t tv_sec;
14863diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14864index 47538a6..44902d1 100644
14865--- a/arch/x86/include/asm/cpufeature.h
14866+++ b/arch/x86/include/asm/cpufeature.h
14867@@ -203,7 +203,7 @@
14868 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14869 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14870 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14871-
14872+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14873
14874 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14875 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14876@@ -211,7 +211,7 @@
14877 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14878 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14879 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14880-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14881+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14882 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14883 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14884 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14885@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14886 #undef cpu_has_centaur_mcr
14887 #define cpu_has_centaur_mcr 0
14888
14889+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14890 #endif /* CONFIG_X86_64 */
14891
14892 #if __GNUC__ >= 4
14893@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14894
14895 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14896 t_warn:
14897- warn_pre_alternatives();
14898+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14899+ warn_pre_alternatives();
14900 return false;
14901 #endif
14902 #else /* GCC_VERSION >= 40500 */
14903@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14904 ".section .discard,\"aw\",@progbits\n"
14905 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14906 ".previous\n"
14907- ".section .altinstr_replacement,\"ax\"\n"
14908+ ".section .altinstr_replacement,\"a\"\n"
14909 "3: movb $1,%0\n"
14910 "4:\n"
14911 ".previous\n"
14912@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14913 " .byte 2b - 1b\n" /* src len */
14914 " .byte 4f - 3f\n" /* repl len */
14915 ".previous\n"
14916- ".section .altinstr_replacement,\"ax\"\n"
14917+ ".section .altinstr_replacement,\"a\"\n"
14918 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14919 "4:\n"
14920 ".previous\n"
14921@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14922 ".section .discard,\"aw\",@progbits\n"
14923 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14924 ".previous\n"
14925- ".section .altinstr_replacement,\"ax\"\n"
14926+ ".section .altinstr_replacement,\"a\"\n"
14927 "3: movb $0,%0\n"
14928 "4:\n"
14929 ".previous\n"
14930@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14931 ".section .discard,\"aw\",@progbits\n"
14932 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14933 ".previous\n"
14934- ".section .altinstr_replacement,\"ax\"\n"
14935+ ".section .altinstr_replacement,\"a\"\n"
14936 "5: movb $1,%0\n"
14937 "6:\n"
14938 ".previous\n"
14939diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14940index b90e5df..b462c91 100644
14941--- a/arch/x86/include/asm/desc.h
14942+++ b/arch/x86/include/asm/desc.h
14943@@ -4,6 +4,7 @@
14944 #include <asm/desc_defs.h>
14945 #include <asm/ldt.h>
14946 #include <asm/mmu.h>
14947+#include <asm/pgtable.h>
14948
14949 #include <linux/smp.h>
14950 #include <linux/percpu.h>
14951@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14952
14953 desc->type = (info->read_exec_only ^ 1) << 1;
14954 desc->type |= info->contents << 2;
14955+ desc->type |= info->seg_not_present ^ 1;
14956
14957 desc->s = 1;
14958 desc->dpl = 0x3;
14959@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14960 }
14961
14962 extern struct desc_ptr idt_descr;
14963-extern gate_desc idt_table[];
14964-extern struct desc_ptr debug_idt_descr;
14965-extern gate_desc debug_idt_table[];
14966-
14967-struct gdt_page {
14968- struct desc_struct gdt[GDT_ENTRIES];
14969-} __attribute__((aligned(PAGE_SIZE)));
14970-
14971-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14972+extern gate_desc idt_table[IDT_ENTRIES];
14973+extern const struct desc_ptr debug_idt_descr;
14974+extern gate_desc debug_idt_table[IDT_ENTRIES];
14975
14976+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14977 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14978 {
14979- return per_cpu(gdt_page, cpu).gdt;
14980+ return cpu_gdt_table[cpu];
14981 }
14982
14983 #ifdef CONFIG_X86_64
14984@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14985 unsigned long base, unsigned dpl, unsigned flags,
14986 unsigned short seg)
14987 {
14988- gate->a = (seg << 16) | (base & 0xffff);
14989- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
14990+ gate->gate.offset_low = base;
14991+ gate->gate.seg = seg;
14992+ gate->gate.reserved = 0;
14993+ gate->gate.type = type;
14994+ gate->gate.s = 0;
14995+ gate->gate.dpl = dpl;
14996+ gate->gate.p = 1;
14997+ gate->gate.offset_high = base >> 16;
14998 }
14999
15000 #endif
15001@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15002
15003 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15004 {
15005+ pax_open_kernel();
15006 memcpy(&idt[entry], gate, sizeof(*gate));
15007+ pax_close_kernel();
15008 }
15009
15010 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15011 {
15012+ pax_open_kernel();
15013 memcpy(&ldt[entry], desc, 8);
15014+ pax_close_kernel();
15015 }
15016
15017 static inline void
15018@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15019 default: size = sizeof(*gdt); break;
15020 }
15021
15022+ pax_open_kernel();
15023 memcpy(&gdt[entry], desc, size);
15024+ pax_close_kernel();
15025 }
15026
15027 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15028@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15029
15030 static inline void native_load_tr_desc(void)
15031 {
15032+ pax_open_kernel();
15033 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15034+ pax_close_kernel();
15035 }
15036
15037 static inline void native_load_gdt(const struct desc_ptr *dtr)
15038@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15039 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15040 unsigned int i;
15041
15042+ pax_open_kernel();
15043 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15044 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15045+ pax_close_kernel();
15046 }
15047
15048 #define _LDT_empty(info) \
15049@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15050 preempt_enable();
15051 }
15052
15053-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15054+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15055 {
15056 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15057 }
15058@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15059 }
15060
15061 #ifdef CONFIG_X86_64
15062-static inline void set_nmi_gate(int gate, void *addr)
15063+static inline void set_nmi_gate(int gate, const void *addr)
15064 {
15065 gate_desc s;
15066
15067@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15068 #endif
15069
15070 #ifdef CONFIG_TRACING
15071-extern struct desc_ptr trace_idt_descr;
15072-extern gate_desc trace_idt_table[];
15073+extern const struct desc_ptr trace_idt_descr;
15074+extern gate_desc trace_idt_table[IDT_ENTRIES];
15075 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15076 {
15077 write_idt_entry(trace_idt_table, entry, gate);
15078@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15079 }
15080 #endif
15081
15082-static inline void _set_gate(int gate, unsigned type, void *addr,
15083+static inline void _set_gate(int gate, unsigned type, const void *addr,
15084 unsigned dpl, unsigned ist, unsigned seg)
15085 {
15086 gate_desc s;
15087@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15088 * Pentium F0 0F bugfix can have resulted in the mapped
15089 * IDT being write-protected.
15090 */
15091-static inline void set_intr_gate(unsigned int n, void *addr)
15092+static inline void set_intr_gate(unsigned int n, const void *addr)
15093 {
15094 BUG_ON((unsigned)n > 0xFF);
15095 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15096@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15097 /*
15098 * This routine sets up an interrupt gate at directory privilege level 3.
15099 */
15100-static inline void set_system_intr_gate(unsigned int n, void *addr)
15101+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15102 {
15103 BUG_ON((unsigned)n > 0xFF);
15104 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15105 }
15106
15107-static inline void set_system_trap_gate(unsigned int n, void *addr)
15108+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15109 {
15110 BUG_ON((unsigned)n > 0xFF);
15111 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15112 }
15113
15114-static inline void set_trap_gate(unsigned int n, void *addr)
15115+static inline void set_trap_gate(unsigned int n, const void *addr)
15116 {
15117 BUG_ON((unsigned)n > 0xFF);
15118 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15119@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15120 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15121 {
15122 BUG_ON((unsigned)n > 0xFF);
15123- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15124+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15125 }
15126
15127-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15128+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15129 {
15130 BUG_ON((unsigned)n > 0xFF);
15131 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15132 }
15133
15134-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15135+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15136 {
15137 BUG_ON((unsigned)n > 0xFF);
15138 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15139@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15140 else
15141 load_idt((const struct desc_ptr *)&idt_descr);
15142 }
15143+
15144+#ifdef CONFIG_X86_32
15145+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15146+{
15147+ struct desc_struct d;
15148+
15149+ if (likely(limit))
15150+ limit = (limit - 1UL) >> PAGE_SHIFT;
15151+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15152+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15153+}
15154+#endif
15155+
15156 #endif /* _ASM_X86_DESC_H */
15157diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15158index 278441f..b95a174 100644
15159--- a/arch/x86/include/asm/desc_defs.h
15160+++ b/arch/x86/include/asm/desc_defs.h
15161@@ -31,6 +31,12 @@ struct desc_struct {
15162 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15163 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15164 };
15165+ struct {
15166+ u16 offset_low;
15167+ u16 seg;
15168+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15169+ unsigned offset_high: 16;
15170+ } gate;
15171 };
15172 } __attribute__((packed));
15173
15174diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15175index ced283a..ffe04cc 100644
15176--- a/arch/x86/include/asm/div64.h
15177+++ b/arch/x86/include/asm/div64.h
15178@@ -39,7 +39,7 @@
15179 __mod; \
15180 })
15181
15182-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15183+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15184 {
15185 union {
15186 u64 v64;
15187diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15188index 9c999c1..3860cb8 100644
15189--- a/arch/x86/include/asm/elf.h
15190+++ b/arch/x86/include/asm/elf.h
15191@@ -243,7 +243,25 @@ extern int force_personality32;
15192 the loader. We need to make sure that it is out of the way of the program
15193 that it will "exec", and that there is sufficient room for the brk. */
15194
15195+#ifdef CONFIG_PAX_SEGMEXEC
15196+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15197+#else
15198 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15199+#endif
15200+
15201+#ifdef CONFIG_PAX_ASLR
15202+#ifdef CONFIG_X86_32
15203+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15204+
15205+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15206+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15207+#else
15208+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15209+
15210+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15211+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15212+#endif
15213+#endif
15214
15215 /* This yields a mask that user programs can use to figure out what
15216 instruction set this CPU supports. This could be done in user space,
15217@@ -296,16 +314,12 @@ do { \
15218
15219 #define ARCH_DLINFO \
15220 do { \
15221- if (vdso_enabled) \
15222- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15223- (unsigned long)current->mm->context.vdso); \
15224+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15225 } while (0)
15226
15227 #define ARCH_DLINFO_X32 \
15228 do { \
15229- if (vdso_enabled) \
15230- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15231- (unsigned long)current->mm->context.vdso); \
15232+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15233 } while (0)
15234
15235 #define AT_SYSINFO 32
15236@@ -320,7 +334,7 @@ else \
15237
15238 #endif /* !CONFIG_X86_32 */
15239
15240-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15241+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15242
15243 #define VDSO_ENTRY \
15244 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15245@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15246 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15247 #define compat_arch_setup_additional_pages syscall32_setup_pages
15248
15249-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15250-#define arch_randomize_brk arch_randomize_brk
15251-
15252 /*
15253 * True on X86_32 or when emulating IA32 on X86_64
15254 */
15255diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15256index 77a99ac..39ff7f5 100644
15257--- a/arch/x86/include/asm/emergency-restart.h
15258+++ b/arch/x86/include/asm/emergency-restart.h
15259@@ -1,6 +1,6 @@
15260 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15261 #define _ASM_X86_EMERGENCY_RESTART_H
15262
15263-extern void machine_emergency_restart(void);
15264+extern void machine_emergency_restart(void) __noreturn;
15265
15266 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15267diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15268index 4d0bda7..221da4d 100644
15269--- a/arch/x86/include/asm/fpu-internal.h
15270+++ b/arch/x86/include/asm/fpu-internal.h
15271@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15272 #define user_insn(insn, output, input...) \
15273 ({ \
15274 int err; \
15275+ pax_open_userland(); \
15276 asm volatile(ASM_STAC "\n" \
15277- "1:" #insn "\n\t" \
15278+ "1:" \
15279+ __copyuser_seg \
15280+ #insn "\n\t" \
15281 "2: " ASM_CLAC "\n" \
15282 ".section .fixup,\"ax\"\n" \
15283 "3: movl $-1,%[err]\n" \
15284@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15285 _ASM_EXTABLE(1b, 3b) \
15286 : [err] "=r" (err), output \
15287 : "0"(0), input); \
15288+ pax_close_userland(); \
15289 err; \
15290 })
15291
15292@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15293 "emms\n\t" /* clear stack tags */
15294 "fildl %P[addr]", /* set F?P to defined value */
15295 X86_FEATURE_FXSAVE_LEAK,
15296- [addr] "m" (tsk->thread.fpu.has_fpu));
15297+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15298
15299 return fpu_restore_checking(&tsk->thread.fpu);
15300 }
15301diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15302index be27ba1..04a8801 100644
15303--- a/arch/x86/include/asm/futex.h
15304+++ b/arch/x86/include/asm/futex.h
15305@@ -12,6 +12,7 @@
15306 #include <asm/smap.h>
15307
15308 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15309+ typecheck(u32 __user *, uaddr); \
15310 asm volatile("\t" ASM_STAC "\n" \
15311 "1:\t" insn "\n" \
15312 "2:\t" ASM_CLAC "\n" \
15313@@ -20,15 +21,16 @@
15314 "\tjmp\t2b\n" \
15315 "\t.previous\n" \
15316 _ASM_EXTABLE(1b, 3b) \
15317- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15318+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15319 : "i" (-EFAULT), "0" (oparg), "1" (0))
15320
15321 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15322+ typecheck(u32 __user *, uaddr); \
15323 asm volatile("\t" ASM_STAC "\n" \
15324 "1:\tmovl %2, %0\n" \
15325 "\tmovl\t%0, %3\n" \
15326 "\t" insn "\n" \
15327- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15328+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15329 "\tjnz\t1b\n" \
15330 "3:\t" ASM_CLAC "\n" \
15331 "\t.section .fixup,\"ax\"\n" \
15332@@ -38,7 +40,7 @@
15333 _ASM_EXTABLE(1b, 4b) \
15334 _ASM_EXTABLE(2b, 4b) \
15335 : "=&a" (oldval), "=&r" (ret), \
15336- "+m" (*uaddr), "=&r" (tem) \
15337+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15338 : "r" (oparg), "i" (-EFAULT), "1" (0))
15339
15340 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15341@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15342
15343 pagefault_disable();
15344
15345+ pax_open_userland();
15346 switch (op) {
15347 case FUTEX_OP_SET:
15348- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15349+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15350 break;
15351 case FUTEX_OP_ADD:
15352- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15353+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15354 uaddr, oparg);
15355 break;
15356 case FUTEX_OP_OR:
15357@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15358 default:
15359 ret = -ENOSYS;
15360 }
15361+ pax_close_userland();
15362
15363 pagefault_enable();
15364
15365@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15366 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15367 return -EFAULT;
15368
15369+ pax_open_userland();
15370 asm volatile("\t" ASM_STAC "\n"
15371- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15372+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15373 "2:\t" ASM_CLAC "\n"
15374 "\t.section .fixup, \"ax\"\n"
15375 "3:\tmov %3, %0\n"
15376 "\tjmp 2b\n"
15377 "\t.previous\n"
15378 _ASM_EXTABLE(1b, 3b)
15379- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15380+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15381 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15382 : "memory"
15383 );
15384+ pax_close_userland();
15385
15386 *uval = oldval;
15387 return ret;
15388diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15389index e4ac559..c1c0c87 100644
15390--- a/arch/x86/include/asm/hw_irq.h
15391+++ b/arch/x86/include/asm/hw_irq.h
15392@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15393 extern void enable_IO_APIC(void);
15394
15395 /* Statistics */
15396-extern atomic_t irq_err_count;
15397-extern atomic_t irq_mis_count;
15398+extern atomic_unchecked_t irq_err_count;
15399+extern atomic_unchecked_t irq_mis_count;
15400
15401 /* EISA */
15402 extern void eisa_set_level_irq(unsigned int irq);
15403diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15404index a203659..9889f1c 100644
15405--- a/arch/x86/include/asm/i8259.h
15406+++ b/arch/x86/include/asm/i8259.h
15407@@ -62,7 +62,7 @@ struct legacy_pic {
15408 void (*init)(int auto_eoi);
15409 int (*irq_pending)(unsigned int irq);
15410 void (*make_irq)(unsigned int irq);
15411-};
15412+} __do_const;
15413
15414 extern struct legacy_pic *legacy_pic;
15415 extern struct legacy_pic null_legacy_pic;
15416diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15417index 34f69cb..6d95446 100644
15418--- a/arch/x86/include/asm/io.h
15419+++ b/arch/x86/include/asm/io.h
15420@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15421 "m" (*(volatile type __force *)addr) barrier); }
15422
15423 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15424-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15425-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15426+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15427+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15428
15429 build_mmio_read(__readb, "b", unsigned char, "=q", )
15430-build_mmio_read(__readw, "w", unsigned short, "=r", )
15431-build_mmio_read(__readl, "l", unsigned int, "=r", )
15432+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15433+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15434
15435 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15436 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15437@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15438 return ioremap_nocache(offset, size);
15439 }
15440
15441-extern void iounmap(volatile void __iomem *addr);
15442+extern void iounmap(const volatile void __iomem *addr);
15443
15444 extern void set_iounmap_nonlazy(void);
15445
15446@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15447
15448 #include <linux/vmalloc.h>
15449
15450+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15451+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15452+{
15453+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15454+}
15455+
15456+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15457+{
15458+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15459+}
15460+
15461 /*
15462 * Convert a virtual cached pointer to an uncached pointer
15463 */
15464diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15465index bba3cf8..06bc8da 100644
15466--- a/arch/x86/include/asm/irqflags.h
15467+++ b/arch/x86/include/asm/irqflags.h
15468@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15469 sti; \
15470 sysexit
15471
15472+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15473+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15474+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15475+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15476+
15477 #else
15478 #define INTERRUPT_RETURN iret
15479 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15480diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15481index 5a6d287..f815789 100644
15482--- a/arch/x86/include/asm/kprobes.h
15483+++ b/arch/x86/include/asm/kprobes.h
15484@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15485 #define RELATIVEJUMP_SIZE 5
15486 #define RELATIVECALL_OPCODE 0xe8
15487 #define RELATIVE_ADDR_SIZE 4
15488-#define MAX_STACK_SIZE 64
15489-#define MIN_STACK_SIZE(ADDR) \
15490- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15491- THREAD_SIZE - (unsigned long)(ADDR))) \
15492- ? (MAX_STACK_SIZE) \
15493- : (((unsigned long)current_thread_info()) + \
15494- THREAD_SIZE - (unsigned long)(ADDR)))
15495+#define MAX_STACK_SIZE 64UL
15496+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15497
15498 #define flush_insn_slot(p) do { } while (0)
15499
15500diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15501index 2d89e39..baee879 100644
15502--- a/arch/x86/include/asm/local.h
15503+++ b/arch/x86/include/asm/local.h
15504@@ -10,33 +10,97 @@ typedef struct {
15505 atomic_long_t a;
15506 } local_t;
15507
15508+typedef struct {
15509+ atomic_long_unchecked_t a;
15510+} local_unchecked_t;
15511+
15512 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15513
15514 #define local_read(l) atomic_long_read(&(l)->a)
15515+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15516 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15517+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15518
15519 static inline void local_inc(local_t *l)
15520 {
15521- asm volatile(_ASM_INC "%0"
15522+ asm volatile(_ASM_INC "%0\n"
15523+
15524+#ifdef CONFIG_PAX_REFCOUNT
15525+ "jno 0f\n"
15526+ _ASM_DEC "%0\n"
15527+ "int $4\n0:\n"
15528+ _ASM_EXTABLE(0b, 0b)
15529+#endif
15530+
15531+ : "+m" (l->a.counter));
15532+}
15533+
15534+static inline void local_inc_unchecked(local_unchecked_t *l)
15535+{
15536+ asm volatile(_ASM_INC "%0\n"
15537 : "+m" (l->a.counter));
15538 }
15539
15540 static inline void local_dec(local_t *l)
15541 {
15542- asm volatile(_ASM_DEC "%0"
15543+ asm volatile(_ASM_DEC "%0\n"
15544+
15545+#ifdef CONFIG_PAX_REFCOUNT
15546+ "jno 0f\n"
15547+ _ASM_INC "%0\n"
15548+ "int $4\n0:\n"
15549+ _ASM_EXTABLE(0b, 0b)
15550+#endif
15551+
15552+ : "+m" (l->a.counter));
15553+}
15554+
15555+static inline void local_dec_unchecked(local_unchecked_t *l)
15556+{
15557+ asm volatile(_ASM_DEC "%0\n"
15558 : "+m" (l->a.counter));
15559 }
15560
15561 static inline void local_add(long i, local_t *l)
15562 {
15563- asm volatile(_ASM_ADD "%1,%0"
15564+ asm volatile(_ASM_ADD "%1,%0\n"
15565+
15566+#ifdef CONFIG_PAX_REFCOUNT
15567+ "jno 0f\n"
15568+ _ASM_SUB "%1,%0\n"
15569+ "int $4\n0:\n"
15570+ _ASM_EXTABLE(0b, 0b)
15571+#endif
15572+
15573+ : "+m" (l->a.counter)
15574+ : "ir" (i));
15575+}
15576+
15577+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15578+{
15579+ asm volatile(_ASM_ADD "%1,%0\n"
15580 : "+m" (l->a.counter)
15581 : "ir" (i));
15582 }
15583
15584 static inline void local_sub(long i, local_t *l)
15585 {
15586- asm volatile(_ASM_SUB "%1,%0"
15587+ asm volatile(_ASM_SUB "%1,%0\n"
15588+
15589+#ifdef CONFIG_PAX_REFCOUNT
15590+ "jno 0f\n"
15591+ _ASM_ADD "%1,%0\n"
15592+ "int $4\n0:\n"
15593+ _ASM_EXTABLE(0b, 0b)
15594+#endif
15595+
15596+ : "+m" (l->a.counter)
15597+ : "ir" (i));
15598+}
15599+
15600+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15601+{
15602+ asm volatile(_ASM_SUB "%1,%0\n"
15603 : "+m" (l->a.counter)
15604 : "ir" (i));
15605 }
15606@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15607 {
15608 unsigned char c;
15609
15610- asm volatile(_ASM_SUB "%2,%0; sete %1"
15611+ asm volatile(_ASM_SUB "%2,%0\n"
15612+
15613+#ifdef CONFIG_PAX_REFCOUNT
15614+ "jno 0f\n"
15615+ _ASM_ADD "%2,%0\n"
15616+ "int $4\n0:\n"
15617+ _ASM_EXTABLE(0b, 0b)
15618+#endif
15619+
15620+ "sete %1\n"
15621 : "+m" (l->a.counter), "=qm" (c)
15622 : "ir" (i) : "memory");
15623 return c;
15624@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15625 {
15626 unsigned char c;
15627
15628- asm volatile(_ASM_DEC "%0; sete %1"
15629+ asm volatile(_ASM_DEC "%0\n"
15630+
15631+#ifdef CONFIG_PAX_REFCOUNT
15632+ "jno 0f\n"
15633+ _ASM_INC "%0\n"
15634+ "int $4\n0:\n"
15635+ _ASM_EXTABLE(0b, 0b)
15636+#endif
15637+
15638+ "sete %1\n"
15639 : "+m" (l->a.counter), "=qm" (c)
15640 : : "memory");
15641 return c != 0;
15642@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15643 {
15644 unsigned char c;
15645
15646- asm volatile(_ASM_INC "%0; sete %1"
15647+ asm volatile(_ASM_INC "%0\n"
15648+
15649+#ifdef CONFIG_PAX_REFCOUNT
15650+ "jno 0f\n"
15651+ _ASM_DEC "%0\n"
15652+ "int $4\n0:\n"
15653+ _ASM_EXTABLE(0b, 0b)
15654+#endif
15655+
15656+ "sete %1\n"
15657 : "+m" (l->a.counter), "=qm" (c)
15658 : : "memory");
15659 return c != 0;
15660@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15661 {
15662 unsigned char c;
15663
15664- asm volatile(_ASM_ADD "%2,%0; sets %1"
15665+ asm volatile(_ASM_ADD "%2,%0\n"
15666+
15667+#ifdef CONFIG_PAX_REFCOUNT
15668+ "jno 0f\n"
15669+ _ASM_SUB "%2,%0\n"
15670+ "int $4\n0:\n"
15671+ _ASM_EXTABLE(0b, 0b)
15672+#endif
15673+
15674+ "sets %1\n"
15675 : "+m" (l->a.counter), "=qm" (c)
15676 : "ir" (i) : "memory");
15677 return c;
15678@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15679 static inline long local_add_return(long i, local_t *l)
15680 {
15681 long __i = i;
15682+ asm volatile(_ASM_XADD "%0, %1\n"
15683+
15684+#ifdef CONFIG_PAX_REFCOUNT
15685+ "jno 0f\n"
15686+ _ASM_MOV "%0,%1\n"
15687+ "int $4\n0:\n"
15688+ _ASM_EXTABLE(0b, 0b)
15689+#endif
15690+
15691+ : "+r" (i), "+m" (l->a.counter)
15692+ : : "memory");
15693+ return i + __i;
15694+}
15695+
15696+/**
15697+ * local_add_return_unchecked - add and return
15698+ * @i: integer value to add
15699+ * @l: pointer to type local_unchecked_t
15700+ *
15701+ * Atomically adds @i to @l and returns @i + @l
15702+ */
15703+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15704+{
15705+ long __i = i;
15706 asm volatile(_ASM_XADD "%0, %1;"
15707 : "+r" (i), "+m" (l->a.counter)
15708 : : "memory");
15709@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15710
15711 #define local_cmpxchg(l, o, n) \
15712 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15713+#define local_cmpxchg_unchecked(l, o, n) \
15714+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15715 /* Always has a lock prefix */
15716 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15717
15718diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15719new file mode 100644
15720index 0000000..2bfd3ba
15721--- /dev/null
15722+++ b/arch/x86/include/asm/mman.h
15723@@ -0,0 +1,15 @@
15724+#ifndef _X86_MMAN_H
15725+#define _X86_MMAN_H
15726+
15727+#include <uapi/asm/mman.h>
15728+
15729+#ifdef __KERNEL__
15730+#ifndef __ASSEMBLY__
15731+#ifdef CONFIG_X86_32
15732+#define arch_mmap_check i386_mmap_check
15733+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15734+#endif
15735+#endif
15736+#endif
15737+
15738+#endif /* X86_MMAN_H */
15739diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15740index 5f55e69..e20bfb1 100644
15741--- a/arch/x86/include/asm/mmu.h
15742+++ b/arch/x86/include/asm/mmu.h
15743@@ -9,7 +9,7 @@
15744 * we put the segment information here.
15745 */
15746 typedef struct {
15747- void *ldt;
15748+ struct desc_struct *ldt;
15749 int size;
15750
15751 #ifdef CONFIG_X86_64
15752@@ -18,7 +18,19 @@ typedef struct {
15753 #endif
15754
15755 struct mutex lock;
15756- void *vdso;
15757+ unsigned long vdso;
15758+
15759+#ifdef CONFIG_X86_32
15760+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15761+ unsigned long user_cs_base;
15762+ unsigned long user_cs_limit;
15763+
15764+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15765+ cpumask_t cpu_user_cs_mask;
15766+#endif
15767+
15768+#endif
15769+#endif
15770 } mm_context_t;
15771
15772 #ifdef CONFIG_SMP
15773diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15774index cdbf367..ce8f82b 100644
15775--- a/arch/x86/include/asm/mmu_context.h
15776+++ b/arch/x86/include/asm/mmu_context.h
15777@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15778
15779 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15780 {
15781+
15782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15783+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15784+ unsigned int i;
15785+ pgd_t *pgd;
15786+
15787+ pax_open_kernel();
15788+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15789+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15790+ set_pgd_batched(pgd+i, native_make_pgd(0));
15791+ pax_close_kernel();
15792+ }
15793+#endif
15794+
15795 #ifdef CONFIG_SMP
15796 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15797 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15798@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15799 struct task_struct *tsk)
15800 {
15801 unsigned cpu = smp_processor_id();
15802+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15803+ int tlbstate = TLBSTATE_OK;
15804+#endif
15805
15806 if (likely(prev != next)) {
15807 #ifdef CONFIG_SMP
15808+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15809+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15810+#endif
15811 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15812 this_cpu_write(cpu_tlbstate.active_mm, next);
15813 #endif
15814 cpumask_set_cpu(cpu, mm_cpumask(next));
15815
15816 /* Re-load page tables */
15817+#ifdef CONFIG_PAX_PER_CPU_PGD
15818+ pax_open_kernel();
15819+
15820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15821+ if (static_cpu_has(X86_FEATURE_PCID))
15822+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15823+ else
15824+#endif
15825+
15826+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15827+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15828+ pax_close_kernel();
15829+ 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));
15830+
15831+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15832+ if (static_cpu_has(X86_FEATURE_PCID)) {
15833+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15834+ u64 descriptor[2];
15835+ descriptor[0] = PCID_USER;
15836+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15837+ } else {
15838+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15839+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15840+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15841+ else
15842+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15843+ }
15844+ } else
15845+#endif
15846+
15847+ load_cr3(get_cpu_pgd(cpu, kernel));
15848+#else
15849 load_cr3(next->pgd);
15850+#endif
15851
15852 /* stop flush ipis for the previous mm */
15853 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15854@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15855 */
15856 if (unlikely(prev->context.ldt != next->context.ldt))
15857 load_LDT_nolock(&next->context);
15858- }
15859+
15860+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15861+ if (!(__supported_pte_mask & _PAGE_NX)) {
15862+ smp_mb__before_clear_bit();
15863+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15864+ smp_mb__after_clear_bit();
15865+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15866+ }
15867+#endif
15868+
15869+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15870+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15871+ prev->context.user_cs_limit != next->context.user_cs_limit))
15872+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15873 #ifdef CONFIG_SMP
15874+ else if (unlikely(tlbstate != TLBSTATE_OK))
15875+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15876+#endif
15877+#endif
15878+
15879+ }
15880 else {
15881+
15882+#ifdef CONFIG_PAX_PER_CPU_PGD
15883+ pax_open_kernel();
15884+
15885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15886+ if (static_cpu_has(X86_FEATURE_PCID))
15887+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15888+ else
15889+#endif
15890+
15891+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15892+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15893+ pax_close_kernel();
15894+ 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));
15895+
15896+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15897+ if (static_cpu_has(X86_FEATURE_PCID)) {
15898+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15899+ u64 descriptor[2];
15900+ descriptor[0] = PCID_USER;
15901+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15902+ } else {
15903+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15904+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15905+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15906+ else
15907+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15908+ }
15909+ } else
15910+#endif
15911+
15912+ load_cr3(get_cpu_pgd(cpu, kernel));
15913+#endif
15914+
15915+#ifdef CONFIG_SMP
15916 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15917 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15918
15919@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15920 * tlb flush IPI delivery. We must reload CR3
15921 * to make sure to use no freed page tables.
15922 */
15923+
15924+#ifndef CONFIG_PAX_PER_CPU_PGD
15925 load_cr3(next->pgd);
15926+#endif
15927+
15928 load_LDT_nolock(&next->context);
15929+
15930+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15931+ if (!(__supported_pte_mask & _PAGE_NX))
15932+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15933+#endif
15934+
15935+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15936+#ifdef CONFIG_PAX_PAGEEXEC
15937+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15938+#endif
15939+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15940+#endif
15941+
15942 }
15943+#endif
15944 }
15945-#endif
15946 }
15947
15948 #define activate_mm(prev, next) \
15949diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15950index e3b7819..b257c64 100644
15951--- a/arch/x86/include/asm/module.h
15952+++ b/arch/x86/include/asm/module.h
15953@@ -5,6 +5,7 @@
15954
15955 #ifdef CONFIG_X86_64
15956 /* X86_64 does not define MODULE_PROC_FAMILY */
15957+#define MODULE_PROC_FAMILY ""
15958 #elif defined CONFIG_M486
15959 #define MODULE_PROC_FAMILY "486 "
15960 #elif defined CONFIG_M586
15961@@ -57,8 +58,20 @@
15962 #error unknown processor family
15963 #endif
15964
15965-#ifdef CONFIG_X86_32
15966-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15967+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15968+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15969+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15970+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15971+#else
15972+#define MODULE_PAX_KERNEXEC ""
15973 #endif
15974
15975+#ifdef CONFIG_PAX_MEMORY_UDEREF
15976+#define MODULE_PAX_UDEREF "UDEREF "
15977+#else
15978+#define MODULE_PAX_UDEREF ""
15979+#endif
15980+
15981+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15982+
15983 #endif /* _ASM_X86_MODULE_H */
15984diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15985index 86f9301..b365cda 100644
15986--- a/arch/x86/include/asm/nmi.h
15987+++ b/arch/x86/include/asm/nmi.h
15988@@ -40,11 +40,11 @@ struct nmiaction {
15989 nmi_handler_t handler;
15990 unsigned long flags;
15991 const char *name;
15992-};
15993+} __do_const;
15994
15995 #define register_nmi_handler(t, fn, fg, n, init...) \
15996 ({ \
15997- static struct nmiaction init fn##_na = { \
15998+ static const struct nmiaction init fn##_na = { \
15999 .handler = (fn), \
16000 .name = (n), \
16001 .flags = (fg), \
16002@@ -52,7 +52,7 @@ struct nmiaction {
16003 __register_nmi_handler((t), &fn##_na); \
16004 })
16005
16006-int __register_nmi_handler(unsigned int, struct nmiaction *);
16007+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16008
16009 void unregister_nmi_handler(unsigned int, const char *);
16010
16011diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16012index c878924..21f4889 100644
16013--- a/arch/x86/include/asm/page.h
16014+++ b/arch/x86/include/asm/page.h
16015@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16016 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16017
16018 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16019+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16020
16021 #define __boot_va(x) __va(x)
16022 #define __boot_pa(x) __pa(x)
16023diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16024index 0f1ddee..e2fc3d1 100644
16025--- a/arch/x86/include/asm/page_64.h
16026+++ b/arch/x86/include/asm/page_64.h
16027@@ -7,9 +7,9 @@
16028
16029 /* duplicated to the one in bootmem.h */
16030 extern unsigned long max_pfn;
16031-extern unsigned long phys_base;
16032+extern const unsigned long phys_base;
16033
16034-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16035+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16036 {
16037 unsigned long y = x - __START_KERNEL_map;
16038
16039diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16040index cfdc9ee..3f7b5d6 100644
16041--- a/arch/x86/include/asm/paravirt.h
16042+++ b/arch/x86/include/asm/paravirt.h
16043@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16044 return (pmd_t) { ret };
16045 }
16046
16047-static inline pmdval_t pmd_val(pmd_t pmd)
16048+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16049 {
16050 pmdval_t ret;
16051
16052@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16053 val);
16054 }
16055
16056+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16057+{
16058+ pgdval_t val = native_pgd_val(pgd);
16059+
16060+ if (sizeof(pgdval_t) > sizeof(long))
16061+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16062+ val, (u64)val >> 32);
16063+ else
16064+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16065+ val);
16066+}
16067+
16068 static inline void pgd_clear(pgd_t *pgdp)
16069 {
16070 set_pgd(pgdp, __pgd(0));
16071@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16072 pv_mmu_ops.set_fixmap(idx, phys, flags);
16073 }
16074
16075+#ifdef CONFIG_PAX_KERNEXEC
16076+static inline unsigned long pax_open_kernel(void)
16077+{
16078+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16079+}
16080+
16081+static inline unsigned long pax_close_kernel(void)
16082+{
16083+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16084+}
16085+#else
16086+static inline unsigned long pax_open_kernel(void) { return 0; }
16087+static inline unsigned long pax_close_kernel(void) { return 0; }
16088+#endif
16089+
16090 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16091
16092 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16093@@ -926,7 +953,7 @@ extern void default_banner(void);
16094
16095 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16096 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16097-#define PARA_INDIRECT(addr) *%cs:addr
16098+#define PARA_INDIRECT(addr) *%ss:addr
16099 #endif
16100
16101 #define INTERRUPT_RETURN \
16102@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16103 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16104 CLBR_NONE, \
16105 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16106+
16107+#define GET_CR0_INTO_RDI \
16108+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16109+ mov %rax,%rdi
16110+
16111+#define SET_RDI_INTO_CR0 \
16112+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16113+
16114+#define GET_CR3_INTO_RDI \
16115+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16116+ mov %rax,%rdi
16117+
16118+#define SET_RDI_INTO_CR3 \
16119+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16120+
16121 #endif /* CONFIG_X86_32 */
16122
16123 #endif /* __ASSEMBLY__ */
16124diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16125index 0db1fca..52310cc 100644
16126--- a/arch/x86/include/asm/paravirt_types.h
16127+++ b/arch/x86/include/asm/paravirt_types.h
16128@@ -84,7 +84,7 @@ struct pv_init_ops {
16129 */
16130 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16131 unsigned long addr, unsigned len);
16132-};
16133+} __no_const;
16134
16135
16136 struct pv_lazy_ops {
16137@@ -98,7 +98,7 @@ struct pv_time_ops {
16138 unsigned long long (*sched_clock)(void);
16139 unsigned long long (*steal_clock)(int cpu);
16140 unsigned long (*get_tsc_khz)(void);
16141-};
16142+} __no_const;
16143
16144 struct pv_cpu_ops {
16145 /* hooks for various privileged instructions */
16146@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16147
16148 void (*start_context_switch)(struct task_struct *prev);
16149 void (*end_context_switch)(struct task_struct *next);
16150-};
16151+} __no_const;
16152
16153 struct pv_irq_ops {
16154 /*
16155@@ -223,7 +223,7 @@ struct pv_apic_ops {
16156 unsigned long start_eip,
16157 unsigned long start_esp);
16158 #endif
16159-};
16160+} __no_const;
16161
16162 struct pv_mmu_ops {
16163 unsigned long (*read_cr2)(void);
16164@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16165 struct paravirt_callee_save make_pud;
16166
16167 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16168+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16169 #endif /* PAGETABLE_LEVELS == 4 */
16170 #endif /* PAGETABLE_LEVELS >= 3 */
16171
16172@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16173 an mfn. We can tell which is which from the index. */
16174 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16175 phys_addr_t phys, pgprot_t flags);
16176+
16177+#ifdef CONFIG_PAX_KERNEXEC
16178+ unsigned long (*pax_open_kernel)(void);
16179+ unsigned long (*pax_close_kernel)(void);
16180+#endif
16181+
16182 };
16183
16184 struct arch_spinlock;
16185@@ -334,7 +341,7 @@ struct pv_lock_ops {
16186 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16187 int (*spin_trylock)(struct arch_spinlock *lock);
16188 void (*spin_unlock)(struct arch_spinlock *lock);
16189-};
16190+} __no_const;
16191
16192 /* This contains all the paravirt structures: we get a convenient
16193 * number for each function using the offset which we use to indicate
16194diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16195index b4389a4..7024269 100644
16196--- a/arch/x86/include/asm/pgalloc.h
16197+++ b/arch/x86/include/asm/pgalloc.h
16198@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16199 pmd_t *pmd, pte_t *pte)
16200 {
16201 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16202+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16203+}
16204+
16205+static inline void pmd_populate_user(struct mm_struct *mm,
16206+ pmd_t *pmd, pte_t *pte)
16207+{
16208+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16209 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16210 }
16211
16212@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16213
16214 #ifdef CONFIG_X86_PAE
16215 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16216+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16217+{
16218+ pud_populate(mm, pudp, pmd);
16219+}
16220 #else /* !CONFIG_X86_PAE */
16221 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16222 {
16223 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16224 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16225 }
16226+
16227+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16228+{
16229+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16230+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16231+}
16232 #endif /* CONFIG_X86_PAE */
16233
16234 #if PAGETABLE_LEVELS > 3
16235@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16236 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16237 }
16238
16239+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16240+{
16241+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16242+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16243+}
16244+
16245 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16246 {
16247 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16248diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16249index 3bf2dd0..23d2a9f 100644
16250--- a/arch/x86/include/asm/pgtable-2level.h
16251+++ b/arch/x86/include/asm/pgtable-2level.h
16252@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16253
16254 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16255 {
16256+ pax_open_kernel();
16257 *pmdp = pmd;
16258+ pax_close_kernel();
16259 }
16260
16261 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16262diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16263index 81bb91b..9392125 100644
16264--- a/arch/x86/include/asm/pgtable-3level.h
16265+++ b/arch/x86/include/asm/pgtable-3level.h
16266@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16267
16268 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16269 {
16270+ pax_open_kernel();
16271 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16272+ pax_close_kernel();
16273 }
16274
16275 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16276 {
16277+ pax_open_kernel();
16278 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16279+ pax_close_kernel();
16280 }
16281
16282 /*
16283diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16284index 1c00631..845f898 100644
16285--- a/arch/x86/include/asm/pgtable.h
16286+++ b/arch/x86/include/asm/pgtable.h
16287@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16288
16289 #ifndef __PAGETABLE_PUD_FOLDED
16290 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16291+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16292 #define pgd_clear(pgd) native_pgd_clear(pgd)
16293 #endif
16294
16295@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16296
16297 #define arch_end_context_switch(prev) do {} while(0)
16298
16299+#define pax_open_kernel() native_pax_open_kernel()
16300+#define pax_close_kernel() native_pax_close_kernel()
16301 #endif /* CONFIG_PARAVIRT */
16302
16303+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16304+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16305+
16306+#ifdef CONFIG_PAX_KERNEXEC
16307+static inline unsigned long native_pax_open_kernel(void)
16308+{
16309+ unsigned long cr0;
16310+
16311+ preempt_disable();
16312+ barrier();
16313+ cr0 = read_cr0() ^ X86_CR0_WP;
16314+ BUG_ON(cr0 & X86_CR0_WP);
16315+ write_cr0(cr0);
16316+ return cr0 ^ X86_CR0_WP;
16317+}
16318+
16319+static inline unsigned long native_pax_close_kernel(void)
16320+{
16321+ unsigned long cr0;
16322+
16323+ cr0 = read_cr0() ^ X86_CR0_WP;
16324+ BUG_ON(!(cr0 & X86_CR0_WP));
16325+ write_cr0(cr0);
16326+ barrier();
16327+ preempt_enable_no_resched();
16328+ return cr0 ^ X86_CR0_WP;
16329+}
16330+#else
16331+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16332+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16333+#endif
16334+
16335 /*
16336 * The following only work if pte_present() is true.
16337 * Undefined behaviour if not..
16338 */
16339+static inline int pte_user(pte_t pte)
16340+{
16341+ return pte_val(pte) & _PAGE_USER;
16342+}
16343+
16344 static inline int pte_dirty(pte_t pte)
16345 {
16346 return pte_flags(pte) & _PAGE_DIRTY;
16347@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16348 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16349 }
16350
16351+static inline unsigned long pgd_pfn(pgd_t pgd)
16352+{
16353+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16354+}
16355+
16356 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16357
16358 static inline int pmd_large(pmd_t pte)
16359@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16360 return pte_clear_flags(pte, _PAGE_RW);
16361 }
16362
16363+static inline pte_t pte_mkread(pte_t pte)
16364+{
16365+ return __pte(pte_val(pte) | _PAGE_USER);
16366+}
16367+
16368 static inline pte_t pte_mkexec(pte_t pte)
16369 {
16370- return pte_clear_flags(pte, _PAGE_NX);
16371+#ifdef CONFIG_X86_PAE
16372+ if (__supported_pte_mask & _PAGE_NX)
16373+ return pte_clear_flags(pte, _PAGE_NX);
16374+ else
16375+#endif
16376+ return pte_set_flags(pte, _PAGE_USER);
16377+}
16378+
16379+static inline pte_t pte_exprotect(pte_t pte)
16380+{
16381+#ifdef CONFIG_X86_PAE
16382+ if (__supported_pte_mask & _PAGE_NX)
16383+ return pte_set_flags(pte, _PAGE_NX);
16384+ else
16385+#endif
16386+ return pte_clear_flags(pte, _PAGE_USER);
16387 }
16388
16389 static inline pte_t pte_mkdirty(pte_t pte)
16390@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16391 #endif
16392
16393 #ifndef __ASSEMBLY__
16394+
16395+#ifdef CONFIG_PAX_PER_CPU_PGD
16396+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16397+enum cpu_pgd_type {kernel = 0, user = 1};
16398+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16399+{
16400+ return cpu_pgd[cpu][type];
16401+}
16402+#endif
16403+
16404 #include <linux/mm_types.h>
16405 #include <linux/log2.h>
16406
16407@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16408 * Currently stuck as a macro due to indirect forward reference to
16409 * linux/mmzone.h's __section_mem_map_addr() definition:
16410 */
16411-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16412+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16413
16414 /* Find an entry in the second-level page table.. */
16415 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16416@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16417 * Currently stuck as a macro due to indirect forward reference to
16418 * linux/mmzone.h's __section_mem_map_addr() definition:
16419 */
16420-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16421+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16422
16423 /* to find an entry in a page-table-directory. */
16424 static inline unsigned long pud_index(unsigned long address)
16425@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16426
16427 static inline int pgd_bad(pgd_t pgd)
16428 {
16429- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16430+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16431 }
16432
16433 static inline int pgd_none(pgd_t pgd)
16434@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16435 * pgd_offset() returns a (pgd_t *)
16436 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16437 */
16438-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16439+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16440+
16441+#ifdef CONFIG_PAX_PER_CPU_PGD
16442+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16443+#endif
16444+
16445 /*
16446 * a shortcut which implies the use of the kernel's pgd, instead
16447 * of a process's
16448@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16449 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16450 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16451
16452+#ifdef CONFIG_X86_32
16453+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16454+#else
16455+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16456+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16457+
16458+#ifdef CONFIG_PAX_MEMORY_UDEREF
16459+#ifdef __ASSEMBLY__
16460+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16461+#else
16462+extern unsigned long pax_user_shadow_base;
16463+extern pgdval_t clone_pgd_mask;
16464+#endif
16465+#endif
16466+
16467+#endif
16468+
16469 #ifndef __ASSEMBLY__
16470
16471 extern int direct_gbpages;
16472@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16473 * dst and src can be on the same page, but the range must not overlap,
16474 * and must not cross a page boundary.
16475 */
16476-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16477+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16478 {
16479- memcpy(dst, src, count * sizeof(pgd_t));
16480+ pax_open_kernel();
16481+ while (count--)
16482+ *dst++ = *src++;
16483+ pax_close_kernel();
16484 }
16485
16486+#ifdef CONFIG_PAX_PER_CPU_PGD
16487+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16488+#endif
16489+
16490+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16491+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16492+#else
16493+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16494+#endif
16495+
16496 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16497 static inline int page_level_shift(enum pg_level level)
16498 {
16499diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16500index 9ee3221..b979c6b 100644
16501--- a/arch/x86/include/asm/pgtable_32.h
16502+++ b/arch/x86/include/asm/pgtable_32.h
16503@@ -25,9 +25,6 @@
16504 struct mm_struct;
16505 struct vm_area_struct;
16506
16507-extern pgd_t swapper_pg_dir[1024];
16508-extern pgd_t initial_page_table[1024];
16509-
16510 static inline void pgtable_cache_init(void) { }
16511 static inline void check_pgt_cache(void) { }
16512 void paging_init(void);
16513@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16514 # include <asm/pgtable-2level.h>
16515 #endif
16516
16517+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16518+extern pgd_t initial_page_table[PTRS_PER_PGD];
16519+#ifdef CONFIG_X86_PAE
16520+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16521+#endif
16522+
16523 #if defined(CONFIG_HIGHPTE)
16524 #define pte_offset_map(dir, address) \
16525 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16526@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16527 /* Clear a kernel PTE and flush it from the TLB */
16528 #define kpte_clear_flush(ptep, vaddr) \
16529 do { \
16530+ pax_open_kernel(); \
16531 pte_clear(&init_mm, (vaddr), (ptep)); \
16532+ pax_close_kernel(); \
16533 __flush_tlb_one((vaddr)); \
16534 } while (0)
16535
16536 #endif /* !__ASSEMBLY__ */
16537
16538+#define HAVE_ARCH_UNMAPPED_AREA
16539+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16540+
16541 /*
16542 * kern_addr_valid() is (1) for FLATMEM and (0) for
16543 * SPARSEMEM and DISCONTIGMEM
16544diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16545index ed5903b..c7fe163 100644
16546--- a/arch/x86/include/asm/pgtable_32_types.h
16547+++ b/arch/x86/include/asm/pgtable_32_types.h
16548@@ -8,7 +8,7 @@
16549 */
16550 #ifdef CONFIG_X86_PAE
16551 # include <asm/pgtable-3level_types.h>
16552-# define PMD_SIZE (1UL << PMD_SHIFT)
16553+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16554 # define PMD_MASK (~(PMD_SIZE - 1))
16555 #else
16556 # include <asm/pgtable-2level_types.h>
16557@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16558 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16559 #endif
16560
16561+#ifdef CONFIG_PAX_KERNEXEC
16562+#ifndef __ASSEMBLY__
16563+extern unsigned char MODULES_EXEC_VADDR[];
16564+extern unsigned char MODULES_EXEC_END[];
16565+#endif
16566+#include <asm/boot.h>
16567+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16568+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16569+#else
16570+#define ktla_ktva(addr) (addr)
16571+#define ktva_ktla(addr) (addr)
16572+#endif
16573+
16574 #define MODULES_VADDR VMALLOC_START
16575 #define MODULES_END VMALLOC_END
16576 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16577diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16578index e22c1db..23a625a 100644
16579--- a/arch/x86/include/asm/pgtable_64.h
16580+++ b/arch/x86/include/asm/pgtable_64.h
16581@@ -16,10 +16,14 @@
16582
16583 extern pud_t level3_kernel_pgt[512];
16584 extern pud_t level3_ident_pgt[512];
16585+extern pud_t level3_vmalloc_start_pgt[512];
16586+extern pud_t level3_vmalloc_end_pgt[512];
16587+extern pud_t level3_vmemmap_pgt[512];
16588+extern pud_t level2_vmemmap_pgt[512];
16589 extern pmd_t level2_kernel_pgt[512];
16590 extern pmd_t level2_fixmap_pgt[512];
16591-extern pmd_t level2_ident_pgt[512];
16592-extern pgd_t init_level4_pgt[];
16593+extern pmd_t level2_ident_pgt[512*2];
16594+extern pgd_t init_level4_pgt[512];
16595
16596 #define swapper_pg_dir init_level4_pgt
16597
16598@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16599
16600 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16601 {
16602+ pax_open_kernel();
16603 *pmdp = pmd;
16604+ pax_close_kernel();
16605 }
16606
16607 static inline void native_pmd_clear(pmd_t *pmd)
16608@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16609
16610 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16611 {
16612+ pax_open_kernel();
16613 *pudp = pud;
16614+ pax_close_kernel();
16615 }
16616
16617 static inline void native_pud_clear(pud_t *pud)
16618@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16619
16620 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16621 {
16622+ pax_open_kernel();
16623+ *pgdp = pgd;
16624+ pax_close_kernel();
16625+}
16626+
16627+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16628+{
16629 *pgdp = pgd;
16630 }
16631
16632diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16633index 2d88344..4679fc3 100644
16634--- a/arch/x86/include/asm/pgtable_64_types.h
16635+++ b/arch/x86/include/asm/pgtable_64_types.h
16636@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16637 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16638 #define MODULES_END _AC(0xffffffffff000000, UL)
16639 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16640+#define MODULES_EXEC_VADDR MODULES_VADDR
16641+#define MODULES_EXEC_END MODULES_END
16642+
16643+#define ktla_ktva(addr) (addr)
16644+#define ktva_ktla(addr) (addr)
16645
16646 #define EARLY_DYNAMIC_PAGE_TABLES 64
16647
16648diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16649index f4843e0..a2526f8 100644
16650--- a/arch/x86/include/asm/pgtable_types.h
16651+++ b/arch/x86/include/asm/pgtable_types.h
16652@@ -16,13 +16,12 @@
16653 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16654 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16655 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16656-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16657+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16658 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16659 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16660 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16661-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16662-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16663-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16664+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16665+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16666 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16667
16668 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16669@@ -40,7 +39,6 @@
16670 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16671 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16672 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16673-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16674 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16675 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16676 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16677@@ -84,8 +82,10 @@
16678
16679 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16680 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16681-#else
16682+#elif defined(CONFIG_KMEMCHECK)
16683 #define _PAGE_NX (_AT(pteval_t, 0))
16684+#else
16685+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16686 #endif
16687
16688 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16689@@ -143,6 +143,9 @@
16690 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16691 _PAGE_ACCESSED)
16692
16693+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16694+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16695+
16696 #define __PAGE_KERNEL_EXEC \
16697 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16698 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16699@@ -153,7 +156,7 @@
16700 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16701 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16702 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16703-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16704+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16705 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16706 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16707 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16708@@ -215,8 +218,8 @@
16709 * bits are combined, this will alow user to access the high address mapped
16710 * VDSO in the presence of CONFIG_COMPAT_VDSO
16711 */
16712-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16713-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16714+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16715+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16716 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16717 #endif
16718
16719@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16720 {
16721 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16722 }
16723+#endif
16724
16725+#if PAGETABLE_LEVELS == 3
16726+#include <asm-generic/pgtable-nopud.h>
16727+#endif
16728+
16729+#if PAGETABLE_LEVELS == 2
16730+#include <asm-generic/pgtable-nopmd.h>
16731+#endif
16732+
16733+#ifndef __ASSEMBLY__
16734 #if PAGETABLE_LEVELS > 3
16735 typedef struct { pudval_t pud; } pud_t;
16736
16737@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16738 return pud.pud;
16739 }
16740 #else
16741-#include <asm-generic/pgtable-nopud.h>
16742-
16743 static inline pudval_t native_pud_val(pud_t pud)
16744 {
16745 return native_pgd_val(pud.pgd);
16746@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16747 return pmd.pmd;
16748 }
16749 #else
16750-#include <asm-generic/pgtable-nopmd.h>
16751-
16752 static inline pmdval_t native_pmd_val(pmd_t pmd)
16753 {
16754 return native_pgd_val(pmd.pud.pgd);
16755@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16756
16757 extern pteval_t __supported_pte_mask;
16758 extern void set_nx(void);
16759-extern int nx_enabled;
16760
16761 #define pgprot_writecombine pgprot_writecombine
16762 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16763diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16764index 24cf5ae..4d9fa2d 100644
16765--- a/arch/x86/include/asm/processor.h
16766+++ b/arch/x86/include/asm/processor.h
16767@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16768 : "memory");
16769 }
16770
16771+/* invpcid (%rdx),%rax */
16772+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16773+
16774+#define INVPCID_SINGLE_ADDRESS 0UL
16775+#define INVPCID_SINGLE_CONTEXT 1UL
16776+#define INVPCID_ALL_GLOBAL 2UL
16777+#define INVPCID_ALL_MONGLOBAL 3UL
16778+
16779+#define PCID_KERNEL 0UL
16780+#define PCID_USER 1UL
16781+#define PCID_NOFLUSH (1UL << 63)
16782+
16783 static inline void load_cr3(pgd_t *pgdir)
16784 {
16785- write_cr3(__pa(pgdir));
16786+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16787 }
16788
16789 #ifdef CONFIG_X86_32
16790@@ -283,7 +295,7 @@ struct tss_struct {
16791
16792 } ____cacheline_aligned;
16793
16794-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16795+extern struct tss_struct init_tss[NR_CPUS];
16796
16797 /*
16798 * Save the original ist values for checking stack pointers during debugging
16799@@ -453,6 +465,7 @@ struct thread_struct {
16800 unsigned short ds;
16801 unsigned short fsindex;
16802 unsigned short gsindex;
16803+ unsigned short ss;
16804 #endif
16805 #ifdef CONFIG_X86_32
16806 unsigned long ip;
16807@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16808 extern unsigned long mmu_cr4_features;
16809 extern u32 *trampoline_cr4_features;
16810
16811-static inline void set_in_cr4(unsigned long mask)
16812-{
16813- unsigned long cr4;
16814-
16815- mmu_cr4_features |= mask;
16816- if (trampoline_cr4_features)
16817- *trampoline_cr4_features = mmu_cr4_features;
16818- cr4 = read_cr4();
16819- cr4 |= mask;
16820- write_cr4(cr4);
16821-}
16822-
16823-static inline void clear_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+extern void set_in_cr4(unsigned long mask);
16835+extern void clear_in_cr4(unsigned long mask);
16836
16837 typedef struct {
16838 unsigned long seg;
16839@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16840 */
16841 #define TASK_SIZE PAGE_OFFSET
16842 #define TASK_SIZE_MAX TASK_SIZE
16843+
16844+#ifdef CONFIG_PAX_SEGMEXEC
16845+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16846+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16847+#else
16848 #define STACK_TOP TASK_SIZE
16849-#define STACK_TOP_MAX STACK_TOP
16850+#endif
16851+
16852+#define STACK_TOP_MAX TASK_SIZE
16853
16854 #define INIT_THREAD { \
16855- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16856+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16857 .vm86_info = NULL, \
16858 .sysenter_cs = __KERNEL_CS, \
16859 .io_bitmap_ptr = NULL, \
16860@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16861 */
16862 #define INIT_TSS { \
16863 .x86_tss = { \
16864- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16865+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16866 .ss0 = __KERNEL_DS, \
16867 .ss1 = __KERNEL_CS, \
16868 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16869@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16870 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16871
16872 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16873-#define KSTK_TOP(info) \
16874-({ \
16875- unsigned long *__ptr = (unsigned long *)(info); \
16876- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16877-})
16878+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16879
16880 /*
16881 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16882@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16883 #define task_pt_regs(task) \
16884 ({ \
16885 struct pt_regs *__regs__; \
16886- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16887+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16888 __regs__ - 1; \
16889 })
16890
16891@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16892 /*
16893 * User space process size. 47bits minus one guard page.
16894 */
16895-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16896+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16897
16898 /* This decides where the kernel will search for a free chunk of vm
16899 * space during mmap's.
16900 */
16901 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16902- 0xc0000000 : 0xFFFFe000)
16903+ 0xc0000000 : 0xFFFFf000)
16904
16905 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16906 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16907@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16908 #define STACK_TOP_MAX TASK_SIZE_MAX
16909
16910 #define INIT_THREAD { \
16911- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16912+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16913 }
16914
16915 #define INIT_TSS { \
16916- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16917+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16918 }
16919
16920 /*
16921@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16922 */
16923 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16924
16925+#ifdef CONFIG_PAX_SEGMEXEC
16926+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16927+#endif
16928+
16929 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16930
16931 /* Get/set a process' ability to use the timestamp counter instruction */
16932@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16933 extern u16 amd_get_nb_id(int cpu);
16934
16935 struct aperfmperf {
16936- u64 aperf, mperf;
16937+ u64 aperf __intentional_overflow(0);
16938+ u64 mperf __intentional_overflow(0);
16939 };
16940
16941 static inline void get_aperfmperf(struct aperfmperf *am)
16942@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16943 return ratio;
16944 }
16945
16946-extern unsigned long arch_align_stack(unsigned long sp);
16947+#define arch_align_stack(x) ((x) & ~0xfUL)
16948 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16949
16950 void default_idle(void);
16951@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16952 #define xen_set_default_idle 0
16953 #endif
16954
16955-void stop_this_cpu(void *dummy);
16956+void stop_this_cpu(void *dummy) __noreturn;
16957 void df_debug(struct pt_regs *regs, long error_code);
16958 #endif /* _ASM_X86_PROCESSOR_H */
16959diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16960index 942a086..6c26446 100644
16961--- a/arch/x86/include/asm/ptrace.h
16962+++ b/arch/x86/include/asm/ptrace.h
16963@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16964 }
16965
16966 /*
16967- * user_mode_vm(regs) determines whether a register set came from user mode.
16968+ * user_mode(regs) determines whether a register set came from user mode.
16969 * This is true if V8086 mode was enabled OR if the register set was from
16970 * protected mode with RPL-3 CS value. This tricky test checks that with
16971 * one comparison. Many places in the kernel can bypass this full check
16972- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16973+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16974+ * be used.
16975 */
16976-static inline int user_mode(struct pt_regs *regs)
16977+static inline int user_mode_novm(struct pt_regs *regs)
16978 {
16979 #ifdef CONFIG_X86_32
16980 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16981 #else
16982- return !!(regs->cs & 3);
16983+ return !!(regs->cs & SEGMENT_RPL_MASK);
16984 #endif
16985 }
16986
16987-static inline int user_mode_vm(struct pt_regs *regs)
16988+static inline int user_mode(struct pt_regs *regs)
16989 {
16990 #ifdef CONFIG_X86_32
16991 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
16992 USER_RPL;
16993 #else
16994- return user_mode(regs);
16995+ return user_mode_novm(regs);
16996 #endif
16997 }
16998
16999@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17000 #ifdef CONFIG_X86_64
17001 static inline bool user_64bit_mode(struct pt_regs *regs)
17002 {
17003+ unsigned long cs = regs->cs & 0xffff;
17004 #ifndef CONFIG_PARAVIRT
17005 /*
17006 * On non-paravirt systems, this is the only long mode CPL 3
17007 * selector. We do not allow long mode selectors in the LDT.
17008 */
17009- return regs->cs == __USER_CS;
17010+ return cs == __USER_CS;
17011 #else
17012 /* Headers are too twisted for this to go in paravirt.h. */
17013- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17014+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17015 #endif
17016 }
17017
17018@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17019 * Traps from the kernel do not save sp and ss.
17020 * Use the helper function to retrieve sp.
17021 */
17022- if (offset == offsetof(struct pt_regs, sp) &&
17023- regs->cs == __KERNEL_CS)
17024- return kernel_stack_pointer(regs);
17025+ if (offset == offsetof(struct pt_regs, sp)) {
17026+ unsigned long cs = regs->cs & 0xffff;
17027+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17028+ return kernel_stack_pointer(regs);
17029+ }
17030 #endif
17031 return *(unsigned long *)((unsigned long)regs + offset);
17032 }
17033diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17034index 9c6b890..5305f53 100644
17035--- a/arch/x86/include/asm/realmode.h
17036+++ b/arch/x86/include/asm/realmode.h
17037@@ -22,16 +22,14 @@ struct real_mode_header {
17038 #endif
17039 /* APM/BIOS reboot */
17040 u32 machine_real_restart_asm;
17041-#ifdef CONFIG_X86_64
17042 u32 machine_real_restart_seg;
17043-#endif
17044 };
17045
17046 /* This must match data at trampoline_32/64.S */
17047 struct trampoline_header {
17048 #ifdef CONFIG_X86_32
17049 u32 start;
17050- u16 gdt_pad;
17051+ u16 boot_cs;
17052 u16 gdt_limit;
17053 u32 gdt_base;
17054 #else
17055diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17056index a82c4f1..ac45053 100644
17057--- a/arch/x86/include/asm/reboot.h
17058+++ b/arch/x86/include/asm/reboot.h
17059@@ -6,13 +6,13 @@
17060 struct pt_regs;
17061
17062 struct machine_ops {
17063- void (*restart)(char *cmd);
17064- void (*halt)(void);
17065- void (*power_off)(void);
17066+ void (* __noreturn restart)(char *cmd);
17067+ void (* __noreturn halt)(void);
17068+ void (* __noreturn power_off)(void);
17069 void (*shutdown)(void);
17070 void (*crash_shutdown)(struct pt_regs *);
17071- void (*emergency_restart)(void);
17072-};
17073+ void (* __noreturn emergency_restart)(void);
17074+} __no_const;
17075
17076 extern struct machine_ops machine_ops;
17077
17078diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17079index cad82c9..2e5c5c1 100644
17080--- a/arch/x86/include/asm/rwsem.h
17081+++ b/arch/x86/include/asm/rwsem.h
17082@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17083 {
17084 asm volatile("# beginning down_read\n\t"
17085 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17086+
17087+#ifdef CONFIG_PAX_REFCOUNT
17088+ "jno 0f\n"
17089+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17090+ "int $4\n0:\n"
17091+ _ASM_EXTABLE(0b, 0b)
17092+#endif
17093+
17094 /* adds 0x00000001 */
17095 " jns 1f\n"
17096 " call call_rwsem_down_read_failed\n"
17097@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17098 "1:\n\t"
17099 " mov %1,%2\n\t"
17100 " add %3,%2\n\t"
17101+
17102+#ifdef CONFIG_PAX_REFCOUNT
17103+ "jno 0f\n"
17104+ "sub %3,%2\n"
17105+ "int $4\n0:\n"
17106+ _ASM_EXTABLE(0b, 0b)
17107+#endif
17108+
17109 " jle 2f\n\t"
17110 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17111 " jnz 1b\n\t"
17112@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17113 long tmp;
17114 asm volatile("# beginning down_write\n\t"
17115 LOCK_PREFIX " xadd %1,(%2)\n\t"
17116+
17117+#ifdef CONFIG_PAX_REFCOUNT
17118+ "jno 0f\n"
17119+ "mov %1,(%2)\n"
17120+ "int $4\n0:\n"
17121+ _ASM_EXTABLE(0b, 0b)
17122+#endif
17123+
17124 /* adds 0xffff0001, returns the old value */
17125 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17126 /* was the active mask 0 before? */
17127@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17128 long tmp;
17129 asm volatile("# beginning __up_read\n\t"
17130 LOCK_PREFIX " xadd %1,(%2)\n\t"
17131+
17132+#ifdef CONFIG_PAX_REFCOUNT
17133+ "jno 0f\n"
17134+ "mov %1,(%2)\n"
17135+ "int $4\n0:\n"
17136+ _ASM_EXTABLE(0b, 0b)
17137+#endif
17138+
17139 /* subtracts 1, returns the old value */
17140 " jns 1f\n\t"
17141 " call call_rwsem_wake\n" /* expects old value in %edx */
17142@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17143 long tmp;
17144 asm volatile("# beginning __up_write\n\t"
17145 LOCK_PREFIX " xadd %1,(%2)\n\t"
17146+
17147+#ifdef CONFIG_PAX_REFCOUNT
17148+ "jno 0f\n"
17149+ "mov %1,(%2)\n"
17150+ "int $4\n0:\n"
17151+ _ASM_EXTABLE(0b, 0b)
17152+#endif
17153+
17154 /* subtracts 0xffff0001, returns the old value */
17155 " jns 1f\n\t"
17156 " call call_rwsem_wake\n" /* expects old value in %edx */
17157@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17158 {
17159 asm volatile("# beginning __downgrade_write\n\t"
17160 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17161+
17162+#ifdef CONFIG_PAX_REFCOUNT
17163+ "jno 0f\n"
17164+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17165+ "int $4\n0:\n"
17166+ _ASM_EXTABLE(0b, 0b)
17167+#endif
17168+
17169 /*
17170 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17171 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17172@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17173 */
17174 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17175 {
17176- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17177+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17178+
17179+#ifdef CONFIG_PAX_REFCOUNT
17180+ "jno 0f\n"
17181+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17182+ "int $4\n0:\n"
17183+ _ASM_EXTABLE(0b, 0b)
17184+#endif
17185+
17186 : "+m" (sem->count)
17187 : "er" (delta));
17188 }
17189@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17190 */
17191 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17192 {
17193- return delta + xadd(&sem->count, delta);
17194+ return delta + xadd_check_overflow(&sem->count, delta);
17195 }
17196
17197 #endif /* __KERNEL__ */
17198diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17199index c48a950..bc40804 100644
17200--- a/arch/x86/include/asm/segment.h
17201+++ b/arch/x86/include/asm/segment.h
17202@@ -64,10 +64,15 @@
17203 * 26 - ESPFIX small SS
17204 * 27 - per-cpu [ offset to per-cpu data area ]
17205 * 28 - stack_canary-20 [ for stack protector ]
17206- * 29 - unused
17207- * 30 - unused
17208+ * 29 - PCI BIOS CS
17209+ * 30 - PCI BIOS DS
17210 * 31 - TSS for double fault handler
17211 */
17212+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17213+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17214+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17215+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17216+
17217 #define GDT_ENTRY_TLS_MIN 6
17218 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17219
17220@@ -79,6 +84,8 @@
17221
17222 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17223
17224+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17225+
17226 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17227
17228 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17229@@ -104,6 +111,12 @@
17230 #define __KERNEL_STACK_CANARY 0
17231 #endif
17232
17233+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17234+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17235+
17236+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17237+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17238+
17239 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17240
17241 /*
17242@@ -141,7 +154,7 @@
17243 */
17244
17245 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17246-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17247+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17248
17249
17250 #else
17251@@ -165,6 +178,8 @@
17252 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17253 #define __USER32_DS __USER_DS
17254
17255+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17256+
17257 #define GDT_ENTRY_TSS 8 /* needs two entries */
17258 #define GDT_ENTRY_LDT 10 /* needs two entries */
17259 #define GDT_ENTRY_TLS_MIN 12
17260@@ -173,6 +188,8 @@
17261 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17262 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17263
17264+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17265+
17266 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17267 #define FS_TLS 0
17268 #define GS_TLS 1
17269@@ -180,12 +197,14 @@
17270 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17271 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17272
17273-#define GDT_ENTRIES 16
17274+#define GDT_ENTRIES 17
17275
17276 #endif
17277
17278 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17279+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17280 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17281+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17282 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17283 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17284 #ifndef CONFIG_PARAVIRT
17285@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17286 {
17287 unsigned long __limit;
17288 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17289- return __limit + 1;
17290+ return __limit;
17291 }
17292
17293 #endif /* !__ASSEMBLY__ */
17294diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17295index 8d3120f..352b440 100644
17296--- a/arch/x86/include/asm/smap.h
17297+++ b/arch/x86/include/asm/smap.h
17298@@ -25,11 +25,40 @@
17299
17300 #include <asm/alternative-asm.h>
17301
17302+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17303+#define ASM_PAX_OPEN_USERLAND \
17304+ 661: jmp 663f; \
17305+ .pushsection .altinstr_replacement, "a" ; \
17306+ 662: pushq %rax; nop; \
17307+ .popsection ; \
17308+ .pushsection .altinstructions, "a" ; \
17309+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17310+ .popsection ; \
17311+ call __pax_open_userland; \
17312+ popq %rax; \
17313+ 663:
17314+
17315+#define ASM_PAX_CLOSE_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_close_userland; \
17324+ popq %rax; \
17325+ 663:
17326+#else
17327+#define ASM_PAX_OPEN_USERLAND
17328+#define ASM_PAX_CLOSE_USERLAND
17329+#endif
17330+
17331 #ifdef CONFIG_X86_SMAP
17332
17333 #define ASM_CLAC \
17334 661: ASM_NOP3 ; \
17335- .pushsection .altinstr_replacement, "ax" ; \
17336+ .pushsection .altinstr_replacement, "a" ; \
17337 662: __ASM_CLAC ; \
17338 .popsection ; \
17339 .pushsection .altinstructions, "a" ; \
17340@@ -38,7 +67,7 @@
17341
17342 #define ASM_STAC \
17343 661: ASM_NOP3 ; \
17344- .pushsection .altinstr_replacement, "ax" ; \
17345+ .pushsection .altinstr_replacement, "a" ; \
17346 662: __ASM_STAC ; \
17347 .popsection ; \
17348 .pushsection .altinstructions, "a" ; \
17349@@ -56,6 +85,37 @@
17350
17351 #include <asm/alternative.h>
17352
17353+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17354+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17355+
17356+extern void __pax_open_userland(void);
17357+static __always_inline unsigned long pax_open_userland(void)
17358+{
17359+
17360+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17361+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17362+ :
17363+ : [open] "i" (__pax_open_userland)
17364+ : "memory", "rax");
17365+#endif
17366+
17367+ return 0;
17368+}
17369+
17370+extern void __pax_close_userland(void);
17371+static __always_inline unsigned long pax_close_userland(void)
17372+{
17373+
17374+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17375+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17376+ :
17377+ : [close] "i" (__pax_close_userland)
17378+ : "memory", "rax");
17379+#endif
17380+
17381+ return 0;
17382+}
17383+
17384 #ifdef CONFIG_X86_SMAP
17385
17386 static __always_inline void clac(void)
17387diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17388index 4137890..03fa172 100644
17389--- a/arch/x86/include/asm/smp.h
17390+++ b/arch/x86/include/asm/smp.h
17391@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17392 /* cpus sharing the last level cache: */
17393 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17394 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17395-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17396+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17397
17398 static inline struct cpumask *cpu_sibling_mask(int cpu)
17399 {
17400@@ -79,7 +79,7 @@ struct smp_ops {
17401
17402 void (*send_call_func_ipi)(const struct cpumask *mask);
17403 void (*send_call_func_single_ipi)(int cpu);
17404-};
17405+} __no_const;
17406
17407 /* Globals due to paravirt */
17408 extern void set_cpu_sibling_map(int cpu);
17409@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17410 extern int safe_smp_processor_id(void);
17411
17412 #elif defined(CONFIG_X86_64_SMP)
17413-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17414-
17415-#define stack_smp_processor_id() \
17416-({ \
17417- struct thread_info *ti; \
17418- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17419- ti->cpu; \
17420-})
17421+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17422+#define stack_smp_processor_id() raw_smp_processor_id()
17423 #define safe_smp_processor_id() smp_processor_id()
17424
17425 #endif
17426diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17427index e3ddd7d..3611fce 100644
17428--- a/arch/x86/include/asm/spinlock.h
17429+++ b/arch/x86/include/asm/spinlock.h
17430@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17431 static inline void arch_read_lock(arch_rwlock_t *rw)
17432 {
17433 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17434+
17435+#ifdef CONFIG_PAX_REFCOUNT
17436+ "jno 0f\n"
17437+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17438+ "int $4\n0:\n"
17439+ _ASM_EXTABLE(0b, 0b)
17440+#endif
17441+
17442 "jns 1f\n"
17443 "call __read_lock_failed\n\t"
17444 "1:\n"
17445@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17446 static inline void arch_write_lock(arch_rwlock_t *rw)
17447 {
17448 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17449+
17450+#ifdef CONFIG_PAX_REFCOUNT
17451+ "jno 0f\n"
17452+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17453+ "int $4\n0:\n"
17454+ _ASM_EXTABLE(0b, 0b)
17455+#endif
17456+
17457 "jz 1f\n"
17458 "call __write_lock_failed\n\t"
17459 "1:\n"
17460@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17461
17462 static inline void arch_read_unlock(arch_rwlock_t *rw)
17463 {
17464- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17465+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17466+
17467+#ifdef CONFIG_PAX_REFCOUNT
17468+ "jno 0f\n"
17469+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17470+ "int $4\n0:\n"
17471+ _ASM_EXTABLE(0b, 0b)
17472+#endif
17473+
17474 :"+m" (rw->lock) : : "memory");
17475 }
17476
17477 static inline void arch_write_unlock(arch_rwlock_t *rw)
17478 {
17479- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17480+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17481+
17482+#ifdef CONFIG_PAX_REFCOUNT
17483+ "jno 0f\n"
17484+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17485+ "int $4\n0:\n"
17486+ _ASM_EXTABLE(0b, 0b)
17487+#endif
17488+
17489 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17490 }
17491
17492diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17493index 6a99859..03cb807 100644
17494--- a/arch/x86/include/asm/stackprotector.h
17495+++ b/arch/x86/include/asm/stackprotector.h
17496@@ -47,7 +47,7 @@
17497 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17498 */
17499 #define GDT_STACK_CANARY_INIT \
17500- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17501+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17502
17503 /*
17504 * Initialize the stackprotector canary value.
17505@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17506
17507 static inline void load_stack_canary_segment(void)
17508 {
17509-#ifdef CONFIG_X86_32
17510+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17511 asm volatile ("mov %0, %%gs" : : "r" (0));
17512 #endif
17513 }
17514diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17515index 70bbe39..4ae2bd4 100644
17516--- a/arch/x86/include/asm/stacktrace.h
17517+++ b/arch/x86/include/asm/stacktrace.h
17518@@ -11,28 +11,20 @@
17519
17520 extern int kstack_depth_to_print;
17521
17522-struct thread_info;
17523+struct task_struct;
17524 struct stacktrace_ops;
17525
17526-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17527- unsigned long *stack,
17528- unsigned long bp,
17529- const struct stacktrace_ops *ops,
17530- void *data,
17531- unsigned long *end,
17532- int *graph);
17533+typedef unsigned long walk_stack_t(struct task_struct *task,
17534+ void *stack_start,
17535+ unsigned long *stack,
17536+ unsigned long bp,
17537+ const struct stacktrace_ops *ops,
17538+ void *data,
17539+ unsigned long *end,
17540+ int *graph);
17541
17542-extern unsigned long
17543-print_context_stack(struct thread_info *tinfo,
17544- unsigned long *stack, unsigned long bp,
17545- const struct stacktrace_ops *ops, void *data,
17546- unsigned long *end, int *graph);
17547-
17548-extern unsigned long
17549-print_context_stack_bp(struct thread_info *tinfo,
17550- unsigned long *stack, unsigned long bp,
17551- const struct stacktrace_ops *ops, void *data,
17552- unsigned long *end, int *graph);
17553+extern walk_stack_t print_context_stack;
17554+extern walk_stack_t print_context_stack_bp;
17555
17556 /* Generic stack tracer with callbacks */
17557
17558@@ -40,7 +32,7 @@ struct stacktrace_ops {
17559 void (*address)(void *data, unsigned long address, int reliable);
17560 /* On negative return stop dumping */
17561 int (*stack)(void *data, char *name);
17562- walk_stack_t walk_stack;
17563+ walk_stack_t *walk_stack;
17564 };
17565
17566 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17567diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17568index 4ec45b3..a4f0a8a 100644
17569--- a/arch/x86/include/asm/switch_to.h
17570+++ b/arch/x86/include/asm/switch_to.h
17571@@ -108,7 +108,7 @@ do { \
17572 "call __switch_to\n\t" \
17573 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17574 __switch_canary \
17575- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17576+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17577 "movq %%rax,%%rdi\n\t" \
17578 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17579 "jnz ret_from_fork\n\t" \
17580@@ -119,7 +119,7 @@ do { \
17581 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17582 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17583 [_tif_fork] "i" (_TIF_FORK), \
17584- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17585+ [thread_info] "m" (current_tinfo), \
17586 [current_task] "m" (current_task) \
17587 __switch_canary_iparam \
17588 : "memory", "cc" __EXTRA_CLOBBER)
17589diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17590index 2781119..618b59b 100644
17591--- a/arch/x86/include/asm/thread_info.h
17592+++ b/arch/x86/include/asm/thread_info.h
17593@@ -10,6 +10,7 @@
17594 #include <linux/compiler.h>
17595 #include <asm/page.h>
17596 #include <asm/types.h>
17597+#include <asm/percpu.h>
17598
17599 /*
17600 * low level task data that entry.S needs immediate access to
17601@@ -23,7 +24,6 @@ struct exec_domain;
17602 #include <linux/atomic.h>
17603
17604 struct thread_info {
17605- struct task_struct *task; /* main task structure */
17606 struct exec_domain *exec_domain; /* execution domain */
17607 __u32 flags; /* low level flags */
17608 __u32 status; /* thread synchronous flags */
17609@@ -33,19 +33,13 @@ struct thread_info {
17610 mm_segment_t addr_limit;
17611 struct restart_block restart_block;
17612 void __user *sysenter_return;
17613-#ifdef CONFIG_X86_32
17614- unsigned long previous_esp; /* ESP of the previous stack in
17615- case of nested (IRQ) stacks
17616- */
17617- __u8 supervisor_stack[0];
17618-#endif
17619+ unsigned long lowest_stack;
17620 unsigned int sig_on_uaccess_error:1;
17621 unsigned int uaccess_err:1; /* uaccess failed */
17622 };
17623
17624-#define INIT_THREAD_INFO(tsk) \
17625+#define INIT_THREAD_INFO \
17626 { \
17627- .task = &tsk, \
17628 .exec_domain = &default_exec_domain, \
17629 .flags = 0, \
17630 .cpu = 0, \
17631@@ -56,7 +50,7 @@ struct thread_info {
17632 }, \
17633 }
17634
17635-#define init_thread_info (init_thread_union.thread_info)
17636+#define init_thread_info (init_thread_union.stack)
17637 #define init_stack (init_thread_union.stack)
17638
17639 #else /* !__ASSEMBLY__ */
17640@@ -96,6 +90,7 @@ struct thread_info {
17641 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17642 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17643 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17644+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17645
17646 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17647 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17648@@ -119,17 +114,18 @@ struct thread_info {
17649 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17650 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17651 #define _TIF_X32 (1 << TIF_X32)
17652+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17653
17654 /* work to do in syscall_trace_enter() */
17655 #define _TIF_WORK_SYSCALL_ENTRY \
17656 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17657 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17658- _TIF_NOHZ)
17659+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17660
17661 /* work to do in syscall_trace_leave() */
17662 #define _TIF_WORK_SYSCALL_EXIT \
17663 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17664- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17665+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17666
17667 /* work to do on interrupt/exception return */
17668 #define _TIF_WORK_MASK \
17669@@ -140,7 +136,7 @@ struct thread_info {
17670 /* work to do on any return to user space */
17671 #define _TIF_ALLWORK_MASK \
17672 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17673- _TIF_NOHZ)
17674+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17675
17676 /* Only used for 64 bit */
17677 #define _TIF_DO_NOTIFY_MASK \
17678@@ -156,45 +152,40 @@ struct thread_info {
17679
17680 #define PREEMPT_ACTIVE 0x10000000
17681
17682-#ifdef CONFIG_X86_32
17683-
17684-#define STACK_WARN (THREAD_SIZE/8)
17685-/*
17686- * macros/functions for gaining access to the thread information structure
17687- *
17688- * preempt_count needs to be 1 initially, until the scheduler is functional.
17689- */
17690-#ifndef __ASSEMBLY__
17691-
17692-
17693-/* how to get the current stack pointer from C */
17694-register unsigned long current_stack_pointer asm("esp") __used;
17695-
17696-/* how to get the thread information struct from C */
17697-static inline struct thread_info *current_thread_info(void)
17698-{
17699- return (struct thread_info *)
17700- (current_stack_pointer & ~(THREAD_SIZE - 1));
17701-}
17702-
17703-#else /* !__ASSEMBLY__ */
17704-
17705+#ifdef __ASSEMBLY__
17706 /* how to get the thread information struct from ASM */
17707 #define GET_THREAD_INFO(reg) \
17708- movl $-THREAD_SIZE, reg; \
17709- andl %esp, reg
17710+ mov PER_CPU_VAR(current_tinfo), reg
17711
17712 /* use this one if reg already contains %esp */
17713-#define GET_THREAD_INFO_WITH_ESP(reg) \
17714- andl $-THREAD_SIZE, reg
17715+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17716+#else
17717+/* how to get the thread information struct from C */
17718+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17719+
17720+static __always_inline struct thread_info *current_thread_info(void)
17721+{
17722+ return this_cpu_read_stable(current_tinfo);
17723+}
17724+#endif
17725+
17726+#ifdef CONFIG_X86_32
17727+
17728+#define STACK_WARN (THREAD_SIZE/8)
17729+/*
17730+ * macros/functions for gaining access to the thread information structure
17731+ *
17732+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17733+ */
17734+#ifndef __ASSEMBLY__
17735+
17736+/* how to get the current stack pointer from C */
17737+register unsigned long current_stack_pointer asm("esp") __used;
17738
17739 #endif
17740
17741 #else /* X86_32 */
17742
17743-#include <asm/percpu.h>
17744-#define KERNEL_STACK_OFFSET (5*8)
17745-
17746 /*
17747 * macros/functions for gaining access to the thread information structure
17748 * preempt_count needs to be 1 initially, until the scheduler is functional.
17749@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17750 #ifndef __ASSEMBLY__
17751 DECLARE_PER_CPU(unsigned long, kernel_stack);
17752
17753-static inline struct thread_info *current_thread_info(void)
17754-{
17755- struct thread_info *ti;
17756- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17757- KERNEL_STACK_OFFSET - THREAD_SIZE);
17758- return ti;
17759-}
17760-
17761-#else /* !__ASSEMBLY__ */
17762-
17763-/* how to get the thread information struct from ASM */
17764-#define GET_THREAD_INFO(reg) \
17765- movq PER_CPU_VAR(kernel_stack),reg ; \
17766- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17767-
17768-/*
17769- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17770- * a certain register (to be used in assembler memory operands).
17771- */
17772-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17773-
17774+/* how to get the current stack pointer from C */
17775+register unsigned long current_stack_pointer asm("rsp") __used;
17776 #endif
17777
17778 #endif /* !X86_32 */
17779@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17780 extern void arch_task_cache_init(void);
17781 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17782 extern void arch_release_task_struct(struct task_struct *tsk);
17783+
17784+#define __HAVE_THREAD_FUNCTIONS
17785+#define task_thread_info(task) (&(task)->tinfo)
17786+#define task_stack_page(task) ((task)->stack)
17787+#define setup_thread_stack(p, org) do {} while (0)
17788+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17789+
17790 #endif
17791 #endif /* _ASM_X86_THREAD_INFO_H */
17792diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17793index cf51200..63ff068 100644
17794--- a/arch/x86/include/asm/tlbflush.h
17795+++ b/arch/x86/include/asm/tlbflush.h
17796@@ -17,18 +17,44 @@
17797
17798 static inline void __native_flush_tlb(void)
17799 {
17800+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17801+ u64 descriptor[2];
17802+
17803+ descriptor[0] = PCID_KERNEL;
17804+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17805+ return;
17806+ }
17807+
17808+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17809+ if (static_cpu_has(X86_FEATURE_PCID)) {
17810+ unsigned int cpu = raw_get_cpu();
17811+
17812+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17813+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17814+ raw_put_cpu_no_resched();
17815+ return;
17816+ }
17817+#endif
17818+
17819 native_write_cr3(native_read_cr3());
17820 }
17821
17822 static inline void __native_flush_tlb_global_irq_disabled(void)
17823 {
17824- unsigned long cr4;
17825+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17826+ u64 descriptor[2];
17827
17828- cr4 = native_read_cr4();
17829- /* clear PGE */
17830- native_write_cr4(cr4 & ~X86_CR4_PGE);
17831- /* write old PGE again and flush TLBs */
17832- native_write_cr4(cr4);
17833+ descriptor[0] = PCID_KERNEL;
17834+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17835+ } else {
17836+ unsigned long cr4;
17837+
17838+ cr4 = native_read_cr4();
17839+ /* clear PGE */
17840+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17841+ /* write old PGE again and flush TLBs */
17842+ native_write_cr4(cr4);
17843+ }
17844 }
17845
17846 static inline void __native_flush_tlb_global(void)
17847@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17848
17849 static inline void __native_flush_tlb_single(unsigned long addr)
17850 {
17851+
17852+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17853+ u64 descriptor[2];
17854+
17855+ descriptor[0] = PCID_KERNEL;
17856+ descriptor[1] = addr;
17857+
17858+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17859+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17860+ if (addr < TASK_SIZE_MAX)
17861+ descriptor[1] += pax_user_shadow_base;
17862+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17863+ }
17864+
17865+ descriptor[0] = PCID_USER;
17866+ descriptor[1] = addr;
17867+#endif
17868+
17869+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17870+ return;
17871+ }
17872+
17873+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17874+ if (static_cpu_has(X86_FEATURE_PCID)) {
17875+ unsigned int cpu = raw_get_cpu();
17876+
17877+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17878+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17879+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17880+ raw_put_cpu_no_resched();
17881+
17882+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17883+ addr += pax_user_shadow_base;
17884+ }
17885+#endif
17886+
17887 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17888 }
17889
17890diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17891index 5ee2687..74590b9 100644
17892--- a/arch/x86/include/asm/uaccess.h
17893+++ b/arch/x86/include/asm/uaccess.h
17894@@ -7,6 +7,7 @@
17895 #include <linux/compiler.h>
17896 #include <linux/thread_info.h>
17897 #include <linux/string.h>
17898+#include <linux/sched.h>
17899 #include <asm/asm.h>
17900 #include <asm/page.h>
17901 #include <asm/smap.h>
17902@@ -29,7 +30,12 @@
17903
17904 #define get_ds() (KERNEL_DS)
17905 #define get_fs() (current_thread_info()->addr_limit)
17906+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17907+void __set_fs(mm_segment_t x);
17908+void set_fs(mm_segment_t x);
17909+#else
17910 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17911+#endif
17912
17913 #define segment_eq(a, b) ((a).seg == (b).seg)
17914
17915@@ -77,8 +83,33 @@
17916 * checks that the pointer is in the user space range - after calling
17917 * this function, memory access functions may still return -EFAULT.
17918 */
17919-#define access_ok(type, addr, size) \
17920- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17921+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17922+#define access_ok(type, addr, size) \
17923+({ \
17924+ long __size = size; \
17925+ unsigned long __addr = (unsigned long)addr; \
17926+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17927+ unsigned long __end_ao = __addr + __size - 1; \
17928+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17929+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17930+ while(__addr_ao <= __end_ao) { \
17931+ char __c_ao; \
17932+ __addr_ao += PAGE_SIZE; \
17933+ if (__size > PAGE_SIZE) \
17934+ cond_resched(); \
17935+ if (__get_user(__c_ao, (char __user *)__addr)) \
17936+ break; \
17937+ if (type != VERIFY_WRITE) { \
17938+ __addr = __addr_ao; \
17939+ continue; \
17940+ } \
17941+ if (__put_user(__c_ao, (char __user *)__addr)) \
17942+ break; \
17943+ __addr = __addr_ao; \
17944+ } \
17945+ } \
17946+ __ret_ao; \
17947+})
17948
17949 /*
17950 * The exception table consists of pairs of addresses relative to the
17951@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17952 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17953 __chk_user_ptr(ptr); \
17954 might_fault(); \
17955+ pax_open_userland(); \
17956 asm volatile("call __get_user_%P3" \
17957 : "=a" (__ret_gu), "=r" (__val_gu) \
17958 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17959 (x) = (__typeof__(*(ptr))) __val_gu; \
17960+ pax_close_userland(); \
17961 __ret_gu; \
17962 })
17963
17964@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17965 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17966 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17967
17968-
17969+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17970+#define __copyuser_seg "gs;"
17971+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17972+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17973+#else
17974+#define __copyuser_seg
17975+#define __COPYUSER_SET_ES
17976+#define __COPYUSER_RESTORE_ES
17977+#endif
17978
17979 #ifdef CONFIG_X86_32
17980 #define __put_user_asm_u64(x, addr, err, errret) \
17981 asm volatile(ASM_STAC "\n" \
17982- "1: movl %%eax,0(%2)\n" \
17983- "2: movl %%edx,4(%2)\n" \
17984+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17985+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17986 "3: " ASM_CLAC "\n" \
17987 ".section .fixup,\"ax\"\n" \
17988 "4: movl %3,%0\n" \
17989@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17990
17991 #define __put_user_asm_ex_u64(x, addr) \
17992 asm volatile(ASM_STAC "\n" \
17993- "1: movl %%eax,0(%1)\n" \
17994- "2: movl %%edx,4(%1)\n" \
17995+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
17996+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
17997 "3: " ASM_CLAC "\n" \
17998 _ASM_EXTABLE_EX(1b, 2b) \
17999 _ASM_EXTABLE_EX(2b, 3b) \
18000@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18001 __typeof__(*(ptr)) __pu_val; \
18002 __chk_user_ptr(ptr); \
18003 might_fault(); \
18004- __pu_val = x; \
18005+ __pu_val = (x); \
18006+ pax_open_userland(); \
18007 switch (sizeof(*(ptr))) { \
18008 case 1: \
18009 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18010@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18011 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18012 break; \
18013 } \
18014+ pax_close_userland(); \
18015 __ret_pu; \
18016 })
18017
18018@@ -344,8 +387,10 @@ do { \
18019 } while (0)
18020
18021 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18022+do { \
18023+ pax_open_userland(); \
18024 asm volatile(ASM_STAC "\n" \
18025- "1: mov"itype" %2,%"rtype"1\n" \
18026+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18027 "2: " ASM_CLAC "\n" \
18028 ".section .fixup,\"ax\"\n" \
18029 "3: mov %3,%0\n" \
18030@@ -353,8 +398,10 @@ do { \
18031 " jmp 2b\n" \
18032 ".previous\n" \
18033 _ASM_EXTABLE(1b, 3b) \
18034- : "=r" (err), ltype(x) \
18035- : "m" (__m(addr)), "i" (errret), "0" (err))
18036+ : "=r" (err), ltype (x) \
18037+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18038+ pax_close_userland(); \
18039+} while (0)
18040
18041 #define __get_user_size_ex(x, ptr, size) \
18042 do { \
18043@@ -378,7 +425,7 @@ do { \
18044 } while (0)
18045
18046 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18047- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18048+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18049 "2:\n" \
18050 _ASM_EXTABLE_EX(1b, 2b) \
18051 : ltype(x) : "m" (__m(addr)))
18052@@ -395,13 +442,24 @@ do { \
18053 int __gu_err; \
18054 unsigned long __gu_val; \
18055 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18056- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18057+ (x) = (__typeof__(*(ptr)))__gu_val; \
18058 __gu_err; \
18059 })
18060
18061 /* FIXME: this hack is definitely wrong -AK */
18062 struct __large_struct { unsigned long buf[100]; };
18063-#define __m(x) (*(struct __large_struct __user *)(x))
18064+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18065+#define ____m(x) \
18066+({ \
18067+ unsigned long ____x = (unsigned long)(x); \
18068+ if (____x < pax_user_shadow_base) \
18069+ ____x += pax_user_shadow_base; \
18070+ (typeof(x))____x; \
18071+})
18072+#else
18073+#define ____m(x) (x)
18074+#endif
18075+#define __m(x) (*(struct __large_struct __user *)____m(x))
18076
18077 /*
18078 * Tell gcc we read from memory instead of writing: this is because
18079@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18080 * aliasing issues.
18081 */
18082 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18083+do { \
18084+ pax_open_userland(); \
18085 asm volatile(ASM_STAC "\n" \
18086- "1: mov"itype" %"rtype"1,%2\n" \
18087+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18088 "2: " ASM_CLAC "\n" \
18089 ".section .fixup,\"ax\"\n" \
18090 "3: mov %3,%0\n" \
18091@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18092 ".previous\n" \
18093 _ASM_EXTABLE(1b, 3b) \
18094 : "=r"(err) \
18095- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18096+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18097+ pax_close_userland(); \
18098+} while (0)
18099
18100 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18101- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18102+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18103 "2:\n" \
18104 _ASM_EXTABLE_EX(1b, 2b) \
18105 : : ltype(x), "m" (__m(addr)))
18106@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18107 */
18108 #define uaccess_try do { \
18109 current_thread_info()->uaccess_err = 0; \
18110+ pax_open_userland(); \
18111 stac(); \
18112 barrier();
18113
18114 #define uaccess_catch(err) \
18115 clac(); \
18116+ pax_close_userland(); \
18117 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18118 } while (0)
18119
18120@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18121 * On error, the variable @x is set to zero.
18122 */
18123
18124+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18125+#define __get_user(x, ptr) get_user((x), (ptr))
18126+#else
18127 #define __get_user(x, ptr) \
18128 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18129+#endif
18130
18131 /**
18132 * __put_user: - Write a simple value into user space, with less checking.
18133@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18134 * Returns zero on success, or -EFAULT on error.
18135 */
18136
18137+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18138+#define __put_user(x, ptr) put_user((x), (ptr))
18139+#else
18140 #define __put_user(x, ptr) \
18141 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18142+#endif
18143
18144 #define __get_user_unaligned __get_user
18145 #define __put_user_unaligned __put_user
18146@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18147 #define get_user_ex(x, ptr) do { \
18148 unsigned long __gue_val; \
18149 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18150- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18151+ (x) = (__typeof__(*(ptr)))__gue_val; \
18152 } while (0)
18153
18154 #define put_user_try uaccess_try
18155@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18156 extern __must_check long strlen_user(const char __user *str);
18157 extern __must_check long strnlen_user(const char __user *str, long n);
18158
18159-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18160-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18161+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18162+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18163
18164 /*
18165 * movsl can be slow when source and dest are not both 8-byte aligned
18166diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18167index 7f760a9..04b1c65 100644
18168--- a/arch/x86/include/asm/uaccess_32.h
18169+++ b/arch/x86/include/asm/uaccess_32.h
18170@@ -11,15 +11,15 @@
18171 #include <asm/page.h>
18172
18173 unsigned long __must_check __copy_to_user_ll
18174- (void __user *to, const void *from, unsigned long n);
18175+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18176 unsigned long __must_check __copy_from_user_ll
18177- (void *to, const void __user *from, unsigned long n);
18178+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18179 unsigned long __must_check __copy_from_user_ll_nozero
18180- (void *to, const void __user *from, unsigned long n);
18181+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18182 unsigned long __must_check __copy_from_user_ll_nocache
18183- (void *to, const void __user *from, unsigned long n);
18184+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18185 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18186- (void *to, const void __user *from, unsigned long n);
18187+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18188
18189 /**
18190 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18191@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18192 static __always_inline unsigned long __must_check
18193 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18194 {
18195+ if ((long)n < 0)
18196+ return n;
18197+
18198+ check_object_size(from, n, true);
18199+
18200 if (__builtin_constant_p(n)) {
18201 unsigned long ret;
18202
18203@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18204 __copy_to_user(void __user *to, const void *from, unsigned long n)
18205 {
18206 might_fault();
18207+
18208 return __copy_to_user_inatomic(to, from, n);
18209 }
18210
18211 static __always_inline unsigned long
18212 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18213 {
18214+ if ((long)n < 0)
18215+ return n;
18216+
18217 /* Avoid zeroing the tail if the copy fails..
18218 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18219 * but as the zeroing behaviour is only significant when n is not
18220@@ -137,6 +146,12 @@ static __always_inline unsigned long
18221 __copy_from_user(void *to, const void __user *from, unsigned long n)
18222 {
18223 might_fault();
18224+
18225+ if ((long)n < 0)
18226+ return n;
18227+
18228+ check_object_size(to, n, false);
18229+
18230 if (__builtin_constant_p(n)) {
18231 unsigned long ret;
18232
18233@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18234 const void __user *from, unsigned long n)
18235 {
18236 might_fault();
18237+
18238+ if ((long)n < 0)
18239+ return n;
18240+
18241 if (__builtin_constant_p(n)) {
18242 unsigned long ret;
18243
18244@@ -181,15 +200,19 @@ static __always_inline unsigned long
18245 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18246 unsigned long n)
18247 {
18248- return __copy_from_user_ll_nocache_nozero(to, from, n);
18249+ if ((long)n < 0)
18250+ return n;
18251+
18252+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18253 }
18254
18255-unsigned long __must_check copy_to_user(void __user *to,
18256- const void *from, unsigned long n);
18257-unsigned long __must_check _copy_from_user(void *to,
18258- const void __user *from,
18259- unsigned long n);
18260-
18261+extern void copy_to_user_overflow(void)
18262+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18263+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18264+#else
18265+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18266+#endif
18267+;
18268
18269 extern void copy_from_user_overflow(void)
18270 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18271@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18272 #endif
18273 ;
18274
18275-static inline unsigned long __must_check copy_from_user(void *to,
18276- const void __user *from,
18277- unsigned long n)
18278+/**
18279+ * copy_to_user: - Copy a block of data into user space.
18280+ * @to: Destination address, in user space.
18281+ * @from: Source address, in kernel space.
18282+ * @n: Number of bytes to copy.
18283+ *
18284+ * Context: User context only. This function may sleep.
18285+ *
18286+ * Copy data from kernel space to user space.
18287+ *
18288+ * Returns number of bytes that could not be copied.
18289+ * On success, this will be zero.
18290+ */
18291+static inline unsigned long __must_check
18292+copy_to_user(void __user *to, const void *from, unsigned long n)
18293 {
18294- int sz = __compiletime_object_size(to);
18295+ size_t sz = __compiletime_object_size(from);
18296
18297- if (likely(sz == -1 || sz >= n))
18298- n = _copy_from_user(to, from, n);
18299- else
18300+ if (unlikely(sz != (size_t)-1 && sz < n))
18301+ copy_to_user_overflow();
18302+ else if (access_ok(VERIFY_WRITE, to, n))
18303+ n = __copy_to_user(to, from, n);
18304+ return n;
18305+}
18306+
18307+/**
18308+ * copy_from_user: - Copy a block of data from user space.
18309+ * @to: Destination address, in kernel space.
18310+ * @from: Source address, in user space.
18311+ * @n: Number of bytes to copy.
18312+ *
18313+ * Context: User context only. This function may sleep.
18314+ *
18315+ * Copy data from user space to kernel space.
18316+ *
18317+ * Returns number of bytes that could not be copied.
18318+ * On success, this will be zero.
18319+ *
18320+ * If some data could not be copied, this function will pad the copied
18321+ * data to the requested size using zero bytes.
18322+ */
18323+static inline unsigned long __must_check
18324+copy_from_user(void *to, const void __user *from, unsigned long n)
18325+{
18326+ size_t sz = __compiletime_object_size(to);
18327+
18328+ check_object_size(to, n, false);
18329+
18330+ if (unlikely(sz != (size_t)-1 && sz < n))
18331 copy_from_user_overflow();
18332-
18333+ else if (access_ok(VERIFY_READ, from, n))
18334+ n = __copy_from_user(to, from, n);
18335+ else if ((long)n > 0)
18336+ memset(to, 0, n);
18337 return n;
18338 }
18339
18340diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18341index 4f7923d..20cb24e 100644
18342--- a/arch/x86/include/asm/uaccess_64.h
18343+++ b/arch/x86/include/asm/uaccess_64.h
18344@@ -10,6 +10,9 @@
18345 #include <asm/alternative.h>
18346 #include <asm/cpufeature.h>
18347 #include <asm/page.h>
18348+#include <asm/pgtable.h>
18349+
18350+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18351
18352 /*
18353 * Copy To/From Userspace
18354@@ -17,13 +20,13 @@
18355
18356 /* Handles exceptions in both to and from, but doesn't do access_ok */
18357 __must_check unsigned long
18358-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18359+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18360 __must_check unsigned long
18361-copy_user_generic_string(void *to, const void *from, unsigned len);
18362+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18363 __must_check unsigned long
18364-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18365+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18366
18367-static __always_inline __must_check unsigned long
18368+static __always_inline __must_check __size_overflow(3) unsigned long
18369 copy_user_generic(void *to, const void *from, unsigned len)
18370 {
18371 unsigned ret;
18372@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18373 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18374 "=d" (len)),
18375 "1" (to), "2" (from), "3" (len)
18376- : "memory", "rcx", "r8", "r9", "r10", "r11");
18377+ : "memory", "rcx", "r8", "r9", "r11");
18378 return ret;
18379 }
18380
18381+static __always_inline __must_check unsigned long
18382+__copy_to_user(void __user *to, const void *from, unsigned long len);
18383+static __always_inline __must_check unsigned long
18384+__copy_from_user(void *to, const void __user *from, unsigned long len);
18385 __must_check unsigned long
18386-_copy_to_user(void __user *to, const void *from, unsigned len);
18387-__must_check unsigned long
18388-_copy_from_user(void *to, const void __user *from, unsigned len);
18389-__must_check unsigned long
18390-copy_in_user(void __user *to, const void __user *from, unsigned len);
18391+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18392+
18393+extern void copy_to_user_overflow(void)
18394+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18395+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18396+#else
18397+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18398+#endif
18399+;
18400+
18401+extern void copy_from_user_overflow(void)
18402+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18403+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18404+#else
18405+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18406+#endif
18407+;
18408
18409 static inline unsigned long __must_check copy_from_user(void *to,
18410 const void __user *from,
18411 unsigned long n)
18412 {
18413- int sz = __compiletime_object_size(to);
18414-
18415 might_fault();
18416- if (likely(sz == -1 || sz >= n))
18417- n = _copy_from_user(to, from, n);
18418-#ifdef CONFIG_DEBUG_VM
18419- else
18420- WARN(1, "Buffer overflow detected!\n");
18421-#endif
18422+
18423+ check_object_size(to, n, false);
18424+
18425+ if (access_ok(VERIFY_READ, from, n))
18426+ n = __copy_from_user(to, from, n);
18427+ else if (n < INT_MAX)
18428+ memset(to, 0, n);
18429 return n;
18430 }
18431
18432 static __always_inline __must_check
18433-int copy_to_user(void __user *dst, const void *src, unsigned size)
18434+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18435 {
18436 might_fault();
18437
18438- return _copy_to_user(dst, src, size);
18439+ if (access_ok(VERIFY_WRITE, dst, size))
18440+ size = __copy_to_user(dst, src, size);
18441+ return size;
18442 }
18443
18444 static __always_inline __must_check
18445-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18446+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18447 {
18448- int ret = 0;
18449+ size_t sz = __compiletime_object_size(dst);
18450+ unsigned ret = 0;
18451
18452 might_fault();
18453+
18454+ if (size > INT_MAX)
18455+ return size;
18456+
18457+ check_object_size(dst, size, false);
18458+
18459+#ifdef CONFIG_PAX_MEMORY_UDEREF
18460+ if (!__access_ok(VERIFY_READ, src, size))
18461+ return size;
18462+#endif
18463+
18464+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18465+ copy_from_user_overflow();
18466+ return size;
18467+ }
18468+
18469 if (!__builtin_constant_p(size))
18470- return copy_user_generic(dst, (__force void *)src, size);
18471+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18472 switch (size) {
18473- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18474+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18475 ret, "b", "b", "=q", 1);
18476 return ret;
18477- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18478+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18479 ret, "w", "w", "=r", 2);
18480 return ret;
18481- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18482+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18483 ret, "l", "k", "=r", 4);
18484 return ret;
18485- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18486+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18487 ret, "q", "", "=r", 8);
18488 return ret;
18489 case 10:
18490- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18491+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18492 ret, "q", "", "=r", 10);
18493 if (unlikely(ret))
18494 return ret;
18495 __get_user_asm(*(u16 *)(8 + (char *)dst),
18496- (u16 __user *)(8 + (char __user *)src),
18497+ (const u16 __user *)(8 + (const char __user *)src),
18498 ret, "w", "w", "=r", 2);
18499 return ret;
18500 case 16:
18501- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18502+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18503 ret, "q", "", "=r", 16);
18504 if (unlikely(ret))
18505 return ret;
18506 __get_user_asm(*(u64 *)(8 + (char *)dst),
18507- (u64 __user *)(8 + (char __user *)src),
18508+ (const u64 __user *)(8 + (const char __user *)src),
18509 ret, "q", "", "=r", 8);
18510 return ret;
18511 default:
18512- return copy_user_generic(dst, (__force void *)src, size);
18513+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18514 }
18515 }
18516
18517 static __always_inline __must_check
18518-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18519+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18520 {
18521- int ret = 0;
18522+ size_t sz = __compiletime_object_size(src);
18523+ unsigned ret = 0;
18524
18525 might_fault();
18526+
18527+ if (size > INT_MAX)
18528+ return size;
18529+
18530+ check_object_size(src, size, true);
18531+
18532+#ifdef CONFIG_PAX_MEMORY_UDEREF
18533+ if (!__access_ok(VERIFY_WRITE, dst, size))
18534+ return size;
18535+#endif
18536+
18537+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18538+ copy_to_user_overflow();
18539+ return size;
18540+ }
18541+
18542 if (!__builtin_constant_p(size))
18543- return copy_user_generic((__force void *)dst, src, size);
18544+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18545 switch (size) {
18546- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18547+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18548 ret, "b", "b", "iq", 1);
18549 return ret;
18550- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18551+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18552 ret, "w", "w", "ir", 2);
18553 return ret;
18554- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18555+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18556 ret, "l", "k", "ir", 4);
18557 return ret;
18558- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18559+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18560 ret, "q", "", "er", 8);
18561 return ret;
18562 case 10:
18563- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18564+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18565 ret, "q", "", "er", 10);
18566 if (unlikely(ret))
18567 return ret;
18568 asm("":::"memory");
18569- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18570+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18571 ret, "w", "w", "ir", 2);
18572 return ret;
18573 case 16:
18574- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18575+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18576 ret, "q", "", "er", 16);
18577 if (unlikely(ret))
18578 return ret;
18579 asm("":::"memory");
18580- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18581+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18582 ret, "q", "", "er", 8);
18583 return ret;
18584 default:
18585- return copy_user_generic((__force void *)dst, src, size);
18586+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18587 }
18588 }
18589
18590 static __always_inline __must_check
18591-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18592+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18593 {
18594- int ret = 0;
18595+ unsigned ret = 0;
18596
18597 might_fault();
18598+
18599+ if (size > INT_MAX)
18600+ return size;
18601+
18602+#ifdef CONFIG_PAX_MEMORY_UDEREF
18603+ if (!__access_ok(VERIFY_READ, src, size))
18604+ return size;
18605+ if (!__access_ok(VERIFY_WRITE, dst, size))
18606+ return size;
18607+#endif
18608+
18609 if (!__builtin_constant_p(size))
18610- return copy_user_generic((__force void *)dst,
18611- (__force void *)src, size);
18612+ return copy_user_generic((__force_kernel void *)____m(dst),
18613+ (__force_kernel const void *)____m(src), size);
18614 switch (size) {
18615 case 1: {
18616 u8 tmp;
18617- __get_user_asm(tmp, (u8 __user *)src,
18618+ __get_user_asm(tmp, (const u8 __user *)src,
18619 ret, "b", "b", "=q", 1);
18620 if (likely(!ret))
18621 __put_user_asm(tmp, (u8 __user *)dst,
18622@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18623 }
18624 case 2: {
18625 u16 tmp;
18626- __get_user_asm(tmp, (u16 __user *)src,
18627+ __get_user_asm(tmp, (const u16 __user *)src,
18628 ret, "w", "w", "=r", 2);
18629 if (likely(!ret))
18630 __put_user_asm(tmp, (u16 __user *)dst,
18631@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18632
18633 case 4: {
18634 u32 tmp;
18635- __get_user_asm(tmp, (u32 __user *)src,
18636+ __get_user_asm(tmp, (const u32 __user *)src,
18637 ret, "l", "k", "=r", 4);
18638 if (likely(!ret))
18639 __put_user_asm(tmp, (u32 __user *)dst,
18640@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18641 }
18642 case 8: {
18643 u64 tmp;
18644- __get_user_asm(tmp, (u64 __user *)src,
18645+ __get_user_asm(tmp, (const u64 __user *)src,
18646 ret, "q", "", "=r", 8);
18647 if (likely(!ret))
18648 __put_user_asm(tmp, (u64 __user *)dst,
18649@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18650 return ret;
18651 }
18652 default:
18653- return copy_user_generic((__force void *)dst,
18654- (__force void *)src, size);
18655+ return copy_user_generic((__force_kernel void *)____m(dst),
18656+ (__force_kernel const void *)____m(src), size);
18657 }
18658 }
18659
18660-static __must_check __always_inline int
18661-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18662+static __must_check __always_inline unsigned long
18663+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18664 {
18665- return copy_user_generic(dst, (__force const void *)src, size);
18666+ if (size > INT_MAX)
18667+ return size;
18668+
18669+#ifdef CONFIG_PAX_MEMORY_UDEREF
18670+ if (!__access_ok(VERIFY_READ, src, size))
18671+ return size;
18672+#endif
18673+
18674+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18675 }
18676
18677-static __must_check __always_inline int
18678-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18679+static __must_check __always_inline unsigned long
18680+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18681 {
18682- return copy_user_generic((__force void *)dst, src, size);
18683+ if (size > INT_MAX)
18684+ return size;
18685+
18686+#ifdef CONFIG_PAX_MEMORY_UDEREF
18687+ if (!__access_ok(VERIFY_WRITE, dst, size))
18688+ return size;
18689+#endif
18690+
18691+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18692 }
18693
18694-extern long __copy_user_nocache(void *dst, const void __user *src,
18695- unsigned size, int zerorest);
18696+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18697+ unsigned long size, int zerorest) __size_overflow(3);
18698
18699-static inline int
18700-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18701+static inline unsigned long
18702+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18703 {
18704 might_fault();
18705+
18706+ if (size > INT_MAX)
18707+ return size;
18708+
18709+#ifdef CONFIG_PAX_MEMORY_UDEREF
18710+ if (!__access_ok(VERIFY_READ, src, size))
18711+ return size;
18712+#endif
18713+
18714 return __copy_user_nocache(dst, src, size, 1);
18715 }
18716
18717-static inline int
18718+static inline unsigned long
18719 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18720- unsigned size)
18721+ unsigned long size)
18722 {
18723+ if (size > INT_MAX)
18724+ return size;
18725+
18726+#ifdef CONFIG_PAX_MEMORY_UDEREF
18727+ if (!__access_ok(VERIFY_READ, src, size))
18728+ return size;
18729+#endif
18730+
18731 return __copy_user_nocache(dst, src, size, 0);
18732 }
18733
18734 unsigned long
18735-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18736+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18737
18738 #endif /* _ASM_X86_UACCESS_64_H */
18739diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18740index 5b238981..77fdd78 100644
18741--- a/arch/x86/include/asm/word-at-a-time.h
18742+++ b/arch/x86/include/asm/word-at-a-time.h
18743@@ -11,7 +11,7 @@
18744 * and shift, for example.
18745 */
18746 struct word_at_a_time {
18747- const unsigned long one_bits, high_bits;
18748+ unsigned long one_bits, high_bits;
18749 };
18750
18751 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18752diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18753index 828a156..650e625 100644
18754--- a/arch/x86/include/asm/x86_init.h
18755+++ b/arch/x86/include/asm/x86_init.h
18756@@ -129,7 +129,7 @@ struct x86_init_ops {
18757 struct x86_init_timers timers;
18758 struct x86_init_iommu iommu;
18759 struct x86_init_pci pci;
18760-};
18761+} __no_const;
18762
18763 /**
18764 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18765@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18766 void (*setup_percpu_clockev)(void);
18767 void (*early_percpu_clock_init)(void);
18768 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18769-};
18770+} __no_const;
18771
18772 struct timespec;
18773
18774@@ -168,7 +168,7 @@ struct x86_platform_ops {
18775 void (*save_sched_clock_state)(void);
18776 void (*restore_sched_clock_state)(void);
18777 void (*apic_post_init)(void);
18778-};
18779+} __no_const;
18780
18781 struct pci_dev;
18782 struct msi_msg;
18783@@ -182,7 +182,7 @@ struct x86_msi_ops {
18784 void (*teardown_msi_irqs)(struct pci_dev *dev);
18785 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18786 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18787-};
18788+} __no_const;
18789
18790 struct IO_APIC_route_entry;
18791 struct io_apic_irq_attr;
18792@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18793 unsigned int destination, int vector,
18794 struct io_apic_irq_attr *attr);
18795 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18796-};
18797+} __no_const;
18798
18799 extern struct x86_init_ops x86_init;
18800 extern struct x86_cpuinit_ops x86_cpuinit;
18801diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18802index 0415cda..3b22adc 100644
18803--- a/arch/x86/include/asm/xsave.h
18804+++ b/arch/x86/include/asm/xsave.h
18805@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18806 if (unlikely(err))
18807 return -EFAULT;
18808
18809+ pax_open_userland();
18810 __asm__ __volatile__(ASM_STAC "\n"
18811- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18812+ "1:"
18813+ __copyuser_seg
18814+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18815 "2: " ASM_CLAC "\n"
18816 ".section .fixup,\"ax\"\n"
18817 "3: movl $-1,%[err]\n"
18818@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18819 : [err] "=r" (err)
18820 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18821 : "memory");
18822+ pax_close_userland();
18823 return err;
18824 }
18825
18826 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18827 {
18828 int err;
18829- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18830+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18831 u32 lmask = mask;
18832 u32 hmask = mask >> 32;
18833
18834+ pax_open_userland();
18835 __asm__ __volatile__(ASM_STAC "\n"
18836- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18837+ "1:"
18838+ __copyuser_seg
18839+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18840 "2: " ASM_CLAC "\n"
18841 ".section .fixup,\"ax\"\n"
18842 "3: movl $-1,%[err]\n"
18843@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18844 : [err] "=r" (err)
18845 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18846 : "memory"); /* memory required? */
18847+ pax_close_userland();
18848 return err;
18849 }
18850
18851diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18852index bbae024..e1528f9 100644
18853--- a/arch/x86/include/uapi/asm/e820.h
18854+++ b/arch/x86/include/uapi/asm/e820.h
18855@@ -63,7 +63,7 @@ struct e820map {
18856 #define ISA_START_ADDRESS 0xa0000
18857 #define ISA_END_ADDRESS 0x100000
18858
18859-#define BIOS_BEGIN 0x000a0000
18860+#define BIOS_BEGIN 0x000c0000
18861 #define BIOS_END 0x00100000
18862
18863 #define BIOS_ROM_BASE 0xffe00000
18864diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18865index 88d99ea..9fc7e17 100644
18866--- a/arch/x86/kernel/Makefile
18867+++ b/arch/x86/kernel/Makefile
18868@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18869 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18870 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18871 obj-y += probe_roms.o
18872-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18873+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18874 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18875 obj-y += syscall_$(BITS).o
18876 obj-$(CONFIG_X86_64) += vsyscall_64.o
18877diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18878index 2627a81..cd8325e 100644
18879--- a/arch/x86/kernel/acpi/boot.c
18880+++ b/arch/x86/kernel/acpi/boot.c
18881@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18882 * If your system is blacklisted here, but you find that acpi=force
18883 * works for you, please contact linux-acpi@vger.kernel.org
18884 */
18885-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18886+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18887 /*
18888 * Boxes that need ACPI disabled
18889 */
18890@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18891 };
18892
18893 /* second table for DMI checks that should run after early-quirks */
18894-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18895+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18896 /*
18897 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18898 * which includes some code which overrides all temperature
18899diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18900index 3312010..a65ca7b 100644
18901--- a/arch/x86/kernel/acpi/sleep.c
18902+++ b/arch/x86/kernel/acpi/sleep.c
18903@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18904 #else /* CONFIG_64BIT */
18905 #ifdef CONFIG_SMP
18906 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18907+
18908+ pax_open_kernel();
18909 early_gdt_descr.address =
18910 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18911+ pax_close_kernel();
18912+
18913 initial_gs = per_cpu_offset(smp_processor_id());
18914 #endif
18915 initial_code = (unsigned long)wakeup_long64;
18916diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18917index d1daa66..59fecba 100644
18918--- a/arch/x86/kernel/acpi/wakeup_32.S
18919+++ b/arch/x86/kernel/acpi/wakeup_32.S
18920@@ -29,13 +29,11 @@ wakeup_pmode_return:
18921 # and restore the stack ... but you need gdt for this to work
18922 movl saved_context_esp, %esp
18923
18924- movl %cs:saved_magic, %eax
18925- cmpl $0x12345678, %eax
18926+ cmpl $0x12345678, saved_magic
18927 jne bogus_magic
18928
18929 # jump to place where we left off
18930- movl saved_eip, %eax
18931- jmp *%eax
18932+ jmp *(saved_eip)
18933
18934 bogus_magic:
18935 jmp bogus_magic
18936diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18937index c15cf9a..0e63558 100644
18938--- a/arch/x86/kernel/alternative.c
18939+++ b/arch/x86/kernel/alternative.c
18940@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18941 */
18942 for (a = start; a < end; a++) {
18943 instr = (u8 *)&a->instr_offset + a->instr_offset;
18944+
18945+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18946+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18947+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18948+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18949+#endif
18950+
18951 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18952 BUG_ON(a->replacementlen > a->instrlen);
18953 BUG_ON(a->instrlen > sizeof(insnbuf));
18954@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18955 for (poff = start; poff < end; poff++) {
18956 u8 *ptr = (u8 *)poff + *poff;
18957
18958+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18959+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18960+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18961+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18962+#endif
18963+
18964 if (!*poff || ptr < text || ptr >= text_end)
18965 continue;
18966 /* turn DS segment override prefix into lock prefix */
18967- if (*ptr == 0x3e)
18968+ if (*ktla_ktva(ptr) == 0x3e)
18969 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18970 }
18971 mutex_unlock(&text_mutex);
18972@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18973 for (poff = start; poff < end; poff++) {
18974 u8 *ptr = (u8 *)poff + *poff;
18975
18976+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18977+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18978+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18979+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18980+#endif
18981+
18982 if (!*poff || ptr < text || ptr >= text_end)
18983 continue;
18984 /* turn lock prefix into DS segment override prefix */
18985- if (*ptr == 0xf0)
18986+ if (*ktla_ktva(ptr) == 0xf0)
18987 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18988 }
18989 mutex_unlock(&text_mutex);
18990@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18991
18992 BUG_ON(p->len > MAX_PATCH_LEN);
18993 /* prep the buffer with the original instructions */
18994- memcpy(insnbuf, p->instr, p->len);
18995+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
18996 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
18997 (unsigned long)p->instr, p->len);
18998
18999@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19000 if (!uniproc_patched || num_possible_cpus() == 1)
19001 free_init_pages("SMP alternatives",
19002 (unsigned long)__smp_locks,
19003- (unsigned long)__smp_locks_end);
19004+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19005 #endif
19006
19007 apply_paravirt(__parainstructions, __parainstructions_end);
19008@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19009 * instructions. And on the local CPU you need to be protected again NMI or MCE
19010 * handlers seeing an inconsistent instruction while you patch.
19011 */
19012-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19013+void *__kprobes text_poke_early(void *addr, const void *opcode,
19014 size_t len)
19015 {
19016 unsigned long flags;
19017 local_irq_save(flags);
19018- memcpy(addr, opcode, len);
19019+
19020+ pax_open_kernel();
19021+ memcpy(ktla_ktva(addr), opcode, len);
19022 sync_core();
19023+ pax_close_kernel();
19024+
19025 local_irq_restore(flags);
19026 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19027 that causes hangs on some VIA CPUs. */
19028@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19029 */
19030 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19031 {
19032- unsigned long flags;
19033- char *vaddr;
19034+ unsigned char *vaddr = ktla_ktva(addr);
19035 struct page *pages[2];
19036- int i;
19037+ size_t i;
19038
19039 if (!core_kernel_text((unsigned long)addr)) {
19040- pages[0] = vmalloc_to_page(addr);
19041- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19042+ pages[0] = vmalloc_to_page(vaddr);
19043+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19044 } else {
19045- pages[0] = virt_to_page(addr);
19046+ pages[0] = virt_to_page(vaddr);
19047 WARN_ON(!PageReserved(pages[0]));
19048- pages[1] = virt_to_page(addr + PAGE_SIZE);
19049+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19050 }
19051 BUG_ON(!pages[0]);
19052- local_irq_save(flags);
19053- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19054- if (pages[1])
19055- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19056- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19057- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19058- clear_fixmap(FIX_TEXT_POKE0);
19059- if (pages[1])
19060- clear_fixmap(FIX_TEXT_POKE1);
19061- local_flush_tlb();
19062- sync_core();
19063- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19064- that causes hangs on some VIA CPUs. */
19065+ text_poke_early(addr, opcode, len);
19066 for (i = 0; i < len; i++)
19067- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19068- local_irq_restore(flags);
19069+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19070 return addr;
19071 }
19072
19073diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19074index eca89c5..d566b78 100644
19075--- a/arch/x86/kernel/apic/apic.c
19076+++ b/arch/x86/kernel/apic/apic.c
19077@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19078 /*
19079 * Debug level, exported for io_apic.c
19080 */
19081-unsigned int apic_verbosity;
19082+int apic_verbosity;
19083
19084 int pic_mode;
19085
19086@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19087 apic_write(APIC_ESR, 0);
19088 v1 = apic_read(APIC_ESR);
19089 ack_APIC_irq();
19090- atomic_inc(&irq_err_count);
19091+ atomic_inc_unchecked(&irq_err_count);
19092
19093 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19094 smp_processor_id(), v0 , v1);
19095diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19096index 00c77cf..2dc6a2d 100644
19097--- a/arch/x86/kernel/apic/apic_flat_64.c
19098+++ b/arch/x86/kernel/apic/apic_flat_64.c
19099@@ -157,7 +157,7 @@ static int flat_probe(void)
19100 return 1;
19101 }
19102
19103-static struct apic apic_flat = {
19104+static struct apic apic_flat __read_only = {
19105 .name = "flat",
19106 .probe = flat_probe,
19107 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19108@@ -271,7 +271,7 @@ static int physflat_probe(void)
19109 return 0;
19110 }
19111
19112-static struct apic apic_physflat = {
19113+static struct apic apic_physflat __read_only = {
19114
19115 .name = "physical flat",
19116 .probe = physflat_probe,
19117diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19118index e145f28..2752888 100644
19119--- a/arch/x86/kernel/apic/apic_noop.c
19120+++ b/arch/x86/kernel/apic/apic_noop.c
19121@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19122 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19123 }
19124
19125-struct apic apic_noop = {
19126+struct apic apic_noop __read_only = {
19127 .name = "noop",
19128 .probe = noop_probe,
19129 .acpi_madt_oem_check = NULL,
19130diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19131index d50e364..543bee3 100644
19132--- a/arch/x86/kernel/apic/bigsmp_32.c
19133+++ b/arch/x86/kernel/apic/bigsmp_32.c
19134@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19135 return dmi_bigsmp;
19136 }
19137
19138-static struct apic apic_bigsmp = {
19139+static struct apic apic_bigsmp __read_only = {
19140
19141 .name = "bigsmp",
19142 .probe = probe_bigsmp,
19143diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19144index c552247..587a316 100644
19145--- a/arch/x86/kernel/apic/es7000_32.c
19146+++ b/arch/x86/kernel/apic/es7000_32.c
19147@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19148 return ret && es7000_apic_is_cluster();
19149 }
19150
19151-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19152-static struct apic __refdata apic_es7000_cluster = {
19153+static struct apic apic_es7000_cluster __read_only = {
19154
19155 .name = "es7000",
19156 .probe = probe_es7000,
19157@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19158 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19159 };
19160
19161-static struct apic __refdata apic_es7000 = {
19162+static struct apic apic_es7000 __read_only = {
19163
19164 .name = "es7000",
19165 .probe = probe_es7000,
19166diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19167index 9ed796c..e930fe4 100644
19168--- a/arch/x86/kernel/apic/io_apic.c
19169+++ b/arch/x86/kernel/apic/io_apic.c
19170@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19171 }
19172 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19173
19174-void lock_vector_lock(void)
19175+void lock_vector_lock(void) __acquires(vector_lock)
19176 {
19177 /* Used to the online set of cpus does not change
19178 * during assign_irq_vector.
19179@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19180 raw_spin_lock(&vector_lock);
19181 }
19182
19183-void unlock_vector_lock(void)
19184+void unlock_vector_lock(void) __releases(vector_lock)
19185 {
19186 raw_spin_unlock(&vector_lock);
19187 }
19188@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19189 ack_APIC_irq();
19190 }
19191
19192-atomic_t irq_mis_count;
19193+atomic_unchecked_t irq_mis_count;
19194
19195 #ifdef CONFIG_GENERIC_PENDING_IRQ
19196 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19197@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19198 * at the cpu.
19199 */
19200 if (!(v & (1 << (i & 0x1f)))) {
19201- atomic_inc(&irq_mis_count);
19202+ atomic_inc_unchecked(&irq_mis_count);
19203
19204 eoi_ioapic_irq(irq, cfg);
19205 }
19206diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19207index 1e42e8f..daacf44 100644
19208--- a/arch/x86/kernel/apic/numaq_32.c
19209+++ b/arch/x86/kernel/apic/numaq_32.c
19210@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19211 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19212 }
19213
19214-/* Use __refdata to keep false positive warning calm. */
19215-static struct apic __refdata apic_numaq = {
19216+static struct apic apic_numaq __read_only = {
19217
19218 .name = "NUMAQ",
19219 .probe = probe_numaq,
19220diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19221index eb35ef9..f184a21 100644
19222--- a/arch/x86/kernel/apic/probe_32.c
19223+++ b/arch/x86/kernel/apic/probe_32.c
19224@@ -72,7 +72,7 @@ static int probe_default(void)
19225 return 1;
19226 }
19227
19228-static struct apic apic_default = {
19229+static struct apic apic_default __read_only = {
19230
19231 .name = "default",
19232 .probe = probe_default,
19233diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19234index 77c95c0..434f8a4 100644
19235--- a/arch/x86/kernel/apic/summit_32.c
19236+++ b/arch/x86/kernel/apic/summit_32.c
19237@@ -486,7 +486,7 @@ void setup_summit(void)
19238 }
19239 #endif
19240
19241-static struct apic apic_summit = {
19242+static struct apic apic_summit __read_only = {
19243
19244 .name = "summit",
19245 .probe = probe_summit,
19246diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19247index 140e29d..d88bc95 100644
19248--- a/arch/x86/kernel/apic/x2apic_cluster.c
19249+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19250@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19251 return notifier_from_errno(err);
19252 }
19253
19254-static struct notifier_block __refdata x2apic_cpu_notifier = {
19255+static struct notifier_block x2apic_cpu_notifier = {
19256 .notifier_call = update_clusterinfo,
19257 };
19258
19259@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19260 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19261 }
19262
19263-static struct apic apic_x2apic_cluster = {
19264+static struct apic apic_x2apic_cluster __read_only = {
19265
19266 .name = "cluster x2apic",
19267 .probe = x2apic_cluster_probe,
19268diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19269index 562a76d..a003c0f 100644
19270--- a/arch/x86/kernel/apic/x2apic_phys.c
19271+++ b/arch/x86/kernel/apic/x2apic_phys.c
19272@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19273 return apic == &apic_x2apic_phys;
19274 }
19275
19276-static struct apic apic_x2apic_phys = {
19277+static struct apic apic_x2apic_phys __read_only = {
19278
19279 .name = "physical x2apic",
19280 .probe = x2apic_phys_probe,
19281diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19282index 1191ac1..2335fa4 100644
19283--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19284+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19285@@ -357,7 +357,7 @@ static int uv_probe(void)
19286 return apic == &apic_x2apic_uv_x;
19287 }
19288
19289-static struct apic __refdata apic_x2apic_uv_x = {
19290+static struct apic apic_x2apic_uv_x __read_only = {
19291
19292 .name = "UV large system",
19293 .probe = uv_probe,
19294diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19295index 53a4e27..038760a 100644
19296--- a/arch/x86/kernel/apm_32.c
19297+++ b/arch/x86/kernel/apm_32.c
19298@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19299 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19300 * even though they are called in protected mode.
19301 */
19302-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19303+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19304 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19305
19306 static const char driver_version[] = "1.16ac"; /* no spaces */
19307@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19308 BUG_ON(cpu != 0);
19309 gdt = get_cpu_gdt_table(cpu);
19310 save_desc_40 = gdt[0x40 / 8];
19311+
19312+ pax_open_kernel();
19313 gdt[0x40 / 8] = bad_bios_desc;
19314+ pax_close_kernel();
19315
19316 apm_irq_save(flags);
19317 APM_DO_SAVE_SEGS;
19318@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19319 &call->esi);
19320 APM_DO_RESTORE_SEGS;
19321 apm_irq_restore(flags);
19322+
19323+ pax_open_kernel();
19324 gdt[0x40 / 8] = save_desc_40;
19325+ pax_close_kernel();
19326+
19327 put_cpu();
19328
19329 return call->eax & 0xff;
19330@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19331 BUG_ON(cpu != 0);
19332 gdt = get_cpu_gdt_table(cpu);
19333 save_desc_40 = gdt[0x40 / 8];
19334+
19335+ pax_open_kernel();
19336 gdt[0x40 / 8] = bad_bios_desc;
19337+ pax_close_kernel();
19338
19339 apm_irq_save(flags);
19340 APM_DO_SAVE_SEGS;
19341@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19342 &call->eax);
19343 APM_DO_RESTORE_SEGS;
19344 apm_irq_restore(flags);
19345+
19346+ pax_open_kernel();
19347 gdt[0x40 / 8] = save_desc_40;
19348+ pax_close_kernel();
19349+
19350 put_cpu();
19351 return error;
19352 }
19353@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19354 * code to that CPU.
19355 */
19356 gdt = get_cpu_gdt_table(0);
19357+
19358+ pax_open_kernel();
19359 set_desc_base(&gdt[APM_CS >> 3],
19360 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19361 set_desc_base(&gdt[APM_CS_16 >> 3],
19362 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19363 set_desc_base(&gdt[APM_DS >> 3],
19364 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19365+ pax_close_kernel();
19366
19367 proc_create("apm", 0, NULL, &apm_file_ops);
19368
19369diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19370index 2861082..6d4718e 100644
19371--- a/arch/x86/kernel/asm-offsets.c
19372+++ b/arch/x86/kernel/asm-offsets.c
19373@@ -33,6 +33,8 @@ void common(void) {
19374 OFFSET(TI_status, thread_info, status);
19375 OFFSET(TI_addr_limit, thread_info, addr_limit);
19376 OFFSET(TI_preempt_count, thread_info, preempt_count);
19377+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19378+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19379
19380 BLANK();
19381 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19382@@ -53,8 +55,26 @@ void common(void) {
19383 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19384 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19385 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19386+
19387+#ifdef CONFIG_PAX_KERNEXEC
19388+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19389 #endif
19390
19391+#ifdef CONFIG_PAX_MEMORY_UDEREF
19392+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19393+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19394+#ifdef CONFIG_X86_64
19395+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19396+#endif
19397+#endif
19398+
19399+#endif
19400+
19401+ BLANK();
19402+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19403+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19404+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19405+
19406 #ifdef CONFIG_XEN
19407 BLANK();
19408 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19409diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19410index e7c798b..2b2019b 100644
19411--- a/arch/x86/kernel/asm-offsets_64.c
19412+++ b/arch/x86/kernel/asm-offsets_64.c
19413@@ -77,6 +77,7 @@ int main(void)
19414 BLANK();
19415 #undef ENTRY
19416
19417+ DEFINE(TSS_size, sizeof(struct tss_struct));
19418 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19419 BLANK();
19420
19421diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19422index 47b56a7..efc2bc6 100644
19423--- a/arch/x86/kernel/cpu/Makefile
19424+++ b/arch/x86/kernel/cpu/Makefile
19425@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19426 CFLAGS_REMOVE_perf_event.o = -pg
19427 endif
19428
19429-# Make sure load_percpu_segment has no stackprotector
19430-nostackp := $(call cc-option, -fno-stack-protector)
19431-CFLAGS_common.o := $(nostackp)
19432-
19433 obj-y := intel_cacheinfo.o scattered.o topology.o
19434 obj-y += proc.o capflags.o powerflags.o common.o
19435 obj-y += rdrand.o
19436diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19437index 08a0890..e557865 100644
19438--- a/arch/x86/kernel/cpu/amd.c
19439+++ b/arch/x86/kernel/cpu/amd.c
19440@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19441 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19442 {
19443 /* AMD errata T13 (order #21922) */
19444- if ((c->x86 == 6)) {
19445+ if (c->x86 == 6) {
19446 /* Duron Rev A0 */
19447 if (c->x86_model == 3 && c->x86_mask == 0)
19448 size = 64;
19449diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19450index 25eb274..3a92d93 100644
19451--- a/arch/x86/kernel/cpu/common.c
19452+++ b/arch/x86/kernel/cpu/common.c
19453@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19454
19455 static const struct cpu_dev *this_cpu = &default_cpu;
19456
19457-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19458-#ifdef CONFIG_X86_64
19459- /*
19460- * We need valid kernel segments for data and code in long mode too
19461- * IRET will check the segment types kkeil 2000/10/28
19462- * Also sysret mandates a special GDT layout
19463- *
19464- * TLS descriptors are currently at a different place compared to i386.
19465- * Hopefully nobody expects them at a fixed place (Wine?)
19466- */
19467- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19468- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19469- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19470- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19471- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19472- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19473-#else
19474- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19475- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19476- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19477- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19478- /*
19479- * Segments used for calling PnP BIOS have byte granularity.
19480- * They code segments and data segments have fixed 64k limits,
19481- * the transfer segment sizes are set at run time.
19482- */
19483- /* 32-bit code */
19484- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19485- /* 16-bit code */
19486- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19487- /* 16-bit data */
19488- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19489- /* 16-bit data */
19490- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19491- /* 16-bit data */
19492- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19493- /*
19494- * The APM segments have byte granularity and their bases
19495- * are set at run time. All have 64k limits.
19496- */
19497- /* 32-bit code */
19498- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19499- /* 16-bit code */
19500- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19501- /* data */
19502- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19503-
19504- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19505- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19506- GDT_STACK_CANARY_INIT
19507-#endif
19508-} };
19509-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19510-
19511 static int __init x86_xsave_setup(char *s)
19512 {
19513 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19514@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19515 set_in_cr4(X86_CR4_SMAP);
19516 }
19517
19518+#ifdef CONFIG_X86_64
19519+static __init int setup_disable_pcid(char *arg)
19520+{
19521+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19522+
19523+#ifdef CONFIG_PAX_MEMORY_UDEREF
19524+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19525+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19526+#endif
19527+
19528+ return 1;
19529+}
19530+__setup("nopcid", setup_disable_pcid);
19531+
19532+static void setup_pcid(struct cpuinfo_x86 *c)
19533+{
19534+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19535+
19536+#ifdef CONFIG_PAX_MEMORY_UDEREF
19537+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19538+ pax_open_kernel();
19539+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19540+ pax_close_kernel();
19541+ printk("PAX: slow and weak UDEREF enabled\n");
19542+ } else
19543+ printk("PAX: UDEREF disabled\n");
19544+#endif
19545+
19546+ return;
19547+ }
19548+
19549+ printk("PAX: PCID detected\n");
19550+ set_in_cr4(X86_CR4_PCIDE);
19551+
19552+#ifdef CONFIG_PAX_MEMORY_UDEREF
19553+ pax_open_kernel();
19554+ clone_pgd_mask = ~(pgdval_t)0UL;
19555+ pax_close_kernel();
19556+ if (pax_user_shadow_base)
19557+ printk("PAX: weak UDEREF enabled\n");
19558+ else {
19559+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19560+ printk("PAX: strong UDEREF enabled\n");
19561+ }
19562+#endif
19563+
19564+ if (cpu_has(c, X86_FEATURE_INVPCID))
19565+ printk("PAX: INVPCID detected\n");
19566+}
19567+#endif
19568+
19569 /*
19570 * Some CPU features depend on higher CPUID levels, which may not always
19571 * be available due to CPUID level capping or broken virtualization
19572@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19573 {
19574 struct desc_ptr gdt_descr;
19575
19576- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19577+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19578 gdt_descr.size = GDT_SIZE - 1;
19579 load_gdt(&gdt_descr);
19580 /* Reload the per-cpu base */
19581@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19582 setup_smep(c);
19583 setup_smap(c);
19584
19585+#ifdef CONFIG_X86_64
19586+ setup_pcid(c);
19587+#endif
19588+
19589 /*
19590 * The vendor-specific functions might have changed features.
19591 * Now we do "generic changes."
19592@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19593 /* Filter out anything that depends on CPUID levels we don't have */
19594 filter_cpuid_features(c, true);
19595
19596+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19597+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19598+#endif
19599+
19600 /* If the model name is still unset, do table lookup. */
19601 if (!c->x86_model_id[0]) {
19602 const char *p;
19603@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19604 }
19605 __setup("clearcpuid=", setup_disablecpuid);
19606
19607+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19608+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19609+
19610 #ifdef CONFIG_X86_64
19611-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19612-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19613- (unsigned long) debug_idt_table };
19614+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19615+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19616
19617 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19618 irq_stack_union) __aligned(PAGE_SIZE);
19619@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19620 EXPORT_PER_CPU_SYMBOL(current_task);
19621
19622 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19623- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19624+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19625 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19626
19627 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19628@@ -1232,7 +1239,7 @@ void cpu_init(void)
19629 load_ucode_ap();
19630
19631 cpu = stack_smp_processor_id();
19632- t = &per_cpu(init_tss, cpu);
19633+ t = init_tss + cpu;
19634 oist = &per_cpu(orig_ist, cpu);
19635
19636 #ifdef CONFIG_NUMA
19637@@ -1267,7 +1274,6 @@ void cpu_init(void)
19638 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19639 barrier();
19640
19641- x86_configure_nx();
19642 enable_x2apic();
19643
19644 /*
19645@@ -1319,7 +1325,7 @@ void cpu_init(void)
19646 {
19647 int cpu = smp_processor_id();
19648 struct task_struct *curr = current;
19649- struct tss_struct *t = &per_cpu(init_tss, cpu);
19650+ struct tss_struct *t = init_tss + cpu;
19651 struct thread_struct *thread = &curr->thread;
19652
19653 show_ucode_info_early();
19654diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19655index 1414c90..1159406 100644
19656--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19657+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19658@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19659 };
19660
19661 #ifdef CONFIG_AMD_NB
19662+static struct attribute *default_attrs_amd_nb[] = {
19663+ &type.attr,
19664+ &level.attr,
19665+ &coherency_line_size.attr,
19666+ &physical_line_partition.attr,
19667+ &ways_of_associativity.attr,
19668+ &number_of_sets.attr,
19669+ &size.attr,
19670+ &shared_cpu_map.attr,
19671+ &shared_cpu_list.attr,
19672+ NULL,
19673+ NULL,
19674+ NULL,
19675+ NULL
19676+};
19677+
19678 static struct attribute **amd_l3_attrs(void)
19679 {
19680 static struct attribute **attrs;
19681@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19682
19683 n = ARRAY_SIZE(default_attrs);
19684
19685- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19686- n += 2;
19687-
19688- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19689- n += 1;
19690-
19691- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19692- if (attrs == NULL)
19693- return attrs = default_attrs;
19694-
19695- for (n = 0; default_attrs[n]; n++)
19696- attrs[n] = default_attrs[n];
19697+ attrs = default_attrs_amd_nb;
19698
19699 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19700 attrs[n++] = &cache_disable_0.attr;
19701@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19702 .default_attrs = default_attrs,
19703 };
19704
19705+#ifdef CONFIG_AMD_NB
19706+static struct kobj_type ktype_cache_amd_nb = {
19707+ .sysfs_ops = &sysfs_ops,
19708+ .default_attrs = default_attrs_amd_nb,
19709+};
19710+#endif
19711+
19712 static struct kobj_type ktype_percpu_entry = {
19713 .sysfs_ops = &sysfs_ops,
19714 };
19715@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19716 return retval;
19717 }
19718
19719+#ifdef CONFIG_AMD_NB
19720+ amd_l3_attrs();
19721+#endif
19722+
19723 for (i = 0; i < num_cache_leaves; i++) {
19724+ struct kobj_type *ktype;
19725+
19726 this_object = INDEX_KOBJECT_PTR(cpu, i);
19727 this_object->cpu = cpu;
19728 this_object->index = i;
19729
19730 this_leaf = CPUID4_INFO_IDX(cpu, i);
19731
19732- ktype_cache.default_attrs = default_attrs;
19733+ ktype = &ktype_cache;
19734 #ifdef CONFIG_AMD_NB
19735 if (this_leaf->base.nb)
19736- ktype_cache.default_attrs = amd_l3_attrs();
19737+ ktype = &ktype_cache_amd_nb;
19738 #endif
19739 retval = kobject_init_and_add(&(this_object->kobj),
19740- &ktype_cache,
19741+ ktype,
19742 per_cpu(ici_cache_kobject, cpu),
19743 "index%1lu", i);
19744 if (unlikely(retval)) {
19745diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19746index 87a65c9..92fcce6 100644
19747--- a/arch/x86/kernel/cpu/mcheck/mce.c
19748+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19749@@ -45,6 +45,7 @@
19750 #include <asm/processor.h>
19751 #include <asm/mce.h>
19752 #include <asm/msr.h>
19753+#include <asm/local.h>
19754
19755 #include "mce-internal.h"
19756
19757@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19758 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19759 m->cs, m->ip);
19760
19761- if (m->cs == __KERNEL_CS)
19762+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19763 print_symbol("{%s}", m->ip);
19764 pr_cont("\n");
19765 }
19766@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19767
19768 #define PANIC_TIMEOUT 5 /* 5 seconds */
19769
19770-static atomic_t mce_paniced;
19771+static atomic_unchecked_t mce_paniced;
19772
19773 static int fake_panic;
19774-static atomic_t mce_fake_paniced;
19775+static atomic_unchecked_t mce_fake_paniced;
19776
19777 /* Panic in progress. Enable interrupts and wait for final IPI */
19778 static void wait_for_panic(void)
19779@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19780 /*
19781 * Make sure only one CPU runs in machine check panic
19782 */
19783- if (atomic_inc_return(&mce_paniced) > 1)
19784+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19785 wait_for_panic();
19786 barrier();
19787
19788@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19789 console_verbose();
19790 } else {
19791 /* Don't log too much for fake panic */
19792- if (atomic_inc_return(&mce_fake_paniced) > 1)
19793+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19794 return;
19795 }
19796 /* First print corrected ones that are still unlogged */
19797@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19798 if (!fake_panic) {
19799 if (panic_timeout == 0)
19800 panic_timeout = mca_cfg.panic_timeout;
19801- panic(msg);
19802+ panic("%s", msg);
19803 } else
19804 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19805 }
19806@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19807 * might have been modified by someone else.
19808 */
19809 rmb();
19810- if (atomic_read(&mce_paniced))
19811+ if (atomic_read_unchecked(&mce_paniced))
19812 wait_for_panic();
19813 if (!mca_cfg.monarch_timeout)
19814 goto out;
19815@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19816 }
19817
19818 /* Call the installed machine check handler for this CPU setup. */
19819-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19820+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19821 unexpected_machine_check;
19822
19823 /*
19824@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19825 return;
19826 }
19827
19828+ pax_open_kernel();
19829 machine_check_vector = do_machine_check;
19830+ pax_close_kernel();
19831
19832 __mcheck_cpu_init_generic();
19833 __mcheck_cpu_init_vendor(c);
19834@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19835 */
19836
19837 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19838-static int mce_chrdev_open_count; /* #times opened */
19839+static local_t mce_chrdev_open_count; /* #times opened */
19840 static int mce_chrdev_open_exclu; /* already open exclusive? */
19841
19842 static int mce_chrdev_open(struct inode *inode, struct file *file)
19843@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19844 spin_lock(&mce_chrdev_state_lock);
19845
19846 if (mce_chrdev_open_exclu ||
19847- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19848+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19849 spin_unlock(&mce_chrdev_state_lock);
19850
19851 return -EBUSY;
19852@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19853
19854 if (file->f_flags & O_EXCL)
19855 mce_chrdev_open_exclu = 1;
19856- mce_chrdev_open_count++;
19857+ local_inc(&mce_chrdev_open_count);
19858
19859 spin_unlock(&mce_chrdev_state_lock);
19860
19861@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19862 {
19863 spin_lock(&mce_chrdev_state_lock);
19864
19865- mce_chrdev_open_count--;
19866+ local_dec(&mce_chrdev_open_count);
19867 mce_chrdev_open_exclu = 0;
19868
19869 spin_unlock(&mce_chrdev_state_lock);
19870@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19871
19872 for (i = 0; i < mca_cfg.banks; i++) {
19873 struct mce_bank *b = &mce_banks[i];
19874- struct device_attribute *a = &b->attr;
19875+ device_attribute_no_const *a = &b->attr;
19876
19877 sysfs_attr_init(&a->attr);
19878 a->attr.name = b->attrname;
19879@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19880 static void mce_reset(void)
19881 {
19882 cpu_missing = 0;
19883- atomic_set(&mce_fake_paniced, 0);
19884+ atomic_set_unchecked(&mce_fake_paniced, 0);
19885 atomic_set(&mce_executing, 0);
19886 atomic_set(&mce_callin, 0);
19887 atomic_set(&global_nwo, 0);
19888diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19889index 1c044b1..37a2a43 100644
19890--- a/arch/x86/kernel/cpu/mcheck/p5.c
19891+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19892@@ -11,6 +11,7 @@
19893 #include <asm/processor.h>
19894 #include <asm/mce.h>
19895 #include <asm/msr.h>
19896+#include <asm/pgtable.h>
19897
19898 /* By default disabled */
19899 int mce_p5_enabled __read_mostly;
19900@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19901 if (!cpu_has(c, X86_FEATURE_MCE))
19902 return;
19903
19904+ pax_open_kernel();
19905 machine_check_vector = pentium_machine_check;
19906+ pax_close_kernel();
19907 /* Make sure the vector pointer is visible before we enable MCEs: */
19908 wmb();
19909
19910diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19911index e9a701a..35317d6 100644
19912--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19913+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19914@@ -10,6 +10,7 @@
19915 #include <asm/processor.h>
19916 #include <asm/mce.h>
19917 #include <asm/msr.h>
19918+#include <asm/pgtable.h>
19919
19920 /* Machine check handler for WinChip C6: */
19921 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19922@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19923 {
19924 u32 lo, hi;
19925
19926+ pax_open_kernel();
19927 machine_check_vector = winchip_machine_check;
19928+ pax_close_kernel();
19929 /* Make sure the vector pointer is visible before we enable MCEs: */
19930 wmb();
19931
19932diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19933index f961de9..8a9d332 100644
19934--- a/arch/x86/kernel/cpu/mtrr/main.c
19935+++ b/arch/x86/kernel/cpu/mtrr/main.c
19936@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19937 u64 size_or_mask, size_and_mask;
19938 static bool mtrr_aps_delayed_init;
19939
19940-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19941+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19942
19943 const struct mtrr_ops *mtrr_if;
19944
19945diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19946index df5e41f..816c719 100644
19947--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19948+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19949@@ -25,7 +25,7 @@ struct mtrr_ops {
19950 int (*validate_add_page)(unsigned long base, unsigned long size,
19951 unsigned int type);
19952 int (*have_wrcomb)(void);
19953-};
19954+} __do_const;
19955
19956 extern int generic_get_free_region(unsigned long base, unsigned long size,
19957 int replace_reg);
19958diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19959index a7c7305..b9705ab 100644
19960--- a/arch/x86/kernel/cpu/perf_event.c
19961+++ b/arch/x86/kernel/cpu/perf_event.c
19962@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19963 pr_info("no hardware sampling interrupt available.\n");
19964 }
19965
19966-static struct attribute_group x86_pmu_format_group = {
19967+static attribute_group_no_const x86_pmu_format_group = {
19968 .name = "format",
19969 .attrs = NULL,
19970 };
19971@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19972 NULL,
19973 };
19974
19975-static struct attribute_group x86_pmu_events_group = {
19976+static attribute_group_no_const x86_pmu_events_group = {
19977 .name = "events",
19978 .attrs = events_attr,
19979 };
19980@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19981 if (idx > GDT_ENTRIES)
19982 return 0;
19983
19984- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19985+ desc = get_cpu_gdt_table(smp_processor_id());
19986 }
19987
19988 return get_desc_base(desc + idx);
19989@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19990 break;
19991
19992 perf_callchain_store(entry, frame.return_address);
19993- fp = frame.next_frame;
19994+ fp = (const void __force_user *)frame.next_frame;
19995 }
19996 }
19997
19998diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19999index 639d128..e92d7e5 100644
20000--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20001+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20002@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20003 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20004 {
20005 struct attribute **attrs;
20006- struct attribute_group *attr_group;
20007+ attribute_group_no_const *attr_group;
20008 int i = 0, j;
20009
20010 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20011diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20012index a45d8d4..8abd32c 100644
20013--- a/arch/x86/kernel/cpu/perf_event_intel.c
20014+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20015@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20016 * v2 and above have a perf capabilities MSR
20017 */
20018 if (version > 1) {
20019- u64 capabilities;
20020+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20021
20022- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20023- x86_pmu.intel_cap.capabilities = capabilities;
20024+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20025+ x86_pmu.intel_cap.capabilities = capabilities;
20026 }
20027
20028 intel_ds_init();
20029diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20030index 1fb6c72..f5fa2a3 100644
20031--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20032+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20033@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20034 static int __init uncore_type_init(struct intel_uncore_type *type)
20035 {
20036 struct intel_uncore_pmu *pmus;
20037- struct attribute_group *attr_group;
20038+ attribute_group_no_const *attr_group;
20039 struct attribute **attrs;
20040 int i, j;
20041
20042diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20043index 47b3d00c..2cf1751 100644
20044--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20045+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20046@@ -488,7 +488,7 @@ struct intel_uncore_box {
20047 struct uncore_event_desc {
20048 struct kobj_attribute attr;
20049 const char *config;
20050-};
20051+} __do_const;
20052
20053 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20054 { \
20055diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20056index 7d9481c..99c7e4b 100644
20057--- a/arch/x86/kernel/cpuid.c
20058+++ b/arch/x86/kernel/cpuid.c
20059@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20060 return notifier_from_errno(err);
20061 }
20062
20063-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20064+static struct notifier_block cpuid_class_cpu_notifier =
20065 {
20066 .notifier_call = cpuid_class_cpu_callback,
20067 };
20068diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20069index 74467fe..18793d5 100644
20070--- a/arch/x86/kernel/crash.c
20071+++ b/arch/x86/kernel/crash.c
20072@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20073 {
20074 #ifdef CONFIG_X86_32
20075 struct pt_regs fixed_regs;
20076-#endif
20077
20078-#ifdef CONFIG_X86_32
20079- if (!user_mode_vm(regs)) {
20080+ if (!user_mode(regs)) {
20081 crash_fixup_ss_esp(&fixed_regs, regs);
20082 regs = &fixed_regs;
20083 }
20084diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20085index afa64ad..dce67dd 100644
20086--- a/arch/x86/kernel/crash_dump_64.c
20087+++ b/arch/x86/kernel/crash_dump_64.c
20088@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20089 return -ENOMEM;
20090
20091 if (userbuf) {
20092- if (copy_to_user(buf, vaddr + offset, csize)) {
20093+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20094 iounmap(vaddr);
20095 return -EFAULT;
20096 }
20097diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20098index 5d3fe8d..02e1429 100644
20099--- a/arch/x86/kernel/doublefault.c
20100+++ b/arch/x86/kernel/doublefault.c
20101@@ -13,7 +13,7 @@
20102
20103 #define DOUBLEFAULT_STACKSIZE (1024)
20104 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20105-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20106+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20107
20108 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20109
20110@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20111 unsigned long gdt, tss;
20112
20113 native_store_gdt(&gdt_desc);
20114- gdt = gdt_desc.address;
20115+ gdt = (unsigned long)gdt_desc.address;
20116
20117 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20118
20119@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20120 /* 0x2 bit is always set */
20121 .flags = X86_EFLAGS_SF | 0x2,
20122 .sp = STACK_START,
20123- .es = __USER_DS,
20124+ .es = __KERNEL_DS,
20125 .cs = __KERNEL_CS,
20126 .ss = __KERNEL_DS,
20127- .ds = __USER_DS,
20128+ .ds = __KERNEL_DS,
20129 .fs = __KERNEL_PERCPU,
20130
20131 .__cr3 = __pa_nodebug(swapper_pg_dir),
20132diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20133index deb6421..76bbc12 100644
20134--- a/arch/x86/kernel/dumpstack.c
20135+++ b/arch/x86/kernel/dumpstack.c
20136@@ -2,6 +2,9 @@
20137 * Copyright (C) 1991, 1992 Linus Torvalds
20138 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20139 */
20140+#ifdef CONFIG_GRKERNSEC_HIDESYM
20141+#define __INCLUDED_BY_HIDESYM 1
20142+#endif
20143 #include <linux/kallsyms.h>
20144 #include <linux/kprobes.h>
20145 #include <linux/uaccess.h>
20146@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20147 static void
20148 print_ftrace_graph_addr(unsigned long addr, void *data,
20149 const struct stacktrace_ops *ops,
20150- struct thread_info *tinfo, int *graph)
20151+ struct task_struct *task, int *graph)
20152 {
20153- struct task_struct *task;
20154 unsigned long ret_addr;
20155 int index;
20156
20157 if (addr != (unsigned long)return_to_handler)
20158 return;
20159
20160- task = tinfo->task;
20161 index = task->curr_ret_stack;
20162
20163 if (!task->ret_stack || index < *graph)
20164@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20165 static inline void
20166 print_ftrace_graph_addr(unsigned long addr, void *data,
20167 const struct stacktrace_ops *ops,
20168- struct thread_info *tinfo, int *graph)
20169+ struct task_struct *task, int *graph)
20170 { }
20171 #endif
20172
20173@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20174 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20175 */
20176
20177-static inline int valid_stack_ptr(struct thread_info *tinfo,
20178- void *p, unsigned int size, void *end)
20179+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20180 {
20181- void *t = tinfo;
20182 if (end) {
20183 if (p < end && p >= (end-THREAD_SIZE))
20184 return 1;
20185@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20186 }
20187
20188 unsigned long
20189-print_context_stack(struct thread_info *tinfo,
20190+print_context_stack(struct task_struct *task, void *stack_start,
20191 unsigned long *stack, unsigned long bp,
20192 const struct stacktrace_ops *ops, void *data,
20193 unsigned long *end, int *graph)
20194 {
20195 struct stack_frame *frame = (struct stack_frame *)bp;
20196
20197- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20198+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20199 unsigned long addr;
20200
20201 addr = *stack;
20202@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20203 } else {
20204 ops->address(data, addr, 0);
20205 }
20206- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20207+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20208 }
20209 stack++;
20210 }
20211@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20212 EXPORT_SYMBOL_GPL(print_context_stack);
20213
20214 unsigned long
20215-print_context_stack_bp(struct thread_info *tinfo,
20216+print_context_stack_bp(struct task_struct *task, void *stack_start,
20217 unsigned long *stack, unsigned long bp,
20218 const struct stacktrace_ops *ops, void *data,
20219 unsigned long *end, int *graph)
20220@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20221 struct stack_frame *frame = (struct stack_frame *)bp;
20222 unsigned long *ret_addr = &frame->return_address;
20223
20224- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20225+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20226 unsigned long addr = *ret_addr;
20227
20228 if (!__kernel_text_address(addr))
20229@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20230 ops->address(data, addr, 1);
20231 frame = frame->next_frame;
20232 ret_addr = &frame->return_address;
20233- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20234+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20235 }
20236
20237 return (unsigned long)frame;
20238@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20239 static void print_trace_address(void *data, unsigned long addr, int reliable)
20240 {
20241 touch_nmi_watchdog();
20242- printk(data);
20243+ printk("%s", (char *)data);
20244 printk_address(addr, reliable);
20245 }
20246
20247@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20248 }
20249 EXPORT_SYMBOL_GPL(oops_begin);
20250
20251+extern void gr_handle_kernel_exploit(void);
20252+
20253 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20254 {
20255 if (regs && kexec_should_crash(current))
20256@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20257 panic("Fatal exception in interrupt");
20258 if (panic_on_oops)
20259 panic("Fatal exception");
20260- do_exit(signr);
20261+
20262+ gr_handle_kernel_exploit();
20263+
20264+ do_group_exit(signr);
20265 }
20266
20267 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20268@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20269 print_modules();
20270 show_regs(regs);
20271 #ifdef CONFIG_X86_32
20272- if (user_mode_vm(regs)) {
20273+ if (user_mode(regs)) {
20274 sp = regs->sp;
20275 ss = regs->ss & 0xffff;
20276 } else {
20277@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20278 unsigned long flags = oops_begin();
20279 int sig = SIGSEGV;
20280
20281- if (!user_mode_vm(regs))
20282+ if (!user_mode(regs))
20283 report_bug(regs->ip, regs);
20284
20285 if (__die(str, regs, err))
20286diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20287index f2a1770..540657f 100644
20288--- a/arch/x86/kernel/dumpstack_32.c
20289+++ b/arch/x86/kernel/dumpstack_32.c
20290@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20291 bp = stack_frame(task, regs);
20292
20293 for (;;) {
20294- struct thread_info *context;
20295+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20296
20297- context = (struct thread_info *)
20298- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20299- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20300+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20301
20302- stack = (unsigned long *)context->previous_esp;
20303- if (!stack)
20304+ if (stack_start == task_stack_page(task))
20305 break;
20306+ stack = *(unsigned long **)stack_start;
20307 if (ops->stack(data, "IRQ") < 0)
20308 break;
20309 touch_nmi_watchdog();
20310@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20311 int i;
20312
20313 show_regs_print_info(KERN_EMERG);
20314- __show_regs(regs, !user_mode_vm(regs));
20315+ __show_regs(regs, !user_mode(regs));
20316
20317 /*
20318 * When in-kernel, we also print out the stack and code at the
20319 * time of the fault..
20320 */
20321- if (!user_mode_vm(regs)) {
20322+ if (!user_mode(regs)) {
20323 unsigned int code_prologue = code_bytes * 43 / 64;
20324 unsigned int code_len = code_bytes;
20325 unsigned char c;
20326 u8 *ip;
20327+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20328
20329 pr_emerg("Stack:\n");
20330 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20331
20332 pr_emerg("Code:");
20333
20334- ip = (u8 *)regs->ip - code_prologue;
20335+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20336 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20337 /* try starting at IP */
20338- ip = (u8 *)regs->ip;
20339+ ip = (u8 *)regs->ip + cs_base;
20340 code_len = code_len - code_prologue + 1;
20341 }
20342 for (i = 0; i < code_len; i++, ip++) {
20343@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20344 pr_cont(" Bad EIP value.");
20345 break;
20346 }
20347- if (ip == (u8 *)regs->ip)
20348+ if (ip == (u8 *)regs->ip + cs_base)
20349 pr_cont(" <%02x>", c);
20350 else
20351 pr_cont(" %02x", c);
20352@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20353 {
20354 unsigned short ud2;
20355
20356+ ip = ktla_ktva(ip);
20357 if (ip < PAGE_OFFSET)
20358 return 0;
20359 if (probe_kernel_address((unsigned short *)ip, ud2))
20360@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20361
20362 return ud2 == 0x0b0f;
20363 }
20364+
20365+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20366+void pax_check_alloca(unsigned long size)
20367+{
20368+ unsigned long sp = (unsigned long)&sp, stack_left;
20369+
20370+ /* all kernel stacks are of the same size */
20371+ stack_left = sp & (THREAD_SIZE - 1);
20372+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20373+}
20374+EXPORT_SYMBOL(pax_check_alloca);
20375+#endif
20376diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20377index addb207..99635fa 100644
20378--- a/arch/x86/kernel/dumpstack_64.c
20379+++ b/arch/x86/kernel/dumpstack_64.c
20380@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20381 unsigned long *irq_stack_end =
20382 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20383 unsigned used = 0;
20384- struct thread_info *tinfo;
20385 int graph = 0;
20386 unsigned long dummy;
20387+ void *stack_start;
20388
20389 if (!task)
20390 task = current;
20391@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20392 * current stack address. If the stacks consist of nested
20393 * exceptions
20394 */
20395- tinfo = task_thread_info(task);
20396 for (;;) {
20397 char *id;
20398 unsigned long *estack_end;
20399+
20400 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20401 &used, &id);
20402
20403@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20404 if (ops->stack(data, id) < 0)
20405 break;
20406
20407- bp = ops->walk_stack(tinfo, stack, bp, ops,
20408+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20409 data, estack_end, &graph);
20410 ops->stack(data, "<EOE>");
20411 /*
20412@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20413 * second-to-last pointer (index -2 to end) in the
20414 * exception stack:
20415 */
20416+ if ((u16)estack_end[-1] != __KERNEL_DS)
20417+ goto out;
20418 stack = (unsigned long *) estack_end[-2];
20419 continue;
20420 }
20421@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20422 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20423 if (ops->stack(data, "IRQ") < 0)
20424 break;
20425- bp = ops->walk_stack(tinfo, stack, bp,
20426+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20427 ops, data, irq_stack_end, &graph);
20428 /*
20429 * We link to the next stack (which would be
20430@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20431 /*
20432 * This handles the process stack:
20433 */
20434- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20435+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20436+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20437+out:
20438 put_cpu();
20439 }
20440 EXPORT_SYMBOL(dump_trace);
20441@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20442
20443 return ud2 == 0x0b0f;
20444 }
20445+
20446+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20447+void pax_check_alloca(unsigned long size)
20448+{
20449+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20450+ unsigned cpu, used;
20451+ char *id;
20452+
20453+ /* check the process stack first */
20454+ stack_start = (unsigned long)task_stack_page(current);
20455+ stack_end = stack_start + THREAD_SIZE;
20456+ if (likely(stack_start <= sp && sp < stack_end)) {
20457+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20458+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20459+ return;
20460+ }
20461+
20462+ cpu = get_cpu();
20463+
20464+ /* check the irq stacks */
20465+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20466+ stack_start = stack_end - IRQ_STACK_SIZE;
20467+ if (stack_start <= sp && sp < stack_end) {
20468+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20469+ put_cpu();
20470+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20471+ return;
20472+ }
20473+
20474+ /* check the exception stacks */
20475+ used = 0;
20476+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20477+ stack_start = stack_end - EXCEPTION_STKSZ;
20478+ if (stack_end && stack_start <= sp && sp < stack_end) {
20479+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20480+ put_cpu();
20481+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20482+ return;
20483+ }
20484+
20485+ put_cpu();
20486+
20487+ /* unknown stack */
20488+ BUG();
20489+}
20490+EXPORT_SYMBOL(pax_check_alloca);
20491+#endif
20492diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20493index d32abea..74daf4f 100644
20494--- a/arch/x86/kernel/e820.c
20495+++ b/arch/x86/kernel/e820.c
20496@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20497
20498 static void early_panic(char *msg)
20499 {
20500- early_printk(msg);
20501- panic(msg);
20502+ early_printk("%s", msg);
20503+ panic("%s", msg);
20504 }
20505
20506 static int userdef __initdata;
20507diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20508index d15f575..d692043 100644
20509--- a/arch/x86/kernel/early_printk.c
20510+++ b/arch/x86/kernel/early_printk.c
20511@@ -7,6 +7,7 @@
20512 #include <linux/pci_regs.h>
20513 #include <linux/pci_ids.h>
20514 #include <linux/errno.h>
20515+#include <linux/sched.h>
20516 #include <asm/io.h>
20517 #include <asm/processor.h>
20518 #include <asm/fcntl.h>
20519diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20520index 2cfbc3a..b756682 100644
20521--- a/arch/x86/kernel/entry_32.S
20522+++ b/arch/x86/kernel/entry_32.S
20523@@ -177,13 +177,153 @@
20524 /*CFI_REL_OFFSET gs, PT_GS*/
20525 .endm
20526 .macro SET_KERNEL_GS reg
20527+
20528+#ifdef CONFIG_CC_STACKPROTECTOR
20529 movl $(__KERNEL_STACK_CANARY), \reg
20530+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20531+ movl $(__USER_DS), \reg
20532+#else
20533+ xorl \reg, \reg
20534+#endif
20535+
20536 movl \reg, %gs
20537 .endm
20538
20539 #endif /* CONFIG_X86_32_LAZY_GS */
20540
20541-.macro SAVE_ALL
20542+.macro pax_enter_kernel
20543+#ifdef CONFIG_PAX_KERNEXEC
20544+ call pax_enter_kernel
20545+#endif
20546+.endm
20547+
20548+.macro pax_exit_kernel
20549+#ifdef CONFIG_PAX_KERNEXEC
20550+ call pax_exit_kernel
20551+#endif
20552+.endm
20553+
20554+#ifdef CONFIG_PAX_KERNEXEC
20555+ENTRY(pax_enter_kernel)
20556+#ifdef CONFIG_PARAVIRT
20557+ pushl %eax
20558+ pushl %ecx
20559+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20560+ mov %eax, %esi
20561+#else
20562+ mov %cr0, %esi
20563+#endif
20564+ bts $16, %esi
20565+ jnc 1f
20566+ mov %cs, %esi
20567+ cmp $__KERNEL_CS, %esi
20568+ jz 3f
20569+ ljmp $__KERNEL_CS, $3f
20570+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20571+2:
20572+#ifdef CONFIG_PARAVIRT
20573+ mov %esi, %eax
20574+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20575+#else
20576+ mov %esi, %cr0
20577+#endif
20578+3:
20579+#ifdef CONFIG_PARAVIRT
20580+ popl %ecx
20581+ popl %eax
20582+#endif
20583+ ret
20584+ENDPROC(pax_enter_kernel)
20585+
20586+ENTRY(pax_exit_kernel)
20587+#ifdef CONFIG_PARAVIRT
20588+ pushl %eax
20589+ pushl %ecx
20590+#endif
20591+ mov %cs, %esi
20592+ cmp $__KERNEXEC_KERNEL_CS, %esi
20593+ jnz 2f
20594+#ifdef CONFIG_PARAVIRT
20595+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20596+ mov %eax, %esi
20597+#else
20598+ mov %cr0, %esi
20599+#endif
20600+ btr $16, %esi
20601+ ljmp $__KERNEL_CS, $1f
20602+1:
20603+#ifdef CONFIG_PARAVIRT
20604+ mov %esi, %eax
20605+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20606+#else
20607+ mov %esi, %cr0
20608+#endif
20609+2:
20610+#ifdef CONFIG_PARAVIRT
20611+ popl %ecx
20612+ popl %eax
20613+#endif
20614+ ret
20615+ENDPROC(pax_exit_kernel)
20616+#endif
20617+
20618+ .macro pax_erase_kstack
20619+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20620+ call pax_erase_kstack
20621+#endif
20622+ .endm
20623+
20624+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20625+/*
20626+ * ebp: thread_info
20627+ */
20628+ENTRY(pax_erase_kstack)
20629+ pushl %edi
20630+ pushl %ecx
20631+ pushl %eax
20632+
20633+ mov TI_lowest_stack(%ebp), %edi
20634+ mov $-0xBEEF, %eax
20635+ std
20636+
20637+1: mov %edi, %ecx
20638+ and $THREAD_SIZE_asm - 1, %ecx
20639+ shr $2, %ecx
20640+ repne scasl
20641+ jecxz 2f
20642+
20643+ cmp $2*16, %ecx
20644+ jc 2f
20645+
20646+ mov $2*16, %ecx
20647+ repe scasl
20648+ jecxz 2f
20649+ jne 1b
20650+
20651+2: cld
20652+ mov %esp, %ecx
20653+ sub %edi, %ecx
20654+
20655+ cmp $THREAD_SIZE_asm, %ecx
20656+ jb 3f
20657+ ud2
20658+3:
20659+
20660+ shr $2, %ecx
20661+ rep stosl
20662+
20663+ mov TI_task_thread_sp0(%ebp), %edi
20664+ sub $128, %edi
20665+ mov %edi, TI_lowest_stack(%ebp)
20666+
20667+ popl %eax
20668+ popl %ecx
20669+ popl %edi
20670+ ret
20671+ENDPROC(pax_erase_kstack)
20672+#endif
20673+
20674+.macro __SAVE_ALL _DS
20675 cld
20676 PUSH_GS
20677 pushl_cfi %fs
20678@@ -206,7 +346,7 @@
20679 CFI_REL_OFFSET ecx, 0
20680 pushl_cfi %ebx
20681 CFI_REL_OFFSET ebx, 0
20682- movl $(__USER_DS), %edx
20683+ movl $\_DS, %edx
20684 movl %edx, %ds
20685 movl %edx, %es
20686 movl $(__KERNEL_PERCPU), %edx
20687@@ -214,6 +354,15 @@
20688 SET_KERNEL_GS %edx
20689 .endm
20690
20691+.macro SAVE_ALL
20692+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20693+ __SAVE_ALL __KERNEL_DS
20694+ pax_enter_kernel
20695+#else
20696+ __SAVE_ALL __USER_DS
20697+#endif
20698+.endm
20699+
20700 .macro RESTORE_INT_REGS
20701 popl_cfi %ebx
20702 CFI_RESTORE ebx
20703@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20704 popfl_cfi
20705 jmp syscall_exit
20706 CFI_ENDPROC
20707-END(ret_from_fork)
20708+ENDPROC(ret_from_fork)
20709
20710 ENTRY(ret_from_kernel_thread)
20711 CFI_STARTPROC
20712@@ -344,7 +493,15 @@ ret_from_intr:
20713 andl $SEGMENT_RPL_MASK, %eax
20714 #endif
20715 cmpl $USER_RPL, %eax
20716+
20717+#ifdef CONFIG_PAX_KERNEXEC
20718+ jae resume_userspace
20719+
20720+ pax_exit_kernel
20721+ jmp resume_kernel
20722+#else
20723 jb resume_kernel # not returning to v8086 or userspace
20724+#endif
20725
20726 ENTRY(resume_userspace)
20727 LOCKDEP_SYS_EXIT
20728@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20729 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20730 # int/exception return?
20731 jne work_pending
20732- jmp restore_all
20733-END(ret_from_exception)
20734+ jmp restore_all_pax
20735+ENDPROC(ret_from_exception)
20736
20737 #ifdef CONFIG_PREEMPT
20738 ENTRY(resume_kernel)
20739@@ -372,7 +529,7 @@ need_resched:
20740 jz restore_all
20741 call preempt_schedule_irq
20742 jmp need_resched
20743-END(resume_kernel)
20744+ENDPROC(resume_kernel)
20745 #endif
20746 CFI_ENDPROC
20747 /*
20748@@ -406,30 +563,45 @@ sysenter_past_esp:
20749 /*CFI_REL_OFFSET cs, 0*/
20750 /*
20751 * Push current_thread_info()->sysenter_return to the stack.
20752- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20753- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20754 */
20755- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20756+ pushl_cfi $0
20757 CFI_REL_OFFSET eip, 0
20758
20759 pushl_cfi %eax
20760 SAVE_ALL
20761+ GET_THREAD_INFO(%ebp)
20762+ movl TI_sysenter_return(%ebp),%ebp
20763+ movl %ebp,PT_EIP(%esp)
20764 ENABLE_INTERRUPTS(CLBR_NONE)
20765
20766 /*
20767 * Load the potential sixth argument from user stack.
20768 * Careful about security.
20769 */
20770+ movl PT_OLDESP(%esp),%ebp
20771+
20772+#ifdef CONFIG_PAX_MEMORY_UDEREF
20773+ mov PT_OLDSS(%esp),%ds
20774+1: movl %ds:(%ebp),%ebp
20775+ push %ss
20776+ pop %ds
20777+#else
20778 cmpl $__PAGE_OFFSET-3,%ebp
20779 jae syscall_fault
20780 ASM_STAC
20781 1: movl (%ebp),%ebp
20782 ASM_CLAC
20783+#endif
20784+
20785 movl %ebp,PT_EBP(%esp)
20786 _ASM_EXTABLE(1b,syscall_fault)
20787
20788 GET_THREAD_INFO(%ebp)
20789
20790+#ifdef CONFIG_PAX_RANDKSTACK
20791+ pax_erase_kstack
20792+#endif
20793+
20794 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20795 jnz sysenter_audit
20796 sysenter_do_call:
20797@@ -444,12 +616,24 @@ sysenter_do_call:
20798 testl $_TIF_ALLWORK_MASK, %ecx
20799 jne sysexit_audit
20800 sysenter_exit:
20801+
20802+#ifdef CONFIG_PAX_RANDKSTACK
20803+ pushl_cfi %eax
20804+ movl %esp, %eax
20805+ call pax_randomize_kstack
20806+ popl_cfi %eax
20807+#endif
20808+
20809+ pax_erase_kstack
20810+
20811 /* if something modifies registers it must also disable sysexit */
20812 movl PT_EIP(%esp), %edx
20813 movl PT_OLDESP(%esp), %ecx
20814 xorl %ebp,%ebp
20815 TRACE_IRQS_ON
20816 1: mov PT_FS(%esp), %fs
20817+2: mov PT_DS(%esp), %ds
20818+3: mov PT_ES(%esp), %es
20819 PTGS_TO_GS
20820 ENABLE_INTERRUPTS_SYSEXIT
20821
20822@@ -466,6 +650,9 @@ sysenter_audit:
20823 movl %eax,%edx /* 2nd arg: syscall number */
20824 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20825 call __audit_syscall_entry
20826+
20827+ pax_erase_kstack
20828+
20829 pushl_cfi %ebx
20830 movl PT_EAX(%esp),%eax /* reload syscall number */
20831 jmp sysenter_do_call
20832@@ -491,10 +678,16 @@ sysexit_audit:
20833
20834 CFI_ENDPROC
20835 .pushsection .fixup,"ax"
20836-2: movl $0,PT_FS(%esp)
20837+4: movl $0,PT_FS(%esp)
20838+ jmp 1b
20839+5: movl $0,PT_DS(%esp)
20840+ jmp 1b
20841+6: movl $0,PT_ES(%esp)
20842 jmp 1b
20843 .popsection
20844- _ASM_EXTABLE(1b,2b)
20845+ _ASM_EXTABLE(1b,4b)
20846+ _ASM_EXTABLE(2b,5b)
20847+ _ASM_EXTABLE(3b,6b)
20848 PTGS_TO_GS_EX
20849 ENDPROC(ia32_sysenter_target)
20850
20851@@ -509,6 +702,11 @@ ENTRY(system_call)
20852 pushl_cfi %eax # save orig_eax
20853 SAVE_ALL
20854 GET_THREAD_INFO(%ebp)
20855+
20856+#ifdef CONFIG_PAX_RANDKSTACK
20857+ pax_erase_kstack
20858+#endif
20859+
20860 # system call tracing in operation / emulation
20861 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20862 jnz syscall_trace_entry
20863@@ -527,6 +725,15 @@ syscall_exit:
20864 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20865 jne syscall_exit_work
20866
20867+restore_all_pax:
20868+
20869+#ifdef CONFIG_PAX_RANDKSTACK
20870+ movl %esp, %eax
20871+ call pax_randomize_kstack
20872+#endif
20873+
20874+ pax_erase_kstack
20875+
20876 restore_all:
20877 TRACE_IRQS_IRET
20878 restore_all_notrace:
20879@@ -583,14 +790,34 @@ ldt_ss:
20880 * compensating for the offset by changing to the ESPFIX segment with
20881 * a base address that matches for the difference.
20882 */
20883-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20884+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20885 mov %esp, %edx /* load kernel esp */
20886 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20887 mov %dx, %ax /* eax: new kernel esp */
20888 sub %eax, %edx /* offset (low word is 0) */
20889+#ifdef CONFIG_SMP
20890+ movl PER_CPU_VAR(cpu_number), %ebx
20891+ shll $PAGE_SHIFT_asm, %ebx
20892+ addl $cpu_gdt_table, %ebx
20893+#else
20894+ movl $cpu_gdt_table, %ebx
20895+#endif
20896 shr $16, %edx
20897- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20898- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20899+
20900+#ifdef CONFIG_PAX_KERNEXEC
20901+ mov %cr0, %esi
20902+ btr $16, %esi
20903+ mov %esi, %cr0
20904+#endif
20905+
20906+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20907+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20908+
20909+#ifdef CONFIG_PAX_KERNEXEC
20910+ bts $16, %esi
20911+ mov %esi, %cr0
20912+#endif
20913+
20914 pushl_cfi $__ESPFIX_SS
20915 pushl_cfi %eax /* new kernel esp */
20916 /* Disable interrupts, but do not irqtrace this section: we
20917@@ -619,20 +846,18 @@ work_resched:
20918 movl TI_flags(%ebp), %ecx
20919 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20920 # than syscall tracing?
20921- jz restore_all
20922+ jz restore_all_pax
20923 testb $_TIF_NEED_RESCHED, %cl
20924 jnz work_resched
20925
20926 work_notifysig: # deal with pending signals and
20927 # notify-resume requests
20928+ movl %esp, %eax
20929 #ifdef CONFIG_VM86
20930 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20931- movl %esp, %eax
20932 jne work_notifysig_v86 # returning to kernel-space or
20933 # vm86-space
20934 1:
20935-#else
20936- movl %esp, %eax
20937 #endif
20938 TRACE_IRQS_ON
20939 ENABLE_INTERRUPTS(CLBR_NONE)
20940@@ -653,7 +878,7 @@ work_notifysig_v86:
20941 movl %eax, %esp
20942 jmp 1b
20943 #endif
20944-END(work_pending)
20945+ENDPROC(work_pending)
20946
20947 # perform syscall exit tracing
20948 ALIGN
20949@@ -661,11 +886,14 @@ syscall_trace_entry:
20950 movl $-ENOSYS,PT_EAX(%esp)
20951 movl %esp, %eax
20952 call syscall_trace_enter
20953+
20954+ pax_erase_kstack
20955+
20956 /* What it returned is what we'll actually use. */
20957 cmpl $(NR_syscalls), %eax
20958 jnae syscall_call
20959 jmp syscall_exit
20960-END(syscall_trace_entry)
20961+ENDPROC(syscall_trace_entry)
20962
20963 # perform syscall exit tracing
20964 ALIGN
20965@@ -678,21 +906,25 @@ syscall_exit_work:
20966 movl %esp, %eax
20967 call syscall_trace_leave
20968 jmp resume_userspace
20969-END(syscall_exit_work)
20970+ENDPROC(syscall_exit_work)
20971 CFI_ENDPROC
20972
20973 RING0_INT_FRAME # can't unwind into user space anyway
20974 syscall_fault:
20975+#ifdef CONFIG_PAX_MEMORY_UDEREF
20976+ push %ss
20977+ pop %ds
20978+#endif
20979 ASM_CLAC
20980 GET_THREAD_INFO(%ebp)
20981 movl $-EFAULT,PT_EAX(%esp)
20982 jmp resume_userspace
20983-END(syscall_fault)
20984+ENDPROC(syscall_fault)
20985
20986 syscall_badsys:
20987 movl $-ENOSYS,PT_EAX(%esp)
20988 jmp resume_userspace
20989-END(syscall_badsys)
20990+ENDPROC(syscall_badsys)
20991 CFI_ENDPROC
20992 /*
20993 * End of kprobes section
20994@@ -708,8 +940,15 @@ END(syscall_badsys)
20995 * normal stack and adjusts ESP with the matching offset.
20996 */
20997 /* fixup the stack */
20998- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20999- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21000+#ifdef CONFIG_SMP
21001+ movl PER_CPU_VAR(cpu_number), %ebx
21002+ shll $PAGE_SHIFT_asm, %ebx
21003+ addl $cpu_gdt_table, %ebx
21004+#else
21005+ movl $cpu_gdt_table, %ebx
21006+#endif
21007+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21008+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21009 shl $16, %eax
21010 addl %esp, %eax /* the adjusted stack pointer */
21011 pushl_cfi $__KERNEL_DS
21012@@ -762,7 +1001,7 @@ vector=vector+1
21013 .endr
21014 2: jmp common_interrupt
21015 .endr
21016-END(irq_entries_start)
21017+ENDPROC(irq_entries_start)
21018
21019 .previous
21020 END(interrupt)
21021@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21022 pushl_cfi $do_coprocessor_error
21023 jmp error_code
21024 CFI_ENDPROC
21025-END(coprocessor_error)
21026+ENDPROC(coprocessor_error)
21027
21028 ENTRY(simd_coprocessor_error)
21029 RING0_INT_FRAME
21030@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21031 .section .altinstructions,"a"
21032 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21033 .previous
21034-.section .altinstr_replacement,"ax"
21035+.section .altinstr_replacement,"a"
21036 663: pushl $do_simd_coprocessor_error
21037 664:
21038 .previous
21039@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21040 #endif
21041 jmp error_code
21042 CFI_ENDPROC
21043-END(simd_coprocessor_error)
21044+ENDPROC(simd_coprocessor_error)
21045
21046 ENTRY(device_not_available)
21047 RING0_INT_FRAME
21048@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21049 pushl_cfi $do_device_not_available
21050 jmp error_code
21051 CFI_ENDPROC
21052-END(device_not_available)
21053+ENDPROC(device_not_available)
21054
21055 #ifdef CONFIG_PARAVIRT
21056 ENTRY(native_iret)
21057 iret
21058 _ASM_EXTABLE(native_iret, iret_exc)
21059-END(native_iret)
21060+ENDPROC(native_iret)
21061
21062 ENTRY(native_irq_enable_sysexit)
21063 sti
21064 sysexit
21065-END(native_irq_enable_sysexit)
21066+ENDPROC(native_irq_enable_sysexit)
21067 #endif
21068
21069 ENTRY(overflow)
21070@@ -875,7 +1114,7 @@ ENTRY(overflow)
21071 pushl_cfi $do_overflow
21072 jmp error_code
21073 CFI_ENDPROC
21074-END(overflow)
21075+ENDPROC(overflow)
21076
21077 ENTRY(bounds)
21078 RING0_INT_FRAME
21079@@ -884,7 +1123,7 @@ ENTRY(bounds)
21080 pushl_cfi $do_bounds
21081 jmp error_code
21082 CFI_ENDPROC
21083-END(bounds)
21084+ENDPROC(bounds)
21085
21086 ENTRY(invalid_op)
21087 RING0_INT_FRAME
21088@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21089 pushl_cfi $do_invalid_op
21090 jmp error_code
21091 CFI_ENDPROC
21092-END(invalid_op)
21093+ENDPROC(invalid_op)
21094
21095 ENTRY(coprocessor_segment_overrun)
21096 RING0_INT_FRAME
21097@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21098 pushl_cfi $do_coprocessor_segment_overrun
21099 jmp error_code
21100 CFI_ENDPROC
21101-END(coprocessor_segment_overrun)
21102+ENDPROC(coprocessor_segment_overrun)
21103
21104 ENTRY(invalid_TSS)
21105 RING0_EC_FRAME
21106@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21107 pushl_cfi $do_invalid_TSS
21108 jmp error_code
21109 CFI_ENDPROC
21110-END(invalid_TSS)
21111+ENDPROC(invalid_TSS)
21112
21113 ENTRY(segment_not_present)
21114 RING0_EC_FRAME
21115@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21116 pushl_cfi $do_segment_not_present
21117 jmp error_code
21118 CFI_ENDPROC
21119-END(segment_not_present)
21120+ENDPROC(segment_not_present)
21121
21122 ENTRY(stack_segment)
21123 RING0_EC_FRAME
21124@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21125 pushl_cfi $do_stack_segment
21126 jmp error_code
21127 CFI_ENDPROC
21128-END(stack_segment)
21129+ENDPROC(stack_segment)
21130
21131 ENTRY(alignment_check)
21132 RING0_EC_FRAME
21133@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21134 pushl_cfi $do_alignment_check
21135 jmp error_code
21136 CFI_ENDPROC
21137-END(alignment_check)
21138+ENDPROC(alignment_check)
21139
21140 ENTRY(divide_error)
21141 RING0_INT_FRAME
21142@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21143 pushl_cfi $do_divide_error
21144 jmp error_code
21145 CFI_ENDPROC
21146-END(divide_error)
21147+ENDPROC(divide_error)
21148
21149 #ifdef CONFIG_X86_MCE
21150 ENTRY(machine_check)
21151@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21152 pushl_cfi machine_check_vector
21153 jmp error_code
21154 CFI_ENDPROC
21155-END(machine_check)
21156+ENDPROC(machine_check)
21157 #endif
21158
21159 ENTRY(spurious_interrupt_bug)
21160@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21161 pushl_cfi $do_spurious_interrupt_bug
21162 jmp error_code
21163 CFI_ENDPROC
21164-END(spurious_interrupt_bug)
21165+ENDPROC(spurious_interrupt_bug)
21166 /*
21167 * End of kprobes section
21168 */
21169@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21170
21171 ENTRY(mcount)
21172 ret
21173-END(mcount)
21174+ENDPROC(mcount)
21175
21176 ENTRY(ftrace_caller)
21177 cmpl $0, function_trace_stop
21178@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21179 .globl ftrace_stub
21180 ftrace_stub:
21181 ret
21182-END(ftrace_caller)
21183+ENDPROC(ftrace_caller)
21184
21185 ENTRY(ftrace_regs_caller)
21186 pushf /* push flags before compare (in cs location) */
21187@@ -1207,7 +1446,7 @@ trace:
21188 popl %ecx
21189 popl %eax
21190 jmp ftrace_stub
21191-END(mcount)
21192+ENDPROC(mcount)
21193 #endif /* CONFIG_DYNAMIC_FTRACE */
21194 #endif /* CONFIG_FUNCTION_TRACER */
21195
21196@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21197 popl %ecx
21198 popl %eax
21199 ret
21200-END(ftrace_graph_caller)
21201+ENDPROC(ftrace_graph_caller)
21202
21203 .globl return_to_handler
21204 return_to_handler:
21205@@ -1281,15 +1520,18 @@ error_code:
21206 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21207 REG_TO_PTGS %ecx
21208 SET_KERNEL_GS %ecx
21209- movl $(__USER_DS), %ecx
21210+ movl $(__KERNEL_DS), %ecx
21211 movl %ecx, %ds
21212 movl %ecx, %es
21213+
21214+ pax_enter_kernel
21215+
21216 TRACE_IRQS_OFF
21217 movl %esp,%eax # pt_regs pointer
21218 call *%edi
21219 jmp ret_from_exception
21220 CFI_ENDPROC
21221-END(page_fault)
21222+ENDPROC(page_fault)
21223
21224 /*
21225 * Debug traps and NMI can happen at the one SYSENTER instruction
21226@@ -1332,7 +1574,7 @@ debug_stack_correct:
21227 call do_debug
21228 jmp ret_from_exception
21229 CFI_ENDPROC
21230-END(debug)
21231+ENDPROC(debug)
21232
21233 /*
21234 * NMI is doubly nasty. It can happen _while_ we're handling
21235@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21236 xorl %edx,%edx # zero error code
21237 movl %esp,%eax # pt_regs pointer
21238 call do_nmi
21239+
21240+ pax_exit_kernel
21241+
21242 jmp restore_all_notrace
21243 CFI_ENDPROC
21244
21245@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21246 FIXUP_ESPFIX_STACK # %eax == %esp
21247 xorl %edx,%edx # zero error code
21248 call do_nmi
21249+
21250+ pax_exit_kernel
21251+
21252 RESTORE_REGS
21253 lss 12+4(%esp), %esp # back to espfix stack
21254 CFI_ADJUST_CFA_OFFSET -24
21255 jmp irq_return
21256 CFI_ENDPROC
21257-END(nmi)
21258+ENDPROC(nmi)
21259
21260 ENTRY(int3)
21261 RING0_INT_FRAME
21262@@ -1424,14 +1672,14 @@ ENTRY(int3)
21263 call do_int3
21264 jmp ret_from_exception
21265 CFI_ENDPROC
21266-END(int3)
21267+ENDPROC(int3)
21268
21269 ENTRY(general_protection)
21270 RING0_EC_FRAME
21271 pushl_cfi $do_general_protection
21272 jmp error_code
21273 CFI_ENDPROC
21274-END(general_protection)
21275+ENDPROC(general_protection)
21276
21277 #ifdef CONFIG_KVM_GUEST
21278 ENTRY(async_page_fault)
21279@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21280 pushl_cfi $do_async_page_fault
21281 jmp error_code
21282 CFI_ENDPROC
21283-END(async_page_fault)
21284+ENDPROC(async_page_fault)
21285 #endif
21286
21287 /*
21288diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21289index 1b69951..8430a6d 100644
21290--- a/arch/x86/kernel/entry_64.S
21291+++ b/arch/x86/kernel/entry_64.S
21292@@ -59,6 +59,8 @@
21293 #include <asm/context_tracking.h>
21294 #include <asm/smap.h>
21295 #include <linux/err.h>
21296+#include <asm/pgtable.h>
21297+#include <asm/alternative-asm.h>
21298
21299 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21300 #include <linux/elf-em.h>
21301@@ -80,8 +82,9 @@
21302 #ifdef CONFIG_DYNAMIC_FTRACE
21303
21304 ENTRY(function_hook)
21305+ pax_force_retaddr
21306 retq
21307-END(function_hook)
21308+ENDPROC(function_hook)
21309
21310 /* skip is set if stack has been adjusted */
21311 .macro ftrace_caller_setup skip=0
21312@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21313 #endif
21314
21315 GLOBAL(ftrace_stub)
21316+ pax_force_retaddr
21317 retq
21318-END(ftrace_caller)
21319+ENDPROC(ftrace_caller)
21320
21321 ENTRY(ftrace_regs_caller)
21322 /* Save the current flags before compare (in SS location)*/
21323@@ -191,7 +195,7 @@ ftrace_restore_flags:
21324 popfq
21325 jmp ftrace_stub
21326
21327-END(ftrace_regs_caller)
21328+ENDPROC(ftrace_regs_caller)
21329
21330
21331 #else /* ! CONFIG_DYNAMIC_FTRACE */
21332@@ -212,6 +216,7 @@ ENTRY(function_hook)
21333 #endif
21334
21335 GLOBAL(ftrace_stub)
21336+ pax_force_retaddr
21337 retq
21338
21339 trace:
21340@@ -225,12 +230,13 @@ trace:
21341 #endif
21342 subq $MCOUNT_INSN_SIZE, %rdi
21343
21344+ pax_force_fptr ftrace_trace_function
21345 call *ftrace_trace_function
21346
21347 MCOUNT_RESTORE_FRAME
21348
21349 jmp ftrace_stub
21350-END(function_hook)
21351+ENDPROC(function_hook)
21352 #endif /* CONFIG_DYNAMIC_FTRACE */
21353 #endif /* CONFIG_FUNCTION_TRACER */
21354
21355@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21356
21357 MCOUNT_RESTORE_FRAME
21358
21359+ pax_force_retaddr
21360 retq
21361-END(ftrace_graph_caller)
21362+ENDPROC(ftrace_graph_caller)
21363
21364 GLOBAL(return_to_handler)
21365 subq $24, %rsp
21366@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21367 movq 8(%rsp), %rdx
21368 movq (%rsp), %rax
21369 addq $24, %rsp
21370+ pax_force_fptr %rdi
21371 jmp *%rdi
21372+ENDPROC(return_to_handler)
21373 #endif
21374
21375
21376@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21377 ENDPROC(native_usergs_sysret64)
21378 #endif /* CONFIG_PARAVIRT */
21379
21380+ .macro ljmpq sel, off
21381+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21382+ .byte 0x48; ljmp *1234f(%rip)
21383+ .pushsection .rodata
21384+ .align 16
21385+ 1234: .quad \off; .word \sel
21386+ .popsection
21387+#else
21388+ pushq $\sel
21389+ pushq $\off
21390+ lretq
21391+#endif
21392+ .endm
21393+
21394+ .macro pax_enter_kernel
21395+ pax_set_fptr_mask
21396+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21397+ call pax_enter_kernel
21398+#endif
21399+ .endm
21400+
21401+ .macro pax_exit_kernel
21402+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21403+ call pax_exit_kernel
21404+#endif
21405+
21406+ .endm
21407+
21408+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21409+ENTRY(pax_enter_kernel)
21410+ pushq %rdi
21411+
21412+#ifdef CONFIG_PARAVIRT
21413+ PV_SAVE_REGS(CLBR_RDI)
21414+#endif
21415+
21416+#ifdef CONFIG_PAX_KERNEXEC
21417+ GET_CR0_INTO_RDI
21418+ bts $16,%rdi
21419+ jnc 3f
21420+ mov %cs,%edi
21421+ cmp $__KERNEL_CS,%edi
21422+ jnz 2f
21423+1:
21424+#endif
21425+
21426+#ifdef CONFIG_PAX_MEMORY_UDEREF
21427+ 661: jmp 111f
21428+ .pushsection .altinstr_replacement, "a"
21429+ 662: ASM_NOP2
21430+ .popsection
21431+ .pushsection .altinstructions, "a"
21432+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21433+ .popsection
21434+ GET_CR3_INTO_RDI
21435+ cmp $0,%dil
21436+ jnz 112f
21437+ mov $__KERNEL_DS,%edi
21438+ mov %edi,%ss
21439+ jmp 111f
21440+112: cmp $1,%dil
21441+ jz 113f
21442+ ud2
21443+113: sub $4097,%rdi
21444+ bts $63,%rdi
21445+ SET_RDI_INTO_CR3
21446+ mov $__UDEREF_KERNEL_DS,%edi
21447+ mov %edi,%ss
21448+111:
21449+#endif
21450+
21451+#ifdef CONFIG_PARAVIRT
21452+ PV_RESTORE_REGS(CLBR_RDI)
21453+#endif
21454+
21455+ popq %rdi
21456+ pax_force_retaddr
21457+ retq
21458+
21459+#ifdef CONFIG_PAX_KERNEXEC
21460+2: ljmpq __KERNEL_CS,1b
21461+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21462+4: SET_RDI_INTO_CR0
21463+ jmp 1b
21464+#endif
21465+ENDPROC(pax_enter_kernel)
21466+
21467+ENTRY(pax_exit_kernel)
21468+ pushq %rdi
21469+
21470+#ifdef CONFIG_PARAVIRT
21471+ PV_SAVE_REGS(CLBR_RDI)
21472+#endif
21473+
21474+#ifdef CONFIG_PAX_KERNEXEC
21475+ mov %cs,%rdi
21476+ cmp $__KERNEXEC_KERNEL_CS,%edi
21477+ jz 2f
21478+ GET_CR0_INTO_RDI
21479+ bts $16,%rdi
21480+ jnc 4f
21481+1:
21482+#endif
21483+
21484+#ifdef CONFIG_PAX_MEMORY_UDEREF
21485+ 661: jmp 111f
21486+ .pushsection .altinstr_replacement, "a"
21487+ 662: ASM_NOP2
21488+ .popsection
21489+ .pushsection .altinstructions, "a"
21490+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21491+ .popsection
21492+ mov %ss,%edi
21493+ cmp $__UDEREF_KERNEL_DS,%edi
21494+ jnz 111f
21495+ GET_CR3_INTO_RDI
21496+ cmp $0,%dil
21497+ jz 112f
21498+ ud2
21499+112: add $4097,%rdi
21500+ bts $63,%rdi
21501+ SET_RDI_INTO_CR3
21502+ mov $__KERNEL_DS,%edi
21503+ mov %edi,%ss
21504+111:
21505+#endif
21506+
21507+#ifdef CONFIG_PARAVIRT
21508+ PV_RESTORE_REGS(CLBR_RDI);
21509+#endif
21510+
21511+ popq %rdi
21512+ pax_force_retaddr
21513+ retq
21514+
21515+#ifdef CONFIG_PAX_KERNEXEC
21516+2: GET_CR0_INTO_RDI
21517+ btr $16,%rdi
21518+ jnc 4f
21519+ ljmpq __KERNEL_CS,3f
21520+3: SET_RDI_INTO_CR0
21521+ jmp 1b
21522+4: ud2
21523+ jmp 4b
21524+#endif
21525+ENDPROC(pax_exit_kernel)
21526+#endif
21527+
21528+ .macro pax_enter_kernel_user
21529+ pax_set_fptr_mask
21530+#ifdef CONFIG_PAX_MEMORY_UDEREF
21531+ call pax_enter_kernel_user
21532+#endif
21533+ .endm
21534+
21535+ .macro pax_exit_kernel_user
21536+#ifdef CONFIG_PAX_MEMORY_UDEREF
21537+ call pax_exit_kernel_user
21538+#endif
21539+#ifdef CONFIG_PAX_RANDKSTACK
21540+ pushq %rax
21541+ pushq %r11
21542+ call pax_randomize_kstack
21543+ popq %r11
21544+ popq %rax
21545+#endif
21546+ .endm
21547+
21548+#ifdef CONFIG_PAX_MEMORY_UDEREF
21549+ENTRY(pax_enter_kernel_user)
21550+ pushq %rdi
21551+ pushq %rbx
21552+
21553+#ifdef CONFIG_PARAVIRT
21554+ PV_SAVE_REGS(CLBR_RDI)
21555+#endif
21556+
21557+ 661: jmp 111f
21558+ .pushsection .altinstr_replacement, "a"
21559+ 662: ASM_NOP2
21560+ .popsection
21561+ .pushsection .altinstructions, "a"
21562+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21563+ .popsection
21564+ GET_CR3_INTO_RDI
21565+ cmp $1,%dil
21566+ jnz 4f
21567+ sub $4097,%rdi
21568+ bts $63,%rdi
21569+ SET_RDI_INTO_CR3
21570+ jmp 3f
21571+111:
21572+
21573+ GET_CR3_INTO_RDI
21574+ mov %rdi,%rbx
21575+ add $__START_KERNEL_map,%rbx
21576+ sub phys_base(%rip),%rbx
21577+
21578+#ifdef CONFIG_PARAVIRT
21579+ cmpl $0, pv_info+PARAVIRT_enabled
21580+ jz 1f
21581+ pushq %rdi
21582+ i = 0
21583+ .rept USER_PGD_PTRS
21584+ mov i*8(%rbx),%rsi
21585+ mov $0,%sil
21586+ lea i*8(%rbx),%rdi
21587+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21588+ i = i + 1
21589+ .endr
21590+ popq %rdi
21591+ jmp 2f
21592+1:
21593+#endif
21594+
21595+ i = 0
21596+ .rept USER_PGD_PTRS
21597+ movb $0,i*8(%rbx)
21598+ i = i + 1
21599+ .endr
21600+
21601+2: SET_RDI_INTO_CR3
21602+
21603+#ifdef CONFIG_PAX_KERNEXEC
21604+ GET_CR0_INTO_RDI
21605+ bts $16,%rdi
21606+ SET_RDI_INTO_CR0
21607+#endif
21608+
21609+3:
21610+
21611+#ifdef CONFIG_PARAVIRT
21612+ PV_RESTORE_REGS(CLBR_RDI)
21613+#endif
21614+
21615+ popq %rbx
21616+ popq %rdi
21617+ pax_force_retaddr
21618+ retq
21619+4: ud2
21620+ENDPROC(pax_enter_kernel_user)
21621+
21622+ENTRY(pax_exit_kernel_user)
21623+ pushq %rdi
21624+ pushq %rbx
21625+
21626+#ifdef CONFIG_PARAVIRT
21627+ PV_SAVE_REGS(CLBR_RDI)
21628+#endif
21629+
21630+ GET_CR3_INTO_RDI
21631+ 661: jmp 1f
21632+ .pushsection .altinstr_replacement, "a"
21633+ 662: ASM_NOP2
21634+ .popsection
21635+ .pushsection .altinstructions, "a"
21636+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21637+ .popsection
21638+ cmp $0,%dil
21639+ jnz 3f
21640+ add $4097,%rdi
21641+ bts $63,%rdi
21642+ SET_RDI_INTO_CR3
21643+ jmp 2f
21644+1:
21645+
21646+ mov %rdi,%rbx
21647+
21648+#ifdef CONFIG_PAX_KERNEXEC
21649+ GET_CR0_INTO_RDI
21650+ btr $16,%rdi
21651+ jnc 3f
21652+ SET_RDI_INTO_CR0
21653+#endif
21654+
21655+ add $__START_KERNEL_map,%rbx
21656+ sub phys_base(%rip),%rbx
21657+
21658+#ifdef CONFIG_PARAVIRT
21659+ cmpl $0, pv_info+PARAVIRT_enabled
21660+ jz 1f
21661+ i = 0
21662+ .rept USER_PGD_PTRS
21663+ mov i*8(%rbx),%rsi
21664+ mov $0x67,%sil
21665+ lea i*8(%rbx),%rdi
21666+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21667+ i = i + 1
21668+ .endr
21669+ jmp 2f
21670+1:
21671+#endif
21672+
21673+ i = 0
21674+ .rept USER_PGD_PTRS
21675+ movb $0x67,i*8(%rbx)
21676+ i = i + 1
21677+ .endr
21678+2:
21679+
21680+#ifdef CONFIG_PARAVIRT
21681+ PV_RESTORE_REGS(CLBR_RDI)
21682+#endif
21683+
21684+ popq %rbx
21685+ popq %rdi
21686+ pax_force_retaddr
21687+ retq
21688+3: ud2
21689+ENDPROC(pax_exit_kernel_user)
21690+#endif
21691+
21692+ .macro pax_enter_kernel_nmi
21693+ pax_set_fptr_mask
21694+
21695+#ifdef CONFIG_PAX_KERNEXEC
21696+ GET_CR0_INTO_RDI
21697+ bts $16,%rdi
21698+ jc 110f
21699+ SET_RDI_INTO_CR0
21700+ or $2,%ebx
21701+110:
21702+#endif
21703+
21704+#ifdef CONFIG_PAX_MEMORY_UDEREF
21705+ 661: jmp 111f
21706+ .pushsection .altinstr_replacement, "a"
21707+ 662: ASM_NOP2
21708+ .popsection
21709+ .pushsection .altinstructions, "a"
21710+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21711+ .popsection
21712+ GET_CR3_INTO_RDI
21713+ cmp $0,%dil
21714+ jz 111f
21715+ sub $4097,%rdi
21716+ or $4,%ebx
21717+ bts $63,%rdi
21718+ SET_RDI_INTO_CR3
21719+ mov $__UDEREF_KERNEL_DS,%edi
21720+ mov %edi,%ss
21721+111:
21722+#endif
21723+ .endm
21724+
21725+ .macro pax_exit_kernel_nmi
21726+#ifdef CONFIG_PAX_KERNEXEC
21727+ btr $1,%ebx
21728+ jnc 110f
21729+ GET_CR0_INTO_RDI
21730+ btr $16,%rdi
21731+ SET_RDI_INTO_CR0
21732+110:
21733+#endif
21734+
21735+#ifdef CONFIG_PAX_MEMORY_UDEREF
21736+ btr $2,%ebx
21737+ jnc 111f
21738+ GET_CR3_INTO_RDI
21739+ add $4097,%rdi
21740+ bts $63,%rdi
21741+ SET_RDI_INTO_CR3
21742+ mov $__KERNEL_DS,%edi
21743+ mov %edi,%ss
21744+111:
21745+#endif
21746+ .endm
21747+
21748+ .macro pax_erase_kstack
21749+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21750+ call pax_erase_kstack
21751+#endif
21752+ .endm
21753+
21754+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21755+ENTRY(pax_erase_kstack)
21756+ pushq %rdi
21757+ pushq %rcx
21758+ pushq %rax
21759+ pushq %r11
21760+
21761+ GET_THREAD_INFO(%r11)
21762+ mov TI_lowest_stack(%r11), %rdi
21763+ mov $-0xBEEF, %rax
21764+ std
21765+
21766+1: mov %edi, %ecx
21767+ and $THREAD_SIZE_asm - 1, %ecx
21768+ shr $3, %ecx
21769+ repne scasq
21770+ jecxz 2f
21771+
21772+ cmp $2*8, %ecx
21773+ jc 2f
21774+
21775+ mov $2*8, %ecx
21776+ repe scasq
21777+ jecxz 2f
21778+ jne 1b
21779+
21780+2: cld
21781+ mov %esp, %ecx
21782+ sub %edi, %ecx
21783+
21784+ cmp $THREAD_SIZE_asm, %rcx
21785+ jb 3f
21786+ ud2
21787+3:
21788+
21789+ shr $3, %ecx
21790+ rep stosq
21791+
21792+ mov TI_task_thread_sp0(%r11), %rdi
21793+ sub $256, %rdi
21794+ mov %rdi, TI_lowest_stack(%r11)
21795+
21796+ popq %r11
21797+ popq %rax
21798+ popq %rcx
21799+ popq %rdi
21800+ pax_force_retaddr
21801+ ret
21802+ENDPROC(pax_erase_kstack)
21803+#endif
21804
21805 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21806 #ifdef CONFIG_TRACE_IRQFLAGS
21807@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21808 .endm
21809
21810 .macro UNFAKE_STACK_FRAME
21811- addq $8*6, %rsp
21812- CFI_ADJUST_CFA_OFFSET -(6*8)
21813+ addq $8*6 + ARG_SKIP, %rsp
21814+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21815 .endm
21816
21817 /*
21818@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21819 movq %rsp, %rsi
21820
21821 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21822- testl $3, CS-RBP(%rsi)
21823+ testb $3, CS-RBP(%rsi)
21824 je 1f
21825 SWAPGS
21826 /*
21827@@ -498,9 +931,10 @@ ENTRY(save_rest)
21828 movq_cfi r15, R15+16
21829 movq %r11, 8(%rsp) /* return address */
21830 FIXUP_TOP_OF_STACK %r11, 16
21831+ pax_force_retaddr
21832 ret
21833 CFI_ENDPROC
21834-END(save_rest)
21835+ENDPROC(save_rest)
21836
21837 /* save complete stack frame */
21838 .pushsection .kprobes.text, "ax"
21839@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21840 js 1f /* negative -> in kernel */
21841 SWAPGS
21842 xorl %ebx,%ebx
21843-1: ret
21844+1: pax_force_retaddr_bts
21845+ ret
21846 CFI_ENDPROC
21847-END(save_paranoid)
21848+ENDPROC(save_paranoid)
21849 .popsection
21850
21851 /*
21852@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21853
21854 RESTORE_REST
21855
21856- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21857+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21858 jz 1f
21859
21860 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21861@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21862 RESTORE_REST
21863 jmp int_ret_from_sys_call
21864 CFI_ENDPROC
21865-END(ret_from_fork)
21866+ENDPROC(ret_from_fork)
21867
21868 /*
21869 * System call entry. Up to 6 arguments in registers are supported.
21870@@ -608,7 +1043,7 @@ END(ret_from_fork)
21871 ENTRY(system_call)
21872 CFI_STARTPROC simple
21873 CFI_SIGNAL_FRAME
21874- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21875+ CFI_DEF_CFA rsp,0
21876 CFI_REGISTER rip,rcx
21877 /*CFI_REGISTER rflags,r11*/
21878 SWAPGS_UNSAFE_STACK
21879@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21880
21881 movq %rsp,PER_CPU_VAR(old_rsp)
21882 movq PER_CPU_VAR(kernel_stack),%rsp
21883+ SAVE_ARGS 8*6,0
21884+ pax_enter_kernel_user
21885+
21886+#ifdef CONFIG_PAX_RANDKSTACK
21887+ pax_erase_kstack
21888+#endif
21889+
21890 /*
21891 * No need to follow this irqs off/on section - it's straight
21892 * and short:
21893 */
21894 ENABLE_INTERRUPTS(CLBR_NONE)
21895- SAVE_ARGS 8,0
21896 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21897 movq %rcx,RIP-ARGOFFSET(%rsp)
21898 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21899- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21900+ GET_THREAD_INFO(%rcx)
21901+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21902 jnz tracesys
21903 system_call_fastpath:
21904 #if __SYSCALL_MASK == ~0
21905@@ -640,7 +1082,7 @@ system_call_fastpath:
21906 cmpl $__NR_syscall_max,%eax
21907 #endif
21908 ja badsys
21909- movq %r10,%rcx
21910+ movq R10-ARGOFFSET(%rsp),%rcx
21911 call *sys_call_table(,%rax,8) # XXX: rip relative
21912 movq %rax,RAX-ARGOFFSET(%rsp)
21913 /*
21914@@ -654,10 +1096,13 @@ sysret_check:
21915 LOCKDEP_SYS_EXIT
21916 DISABLE_INTERRUPTS(CLBR_NONE)
21917 TRACE_IRQS_OFF
21918- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21919+ GET_THREAD_INFO(%rcx)
21920+ movl TI_flags(%rcx),%edx
21921 andl %edi,%edx
21922 jnz sysret_careful
21923 CFI_REMEMBER_STATE
21924+ pax_exit_kernel_user
21925+ pax_erase_kstack
21926 /*
21927 * sysretq will re-enable interrupts:
21928 */
21929@@ -709,14 +1154,18 @@ badsys:
21930 * jump back to the normal fast path.
21931 */
21932 auditsys:
21933- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21934+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21935 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21936 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21937 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21938 movq %rax,%rsi /* 2nd arg: syscall number */
21939 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21940 call __audit_syscall_entry
21941+
21942+ pax_erase_kstack
21943+
21944 LOAD_ARGS 0 /* reload call-clobbered registers */
21945+ pax_set_fptr_mask
21946 jmp system_call_fastpath
21947
21948 /*
21949@@ -737,7 +1186,7 @@ sysret_audit:
21950 /* Do syscall tracing */
21951 tracesys:
21952 #ifdef CONFIG_AUDITSYSCALL
21953- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21954+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21955 jz auditsys
21956 #endif
21957 SAVE_REST
21958@@ -745,12 +1194,16 @@ tracesys:
21959 FIXUP_TOP_OF_STACK %rdi
21960 movq %rsp,%rdi
21961 call syscall_trace_enter
21962+
21963+ pax_erase_kstack
21964+
21965 /*
21966 * Reload arg registers from stack in case ptrace changed them.
21967 * We don't reload %rax because syscall_trace_enter() returned
21968 * the value it wants us to use in the table lookup.
21969 */
21970 LOAD_ARGS ARGOFFSET, 1
21971+ pax_set_fptr_mask
21972 RESTORE_REST
21973 #if __SYSCALL_MASK == ~0
21974 cmpq $__NR_syscall_max,%rax
21975@@ -759,7 +1212,7 @@ tracesys:
21976 cmpl $__NR_syscall_max,%eax
21977 #endif
21978 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21979- movq %r10,%rcx /* fixup for C */
21980+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21981 call *sys_call_table(,%rax,8)
21982 movq %rax,RAX-ARGOFFSET(%rsp)
21983 /* Use IRET because user could have changed frame */
21984@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21985 andl %edi,%edx
21986 jnz int_careful
21987 andl $~TS_COMPAT,TI_status(%rcx)
21988- jmp retint_swapgs
21989+ pax_exit_kernel_user
21990+ pax_erase_kstack
21991+ jmp retint_swapgs_pax
21992
21993 /* Either reschedule or signal or syscall exit tracking needed. */
21994 /* First do a reschedule test. */
21995@@ -826,7 +1281,7 @@ int_restore_rest:
21996 TRACE_IRQS_OFF
21997 jmp int_with_check
21998 CFI_ENDPROC
21999-END(system_call)
22000+ENDPROC(system_call)
22001
22002 .macro FORK_LIKE func
22003 ENTRY(stub_\func)
22004@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22005 DEFAULT_FRAME 0 8 /* offset 8: return address */
22006 call sys_\func
22007 RESTORE_TOP_OF_STACK %r11, 8
22008+ pax_force_retaddr
22009 ret $REST_SKIP /* pop extended registers */
22010 CFI_ENDPROC
22011-END(stub_\func)
22012+ENDPROC(stub_\func)
22013 .endm
22014
22015 .macro FIXED_FRAME label,func
22016@@ -851,9 +1307,10 @@ ENTRY(\label)
22017 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22018 call \func
22019 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22020+ pax_force_retaddr
22021 ret
22022 CFI_ENDPROC
22023-END(\label)
22024+ENDPROC(\label)
22025 .endm
22026
22027 FORK_LIKE clone
22028@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22029 movq_cfi_restore R12+8, r12
22030 movq_cfi_restore RBP+8, rbp
22031 movq_cfi_restore RBX+8, rbx
22032+ pax_force_retaddr
22033 ret $REST_SKIP /* pop extended registers */
22034 CFI_ENDPROC
22035-END(ptregscall_common)
22036+ENDPROC(ptregscall_common)
22037
22038 ENTRY(stub_execve)
22039 CFI_STARTPROC
22040@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22041 RESTORE_REST
22042 jmp int_ret_from_sys_call
22043 CFI_ENDPROC
22044-END(stub_execve)
22045+ENDPROC(stub_execve)
22046
22047 /*
22048 * sigreturn is special because it needs to restore all registers on return.
22049@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22050 RESTORE_REST
22051 jmp int_ret_from_sys_call
22052 CFI_ENDPROC
22053-END(stub_rt_sigreturn)
22054+ENDPROC(stub_rt_sigreturn)
22055
22056 #ifdef CONFIG_X86_X32_ABI
22057 ENTRY(stub_x32_rt_sigreturn)
22058@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22059 RESTORE_REST
22060 jmp int_ret_from_sys_call
22061 CFI_ENDPROC
22062-END(stub_x32_rt_sigreturn)
22063+ENDPROC(stub_x32_rt_sigreturn)
22064
22065 ENTRY(stub_x32_execve)
22066 CFI_STARTPROC
22067@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22068 RESTORE_REST
22069 jmp int_ret_from_sys_call
22070 CFI_ENDPROC
22071-END(stub_x32_execve)
22072+ENDPROC(stub_x32_execve)
22073
22074 #endif
22075
22076@@ -967,7 +1425,7 @@ vector=vector+1
22077 2: jmp common_interrupt
22078 .endr
22079 CFI_ENDPROC
22080-END(irq_entries_start)
22081+ENDPROC(irq_entries_start)
22082
22083 .previous
22084 END(interrupt)
22085@@ -987,6 +1445,16 @@ END(interrupt)
22086 subq $ORIG_RAX-RBP, %rsp
22087 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22088 SAVE_ARGS_IRQ
22089+#ifdef CONFIG_PAX_MEMORY_UDEREF
22090+ testb $3, CS(%rdi)
22091+ jnz 1f
22092+ pax_enter_kernel
22093+ jmp 2f
22094+1: pax_enter_kernel_user
22095+2:
22096+#else
22097+ pax_enter_kernel
22098+#endif
22099 call \func
22100 .endm
22101
22102@@ -1019,7 +1487,7 @@ ret_from_intr:
22103
22104 exit_intr:
22105 GET_THREAD_INFO(%rcx)
22106- testl $3,CS-ARGOFFSET(%rsp)
22107+ testb $3,CS-ARGOFFSET(%rsp)
22108 je retint_kernel
22109
22110 /* Interrupt came from user space */
22111@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22112 * The iretq could re-enable interrupts:
22113 */
22114 DISABLE_INTERRUPTS(CLBR_ANY)
22115+ pax_exit_kernel_user
22116+retint_swapgs_pax:
22117 TRACE_IRQS_IRETQ
22118 SWAPGS
22119 jmp restore_args
22120
22121 retint_restore_args: /* return to kernel space */
22122 DISABLE_INTERRUPTS(CLBR_ANY)
22123+ pax_exit_kernel
22124+ pax_force_retaddr (RIP-ARGOFFSET)
22125 /*
22126 * The iretq could re-enable interrupts:
22127 */
22128@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22129 #endif
22130
22131 CFI_ENDPROC
22132-END(common_interrupt)
22133+ENDPROC(common_interrupt)
22134 /*
22135 * End of kprobes section
22136 */
22137@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22138 interrupt \do_sym
22139 jmp ret_from_intr
22140 CFI_ENDPROC
22141-END(\sym)
22142+ENDPROC(\sym)
22143 .endm
22144
22145 #ifdef CONFIG_TRACING
22146@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22147 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22148 call error_entry
22149 DEFAULT_FRAME 0
22150+#ifdef CONFIG_PAX_MEMORY_UDEREF
22151+ testb $3, CS(%rsp)
22152+ jnz 1f
22153+ pax_enter_kernel
22154+ jmp 2f
22155+1: pax_enter_kernel_user
22156+2:
22157+#else
22158+ pax_enter_kernel
22159+#endif
22160 movq %rsp,%rdi /* pt_regs pointer */
22161 xorl %esi,%esi /* no error code */
22162 call \do_sym
22163 jmp error_exit /* %ebx: no swapgs flag */
22164 CFI_ENDPROC
22165-END(\sym)
22166+ENDPROC(\sym)
22167 .endm
22168
22169 .macro paranoidzeroentry sym do_sym
22170@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22171 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22172 call save_paranoid
22173 TRACE_IRQS_OFF
22174+#ifdef CONFIG_PAX_MEMORY_UDEREF
22175+ testb $3, CS(%rsp)
22176+ jnz 1f
22177+ pax_enter_kernel
22178+ jmp 2f
22179+1: pax_enter_kernel_user
22180+2:
22181+#else
22182+ pax_enter_kernel
22183+#endif
22184 movq %rsp,%rdi /* pt_regs pointer */
22185 xorl %esi,%esi /* no error code */
22186 call \do_sym
22187 jmp paranoid_exit /* %ebx: no swapgs flag */
22188 CFI_ENDPROC
22189-END(\sym)
22190+ENDPROC(\sym)
22191 .endm
22192
22193-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22194+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22195 .macro paranoidzeroentry_ist sym do_sym ist
22196 ENTRY(\sym)
22197 INTR_FRAME
22198@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22199 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22200 call save_paranoid
22201 TRACE_IRQS_OFF_DEBUG
22202+#ifdef CONFIG_PAX_MEMORY_UDEREF
22203+ testb $3, CS(%rsp)
22204+ jnz 1f
22205+ pax_enter_kernel
22206+ jmp 2f
22207+1: pax_enter_kernel_user
22208+2:
22209+#else
22210+ pax_enter_kernel
22211+#endif
22212 movq %rsp,%rdi /* pt_regs pointer */
22213 xorl %esi,%esi /* no error code */
22214+#ifdef CONFIG_SMP
22215+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22216+ lea init_tss(%r12), %r12
22217+#else
22218+ lea init_tss(%rip), %r12
22219+#endif
22220 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22221 call \do_sym
22222 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22223 jmp paranoid_exit /* %ebx: no swapgs flag */
22224 CFI_ENDPROC
22225-END(\sym)
22226+ENDPROC(\sym)
22227 .endm
22228
22229 .macro errorentry sym do_sym
22230@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22231 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22232 call error_entry
22233 DEFAULT_FRAME 0
22234+#ifdef CONFIG_PAX_MEMORY_UDEREF
22235+ testb $3, CS(%rsp)
22236+ jnz 1f
22237+ pax_enter_kernel
22238+ jmp 2f
22239+1: pax_enter_kernel_user
22240+2:
22241+#else
22242+ pax_enter_kernel
22243+#endif
22244 movq %rsp,%rdi /* pt_regs pointer */
22245 movq ORIG_RAX(%rsp),%rsi /* get error code */
22246 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22247 call \do_sym
22248 jmp error_exit /* %ebx: no swapgs flag */
22249 CFI_ENDPROC
22250-END(\sym)
22251+ENDPROC(\sym)
22252 .endm
22253
22254 /* error code is on the stack already */
22255@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22256 call save_paranoid
22257 DEFAULT_FRAME 0
22258 TRACE_IRQS_OFF
22259+#ifdef CONFIG_PAX_MEMORY_UDEREF
22260+ testb $3, CS(%rsp)
22261+ jnz 1f
22262+ pax_enter_kernel
22263+ jmp 2f
22264+1: pax_enter_kernel_user
22265+2:
22266+#else
22267+ pax_enter_kernel
22268+#endif
22269 movq %rsp,%rdi /* pt_regs pointer */
22270 movq ORIG_RAX(%rsp),%rsi /* get error code */
22271 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22272 call \do_sym
22273 jmp paranoid_exit /* %ebx: no swapgs flag */
22274 CFI_ENDPROC
22275-END(\sym)
22276+ENDPROC(\sym)
22277 .endm
22278
22279 zeroentry divide_error do_divide_error
22280@@ -1342,9 +1870,10 @@ gs_change:
22281 2: mfence /* workaround */
22282 SWAPGS
22283 popfq_cfi
22284+ pax_force_retaddr
22285 ret
22286 CFI_ENDPROC
22287-END(native_load_gs_index)
22288+ENDPROC(native_load_gs_index)
22289
22290 _ASM_EXTABLE(gs_change,bad_gs)
22291 .section .fixup,"ax"
22292@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22293 CFI_DEF_CFA_REGISTER rsp
22294 CFI_ADJUST_CFA_OFFSET -8
22295 decl PER_CPU_VAR(irq_count)
22296+ pax_force_retaddr
22297 ret
22298 CFI_ENDPROC
22299-END(call_softirq)
22300+ENDPROC(call_softirq)
22301
22302 #ifdef CONFIG_XEN
22303 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22304@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22305 decl PER_CPU_VAR(irq_count)
22306 jmp error_exit
22307 CFI_ENDPROC
22308-END(xen_do_hypervisor_callback)
22309+ENDPROC(xen_do_hypervisor_callback)
22310
22311 /*
22312 * Hypervisor uses this for application faults while it executes.
22313@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22314 SAVE_ALL
22315 jmp error_exit
22316 CFI_ENDPROC
22317-END(xen_failsafe_callback)
22318+ENDPROC(xen_failsafe_callback)
22319
22320 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22321 xen_hvm_callback_vector xen_evtchn_do_upcall
22322@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22323 DEFAULT_FRAME
22324 DISABLE_INTERRUPTS(CLBR_NONE)
22325 TRACE_IRQS_OFF_DEBUG
22326- testl %ebx,%ebx /* swapgs needed? */
22327+ testl $1,%ebx /* swapgs needed? */
22328 jnz paranoid_restore
22329- testl $3,CS(%rsp)
22330+ testb $3,CS(%rsp)
22331 jnz paranoid_userspace
22332+#ifdef CONFIG_PAX_MEMORY_UDEREF
22333+ pax_exit_kernel
22334+ TRACE_IRQS_IRETQ 0
22335+ SWAPGS_UNSAFE_STACK
22336+ RESTORE_ALL 8
22337+ pax_force_retaddr_bts
22338+ jmp irq_return
22339+#endif
22340 paranoid_swapgs:
22341+#ifdef CONFIG_PAX_MEMORY_UDEREF
22342+ pax_exit_kernel_user
22343+#else
22344+ pax_exit_kernel
22345+#endif
22346 TRACE_IRQS_IRETQ 0
22347 SWAPGS_UNSAFE_STACK
22348 RESTORE_ALL 8
22349 jmp irq_return
22350 paranoid_restore:
22351+ pax_exit_kernel
22352 TRACE_IRQS_IRETQ_DEBUG 0
22353 RESTORE_ALL 8
22354+ pax_force_retaddr_bts
22355 jmp irq_return
22356 paranoid_userspace:
22357 GET_THREAD_INFO(%rcx)
22358@@ -1563,7 +2108,7 @@ paranoid_schedule:
22359 TRACE_IRQS_OFF
22360 jmp paranoid_userspace
22361 CFI_ENDPROC
22362-END(paranoid_exit)
22363+ENDPROC(paranoid_exit)
22364
22365 /*
22366 * Exception entry point. This expects an error code/orig_rax on the stack.
22367@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22368 movq_cfi r14, R14+8
22369 movq_cfi r15, R15+8
22370 xorl %ebx,%ebx
22371- testl $3,CS+8(%rsp)
22372+ testb $3,CS+8(%rsp)
22373 je error_kernelspace
22374 error_swapgs:
22375 SWAPGS
22376 error_sti:
22377 TRACE_IRQS_OFF
22378+ pax_force_retaddr_bts
22379 ret
22380
22381 /*
22382@@ -1622,7 +2168,7 @@ bstep_iret:
22383 movq %rcx,RIP+8(%rsp)
22384 jmp error_swapgs
22385 CFI_ENDPROC
22386-END(error_entry)
22387+ENDPROC(error_entry)
22388
22389
22390 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22391@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22392 DISABLE_INTERRUPTS(CLBR_NONE)
22393 TRACE_IRQS_OFF
22394 GET_THREAD_INFO(%rcx)
22395- testl %eax,%eax
22396+ testl $1,%eax
22397 jne retint_kernel
22398 LOCKDEP_SYS_EXIT_IRQ
22399 movl TI_flags(%rcx),%edx
22400@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22401 jnz retint_careful
22402 jmp retint_swapgs
22403 CFI_ENDPROC
22404-END(error_exit)
22405+ENDPROC(error_exit)
22406
22407 /*
22408 * Test if a given stack is an NMI stack or not.
22409@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22410 * If %cs was not the kernel segment, then the NMI triggered in user
22411 * space, which means it is definitely not nested.
22412 */
22413+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22414+ je 1f
22415 cmpl $__KERNEL_CS, 16(%rsp)
22416 jne first_nmi
22417-
22418+1:
22419 /*
22420 * Check the special variable on the stack to see if NMIs are
22421 * executing.
22422@@ -1736,8 +2284,7 @@ nested_nmi:
22423
22424 1:
22425 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22426- leaq -1*8(%rsp), %rdx
22427- movq %rdx, %rsp
22428+ subq $8, %rsp
22429 CFI_ADJUST_CFA_OFFSET 1*8
22430 leaq -10*8(%rsp), %rdx
22431 pushq_cfi $__KERNEL_DS
22432@@ -1755,6 +2302,7 @@ nested_nmi_out:
22433 CFI_RESTORE rdx
22434
22435 /* No need to check faults here */
22436+# pax_force_retaddr_bts
22437 INTERRUPT_RETURN
22438
22439 CFI_RESTORE_STATE
22440@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22441 */
22442 movq %cr2, %r12
22443
22444+ pax_enter_kernel_nmi
22445+
22446 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22447 movq %rsp,%rdi
22448 movq $-1,%rsi
22449@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22450 movq %r12, %cr2
22451 1:
22452
22453- testl %ebx,%ebx /* swapgs needed? */
22454+ testl $1,%ebx /* swapgs needed? */
22455 jnz nmi_restore
22456 nmi_swapgs:
22457 SWAPGS_UNSAFE_STACK
22458 nmi_restore:
22459+ pax_exit_kernel_nmi
22460 /* Pop the extra iret frame at once */
22461 RESTORE_ALL 6*8
22462+ testb $3, 8(%rsp)
22463+ jnz 1f
22464+ pax_force_retaddr_bts
22465+1:
22466
22467 /* Clear the NMI executing stack variable */
22468 movq $0, 5*8(%rsp)
22469 jmp irq_return
22470 CFI_ENDPROC
22471-END(nmi)
22472+ENDPROC(nmi)
22473
22474 ENTRY(ignore_sysret)
22475 CFI_STARTPROC
22476 mov $-ENOSYS,%eax
22477 sysret
22478 CFI_ENDPROC
22479-END(ignore_sysret)
22480+ENDPROC(ignore_sysret)
22481
22482 /*
22483 * End of kprobes section
22484diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22485index 42a392a..fbbd930 100644
22486--- a/arch/x86/kernel/ftrace.c
22487+++ b/arch/x86/kernel/ftrace.c
22488@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22489 {
22490 unsigned char replaced[MCOUNT_INSN_SIZE];
22491
22492+ ip = ktla_ktva(ip);
22493+
22494 /*
22495 * Note: Due to modules and __init, code can
22496 * disappear and change, we need to protect against faulting
22497@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22498 unsigned char old[MCOUNT_INSN_SIZE], *new;
22499 int ret;
22500
22501- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22502+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22503 new = ftrace_call_replace(ip, (unsigned long)func);
22504
22505 /* See comment above by declaration of modifying_ftrace_code */
22506@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22507 /* Also update the regs callback function */
22508 if (!ret) {
22509 ip = (unsigned long)(&ftrace_regs_call);
22510- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22511+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22512 new = ftrace_call_replace(ip, (unsigned long)func);
22513 ret = ftrace_modify_code(ip, old, new);
22514 }
22515@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22516 * kernel identity mapping to modify code.
22517 */
22518 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22519- ip = (unsigned long)__va(__pa_symbol(ip));
22520+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22521
22522 return probe_kernel_write((void *)ip, val, size);
22523 }
22524@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22525 unsigned char replaced[MCOUNT_INSN_SIZE];
22526 unsigned char brk = BREAKPOINT_INSTRUCTION;
22527
22528- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22529+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22530 return -EFAULT;
22531
22532 /* Make sure it is what we expect it to be */
22533@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22534 return ret;
22535
22536 fail_update:
22537- probe_kernel_write((void *)ip, &old_code[0], 1);
22538+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22539 goto out;
22540 }
22541
22542@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22543 {
22544 unsigned char code[MCOUNT_INSN_SIZE];
22545
22546+ ip = ktla_ktva(ip);
22547+
22548 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22549 return -EFAULT;
22550
22551diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22552index 55b6761..a6456fc 100644
22553--- a/arch/x86/kernel/head64.c
22554+++ b/arch/x86/kernel/head64.c
22555@@ -67,12 +67,12 @@ again:
22556 pgd = *pgd_p;
22557
22558 /*
22559- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22560- * critical -- __PAGE_OFFSET would point us back into the dynamic
22561+ * The use of __early_va rather than __va here is critical:
22562+ * __va would point us back into the dynamic
22563 * range and we might end up looping forever...
22564 */
22565 if (pgd)
22566- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22567+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22568 else {
22569 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22570 reset_early_page_tables();
22571@@ -82,13 +82,13 @@ again:
22572 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22573 for (i = 0; i < PTRS_PER_PUD; i++)
22574 pud_p[i] = 0;
22575- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22576+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22577 }
22578 pud_p += pud_index(address);
22579 pud = *pud_p;
22580
22581 if (pud)
22582- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22583+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22584 else {
22585 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22586 reset_early_page_tables();
22587@@ -98,7 +98,7 @@ again:
22588 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22589 for (i = 0; i < PTRS_PER_PMD; i++)
22590 pmd_p[i] = 0;
22591- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22592+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22593 }
22594 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22595 pmd_p[pmd_index(address)] = pmd;
22596@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22597 if (console_loglevel == 10)
22598 early_printk("Kernel alive\n");
22599
22600- clear_page(init_level4_pgt);
22601 /* set init_level4_pgt kernel high mapping*/
22602 init_level4_pgt[511] = early_level4_pgt[511];
22603
22604diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22605index 5dd87a8..d68b3f4 100644
22606--- a/arch/x86/kernel/head_32.S
22607+++ b/arch/x86/kernel/head_32.S
22608@@ -26,6 +26,12 @@
22609 /* Physical address */
22610 #define pa(X) ((X) - __PAGE_OFFSET)
22611
22612+#ifdef CONFIG_PAX_KERNEXEC
22613+#define ta(X) (X)
22614+#else
22615+#define ta(X) ((X) - __PAGE_OFFSET)
22616+#endif
22617+
22618 /*
22619 * References to members of the new_cpu_data structure.
22620 */
22621@@ -55,11 +61,7 @@
22622 * and small than max_low_pfn, otherwise will waste some page table entries
22623 */
22624
22625-#if PTRS_PER_PMD > 1
22626-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22627-#else
22628-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22629-#endif
22630+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22631
22632 /* Number of possible pages in the lowmem region */
22633 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22634@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22635 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22636
22637 /*
22638+ * Real beginning of normal "text" segment
22639+ */
22640+ENTRY(stext)
22641+ENTRY(_stext)
22642+
22643+/*
22644 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22645 * %esi points to the real-mode code as a 32-bit pointer.
22646 * CS and DS must be 4 GB flat segments, but we don't depend on
22647@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22648 * can.
22649 */
22650 __HEAD
22651+
22652+#ifdef CONFIG_PAX_KERNEXEC
22653+ jmp startup_32
22654+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22655+.fill PAGE_SIZE-5,1,0xcc
22656+#endif
22657+
22658 ENTRY(startup_32)
22659 movl pa(stack_start),%ecx
22660
22661@@ -106,6 +121,59 @@ ENTRY(startup_32)
22662 2:
22663 leal -__PAGE_OFFSET(%ecx),%esp
22664
22665+#ifdef CONFIG_SMP
22666+ movl $pa(cpu_gdt_table),%edi
22667+ movl $__per_cpu_load,%eax
22668+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22669+ rorl $16,%eax
22670+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22671+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22672+ movl $__per_cpu_end - 1,%eax
22673+ subl $__per_cpu_start,%eax
22674+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22675+#endif
22676+
22677+#ifdef CONFIG_PAX_MEMORY_UDEREF
22678+ movl $NR_CPUS,%ecx
22679+ movl $pa(cpu_gdt_table),%edi
22680+1:
22681+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22682+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22683+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22684+ addl $PAGE_SIZE_asm,%edi
22685+ loop 1b
22686+#endif
22687+
22688+#ifdef CONFIG_PAX_KERNEXEC
22689+ movl $pa(boot_gdt),%edi
22690+ movl $__LOAD_PHYSICAL_ADDR,%eax
22691+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22692+ rorl $16,%eax
22693+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22694+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22695+ rorl $16,%eax
22696+
22697+ ljmp $(__BOOT_CS),$1f
22698+1:
22699+
22700+ movl $NR_CPUS,%ecx
22701+ movl $pa(cpu_gdt_table),%edi
22702+ addl $__PAGE_OFFSET,%eax
22703+1:
22704+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22705+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22706+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22707+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22708+ rorl $16,%eax
22709+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22710+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22711+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22712+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22713+ rorl $16,%eax
22714+ addl $PAGE_SIZE_asm,%edi
22715+ loop 1b
22716+#endif
22717+
22718 /*
22719 * Clear BSS first so that there are no surprises...
22720 */
22721@@ -201,8 +269,11 @@ ENTRY(startup_32)
22722 movl %eax, pa(max_pfn_mapped)
22723
22724 /* Do early initialization of the fixmap area */
22725- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22726- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22727+#ifdef CONFIG_COMPAT_VDSO
22728+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22729+#else
22730+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22731+#endif
22732 #else /* Not PAE */
22733
22734 page_pde_offset = (__PAGE_OFFSET >> 20);
22735@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22736 movl %eax, pa(max_pfn_mapped)
22737
22738 /* Do early initialization of the fixmap area */
22739- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22740- movl %eax,pa(initial_page_table+0xffc)
22741+#ifdef CONFIG_COMPAT_VDSO
22742+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22743+#else
22744+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22745+#endif
22746 #endif
22747
22748 #ifdef CONFIG_PARAVIRT
22749@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22750 cmpl $num_subarch_entries, %eax
22751 jae bad_subarch
22752
22753- movl pa(subarch_entries)(,%eax,4), %eax
22754- subl $__PAGE_OFFSET, %eax
22755- jmp *%eax
22756+ jmp *pa(subarch_entries)(,%eax,4)
22757
22758 bad_subarch:
22759 WEAK(lguest_entry)
22760@@ -261,10 +333,10 @@ WEAK(xen_entry)
22761 __INITDATA
22762
22763 subarch_entries:
22764- .long default_entry /* normal x86/PC */
22765- .long lguest_entry /* lguest hypervisor */
22766- .long xen_entry /* Xen hypervisor */
22767- .long default_entry /* Moorestown MID */
22768+ .long ta(default_entry) /* normal x86/PC */
22769+ .long ta(lguest_entry) /* lguest hypervisor */
22770+ .long ta(xen_entry) /* Xen hypervisor */
22771+ .long ta(default_entry) /* Moorestown MID */
22772 num_subarch_entries = (. - subarch_entries) / 4
22773 .previous
22774 #else
22775@@ -354,6 +426,7 @@ default_entry:
22776 movl pa(mmu_cr4_features),%eax
22777 movl %eax,%cr4
22778
22779+#ifdef CONFIG_X86_PAE
22780 testb $X86_CR4_PAE, %al # check if PAE is enabled
22781 jz enable_paging
22782
22783@@ -382,6 +455,9 @@ default_entry:
22784 /* Make changes effective */
22785 wrmsr
22786
22787+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22788+#endif
22789+
22790 enable_paging:
22791
22792 /*
22793@@ -449,14 +525,20 @@ is486:
22794 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22795 movl %eax,%ss # after changing gdt.
22796
22797- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22798+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22799 movl %eax,%ds
22800 movl %eax,%es
22801
22802 movl $(__KERNEL_PERCPU), %eax
22803 movl %eax,%fs # set this cpu's percpu
22804
22805+#ifdef CONFIG_CC_STACKPROTECTOR
22806 movl $(__KERNEL_STACK_CANARY),%eax
22807+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22808+ movl $(__USER_DS),%eax
22809+#else
22810+ xorl %eax,%eax
22811+#endif
22812 movl %eax,%gs
22813
22814 xorl %eax,%eax # Clear LDT
22815@@ -512,8 +594,11 @@ setup_once:
22816 * relocation. Manually set base address in stack canary
22817 * segment descriptor.
22818 */
22819- movl $gdt_page,%eax
22820+ movl $cpu_gdt_table,%eax
22821 movl $stack_canary,%ecx
22822+#ifdef CONFIG_SMP
22823+ addl $__per_cpu_load,%ecx
22824+#endif
22825 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22826 shrl $16, %ecx
22827 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22828@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22829 /* This is global to keep gas from relaxing the jumps */
22830 ENTRY(early_idt_handler)
22831 cld
22832- cmpl $2,%ss:early_recursion_flag
22833+ cmpl $1,%ss:early_recursion_flag
22834 je hlt_loop
22835 incl %ss:early_recursion_flag
22836
22837@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22838 pushl (20+6*4)(%esp) /* trapno */
22839 pushl $fault_msg
22840 call printk
22841-#endif
22842 call dump_stack
22843+#endif
22844 hlt_loop:
22845 hlt
22846 jmp hlt_loop
22847@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22848 /* This is the default interrupt "handler" :-) */
22849 ALIGN
22850 ignore_int:
22851- cld
22852 #ifdef CONFIG_PRINTK
22853+ cmpl $2,%ss:early_recursion_flag
22854+ je hlt_loop
22855+ incl %ss:early_recursion_flag
22856+ cld
22857 pushl %eax
22858 pushl %ecx
22859 pushl %edx
22860@@ -612,9 +700,6 @@ ignore_int:
22861 movl $(__KERNEL_DS),%eax
22862 movl %eax,%ds
22863 movl %eax,%es
22864- cmpl $2,early_recursion_flag
22865- je hlt_loop
22866- incl early_recursion_flag
22867 pushl 16(%esp)
22868 pushl 24(%esp)
22869 pushl 32(%esp)
22870@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22871 /*
22872 * BSS section
22873 */
22874-__PAGE_ALIGNED_BSS
22875- .align PAGE_SIZE
22876 #ifdef CONFIG_X86_PAE
22877+.section .initial_pg_pmd,"a",@progbits
22878 initial_pg_pmd:
22879 .fill 1024*KPMDS,4,0
22880 #else
22881+.section .initial_page_table,"a",@progbits
22882 ENTRY(initial_page_table)
22883 .fill 1024,4,0
22884 #endif
22885+.section .initial_pg_fixmap,"a",@progbits
22886 initial_pg_fixmap:
22887 .fill 1024,4,0
22888+.section .empty_zero_page,"a",@progbits
22889 ENTRY(empty_zero_page)
22890 .fill 4096,1,0
22891+.section .swapper_pg_dir,"a",@progbits
22892 ENTRY(swapper_pg_dir)
22893+#ifdef CONFIG_X86_PAE
22894+ .fill 4,8,0
22895+#else
22896 .fill 1024,4,0
22897+#endif
22898
22899 /*
22900 * This starts the data section.
22901 */
22902 #ifdef CONFIG_X86_PAE
22903-__PAGE_ALIGNED_DATA
22904- /* Page-aligned for the benefit of paravirt? */
22905- .align PAGE_SIZE
22906+.section .initial_page_table,"a",@progbits
22907 ENTRY(initial_page_table)
22908 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22909 # if KPMDS == 3
22910@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22911 # error "Kernel PMDs should be 1, 2 or 3"
22912 # endif
22913 .align PAGE_SIZE /* needs to be page-sized too */
22914+
22915+#ifdef CONFIG_PAX_PER_CPU_PGD
22916+ENTRY(cpu_pgd)
22917+ .rept 2*NR_CPUS
22918+ .fill 4,8,0
22919+ .endr
22920+#endif
22921+
22922 #endif
22923
22924 .data
22925 .balign 4
22926 ENTRY(stack_start)
22927- .long init_thread_union+THREAD_SIZE
22928+ .long init_thread_union+THREAD_SIZE-8
22929
22930 __INITRODATA
22931 int_msg:
22932@@ -722,7 +820,7 @@ fault_msg:
22933 * segment size, and 32-bit linear address value:
22934 */
22935
22936- .data
22937+.section .rodata,"a",@progbits
22938 .globl boot_gdt_descr
22939 .globl idt_descr
22940
22941@@ -731,7 +829,7 @@ fault_msg:
22942 .word 0 # 32 bit align gdt_desc.address
22943 boot_gdt_descr:
22944 .word __BOOT_DS+7
22945- .long boot_gdt - __PAGE_OFFSET
22946+ .long pa(boot_gdt)
22947
22948 .word 0 # 32-bit align idt_desc.address
22949 idt_descr:
22950@@ -742,7 +840,7 @@ idt_descr:
22951 .word 0 # 32 bit align gdt_desc.address
22952 ENTRY(early_gdt_descr)
22953 .word GDT_ENTRIES*8-1
22954- .long gdt_page /* Overwritten for secondary CPUs */
22955+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22956
22957 /*
22958 * The boot_gdt must mirror the equivalent in setup.S and is
22959@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22960 .align L1_CACHE_BYTES
22961 ENTRY(boot_gdt)
22962 .fill GDT_ENTRY_BOOT_CS,8,0
22963- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22964- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22965+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22966+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22967+
22968+ .align PAGE_SIZE_asm
22969+ENTRY(cpu_gdt_table)
22970+ .rept NR_CPUS
22971+ .quad 0x0000000000000000 /* NULL descriptor */
22972+ .quad 0x0000000000000000 /* 0x0b reserved */
22973+ .quad 0x0000000000000000 /* 0x13 reserved */
22974+ .quad 0x0000000000000000 /* 0x1b reserved */
22975+
22976+#ifdef CONFIG_PAX_KERNEXEC
22977+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22978+#else
22979+ .quad 0x0000000000000000 /* 0x20 unused */
22980+#endif
22981+
22982+ .quad 0x0000000000000000 /* 0x28 unused */
22983+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22984+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22985+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22986+ .quad 0x0000000000000000 /* 0x4b reserved */
22987+ .quad 0x0000000000000000 /* 0x53 reserved */
22988+ .quad 0x0000000000000000 /* 0x5b reserved */
22989+
22990+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22991+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22992+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22993+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22994+
22995+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22996+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22997+
22998+ /*
22999+ * Segments used for calling PnP BIOS have byte granularity.
23000+ * The code segments and data segments have fixed 64k limits,
23001+ * the transfer segment sizes are set at run time.
23002+ */
23003+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23004+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23005+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23006+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23007+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23008+
23009+ /*
23010+ * The APM segments have byte granularity and their bases
23011+ * are set at run time. All have 64k limits.
23012+ */
23013+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23014+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23015+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23016+
23017+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23018+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23019+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23020+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23021+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23022+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23023+
23024+ /* Be sure this is zeroed to avoid false validations in Xen */
23025+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23026+ .endr
23027diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23028index e1aabdb..73dcad8 100644
23029--- a/arch/x86/kernel/head_64.S
23030+++ b/arch/x86/kernel/head_64.S
23031@@ -20,6 +20,8 @@
23032 #include <asm/processor-flags.h>
23033 #include <asm/percpu.h>
23034 #include <asm/nops.h>
23035+#include <asm/cpufeature.h>
23036+#include <asm/alternative-asm.h>
23037
23038 #ifdef CONFIG_PARAVIRT
23039 #include <asm/asm-offsets.h>
23040@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23041 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23042 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23043 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23044+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23045+L3_VMALLOC_START = pud_index(VMALLOC_START)
23046+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23047+L3_VMALLOC_END = pud_index(VMALLOC_END)
23048+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23049+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23050
23051 .text
23052 __HEAD
23053@@ -89,11 +97,23 @@ startup_64:
23054 * Fixup the physical addresses in the page table
23055 */
23056 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23057+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23058+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23059+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23060+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23061+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23062
23063- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23064- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23065+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23066+#ifndef CONFIG_XEN
23067+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23068+#endif
23069
23070- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23071+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23072+
23073+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23074+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23075+
23076+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23077
23078 /*
23079 * Set up the identity mapping for the switchover. These
23080@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23081 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23082 1:
23083
23084- /* Enable PAE mode and PGE */
23085- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23086+ /* Enable PAE mode and PSE/PGE */
23087+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23088 movq %rcx, %cr4
23089
23090 /* Setup early boot stage 4 level pagetables. */
23091@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23092 movl $MSR_EFER, %ecx
23093 rdmsr
23094 btsl $_EFER_SCE, %eax /* Enable System Call */
23095- btl $20,%edi /* No Execute supported? */
23096+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23097 jnc 1f
23098 btsl $_EFER_NX, %eax
23099 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23100+ leaq init_level4_pgt(%rip), %rdi
23101+#ifndef CONFIG_EFI
23102+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23103+#endif
23104+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23105+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23106+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23107+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23108 1: wrmsr /* Make changes effective */
23109
23110 /* Setup cr0 */
23111@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23112 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23113 * address given in m16:64.
23114 */
23115+ pax_set_fptr_mask
23116 movq initial_code(%rip),%rax
23117 pushq $0 # fake return address to stop unwinder
23118 pushq $__KERNEL_CS # set correct cs
23119@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23120 call dump_stack
23121 #ifdef CONFIG_KALLSYMS
23122 leaq early_idt_ripmsg(%rip),%rdi
23123- movq 40(%rsp),%rsi # %rip again
23124+ movq 88(%rsp),%rsi # %rip again
23125 call __print_symbol
23126 #endif
23127 #endif /* EARLY_PRINTK */
23128@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23129 early_recursion_flag:
23130 .long 0
23131
23132+ .section .rodata,"a",@progbits
23133 #ifdef CONFIG_EARLY_PRINTK
23134 early_idt_msg:
23135 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23136@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23137 NEXT_PAGE(early_dynamic_pgts)
23138 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23139
23140- .data
23141+ .section .rodata,"a",@progbits
23142
23143-#ifndef CONFIG_XEN
23144 NEXT_PAGE(init_level4_pgt)
23145- .fill 512,8,0
23146-#else
23147-NEXT_PAGE(init_level4_pgt)
23148- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23149 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23150 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23151+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23152+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23153+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23154+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23155+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23156+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23157 .org init_level4_pgt + L4_START_KERNEL*8, 0
23158 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23159 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23160
23161+#ifdef CONFIG_PAX_PER_CPU_PGD
23162+NEXT_PAGE(cpu_pgd)
23163+ .rept 2*NR_CPUS
23164+ .fill 512,8,0
23165+ .endr
23166+#endif
23167+
23168 NEXT_PAGE(level3_ident_pgt)
23169 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23170+#ifdef CONFIG_XEN
23171 .fill 511, 8, 0
23172+#else
23173+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23174+ .fill 510,8,0
23175+#endif
23176+
23177+NEXT_PAGE(level3_vmalloc_start_pgt)
23178+ .fill 512,8,0
23179+
23180+NEXT_PAGE(level3_vmalloc_end_pgt)
23181+ .fill 512,8,0
23182+
23183+NEXT_PAGE(level3_vmemmap_pgt)
23184+ .fill L3_VMEMMAP_START,8,0
23185+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23186+
23187 NEXT_PAGE(level2_ident_pgt)
23188- /* Since I easily can, map the first 1G.
23189+ /* Since I easily can, map the first 2G.
23190 * Don't set NX because code runs from these pages.
23191 */
23192- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23193-#endif
23194+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23195
23196 NEXT_PAGE(level3_kernel_pgt)
23197 .fill L3_START_KERNEL,8,0
23198@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23199 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23200 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23201
23202+NEXT_PAGE(level2_vmemmap_pgt)
23203+ .fill 512,8,0
23204+
23205 NEXT_PAGE(level2_kernel_pgt)
23206 /*
23207 * 512 MB kernel mapping. We spend a full page on this pagetable
23208@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23209 KERNEL_IMAGE_SIZE/PMD_SIZE)
23210
23211 NEXT_PAGE(level2_fixmap_pgt)
23212- .fill 506,8,0
23213- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23214- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23215- .fill 5,8,0
23216+ .fill 507,8,0
23217+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23218+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23219+ .fill 4,8,0
23220
23221-NEXT_PAGE(level1_fixmap_pgt)
23222+NEXT_PAGE(level1_vsyscall_pgt)
23223 .fill 512,8,0
23224
23225 #undef PMDS
23226
23227- .data
23228+ .align PAGE_SIZE
23229+ENTRY(cpu_gdt_table)
23230+ .rept NR_CPUS
23231+ .quad 0x0000000000000000 /* NULL descriptor */
23232+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23233+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23234+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23235+ .quad 0x00cffb000000ffff /* __USER32_CS */
23236+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23237+ .quad 0x00affb000000ffff /* __USER_CS */
23238+
23239+#ifdef CONFIG_PAX_KERNEXEC
23240+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23241+#else
23242+ .quad 0x0 /* unused */
23243+#endif
23244+
23245+ .quad 0,0 /* TSS */
23246+ .quad 0,0 /* LDT */
23247+ .quad 0,0,0 /* three TLS descriptors */
23248+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23249+ /* asm/segment.h:GDT_ENTRIES must match this */
23250+
23251+#ifdef CONFIG_PAX_MEMORY_UDEREF
23252+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23253+#else
23254+ .quad 0x0 /* unused */
23255+#endif
23256+
23257+ /* zero the remaining page */
23258+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23259+ .endr
23260+
23261 .align 16
23262 .globl early_gdt_descr
23263 early_gdt_descr:
23264 .word GDT_ENTRIES*8-1
23265 early_gdt_descr_base:
23266- .quad INIT_PER_CPU_VAR(gdt_page)
23267+ .quad cpu_gdt_table
23268
23269 ENTRY(phys_base)
23270 /* This must match the first entry in level2_kernel_pgt */
23271 .quad 0x0000000000000000
23272
23273 #include "../../x86/xen/xen-head.S"
23274-
23275- __PAGE_ALIGNED_BSS
23276+
23277+ .section .rodata,"a",@progbits
23278 NEXT_PAGE(empty_zero_page)
23279 .skip PAGE_SIZE
23280diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23281index 0fa6912..b37438b 100644
23282--- a/arch/x86/kernel/i386_ksyms_32.c
23283+++ b/arch/x86/kernel/i386_ksyms_32.c
23284@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23285 EXPORT_SYMBOL(cmpxchg8b_emu);
23286 #endif
23287
23288+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23289+
23290 /* Networking helper routines. */
23291 EXPORT_SYMBOL(csum_partial_copy_generic);
23292+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23293+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23294
23295 EXPORT_SYMBOL(__get_user_1);
23296 EXPORT_SYMBOL(__get_user_2);
23297@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23298
23299 EXPORT_SYMBOL(csum_partial);
23300 EXPORT_SYMBOL(empty_zero_page);
23301+
23302+#ifdef CONFIG_PAX_KERNEXEC
23303+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23304+#endif
23305+
23306+#ifdef CONFIG_PAX_PER_CPU_PGD
23307+EXPORT_SYMBOL(cpu_pgd);
23308+#endif
23309diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23310index 5d576ab..1403a03 100644
23311--- a/arch/x86/kernel/i387.c
23312+++ b/arch/x86/kernel/i387.c
23313@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23314 static inline bool interrupted_user_mode(void)
23315 {
23316 struct pt_regs *regs = get_irq_regs();
23317- return regs && user_mode_vm(regs);
23318+ return regs && user_mode(regs);
23319 }
23320
23321 /*
23322diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23323index 9a5c460..84868423 100644
23324--- a/arch/x86/kernel/i8259.c
23325+++ b/arch/x86/kernel/i8259.c
23326@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23327 static void make_8259A_irq(unsigned int irq)
23328 {
23329 disable_irq_nosync(irq);
23330- io_apic_irqs &= ~(1<<irq);
23331+ io_apic_irqs &= ~(1UL<<irq);
23332 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23333 i8259A_chip.name);
23334 enable_irq(irq);
23335@@ -209,7 +209,7 @@ spurious_8259A_irq:
23336 "spurious 8259A interrupt: IRQ%d.\n", irq);
23337 spurious_irq_mask |= irqmask;
23338 }
23339- atomic_inc(&irq_err_count);
23340+ atomic_inc_unchecked(&irq_err_count);
23341 /*
23342 * Theoretically we do not have to handle this IRQ,
23343 * but in Linux this does not cause problems and is
23344@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23345 /* (slave's support for AEOI in flat mode is to be investigated) */
23346 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23347
23348+ pax_open_kernel();
23349 if (auto_eoi)
23350 /*
23351 * In AEOI mode we just have to mask the interrupt
23352 * when acking.
23353 */
23354- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23355+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23356 else
23357- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23358+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23359+ pax_close_kernel();
23360
23361 udelay(100); /* wait for 8259A to initialize */
23362
23363diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23364index a979b5b..1d6db75 100644
23365--- a/arch/x86/kernel/io_delay.c
23366+++ b/arch/x86/kernel/io_delay.c
23367@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23368 * Quirk table for systems that misbehave (lock up, etc.) if port
23369 * 0x80 is used:
23370 */
23371-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23372+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23373 {
23374 .callback = dmi_io_delay_0xed_port,
23375 .ident = "Compaq Presario V6000",
23376diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23377index 4ddaf66..6292f4e 100644
23378--- a/arch/x86/kernel/ioport.c
23379+++ b/arch/x86/kernel/ioport.c
23380@@ -6,6 +6,7 @@
23381 #include <linux/sched.h>
23382 #include <linux/kernel.h>
23383 #include <linux/capability.h>
23384+#include <linux/security.h>
23385 #include <linux/errno.h>
23386 #include <linux/types.h>
23387 #include <linux/ioport.h>
23388@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23389
23390 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23391 return -EINVAL;
23392+#ifdef CONFIG_GRKERNSEC_IO
23393+ if (turn_on && grsec_disable_privio) {
23394+ gr_handle_ioperm();
23395+ return -EPERM;
23396+ }
23397+#endif
23398 if (turn_on && !capable(CAP_SYS_RAWIO))
23399 return -EPERM;
23400
23401@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23402 * because the ->io_bitmap_max value must match the bitmap
23403 * contents:
23404 */
23405- tss = &per_cpu(init_tss, get_cpu());
23406+ tss = init_tss + get_cpu();
23407
23408 if (turn_on)
23409 bitmap_clear(t->io_bitmap_ptr, from, num);
23410@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23411 return -EINVAL;
23412 /* Trying to gain more privileges? */
23413 if (level > old) {
23414+#ifdef CONFIG_GRKERNSEC_IO
23415+ if (grsec_disable_privio) {
23416+ gr_handle_iopl();
23417+ return -EPERM;
23418+ }
23419+#endif
23420 if (!capable(CAP_SYS_RAWIO))
23421 return -EPERM;
23422 }
23423diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23424index 3a8185c..3c042ee 100644
23425--- a/arch/x86/kernel/irq.c
23426+++ b/arch/x86/kernel/irq.c
23427@@ -21,7 +21,7 @@
23428 #define CREATE_TRACE_POINTS
23429 #include <asm/trace/irq_vectors.h>
23430
23431-atomic_t irq_err_count;
23432+atomic_unchecked_t irq_err_count;
23433
23434 /* Function pointer for generic interrupt vector handling */
23435 void (*x86_platform_ipi_callback)(void) = NULL;
23436@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23437 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23438 seq_printf(p, " Machine check polls\n");
23439 #endif
23440- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23441+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23442 #if defined(CONFIG_X86_IO_APIC)
23443- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23444+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23445 #endif
23446 return 0;
23447 }
23448@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23449
23450 u64 arch_irq_stat(void)
23451 {
23452- u64 sum = atomic_read(&irq_err_count);
23453+ u64 sum = atomic_read_unchecked(&irq_err_count);
23454 return sum;
23455 }
23456
23457diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23458index 4186755..784efa0 100644
23459--- a/arch/x86/kernel/irq_32.c
23460+++ b/arch/x86/kernel/irq_32.c
23461@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23462 __asm__ __volatile__("andl %%esp,%0" :
23463 "=r" (sp) : "0" (THREAD_SIZE - 1));
23464
23465- return sp < (sizeof(struct thread_info) + STACK_WARN);
23466+ return sp < STACK_WARN;
23467 }
23468
23469 static void print_stack_overflow(void)
23470@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23471 * per-CPU IRQ handling contexts (thread information and stack)
23472 */
23473 union irq_ctx {
23474- struct thread_info tinfo;
23475- u32 stack[THREAD_SIZE/sizeof(u32)];
23476+ unsigned long previous_esp;
23477+ u32 stack[THREAD_SIZE/sizeof(u32)];
23478 } __attribute__((aligned(THREAD_SIZE)));
23479
23480 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23481@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23482 static inline int
23483 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23484 {
23485- union irq_ctx *curctx, *irqctx;
23486+ union irq_ctx *irqctx;
23487 u32 *isp, arg1, arg2;
23488
23489- curctx = (union irq_ctx *) current_thread_info();
23490 irqctx = __this_cpu_read(hardirq_ctx);
23491
23492 /*
23493@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23494 * handler) we can't do that and just have to keep using the
23495 * current stack (which is the irq stack already after all)
23496 */
23497- if (unlikely(curctx == irqctx))
23498+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23499 return 0;
23500
23501 /* build the stack frame on the IRQ stack */
23502- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23503- irqctx->tinfo.task = curctx->tinfo.task;
23504- irqctx->tinfo.previous_esp = current_stack_pointer;
23505+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23506+ irqctx->previous_esp = current_stack_pointer;
23507
23508- /* Copy the preempt_count so that the [soft]irq checks work. */
23509- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23510+#ifdef CONFIG_PAX_MEMORY_UDEREF
23511+ __set_fs(MAKE_MM_SEG(0));
23512+#endif
23513
23514 if (unlikely(overflow))
23515 call_on_stack(print_stack_overflow, isp);
23516@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23517 : "0" (irq), "1" (desc), "2" (isp),
23518 "D" (desc->handle_irq)
23519 : "memory", "cc", "ecx");
23520+
23521+#ifdef CONFIG_PAX_MEMORY_UDEREF
23522+ __set_fs(current_thread_info()->addr_limit);
23523+#endif
23524+
23525 return 1;
23526 }
23527
23528@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23529 */
23530 void irq_ctx_init(int cpu)
23531 {
23532- union irq_ctx *irqctx;
23533-
23534 if (per_cpu(hardirq_ctx, cpu))
23535 return;
23536
23537- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23538- THREADINFO_GFP,
23539- THREAD_SIZE_ORDER));
23540- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23541- irqctx->tinfo.cpu = cpu;
23542- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23543- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23544+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23545+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23546
23547- per_cpu(hardirq_ctx, cpu) = irqctx;
23548-
23549- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23550- THREADINFO_GFP,
23551- THREAD_SIZE_ORDER));
23552- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23553- irqctx->tinfo.cpu = cpu;
23554- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23555-
23556- per_cpu(softirq_ctx, cpu) = irqctx;
23557+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23558+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23559
23560 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23561 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23562@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23563 asmlinkage void do_softirq(void)
23564 {
23565 unsigned long flags;
23566- struct thread_info *curctx;
23567 union irq_ctx *irqctx;
23568 u32 *isp;
23569
23570@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23571 local_irq_save(flags);
23572
23573 if (local_softirq_pending()) {
23574- curctx = current_thread_info();
23575 irqctx = __this_cpu_read(softirq_ctx);
23576- irqctx->tinfo.task = curctx->task;
23577- irqctx->tinfo.previous_esp = current_stack_pointer;
23578+ irqctx->previous_esp = current_stack_pointer;
23579
23580 /* build the stack frame on the softirq stack */
23581- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23582+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23583+
23584+#ifdef CONFIG_PAX_MEMORY_UDEREF
23585+ __set_fs(MAKE_MM_SEG(0));
23586+#endif
23587
23588 call_on_stack(__do_softirq, isp);
23589+
23590+#ifdef CONFIG_PAX_MEMORY_UDEREF
23591+ __set_fs(current_thread_info()->addr_limit);
23592+#endif
23593+
23594 /*
23595 * Shouldn't happen, we returned above if in_interrupt():
23596 */
23597@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23598 if (unlikely(!desc))
23599 return false;
23600
23601- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23602+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23603 if (unlikely(overflow))
23604 print_stack_overflow();
23605 desc->handle_irq(irq, desc);
23606diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23607index d04d3ec..ea4b374 100644
23608--- a/arch/x86/kernel/irq_64.c
23609+++ b/arch/x86/kernel/irq_64.c
23610@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23611 u64 estack_top, estack_bottom;
23612 u64 curbase = (u64)task_stack_page(current);
23613
23614- if (user_mode_vm(regs))
23615+ if (user_mode(regs))
23616 return;
23617
23618 if (regs->sp >= curbase + sizeof(struct thread_info) +
23619diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23620index dc1404b..bbc43e7 100644
23621--- a/arch/x86/kernel/kdebugfs.c
23622+++ b/arch/x86/kernel/kdebugfs.c
23623@@ -27,7 +27,7 @@ struct setup_data_node {
23624 u32 len;
23625 };
23626
23627-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23628+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23629 size_t count, loff_t *ppos)
23630 {
23631 struct setup_data_node *node = file->private_data;
23632diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23633index 836f832..a8bda67 100644
23634--- a/arch/x86/kernel/kgdb.c
23635+++ b/arch/x86/kernel/kgdb.c
23636@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23637 #ifdef CONFIG_X86_32
23638 switch (regno) {
23639 case GDB_SS:
23640- if (!user_mode_vm(regs))
23641+ if (!user_mode(regs))
23642 *(unsigned long *)mem = __KERNEL_DS;
23643 break;
23644 case GDB_SP:
23645- if (!user_mode_vm(regs))
23646+ if (!user_mode(regs))
23647 *(unsigned long *)mem = kernel_stack_pointer(regs);
23648 break;
23649 case GDB_GS:
23650@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23651 bp->attr.bp_addr = breakinfo[breakno].addr;
23652 bp->attr.bp_len = breakinfo[breakno].len;
23653 bp->attr.bp_type = breakinfo[breakno].type;
23654- info->address = breakinfo[breakno].addr;
23655+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23656+ info->address = ktla_ktva(breakinfo[breakno].addr);
23657+ else
23658+ info->address = breakinfo[breakno].addr;
23659 info->len = breakinfo[breakno].len;
23660 info->type = breakinfo[breakno].type;
23661 val = arch_install_hw_breakpoint(bp);
23662@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23663 case 'k':
23664 /* clear the trace bit */
23665 linux_regs->flags &= ~X86_EFLAGS_TF;
23666- atomic_set(&kgdb_cpu_doing_single_step, -1);
23667+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23668
23669 /* set the trace bit if we're stepping */
23670 if (remcomInBuffer[0] == 's') {
23671 linux_regs->flags |= X86_EFLAGS_TF;
23672- atomic_set(&kgdb_cpu_doing_single_step,
23673+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23674 raw_smp_processor_id());
23675 }
23676
23677@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23678
23679 switch (cmd) {
23680 case DIE_DEBUG:
23681- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23682+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23683 if (user_mode(regs))
23684 return single_step_cont(regs, args);
23685 break;
23686@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23687 #endif /* CONFIG_DEBUG_RODATA */
23688
23689 bpt->type = BP_BREAKPOINT;
23690- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23691+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23692 BREAK_INSTR_SIZE);
23693 if (err)
23694 return err;
23695- err = probe_kernel_write((char *)bpt->bpt_addr,
23696+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23697 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23698 #ifdef CONFIG_DEBUG_RODATA
23699 if (!err)
23700@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23701 return -EBUSY;
23702 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23703 BREAK_INSTR_SIZE);
23704- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23705+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23706 if (err)
23707 return err;
23708 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23709@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23710 if (mutex_is_locked(&text_mutex))
23711 goto knl_write;
23712 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, 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 || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23716 goto knl_write;
23717 return err;
23718 knl_write:
23719 #endif /* CONFIG_DEBUG_RODATA */
23720- return probe_kernel_write((char *)bpt->bpt_addr,
23721+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23722 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23723 }
23724
23725diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23726index 211bce4..6e2580a 100644
23727--- a/arch/x86/kernel/kprobes/core.c
23728+++ b/arch/x86/kernel/kprobes/core.c
23729@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23730 s32 raddr;
23731 } __packed *insn;
23732
23733- insn = (struct __arch_relative_insn *)from;
23734+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23735+
23736+ pax_open_kernel();
23737 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23738 insn->op = op;
23739+ pax_close_kernel();
23740 }
23741
23742 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23743@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23744 kprobe_opcode_t opcode;
23745 kprobe_opcode_t *orig_opcodes = opcodes;
23746
23747- if (search_exception_tables((unsigned long)opcodes))
23748+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23749 return 0; /* Page fault may occur on this address. */
23750
23751 retry:
23752@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23753 * for the first byte, we can recover the original instruction
23754 * from it and kp->opcode.
23755 */
23756- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23757+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23758 buf[0] = kp->opcode;
23759- return (unsigned long)buf;
23760+ return ktva_ktla((unsigned long)buf);
23761 }
23762
23763 /*
23764@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23765 /* Another subsystem puts a breakpoint, failed to recover */
23766 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23767 return 0;
23768+ pax_open_kernel();
23769 memcpy(dest, insn.kaddr, insn.length);
23770+ pax_close_kernel();
23771
23772 #ifdef CONFIG_X86_64
23773 if (insn_rip_relative(&insn)) {
23774@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23775 return 0;
23776 }
23777 disp = (u8 *) dest + insn_offset_displacement(&insn);
23778+ pax_open_kernel();
23779 *(s32 *) disp = (s32) newdisp;
23780+ pax_close_kernel();
23781 }
23782 #endif
23783 return insn.length;
23784@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23785 * nor set current_kprobe, because it doesn't use single
23786 * stepping.
23787 */
23788- regs->ip = (unsigned long)p->ainsn.insn;
23789+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23790 preempt_enable_no_resched();
23791 return;
23792 }
23793@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23794 regs->flags &= ~X86_EFLAGS_IF;
23795 /* single step inline if the instruction is an int3 */
23796 if (p->opcode == BREAKPOINT_INSTRUCTION)
23797- regs->ip = (unsigned long)p->addr;
23798+ regs->ip = ktla_ktva((unsigned long)p->addr);
23799 else
23800- regs->ip = (unsigned long)p->ainsn.insn;
23801+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23802 }
23803
23804 /*
23805@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23806 setup_singlestep(p, regs, kcb, 0);
23807 return 1;
23808 }
23809- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23810+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23811 /*
23812 * The breakpoint instruction was removed right
23813 * after we hit it. Another cpu has removed
23814@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23815 " movq %rax, 152(%rsp)\n"
23816 RESTORE_REGS_STRING
23817 " popfq\n"
23818+#ifdef KERNEXEC_PLUGIN
23819+ " btsq $63,(%rsp)\n"
23820+#endif
23821 #else
23822 " pushf\n"
23823 SAVE_REGS_STRING
23824@@ -779,7 +789,7 @@ static void __kprobes
23825 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23826 {
23827 unsigned long *tos = stack_addr(regs);
23828- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23829+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23830 unsigned long orig_ip = (unsigned long)p->addr;
23831 kprobe_opcode_t *insn = p->ainsn.insn;
23832
23833@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23834 struct die_args *args = data;
23835 int ret = NOTIFY_DONE;
23836
23837- if (args->regs && user_mode_vm(args->regs))
23838+ if (args->regs && user_mode(args->regs))
23839 return ret;
23840
23841 switch (val) {
23842diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23843index 76dc6f0..66bdfc3 100644
23844--- a/arch/x86/kernel/kprobes/opt.c
23845+++ b/arch/x86/kernel/kprobes/opt.c
23846@@ -79,6 +79,7 @@ found:
23847 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23848 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23849 {
23850+ pax_open_kernel();
23851 #ifdef CONFIG_X86_64
23852 *addr++ = 0x48;
23853 *addr++ = 0xbf;
23854@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23855 *addr++ = 0xb8;
23856 #endif
23857 *(unsigned long *)addr = val;
23858+ pax_close_kernel();
23859 }
23860
23861 static void __used __kprobes kprobes_optinsn_template_holder(void)
23862@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23863 * Verify if the address gap is in 2GB range, because this uses
23864 * a relative jump.
23865 */
23866- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23867+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23868 if (abs(rel) > 0x7fffffff)
23869 return -ERANGE;
23870
23871@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23872 op->optinsn.size = ret;
23873
23874 /* Copy arch-dep-instance from template */
23875- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23876+ pax_open_kernel();
23877+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23878+ pax_close_kernel();
23879
23880 /* Set probe information */
23881 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23882
23883 /* Set probe function call */
23884- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23885+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23886
23887 /* Set returning jmp instruction at the tail of out-of-line buffer */
23888- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23889+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23890 (u8 *)op->kp.addr + op->optinsn.size);
23891
23892 flush_icache_range((unsigned long) buf,
23893@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23894 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23895
23896 /* Backup instructions which will be replaced by jump address */
23897- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23898+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23899 RELATIVE_ADDR_SIZE);
23900
23901 insn_buf[0] = RELATIVEJUMP_OPCODE;
23902@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23903 /* This kprobe is really able to run optimized path. */
23904 op = container_of(p, struct optimized_kprobe, kp);
23905 /* Detour through copied instructions */
23906- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23907+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23908 if (!reenter)
23909 reset_current_kprobe();
23910 preempt_enable_no_resched();
23911diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23912index ebc9873..1b9724b 100644
23913--- a/arch/x86/kernel/ldt.c
23914+++ b/arch/x86/kernel/ldt.c
23915@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23916 if (reload) {
23917 #ifdef CONFIG_SMP
23918 preempt_disable();
23919- load_LDT(pc);
23920+ load_LDT_nolock(pc);
23921 if (!cpumask_equal(mm_cpumask(current->mm),
23922 cpumask_of(smp_processor_id())))
23923 smp_call_function(flush_ldt, current->mm, 1);
23924 preempt_enable();
23925 #else
23926- load_LDT(pc);
23927+ load_LDT_nolock(pc);
23928 #endif
23929 }
23930 if (oldsize) {
23931@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23932 return err;
23933
23934 for (i = 0; i < old->size; i++)
23935- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23936+ write_ldt_entry(new->ldt, i, old->ldt + i);
23937 return 0;
23938 }
23939
23940@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23941 retval = copy_ldt(&mm->context, &old_mm->context);
23942 mutex_unlock(&old_mm->context.lock);
23943 }
23944+
23945+ if (tsk == current) {
23946+ mm->context.vdso = 0;
23947+
23948+#ifdef CONFIG_X86_32
23949+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23950+ mm->context.user_cs_base = 0UL;
23951+ mm->context.user_cs_limit = ~0UL;
23952+
23953+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23954+ cpus_clear(mm->context.cpu_user_cs_mask);
23955+#endif
23956+
23957+#endif
23958+#endif
23959+
23960+ }
23961+
23962 return retval;
23963 }
23964
23965@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23966 }
23967 }
23968
23969+#ifdef CONFIG_PAX_SEGMEXEC
23970+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23971+ error = -EINVAL;
23972+ goto out_unlock;
23973+ }
23974+#endif
23975+
23976 fill_ldt(&ldt, &ldt_info);
23977 if (oldmode)
23978 ldt.avl = 0;
23979diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23980index 5b19e4d..6476a76 100644
23981--- a/arch/x86/kernel/machine_kexec_32.c
23982+++ b/arch/x86/kernel/machine_kexec_32.c
23983@@ -26,7 +26,7 @@
23984 #include <asm/cacheflush.h>
23985 #include <asm/debugreg.h>
23986
23987-static void set_idt(void *newidt, __u16 limit)
23988+static void set_idt(struct desc_struct *newidt, __u16 limit)
23989 {
23990 struct desc_ptr curidt;
23991
23992@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23993 }
23994
23995
23996-static void set_gdt(void *newgdt, __u16 limit)
23997+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23998 {
23999 struct desc_ptr curgdt;
24000
24001@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24002 }
24003
24004 control_page = page_address(image->control_code_page);
24005- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24006+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24007
24008 relocate_kernel_ptr = control_page;
24009 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24010diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24011index 15c9876..0a43909 100644
24012--- a/arch/x86/kernel/microcode_core.c
24013+++ b/arch/x86/kernel/microcode_core.c
24014@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24015 return NOTIFY_OK;
24016 }
24017
24018-static struct notifier_block __refdata mc_cpu_notifier = {
24019+static struct notifier_block mc_cpu_notifier = {
24020 .notifier_call = mc_cpu_callback,
24021 };
24022
24023diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24024index 5fb2ceb..3ae90bb 100644
24025--- a/arch/x86/kernel/microcode_intel.c
24026+++ b/arch/x86/kernel/microcode_intel.c
24027@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24028
24029 static int get_ucode_user(void *to, const void *from, size_t n)
24030 {
24031- return copy_from_user(to, from, n);
24032+ return copy_from_user(to, (const void __force_user *)from, n);
24033 }
24034
24035 static enum ucode_state
24036 request_microcode_user(int cpu, const void __user *buf, size_t size)
24037 {
24038- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24039+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24040 }
24041
24042 static void microcode_fini_cpu(int cpu)
24043diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24044index 216a4d7..228255a 100644
24045--- a/arch/x86/kernel/module.c
24046+++ b/arch/x86/kernel/module.c
24047@@ -43,15 +43,60 @@ do { \
24048 } while (0)
24049 #endif
24050
24051-void *module_alloc(unsigned long size)
24052+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24053 {
24054- if (PAGE_ALIGN(size) > MODULES_LEN)
24055+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24056 return NULL;
24057 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24058- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24059+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24060 -1, __builtin_return_address(0));
24061 }
24062
24063+void *module_alloc(unsigned long size)
24064+{
24065+
24066+#ifdef CONFIG_PAX_KERNEXEC
24067+ return __module_alloc(size, PAGE_KERNEL);
24068+#else
24069+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24070+#endif
24071+
24072+}
24073+
24074+#ifdef CONFIG_PAX_KERNEXEC
24075+#ifdef CONFIG_X86_32
24076+void *module_alloc_exec(unsigned long size)
24077+{
24078+ struct vm_struct *area;
24079+
24080+ if (size == 0)
24081+ return NULL;
24082+
24083+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24084+ return area ? area->addr : NULL;
24085+}
24086+EXPORT_SYMBOL(module_alloc_exec);
24087+
24088+void module_free_exec(struct module *mod, void *module_region)
24089+{
24090+ vunmap(module_region);
24091+}
24092+EXPORT_SYMBOL(module_free_exec);
24093+#else
24094+void module_free_exec(struct module *mod, void *module_region)
24095+{
24096+ module_free(mod, module_region);
24097+}
24098+EXPORT_SYMBOL(module_free_exec);
24099+
24100+void *module_alloc_exec(unsigned long size)
24101+{
24102+ return __module_alloc(size, PAGE_KERNEL_RX);
24103+}
24104+EXPORT_SYMBOL(module_alloc_exec);
24105+#endif
24106+#endif
24107+
24108 #ifdef CONFIG_X86_32
24109 int apply_relocate(Elf32_Shdr *sechdrs,
24110 const char *strtab,
24111@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24112 unsigned int i;
24113 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24114 Elf32_Sym *sym;
24115- uint32_t *location;
24116+ uint32_t *plocation, location;
24117
24118 DEBUGP("Applying relocate section %u to %u\n",
24119 relsec, sechdrs[relsec].sh_info);
24120 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24121 /* This is where to make the change */
24122- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24123- + rel[i].r_offset;
24124+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24125+ location = (uint32_t)plocation;
24126+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24127+ plocation = ktla_ktva((void *)plocation);
24128 /* This is the symbol it is referring to. Note that all
24129 undefined symbols have been resolved. */
24130 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24131@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24132 switch (ELF32_R_TYPE(rel[i].r_info)) {
24133 case R_386_32:
24134 /* We add the value into the location given */
24135- *location += sym->st_value;
24136+ pax_open_kernel();
24137+ *plocation += sym->st_value;
24138+ pax_close_kernel();
24139 break;
24140 case R_386_PC32:
24141 /* Add the value, subtract its position */
24142- *location += sym->st_value - (uint32_t)location;
24143+ pax_open_kernel();
24144+ *plocation += sym->st_value - location;
24145+ pax_close_kernel();
24146 break;
24147 default:
24148 pr_err("%s: Unknown relocation: %u\n",
24149@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24150 case R_X86_64_NONE:
24151 break;
24152 case R_X86_64_64:
24153+ pax_open_kernel();
24154 *(u64 *)loc = val;
24155+ pax_close_kernel();
24156 break;
24157 case R_X86_64_32:
24158+ pax_open_kernel();
24159 *(u32 *)loc = val;
24160+ pax_close_kernel();
24161 if (val != *(u32 *)loc)
24162 goto overflow;
24163 break;
24164 case R_X86_64_32S:
24165+ pax_open_kernel();
24166 *(s32 *)loc = val;
24167+ pax_close_kernel();
24168 if ((s64)val != *(s32 *)loc)
24169 goto overflow;
24170 break;
24171 case R_X86_64_PC32:
24172 val -= (u64)loc;
24173+ pax_open_kernel();
24174 *(u32 *)loc = val;
24175+ pax_close_kernel();
24176+
24177 #if 0
24178 if ((s64)val != *(s32 *)loc)
24179 goto overflow;
24180diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24181index 88458fa..349f7a4 100644
24182--- a/arch/x86/kernel/msr.c
24183+++ b/arch/x86/kernel/msr.c
24184@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24185 return notifier_from_errno(err);
24186 }
24187
24188-static struct notifier_block __refdata msr_class_cpu_notifier = {
24189+static struct notifier_block msr_class_cpu_notifier = {
24190 .notifier_call = msr_class_cpu_callback,
24191 };
24192
24193diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24194index ba77ebc..65da999 100644
24195--- a/arch/x86/kernel/nmi.c
24196+++ b/arch/x86/kernel/nmi.c
24197@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24198 return handled;
24199 }
24200
24201-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24202+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24203 {
24204 struct nmi_desc *desc = nmi_to_desc(type);
24205 unsigned long flags;
24206@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24207 * event confuses some handlers (kdump uses this flag)
24208 */
24209 if (action->flags & NMI_FLAG_FIRST)
24210- list_add_rcu(&action->list, &desc->head);
24211+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24212 else
24213- list_add_tail_rcu(&action->list, &desc->head);
24214+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24215
24216 spin_unlock_irqrestore(&desc->lock, flags);
24217 return 0;
24218@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24219 if (!strcmp(n->name, name)) {
24220 WARN(in_nmi(),
24221 "Trying to free NMI (%s) from NMI context!\n", n->name);
24222- list_del_rcu(&n->list);
24223+ pax_list_del_rcu((struct list_head *)&n->list);
24224 break;
24225 }
24226 }
24227@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24228 dotraplinkage notrace __kprobes void
24229 do_nmi(struct pt_regs *regs, long error_code)
24230 {
24231+
24232+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24233+ if (!user_mode(regs)) {
24234+ unsigned long cs = regs->cs & 0xFFFF;
24235+ unsigned long ip = ktva_ktla(regs->ip);
24236+
24237+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24238+ regs->ip = ip;
24239+ }
24240+#endif
24241+
24242 nmi_nesting_preprocess(regs);
24243
24244 nmi_enter();
24245diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24246index 6d9582e..f746287 100644
24247--- a/arch/x86/kernel/nmi_selftest.c
24248+++ b/arch/x86/kernel/nmi_selftest.c
24249@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24250 {
24251 /* trap all the unknown NMIs we may generate */
24252 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24253- __initdata);
24254+ __initconst);
24255 }
24256
24257 static void __init cleanup_nmi_testsuite(void)
24258@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24259 unsigned long timeout;
24260
24261 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24262- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24263+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24264 nmi_fail = FAILURE;
24265 return;
24266 }
24267diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24268index 676b8c7..870ba04 100644
24269--- a/arch/x86/kernel/paravirt-spinlocks.c
24270+++ b/arch/x86/kernel/paravirt-spinlocks.c
24271@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24272 arch_spin_lock(lock);
24273 }
24274
24275-struct pv_lock_ops pv_lock_ops = {
24276+struct pv_lock_ops pv_lock_ops __read_only = {
24277 #ifdef CONFIG_SMP
24278 .spin_is_locked = __ticket_spin_is_locked,
24279 .spin_is_contended = __ticket_spin_is_contended,
24280diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24281index cd6de64..27c6af0 100644
24282--- a/arch/x86/kernel/paravirt.c
24283+++ b/arch/x86/kernel/paravirt.c
24284@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24285 {
24286 return x;
24287 }
24288+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24289+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24290+#endif
24291
24292 void __init default_banner(void)
24293 {
24294@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24295 if (opfunc == NULL)
24296 /* If there's no function, patch it with a ud2a (BUG) */
24297 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24298- else if (opfunc == _paravirt_nop)
24299+ else if (opfunc == (void *)_paravirt_nop)
24300 /* If the operation is a nop, then nop the callsite */
24301 ret = paravirt_patch_nop();
24302
24303 /* identity functions just return their single argument */
24304- else if (opfunc == _paravirt_ident_32)
24305+ else if (opfunc == (void *)_paravirt_ident_32)
24306 ret = paravirt_patch_ident_32(insnbuf, len);
24307- else if (opfunc == _paravirt_ident_64)
24308+ else if (opfunc == (void *)_paravirt_ident_64)
24309 ret = paravirt_patch_ident_64(insnbuf, len);
24310+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24311+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24312+ ret = paravirt_patch_ident_64(insnbuf, len);
24313+#endif
24314
24315 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24316 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24317@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24318 if (insn_len > len || start == NULL)
24319 insn_len = len;
24320 else
24321- memcpy(insnbuf, start, insn_len);
24322+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24323
24324 return insn_len;
24325 }
24326@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24327 return this_cpu_read(paravirt_lazy_mode);
24328 }
24329
24330-struct pv_info pv_info = {
24331+struct pv_info pv_info __read_only = {
24332 .name = "bare hardware",
24333 .paravirt_enabled = 0,
24334 .kernel_rpl = 0,
24335@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24336 #endif
24337 };
24338
24339-struct pv_init_ops pv_init_ops = {
24340+struct pv_init_ops pv_init_ops __read_only = {
24341 .patch = native_patch,
24342 };
24343
24344-struct pv_time_ops pv_time_ops = {
24345+struct pv_time_ops pv_time_ops __read_only = {
24346 .sched_clock = native_sched_clock,
24347 .steal_clock = native_steal_clock,
24348 };
24349
24350-struct pv_irq_ops pv_irq_ops = {
24351+struct pv_irq_ops pv_irq_ops __read_only = {
24352 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24353 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24354 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24355@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24356 #endif
24357 };
24358
24359-struct pv_cpu_ops pv_cpu_ops = {
24360+struct pv_cpu_ops pv_cpu_ops __read_only = {
24361 .cpuid = native_cpuid,
24362 .get_debugreg = native_get_debugreg,
24363 .set_debugreg = native_set_debugreg,
24364@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24365 .end_context_switch = paravirt_nop,
24366 };
24367
24368-struct pv_apic_ops pv_apic_ops = {
24369+struct pv_apic_ops pv_apic_ops __read_only= {
24370 #ifdef CONFIG_X86_LOCAL_APIC
24371 .startup_ipi_hook = paravirt_nop,
24372 #endif
24373 };
24374
24375-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24376+#ifdef CONFIG_X86_32
24377+#ifdef CONFIG_X86_PAE
24378+/* 64-bit pagetable entries */
24379+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24380+#else
24381 /* 32-bit pagetable entries */
24382 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24383+#endif
24384 #else
24385 /* 64-bit pagetable entries */
24386 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24387 #endif
24388
24389-struct pv_mmu_ops pv_mmu_ops = {
24390+struct pv_mmu_ops pv_mmu_ops __read_only = {
24391
24392 .read_cr2 = native_read_cr2,
24393 .write_cr2 = native_write_cr2,
24394@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24395 .make_pud = PTE_IDENT,
24396
24397 .set_pgd = native_set_pgd,
24398+ .set_pgd_batched = native_set_pgd_batched,
24399 #endif
24400 #endif /* PAGETABLE_LEVELS >= 3 */
24401
24402@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24403 },
24404
24405 .set_fixmap = native_set_fixmap,
24406+
24407+#ifdef CONFIG_PAX_KERNEXEC
24408+ .pax_open_kernel = native_pax_open_kernel,
24409+ .pax_close_kernel = native_pax_close_kernel,
24410+#endif
24411+
24412 };
24413
24414 EXPORT_SYMBOL_GPL(pv_time_ops);
24415diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24416index 299d493..2ccb0ee 100644
24417--- a/arch/x86/kernel/pci-calgary_64.c
24418+++ b/arch/x86/kernel/pci-calgary_64.c
24419@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24420 tce_space = be64_to_cpu(readq(target));
24421 tce_space = tce_space & TAR_SW_BITS;
24422
24423- tce_space = tce_space & (~specified_table_size);
24424+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24425 info->tce_space = (u64 *)__va(tce_space);
24426 }
24427 }
24428diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24429index 35ccf75..7a15747 100644
24430--- a/arch/x86/kernel/pci-iommu_table.c
24431+++ b/arch/x86/kernel/pci-iommu_table.c
24432@@ -2,7 +2,7 @@
24433 #include <asm/iommu_table.h>
24434 #include <linux/string.h>
24435 #include <linux/kallsyms.h>
24436-
24437+#include <linux/sched.h>
24438
24439 #define DEBUG 1
24440
24441diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24442index 6c483ba..d10ce2f 100644
24443--- a/arch/x86/kernel/pci-swiotlb.c
24444+++ b/arch/x86/kernel/pci-swiotlb.c
24445@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24446 void *vaddr, dma_addr_t dma_addr,
24447 struct dma_attrs *attrs)
24448 {
24449- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24450+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24451 }
24452
24453 static struct dma_map_ops swiotlb_dma_ops = {
24454diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24455index 83369e5..52b93f0 100644
24456--- a/arch/x86/kernel/process.c
24457+++ b/arch/x86/kernel/process.c
24458@@ -36,7 +36,8 @@
24459 * section. Since TSS's are completely CPU-local, we want them
24460 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24461 */
24462-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24463+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24464+EXPORT_SYMBOL(init_tss);
24465
24466 #ifdef CONFIG_X86_64
24467 static DEFINE_PER_CPU(unsigned char, is_idle);
24468@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24469 task_xstate_cachep =
24470 kmem_cache_create("task_xstate", xstate_size,
24471 __alignof__(union thread_xstate),
24472- SLAB_PANIC | SLAB_NOTRACK, NULL);
24473+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24474 }
24475
24476 /*
24477@@ -105,7 +106,7 @@ void exit_thread(void)
24478 unsigned long *bp = t->io_bitmap_ptr;
24479
24480 if (bp) {
24481- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24482+ struct tss_struct *tss = init_tss + get_cpu();
24483
24484 t->io_bitmap_ptr = NULL;
24485 clear_thread_flag(TIF_IO_BITMAP);
24486@@ -125,6 +126,9 @@ void flush_thread(void)
24487 {
24488 struct task_struct *tsk = current;
24489
24490+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24491+ loadsegment(gs, 0);
24492+#endif
24493 flush_ptrace_hw_breakpoint(tsk);
24494 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24495 drop_init_fpu(tsk);
24496@@ -271,7 +275,7 @@ static void __exit_idle(void)
24497 void exit_idle(void)
24498 {
24499 /* idle loop has pid 0 */
24500- if (current->pid)
24501+ if (task_pid_nr(current))
24502 return;
24503 __exit_idle();
24504 }
24505@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24506 return ret;
24507 }
24508 #endif
24509-void stop_this_cpu(void *dummy)
24510+__noreturn void stop_this_cpu(void *dummy)
24511 {
24512 local_irq_disable();
24513 /*
24514@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24515 }
24516 early_param("idle", idle_setup);
24517
24518-unsigned long arch_align_stack(unsigned long sp)
24519+#ifdef CONFIG_PAX_RANDKSTACK
24520+void pax_randomize_kstack(struct pt_regs *regs)
24521 {
24522- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24523- sp -= get_random_int() % 8192;
24524- return sp & ~0xf;
24525-}
24526+ struct thread_struct *thread = &current->thread;
24527+ unsigned long time;
24528
24529-unsigned long arch_randomize_brk(struct mm_struct *mm)
24530-{
24531- unsigned long range_end = mm->brk + 0x02000000;
24532- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24533-}
24534+ if (!randomize_va_space)
24535+ return;
24536+
24537+ if (v8086_mode(regs))
24538+ return;
24539
24540+ rdtscl(time);
24541+
24542+ /* P4 seems to return a 0 LSB, ignore it */
24543+#ifdef CONFIG_MPENTIUM4
24544+ time &= 0x3EUL;
24545+ time <<= 2;
24546+#elif defined(CONFIG_X86_64)
24547+ time &= 0xFUL;
24548+ time <<= 4;
24549+#else
24550+ time &= 0x1FUL;
24551+ time <<= 3;
24552+#endif
24553+
24554+ thread->sp0 ^= time;
24555+ load_sp0(init_tss + smp_processor_id(), thread);
24556+
24557+#ifdef CONFIG_X86_64
24558+ this_cpu_write(kernel_stack, thread->sp0);
24559+#endif
24560+}
24561+#endif
24562diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24563index f8adefc..4bce3d6 100644
24564--- a/arch/x86/kernel/process_32.c
24565+++ b/arch/x86/kernel/process_32.c
24566@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24567 unsigned long thread_saved_pc(struct task_struct *tsk)
24568 {
24569 return ((unsigned long *)tsk->thread.sp)[3];
24570+//XXX return tsk->thread.eip;
24571 }
24572
24573 void __show_regs(struct pt_regs *regs, int all)
24574@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24575 unsigned long sp;
24576 unsigned short ss, gs;
24577
24578- if (user_mode_vm(regs)) {
24579+ if (user_mode(regs)) {
24580 sp = regs->sp;
24581 ss = regs->ss & 0xffff;
24582- gs = get_user_gs(regs);
24583 } else {
24584 sp = kernel_stack_pointer(regs);
24585 savesegment(ss, ss);
24586- savesegment(gs, gs);
24587 }
24588+ gs = get_user_gs(regs);
24589
24590 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24591 (u16)regs->cs, regs->ip, regs->flags,
24592- smp_processor_id());
24593+ raw_smp_processor_id());
24594 print_symbol("EIP is at %s\n", regs->ip);
24595
24596 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24597@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24598 int copy_thread(unsigned long clone_flags, unsigned long sp,
24599 unsigned long arg, struct task_struct *p)
24600 {
24601- struct pt_regs *childregs = task_pt_regs(p);
24602+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24603 struct task_struct *tsk;
24604 int err;
24605
24606 p->thread.sp = (unsigned long) childregs;
24607 p->thread.sp0 = (unsigned long) (childregs+1);
24608+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24609
24610 if (unlikely(p->flags & PF_KTHREAD)) {
24611 /* kernel thread */
24612 memset(childregs, 0, sizeof(struct pt_regs));
24613 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24614- task_user_gs(p) = __KERNEL_STACK_CANARY;
24615- childregs->ds = __USER_DS;
24616- childregs->es = __USER_DS;
24617+ savesegment(gs, childregs->gs);
24618+ childregs->ds = __KERNEL_DS;
24619+ childregs->es = __KERNEL_DS;
24620 childregs->fs = __KERNEL_PERCPU;
24621 childregs->bx = sp; /* function */
24622 childregs->bp = arg;
24623@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24624 struct thread_struct *prev = &prev_p->thread,
24625 *next = &next_p->thread;
24626 int cpu = smp_processor_id();
24627- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24628+ struct tss_struct *tss = init_tss + cpu;
24629 fpu_switch_t fpu;
24630
24631 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24632@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24633 */
24634 lazy_save_gs(prev->gs);
24635
24636+#ifdef CONFIG_PAX_MEMORY_UDEREF
24637+ __set_fs(task_thread_info(next_p)->addr_limit);
24638+#endif
24639+
24640 /*
24641 * Load the per-thread Thread-Local Storage descriptor.
24642 */
24643@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24644 */
24645 arch_end_context_switch(next_p);
24646
24647+ this_cpu_write(current_task, next_p);
24648+ this_cpu_write(current_tinfo, &next_p->tinfo);
24649+
24650 /*
24651 * Restore %gs if needed (which is common)
24652 */
24653@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24654
24655 switch_fpu_finish(next_p, fpu);
24656
24657- this_cpu_write(current_task, next_p);
24658-
24659 return prev_p;
24660 }
24661
24662@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24663 } while (count++ < 16);
24664 return 0;
24665 }
24666-
24667diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24668index 05646ba..0c2906d 100644
24669--- a/arch/x86/kernel/process_64.c
24670+++ b/arch/x86/kernel/process_64.c
24671@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24672 struct pt_regs *childregs;
24673 struct task_struct *me = current;
24674
24675- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24676+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24677 childregs = task_pt_regs(p);
24678 p->thread.sp = (unsigned long) childregs;
24679 p->thread.usersp = me->thread.usersp;
24680+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24681 set_tsk_thread_flag(p, TIF_FORK);
24682 p->fpu_counter = 0;
24683 p->thread.io_bitmap_ptr = NULL;
24684@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24685 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24686 savesegment(es, p->thread.es);
24687 savesegment(ds, p->thread.ds);
24688+ savesegment(ss, p->thread.ss);
24689+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24690 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24691
24692 if (unlikely(p->flags & PF_KTHREAD)) {
24693@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24694 struct thread_struct *prev = &prev_p->thread;
24695 struct thread_struct *next = &next_p->thread;
24696 int cpu = smp_processor_id();
24697- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24698+ struct tss_struct *tss = init_tss + cpu;
24699 unsigned fsindex, gsindex;
24700 fpu_switch_t fpu;
24701
24702@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24703 if (unlikely(next->ds | prev->ds))
24704 loadsegment(ds, next->ds);
24705
24706+ savesegment(ss, prev->ss);
24707+ if (unlikely(next->ss != prev->ss))
24708+ loadsegment(ss, next->ss);
24709
24710 /* We must save %fs and %gs before load_TLS() because
24711 * %fs and %gs may be cleared by load_TLS().
24712@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24713 prev->usersp = this_cpu_read(old_rsp);
24714 this_cpu_write(old_rsp, next->usersp);
24715 this_cpu_write(current_task, next_p);
24716+ this_cpu_write(current_tinfo, &next_p->tinfo);
24717
24718- this_cpu_write(kernel_stack,
24719- (unsigned long)task_stack_page(next_p) +
24720- THREAD_SIZE - KERNEL_STACK_OFFSET);
24721+ this_cpu_write(kernel_stack, next->sp0);
24722
24723 /*
24724 * Now maybe reload the debug registers and handle I/O bitmaps
24725@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24726 if (!p || p == current || p->state == TASK_RUNNING)
24727 return 0;
24728 stack = (unsigned long)task_stack_page(p);
24729- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24730+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24731 return 0;
24732 fp = *(u64 *)(p->thread.sp);
24733 do {
24734- if (fp < (unsigned long)stack ||
24735- fp >= (unsigned long)stack+THREAD_SIZE)
24736+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24737 return 0;
24738 ip = *(u64 *)(fp+8);
24739 if (!in_sched_functions(ip))
24740diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24741index 7461f50..1334029 100644
24742--- a/arch/x86/kernel/ptrace.c
24743+++ b/arch/x86/kernel/ptrace.c
24744@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24745 {
24746 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24747 unsigned long sp = (unsigned long)&regs->sp;
24748- struct thread_info *tinfo;
24749
24750- if (context == (sp & ~(THREAD_SIZE - 1)))
24751+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24752 return sp;
24753
24754- tinfo = (struct thread_info *)context;
24755- if (tinfo->previous_esp)
24756- return tinfo->previous_esp;
24757+ sp = *(unsigned long *)context;
24758+ if (sp)
24759+ return sp;
24760
24761 return (unsigned long)regs;
24762 }
24763@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24764 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24765 {
24766 int i;
24767- int dr7 = 0;
24768+ unsigned long dr7 = 0;
24769 struct arch_hw_breakpoint *info;
24770
24771 for (i = 0; i < HBP_NUM; i++) {
24772@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24773 unsigned long addr, unsigned long data)
24774 {
24775 int ret;
24776- unsigned long __user *datap = (unsigned long __user *)data;
24777+ unsigned long __user *datap = (__force unsigned long __user *)data;
24778
24779 switch (request) {
24780 /* read the word at location addr in the USER area. */
24781@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24782 if ((int) addr < 0)
24783 return -EIO;
24784 ret = do_get_thread_area(child, addr,
24785- (struct user_desc __user *)data);
24786+ (__force struct user_desc __user *) data);
24787 break;
24788
24789 case PTRACE_SET_THREAD_AREA:
24790 if ((int) addr < 0)
24791 return -EIO;
24792 ret = do_set_thread_area(child, addr,
24793- (struct user_desc __user *)data, 0);
24794+ (__force struct user_desc __user *) data, 0);
24795 break;
24796 #endif
24797
24798@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24799
24800 #ifdef CONFIG_X86_64
24801
24802-static struct user_regset x86_64_regsets[] __read_mostly = {
24803+static user_regset_no_const x86_64_regsets[] __read_only = {
24804 [REGSET_GENERAL] = {
24805 .core_note_type = NT_PRSTATUS,
24806 .n = sizeof(struct user_regs_struct) / sizeof(long),
24807@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24808 #endif /* CONFIG_X86_64 */
24809
24810 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24811-static struct user_regset x86_32_regsets[] __read_mostly = {
24812+static user_regset_no_const x86_32_regsets[] __read_only = {
24813 [REGSET_GENERAL] = {
24814 .core_note_type = NT_PRSTATUS,
24815 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24816@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24817 */
24818 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24819
24820-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24821+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24822 {
24823 #ifdef CONFIG_X86_64
24824 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24825@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24826 memset(info, 0, sizeof(*info));
24827 info->si_signo = SIGTRAP;
24828 info->si_code = si_code;
24829- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24830+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24831 }
24832
24833 void user_single_step_siginfo(struct task_struct *tsk,
24834@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24835 # define IS_IA32 0
24836 #endif
24837
24838+#ifdef CONFIG_GRKERNSEC_SETXID
24839+extern void gr_delayed_cred_worker(void);
24840+#endif
24841+
24842 /*
24843 * We must return the syscall number to actually look up in the table.
24844 * This can be -1L to skip running any syscall at all.
24845@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24846
24847 user_exit();
24848
24849+#ifdef CONFIG_GRKERNSEC_SETXID
24850+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24851+ gr_delayed_cred_worker();
24852+#endif
24853+
24854 /*
24855 * If we stepped into a sysenter/syscall insn, it trapped in
24856 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24857@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24858 */
24859 user_exit();
24860
24861+#ifdef CONFIG_GRKERNSEC_SETXID
24862+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24863+ gr_delayed_cred_worker();
24864+#endif
24865+
24866 audit_syscall_exit(regs);
24867
24868 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24869diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24870index 2cb9470..ff1fd80 100644
24871--- a/arch/x86/kernel/pvclock.c
24872+++ b/arch/x86/kernel/pvclock.c
24873@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24874 return pv_tsc_khz;
24875 }
24876
24877-static atomic64_t last_value = ATOMIC64_INIT(0);
24878+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24879
24880 void pvclock_resume(void)
24881 {
24882- atomic64_set(&last_value, 0);
24883+ atomic64_set_unchecked(&last_value, 0);
24884 }
24885
24886 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24887@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24888 * updating at the same time, and one of them could be slightly behind,
24889 * making the assumption that last_value always go forward fail to hold.
24890 */
24891- last = atomic64_read(&last_value);
24892+ last = atomic64_read_unchecked(&last_value);
24893 do {
24894 if (ret < last)
24895 return last;
24896- last = atomic64_cmpxchg(&last_value, last, ret);
24897+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24898 } while (unlikely(last != ret));
24899
24900 return ret;
24901diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24902index 563ed91..b9c3313 100644
24903--- a/arch/x86/kernel/reboot.c
24904+++ b/arch/x86/kernel/reboot.c
24905@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24906
24907 void __noreturn machine_real_restart(unsigned int type)
24908 {
24909+
24910+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24911+ struct desc_struct *gdt;
24912+#endif
24913+
24914 local_irq_disable();
24915
24916 /*
24917@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24918
24919 /* Jump to the identity-mapped low memory code */
24920 #ifdef CONFIG_X86_32
24921- asm volatile("jmpl *%0" : :
24922+
24923+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24924+ gdt = get_cpu_gdt_table(smp_processor_id());
24925+ pax_open_kernel();
24926+#ifdef CONFIG_PAX_MEMORY_UDEREF
24927+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24928+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24929+ loadsegment(ds, __KERNEL_DS);
24930+ loadsegment(es, __KERNEL_DS);
24931+ loadsegment(ss, __KERNEL_DS);
24932+#endif
24933+#ifdef CONFIG_PAX_KERNEXEC
24934+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24935+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24936+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24937+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24938+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24939+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24940+#endif
24941+ pax_close_kernel();
24942+#endif
24943+
24944+ asm volatile("ljmpl *%0" : :
24945 "rm" (real_mode_header->machine_real_restart_asm),
24946 "a" (type));
24947 #else
24948@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24949 * try to force a triple fault and then cycle between hitting the keyboard
24950 * controller and doing that
24951 */
24952-static void native_machine_emergency_restart(void)
24953+static void __noreturn native_machine_emergency_restart(void)
24954 {
24955 int i;
24956 int attempt = 0;
24957@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24958 #endif
24959 }
24960
24961-static void __machine_emergency_restart(int emergency)
24962+static void __noreturn __machine_emergency_restart(int emergency)
24963 {
24964 reboot_emergency = emergency;
24965 machine_ops.emergency_restart();
24966 }
24967
24968-static void native_machine_restart(char *__unused)
24969+static void __noreturn native_machine_restart(char *__unused)
24970 {
24971 pr_notice("machine restart\n");
24972
24973@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24974 __machine_emergency_restart(0);
24975 }
24976
24977-static void native_machine_halt(void)
24978+static void __noreturn native_machine_halt(void)
24979 {
24980 /* Stop other cpus and apics */
24981 machine_shutdown();
24982@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24983 stop_this_cpu(NULL);
24984 }
24985
24986-static void native_machine_power_off(void)
24987+static void __noreturn native_machine_power_off(void)
24988 {
24989 if (pm_power_off) {
24990 if (!reboot_force)
24991@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
24992 }
24993 /* A fallback in case there is no PM info available */
24994 tboot_shutdown(TB_SHUTDOWN_HALT);
24995+ unreachable();
24996 }
24997
24998-struct machine_ops machine_ops = {
24999+struct machine_ops machine_ops __read_only = {
25000 .power_off = native_machine_power_off,
25001 .shutdown = native_machine_shutdown,
25002 .emergency_restart = native_machine_emergency_restart,
25003diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25004index c8e41e9..64049ef 100644
25005--- a/arch/x86/kernel/reboot_fixups_32.c
25006+++ b/arch/x86/kernel/reboot_fixups_32.c
25007@@ -57,7 +57,7 @@ struct device_fixup {
25008 unsigned int vendor;
25009 unsigned int device;
25010 void (*reboot_fixup)(struct pci_dev *);
25011-};
25012+} __do_const;
25013
25014 /*
25015 * PCI ids solely used for fixups_table go here
25016diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25017index 3fd2c69..16ef367 100644
25018--- a/arch/x86/kernel/relocate_kernel_64.S
25019+++ b/arch/x86/kernel/relocate_kernel_64.S
25020@@ -11,6 +11,7 @@
25021 #include <asm/kexec.h>
25022 #include <asm/processor-flags.h>
25023 #include <asm/pgtable_types.h>
25024+#include <asm/alternative-asm.h>
25025
25026 /*
25027 * Must be relocatable PIC code callable as a C function
25028@@ -96,8 +97,7 @@ relocate_kernel:
25029
25030 /* jump to identity mapped page */
25031 addq $(identity_mapped - relocate_kernel), %r8
25032- pushq %r8
25033- ret
25034+ jmp *%r8
25035
25036 identity_mapped:
25037 /* set return address to 0 if not preserving context */
25038@@ -167,6 +167,7 @@ identity_mapped:
25039 xorl %r14d, %r14d
25040 xorl %r15d, %r15d
25041
25042+ pax_force_retaddr 0, 1
25043 ret
25044
25045 1:
25046diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25047index f8ec578..0cc110a 100644
25048--- a/arch/x86/kernel/setup.c
25049+++ b/arch/x86/kernel/setup.c
25050@@ -110,6 +110,7 @@
25051 #include <asm/mce.h>
25052 #include <asm/alternative.h>
25053 #include <asm/prom.h>
25054+#include <asm/boot.h>
25055
25056 /*
25057 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25058@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25059 #endif
25060
25061
25062-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25063-unsigned long mmu_cr4_features;
25064+#ifdef CONFIG_X86_64
25065+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25066+#elif defined(CONFIG_X86_PAE)
25067+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25068 #else
25069-unsigned long mmu_cr4_features = X86_CR4_PAE;
25070+unsigned long mmu_cr4_features __read_only;
25071 #endif
25072
25073+void set_in_cr4(unsigned long mask)
25074+{
25075+ unsigned long cr4 = read_cr4();
25076+
25077+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25078+ return;
25079+
25080+ pax_open_kernel();
25081+ mmu_cr4_features |= mask;
25082+ pax_close_kernel();
25083+
25084+ if (trampoline_cr4_features)
25085+ *trampoline_cr4_features = mmu_cr4_features;
25086+ cr4 |= mask;
25087+ write_cr4(cr4);
25088+}
25089+EXPORT_SYMBOL(set_in_cr4);
25090+
25091+void clear_in_cr4(unsigned long mask)
25092+{
25093+ unsigned long cr4 = read_cr4();
25094+
25095+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25096+ return;
25097+
25098+ pax_open_kernel();
25099+ mmu_cr4_features &= ~mask;
25100+ pax_close_kernel();
25101+
25102+ if (trampoline_cr4_features)
25103+ *trampoline_cr4_features = mmu_cr4_features;
25104+ cr4 &= ~mask;
25105+ write_cr4(cr4);
25106+}
25107+EXPORT_SYMBOL(clear_in_cr4);
25108+
25109 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25110 int bootloader_type, bootloader_version;
25111
25112@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25113
25114 switch (data->type) {
25115 case SETUP_E820_EXT:
25116- parse_e820_ext(data);
25117+ parse_e820_ext((struct setup_data __force_kernel *)data);
25118 break;
25119 case SETUP_DTB:
25120 add_dtb(pa_data);
25121@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25122 * area (640->1Mb) as ram even though it is not.
25123 * take them out.
25124 */
25125- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25126+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25127
25128 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25129 }
25130@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25131 /* called before trim_bios_range() to spare extra sanitize */
25132 static void __init e820_add_kernel_range(void)
25133 {
25134- u64 start = __pa_symbol(_text);
25135+ u64 start = __pa_symbol(ktla_ktva(_text));
25136 u64 size = __pa_symbol(_end) - start;
25137
25138 /*
25139@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25140
25141 void __init setup_arch(char **cmdline_p)
25142 {
25143+#ifdef CONFIG_X86_32
25144+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25145+#else
25146 memblock_reserve(__pa_symbol(_text),
25147 (unsigned long)__bss_stop - (unsigned long)_text);
25148+#endif
25149
25150 early_reserve_initrd();
25151
25152@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25153
25154 if (!boot_params.hdr.root_flags)
25155 root_mountflags &= ~MS_RDONLY;
25156- init_mm.start_code = (unsigned long) _text;
25157- init_mm.end_code = (unsigned long) _etext;
25158+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25159+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25160 init_mm.end_data = (unsigned long) _edata;
25161 init_mm.brk = _brk_end;
25162
25163- code_resource.start = __pa_symbol(_text);
25164- code_resource.end = __pa_symbol(_etext)-1;
25165- data_resource.start = __pa_symbol(_etext);
25166+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25167+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25168+ data_resource.start = __pa_symbol(_sdata);
25169 data_resource.end = __pa_symbol(_edata)-1;
25170 bss_resource.start = __pa_symbol(__bss_start);
25171 bss_resource.end = __pa_symbol(__bss_stop)-1;
25172diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25173index 5cdff03..80fa283 100644
25174--- a/arch/x86/kernel/setup_percpu.c
25175+++ b/arch/x86/kernel/setup_percpu.c
25176@@ -21,19 +21,17 @@
25177 #include <asm/cpu.h>
25178 #include <asm/stackprotector.h>
25179
25180-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25181+#ifdef CONFIG_SMP
25182+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25183 EXPORT_PER_CPU_SYMBOL(cpu_number);
25184+#endif
25185
25186-#ifdef CONFIG_X86_64
25187 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25188-#else
25189-#define BOOT_PERCPU_OFFSET 0
25190-#endif
25191
25192 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25193 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25194
25195-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25196+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25197 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25198 };
25199 EXPORT_SYMBOL(__per_cpu_offset);
25200@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25201 {
25202 #ifdef CONFIG_NEED_MULTIPLE_NODES
25203 pg_data_t *last = NULL;
25204- unsigned int cpu;
25205+ int cpu;
25206
25207 for_each_possible_cpu(cpu) {
25208 int node = early_cpu_to_node(cpu);
25209@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25210 {
25211 #ifdef CONFIG_X86_32
25212 struct desc_struct gdt;
25213+ unsigned long base = per_cpu_offset(cpu);
25214
25215- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25216- 0x2 | DESCTYPE_S, 0x8);
25217- gdt.s = 1;
25218+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25219+ 0x83 | DESCTYPE_S, 0xC);
25220 write_gdt_entry(get_cpu_gdt_table(cpu),
25221 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25222 #endif
25223@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25224 /* alrighty, percpu areas up and running */
25225 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25226 for_each_possible_cpu(cpu) {
25227+#ifdef CONFIG_CC_STACKPROTECTOR
25228+#ifdef CONFIG_X86_32
25229+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25230+#endif
25231+#endif
25232 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25233 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25234 per_cpu(cpu_number, cpu) = cpu;
25235@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25236 */
25237 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25238 #endif
25239+#ifdef CONFIG_CC_STACKPROTECTOR
25240+#ifdef CONFIG_X86_32
25241+ if (!cpu)
25242+ per_cpu(stack_canary.canary, cpu) = canary;
25243+#endif
25244+#endif
25245 /*
25246 * Up to this point, the boot CPU has been using .init.data
25247 * area. Reload any changed state for the boot CPU.
25248diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25249index cf91358..a7081ea 100644
25250--- a/arch/x86/kernel/signal.c
25251+++ b/arch/x86/kernel/signal.c
25252@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25253 * Align the stack pointer according to the i386 ABI,
25254 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25255 */
25256- sp = ((sp + 4) & -16ul) - 4;
25257+ sp = ((sp - 12) & -16ul) - 4;
25258 #else /* !CONFIG_X86_32 */
25259 sp = round_down(sp, 16) - 8;
25260 #endif
25261@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25262 }
25263
25264 if (current->mm->context.vdso)
25265- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25266+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25267 else
25268- restorer = &frame->retcode;
25269+ restorer = (void __user *)&frame->retcode;
25270 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25271 restorer = ksig->ka.sa.sa_restorer;
25272
25273@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25274 * reasons and because gdb uses it as a signature to notice
25275 * signal handler stack frames.
25276 */
25277- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25278+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25279
25280 if (err)
25281 return -EFAULT;
25282@@ -358,10 +358,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25283 else
25284 put_user_ex(0, &frame->uc.uc_flags);
25285 put_user_ex(0, &frame->uc.uc_link);
25286- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25287+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25288
25289 /* Set up to return from userspace. */
25290- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25291+ if (current->mm->context.vdso)
25292+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25293+ else
25294+ restorer = (void __user *)&frame->retcode;
25295 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25296 restorer = ksig->ka.sa.sa_restorer;
25297 put_user_ex(restorer, &frame->pretcode);
25298@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25299 * reasons and because gdb uses it as a signature to notice
25300 * signal handler stack frames.
25301 */
25302- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25303+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25304 } put_user_catch(err);
25305
25306 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25307@@ -423,7 +426,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25308 else
25309 put_user_ex(0, &frame->uc.uc_flags);
25310 put_user_ex(0, &frame->uc.uc_link);
25311- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25312+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25313
25314 /* Set up to return from userspace. If provided, use a stub
25315 already in userspace. */
25316@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25317 {
25318 int usig = signr_convert(ksig->sig);
25319 sigset_t *set = sigmask_to_save();
25320- compat_sigset_t *cset = (compat_sigset_t *) set;
25321+ sigset_t sigcopy;
25322+ compat_sigset_t *cset;
25323+
25324+ sigcopy = *set;
25325+
25326+ cset = (compat_sigset_t *) &sigcopy;
25327
25328 /* Set up the stack frame */
25329 if (is_ia32_frame()) {
25330@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25331 } else if (is_x32_frame()) {
25332 return x32_setup_rt_frame(ksig, cset, regs);
25333 } else {
25334- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25335+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25336 }
25337 }
25338
25339diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25340index cdaa347..f5af55d 100644
25341--- a/arch/x86/kernel/smp.c
25342+++ b/arch/x86/kernel/smp.c
25343@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25344
25345 __setup("nonmi_ipi", nonmi_ipi_setup);
25346
25347-struct smp_ops smp_ops = {
25348+struct smp_ops smp_ops __read_only = {
25349 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25350 .smp_prepare_cpus = native_smp_prepare_cpus,
25351 .smp_cpus_done = native_smp_cpus_done,
25352diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25353index aecc98a..0244a53 100644
25354--- a/arch/x86/kernel/smpboot.c
25355+++ b/arch/x86/kernel/smpboot.c
25356@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25357
25358 enable_start_cpu0 = 0;
25359
25360-#ifdef CONFIG_X86_32
25361- /* switch away from the initial page table */
25362- load_cr3(swapper_pg_dir);
25363- __flush_tlb_all();
25364-#endif
25365-
25366 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25367 barrier();
25368+
25369+ /* switch away from the initial page table */
25370+#ifdef CONFIG_PAX_PER_CPU_PGD
25371+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25372+ __flush_tlb_all();
25373+#elif defined(CONFIG_X86_32)
25374+ load_cr3(swapper_pg_dir);
25375+ __flush_tlb_all();
25376+#endif
25377+
25378 /*
25379 * Check TSC synchronization with the BP:
25380 */
25381@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25382 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25383 (THREAD_SIZE + task_stack_page(idle))) - 1);
25384 per_cpu(current_task, cpu) = idle;
25385+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25386
25387 #ifdef CONFIG_X86_32
25388 /* Stack for startup_32 can be just as for start_secondary onwards */
25389@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25390 #else
25391 clear_tsk_thread_flag(idle, TIF_FORK);
25392 initial_gs = per_cpu_offset(cpu);
25393- per_cpu(kernel_stack, cpu) =
25394- (unsigned long)task_stack_page(idle) -
25395- KERNEL_STACK_OFFSET + THREAD_SIZE;
25396+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25397 #endif
25398+
25399+ pax_open_kernel();
25400 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25401+ pax_close_kernel();
25402+
25403 initial_code = (unsigned long)start_secondary;
25404 stack_start = idle->thread.sp;
25405
25406@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25407 /* the FPU context is blank, nobody can own it */
25408 __cpu_disable_lazy_restore(cpu);
25409
25410+#ifdef CONFIG_PAX_PER_CPU_PGD
25411+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25412+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25413+ KERNEL_PGD_PTRS);
25414+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25415+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25416+ KERNEL_PGD_PTRS);
25417+#endif
25418+
25419 err = do_boot_cpu(apicid, cpu, tidle);
25420 if (err) {
25421 pr_debug("do_boot_cpu failed %d\n", err);
25422diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25423index 9b4d51d..5d28b58 100644
25424--- a/arch/x86/kernel/step.c
25425+++ b/arch/x86/kernel/step.c
25426@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25427 struct desc_struct *desc;
25428 unsigned long base;
25429
25430- seg &= ~7UL;
25431+ seg >>= 3;
25432
25433 mutex_lock(&child->mm->context.lock);
25434- if (unlikely((seg >> 3) >= child->mm->context.size))
25435+ if (unlikely(seg >= child->mm->context.size))
25436 addr = -1L; /* bogus selector, access would fault */
25437 else {
25438 desc = child->mm->context.ldt + seg;
25439@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25440 addr += base;
25441 }
25442 mutex_unlock(&child->mm->context.lock);
25443- }
25444+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25445+ addr = ktla_ktva(addr);
25446
25447 return addr;
25448 }
25449@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25450 unsigned char opcode[15];
25451 unsigned long addr = convert_ip_to_linear(child, regs);
25452
25453+ if (addr == -EINVAL)
25454+ return 0;
25455+
25456 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25457 for (i = 0; i < copied; i++) {
25458 switch (opcode[i]) {
25459diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25460new file mode 100644
25461index 0000000..5877189
25462--- /dev/null
25463+++ b/arch/x86/kernel/sys_i386_32.c
25464@@ -0,0 +1,189 @@
25465+/*
25466+ * This file contains various random system calls that
25467+ * have a non-standard calling sequence on the Linux/i386
25468+ * platform.
25469+ */
25470+
25471+#include <linux/errno.h>
25472+#include <linux/sched.h>
25473+#include <linux/mm.h>
25474+#include <linux/fs.h>
25475+#include <linux/smp.h>
25476+#include <linux/sem.h>
25477+#include <linux/msg.h>
25478+#include <linux/shm.h>
25479+#include <linux/stat.h>
25480+#include <linux/syscalls.h>
25481+#include <linux/mman.h>
25482+#include <linux/file.h>
25483+#include <linux/utsname.h>
25484+#include <linux/ipc.h>
25485+#include <linux/elf.h>
25486+
25487+#include <linux/uaccess.h>
25488+#include <linux/unistd.h>
25489+
25490+#include <asm/syscalls.h>
25491+
25492+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25493+{
25494+ unsigned long pax_task_size = TASK_SIZE;
25495+
25496+#ifdef CONFIG_PAX_SEGMEXEC
25497+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25498+ pax_task_size = SEGMEXEC_TASK_SIZE;
25499+#endif
25500+
25501+ if (flags & MAP_FIXED)
25502+ if (len > pax_task_size || addr > pax_task_size - len)
25503+ return -EINVAL;
25504+
25505+ return 0;
25506+}
25507+
25508+/*
25509+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25510+ */
25511+static unsigned long get_align_mask(void)
25512+{
25513+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25514+ return 0;
25515+
25516+ if (!(current->flags & PF_RANDOMIZE))
25517+ return 0;
25518+
25519+ return va_align.mask;
25520+}
25521+
25522+unsigned long
25523+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25524+ unsigned long len, unsigned long pgoff, unsigned long flags)
25525+{
25526+ struct mm_struct *mm = current->mm;
25527+ struct vm_area_struct *vma;
25528+ unsigned long pax_task_size = TASK_SIZE;
25529+ struct vm_unmapped_area_info info;
25530+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25531+
25532+#ifdef CONFIG_PAX_SEGMEXEC
25533+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25534+ pax_task_size = SEGMEXEC_TASK_SIZE;
25535+#endif
25536+
25537+ pax_task_size -= PAGE_SIZE;
25538+
25539+ if (len > pax_task_size)
25540+ return -ENOMEM;
25541+
25542+ if (flags & MAP_FIXED)
25543+ return addr;
25544+
25545+#ifdef CONFIG_PAX_RANDMMAP
25546+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25547+#endif
25548+
25549+ if (addr) {
25550+ addr = PAGE_ALIGN(addr);
25551+ if (pax_task_size - len >= addr) {
25552+ vma = find_vma(mm, addr);
25553+ if (check_heap_stack_gap(vma, addr, len, offset))
25554+ return addr;
25555+ }
25556+ }
25557+
25558+ info.flags = 0;
25559+ info.length = len;
25560+ info.align_mask = filp ? get_align_mask() : 0;
25561+ info.align_offset = pgoff << PAGE_SHIFT;
25562+ info.threadstack_offset = offset;
25563+
25564+#ifdef CONFIG_PAX_PAGEEXEC
25565+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25566+ info.low_limit = 0x00110000UL;
25567+ info.high_limit = mm->start_code;
25568+
25569+#ifdef CONFIG_PAX_RANDMMAP
25570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25571+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25572+#endif
25573+
25574+ if (info.low_limit < info.high_limit) {
25575+ addr = vm_unmapped_area(&info);
25576+ if (!IS_ERR_VALUE(addr))
25577+ return addr;
25578+ }
25579+ } else
25580+#endif
25581+
25582+ info.low_limit = mm->mmap_base;
25583+ info.high_limit = pax_task_size;
25584+
25585+ return vm_unmapped_area(&info);
25586+}
25587+
25588+unsigned long
25589+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25590+ const unsigned long len, const unsigned long pgoff,
25591+ const unsigned long flags)
25592+{
25593+ struct vm_area_struct *vma;
25594+ struct mm_struct *mm = current->mm;
25595+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25596+ struct vm_unmapped_area_info info;
25597+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25598+
25599+#ifdef CONFIG_PAX_SEGMEXEC
25600+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25601+ pax_task_size = SEGMEXEC_TASK_SIZE;
25602+#endif
25603+
25604+ pax_task_size -= PAGE_SIZE;
25605+
25606+ /* requested length too big for entire address space */
25607+ if (len > pax_task_size)
25608+ return -ENOMEM;
25609+
25610+ if (flags & MAP_FIXED)
25611+ return addr;
25612+
25613+#ifdef CONFIG_PAX_PAGEEXEC
25614+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25615+ goto bottomup;
25616+#endif
25617+
25618+#ifdef CONFIG_PAX_RANDMMAP
25619+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25620+#endif
25621+
25622+ /* requesting a specific address */
25623+ if (addr) {
25624+ addr = PAGE_ALIGN(addr);
25625+ if (pax_task_size - len >= addr) {
25626+ vma = find_vma(mm, addr);
25627+ if (check_heap_stack_gap(vma, addr, len, offset))
25628+ return addr;
25629+ }
25630+ }
25631+
25632+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25633+ info.length = len;
25634+ info.low_limit = PAGE_SIZE;
25635+ info.high_limit = mm->mmap_base;
25636+ info.align_mask = filp ? get_align_mask() : 0;
25637+ info.align_offset = pgoff << PAGE_SHIFT;
25638+ info.threadstack_offset = offset;
25639+
25640+ addr = vm_unmapped_area(&info);
25641+ if (!(addr & ~PAGE_MASK))
25642+ return addr;
25643+ VM_BUG_ON(addr != -ENOMEM);
25644+
25645+bottomup:
25646+ /*
25647+ * A failed mmap() very likely causes application failure,
25648+ * so fall back to the bottom-up function here. This scenario
25649+ * can happen with large stack limits and large mmap()
25650+ * allocations.
25651+ */
25652+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25653+}
25654diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25655index 30277e2..5664a29 100644
25656--- a/arch/x86/kernel/sys_x86_64.c
25657+++ b/arch/x86/kernel/sys_x86_64.c
25658@@ -81,8 +81,8 @@ out:
25659 return error;
25660 }
25661
25662-static void find_start_end(unsigned long flags, unsigned long *begin,
25663- unsigned long *end)
25664+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25665+ unsigned long *begin, unsigned long *end)
25666 {
25667 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25668 unsigned long new_begin;
25669@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25670 *begin = new_begin;
25671 }
25672 } else {
25673- *begin = current->mm->mmap_legacy_base;
25674+ *begin = mm->mmap_legacy_base;
25675 *end = TASK_SIZE;
25676 }
25677 }
25678@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25679 struct vm_area_struct *vma;
25680 struct vm_unmapped_area_info info;
25681 unsigned long begin, end;
25682+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25683
25684 if (flags & MAP_FIXED)
25685 return addr;
25686
25687- find_start_end(flags, &begin, &end);
25688+ find_start_end(mm, flags, &begin, &end);
25689
25690 if (len > end)
25691 return -ENOMEM;
25692
25693+#ifdef CONFIG_PAX_RANDMMAP
25694+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25695+#endif
25696+
25697 if (addr) {
25698 addr = PAGE_ALIGN(addr);
25699 vma = find_vma(mm, addr);
25700- if (end - len >= addr &&
25701- (!vma || addr + len <= vma->vm_start))
25702+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25703 return addr;
25704 }
25705
25706@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25707 info.high_limit = end;
25708 info.align_mask = filp ? get_align_mask() : 0;
25709 info.align_offset = pgoff << PAGE_SHIFT;
25710+ info.threadstack_offset = offset;
25711 return vm_unmapped_area(&info);
25712 }
25713
25714@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25715 struct mm_struct *mm = current->mm;
25716 unsigned long addr = addr0;
25717 struct vm_unmapped_area_info info;
25718+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25719
25720 /* requested length too big for entire address space */
25721 if (len > TASK_SIZE)
25722@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25723 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25724 goto bottomup;
25725
25726+#ifdef CONFIG_PAX_RANDMMAP
25727+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25728+#endif
25729+
25730 /* requesting a specific address */
25731 if (addr) {
25732 addr = PAGE_ALIGN(addr);
25733 vma = find_vma(mm, addr);
25734- if (TASK_SIZE - len >= addr &&
25735- (!vma || addr + len <= vma->vm_start))
25736+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25737 return addr;
25738 }
25739
25740@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25741 info.high_limit = mm->mmap_base;
25742 info.align_mask = filp ? get_align_mask() : 0;
25743 info.align_offset = pgoff << PAGE_SHIFT;
25744+ info.threadstack_offset = offset;
25745 addr = vm_unmapped_area(&info);
25746 if (!(addr & ~PAGE_MASK))
25747 return addr;
25748diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25749index addf7b5..f960685 100644
25750--- a/arch/x86/kernel/tboot.c
25751+++ b/arch/x86/kernel/tboot.c
25752@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25753
25754 void tboot_shutdown(u32 shutdown_type)
25755 {
25756- void (*shutdown)(void);
25757+ void (* __noreturn shutdown)(void);
25758
25759 if (!tboot_enabled())
25760 return;
25761@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25762
25763 switch_to_tboot_pt();
25764
25765- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25766+ shutdown = (void *)tboot->shutdown_entry;
25767 shutdown();
25768
25769 /* should not reach here */
25770@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25771 return 0;
25772 }
25773
25774-static atomic_t ap_wfs_count;
25775+static atomic_unchecked_t ap_wfs_count;
25776
25777 static int tboot_wait_for_aps(int num_aps)
25778 {
25779@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25780 {
25781 switch (action) {
25782 case CPU_DYING:
25783- atomic_inc(&ap_wfs_count);
25784+ atomic_inc_unchecked(&ap_wfs_count);
25785 if (num_online_cpus() == 1)
25786- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25787+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25788 return NOTIFY_BAD;
25789 break;
25790 }
25791@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25792
25793 tboot_create_trampoline();
25794
25795- atomic_set(&ap_wfs_count, 0);
25796+ atomic_set_unchecked(&ap_wfs_count, 0);
25797 register_hotcpu_notifier(&tboot_cpu_notifier);
25798
25799 #ifdef CONFIG_DEBUG_FS
25800diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25801index 24d3c91..d06b473 100644
25802--- a/arch/x86/kernel/time.c
25803+++ b/arch/x86/kernel/time.c
25804@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25805 {
25806 unsigned long pc = instruction_pointer(regs);
25807
25808- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25809+ if (!user_mode(regs) && in_lock_functions(pc)) {
25810 #ifdef CONFIG_FRAME_POINTER
25811- return *(unsigned long *)(regs->bp + sizeof(long));
25812+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25813 #else
25814 unsigned long *sp =
25815 (unsigned long *)kernel_stack_pointer(regs);
25816@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25817 * or above a saved flags. Eflags has bits 22-31 zero,
25818 * kernel addresses don't.
25819 */
25820+
25821+#ifdef CONFIG_PAX_KERNEXEC
25822+ return ktla_ktva(sp[0]);
25823+#else
25824 if (sp[0] >> 22)
25825 return sp[0];
25826 if (sp[1] >> 22)
25827 return sp[1];
25828 #endif
25829+
25830+#endif
25831 }
25832 return pc;
25833 }
25834diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25835index f7fec09..9991981 100644
25836--- a/arch/x86/kernel/tls.c
25837+++ b/arch/x86/kernel/tls.c
25838@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25839 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25840 return -EINVAL;
25841
25842+#ifdef CONFIG_PAX_SEGMEXEC
25843+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25844+ return -EINVAL;
25845+#endif
25846+
25847 set_tls_desc(p, idx, &info, 1);
25848
25849 return 0;
25850@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25851
25852 if (kbuf)
25853 info = kbuf;
25854- else if (__copy_from_user(infobuf, ubuf, count))
25855+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25856 return -EFAULT;
25857 else
25858 info = infobuf;
25859diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25860index 1c113db..287b42e 100644
25861--- a/arch/x86/kernel/tracepoint.c
25862+++ b/arch/x86/kernel/tracepoint.c
25863@@ -9,11 +9,11 @@
25864 #include <linux/atomic.h>
25865
25866 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25867-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25868+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25869 (unsigned long) trace_idt_table };
25870
25871 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25872-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25873+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25874
25875 static int trace_irq_vector_refcount;
25876 static DEFINE_MUTEX(irq_vector_mutex);
25877diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25878index 1b23a1c..910de0d 100644
25879--- a/arch/x86/kernel/traps.c
25880+++ b/arch/x86/kernel/traps.c
25881@@ -65,7 +65,7 @@
25882 #include <asm/proto.h>
25883
25884 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25885-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25886+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25887 #else
25888 #include <asm/processor-flags.h>
25889 #include <asm/setup.h>
25890@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25891 #endif
25892
25893 /* Must be page-aligned because the real IDT is used in a fixmap. */
25894-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25895+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25896
25897 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25898 EXPORT_SYMBOL_GPL(used_vectors);
25899@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25900 }
25901
25902 static int __kprobes
25903-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25904+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25905 struct pt_regs *regs, long error_code)
25906 {
25907 #ifdef CONFIG_X86_32
25908- if (regs->flags & X86_VM_MASK) {
25909+ if (v8086_mode(regs)) {
25910 /*
25911 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25912 * On nmi (interrupt 2), do_trap should not be called.
25913@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25914 return -1;
25915 }
25916 #endif
25917- if (!user_mode(regs)) {
25918+ if (!user_mode_novm(regs)) {
25919 if (!fixup_exception(regs)) {
25920 tsk->thread.error_code = error_code;
25921 tsk->thread.trap_nr = trapnr;
25922+
25923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25924+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25925+ str = "PAX: suspicious stack segment fault";
25926+#endif
25927+
25928 die(str, regs, error_code);
25929 }
25930+
25931+#ifdef CONFIG_PAX_REFCOUNT
25932+ if (trapnr == 4)
25933+ pax_report_refcount_overflow(regs);
25934+#endif
25935+
25936 return 0;
25937 }
25938
25939@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25940 }
25941
25942 static void __kprobes
25943-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25944+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25945 long error_code, siginfo_t *info)
25946 {
25947 struct task_struct *tsk = current;
25948@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25949 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25950 printk_ratelimit()) {
25951 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25952- tsk->comm, tsk->pid, str,
25953+ tsk->comm, task_pid_nr(tsk), str,
25954 regs->ip, regs->sp, error_code);
25955 print_vma_addr(" in ", regs->ip);
25956 pr_cont("\n");
25957@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25958 conditional_sti(regs);
25959
25960 #ifdef CONFIG_X86_32
25961- if (regs->flags & X86_VM_MASK) {
25962+ if (v8086_mode(regs)) {
25963 local_irq_enable();
25964 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25965 goto exit;
25966@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25967 #endif
25968
25969 tsk = current;
25970- if (!user_mode(regs)) {
25971+ if (!user_mode_novm(regs)) {
25972 if (fixup_exception(regs))
25973 goto exit;
25974
25975 tsk->thread.error_code = error_code;
25976 tsk->thread.trap_nr = X86_TRAP_GP;
25977 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25978- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25979+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25980+
25981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25982+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25983+ die("PAX: suspicious general protection fault", regs, error_code);
25984+ else
25985+#endif
25986+
25987 die("general protection fault", regs, error_code);
25988+ }
25989 goto exit;
25990 }
25991
25992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25993+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25994+ struct mm_struct *mm = tsk->mm;
25995+ unsigned long limit;
25996+
25997+ down_write(&mm->mmap_sem);
25998+ limit = mm->context.user_cs_limit;
25999+ if (limit < TASK_SIZE) {
26000+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26001+ up_write(&mm->mmap_sem);
26002+ return;
26003+ }
26004+ up_write(&mm->mmap_sem);
26005+ }
26006+#endif
26007+
26008 tsk->thread.error_code = error_code;
26009 tsk->thread.trap_nr = X86_TRAP_GP;
26010
26011@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26012 /* It's safe to allow irq's after DR6 has been saved */
26013 preempt_conditional_sti(regs);
26014
26015- if (regs->flags & X86_VM_MASK) {
26016+ if (v8086_mode(regs)) {
26017 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26018 X86_TRAP_DB);
26019 preempt_conditional_cli(regs);
26020@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26021 * We already checked v86 mode above, so we can check for kernel mode
26022 * by just checking the CPL of CS.
26023 */
26024- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26025+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26026 tsk->thread.debugreg6 &= ~DR_STEP;
26027 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26028 regs->flags &= ~X86_EFLAGS_TF;
26029@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26030 return;
26031 conditional_sti(regs);
26032
26033- if (!user_mode_vm(regs))
26034+ if (!user_mode(regs))
26035 {
26036 if (!fixup_exception(regs)) {
26037 task->thread.error_code = error_code;
26038diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26039index 2ed8459..7cf329f 100644
26040--- a/arch/x86/kernel/uprobes.c
26041+++ b/arch/x86/kernel/uprobes.c
26042@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26043 int ret = NOTIFY_DONE;
26044
26045 /* We are only interested in userspace traps */
26046- if (regs && !user_mode_vm(regs))
26047+ if (regs && !user_mode(regs))
26048 return NOTIFY_DONE;
26049
26050 switch (val) {
26051@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26052
26053 if (ncopied != rasize) {
26054 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26055- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26056+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26057
26058 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26059 }
26060diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26061index b9242ba..50c5edd 100644
26062--- a/arch/x86/kernel/verify_cpu.S
26063+++ b/arch/x86/kernel/verify_cpu.S
26064@@ -20,6 +20,7 @@
26065 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26066 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26067 * arch/x86/kernel/head_32.S: processor startup
26068+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26069 *
26070 * verify_cpu, returns the status of longmode and SSE in register %eax.
26071 * 0: Success 1: Failure
26072diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26073index e8edcf5..27f9344 100644
26074--- a/arch/x86/kernel/vm86_32.c
26075+++ b/arch/x86/kernel/vm86_32.c
26076@@ -44,6 +44,7 @@
26077 #include <linux/ptrace.h>
26078 #include <linux/audit.h>
26079 #include <linux/stddef.h>
26080+#include <linux/grsecurity.h>
26081
26082 #include <asm/uaccess.h>
26083 #include <asm/io.h>
26084@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26085 do_exit(SIGSEGV);
26086 }
26087
26088- tss = &per_cpu(init_tss, get_cpu());
26089+ tss = init_tss + get_cpu();
26090 current->thread.sp0 = current->thread.saved_sp0;
26091 current->thread.sysenter_cs = __KERNEL_CS;
26092 load_sp0(tss, &current->thread);
26093@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26094
26095 if (tsk->thread.saved_sp0)
26096 return -EPERM;
26097+
26098+#ifdef CONFIG_GRKERNSEC_VM86
26099+ if (!capable(CAP_SYS_RAWIO)) {
26100+ gr_handle_vm86();
26101+ return -EPERM;
26102+ }
26103+#endif
26104+
26105 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26106 offsetof(struct kernel_vm86_struct, vm86plus) -
26107 sizeof(info.regs));
26108@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26109 int tmp;
26110 struct vm86plus_struct __user *v86;
26111
26112+#ifdef CONFIG_GRKERNSEC_VM86
26113+ if (!capable(CAP_SYS_RAWIO)) {
26114+ gr_handle_vm86();
26115+ return -EPERM;
26116+ }
26117+#endif
26118+
26119 tsk = current;
26120 switch (cmd) {
26121 case VM86_REQUEST_IRQ:
26122@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26123 tsk->thread.saved_fs = info->regs32->fs;
26124 tsk->thread.saved_gs = get_user_gs(info->regs32);
26125
26126- tss = &per_cpu(init_tss, get_cpu());
26127+ tss = init_tss + get_cpu();
26128 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26129 if (cpu_has_sep)
26130 tsk->thread.sysenter_cs = 0;
26131@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26132 goto cannot_handle;
26133 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26134 goto cannot_handle;
26135- intr_ptr = (unsigned long __user *) (i << 2);
26136+ intr_ptr = (__force unsigned long __user *) (i << 2);
26137 if (get_user(segoffs, intr_ptr))
26138 goto cannot_handle;
26139 if ((segoffs >> 16) == BIOSSEG)
26140diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26141index 10c4f30..65408b9 100644
26142--- a/arch/x86/kernel/vmlinux.lds.S
26143+++ b/arch/x86/kernel/vmlinux.lds.S
26144@@ -26,6 +26,13 @@
26145 #include <asm/page_types.h>
26146 #include <asm/cache.h>
26147 #include <asm/boot.h>
26148+#include <asm/segment.h>
26149+
26150+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26151+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26152+#else
26153+#define __KERNEL_TEXT_OFFSET 0
26154+#endif
26155
26156 #undef i386 /* in case the preprocessor is a 32bit one */
26157
26158@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26159
26160 PHDRS {
26161 text PT_LOAD FLAGS(5); /* R_E */
26162+#ifdef CONFIG_X86_32
26163+ module PT_LOAD FLAGS(5); /* R_E */
26164+#endif
26165+#ifdef CONFIG_XEN
26166+ rodata PT_LOAD FLAGS(5); /* R_E */
26167+#else
26168+ rodata PT_LOAD FLAGS(4); /* R__ */
26169+#endif
26170 data PT_LOAD FLAGS(6); /* RW_ */
26171-#ifdef CONFIG_X86_64
26172+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26173 #ifdef CONFIG_SMP
26174 percpu PT_LOAD FLAGS(6); /* RW_ */
26175 #endif
26176+ text.init PT_LOAD FLAGS(5); /* R_E */
26177+ text.exit PT_LOAD FLAGS(5); /* R_E */
26178 init PT_LOAD FLAGS(7); /* RWE */
26179-#endif
26180 note PT_NOTE FLAGS(0); /* ___ */
26181 }
26182
26183 SECTIONS
26184 {
26185 #ifdef CONFIG_X86_32
26186- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26187- phys_startup_32 = startup_32 - LOAD_OFFSET;
26188+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26189 #else
26190- . = __START_KERNEL;
26191- phys_startup_64 = startup_64 - LOAD_OFFSET;
26192+ . = __START_KERNEL;
26193 #endif
26194
26195 /* Text and read-only data */
26196- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26197- _text = .;
26198+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26199 /* bootstrapping code */
26200+#ifdef CONFIG_X86_32
26201+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26202+#else
26203+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26204+#endif
26205+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26206+ _text = .;
26207 HEAD_TEXT
26208 . = ALIGN(8);
26209 _stext = .;
26210@@ -104,13 +124,47 @@ SECTIONS
26211 IRQENTRY_TEXT
26212 *(.fixup)
26213 *(.gnu.warning)
26214- /* End of text section */
26215- _etext = .;
26216 } :text = 0x9090
26217
26218- NOTES :text :note
26219+ . += __KERNEL_TEXT_OFFSET;
26220
26221- EXCEPTION_TABLE(16) :text = 0x9090
26222+#ifdef CONFIG_X86_32
26223+ . = ALIGN(PAGE_SIZE);
26224+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26225+
26226+#ifdef CONFIG_PAX_KERNEXEC
26227+ MODULES_EXEC_VADDR = .;
26228+ BYTE(0)
26229+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26230+ . = ALIGN(HPAGE_SIZE) - 1;
26231+ MODULES_EXEC_END = .;
26232+#endif
26233+
26234+ } :module
26235+#endif
26236+
26237+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26238+ /* End of text section */
26239+ BYTE(0)
26240+ _etext = . - __KERNEL_TEXT_OFFSET;
26241+ }
26242+
26243+#ifdef CONFIG_X86_32
26244+ . = ALIGN(PAGE_SIZE);
26245+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26246+ . = ALIGN(PAGE_SIZE);
26247+ *(.empty_zero_page)
26248+ *(.initial_pg_fixmap)
26249+ *(.initial_pg_pmd)
26250+ *(.initial_page_table)
26251+ *(.swapper_pg_dir)
26252+ } :rodata
26253+#endif
26254+
26255+ . = ALIGN(PAGE_SIZE);
26256+ NOTES :rodata :note
26257+
26258+ EXCEPTION_TABLE(16) :rodata
26259
26260 #if defined(CONFIG_DEBUG_RODATA)
26261 /* .text should occupy whole number of pages */
26262@@ -122,16 +176,20 @@ SECTIONS
26263
26264 /* Data */
26265 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26266+
26267+#ifdef CONFIG_PAX_KERNEXEC
26268+ . = ALIGN(HPAGE_SIZE);
26269+#else
26270+ . = ALIGN(PAGE_SIZE);
26271+#endif
26272+
26273 /* Start of data section */
26274 _sdata = .;
26275
26276 /* init_task */
26277 INIT_TASK_DATA(THREAD_SIZE)
26278
26279-#ifdef CONFIG_X86_32
26280- /* 32 bit has nosave before _edata */
26281 NOSAVE_DATA
26282-#endif
26283
26284 PAGE_ALIGNED_DATA(PAGE_SIZE)
26285
26286@@ -172,12 +230,19 @@ SECTIONS
26287 #endif /* CONFIG_X86_64 */
26288
26289 /* Init code and data - will be freed after init */
26290- . = ALIGN(PAGE_SIZE);
26291 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26292+ BYTE(0)
26293+
26294+#ifdef CONFIG_PAX_KERNEXEC
26295+ . = ALIGN(HPAGE_SIZE);
26296+#else
26297+ . = ALIGN(PAGE_SIZE);
26298+#endif
26299+
26300 __init_begin = .; /* paired with __init_end */
26301- }
26302+ } :init.begin
26303
26304-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26305+#ifdef CONFIG_SMP
26306 /*
26307 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26308 * output PHDR, so the next output section - .init.text - should
26309@@ -186,12 +251,27 @@ SECTIONS
26310 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26311 #endif
26312
26313- INIT_TEXT_SECTION(PAGE_SIZE)
26314-#ifdef CONFIG_X86_64
26315- :init
26316-#endif
26317+ . = ALIGN(PAGE_SIZE);
26318+ init_begin = .;
26319+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26320+ VMLINUX_SYMBOL(_sinittext) = .;
26321+ INIT_TEXT
26322+ VMLINUX_SYMBOL(_einittext) = .;
26323+ . = ALIGN(PAGE_SIZE);
26324+ } :text.init
26325
26326- INIT_DATA_SECTION(16)
26327+ /*
26328+ * .exit.text is discard at runtime, not link time, to deal with
26329+ * references from .altinstructions and .eh_frame
26330+ */
26331+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26332+ EXIT_TEXT
26333+ . = ALIGN(16);
26334+ } :text.exit
26335+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26336+
26337+ . = ALIGN(PAGE_SIZE);
26338+ INIT_DATA_SECTION(16) :init
26339
26340 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26341 __x86_cpu_dev_start = .;
26342@@ -253,19 +333,12 @@ SECTIONS
26343 }
26344
26345 . = ALIGN(8);
26346- /*
26347- * .exit.text is discard at runtime, not link time, to deal with
26348- * references from .altinstructions and .eh_frame
26349- */
26350- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26351- EXIT_TEXT
26352- }
26353
26354 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26355 EXIT_DATA
26356 }
26357
26358-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26359+#ifndef CONFIG_SMP
26360 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26361 #endif
26362
26363@@ -284,16 +357,10 @@ SECTIONS
26364 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26365 __smp_locks = .;
26366 *(.smp_locks)
26367- . = ALIGN(PAGE_SIZE);
26368 __smp_locks_end = .;
26369+ . = ALIGN(PAGE_SIZE);
26370 }
26371
26372-#ifdef CONFIG_X86_64
26373- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26374- NOSAVE_DATA
26375- }
26376-#endif
26377-
26378 /* BSS */
26379 . = ALIGN(PAGE_SIZE);
26380 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26381@@ -309,6 +376,7 @@ SECTIONS
26382 __brk_base = .;
26383 . += 64 * 1024; /* 64k alignment slop space */
26384 *(.brk_reservation) /* areas brk users have reserved */
26385+ . = ALIGN(HPAGE_SIZE);
26386 __brk_limit = .;
26387 }
26388
26389@@ -335,13 +403,12 @@ SECTIONS
26390 * for the boot processor.
26391 */
26392 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26393-INIT_PER_CPU(gdt_page);
26394 INIT_PER_CPU(irq_stack_union);
26395
26396 /*
26397 * Build-time check on the image size:
26398 */
26399-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26400+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26401 "kernel image bigger than KERNEL_IMAGE_SIZE");
26402
26403 #ifdef CONFIG_SMP
26404diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26405index 1f96f93..d5c8f7a 100644
26406--- a/arch/x86/kernel/vsyscall_64.c
26407+++ b/arch/x86/kernel/vsyscall_64.c
26408@@ -56,15 +56,13 @@
26409 DEFINE_VVAR(int, vgetcpu_mode);
26410 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26411
26412-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26413+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26414
26415 static int __init vsyscall_setup(char *str)
26416 {
26417 if (str) {
26418 if (!strcmp("emulate", str))
26419 vsyscall_mode = EMULATE;
26420- else if (!strcmp("native", str))
26421- vsyscall_mode = NATIVE;
26422 else if (!strcmp("none", str))
26423 vsyscall_mode = NONE;
26424 else
26425@@ -323,8 +321,7 @@ do_ret:
26426 return true;
26427
26428 sigsegv:
26429- force_sig(SIGSEGV, current);
26430- return true;
26431+ do_group_exit(SIGKILL);
26432 }
26433
26434 /*
26435@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26436 extern char __vvar_page;
26437 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26438
26439- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26440- vsyscall_mode == NATIVE
26441- ? PAGE_KERNEL_VSYSCALL
26442- : PAGE_KERNEL_VVAR);
26443+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26444 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26445 (unsigned long)VSYSCALL_START);
26446
26447diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26448index b014d94..e775258 100644
26449--- a/arch/x86/kernel/x8664_ksyms_64.c
26450+++ b/arch/x86/kernel/x8664_ksyms_64.c
26451@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26452 EXPORT_SYMBOL(copy_user_generic_unrolled);
26453 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26454 EXPORT_SYMBOL(__copy_user_nocache);
26455-EXPORT_SYMBOL(_copy_from_user);
26456-EXPORT_SYMBOL(_copy_to_user);
26457
26458 EXPORT_SYMBOL(copy_page);
26459 EXPORT_SYMBOL(clear_page);
26460@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26461 #ifndef CONFIG_PARAVIRT
26462 EXPORT_SYMBOL(native_load_gs_index);
26463 #endif
26464+
26465+#ifdef CONFIG_PAX_PER_CPU_PGD
26466+EXPORT_SYMBOL(cpu_pgd);
26467+#endif
26468diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26469index 5f24c71..1dadf09 100644
26470--- a/arch/x86/kernel/x86_init.c
26471+++ b/arch/x86/kernel/x86_init.c
26472@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26473 static void default_nmi_init(void) { };
26474 static int default_i8042_detect(void) { return 1; };
26475
26476-struct x86_platform_ops x86_platform = {
26477+struct x86_platform_ops x86_platform __read_only = {
26478 .calibrate_tsc = native_calibrate_tsc,
26479 .get_wallclock = mach_get_cmos_time,
26480 .set_wallclock = mach_set_rtc_mmss,
26481@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26482 };
26483
26484 EXPORT_SYMBOL_GPL(x86_platform);
26485-struct x86_msi_ops x86_msi = {
26486+struct x86_msi_ops x86_msi __read_only = {
26487 .setup_msi_irqs = native_setup_msi_irqs,
26488 .compose_msi_msg = native_compose_msi_msg,
26489 .teardown_msi_irq = native_teardown_msi_irq,
26490@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26491 .setup_hpet_msi = default_setup_hpet_msi,
26492 };
26493
26494-struct x86_io_apic_ops x86_io_apic_ops = {
26495+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26496 .init = native_io_apic_init_mappings,
26497 .read = native_io_apic_read,
26498 .write = native_io_apic_write,
26499diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26500index 422fd82..c3687ca 100644
26501--- a/arch/x86/kernel/xsave.c
26502+++ b/arch/x86/kernel/xsave.c
26503@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26504 {
26505 int err;
26506
26507+ buf = (struct xsave_struct __user *)____m(buf);
26508 if (use_xsave())
26509 err = xsave_user(buf);
26510 else if (use_fxsr())
26511@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26512 */
26513 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26514 {
26515+ buf = (void __user *)____m(buf);
26516 if (use_xsave()) {
26517 if ((unsigned long)buf % 64 || fx_only) {
26518 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26519diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26520index a20ecb5..d0e2194 100644
26521--- a/arch/x86/kvm/cpuid.c
26522+++ b/arch/x86/kvm/cpuid.c
26523@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26524 struct kvm_cpuid2 *cpuid,
26525 struct kvm_cpuid_entry2 __user *entries)
26526 {
26527- int r;
26528+ int r, i;
26529
26530 r = -E2BIG;
26531 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26532 goto out;
26533 r = -EFAULT;
26534- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26535- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26536+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26537 goto out;
26538+ for (i = 0; i < cpuid->nent; ++i) {
26539+ struct kvm_cpuid_entry2 cpuid_entry;
26540+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26541+ goto out;
26542+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26543+ }
26544 vcpu->arch.cpuid_nent = cpuid->nent;
26545 kvm_apic_set_version(vcpu);
26546 kvm_x86_ops->cpuid_update(vcpu);
26547@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26548 struct kvm_cpuid2 *cpuid,
26549 struct kvm_cpuid_entry2 __user *entries)
26550 {
26551- int r;
26552+ int r, i;
26553
26554 r = -E2BIG;
26555 if (cpuid->nent < vcpu->arch.cpuid_nent)
26556 goto out;
26557 r = -EFAULT;
26558- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26559- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26560+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26561 goto out;
26562+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26563+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26564+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26565+ goto out;
26566+ }
26567 return 0;
26568
26569 out:
26570diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26571index afc1124..3e431f2 100644
26572--- a/arch/x86/kvm/lapic.c
26573+++ b/arch/x86/kvm/lapic.c
26574@@ -55,7 +55,7 @@
26575 #define APIC_BUS_CYCLE_NS 1
26576
26577 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26578-#define apic_debug(fmt, arg...)
26579+#define apic_debug(fmt, arg...) do {} while (0)
26580
26581 #define APIC_LVT_NUM 6
26582 /* 14 is the version for Xeon and Pentium 8.4.8*/
26583diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26584index 7769699..c8aca4a7f 100644
26585--- a/arch/x86/kvm/paging_tmpl.h
26586+++ b/arch/x86/kvm/paging_tmpl.h
26587@@ -208,7 +208,7 @@ retry_walk:
26588 if (unlikely(kvm_is_error_hva(host_addr)))
26589 goto error;
26590
26591- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26592+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26593 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26594 goto error;
26595 walker->ptep_user[walker->level - 1] = ptep_user;
26596diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26597index c0bc803..6837a50 100644
26598--- a/arch/x86/kvm/svm.c
26599+++ b/arch/x86/kvm/svm.c
26600@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26601 int cpu = raw_smp_processor_id();
26602
26603 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26604+
26605+ pax_open_kernel();
26606 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26607+ pax_close_kernel();
26608+
26609 load_TR_desc();
26610 }
26611
26612@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26613 #endif
26614 #endif
26615
26616+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26617+ __set_fs(current_thread_info()->addr_limit);
26618+#endif
26619+
26620 reload_tss(vcpu);
26621
26622 local_irq_disable();
26623diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26624index 064d0be..f5f758e 100644
26625--- a/arch/x86/kvm/vmx.c
26626+++ b/arch/x86/kvm/vmx.c
26627@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26628 #endif
26629 }
26630
26631-static void vmcs_clear_bits(unsigned long field, u32 mask)
26632+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26633 {
26634 vmcs_writel(field, vmcs_readl(field) & ~mask);
26635 }
26636
26637-static void vmcs_set_bits(unsigned long field, u32 mask)
26638+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26639 {
26640 vmcs_writel(field, vmcs_readl(field) | mask);
26641 }
26642@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26643 struct desc_struct *descs;
26644
26645 descs = (void *)gdt->address;
26646+
26647+ pax_open_kernel();
26648 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26649+ pax_close_kernel();
26650+
26651 load_TR_desc();
26652 }
26653
26654@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26655 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26656 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26657
26658+#ifdef CONFIG_PAX_PER_CPU_PGD
26659+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26660+#endif
26661+
26662 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26663 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26664 vmx->loaded_vmcs->cpu = cpu;
26665@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26666 if (!cpu_has_vmx_flexpriority())
26667 flexpriority_enabled = 0;
26668
26669- if (!cpu_has_vmx_tpr_shadow())
26670- kvm_x86_ops->update_cr8_intercept = NULL;
26671+ if (!cpu_has_vmx_tpr_shadow()) {
26672+ pax_open_kernel();
26673+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26674+ pax_close_kernel();
26675+ }
26676
26677 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26678 kvm_disable_largepages();
26679@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26680 if (!cpu_has_vmx_apicv())
26681 enable_apicv = 0;
26682
26683+ pax_open_kernel();
26684 if (enable_apicv)
26685- kvm_x86_ops->update_cr8_intercept = NULL;
26686+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26687 else {
26688- kvm_x86_ops->hwapic_irr_update = NULL;
26689- kvm_x86_ops->deliver_posted_interrupt = NULL;
26690- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26691+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26692+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26693+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26694 }
26695+ pax_close_kernel();
26696
26697 if (nested)
26698 nested_vmx_setup_ctls_msrs();
26699@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26700
26701 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26702 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26703+
26704+#ifndef CONFIG_PAX_PER_CPU_PGD
26705 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26706+#endif
26707
26708 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26709 #ifdef CONFIG_X86_64
26710@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26711 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26712 vmx->host_idt_base = dt.address;
26713
26714- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26715+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26716
26717 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26718 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26719@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26720 "jmp 2f \n\t"
26721 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26722 "2: "
26723+
26724+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26725+ "ljmp %[cs],$3f\n\t"
26726+ "3: "
26727+#endif
26728+
26729 /* Save guest registers, load host registers, keep flags */
26730 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26731 "pop %0 \n\t"
26732@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26733 #endif
26734 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26735 [wordsize]"i"(sizeof(ulong))
26736+
26737+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26738+ ,[cs]"i"(__KERNEL_CS)
26739+#endif
26740+
26741 : "cc", "memory"
26742 #ifdef CONFIG_X86_64
26743 , "rax", "rbx", "rdi", "rsi"
26744@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26745 if (debugctlmsr)
26746 update_debugctlmsr(debugctlmsr);
26747
26748-#ifndef CONFIG_X86_64
26749+#ifdef CONFIG_X86_32
26750 /*
26751 * The sysexit path does not restore ds/es, so we must set them to
26752 * a reasonable value ourselves.
26753@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26754 * may be executed in interrupt context, which saves and restore segments
26755 * around it, nullifying its effect.
26756 */
26757- loadsegment(ds, __USER_DS);
26758- loadsegment(es, __USER_DS);
26759+ loadsegment(ds, __KERNEL_DS);
26760+ loadsegment(es, __KERNEL_DS);
26761+ loadsegment(ss, __KERNEL_DS);
26762+
26763+#ifdef CONFIG_PAX_KERNEXEC
26764+ loadsegment(fs, __KERNEL_PERCPU);
26765+#endif
26766+
26767+#ifdef CONFIG_PAX_MEMORY_UDEREF
26768+ __set_fs(current_thread_info()->addr_limit);
26769+#endif
26770+
26771 #endif
26772
26773 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26774diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26775index d21bce5..fdae9f1 100644
26776--- a/arch/x86/kvm/x86.c
26777+++ b/arch/x86/kvm/x86.c
26778@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26779 {
26780 struct kvm *kvm = vcpu->kvm;
26781 int lm = is_long_mode(vcpu);
26782- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26783- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26784+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26785+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26786 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26787 : kvm->arch.xen_hvm_config.blob_size_32;
26788 u32 page_num = data & ~PAGE_MASK;
26789@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26790 if (n < msr_list.nmsrs)
26791 goto out;
26792 r = -EFAULT;
26793+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26794+ goto out;
26795 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26796 num_msrs_to_save * sizeof(u32)))
26797 goto out;
26798@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26799 };
26800 #endif
26801
26802-int kvm_arch_init(void *opaque)
26803+int kvm_arch_init(const void *opaque)
26804 {
26805 int r;
26806 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26807diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26808index 6a22c19..1763f04 100644
26809--- a/arch/x86/lguest/boot.c
26810+++ b/arch/x86/lguest/boot.c
26811@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26812 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26813 * Launcher to reboot us.
26814 */
26815-static void lguest_restart(char *reason)
26816+static __noreturn void lguest_restart(char *reason)
26817 {
26818 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26819+ BUG();
26820 }
26821
26822 /*G:050
26823diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26824index 00933d5..3a64af9 100644
26825--- a/arch/x86/lib/atomic64_386_32.S
26826+++ b/arch/x86/lib/atomic64_386_32.S
26827@@ -48,6 +48,10 @@ BEGIN(read)
26828 movl (v), %eax
26829 movl 4(v), %edx
26830 RET_ENDP
26831+BEGIN(read_unchecked)
26832+ movl (v), %eax
26833+ movl 4(v), %edx
26834+RET_ENDP
26835 #undef v
26836
26837 #define v %esi
26838@@ -55,6 +59,10 @@ BEGIN(set)
26839 movl %ebx, (v)
26840 movl %ecx, 4(v)
26841 RET_ENDP
26842+BEGIN(set_unchecked)
26843+ movl %ebx, (v)
26844+ movl %ecx, 4(v)
26845+RET_ENDP
26846 #undef v
26847
26848 #define v %esi
26849@@ -70,6 +78,20 @@ RET_ENDP
26850 BEGIN(add)
26851 addl %eax, (v)
26852 adcl %edx, 4(v)
26853+
26854+#ifdef CONFIG_PAX_REFCOUNT
26855+ jno 0f
26856+ subl %eax, (v)
26857+ sbbl %edx, 4(v)
26858+ int $4
26859+0:
26860+ _ASM_EXTABLE(0b, 0b)
26861+#endif
26862+
26863+RET_ENDP
26864+BEGIN(add_unchecked)
26865+ addl %eax, (v)
26866+ adcl %edx, 4(v)
26867 RET_ENDP
26868 #undef v
26869
26870@@ -77,6 +99,24 @@ RET_ENDP
26871 BEGIN(add_return)
26872 addl (v), %eax
26873 adcl 4(v), %edx
26874+
26875+#ifdef CONFIG_PAX_REFCOUNT
26876+ into
26877+1234:
26878+ _ASM_EXTABLE(1234b, 2f)
26879+#endif
26880+
26881+ movl %eax, (v)
26882+ movl %edx, 4(v)
26883+
26884+#ifdef CONFIG_PAX_REFCOUNT
26885+2:
26886+#endif
26887+
26888+RET_ENDP
26889+BEGIN(add_return_unchecked)
26890+ addl (v), %eax
26891+ adcl 4(v), %edx
26892 movl %eax, (v)
26893 movl %edx, 4(v)
26894 RET_ENDP
26895@@ -86,6 +126,20 @@ RET_ENDP
26896 BEGIN(sub)
26897 subl %eax, (v)
26898 sbbl %edx, 4(v)
26899+
26900+#ifdef CONFIG_PAX_REFCOUNT
26901+ jno 0f
26902+ addl %eax, (v)
26903+ adcl %edx, 4(v)
26904+ int $4
26905+0:
26906+ _ASM_EXTABLE(0b, 0b)
26907+#endif
26908+
26909+RET_ENDP
26910+BEGIN(sub_unchecked)
26911+ subl %eax, (v)
26912+ sbbl %edx, 4(v)
26913 RET_ENDP
26914 #undef v
26915
26916@@ -96,6 +150,27 @@ BEGIN(sub_return)
26917 sbbl $0, %edx
26918 addl (v), %eax
26919 adcl 4(v), %edx
26920+
26921+#ifdef CONFIG_PAX_REFCOUNT
26922+ into
26923+1234:
26924+ _ASM_EXTABLE(1234b, 2f)
26925+#endif
26926+
26927+ movl %eax, (v)
26928+ movl %edx, 4(v)
26929+
26930+#ifdef CONFIG_PAX_REFCOUNT
26931+2:
26932+#endif
26933+
26934+RET_ENDP
26935+BEGIN(sub_return_unchecked)
26936+ negl %edx
26937+ negl %eax
26938+ sbbl $0, %edx
26939+ addl (v), %eax
26940+ adcl 4(v), %edx
26941 movl %eax, (v)
26942 movl %edx, 4(v)
26943 RET_ENDP
26944@@ -105,6 +180,20 @@ RET_ENDP
26945 BEGIN(inc)
26946 addl $1, (v)
26947 adcl $0, 4(v)
26948+
26949+#ifdef CONFIG_PAX_REFCOUNT
26950+ jno 0f
26951+ subl $1, (v)
26952+ sbbl $0, 4(v)
26953+ int $4
26954+0:
26955+ _ASM_EXTABLE(0b, 0b)
26956+#endif
26957+
26958+RET_ENDP
26959+BEGIN(inc_unchecked)
26960+ addl $1, (v)
26961+ adcl $0, 4(v)
26962 RET_ENDP
26963 #undef v
26964
26965@@ -114,6 +203,26 @@ BEGIN(inc_return)
26966 movl 4(v), %edx
26967 addl $1, %eax
26968 adcl $0, %edx
26969+
26970+#ifdef CONFIG_PAX_REFCOUNT
26971+ into
26972+1234:
26973+ _ASM_EXTABLE(1234b, 2f)
26974+#endif
26975+
26976+ movl %eax, (v)
26977+ movl %edx, 4(v)
26978+
26979+#ifdef CONFIG_PAX_REFCOUNT
26980+2:
26981+#endif
26982+
26983+RET_ENDP
26984+BEGIN(inc_return_unchecked)
26985+ movl (v), %eax
26986+ movl 4(v), %edx
26987+ addl $1, %eax
26988+ adcl $0, %edx
26989 movl %eax, (v)
26990 movl %edx, 4(v)
26991 RET_ENDP
26992@@ -123,6 +232,20 @@ RET_ENDP
26993 BEGIN(dec)
26994 subl $1, (v)
26995 sbbl $0, 4(v)
26996+
26997+#ifdef CONFIG_PAX_REFCOUNT
26998+ jno 0f
26999+ addl $1, (v)
27000+ adcl $0, 4(v)
27001+ int $4
27002+0:
27003+ _ASM_EXTABLE(0b, 0b)
27004+#endif
27005+
27006+RET_ENDP
27007+BEGIN(dec_unchecked)
27008+ subl $1, (v)
27009+ sbbl $0, 4(v)
27010 RET_ENDP
27011 #undef v
27012
27013@@ -132,6 +255,26 @@ BEGIN(dec_return)
27014 movl 4(v), %edx
27015 subl $1, %eax
27016 sbbl $0, %edx
27017+
27018+#ifdef CONFIG_PAX_REFCOUNT
27019+ into
27020+1234:
27021+ _ASM_EXTABLE(1234b, 2f)
27022+#endif
27023+
27024+ movl %eax, (v)
27025+ movl %edx, 4(v)
27026+
27027+#ifdef CONFIG_PAX_REFCOUNT
27028+2:
27029+#endif
27030+
27031+RET_ENDP
27032+BEGIN(dec_return_unchecked)
27033+ movl (v), %eax
27034+ movl 4(v), %edx
27035+ subl $1, %eax
27036+ sbbl $0, %edx
27037 movl %eax, (v)
27038 movl %edx, 4(v)
27039 RET_ENDP
27040@@ -143,6 +286,13 @@ BEGIN(add_unless)
27041 adcl %edx, %edi
27042 addl (v), %eax
27043 adcl 4(v), %edx
27044+
27045+#ifdef CONFIG_PAX_REFCOUNT
27046+ into
27047+1234:
27048+ _ASM_EXTABLE(1234b, 2f)
27049+#endif
27050+
27051 cmpl %eax, %ecx
27052 je 3f
27053 1:
27054@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27055 1:
27056 addl $1, %eax
27057 adcl $0, %edx
27058+
27059+#ifdef CONFIG_PAX_REFCOUNT
27060+ into
27061+1234:
27062+ _ASM_EXTABLE(1234b, 2f)
27063+#endif
27064+
27065 movl %eax, (v)
27066 movl %edx, 4(v)
27067 movl $1, %eax
27068@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27069 movl 4(v), %edx
27070 subl $1, %eax
27071 sbbl $0, %edx
27072+
27073+#ifdef CONFIG_PAX_REFCOUNT
27074+ into
27075+1234:
27076+ _ASM_EXTABLE(1234b, 1f)
27077+#endif
27078+
27079 js 1f
27080 movl %eax, (v)
27081 movl %edx, 4(v)
27082diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27083index f5cc9eb..51fa319 100644
27084--- a/arch/x86/lib/atomic64_cx8_32.S
27085+++ b/arch/x86/lib/atomic64_cx8_32.S
27086@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27087 CFI_STARTPROC
27088
27089 read64 %ecx
27090+ pax_force_retaddr
27091 ret
27092 CFI_ENDPROC
27093 ENDPROC(atomic64_read_cx8)
27094
27095+ENTRY(atomic64_read_unchecked_cx8)
27096+ CFI_STARTPROC
27097+
27098+ read64 %ecx
27099+ pax_force_retaddr
27100+ ret
27101+ CFI_ENDPROC
27102+ENDPROC(atomic64_read_unchecked_cx8)
27103+
27104 ENTRY(atomic64_set_cx8)
27105 CFI_STARTPROC
27106
27107@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27108 cmpxchg8b (%esi)
27109 jne 1b
27110
27111+ pax_force_retaddr
27112 ret
27113 CFI_ENDPROC
27114 ENDPROC(atomic64_set_cx8)
27115
27116+ENTRY(atomic64_set_unchecked_cx8)
27117+ CFI_STARTPROC
27118+
27119+1:
27120+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27121+ * are atomic on 586 and newer */
27122+ cmpxchg8b (%esi)
27123+ jne 1b
27124+
27125+ pax_force_retaddr
27126+ ret
27127+ CFI_ENDPROC
27128+ENDPROC(atomic64_set_unchecked_cx8)
27129+
27130 ENTRY(atomic64_xchg_cx8)
27131 CFI_STARTPROC
27132
27133@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27134 cmpxchg8b (%esi)
27135 jne 1b
27136
27137+ pax_force_retaddr
27138 ret
27139 CFI_ENDPROC
27140 ENDPROC(atomic64_xchg_cx8)
27141
27142-.macro addsub_return func ins insc
27143-ENTRY(atomic64_\func\()_return_cx8)
27144+.macro addsub_return func ins insc unchecked=""
27145+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27146 CFI_STARTPROC
27147 SAVE ebp
27148 SAVE ebx
27149@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27150 movl %edx, %ecx
27151 \ins\()l %esi, %ebx
27152 \insc\()l %edi, %ecx
27153+
27154+.ifb \unchecked
27155+#ifdef CONFIG_PAX_REFCOUNT
27156+ into
27157+2:
27158+ _ASM_EXTABLE(2b, 3f)
27159+#endif
27160+.endif
27161+
27162 LOCK_PREFIX
27163 cmpxchg8b (%ebp)
27164 jne 1b
27165-
27166-10:
27167 movl %ebx, %eax
27168 movl %ecx, %edx
27169+
27170+.ifb \unchecked
27171+#ifdef CONFIG_PAX_REFCOUNT
27172+3:
27173+#endif
27174+.endif
27175+
27176 RESTORE edi
27177 RESTORE esi
27178 RESTORE ebx
27179 RESTORE ebp
27180+ pax_force_retaddr
27181 ret
27182 CFI_ENDPROC
27183-ENDPROC(atomic64_\func\()_return_cx8)
27184+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27185 .endm
27186
27187 addsub_return add add adc
27188 addsub_return sub sub sbb
27189+addsub_return add add adc _unchecked
27190+addsub_return sub sub sbb _unchecked
27191
27192-.macro incdec_return func ins insc
27193-ENTRY(atomic64_\func\()_return_cx8)
27194+.macro incdec_return func ins insc unchecked=""
27195+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27196 CFI_STARTPROC
27197 SAVE ebx
27198
27199@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27200 movl %edx, %ecx
27201 \ins\()l $1, %ebx
27202 \insc\()l $0, %ecx
27203+
27204+.ifb \unchecked
27205+#ifdef CONFIG_PAX_REFCOUNT
27206+ into
27207+2:
27208+ _ASM_EXTABLE(2b, 3f)
27209+#endif
27210+.endif
27211+
27212 LOCK_PREFIX
27213 cmpxchg8b (%esi)
27214 jne 1b
27215
27216-10:
27217 movl %ebx, %eax
27218 movl %ecx, %edx
27219+
27220+.ifb \unchecked
27221+#ifdef CONFIG_PAX_REFCOUNT
27222+3:
27223+#endif
27224+.endif
27225+
27226 RESTORE ebx
27227+ pax_force_retaddr
27228 ret
27229 CFI_ENDPROC
27230-ENDPROC(atomic64_\func\()_return_cx8)
27231+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27232 .endm
27233
27234 incdec_return inc add adc
27235 incdec_return dec sub sbb
27236+incdec_return inc add adc _unchecked
27237+incdec_return dec sub sbb _unchecked
27238
27239 ENTRY(atomic64_dec_if_positive_cx8)
27240 CFI_STARTPROC
27241@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27242 movl %edx, %ecx
27243 subl $1, %ebx
27244 sbb $0, %ecx
27245+
27246+#ifdef CONFIG_PAX_REFCOUNT
27247+ into
27248+1234:
27249+ _ASM_EXTABLE(1234b, 2f)
27250+#endif
27251+
27252 js 2f
27253 LOCK_PREFIX
27254 cmpxchg8b (%esi)
27255@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27256 movl %ebx, %eax
27257 movl %ecx, %edx
27258 RESTORE ebx
27259+ pax_force_retaddr
27260 ret
27261 CFI_ENDPROC
27262 ENDPROC(atomic64_dec_if_positive_cx8)
27263@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27264 movl %edx, %ecx
27265 addl %ebp, %ebx
27266 adcl %edi, %ecx
27267+
27268+#ifdef CONFIG_PAX_REFCOUNT
27269+ into
27270+1234:
27271+ _ASM_EXTABLE(1234b, 3f)
27272+#endif
27273+
27274 LOCK_PREFIX
27275 cmpxchg8b (%esi)
27276 jne 1b
27277@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27278 CFI_ADJUST_CFA_OFFSET -8
27279 RESTORE ebx
27280 RESTORE ebp
27281+ pax_force_retaddr
27282 ret
27283 4:
27284 cmpl %edx, 4(%esp)
27285@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27286 xorl %ecx, %ecx
27287 addl $1, %ebx
27288 adcl %edx, %ecx
27289+
27290+#ifdef CONFIG_PAX_REFCOUNT
27291+ into
27292+1234:
27293+ _ASM_EXTABLE(1234b, 3f)
27294+#endif
27295+
27296 LOCK_PREFIX
27297 cmpxchg8b (%esi)
27298 jne 1b
27299@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27300 movl $1, %eax
27301 3:
27302 RESTORE ebx
27303+ pax_force_retaddr
27304 ret
27305 CFI_ENDPROC
27306 ENDPROC(atomic64_inc_not_zero_cx8)
27307diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27308index e78b8ee..7e173a8 100644
27309--- a/arch/x86/lib/checksum_32.S
27310+++ b/arch/x86/lib/checksum_32.S
27311@@ -29,7 +29,8 @@
27312 #include <asm/dwarf2.h>
27313 #include <asm/errno.h>
27314 #include <asm/asm.h>
27315-
27316+#include <asm/segment.h>
27317+
27318 /*
27319 * computes a partial checksum, e.g. for TCP/UDP fragments
27320 */
27321@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27322
27323 #define ARGBASE 16
27324 #define FP 12
27325-
27326-ENTRY(csum_partial_copy_generic)
27327+
27328+ENTRY(csum_partial_copy_generic_to_user)
27329 CFI_STARTPROC
27330+
27331+#ifdef CONFIG_PAX_MEMORY_UDEREF
27332+ pushl_cfi %gs
27333+ popl_cfi %es
27334+ jmp csum_partial_copy_generic
27335+#endif
27336+
27337+ENTRY(csum_partial_copy_generic_from_user)
27338+
27339+#ifdef CONFIG_PAX_MEMORY_UDEREF
27340+ pushl_cfi %gs
27341+ popl_cfi %ds
27342+#endif
27343+
27344+ENTRY(csum_partial_copy_generic)
27345 subl $4,%esp
27346 CFI_ADJUST_CFA_OFFSET 4
27347 pushl_cfi %edi
27348@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27349 jmp 4f
27350 SRC(1: movw (%esi), %bx )
27351 addl $2, %esi
27352-DST( movw %bx, (%edi) )
27353+DST( movw %bx, %es:(%edi) )
27354 addl $2, %edi
27355 addw %bx, %ax
27356 adcl $0, %eax
27357@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27358 SRC(1: movl (%esi), %ebx )
27359 SRC( movl 4(%esi), %edx )
27360 adcl %ebx, %eax
27361-DST( movl %ebx, (%edi) )
27362+DST( movl %ebx, %es:(%edi) )
27363 adcl %edx, %eax
27364-DST( movl %edx, 4(%edi) )
27365+DST( movl %edx, %es:4(%edi) )
27366
27367 SRC( movl 8(%esi), %ebx )
27368 SRC( movl 12(%esi), %edx )
27369 adcl %ebx, %eax
27370-DST( movl %ebx, 8(%edi) )
27371+DST( movl %ebx, %es:8(%edi) )
27372 adcl %edx, %eax
27373-DST( movl %edx, 12(%edi) )
27374+DST( movl %edx, %es:12(%edi) )
27375
27376 SRC( movl 16(%esi), %ebx )
27377 SRC( movl 20(%esi), %edx )
27378 adcl %ebx, %eax
27379-DST( movl %ebx, 16(%edi) )
27380+DST( movl %ebx, %es:16(%edi) )
27381 adcl %edx, %eax
27382-DST( movl %edx, 20(%edi) )
27383+DST( movl %edx, %es:20(%edi) )
27384
27385 SRC( movl 24(%esi), %ebx )
27386 SRC( movl 28(%esi), %edx )
27387 adcl %ebx, %eax
27388-DST( movl %ebx, 24(%edi) )
27389+DST( movl %ebx, %es:24(%edi) )
27390 adcl %edx, %eax
27391-DST( movl %edx, 28(%edi) )
27392+DST( movl %edx, %es:28(%edi) )
27393
27394 lea 32(%esi), %esi
27395 lea 32(%edi), %edi
27396@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27397 shrl $2, %edx # This clears CF
27398 SRC(3: movl (%esi), %ebx )
27399 adcl %ebx, %eax
27400-DST( movl %ebx, (%edi) )
27401+DST( movl %ebx, %es:(%edi) )
27402 lea 4(%esi), %esi
27403 lea 4(%edi), %edi
27404 dec %edx
27405@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27406 jb 5f
27407 SRC( movw (%esi), %cx )
27408 leal 2(%esi), %esi
27409-DST( movw %cx, (%edi) )
27410+DST( movw %cx, %es:(%edi) )
27411 leal 2(%edi), %edi
27412 je 6f
27413 shll $16,%ecx
27414 SRC(5: movb (%esi), %cl )
27415-DST( movb %cl, (%edi) )
27416+DST( movb %cl, %es:(%edi) )
27417 6: addl %ecx, %eax
27418 adcl $0, %eax
27419 7:
27420@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27421
27422 6001:
27423 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27424- movl $-EFAULT, (%ebx)
27425+ movl $-EFAULT, %ss:(%ebx)
27426
27427 # zero the complete destination - computing the rest
27428 # is too much work
27429@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27430
27431 6002:
27432 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27433- movl $-EFAULT,(%ebx)
27434+ movl $-EFAULT,%ss:(%ebx)
27435 jmp 5000b
27436
27437 .previous
27438
27439+ pushl_cfi %ss
27440+ popl_cfi %ds
27441+ pushl_cfi %ss
27442+ popl_cfi %es
27443 popl_cfi %ebx
27444 CFI_RESTORE ebx
27445 popl_cfi %esi
27446@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27447 popl_cfi %ecx # equivalent to addl $4,%esp
27448 ret
27449 CFI_ENDPROC
27450-ENDPROC(csum_partial_copy_generic)
27451+ENDPROC(csum_partial_copy_generic_to_user)
27452
27453 #else
27454
27455 /* Version for PentiumII/PPro */
27456
27457 #define ROUND1(x) \
27458+ nop; nop; nop; \
27459 SRC(movl x(%esi), %ebx ) ; \
27460 addl %ebx, %eax ; \
27461- DST(movl %ebx, x(%edi) ) ;
27462+ DST(movl %ebx, %es:x(%edi)) ;
27463
27464 #define ROUND(x) \
27465+ nop; nop; nop; \
27466 SRC(movl x(%esi), %ebx ) ; \
27467 adcl %ebx, %eax ; \
27468- DST(movl %ebx, x(%edi) ) ;
27469+ DST(movl %ebx, %es:x(%edi)) ;
27470
27471 #define ARGBASE 12
27472-
27473-ENTRY(csum_partial_copy_generic)
27474+
27475+ENTRY(csum_partial_copy_generic_to_user)
27476 CFI_STARTPROC
27477+
27478+#ifdef CONFIG_PAX_MEMORY_UDEREF
27479+ pushl_cfi %gs
27480+ popl_cfi %es
27481+ jmp csum_partial_copy_generic
27482+#endif
27483+
27484+ENTRY(csum_partial_copy_generic_from_user)
27485+
27486+#ifdef CONFIG_PAX_MEMORY_UDEREF
27487+ pushl_cfi %gs
27488+ popl_cfi %ds
27489+#endif
27490+
27491+ENTRY(csum_partial_copy_generic)
27492 pushl_cfi %ebx
27493 CFI_REL_OFFSET ebx, 0
27494 pushl_cfi %edi
27495@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27496 subl %ebx, %edi
27497 lea -1(%esi),%edx
27498 andl $-32,%edx
27499- lea 3f(%ebx,%ebx), %ebx
27500+ lea 3f(%ebx,%ebx,2), %ebx
27501 testl %esi, %esi
27502 jmp *%ebx
27503 1: addl $64,%esi
27504@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27505 jb 5f
27506 SRC( movw (%esi), %dx )
27507 leal 2(%esi), %esi
27508-DST( movw %dx, (%edi) )
27509+DST( movw %dx, %es:(%edi) )
27510 leal 2(%edi), %edi
27511 je 6f
27512 shll $16,%edx
27513 5:
27514 SRC( movb (%esi), %dl )
27515-DST( movb %dl, (%edi) )
27516+DST( movb %dl, %es:(%edi) )
27517 6: addl %edx, %eax
27518 adcl $0, %eax
27519 7:
27520 .section .fixup, "ax"
27521 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27522- movl $-EFAULT, (%ebx)
27523+ movl $-EFAULT, %ss:(%ebx)
27524 # zero the complete destination (computing the rest is too much work)
27525 movl ARGBASE+8(%esp),%edi # dst
27526 movl ARGBASE+12(%esp),%ecx # len
27527@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27528 rep; stosb
27529 jmp 7b
27530 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27531- movl $-EFAULT, (%ebx)
27532+ movl $-EFAULT, %ss:(%ebx)
27533 jmp 7b
27534 .previous
27535
27536+#ifdef CONFIG_PAX_MEMORY_UDEREF
27537+ pushl_cfi %ss
27538+ popl_cfi %ds
27539+ pushl_cfi %ss
27540+ popl_cfi %es
27541+#endif
27542+
27543 popl_cfi %esi
27544 CFI_RESTORE esi
27545 popl_cfi %edi
27546@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27547 CFI_RESTORE ebx
27548 ret
27549 CFI_ENDPROC
27550-ENDPROC(csum_partial_copy_generic)
27551+ENDPROC(csum_partial_copy_generic_to_user)
27552
27553 #undef ROUND
27554 #undef ROUND1
27555diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27556index f2145cf..cea889d 100644
27557--- a/arch/x86/lib/clear_page_64.S
27558+++ b/arch/x86/lib/clear_page_64.S
27559@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27560 movl $4096/8,%ecx
27561 xorl %eax,%eax
27562 rep stosq
27563+ pax_force_retaddr
27564 ret
27565 CFI_ENDPROC
27566 ENDPROC(clear_page_c)
27567@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27568 movl $4096,%ecx
27569 xorl %eax,%eax
27570 rep stosb
27571+ pax_force_retaddr
27572 ret
27573 CFI_ENDPROC
27574 ENDPROC(clear_page_c_e)
27575@@ -43,6 +45,7 @@ ENTRY(clear_page)
27576 leaq 64(%rdi),%rdi
27577 jnz .Lloop
27578 nop
27579+ pax_force_retaddr
27580 ret
27581 CFI_ENDPROC
27582 .Lclear_page_end:
27583@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27584
27585 #include <asm/cpufeature.h>
27586
27587- .section .altinstr_replacement,"ax"
27588+ .section .altinstr_replacement,"a"
27589 1: .byte 0xeb /* jmp <disp8> */
27590 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27591 2: .byte 0xeb /* jmp <disp8> */
27592diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27593index 1e572c5..2a162cd 100644
27594--- a/arch/x86/lib/cmpxchg16b_emu.S
27595+++ b/arch/x86/lib/cmpxchg16b_emu.S
27596@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27597
27598 popf
27599 mov $1, %al
27600+ pax_force_retaddr
27601 ret
27602
27603 not_same:
27604 popf
27605 xor %al,%al
27606+ pax_force_retaddr
27607 ret
27608
27609 CFI_ENDPROC
27610diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27611index 176cca6..1166c50 100644
27612--- a/arch/x86/lib/copy_page_64.S
27613+++ b/arch/x86/lib/copy_page_64.S
27614@@ -9,6 +9,7 @@ copy_page_rep:
27615 CFI_STARTPROC
27616 movl $4096/8, %ecx
27617 rep movsq
27618+ pax_force_retaddr
27619 ret
27620 CFI_ENDPROC
27621 ENDPROC(copy_page_rep)
27622@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27623
27624 ENTRY(copy_page)
27625 CFI_STARTPROC
27626- subq $2*8, %rsp
27627- CFI_ADJUST_CFA_OFFSET 2*8
27628+ subq $3*8, %rsp
27629+ CFI_ADJUST_CFA_OFFSET 3*8
27630 movq %rbx, (%rsp)
27631 CFI_REL_OFFSET rbx, 0
27632 movq %r12, 1*8(%rsp)
27633 CFI_REL_OFFSET r12, 1*8
27634+ movq %r13, 2*8(%rsp)
27635+ CFI_REL_OFFSET r13, 2*8
27636
27637 movl $(4096/64)-5, %ecx
27638 .p2align 4
27639@@ -36,7 +39,7 @@ ENTRY(copy_page)
27640 movq 0x8*2(%rsi), %rdx
27641 movq 0x8*3(%rsi), %r8
27642 movq 0x8*4(%rsi), %r9
27643- movq 0x8*5(%rsi), %r10
27644+ movq 0x8*5(%rsi), %r13
27645 movq 0x8*6(%rsi), %r11
27646 movq 0x8*7(%rsi), %r12
27647
27648@@ -47,7 +50,7 @@ ENTRY(copy_page)
27649 movq %rdx, 0x8*2(%rdi)
27650 movq %r8, 0x8*3(%rdi)
27651 movq %r9, 0x8*4(%rdi)
27652- movq %r10, 0x8*5(%rdi)
27653+ movq %r13, 0x8*5(%rdi)
27654 movq %r11, 0x8*6(%rdi)
27655 movq %r12, 0x8*7(%rdi)
27656
27657@@ -66,7 +69,7 @@ ENTRY(copy_page)
27658 movq 0x8*2(%rsi), %rdx
27659 movq 0x8*3(%rsi), %r8
27660 movq 0x8*4(%rsi), %r9
27661- movq 0x8*5(%rsi), %r10
27662+ movq 0x8*5(%rsi), %r13
27663 movq 0x8*6(%rsi), %r11
27664 movq 0x8*7(%rsi), %r12
27665
27666@@ -75,7 +78,7 @@ ENTRY(copy_page)
27667 movq %rdx, 0x8*2(%rdi)
27668 movq %r8, 0x8*3(%rdi)
27669 movq %r9, 0x8*4(%rdi)
27670- movq %r10, 0x8*5(%rdi)
27671+ movq %r13, 0x8*5(%rdi)
27672 movq %r11, 0x8*6(%rdi)
27673 movq %r12, 0x8*7(%rdi)
27674
27675@@ -87,8 +90,11 @@ ENTRY(copy_page)
27676 CFI_RESTORE rbx
27677 movq 1*8(%rsp), %r12
27678 CFI_RESTORE r12
27679- addq $2*8, %rsp
27680- CFI_ADJUST_CFA_OFFSET -2*8
27681+ movq 2*8(%rsp), %r13
27682+ CFI_RESTORE r13
27683+ addq $3*8, %rsp
27684+ CFI_ADJUST_CFA_OFFSET -3*8
27685+ pax_force_retaddr
27686 ret
27687 .Lcopy_page_end:
27688 CFI_ENDPROC
27689@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27690
27691 #include <asm/cpufeature.h>
27692
27693- .section .altinstr_replacement,"ax"
27694+ .section .altinstr_replacement,"a"
27695 1: .byte 0xeb /* jmp <disp8> */
27696 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27697 2:
27698diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27699index a30ca15..6b3f4e1 100644
27700--- a/arch/x86/lib/copy_user_64.S
27701+++ b/arch/x86/lib/copy_user_64.S
27702@@ -18,31 +18,7 @@
27703 #include <asm/alternative-asm.h>
27704 #include <asm/asm.h>
27705 #include <asm/smap.h>
27706-
27707-/*
27708- * By placing feature2 after feature1 in altinstructions section, we logically
27709- * implement:
27710- * If CPU has feature2, jmp to alt2 is used
27711- * else if CPU has feature1, jmp to alt1 is used
27712- * else jmp to orig is used.
27713- */
27714- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27715-0:
27716- .byte 0xe9 /* 32bit jump */
27717- .long \orig-1f /* by default jump to orig */
27718-1:
27719- .section .altinstr_replacement,"ax"
27720-2: .byte 0xe9 /* near jump with 32bit immediate */
27721- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27722-3: .byte 0xe9 /* near jump with 32bit immediate */
27723- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27724- .previous
27725-
27726- .section .altinstructions,"a"
27727- altinstruction_entry 0b,2b,\feature1,5,5
27728- altinstruction_entry 0b,3b,\feature2,5,5
27729- .previous
27730- .endm
27731+#include <asm/pgtable.h>
27732
27733 .macro ALIGN_DESTINATION
27734 #ifdef FIX_ALIGNMENT
27735@@ -70,52 +46,6 @@
27736 #endif
27737 .endm
27738
27739-/* Standard copy_to_user with segment limit checking */
27740-ENTRY(_copy_to_user)
27741- CFI_STARTPROC
27742- GET_THREAD_INFO(%rax)
27743- movq %rdi,%rcx
27744- addq %rdx,%rcx
27745- jc bad_to_user
27746- cmpq TI_addr_limit(%rax),%rcx
27747- ja bad_to_user
27748- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27749- copy_user_generic_unrolled,copy_user_generic_string, \
27750- copy_user_enhanced_fast_string
27751- CFI_ENDPROC
27752-ENDPROC(_copy_to_user)
27753-
27754-/* Standard copy_from_user with segment limit checking */
27755-ENTRY(_copy_from_user)
27756- CFI_STARTPROC
27757- GET_THREAD_INFO(%rax)
27758- movq %rsi,%rcx
27759- addq %rdx,%rcx
27760- jc bad_from_user
27761- cmpq TI_addr_limit(%rax),%rcx
27762- ja bad_from_user
27763- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27764- copy_user_generic_unrolled,copy_user_generic_string, \
27765- copy_user_enhanced_fast_string
27766- CFI_ENDPROC
27767-ENDPROC(_copy_from_user)
27768-
27769- .section .fixup,"ax"
27770- /* must zero dest */
27771-ENTRY(bad_from_user)
27772-bad_from_user:
27773- CFI_STARTPROC
27774- movl %edx,%ecx
27775- xorl %eax,%eax
27776- rep
27777- stosb
27778-bad_to_user:
27779- movl %edx,%eax
27780- ret
27781- CFI_ENDPROC
27782-ENDPROC(bad_from_user)
27783- .previous
27784-
27785 /*
27786 * copy_user_generic_unrolled - memory copy with exception handling.
27787 * This version is for CPUs like P4 that don't have efficient micro
27788@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27789 */
27790 ENTRY(copy_user_generic_unrolled)
27791 CFI_STARTPROC
27792+ ASM_PAX_OPEN_USERLAND
27793 ASM_STAC
27794 cmpl $8,%edx
27795 jb 20f /* less then 8 bytes, go to byte copy loop */
27796@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27797 jz 17f
27798 1: movq (%rsi),%r8
27799 2: movq 1*8(%rsi),%r9
27800-3: movq 2*8(%rsi),%r10
27801+3: movq 2*8(%rsi),%rax
27802 4: movq 3*8(%rsi),%r11
27803 5: movq %r8,(%rdi)
27804 6: movq %r9,1*8(%rdi)
27805-7: movq %r10,2*8(%rdi)
27806+7: movq %rax,2*8(%rdi)
27807 8: movq %r11,3*8(%rdi)
27808 9: movq 4*8(%rsi),%r8
27809 10: movq 5*8(%rsi),%r9
27810-11: movq 6*8(%rsi),%r10
27811+11: movq 6*8(%rsi),%rax
27812 12: movq 7*8(%rsi),%r11
27813 13: movq %r8,4*8(%rdi)
27814 14: movq %r9,5*8(%rdi)
27815-15: movq %r10,6*8(%rdi)
27816+15: movq %rax,6*8(%rdi)
27817 16: movq %r11,7*8(%rdi)
27818 leaq 64(%rsi),%rsi
27819 leaq 64(%rdi),%rdi
27820@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27821 jnz 21b
27822 23: xor %eax,%eax
27823 ASM_CLAC
27824+ ASM_PAX_CLOSE_USERLAND
27825+ pax_force_retaddr
27826 ret
27827
27828 .section .fixup,"ax"
27829@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27830 */
27831 ENTRY(copy_user_generic_string)
27832 CFI_STARTPROC
27833+ ASM_PAX_OPEN_USERLAND
27834 ASM_STAC
27835 andl %edx,%edx
27836 jz 4f
27837@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27838 movsb
27839 4: xorl %eax,%eax
27840 ASM_CLAC
27841+ ASM_PAX_CLOSE_USERLAND
27842+ pax_force_retaddr
27843 ret
27844
27845 .section .fixup,"ax"
27846@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27847 */
27848 ENTRY(copy_user_enhanced_fast_string)
27849 CFI_STARTPROC
27850+ ASM_PAX_OPEN_USERLAND
27851 ASM_STAC
27852 andl %edx,%edx
27853 jz 2f
27854@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27855 movsb
27856 2: xorl %eax,%eax
27857 ASM_CLAC
27858+ ASM_PAX_CLOSE_USERLAND
27859+ pax_force_retaddr
27860 ret
27861
27862 .section .fixup,"ax"
27863diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27864index 6a4f43c..55d26f2 100644
27865--- a/arch/x86/lib/copy_user_nocache_64.S
27866+++ b/arch/x86/lib/copy_user_nocache_64.S
27867@@ -8,6 +8,7 @@
27868
27869 #include <linux/linkage.h>
27870 #include <asm/dwarf2.h>
27871+#include <asm/alternative-asm.h>
27872
27873 #define FIX_ALIGNMENT 1
27874
27875@@ -16,6 +17,7 @@
27876 #include <asm/thread_info.h>
27877 #include <asm/asm.h>
27878 #include <asm/smap.h>
27879+#include <asm/pgtable.h>
27880
27881 .macro ALIGN_DESTINATION
27882 #ifdef FIX_ALIGNMENT
27883@@ -49,6 +51,16 @@
27884 */
27885 ENTRY(__copy_user_nocache)
27886 CFI_STARTPROC
27887+
27888+#ifdef CONFIG_PAX_MEMORY_UDEREF
27889+ mov pax_user_shadow_base,%rcx
27890+ cmp %rcx,%rsi
27891+ jae 1f
27892+ add %rcx,%rsi
27893+1:
27894+#endif
27895+
27896+ ASM_PAX_OPEN_USERLAND
27897 ASM_STAC
27898 cmpl $8,%edx
27899 jb 20f /* less then 8 bytes, go to byte copy loop */
27900@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27901 jz 17f
27902 1: movq (%rsi),%r8
27903 2: movq 1*8(%rsi),%r9
27904-3: movq 2*8(%rsi),%r10
27905+3: movq 2*8(%rsi),%rax
27906 4: movq 3*8(%rsi),%r11
27907 5: movnti %r8,(%rdi)
27908 6: movnti %r9,1*8(%rdi)
27909-7: movnti %r10,2*8(%rdi)
27910+7: movnti %rax,2*8(%rdi)
27911 8: movnti %r11,3*8(%rdi)
27912 9: movq 4*8(%rsi),%r8
27913 10: movq 5*8(%rsi),%r9
27914-11: movq 6*8(%rsi),%r10
27915+11: movq 6*8(%rsi),%rax
27916 12: movq 7*8(%rsi),%r11
27917 13: movnti %r8,4*8(%rdi)
27918 14: movnti %r9,5*8(%rdi)
27919-15: movnti %r10,6*8(%rdi)
27920+15: movnti %rax,6*8(%rdi)
27921 16: movnti %r11,7*8(%rdi)
27922 leaq 64(%rsi),%rsi
27923 leaq 64(%rdi),%rdi
27924@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27925 jnz 21b
27926 23: xorl %eax,%eax
27927 ASM_CLAC
27928+ ASM_PAX_CLOSE_USERLAND
27929 sfence
27930+ pax_force_retaddr
27931 ret
27932
27933 .section .fixup,"ax"
27934diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27935index 2419d5f..953ee51 100644
27936--- a/arch/x86/lib/csum-copy_64.S
27937+++ b/arch/x86/lib/csum-copy_64.S
27938@@ -9,6 +9,7 @@
27939 #include <asm/dwarf2.h>
27940 #include <asm/errno.h>
27941 #include <asm/asm.h>
27942+#include <asm/alternative-asm.h>
27943
27944 /*
27945 * Checksum copy with exception handling.
27946@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27947 CFI_RESTORE rbp
27948 addq $7*8, %rsp
27949 CFI_ADJUST_CFA_OFFSET -7*8
27950+ pax_force_retaddr 0, 1
27951 ret
27952 CFI_RESTORE_STATE
27953
27954diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27955index 25b7ae8..c40113e 100644
27956--- a/arch/x86/lib/csum-wrappers_64.c
27957+++ b/arch/x86/lib/csum-wrappers_64.c
27958@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27959 len -= 2;
27960 }
27961 }
27962- isum = csum_partial_copy_generic((__force const void *)src,
27963+ pax_open_userland();
27964+ stac();
27965+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27966 dst, len, isum, errp, NULL);
27967+ clac();
27968+ pax_close_userland();
27969 if (unlikely(*errp))
27970 goto out_err;
27971
27972@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27973 }
27974
27975 *errp = 0;
27976- return csum_partial_copy_generic(src, (void __force *)dst,
27977+ pax_open_userland();
27978+ stac();
27979+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27980 len, isum, NULL, errp);
27981+ clac();
27982+ pax_close_userland();
27983+ return isum;
27984 }
27985 EXPORT_SYMBOL(csum_partial_copy_to_user);
27986
27987diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27988index a451235..1daa956 100644
27989--- a/arch/x86/lib/getuser.S
27990+++ b/arch/x86/lib/getuser.S
27991@@ -33,17 +33,40 @@
27992 #include <asm/thread_info.h>
27993 #include <asm/asm.h>
27994 #include <asm/smap.h>
27995+#include <asm/segment.h>
27996+#include <asm/pgtable.h>
27997+#include <asm/alternative-asm.h>
27998+
27999+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28000+#define __copyuser_seg gs;
28001+#else
28002+#define __copyuser_seg
28003+#endif
28004
28005 .text
28006 ENTRY(__get_user_1)
28007 CFI_STARTPROC
28008+
28009+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28010 GET_THREAD_INFO(%_ASM_DX)
28011 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28012 jae bad_get_user
28013 ASM_STAC
28014-1: movzbl (%_ASM_AX),%edx
28015+
28016+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28017+ mov pax_user_shadow_base,%_ASM_DX
28018+ cmp %_ASM_DX,%_ASM_AX
28019+ jae 1234f
28020+ add %_ASM_DX,%_ASM_AX
28021+1234:
28022+#endif
28023+
28024+#endif
28025+
28026+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28027 xor %eax,%eax
28028 ASM_CLAC
28029+ pax_force_retaddr
28030 ret
28031 CFI_ENDPROC
28032 ENDPROC(__get_user_1)
28033@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28034 ENTRY(__get_user_2)
28035 CFI_STARTPROC
28036 add $1,%_ASM_AX
28037+
28038+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28039 jc bad_get_user
28040 GET_THREAD_INFO(%_ASM_DX)
28041 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28042 jae bad_get_user
28043 ASM_STAC
28044-2: movzwl -1(%_ASM_AX),%edx
28045+
28046+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28047+ mov pax_user_shadow_base,%_ASM_DX
28048+ cmp %_ASM_DX,%_ASM_AX
28049+ jae 1234f
28050+ add %_ASM_DX,%_ASM_AX
28051+1234:
28052+#endif
28053+
28054+#endif
28055+
28056+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28057 xor %eax,%eax
28058 ASM_CLAC
28059+ pax_force_retaddr
28060 ret
28061 CFI_ENDPROC
28062 ENDPROC(__get_user_2)
28063@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28064 ENTRY(__get_user_4)
28065 CFI_STARTPROC
28066 add $3,%_ASM_AX
28067+
28068+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28069 jc bad_get_user
28070 GET_THREAD_INFO(%_ASM_DX)
28071 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28072 jae bad_get_user
28073 ASM_STAC
28074-3: movl -3(%_ASM_AX),%edx
28075+
28076+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28077+ mov pax_user_shadow_base,%_ASM_DX
28078+ cmp %_ASM_DX,%_ASM_AX
28079+ jae 1234f
28080+ add %_ASM_DX,%_ASM_AX
28081+1234:
28082+#endif
28083+
28084+#endif
28085+
28086+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28087 xor %eax,%eax
28088 ASM_CLAC
28089+ pax_force_retaddr
28090 ret
28091 CFI_ENDPROC
28092 ENDPROC(__get_user_4)
28093@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28094 GET_THREAD_INFO(%_ASM_DX)
28095 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28096 jae bad_get_user
28097+
28098+#ifdef CONFIG_PAX_MEMORY_UDEREF
28099+ mov pax_user_shadow_base,%_ASM_DX
28100+ cmp %_ASM_DX,%_ASM_AX
28101+ jae 1234f
28102+ add %_ASM_DX,%_ASM_AX
28103+1234:
28104+#endif
28105+
28106 ASM_STAC
28107 4: movq -7(%_ASM_AX),%rdx
28108 xor %eax,%eax
28109 ASM_CLAC
28110+ pax_force_retaddr
28111 ret
28112 #else
28113 add $7,%_ASM_AX
28114@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28115 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28116 jae bad_get_user_8
28117 ASM_STAC
28118-4: movl -7(%_ASM_AX),%edx
28119-5: movl -3(%_ASM_AX),%ecx
28120+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28121+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28122 xor %eax,%eax
28123 ASM_CLAC
28124+ pax_force_retaddr
28125 ret
28126 #endif
28127 CFI_ENDPROC
28128@@ -113,6 +175,7 @@ bad_get_user:
28129 xor %edx,%edx
28130 mov $(-EFAULT),%_ASM_AX
28131 ASM_CLAC
28132+ pax_force_retaddr
28133 ret
28134 CFI_ENDPROC
28135 END(bad_get_user)
28136@@ -124,6 +187,7 @@ bad_get_user_8:
28137 xor %ecx,%ecx
28138 mov $(-EFAULT),%_ASM_AX
28139 ASM_CLAC
28140+ pax_force_retaddr
28141 ret
28142 CFI_ENDPROC
28143 END(bad_get_user_8)
28144diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28145index 54fcffe..7be149e 100644
28146--- a/arch/x86/lib/insn.c
28147+++ b/arch/x86/lib/insn.c
28148@@ -20,8 +20,10 @@
28149
28150 #ifdef __KERNEL__
28151 #include <linux/string.h>
28152+#include <asm/pgtable_types.h>
28153 #else
28154 #include <string.h>
28155+#define ktla_ktva(addr) addr
28156 #endif
28157 #include <asm/inat.h>
28158 #include <asm/insn.h>
28159@@ -53,8 +55,8 @@
28160 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28161 {
28162 memset(insn, 0, sizeof(*insn));
28163- insn->kaddr = kaddr;
28164- insn->next_byte = kaddr;
28165+ insn->kaddr = ktla_ktva(kaddr);
28166+ insn->next_byte = ktla_ktva(kaddr);
28167 insn->x86_64 = x86_64 ? 1 : 0;
28168 insn->opnd_bytes = 4;
28169 if (x86_64)
28170diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28171index 05a95e7..326f2fa 100644
28172--- a/arch/x86/lib/iomap_copy_64.S
28173+++ b/arch/x86/lib/iomap_copy_64.S
28174@@ -17,6 +17,7 @@
28175
28176 #include <linux/linkage.h>
28177 #include <asm/dwarf2.h>
28178+#include <asm/alternative-asm.h>
28179
28180 /*
28181 * override generic version in lib/iomap_copy.c
28182@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28183 CFI_STARTPROC
28184 movl %edx,%ecx
28185 rep movsd
28186+ pax_force_retaddr
28187 ret
28188 CFI_ENDPROC
28189 ENDPROC(__iowrite32_copy)
28190diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28191index 56313a3..9b59269 100644
28192--- a/arch/x86/lib/memcpy_64.S
28193+++ b/arch/x86/lib/memcpy_64.S
28194@@ -24,7 +24,7 @@
28195 * This gets patched over the unrolled variant (below) via the
28196 * alternative instructions framework:
28197 */
28198- .section .altinstr_replacement, "ax", @progbits
28199+ .section .altinstr_replacement, "a", @progbits
28200 .Lmemcpy_c:
28201 movq %rdi, %rax
28202 movq %rdx, %rcx
28203@@ -33,6 +33,7 @@
28204 rep movsq
28205 movl %edx, %ecx
28206 rep movsb
28207+ pax_force_retaddr
28208 ret
28209 .Lmemcpy_e:
28210 .previous
28211@@ -44,11 +45,12 @@
28212 * This gets patched over the unrolled variant (below) via the
28213 * alternative instructions framework:
28214 */
28215- .section .altinstr_replacement, "ax", @progbits
28216+ .section .altinstr_replacement, "a", @progbits
28217 .Lmemcpy_c_e:
28218 movq %rdi, %rax
28219 movq %rdx, %rcx
28220 rep movsb
28221+ pax_force_retaddr
28222 ret
28223 .Lmemcpy_e_e:
28224 .previous
28225@@ -76,13 +78,13 @@ ENTRY(memcpy)
28226 */
28227 movq 0*8(%rsi), %r8
28228 movq 1*8(%rsi), %r9
28229- movq 2*8(%rsi), %r10
28230+ movq 2*8(%rsi), %rcx
28231 movq 3*8(%rsi), %r11
28232 leaq 4*8(%rsi), %rsi
28233
28234 movq %r8, 0*8(%rdi)
28235 movq %r9, 1*8(%rdi)
28236- movq %r10, 2*8(%rdi)
28237+ movq %rcx, 2*8(%rdi)
28238 movq %r11, 3*8(%rdi)
28239 leaq 4*8(%rdi), %rdi
28240 jae .Lcopy_forward_loop
28241@@ -105,12 +107,12 @@ ENTRY(memcpy)
28242 subq $0x20, %rdx
28243 movq -1*8(%rsi), %r8
28244 movq -2*8(%rsi), %r9
28245- movq -3*8(%rsi), %r10
28246+ movq -3*8(%rsi), %rcx
28247 movq -4*8(%rsi), %r11
28248 leaq -4*8(%rsi), %rsi
28249 movq %r8, -1*8(%rdi)
28250 movq %r9, -2*8(%rdi)
28251- movq %r10, -3*8(%rdi)
28252+ movq %rcx, -3*8(%rdi)
28253 movq %r11, -4*8(%rdi)
28254 leaq -4*8(%rdi), %rdi
28255 jae .Lcopy_backward_loop
28256@@ -130,12 +132,13 @@ ENTRY(memcpy)
28257 */
28258 movq 0*8(%rsi), %r8
28259 movq 1*8(%rsi), %r9
28260- movq -2*8(%rsi, %rdx), %r10
28261+ movq -2*8(%rsi, %rdx), %rcx
28262 movq -1*8(%rsi, %rdx), %r11
28263 movq %r8, 0*8(%rdi)
28264 movq %r9, 1*8(%rdi)
28265- movq %r10, -2*8(%rdi, %rdx)
28266+ movq %rcx, -2*8(%rdi, %rdx)
28267 movq %r11, -1*8(%rdi, %rdx)
28268+ pax_force_retaddr
28269 retq
28270 .p2align 4
28271 .Lless_16bytes:
28272@@ -148,6 +151,7 @@ ENTRY(memcpy)
28273 movq -1*8(%rsi, %rdx), %r9
28274 movq %r8, 0*8(%rdi)
28275 movq %r9, -1*8(%rdi, %rdx)
28276+ pax_force_retaddr
28277 retq
28278 .p2align 4
28279 .Lless_8bytes:
28280@@ -161,6 +165,7 @@ ENTRY(memcpy)
28281 movl -4(%rsi, %rdx), %r8d
28282 movl %ecx, (%rdi)
28283 movl %r8d, -4(%rdi, %rdx)
28284+ pax_force_retaddr
28285 retq
28286 .p2align 4
28287 .Lless_3bytes:
28288@@ -179,6 +184,7 @@ ENTRY(memcpy)
28289 movb %cl, (%rdi)
28290
28291 .Lend:
28292+ pax_force_retaddr
28293 retq
28294 CFI_ENDPROC
28295 ENDPROC(memcpy)
28296diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28297index 65268a6..5aa7815 100644
28298--- a/arch/x86/lib/memmove_64.S
28299+++ b/arch/x86/lib/memmove_64.S
28300@@ -61,13 +61,13 @@ ENTRY(memmove)
28301 5:
28302 sub $0x20, %rdx
28303 movq 0*8(%rsi), %r11
28304- movq 1*8(%rsi), %r10
28305+ movq 1*8(%rsi), %rcx
28306 movq 2*8(%rsi), %r9
28307 movq 3*8(%rsi), %r8
28308 leaq 4*8(%rsi), %rsi
28309
28310 movq %r11, 0*8(%rdi)
28311- movq %r10, 1*8(%rdi)
28312+ movq %rcx, 1*8(%rdi)
28313 movq %r9, 2*8(%rdi)
28314 movq %r8, 3*8(%rdi)
28315 leaq 4*8(%rdi), %rdi
28316@@ -81,10 +81,10 @@ ENTRY(memmove)
28317 4:
28318 movq %rdx, %rcx
28319 movq -8(%rsi, %rdx), %r11
28320- lea -8(%rdi, %rdx), %r10
28321+ lea -8(%rdi, %rdx), %r9
28322 shrq $3, %rcx
28323 rep movsq
28324- movq %r11, (%r10)
28325+ movq %r11, (%r9)
28326 jmp 13f
28327 .Lmemmove_end_forward:
28328
28329@@ -95,14 +95,14 @@ ENTRY(memmove)
28330 7:
28331 movq %rdx, %rcx
28332 movq (%rsi), %r11
28333- movq %rdi, %r10
28334+ movq %rdi, %r9
28335 leaq -8(%rsi, %rdx), %rsi
28336 leaq -8(%rdi, %rdx), %rdi
28337 shrq $3, %rcx
28338 std
28339 rep movsq
28340 cld
28341- movq %r11, (%r10)
28342+ movq %r11, (%r9)
28343 jmp 13f
28344
28345 /*
28346@@ -127,13 +127,13 @@ ENTRY(memmove)
28347 8:
28348 subq $0x20, %rdx
28349 movq -1*8(%rsi), %r11
28350- movq -2*8(%rsi), %r10
28351+ movq -2*8(%rsi), %rcx
28352 movq -3*8(%rsi), %r9
28353 movq -4*8(%rsi), %r8
28354 leaq -4*8(%rsi), %rsi
28355
28356 movq %r11, -1*8(%rdi)
28357- movq %r10, -2*8(%rdi)
28358+ movq %rcx, -2*8(%rdi)
28359 movq %r9, -3*8(%rdi)
28360 movq %r8, -4*8(%rdi)
28361 leaq -4*8(%rdi), %rdi
28362@@ -151,11 +151,11 @@ ENTRY(memmove)
28363 * Move data from 16 bytes to 31 bytes.
28364 */
28365 movq 0*8(%rsi), %r11
28366- movq 1*8(%rsi), %r10
28367+ movq 1*8(%rsi), %rcx
28368 movq -2*8(%rsi, %rdx), %r9
28369 movq -1*8(%rsi, %rdx), %r8
28370 movq %r11, 0*8(%rdi)
28371- movq %r10, 1*8(%rdi)
28372+ movq %rcx, 1*8(%rdi)
28373 movq %r9, -2*8(%rdi, %rdx)
28374 movq %r8, -1*8(%rdi, %rdx)
28375 jmp 13f
28376@@ -167,9 +167,9 @@ ENTRY(memmove)
28377 * Move data from 8 bytes to 15 bytes.
28378 */
28379 movq 0*8(%rsi), %r11
28380- movq -1*8(%rsi, %rdx), %r10
28381+ movq -1*8(%rsi, %rdx), %r9
28382 movq %r11, 0*8(%rdi)
28383- movq %r10, -1*8(%rdi, %rdx)
28384+ movq %r9, -1*8(%rdi, %rdx)
28385 jmp 13f
28386 10:
28387 cmpq $4, %rdx
28388@@ -178,9 +178,9 @@ ENTRY(memmove)
28389 * Move data from 4 bytes to 7 bytes.
28390 */
28391 movl (%rsi), %r11d
28392- movl -4(%rsi, %rdx), %r10d
28393+ movl -4(%rsi, %rdx), %r9d
28394 movl %r11d, (%rdi)
28395- movl %r10d, -4(%rdi, %rdx)
28396+ movl %r9d, -4(%rdi, %rdx)
28397 jmp 13f
28398 11:
28399 cmp $2, %rdx
28400@@ -189,9 +189,9 @@ ENTRY(memmove)
28401 * Move data from 2 bytes to 3 bytes.
28402 */
28403 movw (%rsi), %r11w
28404- movw -2(%rsi, %rdx), %r10w
28405+ movw -2(%rsi, %rdx), %r9w
28406 movw %r11w, (%rdi)
28407- movw %r10w, -2(%rdi, %rdx)
28408+ movw %r9w, -2(%rdi, %rdx)
28409 jmp 13f
28410 12:
28411 cmp $1, %rdx
28412@@ -202,14 +202,16 @@ ENTRY(memmove)
28413 movb (%rsi), %r11b
28414 movb %r11b, (%rdi)
28415 13:
28416+ pax_force_retaddr
28417 retq
28418 CFI_ENDPROC
28419
28420- .section .altinstr_replacement,"ax"
28421+ .section .altinstr_replacement,"a"
28422 .Lmemmove_begin_forward_efs:
28423 /* Forward moving data. */
28424 movq %rdx, %rcx
28425 rep movsb
28426+ pax_force_retaddr
28427 retq
28428 .Lmemmove_end_forward_efs:
28429 .previous
28430diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28431index 2dcb380..50a78bc 100644
28432--- a/arch/x86/lib/memset_64.S
28433+++ b/arch/x86/lib/memset_64.S
28434@@ -16,7 +16,7 @@
28435 *
28436 * rax original destination
28437 */
28438- .section .altinstr_replacement, "ax", @progbits
28439+ .section .altinstr_replacement, "a", @progbits
28440 .Lmemset_c:
28441 movq %rdi,%r9
28442 movq %rdx,%rcx
28443@@ -30,6 +30,7 @@
28444 movl %edx,%ecx
28445 rep stosb
28446 movq %r9,%rax
28447+ pax_force_retaddr
28448 ret
28449 .Lmemset_e:
28450 .previous
28451@@ -45,13 +46,14 @@
28452 *
28453 * rax original destination
28454 */
28455- .section .altinstr_replacement, "ax", @progbits
28456+ .section .altinstr_replacement, "a", @progbits
28457 .Lmemset_c_e:
28458 movq %rdi,%r9
28459 movb %sil,%al
28460 movq %rdx,%rcx
28461 rep stosb
28462 movq %r9,%rax
28463+ pax_force_retaddr
28464 ret
28465 .Lmemset_e_e:
28466 .previous
28467@@ -59,7 +61,7 @@
28468 ENTRY(memset)
28469 ENTRY(__memset)
28470 CFI_STARTPROC
28471- movq %rdi,%r10
28472+ movq %rdi,%r11
28473
28474 /* expand byte value */
28475 movzbl %sil,%ecx
28476@@ -117,7 +119,8 @@ ENTRY(__memset)
28477 jnz .Lloop_1
28478
28479 .Lende:
28480- movq %r10,%rax
28481+ movq %r11,%rax
28482+ pax_force_retaddr
28483 ret
28484
28485 CFI_RESTORE_STATE
28486diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28487index c9f2d9b..e7fd2c0 100644
28488--- a/arch/x86/lib/mmx_32.c
28489+++ b/arch/x86/lib/mmx_32.c
28490@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28491 {
28492 void *p;
28493 int i;
28494+ unsigned long cr0;
28495
28496 if (unlikely(in_interrupt()))
28497 return __memcpy(to, from, len);
28498@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28499 kernel_fpu_begin();
28500
28501 __asm__ __volatile__ (
28502- "1: prefetch (%0)\n" /* This set is 28 bytes */
28503- " prefetch 64(%0)\n"
28504- " prefetch 128(%0)\n"
28505- " prefetch 192(%0)\n"
28506- " prefetch 256(%0)\n"
28507+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28508+ " prefetch 64(%1)\n"
28509+ " prefetch 128(%1)\n"
28510+ " prefetch 192(%1)\n"
28511+ " prefetch 256(%1)\n"
28512 "2: \n"
28513 ".section .fixup, \"ax\"\n"
28514- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28515+ "3: \n"
28516+
28517+#ifdef CONFIG_PAX_KERNEXEC
28518+ " movl %%cr0, %0\n"
28519+ " movl %0, %%eax\n"
28520+ " andl $0xFFFEFFFF, %%eax\n"
28521+ " movl %%eax, %%cr0\n"
28522+#endif
28523+
28524+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28525+
28526+#ifdef CONFIG_PAX_KERNEXEC
28527+ " movl %0, %%cr0\n"
28528+#endif
28529+
28530 " jmp 2b\n"
28531 ".previous\n"
28532 _ASM_EXTABLE(1b, 3b)
28533- : : "r" (from));
28534+ : "=&r" (cr0) : "r" (from) : "ax");
28535
28536 for ( ; i > 5; i--) {
28537 __asm__ __volatile__ (
28538- "1: prefetch 320(%0)\n"
28539- "2: movq (%0), %%mm0\n"
28540- " movq 8(%0), %%mm1\n"
28541- " movq 16(%0), %%mm2\n"
28542- " movq 24(%0), %%mm3\n"
28543- " movq %%mm0, (%1)\n"
28544- " movq %%mm1, 8(%1)\n"
28545- " movq %%mm2, 16(%1)\n"
28546- " movq %%mm3, 24(%1)\n"
28547- " movq 32(%0), %%mm0\n"
28548- " movq 40(%0), %%mm1\n"
28549- " movq 48(%0), %%mm2\n"
28550- " movq 56(%0), %%mm3\n"
28551- " movq %%mm0, 32(%1)\n"
28552- " movq %%mm1, 40(%1)\n"
28553- " movq %%mm2, 48(%1)\n"
28554- " movq %%mm3, 56(%1)\n"
28555+ "1: prefetch 320(%1)\n"
28556+ "2: movq (%1), %%mm0\n"
28557+ " movq 8(%1), %%mm1\n"
28558+ " movq 16(%1), %%mm2\n"
28559+ " movq 24(%1), %%mm3\n"
28560+ " movq %%mm0, (%2)\n"
28561+ " movq %%mm1, 8(%2)\n"
28562+ " movq %%mm2, 16(%2)\n"
28563+ " movq %%mm3, 24(%2)\n"
28564+ " movq 32(%1), %%mm0\n"
28565+ " movq 40(%1), %%mm1\n"
28566+ " movq 48(%1), %%mm2\n"
28567+ " movq 56(%1), %%mm3\n"
28568+ " movq %%mm0, 32(%2)\n"
28569+ " movq %%mm1, 40(%2)\n"
28570+ " movq %%mm2, 48(%2)\n"
28571+ " movq %%mm3, 56(%2)\n"
28572 ".section .fixup, \"ax\"\n"
28573- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28574+ "3:\n"
28575+
28576+#ifdef CONFIG_PAX_KERNEXEC
28577+ " movl %%cr0, %0\n"
28578+ " movl %0, %%eax\n"
28579+ " andl $0xFFFEFFFF, %%eax\n"
28580+ " movl %%eax, %%cr0\n"
28581+#endif
28582+
28583+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28584+
28585+#ifdef CONFIG_PAX_KERNEXEC
28586+ " movl %0, %%cr0\n"
28587+#endif
28588+
28589 " jmp 2b\n"
28590 ".previous\n"
28591 _ASM_EXTABLE(1b, 3b)
28592- : : "r" (from), "r" (to) : "memory");
28593+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28594
28595 from += 64;
28596 to += 64;
28597@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28598 static void fast_copy_page(void *to, void *from)
28599 {
28600 int i;
28601+ unsigned long cr0;
28602
28603 kernel_fpu_begin();
28604
28605@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28606 * but that is for later. -AV
28607 */
28608 __asm__ __volatile__(
28609- "1: prefetch (%0)\n"
28610- " prefetch 64(%0)\n"
28611- " prefetch 128(%0)\n"
28612- " prefetch 192(%0)\n"
28613- " prefetch 256(%0)\n"
28614+ "1: prefetch (%1)\n"
28615+ " prefetch 64(%1)\n"
28616+ " prefetch 128(%1)\n"
28617+ " prefetch 192(%1)\n"
28618+ " prefetch 256(%1)\n"
28619 "2: \n"
28620 ".section .fixup, \"ax\"\n"
28621- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28622+ "3: \n"
28623+
28624+#ifdef CONFIG_PAX_KERNEXEC
28625+ " movl %%cr0, %0\n"
28626+ " movl %0, %%eax\n"
28627+ " andl $0xFFFEFFFF, %%eax\n"
28628+ " movl %%eax, %%cr0\n"
28629+#endif
28630+
28631+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28632+
28633+#ifdef CONFIG_PAX_KERNEXEC
28634+ " movl %0, %%cr0\n"
28635+#endif
28636+
28637 " jmp 2b\n"
28638 ".previous\n"
28639- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28640+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28641
28642 for (i = 0; i < (4096-320)/64; i++) {
28643 __asm__ __volatile__ (
28644- "1: prefetch 320(%0)\n"
28645- "2: movq (%0), %%mm0\n"
28646- " movntq %%mm0, (%1)\n"
28647- " movq 8(%0), %%mm1\n"
28648- " movntq %%mm1, 8(%1)\n"
28649- " movq 16(%0), %%mm2\n"
28650- " movntq %%mm2, 16(%1)\n"
28651- " movq 24(%0), %%mm3\n"
28652- " movntq %%mm3, 24(%1)\n"
28653- " movq 32(%0), %%mm4\n"
28654- " movntq %%mm4, 32(%1)\n"
28655- " movq 40(%0), %%mm5\n"
28656- " movntq %%mm5, 40(%1)\n"
28657- " movq 48(%0), %%mm6\n"
28658- " movntq %%mm6, 48(%1)\n"
28659- " movq 56(%0), %%mm7\n"
28660- " movntq %%mm7, 56(%1)\n"
28661+ "1: prefetch 320(%1)\n"
28662+ "2: movq (%1), %%mm0\n"
28663+ " movntq %%mm0, (%2)\n"
28664+ " movq 8(%1), %%mm1\n"
28665+ " movntq %%mm1, 8(%2)\n"
28666+ " movq 16(%1), %%mm2\n"
28667+ " movntq %%mm2, 16(%2)\n"
28668+ " movq 24(%1), %%mm3\n"
28669+ " movntq %%mm3, 24(%2)\n"
28670+ " movq 32(%1), %%mm4\n"
28671+ " movntq %%mm4, 32(%2)\n"
28672+ " movq 40(%1), %%mm5\n"
28673+ " movntq %%mm5, 40(%2)\n"
28674+ " movq 48(%1), %%mm6\n"
28675+ " movntq %%mm6, 48(%2)\n"
28676+ " movq 56(%1), %%mm7\n"
28677+ " movntq %%mm7, 56(%2)\n"
28678 ".section .fixup, \"ax\"\n"
28679- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28680+ "3:\n"
28681+
28682+#ifdef CONFIG_PAX_KERNEXEC
28683+ " movl %%cr0, %0\n"
28684+ " movl %0, %%eax\n"
28685+ " andl $0xFFFEFFFF, %%eax\n"
28686+ " movl %%eax, %%cr0\n"
28687+#endif
28688+
28689+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28690+
28691+#ifdef CONFIG_PAX_KERNEXEC
28692+ " movl %0, %%cr0\n"
28693+#endif
28694+
28695 " jmp 2b\n"
28696 ".previous\n"
28697- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28698+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28699
28700 from += 64;
28701 to += 64;
28702@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28703 static void fast_copy_page(void *to, void *from)
28704 {
28705 int i;
28706+ unsigned long cr0;
28707
28708 kernel_fpu_begin();
28709
28710 __asm__ __volatile__ (
28711- "1: prefetch (%0)\n"
28712- " prefetch 64(%0)\n"
28713- " prefetch 128(%0)\n"
28714- " prefetch 192(%0)\n"
28715- " prefetch 256(%0)\n"
28716+ "1: prefetch (%1)\n"
28717+ " prefetch 64(%1)\n"
28718+ " prefetch 128(%1)\n"
28719+ " prefetch 192(%1)\n"
28720+ " prefetch 256(%1)\n"
28721 "2: \n"
28722 ".section .fixup, \"ax\"\n"
28723- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28724+ "3: \n"
28725+
28726+#ifdef CONFIG_PAX_KERNEXEC
28727+ " movl %%cr0, %0\n"
28728+ " movl %0, %%eax\n"
28729+ " andl $0xFFFEFFFF, %%eax\n"
28730+ " movl %%eax, %%cr0\n"
28731+#endif
28732+
28733+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28734+
28735+#ifdef CONFIG_PAX_KERNEXEC
28736+ " movl %0, %%cr0\n"
28737+#endif
28738+
28739 " jmp 2b\n"
28740 ".previous\n"
28741- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28742+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28743
28744 for (i = 0; i < 4096/64; i++) {
28745 __asm__ __volatile__ (
28746- "1: prefetch 320(%0)\n"
28747- "2: movq (%0), %%mm0\n"
28748- " movq 8(%0), %%mm1\n"
28749- " movq 16(%0), %%mm2\n"
28750- " movq 24(%0), %%mm3\n"
28751- " movq %%mm0, (%1)\n"
28752- " movq %%mm1, 8(%1)\n"
28753- " movq %%mm2, 16(%1)\n"
28754- " movq %%mm3, 24(%1)\n"
28755- " movq 32(%0), %%mm0\n"
28756- " movq 40(%0), %%mm1\n"
28757- " movq 48(%0), %%mm2\n"
28758- " movq 56(%0), %%mm3\n"
28759- " movq %%mm0, 32(%1)\n"
28760- " movq %%mm1, 40(%1)\n"
28761- " movq %%mm2, 48(%1)\n"
28762- " movq %%mm3, 56(%1)\n"
28763+ "1: prefetch 320(%1)\n"
28764+ "2: movq (%1), %%mm0\n"
28765+ " movq 8(%1), %%mm1\n"
28766+ " movq 16(%1), %%mm2\n"
28767+ " movq 24(%1), %%mm3\n"
28768+ " movq %%mm0, (%2)\n"
28769+ " movq %%mm1, 8(%2)\n"
28770+ " movq %%mm2, 16(%2)\n"
28771+ " movq %%mm3, 24(%2)\n"
28772+ " movq 32(%1), %%mm0\n"
28773+ " movq 40(%1), %%mm1\n"
28774+ " movq 48(%1), %%mm2\n"
28775+ " movq 56(%1), %%mm3\n"
28776+ " movq %%mm0, 32(%2)\n"
28777+ " movq %%mm1, 40(%2)\n"
28778+ " movq %%mm2, 48(%2)\n"
28779+ " movq %%mm3, 56(%2)\n"
28780 ".section .fixup, \"ax\"\n"
28781- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28782+ "3:\n"
28783+
28784+#ifdef CONFIG_PAX_KERNEXEC
28785+ " movl %%cr0, %0\n"
28786+ " movl %0, %%eax\n"
28787+ " andl $0xFFFEFFFF, %%eax\n"
28788+ " movl %%eax, %%cr0\n"
28789+#endif
28790+
28791+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28792+
28793+#ifdef CONFIG_PAX_KERNEXEC
28794+ " movl %0, %%cr0\n"
28795+#endif
28796+
28797 " jmp 2b\n"
28798 ".previous\n"
28799 _ASM_EXTABLE(1b, 3b)
28800- : : "r" (from), "r" (to) : "memory");
28801+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28802
28803 from += 64;
28804 to += 64;
28805diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28806index f6d13ee..aca5f0b 100644
28807--- a/arch/x86/lib/msr-reg.S
28808+++ b/arch/x86/lib/msr-reg.S
28809@@ -3,6 +3,7 @@
28810 #include <asm/dwarf2.h>
28811 #include <asm/asm.h>
28812 #include <asm/msr.h>
28813+#include <asm/alternative-asm.h>
28814
28815 #ifdef CONFIG_X86_64
28816 /*
28817@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28818 CFI_STARTPROC
28819 pushq_cfi %rbx
28820 pushq_cfi %rbp
28821- movq %rdi, %r10 /* Save pointer */
28822+ movq %rdi, %r9 /* Save pointer */
28823 xorl %r11d, %r11d /* Return value */
28824 movl (%rdi), %eax
28825 movl 4(%rdi), %ecx
28826@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28827 movl 28(%rdi), %edi
28828 CFI_REMEMBER_STATE
28829 1: \op
28830-2: movl %eax, (%r10)
28831+2: movl %eax, (%r9)
28832 movl %r11d, %eax /* Return value */
28833- movl %ecx, 4(%r10)
28834- movl %edx, 8(%r10)
28835- movl %ebx, 12(%r10)
28836- movl %ebp, 20(%r10)
28837- movl %esi, 24(%r10)
28838- movl %edi, 28(%r10)
28839+ movl %ecx, 4(%r9)
28840+ movl %edx, 8(%r9)
28841+ movl %ebx, 12(%r9)
28842+ movl %ebp, 20(%r9)
28843+ movl %esi, 24(%r9)
28844+ movl %edi, 28(%r9)
28845 popq_cfi %rbp
28846 popq_cfi %rbx
28847+ pax_force_retaddr
28848 ret
28849 3:
28850 CFI_RESTORE_STATE
28851diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28852index fc6ba17..d4d989d 100644
28853--- a/arch/x86/lib/putuser.S
28854+++ b/arch/x86/lib/putuser.S
28855@@ -16,7 +16,9 @@
28856 #include <asm/errno.h>
28857 #include <asm/asm.h>
28858 #include <asm/smap.h>
28859-
28860+#include <asm/segment.h>
28861+#include <asm/pgtable.h>
28862+#include <asm/alternative-asm.h>
28863
28864 /*
28865 * __put_user_X
28866@@ -30,57 +32,125 @@
28867 * as they get called from within inline assembly.
28868 */
28869
28870-#define ENTER CFI_STARTPROC ; \
28871- GET_THREAD_INFO(%_ASM_BX)
28872-#define EXIT ASM_CLAC ; \
28873- ret ; \
28874+#define ENTER CFI_STARTPROC
28875+#define EXIT ASM_CLAC ; \
28876+ pax_force_retaddr ; \
28877+ ret ; \
28878 CFI_ENDPROC
28879
28880+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28881+#define _DEST %_ASM_CX,%_ASM_BX
28882+#else
28883+#define _DEST %_ASM_CX
28884+#endif
28885+
28886+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28887+#define __copyuser_seg gs;
28888+#else
28889+#define __copyuser_seg
28890+#endif
28891+
28892 .text
28893 ENTRY(__put_user_1)
28894 ENTER
28895+
28896+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28897+ GET_THREAD_INFO(%_ASM_BX)
28898 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28899 jae bad_put_user
28900 ASM_STAC
28901-1: movb %al,(%_ASM_CX)
28902+
28903+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28904+ mov pax_user_shadow_base,%_ASM_BX
28905+ cmp %_ASM_BX,%_ASM_CX
28906+ jb 1234f
28907+ xor %ebx,%ebx
28908+1234:
28909+#endif
28910+
28911+#endif
28912+
28913+1: __copyuser_seg movb %al,(_DEST)
28914 xor %eax,%eax
28915 EXIT
28916 ENDPROC(__put_user_1)
28917
28918 ENTRY(__put_user_2)
28919 ENTER
28920+
28921+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28922+ GET_THREAD_INFO(%_ASM_BX)
28923 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28924 sub $1,%_ASM_BX
28925 cmp %_ASM_BX,%_ASM_CX
28926 jae bad_put_user
28927 ASM_STAC
28928-2: movw %ax,(%_ASM_CX)
28929+
28930+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28931+ mov pax_user_shadow_base,%_ASM_BX
28932+ cmp %_ASM_BX,%_ASM_CX
28933+ jb 1234f
28934+ xor %ebx,%ebx
28935+1234:
28936+#endif
28937+
28938+#endif
28939+
28940+2: __copyuser_seg movw %ax,(_DEST)
28941 xor %eax,%eax
28942 EXIT
28943 ENDPROC(__put_user_2)
28944
28945 ENTRY(__put_user_4)
28946 ENTER
28947+
28948+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28949+ GET_THREAD_INFO(%_ASM_BX)
28950 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28951 sub $3,%_ASM_BX
28952 cmp %_ASM_BX,%_ASM_CX
28953 jae bad_put_user
28954 ASM_STAC
28955-3: movl %eax,(%_ASM_CX)
28956+
28957+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28958+ mov pax_user_shadow_base,%_ASM_BX
28959+ cmp %_ASM_BX,%_ASM_CX
28960+ jb 1234f
28961+ xor %ebx,%ebx
28962+1234:
28963+#endif
28964+
28965+#endif
28966+
28967+3: __copyuser_seg movl %eax,(_DEST)
28968 xor %eax,%eax
28969 EXIT
28970 ENDPROC(__put_user_4)
28971
28972 ENTRY(__put_user_8)
28973 ENTER
28974+
28975+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28976+ GET_THREAD_INFO(%_ASM_BX)
28977 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28978 sub $7,%_ASM_BX
28979 cmp %_ASM_BX,%_ASM_CX
28980 jae bad_put_user
28981 ASM_STAC
28982-4: mov %_ASM_AX,(%_ASM_CX)
28983+
28984+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28985+ mov pax_user_shadow_base,%_ASM_BX
28986+ cmp %_ASM_BX,%_ASM_CX
28987+ jb 1234f
28988+ xor %ebx,%ebx
28989+1234:
28990+#endif
28991+
28992+#endif
28993+
28994+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28995 #ifdef CONFIG_X86_32
28996-5: movl %edx,4(%_ASM_CX)
28997+5: __copyuser_seg movl %edx,4(_DEST)
28998 #endif
28999 xor %eax,%eax
29000 EXIT
29001diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29002index 1cad221..de671ee 100644
29003--- a/arch/x86/lib/rwlock.S
29004+++ b/arch/x86/lib/rwlock.S
29005@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29006 FRAME
29007 0: LOCK_PREFIX
29008 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29009+
29010+#ifdef CONFIG_PAX_REFCOUNT
29011+ jno 1234f
29012+ LOCK_PREFIX
29013+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29014+ int $4
29015+1234:
29016+ _ASM_EXTABLE(1234b, 1234b)
29017+#endif
29018+
29019 1: rep; nop
29020 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29021 jne 1b
29022 LOCK_PREFIX
29023 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29024+
29025+#ifdef CONFIG_PAX_REFCOUNT
29026+ jno 1234f
29027+ LOCK_PREFIX
29028+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29029+ int $4
29030+1234:
29031+ _ASM_EXTABLE(1234b, 1234b)
29032+#endif
29033+
29034 jnz 0b
29035 ENDFRAME
29036+ pax_force_retaddr
29037 ret
29038 CFI_ENDPROC
29039 END(__write_lock_failed)
29040@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29041 FRAME
29042 0: LOCK_PREFIX
29043 READ_LOCK_SIZE(inc) (%__lock_ptr)
29044+
29045+#ifdef CONFIG_PAX_REFCOUNT
29046+ jno 1234f
29047+ LOCK_PREFIX
29048+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29049+ int $4
29050+1234:
29051+ _ASM_EXTABLE(1234b, 1234b)
29052+#endif
29053+
29054 1: rep; nop
29055 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29056 js 1b
29057 LOCK_PREFIX
29058 READ_LOCK_SIZE(dec) (%__lock_ptr)
29059+
29060+#ifdef CONFIG_PAX_REFCOUNT
29061+ jno 1234f
29062+ LOCK_PREFIX
29063+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29064+ int $4
29065+1234:
29066+ _ASM_EXTABLE(1234b, 1234b)
29067+#endif
29068+
29069 js 0b
29070 ENDFRAME
29071+ pax_force_retaddr
29072 ret
29073 CFI_ENDPROC
29074 END(__read_lock_failed)
29075diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29076index 5dff5f0..cadebf4 100644
29077--- a/arch/x86/lib/rwsem.S
29078+++ b/arch/x86/lib/rwsem.S
29079@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29080 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29081 CFI_RESTORE __ASM_REG(dx)
29082 restore_common_regs
29083+ pax_force_retaddr
29084 ret
29085 CFI_ENDPROC
29086 ENDPROC(call_rwsem_down_read_failed)
29087@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29088 movq %rax,%rdi
29089 call rwsem_down_write_failed
29090 restore_common_regs
29091+ pax_force_retaddr
29092 ret
29093 CFI_ENDPROC
29094 ENDPROC(call_rwsem_down_write_failed)
29095@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29096 movq %rax,%rdi
29097 call rwsem_wake
29098 restore_common_regs
29099-1: ret
29100+1: pax_force_retaddr
29101+ ret
29102 CFI_ENDPROC
29103 ENDPROC(call_rwsem_wake)
29104
29105@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29106 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29107 CFI_RESTORE __ASM_REG(dx)
29108 restore_common_regs
29109+ pax_force_retaddr
29110 ret
29111 CFI_ENDPROC
29112 ENDPROC(call_rwsem_downgrade_wake)
29113diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29114index a63efd6..ccecad8 100644
29115--- a/arch/x86/lib/thunk_64.S
29116+++ b/arch/x86/lib/thunk_64.S
29117@@ -8,6 +8,7 @@
29118 #include <linux/linkage.h>
29119 #include <asm/dwarf2.h>
29120 #include <asm/calling.h>
29121+#include <asm/alternative-asm.h>
29122
29123 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29124 .macro THUNK name, func, put_ret_addr_in_rdi=0
29125@@ -41,5 +42,6 @@
29126 SAVE_ARGS
29127 restore:
29128 RESTORE_ARGS
29129+ pax_force_retaddr
29130 ret
29131 CFI_ENDPROC
29132diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29133index 3eb18ac..6890bc3 100644
29134--- a/arch/x86/lib/usercopy_32.c
29135+++ b/arch/x86/lib/usercopy_32.c
29136@@ -42,11 +42,13 @@ do { \
29137 int __d0; \
29138 might_fault(); \
29139 __asm__ __volatile__( \
29140+ __COPYUSER_SET_ES \
29141 ASM_STAC "\n" \
29142 "0: rep; stosl\n" \
29143 " movl %2,%0\n" \
29144 "1: rep; stosb\n" \
29145 "2: " ASM_CLAC "\n" \
29146+ __COPYUSER_RESTORE_ES \
29147 ".section .fixup,\"ax\"\n" \
29148 "3: lea 0(%2,%0,4),%0\n" \
29149 " jmp 2b\n" \
29150@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29151
29152 #ifdef CONFIG_X86_INTEL_USERCOPY
29153 static unsigned long
29154-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29155+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29156 {
29157 int d0, d1;
29158 __asm__ __volatile__(
29159@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29160 " .align 2,0x90\n"
29161 "3: movl 0(%4), %%eax\n"
29162 "4: movl 4(%4), %%edx\n"
29163- "5: movl %%eax, 0(%3)\n"
29164- "6: movl %%edx, 4(%3)\n"
29165+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29166+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29167 "7: movl 8(%4), %%eax\n"
29168 "8: movl 12(%4),%%edx\n"
29169- "9: movl %%eax, 8(%3)\n"
29170- "10: movl %%edx, 12(%3)\n"
29171+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29172+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29173 "11: movl 16(%4), %%eax\n"
29174 "12: movl 20(%4), %%edx\n"
29175- "13: movl %%eax, 16(%3)\n"
29176- "14: movl %%edx, 20(%3)\n"
29177+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29178+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29179 "15: movl 24(%4), %%eax\n"
29180 "16: movl 28(%4), %%edx\n"
29181- "17: movl %%eax, 24(%3)\n"
29182- "18: movl %%edx, 28(%3)\n"
29183+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29184+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29185 "19: movl 32(%4), %%eax\n"
29186 "20: movl 36(%4), %%edx\n"
29187- "21: movl %%eax, 32(%3)\n"
29188- "22: movl %%edx, 36(%3)\n"
29189+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29190+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29191 "23: movl 40(%4), %%eax\n"
29192 "24: movl 44(%4), %%edx\n"
29193- "25: movl %%eax, 40(%3)\n"
29194- "26: movl %%edx, 44(%3)\n"
29195+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29196+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29197 "27: movl 48(%4), %%eax\n"
29198 "28: movl 52(%4), %%edx\n"
29199- "29: movl %%eax, 48(%3)\n"
29200- "30: movl %%edx, 52(%3)\n"
29201+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29202+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29203 "31: movl 56(%4), %%eax\n"
29204 "32: movl 60(%4), %%edx\n"
29205- "33: movl %%eax, 56(%3)\n"
29206- "34: movl %%edx, 60(%3)\n"
29207+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29208+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29209 " addl $-64, %0\n"
29210 " addl $64, %4\n"
29211 " addl $64, %3\n"
29212@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29213 " shrl $2, %0\n"
29214 " andl $3, %%eax\n"
29215 " cld\n"
29216+ __COPYUSER_SET_ES
29217 "99: rep; movsl\n"
29218 "36: movl %%eax, %0\n"
29219 "37: rep; movsb\n"
29220 "100:\n"
29221+ __COPYUSER_RESTORE_ES
29222 ".section .fixup,\"ax\"\n"
29223 "101: lea 0(%%eax,%0,4),%0\n"
29224 " jmp 100b\n"
29225@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29226 }
29227
29228 static unsigned long
29229+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29230+{
29231+ int d0, d1;
29232+ __asm__ __volatile__(
29233+ " .align 2,0x90\n"
29234+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29235+ " cmpl $67, %0\n"
29236+ " jbe 3f\n"
29237+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29238+ " .align 2,0x90\n"
29239+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29240+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29241+ "5: movl %%eax, 0(%3)\n"
29242+ "6: movl %%edx, 4(%3)\n"
29243+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29244+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29245+ "9: movl %%eax, 8(%3)\n"
29246+ "10: movl %%edx, 12(%3)\n"
29247+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29248+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29249+ "13: movl %%eax, 16(%3)\n"
29250+ "14: movl %%edx, 20(%3)\n"
29251+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29252+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29253+ "17: movl %%eax, 24(%3)\n"
29254+ "18: movl %%edx, 28(%3)\n"
29255+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29256+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29257+ "21: movl %%eax, 32(%3)\n"
29258+ "22: movl %%edx, 36(%3)\n"
29259+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29260+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29261+ "25: movl %%eax, 40(%3)\n"
29262+ "26: movl %%edx, 44(%3)\n"
29263+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29264+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29265+ "29: movl %%eax, 48(%3)\n"
29266+ "30: movl %%edx, 52(%3)\n"
29267+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29268+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29269+ "33: movl %%eax, 56(%3)\n"
29270+ "34: movl %%edx, 60(%3)\n"
29271+ " addl $-64, %0\n"
29272+ " addl $64, %4\n"
29273+ " addl $64, %3\n"
29274+ " cmpl $63, %0\n"
29275+ " ja 1b\n"
29276+ "35: movl %0, %%eax\n"
29277+ " shrl $2, %0\n"
29278+ " andl $3, %%eax\n"
29279+ " cld\n"
29280+ "99: rep; "__copyuser_seg" movsl\n"
29281+ "36: movl %%eax, %0\n"
29282+ "37: rep; "__copyuser_seg" movsb\n"
29283+ "100:\n"
29284+ ".section .fixup,\"ax\"\n"
29285+ "101: lea 0(%%eax,%0,4),%0\n"
29286+ " jmp 100b\n"
29287+ ".previous\n"
29288+ _ASM_EXTABLE(1b,100b)
29289+ _ASM_EXTABLE(2b,100b)
29290+ _ASM_EXTABLE(3b,100b)
29291+ _ASM_EXTABLE(4b,100b)
29292+ _ASM_EXTABLE(5b,100b)
29293+ _ASM_EXTABLE(6b,100b)
29294+ _ASM_EXTABLE(7b,100b)
29295+ _ASM_EXTABLE(8b,100b)
29296+ _ASM_EXTABLE(9b,100b)
29297+ _ASM_EXTABLE(10b,100b)
29298+ _ASM_EXTABLE(11b,100b)
29299+ _ASM_EXTABLE(12b,100b)
29300+ _ASM_EXTABLE(13b,100b)
29301+ _ASM_EXTABLE(14b,100b)
29302+ _ASM_EXTABLE(15b,100b)
29303+ _ASM_EXTABLE(16b,100b)
29304+ _ASM_EXTABLE(17b,100b)
29305+ _ASM_EXTABLE(18b,100b)
29306+ _ASM_EXTABLE(19b,100b)
29307+ _ASM_EXTABLE(20b,100b)
29308+ _ASM_EXTABLE(21b,100b)
29309+ _ASM_EXTABLE(22b,100b)
29310+ _ASM_EXTABLE(23b,100b)
29311+ _ASM_EXTABLE(24b,100b)
29312+ _ASM_EXTABLE(25b,100b)
29313+ _ASM_EXTABLE(26b,100b)
29314+ _ASM_EXTABLE(27b,100b)
29315+ _ASM_EXTABLE(28b,100b)
29316+ _ASM_EXTABLE(29b,100b)
29317+ _ASM_EXTABLE(30b,100b)
29318+ _ASM_EXTABLE(31b,100b)
29319+ _ASM_EXTABLE(32b,100b)
29320+ _ASM_EXTABLE(33b,100b)
29321+ _ASM_EXTABLE(34b,100b)
29322+ _ASM_EXTABLE(35b,100b)
29323+ _ASM_EXTABLE(36b,100b)
29324+ _ASM_EXTABLE(37b,100b)
29325+ _ASM_EXTABLE(99b,101b)
29326+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29327+ : "1"(to), "2"(from), "0"(size)
29328+ : "eax", "edx", "memory");
29329+ return size;
29330+}
29331+
29332+static unsigned long __size_overflow(3)
29333 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29334 {
29335 int d0, d1;
29336 __asm__ __volatile__(
29337 " .align 2,0x90\n"
29338- "0: movl 32(%4), %%eax\n"
29339+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29340 " cmpl $67, %0\n"
29341 " jbe 2f\n"
29342- "1: movl 64(%4), %%eax\n"
29343+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29344 " .align 2,0x90\n"
29345- "2: movl 0(%4), %%eax\n"
29346- "21: movl 4(%4), %%edx\n"
29347+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29348+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29349 " movl %%eax, 0(%3)\n"
29350 " movl %%edx, 4(%3)\n"
29351- "3: movl 8(%4), %%eax\n"
29352- "31: movl 12(%4),%%edx\n"
29353+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29354+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29355 " movl %%eax, 8(%3)\n"
29356 " movl %%edx, 12(%3)\n"
29357- "4: movl 16(%4), %%eax\n"
29358- "41: movl 20(%4), %%edx\n"
29359+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29360+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29361 " movl %%eax, 16(%3)\n"
29362 " movl %%edx, 20(%3)\n"
29363- "10: movl 24(%4), %%eax\n"
29364- "51: movl 28(%4), %%edx\n"
29365+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29366+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29367 " movl %%eax, 24(%3)\n"
29368 " movl %%edx, 28(%3)\n"
29369- "11: movl 32(%4), %%eax\n"
29370- "61: movl 36(%4), %%edx\n"
29371+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29372+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29373 " movl %%eax, 32(%3)\n"
29374 " movl %%edx, 36(%3)\n"
29375- "12: movl 40(%4), %%eax\n"
29376- "71: movl 44(%4), %%edx\n"
29377+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29378+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29379 " movl %%eax, 40(%3)\n"
29380 " movl %%edx, 44(%3)\n"
29381- "13: movl 48(%4), %%eax\n"
29382- "81: movl 52(%4), %%edx\n"
29383+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29384+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29385 " movl %%eax, 48(%3)\n"
29386 " movl %%edx, 52(%3)\n"
29387- "14: movl 56(%4), %%eax\n"
29388- "91: movl 60(%4), %%edx\n"
29389+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29390+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29391 " movl %%eax, 56(%3)\n"
29392 " movl %%edx, 60(%3)\n"
29393 " addl $-64, %0\n"
29394@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29395 " shrl $2, %0\n"
29396 " andl $3, %%eax\n"
29397 " cld\n"
29398- "6: rep; movsl\n"
29399+ "6: rep; "__copyuser_seg" movsl\n"
29400 " movl %%eax,%0\n"
29401- "7: rep; movsb\n"
29402+ "7: rep; "__copyuser_seg" movsb\n"
29403 "8:\n"
29404 ".section .fixup,\"ax\"\n"
29405 "9: lea 0(%%eax,%0,4),%0\n"
29406@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29407 * hyoshiok@miraclelinux.com
29408 */
29409
29410-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29411+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29412 const void __user *from, unsigned long size)
29413 {
29414 int d0, d1;
29415
29416 __asm__ __volatile__(
29417 " .align 2,0x90\n"
29418- "0: movl 32(%4), %%eax\n"
29419+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29420 " cmpl $67, %0\n"
29421 " jbe 2f\n"
29422- "1: movl 64(%4), %%eax\n"
29423+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29424 " .align 2,0x90\n"
29425- "2: movl 0(%4), %%eax\n"
29426- "21: movl 4(%4), %%edx\n"
29427+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29428+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29429 " movnti %%eax, 0(%3)\n"
29430 " movnti %%edx, 4(%3)\n"
29431- "3: movl 8(%4), %%eax\n"
29432- "31: movl 12(%4),%%edx\n"
29433+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29434+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29435 " movnti %%eax, 8(%3)\n"
29436 " movnti %%edx, 12(%3)\n"
29437- "4: movl 16(%4), %%eax\n"
29438- "41: movl 20(%4), %%edx\n"
29439+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29440+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29441 " movnti %%eax, 16(%3)\n"
29442 " movnti %%edx, 20(%3)\n"
29443- "10: movl 24(%4), %%eax\n"
29444- "51: movl 28(%4), %%edx\n"
29445+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29446+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29447 " movnti %%eax, 24(%3)\n"
29448 " movnti %%edx, 28(%3)\n"
29449- "11: movl 32(%4), %%eax\n"
29450- "61: movl 36(%4), %%edx\n"
29451+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29452+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29453 " movnti %%eax, 32(%3)\n"
29454 " movnti %%edx, 36(%3)\n"
29455- "12: movl 40(%4), %%eax\n"
29456- "71: movl 44(%4), %%edx\n"
29457+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29458+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29459 " movnti %%eax, 40(%3)\n"
29460 " movnti %%edx, 44(%3)\n"
29461- "13: movl 48(%4), %%eax\n"
29462- "81: movl 52(%4), %%edx\n"
29463+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29464+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29465 " movnti %%eax, 48(%3)\n"
29466 " movnti %%edx, 52(%3)\n"
29467- "14: movl 56(%4), %%eax\n"
29468- "91: movl 60(%4), %%edx\n"
29469+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29470+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29471 " movnti %%eax, 56(%3)\n"
29472 " movnti %%edx, 60(%3)\n"
29473 " addl $-64, %0\n"
29474@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29475 " shrl $2, %0\n"
29476 " andl $3, %%eax\n"
29477 " cld\n"
29478- "6: rep; movsl\n"
29479+ "6: rep; "__copyuser_seg" movsl\n"
29480 " movl %%eax,%0\n"
29481- "7: rep; movsb\n"
29482+ "7: rep; "__copyuser_seg" movsb\n"
29483 "8:\n"
29484 ".section .fixup,\"ax\"\n"
29485 "9: lea 0(%%eax,%0,4),%0\n"
29486@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29487 return size;
29488 }
29489
29490-static unsigned long __copy_user_intel_nocache(void *to,
29491+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29492 const void __user *from, unsigned long size)
29493 {
29494 int d0, d1;
29495
29496 __asm__ __volatile__(
29497 " .align 2,0x90\n"
29498- "0: movl 32(%4), %%eax\n"
29499+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29500 " cmpl $67, %0\n"
29501 " jbe 2f\n"
29502- "1: movl 64(%4), %%eax\n"
29503+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29504 " .align 2,0x90\n"
29505- "2: movl 0(%4), %%eax\n"
29506- "21: movl 4(%4), %%edx\n"
29507+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29508+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29509 " movnti %%eax, 0(%3)\n"
29510 " movnti %%edx, 4(%3)\n"
29511- "3: movl 8(%4), %%eax\n"
29512- "31: movl 12(%4),%%edx\n"
29513+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29514+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29515 " movnti %%eax, 8(%3)\n"
29516 " movnti %%edx, 12(%3)\n"
29517- "4: movl 16(%4), %%eax\n"
29518- "41: movl 20(%4), %%edx\n"
29519+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29520+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29521 " movnti %%eax, 16(%3)\n"
29522 " movnti %%edx, 20(%3)\n"
29523- "10: movl 24(%4), %%eax\n"
29524- "51: movl 28(%4), %%edx\n"
29525+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29526+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29527 " movnti %%eax, 24(%3)\n"
29528 " movnti %%edx, 28(%3)\n"
29529- "11: movl 32(%4), %%eax\n"
29530- "61: movl 36(%4), %%edx\n"
29531+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29532+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29533 " movnti %%eax, 32(%3)\n"
29534 " movnti %%edx, 36(%3)\n"
29535- "12: movl 40(%4), %%eax\n"
29536- "71: movl 44(%4), %%edx\n"
29537+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29538+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29539 " movnti %%eax, 40(%3)\n"
29540 " movnti %%edx, 44(%3)\n"
29541- "13: movl 48(%4), %%eax\n"
29542- "81: movl 52(%4), %%edx\n"
29543+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29544+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29545 " movnti %%eax, 48(%3)\n"
29546 " movnti %%edx, 52(%3)\n"
29547- "14: movl 56(%4), %%eax\n"
29548- "91: movl 60(%4), %%edx\n"
29549+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29550+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29551 " movnti %%eax, 56(%3)\n"
29552 " movnti %%edx, 60(%3)\n"
29553 " addl $-64, %0\n"
29554@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29555 " shrl $2, %0\n"
29556 " andl $3, %%eax\n"
29557 " cld\n"
29558- "6: rep; movsl\n"
29559+ "6: rep; "__copyuser_seg" movsl\n"
29560 " movl %%eax,%0\n"
29561- "7: rep; movsb\n"
29562+ "7: rep; "__copyuser_seg" movsb\n"
29563 "8:\n"
29564 ".section .fixup,\"ax\"\n"
29565 "9: lea 0(%%eax,%0,4),%0\n"
29566@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29567 */
29568 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29569 unsigned long size);
29570-unsigned long __copy_user_intel(void __user *to, const void *from,
29571+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29572+ unsigned long size);
29573+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29574 unsigned long size);
29575 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29576 const void __user *from, unsigned long size);
29577 #endif /* CONFIG_X86_INTEL_USERCOPY */
29578
29579 /* Generic arbitrary sized copy. */
29580-#define __copy_user(to, from, size) \
29581+#define __copy_user(to, from, size, prefix, set, restore) \
29582 do { \
29583 int __d0, __d1, __d2; \
29584 __asm__ __volatile__( \
29585+ set \
29586 " cmp $7,%0\n" \
29587 " jbe 1f\n" \
29588 " movl %1,%0\n" \
29589 " negl %0\n" \
29590 " andl $7,%0\n" \
29591 " subl %0,%3\n" \
29592- "4: rep; movsb\n" \
29593+ "4: rep; "prefix"movsb\n" \
29594 " movl %3,%0\n" \
29595 " shrl $2,%0\n" \
29596 " andl $3,%3\n" \
29597 " .align 2,0x90\n" \
29598- "0: rep; movsl\n" \
29599+ "0: rep; "prefix"movsl\n" \
29600 " movl %3,%0\n" \
29601- "1: rep; movsb\n" \
29602+ "1: rep; "prefix"movsb\n" \
29603 "2:\n" \
29604+ restore \
29605 ".section .fixup,\"ax\"\n" \
29606 "5: addl %3,%0\n" \
29607 " jmp 2b\n" \
29608@@ -538,14 +650,14 @@ do { \
29609 " negl %0\n" \
29610 " andl $7,%0\n" \
29611 " subl %0,%3\n" \
29612- "4: rep; movsb\n" \
29613+ "4: rep; "__copyuser_seg"movsb\n" \
29614 " movl %3,%0\n" \
29615 " shrl $2,%0\n" \
29616 " andl $3,%3\n" \
29617 " .align 2,0x90\n" \
29618- "0: rep; movsl\n" \
29619+ "0: rep; "__copyuser_seg"movsl\n" \
29620 " movl %3,%0\n" \
29621- "1: rep; movsb\n" \
29622+ "1: rep; "__copyuser_seg"movsb\n" \
29623 "2:\n" \
29624 ".section .fixup,\"ax\"\n" \
29625 "5: addl %3,%0\n" \
29626@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29627 {
29628 stac();
29629 if (movsl_is_ok(to, from, n))
29630- __copy_user(to, from, n);
29631+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29632 else
29633- n = __copy_user_intel(to, from, n);
29634+ n = __generic_copy_to_user_intel(to, from, n);
29635 clac();
29636 return n;
29637 }
29638@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29639 {
29640 stac();
29641 if (movsl_is_ok(to, from, n))
29642- __copy_user(to, from, n);
29643+ __copy_user(to, from, n, __copyuser_seg, "", "");
29644 else
29645- n = __copy_user_intel((void __user *)to,
29646- (const void *)from, n);
29647+ n = __generic_copy_from_user_intel(to, from, n);
29648 clac();
29649 return n;
29650 }
29651@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29652 if (n > 64 && cpu_has_xmm2)
29653 n = __copy_user_intel_nocache(to, from, n);
29654 else
29655- __copy_user(to, from, n);
29656+ __copy_user(to, from, n, __copyuser_seg, "", "");
29657 #else
29658- __copy_user(to, from, n);
29659+ __copy_user(to, from, n, __copyuser_seg, "", "");
29660 #endif
29661 clac();
29662 return n;
29663 }
29664 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29665
29666-/**
29667- * copy_to_user: - Copy a block of data into user space.
29668- * @to: Destination address, in user space.
29669- * @from: Source address, in kernel space.
29670- * @n: Number of bytes to copy.
29671- *
29672- * Context: User context only. This function may sleep.
29673- *
29674- * Copy data from kernel space to user space.
29675- *
29676- * Returns number of bytes that could not be copied.
29677- * On success, this will be zero.
29678- */
29679-unsigned long
29680-copy_to_user(void __user *to, const void *from, unsigned long n)
29681+#ifdef CONFIG_PAX_MEMORY_UDEREF
29682+void __set_fs(mm_segment_t x)
29683 {
29684- if (access_ok(VERIFY_WRITE, to, n))
29685- n = __copy_to_user(to, from, n);
29686- return n;
29687+ switch (x.seg) {
29688+ case 0:
29689+ loadsegment(gs, 0);
29690+ break;
29691+ case TASK_SIZE_MAX:
29692+ loadsegment(gs, __USER_DS);
29693+ break;
29694+ case -1UL:
29695+ loadsegment(gs, __KERNEL_DS);
29696+ break;
29697+ default:
29698+ BUG();
29699+ }
29700 }
29701-EXPORT_SYMBOL(copy_to_user);
29702+EXPORT_SYMBOL(__set_fs);
29703
29704-/**
29705- * copy_from_user: - Copy a block of data from user space.
29706- * @to: Destination address, in kernel space.
29707- * @from: Source address, in user space.
29708- * @n: Number of bytes to copy.
29709- *
29710- * Context: User context only. This function may sleep.
29711- *
29712- * Copy data from user space to kernel space.
29713- *
29714- * Returns number of bytes that could not be copied.
29715- * On success, this will be zero.
29716- *
29717- * If some data could not be copied, this function will pad the copied
29718- * data to the requested size using zero bytes.
29719- */
29720-unsigned long
29721-_copy_from_user(void *to, const void __user *from, unsigned long n)
29722+void set_fs(mm_segment_t x)
29723 {
29724- if (access_ok(VERIFY_READ, from, n))
29725- n = __copy_from_user(to, from, n);
29726- else
29727- memset(to, 0, n);
29728- return n;
29729+ current_thread_info()->addr_limit = x;
29730+ __set_fs(x);
29731 }
29732-EXPORT_SYMBOL(_copy_from_user);
29733+EXPORT_SYMBOL(set_fs);
29734+#endif
29735diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29736index 906fea3..0194a18 100644
29737--- a/arch/x86/lib/usercopy_64.c
29738+++ b/arch/x86/lib/usercopy_64.c
29739@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29740 might_fault();
29741 /* no memory constraint because it doesn't change any memory gcc knows
29742 about */
29743+ pax_open_userland();
29744 stac();
29745 asm volatile(
29746 " testq %[size8],%[size8]\n"
29747@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29748 _ASM_EXTABLE(0b,3b)
29749 _ASM_EXTABLE(1b,2b)
29750 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29751- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29752+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29753 [zero] "r" (0UL), [eight] "r" (8UL));
29754 clac();
29755+ pax_close_userland();
29756 return size;
29757 }
29758 EXPORT_SYMBOL(__clear_user);
29759@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29760 }
29761 EXPORT_SYMBOL(clear_user);
29762
29763-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29764+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29765 {
29766- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29767- return copy_user_generic((__force void *)to, (__force void *)from, len);
29768- }
29769- return len;
29770+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29771+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29772+ return len;
29773 }
29774 EXPORT_SYMBOL(copy_in_user);
29775
29776@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29777 * it is not necessary to optimize tail handling.
29778 */
29779 unsigned long
29780-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29781+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29782 {
29783 char c;
29784 unsigned zero_len;
29785
29786+ clac();
29787+ pax_close_userland();
29788 for (; len; --len, to++) {
29789 if (__get_user_nocheck(c, from++, sizeof(char)))
29790 break;
29791@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29792 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29793 if (__put_user_nocheck(c, to++, sizeof(char)))
29794 break;
29795- clac();
29796 return len;
29797 }
29798diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29799index 23d8e5f..9ccc13a 100644
29800--- a/arch/x86/mm/Makefile
29801+++ b/arch/x86/mm/Makefile
29802@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29803 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29804
29805 obj-$(CONFIG_MEMTEST) += memtest.o
29806+
29807+quote:="
29808+obj-$(CONFIG_X86_64) += uderef_64.o
29809+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29810diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29811index 903ec1e..c4166b2 100644
29812--- a/arch/x86/mm/extable.c
29813+++ b/arch/x86/mm/extable.c
29814@@ -6,12 +6,24 @@
29815 static inline unsigned long
29816 ex_insn_addr(const struct exception_table_entry *x)
29817 {
29818- return (unsigned long)&x->insn + x->insn;
29819+ unsigned long reloc = 0;
29820+
29821+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29822+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29823+#endif
29824+
29825+ return (unsigned long)&x->insn + x->insn + reloc;
29826 }
29827 static inline unsigned long
29828 ex_fixup_addr(const struct exception_table_entry *x)
29829 {
29830- return (unsigned long)&x->fixup + x->fixup;
29831+ unsigned long reloc = 0;
29832+
29833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29834+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29835+#endif
29836+
29837+ return (unsigned long)&x->fixup + x->fixup + reloc;
29838 }
29839
29840 int fixup_exception(struct pt_regs *regs)
29841@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29842 unsigned long new_ip;
29843
29844 #ifdef CONFIG_PNPBIOS
29845- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29846+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29847 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29848 extern u32 pnp_bios_is_utter_crap;
29849 pnp_bios_is_utter_crap = 1;
29850@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29851 i += 4;
29852 p->fixup -= i;
29853 i += 4;
29854+
29855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29856+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29857+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29858+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29859+#endif
29860+
29861 }
29862 }
29863
29864diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29865index 654be4a..a4a3da1 100644
29866--- a/arch/x86/mm/fault.c
29867+++ b/arch/x86/mm/fault.c
29868@@ -14,11 +14,18 @@
29869 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29870 #include <linux/prefetch.h> /* prefetchw */
29871 #include <linux/context_tracking.h> /* exception_enter(), ... */
29872+#include <linux/unistd.h>
29873+#include <linux/compiler.h>
29874
29875 #include <asm/traps.h> /* dotraplinkage, ... */
29876 #include <asm/pgalloc.h> /* pgd_*(), ... */
29877 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29878 #include <asm/fixmap.h> /* VSYSCALL_START */
29879+#include <asm/tlbflush.h>
29880+
29881+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29882+#include <asm/stacktrace.h>
29883+#endif
29884
29885 /*
29886 * Page fault error code bits:
29887@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29888 int ret = 0;
29889
29890 /* kprobe_running() needs smp_processor_id() */
29891- if (kprobes_built_in() && !user_mode_vm(regs)) {
29892+ if (kprobes_built_in() && !user_mode(regs)) {
29893 preempt_disable();
29894 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29895 ret = 1;
29896@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29897 return !instr_lo || (instr_lo>>1) == 1;
29898 case 0x00:
29899 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29900- if (probe_kernel_address(instr, opcode))
29901+ if (user_mode(regs)) {
29902+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29903+ return 0;
29904+ } else if (probe_kernel_address(instr, opcode))
29905 return 0;
29906
29907 *prefetch = (instr_lo == 0xF) &&
29908@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29909 while (instr < max_instr) {
29910 unsigned char opcode;
29911
29912- if (probe_kernel_address(instr, opcode))
29913+ if (user_mode(regs)) {
29914+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29915+ break;
29916+ } else if (probe_kernel_address(instr, opcode))
29917 break;
29918
29919 instr++;
29920@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29921 force_sig_info(si_signo, &info, tsk);
29922 }
29923
29924+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29925+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29926+#endif
29927+
29928+#ifdef CONFIG_PAX_EMUTRAMP
29929+static int pax_handle_fetch_fault(struct pt_regs *regs);
29930+#endif
29931+
29932+#ifdef CONFIG_PAX_PAGEEXEC
29933+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29934+{
29935+ pgd_t *pgd;
29936+ pud_t *pud;
29937+ pmd_t *pmd;
29938+
29939+ pgd = pgd_offset(mm, address);
29940+ if (!pgd_present(*pgd))
29941+ return NULL;
29942+ pud = pud_offset(pgd, address);
29943+ if (!pud_present(*pud))
29944+ return NULL;
29945+ pmd = pmd_offset(pud, address);
29946+ if (!pmd_present(*pmd))
29947+ return NULL;
29948+ return pmd;
29949+}
29950+#endif
29951+
29952 DEFINE_SPINLOCK(pgd_lock);
29953 LIST_HEAD(pgd_list);
29954
29955@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29956 for (address = VMALLOC_START & PMD_MASK;
29957 address >= TASK_SIZE && address < FIXADDR_TOP;
29958 address += PMD_SIZE) {
29959+
29960+#ifdef CONFIG_PAX_PER_CPU_PGD
29961+ unsigned long cpu;
29962+#else
29963 struct page *page;
29964+#endif
29965
29966 spin_lock(&pgd_lock);
29967+
29968+#ifdef CONFIG_PAX_PER_CPU_PGD
29969+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29970+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29971+ pmd_t *ret;
29972+
29973+ ret = vmalloc_sync_one(pgd, address);
29974+ if (!ret)
29975+ break;
29976+ pgd = get_cpu_pgd(cpu, kernel);
29977+#else
29978 list_for_each_entry(page, &pgd_list, lru) {
29979+ pgd_t *pgd;
29980 spinlock_t *pgt_lock;
29981 pmd_t *ret;
29982
29983@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29984 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29985
29986 spin_lock(pgt_lock);
29987- ret = vmalloc_sync_one(page_address(page), address);
29988+ pgd = page_address(page);
29989+#endif
29990+
29991+ ret = vmalloc_sync_one(pgd, address);
29992+
29993+#ifndef CONFIG_PAX_PER_CPU_PGD
29994 spin_unlock(pgt_lock);
29995+#endif
29996
29997 if (!ret)
29998 break;
29999@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30000 * an interrupt in the middle of a task switch..
30001 */
30002 pgd_paddr = read_cr3();
30003+
30004+#ifdef CONFIG_PAX_PER_CPU_PGD
30005+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30006+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30007+#endif
30008+
30009 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30010 if (!pmd_k)
30011 return -1;
30012@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30013 * happen within a race in page table update. In the later
30014 * case just flush:
30015 */
30016- pgd = pgd_offset(current->active_mm, address);
30017+
30018 pgd_ref = pgd_offset_k(address);
30019 if (pgd_none(*pgd_ref))
30020 return -1;
30021
30022+#ifdef CONFIG_PAX_PER_CPU_PGD
30023+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30024+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30025+ if (pgd_none(*pgd)) {
30026+ set_pgd(pgd, *pgd_ref);
30027+ arch_flush_lazy_mmu_mode();
30028+ } else {
30029+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30030+ }
30031+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30032+#else
30033+ pgd = pgd_offset(current->active_mm, address);
30034+#endif
30035+
30036 if (pgd_none(*pgd)) {
30037 set_pgd(pgd, *pgd_ref);
30038 arch_flush_lazy_mmu_mode();
30039@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30040 static int is_errata100(struct pt_regs *regs, unsigned long address)
30041 {
30042 #ifdef CONFIG_X86_64
30043- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30044+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30045 return 1;
30046 #endif
30047 return 0;
30048@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30049 }
30050
30051 static const char nx_warning[] = KERN_CRIT
30052-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30053+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30054
30055 static void
30056 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30057@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30058 if (!oops_may_print())
30059 return;
30060
30061- if (error_code & PF_INSTR) {
30062+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30063 unsigned int level;
30064
30065 pte_t *pte = lookup_address(address, &level);
30066
30067 if (pte && pte_present(*pte) && !pte_exec(*pte))
30068- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30069+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30070 }
30071
30072+#ifdef CONFIG_PAX_KERNEXEC
30073+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30074+ if (current->signal->curr_ip)
30075+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30076+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30077+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30078+ else
30079+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30080+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30081+ }
30082+#endif
30083+
30084 printk(KERN_ALERT "BUG: unable to handle kernel ");
30085 if (address < PAGE_SIZE)
30086 printk(KERN_CONT "NULL pointer dereference");
30087@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30088 return;
30089 }
30090 #endif
30091+
30092+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30093+ if (pax_is_fetch_fault(regs, error_code, address)) {
30094+
30095+#ifdef CONFIG_PAX_EMUTRAMP
30096+ switch (pax_handle_fetch_fault(regs)) {
30097+ case 2:
30098+ return;
30099+ }
30100+#endif
30101+
30102+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30103+ do_group_exit(SIGKILL);
30104+ }
30105+#endif
30106+
30107 /* Kernel addresses are always protection faults: */
30108 if (address >= TASK_SIZE)
30109 error_code |= PF_PROT;
30110@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30111 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30112 printk(KERN_ERR
30113 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30114- tsk->comm, tsk->pid, address);
30115+ tsk->comm, task_pid_nr(tsk), address);
30116 code = BUS_MCEERR_AR;
30117 }
30118 #endif
30119@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30120 return 1;
30121 }
30122
30123+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30124+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30125+{
30126+ pte_t *pte;
30127+ pmd_t *pmd;
30128+ spinlock_t *ptl;
30129+ unsigned char pte_mask;
30130+
30131+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30132+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30133+ return 0;
30134+
30135+ /* PaX: it's our fault, let's handle it if we can */
30136+
30137+ /* PaX: take a look at read faults before acquiring any locks */
30138+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30139+ /* instruction fetch attempt from a protected page in user mode */
30140+ up_read(&mm->mmap_sem);
30141+
30142+#ifdef CONFIG_PAX_EMUTRAMP
30143+ switch (pax_handle_fetch_fault(regs)) {
30144+ case 2:
30145+ return 1;
30146+ }
30147+#endif
30148+
30149+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30150+ do_group_exit(SIGKILL);
30151+ }
30152+
30153+ pmd = pax_get_pmd(mm, address);
30154+ if (unlikely(!pmd))
30155+ return 0;
30156+
30157+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30158+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30159+ pte_unmap_unlock(pte, ptl);
30160+ return 0;
30161+ }
30162+
30163+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30164+ /* write attempt to a protected page in user mode */
30165+ pte_unmap_unlock(pte, ptl);
30166+ return 0;
30167+ }
30168+
30169+#ifdef CONFIG_SMP
30170+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30171+#else
30172+ if (likely(address > get_limit(regs->cs)))
30173+#endif
30174+ {
30175+ set_pte(pte, pte_mkread(*pte));
30176+ __flush_tlb_one(address);
30177+ pte_unmap_unlock(pte, ptl);
30178+ up_read(&mm->mmap_sem);
30179+ return 1;
30180+ }
30181+
30182+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30183+
30184+ /*
30185+ * PaX: fill DTLB with user rights and retry
30186+ */
30187+ __asm__ __volatile__ (
30188+ "orb %2,(%1)\n"
30189+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30190+/*
30191+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30192+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30193+ * page fault when examined during a TLB load attempt. this is true not only
30194+ * for PTEs holding a non-present entry but also present entries that will
30195+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30196+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30197+ * for our target pages since their PTEs are simply not in the TLBs at all.
30198+
30199+ * the best thing in omitting it is that we gain around 15-20% speed in the
30200+ * fast path of the page fault handler and can get rid of tracing since we
30201+ * can no longer flush unintended entries.
30202+ */
30203+ "invlpg (%0)\n"
30204+#endif
30205+ __copyuser_seg"testb $0,(%0)\n"
30206+ "xorb %3,(%1)\n"
30207+ :
30208+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30209+ : "memory", "cc");
30210+ pte_unmap_unlock(pte, ptl);
30211+ up_read(&mm->mmap_sem);
30212+ return 1;
30213+}
30214+#endif
30215+
30216 /*
30217 * Handle a spurious fault caused by a stale TLB entry.
30218 *
30219@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30220 static inline int
30221 access_error(unsigned long error_code, struct vm_area_struct *vma)
30222 {
30223+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30224+ return 1;
30225+
30226 if (error_code & PF_WRITE) {
30227 /* write, present and write, not present: */
30228 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30229@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30230 if (error_code & PF_USER)
30231 return false;
30232
30233- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30234+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30235 return false;
30236
30237 return true;
30238@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30239 {
30240 struct vm_area_struct *vma;
30241 struct task_struct *tsk;
30242- unsigned long address;
30243 struct mm_struct *mm;
30244 int fault;
30245 int write = error_code & PF_WRITE;
30246 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30247 (write ? FAULT_FLAG_WRITE : 0);
30248
30249- tsk = current;
30250- mm = tsk->mm;
30251-
30252 /* Get the faulting address: */
30253- address = read_cr2();
30254+ unsigned long address = read_cr2();
30255+
30256+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30257+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30258+ if (!search_exception_tables(regs->ip)) {
30259+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30260+ bad_area_nosemaphore(regs, error_code, address);
30261+ return;
30262+ }
30263+ if (address < pax_user_shadow_base) {
30264+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30265+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30266+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30267+ } else
30268+ address -= pax_user_shadow_base;
30269+ }
30270+#endif
30271+
30272+ tsk = current;
30273+ mm = tsk->mm;
30274
30275 /*
30276 * Detect and handle instructions that would cause a page fault for
30277@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30278 * User-mode registers count as a user access even for any
30279 * potential system fault or CPU buglet:
30280 */
30281- if (user_mode_vm(regs)) {
30282+ if (user_mode(regs)) {
30283 local_irq_enable();
30284 error_code |= PF_USER;
30285 } else {
30286@@ -1142,6 +1365,11 @@ retry:
30287 might_sleep();
30288 }
30289
30290+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30291+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30292+ return;
30293+#endif
30294+
30295 vma = find_vma(mm, address);
30296 if (unlikely(!vma)) {
30297 bad_area(regs, error_code, address);
30298@@ -1153,18 +1381,24 @@ retry:
30299 bad_area(regs, error_code, address);
30300 return;
30301 }
30302- if (error_code & PF_USER) {
30303- /*
30304- * Accessing the stack below %sp is always a bug.
30305- * The large cushion allows instructions like enter
30306- * and pusha to work. ("enter $65535, $31" pushes
30307- * 32 pointers and then decrements %sp by 65535.)
30308- */
30309- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30310- bad_area(regs, error_code, address);
30311- return;
30312- }
30313+ /*
30314+ * Accessing the stack below %sp is always a bug.
30315+ * The large cushion allows instructions like enter
30316+ * and pusha to work. ("enter $65535, $31" pushes
30317+ * 32 pointers and then decrements %sp by 65535.)
30318+ */
30319+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30320+ bad_area(regs, error_code, address);
30321+ return;
30322 }
30323+
30324+#ifdef CONFIG_PAX_SEGMEXEC
30325+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30326+ bad_area(regs, error_code, address);
30327+ return;
30328+ }
30329+#endif
30330+
30331 if (unlikely(expand_stack(vma, address))) {
30332 bad_area(regs, error_code, address);
30333 return;
30334@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30335 __do_page_fault(regs, error_code);
30336 exception_exit(prev_state);
30337 }
30338+
30339+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30340+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30341+{
30342+ struct mm_struct *mm = current->mm;
30343+ unsigned long ip = regs->ip;
30344+
30345+ if (v8086_mode(regs))
30346+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30347+
30348+#ifdef CONFIG_PAX_PAGEEXEC
30349+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30350+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30351+ return true;
30352+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30353+ return true;
30354+ return false;
30355+ }
30356+#endif
30357+
30358+#ifdef CONFIG_PAX_SEGMEXEC
30359+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30360+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30361+ return true;
30362+ return false;
30363+ }
30364+#endif
30365+
30366+ return false;
30367+}
30368+#endif
30369+
30370+#ifdef CONFIG_PAX_EMUTRAMP
30371+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30372+{
30373+ int err;
30374+
30375+ do { /* PaX: libffi trampoline emulation */
30376+ unsigned char mov, jmp;
30377+ unsigned int addr1, addr2;
30378+
30379+#ifdef CONFIG_X86_64
30380+ if ((regs->ip + 9) >> 32)
30381+ break;
30382+#endif
30383+
30384+ err = get_user(mov, (unsigned char __user *)regs->ip);
30385+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30386+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30387+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30388+
30389+ if (err)
30390+ break;
30391+
30392+ if (mov == 0xB8 && jmp == 0xE9) {
30393+ regs->ax = addr1;
30394+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30395+ return 2;
30396+ }
30397+ } while (0);
30398+
30399+ do { /* PaX: gcc trampoline emulation #1 */
30400+ unsigned char mov1, mov2;
30401+ unsigned short jmp;
30402+ unsigned int addr1, addr2;
30403+
30404+#ifdef CONFIG_X86_64
30405+ if ((regs->ip + 11) >> 32)
30406+ break;
30407+#endif
30408+
30409+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30410+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30411+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30412+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30413+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30414+
30415+ if (err)
30416+ break;
30417+
30418+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30419+ regs->cx = addr1;
30420+ regs->ax = addr2;
30421+ regs->ip = addr2;
30422+ return 2;
30423+ }
30424+ } while (0);
30425+
30426+ do { /* PaX: gcc trampoline emulation #2 */
30427+ unsigned char mov, jmp;
30428+ unsigned int addr1, addr2;
30429+
30430+#ifdef CONFIG_X86_64
30431+ if ((regs->ip + 9) >> 32)
30432+ break;
30433+#endif
30434+
30435+ err = get_user(mov, (unsigned char __user *)regs->ip);
30436+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30437+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30438+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30439+
30440+ if (err)
30441+ break;
30442+
30443+ if (mov == 0xB9 && jmp == 0xE9) {
30444+ regs->cx = addr1;
30445+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30446+ return 2;
30447+ }
30448+ } while (0);
30449+
30450+ return 1; /* PaX in action */
30451+}
30452+
30453+#ifdef CONFIG_X86_64
30454+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30455+{
30456+ int err;
30457+
30458+ do { /* PaX: libffi trampoline emulation */
30459+ unsigned short mov1, mov2, jmp1;
30460+ unsigned char stcclc, jmp2;
30461+ unsigned long addr1, addr2;
30462+
30463+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30464+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30465+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30466+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30467+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30468+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30469+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30470+
30471+ if (err)
30472+ break;
30473+
30474+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30475+ regs->r11 = addr1;
30476+ regs->r10 = addr2;
30477+ if (stcclc == 0xF8)
30478+ regs->flags &= ~X86_EFLAGS_CF;
30479+ else
30480+ regs->flags |= X86_EFLAGS_CF;
30481+ regs->ip = addr1;
30482+ return 2;
30483+ }
30484+ } while (0);
30485+
30486+ do { /* PaX: gcc trampoline emulation #1 */
30487+ unsigned short mov1, mov2, jmp1;
30488+ unsigned char jmp2;
30489+ unsigned int addr1;
30490+ unsigned long addr2;
30491+
30492+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30493+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30494+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30495+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30496+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30497+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30498+
30499+ if (err)
30500+ break;
30501+
30502+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30503+ regs->r11 = addr1;
30504+ regs->r10 = addr2;
30505+ regs->ip = addr1;
30506+ return 2;
30507+ }
30508+ } while (0);
30509+
30510+ do { /* PaX: gcc trampoline emulation #2 */
30511+ unsigned short mov1, mov2, jmp1;
30512+ unsigned char jmp2;
30513+ unsigned long addr1, addr2;
30514+
30515+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30516+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30517+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30518+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30519+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30520+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30521+
30522+ if (err)
30523+ break;
30524+
30525+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30526+ regs->r11 = addr1;
30527+ regs->r10 = addr2;
30528+ regs->ip = addr1;
30529+ return 2;
30530+ }
30531+ } while (0);
30532+
30533+ return 1; /* PaX in action */
30534+}
30535+#endif
30536+
30537+/*
30538+ * PaX: decide what to do with offenders (regs->ip = fault address)
30539+ *
30540+ * returns 1 when task should be killed
30541+ * 2 when gcc trampoline was detected
30542+ */
30543+static int pax_handle_fetch_fault(struct pt_regs *regs)
30544+{
30545+ if (v8086_mode(regs))
30546+ return 1;
30547+
30548+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30549+ return 1;
30550+
30551+#ifdef CONFIG_X86_32
30552+ return pax_handle_fetch_fault_32(regs);
30553+#else
30554+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30555+ return pax_handle_fetch_fault_32(regs);
30556+ else
30557+ return pax_handle_fetch_fault_64(regs);
30558+#endif
30559+}
30560+#endif
30561+
30562+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30563+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30564+{
30565+ long i;
30566+
30567+ printk(KERN_ERR "PAX: bytes at PC: ");
30568+ for (i = 0; i < 20; i++) {
30569+ unsigned char c;
30570+ if (get_user(c, (unsigned char __force_user *)pc+i))
30571+ printk(KERN_CONT "?? ");
30572+ else
30573+ printk(KERN_CONT "%02x ", c);
30574+ }
30575+ printk("\n");
30576+
30577+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30578+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30579+ unsigned long c;
30580+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30581+#ifdef CONFIG_X86_32
30582+ printk(KERN_CONT "???????? ");
30583+#else
30584+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30585+ printk(KERN_CONT "???????? ???????? ");
30586+ else
30587+ printk(KERN_CONT "???????????????? ");
30588+#endif
30589+ } else {
30590+#ifdef CONFIG_X86_64
30591+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30592+ printk(KERN_CONT "%08x ", (unsigned int)c);
30593+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30594+ } else
30595+#endif
30596+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30597+ }
30598+ }
30599+ printk("\n");
30600+}
30601+#endif
30602+
30603+/**
30604+ * probe_kernel_write(): safely attempt to write to a location
30605+ * @dst: address to write to
30606+ * @src: pointer to the data that shall be written
30607+ * @size: size of the data chunk
30608+ *
30609+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30610+ * happens, handle that and return -EFAULT.
30611+ */
30612+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30613+{
30614+ long ret;
30615+ mm_segment_t old_fs = get_fs();
30616+
30617+ set_fs(KERNEL_DS);
30618+ pagefault_disable();
30619+ pax_open_kernel();
30620+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30621+ pax_close_kernel();
30622+ pagefault_enable();
30623+ set_fs(old_fs);
30624+
30625+ return ret ? -EFAULT : 0;
30626+}
30627diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30628index dd74e46..7d26398 100644
30629--- a/arch/x86/mm/gup.c
30630+++ b/arch/x86/mm/gup.c
30631@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30632 addr = start;
30633 len = (unsigned long) nr_pages << PAGE_SHIFT;
30634 end = start + len;
30635- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30636+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30637 (void __user *)start, len)))
30638 return 0;
30639
30640diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30641index 4500142..53a363c 100644
30642--- a/arch/x86/mm/highmem_32.c
30643+++ b/arch/x86/mm/highmem_32.c
30644@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30645 idx = type + KM_TYPE_NR*smp_processor_id();
30646 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30647 BUG_ON(!pte_none(*(kmap_pte-idx)));
30648+
30649+ pax_open_kernel();
30650 set_pte(kmap_pte-idx, mk_pte(page, prot));
30651+ pax_close_kernel();
30652+
30653 arch_flush_lazy_mmu_mode();
30654
30655 return (void *)vaddr;
30656diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30657index 7e73e8c..11d3b86 100644
30658--- a/arch/x86/mm/hugetlbpage.c
30659+++ b/arch/x86/mm/hugetlbpage.c
30660@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30661 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30662 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30663 unsigned long addr, unsigned long len,
30664- unsigned long pgoff, unsigned long flags)
30665+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30666 {
30667 struct hstate *h = hstate_file(file);
30668 struct vm_unmapped_area_info info;
30669-
30670+
30671 info.flags = 0;
30672 info.length = len;
30673 info.low_limit = TASK_UNMAPPED_BASE;
30674+
30675+#ifdef CONFIG_PAX_RANDMMAP
30676+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30677+ info.low_limit += current->mm->delta_mmap;
30678+#endif
30679+
30680 info.high_limit = TASK_SIZE;
30681 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30682 info.align_offset = 0;
30683+ info.threadstack_offset = offset;
30684 return vm_unmapped_area(&info);
30685 }
30686
30687 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30688 unsigned long addr0, unsigned long len,
30689- unsigned long pgoff, unsigned long flags)
30690+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30691 {
30692 struct hstate *h = hstate_file(file);
30693 struct vm_unmapped_area_info info;
30694@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30695 info.high_limit = current->mm->mmap_base;
30696 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30697 info.align_offset = 0;
30698+ info.threadstack_offset = offset;
30699 addr = vm_unmapped_area(&info);
30700
30701 /*
30702@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30703 VM_BUG_ON(addr != -ENOMEM);
30704 info.flags = 0;
30705 info.low_limit = TASK_UNMAPPED_BASE;
30706+
30707+#ifdef CONFIG_PAX_RANDMMAP
30708+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30709+ info.low_limit += current->mm->delta_mmap;
30710+#endif
30711+
30712 info.high_limit = TASK_SIZE;
30713 addr = vm_unmapped_area(&info);
30714 }
30715@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30716 struct hstate *h = hstate_file(file);
30717 struct mm_struct *mm = current->mm;
30718 struct vm_area_struct *vma;
30719+ unsigned long pax_task_size = TASK_SIZE;
30720+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30721
30722 if (len & ~huge_page_mask(h))
30723 return -EINVAL;
30724- if (len > TASK_SIZE)
30725+
30726+#ifdef CONFIG_PAX_SEGMEXEC
30727+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30728+ pax_task_size = SEGMEXEC_TASK_SIZE;
30729+#endif
30730+
30731+ pax_task_size -= PAGE_SIZE;
30732+
30733+ if (len > pax_task_size)
30734 return -ENOMEM;
30735
30736 if (flags & MAP_FIXED) {
30737@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30738 return addr;
30739 }
30740
30741+#ifdef CONFIG_PAX_RANDMMAP
30742+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30743+#endif
30744+
30745 if (addr) {
30746 addr = ALIGN(addr, huge_page_size(h));
30747 vma = find_vma(mm, addr);
30748- if (TASK_SIZE - len >= addr &&
30749- (!vma || addr + len <= vma->vm_start))
30750+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30751 return addr;
30752 }
30753 if (mm->get_unmapped_area == arch_get_unmapped_area)
30754 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30755- pgoff, flags);
30756+ pgoff, flags, offset);
30757 else
30758 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30759- pgoff, flags);
30760+ pgoff, flags, offset);
30761 }
30762
30763 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30764diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30765index 04664cd..dae6e5d 100644
30766--- a/arch/x86/mm/init.c
30767+++ b/arch/x86/mm/init.c
30768@@ -4,6 +4,7 @@
30769 #include <linux/swap.h>
30770 #include <linux/memblock.h>
30771 #include <linux/bootmem.h> /* for max_low_pfn */
30772+#include <linux/tboot.h>
30773
30774 #include <asm/cacheflush.h>
30775 #include <asm/e820.h>
30776@@ -17,6 +18,8 @@
30777 #include <asm/proto.h>
30778 #include <asm/dma.h> /* for MAX_DMA_PFN */
30779 #include <asm/microcode.h>
30780+#include <asm/desc.h>
30781+#include <asm/bios_ebda.h>
30782
30783 #include "mm_internal.h"
30784
30785@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30786 early_ioremap_page_table_range_init();
30787 #endif
30788
30789+#ifdef CONFIG_PAX_PER_CPU_PGD
30790+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30791+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30792+ KERNEL_PGD_PTRS);
30793+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30794+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30795+ KERNEL_PGD_PTRS);
30796+ load_cr3(get_cpu_pgd(0, kernel));
30797+#else
30798 load_cr3(swapper_pg_dir);
30799+#endif
30800+
30801 __flush_tlb_all();
30802
30803 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30804@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30805 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30806 * mmio resources as well as potential bios/acpi data regions.
30807 */
30808+
30809+#ifdef CONFIG_GRKERNSEC_KMEM
30810+static unsigned int ebda_start __read_only;
30811+static unsigned int ebda_end __read_only;
30812+#endif
30813+
30814 int devmem_is_allowed(unsigned long pagenr)
30815 {
30816- if (pagenr < 256)
30817+#ifdef CONFIG_GRKERNSEC_KMEM
30818+ /* allow BDA */
30819+ if (!pagenr)
30820 return 1;
30821+ /* allow EBDA */
30822+ if (pagenr >= ebda_start && pagenr < ebda_end)
30823+ return 1;
30824+ /* if tboot is in use, allow access to its hardcoded serial log range */
30825+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30826+ return 1;
30827+#else
30828+ if (!pagenr)
30829+ return 1;
30830+#ifdef CONFIG_VM86
30831+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30832+ return 1;
30833+#endif
30834+#endif
30835+
30836+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30837+ return 1;
30838+#ifdef CONFIG_GRKERNSEC_KMEM
30839+ /* throw out everything else below 1MB */
30840+ if (pagenr <= 256)
30841+ return 0;
30842+#endif
30843 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30844 return 0;
30845 if (!page_is_ram(pagenr))
30846@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30847 #endif
30848 }
30849
30850+#ifdef CONFIG_GRKERNSEC_KMEM
30851+static inline void gr_init_ebda(void)
30852+{
30853+ unsigned int ebda_addr;
30854+ unsigned int ebda_size = 0;
30855+
30856+ ebda_addr = get_bios_ebda();
30857+ if (ebda_addr) {
30858+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30859+ ebda_size <<= 10;
30860+ }
30861+ if (ebda_addr && ebda_size) {
30862+ ebda_start = ebda_addr >> PAGE_SHIFT;
30863+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30864+ } else {
30865+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30866+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30867+ }
30868+}
30869+#else
30870+static inline void gr_init_ebda(void) { }
30871+#endif
30872+
30873 void free_initmem(void)
30874 {
30875+#ifdef CONFIG_PAX_KERNEXEC
30876+#ifdef CONFIG_X86_32
30877+ /* PaX: limit KERNEL_CS to actual size */
30878+ unsigned long addr, limit;
30879+ struct desc_struct d;
30880+ int cpu;
30881+#else
30882+ pgd_t *pgd;
30883+ pud_t *pud;
30884+ pmd_t *pmd;
30885+ unsigned long addr, end;
30886+#endif
30887+#endif
30888+
30889+ gr_init_ebda();
30890+
30891+#ifdef CONFIG_PAX_KERNEXEC
30892+#ifdef CONFIG_X86_32
30893+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30894+ limit = (limit - 1UL) >> PAGE_SHIFT;
30895+
30896+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30897+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30898+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30899+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30900+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30901+ }
30902+
30903+ /* PaX: make KERNEL_CS read-only */
30904+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30905+ if (!paravirt_enabled())
30906+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30907+/*
30908+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30909+ pgd = pgd_offset_k(addr);
30910+ pud = pud_offset(pgd, addr);
30911+ pmd = pmd_offset(pud, addr);
30912+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30913+ }
30914+*/
30915+#ifdef CONFIG_X86_PAE
30916+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30917+/*
30918+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30919+ pgd = pgd_offset_k(addr);
30920+ pud = pud_offset(pgd, addr);
30921+ pmd = pmd_offset(pud, addr);
30922+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30923+ }
30924+*/
30925+#endif
30926+
30927+#ifdef CONFIG_MODULES
30928+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30929+#endif
30930+
30931+#else
30932+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30933+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30934+ pgd = pgd_offset_k(addr);
30935+ pud = pud_offset(pgd, addr);
30936+ pmd = pmd_offset(pud, addr);
30937+ if (!pmd_present(*pmd))
30938+ continue;
30939+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30940+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30941+ else
30942+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30943+ }
30944+
30945+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30946+ end = addr + KERNEL_IMAGE_SIZE;
30947+ for (; addr < end; addr += PMD_SIZE) {
30948+ pgd = pgd_offset_k(addr);
30949+ pud = pud_offset(pgd, addr);
30950+ pmd = pmd_offset(pud, addr);
30951+ if (!pmd_present(*pmd))
30952+ continue;
30953+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30954+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30955+ }
30956+#endif
30957+
30958+ flush_tlb_all();
30959+#endif
30960+
30961 free_init_pages("unused kernel",
30962 (unsigned long)(&__init_begin),
30963 (unsigned long)(&__init_end));
30964diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30965index 4287f1f..3b99c71 100644
30966--- a/arch/x86/mm/init_32.c
30967+++ b/arch/x86/mm/init_32.c
30968@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30969 bool __read_mostly __vmalloc_start_set = false;
30970
30971 /*
30972- * Creates a middle page table and puts a pointer to it in the
30973- * given global directory entry. This only returns the gd entry
30974- * in non-PAE compilation mode, since the middle layer is folded.
30975- */
30976-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30977-{
30978- pud_t *pud;
30979- pmd_t *pmd_table;
30980-
30981-#ifdef CONFIG_X86_PAE
30982- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30983- pmd_table = (pmd_t *)alloc_low_page();
30984- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30985- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30986- pud = pud_offset(pgd, 0);
30987- BUG_ON(pmd_table != pmd_offset(pud, 0));
30988-
30989- return pmd_table;
30990- }
30991-#endif
30992- pud = pud_offset(pgd, 0);
30993- pmd_table = pmd_offset(pud, 0);
30994-
30995- return pmd_table;
30996-}
30997-
30998-/*
30999 * Create a page table and place a pointer to it in a middle page
31000 * directory entry:
31001 */
31002@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31003 pte_t *page_table = (pte_t *)alloc_low_page();
31004
31005 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31006+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31007+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31008+#else
31009 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31010+#endif
31011 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31012 }
31013
31014 return pte_offset_kernel(pmd, 0);
31015 }
31016
31017+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31018+{
31019+ pud_t *pud;
31020+ pmd_t *pmd_table;
31021+
31022+ pud = pud_offset(pgd, 0);
31023+ pmd_table = pmd_offset(pud, 0);
31024+
31025+ return pmd_table;
31026+}
31027+
31028 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31029 {
31030 int pgd_idx = pgd_index(vaddr);
31031@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31032 int pgd_idx, pmd_idx;
31033 unsigned long vaddr;
31034 pgd_t *pgd;
31035+ pud_t *pud;
31036 pmd_t *pmd;
31037 pte_t *pte = NULL;
31038 unsigned long count = page_table_range_init_count(start, end);
31039@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31040 pgd = pgd_base + pgd_idx;
31041
31042 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31043- pmd = one_md_table_init(pgd);
31044- pmd = pmd + pmd_index(vaddr);
31045+ pud = pud_offset(pgd, vaddr);
31046+ pmd = pmd_offset(pud, vaddr);
31047+
31048+#ifdef CONFIG_X86_PAE
31049+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31050+#endif
31051+
31052 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31053 pmd++, pmd_idx++) {
31054 pte = page_table_kmap_check(one_page_table_init(pmd),
31055@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31056 }
31057 }
31058
31059-static inline int is_kernel_text(unsigned long addr)
31060+static inline int is_kernel_text(unsigned long start, unsigned long end)
31061 {
31062- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31063- return 1;
31064- return 0;
31065+ if ((start > ktla_ktva((unsigned long)_etext) ||
31066+ end <= ktla_ktva((unsigned long)_stext)) &&
31067+ (start > ktla_ktva((unsigned long)_einittext) ||
31068+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31069+
31070+#ifdef CONFIG_ACPI_SLEEP
31071+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31072+#endif
31073+
31074+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31075+ return 0;
31076+ return 1;
31077 }
31078
31079 /*
31080@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31081 unsigned long last_map_addr = end;
31082 unsigned long start_pfn, end_pfn;
31083 pgd_t *pgd_base = swapper_pg_dir;
31084- int pgd_idx, pmd_idx, pte_ofs;
31085+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31086 unsigned long pfn;
31087 pgd_t *pgd;
31088+ pud_t *pud;
31089 pmd_t *pmd;
31090 pte_t *pte;
31091 unsigned pages_2m, pages_4k;
31092@@ -291,8 +295,13 @@ repeat:
31093 pfn = start_pfn;
31094 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31095 pgd = pgd_base + pgd_idx;
31096- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31097- pmd = one_md_table_init(pgd);
31098+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31099+ pud = pud_offset(pgd, 0);
31100+ pmd = pmd_offset(pud, 0);
31101+
31102+#ifdef CONFIG_X86_PAE
31103+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31104+#endif
31105
31106 if (pfn >= end_pfn)
31107 continue;
31108@@ -304,14 +313,13 @@ repeat:
31109 #endif
31110 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31111 pmd++, pmd_idx++) {
31112- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31113+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31114
31115 /*
31116 * Map with big pages if possible, otherwise
31117 * create normal page tables:
31118 */
31119 if (use_pse) {
31120- unsigned int addr2;
31121 pgprot_t prot = PAGE_KERNEL_LARGE;
31122 /*
31123 * first pass will use the same initial
31124@@ -322,11 +330,7 @@ repeat:
31125 _PAGE_PSE);
31126
31127 pfn &= PMD_MASK >> PAGE_SHIFT;
31128- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31129- PAGE_OFFSET + PAGE_SIZE-1;
31130-
31131- if (is_kernel_text(addr) ||
31132- is_kernel_text(addr2))
31133+ if (is_kernel_text(address, address + PMD_SIZE))
31134 prot = PAGE_KERNEL_LARGE_EXEC;
31135
31136 pages_2m++;
31137@@ -343,7 +347,7 @@ repeat:
31138 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31139 pte += pte_ofs;
31140 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31141- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31142+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31143 pgprot_t prot = PAGE_KERNEL;
31144 /*
31145 * first pass will use the same initial
31146@@ -351,7 +355,7 @@ repeat:
31147 */
31148 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31149
31150- if (is_kernel_text(addr))
31151+ if (is_kernel_text(address, address + PAGE_SIZE))
31152 prot = PAGE_KERNEL_EXEC;
31153
31154 pages_4k++;
31155@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31156
31157 pud = pud_offset(pgd, va);
31158 pmd = pmd_offset(pud, va);
31159- if (!pmd_present(*pmd))
31160+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31161 break;
31162
31163 /* should not be large page here */
31164@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31165
31166 static void __init pagetable_init(void)
31167 {
31168- pgd_t *pgd_base = swapper_pg_dir;
31169-
31170- permanent_kmaps_init(pgd_base);
31171+ permanent_kmaps_init(swapper_pg_dir);
31172 }
31173
31174-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31175+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31176 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31177
31178 /* user-defined highmem size */
31179@@ -787,10 +789,10 @@ void __init mem_init(void)
31180 ((unsigned long)&__init_end -
31181 (unsigned long)&__init_begin) >> 10,
31182
31183- (unsigned long)&_etext, (unsigned long)&_edata,
31184- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31185+ (unsigned long)&_sdata, (unsigned long)&_edata,
31186+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31187
31188- (unsigned long)&_text, (unsigned long)&_etext,
31189+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31190 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31191
31192 /*
31193@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31194 if (!kernel_set_to_readonly)
31195 return;
31196
31197+ start = ktla_ktva(start);
31198 pr_debug("Set kernel text: %lx - %lx for read write\n",
31199 start, start+size);
31200
31201@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31202 if (!kernel_set_to_readonly)
31203 return;
31204
31205+ start = ktla_ktva(start);
31206 pr_debug("Set kernel text: %lx - %lx for read only\n",
31207 start, start+size);
31208
31209@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31210 unsigned long start = PFN_ALIGN(_text);
31211 unsigned long size = PFN_ALIGN(_etext) - start;
31212
31213+ start = ktla_ktva(start);
31214 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31215 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31216 size >> 10);
31217diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31218index 104d56a..62ba13f 100644
31219--- a/arch/x86/mm/init_64.c
31220+++ b/arch/x86/mm/init_64.c
31221@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31222 * around without checking the pgd every time.
31223 */
31224
31225-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31226+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31227 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31228
31229 int force_personality32;
31230@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31231
31232 for (address = start; address <= end; address += PGDIR_SIZE) {
31233 const pgd_t *pgd_ref = pgd_offset_k(address);
31234+
31235+#ifdef CONFIG_PAX_PER_CPU_PGD
31236+ unsigned long cpu;
31237+#else
31238 struct page *page;
31239+#endif
31240
31241 if (pgd_none(*pgd_ref))
31242 continue;
31243
31244 spin_lock(&pgd_lock);
31245+
31246+#ifdef CONFIG_PAX_PER_CPU_PGD
31247+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31248+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31249+
31250+ if (pgd_none(*pgd))
31251+ set_pgd(pgd, *pgd_ref);
31252+ else
31253+ BUG_ON(pgd_page_vaddr(*pgd)
31254+ != pgd_page_vaddr(*pgd_ref));
31255+ pgd = pgd_offset_cpu(cpu, kernel, address);
31256+#else
31257 list_for_each_entry(page, &pgd_list, lru) {
31258 pgd_t *pgd;
31259 spinlock_t *pgt_lock;
31260@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31261 /* the pgt_lock only for Xen */
31262 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31263 spin_lock(pgt_lock);
31264+#endif
31265
31266 if (pgd_none(*pgd))
31267 set_pgd(pgd, *pgd_ref);
31268@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31269 BUG_ON(pgd_page_vaddr(*pgd)
31270 != pgd_page_vaddr(*pgd_ref));
31271
31272+#ifndef CONFIG_PAX_PER_CPU_PGD
31273 spin_unlock(pgt_lock);
31274+#endif
31275+
31276 }
31277 spin_unlock(&pgd_lock);
31278 }
31279@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31280 {
31281 if (pgd_none(*pgd)) {
31282 pud_t *pud = (pud_t *)spp_getpage();
31283- pgd_populate(&init_mm, pgd, pud);
31284+ pgd_populate_kernel(&init_mm, pgd, pud);
31285 if (pud != pud_offset(pgd, 0))
31286 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31287 pud, pud_offset(pgd, 0));
31288@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31289 {
31290 if (pud_none(*pud)) {
31291 pmd_t *pmd = (pmd_t *) spp_getpage();
31292- pud_populate(&init_mm, pud, pmd);
31293+ pud_populate_kernel(&init_mm, pud, pmd);
31294 if (pmd != pmd_offset(pud, 0))
31295 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31296 pmd, pmd_offset(pud, 0));
31297@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31298 pmd = fill_pmd(pud, vaddr);
31299 pte = fill_pte(pmd, vaddr);
31300
31301+ pax_open_kernel();
31302 set_pte(pte, new_pte);
31303+ pax_close_kernel();
31304
31305 /*
31306 * It's enough to flush this one mapping.
31307@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31308 pgd = pgd_offset_k((unsigned long)__va(phys));
31309 if (pgd_none(*pgd)) {
31310 pud = (pud_t *) spp_getpage();
31311- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31312- _PAGE_USER));
31313+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31314 }
31315 pud = pud_offset(pgd, (unsigned long)__va(phys));
31316 if (pud_none(*pud)) {
31317 pmd = (pmd_t *) spp_getpage();
31318- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31319- _PAGE_USER));
31320+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31321 }
31322 pmd = pmd_offset(pud, phys);
31323 BUG_ON(!pmd_none(*pmd));
31324@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31325 prot);
31326
31327 spin_lock(&init_mm.page_table_lock);
31328- pud_populate(&init_mm, pud, pmd);
31329+ pud_populate_kernel(&init_mm, pud, pmd);
31330 spin_unlock(&init_mm.page_table_lock);
31331 }
31332 __flush_tlb_all();
31333@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31334 page_size_mask);
31335
31336 spin_lock(&init_mm.page_table_lock);
31337- pgd_populate(&init_mm, pgd, pud);
31338+ pgd_populate_kernel(&init_mm, pgd, pud);
31339 spin_unlock(&init_mm.page_table_lock);
31340 pgd_changed = true;
31341 }
31342@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31343 static struct vm_area_struct gate_vma = {
31344 .vm_start = VSYSCALL_START,
31345 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31346- .vm_page_prot = PAGE_READONLY_EXEC,
31347- .vm_flags = VM_READ | VM_EXEC
31348+ .vm_page_prot = PAGE_READONLY,
31349+ .vm_flags = VM_READ
31350 };
31351
31352 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31353@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31354
31355 const char *arch_vma_name(struct vm_area_struct *vma)
31356 {
31357- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31358+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31359 return "[vdso]";
31360 if (vma == &gate_vma)
31361 return "[vsyscall]";
31362diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31363index 7b179b4..6bd17777 100644
31364--- a/arch/x86/mm/iomap_32.c
31365+++ b/arch/x86/mm/iomap_32.c
31366@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31367 type = kmap_atomic_idx_push();
31368 idx = type + KM_TYPE_NR * smp_processor_id();
31369 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31370+
31371+ pax_open_kernel();
31372 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31373+ pax_close_kernel();
31374+
31375 arch_flush_lazy_mmu_mode();
31376
31377 return (void *)vaddr;
31378diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31379index 0215e2c..1c62dab 100644
31380--- a/arch/x86/mm/ioremap.c
31381+++ b/arch/x86/mm/ioremap.c
31382@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31383 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31384 int is_ram = page_is_ram(pfn);
31385
31386- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31387+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31388 return NULL;
31389 WARN_ON_ONCE(is_ram);
31390 }
31391@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31392 *
31393 * Caller must ensure there is only one unmapping for the same pointer.
31394 */
31395-void iounmap(volatile void __iomem *addr)
31396+void iounmap(const volatile void __iomem *addr)
31397 {
31398 struct vm_struct *p, *o;
31399
31400@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31401
31402 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31403 if (page_is_ram(start >> PAGE_SHIFT))
31404+#ifdef CONFIG_HIGHMEM
31405+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31406+#endif
31407 return __va(phys);
31408
31409 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31410@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31411 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31412 {
31413 if (page_is_ram(phys >> PAGE_SHIFT))
31414+#ifdef CONFIG_HIGHMEM
31415+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31416+#endif
31417 return;
31418
31419 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31420@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31421 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31422
31423 static __initdata int after_paging_init;
31424-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31425+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31426
31427 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31428 {
31429@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31430 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31431
31432 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31433- memset(bm_pte, 0, sizeof(bm_pte));
31434- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31435+ pmd_populate_user(&init_mm, pmd, bm_pte);
31436
31437 /*
31438 * The boot-ioremap range spans multiple pmds, for which
31439diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31440index d87dd6d..bf3fa66 100644
31441--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31442+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31443@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31444 * memory (e.g. tracked pages)? For now, we need this to avoid
31445 * invoking kmemcheck for PnP BIOS calls.
31446 */
31447- if (regs->flags & X86_VM_MASK)
31448+ if (v8086_mode(regs))
31449 return false;
31450- if (regs->cs != __KERNEL_CS)
31451+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31452 return false;
31453
31454 pte = kmemcheck_pte_lookup(address);
31455diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31456index 25e7e13..1964579 100644
31457--- a/arch/x86/mm/mmap.c
31458+++ b/arch/x86/mm/mmap.c
31459@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31460 * Leave an at least ~128 MB hole with possible stack randomization.
31461 */
31462 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31463-#define MAX_GAP (TASK_SIZE/6*5)
31464+#define MAX_GAP (pax_task_size/6*5)
31465
31466 static int mmap_is_legacy(void)
31467 {
31468@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31469 return rnd << PAGE_SHIFT;
31470 }
31471
31472-static unsigned long mmap_base(void)
31473+static unsigned long mmap_base(struct mm_struct *mm)
31474 {
31475 unsigned long gap = rlimit(RLIMIT_STACK);
31476+ unsigned long pax_task_size = TASK_SIZE;
31477+
31478+#ifdef CONFIG_PAX_SEGMEXEC
31479+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31480+ pax_task_size = SEGMEXEC_TASK_SIZE;
31481+#endif
31482
31483 if (gap < MIN_GAP)
31484 gap = MIN_GAP;
31485 else if (gap > MAX_GAP)
31486 gap = MAX_GAP;
31487
31488- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31489+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31490 }
31491
31492 /*
31493 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31494 * does, but not when emulating X86_32
31495 */
31496-static unsigned long mmap_legacy_base(void)
31497+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31498 {
31499- if (mmap_is_ia32())
31500+ if (mmap_is_ia32()) {
31501+
31502+#ifdef CONFIG_PAX_SEGMEXEC
31503+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31504+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31505+ else
31506+#endif
31507+
31508 return TASK_UNMAPPED_BASE;
31509- else
31510+ } else
31511 return TASK_UNMAPPED_BASE + mmap_rnd();
31512 }
31513
31514@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31515 */
31516 void arch_pick_mmap_layout(struct mm_struct *mm)
31517 {
31518- mm->mmap_legacy_base = mmap_legacy_base();
31519- mm->mmap_base = mmap_base();
31520+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31521+ mm->mmap_base = mmap_base(mm);
31522+
31523+#ifdef CONFIG_PAX_RANDMMAP
31524+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31525+ mm->mmap_legacy_base += mm->delta_mmap;
31526+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31527+ }
31528+#endif
31529
31530 if (mmap_is_legacy()) {
31531 mm->mmap_base = mm->mmap_legacy_base;
31532diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31533index 0057a7a..95c7edd 100644
31534--- a/arch/x86/mm/mmio-mod.c
31535+++ b/arch/x86/mm/mmio-mod.c
31536@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31537 break;
31538 default:
31539 {
31540- unsigned char *ip = (unsigned char *)instptr;
31541+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31542 my_trace->opcode = MMIO_UNKNOWN_OP;
31543 my_trace->width = 0;
31544 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31545@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31546 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31547 void __iomem *addr)
31548 {
31549- static atomic_t next_id;
31550+ static atomic_unchecked_t next_id;
31551 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31552 /* These are page-unaligned. */
31553 struct mmiotrace_map map = {
31554@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31555 .private = trace
31556 },
31557 .phys = offset,
31558- .id = atomic_inc_return(&next_id)
31559+ .id = atomic_inc_return_unchecked(&next_id)
31560 };
31561 map.map_id = trace->id;
31562
31563@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31564 ioremap_trace_core(offset, size, addr);
31565 }
31566
31567-static void iounmap_trace_core(volatile void __iomem *addr)
31568+static void iounmap_trace_core(const volatile void __iomem *addr)
31569 {
31570 struct mmiotrace_map map = {
31571 .phys = 0,
31572@@ -328,7 +328,7 @@ not_enabled:
31573 }
31574 }
31575
31576-void mmiotrace_iounmap(volatile void __iomem *addr)
31577+void mmiotrace_iounmap(const volatile void __iomem *addr)
31578 {
31579 might_sleep();
31580 if (is_enabled()) /* recheck and proper locking in *_core() */
31581diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31582index 8bf93ba..dbcd670 100644
31583--- a/arch/x86/mm/numa.c
31584+++ b/arch/x86/mm/numa.c
31585@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31586 return true;
31587 }
31588
31589-static int __init numa_register_memblks(struct numa_meminfo *mi)
31590+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31591 {
31592 unsigned long uninitialized_var(pfn_align);
31593 int i, nid;
31594diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31595index d0b1773..4c3327c 100644
31596--- a/arch/x86/mm/pageattr-test.c
31597+++ b/arch/x86/mm/pageattr-test.c
31598@@ -36,7 +36,7 @@ enum {
31599
31600 static int pte_testbit(pte_t pte)
31601 {
31602- return pte_flags(pte) & _PAGE_UNUSED1;
31603+ return pte_flags(pte) & _PAGE_CPA_TEST;
31604 }
31605
31606 struct split_state {
31607diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31608index bb32480..75f2f5e 100644
31609--- a/arch/x86/mm/pageattr.c
31610+++ b/arch/x86/mm/pageattr.c
31611@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31612 */
31613 #ifdef CONFIG_PCI_BIOS
31614 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31615- pgprot_val(forbidden) |= _PAGE_NX;
31616+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31617 #endif
31618
31619 /*
31620@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31621 * Does not cover __inittext since that is gone later on. On
31622 * 64bit we do not enforce !NX on the low mapping
31623 */
31624- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31625- pgprot_val(forbidden) |= _PAGE_NX;
31626+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31627+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31628
31629+#ifdef CONFIG_DEBUG_RODATA
31630 /*
31631 * The .rodata section needs to be read-only. Using the pfn
31632 * catches all aliases.
31633@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31634 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31635 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31636 pgprot_val(forbidden) |= _PAGE_RW;
31637+#endif
31638
31639 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31640 /*
31641@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31642 }
31643 #endif
31644
31645+#ifdef CONFIG_PAX_KERNEXEC
31646+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31647+ pgprot_val(forbidden) |= _PAGE_RW;
31648+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31649+ }
31650+#endif
31651+
31652 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31653
31654 return prot;
31655@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31656 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31657 {
31658 /* change init_mm */
31659+ pax_open_kernel();
31660 set_pte_atomic(kpte, pte);
31661+
31662 #ifdef CONFIG_X86_32
31663 if (!SHARED_KERNEL_PMD) {
31664+
31665+#ifdef CONFIG_PAX_PER_CPU_PGD
31666+ unsigned long cpu;
31667+#else
31668 struct page *page;
31669+#endif
31670
31671+#ifdef CONFIG_PAX_PER_CPU_PGD
31672+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31673+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31674+#else
31675 list_for_each_entry(page, &pgd_list, lru) {
31676- pgd_t *pgd;
31677+ pgd_t *pgd = (pgd_t *)page_address(page);
31678+#endif
31679+
31680 pud_t *pud;
31681 pmd_t *pmd;
31682
31683- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31684+ pgd += pgd_index(address);
31685 pud = pud_offset(pgd, address);
31686 pmd = pmd_offset(pud, address);
31687 set_pte_atomic((pte_t *)pmd, pte);
31688 }
31689 }
31690 #endif
31691+ pax_close_kernel();
31692 }
31693
31694 static int
31695diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31696index 6574388..87e9bef 100644
31697--- a/arch/x86/mm/pat.c
31698+++ b/arch/x86/mm/pat.c
31699@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31700
31701 if (!entry) {
31702 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31703- current->comm, current->pid, start, end - 1);
31704+ current->comm, task_pid_nr(current), start, end - 1);
31705 return -EINVAL;
31706 }
31707
31708@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31709
31710 while (cursor < to) {
31711 if (!devmem_is_allowed(pfn)) {
31712- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31713- current->comm, from, to - 1);
31714+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31715+ current->comm, from, to - 1, cursor);
31716 return 0;
31717 }
31718 cursor += PAGE_SIZE;
31719@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31720 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31721 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31722 "for [mem %#010Lx-%#010Lx]\n",
31723- current->comm, current->pid,
31724+ current->comm, task_pid_nr(current),
31725 cattr_name(flags),
31726 base, (unsigned long long)(base + size-1));
31727 return -EINVAL;
31728@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31729 flags = lookup_memtype(paddr);
31730 if (want_flags != flags) {
31731 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31732- current->comm, current->pid,
31733+ current->comm, task_pid_nr(current),
31734 cattr_name(want_flags),
31735 (unsigned long long)paddr,
31736 (unsigned long long)(paddr + size - 1),
31737@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31738 free_memtype(paddr, paddr + size);
31739 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31740 " for [mem %#010Lx-%#010Lx], got %s\n",
31741- current->comm, current->pid,
31742+ current->comm, task_pid_nr(current),
31743 cattr_name(want_flags),
31744 (unsigned long long)paddr,
31745 (unsigned long long)(paddr + size - 1),
31746diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31747index 415f6c4..d319983 100644
31748--- a/arch/x86/mm/pat_rbtree.c
31749+++ b/arch/x86/mm/pat_rbtree.c
31750@@ -160,7 +160,7 @@ success:
31751
31752 failure:
31753 printk(KERN_INFO "%s:%d conflicting memory types "
31754- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31755+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31756 end, cattr_name(found_type), cattr_name(match->type));
31757 return -EBUSY;
31758 }
31759diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31760index 9f0614d..92ae64a 100644
31761--- a/arch/x86/mm/pf_in.c
31762+++ b/arch/x86/mm/pf_in.c
31763@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31764 int i;
31765 enum reason_type rv = OTHERS;
31766
31767- p = (unsigned char *)ins_addr;
31768+ p = (unsigned char *)ktla_ktva(ins_addr);
31769 p += skip_prefix(p, &prf);
31770 p += get_opcode(p, &opcode);
31771
31772@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31773 struct prefix_bits prf;
31774 int i;
31775
31776- p = (unsigned char *)ins_addr;
31777+ p = (unsigned char *)ktla_ktva(ins_addr);
31778 p += skip_prefix(p, &prf);
31779 p += get_opcode(p, &opcode);
31780
31781@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31782 struct prefix_bits prf;
31783 int i;
31784
31785- p = (unsigned char *)ins_addr;
31786+ p = (unsigned char *)ktla_ktva(ins_addr);
31787 p += skip_prefix(p, &prf);
31788 p += get_opcode(p, &opcode);
31789
31790@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31791 struct prefix_bits prf;
31792 int i;
31793
31794- p = (unsigned char *)ins_addr;
31795+ p = (unsigned char *)ktla_ktva(ins_addr);
31796 p += skip_prefix(p, &prf);
31797 p += get_opcode(p, &opcode);
31798 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31799@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31800 struct prefix_bits prf;
31801 int i;
31802
31803- p = (unsigned char *)ins_addr;
31804+ p = (unsigned char *)ktla_ktva(ins_addr);
31805 p += skip_prefix(p, &prf);
31806 p += get_opcode(p, &opcode);
31807 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31808diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31809index dfa537a..fd45c64 100644
31810--- a/arch/x86/mm/pgtable.c
31811+++ b/arch/x86/mm/pgtable.c
31812@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31813 list_del(&page->lru);
31814 }
31815
31816-#define UNSHARED_PTRS_PER_PGD \
31817- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31818+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31819+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31820
31821+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31822+{
31823+ unsigned int count = USER_PGD_PTRS;
31824
31825+ if (!pax_user_shadow_base)
31826+ return;
31827+
31828+ while (count--)
31829+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31830+}
31831+#endif
31832+
31833+#ifdef CONFIG_PAX_PER_CPU_PGD
31834+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31835+{
31836+ unsigned int count = USER_PGD_PTRS;
31837+
31838+ while (count--) {
31839+ pgd_t pgd;
31840+
31841+#ifdef CONFIG_X86_64
31842+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31843+#else
31844+ pgd = *src++;
31845+#endif
31846+
31847+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31848+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31849+#endif
31850+
31851+ *dst++ = pgd;
31852+ }
31853+
31854+}
31855+#endif
31856+
31857+#ifdef CONFIG_X86_64
31858+#define pxd_t pud_t
31859+#define pyd_t pgd_t
31860+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31861+#define pxd_free(mm, pud) pud_free((mm), (pud))
31862+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31863+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31864+#define PYD_SIZE PGDIR_SIZE
31865+#else
31866+#define pxd_t pmd_t
31867+#define pyd_t pud_t
31868+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31869+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31870+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31871+#define pyd_offset(mm, address) pud_offset((mm), (address))
31872+#define PYD_SIZE PUD_SIZE
31873+#endif
31874+
31875+#ifdef CONFIG_PAX_PER_CPU_PGD
31876+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31877+static inline void pgd_dtor(pgd_t *pgd) {}
31878+#else
31879 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31880 {
31881 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31882@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31883 pgd_list_del(pgd);
31884 spin_unlock(&pgd_lock);
31885 }
31886+#endif
31887
31888 /*
31889 * List of all pgd's needed for non-PAE so it can invalidate entries
31890@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31891 * -- nyc
31892 */
31893
31894-#ifdef CONFIG_X86_PAE
31895+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31896 /*
31897 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31898 * updating the top-level pagetable entries to guarantee the
31899@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31900 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31901 * and initialize the kernel pmds here.
31902 */
31903-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31904+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31905
31906 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31907 {
31908@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31909 */
31910 flush_tlb_mm(mm);
31911 }
31912+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31913+#define PREALLOCATED_PXDS USER_PGD_PTRS
31914 #else /* !CONFIG_X86_PAE */
31915
31916 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31917-#define PREALLOCATED_PMDS 0
31918+#define PREALLOCATED_PXDS 0
31919
31920 #endif /* CONFIG_X86_PAE */
31921
31922-static void free_pmds(pmd_t *pmds[])
31923+static void free_pxds(pxd_t *pxds[])
31924 {
31925 int i;
31926
31927- for(i = 0; i < PREALLOCATED_PMDS; i++)
31928- if (pmds[i])
31929- free_page((unsigned long)pmds[i]);
31930+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31931+ if (pxds[i])
31932+ free_page((unsigned long)pxds[i]);
31933 }
31934
31935-static int preallocate_pmds(pmd_t *pmds[])
31936+static int preallocate_pxds(pxd_t *pxds[])
31937 {
31938 int i;
31939 bool failed = false;
31940
31941- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31942- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31943- if (pmd == NULL)
31944+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31945+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31946+ if (pxd == NULL)
31947 failed = true;
31948- pmds[i] = pmd;
31949+ pxds[i] = pxd;
31950 }
31951
31952 if (failed) {
31953- free_pmds(pmds);
31954+ free_pxds(pxds);
31955 return -ENOMEM;
31956 }
31957
31958@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31959 * preallocate which never got a corresponding vma will need to be
31960 * freed manually.
31961 */
31962-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31963+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31964 {
31965 int i;
31966
31967- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31968+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31969 pgd_t pgd = pgdp[i];
31970
31971 if (pgd_val(pgd) != 0) {
31972- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31973+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31974
31975- pgdp[i] = native_make_pgd(0);
31976+ set_pgd(pgdp + i, native_make_pgd(0));
31977
31978- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31979- pmd_free(mm, pmd);
31980+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31981+ pxd_free(mm, pxd);
31982 }
31983 }
31984 }
31985
31986-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31987+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31988 {
31989- pud_t *pud;
31990+ pyd_t *pyd;
31991 int i;
31992
31993- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31994+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31995 return;
31996
31997- pud = pud_offset(pgd, 0);
31998-
31999- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32000- pmd_t *pmd = pmds[i];
32001+#ifdef CONFIG_X86_64
32002+ pyd = pyd_offset(mm, 0L);
32003+#else
32004+ pyd = pyd_offset(pgd, 0L);
32005+#endif
32006
32007+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32008+ pxd_t *pxd = pxds[i];
32009 if (i >= KERNEL_PGD_BOUNDARY)
32010- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32011- sizeof(pmd_t) * PTRS_PER_PMD);
32012+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32013+ sizeof(pxd_t) * PTRS_PER_PMD);
32014
32015- pud_populate(mm, pud, pmd);
32016+ pyd_populate(mm, pyd, pxd);
32017 }
32018 }
32019
32020 pgd_t *pgd_alloc(struct mm_struct *mm)
32021 {
32022 pgd_t *pgd;
32023- pmd_t *pmds[PREALLOCATED_PMDS];
32024+ pxd_t *pxds[PREALLOCATED_PXDS];
32025
32026 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32027
32028@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32029
32030 mm->pgd = pgd;
32031
32032- if (preallocate_pmds(pmds) != 0)
32033+ if (preallocate_pxds(pxds) != 0)
32034 goto out_free_pgd;
32035
32036 if (paravirt_pgd_alloc(mm) != 0)
32037- goto out_free_pmds;
32038+ goto out_free_pxds;
32039
32040 /*
32041 * Make sure that pre-populating the pmds is atomic with
32042@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32043 spin_lock(&pgd_lock);
32044
32045 pgd_ctor(mm, pgd);
32046- pgd_prepopulate_pmd(mm, pgd, pmds);
32047+ pgd_prepopulate_pxd(mm, pgd, pxds);
32048
32049 spin_unlock(&pgd_lock);
32050
32051 return pgd;
32052
32053-out_free_pmds:
32054- free_pmds(pmds);
32055+out_free_pxds:
32056+ free_pxds(pxds);
32057 out_free_pgd:
32058 free_page((unsigned long)pgd);
32059 out:
32060@@ -300,7 +363,7 @@ out:
32061
32062 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32063 {
32064- pgd_mop_up_pmds(mm, pgd);
32065+ pgd_mop_up_pxds(mm, pgd);
32066 pgd_dtor(pgd);
32067 paravirt_pgd_free(mm, pgd);
32068 free_page((unsigned long)pgd);
32069diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32070index a69bcb8..19068ab 100644
32071--- a/arch/x86/mm/pgtable_32.c
32072+++ b/arch/x86/mm/pgtable_32.c
32073@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32074 return;
32075 }
32076 pte = pte_offset_kernel(pmd, vaddr);
32077+
32078+ pax_open_kernel();
32079 if (pte_val(pteval))
32080 set_pte_at(&init_mm, vaddr, pte, pteval);
32081 else
32082 pte_clear(&init_mm, vaddr, pte);
32083+ pax_close_kernel();
32084
32085 /*
32086 * It's enough to flush this one mapping.
32087diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32088index e666cbb..61788c45 100644
32089--- a/arch/x86/mm/physaddr.c
32090+++ b/arch/x86/mm/physaddr.c
32091@@ -10,7 +10,7 @@
32092 #ifdef CONFIG_X86_64
32093
32094 #ifdef CONFIG_DEBUG_VIRTUAL
32095-unsigned long __phys_addr(unsigned long x)
32096+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32097 {
32098 unsigned long y = x - __START_KERNEL_map;
32099
32100@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32101 #else
32102
32103 #ifdef CONFIG_DEBUG_VIRTUAL
32104-unsigned long __phys_addr(unsigned long x)
32105+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32106 {
32107 unsigned long phys_addr = x - PAGE_OFFSET;
32108 /* VMALLOC_* aren't constants */
32109diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32110index 90555bf..f5f1828 100644
32111--- a/arch/x86/mm/setup_nx.c
32112+++ b/arch/x86/mm/setup_nx.c
32113@@ -5,8 +5,10 @@
32114 #include <asm/pgtable.h>
32115 #include <asm/proto.h>
32116
32117+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32118 static int disable_nx;
32119
32120+#ifndef CONFIG_PAX_PAGEEXEC
32121 /*
32122 * noexec = on|off
32123 *
32124@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32125 return 0;
32126 }
32127 early_param("noexec", noexec_setup);
32128+#endif
32129+
32130+#endif
32131
32132 void x86_configure_nx(void)
32133 {
32134+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32135 if (cpu_has_nx && !disable_nx)
32136 __supported_pte_mask |= _PAGE_NX;
32137 else
32138+#endif
32139 __supported_pte_mask &= ~_PAGE_NX;
32140 }
32141
32142diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32143index 282375f..e03a98f 100644
32144--- a/arch/x86/mm/tlb.c
32145+++ b/arch/x86/mm/tlb.c
32146@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32147 BUG();
32148 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32149 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32150+
32151+#ifndef CONFIG_PAX_PER_CPU_PGD
32152 load_cr3(swapper_pg_dir);
32153+#endif
32154+
32155 }
32156 }
32157 EXPORT_SYMBOL_GPL(leave_mm);
32158diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32159new file mode 100644
32160index 0000000..dace51c
32161--- /dev/null
32162+++ b/arch/x86/mm/uderef_64.c
32163@@ -0,0 +1,37 @@
32164+#include <linux/mm.h>
32165+#include <asm/pgtable.h>
32166+#include <asm/uaccess.h>
32167+
32168+#ifdef CONFIG_PAX_MEMORY_UDEREF
32169+/* PaX: due to the special call convention these functions must
32170+ * - remain leaf functions under all configurations,
32171+ * - never be called directly, only dereferenced from the wrappers.
32172+ */
32173+void __pax_open_userland(void)
32174+{
32175+ unsigned int cpu;
32176+
32177+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32178+ return;
32179+
32180+ cpu = raw_get_cpu();
32181+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32182+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32183+ raw_put_cpu_no_resched();
32184+}
32185+EXPORT_SYMBOL(__pax_open_userland);
32186+
32187+void __pax_close_userland(void)
32188+{
32189+ unsigned int cpu;
32190+
32191+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32192+ return;
32193+
32194+ cpu = raw_get_cpu();
32195+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32196+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32197+ raw_put_cpu_no_resched();
32198+}
32199+EXPORT_SYMBOL(__pax_close_userland);
32200+#endif
32201diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32202index 877b9a1..a8ecf42 100644
32203--- a/arch/x86/net/bpf_jit.S
32204+++ b/arch/x86/net/bpf_jit.S
32205@@ -9,6 +9,7 @@
32206 */
32207 #include <linux/linkage.h>
32208 #include <asm/dwarf2.h>
32209+#include <asm/alternative-asm.h>
32210
32211 /*
32212 * Calling convention :
32213@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32214 jle bpf_slow_path_word
32215 mov (SKBDATA,%rsi),%eax
32216 bswap %eax /* ntohl() */
32217+ pax_force_retaddr
32218 ret
32219
32220 sk_load_half:
32221@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32222 jle bpf_slow_path_half
32223 movzwl (SKBDATA,%rsi),%eax
32224 rol $8,%ax # ntohs()
32225+ pax_force_retaddr
32226 ret
32227
32228 sk_load_byte:
32229@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32230 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32231 jle bpf_slow_path_byte
32232 movzbl (SKBDATA,%rsi),%eax
32233+ pax_force_retaddr
32234 ret
32235
32236 /**
32237@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32238 movzbl (SKBDATA,%rsi),%ebx
32239 and $15,%bl
32240 shl $2,%bl
32241+ pax_force_retaddr
32242 ret
32243
32244 /* rsi contains offset and can be scratched */
32245@@ -109,6 +114,7 @@ bpf_slow_path_word:
32246 js bpf_error
32247 mov -12(%rbp),%eax
32248 bswap %eax
32249+ pax_force_retaddr
32250 ret
32251
32252 bpf_slow_path_half:
32253@@ -117,12 +123,14 @@ bpf_slow_path_half:
32254 mov -12(%rbp),%ax
32255 rol $8,%ax
32256 movzwl %ax,%eax
32257+ pax_force_retaddr
32258 ret
32259
32260 bpf_slow_path_byte:
32261 bpf_slow_path_common(1)
32262 js bpf_error
32263 movzbl -12(%rbp),%eax
32264+ pax_force_retaddr
32265 ret
32266
32267 bpf_slow_path_byte_msh:
32268@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32269 and $15,%al
32270 shl $2,%al
32271 xchg %eax,%ebx
32272+ pax_force_retaddr
32273 ret
32274
32275 #define sk_negative_common(SIZE) \
32276@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32277 sk_negative_common(4)
32278 mov (%rax), %eax
32279 bswap %eax
32280+ pax_force_retaddr
32281 ret
32282
32283 bpf_slow_path_half_neg:
32284@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32285 mov (%rax),%ax
32286 rol $8,%ax
32287 movzwl %ax,%eax
32288+ pax_force_retaddr
32289 ret
32290
32291 bpf_slow_path_byte_neg:
32292@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32293 .globl sk_load_byte_negative_offset
32294 sk_negative_common(1)
32295 movzbl (%rax), %eax
32296+ pax_force_retaddr
32297 ret
32298
32299 bpf_slow_path_byte_msh_neg:
32300@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32301 and $15,%al
32302 shl $2,%al
32303 xchg %eax,%ebx
32304+ pax_force_retaddr
32305 ret
32306
32307 bpf_error:
32308@@ -197,4 +210,5 @@ bpf_error:
32309 xor %eax,%eax
32310 mov -8(%rbp),%rbx
32311 leaveq
32312+ pax_force_retaddr
32313 ret
32314diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32315index 79c216a..08d39cc 100644
32316--- a/arch/x86/net/bpf_jit_comp.c
32317+++ b/arch/x86/net/bpf_jit_comp.c
32318@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32319 return ptr + len;
32320 }
32321
32322+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32323+#define MAX_INSTR_CODE_SIZE 96
32324+#else
32325+#define MAX_INSTR_CODE_SIZE 64
32326+#endif
32327+
32328 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32329
32330 #define EMIT1(b1) EMIT(b1, 1)
32331 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32332 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32333 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32334+
32335+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32336+/* original constant will appear in ecx */
32337+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32338+do { \
32339+ /* mov ecx, randkey */ \
32340+ EMIT1(0xb9); \
32341+ EMIT(_key, 4); \
32342+ /* xor ecx, randkey ^ off */ \
32343+ EMIT2(0x81, 0xf1); \
32344+ EMIT((_key) ^ (_off), 4); \
32345+} while (0)
32346+
32347+#define EMIT1_off32(b1, _off) \
32348+do { \
32349+ switch (b1) { \
32350+ case 0x05: /* add eax, imm32 */ \
32351+ case 0x2d: /* sub eax, imm32 */ \
32352+ case 0x25: /* and eax, imm32 */ \
32353+ case 0x0d: /* or eax, imm32 */ \
32354+ case 0xb8: /* mov eax, imm32 */ \
32355+ case 0x35: /* xor eax, imm32 */ \
32356+ case 0x3d: /* cmp eax, imm32 */ \
32357+ case 0xa9: /* test eax, imm32 */ \
32358+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32359+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32360+ break; \
32361+ case 0xbb: /* mov ebx, imm32 */ \
32362+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32363+ /* mov ebx, ecx */ \
32364+ EMIT2(0x89, 0xcb); \
32365+ break; \
32366+ case 0xbe: /* mov esi, imm32 */ \
32367+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32368+ /* mov esi, ecx */ \
32369+ EMIT2(0x89, 0xce); \
32370+ break; \
32371+ case 0xe8: /* call rel imm32, always to known funcs */ \
32372+ EMIT1(b1); \
32373+ EMIT(_off, 4); \
32374+ break; \
32375+ case 0xe9: /* jmp rel imm32 */ \
32376+ EMIT1(b1); \
32377+ EMIT(_off, 4); \
32378+ /* prevent fall-through, we're not called if off = 0 */ \
32379+ EMIT(0xcccccccc, 4); \
32380+ EMIT(0xcccccccc, 4); \
32381+ break; \
32382+ default: \
32383+ BUILD_BUG(); \
32384+ } \
32385+} while (0)
32386+
32387+#define EMIT2_off32(b1, b2, _off) \
32388+do { \
32389+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32390+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32391+ EMIT(randkey, 4); \
32392+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32393+ EMIT((_off) - randkey, 4); \
32394+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32395+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32396+ /* imul eax, ecx */ \
32397+ EMIT3(0x0f, 0xaf, 0xc1); \
32398+ } else { \
32399+ BUILD_BUG(); \
32400+ } \
32401+} while (0)
32402+#else
32403 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32404+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32405+#endif
32406
32407 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32408 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32409@@ -91,6 +168,24 @@ do { \
32410 #define X86_JBE 0x76
32411 #define X86_JA 0x77
32412
32413+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32414+#define APPEND_FLOW_VERIFY() \
32415+do { \
32416+ /* mov ecx, randkey */ \
32417+ EMIT1(0xb9); \
32418+ EMIT(randkey, 4); \
32419+ /* cmp ecx, randkey */ \
32420+ EMIT2(0x81, 0xf9); \
32421+ EMIT(randkey, 4); \
32422+ /* jz after 8 int 3s */ \
32423+ EMIT2(0x74, 0x08); \
32424+ EMIT(0xcccccccc, 4); \
32425+ EMIT(0xcccccccc, 4); \
32426+} while (0)
32427+#else
32428+#define APPEND_FLOW_VERIFY() do { } while (0)
32429+#endif
32430+
32431 #define EMIT_COND_JMP(op, offset) \
32432 do { \
32433 if (is_near(offset)) \
32434@@ -98,6 +193,7 @@ do { \
32435 else { \
32436 EMIT2(0x0f, op + 0x10); \
32437 EMIT(offset, 4); /* jxx .+off32 */ \
32438+ APPEND_FLOW_VERIFY(); \
32439 } \
32440 } while (0)
32441
32442@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32443 return -1;
32444 }
32445
32446-struct bpf_binary_header {
32447- unsigned int pages;
32448- /* Note : for security reasons, bpf code will follow a randomly
32449- * sized amount of int3 instructions
32450- */
32451- u8 image[];
32452-};
32453-
32454-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32455+/* Note : for security reasons, bpf code will follow a randomly
32456+ * sized amount of int3 instructions
32457+ */
32458+static u8 *bpf_alloc_binary(unsigned int proglen,
32459 u8 **image_ptr)
32460 {
32461 unsigned int sz, hole;
32462- struct bpf_binary_header *header;
32463+ u8 *header;
32464
32465 /* Most of BPF filters are really small,
32466 * but if some of them fill a page, allow at least
32467 * 128 extra bytes to insert a random section of int3
32468 */
32469- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32470- header = module_alloc(sz);
32471+ sz = round_up(proglen + 128, PAGE_SIZE);
32472+ header = module_alloc_exec(sz);
32473 if (!header)
32474 return NULL;
32475
32476+ pax_open_kernel();
32477 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32478+ pax_close_kernel();
32479
32480- header->pages = sz / PAGE_SIZE;
32481- hole = sz - (proglen + sizeof(*header));
32482+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32483
32484 /* insert a random number of int3 instructions before BPF code */
32485- *image_ptr = &header->image[prandom_u32() % hole];
32486+ *image_ptr = &header[prandom_u32() % hole];
32487 return header;
32488 }
32489
32490 void bpf_jit_compile(struct sk_filter *fp)
32491 {
32492- u8 temp[64];
32493+ u8 temp[MAX_INSTR_CODE_SIZE];
32494 u8 *prog;
32495 unsigned int proglen, oldproglen = 0;
32496 int ilen, i;
32497 int t_offset, f_offset;
32498 u8 t_op, f_op, seen = 0, pass;
32499 u8 *image = NULL;
32500- struct bpf_binary_header *header = NULL;
32501+ u8 *header = NULL;
32502 u8 *func;
32503 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32504 unsigned int cleanup_addr; /* epilogue code offset */
32505 unsigned int *addrs;
32506 const struct sock_filter *filter = fp->insns;
32507 int flen = fp->len;
32508+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32509+ unsigned int randkey;
32510+#endif
32511
32512 if (!bpf_jit_enable)
32513 return;
32514@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32515 if (addrs == NULL)
32516 return;
32517
32518+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32519+ randkey = get_random_int();
32520+#endif
32521+
32522 /* Before first pass, make a rough estimation of addrs[]
32523- * each bpf instruction is translated to less than 64 bytes
32524+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32525 */
32526 for (proglen = 0, i = 0; i < flen; i++) {
32527- proglen += 64;
32528+ proglen += MAX_INSTR_CODE_SIZE;
32529 addrs[i] = proglen;
32530 }
32531 cleanup_addr = proglen; /* epilogue address */
32532@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32533 case BPF_S_ALU_MUL_K: /* A *= K */
32534 if (is_imm8(K))
32535 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32536- else {
32537- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32538- EMIT(K, 4);
32539- }
32540+ else
32541+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32542 break;
32543 case BPF_S_ALU_DIV_X: /* A /= X; */
32544 seen |= SEEN_XREG;
32545@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32546 break;
32547 case BPF_S_ALU_MOD_K: /* A %= K; */
32548 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32549+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32550+ DILUTE_CONST_SEQUENCE(K, randkey);
32551+#else
32552 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32553+#endif
32554 EMIT2(0xf7, 0xf1); /* div %ecx */
32555 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32556 break;
32557 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32558+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32559+ DILUTE_CONST_SEQUENCE(K, randkey);
32560+ // imul rax, rcx
32561+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32562+#else
32563 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32564 EMIT(K, 4);
32565+#endif
32566 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32567 break;
32568 case BPF_S_ALU_AND_X:
32569@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32570 if (is_imm8(K)) {
32571 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32572 } else {
32573- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32574- EMIT(K, 4);
32575+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32576 }
32577 } else {
32578 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32579@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32580 if (unlikely(proglen + ilen > oldproglen)) {
32581 pr_err("bpb_jit_compile fatal error\n");
32582 kfree(addrs);
32583- module_free(NULL, header);
32584+ module_free_exec(NULL, image);
32585 return;
32586 }
32587+ pax_open_kernel();
32588 memcpy(image + proglen, temp, ilen);
32589+ pax_close_kernel();
32590 }
32591 proglen += ilen;
32592 addrs[i] = proglen;
32593@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32594
32595 if (image) {
32596 bpf_flush_icache(header, image + proglen);
32597- set_memory_ro((unsigned long)header, header->pages);
32598 fp->bpf_func = (void *)image;
32599 }
32600 out:
32601@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32602 {
32603 if (fp->bpf_func != sk_run_filter) {
32604 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32605- struct bpf_binary_header *header = (void *)addr;
32606-
32607- set_memory_rw(addr, header->pages);
32608- module_free(NULL, header);
32609+ set_memory_rw(addr, 1);
32610+ module_free_exec(NULL, (void *)addr);
32611 }
32612 }
32613diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32614index d6aa6e8..266395a 100644
32615--- a/arch/x86/oprofile/backtrace.c
32616+++ b/arch/x86/oprofile/backtrace.c
32617@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32618 struct stack_frame_ia32 *fp;
32619 unsigned long bytes;
32620
32621- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32622+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32623 if (bytes != sizeof(bufhead))
32624 return NULL;
32625
32626- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32627+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32628
32629 oprofile_add_trace(bufhead[0].return_address);
32630
32631@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32632 struct stack_frame bufhead[2];
32633 unsigned long bytes;
32634
32635- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32636+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32637 if (bytes != sizeof(bufhead))
32638 return NULL;
32639
32640@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32641 {
32642 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32643
32644- if (!user_mode_vm(regs)) {
32645+ if (!user_mode(regs)) {
32646 unsigned long stack = kernel_stack_pointer(regs);
32647 if (depth)
32648 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32649diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32650index 48768df..ba9143c 100644
32651--- a/arch/x86/oprofile/nmi_int.c
32652+++ b/arch/x86/oprofile/nmi_int.c
32653@@ -23,6 +23,7 @@
32654 #include <asm/nmi.h>
32655 #include <asm/msr.h>
32656 #include <asm/apic.h>
32657+#include <asm/pgtable.h>
32658
32659 #include "op_counter.h"
32660 #include "op_x86_model.h"
32661@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32662 if (ret)
32663 return ret;
32664
32665- if (!model->num_virt_counters)
32666- model->num_virt_counters = model->num_counters;
32667+ if (!model->num_virt_counters) {
32668+ pax_open_kernel();
32669+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32670+ pax_close_kernel();
32671+ }
32672
32673 mux_init(ops);
32674
32675diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32676index b2b9443..be58856 100644
32677--- a/arch/x86/oprofile/op_model_amd.c
32678+++ b/arch/x86/oprofile/op_model_amd.c
32679@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32680 num_counters = AMD64_NUM_COUNTERS;
32681 }
32682
32683- op_amd_spec.num_counters = num_counters;
32684- op_amd_spec.num_controls = num_counters;
32685- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32686+ pax_open_kernel();
32687+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32688+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32689+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32690+ pax_close_kernel();
32691
32692 return 0;
32693 }
32694diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32695index d90528e..0127e2b 100644
32696--- a/arch/x86/oprofile/op_model_ppro.c
32697+++ b/arch/x86/oprofile/op_model_ppro.c
32698@@ -19,6 +19,7 @@
32699 #include <asm/msr.h>
32700 #include <asm/apic.h>
32701 #include <asm/nmi.h>
32702+#include <asm/pgtable.h>
32703
32704 #include "op_x86_model.h"
32705 #include "op_counter.h"
32706@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32707
32708 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32709
32710- op_arch_perfmon_spec.num_counters = num_counters;
32711- op_arch_perfmon_spec.num_controls = num_counters;
32712+ pax_open_kernel();
32713+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32714+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32715+ pax_close_kernel();
32716 }
32717
32718 static int arch_perfmon_init(struct oprofile_operations *ignore)
32719diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32720index 71e8a67..6a313bb 100644
32721--- a/arch/x86/oprofile/op_x86_model.h
32722+++ b/arch/x86/oprofile/op_x86_model.h
32723@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32724 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32725 struct op_msrs const * const msrs);
32726 #endif
32727-};
32728+} __do_const;
32729
32730 struct op_counter_config;
32731
32732diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32733index 372e9b8..e775a6c 100644
32734--- a/arch/x86/pci/irq.c
32735+++ b/arch/x86/pci/irq.c
32736@@ -50,7 +50,7 @@ struct irq_router {
32737 struct irq_router_handler {
32738 u16 vendor;
32739 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32740-};
32741+} __do_const;
32742
32743 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32744 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32745@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32746 return 0;
32747 }
32748
32749-static __initdata struct irq_router_handler pirq_routers[] = {
32750+static __initconst const struct irq_router_handler pirq_routers[] = {
32751 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32752 { PCI_VENDOR_ID_AL, ali_router_probe },
32753 { PCI_VENDOR_ID_ITE, ite_router_probe },
32754@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32755 static void __init pirq_find_router(struct irq_router *r)
32756 {
32757 struct irq_routing_table *rt = pirq_table;
32758- struct irq_router_handler *h;
32759+ const struct irq_router_handler *h;
32760
32761 #ifdef CONFIG_PCI_BIOS
32762 if (!rt->signature) {
32763@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32764 return 0;
32765 }
32766
32767-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32768+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32769 {
32770 .callback = fix_broken_hp_bios_irq9,
32771 .ident = "HP Pavilion N5400 Series Laptop",
32772diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32773index 6eb18c4..20d83de 100644
32774--- a/arch/x86/pci/mrst.c
32775+++ b/arch/x86/pci/mrst.c
32776@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32777 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32778 pci_mmcfg_late_init();
32779 pcibios_enable_irq = mrst_pci_irq_enable;
32780- pci_root_ops = pci_mrst_ops;
32781+ pax_open_kernel();
32782+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32783+ pax_close_kernel();
32784 pci_soc_mode = 1;
32785 /* Continue with standard init */
32786 return 1;
32787diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32788index c77b24a..c979855 100644
32789--- a/arch/x86/pci/pcbios.c
32790+++ b/arch/x86/pci/pcbios.c
32791@@ -79,7 +79,7 @@ union bios32 {
32792 static struct {
32793 unsigned long address;
32794 unsigned short segment;
32795-} bios32_indirect = { 0, __KERNEL_CS };
32796+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32797
32798 /*
32799 * Returns the entry point for the given service, NULL on error
32800@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32801 unsigned long length; /* %ecx */
32802 unsigned long entry; /* %edx */
32803 unsigned long flags;
32804+ struct desc_struct d, *gdt;
32805
32806 local_irq_save(flags);
32807- __asm__("lcall *(%%edi); cld"
32808+
32809+ gdt = get_cpu_gdt_table(smp_processor_id());
32810+
32811+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32812+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32813+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32814+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32815+
32816+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32817 : "=a" (return_code),
32818 "=b" (address),
32819 "=c" (length),
32820 "=d" (entry)
32821 : "0" (service),
32822 "1" (0),
32823- "D" (&bios32_indirect));
32824+ "D" (&bios32_indirect),
32825+ "r"(__PCIBIOS_DS)
32826+ : "memory");
32827+
32828+ pax_open_kernel();
32829+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32830+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32831+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32832+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32833+ pax_close_kernel();
32834+
32835 local_irq_restore(flags);
32836
32837 switch (return_code) {
32838- case 0:
32839- return address + entry;
32840- case 0x80: /* Not present */
32841- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32842- return 0;
32843- default: /* Shouldn't happen */
32844- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32845- service, return_code);
32846+ case 0: {
32847+ int cpu;
32848+ unsigned char flags;
32849+
32850+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32851+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32852+ printk(KERN_WARNING "bios32_service: not valid\n");
32853 return 0;
32854+ }
32855+ address = address + PAGE_OFFSET;
32856+ length += 16UL; /* some BIOSs underreport this... */
32857+ flags = 4;
32858+ if (length >= 64*1024*1024) {
32859+ length >>= PAGE_SHIFT;
32860+ flags |= 8;
32861+ }
32862+
32863+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32864+ gdt = get_cpu_gdt_table(cpu);
32865+ pack_descriptor(&d, address, length, 0x9b, flags);
32866+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32867+ pack_descriptor(&d, address, length, 0x93, flags);
32868+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32869+ }
32870+ return entry;
32871+ }
32872+ case 0x80: /* Not present */
32873+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32874+ return 0;
32875+ default: /* Shouldn't happen */
32876+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32877+ service, return_code);
32878+ return 0;
32879 }
32880 }
32881
32882 static struct {
32883 unsigned long address;
32884 unsigned short segment;
32885-} pci_indirect = { 0, __KERNEL_CS };
32886+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32887
32888-static int pci_bios_present;
32889+static int pci_bios_present __read_only;
32890
32891 static int check_pcibios(void)
32892 {
32893@@ -131,11 +174,13 @@ static int check_pcibios(void)
32894 unsigned long flags, pcibios_entry;
32895
32896 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32897- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32898+ pci_indirect.address = pcibios_entry;
32899
32900 local_irq_save(flags);
32901- __asm__(
32902- "lcall *(%%edi); cld\n\t"
32903+ __asm__("movw %w6, %%ds\n\t"
32904+ "lcall *%%ss:(%%edi); cld\n\t"
32905+ "push %%ss\n\t"
32906+ "pop %%ds\n\t"
32907 "jc 1f\n\t"
32908 "xor %%ah, %%ah\n"
32909 "1:"
32910@@ -144,7 +189,8 @@ static int check_pcibios(void)
32911 "=b" (ebx),
32912 "=c" (ecx)
32913 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32914- "D" (&pci_indirect)
32915+ "D" (&pci_indirect),
32916+ "r" (__PCIBIOS_DS)
32917 : "memory");
32918 local_irq_restore(flags);
32919
32920@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32921
32922 switch (len) {
32923 case 1:
32924- __asm__("lcall *(%%esi); cld\n\t"
32925+ __asm__("movw %w6, %%ds\n\t"
32926+ "lcall *%%ss:(%%esi); cld\n\t"
32927+ "push %%ss\n\t"
32928+ "pop %%ds\n\t"
32929 "jc 1f\n\t"
32930 "xor %%ah, %%ah\n"
32931 "1:"
32932@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32933 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32934 "b" (bx),
32935 "D" ((long)reg),
32936- "S" (&pci_indirect));
32937+ "S" (&pci_indirect),
32938+ "r" (__PCIBIOS_DS));
32939 /*
32940 * Zero-extend the result beyond 8 bits, do not trust the
32941 * BIOS having done it:
32942@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32943 *value &= 0xff;
32944 break;
32945 case 2:
32946- __asm__("lcall *(%%esi); cld\n\t"
32947+ __asm__("movw %w6, %%ds\n\t"
32948+ "lcall *%%ss:(%%esi); cld\n\t"
32949+ "push %%ss\n\t"
32950+ "pop %%ds\n\t"
32951 "jc 1f\n\t"
32952 "xor %%ah, %%ah\n"
32953 "1:"
32954@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32955 : "1" (PCIBIOS_READ_CONFIG_WORD),
32956 "b" (bx),
32957 "D" ((long)reg),
32958- "S" (&pci_indirect));
32959+ "S" (&pci_indirect),
32960+ "r" (__PCIBIOS_DS));
32961 /*
32962 * Zero-extend the result beyond 16 bits, do not trust the
32963 * BIOS having done it:
32964@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32965 *value &= 0xffff;
32966 break;
32967 case 4:
32968- __asm__("lcall *(%%esi); cld\n\t"
32969+ __asm__("movw %w6, %%ds\n\t"
32970+ "lcall *%%ss:(%%esi); cld\n\t"
32971+ "push %%ss\n\t"
32972+ "pop %%ds\n\t"
32973 "jc 1f\n\t"
32974 "xor %%ah, %%ah\n"
32975 "1:"
32976@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32977 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32978 "b" (bx),
32979 "D" ((long)reg),
32980- "S" (&pci_indirect));
32981+ "S" (&pci_indirect),
32982+ "r" (__PCIBIOS_DS));
32983 break;
32984 }
32985
32986@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32987
32988 switch (len) {
32989 case 1:
32990- __asm__("lcall *(%%esi); cld\n\t"
32991+ __asm__("movw %w6, %%ds\n\t"
32992+ "lcall *%%ss:(%%esi); cld\n\t"
32993+ "push %%ss\n\t"
32994+ "pop %%ds\n\t"
32995 "jc 1f\n\t"
32996 "xor %%ah, %%ah\n"
32997 "1:"
32998@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32999 "c" (value),
33000 "b" (bx),
33001 "D" ((long)reg),
33002- "S" (&pci_indirect));
33003+ "S" (&pci_indirect),
33004+ "r" (__PCIBIOS_DS));
33005 break;
33006 case 2:
33007- __asm__("lcall *(%%esi); cld\n\t"
33008+ __asm__("movw %w6, %%ds\n\t"
33009+ "lcall *%%ss:(%%esi); cld\n\t"
33010+ "push %%ss\n\t"
33011+ "pop %%ds\n\t"
33012 "jc 1f\n\t"
33013 "xor %%ah, %%ah\n"
33014 "1:"
33015@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33016 "c" (value),
33017 "b" (bx),
33018 "D" ((long)reg),
33019- "S" (&pci_indirect));
33020+ "S" (&pci_indirect),
33021+ "r" (__PCIBIOS_DS));
33022 break;
33023 case 4:
33024- __asm__("lcall *(%%esi); cld\n\t"
33025+ __asm__("movw %w6, %%ds\n\t"
33026+ "lcall *%%ss:(%%esi); cld\n\t"
33027+ "push %%ss\n\t"
33028+ "pop %%ds\n\t"
33029 "jc 1f\n\t"
33030 "xor %%ah, %%ah\n"
33031 "1:"
33032@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33033 "c" (value),
33034 "b" (bx),
33035 "D" ((long)reg),
33036- "S" (&pci_indirect));
33037+ "S" (&pci_indirect),
33038+ "r" (__PCIBIOS_DS));
33039 break;
33040 }
33041
33042@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33043
33044 DBG("PCI: Fetching IRQ routing table... ");
33045 __asm__("push %%es\n\t"
33046+ "movw %w8, %%ds\n\t"
33047 "push %%ds\n\t"
33048 "pop %%es\n\t"
33049- "lcall *(%%esi); cld\n\t"
33050+ "lcall *%%ss:(%%esi); cld\n\t"
33051 "pop %%es\n\t"
33052+ "push %%ss\n\t"
33053+ "pop %%ds\n"
33054 "jc 1f\n\t"
33055 "xor %%ah, %%ah\n"
33056 "1:"
33057@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33058 "1" (0),
33059 "D" ((long) &opt),
33060 "S" (&pci_indirect),
33061- "m" (opt)
33062+ "m" (opt),
33063+ "r" (__PCIBIOS_DS)
33064 : "memory");
33065 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33066 if (ret & 0xff00)
33067@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33068 {
33069 int ret;
33070
33071- __asm__("lcall *(%%esi); cld\n\t"
33072+ __asm__("movw %w5, %%ds\n\t"
33073+ "lcall *%%ss:(%%esi); cld\n\t"
33074+ "push %%ss\n\t"
33075+ "pop %%ds\n"
33076 "jc 1f\n\t"
33077 "xor %%ah, %%ah\n"
33078 "1:"
33079@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33080 : "0" (PCIBIOS_SET_PCI_HW_INT),
33081 "b" ((dev->bus->number << 8) | dev->devfn),
33082 "c" ((irq << 8) | (pin + 10)),
33083- "S" (&pci_indirect));
33084+ "S" (&pci_indirect),
33085+ "r" (__PCIBIOS_DS));
33086 return !(ret & 0xff00);
33087 }
33088 EXPORT_SYMBOL(pcibios_set_irq_routing);
33089diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33090index 40e4469..d915bf9 100644
33091--- a/arch/x86/platform/efi/efi_32.c
33092+++ b/arch/x86/platform/efi/efi_32.c
33093@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33094 {
33095 struct desc_ptr gdt_descr;
33096
33097+#ifdef CONFIG_PAX_KERNEXEC
33098+ struct desc_struct d;
33099+#endif
33100+
33101 local_irq_save(efi_rt_eflags);
33102
33103 load_cr3(initial_page_table);
33104 __flush_tlb_all();
33105
33106+#ifdef CONFIG_PAX_KERNEXEC
33107+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33108+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33109+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33110+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33111+#endif
33112+
33113 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33114 gdt_descr.size = GDT_SIZE - 1;
33115 load_gdt(&gdt_descr);
33116@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33117 {
33118 struct desc_ptr gdt_descr;
33119
33120+#ifdef CONFIG_PAX_KERNEXEC
33121+ struct desc_struct d;
33122+
33123+ memset(&d, 0, sizeof d);
33124+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33125+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33126+#endif
33127+
33128 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33129 gdt_descr.size = GDT_SIZE - 1;
33130 load_gdt(&gdt_descr);
33131
33132+#ifdef CONFIG_PAX_PER_CPU_PGD
33133+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33134+#else
33135 load_cr3(swapper_pg_dir);
33136+#endif
33137+
33138 __flush_tlb_all();
33139
33140 local_irq_restore(efi_rt_eflags);
33141diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33142index 39a0e7f1..872396e 100644
33143--- a/arch/x86/platform/efi/efi_64.c
33144+++ b/arch/x86/platform/efi/efi_64.c
33145@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33146 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33147 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33148 }
33149+
33150+#ifdef CONFIG_PAX_PER_CPU_PGD
33151+ load_cr3(swapper_pg_dir);
33152+#endif
33153+
33154 __flush_tlb_all();
33155 }
33156
33157@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33158 for (pgd = 0; pgd < n_pgds; pgd++)
33159 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33160 kfree(save_pgd);
33161+
33162+#ifdef CONFIG_PAX_PER_CPU_PGD
33163+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33164+#endif
33165+
33166 __flush_tlb_all();
33167 local_irq_restore(efi_flags);
33168 early_code_mapping_set_exec(0);
33169diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33170index fbe66e6..eae5e38 100644
33171--- a/arch/x86/platform/efi/efi_stub_32.S
33172+++ b/arch/x86/platform/efi/efi_stub_32.S
33173@@ -6,7 +6,9 @@
33174 */
33175
33176 #include <linux/linkage.h>
33177+#include <linux/init.h>
33178 #include <asm/page_types.h>
33179+#include <asm/segment.h>
33180
33181 /*
33182 * efi_call_phys(void *, ...) is a function with variable parameters.
33183@@ -20,7 +22,7 @@
33184 * service functions will comply with gcc calling convention, too.
33185 */
33186
33187-.text
33188+__INIT
33189 ENTRY(efi_call_phys)
33190 /*
33191 * 0. The function can only be called in Linux kernel. So CS has been
33192@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33193 * The mapping of lower virtual memory has been created in prelog and
33194 * epilog.
33195 */
33196- movl $1f, %edx
33197- subl $__PAGE_OFFSET, %edx
33198- jmp *%edx
33199+#ifdef CONFIG_PAX_KERNEXEC
33200+ movl $(__KERNEXEC_EFI_DS), %edx
33201+ mov %edx, %ds
33202+ mov %edx, %es
33203+ mov %edx, %ss
33204+ addl $2f,(1f)
33205+ ljmp *(1f)
33206+
33207+__INITDATA
33208+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33209+.previous
33210+
33211+2:
33212+ subl $2b,(1b)
33213+#else
33214+ jmp 1f-__PAGE_OFFSET
33215 1:
33216+#endif
33217
33218 /*
33219 * 2. Now on the top of stack is the return
33220@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33221 * parameter 2, ..., param n. To make things easy, we save the return
33222 * address of efi_call_phys in a global variable.
33223 */
33224- popl %edx
33225- movl %edx, saved_return_addr
33226- /* get the function pointer into ECX*/
33227- popl %ecx
33228- movl %ecx, efi_rt_function_ptr
33229- movl $2f, %edx
33230- subl $__PAGE_OFFSET, %edx
33231- pushl %edx
33232+ popl (saved_return_addr)
33233+ popl (efi_rt_function_ptr)
33234
33235 /*
33236 * 3. Clear PG bit in %CR0.
33237@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33238 /*
33239 * 5. Call the physical function.
33240 */
33241- jmp *%ecx
33242+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33243
33244-2:
33245 /*
33246 * 6. After EFI runtime service returns, control will return to
33247 * following instruction. We'd better readjust stack pointer first.
33248@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33249 movl %cr0, %edx
33250 orl $0x80000000, %edx
33251 movl %edx, %cr0
33252- jmp 1f
33253-1:
33254+
33255 /*
33256 * 8. Now restore the virtual mode from flat mode by
33257 * adding EIP with PAGE_OFFSET.
33258 */
33259- movl $1f, %edx
33260- jmp *%edx
33261+#ifdef CONFIG_PAX_KERNEXEC
33262+ movl $(__KERNEL_DS), %edx
33263+ mov %edx, %ds
33264+ mov %edx, %es
33265+ mov %edx, %ss
33266+ ljmp $(__KERNEL_CS),$1f
33267+#else
33268+ jmp 1f+__PAGE_OFFSET
33269+#endif
33270 1:
33271
33272 /*
33273 * 9. Balance the stack. And because EAX contain the return value,
33274 * we'd better not clobber it.
33275 */
33276- leal efi_rt_function_ptr, %edx
33277- movl (%edx), %ecx
33278- pushl %ecx
33279+ pushl (efi_rt_function_ptr)
33280
33281 /*
33282- * 10. Push the saved return address onto the stack and return.
33283+ * 10. Return to the saved return address.
33284 */
33285- leal saved_return_addr, %edx
33286- movl (%edx), %ecx
33287- pushl %ecx
33288- ret
33289+ jmpl *(saved_return_addr)
33290 ENDPROC(efi_call_phys)
33291 .previous
33292
33293-.data
33294+__INITDATA
33295 saved_return_addr:
33296 .long 0
33297 efi_rt_function_ptr:
33298diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33299index 4c07cca..2c8427d 100644
33300--- a/arch/x86/platform/efi/efi_stub_64.S
33301+++ b/arch/x86/platform/efi/efi_stub_64.S
33302@@ -7,6 +7,7 @@
33303 */
33304
33305 #include <linux/linkage.h>
33306+#include <asm/alternative-asm.h>
33307
33308 #define SAVE_XMM \
33309 mov %rsp, %rax; \
33310@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33311 call *%rdi
33312 addq $32, %rsp
33313 RESTORE_XMM
33314+ pax_force_retaddr 0, 1
33315 ret
33316 ENDPROC(efi_call0)
33317
33318@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33319 call *%rdi
33320 addq $32, %rsp
33321 RESTORE_XMM
33322+ pax_force_retaddr 0, 1
33323 ret
33324 ENDPROC(efi_call1)
33325
33326@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33327 call *%rdi
33328 addq $32, %rsp
33329 RESTORE_XMM
33330+ pax_force_retaddr 0, 1
33331 ret
33332 ENDPROC(efi_call2)
33333
33334@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33335 call *%rdi
33336 addq $32, %rsp
33337 RESTORE_XMM
33338+ pax_force_retaddr 0, 1
33339 ret
33340 ENDPROC(efi_call3)
33341
33342@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33343 call *%rdi
33344 addq $32, %rsp
33345 RESTORE_XMM
33346+ pax_force_retaddr 0, 1
33347 ret
33348 ENDPROC(efi_call4)
33349
33350@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33351 call *%rdi
33352 addq $48, %rsp
33353 RESTORE_XMM
33354+ pax_force_retaddr 0, 1
33355 ret
33356 ENDPROC(efi_call5)
33357
33358@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33359 call *%rdi
33360 addq $48, %rsp
33361 RESTORE_XMM
33362+ pax_force_retaddr 0, 1
33363 ret
33364 ENDPROC(efi_call6)
33365diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33366index 47fe66f..6206449 100644
33367--- a/arch/x86/platform/mrst/mrst.c
33368+++ b/arch/x86/platform/mrst/mrst.c
33369@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33370 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33371 int sfi_mrtc_num;
33372
33373-static void mrst_power_off(void)
33374+static __noreturn void mrst_power_off(void)
33375 {
33376+ BUG();
33377 }
33378
33379-static void mrst_reboot(void)
33380+static __noreturn void mrst_reboot(void)
33381 {
33382 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33383+ BUG();
33384 }
33385
33386 /* parse all the mtimer info to a static mtimer array */
33387diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33388index d6ee929..3637cb5 100644
33389--- a/arch/x86/platform/olpc/olpc_dt.c
33390+++ b/arch/x86/platform/olpc/olpc_dt.c
33391@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33392 return res;
33393 }
33394
33395-static struct of_pdt_ops prom_olpc_ops __initdata = {
33396+static struct of_pdt_ops prom_olpc_ops __initconst = {
33397 .nextprop = olpc_dt_nextprop,
33398 .getproplen = olpc_dt_getproplen,
33399 .getproperty = olpc_dt_getproperty,
33400diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33401index 1cf5b30..fd45732 100644
33402--- a/arch/x86/power/cpu.c
33403+++ b/arch/x86/power/cpu.c
33404@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33405 static void fix_processor_context(void)
33406 {
33407 int cpu = smp_processor_id();
33408- struct tss_struct *t = &per_cpu(init_tss, cpu);
33409-#ifdef CONFIG_X86_64
33410- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33411- tss_desc tss;
33412-#endif
33413+ struct tss_struct *t = init_tss + cpu;
33414+
33415 set_tss_desc(cpu, t); /*
33416 * This just modifies memory; should not be
33417 * necessary. But... This is necessary, because
33418@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33419 */
33420
33421 #ifdef CONFIG_X86_64
33422- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33423- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33424- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33425-
33426 syscall_init(); /* This sets MSR_*STAR and related */
33427 #endif
33428 load_TR_desc(); /* This does ltr */
33429diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33430index a44f457..9140171 100644
33431--- a/arch/x86/realmode/init.c
33432+++ b/arch/x86/realmode/init.c
33433@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33434 __va(real_mode_header->trampoline_header);
33435
33436 #ifdef CONFIG_X86_32
33437- trampoline_header->start = __pa_symbol(startup_32_smp);
33438+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33439+
33440+#ifdef CONFIG_PAX_KERNEXEC
33441+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33442+#endif
33443+
33444+ trampoline_header->boot_cs = __BOOT_CS;
33445 trampoline_header->gdt_limit = __BOOT_DS + 7;
33446 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33447 #else
33448@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33449 *trampoline_cr4_features = read_cr4();
33450
33451 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33452- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33453+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33454 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33455 #endif
33456 }
33457diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33458index 8869287..d577672 100644
33459--- a/arch/x86/realmode/rm/Makefile
33460+++ b/arch/x86/realmode/rm/Makefile
33461@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33462 $(call cc-option, -fno-unit-at-a-time)) \
33463 $(call cc-option, -fno-stack-protector) \
33464 $(call cc-option, -mpreferred-stack-boundary=2)
33465+ifdef CONSTIFY_PLUGIN
33466+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33467+endif
33468 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33469 GCOV_PROFILE := n
33470diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33471index a28221d..93c40f1 100644
33472--- a/arch/x86/realmode/rm/header.S
33473+++ b/arch/x86/realmode/rm/header.S
33474@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33475 #endif
33476 /* APM/BIOS reboot */
33477 .long pa_machine_real_restart_asm
33478-#ifdef CONFIG_X86_64
33479+#ifdef CONFIG_X86_32
33480+ .long __KERNEL_CS
33481+#else
33482 .long __KERNEL32_CS
33483 #endif
33484 END(real_mode_header)
33485diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33486index c1b2791..f9e31c7 100644
33487--- a/arch/x86/realmode/rm/trampoline_32.S
33488+++ b/arch/x86/realmode/rm/trampoline_32.S
33489@@ -25,6 +25,12 @@
33490 #include <asm/page_types.h>
33491 #include "realmode.h"
33492
33493+#ifdef CONFIG_PAX_KERNEXEC
33494+#define ta(X) (X)
33495+#else
33496+#define ta(X) (pa_ ## X)
33497+#endif
33498+
33499 .text
33500 .code16
33501
33502@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33503
33504 cli # We should be safe anyway
33505
33506- movl tr_start, %eax # where we need to go
33507-
33508 movl $0xA5A5A5A5, trampoline_status
33509 # write marker for master knows we're running
33510
33511@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33512 movw $1, %dx # protected mode (PE) bit
33513 lmsw %dx # into protected mode
33514
33515- ljmpl $__BOOT_CS, $pa_startup_32
33516+ ljmpl *(trampoline_header)
33517
33518 .section ".text32","ax"
33519 .code32
33520@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33521 .balign 8
33522 GLOBAL(trampoline_header)
33523 tr_start: .space 4
33524- tr_gdt_pad: .space 2
33525+ tr_boot_cs: .space 2
33526 tr_gdt: .space 6
33527 END(trampoline_header)
33528
33529diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33530index bb360dc..d0fd8f8 100644
33531--- a/arch/x86/realmode/rm/trampoline_64.S
33532+++ b/arch/x86/realmode/rm/trampoline_64.S
33533@@ -94,6 +94,7 @@ ENTRY(startup_32)
33534 movl %edx, %gs
33535
33536 movl pa_tr_cr4, %eax
33537+ andl $~X86_CR4_PCIDE, %eax
33538 movl %eax, %cr4 # Enable PAE mode
33539
33540 # Setup trampoline 4 level pagetables
33541@@ -107,7 +108,7 @@ ENTRY(startup_32)
33542 wrmsr
33543
33544 # Enable paging and in turn activate Long Mode
33545- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33546+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33547 movl %eax, %cr0
33548
33549 /*
33550diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33551index e812034..c747134 100644
33552--- a/arch/x86/tools/Makefile
33553+++ b/arch/x86/tools/Makefile
33554@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33555
33556 $(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
33557
33558-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33559+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33560 hostprogs-y += relocs
33561 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33562 relocs: $(obj)/relocs
33563diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33564index f7bab68..b6d9886 100644
33565--- a/arch/x86/tools/relocs.c
33566+++ b/arch/x86/tools/relocs.c
33567@@ -1,5 +1,7 @@
33568 /* This is included from relocs_32/64.c */
33569
33570+#include "../../../include/generated/autoconf.h"
33571+
33572 #define ElfW(type) _ElfW(ELF_BITS, type)
33573 #define _ElfW(bits, type) __ElfW(bits, type)
33574 #define __ElfW(bits, type) Elf##bits##_##type
33575@@ -11,6 +13,7 @@
33576 #define Elf_Sym ElfW(Sym)
33577
33578 static Elf_Ehdr ehdr;
33579+static Elf_Phdr *phdr;
33580
33581 struct relocs {
33582 uint32_t *offset;
33583@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33584 }
33585 }
33586
33587+static void read_phdrs(FILE *fp)
33588+{
33589+ unsigned int i;
33590+
33591+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33592+ if (!phdr) {
33593+ die("Unable to allocate %d program headers\n",
33594+ ehdr.e_phnum);
33595+ }
33596+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33597+ die("Seek to %d failed: %s\n",
33598+ ehdr.e_phoff, strerror(errno));
33599+ }
33600+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33601+ die("Cannot read ELF program headers: %s\n",
33602+ strerror(errno));
33603+ }
33604+ for(i = 0; i < ehdr.e_phnum; i++) {
33605+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33606+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33607+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33608+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33609+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33610+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33611+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33612+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33613+ }
33614+
33615+}
33616+
33617 static void read_shdrs(FILE *fp)
33618 {
33619- int i;
33620+ unsigned int i;
33621 Elf_Shdr shdr;
33622
33623 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33624@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33625
33626 static void read_strtabs(FILE *fp)
33627 {
33628- int i;
33629+ unsigned int i;
33630 for (i = 0; i < ehdr.e_shnum; i++) {
33631 struct section *sec = &secs[i];
33632 if (sec->shdr.sh_type != SHT_STRTAB) {
33633@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33634
33635 static void read_symtabs(FILE *fp)
33636 {
33637- int i,j;
33638+ unsigned int i,j;
33639 for (i = 0; i < ehdr.e_shnum; i++) {
33640 struct section *sec = &secs[i];
33641 if (sec->shdr.sh_type != SHT_SYMTAB) {
33642@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33643 }
33644
33645
33646-static void read_relocs(FILE *fp)
33647+static void read_relocs(FILE *fp, int use_real_mode)
33648 {
33649- int i,j;
33650+ unsigned int i,j;
33651+ uint32_t base;
33652+
33653 for (i = 0; i < ehdr.e_shnum; i++) {
33654 struct section *sec = &secs[i];
33655 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33656@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33657 die("Cannot read symbol table: %s\n",
33658 strerror(errno));
33659 }
33660+ base = 0;
33661+
33662+#ifdef CONFIG_X86_32
33663+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33664+ if (phdr[j].p_type != PT_LOAD )
33665+ continue;
33666+ 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)
33667+ continue;
33668+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33669+ break;
33670+ }
33671+#endif
33672+
33673 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33674 Elf_Rel *rel = &sec->reltab[j];
33675- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33676+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33677 rel->r_info = elf_xword_to_cpu(rel->r_info);
33678 #if (SHT_REL_TYPE == SHT_RELA)
33679 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33680@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33681
33682 static void print_absolute_symbols(void)
33683 {
33684- int i;
33685+ unsigned int i;
33686 const char *format;
33687
33688 if (ELF_BITS == 64)
33689@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33690 for (i = 0; i < ehdr.e_shnum; i++) {
33691 struct section *sec = &secs[i];
33692 char *sym_strtab;
33693- int j;
33694+ unsigned int j;
33695
33696 if (sec->shdr.sh_type != SHT_SYMTAB) {
33697 continue;
33698@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33699
33700 static void print_absolute_relocs(void)
33701 {
33702- int i, printed = 0;
33703+ unsigned int i, printed = 0;
33704 const char *format;
33705
33706 if (ELF_BITS == 64)
33707@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33708 struct section *sec_applies, *sec_symtab;
33709 char *sym_strtab;
33710 Elf_Sym *sh_symtab;
33711- int j;
33712+ unsigned int j;
33713 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33714 continue;
33715 }
33716@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33717 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33718 Elf_Sym *sym, const char *symname))
33719 {
33720- int i;
33721+ unsigned int i;
33722 /* Walk through the relocations */
33723 for (i = 0; i < ehdr.e_shnum; i++) {
33724 char *sym_strtab;
33725 Elf_Sym *sh_symtab;
33726 struct section *sec_applies, *sec_symtab;
33727- int j;
33728+ unsigned int j;
33729 struct section *sec = &secs[i];
33730
33731 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33732@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33733 {
33734 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33735 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33736+ char *sym_strtab = sec->link->link->strtab;
33737+
33738+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33739+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33740+ return 0;
33741+
33742+#ifdef CONFIG_PAX_KERNEXEC
33743+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33744+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33745+ return 0;
33746+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33747+ return 0;
33748+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33749+ return 0;
33750+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33751+ return 0;
33752+#endif
33753
33754 switch (r_type) {
33755 case R_386_NONE:
33756@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33757
33758 static void emit_relocs(int as_text, int use_real_mode)
33759 {
33760- int i;
33761+ unsigned int i;
33762 int (*write_reloc)(uint32_t, FILE *) = write32;
33763 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33764 const char *symname);
33765@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33766 {
33767 regex_init(use_real_mode);
33768 read_ehdr(fp);
33769+ read_phdrs(fp);
33770 read_shdrs(fp);
33771 read_strtabs(fp);
33772 read_symtabs(fp);
33773- read_relocs(fp);
33774+ read_relocs(fp, use_real_mode);
33775 if (ELF_BITS == 64)
33776 percpu_init();
33777 if (show_absolute_syms) {
33778diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33779index 80ffa5b..a33bd15 100644
33780--- a/arch/x86/um/tls_32.c
33781+++ b/arch/x86/um/tls_32.c
33782@@ -260,7 +260,7 @@ out:
33783 if (unlikely(task == current &&
33784 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33785 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33786- "without flushed TLS.", current->pid);
33787+ "without flushed TLS.", task_pid_nr(current));
33788 }
33789
33790 return 0;
33791diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33792index fd14be1..e3c79c0 100644
33793--- a/arch/x86/vdso/Makefile
33794+++ b/arch/x86/vdso/Makefile
33795@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33796 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33797 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33798
33799-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33800+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33801 GCOV_PROFILE := n
33802
33803 #
33804diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33805index d6bfb87..876ee18 100644
33806--- a/arch/x86/vdso/vdso32-setup.c
33807+++ b/arch/x86/vdso/vdso32-setup.c
33808@@ -25,6 +25,7 @@
33809 #include <asm/tlbflush.h>
33810 #include <asm/vdso.h>
33811 #include <asm/proto.h>
33812+#include <asm/mman.h>
33813
33814 enum {
33815 VDSO_DISABLED = 0,
33816@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33817 void enable_sep_cpu(void)
33818 {
33819 int cpu = get_cpu();
33820- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33821+ struct tss_struct *tss = init_tss + cpu;
33822
33823 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33824 put_cpu();
33825@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33826 gate_vma.vm_start = FIXADDR_USER_START;
33827 gate_vma.vm_end = FIXADDR_USER_END;
33828 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33829- gate_vma.vm_page_prot = __P101;
33830+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33831
33832 return 0;
33833 }
33834@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33835 if (compat)
33836 addr = VDSO_HIGH_BASE;
33837 else {
33838- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33839+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33840 if (IS_ERR_VALUE(addr)) {
33841 ret = addr;
33842 goto up_fail;
33843 }
33844 }
33845
33846- current->mm->context.vdso = (void *)addr;
33847+ current->mm->context.vdso = addr;
33848
33849 if (compat_uses_vma || !compat) {
33850 /*
33851@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33852 }
33853
33854 current_thread_info()->sysenter_return =
33855- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33856+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33857
33858 up_fail:
33859 if (ret)
33860- current->mm->context.vdso = NULL;
33861+ current->mm->context.vdso = 0;
33862
33863 up_write(&mm->mmap_sem);
33864
33865@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33866
33867 const char *arch_vma_name(struct vm_area_struct *vma)
33868 {
33869- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33870+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33871 return "[vdso]";
33872+
33873+#ifdef CONFIG_PAX_SEGMEXEC
33874+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33875+ return "[vdso]";
33876+#endif
33877+
33878 return NULL;
33879 }
33880
33881@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33882 * Check to see if the corresponding task was created in compat vdso
33883 * mode.
33884 */
33885- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33886+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33887 return &gate_vma;
33888 return NULL;
33889 }
33890diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33891index 431e875..cbb23f3 100644
33892--- a/arch/x86/vdso/vma.c
33893+++ b/arch/x86/vdso/vma.c
33894@@ -16,8 +16,6 @@
33895 #include <asm/vdso.h>
33896 #include <asm/page.h>
33897
33898-unsigned int __read_mostly vdso_enabled = 1;
33899-
33900 extern char vdso_start[], vdso_end[];
33901 extern unsigned short vdso_sync_cpuid;
33902
33903@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33904 * unaligned here as a result of stack start randomization.
33905 */
33906 addr = PAGE_ALIGN(addr);
33907- addr = align_vdso_addr(addr);
33908
33909 return addr;
33910 }
33911@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33912 unsigned size)
33913 {
33914 struct mm_struct *mm = current->mm;
33915- unsigned long addr;
33916+ unsigned long addr = 0;
33917 int ret;
33918
33919- if (!vdso_enabled)
33920- return 0;
33921-
33922 down_write(&mm->mmap_sem);
33923+
33924+#ifdef CONFIG_PAX_RANDMMAP
33925+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33926+#endif
33927+
33928 addr = vdso_addr(mm->start_stack, size);
33929+ addr = align_vdso_addr(addr);
33930 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33931 if (IS_ERR_VALUE(addr)) {
33932 ret = addr;
33933 goto up_fail;
33934 }
33935
33936- current->mm->context.vdso = (void *)addr;
33937+ mm->context.vdso = addr;
33938
33939 ret = install_special_mapping(mm, addr, size,
33940 VM_READ|VM_EXEC|
33941 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33942 pages);
33943- if (ret) {
33944- current->mm->context.vdso = NULL;
33945- goto up_fail;
33946- }
33947+ if (ret)
33948+ mm->context.vdso = 0;
33949
33950 up_fail:
33951 up_write(&mm->mmap_sem);
33952@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33953 vdsox32_size);
33954 }
33955 #endif
33956-
33957-static __init int vdso_setup(char *s)
33958-{
33959- vdso_enabled = simple_strtoul(s, NULL, 0);
33960- return 0;
33961-}
33962-__setup("vdso=", vdso_setup);
33963diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33964index 193097e..7590269 100644
33965--- a/arch/x86/xen/enlighten.c
33966+++ b/arch/x86/xen/enlighten.c
33967@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33968
33969 struct shared_info xen_dummy_shared_info;
33970
33971-void *xen_initial_gdt;
33972-
33973 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33974 __read_mostly int xen_have_vector_callback;
33975 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33976@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33977 {
33978 unsigned long va = dtr->address;
33979 unsigned int size = dtr->size + 1;
33980- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33981- unsigned long frames[pages];
33982+ unsigned long frames[65536 / PAGE_SIZE];
33983 int f;
33984
33985 /*
33986@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33987 {
33988 unsigned long va = dtr->address;
33989 unsigned int size = dtr->size + 1;
33990- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33991- unsigned long frames[pages];
33992+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33993 int f;
33994
33995 /*
33996@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33997 * 8-byte entries, or 16 4k pages..
33998 */
33999
34000- BUG_ON(size > 65536);
34001+ BUG_ON(size > GDT_SIZE);
34002 BUG_ON(va & ~PAGE_MASK);
34003
34004 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34005@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34006 return 0;
34007 }
34008
34009-static void set_xen_basic_apic_ops(void)
34010+static void __init set_xen_basic_apic_ops(void)
34011 {
34012 apic->read = xen_apic_read;
34013 apic->write = xen_apic_write;
34014@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34015 #endif
34016 };
34017
34018-static void xen_reboot(int reason)
34019+static __noreturn void xen_reboot(int reason)
34020 {
34021 struct sched_shutdown r = { .reason = reason };
34022
34023- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34024- BUG();
34025+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34026+ BUG();
34027 }
34028
34029-static void xen_restart(char *msg)
34030+static __noreturn void xen_restart(char *msg)
34031 {
34032 xen_reboot(SHUTDOWN_reboot);
34033 }
34034
34035-static void xen_emergency_restart(void)
34036+static __noreturn void xen_emergency_restart(void)
34037 {
34038 xen_reboot(SHUTDOWN_reboot);
34039 }
34040
34041-static void xen_machine_halt(void)
34042+static __noreturn void xen_machine_halt(void)
34043 {
34044 xen_reboot(SHUTDOWN_poweroff);
34045 }
34046
34047-static void xen_machine_power_off(void)
34048+static __noreturn void xen_machine_power_off(void)
34049 {
34050 if (pm_power_off)
34051 pm_power_off();
34052@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34053 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34054
34055 /* Work out if we support NX */
34056- x86_configure_nx();
34057+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34058+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34059+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34060+ unsigned l, h;
34061+
34062+ __supported_pte_mask |= _PAGE_NX;
34063+ rdmsr(MSR_EFER, l, h);
34064+ l |= EFER_NX;
34065+ wrmsr(MSR_EFER, l, h);
34066+ }
34067+#endif
34068
34069 xen_setup_features();
34070
34071@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34072
34073 machine_ops = xen_machine_ops;
34074
34075- /*
34076- * The only reliable way to retain the initial address of the
34077- * percpu gdt_page is to remember it here, so we can go and
34078- * mark it RW later, when the initial percpu area is freed.
34079- */
34080- xen_initial_gdt = &per_cpu(gdt_page, 0);
34081-
34082 xen_smp_init();
34083
34084 #ifdef CONFIG_ACPI_NUMA
34085diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34086index fdc3ba2..3daee39 100644
34087--- a/arch/x86/xen/mmu.c
34088+++ b/arch/x86/xen/mmu.c
34089@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34090 /* L3_k[510] -> level2_kernel_pgt
34091 * L3_i[511] -> level2_fixmap_pgt */
34092 convert_pfn_mfn(level3_kernel_pgt);
34093+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34094+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34095+ convert_pfn_mfn(level3_vmemmap_pgt);
34096
34097 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34098 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34099@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34100 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34101 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34102 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34103+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34104+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34105+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34106 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34107 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34108+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34109 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34110 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34111
34112@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34113 pv_mmu_ops.set_pud = xen_set_pud;
34114 #if PAGETABLE_LEVELS == 4
34115 pv_mmu_ops.set_pgd = xen_set_pgd;
34116+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34117 #endif
34118
34119 /* This will work as long as patching hasn't happened yet
34120@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34121 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34122 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34123 .set_pgd = xen_set_pgd_hyper,
34124+ .set_pgd_batched = xen_set_pgd_hyper,
34125
34126 .alloc_pud = xen_alloc_pmd_init,
34127 .release_pud = xen_release_pmd_init,
34128diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34129index b81c88e..2cbe7b8 100644
34130--- a/arch/x86/xen/smp.c
34131+++ b/arch/x86/xen/smp.c
34132@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34133 {
34134 BUG_ON(smp_processor_id() != 0);
34135 native_smp_prepare_boot_cpu();
34136-
34137- /* We've switched to the "real" per-cpu gdt, so make sure the
34138- old memory can be recycled */
34139- make_lowmem_page_readwrite(xen_initial_gdt);
34140-
34141 xen_filter_cpu_maps();
34142 xen_setup_vcpu_info_placement();
34143 }
34144@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34145 ctxt->user_regs.ss = __KERNEL_DS;
34146 #ifdef CONFIG_X86_32
34147 ctxt->user_regs.fs = __KERNEL_PERCPU;
34148- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34149+ savesegment(gs, ctxt->user_regs.gs);
34150 #else
34151 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34152 #endif
34153@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34154
34155 {
34156 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34157- ctxt->user_regs.ds = __USER_DS;
34158- ctxt->user_regs.es = __USER_DS;
34159+ ctxt->user_regs.ds = __KERNEL_DS;
34160+ ctxt->user_regs.es = __KERNEL_DS;
34161
34162 xen_copy_trap_info(ctxt->trap_ctxt);
34163
34164@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34165 int rc;
34166
34167 per_cpu(current_task, cpu) = idle;
34168+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34169 #ifdef CONFIG_X86_32
34170 irq_ctx_init(cpu);
34171 #else
34172 clear_tsk_thread_flag(idle, TIF_FORK);
34173- per_cpu(kernel_stack, cpu) =
34174- (unsigned long)task_stack_page(idle) -
34175- KERNEL_STACK_OFFSET + THREAD_SIZE;
34176+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34177 #endif
34178 xen_setup_runstate_info(cpu);
34179 xen_setup_timer(cpu);
34180@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34181
34182 void __init xen_smp_init(void)
34183 {
34184- smp_ops = xen_smp_ops;
34185+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34186 xen_fill_possible_map();
34187 xen_init_spinlocks();
34188 }
34189diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34190index 33ca6e4..0ded929 100644
34191--- a/arch/x86/xen/xen-asm_32.S
34192+++ b/arch/x86/xen/xen-asm_32.S
34193@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34194 ESP_OFFSET=4 # bytes pushed onto stack
34195
34196 /*
34197- * Store vcpu_info pointer for easy access. Do it this way to
34198- * avoid having to reload %fs
34199+ * Store vcpu_info pointer for easy access.
34200 */
34201 #ifdef CONFIG_SMP
34202- GET_THREAD_INFO(%eax)
34203- movl %ss:TI_cpu(%eax), %eax
34204- movl %ss:__per_cpu_offset(,%eax,4), %eax
34205- mov %ss:xen_vcpu(%eax), %eax
34206+ push %fs
34207+ mov $(__KERNEL_PERCPU), %eax
34208+ mov %eax, %fs
34209+ mov PER_CPU_VAR(xen_vcpu), %eax
34210+ pop %fs
34211 #else
34212 movl %ss:xen_vcpu, %eax
34213 #endif
34214diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34215index 7faed58..ba4427c 100644
34216--- a/arch/x86/xen/xen-head.S
34217+++ b/arch/x86/xen/xen-head.S
34218@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34219 #ifdef CONFIG_X86_32
34220 mov %esi,xen_start_info
34221 mov $init_thread_union+THREAD_SIZE,%esp
34222+#ifdef CONFIG_SMP
34223+ movl $cpu_gdt_table,%edi
34224+ movl $__per_cpu_load,%eax
34225+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34226+ rorl $16,%eax
34227+ movb %al,__KERNEL_PERCPU + 4(%edi)
34228+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34229+ movl $__per_cpu_end - 1,%eax
34230+ subl $__per_cpu_start,%eax
34231+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34232+#endif
34233 #else
34234 mov %rsi,xen_start_info
34235 mov $init_thread_union+THREAD_SIZE,%rsp
34236diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34237index 86782c5..fa272c8 100644
34238--- a/arch/x86/xen/xen-ops.h
34239+++ b/arch/x86/xen/xen-ops.h
34240@@ -10,8 +10,6 @@
34241 extern const char xen_hypervisor_callback[];
34242 extern const char xen_failsafe_callback[];
34243
34244-extern void *xen_initial_gdt;
34245-
34246 struct trap_info;
34247 void xen_copy_trap_info(struct trap_info *traps);
34248
34249diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34250index 525bd3d..ef888b1 100644
34251--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34252+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34253@@ -119,9 +119,9 @@
34254 ----------------------------------------------------------------------*/
34255
34256 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34257-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34258 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34259 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34260+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34261
34262 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34263 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34264diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34265index 2f33760..835e50a 100644
34266--- a/arch/xtensa/variants/fsf/include/variant/core.h
34267+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34268@@ -11,6 +11,7 @@
34269 #ifndef _XTENSA_CORE_H
34270 #define _XTENSA_CORE_H
34271
34272+#include <linux/const.h>
34273
34274 /****************************************************************************
34275 Parameters Useful for Any Code, USER or PRIVILEGED
34276@@ -112,9 +113,9 @@
34277 ----------------------------------------------------------------------*/
34278
34279 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34280-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34281 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34282 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34283+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34284
34285 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34286 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34287diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34288index af00795..2bb8105 100644
34289--- a/arch/xtensa/variants/s6000/include/variant/core.h
34290+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34291@@ -11,6 +11,7 @@
34292 #ifndef _XTENSA_CORE_CONFIGURATION_H
34293 #define _XTENSA_CORE_CONFIGURATION_H
34294
34295+#include <linux/const.h>
34296
34297 /****************************************************************************
34298 Parameters Useful for Any Code, USER or PRIVILEGED
34299@@ -118,9 +119,9 @@
34300 ----------------------------------------------------------------------*/
34301
34302 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34303-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34304 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34305 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34306+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34307
34308 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34309 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34310diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34311index 290792a..416f287 100644
34312--- a/block/blk-cgroup.c
34313+++ b/block/blk-cgroup.c
34314@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34315
34316 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34317 {
34318- static atomic64_t id_seq = ATOMIC64_INIT(0);
34319+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34320 struct blkcg *blkcg;
34321 struct cgroup *parent = cgroup->parent;
34322
34323@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34324
34325 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34326 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34327- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34328+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34329 done:
34330 spin_lock_init(&blkcg->lock);
34331 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34332diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34333index 4b8d9b54..a7178c0 100644
34334--- a/block/blk-iopoll.c
34335+++ b/block/blk-iopoll.c
34336@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34337 }
34338 EXPORT_SYMBOL(blk_iopoll_complete);
34339
34340-static void blk_iopoll_softirq(struct softirq_action *h)
34341+static __latent_entropy void blk_iopoll_softirq(void)
34342 {
34343 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34344 int rearm = 0, budget = blk_iopoll_budget;
34345diff --git a/block/blk-map.c b/block/blk-map.c
34346index 623e1cd..ca1e109 100644
34347--- a/block/blk-map.c
34348+++ b/block/blk-map.c
34349@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34350 if (!len || !kbuf)
34351 return -EINVAL;
34352
34353- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34354+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34355 if (do_copy)
34356 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34357 else
34358diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34359index ec9e606..3f38839 100644
34360--- a/block/blk-softirq.c
34361+++ b/block/blk-softirq.c
34362@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34363 * Softirq action handler - move entries to local list and loop over them
34364 * while passing them to the queue registered handler.
34365 */
34366-static void blk_done_softirq(struct softirq_action *h)
34367+static __latent_entropy void blk_done_softirq(void)
34368 {
34369 struct list_head *cpu_list, local_list;
34370
34371diff --git a/block/bsg.c b/block/bsg.c
34372index 420a5a9..23834aa 100644
34373--- a/block/bsg.c
34374+++ b/block/bsg.c
34375@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34376 struct sg_io_v4 *hdr, struct bsg_device *bd,
34377 fmode_t has_write_perm)
34378 {
34379+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34380+ unsigned char *cmdptr;
34381+
34382 if (hdr->request_len > BLK_MAX_CDB) {
34383 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34384 if (!rq->cmd)
34385 return -ENOMEM;
34386- }
34387+ cmdptr = rq->cmd;
34388+ } else
34389+ cmdptr = tmpcmd;
34390
34391- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34392+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34393 hdr->request_len))
34394 return -EFAULT;
34395
34396+ if (cmdptr != rq->cmd)
34397+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34398+
34399 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34400 if (blk_verify_command(rq->cmd, has_write_perm))
34401 return -EPERM;
34402diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34403index 7e5d474..0cf0017 100644
34404--- a/block/compat_ioctl.c
34405+++ b/block/compat_ioctl.c
34406@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34407 err |= __get_user(f->spec1, &uf->spec1);
34408 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34409 err |= __get_user(name, &uf->name);
34410- f->name = compat_ptr(name);
34411+ f->name = (void __force_kernel *)compat_ptr(name);
34412 if (err) {
34413 err = -EFAULT;
34414 goto out;
34415diff --git a/block/genhd.c b/block/genhd.c
34416index dadf42b..48dc887 100644
34417--- a/block/genhd.c
34418+++ b/block/genhd.c
34419@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34420
34421 /*
34422 * Register device numbers dev..(dev+range-1)
34423- * range must be nonzero
34424+ * Noop if @range is zero.
34425 * The hash chain is sorted on range, so that subranges can override.
34426 */
34427 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34428 struct kobject *(*probe)(dev_t, int *, void *),
34429 int (*lock)(dev_t, void *), void *data)
34430 {
34431- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34432+ if (range)
34433+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34434 }
34435
34436 EXPORT_SYMBOL(blk_register_region);
34437
34438+/* undo blk_register_region(), noop if @range is zero */
34439 void blk_unregister_region(dev_t devt, unsigned long range)
34440 {
34441- kobj_unmap(bdev_map, devt, range);
34442+ if (range)
34443+ kobj_unmap(bdev_map, devt, range);
34444 }
34445
34446 EXPORT_SYMBOL(blk_unregister_region);
34447diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34448index c85fc89..51e690b 100644
34449--- a/block/partitions/efi.c
34450+++ b/block/partitions/efi.c
34451@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34452 if (!gpt)
34453 return NULL;
34454
34455+ if (!le32_to_cpu(gpt->num_partition_entries))
34456+ return NULL;
34457+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34458+ if (!pte)
34459+ return NULL;
34460+
34461 count = le32_to_cpu(gpt->num_partition_entries) *
34462 le32_to_cpu(gpt->sizeof_partition_entry);
34463- if (!count)
34464- return NULL;
34465- pte = kmalloc(count, GFP_KERNEL);
34466- if (!pte)
34467- return NULL;
34468-
34469 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34470 (u8 *) pte,
34471 count) < count) {
34472diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34473index a5ffcc9..3cedc9c 100644
34474--- a/block/scsi_ioctl.c
34475+++ b/block/scsi_ioctl.c
34476@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34477 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34478 struct sg_io_hdr *hdr, fmode_t mode)
34479 {
34480- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34481+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34482+ unsigned char *cmdptr;
34483+
34484+ if (rq->cmd != rq->__cmd)
34485+ cmdptr = rq->cmd;
34486+ else
34487+ cmdptr = tmpcmd;
34488+
34489+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34490 return -EFAULT;
34491+
34492+ if (cmdptr != rq->cmd)
34493+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34494+
34495 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34496 return -EPERM;
34497
34498@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34499 int err;
34500 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34501 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34502+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34503+ unsigned char *cmdptr;
34504
34505 if (!sic)
34506 return -EINVAL;
34507@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34508 */
34509 err = -EFAULT;
34510 rq->cmd_len = cmdlen;
34511- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34512+
34513+ if (rq->cmd != rq->__cmd)
34514+ cmdptr = rq->cmd;
34515+ else
34516+ cmdptr = tmpcmd;
34517+
34518+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34519 goto error;
34520
34521+ if (rq->cmd != cmdptr)
34522+ memcpy(rq->cmd, cmdptr, cmdlen);
34523+
34524 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34525 goto error;
34526
34527diff --git a/crypto/api.c b/crypto/api.c
34528index 3b61803..37c4c72 100644
34529--- a/crypto/api.c
34530+++ b/crypto/api.c
34531@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
34532 BLOCKING_NOTIFIER_HEAD(crypto_chain);
34533 EXPORT_SYMBOL_GPL(crypto_chain);
34534
34535+static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
34536+
34537 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
34538 {
34539 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
34540@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
34541 }
34542 up_write(&crypto_alg_sem);
34543
34544- if (alg != &larval->alg)
34545+ if (alg != &larval->alg) {
34546 kfree(larval);
34547+ if (crypto_is_larval(alg))
34548+ alg = crypto_larval_wait(alg);
34549+ }
34550
34551 return alg;
34552 }
34553diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34554index 7bdd61b..afec999 100644
34555--- a/crypto/cryptd.c
34556+++ b/crypto/cryptd.c
34557@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34558
34559 struct cryptd_blkcipher_request_ctx {
34560 crypto_completion_t complete;
34561-};
34562+} __no_const;
34563
34564 struct cryptd_hash_ctx {
34565 struct crypto_shash *child;
34566@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34567
34568 struct cryptd_aead_request_ctx {
34569 crypto_completion_t complete;
34570-};
34571+} __no_const;
34572
34573 static void cryptd_queue_worker(struct work_struct *work);
34574
34575diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34576index f8c920c..ab2cb5a 100644
34577--- a/crypto/pcrypt.c
34578+++ b/crypto/pcrypt.c
34579@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34580 int ret;
34581
34582 pinst->kobj.kset = pcrypt_kset;
34583- ret = kobject_add(&pinst->kobj, NULL, name);
34584+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34585 if (!ret)
34586 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34587
34588diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34589index f220d64..d359ad6 100644
34590--- a/drivers/acpi/apei/apei-internal.h
34591+++ b/drivers/acpi/apei/apei-internal.h
34592@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34593 struct apei_exec_ins_type {
34594 u32 flags;
34595 apei_exec_ins_func_t run;
34596-};
34597+} __do_const;
34598
34599 struct apei_exec_context {
34600 u32 ip;
34601diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34602index 33dc6a0..4b24b47 100644
34603--- a/drivers/acpi/apei/cper.c
34604+++ b/drivers/acpi/apei/cper.c
34605@@ -39,12 +39,12 @@
34606 */
34607 u64 cper_next_record_id(void)
34608 {
34609- static atomic64_t seq;
34610+ static atomic64_unchecked_t seq;
34611
34612- if (!atomic64_read(&seq))
34613- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34614+ if (!atomic64_read_unchecked(&seq))
34615+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34616
34617- return atomic64_inc_return(&seq);
34618+ return atomic64_inc_return_unchecked(&seq);
34619 }
34620 EXPORT_SYMBOL_GPL(cper_next_record_id);
34621
34622diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34623index ec9b57d..9682b3a 100644
34624--- a/drivers/acpi/apei/ghes.c
34625+++ b/drivers/acpi/apei/ghes.c
34626@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34627 const struct acpi_hest_generic *generic,
34628 const struct acpi_hest_generic_status *estatus)
34629 {
34630- static atomic_t seqno;
34631+ static atomic_unchecked_t seqno;
34632 unsigned int curr_seqno;
34633 char pfx_seq[64];
34634
34635@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34636 else
34637 pfx = KERN_ERR;
34638 }
34639- curr_seqno = atomic_inc_return(&seqno);
34640+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34641 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34642 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34643 pfx_seq, generic->header.source_id);
34644diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34645index be60399..778b33e8 100644
34646--- a/drivers/acpi/bgrt.c
34647+++ b/drivers/acpi/bgrt.c
34648@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34649 return -ENODEV;
34650
34651 sysfs_bin_attr_init(&image_attr);
34652- image_attr.private = bgrt_image;
34653- image_attr.size = bgrt_image_size;
34654+ pax_open_kernel();
34655+ *(void **)&image_attr.private = bgrt_image;
34656+ *(size_t *)&image_attr.size = bgrt_image_size;
34657+ pax_close_kernel();
34658
34659 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34660 if (!bgrt_kobj)
34661diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34662index cb96296..b81293b 100644
34663--- a/drivers/acpi/blacklist.c
34664+++ b/drivers/acpi/blacklist.c
34665@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34666 u32 is_critical_error;
34667 };
34668
34669-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34670+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34671
34672 /*
34673 * POLICY: If *anything* doesn't work, put it on the blacklist.
34674@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34675 return 0;
34676 }
34677
34678-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34679+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34680 {
34681 .callback = dmi_disable_osi_vista,
34682 .ident = "Fujitsu Siemens",
34683diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34684index f98dd00..7b69865 100644
34685--- a/drivers/acpi/processor_idle.c
34686+++ b/drivers/acpi/processor_idle.c
34687@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34688 {
34689 int i, count = CPUIDLE_DRIVER_STATE_START;
34690 struct acpi_processor_cx *cx;
34691- struct cpuidle_state *state;
34692+ cpuidle_state_no_const *state;
34693 struct cpuidle_driver *drv = &acpi_idle_driver;
34694
34695 if (!pr->flags.power_setup_done)
34696diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34697index 05306a5..733d1f0 100644
34698--- a/drivers/acpi/sysfs.c
34699+++ b/drivers/acpi/sysfs.c
34700@@ -423,11 +423,11 @@ static u32 num_counters;
34701 static struct attribute **all_attrs;
34702 static u32 acpi_gpe_count;
34703
34704-static struct attribute_group interrupt_stats_attr_group = {
34705+static attribute_group_no_const interrupt_stats_attr_group = {
34706 .name = "interrupts",
34707 };
34708
34709-static struct kobj_attribute *counter_attrs;
34710+static kobj_attribute_no_const *counter_attrs;
34711
34712 static void delete_gpe_attr_array(void)
34713 {
34714diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34715index acfd0f7..e5acb08 100644
34716--- a/drivers/ata/libahci.c
34717+++ b/drivers/ata/libahci.c
34718@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34719 }
34720 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34721
34722-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34723+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34724 struct ata_taskfile *tf, int is_cmd, u16 flags,
34725 unsigned long timeout_msec)
34726 {
34727diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34728index c24354d..335c975 100644
34729--- a/drivers/ata/libata-core.c
34730+++ b/drivers/ata/libata-core.c
34731@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34732 static void ata_dev_xfermask(struct ata_device *dev);
34733 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34734
34735-atomic_t ata_print_id = ATOMIC_INIT(0);
34736+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34737
34738 struct ata_force_param {
34739 const char *name;
34740@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34741 struct ata_port *ap;
34742 unsigned int tag;
34743
34744- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34745+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34746 ap = qc->ap;
34747
34748 qc->flags = 0;
34749@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34750 struct ata_port *ap;
34751 struct ata_link *link;
34752
34753- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34754+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34755 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34756 ap = qc->ap;
34757 link = qc->dev->link;
34758@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34759 return;
34760
34761 spin_lock(&lock);
34762+ pax_open_kernel();
34763
34764 for (cur = ops->inherits; cur; cur = cur->inherits) {
34765 void **inherit = (void **)cur;
34766@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34767 if (IS_ERR(*pp))
34768 *pp = NULL;
34769
34770- ops->inherits = NULL;
34771+ *(struct ata_port_operations **)&ops->inherits = NULL;
34772
34773+ pax_close_kernel();
34774 spin_unlock(&lock);
34775 }
34776
34777@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34778
34779 /* give ports names and add SCSI hosts */
34780 for (i = 0; i < host->n_ports; i++) {
34781- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34782+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34783 host->ports[i]->local_port_no = i + 1;
34784 }
34785
34786diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34787index b1e880a..8cf82e1 100644
34788--- a/drivers/ata/libata-scsi.c
34789+++ b/drivers/ata/libata-scsi.c
34790@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34791
34792 if (rc)
34793 return rc;
34794- ap->print_id = atomic_inc_return(&ata_print_id);
34795+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34796 return 0;
34797 }
34798 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34799diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34800index 577d902b..cb4781e 100644
34801--- a/drivers/ata/libata.h
34802+++ b/drivers/ata/libata.h
34803@@ -53,7 +53,7 @@ enum {
34804 ATA_DNXFER_QUIET = (1 << 31),
34805 };
34806
34807-extern atomic_t ata_print_id;
34808+extern atomic_unchecked_t ata_print_id;
34809 extern int atapi_passthru16;
34810 extern int libata_fua;
34811 extern int libata_noacpi;
34812diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34813index 848ed32..132f39d 100644
34814--- a/drivers/ata/pata_arasan_cf.c
34815+++ b/drivers/ata/pata_arasan_cf.c
34816@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34817 /* Handle platform specific quirks */
34818 if (quirk) {
34819 if (quirk & CF_BROKEN_PIO) {
34820- ap->ops->set_piomode = NULL;
34821+ pax_open_kernel();
34822+ *(void **)&ap->ops->set_piomode = NULL;
34823+ pax_close_kernel();
34824 ap->pio_mask = 0;
34825 }
34826 if (quirk & CF_BROKEN_MWDMA)
34827diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34828index f9b983a..887b9d8 100644
34829--- a/drivers/atm/adummy.c
34830+++ b/drivers/atm/adummy.c
34831@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34832 vcc->pop(vcc, skb);
34833 else
34834 dev_kfree_skb_any(skb);
34835- atomic_inc(&vcc->stats->tx);
34836+ atomic_inc_unchecked(&vcc->stats->tx);
34837
34838 return 0;
34839 }
34840diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34841index 62a7607..cc4be104 100644
34842--- a/drivers/atm/ambassador.c
34843+++ b/drivers/atm/ambassador.c
34844@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34845 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34846
34847 // VC layer stats
34848- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34849+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34850
34851 // free the descriptor
34852 kfree (tx_descr);
34853@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34854 dump_skb ("<<<", vc, skb);
34855
34856 // VC layer stats
34857- atomic_inc(&atm_vcc->stats->rx);
34858+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34859 __net_timestamp(skb);
34860 // end of our responsibility
34861 atm_vcc->push (atm_vcc, skb);
34862@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34863 } else {
34864 PRINTK (KERN_INFO, "dropped over-size frame");
34865 // should we count this?
34866- atomic_inc(&atm_vcc->stats->rx_drop);
34867+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34868 }
34869
34870 } else {
34871@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34872 }
34873
34874 if (check_area (skb->data, skb->len)) {
34875- atomic_inc(&atm_vcc->stats->tx_err);
34876+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34877 return -ENOMEM; // ?
34878 }
34879
34880diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34881index 0e3f8f9..765a7a5 100644
34882--- a/drivers/atm/atmtcp.c
34883+++ b/drivers/atm/atmtcp.c
34884@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34885 if (vcc->pop) vcc->pop(vcc,skb);
34886 else dev_kfree_skb(skb);
34887 if (dev_data) return 0;
34888- atomic_inc(&vcc->stats->tx_err);
34889+ atomic_inc_unchecked(&vcc->stats->tx_err);
34890 return -ENOLINK;
34891 }
34892 size = skb->len+sizeof(struct atmtcp_hdr);
34893@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34894 if (!new_skb) {
34895 if (vcc->pop) vcc->pop(vcc,skb);
34896 else dev_kfree_skb(skb);
34897- atomic_inc(&vcc->stats->tx_err);
34898+ atomic_inc_unchecked(&vcc->stats->tx_err);
34899 return -ENOBUFS;
34900 }
34901 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34902@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34903 if (vcc->pop) vcc->pop(vcc,skb);
34904 else dev_kfree_skb(skb);
34905 out_vcc->push(out_vcc,new_skb);
34906- atomic_inc(&vcc->stats->tx);
34907- atomic_inc(&out_vcc->stats->rx);
34908+ atomic_inc_unchecked(&vcc->stats->tx);
34909+ atomic_inc_unchecked(&out_vcc->stats->rx);
34910 return 0;
34911 }
34912
34913@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34914 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34915 read_unlock(&vcc_sklist_lock);
34916 if (!out_vcc) {
34917- atomic_inc(&vcc->stats->tx_err);
34918+ atomic_inc_unchecked(&vcc->stats->tx_err);
34919 goto done;
34920 }
34921 skb_pull(skb,sizeof(struct atmtcp_hdr));
34922@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34923 __net_timestamp(new_skb);
34924 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34925 out_vcc->push(out_vcc,new_skb);
34926- atomic_inc(&vcc->stats->tx);
34927- atomic_inc(&out_vcc->stats->rx);
34928+ atomic_inc_unchecked(&vcc->stats->tx);
34929+ atomic_inc_unchecked(&out_vcc->stats->rx);
34930 done:
34931 if (vcc->pop) vcc->pop(vcc,skb);
34932 else dev_kfree_skb(skb);
34933diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34934index b1955ba..b179940 100644
34935--- a/drivers/atm/eni.c
34936+++ b/drivers/atm/eni.c
34937@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34938 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34939 vcc->dev->number);
34940 length = 0;
34941- atomic_inc(&vcc->stats->rx_err);
34942+ atomic_inc_unchecked(&vcc->stats->rx_err);
34943 }
34944 else {
34945 length = ATM_CELL_SIZE-1; /* no HEC */
34946@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34947 size);
34948 }
34949 eff = length = 0;
34950- atomic_inc(&vcc->stats->rx_err);
34951+ atomic_inc_unchecked(&vcc->stats->rx_err);
34952 }
34953 else {
34954 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34955@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34956 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34957 vcc->dev->number,vcc->vci,length,size << 2,descr);
34958 length = eff = 0;
34959- atomic_inc(&vcc->stats->rx_err);
34960+ atomic_inc_unchecked(&vcc->stats->rx_err);
34961 }
34962 }
34963 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34964@@ -767,7 +767,7 @@ rx_dequeued++;
34965 vcc->push(vcc,skb);
34966 pushed++;
34967 }
34968- atomic_inc(&vcc->stats->rx);
34969+ atomic_inc_unchecked(&vcc->stats->rx);
34970 }
34971 wake_up(&eni_dev->rx_wait);
34972 }
34973@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34974 PCI_DMA_TODEVICE);
34975 if (vcc->pop) vcc->pop(vcc,skb);
34976 else dev_kfree_skb_irq(skb);
34977- atomic_inc(&vcc->stats->tx);
34978+ atomic_inc_unchecked(&vcc->stats->tx);
34979 wake_up(&eni_dev->tx_wait);
34980 dma_complete++;
34981 }
34982diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34983index b41c948..a002b17 100644
34984--- a/drivers/atm/firestream.c
34985+++ b/drivers/atm/firestream.c
34986@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34987 }
34988 }
34989
34990- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34991+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34992
34993 fs_dprintk (FS_DEBUG_TXMEM, "i");
34994 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34995@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34996 #endif
34997 skb_put (skb, qe->p1 & 0xffff);
34998 ATM_SKB(skb)->vcc = atm_vcc;
34999- atomic_inc(&atm_vcc->stats->rx);
35000+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35001 __net_timestamp(skb);
35002 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35003 atm_vcc->push (atm_vcc, skb);
35004@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35005 kfree (pe);
35006 }
35007 if (atm_vcc)
35008- atomic_inc(&atm_vcc->stats->rx_drop);
35009+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35010 break;
35011 case 0x1f: /* Reassembly abort: no buffers. */
35012 /* Silently increment error counter. */
35013 if (atm_vcc)
35014- atomic_inc(&atm_vcc->stats->rx_drop);
35015+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35016 break;
35017 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35018 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35019diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35020index 204814e..cede831 100644
35021--- a/drivers/atm/fore200e.c
35022+++ b/drivers/atm/fore200e.c
35023@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35024 #endif
35025 /* check error condition */
35026 if (*entry->status & STATUS_ERROR)
35027- atomic_inc(&vcc->stats->tx_err);
35028+ atomic_inc_unchecked(&vcc->stats->tx_err);
35029 else
35030- atomic_inc(&vcc->stats->tx);
35031+ atomic_inc_unchecked(&vcc->stats->tx);
35032 }
35033 }
35034
35035@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35036 if (skb == NULL) {
35037 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35038
35039- atomic_inc(&vcc->stats->rx_drop);
35040+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35041 return -ENOMEM;
35042 }
35043
35044@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35045
35046 dev_kfree_skb_any(skb);
35047
35048- atomic_inc(&vcc->stats->rx_drop);
35049+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35050 return -ENOMEM;
35051 }
35052
35053 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35054
35055 vcc->push(vcc, skb);
35056- atomic_inc(&vcc->stats->rx);
35057+ atomic_inc_unchecked(&vcc->stats->rx);
35058
35059 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35060
35061@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35062 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35063 fore200e->atm_dev->number,
35064 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35065- atomic_inc(&vcc->stats->rx_err);
35066+ atomic_inc_unchecked(&vcc->stats->rx_err);
35067 }
35068 }
35069
35070@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35071 goto retry_here;
35072 }
35073
35074- atomic_inc(&vcc->stats->tx_err);
35075+ atomic_inc_unchecked(&vcc->stats->tx_err);
35076
35077 fore200e->tx_sat++;
35078 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35079diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35080index 507362a..a845e57 100644
35081--- a/drivers/atm/he.c
35082+++ b/drivers/atm/he.c
35083@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35084
35085 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35086 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35087- atomic_inc(&vcc->stats->rx_drop);
35088+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35089 goto return_host_buffers;
35090 }
35091
35092@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35093 RBRQ_LEN_ERR(he_dev->rbrq_head)
35094 ? "LEN_ERR" : "",
35095 vcc->vpi, vcc->vci);
35096- atomic_inc(&vcc->stats->rx_err);
35097+ atomic_inc_unchecked(&vcc->stats->rx_err);
35098 goto return_host_buffers;
35099 }
35100
35101@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35102 vcc->push(vcc, skb);
35103 spin_lock(&he_dev->global_lock);
35104
35105- atomic_inc(&vcc->stats->rx);
35106+ atomic_inc_unchecked(&vcc->stats->rx);
35107
35108 return_host_buffers:
35109 ++pdus_assembled;
35110@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35111 tpd->vcc->pop(tpd->vcc, tpd->skb);
35112 else
35113 dev_kfree_skb_any(tpd->skb);
35114- atomic_inc(&tpd->vcc->stats->tx_err);
35115+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35116 }
35117 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35118 return;
35119@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35120 vcc->pop(vcc, skb);
35121 else
35122 dev_kfree_skb_any(skb);
35123- atomic_inc(&vcc->stats->tx_err);
35124+ atomic_inc_unchecked(&vcc->stats->tx_err);
35125 return -EINVAL;
35126 }
35127
35128@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35129 vcc->pop(vcc, skb);
35130 else
35131 dev_kfree_skb_any(skb);
35132- atomic_inc(&vcc->stats->tx_err);
35133+ atomic_inc_unchecked(&vcc->stats->tx_err);
35134 return -EINVAL;
35135 }
35136 #endif
35137@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35138 vcc->pop(vcc, skb);
35139 else
35140 dev_kfree_skb_any(skb);
35141- atomic_inc(&vcc->stats->tx_err);
35142+ atomic_inc_unchecked(&vcc->stats->tx_err);
35143 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35144 return -ENOMEM;
35145 }
35146@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35147 vcc->pop(vcc, skb);
35148 else
35149 dev_kfree_skb_any(skb);
35150- atomic_inc(&vcc->stats->tx_err);
35151+ atomic_inc_unchecked(&vcc->stats->tx_err);
35152 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35153 return -ENOMEM;
35154 }
35155@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35156 __enqueue_tpd(he_dev, tpd, cid);
35157 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35158
35159- atomic_inc(&vcc->stats->tx);
35160+ atomic_inc_unchecked(&vcc->stats->tx);
35161
35162 return 0;
35163 }
35164diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35165index 1dc0519..1aadaf7 100644
35166--- a/drivers/atm/horizon.c
35167+++ b/drivers/atm/horizon.c
35168@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35169 {
35170 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35171 // VC layer stats
35172- atomic_inc(&vcc->stats->rx);
35173+ atomic_inc_unchecked(&vcc->stats->rx);
35174 __net_timestamp(skb);
35175 // end of our responsibility
35176 vcc->push (vcc, skb);
35177@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35178 dev->tx_iovec = NULL;
35179
35180 // VC layer stats
35181- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35182+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35183
35184 // free the skb
35185 hrz_kfree_skb (skb);
35186diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35187index 272f009..a18ba55 100644
35188--- a/drivers/atm/idt77252.c
35189+++ b/drivers/atm/idt77252.c
35190@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35191 else
35192 dev_kfree_skb(skb);
35193
35194- atomic_inc(&vcc->stats->tx);
35195+ atomic_inc_unchecked(&vcc->stats->tx);
35196 }
35197
35198 atomic_dec(&scq->used);
35199@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35200 if ((sb = dev_alloc_skb(64)) == NULL) {
35201 printk("%s: Can't allocate buffers for aal0.\n",
35202 card->name);
35203- atomic_add(i, &vcc->stats->rx_drop);
35204+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35205 break;
35206 }
35207 if (!atm_charge(vcc, sb->truesize)) {
35208 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35209 card->name);
35210- atomic_add(i - 1, &vcc->stats->rx_drop);
35211+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35212 dev_kfree_skb(sb);
35213 break;
35214 }
35215@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35216 ATM_SKB(sb)->vcc = vcc;
35217 __net_timestamp(sb);
35218 vcc->push(vcc, sb);
35219- atomic_inc(&vcc->stats->rx);
35220+ atomic_inc_unchecked(&vcc->stats->rx);
35221
35222 cell += ATM_CELL_PAYLOAD;
35223 }
35224@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35225 "(CDC: %08x)\n",
35226 card->name, len, rpp->len, readl(SAR_REG_CDC));
35227 recycle_rx_pool_skb(card, rpp);
35228- atomic_inc(&vcc->stats->rx_err);
35229+ atomic_inc_unchecked(&vcc->stats->rx_err);
35230 return;
35231 }
35232 if (stat & SAR_RSQE_CRC) {
35233 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35234 recycle_rx_pool_skb(card, rpp);
35235- atomic_inc(&vcc->stats->rx_err);
35236+ atomic_inc_unchecked(&vcc->stats->rx_err);
35237 return;
35238 }
35239 if (skb_queue_len(&rpp->queue) > 1) {
35240@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35241 RXPRINTK("%s: Can't alloc RX skb.\n",
35242 card->name);
35243 recycle_rx_pool_skb(card, rpp);
35244- atomic_inc(&vcc->stats->rx_err);
35245+ atomic_inc_unchecked(&vcc->stats->rx_err);
35246 return;
35247 }
35248 if (!atm_charge(vcc, skb->truesize)) {
35249@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35250 __net_timestamp(skb);
35251
35252 vcc->push(vcc, skb);
35253- atomic_inc(&vcc->stats->rx);
35254+ atomic_inc_unchecked(&vcc->stats->rx);
35255
35256 return;
35257 }
35258@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35259 __net_timestamp(skb);
35260
35261 vcc->push(vcc, skb);
35262- atomic_inc(&vcc->stats->rx);
35263+ atomic_inc_unchecked(&vcc->stats->rx);
35264
35265 if (skb->truesize > SAR_FB_SIZE_3)
35266 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35267@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35268 if (vcc->qos.aal != ATM_AAL0) {
35269 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35270 card->name, vpi, vci);
35271- atomic_inc(&vcc->stats->rx_drop);
35272+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35273 goto drop;
35274 }
35275
35276 if ((sb = dev_alloc_skb(64)) == NULL) {
35277 printk("%s: Can't allocate buffers for AAL0.\n",
35278 card->name);
35279- atomic_inc(&vcc->stats->rx_err);
35280+ atomic_inc_unchecked(&vcc->stats->rx_err);
35281 goto drop;
35282 }
35283
35284@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35285 ATM_SKB(sb)->vcc = vcc;
35286 __net_timestamp(sb);
35287 vcc->push(vcc, sb);
35288- atomic_inc(&vcc->stats->rx);
35289+ atomic_inc_unchecked(&vcc->stats->rx);
35290
35291 drop:
35292 skb_pull(queue, 64);
35293@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35294
35295 if (vc == NULL) {
35296 printk("%s: NULL connection in send().\n", card->name);
35297- atomic_inc(&vcc->stats->tx_err);
35298+ atomic_inc_unchecked(&vcc->stats->tx_err);
35299 dev_kfree_skb(skb);
35300 return -EINVAL;
35301 }
35302 if (!test_bit(VCF_TX, &vc->flags)) {
35303 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35304- atomic_inc(&vcc->stats->tx_err);
35305+ atomic_inc_unchecked(&vcc->stats->tx_err);
35306 dev_kfree_skb(skb);
35307 return -EINVAL;
35308 }
35309@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35310 break;
35311 default:
35312 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35313- atomic_inc(&vcc->stats->tx_err);
35314+ atomic_inc_unchecked(&vcc->stats->tx_err);
35315 dev_kfree_skb(skb);
35316 return -EINVAL;
35317 }
35318
35319 if (skb_shinfo(skb)->nr_frags != 0) {
35320 printk("%s: No scatter-gather yet.\n", card->name);
35321- atomic_inc(&vcc->stats->tx_err);
35322+ atomic_inc_unchecked(&vcc->stats->tx_err);
35323 dev_kfree_skb(skb);
35324 return -EINVAL;
35325 }
35326@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35327
35328 err = queue_skb(card, vc, skb, oam);
35329 if (err) {
35330- atomic_inc(&vcc->stats->tx_err);
35331+ atomic_inc_unchecked(&vcc->stats->tx_err);
35332 dev_kfree_skb(skb);
35333 return err;
35334 }
35335@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35336 skb = dev_alloc_skb(64);
35337 if (!skb) {
35338 printk("%s: Out of memory in send_oam().\n", card->name);
35339- atomic_inc(&vcc->stats->tx_err);
35340+ atomic_inc_unchecked(&vcc->stats->tx_err);
35341 return -ENOMEM;
35342 }
35343 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35344diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35345index 4217f29..88f547a 100644
35346--- a/drivers/atm/iphase.c
35347+++ b/drivers/atm/iphase.c
35348@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35349 status = (u_short) (buf_desc_ptr->desc_mode);
35350 if (status & (RX_CER | RX_PTE | RX_OFL))
35351 {
35352- atomic_inc(&vcc->stats->rx_err);
35353+ atomic_inc_unchecked(&vcc->stats->rx_err);
35354 IF_ERR(printk("IA: bad packet, dropping it");)
35355 if (status & RX_CER) {
35356 IF_ERR(printk(" cause: packet CRC error\n");)
35357@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35358 len = dma_addr - buf_addr;
35359 if (len > iadev->rx_buf_sz) {
35360 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35361- atomic_inc(&vcc->stats->rx_err);
35362+ atomic_inc_unchecked(&vcc->stats->rx_err);
35363 goto out_free_desc;
35364 }
35365
35366@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35367 ia_vcc = INPH_IA_VCC(vcc);
35368 if (ia_vcc == NULL)
35369 {
35370- atomic_inc(&vcc->stats->rx_err);
35371+ atomic_inc_unchecked(&vcc->stats->rx_err);
35372 atm_return(vcc, skb->truesize);
35373 dev_kfree_skb_any(skb);
35374 goto INCR_DLE;
35375@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35376 if ((length > iadev->rx_buf_sz) || (length >
35377 (skb->len - sizeof(struct cpcs_trailer))))
35378 {
35379- atomic_inc(&vcc->stats->rx_err);
35380+ atomic_inc_unchecked(&vcc->stats->rx_err);
35381 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35382 length, skb->len);)
35383 atm_return(vcc, skb->truesize);
35384@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35385
35386 IF_RX(printk("rx_dle_intr: skb push");)
35387 vcc->push(vcc,skb);
35388- atomic_inc(&vcc->stats->rx);
35389+ atomic_inc_unchecked(&vcc->stats->rx);
35390 iadev->rx_pkt_cnt++;
35391 }
35392 INCR_DLE:
35393@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35394 {
35395 struct k_sonet_stats *stats;
35396 stats = &PRIV(_ia_dev[board])->sonet_stats;
35397- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35398- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35399- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35400- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35401- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35402- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35403- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35404- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35405- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35406+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35407+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35408+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35409+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35410+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35411+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35412+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35413+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35414+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35415 }
35416 ia_cmds.status = 0;
35417 break;
35418@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35419 if ((desc == 0) || (desc > iadev->num_tx_desc))
35420 {
35421 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35422- atomic_inc(&vcc->stats->tx);
35423+ atomic_inc_unchecked(&vcc->stats->tx);
35424 if (vcc->pop)
35425 vcc->pop(vcc, skb);
35426 else
35427@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35428 ATM_DESC(skb) = vcc->vci;
35429 skb_queue_tail(&iadev->tx_dma_q, skb);
35430
35431- atomic_inc(&vcc->stats->tx);
35432+ atomic_inc_unchecked(&vcc->stats->tx);
35433 iadev->tx_pkt_cnt++;
35434 /* Increment transaction counter */
35435 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35436
35437 #if 0
35438 /* add flow control logic */
35439- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35440+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35441 if (iavcc->vc_desc_cnt > 10) {
35442 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35443 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35444diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35445index fa7d701..1e404c7 100644
35446--- a/drivers/atm/lanai.c
35447+++ b/drivers/atm/lanai.c
35448@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35449 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35450 lanai_endtx(lanai, lvcc);
35451 lanai_free_skb(lvcc->tx.atmvcc, skb);
35452- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35453+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35454 }
35455
35456 /* Try to fill the buffer - don't call unless there is backlog */
35457@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35458 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35459 __net_timestamp(skb);
35460 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35461- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35462+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35463 out:
35464 lvcc->rx.buf.ptr = end;
35465 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35466@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35467 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35468 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35469 lanai->stats.service_rxnotaal5++;
35470- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35471+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35472 return 0;
35473 }
35474 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35475@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35476 int bytes;
35477 read_unlock(&vcc_sklist_lock);
35478 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35479- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35480+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35481 lvcc->stats.x.aal5.service_trash++;
35482 bytes = (SERVICE_GET_END(s) * 16) -
35483 (((unsigned long) lvcc->rx.buf.ptr) -
35484@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35485 }
35486 if (s & SERVICE_STREAM) {
35487 read_unlock(&vcc_sklist_lock);
35488- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35489+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35490 lvcc->stats.x.aal5.service_stream++;
35491 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35492 "PDU on VCI %d!\n", lanai->number, vci);
35493@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35494 return 0;
35495 }
35496 DPRINTK("got rx crc error on vci %d\n", vci);
35497- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35498+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35499 lvcc->stats.x.aal5.service_rxcrc++;
35500 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35501 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35502diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35503index 6587dc2..149833d 100644
35504--- a/drivers/atm/nicstar.c
35505+++ b/drivers/atm/nicstar.c
35506@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35507 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35508 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35509 card->index);
35510- atomic_inc(&vcc->stats->tx_err);
35511+ atomic_inc_unchecked(&vcc->stats->tx_err);
35512 dev_kfree_skb_any(skb);
35513 return -EINVAL;
35514 }
35515@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35516 if (!vc->tx) {
35517 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35518 card->index);
35519- atomic_inc(&vcc->stats->tx_err);
35520+ atomic_inc_unchecked(&vcc->stats->tx_err);
35521 dev_kfree_skb_any(skb);
35522 return -EINVAL;
35523 }
35524@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35525 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35526 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35527 card->index);
35528- atomic_inc(&vcc->stats->tx_err);
35529+ atomic_inc_unchecked(&vcc->stats->tx_err);
35530 dev_kfree_skb_any(skb);
35531 return -EINVAL;
35532 }
35533
35534 if (skb_shinfo(skb)->nr_frags != 0) {
35535 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35536- atomic_inc(&vcc->stats->tx_err);
35537+ atomic_inc_unchecked(&vcc->stats->tx_err);
35538 dev_kfree_skb_any(skb);
35539 return -EINVAL;
35540 }
35541@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35542 }
35543
35544 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35545- atomic_inc(&vcc->stats->tx_err);
35546+ atomic_inc_unchecked(&vcc->stats->tx_err);
35547 dev_kfree_skb_any(skb);
35548 return -EIO;
35549 }
35550- atomic_inc(&vcc->stats->tx);
35551+ atomic_inc_unchecked(&vcc->stats->tx);
35552
35553 return 0;
35554 }
35555@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35556 printk
35557 ("nicstar%d: Can't allocate buffers for aal0.\n",
35558 card->index);
35559- atomic_add(i, &vcc->stats->rx_drop);
35560+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35561 break;
35562 }
35563 if (!atm_charge(vcc, sb->truesize)) {
35564 RXPRINTK
35565 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35566 card->index);
35567- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35568+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35569 dev_kfree_skb_any(sb);
35570 break;
35571 }
35572@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35573 ATM_SKB(sb)->vcc = vcc;
35574 __net_timestamp(sb);
35575 vcc->push(vcc, sb);
35576- atomic_inc(&vcc->stats->rx);
35577+ atomic_inc_unchecked(&vcc->stats->rx);
35578 cell += ATM_CELL_PAYLOAD;
35579 }
35580
35581@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35582 if (iovb == NULL) {
35583 printk("nicstar%d: Out of iovec buffers.\n",
35584 card->index);
35585- atomic_inc(&vcc->stats->rx_drop);
35586+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35587 recycle_rx_buf(card, skb);
35588 return;
35589 }
35590@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35591 small or large buffer itself. */
35592 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35593 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35594- atomic_inc(&vcc->stats->rx_err);
35595+ atomic_inc_unchecked(&vcc->stats->rx_err);
35596 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35597 NS_MAX_IOVECS);
35598 NS_PRV_IOVCNT(iovb) = 0;
35599@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35600 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35601 card->index);
35602 which_list(card, skb);
35603- atomic_inc(&vcc->stats->rx_err);
35604+ atomic_inc_unchecked(&vcc->stats->rx_err);
35605 recycle_rx_buf(card, skb);
35606 vc->rx_iov = NULL;
35607 recycle_iov_buf(card, iovb);
35608@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35609 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35610 card->index);
35611 which_list(card, skb);
35612- atomic_inc(&vcc->stats->rx_err);
35613+ atomic_inc_unchecked(&vcc->stats->rx_err);
35614 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35615 NS_PRV_IOVCNT(iovb));
35616 vc->rx_iov = NULL;
35617@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35618 printk(" - PDU size mismatch.\n");
35619 else
35620 printk(".\n");
35621- atomic_inc(&vcc->stats->rx_err);
35622+ atomic_inc_unchecked(&vcc->stats->rx_err);
35623 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35624 NS_PRV_IOVCNT(iovb));
35625 vc->rx_iov = NULL;
35626@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35627 /* skb points to a small buffer */
35628 if (!atm_charge(vcc, skb->truesize)) {
35629 push_rxbufs(card, skb);
35630- atomic_inc(&vcc->stats->rx_drop);
35631+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35632 } else {
35633 skb_put(skb, len);
35634 dequeue_sm_buf(card, skb);
35635@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35636 ATM_SKB(skb)->vcc = vcc;
35637 __net_timestamp(skb);
35638 vcc->push(vcc, skb);
35639- atomic_inc(&vcc->stats->rx);
35640+ atomic_inc_unchecked(&vcc->stats->rx);
35641 }
35642 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35643 struct sk_buff *sb;
35644@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35645 if (len <= NS_SMBUFSIZE) {
35646 if (!atm_charge(vcc, sb->truesize)) {
35647 push_rxbufs(card, sb);
35648- atomic_inc(&vcc->stats->rx_drop);
35649+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35650 } else {
35651 skb_put(sb, len);
35652 dequeue_sm_buf(card, sb);
35653@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35654 ATM_SKB(sb)->vcc = vcc;
35655 __net_timestamp(sb);
35656 vcc->push(vcc, sb);
35657- atomic_inc(&vcc->stats->rx);
35658+ atomic_inc_unchecked(&vcc->stats->rx);
35659 }
35660
35661 push_rxbufs(card, skb);
35662@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35663
35664 if (!atm_charge(vcc, skb->truesize)) {
35665 push_rxbufs(card, skb);
35666- atomic_inc(&vcc->stats->rx_drop);
35667+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35668 } else {
35669 dequeue_lg_buf(card, skb);
35670 #ifdef NS_USE_DESTRUCTORS
35671@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35672 ATM_SKB(skb)->vcc = vcc;
35673 __net_timestamp(skb);
35674 vcc->push(vcc, skb);
35675- atomic_inc(&vcc->stats->rx);
35676+ atomic_inc_unchecked(&vcc->stats->rx);
35677 }
35678
35679 push_rxbufs(card, sb);
35680@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35681 printk
35682 ("nicstar%d: Out of huge buffers.\n",
35683 card->index);
35684- atomic_inc(&vcc->stats->rx_drop);
35685+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35686 recycle_iovec_rx_bufs(card,
35687 (struct iovec *)
35688 iovb->data,
35689@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35690 card->hbpool.count++;
35691 } else
35692 dev_kfree_skb_any(hb);
35693- atomic_inc(&vcc->stats->rx_drop);
35694+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35695 } else {
35696 /* Copy the small buffer to the huge buffer */
35697 sb = (struct sk_buff *)iov->iov_base;
35698@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35699 #endif /* NS_USE_DESTRUCTORS */
35700 __net_timestamp(hb);
35701 vcc->push(vcc, hb);
35702- atomic_inc(&vcc->stats->rx);
35703+ atomic_inc_unchecked(&vcc->stats->rx);
35704 }
35705 }
35706
35707diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35708index 32784d1..4a8434a 100644
35709--- a/drivers/atm/solos-pci.c
35710+++ b/drivers/atm/solos-pci.c
35711@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35712 }
35713 atm_charge(vcc, skb->truesize);
35714 vcc->push(vcc, skb);
35715- atomic_inc(&vcc->stats->rx);
35716+ atomic_inc_unchecked(&vcc->stats->rx);
35717 break;
35718
35719 case PKT_STATUS:
35720@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35721 vcc = SKB_CB(oldskb)->vcc;
35722
35723 if (vcc) {
35724- atomic_inc(&vcc->stats->tx);
35725+ atomic_inc_unchecked(&vcc->stats->tx);
35726 solos_pop(vcc, oldskb);
35727 } else {
35728 dev_kfree_skb_irq(oldskb);
35729diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35730index 0215934..ce9f5b1 100644
35731--- a/drivers/atm/suni.c
35732+++ b/drivers/atm/suni.c
35733@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35734
35735
35736 #define ADD_LIMITED(s,v) \
35737- atomic_add((v),&stats->s); \
35738- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35739+ atomic_add_unchecked((v),&stats->s); \
35740+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35741
35742
35743 static void suni_hz(unsigned long from_timer)
35744diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35745index 5120a96..e2572bd 100644
35746--- a/drivers/atm/uPD98402.c
35747+++ b/drivers/atm/uPD98402.c
35748@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35749 struct sonet_stats tmp;
35750 int error = 0;
35751
35752- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35753+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35754 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35755 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35756 if (zero && !error) {
35757@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35758
35759
35760 #define ADD_LIMITED(s,v) \
35761- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35762- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35763- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35764+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35765+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35766+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35767
35768
35769 static void stat_event(struct atm_dev *dev)
35770@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35771 if (reason & uPD98402_INT_PFM) stat_event(dev);
35772 if (reason & uPD98402_INT_PCO) {
35773 (void) GET(PCOCR); /* clear interrupt cause */
35774- atomic_add(GET(HECCT),
35775+ atomic_add_unchecked(GET(HECCT),
35776 &PRIV(dev)->sonet_stats.uncorr_hcs);
35777 }
35778 if ((reason & uPD98402_INT_RFO) &&
35779@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35780 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35781 uPD98402_INT_LOS),PIMR); /* enable them */
35782 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35783- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35784- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35785- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35786+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35787+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35788+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35789 return 0;
35790 }
35791
35792diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35793index 969c3c2..9b72956 100644
35794--- a/drivers/atm/zatm.c
35795+++ b/drivers/atm/zatm.c
35796@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35797 }
35798 if (!size) {
35799 dev_kfree_skb_irq(skb);
35800- if (vcc) atomic_inc(&vcc->stats->rx_err);
35801+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35802 continue;
35803 }
35804 if (!atm_charge(vcc,skb->truesize)) {
35805@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35806 skb->len = size;
35807 ATM_SKB(skb)->vcc = vcc;
35808 vcc->push(vcc,skb);
35809- atomic_inc(&vcc->stats->rx);
35810+ atomic_inc_unchecked(&vcc->stats->rx);
35811 }
35812 zout(pos & 0xffff,MTA(mbx));
35813 #if 0 /* probably a stupid idea */
35814@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35815 skb_queue_head(&zatm_vcc->backlog,skb);
35816 break;
35817 }
35818- atomic_inc(&vcc->stats->tx);
35819+ atomic_inc_unchecked(&vcc->stats->tx);
35820 wake_up(&zatm_vcc->tx_wait);
35821 }
35822
35823diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35824index d414331..b4dd4ba 100644
35825--- a/drivers/base/bus.c
35826+++ b/drivers/base/bus.c
35827@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35828 return -EINVAL;
35829
35830 mutex_lock(&subsys->p->mutex);
35831- list_add_tail(&sif->node, &subsys->p->interfaces);
35832+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35833 if (sif->add_dev) {
35834 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35835 while ((dev = subsys_dev_iter_next(&iter)))
35836@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35837 subsys = sif->subsys;
35838
35839 mutex_lock(&subsys->p->mutex);
35840- list_del_init(&sif->node);
35841+ pax_list_del_init((struct list_head *)&sif->node);
35842 if (sif->remove_dev) {
35843 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35844 while ((dev = subsys_dev_iter_next(&iter)))
35845diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35846index 7413d06..79155fa 100644
35847--- a/drivers/base/devtmpfs.c
35848+++ b/drivers/base/devtmpfs.c
35849@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35850 if (!thread)
35851 return 0;
35852
35853- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35854+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35855 if (err)
35856 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35857 else
35858@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35859 *err = sys_unshare(CLONE_NEWNS);
35860 if (*err)
35861 goto out;
35862- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35863+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35864 if (*err)
35865 goto out;
35866- sys_chdir("/.."); /* will traverse into overmounted root */
35867- sys_chroot(".");
35868+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35869+ sys_chroot((char __force_user *)".");
35870 complete(&setup_done);
35871 while (1) {
35872 spin_lock(&req_lock);
35873diff --git a/drivers/base/node.c b/drivers/base/node.c
35874index 7616a77c..8f57f51 100644
35875--- a/drivers/base/node.c
35876+++ b/drivers/base/node.c
35877@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35878 struct node_attr {
35879 struct device_attribute attr;
35880 enum node_states state;
35881-};
35882+} __do_const;
35883
35884 static ssize_t show_node_state(struct device *dev,
35885 struct device_attribute *attr, char *buf)
35886diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35887index bfb8955..42c9b9a 100644
35888--- a/drivers/base/power/domain.c
35889+++ b/drivers/base/power/domain.c
35890@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35891 {
35892 struct cpuidle_driver *cpuidle_drv;
35893 struct gpd_cpu_data *cpu_data;
35894- struct cpuidle_state *idle_state;
35895+ cpuidle_state_no_const *idle_state;
35896 int ret = 0;
35897
35898 if (IS_ERR_OR_NULL(genpd) || state < 0)
35899@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35900 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35901 {
35902 struct gpd_cpu_data *cpu_data;
35903- struct cpuidle_state *idle_state;
35904+ cpuidle_state_no_const *idle_state;
35905 int ret = 0;
35906
35907 if (IS_ERR_OR_NULL(genpd))
35908diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35909index a53ebd2..8f73eeb 100644
35910--- a/drivers/base/power/sysfs.c
35911+++ b/drivers/base/power/sysfs.c
35912@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35913 return -EIO;
35914 }
35915 }
35916- return sprintf(buf, p);
35917+ return sprintf(buf, "%s", p);
35918 }
35919
35920 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35921diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35922index 2d56f41..8830f19 100644
35923--- a/drivers/base/power/wakeup.c
35924+++ b/drivers/base/power/wakeup.c
35925@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35926 * They need to be modified together atomically, so it's better to use one
35927 * atomic variable to hold them both.
35928 */
35929-static atomic_t combined_event_count = ATOMIC_INIT(0);
35930+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35931
35932 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35933 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35934
35935 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35936 {
35937- unsigned int comb = atomic_read(&combined_event_count);
35938+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35939
35940 *cnt = (comb >> IN_PROGRESS_BITS);
35941 *inpr = comb & MAX_IN_PROGRESS;
35942@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35943 ws->start_prevent_time = ws->last_time;
35944
35945 /* Increment the counter of events in progress. */
35946- cec = atomic_inc_return(&combined_event_count);
35947+ cec = atomic_inc_return_unchecked(&combined_event_count);
35948
35949 trace_wakeup_source_activate(ws->name, cec);
35950 }
35951@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35952 * Increment the counter of registered wakeup events and decrement the
35953 * couter of wakeup events in progress simultaneously.
35954 */
35955- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35956+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35957 trace_wakeup_source_deactivate(ws->name, cec);
35958
35959 split_counters(&cnt, &inpr);
35960diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35961index e8d11b6..7b1b36f 100644
35962--- a/drivers/base/syscore.c
35963+++ b/drivers/base/syscore.c
35964@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35965 void register_syscore_ops(struct syscore_ops *ops)
35966 {
35967 mutex_lock(&syscore_ops_lock);
35968- list_add_tail(&ops->node, &syscore_ops_list);
35969+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35970 mutex_unlock(&syscore_ops_lock);
35971 }
35972 EXPORT_SYMBOL_GPL(register_syscore_ops);
35973@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35974 void unregister_syscore_ops(struct syscore_ops *ops)
35975 {
35976 mutex_lock(&syscore_ops_lock);
35977- list_del(&ops->node);
35978+ pax_list_del((struct list_head *)&ops->node);
35979 mutex_unlock(&syscore_ops_lock);
35980 }
35981 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35982diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35983index 62b6c2c..4a11354 100644
35984--- a/drivers/block/cciss.c
35985+++ b/drivers/block/cciss.c
35986@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35987 int err;
35988 u32 cp;
35989
35990+ memset(&arg64, 0, sizeof(arg64));
35991+
35992 err = 0;
35993 err |=
35994 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35995@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35996 while (!list_empty(&h->reqQ)) {
35997 c = list_entry(h->reqQ.next, CommandList_struct, list);
35998 /* can't do anything if fifo is full */
35999- if ((h->access.fifo_full(h))) {
36000+ if ((h->access->fifo_full(h))) {
36001 dev_warn(&h->pdev->dev, "fifo full\n");
36002 break;
36003 }
36004@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
36005 h->Qdepth--;
36006
36007 /* Tell the controller execute command */
36008- h->access.submit_command(h, c);
36009+ h->access->submit_command(h, c);
36010
36011 /* Put job onto the completed Q */
36012 addQ(&h->cmpQ, c);
36013@@ -3446,17 +3448,17 @@ startio:
36014
36015 static inline unsigned long get_next_completion(ctlr_info_t *h)
36016 {
36017- return h->access.command_completed(h);
36018+ return h->access->command_completed(h);
36019 }
36020
36021 static inline int interrupt_pending(ctlr_info_t *h)
36022 {
36023- return h->access.intr_pending(h);
36024+ return h->access->intr_pending(h);
36025 }
36026
36027 static inline long interrupt_not_for_us(ctlr_info_t *h)
36028 {
36029- return ((h->access.intr_pending(h) == 0) ||
36030+ return ((h->access->intr_pending(h) == 0) ||
36031 (h->interrupts_enabled == 0));
36032 }
36033
36034@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
36035 u32 a;
36036
36037 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36038- return h->access.command_completed(h);
36039+ return h->access->command_completed(h);
36040
36041 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36042 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36043@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36044 trans_support & CFGTBL_Trans_use_short_tags);
36045
36046 /* Change the access methods to the performant access methods */
36047- h->access = SA5_performant_access;
36048+ h->access = &SA5_performant_access;
36049 h->transMethod = CFGTBL_Trans_Performant;
36050
36051 return;
36052@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36053 if (prod_index < 0)
36054 return -ENODEV;
36055 h->product_name = products[prod_index].product_name;
36056- h->access = *(products[prod_index].access);
36057+ h->access = products[prod_index].access;
36058
36059 if (cciss_board_disabled(h)) {
36060 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36061@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
36062 }
36063
36064 /* make sure the board interrupts are off */
36065- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36066+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36067 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36068 if (rc)
36069 goto clean2;
36070@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
36071 * fake ones to scoop up any residual completions.
36072 */
36073 spin_lock_irqsave(&h->lock, flags);
36074- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36075+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36076 spin_unlock_irqrestore(&h->lock, flags);
36077 free_irq(h->intr[h->intr_mode], h);
36078 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36079@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36080 dev_info(&h->pdev->dev, "Board READY.\n");
36081 dev_info(&h->pdev->dev,
36082 "Waiting for stale completions to drain.\n");
36083- h->access.set_intr_mask(h, CCISS_INTR_ON);
36084+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36085 msleep(10000);
36086- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36087+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36088
36089 rc = controller_reset_failed(h->cfgtable);
36090 if (rc)
36091@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36092 cciss_scsi_setup(h);
36093
36094 /* Turn the interrupts on so we can service requests */
36095- h->access.set_intr_mask(h, CCISS_INTR_ON);
36096+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36097
36098 /* Get the firmware version */
36099 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36100@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36101 kfree(flush_buf);
36102 if (return_code != IO_OK)
36103 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36104- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36105+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36106 free_irq(h->intr[h->intr_mode], h);
36107 }
36108
36109diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36110index 7fda30e..eb5dfe0 100644
36111--- a/drivers/block/cciss.h
36112+++ b/drivers/block/cciss.h
36113@@ -101,7 +101,7 @@ struct ctlr_info
36114 /* information about each logical volume */
36115 drive_info_struct *drv[CISS_MAX_LUN];
36116
36117- struct access_method access;
36118+ struct access_method *access;
36119
36120 /* queue and queue Info */
36121 struct list_head reqQ;
36122diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36123index 639d26b..fd6ad1f 100644
36124--- a/drivers/block/cpqarray.c
36125+++ b/drivers/block/cpqarray.c
36126@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36127 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36128 goto Enomem4;
36129 }
36130- hba[i]->access.set_intr_mask(hba[i], 0);
36131+ hba[i]->access->set_intr_mask(hba[i], 0);
36132 if (request_irq(hba[i]->intr, do_ida_intr,
36133 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36134 {
36135@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36136 add_timer(&hba[i]->timer);
36137
36138 /* Enable IRQ now that spinlock and rate limit timer are set up */
36139- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36140+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36141
36142 for(j=0; j<NWD; j++) {
36143 struct gendisk *disk = ida_gendisk[i][j];
36144@@ -694,7 +694,7 @@ DBGINFO(
36145 for(i=0; i<NR_PRODUCTS; i++) {
36146 if (board_id == products[i].board_id) {
36147 c->product_name = products[i].product_name;
36148- c->access = *(products[i].access);
36149+ c->access = products[i].access;
36150 break;
36151 }
36152 }
36153@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36154 hba[ctlr]->intr = intr;
36155 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36156 hba[ctlr]->product_name = products[j].product_name;
36157- hba[ctlr]->access = *(products[j].access);
36158+ hba[ctlr]->access = products[j].access;
36159 hba[ctlr]->ctlr = ctlr;
36160 hba[ctlr]->board_id = board_id;
36161 hba[ctlr]->pci_dev = NULL; /* not PCI */
36162@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36163
36164 while((c = h->reqQ) != NULL) {
36165 /* Can't do anything if we're busy */
36166- if (h->access.fifo_full(h) == 0)
36167+ if (h->access->fifo_full(h) == 0)
36168 return;
36169
36170 /* Get the first entry from the request Q */
36171@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36172 h->Qdepth--;
36173
36174 /* Tell the controller to do our bidding */
36175- h->access.submit_command(h, c);
36176+ h->access->submit_command(h, c);
36177
36178 /* Get onto the completion Q */
36179 addQ(&h->cmpQ, c);
36180@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36181 unsigned long flags;
36182 __u32 a,a1;
36183
36184- istat = h->access.intr_pending(h);
36185+ istat = h->access->intr_pending(h);
36186 /* Is this interrupt for us? */
36187 if (istat == 0)
36188 return IRQ_NONE;
36189@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36190 */
36191 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36192 if (istat & FIFO_NOT_EMPTY) {
36193- while((a = h->access.command_completed(h))) {
36194+ while((a = h->access->command_completed(h))) {
36195 a1 = a; a &= ~3;
36196 if ((c = h->cmpQ) == NULL)
36197 {
36198@@ -1193,6 +1193,7 @@ out_passthru:
36199 ida_pci_info_struct pciinfo;
36200
36201 if (!arg) return -EINVAL;
36202+ memset(&pciinfo, 0, sizeof(pciinfo));
36203 pciinfo.bus = host->pci_dev->bus->number;
36204 pciinfo.dev_fn = host->pci_dev->devfn;
36205 pciinfo.board_id = host->board_id;
36206@@ -1447,11 +1448,11 @@ static int sendcmd(
36207 /*
36208 * Disable interrupt
36209 */
36210- info_p->access.set_intr_mask(info_p, 0);
36211+ info_p->access->set_intr_mask(info_p, 0);
36212 /* Make sure there is room in the command FIFO */
36213 /* Actually it should be completely empty at this time. */
36214 for (i = 200000; i > 0; i--) {
36215- temp = info_p->access.fifo_full(info_p);
36216+ temp = info_p->access->fifo_full(info_p);
36217 if (temp != 0) {
36218 break;
36219 }
36220@@ -1464,7 +1465,7 @@ DBG(
36221 /*
36222 * Send the cmd
36223 */
36224- info_p->access.submit_command(info_p, c);
36225+ info_p->access->submit_command(info_p, c);
36226 complete = pollcomplete(ctlr);
36227
36228 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36229@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36230 * we check the new geometry. Then turn interrupts back on when
36231 * we're done.
36232 */
36233- host->access.set_intr_mask(host, 0);
36234+ host->access->set_intr_mask(host, 0);
36235 getgeometry(ctlr);
36236- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36237+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36238
36239 for(i=0; i<NWD; i++) {
36240 struct gendisk *disk = ida_gendisk[ctlr][i];
36241@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36242 /* Wait (up to 2 seconds) for a command to complete */
36243
36244 for (i = 200000; i > 0; i--) {
36245- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36246+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36247 if (done == 0) {
36248 udelay(10); /* a short fixed delay */
36249 } else
36250diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36251index be73e9d..7fbf140 100644
36252--- a/drivers/block/cpqarray.h
36253+++ b/drivers/block/cpqarray.h
36254@@ -99,7 +99,7 @@ struct ctlr_info {
36255 drv_info_t drv[NWD];
36256 struct proc_dir_entry *proc;
36257
36258- struct access_method access;
36259+ struct access_method *access;
36260
36261 cmdlist_t *reqQ;
36262 cmdlist_t *cmpQ;
36263diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36264index 2d7f608..11245fe 100644
36265--- a/drivers/block/drbd/drbd_int.h
36266+++ b/drivers/block/drbd/drbd_int.h
36267@@ -582,7 +582,7 @@ struct drbd_epoch {
36268 struct drbd_tconn *tconn;
36269 struct list_head list;
36270 unsigned int barrier_nr;
36271- atomic_t epoch_size; /* increased on every request added. */
36272+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36273 atomic_t active; /* increased on every req. added, and dec on every finished. */
36274 unsigned long flags;
36275 };
36276@@ -1022,7 +1022,7 @@ struct drbd_conf {
36277 unsigned int al_tr_number;
36278 int al_tr_cycle;
36279 wait_queue_head_t seq_wait;
36280- atomic_t packet_seq;
36281+ atomic_unchecked_t packet_seq;
36282 unsigned int peer_seq;
36283 spinlock_t peer_seq_lock;
36284 unsigned int minor;
36285@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36286 char __user *uoptval;
36287 int err;
36288
36289- uoptval = (char __user __force *)optval;
36290+ uoptval = (char __force_user *)optval;
36291
36292 set_fs(KERNEL_DS);
36293 if (level == SOL_SOCKET)
36294diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36295index 55635ed..40e837c 100644
36296--- a/drivers/block/drbd/drbd_main.c
36297+++ b/drivers/block/drbd/drbd_main.c
36298@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36299 p->sector = sector;
36300 p->block_id = block_id;
36301 p->blksize = blksize;
36302- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36303+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36304 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36305 }
36306
36307@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36308 return -EIO;
36309 p->sector = cpu_to_be64(req->i.sector);
36310 p->block_id = (unsigned long)req;
36311- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36312+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36313 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36314 if (mdev->state.conn >= C_SYNC_SOURCE &&
36315 mdev->state.conn <= C_PAUSED_SYNC_T)
36316@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36317 {
36318 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36319
36320- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36321- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36322+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36323+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36324 kfree(tconn->current_epoch);
36325
36326 idr_destroy(&tconn->volumes);
36327diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36328index 8cc1e64..ba7ffa9 100644
36329--- a/drivers/block/drbd/drbd_nl.c
36330+++ b/drivers/block/drbd/drbd_nl.c
36331@@ -3440,7 +3440,7 @@ out:
36332
36333 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36334 {
36335- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36336+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36337 struct sk_buff *msg;
36338 struct drbd_genlmsghdr *d_out;
36339 unsigned seq;
36340@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36341 return;
36342 }
36343
36344- seq = atomic_inc_return(&drbd_genl_seq);
36345+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36346 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36347 if (!msg)
36348 goto failed;
36349diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36350index cc29cd3..d4b058b 100644
36351--- a/drivers/block/drbd/drbd_receiver.c
36352+++ b/drivers/block/drbd/drbd_receiver.c
36353@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36354 {
36355 int err;
36356
36357- atomic_set(&mdev->packet_seq, 0);
36358+ atomic_set_unchecked(&mdev->packet_seq, 0);
36359 mdev->peer_seq = 0;
36360
36361 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36362@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36363 do {
36364 next_epoch = NULL;
36365
36366- epoch_size = atomic_read(&epoch->epoch_size);
36367+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36368
36369 switch (ev & ~EV_CLEANUP) {
36370 case EV_PUT:
36371@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36372 rv = FE_DESTROYED;
36373 } else {
36374 epoch->flags = 0;
36375- atomic_set(&epoch->epoch_size, 0);
36376+ atomic_set_unchecked(&epoch->epoch_size, 0);
36377 /* atomic_set(&epoch->active, 0); is already zero */
36378 if (rv == FE_STILL_LIVE)
36379 rv = FE_RECYCLED;
36380@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36381 conn_wait_active_ee_empty(tconn);
36382 drbd_flush(tconn);
36383
36384- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36385+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36386 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36387 if (epoch)
36388 break;
36389@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36390 }
36391
36392 epoch->flags = 0;
36393- atomic_set(&epoch->epoch_size, 0);
36394+ atomic_set_unchecked(&epoch->epoch_size, 0);
36395 atomic_set(&epoch->active, 0);
36396
36397 spin_lock(&tconn->epoch_lock);
36398- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36399+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36400 list_add(&epoch->list, &tconn->current_epoch->list);
36401 tconn->current_epoch = epoch;
36402 tconn->epochs++;
36403@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36404
36405 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36406 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36407- atomic_inc(&tconn->current_epoch->epoch_size);
36408+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36409 err2 = drbd_drain_block(mdev, pi->size);
36410 if (!err)
36411 err = err2;
36412@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36413
36414 spin_lock(&tconn->epoch_lock);
36415 peer_req->epoch = tconn->current_epoch;
36416- atomic_inc(&peer_req->epoch->epoch_size);
36417+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36418 atomic_inc(&peer_req->epoch->active);
36419 spin_unlock(&tconn->epoch_lock);
36420
36421@@ -4347,7 +4347,7 @@ struct data_cmd {
36422 int expect_payload;
36423 size_t pkt_size;
36424 int (*fn)(struct drbd_tconn *, struct packet_info *);
36425-};
36426+} __do_const;
36427
36428 static struct data_cmd drbd_cmd_handler[] = {
36429 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36430@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36431 if (!list_empty(&tconn->current_epoch->list))
36432 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36433 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36434- atomic_set(&tconn->current_epoch->epoch_size, 0);
36435+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36436 tconn->send.seen_any_write_yet = false;
36437
36438 conn_info(tconn, "Connection closed\n");
36439@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36440 struct asender_cmd {
36441 size_t pkt_size;
36442 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36443-};
36444+} __do_const;
36445
36446 static struct asender_cmd asender_tbl[] = {
36447 [P_PING] = { 0, got_Ping },
36448diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36449index 40e7155..df5c79a 100644
36450--- a/drivers/block/loop.c
36451+++ b/drivers/block/loop.c
36452@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36453
36454 file_start_write(file);
36455 set_fs(get_ds());
36456- bw = file->f_op->write(file, buf, len, &pos);
36457+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36458 set_fs(old_fs);
36459 file_end_write(file);
36460 if (likely(bw == len))
36461diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36462index f5d0ea1..c62380a 100644
36463--- a/drivers/block/pktcdvd.c
36464+++ b/drivers/block/pktcdvd.c
36465@@ -84,7 +84,7 @@
36466 #define MAX_SPEED 0xffff
36467
36468 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36469- ~(sector_t)((pd)->settings.size - 1))
36470+ ~(sector_t)((pd)->settings.size - 1UL))
36471
36472 static DEFINE_MUTEX(pktcdvd_mutex);
36473 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36474diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36475index 7332889..9ece19e 100644
36476--- a/drivers/bus/arm-cci.c
36477+++ b/drivers/bus/arm-cci.c
36478@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36479
36480 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36481
36482- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36483+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36484 if (!ports)
36485 return -ENOMEM;
36486
36487diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36488index 8a3aff7..d7538c2 100644
36489--- a/drivers/cdrom/cdrom.c
36490+++ b/drivers/cdrom/cdrom.c
36491@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36492 ENSURE(reset, CDC_RESET);
36493 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36494 cdi->mc_flags = 0;
36495- cdo->n_minors = 0;
36496 cdi->options = CDO_USE_FFLAGS;
36497
36498 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36499@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36500 else
36501 cdi->cdda_method = CDDA_OLD;
36502
36503- if (!cdo->generic_packet)
36504- cdo->generic_packet = cdrom_dummy_generic_packet;
36505+ if (!cdo->generic_packet) {
36506+ pax_open_kernel();
36507+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36508+ pax_close_kernel();
36509+ }
36510
36511 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36512 mutex_lock(&cdrom_mutex);
36513@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36514 if (cdi->exit)
36515 cdi->exit(cdi);
36516
36517- cdi->ops->n_minors--;
36518 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36519 }
36520
36521@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36522 */
36523 nr = nframes;
36524 do {
36525- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36526+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36527 if (cgc.buffer)
36528 break;
36529
36530@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36531 struct cdrom_device_info *cdi;
36532 int ret;
36533
36534- ret = scnprintf(info + *pos, max_size - *pos, header);
36535+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36536 if (!ret)
36537 return 1;
36538
36539diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36540index 5980cb9..6d7bd7e 100644
36541--- a/drivers/cdrom/gdrom.c
36542+++ b/drivers/cdrom/gdrom.c
36543@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36544 .audio_ioctl = gdrom_audio_ioctl,
36545 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36546 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36547- .n_minors = 1,
36548 };
36549
36550 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36551diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36552index 1421997..33f5d6d 100644
36553--- a/drivers/char/Kconfig
36554+++ b/drivers/char/Kconfig
36555@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36556
36557 config DEVKMEM
36558 bool "/dev/kmem virtual device support"
36559- default y
36560+ default n
36561+ depends on !GRKERNSEC_KMEM
36562 help
36563 Say Y here if you want to support the /dev/kmem device. The
36564 /dev/kmem device is rarely used, but can be used for certain
36565@@ -570,6 +571,7 @@ config DEVPORT
36566 bool
36567 depends on !M68K
36568 depends on ISA || PCI
36569+ depends on !GRKERNSEC_KMEM
36570 default y
36571
36572 source "drivers/s390/char/Kconfig"
36573diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36574index a48e05b..6bac831 100644
36575--- a/drivers/char/agp/compat_ioctl.c
36576+++ b/drivers/char/agp/compat_ioctl.c
36577@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36578 return -ENOMEM;
36579 }
36580
36581- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36582+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36583 sizeof(*usegment) * ureserve.seg_count)) {
36584 kfree(usegment);
36585 kfree(ksegment);
36586diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36587index 1b19239..b87b143 100644
36588--- a/drivers/char/agp/frontend.c
36589+++ b/drivers/char/agp/frontend.c
36590@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36591 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36592 return -EFAULT;
36593
36594- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36595+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36596 return -EFAULT;
36597
36598 client = agp_find_client_by_pid(reserve.pid);
36599@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36600 if (segment == NULL)
36601 return -ENOMEM;
36602
36603- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36604+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36605 sizeof(struct agp_segment) * reserve.seg_count)) {
36606 kfree(segment);
36607 return -EFAULT;
36608diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36609index 4f94375..413694e 100644
36610--- a/drivers/char/genrtc.c
36611+++ b/drivers/char/genrtc.c
36612@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36613 switch (cmd) {
36614
36615 case RTC_PLL_GET:
36616+ memset(&pll, 0, sizeof(pll));
36617 if (get_rtc_pll(&pll))
36618 return -EINVAL;
36619 else
36620diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36621index 448ce5e..3a76625 100644
36622--- a/drivers/char/hpet.c
36623+++ b/drivers/char/hpet.c
36624@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36625 }
36626
36627 static int
36628-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36629+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36630 struct hpet_info *info)
36631 {
36632 struct hpet_timer __iomem *timer;
36633diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36634index 86fe45c..c0ea948 100644
36635--- a/drivers/char/hw_random/intel-rng.c
36636+++ b/drivers/char/hw_random/intel-rng.c
36637@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36638
36639 if (no_fwh_detect)
36640 return -ENODEV;
36641- printk(warning);
36642+ printk("%s", warning);
36643 return -EBUSY;
36644 }
36645
36646diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36647index 4445fa1..7c6de37 100644
36648--- a/drivers/char/ipmi/ipmi_msghandler.c
36649+++ b/drivers/char/ipmi/ipmi_msghandler.c
36650@@ -420,7 +420,7 @@ struct ipmi_smi {
36651 struct proc_dir_entry *proc_dir;
36652 char proc_dir_name[10];
36653
36654- atomic_t stats[IPMI_NUM_STATS];
36655+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36656
36657 /*
36658 * run_to_completion duplicate of smb_info, smi_info
36659@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36660
36661
36662 #define ipmi_inc_stat(intf, stat) \
36663- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36664+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36665 #define ipmi_get_stat(intf, stat) \
36666- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36667+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36668
36669 static int is_lan_addr(struct ipmi_addr *addr)
36670 {
36671@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36672 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36673 init_waitqueue_head(&intf->waitq);
36674 for (i = 0; i < IPMI_NUM_STATS; i++)
36675- atomic_set(&intf->stats[i], 0);
36676+ atomic_set_unchecked(&intf->stats[i], 0);
36677
36678 intf->proc_dir = NULL;
36679
36680diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36681index af4b23f..79806fc 100644
36682--- a/drivers/char/ipmi/ipmi_si_intf.c
36683+++ b/drivers/char/ipmi/ipmi_si_intf.c
36684@@ -275,7 +275,7 @@ struct smi_info {
36685 unsigned char slave_addr;
36686
36687 /* Counters and things for the proc filesystem. */
36688- atomic_t stats[SI_NUM_STATS];
36689+ atomic_unchecked_t stats[SI_NUM_STATS];
36690
36691 struct task_struct *thread;
36692
36693@@ -284,9 +284,9 @@ struct smi_info {
36694 };
36695
36696 #define smi_inc_stat(smi, stat) \
36697- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36698+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36699 #define smi_get_stat(smi, stat) \
36700- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36701+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36702
36703 #define SI_MAX_PARMS 4
36704
36705@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36706 atomic_set(&new_smi->req_events, 0);
36707 new_smi->run_to_completion = 0;
36708 for (i = 0; i < SI_NUM_STATS; i++)
36709- atomic_set(&new_smi->stats[i], 0);
36710+ atomic_set_unchecked(&new_smi->stats[i], 0);
36711
36712 new_smi->interrupt_disabled = 1;
36713 atomic_set(&new_smi->stop_operation, 0);
36714diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36715index f895a8c..2bc9147 100644
36716--- a/drivers/char/mem.c
36717+++ b/drivers/char/mem.c
36718@@ -18,6 +18,7 @@
36719 #include <linux/raw.h>
36720 #include <linux/tty.h>
36721 #include <linux/capability.h>
36722+#include <linux/security.h>
36723 #include <linux/ptrace.h>
36724 #include <linux/device.h>
36725 #include <linux/highmem.h>
36726@@ -37,6 +38,10 @@
36727
36728 #define DEVPORT_MINOR 4
36729
36730+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36731+extern const struct file_operations grsec_fops;
36732+#endif
36733+
36734 static inline unsigned long size_inside_page(unsigned long start,
36735 unsigned long size)
36736 {
36737@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36738
36739 while (cursor < to) {
36740 if (!devmem_is_allowed(pfn)) {
36741+#ifdef CONFIG_GRKERNSEC_KMEM
36742+ gr_handle_mem_readwrite(from, to);
36743+#else
36744 printk(KERN_INFO
36745 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36746 current->comm, from, to);
36747+#endif
36748 return 0;
36749 }
36750 cursor += PAGE_SIZE;
36751@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36752 }
36753 return 1;
36754 }
36755+#elif defined(CONFIG_GRKERNSEC_KMEM)
36756+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36757+{
36758+ return 0;
36759+}
36760 #else
36761 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36762 {
36763@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36764
36765 while (count > 0) {
36766 unsigned long remaining;
36767+ char *temp;
36768
36769 sz = size_inside_page(p, count);
36770
36771@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36772 if (!ptr)
36773 return -EFAULT;
36774
36775- remaining = copy_to_user(buf, ptr, sz);
36776+#ifdef CONFIG_PAX_USERCOPY
36777+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36778+ if (!temp) {
36779+ unxlate_dev_mem_ptr(p, ptr);
36780+ return -ENOMEM;
36781+ }
36782+ memcpy(temp, ptr, sz);
36783+#else
36784+ temp = ptr;
36785+#endif
36786+
36787+ remaining = copy_to_user(buf, temp, sz);
36788+
36789+#ifdef CONFIG_PAX_USERCOPY
36790+ kfree(temp);
36791+#endif
36792+
36793 unxlate_dev_mem_ptr(p, ptr);
36794 if (remaining)
36795 return -EFAULT;
36796@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36797 size_t count, loff_t *ppos)
36798 {
36799 unsigned long p = *ppos;
36800- ssize_t low_count, read, sz;
36801+ ssize_t low_count, read, sz, err = 0;
36802 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36803- int err = 0;
36804
36805 read = 0;
36806 if (p < (unsigned long) high_memory) {
36807@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36808 }
36809 #endif
36810 while (low_count > 0) {
36811+ char *temp;
36812+
36813 sz = size_inside_page(p, low_count);
36814
36815 /*
36816@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36817 */
36818 kbuf = xlate_dev_kmem_ptr((char *)p);
36819
36820- if (copy_to_user(buf, kbuf, sz))
36821+#ifdef CONFIG_PAX_USERCOPY
36822+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36823+ if (!temp)
36824+ return -ENOMEM;
36825+ memcpy(temp, kbuf, sz);
36826+#else
36827+ temp = kbuf;
36828+#endif
36829+
36830+ err = copy_to_user(buf, temp, sz);
36831+
36832+#ifdef CONFIG_PAX_USERCOPY
36833+ kfree(temp);
36834+#endif
36835+
36836+ if (err)
36837 return -EFAULT;
36838 buf += sz;
36839 p += sz;
36840@@ -822,6 +869,9 @@ static const struct memdev {
36841 #ifdef CONFIG_PRINTK
36842 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36843 #endif
36844+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36845+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36846+#endif
36847 };
36848
36849 static int memory_open(struct inode *inode, struct file *filp)
36850@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36851 continue;
36852
36853 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36854- NULL, devlist[minor].name);
36855+ NULL, "%s", devlist[minor].name);
36856 }
36857
36858 return tty_init();
36859diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36860index 9df78e2..01ba9ae 100644
36861--- a/drivers/char/nvram.c
36862+++ b/drivers/char/nvram.c
36863@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36864
36865 spin_unlock_irq(&rtc_lock);
36866
36867- if (copy_to_user(buf, contents, tmp - contents))
36868+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36869 return -EFAULT;
36870
36871 *ppos = i;
36872diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36873index 5c5cc00..ac9edb7 100644
36874--- a/drivers/char/pcmcia/synclink_cs.c
36875+++ b/drivers/char/pcmcia/synclink_cs.c
36876@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36877
36878 if (debug_level >= DEBUG_LEVEL_INFO)
36879 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36880- __FILE__, __LINE__, info->device_name, port->count);
36881+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36882
36883- WARN_ON(!port->count);
36884+ WARN_ON(!atomic_read(&port->count));
36885
36886 if (tty_port_close_start(port, tty, filp) == 0)
36887 goto cleanup;
36888@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36889 cleanup:
36890 if (debug_level >= DEBUG_LEVEL_INFO)
36891 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36892- tty->driver->name, port->count);
36893+ tty->driver->name, atomic_read(&port->count));
36894 }
36895
36896 /* Wait until the transmitter is empty.
36897@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36898
36899 if (debug_level >= DEBUG_LEVEL_INFO)
36900 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36901- __FILE__, __LINE__, tty->driver->name, port->count);
36902+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36903
36904 /* If port is closing, signal caller to try again */
36905 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36906@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36907 goto cleanup;
36908 }
36909 spin_lock(&port->lock);
36910- port->count++;
36911+ atomic_inc(&port->count);
36912 spin_unlock(&port->lock);
36913 spin_unlock_irqrestore(&info->netlock, flags);
36914
36915- if (port->count == 1) {
36916+ if (atomic_read(&port->count) == 1) {
36917 /* 1st open on this device, init hardware */
36918 retval = startup(info, tty);
36919 if (retval < 0)
36920@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36921 unsigned short new_crctype;
36922
36923 /* return error if TTY interface open */
36924- if (info->port.count)
36925+ if (atomic_read(&info->port.count))
36926 return -EBUSY;
36927
36928 switch (encoding)
36929@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36930
36931 /* arbitrate between network and tty opens */
36932 spin_lock_irqsave(&info->netlock, flags);
36933- if (info->port.count != 0 || info->netcount != 0) {
36934+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36935 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36936 spin_unlock_irqrestore(&info->netlock, flags);
36937 return -EBUSY;
36938@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36939 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36940
36941 /* return error if TTY interface open */
36942- if (info->port.count)
36943+ if (atomic_read(&info->port.count))
36944 return -EBUSY;
36945
36946 if (cmd != SIOCWANDEV)
36947diff --git a/drivers/char/random.c b/drivers/char/random.c
36948index 0d91fe5..f8e37b0 100644
36949--- a/drivers/char/random.c
36950+++ b/drivers/char/random.c
36951@@ -272,8 +272,13 @@
36952 /*
36953 * Configuration information
36954 */
36955+#ifdef CONFIG_GRKERNSEC_RANDNET
36956+#define INPUT_POOL_WORDS 512
36957+#define OUTPUT_POOL_WORDS 128
36958+#else
36959 #define INPUT_POOL_WORDS 128
36960 #define OUTPUT_POOL_WORDS 32
36961+#endif
36962 #define SEC_XFER_SIZE 512
36963 #define EXTRACT_SIZE 10
36964
36965@@ -313,10 +318,17 @@ static struct poolinfo {
36966 int poolwords;
36967 int tap1, tap2, tap3, tap4, tap5;
36968 } poolinfo_table[] = {
36969+#ifdef CONFIG_GRKERNSEC_RANDNET
36970+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36971+ { 512, 411, 308, 208, 104, 1 },
36972+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36973+ { 128, 103, 76, 51, 25, 1 },
36974+#else
36975 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36976 { 128, 103, 76, 51, 25, 1 },
36977 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36978 { 32, 26, 20, 14, 7, 1 },
36979+#endif
36980 #if 0
36981 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36982 { 2048, 1638, 1231, 819, 411, 1 },
36983@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36984 input_rotate += i ? 7 : 14;
36985 }
36986
36987- ACCESS_ONCE(r->input_rotate) = input_rotate;
36988- ACCESS_ONCE(r->add_ptr) = i;
36989+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36990+ ACCESS_ONCE_RW(r->add_ptr) = i;
36991 smp_wmb();
36992
36993 if (out)
36994@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36995
36996 extract_buf(r, tmp);
36997 i = min_t(int, nbytes, EXTRACT_SIZE);
36998- if (copy_to_user(buf, tmp, i)) {
36999+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37000 ret = -EFAULT;
37001 break;
37002 }
37003@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37004 #include <linux/sysctl.h>
37005
37006 static int min_read_thresh = 8, min_write_thresh;
37007-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37008+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37009 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37010 static char sysctl_bootid[16];
37011
37012@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
37013 static int proc_do_uuid(struct ctl_table *table, int write,
37014 void __user *buffer, size_t *lenp, loff_t *ppos)
37015 {
37016- struct ctl_table fake_table;
37017+ ctl_table_no_const fake_table;
37018 unsigned char buf[64], tmp_uuid[16], *uuid;
37019
37020 uuid = table->data;
37021diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37022index bf2349db..5456d53 100644
37023--- a/drivers/char/sonypi.c
37024+++ b/drivers/char/sonypi.c
37025@@ -54,6 +54,7 @@
37026
37027 #include <asm/uaccess.h>
37028 #include <asm/io.h>
37029+#include <asm/local.h>
37030
37031 #include <linux/sonypi.h>
37032
37033@@ -490,7 +491,7 @@ static struct sonypi_device {
37034 spinlock_t fifo_lock;
37035 wait_queue_head_t fifo_proc_list;
37036 struct fasync_struct *fifo_async;
37037- int open_count;
37038+ local_t open_count;
37039 int model;
37040 struct input_dev *input_jog_dev;
37041 struct input_dev *input_key_dev;
37042@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37043 static int sonypi_misc_release(struct inode *inode, struct file *file)
37044 {
37045 mutex_lock(&sonypi_device.lock);
37046- sonypi_device.open_count--;
37047+ local_dec(&sonypi_device.open_count);
37048 mutex_unlock(&sonypi_device.lock);
37049 return 0;
37050 }
37051@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37052 {
37053 mutex_lock(&sonypi_device.lock);
37054 /* Flush input queue on first open */
37055- if (!sonypi_device.open_count)
37056+ if (!local_read(&sonypi_device.open_count))
37057 kfifo_reset(&sonypi_device.fifo);
37058- sonypi_device.open_count++;
37059+ local_inc(&sonypi_device.open_count);
37060 mutex_unlock(&sonypi_device.lock);
37061
37062 return 0;
37063diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37064index 64420b3..5c40b56 100644
37065--- a/drivers/char/tpm/tpm_acpi.c
37066+++ b/drivers/char/tpm/tpm_acpi.c
37067@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37068 virt = acpi_os_map_memory(start, len);
37069 if (!virt) {
37070 kfree(log->bios_event_log);
37071+ log->bios_event_log = NULL;
37072 printk("%s: ERROR - Unable to map memory\n", __func__);
37073 return -EIO;
37074 }
37075
37076- memcpy_fromio(log->bios_event_log, virt, len);
37077+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37078
37079 acpi_os_unmap_memory(virt, len);
37080 return 0;
37081diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37082index 84ddc55..1d32f1e 100644
37083--- a/drivers/char/tpm/tpm_eventlog.c
37084+++ b/drivers/char/tpm/tpm_eventlog.c
37085@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37086 event = addr;
37087
37088 if ((event->event_type == 0 && event->event_size == 0) ||
37089- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37090+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37091 return NULL;
37092
37093 return addr;
37094@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37095 return NULL;
37096
37097 if ((event->event_type == 0 && event->event_size == 0) ||
37098- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37099+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37100 return NULL;
37101
37102 (*pos)++;
37103@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37104 int i;
37105
37106 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37107- seq_putc(m, data[i]);
37108+ if (!seq_putc(m, data[i]))
37109+ return -EFAULT;
37110
37111 return 0;
37112 }
37113diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37114index fc45567..fa2a590 100644
37115--- a/drivers/char/virtio_console.c
37116+++ b/drivers/char/virtio_console.c
37117@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37118 if (to_user) {
37119 ssize_t ret;
37120
37121- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37122+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37123 if (ret)
37124 return -EFAULT;
37125 } else {
37126@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37127 if (!port_has_data(port) && !port->host_connected)
37128 return 0;
37129
37130- return fill_readbuf(port, ubuf, count, true);
37131+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37132 }
37133
37134 static int wait_port_writable(struct port *port, bool nonblock)
37135diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37136index a33f46f..a720eed 100644
37137--- a/drivers/clk/clk-composite.c
37138+++ b/drivers/clk/clk-composite.c
37139@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37140 struct clk *clk;
37141 struct clk_init_data init;
37142 struct clk_composite *composite;
37143- struct clk_ops *clk_composite_ops;
37144+ clk_ops_no_const *clk_composite_ops;
37145
37146 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37147 if (!composite) {
37148diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37149index 5bb848c..f1d4fc9 100644
37150--- a/drivers/clk/socfpga/clk.c
37151+++ b/drivers/clk/socfpga/clk.c
37152@@ -22,6 +22,7 @@
37153 #include <linux/clk-provider.h>
37154 #include <linux/io.h>
37155 #include <linux/of.h>
37156+#include <asm/pgtable.h>
37157
37158 /* Clock Manager offsets */
37159 #define CLKMGR_CTRL 0x0
37160@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37161 streq(clk_name, "periph_pll") ||
37162 streq(clk_name, "sdram_pll")) {
37163 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37164- clk_pll_ops.enable = clk_gate_ops.enable;
37165- clk_pll_ops.disable = clk_gate_ops.disable;
37166+ pax_open_kernel();
37167+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37168+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37169+ pax_close_kernel();
37170 }
37171
37172 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37173@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37174 return parent_rate / div;
37175 }
37176
37177-static struct clk_ops gateclk_ops = {
37178+static clk_ops_no_const gateclk_ops __read_only = {
37179 .recalc_rate = socfpga_clk_recalc_rate,
37180 .get_parent = socfpga_clk_get_parent,
37181 .set_parent = socfpga_clk_set_parent,
37182diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37183index 3926402..37b580d 100644
37184--- a/drivers/cpufreq/acpi-cpufreq.c
37185+++ b/drivers/cpufreq/acpi-cpufreq.c
37186@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37187 return sprintf(buf, "%u\n", boost_enabled);
37188 }
37189
37190-static struct global_attr global_boost = __ATTR(boost, 0644,
37191+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37192 show_global_boost,
37193 store_global_boost);
37194
37195@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37196 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37197 per_cpu(acfreq_data, cpu) = data;
37198
37199- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37200- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37201+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37202+ pax_open_kernel();
37203+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37204+ pax_close_kernel();
37205+ }
37206
37207 result = acpi_processor_register_performance(data->acpi_data, cpu);
37208 if (result)
37209@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37210 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37211 break;
37212 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37213- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37214+ pax_open_kernel();
37215+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37216+ pax_close_kernel();
37217 policy->cur = get_cur_freq_on_cpu(cpu);
37218 break;
37219 default:
37220@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37221 acpi_processor_notify_smm(THIS_MODULE);
37222
37223 /* Check for APERF/MPERF support in hardware */
37224- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37225- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37226+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37227+ pax_open_kernel();
37228+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37229+ pax_close_kernel();
37230+ }
37231
37232 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37233 for (i = 0; i < perf->state_count; i++)
37234diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37235index f0a5e2b..0a7ee46 100644
37236--- a/drivers/cpufreq/cpufreq.c
37237+++ b/drivers/cpufreq/cpufreq.c
37238@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37239 return NOTIFY_OK;
37240 }
37241
37242-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37243+static struct notifier_block cpufreq_cpu_notifier = {
37244 .notifier_call = cpufreq_cpu_callback,
37245 };
37246
37247@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37248
37249 pr_debug("trying to register driver %s\n", driver_data->name);
37250
37251- if (driver_data->setpolicy)
37252- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37253+ if (driver_data->setpolicy) {
37254+ pax_open_kernel();
37255+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37256+ pax_close_kernel();
37257+ }
37258
37259 write_lock_irqsave(&cpufreq_driver_lock, flags);
37260 if (cpufreq_driver) {
37261diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37262index e59afaa..a53a3ff 100644
37263--- a/drivers/cpufreq/cpufreq_governor.c
37264+++ b/drivers/cpufreq/cpufreq_governor.c
37265@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37266 struct dbs_data *dbs_data;
37267 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37268 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37269- struct od_ops *od_ops = NULL;
37270+ const struct od_ops *od_ops = NULL;
37271 struct od_dbs_tuners *od_tuners = NULL;
37272 struct cs_dbs_tuners *cs_tuners = NULL;
37273 struct cpu_dbs_common_info *cpu_cdbs;
37274@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37275
37276 if ((cdata->governor == GOV_CONSERVATIVE) &&
37277 (!policy->governor->initialized)) {
37278- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37279+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37280
37281 cpufreq_register_notifier(cs_ops->notifier_block,
37282 CPUFREQ_TRANSITION_NOTIFIER);
37283@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37284
37285 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37286 (policy->governor->initialized == 1)) {
37287- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37288+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37289
37290 cpufreq_unregister_notifier(cs_ops->notifier_block,
37291 CPUFREQ_TRANSITION_NOTIFIER);
37292diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37293index d5f12b4..eb30af1 100644
37294--- a/drivers/cpufreq/cpufreq_governor.h
37295+++ b/drivers/cpufreq/cpufreq_governor.h
37296@@ -204,7 +204,7 @@ struct common_dbs_data {
37297 void (*exit)(struct dbs_data *dbs_data);
37298
37299 /* Governor specific ops, see below */
37300- void *gov_ops;
37301+ const void *gov_ops;
37302 };
37303
37304 /* Governer Per policy data */
37305@@ -224,7 +224,7 @@ struct od_ops {
37306 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37307 unsigned int freq_next, unsigned int relation);
37308 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37309-};
37310+} __no_const;
37311
37312 struct cs_ops {
37313 struct notifier_block *notifier_block;
37314diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37315index c087347..989aa2e 100644
37316--- a/drivers/cpufreq/cpufreq_ondemand.c
37317+++ b/drivers/cpufreq/cpufreq_ondemand.c
37318@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37319
37320 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37321
37322-static struct od_ops od_ops = {
37323+static struct od_ops od_ops __read_only = {
37324 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37325 .powersave_bias_target = generic_powersave_bias_target,
37326 .freq_increase = dbs_freq_increase,
37327@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37328 (struct cpufreq_policy *, unsigned int, unsigned int),
37329 unsigned int powersave_bias)
37330 {
37331- od_ops.powersave_bias_target = f;
37332+ pax_open_kernel();
37333+ *(void **)&od_ops.powersave_bias_target = f;
37334+ pax_close_kernel();
37335 od_set_powersave_bias(powersave_bias);
37336 }
37337 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37338
37339 void od_unregister_powersave_bias_handler(void)
37340 {
37341- od_ops.powersave_bias_target = generic_powersave_bias_target;
37342+ pax_open_kernel();
37343+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37344+ pax_close_kernel();
37345 od_set_powersave_bias(0);
37346 }
37347 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37348diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37349index d37568c..fbb19a1 100644
37350--- a/drivers/cpufreq/cpufreq_stats.c
37351+++ b/drivers/cpufreq/cpufreq_stats.c
37352@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37353 }
37354
37355 /* priority=1 so this will get called before cpufreq_remove_dev */
37356-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37357+static struct notifier_block cpufreq_stat_cpu_notifier = {
37358 .notifier_call = cpufreq_stat_cpu_callback,
37359 .priority = 1,
37360 };
37361diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37362index 9ee7817..17b658e 100644
37363--- a/drivers/cpufreq/p4-clockmod.c
37364+++ b/drivers/cpufreq/p4-clockmod.c
37365@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37366 case 0x0F: /* Core Duo */
37367 case 0x16: /* Celeron Core */
37368 case 0x1C: /* Atom */
37369- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37370+ pax_open_kernel();
37371+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37372+ pax_close_kernel();
37373 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37374 case 0x0D: /* Pentium M (Dothan) */
37375- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37376+ pax_open_kernel();
37377+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37378+ pax_close_kernel();
37379 /* fall through */
37380 case 0x09: /* Pentium M (Banias) */
37381 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37382@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37383
37384 /* on P-4s, the TSC runs with constant frequency independent whether
37385 * throttling is active or not. */
37386- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37387+ pax_open_kernel();
37388+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37389+ pax_close_kernel();
37390
37391 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37392 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37393diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37394index 880ee29..2445bc6 100644
37395--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37396+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37397@@ -18,14 +18,12 @@
37398 #include <asm/head.h>
37399 #include <asm/timer.h>
37400
37401-static struct cpufreq_driver *cpufreq_us3_driver;
37402-
37403 struct us3_freq_percpu_info {
37404 struct cpufreq_frequency_table table[4];
37405 };
37406
37407 /* Indexed by cpu number. */
37408-static struct us3_freq_percpu_info *us3_freq_table;
37409+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37410
37411 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37412 * in the Safari config register.
37413@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37414
37415 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37416 {
37417- if (cpufreq_us3_driver)
37418- us3_set_cpu_divider_index(policy, 0);
37419+ us3_set_cpu_divider_index(policy->cpu, 0);
37420
37421 return 0;
37422 }
37423
37424+static int __init us3_freq_init(void);
37425+static void __exit us3_freq_exit(void);
37426+
37427+static struct cpufreq_driver cpufreq_us3_driver = {
37428+ .init = us3_freq_cpu_init,
37429+ .verify = us3_freq_verify,
37430+ .target = us3_freq_target,
37431+ .get = us3_freq_get,
37432+ .exit = us3_freq_cpu_exit,
37433+ .owner = THIS_MODULE,
37434+ .name = "UltraSPARC-III",
37435+
37436+};
37437+
37438 static int __init us3_freq_init(void)
37439 {
37440 unsigned long manuf, impl, ver;
37441@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37442 (impl == CHEETAH_IMPL ||
37443 impl == CHEETAH_PLUS_IMPL ||
37444 impl == JAGUAR_IMPL ||
37445- impl == PANTHER_IMPL)) {
37446- struct cpufreq_driver *driver;
37447-
37448- ret = -ENOMEM;
37449- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37450- if (!driver)
37451- goto err_out;
37452-
37453- us3_freq_table = kzalloc(
37454- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37455- GFP_KERNEL);
37456- if (!us3_freq_table)
37457- goto err_out;
37458-
37459- driver->init = us3_freq_cpu_init;
37460- driver->verify = us3_freq_verify;
37461- driver->target = us3_freq_target;
37462- driver->get = us3_freq_get;
37463- driver->exit = us3_freq_cpu_exit;
37464- driver->owner = THIS_MODULE,
37465- strcpy(driver->name, "UltraSPARC-III");
37466-
37467- cpufreq_us3_driver = driver;
37468- ret = cpufreq_register_driver(driver);
37469- if (ret)
37470- goto err_out;
37471-
37472- return 0;
37473-
37474-err_out:
37475- if (driver) {
37476- kfree(driver);
37477- cpufreq_us3_driver = NULL;
37478- }
37479- kfree(us3_freq_table);
37480- us3_freq_table = NULL;
37481- return ret;
37482- }
37483+ impl == PANTHER_IMPL))
37484+ return cpufreq_register_driver(&cpufreq_us3_driver);
37485
37486 return -ENODEV;
37487 }
37488
37489 static void __exit us3_freq_exit(void)
37490 {
37491- if (cpufreq_us3_driver) {
37492- cpufreq_unregister_driver(cpufreq_us3_driver);
37493- kfree(cpufreq_us3_driver);
37494- cpufreq_us3_driver = NULL;
37495- kfree(us3_freq_table);
37496- us3_freq_table = NULL;
37497- }
37498+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37499 }
37500
37501 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37502diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37503index 0915e71..53376ed 100644
37504--- a/drivers/cpufreq/speedstep-centrino.c
37505+++ b/drivers/cpufreq/speedstep-centrino.c
37506@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37507 !cpu_has(cpu, X86_FEATURE_EST))
37508 return -ENODEV;
37509
37510- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37511- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37512+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37513+ pax_open_kernel();
37514+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37515+ pax_close_kernel();
37516+ }
37517
37518 if (policy->cpu != 0)
37519 return -ENODEV;
37520diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37521index fdc432f..98e64e2 100644
37522--- a/drivers/cpuidle/cpuidle.c
37523+++ b/drivers/cpuidle/cpuidle.c
37524@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37525
37526 static void poll_idle_init(struct cpuidle_driver *drv)
37527 {
37528- struct cpuidle_state *state = &drv->states[0];
37529+ cpuidle_state_no_const *state = &drv->states[0];
37530
37531 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37532 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37533diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37534index ea2f8e7..70ac501 100644
37535--- a/drivers/cpuidle/governor.c
37536+++ b/drivers/cpuidle/governor.c
37537@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37538 mutex_lock(&cpuidle_lock);
37539 if (__cpuidle_find_governor(gov->name) == NULL) {
37540 ret = 0;
37541- list_add_tail(&gov->governor_list, &cpuidle_governors);
37542+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37543 if (!cpuidle_curr_governor ||
37544 cpuidle_curr_governor->rating < gov->rating)
37545 cpuidle_switch_governor(gov);
37546@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37547 new_gov = cpuidle_replace_governor(gov->rating);
37548 cpuidle_switch_governor(new_gov);
37549 }
37550- list_del(&gov->governor_list);
37551+ pax_list_del((struct list_head *)&gov->governor_list);
37552 mutex_unlock(&cpuidle_lock);
37553 }
37554
37555diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37556index 428754a..8bdf9cc 100644
37557--- a/drivers/cpuidle/sysfs.c
37558+++ b/drivers/cpuidle/sysfs.c
37559@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37560 NULL
37561 };
37562
37563-static struct attribute_group cpuidle_attr_group = {
37564+static attribute_group_no_const cpuidle_attr_group = {
37565 .attrs = cpuidle_default_attrs,
37566 .name = "cpuidle",
37567 };
37568diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37569index 12fea3e..1e28f47 100644
37570--- a/drivers/crypto/hifn_795x.c
37571+++ b/drivers/crypto/hifn_795x.c
37572@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37573 MODULE_PARM_DESC(hifn_pll_ref,
37574 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37575
37576-static atomic_t hifn_dev_number;
37577+static atomic_unchecked_t hifn_dev_number;
37578
37579 #define ACRYPTO_OP_DECRYPT 0
37580 #define ACRYPTO_OP_ENCRYPT 1
37581@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37582 goto err_out_disable_pci_device;
37583
37584 snprintf(name, sizeof(name), "hifn%d",
37585- atomic_inc_return(&hifn_dev_number)-1);
37586+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37587
37588 err = pci_request_regions(pdev, name);
37589 if (err)
37590diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37591index e94e619..f7e249c 100644
37592--- a/drivers/devfreq/devfreq.c
37593+++ b/drivers/devfreq/devfreq.c
37594@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37595 goto err_out;
37596 }
37597
37598- list_add(&governor->node, &devfreq_governor_list);
37599+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37600
37601 list_for_each_entry(devfreq, &devfreq_list, node) {
37602 int ret = 0;
37603@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37604 }
37605 }
37606
37607- list_del(&governor->node);
37608+ pax_list_del((struct list_head *)&governor->node);
37609 err_out:
37610 mutex_unlock(&devfreq_list_lock);
37611
37612diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37613index 5039fbc..841169f 100644
37614--- a/drivers/dma/sh/shdma.c
37615+++ b/drivers/dma/sh/shdma.c
37616@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37617 return ret;
37618 }
37619
37620-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37621+static struct notifier_block sh_dmae_nmi_notifier = {
37622 .notifier_call = sh_dmae_nmi_handler,
37623
37624 /* Run before NMI debug handler and KGDB */
37625diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37626index 211021d..201d47f 100644
37627--- a/drivers/edac/edac_device.c
37628+++ b/drivers/edac/edac_device.c
37629@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37630 */
37631 int edac_device_alloc_index(void)
37632 {
37633- static atomic_t device_indexes = ATOMIC_INIT(0);
37634+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37635
37636- return atomic_inc_return(&device_indexes) - 1;
37637+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37638 }
37639 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37640
37641diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37642index e7c32c4..6397af1 100644
37643--- a/drivers/edac/edac_mc_sysfs.c
37644+++ b/drivers/edac/edac_mc_sysfs.c
37645@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37646 struct dev_ch_attribute {
37647 struct device_attribute attr;
37648 int channel;
37649-};
37650+} __do_const;
37651
37652 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37653 struct dev_ch_attribute dev_attr_legacy_##_name = \
37654@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37655 }
37656
37657 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37658+ pax_open_kernel();
37659 if (mci->get_sdram_scrub_rate) {
37660- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37661- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37662+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37663+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37664 }
37665 if (mci->set_sdram_scrub_rate) {
37666- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37667- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37668+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37669+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37670 }
37671+ pax_close_kernel();
37672 err = device_create_file(&mci->dev,
37673 &dev_attr_sdram_scrub_rate);
37674 if (err) {
37675diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37676index dd370f9..0281629 100644
37677--- a/drivers/edac/edac_pci.c
37678+++ b/drivers/edac/edac_pci.c
37679@@ -29,7 +29,7 @@
37680
37681 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37682 static LIST_HEAD(edac_pci_list);
37683-static atomic_t pci_indexes = ATOMIC_INIT(0);
37684+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37685
37686 /*
37687 * edac_pci_alloc_ctl_info
37688@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37689 */
37690 int edac_pci_alloc_index(void)
37691 {
37692- return atomic_inc_return(&pci_indexes) - 1;
37693+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37694 }
37695 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37696
37697diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37698index e8658e4..22746d6 100644
37699--- a/drivers/edac/edac_pci_sysfs.c
37700+++ b/drivers/edac/edac_pci_sysfs.c
37701@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37702 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37703 static int edac_pci_poll_msec = 1000; /* one second workq period */
37704
37705-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37706-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37707+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37708+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37709
37710 static struct kobject *edac_pci_top_main_kobj;
37711 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37712@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37713 void *value;
37714 ssize_t(*show) (void *, char *);
37715 ssize_t(*store) (void *, const char *, size_t);
37716-};
37717+} __do_const;
37718
37719 /* Set of show/store abstract level functions for PCI Parity object */
37720 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37721@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37722 edac_printk(KERN_CRIT, EDAC_PCI,
37723 "Signaled System Error on %s\n",
37724 pci_name(dev));
37725- atomic_inc(&pci_nonparity_count);
37726+ atomic_inc_unchecked(&pci_nonparity_count);
37727 }
37728
37729 if (status & (PCI_STATUS_PARITY)) {
37730@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37731 "Master Data Parity Error on %s\n",
37732 pci_name(dev));
37733
37734- atomic_inc(&pci_parity_count);
37735+ atomic_inc_unchecked(&pci_parity_count);
37736 }
37737
37738 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37739@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37740 "Detected Parity Error on %s\n",
37741 pci_name(dev));
37742
37743- atomic_inc(&pci_parity_count);
37744+ atomic_inc_unchecked(&pci_parity_count);
37745 }
37746 }
37747
37748@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37749 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37750 "Signaled System Error on %s\n",
37751 pci_name(dev));
37752- atomic_inc(&pci_nonparity_count);
37753+ atomic_inc_unchecked(&pci_nonparity_count);
37754 }
37755
37756 if (status & (PCI_STATUS_PARITY)) {
37757@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37758 "Master Data Parity Error on "
37759 "%s\n", pci_name(dev));
37760
37761- atomic_inc(&pci_parity_count);
37762+ atomic_inc_unchecked(&pci_parity_count);
37763 }
37764
37765 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37766@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37767 "Detected Parity Error on %s\n",
37768 pci_name(dev));
37769
37770- atomic_inc(&pci_parity_count);
37771+ atomic_inc_unchecked(&pci_parity_count);
37772 }
37773 }
37774 }
37775@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37776 if (!check_pci_errors)
37777 return;
37778
37779- before_count = atomic_read(&pci_parity_count);
37780+ before_count = atomic_read_unchecked(&pci_parity_count);
37781
37782 /* scan all PCI devices looking for a Parity Error on devices and
37783 * bridges.
37784@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37785 /* Only if operator has selected panic on PCI Error */
37786 if (edac_pci_get_panic_on_pe()) {
37787 /* If the count is different 'after' from 'before' */
37788- if (before_count != atomic_read(&pci_parity_count))
37789+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37790 panic("EDAC: PCI Parity Error");
37791 }
37792 }
37793diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37794index 51b7e3a..aa8a3e8 100644
37795--- a/drivers/edac/mce_amd.h
37796+++ b/drivers/edac/mce_amd.h
37797@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37798 bool (*mc0_mce)(u16, u8);
37799 bool (*mc1_mce)(u16, u8);
37800 bool (*mc2_mce)(u16, u8);
37801-};
37802+} __no_const;
37803
37804 void amd_report_gart_errors(bool);
37805 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37806diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37807index 57ea7f4..af06b76 100644
37808--- a/drivers/firewire/core-card.c
37809+++ b/drivers/firewire/core-card.c
37810@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37811 const struct fw_card_driver *driver,
37812 struct device *device)
37813 {
37814- static atomic_t index = ATOMIC_INIT(-1);
37815+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37816
37817- card->index = atomic_inc_return(&index);
37818+ card->index = atomic_inc_return_unchecked(&index);
37819 card->driver = driver;
37820 card->device = device;
37821 card->current_tlabel = 0;
37822@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37823
37824 void fw_core_remove_card(struct fw_card *card)
37825 {
37826- struct fw_card_driver dummy_driver = dummy_driver_template;
37827+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37828
37829 card->driver->update_phy_reg(card, 4,
37830 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37831diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37832index de4aa40..49ab1f2 100644
37833--- a/drivers/firewire/core-device.c
37834+++ b/drivers/firewire/core-device.c
37835@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37836 struct config_rom_attribute {
37837 struct device_attribute attr;
37838 u32 key;
37839-};
37840+} __do_const;
37841
37842 static ssize_t show_immediate(struct device *dev,
37843 struct device_attribute *dattr, char *buf)
37844diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37845index 28a94c7..58da63a 100644
37846--- a/drivers/firewire/core-transaction.c
37847+++ b/drivers/firewire/core-transaction.c
37848@@ -38,6 +38,7 @@
37849 #include <linux/timer.h>
37850 #include <linux/types.h>
37851 #include <linux/workqueue.h>
37852+#include <linux/sched.h>
37853
37854 #include <asm/byteorder.h>
37855
37856diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37857index 515a42c..5ecf3ba 100644
37858--- a/drivers/firewire/core.h
37859+++ b/drivers/firewire/core.h
37860@@ -111,6 +111,7 @@ struct fw_card_driver {
37861
37862 int (*stop_iso)(struct fw_iso_context *ctx);
37863 };
37864+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37865
37866 void fw_card_initialize(struct fw_card *card,
37867 const struct fw_card_driver *driver, struct device *device);
37868diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37869index 94a58a0..f5eba42 100644
37870--- a/drivers/firmware/dmi-id.c
37871+++ b/drivers/firmware/dmi-id.c
37872@@ -16,7 +16,7 @@
37873 struct dmi_device_attribute{
37874 struct device_attribute dev_attr;
37875 int field;
37876-};
37877+} __do_const;
37878 #define to_dmi_dev_attr(_dev_attr) \
37879 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37880
37881diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37882index 232fa8f..386c255 100644
37883--- a/drivers/firmware/dmi_scan.c
37884+++ b/drivers/firmware/dmi_scan.c
37885@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37886 }
37887 }
37888 else {
37889- /*
37890- * no iounmap() for that ioremap(); it would be a no-op, but
37891- * it's so early in setup that sucker gets confused into doing
37892- * what it shouldn't if we actually call it.
37893- */
37894 p = dmi_ioremap(0xF0000, 0x10000);
37895 if (p == NULL)
37896 goto error;
37897@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37898 if (buf == NULL)
37899 return -1;
37900
37901- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37902+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37903
37904 iounmap(buf);
37905 return 0;
37906diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37907index 5145fa3..0d3babd 100644
37908--- a/drivers/firmware/efi/efi.c
37909+++ b/drivers/firmware/efi/efi.c
37910@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37911 };
37912
37913 static struct efivars generic_efivars;
37914-static struct efivar_operations generic_ops;
37915+static efivar_operations_no_const generic_ops __read_only;
37916
37917 static int generic_ops_register(void)
37918 {
37919- generic_ops.get_variable = efi.get_variable;
37920- generic_ops.set_variable = efi.set_variable;
37921- generic_ops.get_next_variable = efi.get_next_variable;
37922- generic_ops.query_variable_store = efi_query_variable_store;
37923+ pax_open_kernel();
37924+ *(void **)&generic_ops.get_variable = efi.get_variable;
37925+ *(void **)&generic_ops.set_variable = efi.set_variable;
37926+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37927+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37928+ pax_close_kernel();
37929
37930 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37931 }
37932diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37933index 8a7432a..28fb839 100644
37934--- a/drivers/firmware/efi/efivars.c
37935+++ b/drivers/firmware/efi/efivars.c
37936@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37937 static int
37938 create_efivars_bin_attributes(void)
37939 {
37940- struct bin_attribute *attr;
37941+ bin_attribute_no_const *attr;
37942 int error;
37943
37944 /* new_var */
37945diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37946index 2a90ba6..07f3733 100644
37947--- a/drivers/firmware/google/memconsole.c
37948+++ b/drivers/firmware/google/memconsole.c
37949@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37950 if (!found_memconsole())
37951 return -ENODEV;
37952
37953- memconsole_bin_attr.size = memconsole_length;
37954+ pax_open_kernel();
37955+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37956+ pax_close_kernel();
37957
37958 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37959
37960diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37961index 2729e3d..f9deca1 100644
37962--- a/drivers/gpio/gpio-ich.c
37963+++ b/drivers/gpio/gpio-ich.c
37964@@ -71,7 +71,7 @@ struct ichx_desc {
37965 /* Some chipsets have quirks, let these use their own request/get */
37966 int (*request)(struct gpio_chip *chip, unsigned offset);
37967 int (*get)(struct gpio_chip *chip, unsigned offset);
37968-};
37969+} __do_const;
37970
37971 static struct {
37972 spinlock_t lock;
37973diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37974index 9902732..64b62dd 100644
37975--- a/drivers/gpio/gpio-vr41xx.c
37976+++ b/drivers/gpio/gpio-vr41xx.c
37977@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37978 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37979 maskl, pendl, maskh, pendh);
37980
37981- atomic_inc(&irq_err_count);
37982+ atomic_inc_unchecked(&irq_err_count);
37983
37984 return -EINVAL;
37985 }
37986diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37987index 6a64749..0767a9f 100644
37988--- a/drivers/gpu/drm/drm_crtc_helper.c
37989+++ b/drivers/gpu/drm/drm_crtc_helper.c
37990@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37991 struct drm_crtc *tmp;
37992 int crtc_mask = 1;
37993
37994- WARN(!crtc, "checking null crtc?\n");
37995+ BUG_ON(!crtc);
37996
37997 dev = crtc->dev;
37998
37999diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38000index 99fcd7c..13cf6c5 100644
38001--- a/drivers/gpu/drm/drm_drv.c
38002+++ b/drivers/gpu/drm/drm_drv.c
38003@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
38004 /**
38005 * Copy and IOCTL return string to user space
38006 */
38007-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38008+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38009 {
38010 int len;
38011
38012@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
38013 struct drm_file *file_priv = filp->private_data;
38014 struct drm_device *dev;
38015 const struct drm_ioctl_desc *ioctl = NULL;
38016- drm_ioctl_t *func;
38017+ drm_ioctl_no_const_t func;
38018 unsigned int nr = DRM_IOCTL_NR(cmd);
38019 int retcode = -EINVAL;
38020 char stack_kdata[128];
38021@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
38022 return -ENODEV;
38023
38024 atomic_inc(&dev->ioctl_count);
38025- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38026+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38027 ++file_priv->ioctl_count;
38028
38029 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38030diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38031index 3a24385..4e426e0 100644
38032--- a/drivers/gpu/drm/drm_fops.c
38033+++ b/drivers/gpu/drm/drm_fops.c
38034@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38035 }
38036
38037 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38038- atomic_set(&dev->counts[i], 0);
38039+ atomic_set_unchecked(&dev->counts[i], 0);
38040
38041 dev->sigdata.lock = NULL;
38042
38043@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38044 if (drm_device_is_unplugged(dev))
38045 return -ENODEV;
38046
38047- if (!dev->open_count++)
38048+ if (local_inc_return(&dev->open_count) == 1)
38049 need_setup = 1;
38050 mutex_lock(&dev->struct_mutex);
38051 old_imapping = inode->i_mapping;
38052@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38053 retcode = drm_open_helper(inode, filp, dev);
38054 if (retcode)
38055 goto err_undo;
38056- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38057+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38058 if (need_setup) {
38059 retcode = drm_setup(dev);
38060 if (retcode)
38061@@ -166,7 +166,7 @@ err_undo:
38062 iput(container_of(dev->dev_mapping, struct inode, i_data));
38063 dev->dev_mapping = old_mapping;
38064 mutex_unlock(&dev->struct_mutex);
38065- dev->open_count--;
38066+ local_dec(&dev->open_count);
38067 return retcode;
38068 }
38069 EXPORT_SYMBOL(drm_open);
38070@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38071
38072 mutex_lock(&drm_global_mutex);
38073
38074- DRM_DEBUG("open_count = %d\n", dev->open_count);
38075+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38076
38077 if (dev->driver->preclose)
38078 dev->driver->preclose(dev, file_priv);
38079@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38080 * Begin inline drm_release
38081 */
38082
38083- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38084+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38085 task_pid_nr(current),
38086 (long)old_encode_dev(file_priv->minor->device),
38087- dev->open_count);
38088+ local_read(&dev->open_count));
38089
38090 /* Release any auth tokens that might point to this file_priv,
38091 (do that under the drm_global_mutex) */
38092@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38093 * End inline drm_release
38094 */
38095
38096- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38097- if (!--dev->open_count) {
38098+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38099+ if (local_dec_and_test(&dev->open_count)) {
38100 if (atomic_read(&dev->ioctl_count)) {
38101 DRM_ERROR("Device busy: %d\n",
38102 atomic_read(&dev->ioctl_count));
38103diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38104index f731116..629842c 100644
38105--- a/drivers/gpu/drm/drm_global.c
38106+++ b/drivers/gpu/drm/drm_global.c
38107@@ -36,7 +36,7 @@
38108 struct drm_global_item {
38109 struct mutex mutex;
38110 void *object;
38111- int refcount;
38112+ atomic_t refcount;
38113 };
38114
38115 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38116@@ -49,7 +49,7 @@ void drm_global_init(void)
38117 struct drm_global_item *item = &glob[i];
38118 mutex_init(&item->mutex);
38119 item->object = NULL;
38120- item->refcount = 0;
38121+ atomic_set(&item->refcount, 0);
38122 }
38123 }
38124
38125@@ -59,7 +59,7 @@ void drm_global_release(void)
38126 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38127 struct drm_global_item *item = &glob[i];
38128 BUG_ON(item->object != NULL);
38129- BUG_ON(item->refcount != 0);
38130+ BUG_ON(atomic_read(&item->refcount) != 0);
38131 }
38132 }
38133
38134@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38135 void *object;
38136
38137 mutex_lock(&item->mutex);
38138- if (item->refcount == 0) {
38139+ if (atomic_read(&item->refcount) == 0) {
38140 item->object = kzalloc(ref->size, GFP_KERNEL);
38141 if (unlikely(item->object == NULL)) {
38142 ret = -ENOMEM;
38143@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38144 goto out_err;
38145
38146 }
38147- ++item->refcount;
38148+ atomic_inc(&item->refcount);
38149 ref->object = item->object;
38150 object = item->object;
38151 mutex_unlock(&item->mutex);
38152@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38153 struct drm_global_item *item = &glob[ref->global_type];
38154
38155 mutex_lock(&item->mutex);
38156- BUG_ON(item->refcount == 0);
38157+ BUG_ON(atomic_read(&item->refcount) == 0);
38158 BUG_ON(ref->object != item->object);
38159- if (--item->refcount == 0) {
38160+ if (atomic_dec_and_test(&item->refcount)) {
38161 ref->release(ref);
38162 item->object = NULL;
38163 }
38164diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38165index d4b20ce..77a8d41 100644
38166--- a/drivers/gpu/drm/drm_info.c
38167+++ b/drivers/gpu/drm/drm_info.c
38168@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38169 struct drm_local_map *map;
38170 struct drm_map_list *r_list;
38171
38172- /* Hardcoded from _DRM_FRAME_BUFFER,
38173- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38174- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38175- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38176+ static const char * const types[] = {
38177+ [_DRM_FRAME_BUFFER] = "FB",
38178+ [_DRM_REGISTERS] = "REG",
38179+ [_DRM_SHM] = "SHM",
38180+ [_DRM_AGP] = "AGP",
38181+ [_DRM_SCATTER_GATHER] = "SG",
38182+ [_DRM_CONSISTENT] = "PCI",
38183+ [_DRM_GEM] = "GEM" };
38184 const char *type;
38185 int i;
38186
38187@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38188 map = r_list->map;
38189 if (!map)
38190 continue;
38191- if (map->type < 0 || map->type > 5)
38192+ if (map->type >= ARRAY_SIZE(types))
38193 type = "??";
38194 else
38195 type = types[map->type];
38196@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38197 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38198 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38199 vma->vm_flags & VM_IO ? 'i' : '-',
38200+#ifdef CONFIG_GRKERNSEC_HIDESYM
38201+ 0);
38202+#else
38203 vma->vm_pgoff);
38204+#endif
38205
38206 #if defined(__i386__)
38207 pgprot = pgprot_val(vma->vm_page_prot);
38208diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38209index 2f4c434..dd12cd2 100644
38210--- a/drivers/gpu/drm/drm_ioc32.c
38211+++ b/drivers/gpu/drm/drm_ioc32.c
38212@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38213 request = compat_alloc_user_space(nbytes);
38214 if (!access_ok(VERIFY_WRITE, request, nbytes))
38215 return -EFAULT;
38216- list = (struct drm_buf_desc *) (request + 1);
38217+ list = (struct drm_buf_desc __user *) (request + 1);
38218
38219 if (__put_user(count, &request->count)
38220 || __put_user(list, &request->list))
38221@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38222 request = compat_alloc_user_space(nbytes);
38223 if (!access_ok(VERIFY_WRITE, request, nbytes))
38224 return -EFAULT;
38225- list = (struct drm_buf_pub *) (request + 1);
38226+ list = (struct drm_buf_pub __user *) (request + 1);
38227
38228 if (__put_user(count, &request->count)
38229 || __put_user(list, &request->list))
38230@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38231 return 0;
38232 }
38233
38234-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38235+drm_ioctl_compat_t drm_compat_ioctls[] = {
38236 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38237 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38238 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38239@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38240 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38241 {
38242 unsigned int nr = DRM_IOCTL_NR(cmd);
38243- drm_ioctl_compat_t *fn;
38244 int ret;
38245
38246 /* Assume that ioctls without an explicit compat routine will just
38247@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38248 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38249 return drm_ioctl(filp, cmd, arg);
38250
38251- fn = drm_compat_ioctls[nr];
38252-
38253- if (fn != NULL)
38254- ret = (*fn) (filp, cmd, arg);
38255+ if (drm_compat_ioctls[nr] != NULL)
38256+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38257 else
38258 ret = drm_ioctl(filp, cmd, arg);
38259
38260diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38261index ffd7a7b..a64643e 100644
38262--- a/drivers/gpu/drm/drm_ioctl.c
38263+++ b/drivers/gpu/drm/drm_ioctl.c
38264@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38265 stats->data[i].value =
38266 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38267 else
38268- stats->data[i].value = atomic_read(&dev->counts[i]);
38269+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38270 stats->data[i].type = dev->types[i];
38271 }
38272
38273diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38274index d752c96..fe08455 100644
38275--- a/drivers/gpu/drm/drm_lock.c
38276+++ b/drivers/gpu/drm/drm_lock.c
38277@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38278 if (drm_lock_take(&master->lock, lock->context)) {
38279 master->lock.file_priv = file_priv;
38280 master->lock.lock_time = jiffies;
38281- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38282+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38283 break; /* Got lock */
38284 }
38285
38286@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38287 return -EINVAL;
38288 }
38289
38290- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38291+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38292
38293 if (drm_lock_free(&master->lock, lock->context)) {
38294 /* FIXME: Should really bail out here. */
38295diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38296index 327ca19..684d3c0 100644
38297--- a/drivers/gpu/drm/drm_stub.c
38298+++ b/drivers/gpu/drm/drm_stub.c
38299@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38300
38301 drm_device_set_unplugged(dev);
38302
38303- if (dev->open_count == 0) {
38304+ if (local_read(&dev->open_count) == 0) {
38305 drm_put_dev(dev);
38306 }
38307 mutex_unlock(&drm_global_mutex);
38308diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38309index 2290b3b..22056a1 100644
38310--- a/drivers/gpu/drm/drm_sysfs.c
38311+++ b/drivers/gpu/drm/drm_sysfs.c
38312@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38313 int drm_sysfs_device_add(struct drm_minor *minor)
38314 {
38315 int err;
38316- char *minor_str;
38317+ const char *minor_str;
38318
38319 minor->kdev.parent = minor->dev->dev;
38320
38321diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38322index ada49ed..29275a0 100644
38323--- a/drivers/gpu/drm/i810/i810_dma.c
38324+++ b/drivers/gpu/drm/i810/i810_dma.c
38325@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38326 dma->buflist[vertex->idx],
38327 vertex->discard, vertex->used);
38328
38329- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38330- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38331+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38332+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38333 sarea_priv->last_enqueue = dev_priv->counter - 1;
38334 sarea_priv->last_dispatch = (int)hw_status[5];
38335
38336@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38337 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38338 mc->last_render);
38339
38340- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38341- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38342+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38343+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38344 sarea_priv->last_enqueue = dev_priv->counter - 1;
38345 sarea_priv->last_dispatch = (int)hw_status[5];
38346
38347diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38348index 6e0acad..93c8289 100644
38349--- a/drivers/gpu/drm/i810/i810_drv.h
38350+++ b/drivers/gpu/drm/i810/i810_drv.h
38351@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38352 int page_flipping;
38353
38354 wait_queue_head_t irq_queue;
38355- atomic_t irq_received;
38356- atomic_t irq_emitted;
38357+ atomic_unchecked_t irq_received;
38358+ atomic_unchecked_t irq_emitted;
38359
38360 int front_offset;
38361 } drm_i810_private_t;
38362diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38363index 47d6c74..279123f 100644
38364--- a/drivers/gpu/drm/i915/i915_debugfs.c
38365+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38366@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38367 I915_READ(GTIMR));
38368 }
38369 seq_printf(m, "Interrupts received: %d\n",
38370- atomic_read(&dev_priv->irq_received));
38371+ atomic_read_unchecked(&dev_priv->irq_received));
38372 for_each_ring(ring, dev_priv, i) {
38373 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38374 seq_printf(m,
38375diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38376index f466980..8f2883f 100644
38377--- a/drivers/gpu/drm/i915/i915_dma.c
38378+++ b/drivers/gpu/drm/i915/i915_dma.c
38379@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38380 bool can_switch;
38381
38382 spin_lock(&dev->count_lock);
38383- can_switch = (dev->open_count == 0);
38384+ can_switch = (local_read(&dev->open_count) == 0);
38385 spin_unlock(&dev->count_lock);
38386 return can_switch;
38387 }
38388diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38389index 1929bff..dab130d 100644
38390--- a/drivers/gpu/drm/i915/i915_drv.h
38391+++ b/drivers/gpu/drm/i915/i915_drv.h
38392@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38393 drm_dma_handle_t *status_page_dmah;
38394 struct resource mch_res;
38395
38396- atomic_t irq_received;
38397+ atomic_unchecked_t irq_received;
38398
38399 /* protects the irq masks */
38400 spinlock_t irq_lock;
38401diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38402index 87a3227..cd13d8f 100644
38403--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38404+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38405@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38406
38407 static int
38408 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38409- int count)
38410+ unsigned int count)
38411 {
38412- int i;
38413+ unsigned int i;
38414 int relocs_total = 0;
38415 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38416
38417diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38418index 3c59584..500f2e9 100644
38419--- a/drivers/gpu/drm/i915/i915_ioc32.c
38420+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38421@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38422 (unsigned long)request);
38423 }
38424
38425-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38426+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38427 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38428 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38429 [DRM_I915_GETPARAM] = compat_i915_getparam,
38430@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38431 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38432 {
38433 unsigned int nr = DRM_IOCTL_NR(cmd);
38434- drm_ioctl_compat_t *fn = NULL;
38435 int ret;
38436
38437 if (nr < DRM_COMMAND_BASE)
38438 return drm_compat_ioctl(filp, cmd, arg);
38439
38440- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38441- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38442-
38443- if (fn != NULL)
38444+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38445+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38446 ret = (*fn) (filp, cmd, arg);
38447- else
38448+ } else
38449 ret = drm_ioctl(filp, cmd, arg);
38450
38451 return ret;
38452diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38453index 3d92a7c..9a9cfd7 100644
38454--- a/drivers/gpu/drm/i915/i915_irq.c
38455+++ b/drivers/gpu/drm/i915/i915_irq.c
38456@@ -970,7 +970,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38457 int pipe;
38458 u32 pipe_stats[I915_MAX_PIPES];
38459
38460- atomic_inc(&dev_priv->irq_received);
38461+ atomic_inc_unchecked(&dev_priv->irq_received);
38462
38463 while (true) {
38464 iir = I915_READ(VLV_IIR);
38465@@ -1187,7 +1187,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38466 irqreturn_t ret = IRQ_NONE;
38467 int i;
38468
38469- atomic_inc(&dev_priv->irq_received);
38470+ atomic_inc_unchecked(&dev_priv->irq_received);
38471
38472 /* We get interrupts on unclaimed registers, so check for this before we
38473 * do any I915_{READ,WRITE}. */
38474@@ -1307,7 +1307,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38475 int ret = IRQ_NONE;
38476 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38477
38478- atomic_inc(&dev_priv->irq_received);
38479+ atomic_inc_unchecked(&dev_priv->irq_received);
38480
38481 /* disable master interrupt before clearing iir */
38482 de_ier = I915_READ(DEIER);
38483@@ -2566,7 +2566,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38484 {
38485 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38486
38487- atomic_set(&dev_priv->irq_received, 0);
38488+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38489
38490 I915_WRITE(HWSTAM, 0xeffe);
38491
38492@@ -2588,7 +2588,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38493 {
38494 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38495
38496- atomic_set(&dev_priv->irq_received, 0);
38497+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38498
38499 I915_WRITE(HWSTAM, 0xeffe);
38500
38501@@ -2616,7 +2616,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38502 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38503 int pipe;
38504
38505- atomic_set(&dev_priv->irq_received, 0);
38506+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38507
38508 /* VLV magic */
38509 I915_WRITE(VLV_IMR, 0);
38510@@ -2928,7 +2928,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38511 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38512 int pipe;
38513
38514- atomic_set(&dev_priv->irq_received, 0);
38515+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38516
38517 for_each_pipe(pipe)
38518 I915_WRITE(PIPESTAT(pipe), 0);
38519@@ -3007,7 +3007,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38520 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38521 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38522
38523- atomic_inc(&dev_priv->irq_received);
38524+ atomic_inc_unchecked(&dev_priv->irq_received);
38525
38526 iir = I915_READ16(IIR);
38527 if (iir == 0)
38528@@ -3082,7 +3082,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38529 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38530 int pipe;
38531
38532- atomic_set(&dev_priv->irq_received, 0);
38533+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38534
38535 if (I915_HAS_HOTPLUG(dev)) {
38536 I915_WRITE(PORT_HOTPLUG_EN, 0);
38537@@ -3181,7 +3181,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38538 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38539 int pipe, ret = IRQ_NONE;
38540
38541- atomic_inc(&dev_priv->irq_received);
38542+ atomic_inc_unchecked(&dev_priv->irq_received);
38543
38544 iir = I915_READ(IIR);
38545 do {
38546@@ -3305,7 +3305,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38547 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38548 int pipe;
38549
38550- atomic_set(&dev_priv->irq_received, 0);
38551+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38552
38553 I915_WRITE(PORT_HOTPLUG_EN, 0);
38554 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38555@@ -3414,7 +3414,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38556 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38557 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38558
38559- atomic_inc(&dev_priv->irq_received);
38560+ atomic_inc_unchecked(&dev_priv->irq_received);
38561
38562 iir = I915_READ(IIR);
38563
38564diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38565index be79f47..95e150b 100644
38566--- a/drivers/gpu/drm/i915/intel_display.c
38567+++ b/drivers/gpu/drm/i915/intel_display.c
38568@@ -9418,13 +9418,13 @@ struct intel_quirk {
38569 int subsystem_vendor;
38570 int subsystem_device;
38571 void (*hook)(struct drm_device *dev);
38572-};
38573+} __do_const;
38574
38575 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38576 struct intel_dmi_quirk {
38577 void (*hook)(struct drm_device *dev);
38578 const struct dmi_system_id (*dmi_id_list)[];
38579-};
38580+} __do_const;
38581
38582 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38583 {
38584@@ -9432,18 +9432,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38585 return 1;
38586 }
38587
38588-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38589+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38590 {
38591- .dmi_id_list = &(const struct dmi_system_id[]) {
38592- {
38593- .callback = intel_dmi_reverse_brightness,
38594- .ident = "NCR Corporation",
38595- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38596- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38597- },
38598- },
38599- { } /* terminating entry */
38600+ .callback = intel_dmi_reverse_brightness,
38601+ .ident = "NCR Corporation",
38602+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38603+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38604 },
38605+ },
38606+ { } /* terminating entry */
38607+};
38608+
38609+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38610+ {
38611+ .dmi_id_list = &intel_dmi_quirks_table,
38612 .hook = quirk_invert_brightness,
38613 },
38614 };
38615diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38616index 54558a0..2d97005 100644
38617--- a/drivers/gpu/drm/mga/mga_drv.h
38618+++ b/drivers/gpu/drm/mga/mga_drv.h
38619@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38620 u32 clear_cmd;
38621 u32 maccess;
38622
38623- atomic_t vbl_received; /**< Number of vblanks received. */
38624+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38625 wait_queue_head_t fence_queue;
38626- atomic_t last_fence_retired;
38627+ atomic_unchecked_t last_fence_retired;
38628 u32 next_fence_to_post;
38629
38630 unsigned int fb_cpp;
38631diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38632index 709e90d..89a1c0d 100644
38633--- a/drivers/gpu/drm/mga/mga_ioc32.c
38634+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38635@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38636 return 0;
38637 }
38638
38639-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38640+drm_ioctl_compat_t mga_compat_ioctls[] = {
38641 [DRM_MGA_INIT] = compat_mga_init,
38642 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38643 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38644@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38645 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38646 {
38647 unsigned int nr = DRM_IOCTL_NR(cmd);
38648- drm_ioctl_compat_t *fn = NULL;
38649 int ret;
38650
38651 if (nr < DRM_COMMAND_BASE)
38652 return drm_compat_ioctl(filp, cmd, arg);
38653
38654- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38655- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38656-
38657- if (fn != NULL)
38658+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38659+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38660 ret = (*fn) (filp, cmd, arg);
38661- else
38662+ } else
38663 ret = drm_ioctl(filp, cmd, arg);
38664
38665 return ret;
38666diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38667index 598c281..60d590e 100644
38668--- a/drivers/gpu/drm/mga/mga_irq.c
38669+++ b/drivers/gpu/drm/mga/mga_irq.c
38670@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38671 if (crtc != 0)
38672 return 0;
38673
38674- return atomic_read(&dev_priv->vbl_received);
38675+ return atomic_read_unchecked(&dev_priv->vbl_received);
38676 }
38677
38678
38679@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38680 /* VBLANK interrupt */
38681 if (status & MGA_VLINEPEN) {
38682 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38683- atomic_inc(&dev_priv->vbl_received);
38684+ atomic_inc_unchecked(&dev_priv->vbl_received);
38685 drm_handle_vblank(dev, 0);
38686 handled = 1;
38687 }
38688@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38689 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38690 MGA_WRITE(MGA_PRIMEND, prim_end);
38691
38692- atomic_inc(&dev_priv->last_fence_retired);
38693+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38694 DRM_WAKEUP(&dev_priv->fence_queue);
38695 handled = 1;
38696 }
38697@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38698 * using fences.
38699 */
38700 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38701- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38702+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38703 - *sequence) <= (1 << 23)));
38704
38705 *sequence = cur_fence;
38706diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38707index 3e72876..d1c15ad 100644
38708--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38709+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38710@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38711 struct bit_table {
38712 const char id;
38713 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38714-};
38715+} __no_const;
38716
38717 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38718
38719diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38720index 41ff7e0..fa854ef 100644
38721--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38722+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38723@@ -92,7 +92,6 @@ struct nouveau_drm {
38724 struct drm_global_reference mem_global_ref;
38725 struct ttm_bo_global_ref bo_global_ref;
38726 struct ttm_bo_device bdev;
38727- atomic_t validate_sequence;
38728 int (*move)(struct nouveau_channel *,
38729 struct ttm_buffer_object *,
38730 struct ttm_mem_reg *, struct ttm_mem_reg *);
38731diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38732index 08214bc..9208577 100644
38733--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38734+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38735@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38736 unsigned long arg)
38737 {
38738 unsigned int nr = DRM_IOCTL_NR(cmd);
38739- drm_ioctl_compat_t *fn = NULL;
38740+ drm_ioctl_compat_t fn = NULL;
38741 int ret;
38742
38743 if (nr < DRM_COMMAND_BASE)
38744diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38745index 25d3495..d81aaf6 100644
38746--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38747+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38748@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38749 bool can_switch;
38750
38751 spin_lock(&dev->count_lock);
38752- can_switch = (dev->open_count == 0);
38753+ can_switch = (local_read(&dev->open_count) == 0);
38754 spin_unlock(&dev->count_lock);
38755 return can_switch;
38756 }
38757diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38758index 1dfd84c..104896c 100644
38759--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38760+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38761@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38762 }
38763 }
38764
38765-static struct vm_operations_struct qxl_ttm_vm_ops;
38766+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38767 static const struct vm_operations_struct *ttm_vm_ops;
38768
38769 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38770@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38771 return r;
38772 if (unlikely(ttm_vm_ops == NULL)) {
38773 ttm_vm_ops = vma->vm_ops;
38774+ pax_open_kernel();
38775 qxl_ttm_vm_ops = *ttm_vm_ops;
38776 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38777+ pax_close_kernel();
38778 }
38779 vma->vm_ops = &qxl_ttm_vm_ops;
38780 return 0;
38781@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38782 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38783 {
38784 #if defined(CONFIG_DEBUG_FS)
38785- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38786- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38787- unsigned i;
38788+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38789+ {
38790+ .name = "qxl_mem_mm",
38791+ .show = &qxl_mm_dump_table,
38792+ },
38793+ {
38794+ .name = "qxl_surf_mm",
38795+ .show = &qxl_mm_dump_table,
38796+ }
38797+ };
38798
38799- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38800- if (i == 0)
38801- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38802- else
38803- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38804- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38805- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38806- qxl_mem_types_list[i].driver_features = 0;
38807- if (i == 0)
38808- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38809- else
38810- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38811+ pax_open_kernel();
38812+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38813+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38814+ pax_close_kernel();
38815
38816- }
38817- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38818+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38819 #else
38820 return 0;
38821 #endif
38822diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38823index d4660cf..70dbe65 100644
38824--- a/drivers/gpu/drm/r128/r128_cce.c
38825+++ b/drivers/gpu/drm/r128/r128_cce.c
38826@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38827
38828 /* GH: Simple idle check.
38829 */
38830- atomic_set(&dev_priv->idle_count, 0);
38831+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38832
38833 /* We don't support anything other than bus-mastering ring mode,
38834 * but the ring can be in either AGP or PCI space for the ring
38835diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38836index 930c71b..499aded 100644
38837--- a/drivers/gpu/drm/r128/r128_drv.h
38838+++ b/drivers/gpu/drm/r128/r128_drv.h
38839@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38840 int is_pci;
38841 unsigned long cce_buffers_offset;
38842
38843- atomic_t idle_count;
38844+ atomic_unchecked_t idle_count;
38845
38846 int page_flipping;
38847 int current_page;
38848 u32 crtc_offset;
38849 u32 crtc_offset_cntl;
38850
38851- atomic_t vbl_received;
38852+ atomic_unchecked_t vbl_received;
38853
38854 u32 color_fmt;
38855 unsigned int front_offset;
38856diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38857index a954c54..9cc595c 100644
38858--- a/drivers/gpu/drm/r128/r128_ioc32.c
38859+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38860@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38861 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38862 }
38863
38864-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38865+drm_ioctl_compat_t r128_compat_ioctls[] = {
38866 [DRM_R128_INIT] = compat_r128_init,
38867 [DRM_R128_DEPTH] = compat_r128_depth,
38868 [DRM_R128_STIPPLE] = compat_r128_stipple,
38869@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38870 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38871 {
38872 unsigned int nr = DRM_IOCTL_NR(cmd);
38873- drm_ioctl_compat_t *fn = NULL;
38874 int ret;
38875
38876 if (nr < DRM_COMMAND_BASE)
38877 return drm_compat_ioctl(filp, cmd, arg);
38878
38879- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38880- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38881-
38882- if (fn != NULL)
38883+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38884+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38885 ret = (*fn) (filp, cmd, arg);
38886- else
38887+ } else
38888 ret = drm_ioctl(filp, cmd, arg);
38889
38890 return ret;
38891diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38892index 2ea4f09..d391371 100644
38893--- a/drivers/gpu/drm/r128/r128_irq.c
38894+++ b/drivers/gpu/drm/r128/r128_irq.c
38895@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38896 if (crtc != 0)
38897 return 0;
38898
38899- return atomic_read(&dev_priv->vbl_received);
38900+ return atomic_read_unchecked(&dev_priv->vbl_received);
38901 }
38902
38903 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38904@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38905 /* VBLANK interrupt */
38906 if (status & R128_CRTC_VBLANK_INT) {
38907 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38908- atomic_inc(&dev_priv->vbl_received);
38909+ atomic_inc_unchecked(&dev_priv->vbl_received);
38910 drm_handle_vblank(dev, 0);
38911 return IRQ_HANDLED;
38912 }
38913diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38914index 19bb7e6..de7e2a2 100644
38915--- a/drivers/gpu/drm/r128/r128_state.c
38916+++ b/drivers/gpu/drm/r128/r128_state.c
38917@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38918
38919 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38920 {
38921- if (atomic_read(&dev_priv->idle_count) == 0)
38922+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38923 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38924 else
38925- atomic_set(&dev_priv->idle_count, 0);
38926+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38927 }
38928
38929 #endif
38930diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38931index af85299..ed9ac8d 100644
38932--- a/drivers/gpu/drm/radeon/mkregtable.c
38933+++ b/drivers/gpu/drm/radeon/mkregtable.c
38934@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38935 regex_t mask_rex;
38936 regmatch_t match[4];
38937 char buf[1024];
38938- size_t end;
38939+ long end;
38940 int len;
38941 int done = 0;
38942 int r;
38943 unsigned o;
38944 struct offset *offset;
38945 char last_reg_s[10];
38946- int last_reg;
38947+ unsigned long last_reg;
38948
38949 if (regcomp
38950 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38951diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38952index 63398ae..669e045 100644
38953--- a/drivers/gpu/drm/radeon/radeon_device.c
38954+++ b/drivers/gpu/drm/radeon/radeon_device.c
38955@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38956 bool can_switch;
38957
38958 spin_lock(&dev->count_lock);
38959- can_switch = (dev->open_count == 0);
38960+ can_switch = (local_read(&dev->open_count) == 0);
38961 spin_unlock(&dev->count_lock);
38962 return can_switch;
38963 }
38964diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38965index b369d42..8dd04eb 100644
38966--- a/drivers/gpu/drm/radeon/radeon_drv.h
38967+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38968@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38969
38970 /* SW interrupt */
38971 wait_queue_head_t swi_queue;
38972- atomic_t swi_emitted;
38973+ atomic_unchecked_t swi_emitted;
38974 int vblank_crtc;
38975 uint32_t irq_enable_reg;
38976 uint32_t r500_disp_irq_reg;
38977diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38978index c180df8..5fd8186 100644
38979--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38980+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38981@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38982 request = compat_alloc_user_space(sizeof(*request));
38983 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38984 || __put_user(req32.param, &request->param)
38985- || __put_user((void __user *)(unsigned long)req32.value,
38986+ || __put_user((unsigned long)req32.value,
38987 &request->value))
38988 return -EFAULT;
38989
38990@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38991 #define compat_radeon_cp_setparam NULL
38992 #endif /* X86_64 || IA64 */
38993
38994-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38995+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38996 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38997 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38998 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38999@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39000 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39001 {
39002 unsigned int nr = DRM_IOCTL_NR(cmd);
39003- drm_ioctl_compat_t *fn = NULL;
39004 int ret;
39005
39006 if (nr < DRM_COMMAND_BASE)
39007 return drm_compat_ioctl(filp, cmd, arg);
39008
39009- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39010- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39011-
39012- if (fn != NULL)
39013+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39014+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39015 ret = (*fn) (filp, cmd, arg);
39016- else
39017+ } else
39018 ret = drm_ioctl(filp, cmd, arg);
39019
39020 return ret;
39021diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39022index 8d68e97..9dcfed8 100644
39023--- a/drivers/gpu/drm/radeon/radeon_irq.c
39024+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39025@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39026 unsigned int ret;
39027 RING_LOCALS;
39028
39029- atomic_inc(&dev_priv->swi_emitted);
39030- ret = atomic_read(&dev_priv->swi_emitted);
39031+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39032+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39033
39034 BEGIN_RING(4);
39035 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39036@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39037 drm_radeon_private_t *dev_priv =
39038 (drm_radeon_private_t *) dev->dev_private;
39039
39040- atomic_set(&dev_priv->swi_emitted, 0);
39041+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39042 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39043
39044 dev->max_vblank_count = 0x001fffff;
39045diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39046index 4d20910..6726b6d 100644
39047--- a/drivers/gpu/drm/radeon/radeon_state.c
39048+++ b/drivers/gpu/drm/radeon/radeon_state.c
39049@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39050 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39051 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39052
39053- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39054+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39055 sarea_priv->nbox * sizeof(depth_boxes[0])))
39056 return -EFAULT;
39057
39058@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39059 {
39060 drm_radeon_private_t *dev_priv = dev->dev_private;
39061 drm_radeon_getparam_t *param = data;
39062- int value;
39063+ int value = 0;
39064
39065 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39066
39067diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39068index 6c0ce89..57a2529 100644
39069--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39070+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39071@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39072 man->size = size >> PAGE_SHIFT;
39073 }
39074
39075-static struct vm_operations_struct radeon_ttm_vm_ops;
39076+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39077 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39078
39079 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39080@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39081 }
39082 if (unlikely(ttm_vm_ops == NULL)) {
39083 ttm_vm_ops = vma->vm_ops;
39084+ pax_open_kernel();
39085 radeon_ttm_vm_ops = *ttm_vm_ops;
39086 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39087+ pax_close_kernel();
39088 }
39089 vma->vm_ops = &radeon_ttm_vm_ops;
39090 return 0;
39091@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39092 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39093 {
39094 #if defined(CONFIG_DEBUG_FS)
39095- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39096- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39097+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39098+ {
39099+ .name = "radeon_vram_mm",
39100+ .show = &radeon_mm_dump_table,
39101+ },
39102+ {
39103+ .name = "radeon_gtt_mm",
39104+ .show = &radeon_mm_dump_table,
39105+ },
39106+ {
39107+ .name = "ttm_page_pool",
39108+ .show = &ttm_page_alloc_debugfs,
39109+ },
39110+ {
39111+ .name = "ttm_dma_page_pool",
39112+ .show = &ttm_dma_page_alloc_debugfs,
39113+ },
39114+ };
39115 unsigned i;
39116
39117- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39118- if (i == 0)
39119- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39120- else
39121- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39122- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39123- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39124- radeon_mem_types_list[i].driver_features = 0;
39125- if (i == 0)
39126- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39127- else
39128- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39129-
39130- }
39131- /* Add ttm page pool to debugfs */
39132- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39133- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39134- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39135- radeon_mem_types_list[i].driver_features = 0;
39136- radeon_mem_types_list[i++].data = NULL;
39137+ pax_open_kernel();
39138+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39139+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39140+ pax_close_kernel();
39141 #ifdef CONFIG_SWIOTLB
39142- if (swiotlb_nr_tbl()) {
39143- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39144- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39145- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39146- radeon_mem_types_list[i].driver_features = 0;
39147- radeon_mem_types_list[i++].data = NULL;
39148- }
39149+ if (swiotlb_nr_tbl())
39150+ i++;
39151 #endif
39152 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39153
39154diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39155index d8ddfb3..609de1d 100644
39156--- a/drivers/gpu/drm/radeon/rs690.c
39157+++ b/drivers/gpu/drm/radeon/rs690.c
39158@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39159 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39160 rdev->pm.sideport_bandwidth.full)
39161 max_bandwidth = rdev->pm.sideport_bandwidth;
39162- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39163+ read_delay_latency.full = dfixed_const(800 * 1000);
39164 read_delay_latency.full = dfixed_div(read_delay_latency,
39165 rdev->pm.igp_sideport_mclk);
39166+ a.full = dfixed_const(370);
39167+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39168 } else {
39169 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39170 rdev->pm.k8_bandwidth.full)
39171diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39172index dbc2def..0a9f710 100644
39173--- a/drivers/gpu/drm/ttm/ttm_memory.c
39174+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39175@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39176 zone->glob = glob;
39177 glob->zone_kernel = zone;
39178 ret = kobject_init_and_add(
39179- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39180+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39181 if (unlikely(ret != 0)) {
39182 kobject_put(&zone->kobj);
39183 return ret;
39184@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39185 zone->glob = glob;
39186 glob->zone_dma32 = zone;
39187 ret = kobject_init_and_add(
39188- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39189+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39190 if (unlikely(ret != 0)) {
39191 kobject_put(&zone->kobj);
39192 return ret;
39193diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39194index bd2a3b4..122d9ad 100644
39195--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39196+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39197@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39198 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39199 struct shrink_control *sc)
39200 {
39201- static atomic_t start_pool = ATOMIC_INIT(0);
39202+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39203 unsigned i;
39204- unsigned pool_offset = atomic_add_return(1, &start_pool);
39205+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39206 struct ttm_page_pool *pool;
39207 int shrink_pages = sc->nr_to_scan;
39208
39209diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39210index 97e9d61..bf23c461 100644
39211--- a/drivers/gpu/drm/udl/udl_fb.c
39212+++ b/drivers/gpu/drm/udl/udl_fb.c
39213@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39214 fb_deferred_io_cleanup(info);
39215 kfree(info->fbdefio);
39216 info->fbdefio = NULL;
39217- info->fbops->fb_mmap = udl_fb_mmap;
39218 }
39219
39220 pr_warn("released /dev/fb%d user=%d count=%d\n",
39221diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39222index 893a650..6190d3b 100644
39223--- a/drivers/gpu/drm/via/via_drv.h
39224+++ b/drivers/gpu/drm/via/via_drv.h
39225@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39226 typedef uint32_t maskarray_t[5];
39227
39228 typedef struct drm_via_irq {
39229- atomic_t irq_received;
39230+ atomic_unchecked_t irq_received;
39231 uint32_t pending_mask;
39232 uint32_t enable_mask;
39233 wait_queue_head_t irq_queue;
39234@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39235 struct timeval last_vblank;
39236 int last_vblank_valid;
39237 unsigned usec_per_vblank;
39238- atomic_t vbl_received;
39239+ atomic_unchecked_t vbl_received;
39240 drm_via_state_t hc_state;
39241 char pci_buf[VIA_PCI_BUF_SIZE];
39242 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39243diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39244index ac98964..5dbf512 100644
39245--- a/drivers/gpu/drm/via/via_irq.c
39246+++ b/drivers/gpu/drm/via/via_irq.c
39247@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39248 if (crtc != 0)
39249 return 0;
39250
39251- return atomic_read(&dev_priv->vbl_received);
39252+ return atomic_read_unchecked(&dev_priv->vbl_received);
39253 }
39254
39255 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39256@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39257
39258 status = VIA_READ(VIA_REG_INTERRUPT);
39259 if (status & VIA_IRQ_VBLANK_PENDING) {
39260- atomic_inc(&dev_priv->vbl_received);
39261- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39262+ atomic_inc_unchecked(&dev_priv->vbl_received);
39263+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39264 do_gettimeofday(&cur_vblank);
39265 if (dev_priv->last_vblank_valid) {
39266 dev_priv->usec_per_vblank =
39267@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39268 dev_priv->last_vblank = cur_vblank;
39269 dev_priv->last_vblank_valid = 1;
39270 }
39271- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39272+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39273 DRM_DEBUG("US per vblank is: %u\n",
39274 dev_priv->usec_per_vblank);
39275 }
39276@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39277
39278 for (i = 0; i < dev_priv->num_irqs; ++i) {
39279 if (status & cur_irq->pending_mask) {
39280- atomic_inc(&cur_irq->irq_received);
39281+ atomic_inc_unchecked(&cur_irq->irq_received);
39282 DRM_WAKEUP(&cur_irq->irq_queue);
39283 handled = 1;
39284 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39285@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39286 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39287 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39288 masks[irq][4]));
39289- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39290+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39291 } else {
39292 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39293 (((cur_irq_sequence =
39294- atomic_read(&cur_irq->irq_received)) -
39295+ atomic_read_unchecked(&cur_irq->irq_received)) -
39296 *sequence) <= (1 << 23)));
39297 }
39298 *sequence = cur_irq_sequence;
39299@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39300 }
39301
39302 for (i = 0; i < dev_priv->num_irqs; ++i) {
39303- atomic_set(&cur_irq->irq_received, 0);
39304+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39305 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39306 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39307 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39308@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39309 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39310 case VIA_IRQ_RELATIVE:
39311 irqwait->request.sequence +=
39312- atomic_read(&cur_irq->irq_received);
39313+ atomic_read_unchecked(&cur_irq->irq_received);
39314 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39315 case VIA_IRQ_ABSOLUTE:
39316 break;
39317diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39318index 13aeda7..4a952d1 100644
39319--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39320+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39321@@ -290,7 +290,7 @@ struct vmw_private {
39322 * Fencing and IRQs.
39323 */
39324
39325- atomic_t marker_seq;
39326+ atomic_unchecked_t marker_seq;
39327 wait_queue_head_t fence_queue;
39328 wait_queue_head_t fifo_queue;
39329 int fence_queue_waiters; /* Protected by hw_mutex */
39330diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39331index 3eb1486..0a47ee9 100644
39332--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39333+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39334@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39335 (unsigned int) min,
39336 (unsigned int) fifo->capabilities);
39337
39338- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39339+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39340 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39341 vmw_marker_queue_init(&fifo->marker_queue);
39342 return vmw_fifo_send_fence(dev_priv, &dummy);
39343@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39344 if (reserveable)
39345 iowrite32(bytes, fifo_mem +
39346 SVGA_FIFO_RESERVED);
39347- return fifo_mem + (next_cmd >> 2);
39348+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39349 } else {
39350 need_bounce = true;
39351 }
39352@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39353
39354 fm = vmw_fifo_reserve(dev_priv, bytes);
39355 if (unlikely(fm == NULL)) {
39356- *seqno = atomic_read(&dev_priv->marker_seq);
39357+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39358 ret = -ENOMEM;
39359 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39360 false, 3*HZ);
39361@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39362 }
39363
39364 do {
39365- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39366+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39367 } while (*seqno == 0);
39368
39369 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39370diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39371index c509d40..3b640c3 100644
39372--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39373+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39374@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39375 int ret;
39376
39377 num_clips = arg->num_clips;
39378- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39379+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39380
39381 if (unlikely(num_clips == 0))
39382 return 0;
39383@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39384 int ret;
39385
39386 num_clips = arg->num_clips;
39387- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39388+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39389
39390 if (unlikely(num_clips == 0))
39391 return 0;
39392diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39393index 4640adb..e1384ed 100644
39394--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39395+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39396@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39397 * emitted. Then the fence is stale and signaled.
39398 */
39399
39400- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39401+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39402 > VMW_FENCE_WRAP);
39403
39404 return ret;
39405@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39406
39407 if (fifo_idle)
39408 down_read(&fifo_state->rwsem);
39409- signal_seq = atomic_read(&dev_priv->marker_seq);
39410+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39411 ret = 0;
39412
39413 for (;;) {
39414diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39415index 8a8725c2..afed796 100644
39416--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39417+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39418@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39419 while (!vmw_lag_lt(queue, us)) {
39420 spin_lock(&queue->lock);
39421 if (list_empty(&queue->head))
39422- seqno = atomic_read(&dev_priv->marker_seq);
39423+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39424 else {
39425 marker = list_first_entry(&queue->head,
39426 struct vmw_marker, head);
39427diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39428index 5360e5a..c2c0d26 100644
39429--- a/drivers/gpu/host1x/drm/dc.c
39430+++ b/drivers/gpu/host1x/drm/dc.c
39431@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39432 }
39433
39434 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39435- dc->debugfs_files[i].data = dc;
39436+ *(void **)&dc->debugfs_files[i].data = dc;
39437
39438 err = drm_debugfs_create_files(dc->debugfs_files,
39439 ARRAY_SIZE(debugfs_files),
39440diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39441index 36668d1..9f4ccb0 100644
39442--- a/drivers/hid/hid-core.c
39443+++ b/drivers/hid/hid-core.c
39444@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39445 struct hid_report_enum *report_enum = device->report_enum + type;
39446 struct hid_report *report;
39447
39448+ if (id >= HID_MAX_IDS)
39449+ return NULL;
39450 if (report_enum->report_id_hash[id])
39451 return report_enum->report_id_hash[id];
39452
39453@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39454
39455 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39456 parser->global.report_id = item_udata(item);
39457- if (parser->global.report_id == 0) {
39458- hid_err(parser->device, "report_id 0 is invalid\n");
39459+ if (parser->global.report_id == 0 ||
39460+ parser->global.report_id >= HID_MAX_IDS) {
39461+ hid_err(parser->device, "report_id %u is invalid\n",
39462+ parser->global.report_id);
39463 return -1;
39464 }
39465 return 0;
39466@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39467 for (i = 0; i < HID_REPORT_TYPES; i++) {
39468 struct hid_report_enum *report_enum = device->report_enum + i;
39469
39470- for (j = 0; j < 256; j++) {
39471+ for (j = 0; j < HID_MAX_IDS; j++) {
39472 struct hid_report *report = report_enum->report_id_hash[j];
39473 if (report)
39474 hid_free_report(report);
39475@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39476 }
39477 EXPORT_SYMBOL_GPL(hid_parse_report);
39478
39479+static const char * const hid_report_names[] = {
39480+ "HID_INPUT_REPORT",
39481+ "HID_OUTPUT_REPORT",
39482+ "HID_FEATURE_REPORT",
39483+};
39484+/**
39485+ * hid_validate_report - validate existing device report
39486+ *
39487+ * @device: hid device
39488+ * @type: which report type to examine
39489+ * @id: which report ID to examine (0 for first)
39490+ * @fields: expected number of fields
39491+ * @report_counts: expected number of values per field
39492+ *
39493+ * Validate the report details after parsing.
39494+ */
39495+struct hid_report *hid_validate_report(struct hid_device *hid,
39496+ unsigned int type, unsigned int id,
39497+ unsigned int fields,
39498+ unsigned int report_counts)
39499+{
39500+ struct hid_report *report;
39501+ unsigned int i;
39502+
39503+ if (type > HID_FEATURE_REPORT) {
39504+ hid_err(hid, "invalid HID report %u\n", type);
39505+ return NULL;
39506+ }
39507+
39508+ report = hid->report_enum[type].report_id_hash[id];
39509+ if (!report) {
39510+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
39511+ return NULL;
39512+ }
39513+ if (report->maxfield < fields) {
39514+ hid_err(hid, "not enough fields in %s %u\n",
39515+ hid_report_names[type], id);
39516+ return NULL;
39517+ }
39518+ for (i = 0; i < fields; i++) {
39519+ if (report->field[i]->report_count < report_counts) {
39520+ hid_err(hid, "not enough values in %s %u fields\n",
39521+ hid_report_names[type], id);
39522+ return NULL;
39523+ }
39524+ }
39525+ return report;
39526+}
39527+EXPORT_SYMBOL_GPL(hid_validate_report);
39528+
39529 /**
39530 * hid_open_report - open a driver-specific device report
39531 *
39532@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
39533
39534 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
39535 {
39536- unsigned size = field->report_size;
39537+ unsigned size;
39538+
39539+ if (!field)
39540+ return -1;
39541+
39542+ size = field->report_size;
39543
39544 hid_dump_input(field->report->device, field->usage + offset, value);
39545
39546@@ -2285,7 +2344,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39547
39548 int hid_add_device(struct hid_device *hdev)
39549 {
39550- static atomic_t id = ATOMIC_INIT(0);
39551+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39552 int ret;
39553
39554 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39555@@ -2319,7 +2378,7 @@ int hid_add_device(struct hid_device *hdev)
39556 /* XXX hack, any other cleaner solution after the driver core
39557 * is converted to allow more than 20 bytes as the device name? */
39558 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39559- hdev->vendor, hdev->product, atomic_inc_return(&id));
39560+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39561
39562 hid_debug_register(hdev, dev_name(&hdev->dev));
39563 ret = device_add(&hdev->dev);
39564diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
39565index 07837f5..b697ada 100644
39566--- a/drivers/hid/hid-lenovo-tpkbd.c
39567+++ b/drivers/hid/hid-lenovo-tpkbd.c
39568@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
39569 char *name_mute, *name_micmute;
39570 int ret;
39571
39572+ /* Validate required reports. */
39573+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
39574+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
39575+ return -ENODEV;
39576+
39577 if (sysfs_create_group(&hdev->dev.kobj,
39578 &tpkbd_attr_group_pointer)) {
39579 hid_warn(hdev, "Could not create sysfs group\n");
39580diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
39581index b3cd150..9805197 100644
39582--- a/drivers/hid/hid-lg2ff.c
39583+++ b/drivers/hid/hid-lg2ff.c
39584@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
39585 struct hid_report *report;
39586 struct hid_input *hidinput = list_entry(hid->inputs.next,
39587 struct hid_input, list);
39588- struct list_head *report_list =
39589- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39590 struct input_dev *dev = hidinput->input;
39591 int error;
39592
39593- if (list_empty(report_list)) {
39594- hid_err(hid, "no output report found\n");
39595+ /* Check that the report looks ok */
39596+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
39597+ if (!report)
39598 return -ENODEV;
39599- }
39600-
39601- report = list_entry(report_list->next, struct hid_report, list);
39602-
39603- if (report->maxfield < 1) {
39604- hid_err(hid, "output report is empty\n");
39605- return -ENODEV;
39606- }
39607- if (report->field[0]->report_count < 7) {
39608- hid_err(hid, "not enough values in the field\n");
39609- return -ENODEV;
39610- }
39611
39612 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
39613 if (!lg2ff)
39614diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
39615index e52f181..53ac79b 100644
39616--- a/drivers/hid/hid-lg3ff.c
39617+++ b/drivers/hid/hid-lg3ff.c
39618@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
39619 int x, y;
39620
39621 /*
39622- * Maxusage should always be 63 (maximum fields)
39623- * likely a better way to ensure this data is clean
39624+ * Available values in the field should always be 63, but we only use up to
39625+ * 35. Instead, clear the entire area, however big it is.
39626 */
39627- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
39628+ memset(report->field[0]->value, 0,
39629+ sizeof(__s32) * report->field[0]->report_count);
39630
39631 switch (effect->type) {
39632 case FF_CONSTANT:
39633@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
39634 int lg3ff_init(struct hid_device *hid)
39635 {
39636 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39637- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39638 struct input_dev *dev = hidinput->input;
39639- struct hid_report *report;
39640- struct hid_field *field;
39641 const signed short *ff_bits = ff3_joystick_ac;
39642 int error;
39643 int i;
39644
39645- /* Find the report to use */
39646- if (list_empty(report_list)) {
39647- hid_err(hid, "No output report found\n");
39648- return -1;
39649- }
39650-
39651 /* Check that the report looks ok */
39652- report = list_entry(report_list->next, struct hid_report, list);
39653- if (!report) {
39654- hid_err(hid, "NULL output report\n");
39655- return -1;
39656- }
39657-
39658- field = report->field[0];
39659- if (!field) {
39660- hid_err(hid, "NULL field\n");
39661- return -1;
39662- }
39663+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
39664+ return -ENODEV;
39665
39666 /* Assume single fixed device G940 */
39667 for (i = 0; ff_bits[i] >= 0; i++)
39668diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
39669index 0ddae2a..8b89f0f 100644
39670--- a/drivers/hid/hid-lg4ff.c
39671+++ b/drivers/hid/hid-lg4ff.c
39672@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
39673 int lg4ff_init(struct hid_device *hid)
39674 {
39675 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39676- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39677 struct input_dev *dev = hidinput->input;
39678- struct hid_report *report;
39679- struct hid_field *field;
39680 struct lg4ff_device_entry *entry;
39681 struct lg_drv_data *drv_data;
39682 struct usb_device_descriptor *udesc;
39683 int error, i, j;
39684 __u16 bcdDevice, rev_maj, rev_min;
39685
39686- /* Find the report to use */
39687- if (list_empty(report_list)) {
39688- hid_err(hid, "No output report found\n");
39689- return -1;
39690- }
39691-
39692 /* Check that the report looks ok */
39693- report = list_entry(report_list->next, struct hid_report, list);
39694- if (!report) {
39695- hid_err(hid, "NULL output report\n");
39696+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39697 return -1;
39698- }
39699-
39700- field = report->field[0];
39701- if (!field) {
39702- hid_err(hid, "NULL field\n");
39703- return -1;
39704- }
39705
39706 /* Check what wheel has been connected */
39707 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
39708diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
39709index d7ea8c8..a84fb40 100644
39710--- a/drivers/hid/hid-lgff.c
39711+++ b/drivers/hid/hid-lgff.c
39712@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
39713 int lgff_init(struct hid_device* hid)
39714 {
39715 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39716- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39717 struct input_dev *dev = hidinput->input;
39718- struct hid_report *report;
39719- struct hid_field *field;
39720 const signed short *ff_bits = ff_joystick;
39721 int error;
39722 int i;
39723
39724- /* Find the report to use */
39725- if (list_empty(report_list)) {
39726- hid_err(hid, "No output report found\n");
39727- return -1;
39728- }
39729-
39730 /* Check that the report looks ok */
39731- report = list_entry(report_list->next, struct hid_report, list);
39732- field = report->field[0];
39733- if (!field) {
39734- hid_err(hid, "NULL field\n");
39735- return -1;
39736- }
39737+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39738+ return -ENODEV;
39739
39740 for (i = 0; i < ARRAY_SIZE(devices); i++) {
39741 if (dev->id.vendor == devices[i].idVendor &&
39742diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
39743index cd33084..7b99c2a 100644
39744--- a/drivers/hid/hid-logitech-dj.c
39745+++ b/drivers/hid/hid-logitech-dj.c
39746@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39747 struct hid_report *report;
39748 struct hid_report_enum *output_report_enum;
39749 u8 *data = (u8 *)(&dj_report->device_index);
39750- int i;
39751+ unsigned int i, length;
39752
39753 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
39754 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
39755@@ -471,7 +471,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39756 return -ENODEV;
39757 }
39758
39759- for (i = 0; i < report->field[0]->report_count; i++)
39760+ length = min_t(size_t, sizeof(*dj_report) - 1,
39761+ report->field[0]->report_count);
39762+ for (i = 0; i < length; i++)
39763 report->field[0]->value[i] = data[i];
39764
39765 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
39766@@ -783,6 +785,12 @@ static int logi_dj_probe(struct hid_device *hdev,
39767 goto hid_parse_fail;
39768 }
39769
39770+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
39771+ 1, 3)) {
39772+ retval = -ENODEV;
39773+ goto hid_parse_fail;
39774+ }
39775+
39776 /* Starts the usb device and connects to upper interfaces hiddev and
39777 * hidraw */
39778 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39779diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
39780index cb0e361..2aa275e 100644
39781--- a/drivers/hid/hid-multitouch.c
39782+++ b/drivers/hid/hid-multitouch.c
39783@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
39784 break;
39785 }
39786 }
39787+ /* Ignore if value index is out of bounds. */
39788+ if (td->inputmode_index < 0 ||
39789+ td->inputmode_index >= field->report_count) {
39790+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
39791+ td->inputmode = -1;
39792+ }
39793
39794 break;
39795 case HID_DG_CONTACTMAX:
39796+ /* Ignore if value count is out of bounds. */
39797+ if (field->report_count < 1)
39798+ break;
39799 td->maxcontact_report_id = field->report->id;
39800 td->maxcontacts = field->value[0];
39801 if (!td->maxcontacts &&
39802@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
39803 unsigned count;
39804 int r, n;
39805
39806+ if (report->maxfield == 0)
39807+ return;
39808+
39809 /*
39810 * Includes multi-packet support where subsequent
39811 * packets are sent with zero contactcount.
39812 */
39813- if (td->cc_index >= 0) {
39814- struct hid_field *field = report->field[td->cc_index];
39815- int value = field->value[td->cc_value_index];
39816- if (value)
39817- td->num_expected = value;
39818+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
39819+ field = report->field[td->cc_index];
39820+ if (td->cc_value_index >= 0 &&
39821+ td->cc_value_index < field->report_count) {
39822+ int value = field->value[td->cc_value_index];
39823+ if (value)
39824+ td->num_expected = value;
39825+ }
39826 }
39827
39828 for (r = 0; r < report->maxfield; r++) {
39829diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
39830index ef95102..5482156 100644
39831--- a/drivers/hid/hid-ntrig.c
39832+++ b/drivers/hid/hid-ntrig.c
39833@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
39834 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
39835 report_id_hash[0x0d];
39836
39837- if (!report)
39838+ if (!report || report->maxfield < 1 ||
39839+ report->field[0]->report_count < 1)
39840 return -EINVAL;
39841
39842 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
39843diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
39844index b48092d..72bba1e 100644
39845--- a/drivers/hid/hid-picolcd_core.c
39846+++ b/drivers/hid/hid-picolcd_core.c
39847@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
39848 buf += 10;
39849 cnt -= 10;
39850 }
39851- if (!report)
39852+ if (!report || report->maxfield < 1)
39853 return -EINVAL;
39854
39855 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
39856diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
39857index d29112f..2dcd7d9 100644
39858--- a/drivers/hid/hid-pl.c
39859+++ b/drivers/hid/hid-pl.c
39860@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
39861 strong = &report->field[0]->value[2];
39862 weak = &report->field[0]->value[3];
39863 debug("detected single-field device");
39864- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
39865- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
39866+ } else if (report->field[0]->maxusage == 1 &&
39867+ report->field[0]->usage[0].hid ==
39868+ (HID_UP_LED | 0x43) &&
39869+ report->maxfield >= 4 &&
39870+ report->field[0]->report_count >= 1 &&
39871+ report->field[1]->report_count >= 1 &&
39872+ report->field[2]->report_count >= 1 &&
39873+ report->field[3]->report_count >= 1) {
39874 report->field[0]->value[0] = 0x00;
39875 report->field[1]->value[0] = 0x00;
39876 strong = &report->field[2]->value[0];
39877diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
39878index ca749810..aa34755 100644
39879--- a/drivers/hid/hid-sensor-hub.c
39880+++ b/drivers/hid/hid-sensor-hub.c
39881@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
39882
39883 mutex_lock(&data->mutex);
39884 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
39885- if (!report || (field_index >= report->maxfield)) {
39886+ if (!report || (field_index >= report->maxfield) ||
39887+ report->field[field_index]->report_count < 1) {
39888 ret = -EINVAL;
39889 goto done_proc;
39890 }
39891diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
39892index d164911..ef42e86 100644
39893--- a/drivers/hid/hid-steelseries.c
39894+++ b/drivers/hid/hid-steelseries.c
39895@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
39896 goto err_free;
39897 }
39898
39899+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
39900+ ret = -ENODEV;
39901+ goto err_free;
39902+ }
39903+
39904 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39905 if (ret) {
39906 hid_err(hdev, "hw start failed\n");
39907diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39908index c13fb5b..55a3802 100644
39909--- a/drivers/hid/hid-wiimote-debug.c
39910+++ b/drivers/hid/hid-wiimote-debug.c
39911@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39912 else if (size == 0)
39913 return -EIO;
39914
39915- if (copy_to_user(u, buf, size))
39916+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39917 return -EFAULT;
39918
39919 *off += size;
39920diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
39921index 6ec28a3..b124991 100644
39922--- a/drivers/hid/hid-zpff.c
39923+++ b/drivers/hid/hid-zpff.c
39924@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
39925 struct hid_report *report;
39926 struct hid_input *hidinput = list_entry(hid->inputs.next,
39927 struct hid_input, list);
39928- struct list_head *report_list =
39929- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39930 struct input_dev *dev = hidinput->input;
39931 int error;
39932
39933- if (list_empty(report_list)) {
39934- hid_err(hid, "no output report found\n");
39935+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
39936+ if (!report)
39937 return -ENODEV;
39938- }
39939-
39940- report = list_entry(report_list->next, struct hid_report, list);
39941-
39942- if (report->maxfield < 4) {
39943- hid_err(hid, "not enough fields in report\n");
39944- return -ENODEV;
39945- }
39946
39947 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
39948 if (!zpff)
39949diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39950index fc307e0..2b255e8 100644
39951--- a/drivers/hid/uhid.c
39952+++ b/drivers/hid/uhid.c
39953@@ -47,7 +47,7 @@ struct uhid_device {
39954 struct mutex report_lock;
39955 wait_queue_head_t report_wait;
39956 atomic_t report_done;
39957- atomic_t report_id;
39958+ atomic_unchecked_t report_id;
39959 struct uhid_event report_buf;
39960 };
39961
39962@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39963
39964 spin_lock_irqsave(&uhid->qlock, flags);
39965 ev->type = UHID_FEATURE;
39966- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39967+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39968 ev->u.feature.rnum = rnum;
39969 ev->u.feature.rtype = report_type;
39970
39971@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39972 spin_lock_irqsave(&uhid->qlock, flags);
39973
39974 /* id for old report; drop it silently */
39975- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39976+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39977 goto unlock;
39978 if (atomic_read(&uhid->report_done))
39979 goto unlock;
39980diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39981index 6de6c98..18319e9 100644
39982--- a/drivers/hv/channel.c
39983+++ b/drivers/hv/channel.c
39984@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39985 int ret = 0;
39986 int t;
39987
39988- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39989- atomic_inc(&vmbus_connection.next_gpadl_handle);
39990+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39991+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39992
39993 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39994 if (ret)
39995diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39996index 88f4096..e50452e 100644
39997--- a/drivers/hv/hv.c
39998+++ b/drivers/hv/hv.c
39999@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40000 u64 output_address = (output) ? virt_to_phys(output) : 0;
40001 u32 output_address_hi = output_address >> 32;
40002 u32 output_address_lo = output_address & 0xFFFFFFFF;
40003- void *hypercall_page = hv_context.hypercall_page;
40004+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40005
40006 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40007 "=a"(hv_status_lo) : "d" (control_hi),
40008diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40009index deb5c25..ed2d4fd 100644
40010--- a/drivers/hv/hv_balloon.c
40011+++ b/drivers/hv/hv_balloon.c
40012@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40013
40014 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40015 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40016-static atomic_t trans_id = ATOMIC_INIT(0);
40017+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40018
40019 static int dm_ring_size = (5 * PAGE_SIZE);
40020
40021@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
40022 memset(&resp, 0, sizeof(struct dm_hot_add_response));
40023 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
40024 resp.hdr.size = sizeof(struct dm_hot_add_response);
40025- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40026+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40027
40028 #ifdef CONFIG_MEMORY_HOTPLUG
40029 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
40030@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40031 memset(&status, 0, sizeof(struct dm_status));
40032 status.hdr.type = DM_STATUS_REPORT;
40033 status.hdr.size = sizeof(struct dm_status);
40034- status.hdr.trans_id = atomic_inc_return(&trans_id);
40035+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40036
40037 /*
40038 * The host expects the guest to report free memory.
40039@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40040 * send the status. This can happen if we were interrupted
40041 * after we picked our transaction ID.
40042 */
40043- if (status.hdr.trans_id != atomic_read(&trans_id))
40044+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40045 return;
40046
40047 vmbus_sendpacket(dm->dev->channel, &status,
40048@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
40049 bl_resp = (struct dm_balloon_response *)send_buffer;
40050 memset(send_buffer, 0, PAGE_SIZE);
40051 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
40052- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40053+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40054 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
40055 bl_resp->more_pages = 1;
40056
40057@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40058
40059 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40060 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40061- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40062+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40063 resp.hdr.size = sizeof(struct dm_unballoon_response);
40064
40065 vmbus_sendpacket(dm_device.dev->channel, &resp,
40066@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40067 memset(&version_req, 0, sizeof(struct dm_version_request));
40068 version_req.hdr.type = DM_VERSION_REQUEST;
40069 version_req.hdr.size = sizeof(struct dm_version_request);
40070- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40071+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40072 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40073 version_req.is_last_attempt = 1;
40074
40075@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40076 memset(&version_req, 0, sizeof(struct dm_version_request));
40077 version_req.hdr.type = DM_VERSION_REQUEST;
40078 version_req.hdr.size = sizeof(struct dm_version_request);
40079- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40080+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40081 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40082 version_req.is_last_attempt = 0;
40083
40084@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40085 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40086 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40087 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40088- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40089+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40090
40091 cap_msg.caps.cap_bits.balloon = 1;
40092 cap_msg.caps.cap_bits.hot_add = 1;
40093diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40094index d84918f..7f38f9f 100644
40095--- a/drivers/hv/hyperv_vmbus.h
40096+++ b/drivers/hv/hyperv_vmbus.h
40097@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40098 struct vmbus_connection {
40099 enum vmbus_connect_state conn_state;
40100
40101- atomic_t next_gpadl_handle;
40102+ atomic_unchecked_t next_gpadl_handle;
40103
40104 /*
40105 * Represents channel interrupts. Each bit position represents a
40106diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40107index e8e071f..5b4b245 100644
40108--- a/drivers/hv/vmbus_drv.c
40109+++ b/drivers/hv/vmbus_drv.c
40110@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40111 {
40112 int ret = 0;
40113
40114- static atomic_t device_num = ATOMIC_INIT(0);
40115+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40116
40117 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40118- atomic_inc_return(&device_num));
40119+ atomic_inc_return_unchecked(&device_num));
40120
40121 child_device_obj->device.bus = &hv_bus;
40122 child_device_obj->device.parent = &hv_acpi_dev->dev;
40123diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40124index 6351aba..dc4aaf4 100644
40125--- a/drivers/hwmon/acpi_power_meter.c
40126+++ b/drivers/hwmon/acpi_power_meter.c
40127@@ -117,7 +117,7 @@ struct sensor_template {
40128 struct device_attribute *devattr,
40129 const char *buf, size_t count);
40130 int index;
40131-};
40132+} __do_const;
40133
40134 /* Averaging interval */
40135 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40136@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40137 struct sensor_template *attrs)
40138 {
40139 struct device *dev = &resource->acpi_dev->dev;
40140- struct sensor_device_attribute *sensors =
40141+ sensor_device_attribute_no_const *sensors =
40142 &resource->sensors[resource->num_sensors];
40143 int res = 0;
40144
40145diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40146index 62c2e32..8f2859a 100644
40147--- a/drivers/hwmon/applesmc.c
40148+++ b/drivers/hwmon/applesmc.c
40149@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40150 {
40151 struct applesmc_node_group *grp;
40152 struct applesmc_dev_attr *node;
40153- struct attribute *attr;
40154+ attribute_no_const *attr;
40155 int ret, i;
40156
40157 for (grp = groups; grp->format; grp++) {
40158diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40159index b25c643..a13460d 100644
40160--- a/drivers/hwmon/asus_atk0110.c
40161+++ b/drivers/hwmon/asus_atk0110.c
40162@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40163 struct atk_sensor_data {
40164 struct list_head list;
40165 struct atk_data *data;
40166- struct device_attribute label_attr;
40167- struct device_attribute input_attr;
40168- struct device_attribute limit1_attr;
40169- struct device_attribute limit2_attr;
40170+ device_attribute_no_const label_attr;
40171+ device_attribute_no_const input_attr;
40172+ device_attribute_no_const limit1_attr;
40173+ device_attribute_no_const limit2_attr;
40174 char label_attr_name[ATTR_NAME_SIZE];
40175 char input_attr_name[ATTR_NAME_SIZE];
40176 char limit1_attr_name[ATTR_NAME_SIZE];
40177@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40178 static struct device_attribute atk_name_attr =
40179 __ATTR(name, 0444, atk_name_show, NULL);
40180
40181-static void atk_init_attribute(struct device_attribute *attr, char *name,
40182+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40183 sysfs_show_func show)
40184 {
40185 sysfs_attr_init(&attr->attr);
40186diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40187index 2e5e2dc..5208b31 100644
40188--- a/drivers/hwmon/coretemp.c
40189+++ b/drivers/hwmon/coretemp.c
40190@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40191 return NOTIFY_OK;
40192 }
40193
40194-static struct notifier_block coretemp_cpu_notifier __refdata = {
40195+static struct notifier_block coretemp_cpu_notifier = {
40196 .notifier_call = coretemp_cpu_callback,
40197 };
40198
40199diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40200index 1429f6e..ee03d59 100644
40201--- a/drivers/hwmon/ibmaem.c
40202+++ b/drivers/hwmon/ibmaem.c
40203@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40204 struct aem_rw_sensor_template *rw)
40205 {
40206 struct device *dev = &data->pdev->dev;
40207- struct sensor_device_attribute *sensors = data->sensors;
40208+ sensor_device_attribute_no_const *sensors = data->sensors;
40209 int err;
40210
40211 /* Set up read-only sensors */
40212diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40213index 708081b..fe2d4ab 100644
40214--- a/drivers/hwmon/iio_hwmon.c
40215+++ b/drivers/hwmon/iio_hwmon.c
40216@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40217 {
40218 struct device *dev = &pdev->dev;
40219 struct iio_hwmon_state *st;
40220- struct sensor_device_attribute *a;
40221+ sensor_device_attribute_no_const *a;
40222 int ret, i;
40223 int in_i = 1, temp_i = 1, curr_i = 1;
40224 enum iio_chan_type type;
40225diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40226index 9add6092..ee7ba3f 100644
40227--- a/drivers/hwmon/pmbus/pmbus_core.c
40228+++ b/drivers/hwmon/pmbus/pmbus_core.c
40229@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40230 return 0;
40231 }
40232
40233-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40234+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40235 const char *name,
40236 umode_t mode,
40237 ssize_t (*show)(struct device *dev,
40238@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40239 dev_attr->store = store;
40240 }
40241
40242-static void pmbus_attr_init(struct sensor_device_attribute *a,
40243+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40244 const char *name,
40245 umode_t mode,
40246 ssize_t (*show)(struct device *dev,
40247@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40248 u16 reg, u8 mask)
40249 {
40250 struct pmbus_boolean *boolean;
40251- struct sensor_device_attribute *a;
40252+ sensor_device_attribute_no_const *a;
40253
40254 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40255 if (!boolean)
40256@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40257 bool update, bool readonly)
40258 {
40259 struct pmbus_sensor *sensor;
40260- struct device_attribute *a;
40261+ device_attribute_no_const *a;
40262
40263 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40264 if (!sensor)
40265@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40266 const char *lstring, int index)
40267 {
40268 struct pmbus_label *label;
40269- struct device_attribute *a;
40270+ device_attribute_no_const *a;
40271
40272 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40273 if (!label)
40274diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40275index 2507f90..1645765 100644
40276--- a/drivers/hwmon/sht15.c
40277+++ b/drivers/hwmon/sht15.c
40278@@ -169,7 +169,7 @@ struct sht15_data {
40279 int supply_uv;
40280 bool supply_uv_valid;
40281 struct work_struct update_supply_work;
40282- atomic_t interrupt_handled;
40283+ atomic_unchecked_t interrupt_handled;
40284 };
40285
40286 /**
40287@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40288 ret = gpio_direction_input(data->pdata->gpio_data);
40289 if (ret)
40290 return ret;
40291- atomic_set(&data->interrupt_handled, 0);
40292+ atomic_set_unchecked(&data->interrupt_handled, 0);
40293
40294 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40295 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40296 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40297 /* Only relevant if the interrupt hasn't occurred. */
40298- if (!atomic_read(&data->interrupt_handled))
40299+ if (!atomic_read_unchecked(&data->interrupt_handled))
40300 schedule_work(&data->read_work);
40301 }
40302 ret = wait_event_timeout(data->wait_queue,
40303@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40304
40305 /* First disable the interrupt */
40306 disable_irq_nosync(irq);
40307- atomic_inc(&data->interrupt_handled);
40308+ atomic_inc_unchecked(&data->interrupt_handled);
40309 /* Then schedule a reading work struct */
40310 if (data->state != SHT15_READING_NOTHING)
40311 schedule_work(&data->read_work);
40312@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40313 * If not, then start the interrupt again - care here as could
40314 * have gone low in meantime so verify it hasn't!
40315 */
40316- atomic_set(&data->interrupt_handled, 0);
40317+ atomic_set_unchecked(&data->interrupt_handled, 0);
40318 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40319 /* If still not occurred or another handler was scheduled */
40320 if (gpio_get_value(data->pdata->gpio_data)
40321- || atomic_read(&data->interrupt_handled))
40322+ || atomic_read_unchecked(&data->interrupt_handled))
40323 return;
40324 }
40325
40326diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40327index 38944e9..ae9e5ed 100644
40328--- a/drivers/hwmon/via-cputemp.c
40329+++ b/drivers/hwmon/via-cputemp.c
40330@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40331 return NOTIFY_OK;
40332 }
40333
40334-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40335+static struct notifier_block via_cputemp_cpu_notifier = {
40336 .notifier_call = via_cputemp_cpu_callback,
40337 };
40338
40339diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40340index 07f01ac..d79ad3d 100644
40341--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40342+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40343@@ -43,7 +43,7 @@
40344 extern struct i2c_adapter amd756_smbus;
40345
40346 static struct i2c_adapter *s4882_adapter;
40347-static struct i2c_algorithm *s4882_algo;
40348+static i2c_algorithm_no_const *s4882_algo;
40349
40350 /* Wrapper access functions for multiplexed SMBus */
40351 static DEFINE_MUTEX(amd756_lock);
40352diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40353index 2ca268d..c6acbdf 100644
40354--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40355+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40356@@ -41,7 +41,7 @@
40357 extern struct i2c_adapter *nforce2_smbus;
40358
40359 static struct i2c_adapter *s4985_adapter;
40360-static struct i2c_algorithm *s4985_algo;
40361+static i2c_algorithm_no_const *s4985_algo;
40362
40363 /* Wrapper access functions for multiplexed SMBus */
40364 static DEFINE_MUTEX(nforce2_lock);
40365diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40366index c3ccdea..5b3dc1a 100644
40367--- a/drivers/i2c/i2c-dev.c
40368+++ b/drivers/i2c/i2c-dev.c
40369@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40370 break;
40371 }
40372
40373- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40374+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40375 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40376 if (IS_ERR(rdwr_pa[i].buf)) {
40377 res = PTR_ERR(rdwr_pa[i].buf);
40378diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40379index 0b510ba..4fbb5085 100644
40380--- a/drivers/ide/ide-cd.c
40381+++ b/drivers/ide/ide-cd.c
40382@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40383 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40384 if ((unsigned long)buf & alignment
40385 || blk_rq_bytes(rq) & q->dma_pad_mask
40386- || object_is_on_stack(buf))
40387+ || object_starts_on_stack(buf))
40388 drive->dma = 0;
40389 }
40390 }
40391diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40392index e145931..08bfc59 100644
40393--- a/drivers/iio/industrialio-core.c
40394+++ b/drivers/iio/industrialio-core.c
40395@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40396 }
40397
40398 static
40399-int __iio_device_attr_init(struct device_attribute *dev_attr,
40400+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40401 const char *postfix,
40402 struct iio_chan_spec const *chan,
40403 ssize_t (*readfunc)(struct device *dev,
40404diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40405index 784b97c..c9ceadf 100644
40406--- a/drivers/infiniband/core/cm.c
40407+++ b/drivers/infiniband/core/cm.c
40408@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40409
40410 struct cm_counter_group {
40411 struct kobject obj;
40412- atomic_long_t counter[CM_ATTR_COUNT];
40413+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40414 };
40415
40416 struct cm_counter_attribute {
40417@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40418 struct ib_mad_send_buf *msg = NULL;
40419 int ret;
40420
40421- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40422+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40423 counter[CM_REQ_COUNTER]);
40424
40425 /* Quick state check to discard duplicate REQs. */
40426@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40427 if (!cm_id_priv)
40428 return;
40429
40430- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40431+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40432 counter[CM_REP_COUNTER]);
40433 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40434 if (ret)
40435@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40436 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40437 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40438 spin_unlock_irq(&cm_id_priv->lock);
40439- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40440+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40441 counter[CM_RTU_COUNTER]);
40442 goto out;
40443 }
40444@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40445 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40446 dreq_msg->local_comm_id);
40447 if (!cm_id_priv) {
40448- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40449+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40450 counter[CM_DREQ_COUNTER]);
40451 cm_issue_drep(work->port, work->mad_recv_wc);
40452 return -EINVAL;
40453@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40454 case IB_CM_MRA_REP_RCVD:
40455 break;
40456 case IB_CM_TIMEWAIT:
40457- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40458+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40459 counter[CM_DREQ_COUNTER]);
40460 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40461 goto unlock;
40462@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40463 cm_free_msg(msg);
40464 goto deref;
40465 case IB_CM_DREQ_RCVD:
40466- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40467+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40468 counter[CM_DREQ_COUNTER]);
40469 goto unlock;
40470 default:
40471@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40472 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40473 cm_id_priv->msg, timeout)) {
40474 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40475- atomic_long_inc(&work->port->
40476+ atomic_long_inc_unchecked(&work->port->
40477 counter_group[CM_RECV_DUPLICATES].
40478 counter[CM_MRA_COUNTER]);
40479 goto out;
40480@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40481 break;
40482 case IB_CM_MRA_REQ_RCVD:
40483 case IB_CM_MRA_REP_RCVD:
40484- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40485+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40486 counter[CM_MRA_COUNTER]);
40487 /* fall through */
40488 default:
40489@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40490 case IB_CM_LAP_IDLE:
40491 break;
40492 case IB_CM_MRA_LAP_SENT:
40493- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40494+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40495 counter[CM_LAP_COUNTER]);
40496 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40497 goto unlock;
40498@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40499 cm_free_msg(msg);
40500 goto deref;
40501 case IB_CM_LAP_RCVD:
40502- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40503+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40504 counter[CM_LAP_COUNTER]);
40505 goto unlock;
40506 default:
40507@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40508 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40509 if (cur_cm_id_priv) {
40510 spin_unlock_irq(&cm.lock);
40511- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40512+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40513 counter[CM_SIDR_REQ_COUNTER]);
40514 goto out; /* Duplicate message. */
40515 }
40516@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40517 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40518 msg->retries = 1;
40519
40520- atomic_long_add(1 + msg->retries,
40521+ atomic_long_add_unchecked(1 + msg->retries,
40522 &port->counter_group[CM_XMIT].counter[attr_index]);
40523 if (msg->retries)
40524- atomic_long_add(msg->retries,
40525+ atomic_long_add_unchecked(msg->retries,
40526 &port->counter_group[CM_XMIT_RETRIES].
40527 counter[attr_index]);
40528
40529@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40530 }
40531
40532 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40533- atomic_long_inc(&port->counter_group[CM_RECV].
40534+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40535 counter[attr_id - CM_ATTR_ID_OFFSET]);
40536
40537 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40538@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40539 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40540
40541 return sprintf(buf, "%ld\n",
40542- atomic_long_read(&group->counter[cm_attr->index]));
40543+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40544 }
40545
40546 static const struct sysfs_ops cm_counter_ops = {
40547diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40548index 9f5ad7c..588cd84 100644
40549--- a/drivers/infiniband/core/fmr_pool.c
40550+++ b/drivers/infiniband/core/fmr_pool.c
40551@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40552
40553 struct task_struct *thread;
40554
40555- atomic_t req_ser;
40556- atomic_t flush_ser;
40557+ atomic_unchecked_t req_ser;
40558+ atomic_unchecked_t flush_ser;
40559
40560 wait_queue_head_t force_wait;
40561 };
40562@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40563 struct ib_fmr_pool *pool = pool_ptr;
40564
40565 do {
40566- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40567+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40568 ib_fmr_batch_release(pool);
40569
40570- atomic_inc(&pool->flush_ser);
40571+ atomic_inc_unchecked(&pool->flush_ser);
40572 wake_up_interruptible(&pool->force_wait);
40573
40574 if (pool->flush_function)
40575@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40576 }
40577
40578 set_current_state(TASK_INTERRUPTIBLE);
40579- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40580+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40581 !kthread_should_stop())
40582 schedule();
40583 __set_current_state(TASK_RUNNING);
40584@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40585 pool->dirty_watermark = params->dirty_watermark;
40586 pool->dirty_len = 0;
40587 spin_lock_init(&pool->pool_lock);
40588- atomic_set(&pool->req_ser, 0);
40589- atomic_set(&pool->flush_ser, 0);
40590+ atomic_set_unchecked(&pool->req_ser, 0);
40591+ atomic_set_unchecked(&pool->flush_ser, 0);
40592 init_waitqueue_head(&pool->force_wait);
40593
40594 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40595@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40596 }
40597 spin_unlock_irq(&pool->pool_lock);
40598
40599- serial = atomic_inc_return(&pool->req_ser);
40600+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40601 wake_up_process(pool->thread);
40602
40603 if (wait_event_interruptible(pool->force_wait,
40604- atomic_read(&pool->flush_ser) - serial >= 0))
40605+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40606 return -EINTR;
40607
40608 return 0;
40609@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40610 } else {
40611 list_add_tail(&fmr->list, &pool->dirty_list);
40612 if (++pool->dirty_len >= pool->dirty_watermark) {
40613- atomic_inc(&pool->req_ser);
40614+ atomic_inc_unchecked(&pool->req_ser);
40615 wake_up_process(pool->thread);
40616 }
40617 }
40618diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40619index 4cb8eb2..146bf60 100644
40620--- a/drivers/infiniband/hw/cxgb4/mem.c
40621+++ b/drivers/infiniband/hw/cxgb4/mem.c
40622@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40623 int err;
40624 struct fw_ri_tpte tpt;
40625 u32 stag_idx;
40626- static atomic_t key;
40627+ static atomic_unchecked_t key;
40628
40629 if (c4iw_fatal_error(rdev))
40630 return -EIO;
40631@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40632 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40633 rdev->stats.stag.max = rdev->stats.stag.cur;
40634 mutex_unlock(&rdev->stats.lock);
40635- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40636+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40637 }
40638 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40639 __func__, stag_state, type, pdid, stag_idx);
40640diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40641index 79b3dbc..96e5fcc 100644
40642--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40643+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40644@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40645 struct ib_atomic_eth *ateth;
40646 struct ipath_ack_entry *e;
40647 u64 vaddr;
40648- atomic64_t *maddr;
40649+ atomic64_unchecked_t *maddr;
40650 u64 sdata;
40651 u32 rkey;
40652 u8 next;
40653@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40654 IB_ACCESS_REMOTE_ATOMIC)))
40655 goto nack_acc_unlck;
40656 /* Perform atomic OP and save result. */
40657- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40658+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40659 sdata = be64_to_cpu(ateth->swap_data);
40660 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40661 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40662- (u64) atomic64_add_return(sdata, maddr) - sdata :
40663+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40664 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40665 be64_to_cpu(ateth->compare_data),
40666 sdata);
40667diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40668index 1f95bba..9530f87 100644
40669--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40670+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40671@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40672 unsigned long flags;
40673 struct ib_wc wc;
40674 u64 sdata;
40675- atomic64_t *maddr;
40676+ atomic64_unchecked_t *maddr;
40677 enum ib_wc_status send_status;
40678
40679 /*
40680@@ -382,11 +382,11 @@ again:
40681 IB_ACCESS_REMOTE_ATOMIC)))
40682 goto acc_err;
40683 /* Perform atomic OP and save result. */
40684- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40685+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40686 sdata = wqe->wr.wr.atomic.compare_add;
40687 *(u64 *) sqp->s_sge.sge.vaddr =
40688 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40689- (u64) atomic64_add_return(sdata, maddr) - sdata :
40690+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40691 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40692 sdata, wqe->wr.wr.atomic.swap);
40693 goto send_comp;
40694diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40695index f2a3f48..673ec79 100644
40696--- a/drivers/infiniband/hw/mlx4/mad.c
40697+++ b/drivers/infiniband/hw/mlx4/mad.c
40698@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40699
40700 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40701 {
40702- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40703+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40704 cpu_to_be64(0xff00000000000000LL);
40705 }
40706
40707diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40708index 25b2cdf..099ff97 100644
40709--- a/drivers/infiniband/hw/mlx4/mcg.c
40710+++ b/drivers/infiniband/hw/mlx4/mcg.c
40711@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40712 {
40713 char name[20];
40714
40715- atomic_set(&ctx->tid, 0);
40716+ atomic_set_unchecked(&ctx->tid, 0);
40717 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40718 ctx->mcg_wq = create_singlethread_workqueue(name);
40719 if (!ctx->mcg_wq)
40720diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40721index f61ec26..ebf72cf 100644
40722--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40723+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40724@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40725 struct list_head mcg_mgid0_list;
40726 struct workqueue_struct *mcg_wq;
40727 struct mlx4_ib_demux_pv_ctx **tun;
40728- atomic_t tid;
40729+ atomic_unchecked_t tid;
40730 int flushing; /* flushing the work queue */
40731 };
40732
40733diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40734index 9d3e5c1..d9afe4a 100644
40735--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40736+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40737@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40738 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40739 }
40740
40741-int mthca_QUERY_FW(struct mthca_dev *dev)
40742+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40743 {
40744 struct mthca_mailbox *mailbox;
40745 u32 *outbox;
40746diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40747index ed9a989..e0c5871 100644
40748--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40749+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40750@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40751 return key;
40752 }
40753
40754-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40755+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40756 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40757 {
40758 struct mthca_mailbox *mailbox;
40759diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40760index 4291410..d2ab1fb 100644
40761--- a/drivers/infiniband/hw/nes/nes.c
40762+++ b/drivers/infiniband/hw/nes/nes.c
40763@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40764 LIST_HEAD(nes_adapter_list);
40765 static LIST_HEAD(nes_dev_list);
40766
40767-atomic_t qps_destroyed;
40768+atomic_unchecked_t qps_destroyed;
40769
40770 static unsigned int ee_flsh_adapter;
40771 static unsigned int sysfs_nonidx_addr;
40772@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40773 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40774 struct nes_adapter *nesadapter = nesdev->nesadapter;
40775
40776- atomic_inc(&qps_destroyed);
40777+ atomic_inc_unchecked(&qps_destroyed);
40778
40779 /* Free the control structures */
40780
40781diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40782index 33cc589..3bd6538 100644
40783--- a/drivers/infiniband/hw/nes/nes.h
40784+++ b/drivers/infiniband/hw/nes/nes.h
40785@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40786 extern unsigned int wqm_quanta;
40787 extern struct list_head nes_adapter_list;
40788
40789-extern atomic_t cm_connects;
40790-extern atomic_t cm_accepts;
40791-extern atomic_t cm_disconnects;
40792-extern atomic_t cm_closes;
40793-extern atomic_t cm_connecteds;
40794-extern atomic_t cm_connect_reqs;
40795-extern atomic_t cm_rejects;
40796-extern atomic_t mod_qp_timouts;
40797-extern atomic_t qps_created;
40798-extern atomic_t qps_destroyed;
40799-extern atomic_t sw_qps_destroyed;
40800+extern atomic_unchecked_t cm_connects;
40801+extern atomic_unchecked_t cm_accepts;
40802+extern atomic_unchecked_t cm_disconnects;
40803+extern atomic_unchecked_t cm_closes;
40804+extern atomic_unchecked_t cm_connecteds;
40805+extern atomic_unchecked_t cm_connect_reqs;
40806+extern atomic_unchecked_t cm_rejects;
40807+extern atomic_unchecked_t mod_qp_timouts;
40808+extern atomic_unchecked_t qps_created;
40809+extern atomic_unchecked_t qps_destroyed;
40810+extern atomic_unchecked_t sw_qps_destroyed;
40811 extern u32 mh_detected;
40812 extern u32 mh_pauses_sent;
40813 extern u32 cm_packets_sent;
40814@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40815 extern u32 cm_packets_received;
40816 extern u32 cm_packets_dropped;
40817 extern u32 cm_packets_retrans;
40818-extern atomic_t cm_listens_created;
40819-extern atomic_t cm_listens_destroyed;
40820+extern atomic_unchecked_t cm_listens_created;
40821+extern atomic_unchecked_t cm_listens_destroyed;
40822 extern u32 cm_backlog_drops;
40823-extern atomic_t cm_loopbacks;
40824-extern atomic_t cm_nodes_created;
40825-extern atomic_t cm_nodes_destroyed;
40826-extern atomic_t cm_accel_dropped_pkts;
40827-extern atomic_t cm_resets_recvd;
40828-extern atomic_t pau_qps_created;
40829-extern atomic_t pau_qps_destroyed;
40830+extern atomic_unchecked_t cm_loopbacks;
40831+extern atomic_unchecked_t cm_nodes_created;
40832+extern atomic_unchecked_t cm_nodes_destroyed;
40833+extern atomic_unchecked_t cm_accel_dropped_pkts;
40834+extern atomic_unchecked_t cm_resets_recvd;
40835+extern atomic_unchecked_t pau_qps_created;
40836+extern atomic_unchecked_t pau_qps_destroyed;
40837
40838 extern u32 int_mod_timer_init;
40839 extern u32 int_mod_cq_depth_256;
40840diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40841index 24b9f1a..00fd004 100644
40842--- a/drivers/infiniband/hw/nes/nes_cm.c
40843+++ b/drivers/infiniband/hw/nes/nes_cm.c
40844@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40845 u32 cm_packets_retrans;
40846 u32 cm_packets_created;
40847 u32 cm_packets_received;
40848-atomic_t cm_listens_created;
40849-atomic_t cm_listens_destroyed;
40850+atomic_unchecked_t cm_listens_created;
40851+atomic_unchecked_t cm_listens_destroyed;
40852 u32 cm_backlog_drops;
40853-atomic_t cm_loopbacks;
40854-atomic_t cm_nodes_created;
40855-atomic_t cm_nodes_destroyed;
40856-atomic_t cm_accel_dropped_pkts;
40857-atomic_t cm_resets_recvd;
40858+atomic_unchecked_t cm_loopbacks;
40859+atomic_unchecked_t cm_nodes_created;
40860+atomic_unchecked_t cm_nodes_destroyed;
40861+atomic_unchecked_t cm_accel_dropped_pkts;
40862+atomic_unchecked_t cm_resets_recvd;
40863
40864 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40865 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40866@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40867
40868 static struct nes_cm_core *g_cm_core;
40869
40870-atomic_t cm_connects;
40871-atomic_t cm_accepts;
40872-atomic_t cm_disconnects;
40873-atomic_t cm_closes;
40874-atomic_t cm_connecteds;
40875-atomic_t cm_connect_reqs;
40876-atomic_t cm_rejects;
40877+atomic_unchecked_t cm_connects;
40878+atomic_unchecked_t cm_accepts;
40879+atomic_unchecked_t cm_disconnects;
40880+atomic_unchecked_t cm_closes;
40881+atomic_unchecked_t cm_connecteds;
40882+atomic_unchecked_t cm_connect_reqs;
40883+atomic_unchecked_t cm_rejects;
40884
40885 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40886 {
40887@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40888 kfree(listener);
40889 listener = NULL;
40890 ret = 0;
40891- atomic_inc(&cm_listens_destroyed);
40892+ atomic_inc_unchecked(&cm_listens_destroyed);
40893 } else {
40894 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40895 }
40896@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40897 cm_node->rem_mac);
40898
40899 add_hte_node(cm_core, cm_node);
40900- atomic_inc(&cm_nodes_created);
40901+ atomic_inc_unchecked(&cm_nodes_created);
40902
40903 return cm_node;
40904 }
40905@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40906 }
40907
40908 atomic_dec(&cm_core->node_cnt);
40909- atomic_inc(&cm_nodes_destroyed);
40910+ atomic_inc_unchecked(&cm_nodes_destroyed);
40911 nesqp = cm_node->nesqp;
40912 if (nesqp) {
40913 nesqp->cm_node = NULL;
40914@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40915
40916 static void drop_packet(struct sk_buff *skb)
40917 {
40918- atomic_inc(&cm_accel_dropped_pkts);
40919+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40920 dev_kfree_skb_any(skb);
40921 }
40922
40923@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40924 {
40925
40926 int reset = 0; /* whether to send reset in case of err.. */
40927- atomic_inc(&cm_resets_recvd);
40928+ atomic_inc_unchecked(&cm_resets_recvd);
40929 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40930 " refcnt=%d\n", cm_node, cm_node->state,
40931 atomic_read(&cm_node->ref_count));
40932@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40933 rem_ref_cm_node(cm_node->cm_core, cm_node);
40934 return NULL;
40935 }
40936- atomic_inc(&cm_loopbacks);
40937+ atomic_inc_unchecked(&cm_loopbacks);
40938 loopbackremotenode->loopbackpartner = cm_node;
40939 loopbackremotenode->tcp_cntxt.rcv_wscale =
40940 NES_CM_DEFAULT_RCV_WND_SCALE;
40941@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40942 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40943 else {
40944 rem_ref_cm_node(cm_core, cm_node);
40945- atomic_inc(&cm_accel_dropped_pkts);
40946+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40947 dev_kfree_skb_any(skb);
40948 }
40949 break;
40950@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40951
40952 if ((cm_id) && (cm_id->event_handler)) {
40953 if (issue_disconn) {
40954- atomic_inc(&cm_disconnects);
40955+ atomic_inc_unchecked(&cm_disconnects);
40956 cm_event.event = IW_CM_EVENT_DISCONNECT;
40957 cm_event.status = disconn_status;
40958 cm_event.local_addr = cm_id->local_addr;
40959@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40960 }
40961
40962 if (issue_close) {
40963- atomic_inc(&cm_closes);
40964+ atomic_inc_unchecked(&cm_closes);
40965 nes_disconnect(nesqp, 1);
40966
40967 cm_id->provider_data = nesqp;
40968@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40969
40970 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40971 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40972- atomic_inc(&cm_accepts);
40973+ atomic_inc_unchecked(&cm_accepts);
40974
40975 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40976 netdev_refcnt_read(nesvnic->netdev));
40977@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40978 struct nes_cm_core *cm_core;
40979 u8 *start_buff;
40980
40981- atomic_inc(&cm_rejects);
40982+ atomic_inc_unchecked(&cm_rejects);
40983 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40984 loopback = cm_node->loopbackpartner;
40985 cm_core = cm_node->cm_core;
40986@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40987 ntohl(cm_id->local_addr.sin_addr.s_addr),
40988 ntohs(cm_id->local_addr.sin_port));
40989
40990- atomic_inc(&cm_connects);
40991+ atomic_inc_unchecked(&cm_connects);
40992 nesqp->active_conn = 1;
40993
40994 /* cache the cm_id in the qp */
40995@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40996 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40997 return err;
40998 }
40999- atomic_inc(&cm_listens_created);
41000+ atomic_inc_unchecked(&cm_listens_created);
41001 }
41002
41003 cm_id->add_ref(cm_id);
41004@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41005
41006 if (nesqp->destroyed)
41007 return;
41008- atomic_inc(&cm_connecteds);
41009+ atomic_inc_unchecked(&cm_connecteds);
41010 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41011 " local port 0x%04X. jiffies = %lu.\n",
41012 nesqp->hwqp.qp_id,
41013@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41014
41015 cm_id->add_ref(cm_id);
41016 ret = cm_id->event_handler(cm_id, &cm_event);
41017- atomic_inc(&cm_closes);
41018+ atomic_inc_unchecked(&cm_closes);
41019 cm_event.event = IW_CM_EVENT_CLOSE;
41020 cm_event.status = 0;
41021 cm_event.provider_data = cm_id->provider_data;
41022@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41023 return;
41024 cm_id = cm_node->cm_id;
41025
41026- atomic_inc(&cm_connect_reqs);
41027+ atomic_inc_unchecked(&cm_connect_reqs);
41028 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41029 cm_node, cm_id, jiffies);
41030
41031@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41032 return;
41033 cm_id = cm_node->cm_id;
41034
41035- atomic_inc(&cm_connect_reqs);
41036+ atomic_inc_unchecked(&cm_connect_reqs);
41037 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41038 cm_node, cm_id, jiffies);
41039
41040diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41041index 4166452..fc952c3 100644
41042--- a/drivers/infiniband/hw/nes/nes_mgt.c
41043+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41044@@ -40,8 +40,8 @@
41045 #include "nes.h"
41046 #include "nes_mgt.h"
41047
41048-atomic_t pau_qps_created;
41049-atomic_t pau_qps_destroyed;
41050+atomic_unchecked_t pau_qps_created;
41051+atomic_unchecked_t pau_qps_destroyed;
41052
41053 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41054 {
41055@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41056 {
41057 struct sk_buff *skb;
41058 unsigned long flags;
41059- atomic_inc(&pau_qps_destroyed);
41060+ atomic_inc_unchecked(&pau_qps_destroyed);
41061
41062 /* Free packets that have not yet been forwarded */
41063 /* Lock is acquired by skb_dequeue when removing the skb */
41064@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41065 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41066 skb_queue_head_init(&nesqp->pau_list);
41067 spin_lock_init(&nesqp->pau_lock);
41068- atomic_inc(&pau_qps_created);
41069+ atomic_inc_unchecked(&pau_qps_created);
41070 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41071 }
41072
41073diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41074index 49eb511..a774366 100644
41075--- a/drivers/infiniband/hw/nes/nes_nic.c
41076+++ b/drivers/infiniband/hw/nes/nes_nic.c
41077@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41078 target_stat_values[++index] = mh_detected;
41079 target_stat_values[++index] = mh_pauses_sent;
41080 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41081- target_stat_values[++index] = atomic_read(&cm_connects);
41082- target_stat_values[++index] = atomic_read(&cm_accepts);
41083- target_stat_values[++index] = atomic_read(&cm_disconnects);
41084- target_stat_values[++index] = atomic_read(&cm_connecteds);
41085- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41086- target_stat_values[++index] = atomic_read(&cm_rejects);
41087- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41088- target_stat_values[++index] = atomic_read(&qps_created);
41089- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41090- target_stat_values[++index] = atomic_read(&qps_destroyed);
41091- target_stat_values[++index] = atomic_read(&cm_closes);
41092+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41093+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41094+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41095+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41096+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41097+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41098+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41099+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41100+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41101+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41102+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41103 target_stat_values[++index] = cm_packets_sent;
41104 target_stat_values[++index] = cm_packets_bounced;
41105 target_stat_values[++index] = cm_packets_created;
41106 target_stat_values[++index] = cm_packets_received;
41107 target_stat_values[++index] = cm_packets_dropped;
41108 target_stat_values[++index] = cm_packets_retrans;
41109- target_stat_values[++index] = atomic_read(&cm_listens_created);
41110- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41111+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41112+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41113 target_stat_values[++index] = cm_backlog_drops;
41114- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41115- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41116- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41117- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41118- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41119+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41120+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41121+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41122+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41123+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41124 target_stat_values[++index] = nesadapter->free_4kpbl;
41125 target_stat_values[++index] = nesadapter->free_256pbl;
41126 target_stat_values[++index] = int_mod_timer_init;
41127 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41128 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41129 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41130- target_stat_values[++index] = atomic_read(&pau_qps_created);
41131- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41132+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41133+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41134 }
41135
41136 /**
41137diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41138index 5b53ca5..443da3c 100644
41139--- a/drivers/infiniband/hw/nes/nes_verbs.c
41140+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41141@@ -46,9 +46,9 @@
41142
41143 #include <rdma/ib_umem.h>
41144
41145-atomic_t mod_qp_timouts;
41146-atomic_t qps_created;
41147-atomic_t sw_qps_destroyed;
41148+atomic_unchecked_t mod_qp_timouts;
41149+atomic_unchecked_t qps_created;
41150+atomic_unchecked_t sw_qps_destroyed;
41151
41152 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41153
41154@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41155 if (init_attr->create_flags)
41156 return ERR_PTR(-EINVAL);
41157
41158- atomic_inc(&qps_created);
41159+ atomic_inc_unchecked(&qps_created);
41160 switch (init_attr->qp_type) {
41161 case IB_QPT_RC:
41162 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41163@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41164 struct iw_cm_event cm_event;
41165 int ret = 0;
41166
41167- atomic_inc(&sw_qps_destroyed);
41168+ atomic_inc_unchecked(&sw_qps_destroyed);
41169 nesqp->destroyed = 1;
41170
41171 /* Blow away the connection if it exists. */
41172diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41173index 4a9af79..b993f75 100644
41174--- a/drivers/infiniband/hw/qib/qib.h
41175+++ b/drivers/infiniband/hw/qib/qib.h
41176@@ -52,6 +52,7 @@
41177 #include <linux/kref.h>
41178 #include <linux/sched.h>
41179 #include <linux/kthread.h>
41180+#include <linux/slab.h>
41181
41182 #include "qib_common.h"
41183 #include "qib_verbs.h"
41184diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41185index da739d9..da1c7f4 100644
41186--- a/drivers/input/gameport/gameport.c
41187+++ b/drivers/input/gameport/gameport.c
41188@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41189 */
41190 static void gameport_init_port(struct gameport *gameport)
41191 {
41192- static atomic_t gameport_no = ATOMIC_INIT(0);
41193+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41194
41195 __module_get(THIS_MODULE);
41196
41197 mutex_init(&gameport->drv_mutex);
41198 device_initialize(&gameport->dev);
41199 dev_set_name(&gameport->dev, "gameport%lu",
41200- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41201+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41202 gameport->dev.bus = &gameport_bus;
41203 gameport->dev.release = gameport_release_port;
41204 if (gameport->parent)
41205diff --git a/drivers/input/input.c b/drivers/input/input.c
41206index c044699..174d71a 100644
41207--- a/drivers/input/input.c
41208+++ b/drivers/input/input.c
41209@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41210 */
41211 int input_register_device(struct input_dev *dev)
41212 {
41213- static atomic_t input_no = ATOMIC_INIT(0);
41214+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41215 struct input_devres *devres = NULL;
41216 struct input_handler *handler;
41217 unsigned int packet_size;
41218@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41219 dev->setkeycode = input_default_setkeycode;
41220
41221 dev_set_name(&dev->dev, "input%ld",
41222- (unsigned long) atomic_inc_return(&input_no) - 1);
41223+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41224
41225 error = device_add(&dev->dev);
41226 if (error)
41227diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41228index 04c69af..5f92d00 100644
41229--- a/drivers/input/joystick/sidewinder.c
41230+++ b/drivers/input/joystick/sidewinder.c
41231@@ -30,6 +30,7 @@
41232 #include <linux/kernel.h>
41233 #include <linux/module.h>
41234 #include <linux/slab.h>
41235+#include <linux/sched.h>
41236 #include <linux/init.h>
41237 #include <linux/input.h>
41238 #include <linux/gameport.h>
41239diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41240index 75e3b10..fb390fd 100644
41241--- a/drivers/input/joystick/xpad.c
41242+++ b/drivers/input/joystick/xpad.c
41243@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41244
41245 static int xpad_led_probe(struct usb_xpad *xpad)
41246 {
41247- static atomic_t led_seq = ATOMIC_INIT(0);
41248+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41249 long led_no;
41250 struct xpad_led *led;
41251 struct led_classdev *led_cdev;
41252@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41253 if (!led)
41254 return -ENOMEM;
41255
41256- led_no = (long)atomic_inc_return(&led_seq) - 1;
41257+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41258
41259 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41260 led->xpad = xpad;
41261diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41262index e204f26..8459f15 100644
41263--- a/drivers/input/misc/ims-pcu.c
41264+++ b/drivers/input/misc/ims-pcu.c
41265@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41266
41267 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41268 {
41269- static atomic_t device_no = ATOMIC_INIT(0);
41270+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41271
41272 const struct ims_pcu_device_info *info;
41273 u8 device_id;
41274@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41275 }
41276
41277 /* Device appears to be operable, complete initialization */
41278- pcu->device_no = atomic_inc_return(&device_no) - 1;
41279+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41280
41281 error = ims_pcu_setup_backlight(pcu);
41282 if (error)
41283diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41284index 2f0b39d..7370f13 100644
41285--- a/drivers/input/mouse/psmouse.h
41286+++ b/drivers/input/mouse/psmouse.h
41287@@ -116,7 +116,7 @@ struct psmouse_attribute {
41288 ssize_t (*set)(struct psmouse *psmouse, void *data,
41289 const char *buf, size_t count);
41290 bool protect;
41291-};
41292+} __do_const;
41293 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41294
41295 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41296diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41297index 4c842c3..590b0bf 100644
41298--- a/drivers/input/mousedev.c
41299+++ b/drivers/input/mousedev.c
41300@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41301
41302 spin_unlock_irq(&client->packet_lock);
41303
41304- if (copy_to_user(buffer, data, count))
41305+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41306 return -EFAULT;
41307
41308 return count;
41309diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41310index 25fc597..558bf3b3 100644
41311--- a/drivers/input/serio/serio.c
41312+++ b/drivers/input/serio/serio.c
41313@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41314 */
41315 static void serio_init_port(struct serio *serio)
41316 {
41317- static atomic_t serio_no = ATOMIC_INIT(0);
41318+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41319
41320 __module_get(THIS_MODULE);
41321
41322@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41323 mutex_init(&serio->drv_mutex);
41324 device_initialize(&serio->dev);
41325 dev_set_name(&serio->dev, "serio%ld",
41326- (long)atomic_inc_return(&serio_no) - 1);
41327+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41328 serio->dev.bus = &serio_bus;
41329 serio->dev.release = serio_release_port;
41330 serio->dev.groups = serio_device_attr_groups;
41331diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41332index 59df2e7..8f1cafb 100644
41333--- a/drivers/input/serio/serio_raw.c
41334+++ b/drivers/input/serio/serio_raw.c
41335@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41336
41337 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41338 {
41339- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41340+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41341 struct serio_raw *serio_raw;
41342 int err;
41343
41344@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41345 }
41346
41347 snprintf(serio_raw->name, sizeof(serio_raw->name),
41348- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41349+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41350 kref_init(&serio_raw->kref);
41351 INIT_LIST_HEAD(&serio_raw->client_list);
41352 init_waitqueue_head(&serio_raw->wait);
41353diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41354index fbe9ca7..dbee61d 100644
41355--- a/drivers/iommu/iommu.c
41356+++ b/drivers/iommu/iommu.c
41357@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41358 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41359 {
41360 bus_register_notifier(bus, &iommu_bus_nb);
41361- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41362+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41363 }
41364
41365 /**
41366diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41367index 39f81ae..2660096 100644
41368--- a/drivers/iommu/irq_remapping.c
41369+++ b/drivers/iommu/irq_remapping.c
41370@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41371 void panic_if_irq_remap(const char *msg)
41372 {
41373 if (irq_remapping_enabled)
41374- panic(msg);
41375+ panic("%s", msg);
41376 }
41377
41378 static void ir_ack_apic_edge(struct irq_data *data)
41379@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41380
41381 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41382 {
41383- chip->irq_print_chip = ir_print_prefix;
41384- chip->irq_ack = ir_ack_apic_edge;
41385- chip->irq_eoi = ir_ack_apic_level;
41386- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41387+ pax_open_kernel();
41388+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41389+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41390+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41391+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41392+ pax_close_kernel();
41393 }
41394
41395 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41396diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41397index ee7c503..5d4ce08 100644
41398--- a/drivers/irqchip/irq-gic.c
41399+++ b/drivers/irqchip/irq-gic.c
41400@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41401 * Supported arch specific GIC irq extension.
41402 * Default make them NULL.
41403 */
41404-struct irq_chip gic_arch_extn = {
41405+irq_chip_no_const gic_arch_extn = {
41406 .irq_eoi = NULL,
41407 .irq_mask = NULL,
41408 .irq_unmask = NULL,
41409@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41410 chained_irq_exit(chip, desc);
41411 }
41412
41413-static struct irq_chip gic_chip = {
41414+static irq_chip_no_const gic_chip __read_only = {
41415 .name = "GIC",
41416 .irq_mask = gic_mask_irq,
41417 .irq_unmask = gic_unmask_irq,
41418diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41419index ac6f72b..81150f2 100644
41420--- a/drivers/isdn/capi/capi.c
41421+++ b/drivers/isdn/capi/capi.c
41422@@ -81,8 +81,8 @@ struct capiminor {
41423
41424 struct capi20_appl *ap;
41425 u32 ncci;
41426- atomic_t datahandle;
41427- atomic_t msgid;
41428+ atomic_unchecked_t datahandle;
41429+ atomic_unchecked_t msgid;
41430
41431 struct tty_port port;
41432 int ttyinstop;
41433@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41434 capimsg_setu16(s, 2, mp->ap->applid);
41435 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41436 capimsg_setu8 (s, 5, CAPI_RESP);
41437- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41438+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41439 capimsg_setu32(s, 8, mp->ncci);
41440 capimsg_setu16(s, 12, datahandle);
41441 }
41442@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41443 mp->outbytes -= len;
41444 spin_unlock_bh(&mp->outlock);
41445
41446- datahandle = atomic_inc_return(&mp->datahandle);
41447+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41448 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41449 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41450 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41451 capimsg_setu16(skb->data, 2, mp->ap->applid);
41452 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41453 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41454- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41455+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41456 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41457 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41458 capimsg_setu16(skb->data, 16, len); /* Data length */
41459diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41460index 600c79b..3752bab 100644
41461--- a/drivers/isdn/gigaset/interface.c
41462+++ b/drivers/isdn/gigaset/interface.c
41463@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41464 }
41465 tty->driver_data = cs;
41466
41467- ++cs->port.count;
41468+ atomic_inc(&cs->port.count);
41469
41470- if (cs->port.count == 1) {
41471+ if (atomic_read(&cs->port.count) == 1) {
41472 tty_port_tty_set(&cs->port, tty);
41473 cs->port.low_latency = 1;
41474 }
41475@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41476
41477 if (!cs->connected)
41478 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41479- else if (!cs->port.count)
41480+ else if (!atomic_read(&cs->port.count))
41481 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41482- else if (!--cs->port.count)
41483+ else if (!atomic_dec_return(&cs->port.count))
41484 tty_port_tty_set(&cs->port, NULL);
41485
41486 mutex_unlock(&cs->mutex);
41487diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41488index d0a41cb..f0cdb8c 100644
41489--- a/drivers/isdn/gigaset/usb-gigaset.c
41490+++ b/drivers/isdn/gigaset/usb-gigaset.c
41491@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41492 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41493 memcpy(cs->hw.usb->bchars, buf, 6);
41494 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41495- 0, 0, &buf, 6, 2000);
41496+ 0, 0, buf, 6, 2000);
41497 }
41498
41499 static void gigaset_freebcshw(struct bc_state *bcs)
41500diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41501index 4d9b195..455075c 100644
41502--- a/drivers/isdn/hardware/avm/b1.c
41503+++ b/drivers/isdn/hardware/avm/b1.c
41504@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41505 }
41506 if (left) {
41507 if (t4file->user) {
41508- if (copy_from_user(buf, dp, left))
41509+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41510 return -EFAULT;
41511 } else {
41512 memcpy(buf, dp, left);
41513@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41514 }
41515 if (left) {
41516 if (config->user) {
41517- if (copy_from_user(buf, dp, left))
41518+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41519 return -EFAULT;
41520 } else {
41521 memcpy(buf, dp, left);
41522diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41523index 1063bab..36817e0 100644
41524--- a/drivers/isdn/hisax/amd7930_fn.c
41525+++ b/drivers/isdn/hisax/amd7930_fn.c
41526@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41527
41528 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41529 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41530- debugl1(cs, cs->dlog);
41531+ debugl1(cs, "%s", cs->dlog);
41532 }
41533 /* moves received data in sk-buffer */
41534 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41535@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41536
41537 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41538 QuickHex(t, deb_ptr, count);
41539- debugl1(cs, cs->dlog);
41540+ debugl1(cs, "%s", cs->dlog);
41541 }
41542 /* AMD interrupts on */
41543 AmdIrqOn(cs);
41544diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41545index ee9b9a0..d1427bd 100644
41546--- a/drivers/isdn/hisax/avm_pci.c
41547+++ b/drivers/isdn/hisax/avm_pci.c
41548@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41549 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41550 bcs->channel ? 'B' : 'A', count);
41551 QuickHex(t, p, count);
41552- debugl1(cs, bcs->blog);
41553+ debugl1(cs, "%s", bcs->blog);
41554 }
41555 }
41556
41557@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41558 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41559 bcs->channel ? 'B' : 'A', count);
41560 QuickHex(t, p, count);
41561- debugl1(cs, bcs->blog);
41562+ debugl1(cs, "%s", bcs->blog);
41563 }
41564 }
41565
41566diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41567index bf04d2a..b33f53b 100644
41568--- a/drivers/isdn/hisax/config.c
41569+++ b/drivers/isdn/hisax/config.c
41570@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41571 ptr--;
41572 *ptr++ = '\n';
41573 *ptr = 0;
41574- HiSax_putstatus(cs, NULL, cs->dlog);
41575+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41576 } else
41577 HiSax_putstatus(cs, "LogEcho: ",
41578 "warning Frame too big (%d)",
41579diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41580index 8d0cf6e..4fc90de 100644
41581--- a/drivers/isdn/hisax/diva.c
41582+++ b/drivers/isdn/hisax/diva.c
41583@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41584 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41585 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41586 QuickHex(t, ptr, count);
41587- debugl1(cs, bcs->blog);
41588+ debugl1(cs, "%s", bcs->blog);
41589 }
41590 }
41591
41592@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41593 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41594 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41595 QuickHex(t, ptr, count);
41596- debugl1(cs, bcs->blog);
41597+ debugl1(cs, "%s", bcs->blog);
41598 }
41599 }
41600
41601diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41602index 1df6f9a..2be1c8a 100644
41603--- a/drivers/isdn/hisax/elsa.c
41604+++ b/drivers/isdn/hisax/elsa.c
41605@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41606 t = tmp;
41607 t += sprintf(tmp, "Arcofi data");
41608 QuickHex(t, p, cs->dc.isac.mon_rxp);
41609- debugl1(cs, tmp);
41610+ debugl1(cs, "%s", tmp);
41611 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41612 switch (cs->dc.isac.mon_rx[1]) {
41613 case 0x80:
41614diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41615index d4c98d3..3f84dd8 100644
41616--- a/drivers/isdn/hisax/elsa_ser.c
41617+++ b/drivers/isdn/hisax/elsa_ser.c
41618@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41619
41620 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41621 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41622- debugl1(cs, tmp);
41623+ debugl1(cs, "%s", tmp);
41624 }
41625 cs->hw.elsa.rcvcnt = 0;
41626 }
41627diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41628index 3ccd724..497bd02 100644
41629--- a/drivers/isdn/hisax/hfc_pci.c
41630+++ b/drivers/isdn/hisax/hfc_pci.c
41631@@ -901,7 +901,7 @@ Begin:
41632 ptr--;
41633 *ptr++ = '\n';
41634 *ptr = 0;
41635- HiSax_putstatus(cs, NULL, cs->dlog);
41636+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41637 } else
41638 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41639 }
41640diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41641index dc4574f..fa1fefd 100644
41642--- a/drivers/isdn/hisax/hfc_sx.c
41643+++ b/drivers/isdn/hisax/hfc_sx.c
41644@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41645 ptr--;
41646 *ptr++ = '\n';
41647 *ptr = 0;
41648- HiSax_putstatus(cs, NULL, cs->dlog);
41649+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41650 } else
41651 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41652 }
41653diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41654index f398d48..a8d6188 100644
41655--- a/drivers/isdn/hisax/hscx_irq.c
41656+++ b/drivers/isdn/hisax/hscx_irq.c
41657@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41658 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41659 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41660 QuickHex(t, ptr, count);
41661- debugl1(cs, bcs->blog);
41662+ debugl1(cs, "%s", bcs->blog);
41663 }
41664 }
41665
41666@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41667 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41668 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41669 QuickHex(t, ptr, count);
41670- debugl1(cs, bcs->blog);
41671+ debugl1(cs, "%s", bcs->blog);
41672 }
41673 }
41674
41675diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41676index db5321f..51dae91 100644
41677--- a/drivers/isdn/hisax/icc.c
41678+++ b/drivers/isdn/hisax/icc.c
41679@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41680
41681 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41682 QuickHex(t, ptr, count);
41683- debugl1(cs, cs->dlog);
41684+ debugl1(cs, "%s", cs->dlog);
41685 }
41686 }
41687
41688@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41689
41690 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41691 QuickHex(t, ptr, count);
41692- debugl1(cs, cs->dlog);
41693+ debugl1(cs, "%s", cs->dlog);
41694 }
41695 }
41696
41697diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41698index 74feb5c..5faa5de 100644
41699--- a/drivers/isdn/hisax/ipacx.c
41700+++ b/drivers/isdn/hisax/ipacx.c
41701@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41702
41703 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41704 QuickHex(t, ptr, count);
41705- debugl1(cs, cs->dlog);
41706+ debugl1(cs, "%s", cs->dlog);
41707 }
41708 }
41709
41710@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41711
41712 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41713 QuickHex(t, ptr, count);
41714- debugl1(cs, cs->dlog);
41715+ debugl1(cs, "%s", cs->dlog);
41716 }
41717 }
41718
41719@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41720
41721 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41722 QuickHex(t, ptr, count);
41723- debugl1(cs, bcs->blog);
41724+ debugl1(cs, "%s", bcs->blog);
41725 }
41726 }
41727
41728@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41729
41730 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41731 QuickHex(t, ptr, count);
41732- debugl1(cs, bcs->blog);
41733+ debugl1(cs, "%s", bcs->blog);
41734 }
41735 }
41736
41737diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41738index a365ccc..7fdf78f 100644
41739--- a/drivers/isdn/hisax/isac.c
41740+++ b/drivers/isdn/hisax/isac.c
41741@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41742
41743 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41744 QuickHex(t, ptr, count);
41745- debugl1(cs, cs->dlog);
41746+ debugl1(cs, "%s", cs->dlog);
41747 }
41748 }
41749
41750@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41751
41752 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41753 QuickHex(t, ptr, count);
41754- debugl1(cs, cs->dlog);
41755+ debugl1(cs, "%s", cs->dlog);
41756 }
41757 }
41758
41759diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41760index 7fdf347..f4956c7 100644
41761--- a/drivers/isdn/hisax/isar.c
41762+++ b/drivers/isdn/hisax/isar.c
41763@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41764 t = tmp;
41765 t += sprintf(t, "sendmbox cnt %d", len);
41766 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41767- debugl1(cs, tmp);
41768+ debugl1(cs, "%s", tmp);
41769 i -= 64;
41770 }
41771 }
41772@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41773 t = tmp;
41774 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41775 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41776- debugl1(cs, tmp);
41777+ debugl1(cs, "%s", tmp);
41778 i -= 64;
41779 }
41780 }
41781@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41782 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41783 ireg->iis, ireg->cmsb);
41784 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41785- debugl1(cs, debbuf);
41786+ debugl1(cs, "%s", debbuf);
41787 }
41788 break;
41789 case ISAR_IIS_INVMSG:
41790diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41791index f946c58..e2ae787 100644
41792--- a/drivers/isdn/hisax/jade.c
41793+++ b/drivers/isdn/hisax/jade.c
41794@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41795 int jade = bcs->hw.hscx.hscx;
41796
41797 if (cs->debug & L1_DEB_HSCX) {
41798- char tmp[40];
41799- sprintf(tmp, "jade %c mode %d ichan %d",
41800- 'A' + jade, mode, bc);
41801- debugl1(cs, tmp);
41802+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41803 }
41804 bcs->mode = mode;
41805 bcs->channel = bc;
41806@@ -257,23 +254,18 @@ void
41807 clear_pending_jade_ints(struct IsdnCardState *cs)
41808 {
41809 int val;
41810- char tmp[64];
41811
41812 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41813 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41814
41815 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41816- sprintf(tmp, "jade B ISTA %x", val);
41817- debugl1(cs, tmp);
41818+ debugl1(cs, "jade B ISTA %x", val);
41819 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41820- sprintf(tmp, "jade A ISTA %x", val);
41821- debugl1(cs, tmp);
41822+ debugl1(cs, "jade A ISTA %x", val);
41823 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41824- sprintf(tmp, "jade B STAR %x", val);
41825- debugl1(cs, tmp);
41826+ debugl1(cs, "jade B STAR %x", val);
41827 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41828- sprintf(tmp, "jade A STAR %x", val);
41829- debugl1(cs, tmp);
41830+ debugl1(cs, "jade A STAR %x", val);
41831 /* Unmask ints */
41832 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41833 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41834diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41835index f521fc8..b930da9 100644
41836--- a/drivers/isdn/hisax/jade_irq.c
41837+++ b/drivers/isdn/hisax/jade_irq.c
41838@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41839 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41840 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41841 QuickHex(t, ptr, count);
41842- debugl1(cs, bcs->blog);
41843+ debugl1(cs, "%s", bcs->blog);
41844 }
41845 }
41846
41847@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41848 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41849 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41850 QuickHex(t, ptr, count);
41851- debugl1(cs, bcs->blog);
41852+ debugl1(cs, "%s", bcs->blog);
41853 }
41854 }
41855
41856diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41857index 4c1bca5..875402e 100644
41858--- a/drivers/isdn/hisax/l3_1tr6.c
41859+++ b/drivers/isdn/hisax/l3_1tr6.c
41860@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41861 {
41862 dev_kfree_skb(skb);
41863 if (pc->st->l3.debug & L3_DEB_WARN)
41864- l3_debug(pc->st, msg);
41865+ l3_debug(pc->st, "%s", msg);
41866 l3_1tr6_release_req(pc, 0, NULL);
41867 }
41868
41869@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41870 {
41871 u_char *p;
41872 int bcfound = 0;
41873- char tmp[80];
41874 struct sk_buff *skb = arg;
41875
41876 /* Channel Identification */
41877@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41878 /* Signal all services, linklevel takes care of Service-Indicator */
41879 if (bcfound) {
41880 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41881- sprintf(tmp, "non-digital call: %s -> %s",
41882+ l3_debug(pc->st, "non-digital call: %s -> %s",
41883 pc->para.setup.phone,
41884 pc->para.setup.eazmsn);
41885- l3_debug(pc->st, tmp);
41886 }
41887 newl3state(pc, 6);
41888 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41889@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41890 {
41891 u_char *p;
41892 int i, tmpcharge = 0;
41893- char a_charge[8], tmp[32];
41894+ char a_charge[8];
41895 struct sk_buff *skb = arg;
41896
41897 p = skb->data;
41898@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41899 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41900 }
41901 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41902- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41903- l3_debug(pc->st, tmp);
41904+ l3_debug(pc->st, "charging info %d",
41905+ pc->para.chargeinfo);
41906 }
41907 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41908 l3_debug(pc->st, "charging info not found");
41909@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41910 struct sk_buff *skb = arg;
41911 u_char *p;
41912 int i, tmpcharge = 0;
41913- char a_charge[8], tmp[32];
41914+ char a_charge[8];
41915
41916 StopAllL3Timer(pc);
41917 p = skb->data;
41918@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41919 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41920 }
41921 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41922- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41923- l3_debug(pc->st, tmp);
41924+ l3_debug(pc->st, "charging info %d",
41925+ pc->para.chargeinfo);
41926 }
41927 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41928 l3_debug(pc->st, "charging info not found");
41929@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41930 int i, mt, cr;
41931 struct l3_process *proc;
41932 struct sk_buff *skb = arg;
41933- char tmp[80];
41934
41935 switch (pr) {
41936 case (DL_DATA | INDICATION):
41937@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41938 }
41939 if (skb->len < 4) {
41940 if (st->l3.debug & L3_DEB_PROTERR) {
41941- sprintf(tmp, "up1tr6 len only %d", skb->len);
41942- l3_debug(st, tmp);
41943+ l3_debug(st, "up1tr6 len only %d", skb->len);
41944 }
41945 dev_kfree_skb(skb);
41946 return;
41947 }
41948 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41949 if (st->l3.debug & L3_DEB_PROTERR) {
41950- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41951+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41952 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41953 skb->data[0], skb->len);
41954- l3_debug(st, tmp);
41955 }
41956 dev_kfree_skb(skb);
41957 return;
41958 }
41959 if (skb->data[1] != 1) {
41960 if (st->l3.debug & L3_DEB_PROTERR) {
41961- sprintf(tmp, "up1tr6 CR len not 1");
41962- l3_debug(st, tmp);
41963+ l3_debug(st, "up1tr6 CR len not 1");
41964 }
41965 dev_kfree_skb(skb);
41966 return;
41967@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41968 if (skb->data[0] == PROTO_DIS_N0) {
41969 dev_kfree_skb(skb);
41970 if (st->l3.debug & L3_DEB_STATE) {
41971- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41972+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41973 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41974- l3_debug(st, tmp);
41975 }
41976 } else if (skb->data[0] == PROTO_DIS_N1) {
41977 if (!(proc = getl3proc(st, cr))) {
41978@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41979 if (cr < 128) {
41980 if (!(proc = new_l3_process(st, cr))) {
41981 if (st->l3.debug & L3_DEB_PROTERR) {
41982- sprintf(tmp, "up1tr6 no roc mem");
41983- l3_debug(st, tmp);
41984+ l3_debug(st, "up1tr6 no roc mem");
41985 }
41986 dev_kfree_skb(skb);
41987 return;
41988@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41989 } else {
41990 if (!(proc = new_l3_process(st, cr))) {
41991 if (st->l3.debug & L3_DEB_PROTERR) {
41992- sprintf(tmp, "up1tr6 no roc mem");
41993- l3_debug(st, tmp);
41994+ l3_debug(st, "up1tr6 no roc mem");
41995 }
41996 dev_kfree_skb(skb);
41997 return;
41998@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41999 if (i == ARRAY_SIZE(datastln1)) {
42000 dev_kfree_skb(skb);
42001 if (st->l3.debug & L3_DEB_STATE) {
42002- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
42003+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
42004 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
42005 proc->state, mt);
42006- l3_debug(st, tmp);
42007 }
42008 return;
42009 } else {
42010 if (st->l3.debug & L3_DEB_STATE) {
42011- sprintf(tmp, "up1tr6%sstate %d mt %x",
42012+ l3_debug(st, "up1tr6%sstate %d mt %x",
42013 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
42014 proc->state, mt);
42015- l3_debug(st, tmp);
42016 }
42017 datastln1[i].rout(proc, pr, skb);
42018 }
42019@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
42020 int i, cr;
42021 struct l3_process *proc;
42022 struct Channel *chan;
42023- char tmp[80];
42024
42025 if ((DL_ESTABLISH | REQUEST) == pr) {
42026 l3_msg(st, pr, NULL);
42027@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
42028 break;
42029 if (i == ARRAY_SIZE(downstl)) {
42030 if (st->l3.debug & L3_DEB_STATE) {
42031- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
42032+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
42033 proc->state, pr);
42034- l3_debug(st, tmp);
42035 }
42036 } else {
42037 if (st->l3.debug & L3_DEB_STATE) {
42038- sprintf(tmp, "down1tr6 state %d prim %d",
42039+ l3_debug(st, "down1tr6 state %d prim %d",
42040 proc->state, pr);
42041- l3_debug(st, tmp);
42042 }
42043 downstl[i].rout(proc, pr, arg);
42044 }
42045diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
42046index b646eed..233e432 100644
42047--- a/drivers/isdn/hisax/netjet.c
42048+++ b/drivers/isdn/hisax/netjet.c
42049@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
42050 else
42051 j = i;
42052 QuickHex(t, p, j);
42053- debugl1(cs, tmp);
42054+ debugl1(cs, "%s", tmp);
42055 p += j;
42056 i -= j;
42057 t = tmp;
42058diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
42059index 041bf52..af1b020 100644
42060--- a/drivers/isdn/hisax/q931.c
42061+++ b/drivers/isdn/hisax/q931.c
42062@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
42063 dp--;
42064 *dp++ = '\n';
42065 *dp = 0;
42066- HiSax_putstatus(cs, NULL, cs->dlog);
42067+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42068 } else
42069 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
42070 }
42071@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
42072 }
42073 if (finish) {
42074 *dp = 0;
42075- HiSax_putstatus(cs, NULL, cs->dlog);
42076+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42077 return;
42078 }
42079 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
42080@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
42081 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
42082 }
42083 *dp = 0;
42084- HiSax_putstatus(cs, NULL, cs->dlog);
42085+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42086 }
42087diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
42088index d8cac69..a858955 100644
42089--- a/drivers/isdn/hisax/w6692.c
42090+++ b/drivers/isdn/hisax/w6692.c
42091@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
42092
42093 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
42094 QuickHex(t, ptr, count);
42095- debugl1(cs, cs->dlog);
42096+ debugl1(cs, "%s", cs->dlog);
42097 }
42098 }
42099
42100@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
42101
42102 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
42103 QuickHex(t, ptr, count);
42104- debugl1(cs, cs->dlog);
42105+ debugl1(cs, "%s", cs->dlog);
42106 }
42107 }
42108
42109@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
42110 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
42111 bcs->channel + '1', count);
42112 QuickHex(t, ptr, count);
42113- debugl1(cs, bcs->blog);
42114+ debugl1(cs, "%s", bcs->blog);
42115 }
42116 }
42117
42118@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
42119 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
42120 bcs->channel + '1', count);
42121 QuickHex(t, ptr, count);
42122- debugl1(cs, bcs->blog);
42123+ debugl1(cs, "%s", bcs->blog);
42124 }
42125 }
42126
42127diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42128index 9bb12ba..d4262f7 100644
42129--- a/drivers/isdn/i4l/isdn_common.c
42130+++ b/drivers/isdn/i4l/isdn_common.c
42131@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42132 } else
42133 return -EINVAL;
42134 case IIOCDBGVAR:
42135+ if (!capable(CAP_SYS_RAWIO))
42136+ return -EPERM;
42137 if (arg) {
42138 if (copy_to_user(argp, &dev, sizeof(ulong)))
42139 return -EFAULT;
42140diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42141index 3c5f249..5fac4d0 100644
42142--- a/drivers/isdn/i4l/isdn_tty.c
42143+++ b/drivers/isdn/i4l/isdn_tty.c
42144@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42145
42146 #ifdef ISDN_DEBUG_MODEM_OPEN
42147 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42148- port->count);
42149+ atomic_read(&port->count));
42150 #endif
42151- port->count++;
42152+ atomic_inc(&port->count);
42153 port->tty = tty;
42154 /*
42155 * Start up serial port
42156@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42157 #endif
42158 return;
42159 }
42160- if ((tty->count == 1) && (port->count != 1)) {
42161+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42162 /*
42163 * Uh, oh. tty->count is 1, which means that the tty
42164 * structure will be freed. Info->count should always
42165@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42166 * serial port won't be shutdown.
42167 */
42168 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42169- "info->count is %d\n", port->count);
42170- port->count = 1;
42171+ "info->count is %d\n", atomic_read(&port->count));
42172+ atomic_set(&port->count, 1);
42173 }
42174- if (--port->count < 0) {
42175+ if (atomic_dec_return(&port->count) < 0) {
42176 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42177- info->line, port->count);
42178- port->count = 0;
42179+ info->line, atomic_read(&port->count));
42180+ atomic_set(&port->count, 0);
42181 }
42182- if (port->count) {
42183+ if (atomic_read(&port->count)) {
42184 #ifdef ISDN_DEBUG_MODEM_OPEN
42185 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42186 #endif
42187@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42188 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42189 return;
42190 isdn_tty_shutdown(info);
42191- port->count = 0;
42192+ atomic_set(&port->count, 0);
42193 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42194 port->tty = NULL;
42195 wake_up_interruptible(&port->open_wait);
42196@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42197 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42198 modem_info *info = &dev->mdm.info[i];
42199
42200- if (info->port.count == 0)
42201+ if (atomic_read(&info->port.count) == 0)
42202 continue;
42203 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42204 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42205diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42206index e74df7c..03a03ba 100644
42207--- a/drivers/isdn/icn/icn.c
42208+++ b/drivers/isdn/icn/icn.c
42209@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42210 if (count > len)
42211 count = len;
42212 if (user) {
42213- if (copy_from_user(msg, buf, count))
42214+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42215 return -EFAULT;
42216 } else
42217 memcpy(msg, buf, count);
42218diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42219index 6a8405d..0bd1c7e 100644
42220--- a/drivers/leds/leds-clevo-mail.c
42221+++ b/drivers/leds/leds-clevo-mail.c
42222@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42223 * detected as working, but in reality it is not) as low as
42224 * possible.
42225 */
42226-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42227+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42228 {
42229 .callback = clevo_mail_led_dmi_callback,
42230 .ident = "Clevo D410J",
42231diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42232index 64e204e..c6bf189 100644
42233--- a/drivers/leds/leds-ss4200.c
42234+++ b/drivers/leds/leds-ss4200.c
42235@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42236 * detected as working, but in reality it is not) as low as
42237 * possible.
42238 */
42239-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42240+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42241 {
42242 .callback = ss4200_led_dmi_callback,
42243 .ident = "Intel SS4200-E",
42244diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42245index 0bf1e4e..b4bf44e 100644
42246--- a/drivers/lguest/core.c
42247+++ b/drivers/lguest/core.c
42248@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42249 * The end address needs +1 because __get_vm_area allocates an
42250 * extra guard page, so we need space for that.
42251 */
42252+
42253+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42254+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42255+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42256+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42257+#else
42258 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42259 VM_ALLOC, switcher_addr, switcher_addr
42260 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42261+#endif
42262+
42263 if (!switcher_vma) {
42264 err = -ENOMEM;
42265 printk("lguest: could not map switcher pages high\n");
42266@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42267 * Now the Switcher is mapped at the right address, we can't fail!
42268 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42269 */
42270- memcpy(switcher_vma->addr, start_switcher_text,
42271+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42272 end_switcher_text - start_switcher_text);
42273
42274 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42275diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42276index a35d8d1..59fb772 100644
42277--- a/drivers/lguest/page_tables.c
42278+++ b/drivers/lguest/page_tables.c
42279@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42280 /*:*/
42281
42282 #ifdef CONFIG_X86_PAE
42283-static void release_pmd(pmd_t *spmd)
42284+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42285 {
42286 /* If the entry's not present, there's nothing to release. */
42287 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42288diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42289index 5169239..47cb4db 100644
42290--- a/drivers/lguest/x86/core.c
42291+++ b/drivers/lguest/x86/core.c
42292@@ -59,7 +59,7 @@ static struct {
42293 /* Offset from where switcher.S was compiled to where we've copied it */
42294 static unsigned long switcher_offset(void)
42295 {
42296- return switcher_addr - (unsigned long)start_switcher_text;
42297+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42298 }
42299
42300 /* This cpu's struct lguest_pages (after the Switcher text page) */
42301@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42302 * These copies are pretty cheap, so we do them unconditionally: */
42303 /* Save the current Host top-level page directory.
42304 */
42305+
42306+#ifdef CONFIG_PAX_PER_CPU_PGD
42307+ pages->state.host_cr3 = read_cr3();
42308+#else
42309 pages->state.host_cr3 = __pa(current->mm->pgd);
42310+#endif
42311+
42312 /*
42313 * Set up the Guest's page tables to see this CPU's pages (and no
42314 * other CPU's pages).
42315@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42316 * compiled-in switcher code and the high-mapped copy we just made.
42317 */
42318 for (i = 0; i < IDT_ENTRIES; i++)
42319- default_idt_entries[i] += switcher_offset();
42320+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42321
42322 /*
42323 * Set up the Switcher's per-cpu areas.
42324@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42325 * it will be undisturbed when we switch. To change %cs and jump we
42326 * need this structure to feed to Intel's "lcall" instruction.
42327 */
42328- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42329+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42330 lguest_entry.segment = LGUEST_CS;
42331
42332 /*
42333diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42334index 40634b0..4f5855e 100644
42335--- a/drivers/lguest/x86/switcher_32.S
42336+++ b/drivers/lguest/x86/switcher_32.S
42337@@ -87,6 +87,7 @@
42338 #include <asm/page.h>
42339 #include <asm/segment.h>
42340 #include <asm/lguest.h>
42341+#include <asm/processor-flags.h>
42342
42343 // We mark the start of the code to copy
42344 // It's placed in .text tho it's never run here
42345@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42346 // Changes type when we load it: damn Intel!
42347 // For after we switch over our page tables
42348 // That entry will be read-only: we'd crash.
42349+
42350+#ifdef CONFIG_PAX_KERNEXEC
42351+ mov %cr0, %edx
42352+ xor $X86_CR0_WP, %edx
42353+ mov %edx, %cr0
42354+#endif
42355+
42356 movl $(GDT_ENTRY_TSS*8), %edx
42357 ltr %dx
42358
42359@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42360 // Let's clear it again for our return.
42361 // The GDT descriptor of the Host
42362 // Points to the table after two "size" bytes
42363- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42364+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42365 // Clear "used" from type field (byte 5, bit 2)
42366- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42367+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42368+
42369+#ifdef CONFIG_PAX_KERNEXEC
42370+ mov %cr0, %eax
42371+ xor $X86_CR0_WP, %eax
42372+ mov %eax, %cr0
42373+#endif
42374
42375 // Once our page table's switched, the Guest is live!
42376 // The Host fades as we run this final step.
42377@@ -295,13 +309,12 @@ deliver_to_host:
42378 // I consulted gcc, and it gave
42379 // These instructions, which I gladly credit:
42380 leal (%edx,%ebx,8), %eax
42381- movzwl (%eax),%edx
42382- movl 4(%eax), %eax
42383- xorw %ax, %ax
42384- orl %eax, %edx
42385+ movl 4(%eax), %edx
42386+ movw (%eax), %dx
42387 // Now the address of the handler's in %edx
42388 // We call it now: its "iret" drops us home.
42389- jmp *%edx
42390+ ljmp $__KERNEL_CS, $1f
42391+1: jmp *%edx
42392
42393 // Every interrupt can come to us here
42394 // But we must truly tell each apart.
42395diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42396index 0003992..854bbce 100644
42397--- a/drivers/md/bcache/closure.h
42398+++ b/drivers/md/bcache/closure.h
42399@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42400 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42401 struct workqueue_struct *wq)
42402 {
42403- BUG_ON(object_is_on_stack(cl));
42404+ BUG_ON(object_starts_on_stack(cl));
42405 closure_set_ip(cl);
42406 cl->fn = fn;
42407 cl->wq = wq;
42408diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42409index 547c4c5..5be1de4 100644
42410--- a/drivers/md/bcache/super.c
42411+++ b/drivers/md/bcache/super.c
42412@@ -1644,7 +1644,7 @@ err_unlock_gc:
42413 err:
42414 closure_sync(&op.cl);
42415 /* XXX: test this, it's broken */
42416- bch_cache_set_error(c, err);
42417+ bch_cache_set_error(c, "%s", err);
42418 }
42419
42420 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42421diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42422index a7fd821..9dcf6c3 100644
42423--- a/drivers/md/bitmap.c
42424+++ b/drivers/md/bitmap.c
42425@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42426 chunk_kb ? "KB" : "B");
42427 if (bitmap->storage.file) {
42428 seq_printf(seq, ", file: ");
42429- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42430+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42431 }
42432
42433 seq_printf(seq, "\n");
42434diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42435index f1b7586..a49c4bd 100644
42436--- a/drivers/md/dm-ioctl.c
42437+++ b/drivers/md/dm-ioctl.c
42438@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42439 cmd == DM_LIST_VERSIONS_CMD)
42440 return 0;
42441
42442- if ((cmd == DM_DEV_CREATE_CMD)) {
42443+ if (cmd == DM_DEV_CREATE_CMD) {
42444 if (!*param->name) {
42445 DMWARN("name not supplied when creating device");
42446 return -EINVAL;
42447diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42448index 699b5be..eac0a15 100644
42449--- a/drivers/md/dm-raid1.c
42450+++ b/drivers/md/dm-raid1.c
42451@@ -40,7 +40,7 @@ enum dm_raid1_error {
42452
42453 struct mirror {
42454 struct mirror_set *ms;
42455- atomic_t error_count;
42456+ atomic_unchecked_t error_count;
42457 unsigned long error_type;
42458 struct dm_dev *dev;
42459 sector_t offset;
42460@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42461 struct mirror *m;
42462
42463 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42464- if (!atomic_read(&m->error_count))
42465+ if (!atomic_read_unchecked(&m->error_count))
42466 return m;
42467
42468 return NULL;
42469@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42470 * simple way to tell if a device has encountered
42471 * errors.
42472 */
42473- atomic_inc(&m->error_count);
42474+ atomic_inc_unchecked(&m->error_count);
42475
42476 if (test_and_set_bit(error_type, &m->error_type))
42477 return;
42478@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42479 struct mirror *m = get_default_mirror(ms);
42480
42481 do {
42482- if (likely(!atomic_read(&m->error_count)))
42483+ if (likely(!atomic_read_unchecked(&m->error_count)))
42484 return m;
42485
42486 if (m-- == ms->mirror)
42487@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42488 {
42489 struct mirror *default_mirror = get_default_mirror(m->ms);
42490
42491- return !atomic_read(&default_mirror->error_count);
42492+ return !atomic_read_unchecked(&default_mirror->error_count);
42493 }
42494
42495 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42496@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42497 */
42498 if (likely(region_in_sync(ms, region, 1)))
42499 m = choose_mirror(ms, bio->bi_sector);
42500- else if (m && atomic_read(&m->error_count))
42501+ else if (m && atomic_read_unchecked(&m->error_count))
42502 m = NULL;
42503
42504 if (likely(m))
42505@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42506 }
42507
42508 ms->mirror[mirror].ms = ms;
42509- atomic_set(&(ms->mirror[mirror].error_count), 0);
42510+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42511 ms->mirror[mirror].error_type = 0;
42512 ms->mirror[mirror].offset = offset;
42513
42514@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42515 */
42516 static char device_status_char(struct mirror *m)
42517 {
42518- if (!atomic_read(&(m->error_count)))
42519+ if (!atomic_read_unchecked(&(m->error_count)))
42520 return 'A';
42521
42522 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42523diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42524index d907ca6..cfb8384 100644
42525--- a/drivers/md/dm-stripe.c
42526+++ b/drivers/md/dm-stripe.c
42527@@ -20,7 +20,7 @@ struct stripe {
42528 struct dm_dev *dev;
42529 sector_t physical_start;
42530
42531- atomic_t error_count;
42532+ atomic_unchecked_t error_count;
42533 };
42534
42535 struct stripe_c {
42536@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42537 kfree(sc);
42538 return r;
42539 }
42540- atomic_set(&(sc->stripe[i].error_count), 0);
42541+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42542 }
42543
42544 ti->private = sc;
42545@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42546 DMEMIT("%d ", sc->stripes);
42547 for (i = 0; i < sc->stripes; i++) {
42548 DMEMIT("%s ", sc->stripe[i].dev->name);
42549- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42550+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42551 'D' : 'A';
42552 }
42553 buffer[i] = '\0';
42554@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42555 */
42556 for (i = 0; i < sc->stripes; i++)
42557 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42558- atomic_inc(&(sc->stripe[i].error_count));
42559- if (atomic_read(&(sc->stripe[i].error_count)) <
42560+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42561+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42562 DM_IO_ERROR_THRESHOLD)
42563 schedule_work(&sc->trigger_event);
42564 }
42565diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42566index f221812..aca962b 100644
42567--- a/drivers/md/dm-table.c
42568+++ b/drivers/md/dm-table.c
42569@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42570 if (!dev_size)
42571 return 0;
42572
42573- if ((start >= dev_size) || (start + len > dev_size)) {
42574+ if ((start >= dev_size) || (len > dev_size - start)) {
42575 DMWARN("%s: %s too small for target: "
42576 "start=%llu, len=%llu, dev_size=%llu",
42577 dm_device_name(ti->table->md), bdevname(bdev, b),
42578diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42579index 60bce43..9b997d0 100644
42580--- a/drivers/md/dm-thin-metadata.c
42581+++ b/drivers/md/dm-thin-metadata.c
42582@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42583 {
42584 pmd->info.tm = pmd->tm;
42585 pmd->info.levels = 2;
42586- pmd->info.value_type.context = pmd->data_sm;
42587+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42588 pmd->info.value_type.size = sizeof(__le64);
42589 pmd->info.value_type.inc = data_block_inc;
42590 pmd->info.value_type.dec = data_block_dec;
42591@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42592
42593 pmd->bl_info.tm = pmd->tm;
42594 pmd->bl_info.levels = 1;
42595- pmd->bl_info.value_type.context = pmd->data_sm;
42596+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42597 pmd->bl_info.value_type.size = sizeof(__le64);
42598 pmd->bl_info.value_type.inc = data_block_inc;
42599 pmd->bl_info.value_type.dec = data_block_dec;
42600diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42601index 9e39d2b..fb879a7 100644
42602--- a/drivers/md/dm.c
42603+++ b/drivers/md/dm.c
42604@@ -178,9 +178,9 @@ struct mapped_device {
42605 /*
42606 * Event handling.
42607 */
42608- atomic_t event_nr;
42609+ atomic_unchecked_t event_nr;
42610 wait_queue_head_t eventq;
42611- atomic_t uevent_seq;
42612+ atomic_unchecked_t uevent_seq;
42613 struct list_head uevent_list;
42614 spinlock_t uevent_lock; /* Protect access to uevent_list */
42615
42616@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42617 spin_lock_init(&md->deferred_lock);
42618 atomic_set(&md->holders, 1);
42619 atomic_set(&md->open_count, 0);
42620- atomic_set(&md->event_nr, 0);
42621- atomic_set(&md->uevent_seq, 0);
42622+ atomic_set_unchecked(&md->event_nr, 0);
42623+ atomic_set_unchecked(&md->uevent_seq, 0);
42624 INIT_LIST_HEAD(&md->uevent_list);
42625 spin_lock_init(&md->uevent_lock);
42626
42627@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42628
42629 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42630
42631- atomic_inc(&md->event_nr);
42632+ atomic_inc_unchecked(&md->event_nr);
42633 wake_up(&md->eventq);
42634 }
42635
42636@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42637
42638 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42639 {
42640- return atomic_add_return(1, &md->uevent_seq);
42641+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42642 }
42643
42644 uint32_t dm_get_event_nr(struct mapped_device *md)
42645 {
42646- return atomic_read(&md->event_nr);
42647+ return atomic_read_unchecked(&md->event_nr);
42648 }
42649
42650 int dm_wait_event(struct mapped_device *md, int event_nr)
42651 {
42652 return wait_event_interruptible(md->eventq,
42653- (event_nr != atomic_read(&md->event_nr)));
42654+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42655 }
42656
42657 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42658diff --git a/drivers/md/md.c b/drivers/md/md.c
42659index 9f13e13..411a5b8 100644
42660--- a/drivers/md/md.c
42661+++ b/drivers/md/md.c
42662@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42663 * start build, activate spare
42664 */
42665 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42666-static atomic_t md_event_count;
42667+static atomic_unchecked_t md_event_count;
42668 void md_new_event(struct mddev *mddev)
42669 {
42670- atomic_inc(&md_event_count);
42671+ atomic_inc_unchecked(&md_event_count);
42672 wake_up(&md_event_waiters);
42673 }
42674 EXPORT_SYMBOL_GPL(md_new_event);
42675@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42676 */
42677 static void md_new_event_inintr(struct mddev *mddev)
42678 {
42679- atomic_inc(&md_event_count);
42680+ atomic_inc_unchecked(&md_event_count);
42681 wake_up(&md_event_waiters);
42682 }
42683
42684@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42685 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42686 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42687 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42688- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42689+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42690
42691 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42692 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42693@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42694 else
42695 sb->resync_offset = cpu_to_le64(0);
42696
42697- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42698+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42699
42700 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42701 sb->size = cpu_to_le64(mddev->dev_sectors);
42702@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42703 static ssize_t
42704 errors_show(struct md_rdev *rdev, char *page)
42705 {
42706- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42707+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42708 }
42709
42710 static ssize_t
42711@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42712 char *e;
42713 unsigned long n = simple_strtoul(buf, &e, 10);
42714 if (*buf && (*e == 0 || *e == '\n')) {
42715- atomic_set(&rdev->corrected_errors, n);
42716+ atomic_set_unchecked(&rdev->corrected_errors, n);
42717 return len;
42718 }
42719 return -EINVAL;
42720@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42721 rdev->sb_loaded = 0;
42722 rdev->bb_page = NULL;
42723 atomic_set(&rdev->nr_pending, 0);
42724- atomic_set(&rdev->read_errors, 0);
42725- atomic_set(&rdev->corrected_errors, 0);
42726+ atomic_set_unchecked(&rdev->read_errors, 0);
42727+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42728
42729 INIT_LIST_HEAD(&rdev->same_set);
42730 init_waitqueue_head(&rdev->blocked_wait);
42731@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42732
42733 spin_unlock(&pers_lock);
42734 seq_printf(seq, "\n");
42735- seq->poll_event = atomic_read(&md_event_count);
42736+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42737 return 0;
42738 }
42739 if (v == (void*)2) {
42740@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42741 return error;
42742
42743 seq = file->private_data;
42744- seq->poll_event = atomic_read(&md_event_count);
42745+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42746 return error;
42747 }
42748
42749@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42750 /* always allow read */
42751 mask = POLLIN | POLLRDNORM;
42752
42753- if (seq->poll_event != atomic_read(&md_event_count))
42754+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42755 mask |= POLLERR | POLLPRI;
42756 return mask;
42757 }
42758@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42759 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42760 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42761 (int)part_stat_read(&disk->part0, sectors[1]) -
42762- atomic_read(&disk->sync_io);
42763+ atomic_read_unchecked(&disk->sync_io);
42764 /* sync IO will cause sync_io to increase before the disk_stats
42765 * as sync_io is counted when a request starts, and
42766 * disk_stats is counted when it completes.
42767diff --git a/drivers/md/md.h b/drivers/md/md.h
42768index 20f02c0..fd8c821 100644
42769--- a/drivers/md/md.h
42770+++ b/drivers/md/md.h
42771@@ -94,13 +94,13 @@ struct md_rdev {
42772 * only maintained for arrays that
42773 * support hot removal
42774 */
42775- atomic_t read_errors; /* number of consecutive read errors that
42776+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42777 * we have tried to ignore.
42778 */
42779 struct timespec last_read_error; /* monotonic time since our
42780 * last read error
42781 */
42782- atomic_t corrected_errors; /* number of corrected read errors,
42783+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42784 * for reporting to userspace and storing
42785 * in superblock.
42786 */
42787@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42788
42789 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42790 {
42791- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42792+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42793 }
42794
42795 struct md_personality
42796diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42797index 3e6d115..ffecdeb 100644
42798--- a/drivers/md/persistent-data/dm-space-map.h
42799+++ b/drivers/md/persistent-data/dm-space-map.h
42800@@ -71,6 +71,7 @@ struct dm_space_map {
42801 dm_sm_threshold_fn fn,
42802 void *context);
42803 };
42804+typedef struct dm_space_map __no_const dm_space_map_no_const;
42805
42806 /*----------------------------------------------------------------*/
42807
42808diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42809index d60412c..8d4c982 100644
42810--- a/drivers/md/raid1.c
42811+++ b/drivers/md/raid1.c
42812@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42813 if (r1_sync_page_io(rdev, sect, s,
42814 bio->bi_io_vec[idx].bv_page,
42815 READ) != 0)
42816- atomic_add(s, &rdev->corrected_errors);
42817+ atomic_add_unchecked(s, &rdev->corrected_errors);
42818 }
42819 sectors -= s;
42820 sect += s;
42821@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42822 test_bit(In_sync, &rdev->flags)) {
42823 if (r1_sync_page_io(rdev, sect, s,
42824 conf->tmppage, READ)) {
42825- atomic_add(s, &rdev->corrected_errors);
42826+ atomic_add_unchecked(s, &rdev->corrected_errors);
42827 printk(KERN_INFO
42828 "md/raid1:%s: read error corrected "
42829 "(%d sectors at %llu on %s)\n",
42830diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42831index df7b0a0..a257495 100644
42832--- a/drivers/md/raid10.c
42833+++ b/drivers/md/raid10.c
42834@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42835 /* The write handler will notice the lack of
42836 * R10BIO_Uptodate and record any errors etc
42837 */
42838- atomic_add(r10_bio->sectors,
42839+ atomic_add_unchecked(r10_bio->sectors,
42840 &conf->mirrors[d].rdev->corrected_errors);
42841
42842 /* for reconstruct, we always reschedule after a read.
42843@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42844 {
42845 struct timespec cur_time_mon;
42846 unsigned long hours_since_last;
42847- unsigned int read_errors = atomic_read(&rdev->read_errors);
42848+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42849
42850 ktime_get_ts(&cur_time_mon);
42851
42852@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42853 * overflowing the shift of read_errors by hours_since_last.
42854 */
42855 if (hours_since_last >= 8 * sizeof(read_errors))
42856- atomic_set(&rdev->read_errors, 0);
42857+ atomic_set_unchecked(&rdev->read_errors, 0);
42858 else
42859- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42860+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42861 }
42862
42863 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42864@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42865 return;
42866
42867 check_decay_read_errors(mddev, rdev);
42868- atomic_inc(&rdev->read_errors);
42869- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42870+ atomic_inc_unchecked(&rdev->read_errors);
42871+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42872 char b[BDEVNAME_SIZE];
42873 bdevname(rdev->bdev, b);
42874
42875@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42876 "md/raid10:%s: %s: Raid device exceeded "
42877 "read_error threshold [cur %d:max %d]\n",
42878 mdname(mddev), b,
42879- atomic_read(&rdev->read_errors), max_read_errors);
42880+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42881 printk(KERN_NOTICE
42882 "md/raid10:%s: %s: Failing raid device\n",
42883 mdname(mddev), b);
42884@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42885 sect +
42886 choose_data_offset(r10_bio, rdev)),
42887 bdevname(rdev->bdev, b));
42888- atomic_add(s, &rdev->corrected_errors);
42889+ atomic_add_unchecked(s, &rdev->corrected_errors);
42890 }
42891
42892 rdev_dec_pending(rdev, mddev);
42893diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42894index 78ea443..7d57513 100644
42895--- a/drivers/md/raid5.c
42896+++ b/drivers/md/raid5.c
42897@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42898 mdname(conf->mddev), STRIPE_SECTORS,
42899 (unsigned long long)s,
42900 bdevname(rdev->bdev, b));
42901- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42902+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42903 clear_bit(R5_ReadError, &sh->dev[i].flags);
42904 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42905 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42906 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42907
42908- if (atomic_read(&rdev->read_errors))
42909- atomic_set(&rdev->read_errors, 0);
42910+ if (atomic_read_unchecked(&rdev->read_errors))
42911+ atomic_set_unchecked(&rdev->read_errors, 0);
42912 } else {
42913 const char *bdn = bdevname(rdev->bdev, b);
42914 int retry = 0;
42915 int set_bad = 0;
42916
42917 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42918- atomic_inc(&rdev->read_errors);
42919+ atomic_inc_unchecked(&rdev->read_errors);
42920 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42921 printk_ratelimited(
42922 KERN_WARNING
42923@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42924 mdname(conf->mddev),
42925 (unsigned long long)s,
42926 bdn);
42927- } else if (atomic_read(&rdev->read_errors)
42928+ } else if (atomic_read_unchecked(&rdev->read_errors)
42929 > conf->max_nr_stripes)
42930 printk(KERN_WARNING
42931 "md/raid:%s: Too many read errors, failing device %s.\n",
42932diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42933index 401ef64..836e563 100644
42934--- a/drivers/media/dvb-core/dvbdev.c
42935+++ b/drivers/media/dvb-core/dvbdev.c
42936@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42937 const struct dvb_device *template, void *priv, int type)
42938 {
42939 struct dvb_device *dvbdev;
42940- struct file_operations *dvbdevfops;
42941+ file_operations_no_const *dvbdevfops;
42942 struct device *clsdev;
42943 int minor;
42944 int id;
42945diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42946index 9b6c3bb..baeb5c7 100644
42947--- a/drivers/media/dvb-frontends/dib3000.h
42948+++ b/drivers/media/dvb-frontends/dib3000.h
42949@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42950 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42951 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42952 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42953-};
42954+} __no_const;
42955
42956 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42957 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42958diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42959index ecf21d9..b992428d 100644
42960--- a/drivers/media/pci/cx88/cx88-video.c
42961+++ b/drivers/media/pci/cx88/cx88-video.c
42962@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42963
42964 /* ------------------------------------------------------------------ */
42965
42966-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42967-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42968-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42969+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42970+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42971+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42972
42973 module_param_array(video_nr, int, NULL, 0444);
42974 module_param_array(vbi_nr, int, NULL, 0444);
42975diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42976index c08ae3e..eb59af1 100644
42977--- a/drivers/media/pci/ivtv/ivtv-driver.c
42978+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42979@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42980 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42981
42982 /* ivtv instance counter */
42983-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42984+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42985
42986 /* Parameter declarations */
42987 static int cardtype[IVTV_MAX_CARDS];
42988diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42989index dfd0a21..6bbb465 100644
42990--- a/drivers/media/platform/omap/omap_vout.c
42991+++ b/drivers/media/platform/omap/omap_vout.c
42992@@ -63,7 +63,6 @@ enum omap_vout_channels {
42993 OMAP_VIDEO2,
42994 };
42995
42996-static struct videobuf_queue_ops video_vbq_ops;
42997 /* Variables configurable through module params*/
42998 static u32 video1_numbuffers = 3;
42999 static u32 video2_numbuffers = 3;
43000@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43001 {
43002 struct videobuf_queue *q;
43003 struct omap_vout_device *vout = NULL;
43004+ static struct videobuf_queue_ops video_vbq_ops = {
43005+ .buf_setup = omap_vout_buffer_setup,
43006+ .buf_prepare = omap_vout_buffer_prepare,
43007+ .buf_release = omap_vout_buffer_release,
43008+ .buf_queue = omap_vout_buffer_queue,
43009+ };
43010
43011 vout = video_drvdata(file);
43012 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43013@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43014 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43015
43016 q = &vout->vbq;
43017- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43018- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43019- video_vbq_ops.buf_release = omap_vout_buffer_release;
43020- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43021 spin_lock_init(&vout->vbq_lock);
43022
43023 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43024diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43025index 04e6490..2df65bf 100644
43026--- a/drivers/media/platform/s5p-tv/mixer.h
43027+++ b/drivers/media/platform/s5p-tv/mixer.h
43028@@ -156,7 +156,7 @@ struct mxr_layer {
43029 /** layer index (unique identifier) */
43030 int idx;
43031 /** callbacks for layer methods */
43032- struct mxr_layer_ops ops;
43033+ struct mxr_layer_ops *ops;
43034 /** format array */
43035 const struct mxr_format **fmt_array;
43036 /** size of format array */
43037diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43038index b93a21f..2535195 100644
43039--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43040+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43041@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43042 {
43043 struct mxr_layer *layer;
43044 int ret;
43045- struct mxr_layer_ops ops = {
43046+ static struct mxr_layer_ops ops = {
43047 .release = mxr_graph_layer_release,
43048 .buffer_set = mxr_graph_buffer_set,
43049 .stream_set = mxr_graph_stream_set,
43050diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43051index b713403..53cb5ad 100644
43052--- a/drivers/media/platform/s5p-tv/mixer_reg.c
43053+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43054@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43055 layer->update_buf = next;
43056 }
43057
43058- layer->ops.buffer_set(layer, layer->update_buf);
43059+ layer->ops->buffer_set(layer, layer->update_buf);
43060
43061 if (done && done != layer->shadow_buf)
43062 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43063diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43064index 641b1f0..49cff30 100644
43065--- a/drivers/media/platform/s5p-tv/mixer_video.c
43066+++ b/drivers/media/platform/s5p-tv/mixer_video.c
43067@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43068 layer->geo.src.height = layer->geo.src.full_height;
43069
43070 mxr_geometry_dump(mdev, &layer->geo);
43071- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43072+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43073 mxr_geometry_dump(mdev, &layer->geo);
43074 }
43075
43076@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43077 layer->geo.dst.full_width = mbus_fmt.width;
43078 layer->geo.dst.full_height = mbus_fmt.height;
43079 layer->geo.dst.field = mbus_fmt.field;
43080- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43081+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43082
43083 mxr_geometry_dump(mdev, &layer->geo);
43084 }
43085@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43086 /* set source size to highest accepted value */
43087 geo->src.full_width = max(geo->dst.full_width, pix->width);
43088 geo->src.full_height = max(geo->dst.full_height, pix->height);
43089- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43090+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43091 mxr_geometry_dump(mdev, &layer->geo);
43092 /* set cropping to total visible screen */
43093 geo->src.width = pix->width;
43094@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43095 geo->src.x_offset = 0;
43096 geo->src.y_offset = 0;
43097 /* assure consistency of geometry */
43098- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43099+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43100 mxr_geometry_dump(mdev, &layer->geo);
43101 /* set full size to lowest possible value */
43102 geo->src.full_width = 0;
43103 geo->src.full_height = 0;
43104- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43105+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43106 mxr_geometry_dump(mdev, &layer->geo);
43107
43108 /* returning results */
43109@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43110 target->width = s->r.width;
43111 target->height = s->r.height;
43112
43113- layer->ops.fix_geometry(layer, stage, s->flags);
43114+ layer->ops->fix_geometry(layer, stage, s->flags);
43115
43116 /* retrieve update selection rectangle */
43117 res.left = target->x_offset;
43118@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43119 mxr_output_get(mdev);
43120
43121 mxr_layer_update_output(layer);
43122- layer->ops.format_set(layer);
43123+ layer->ops->format_set(layer);
43124 /* enabling layer in hardware */
43125 spin_lock_irqsave(&layer->enq_slock, flags);
43126 layer->state = MXR_LAYER_STREAMING;
43127 spin_unlock_irqrestore(&layer->enq_slock, flags);
43128
43129- layer->ops.stream_set(layer, MXR_ENABLE);
43130+ layer->ops->stream_set(layer, MXR_ENABLE);
43131 mxr_streamer_get(mdev);
43132
43133 return 0;
43134@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43135 spin_unlock_irqrestore(&layer->enq_slock, flags);
43136
43137 /* disabling layer in hardware */
43138- layer->ops.stream_set(layer, MXR_DISABLE);
43139+ layer->ops->stream_set(layer, MXR_DISABLE);
43140 /* remove one streamer */
43141 mxr_streamer_put(mdev);
43142 /* allow changes in output configuration */
43143@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43144
43145 void mxr_layer_release(struct mxr_layer *layer)
43146 {
43147- if (layer->ops.release)
43148- layer->ops.release(layer);
43149+ if (layer->ops->release)
43150+ layer->ops->release(layer);
43151 }
43152
43153 void mxr_base_layer_release(struct mxr_layer *layer)
43154@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43155
43156 layer->mdev = mdev;
43157 layer->idx = idx;
43158- layer->ops = *ops;
43159+ layer->ops = ops;
43160
43161 spin_lock_init(&layer->enq_slock);
43162 INIT_LIST_HEAD(&layer->enq_list);
43163diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43164index 3d13a63..da31bf1 100644
43165--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43166+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43167@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43168 {
43169 struct mxr_layer *layer;
43170 int ret;
43171- struct mxr_layer_ops ops = {
43172+ static struct mxr_layer_ops ops = {
43173 .release = mxr_vp_layer_release,
43174 .buffer_set = mxr_vp_buffer_set,
43175 .stream_set = mxr_vp_stream_set,
43176diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43177index 545c04c..a14bded 100644
43178--- a/drivers/media/radio/radio-cadet.c
43179+++ b/drivers/media/radio/radio-cadet.c
43180@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43181 unsigned char readbuf[RDS_BUFFER];
43182 int i = 0;
43183
43184+ if (count > RDS_BUFFER)
43185+ return -EFAULT;
43186 mutex_lock(&dev->lock);
43187 if (dev->rdsstat == 0)
43188 cadet_start_rds(dev);
43189@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43190 while (i < count && dev->rdsin != dev->rdsout)
43191 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43192
43193- if (i && copy_to_user(data, readbuf, i))
43194+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43195 i = -EFAULT;
43196 unlock:
43197 mutex_unlock(&dev->lock);
43198diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43199index bd4d3a7..ffc0b9d 100644
43200--- a/drivers/media/radio/radio-maxiradio.c
43201+++ b/drivers/media/radio/radio-maxiradio.c
43202@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43203 /* TEA5757 pin mappings */
43204 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43205
43206-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43207+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43208
43209 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43210 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43211diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43212index 8fa18ab..caee70f 100644
43213--- a/drivers/media/radio/radio-shark.c
43214+++ b/drivers/media/radio/radio-shark.c
43215@@ -79,7 +79,7 @@ struct shark_device {
43216 u32 last_val;
43217 };
43218
43219-static atomic_t shark_instance = ATOMIC_INIT(0);
43220+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43221
43222 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43223 {
43224diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43225index 9fb6697..f167415 100644
43226--- a/drivers/media/radio/radio-shark2.c
43227+++ b/drivers/media/radio/radio-shark2.c
43228@@ -74,7 +74,7 @@ struct shark_device {
43229 u8 *transfer_buffer;
43230 };
43231
43232-static atomic_t shark_instance = ATOMIC_INIT(0);
43233+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43234
43235 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43236 {
43237diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43238index 9c9084c..a9e8dfb 100644
43239--- a/drivers/media/radio/radio-si476x.c
43240+++ b/drivers/media/radio/radio-si476x.c
43241@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43242 struct si476x_radio *radio;
43243 struct v4l2_ctrl *ctrl;
43244
43245- static atomic_t instance = ATOMIC_INIT(0);
43246+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43247
43248 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43249 if (!radio)
43250diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43251index 1cf382a..c22998c 100644
43252--- a/drivers/media/rc/rc-main.c
43253+++ b/drivers/media/rc/rc-main.c
43254@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43255 int rc_register_device(struct rc_dev *dev)
43256 {
43257 static bool raw_init = false; /* raw decoders loaded? */
43258- static atomic_t devno = ATOMIC_INIT(0);
43259+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43260 struct rc_map *rc_map;
43261 const char *path;
43262 int rc;
43263@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43264 */
43265 mutex_lock(&dev->lock);
43266
43267- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43268+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43269 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43270 dev_set_drvdata(&dev->dev, dev);
43271 rc = device_add(&dev->dev);
43272diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43273index 3940bb0..fb3952a 100644
43274--- a/drivers/media/usb/dvb-usb/cxusb.c
43275+++ b/drivers/media/usb/dvb-usb/cxusb.c
43276@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43277
43278 struct dib0700_adapter_state {
43279 int (*set_param_save) (struct dvb_frontend *);
43280-};
43281+} __no_const;
43282
43283 static int dib7070_set_param_override(struct dvb_frontend *fe)
43284 {
43285diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43286index 6e237b6..dc25556 100644
43287--- a/drivers/media/usb/dvb-usb/dw2102.c
43288+++ b/drivers/media/usb/dvb-usb/dw2102.c
43289@@ -118,7 +118,7 @@ struct su3000_state {
43290
43291 struct s6x0_state {
43292 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43293-};
43294+} __no_const;
43295
43296 /* debug */
43297 static int dvb_usb_dw2102_debug;
43298diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43299index 8f7a6a4..59502dd 100644
43300--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43301+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43302@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43303 __u32 reserved;
43304 };
43305
43306-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43307+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43308 enum v4l2_memory memory)
43309 {
43310 void __user *up_pln;
43311@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43312 return 0;
43313 }
43314
43315-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43316+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43317 enum v4l2_memory memory)
43318 {
43319 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43320@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43321 put_user(kp->start_block, &up->start_block) ||
43322 put_user(kp->blocks, &up->blocks) ||
43323 put_user(tmp, &up->edid) ||
43324- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43325+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43326 return -EFAULT;
43327 return 0;
43328 }
43329diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43330index 02d1b63..5fd6b16 100644
43331--- a/drivers/media/v4l2-core/v4l2-device.c
43332+++ b/drivers/media/v4l2-core/v4l2-device.c
43333@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43334 EXPORT_SYMBOL_GPL(v4l2_device_put);
43335
43336 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43337- atomic_t *instance)
43338+ atomic_unchecked_t *instance)
43339 {
43340- int num = atomic_inc_return(instance) - 1;
43341+ int num = atomic_inc_return_unchecked(instance) - 1;
43342 int len = strlen(basename);
43343
43344 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43345diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43346index 68e6b5e..d8b923e 100644
43347--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43348+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43349@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43350 struct file *file, void *fh, void *p);
43351 } u;
43352 void (*debug)(const void *arg, bool write_only);
43353-};
43354+} __do_const;
43355+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43356
43357 /* This control needs a priority check */
43358 #define INFO_FL_PRIO (1 << 0)
43359@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43360 struct video_device *vfd = video_devdata(file);
43361 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43362 bool write_only = false;
43363- struct v4l2_ioctl_info default_info;
43364+ v4l2_ioctl_info_no_const default_info;
43365 const struct v4l2_ioctl_info *info;
43366 void *fh = file->private_data;
43367 struct v4l2_fh *vfh = NULL;
43368@@ -2194,7 +2195,7 @@ done:
43369 }
43370
43371 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43372- void * __user *user_ptr, void ***kernel_ptr)
43373+ void __user **user_ptr, void ***kernel_ptr)
43374 {
43375 int ret = 0;
43376
43377@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43378 ret = -EINVAL;
43379 break;
43380 }
43381- *user_ptr = (void __user *)buf->m.planes;
43382+ *user_ptr = (void __force_user *)buf->m.planes;
43383 *kernel_ptr = (void *)&buf->m.planes;
43384 *array_size = sizeof(struct v4l2_plane) * buf->length;
43385 ret = 1;
43386@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43387 ret = -EINVAL;
43388 break;
43389 }
43390- *user_ptr = (void __user *)ctrls->controls;
43391+ *user_ptr = (void __force_user *)ctrls->controls;
43392 *kernel_ptr = (void *)&ctrls->controls;
43393 *array_size = sizeof(struct v4l2_ext_control)
43394 * ctrls->count;
43395diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43396index 767ff4d..c69d259 100644
43397--- a/drivers/message/fusion/mptbase.c
43398+++ b/drivers/message/fusion/mptbase.c
43399@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43400 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43401 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43402
43403+#ifdef CONFIG_GRKERNSEC_HIDESYM
43404+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43405+#else
43406 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43407 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43408+#endif
43409+
43410 /*
43411 * Rounding UP to nearest 4-kB boundary here...
43412 */
43413@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43414 ioc->facts.GlobalCredits);
43415
43416 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43417+#ifdef CONFIG_GRKERNSEC_HIDESYM
43418+ NULL, NULL);
43419+#else
43420 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43421+#endif
43422 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43423 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43424 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43425diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43426index dd239bd..689c4f7 100644
43427--- a/drivers/message/fusion/mptsas.c
43428+++ b/drivers/message/fusion/mptsas.c
43429@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43430 return 0;
43431 }
43432
43433+static inline void
43434+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43435+{
43436+ if (phy_info->port_details) {
43437+ phy_info->port_details->rphy = rphy;
43438+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43439+ ioc->name, rphy));
43440+ }
43441+
43442+ if (rphy) {
43443+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43444+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43445+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43446+ ioc->name, rphy, rphy->dev.release));
43447+ }
43448+}
43449+
43450 /* no mutex */
43451 static void
43452 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43453@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43454 return NULL;
43455 }
43456
43457-static inline void
43458-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43459-{
43460- if (phy_info->port_details) {
43461- phy_info->port_details->rphy = rphy;
43462- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43463- ioc->name, rphy));
43464- }
43465-
43466- if (rphy) {
43467- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43468- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43469- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43470- ioc->name, rphy, rphy->dev.release));
43471- }
43472-}
43473-
43474 static inline struct sas_port *
43475 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43476 {
43477diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43478index 727819c..ad74694 100644
43479--- a/drivers/message/fusion/mptscsih.c
43480+++ b/drivers/message/fusion/mptscsih.c
43481@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43482
43483 h = shost_priv(SChost);
43484
43485- if (h) {
43486- if (h->info_kbuf == NULL)
43487- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43488- return h->info_kbuf;
43489- h->info_kbuf[0] = '\0';
43490+ if (!h)
43491+ return NULL;
43492
43493- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43494- h->info_kbuf[size-1] = '\0';
43495- }
43496+ if (h->info_kbuf == NULL)
43497+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43498+ return h->info_kbuf;
43499+ h->info_kbuf[0] = '\0';
43500+
43501+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43502+ h->info_kbuf[size-1] = '\0';
43503
43504 return h->info_kbuf;
43505 }
43506diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43507index b7d87cd..9890039 100644
43508--- a/drivers/message/i2o/i2o_proc.c
43509+++ b/drivers/message/i2o/i2o_proc.c
43510@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43511 "Array Controller Device"
43512 };
43513
43514-static char *chtostr(char *tmp, u8 *chars, int n)
43515-{
43516- tmp[0] = 0;
43517- return strncat(tmp, (char *)chars, n);
43518-}
43519-
43520 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43521 char *group)
43522 {
43523@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43524 } *result;
43525
43526 i2o_exec_execute_ddm_table ddm_table;
43527- char tmp[28 + 1];
43528
43529 result = kmalloc(sizeof(*result), GFP_KERNEL);
43530 if (!result)
43531@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43532
43533 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43534 seq_printf(seq, "%-#8x", ddm_table.module_id);
43535- seq_printf(seq, "%-29s",
43536- chtostr(tmp, ddm_table.module_name_version, 28));
43537+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43538 seq_printf(seq, "%9d ", ddm_table.data_size);
43539 seq_printf(seq, "%8d", ddm_table.code_size);
43540
43541@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43542
43543 i2o_driver_result_table *result;
43544 i2o_driver_store_table *dst;
43545- char tmp[28 + 1];
43546
43547 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43548 if (result == NULL)
43549@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43550
43551 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43552 seq_printf(seq, "%-#8x", dst->module_id);
43553- seq_printf(seq, "%-29s",
43554- chtostr(tmp, dst->module_name_version, 28));
43555- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43556+ seq_printf(seq, "%-.28s", dst->module_name_version);
43557+ seq_printf(seq, "%-.8s", dst->date);
43558 seq_printf(seq, "%8d ", dst->module_size);
43559 seq_printf(seq, "%8d ", dst->mpb_size);
43560 seq_printf(seq, "0x%04x", dst->module_flags);
43561@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43562 // == (allow) 512d bytes (max)
43563 static u16 *work16 = (u16 *) work32;
43564 int token;
43565- char tmp[16 + 1];
43566
43567 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43568
43569@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43570 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43571 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43572 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43573- seq_printf(seq, "Vendor info : %s\n",
43574- chtostr(tmp, (u8 *) (work32 + 2), 16));
43575- seq_printf(seq, "Product info : %s\n",
43576- chtostr(tmp, (u8 *) (work32 + 6), 16));
43577- seq_printf(seq, "Description : %s\n",
43578- chtostr(tmp, (u8 *) (work32 + 10), 16));
43579- seq_printf(seq, "Product rev. : %s\n",
43580- chtostr(tmp, (u8 *) (work32 + 14), 8));
43581+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43582+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43583+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43584+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43585
43586 seq_printf(seq, "Serial number : ");
43587 print_serial_number(seq, (u8 *) (work32 + 16),
43588@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43589 u8 pad[256]; // allow up to 256 byte (max) serial number
43590 } result;
43591
43592- char tmp[24 + 1];
43593-
43594 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43595
43596 if (token < 0) {
43597@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43598 }
43599
43600 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43601- seq_printf(seq, "Module name : %s\n",
43602- chtostr(tmp, result.module_name, 24));
43603- seq_printf(seq, "Module revision : %s\n",
43604- chtostr(tmp, result.module_rev, 8));
43605+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43606+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43607
43608 seq_printf(seq, "Serial number : ");
43609 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43610@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43611 u8 instance_number[4];
43612 } result;
43613
43614- char tmp[64 + 1];
43615-
43616 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43617
43618 if (token < 0) {
43619@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43620 return 0;
43621 }
43622
43623- seq_printf(seq, "Device name : %s\n",
43624- chtostr(tmp, result.device_name, 64));
43625- seq_printf(seq, "Service name : %s\n",
43626- chtostr(tmp, result.service_name, 64));
43627- seq_printf(seq, "Physical name : %s\n",
43628- chtostr(tmp, result.physical_location, 64));
43629- seq_printf(seq, "Instance number : %s\n",
43630- chtostr(tmp, result.instance_number, 4));
43631+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43632+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43633+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43634+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43635
43636 return 0;
43637 }
43638diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43639index a8c08f3..155fe3d 100644
43640--- a/drivers/message/i2o/iop.c
43641+++ b/drivers/message/i2o/iop.c
43642@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43643
43644 spin_lock_irqsave(&c->context_list_lock, flags);
43645
43646- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43647- atomic_inc(&c->context_list_counter);
43648+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43649+ atomic_inc_unchecked(&c->context_list_counter);
43650
43651- entry->context = atomic_read(&c->context_list_counter);
43652+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43653
43654 list_add(&entry->list, &c->context_list);
43655
43656@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43657
43658 #if BITS_PER_LONG == 64
43659 spin_lock_init(&c->context_list_lock);
43660- atomic_set(&c->context_list_counter, 0);
43661+ atomic_set_unchecked(&c->context_list_counter, 0);
43662 INIT_LIST_HEAD(&c->context_list);
43663 #endif
43664
43665diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43666index fcbb2e9..2635e11 100644
43667--- a/drivers/mfd/janz-cmodio.c
43668+++ b/drivers/mfd/janz-cmodio.c
43669@@ -13,6 +13,7 @@
43670
43671 #include <linux/kernel.h>
43672 #include <linux/module.h>
43673+#include <linux/slab.h>
43674 #include <linux/init.h>
43675 #include <linux/pci.h>
43676 #include <linux/interrupt.h>
43677diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43678index 9aa6d1e..1631bfc 100644
43679--- a/drivers/mfd/twl4030-irq.c
43680+++ b/drivers/mfd/twl4030-irq.c
43681@@ -35,6 +35,7 @@
43682 #include <linux/of.h>
43683 #include <linux/irqdomain.h>
43684 #include <linux/i2c/twl.h>
43685+#include <asm/pgtable.h>
43686
43687 #include "twl-core.h"
43688
43689@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43690 * Install an irq handler for each of the SIH modules;
43691 * clone dummy irq_chip since PIH can't *do* anything
43692 */
43693- twl4030_irq_chip = dummy_irq_chip;
43694- twl4030_irq_chip.name = "twl4030";
43695+ pax_open_kernel();
43696+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43697+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43698
43699- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43700+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43701+ pax_close_kernel();
43702
43703 for (i = irq_base; i < irq_end; i++) {
43704 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43705diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43706index 277a8db..0e0b754 100644
43707--- a/drivers/mfd/twl6030-irq.c
43708+++ b/drivers/mfd/twl6030-irq.c
43709@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43710 * install an irq handler for each of the modules;
43711 * clone dummy irq_chip since PIH can't *do* anything
43712 */
43713- twl6030_irq_chip = dummy_irq_chip;
43714- twl6030_irq_chip.name = "twl6030";
43715- twl6030_irq_chip.irq_set_type = NULL;
43716- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43717+ pax_open_kernel();
43718+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43719+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43720+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43721+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43722+ pax_close_kernel();
43723
43724 for (i = irq_base; i < irq_end; i++) {
43725 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43726diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43727index f32550a..e3e52a2 100644
43728--- a/drivers/misc/c2port/core.c
43729+++ b/drivers/misc/c2port/core.c
43730@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43731 mutex_init(&c2dev->mutex);
43732
43733 /* Create binary file */
43734- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43735+ pax_open_kernel();
43736+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43737+ pax_close_kernel();
43738 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43739 if (unlikely(ret))
43740 goto error_device_create_bin_file;
43741diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43742index 36f5d52..32311c3 100644
43743--- a/drivers/misc/kgdbts.c
43744+++ b/drivers/misc/kgdbts.c
43745@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43746 char before[BREAK_INSTR_SIZE];
43747 char after[BREAK_INSTR_SIZE];
43748
43749- probe_kernel_read(before, (char *)kgdbts_break_test,
43750+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43751 BREAK_INSTR_SIZE);
43752 init_simple_test();
43753 ts.tst = plant_and_detach_test;
43754@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43755 /* Activate test with initial breakpoint */
43756 if (!is_early)
43757 kgdb_breakpoint();
43758- probe_kernel_read(after, (char *)kgdbts_break_test,
43759+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43760 BREAK_INSTR_SIZE);
43761 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43762 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43763diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43764index 036effe..b3a6336 100644
43765--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43766+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43767@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43768 * the lid is closed. This leads to interrupts as soon as a little move
43769 * is done.
43770 */
43771- atomic_inc(&lis3->count);
43772+ atomic_inc_unchecked(&lis3->count);
43773
43774 wake_up_interruptible(&lis3->misc_wait);
43775 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43776@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43777 if (lis3->pm_dev)
43778 pm_runtime_get_sync(lis3->pm_dev);
43779
43780- atomic_set(&lis3->count, 0);
43781+ atomic_set_unchecked(&lis3->count, 0);
43782 return 0;
43783 }
43784
43785@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43786 add_wait_queue(&lis3->misc_wait, &wait);
43787 while (true) {
43788 set_current_state(TASK_INTERRUPTIBLE);
43789- data = atomic_xchg(&lis3->count, 0);
43790+ data = atomic_xchg_unchecked(&lis3->count, 0);
43791 if (data)
43792 break;
43793
43794@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43795 struct lis3lv02d, miscdev);
43796
43797 poll_wait(file, &lis3->misc_wait, wait);
43798- if (atomic_read(&lis3->count))
43799+ if (atomic_read_unchecked(&lis3->count))
43800 return POLLIN | POLLRDNORM;
43801 return 0;
43802 }
43803diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43804index c439c82..1f20f57 100644
43805--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43806+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43807@@ -297,7 +297,7 @@ struct lis3lv02d {
43808 struct input_polled_dev *idev; /* input device */
43809 struct platform_device *pdev; /* platform device */
43810 struct regulator_bulk_data regulators[2];
43811- atomic_t count; /* interrupt count after last read */
43812+ atomic_unchecked_t count; /* interrupt count after last read */
43813 union axis_conversion ac; /* hw -> logical axis */
43814 int mapped_btns[3];
43815
43816diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43817index 2f30bad..c4c13d0 100644
43818--- a/drivers/misc/sgi-gru/gruhandles.c
43819+++ b/drivers/misc/sgi-gru/gruhandles.c
43820@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43821 unsigned long nsec;
43822
43823 nsec = CLKS2NSEC(clks);
43824- atomic_long_inc(&mcs_op_statistics[op].count);
43825- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43826+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43827+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43828 if (mcs_op_statistics[op].max < nsec)
43829 mcs_op_statistics[op].max = nsec;
43830 }
43831diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43832index 4f76359..cdfcb2e 100644
43833--- a/drivers/misc/sgi-gru/gruprocfs.c
43834+++ b/drivers/misc/sgi-gru/gruprocfs.c
43835@@ -32,9 +32,9 @@
43836
43837 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43838
43839-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43840+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43841 {
43842- unsigned long val = atomic_long_read(v);
43843+ unsigned long val = atomic_long_read_unchecked(v);
43844
43845 seq_printf(s, "%16lu %s\n", val, id);
43846 }
43847@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43848
43849 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43850 for (op = 0; op < mcsop_last; op++) {
43851- count = atomic_long_read(&mcs_op_statistics[op].count);
43852- total = atomic_long_read(&mcs_op_statistics[op].total);
43853+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43854+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43855 max = mcs_op_statistics[op].max;
43856 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43857 count ? total / count : 0, max);
43858diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43859index 5c3ce24..4915ccb 100644
43860--- a/drivers/misc/sgi-gru/grutables.h
43861+++ b/drivers/misc/sgi-gru/grutables.h
43862@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43863 * GRU statistics.
43864 */
43865 struct gru_stats_s {
43866- atomic_long_t vdata_alloc;
43867- atomic_long_t vdata_free;
43868- atomic_long_t gts_alloc;
43869- atomic_long_t gts_free;
43870- atomic_long_t gms_alloc;
43871- atomic_long_t gms_free;
43872- atomic_long_t gts_double_allocate;
43873- atomic_long_t assign_context;
43874- atomic_long_t assign_context_failed;
43875- atomic_long_t free_context;
43876- atomic_long_t load_user_context;
43877- atomic_long_t load_kernel_context;
43878- atomic_long_t lock_kernel_context;
43879- atomic_long_t unlock_kernel_context;
43880- atomic_long_t steal_user_context;
43881- atomic_long_t steal_kernel_context;
43882- atomic_long_t steal_context_failed;
43883- atomic_long_t nopfn;
43884- atomic_long_t asid_new;
43885- atomic_long_t asid_next;
43886- atomic_long_t asid_wrap;
43887- atomic_long_t asid_reuse;
43888- atomic_long_t intr;
43889- atomic_long_t intr_cbr;
43890- atomic_long_t intr_tfh;
43891- atomic_long_t intr_spurious;
43892- atomic_long_t intr_mm_lock_failed;
43893- atomic_long_t call_os;
43894- atomic_long_t call_os_wait_queue;
43895- atomic_long_t user_flush_tlb;
43896- atomic_long_t user_unload_context;
43897- atomic_long_t user_exception;
43898- atomic_long_t set_context_option;
43899- atomic_long_t check_context_retarget_intr;
43900- atomic_long_t check_context_unload;
43901- atomic_long_t tlb_dropin;
43902- atomic_long_t tlb_preload_page;
43903- atomic_long_t tlb_dropin_fail_no_asid;
43904- atomic_long_t tlb_dropin_fail_upm;
43905- atomic_long_t tlb_dropin_fail_invalid;
43906- atomic_long_t tlb_dropin_fail_range_active;
43907- atomic_long_t tlb_dropin_fail_idle;
43908- atomic_long_t tlb_dropin_fail_fmm;
43909- atomic_long_t tlb_dropin_fail_no_exception;
43910- atomic_long_t tfh_stale_on_fault;
43911- atomic_long_t mmu_invalidate_range;
43912- atomic_long_t mmu_invalidate_page;
43913- atomic_long_t flush_tlb;
43914- atomic_long_t flush_tlb_gru;
43915- atomic_long_t flush_tlb_gru_tgh;
43916- atomic_long_t flush_tlb_gru_zero_asid;
43917+ atomic_long_unchecked_t vdata_alloc;
43918+ atomic_long_unchecked_t vdata_free;
43919+ atomic_long_unchecked_t gts_alloc;
43920+ atomic_long_unchecked_t gts_free;
43921+ atomic_long_unchecked_t gms_alloc;
43922+ atomic_long_unchecked_t gms_free;
43923+ atomic_long_unchecked_t gts_double_allocate;
43924+ atomic_long_unchecked_t assign_context;
43925+ atomic_long_unchecked_t assign_context_failed;
43926+ atomic_long_unchecked_t free_context;
43927+ atomic_long_unchecked_t load_user_context;
43928+ atomic_long_unchecked_t load_kernel_context;
43929+ atomic_long_unchecked_t lock_kernel_context;
43930+ atomic_long_unchecked_t unlock_kernel_context;
43931+ atomic_long_unchecked_t steal_user_context;
43932+ atomic_long_unchecked_t steal_kernel_context;
43933+ atomic_long_unchecked_t steal_context_failed;
43934+ atomic_long_unchecked_t nopfn;
43935+ atomic_long_unchecked_t asid_new;
43936+ atomic_long_unchecked_t asid_next;
43937+ atomic_long_unchecked_t asid_wrap;
43938+ atomic_long_unchecked_t asid_reuse;
43939+ atomic_long_unchecked_t intr;
43940+ atomic_long_unchecked_t intr_cbr;
43941+ atomic_long_unchecked_t intr_tfh;
43942+ atomic_long_unchecked_t intr_spurious;
43943+ atomic_long_unchecked_t intr_mm_lock_failed;
43944+ atomic_long_unchecked_t call_os;
43945+ atomic_long_unchecked_t call_os_wait_queue;
43946+ atomic_long_unchecked_t user_flush_tlb;
43947+ atomic_long_unchecked_t user_unload_context;
43948+ atomic_long_unchecked_t user_exception;
43949+ atomic_long_unchecked_t set_context_option;
43950+ atomic_long_unchecked_t check_context_retarget_intr;
43951+ atomic_long_unchecked_t check_context_unload;
43952+ atomic_long_unchecked_t tlb_dropin;
43953+ atomic_long_unchecked_t tlb_preload_page;
43954+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43955+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43956+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43957+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43958+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43959+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43960+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43961+ atomic_long_unchecked_t tfh_stale_on_fault;
43962+ atomic_long_unchecked_t mmu_invalidate_range;
43963+ atomic_long_unchecked_t mmu_invalidate_page;
43964+ atomic_long_unchecked_t flush_tlb;
43965+ atomic_long_unchecked_t flush_tlb_gru;
43966+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43967+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43968
43969- atomic_long_t copy_gpa;
43970- atomic_long_t read_gpa;
43971+ atomic_long_unchecked_t copy_gpa;
43972+ atomic_long_unchecked_t read_gpa;
43973
43974- atomic_long_t mesq_receive;
43975- atomic_long_t mesq_receive_none;
43976- atomic_long_t mesq_send;
43977- atomic_long_t mesq_send_failed;
43978- atomic_long_t mesq_noop;
43979- atomic_long_t mesq_send_unexpected_error;
43980- atomic_long_t mesq_send_lb_overflow;
43981- atomic_long_t mesq_send_qlimit_reached;
43982- atomic_long_t mesq_send_amo_nacked;
43983- atomic_long_t mesq_send_put_nacked;
43984- atomic_long_t mesq_page_overflow;
43985- atomic_long_t mesq_qf_locked;
43986- atomic_long_t mesq_qf_noop_not_full;
43987- atomic_long_t mesq_qf_switch_head_failed;
43988- atomic_long_t mesq_qf_unexpected_error;
43989- atomic_long_t mesq_noop_unexpected_error;
43990- atomic_long_t mesq_noop_lb_overflow;
43991- atomic_long_t mesq_noop_qlimit_reached;
43992- atomic_long_t mesq_noop_amo_nacked;
43993- atomic_long_t mesq_noop_put_nacked;
43994- atomic_long_t mesq_noop_page_overflow;
43995+ atomic_long_unchecked_t mesq_receive;
43996+ atomic_long_unchecked_t mesq_receive_none;
43997+ atomic_long_unchecked_t mesq_send;
43998+ atomic_long_unchecked_t mesq_send_failed;
43999+ atomic_long_unchecked_t mesq_noop;
44000+ atomic_long_unchecked_t mesq_send_unexpected_error;
44001+ atomic_long_unchecked_t mesq_send_lb_overflow;
44002+ atomic_long_unchecked_t mesq_send_qlimit_reached;
44003+ atomic_long_unchecked_t mesq_send_amo_nacked;
44004+ atomic_long_unchecked_t mesq_send_put_nacked;
44005+ atomic_long_unchecked_t mesq_page_overflow;
44006+ atomic_long_unchecked_t mesq_qf_locked;
44007+ atomic_long_unchecked_t mesq_qf_noop_not_full;
44008+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
44009+ atomic_long_unchecked_t mesq_qf_unexpected_error;
44010+ atomic_long_unchecked_t mesq_noop_unexpected_error;
44011+ atomic_long_unchecked_t mesq_noop_lb_overflow;
44012+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
44013+ atomic_long_unchecked_t mesq_noop_amo_nacked;
44014+ atomic_long_unchecked_t mesq_noop_put_nacked;
44015+ atomic_long_unchecked_t mesq_noop_page_overflow;
44016
44017 };
44018
44019@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44020 tghop_invalidate, mcsop_last};
44021
44022 struct mcs_op_statistic {
44023- atomic_long_t count;
44024- atomic_long_t total;
44025+ atomic_long_unchecked_t count;
44026+ atomic_long_unchecked_t total;
44027 unsigned long max;
44028 };
44029
44030@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44031
44032 #define STAT(id) do { \
44033 if (gru_options & OPT_STATS) \
44034- atomic_long_inc(&gru_stats.id); \
44035+ atomic_long_inc_unchecked(&gru_stats.id); \
44036 } while (0)
44037
44038 #ifdef CONFIG_SGI_GRU_DEBUG
44039diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44040index c862cd4..0d176fe 100644
44041--- a/drivers/misc/sgi-xp/xp.h
44042+++ b/drivers/misc/sgi-xp/xp.h
44043@@ -288,7 +288,7 @@ struct xpc_interface {
44044 xpc_notify_func, void *);
44045 void (*received) (short, int, void *);
44046 enum xp_retval (*partid_to_nasids) (short, void *);
44047-};
44048+} __no_const;
44049
44050 extern struct xpc_interface xpc_interface;
44051
44052diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44053index b94d5f7..7f494c5 100644
44054--- a/drivers/misc/sgi-xp/xpc.h
44055+++ b/drivers/misc/sgi-xp/xpc.h
44056@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44057 void (*received_payload) (struct xpc_channel *, void *);
44058 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44059 };
44060+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44061
44062 /* struct xpc_partition act_state values (for XPC HB) */
44063
44064@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44065 /* found in xpc_main.c */
44066 extern struct device *xpc_part;
44067 extern struct device *xpc_chan;
44068-extern struct xpc_arch_operations xpc_arch_ops;
44069+extern xpc_arch_operations_no_const xpc_arch_ops;
44070 extern int xpc_disengage_timelimit;
44071 extern int xpc_disengage_timedout;
44072 extern int xpc_activate_IRQ_rcvd;
44073diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44074index 82dc574..8539ab2 100644
44075--- a/drivers/misc/sgi-xp/xpc_main.c
44076+++ b/drivers/misc/sgi-xp/xpc_main.c
44077@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44078 .notifier_call = xpc_system_die,
44079 };
44080
44081-struct xpc_arch_operations xpc_arch_ops;
44082+xpc_arch_operations_no_const xpc_arch_ops;
44083
44084 /*
44085 * Timer function to enforce the timelimit on the partition disengage.
44086@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44087
44088 if (((die_args->trapnr == X86_TRAP_MF) ||
44089 (die_args->trapnr == X86_TRAP_XF)) &&
44090- !user_mode_vm(die_args->regs))
44091+ !user_mode(die_args->regs))
44092 xpc_die_deactivate();
44093
44094 break;
44095diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44096index 837fc73..acb5862 100644
44097--- a/drivers/mmc/core/mmc_ops.c
44098+++ b/drivers/mmc/core/mmc_ops.c
44099@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44100 void *data_buf;
44101 int is_on_stack;
44102
44103- is_on_stack = object_is_on_stack(buf);
44104+ is_on_stack = object_starts_on_stack(buf);
44105 if (is_on_stack) {
44106 /*
44107 * dma onto stack is unsafe/nonportable, but callers to this
44108diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44109index 81b2994..dce857e 100644
44110--- a/drivers/mmc/host/dw_mmc.h
44111+++ b/drivers/mmc/host/dw_mmc.h
44112@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44113 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44114 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44115 int (*parse_dt)(struct dw_mci *host);
44116-};
44117+} __do_const;
44118 #endif /* _DW_MMC_H_ */
44119diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44120index c3785ed..1984c44 100644
44121--- a/drivers/mmc/host/mmci.c
44122+++ b/drivers/mmc/host/mmci.c
44123@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
44124 }
44125
44126 if (variant->busy_detect) {
44127- mmci_ops.card_busy = mmci_card_busy;
44128+ pax_open_kernel();
44129+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44130+ pax_close_kernel();
44131 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44132 }
44133
44134diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44135index 926aaf6..8e153e2 100644
44136--- a/drivers/mmc/host/sdhci-s3c.c
44137+++ b/drivers/mmc/host/sdhci-s3c.c
44138@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44139 * we can use overriding functions instead of default.
44140 */
44141 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44142- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44143- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44144- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44145+ pax_open_kernel();
44146+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44147+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44148+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44149+ pax_close_kernel();
44150 }
44151
44152 /* It supports additional host capabilities if needed */
44153diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44154index 0c8bb6b..6f35deb 100644
44155--- a/drivers/mtd/nand/denali.c
44156+++ b/drivers/mtd/nand/denali.c
44157@@ -24,6 +24,7 @@
44158 #include <linux/slab.h>
44159 #include <linux/mtd/mtd.h>
44160 #include <linux/module.h>
44161+#include <linux/slab.h>
44162
44163 #include "denali.h"
44164
44165diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44166index 51b9d6a..52af9a7 100644
44167--- a/drivers/mtd/nftlmount.c
44168+++ b/drivers/mtd/nftlmount.c
44169@@ -24,6 +24,7 @@
44170 #include <asm/errno.h>
44171 #include <linux/delay.h>
44172 #include <linux/slab.h>
44173+#include <linux/sched.h>
44174 #include <linux/mtd/mtd.h>
44175 #include <linux/mtd/nand.h>
44176 #include <linux/mtd/nftl.h>
44177diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44178index f9d5615..99dd95f 100644
44179--- a/drivers/mtd/sm_ftl.c
44180+++ b/drivers/mtd/sm_ftl.c
44181@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44182 #define SM_CIS_VENDOR_OFFSET 0x59
44183 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44184 {
44185- struct attribute_group *attr_group;
44186+ attribute_group_no_const *attr_group;
44187 struct attribute **attributes;
44188 struct sm_sysfs_attribute *vendor_attribute;
44189
44190diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44191index e48cb33..72e73fc 100644
44192--- a/drivers/net/bonding/bond_main.c
44193+++ b/drivers/net/bonding/bond_main.c
44194@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
44195 return tx_queues;
44196 }
44197
44198-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44199+static struct rtnl_link_ops bond_link_ops = {
44200 .kind = "bond",
44201 .priv_size = sizeof(struct bonding),
44202 .setup = bond_setup,
44203@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
44204
44205 bond_destroy_debugfs();
44206
44207- rtnl_link_unregister(&bond_link_ops);
44208 unregister_pernet_subsys(&bond_net_ops);
44209+ rtnl_link_unregister(&bond_link_ops);
44210
44211 #ifdef CONFIG_NET_POLL_CONTROLLER
44212 /*
44213diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44214index e1d2643..7f4133b 100644
44215--- a/drivers/net/ethernet/8390/ax88796.c
44216+++ b/drivers/net/ethernet/8390/ax88796.c
44217@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44218 if (ax->plat->reg_offsets)
44219 ei_local->reg_offset = ax->plat->reg_offsets;
44220 else {
44221+ resource_size_t _mem_size = mem_size;
44222+ do_div(_mem_size, 0x18);
44223 ei_local->reg_offset = ax->reg_offsets;
44224 for (ret = 0; ret < 0x18; ret++)
44225- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44226+ ax->reg_offsets[ret] = _mem_size * ret;
44227 }
44228
44229 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44230diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44231index c07a6d0..ca88c45 100644
44232--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44233+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44234@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44235 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44236 {
44237 /* RX_MODE controlling object */
44238- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44239+ bnx2x_init_rx_mode_obj(bp);
44240
44241 /* multicast configuration controlling object */
44242 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44243diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44244index 8f03c98..dd0ef10 100644
44245--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44246+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44247@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44248 return rc;
44249 }
44250
44251-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44252- struct bnx2x_rx_mode_obj *o)
44253+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44254 {
44255 if (CHIP_IS_E1x(bp)) {
44256- o->wait_comp = bnx2x_empty_rx_mode_wait;
44257- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44258+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44259+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44260 } else {
44261- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44262- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44263+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44264+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44265 }
44266 }
44267
44268diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44269index 798dfe9..05d0a44 100644
44270--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44271+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44272@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44273
44274 /********************* RX MODE ****************/
44275
44276-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44277- struct bnx2x_rx_mode_obj *o);
44278+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44279
44280 /**
44281 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44282diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44283index cd63d11..b67dd78 100644
44284--- a/drivers/net/ethernet/broadcom/tg3.h
44285+++ b/drivers/net/ethernet/broadcom/tg3.h
44286@@ -147,6 +147,7 @@
44287 #define CHIPREV_ID_5750_A0 0x4000
44288 #define CHIPREV_ID_5750_A1 0x4001
44289 #define CHIPREV_ID_5750_A3 0x4003
44290+#define CHIPREV_ID_5750_C1 0x4201
44291 #define CHIPREV_ID_5750_C2 0x4202
44292 #define CHIPREV_ID_5752_A0_HW 0x5000
44293 #define CHIPREV_ID_5752_A0 0x6000
44294diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44295index 8cffcdf..aadf043 100644
44296--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44297+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44298@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44299 */
44300 struct l2t_skb_cb {
44301 arp_failure_handler_func arp_failure_handler;
44302-};
44303+} __no_const;
44304
44305 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44306
44307diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44308index 9c89dc8..725ecc3 100644
44309--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
44310+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44311@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
44312 flits = skb_transport_offset(skb) / 8;
44313 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
44314 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
44315- skb->tail - skb->transport_header,
44316+ skb_tail_pointer(skb) - skb_transport_header(skb),
44317 adap->pdev);
44318 if (need_skb_unmap()) {
44319 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
44320diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44321index 4c83003..2a2a5b9 100644
44322--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44323+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44324@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44325 for (i=0; i<ETH_ALEN; i++) {
44326 tmp.addr[i] = dev->dev_addr[i];
44327 }
44328- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44329+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44330 break;
44331
44332 case DE4X5_SET_HWADDR: /* Set the hardware address */
44333@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44334 spin_lock_irqsave(&lp->lock, flags);
44335 memcpy(&statbuf, &lp->pktStats, ioc->len);
44336 spin_unlock_irqrestore(&lp->lock, flags);
44337- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44338+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44339 return -EFAULT;
44340 break;
44341 }
44342diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44343index 3d91a5e..1014702 100644
44344--- a/drivers/net/ethernet/emulex/benet/be_main.c
44345+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44346@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44347
44348 if (wrapped)
44349 newacc += 65536;
44350- ACCESS_ONCE(*acc) = newacc;
44351+ ACCESS_ONCE_RW(*acc) = newacc;
44352 }
44353
44354 void populate_erx_stats(struct be_adapter *adapter,
44355diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44356index 934e1ae..b262e6b 100644
44357--- a/drivers/net/ethernet/faraday/ftgmac100.c
44358+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44359@@ -31,6 +31,8 @@
44360 #include <linux/netdevice.h>
44361 #include <linux/phy.h>
44362 #include <linux/platform_device.h>
44363+#include <linux/interrupt.h>
44364+#include <linux/irqreturn.h>
44365 #include <net/ip.h>
44366
44367 #include "ftgmac100.h"
44368diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44369index 4658f4c..407d155 100644
44370--- a/drivers/net/ethernet/faraday/ftmac100.c
44371+++ b/drivers/net/ethernet/faraday/ftmac100.c
44372@@ -31,6 +31,8 @@
44373 #include <linux/module.h>
44374 #include <linux/netdevice.h>
44375 #include <linux/platform_device.h>
44376+#include <linux/interrupt.h>
44377+#include <linux/irqreturn.h>
44378
44379 #include "ftmac100.h"
44380
44381diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44382index 331987d..3be1135 100644
44383--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44384+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44385@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44386 }
44387
44388 /* update the base incval used to calculate frequency adjustment */
44389- ACCESS_ONCE(adapter->base_incval) = incval;
44390+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44391 smp_mb();
44392
44393 /* need lock to prevent incorrect read while modifying cyclecounter */
44394diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44395index fbe5363..266b4e3 100644
44396--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44397+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44398@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44399 struct __vxge_hw_fifo *fifo;
44400 struct vxge_hw_fifo_config *config;
44401 u32 txdl_size, txdl_per_memblock;
44402- struct vxge_hw_mempool_cbs fifo_mp_callback;
44403+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44404+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44405+ };
44406+
44407 struct __vxge_hw_virtualpath *vpath;
44408
44409 if ((vp == NULL) || (attr == NULL)) {
44410@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44411 goto exit;
44412 }
44413
44414- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44415-
44416 fifo->mempool =
44417 __vxge_hw_mempool_create(vpath->hldev,
44418 fifo->config->memblock_size,
44419diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44420index 345d987..af69721 100644
44421--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44422+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44423@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44424 op_mode = QLC_83XX_DEFAULT_OPMODE;
44425
44426 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44427- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44428+ pax_open_kernel();
44429+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44430+ pax_close_kernel();
44431 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44432 } else {
44433 return -EIO;
44434diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44435index 599d1fd..59868fe 100644
44436--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44437+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44438@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44439 case QLCNIC_NON_PRIV_FUNC:
44440 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44441 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44442- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44443+ pax_open_kernel();
44444+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44445+ pax_close_kernel();
44446 break;
44447 case QLCNIC_PRIV_FUNC:
44448 ahw->op_mode = QLCNIC_PRIV_FUNC;
44449 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44450- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44451+ pax_open_kernel();
44452+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44453+ pax_close_kernel();
44454 break;
44455 case QLCNIC_MGMT_FUNC:
44456 ahw->op_mode = QLCNIC_MGMT_FUNC;
44457 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44458- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44459+ pax_open_kernel();
44460+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44461+ pax_close_kernel();
44462 break;
44463 default:
44464 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44465diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44466index 85e5c97..76f97ec 100644
44467--- a/drivers/net/ethernet/realtek/r8169.c
44468+++ b/drivers/net/ethernet/realtek/r8169.c
44469@@ -759,22 +759,22 @@ struct rtl8169_private {
44470 struct mdio_ops {
44471 void (*write)(struct rtl8169_private *, int, int);
44472 int (*read)(struct rtl8169_private *, int);
44473- } mdio_ops;
44474+ } __no_const mdio_ops;
44475
44476 struct pll_power_ops {
44477 void (*down)(struct rtl8169_private *);
44478 void (*up)(struct rtl8169_private *);
44479- } pll_power_ops;
44480+ } __no_const pll_power_ops;
44481
44482 struct jumbo_ops {
44483 void (*enable)(struct rtl8169_private *);
44484 void (*disable)(struct rtl8169_private *);
44485- } jumbo_ops;
44486+ } __no_const jumbo_ops;
44487
44488 struct csi_ops {
44489 void (*write)(struct rtl8169_private *, int, int);
44490 u32 (*read)(struct rtl8169_private *, int);
44491- } csi_ops;
44492+ } __no_const csi_ops;
44493
44494 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44495 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44496diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44497index b495394..0748c54 100644
44498--- a/drivers/net/ethernet/sfc/ptp.c
44499+++ b/drivers/net/ethernet/sfc/ptp.c
44500@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44501 (u32)((u64)ptp->start.dma_addr >> 32));
44502
44503 /* Clear flag that signals MC ready */
44504- ACCESS_ONCE(*start) = 0;
44505+ ACCESS_ONCE_RW(*start) = 0;
44506 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44507 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44508
44509diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44510index 50617c5..b13724c 100644
44511--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44512+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44513@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44514
44515 writel(value, ioaddr + MMC_CNTRL);
44516
44517- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44518- MMC_CNTRL, value);
44519+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44520+// MMC_CNTRL, value);
44521 }
44522
44523 /* To mask all all interrupts.*/
44524diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44525index e6fe0d8..2b7d752 100644
44526--- a/drivers/net/hyperv/hyperv_net.h
44527+++ b/drivers/net/hyperv/hyperv_net.h
44528@@ -101,7 +101,7 @@ struct rndis_device {
44529
44530 enum rndis_device_state state;
44531 bool link_state;
44532- atomic_t new_req_id;
44533+ atomic_unchecked_t new_req_id;
44534
44535 spinlock_t request_lock;
44536 struct list_head req_list;
44537diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44538index 0775f0a..d4fb316 100644
44539--- a/drivers/net/hyperv/rndis_filter.c
44540+++ b/drivers/net/hyperv/rndis_filter.c
44541@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44542 * template
44543 */
44544 set = &rndis_msg->msg.set_req;
44545- set->req_id = atomic_inc_return(&dev->new_req_id);
44546+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44547
44548 /* Add to the request list */
44549 spin_lock_irqsave(&dev->request_lock, flags);
44550@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44551
44552 /* Setup the rndis set */
44553 halt = &request->request_msg.msg.halt_req;
44554- halt->req_id = atomic_inc_return(&dev->new_req_id);
44555+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44556
44557 /* Ignore return since this msg is optional. */
44558 rndis_filter_send_request(dev, request);
44559diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44560index bf0d55e..82bcfbd1 100644
44561--- a/drivers/net/ieee802154/fakehard.c
44562+++ b/drivers/net/ieee802154/fakehard.c
44563@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44564 phy->transmit_power = 0xbf;
44565
44566 dev->netdev_ops = &fake_ops;
44567- dev->ml_priv = &fake_mlme;
44568+ dev->ml_priv = (void *)&fake_mlme;
44569
44570 priv = netdev_priv(dev);
44571 priv->phy = phy;
44572diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44573index 16b43bf..ead0c35 100644
44574--- a/drivers/net/macvlan.c
44575+++ b/drivers/net/macvlan.c
44576@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44577 int macvlan_link_register(struct rtnl_link_ops *ops)
44578 {
44579 /* common fields */
44580- ops->priv_size = sizeof(struct macvlan_dev);
44581- ops->validate = macvlan_validate;
44582- ops->maxtype = IFLA_MACVLAN_MAX;
44583- ops->policy = macvlan_policy;
44584- ops->changelink = macvlan_changelink;
44585- ops->get_size = macvlan_get_size;
44586- ops->fill_info = macvlan_fill_info;
44587+ pax_open_kernel();
44588+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44589+ *(void **)&ops->validate = macvlan_validate;
44590+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44591+ *(const void **)&ops->policy = macvlan_policy;
44592+ *(void **)&ops->changelink = macvlan_changelink;
44593+ *(void **)&ops->get_size = macvlan_get_size;
44594+ *(void **)&ops->fill_info = macvlan_fill_info;
44595+ pax_close_kernel();
44596
44597 return rtnl_link_register(ops);
44598 };
44599@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44600 return NOTIFY_DONE;
44601 }
44602
44603-static struct notifier_block macvlan_notifier_block __read_mostly = {
44604+static struct notifier_block macvlan_notifier_block = {
44605 .notifier_call = macvlan_device_event,
44606 };
44607
44608diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44609index ea53abb..2e4d087 100644
44610--- a/drivers/net/macvtap.c
44611+++ b/drivers/net/macvtap.c
44612@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44613 return NOTIFY_DONE;
44614 }
44615
44616-static struct notifier_block macvtap_notifier_block __read_mostly = {
44617+static struct notifier_block macvtap_notifier_block = {
44618 .notifier_call = macvtap_device_event,
44619 };
44620
44621diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44622index daec9b0..6428fcb 100644
44623--- a/drivers/net/phy/mdio-bitbang.c
44624+++ b/drivers/net/phy/mdio-bitbang.c
44625@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44626 struct mdiobb_ctrl *ctrl = bus->priv;
44627
44628 module_put(ctrl->ops->owner);
44629+ mdiobus_unregister(bus);
44630 mdiobus_free(bus);
44631 }
44632 EXPORT_SYMBOL(free_mdio_bitbang);
44633diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44634index 72ff14b..11d442d 100644
44635--- a/drivers/net/ppp/ppp_generic.c
44636+++ b/drivers/net/ppp/ppp_generic.c
44637@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44638 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44639 struct ppp_stats stats;
44640 struct ppp_comp_stats cstats;
44641- char *vers;
44642
44643 switch (cmd) {
44644 case SIOCGPPPSTATS:
44645@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44646 break;
44647
44648 case SIOCGPPPVER:
44649- vers = PPP_VERSION;
44650- if (copy_to_user(addr, vers, strlen(vers) + 1))
44651+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44652 break;
44653 err = 0;
44654 break;
44655diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44656index 1252d9c..80e660b 100644
44657--- a/drivers/net/slip/slhc.c
44658+++ b/drivers/net/slip/slhc.c
44659@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44660 register struct tcphdr *thp;
44661 register struct iphdr *ip;
44662 register struct cstate *cs;
44663- int len, hdrlen;
44664+ long len, hdrlen;
44665 unsigned char *cp = icp;
44666
44667 /* We've got a compressed packet; read the change byte */
44668diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44669index bff7e0b..7315137 100644
44670--- a/drivers/net/team/team.c
44671+++ b/drivers/net/team/team.c
44672@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44673 return NOTIFY_DONE;
44674 }
44675
44676-static struct notifier_block team_notifier_block __read_mostly = {
44677+static struct notifier_block team_notifier_block = {
44678 .notifier_call = team_device_event,
44679 };
44680
44681diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44682index 71af122..b3c20f3 100644
44683--- a/drivers/net/tun.c
44684+++ b/drivers/net/tun.c
44685@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44686 INIT_LIST_HEAD(&tun->disabled);
44687 err = tun_attach(tun, file);
44688 if (err < 0)
44689- goto err_free_dev;
44690+ goto err_free_flow;
44691
44692 err = register_netdevice(tun->dev);
44693 if (err < 0)
44694- goto err_free_dev;
44695+ goto err_detach;
44696
44697 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44698 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44699@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44700 strcpy(ifr->ifr_name, tun->dev->name);
44701 return 0;
44702
44703- err_free_dev:
44704+err_detach:
44705+ tun_detach_all(dev);
44706+err_free_flow:
44707+ tun_flow_uninit(tun);
44708+ security_tun_dev_free_security(tun->security);
44709+err_free_dev:
44710 free_netdev(dev);
44711 return err;
44712 }
44713@@ -1869,7 +1874,7 @@ unlock:
44714 }
44715
44716 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44717- unsigned long arg, int ifreq_len)
44718+ unsigned long arg, size_t ifreq_len)
44719 {
44720 struct tun_file *tfile = file->private_data;
44721 struct tun_struct *tun;
44722@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44723 int vnet_hdr_sz;
44724 int ret;
44725
44726+ if (ifreq_len > sizeof ifr)
44727+ return -EFAULT;
44728+
44729 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44730 if (copy_from_user(&ifr, argp, ifreq_len))
44731 return -EFAULT;
44732diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44733index 86292e6..8d34433 100644
44734--- a/drivers/net/usb/hso.c
44735+++ b/drivers/net/usb/hso.c
44736@@ -71,7 +71,7 @@
44737 #include <asm/byteorder.h>
44738 #include <linux/serial_core.h>
44739 #include <linux/serial.h>
44740-
44741+#include <asm/local.h>
44742
44743 #define MOD_AUTHOR "Option Wireless"
44744 #define MOD_DESCRIPTION "USB High Speed Option driver"
44745@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44746 struct urb *urb;
44747
44748 urb = serial->rx_urb[0];
44749- if (serial->port.count > 0) {
44750+ if (atomic_read(&serial->port.count) > 0) {
44751 count = put_rxbuf_data(urb, serial);
44752 if (count == -1)
44753 return;
44754@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44755 DUMP1(urb->transfer_buffer, urb->actual_length);
44756
44757 /* Anyone listening? */
44758- if (serial->port.count == 0)
44759+ if (atomic_read(&serial->port.count) == 0)
44760 return;
44761
44762 if (status == 0) {
44763@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44764 tty_port_tty_set(&serial->port, tty);
44765
44766 /* check for port already opened, if not set the termios */
44767- serial->port.count++;
44768- if (serial->port.count == 1) {
44769+ if (atomic_inc_return(&serial->port.count) == 1) {
44770 serial->rx_state = RX_IDLE;
44771 /* Force default termio settings */
44772 _hso_serial_set_termios(tty, NULL);
44773@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44774 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44775 if (result) {
44776 hso_stop_serial_device(serial->parent);
44777- serial->port.count--;
44778+ atomic_dec(&serial->port.count);
44779 kref_put(&serial->parent->ref, hso_serial_ref_free);
44780 }
44781 } else {
44782@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44783
44784 /* reset the rts and dtr */
44785 /* do the actual close */
44786- serial->port.count--;
44787+ atomic_dec(&serial->port.count);
44788
44789- if (serial->port.count <= 0) {
44790- serial->port.count = 0;
44791+ if (atomic_read(&serial->port.count) <= 0) {
44792+ atomic_set(&serial->port.count, 0);
44793 tty_port_tty_set(&serial->port, NULL);
44794 if (!usb_gone)
44795 hso_stop_serial_device(serial->parent);
44796@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44797
44798 /* the actual setup */
44799 spin_lock_irqsave(&serial->serial_lock, flags);
44800- if (serial->port.count)
44801+ if (atomic_read(&serial->port.count))
44802 _hso_serial_set_termios(tty, old);
44803 else
44804 tty->termios = *old;
44805@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44806 D1("Pending read interrupt on port %d\n", i);
44807 spin_lock(&serial->serial_lock);
44808 if (serial->rx_state == RX_IDLE &&
44809- serial->port.count > 0) {
44810+ atomic_read(&serial->port.count) > 0) {
44811 /* Setup and send a ctrl req read on
44812 * port i */
44813 if (!serial->rx_urb_filled[0]) {
44814@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44815 /* Start all serial ports */
44816 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44817 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44818- if (dev2ser(serial_table[i])->port.count) {
44819+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44820 result =
44821 hso_start_serial_device(serial_table[i], GFP_NOIO);
44822 hso_kick_transmit(dev2ser(serial_table[i]));
44823diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44824index a79e9d3..78cd4fa 100644
44825--- a/drivers/net/usb/sierra_net.c
44826+++ b/drivers/net/usb/sierra_net.c
44827@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44828 /* atomic counter partially included in MAC address to make sure 2 devices
44829 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44830 */
44831-static atomic_t iface_counter = ATOMIC_INIT(0);
44832+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44833
44834 /*
44835 * SYNC Timer Delay definition used to set the expiry time
44836@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44837 dev->net->netdev_ops = &sierra_net_device_ops;
44838
44839 /* change MAC addr to include, ifacenum, and to be unique */
44840- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44841+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44842 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44843
44844 /* we will have to manufacture ethernet headers, prepare template */
44845diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44846index 767f7af..8162b9d 100644
44847--- a/drivers/net/vxlan.c
44848+++ b/drivers/net/vxlan.c
44849@@ -1868,7 +1868,7 @@ nla_put_failure:
44850 return -EMSGSIZE;
44851 }
44852
44853-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44854+static struct rtnl_link_ops vxlan_link_ops = {
44855 .kind = "vxlan",
44856 .maxtype = IFLA_VXLAN_MAX,
44857 .policy = vxlan_policy,
44858diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44859index 0b60295..b8bfa5b 100644
44860--- a/drivers/net/wimax/i2400m/rx.c
44861+++ b/drivers/net/wimax/i2400m/rx.c
44862@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44863 if (i2400m->rx_roq == NULL)
44864 goto error_roq_alloc;
44865
44866- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44867+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44868 GFP_KERNEL);
44869 if (rd == NULL) {
44870 result = -ENOMEM;
44871diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44872index 34c8a33..3261fdc 100644
44873--- a/drivers/net/wireless/at76c50x-usb.c
44874+++ b/drivers/net/wireless/at76c50x-usb.c
44875@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44876 }
44877
44878 /* Convert timeout from the DFU status to jiffies */
44879-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44880+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44881 {
44882 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44883 | (s->poll_timeout[1] << 8)
44884diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44885index 2b3426b..1f564be 100644
44886--- a/drivers/net/wireless/ath/ath10k/core.c
44887+++ b/drivers/net/wireless/ath/ath10k/core.c
44888@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44889
44890 int ath10k_core_register(struct ath10k *ar)
44891 {
44892- struct ath10k_htc_ops htc_ops;
44893+ static struct ath10k_htc_ops htc_ops = {
44894+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44895+ };
44896 struct bmi_target_info target_info;
44897 int status;
44898
44899@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44900 if (status)
44901 goto err;
44902
44903- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44904-
44905 ar->htc = ath10k_htc_create(ar, &htc_ops);
44906 if (IS_ERR(ar->htc)) {
44907 status = PTR_ERR(ar->htc);
44908diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44909index 74363c9..237b926 100644
44910--- a/drivers/net/wireless/ath/ath10k/htc.c
44911+++ b/drivers/net/wireless/ath/ath10k/htc.c
44912@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44913 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44914 struct ath10k_htc_ops *htc_ops)
44915 {
44916- struct ath10k_hif_cb htc_callbacks;
44917+ static struct ath10k_hif_cb htc_callbacks = {
44918+ .rx_completion = ath10k_htc_rx_completion_handler,
44919+ .tx_completion = ath10k_htc_tx_completion_handler,
44920+ };
44921 struct ath10k_htc_ep *ep = NULL;
44922 struct ath10k_htc *htc = NULL;
44923
44924@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44925 ath10k_htc_reset_endpoint_states(htc);
44926
44927 /* setup HIF layer callbacks */
44928- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44929- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44930 htc->ar = ar;
44931
44932 /* Get HIF default pipe for HTC message exchange */
44933diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44934index 8d78253..bebbb68 100644
44935--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44936+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44937@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44938 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44939 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44940
44941- ACCESS_ONCE(ads->ds_link) = i->link;
44942- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44943+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44944+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44945
44946 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44947 ctl6 = SM(i->keytype, AR_EncrType);
44948@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44949
44950 if ((i->is_first || i->is_last) &&
44951 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44952- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44953+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44954 | set11nTries(i->rates, 1)
44955 | set11nTries(i->rates, 2)
44956 | set11nTries(i->rates, 3)
44957 | (i->dur_update ? AR_DurUpdateEna : 0)
44958 | SM(0, AR_BurstDur);
44959
44960- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44961+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44962 | set11nRate(i->rates, 1)
44963 | set11nRate(i->rates, 2)
44964 | set11nRate(i->rates, 3);
44965 } else {
44966- ACCESS_ONCE(ads->ds_ctl2) = 0;
44967- ACCESS_ONCE(ads->ds_ctl3) = 0;
44968+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44969+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44970 }
44971
44972 if (!i->is_first) {
44973- ACCESS_ONCE(ads->ds_ctl0) = 0;
44974- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44975- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44976+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44977+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44978+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44979 return;
44980 }
44981
44982@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44983 break;
44984 }
44985
44986- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44987+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44988 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44989 | SM(i->txpower, AR_XmitPower)
44990 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44991@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44992 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44993 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44994
44995- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44996- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44997+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44998+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44999
45000 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
45001 return;
45002
45003- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45004+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45005 | set11nPktDurRTSCTS(i->rates, 1);
45006
45007- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45008+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45009 | set11nPktDurRTSCTS(i->rates, 3);
45010
45011- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45012+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45013 | set11nRateFlags(i->rates, 1)
45014 | set11nRateFlags(i->rates, 2)
45015 | set11nRateFlags(i->rates, 3)
45016diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45017index 5163abd..3ada4c2 100644
45018--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45019+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45020@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45021 (i->qcu << AR_TxQcuNum_S) | desc_len;
45022
45023 checksum += val;
45024- ACCESS_ONCE(ads->info) = val;
45025+ ACCESS_ONCE_RW(ads->info) = val;
45026
45027 checksum += i->link;
45028- ACCESS_ONCE(ads->link) = i->link;
45029+ ACCESS_ONCE_RW(ads->link) = i->link;
45030
45031 checksum += i->buf_addr[0];
45032- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
45033+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
45034 checksum += i->buf_addr[1];
45035- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
45036+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
45037 checksum += i->buf_addr[2];
45038- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
45039+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
45040 checksum += i->buf_addr[3];
45041- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45042+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45043
45044 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45045- ACCESS_ONCE(ads->ctl3) = val;
45046+ ACCESS_ONCE_RW(ads->ctl3) = val;
45047 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45048- ACCESS_ONCE(ads->ctl5) = val;
45049+ ACCESS_ONCE_RW(ads->ctl5) = val;
45050 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45051- ACCESS_ONCE(ads->ctl7) = val;
45052+ ACCESS_ONCE_RW(ads->ctl7) = val;
45053 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45054- ACCESS_ONCE(ads->ctl9) = val;
45055+ ACCESS_ONCE_RW(ads->ctl9) = val;
45056
45057 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45058- ACCESS_ONCE(ads->ctl10) = checksum;
45059+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
45060
45061 if (i->is_first || i->is_last) {
45062- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45063+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45064 | set11nTries(i->rates, 1)
45065 | set11nTries(i->rates, 2)
45066 | set11nTries(i->rates, 3)
45067 | (i->dur_update ? AR_DurUpdateEna : 0)
45068 | SM(0, AR_BurstDur);
45069
45070- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45071+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45072 | set11nRate(i->rates, 1)
45073 | set11nRate(i->rates, 2)
45074 | set11nRate(i->rates, 3);
45075 } else {
45076- ACCESS_ONCE(ads->ctl13) = 0;
45077- ACCESS_ONCE(ads->ctl14) = 0;
45078+ ACCESS_ONCE_RW(ads->ctl13) = 0;
45079+ ACCESS_ONCE_RW(ads->ctl14) = 0;
45080 }
45081
45082 ads->ctl20 = 0;
45083@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45084
45085 ctl17 = SM(i->keytype, AR_EncrType);
45086 if (!i->is_first) {
45087- ACCESS_ONCE(ads->ctl11) = 0;
45088- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45089- ACCESS_ONCE(ads->ctl15) = 0;
45090- ACCESS_ONCE(ads->ctl16) = 0;
45091- ACCESS_ONCE(ads->ctl17) = ctl17;
45092- ACCESS_ONCE(ads->ctl18) = 0;
45093- ACCESS_ONCE(ads->ctl19) = 0;
45094+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45095+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45096+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45097+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45098+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45099+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45100+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45101 return;
45102 }
45103
45104- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45105+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45106 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45107 | SM(i->txpower, AR_XmitPower)
45108 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45109@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45110 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45111 ctl12 |= SM(val, AR_PAPRDChainMask);
45112
45113- ACCESS_ONCE(ads->ctl12) = ctl12;
45114- ACCESS_ONCE(ads->ctl17) = ctl17;
45115+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45116+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45117
45118- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45119+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45120 | set11nPktDurRTSCTS(i->rates, 1);
45121
45122- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45123+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45124 | set11nPktDurRTSCTS(i->rates, 3);
45125
45126- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45127+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45128 | set11nRateFlags(i->rates, 1)
45129 | set11nRateFlags(i->rates, 2)
45130 | set11nRateFlags(i->rates, 3)
45131 | SM(i->rtscts_rate, AR_RTSCTSRate);
45132
45133- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45134+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45135 }
45136
45137 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45138diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45139index cd74b3a..6a28d24 100644
45140--- a/drivers/net/wireless/ath/ath9k/hw.h
45141+++ b/drivers/net/wireless/ath/ath9k/hw.h
45142@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45143
45144 /* ANI */
45145 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45146-};
45147+} __no_const;
45148
45149 /**
45150 * struct ath_spec_scan - parameters for Atheros spectral scan
45151@@ -721,7 +721,7 @@ struct ath_hw_ops {
45152 struct ath_spec_scan *param);
45153 void (*spectral_scan_trigger)(struct ath_hw *ah);
45154 void (*spectral_scan_wait)(struct ath_hw *ah);
45155-};
45156+} __no_const;
45157
45158 struct ath_nf_limits {
45159 s16 max;
45160diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45161index 9581d07..84f6a76 100644
45162--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45163+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45164@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45165 */
45166 if (il3945_mod_params.disable_hw_scan) {
45167 D_INFO("Disabling hw_scan\n");
45168- il3945_mac_ops.hw_scan = NULL;
45169+ pax_open_kernel();
45170+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45171+ pax_close_kernel();
45172 }
45173
45174 D_INFO("*** LOAD DRIVER ***\n");
45175diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45176index d532948..e0d8bb1 100644
45177--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45178+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45179@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45180 {
45181 struct iwl_priv *priv = file->private_data;
45182 char buf[64];
45183- int buf_size;
45184+ size_t buf_size;
45185 u32 offset, len;
45186
45187 memset(buf, 0, sizeof(buf));
45188@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45189 struct iwl_priv *priv = file->private_data;
45190
45191 char buf[8];
45192- int buf_size;
45193+ size_t buf_size;
45194 u32 reset_flag;
45195
45196 memset(buf, 0, sizeof(buf));
45197@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45198 {
45199 struct iwl_priv *priv = file->private_data;
45200 char buf[8];
45201- int buf_size;
45202+ size_t buf_size;
45203 int ht40;
45204
45205 memset(buf, 0, sizeof(buf));
45206@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45207 {
45208 struct iwl_priv *priv = file->private_data;
45209 char buf[8];
45210- int buf_size;
45211+ size_t buf_size;
45212 int value;
45213
45214 memset(buf, 0, sizeof(buf));
45215@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45216 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45217 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45218
45219-static const char *fmt_value = " %-30s %10u\n";
45220-static const char *fmt_hex = " %-30s 0x%02X\n";
45221-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45222-static const char *fmt_header =
45223+static const char fmt_value[] = " %-30s %10u\n";
45224+static const char fmt_hex[] = " %-30s 0x%02X\n";
45225+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45226+static const char fmt_header[] =
45227 "%-32s current cumulative delta max\n";
45228
45229 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45230@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45231 {
45232 struct iwl_priv *priv = file->private_data;
45233 char buf[8];
45234- int buf_size;
45235+ size_t buf_size;
45236 int clear;
45237
45238 memset(buf, 0, sizeof(buf));
45239@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45240 {
45241 struct iwl_priv *priv = file->private_data;
45242 char buf[8];
45243- int buf_size;
45244+ size_t buf_size;
45245 int trace;
45246
45247 memset(buf, 0, sizeof(buf));
45248@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45249 {
45250 struct iwl_priv *priv = file->private_data;
45251 char buf[8];
45252- int buf_size;
45253+ size_t buf_size;
45254 int missed;
45255
45256 memset(buf, 0, sizeof(buf));
45257@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45258
45259 struct iwl_priv *priv = file->private_data;
45260 char buf[8];
45261- int buf_size;
45262+ size_t buf_size;
45263 int plcp;
45264
45265 memset(buf, 0, sizeof(buf));
45266@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45267
45268 struct iwl_priv *priv = file->private_data;
45269 char buf[8];
45270- int buf_size;
45271+ size_t buf_size;
45272 int flush;
45273
45274 memset(buf, 0, sizeof(buf));
45275@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45276
45277 struct iwl_priv *priv = file->private_data;
45278 char buf[8];
45279- int buf_size;
45280+ size_t buf_size;
45281 int rts;
45282
45283 if (!priv->cfg->ht_params)
45284@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45285 {
45286 struct iwl_priv *priv = file->private_data;
45287 char buf[8];
45288- int buf_size;
45289+ size_t buf_size;
45290
45291 memset(buf, 0, sizeof(buf));
45292 buf_size = min(count, sizeof(buf) - 1);
45293@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45294 struct iwl_priv *priv = file->private_data;
45295 u32 event_log_flag;
45296 char buf[8];
45297- int buf_size;
45298+ size_t buf_size;
45299
45300 /* check that the interface is up */
45301 if (!iwl_is_ready(priv))
45302@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45303 struct iwl_priv *priv = file->private_data;
45304 char buf[8];
45305 u32 calib_disabled;
45306- int buf_size;
45307+ size_t buf_size;
45308
45309 memset(buf, 0, sizeof(buf));
45310 buf_size = min(count, sizeof(buf) - 1);
45311diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45312index 1531a4f..21d2641 100644
45313--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45314+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45315@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45316 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45317 {
45318 struct iwl_nvm_data *data = priv->nvm_data;
45319- char *debug_msg;
45320+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45321
45322 if (data->sku_cap_11n_enable &&
45323 !priv->cfg->ht_params) {
45324@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45325 return -EINVAL;
45326 }
45327
45328- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45329 IWL_DEBUG_INFO(priv, debug_msg,
45330 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45331 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45332diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45333index 390e2f0..75cfbaf 100644
45334--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45335+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45336@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45337 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45338
45339 char buf[8];
45340- int buf_size;
45341+ size_t buf_size;
45342 u32 reset_flag;
45343
45344 memset(buf, 0, sizeof(buf));
45345@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45346 {
45347 struct iwl_trans *trans = file->private_data;
45348 char buf[8];
45349- int buf_size;
45350+ size_t buf_size;
45351 int csr;
45352
45353 memset(buf, 0, sizeof(buf));
45354diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45355index cb34c78..9fec0dc 100644
45356--- a/drivers/net/wireless/mac80211_hwsim.c
45357+++ b/drivers/net/wireless/mac80211_hwsim.c
45358@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45359
45360 if (channels > 1) {
45361 hwsim_if_comb.num_different_channels = channels;
45362- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45363- mac80211_hwsim_ops.cancel_hw_scan =
45364- mac80211_hwsim_cancel_hw_scan;
45365- mac80211_hwsim_ops.sw_scan_start = NULL;
45366- mac80211_hwsim_ops.sw_scan_complete = NULL;
45367- mac80211_hwsim_ops.remain_on_channel =
45368- mac80211_hwsim_roc;
45369- mac80211_hwsim_ops.cancel_remain_on_channel =
45370- mac80211_hwsim_croc;
45371- mac80211_hwsim_ops.add_chanctx =
45372- mac80211_hwsim_add_chanctx;
45373- mac80211_hwsim_ops.remove_chanctx =
45374- mac80211_hwsim_remove_chanctx;
45375- mac80211_hwsim_ops.change_chanctx =
45376- mac80211_hwsim_change_chanctx;
45377- mac80211_hwsim_ops.assign_vif_chanctx =
45378- mac80211_hwsim_assign_vif_chanctx;
45379- mac80211_hwsim_ops.unassign_vif_chanctx =
45380- mac80211_hwsim_unassign_vif_chanctx;
45381+ pax_open_kernel();
45382+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45383+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45384+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45385+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45386+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45387+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45388+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45389+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45390+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45391+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45392+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45393+ pax_close_kernel();
45394 }
45395
45396 spin_lock_init(&hwsim_radio_lock);
45397diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45398index 8169a85..7fa3b47 100644
45399--- a/drivers/net/wireless/rndis_wlan.c
45400+++ b/drivers/net/wireless/rndis_wlan.c
45401@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45402
45403 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45404
45405- if (rts_threshold < 0 || rts_threshold > 2347)
45406+ if (rts_threshold > 2347)
45407 rts_threshold = 2347;
45408
45409 tmp = cpu_to_le32(rts_threshold);
45410diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45411index ee3fc57..ed5ddc9 100644
45412--- a/drivers/net/wireless/rt2x00/rt2x00.h
45413+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45414@@ -386,7 +386,7 @@ struct rt2x00_intf {
45415 * for hardware which doesn't support hardware
45416 * sequence counting.
45417 */
45418- atomic_t seqno;
45419+ atomic_unchecked_t seqno;
45420 };
45421
45422 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45423diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45424index aa95c6c..a59dd67 100644
45425--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45426+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45427@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45428 * sequence counter given by mac80211.
45429 */
45430 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45431- seqno = atomic_add_return(0x10, &intf->seqno);
45432+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45433 else
45434- seqno = atomic_read(&intf->seqno);
45435+ seqno = atomic_read_unchecked(&intf->seqno);
45436
45437 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45438 hdr->seq_ctrl |= cpu_to_le16(seqno);
45439diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45440index e2b3d9c..67a5184 100644
45441--- a/drivers/net/wireless/ti/wl1251/sdio.c
45442+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45443@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45444
45445 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45446
45447- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45448- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45449+ pax_open_kernel();
45450+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45451+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45452+ pax_close_kernel();
45453
45454 wl1251_info("using dedicated interrupt line");
45455 } else {
45456- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45457- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45458+ pax_open_kernel();
45459+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45460+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45461+ pax_close_kernel();
45462
45463 wl1251_info("using SDIO interrupt");
45464 }
45465diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45466index 1c627da..69f7d17 100644
45467--- a/drivers/net/wireless/ti/wl12xx/main.c
45468+++ b/drivers/net/wireless/ti/wl12xx/main.c
45469@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45470 sizeof(wl->conf.mem));
45471
45472 /* read data preparation is only needed by wl127x */
45473- wl->ops->prepare_read = wl127x_prepare_read;
45474+ pax_open_kernel();
45475+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45476+ pax_close_kernel();
45477
45478 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45479 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45480@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45481 sizeof(wl->conf.mem));
45482
45483 /* read data preparation is only needed by wl127x */
45484- wl->ops->prepare_read = wl127x_prepare_read;
45485+ pax_open_kernel();
45486+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45487+ pax_close_kernel();
45488
45489 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45490 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45491diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45492index 7aa0eb8..5a9ef38 100644
45493--- a/drivers/net/wireless/ti/wl18xx/main.c
45494+++ b/drivers/net/wireless/ti/wl18xx/main.c
45495@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45496 }
45497
45498 if (!checksum_param) {
45499- wl18xx_ops.set_rx_csum = NULL;
45500- wl18xx_ops.init_vif = NULL;
45501+ pax_open_kernel();
45502+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45503+ *(void **)&wl18xx_ops.init_vif = NULL;
45504+ pax_close_kernel();
45505 }
45506
45507 /* Enable 11a Band only if we have 5G antennas */
45508diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45509index 7ef0b4a..ff65c28 100644
45510--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45511+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45512@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45513 {
45514 struct zd_usb *usb = urb->context;
45515 struct zd_usb_interrupt *intr = &usb->intr;
45516- int len;
45517+ unsigned int len;
45518 u16 int_num;
45519
45520 ZD_ASSERT(in_interrupt());
45521diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45522index d93b2b6..ae50401 100644
45523--- a/drivers/oprofile/buffer_sync.c
45524+++ b/drivers/oprofile/buffer_sync.c
45525@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45526 if (cookie == NO_COOKIE)
45527 offset = pc;
45528 if (cookie == INVALID_COOKIE) {
45529- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45530+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45531 offset = pc;
45532 }
45533 if (cookie != last_cookie) {
45534@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45535 /* add userspace sample */
45536
45537 if (!mm) {
45538- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45539+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45540 return 0;
45541 }
45542
45543 cookie = lookup_dcookie(mm, s->eip, &offset);
45544
45545 if (cookie == INVALID_COOKIE) {
45546- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45547+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45548 return 0;
45549 }
45550
45551@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45552 /* ignore backtraces if failed to add a sample */
45553 if (state == sb_bt_start) {
45554 state = sb_bt_ignore;
45555- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45556+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45557 }
45558 }
45559 release_mm(mm);
45560diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45561index c0cc4e7..44d4e54 100644
45562--- a/drivers/oprofile/event_buffer.c
45563+++ b/drivers/oprofile/event_buffer.c
45564@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45565 }
45566
45567 if (buffer_pos == buffer_size) {
45568- atomic_inc(&oprofile_stats.event_lost_overflow);
45569+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45570 return;
45571 }
45572
45573diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45574index ed2c3ec..deda85a 100644
45575--- a/drivers/oprofile/oprof.c
45576+++ b/drivers/oprofile/oprof.c
45577@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45578 if (oprofile_ops.switch_events())
45579 return;
45580
45581- atomic_inc(&oprofile_stats.multiplex_counter);
45582+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45583 start_switch_worker();
45584 }
45585
45586diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45587index 84a208d..d61b0a1 100644
45588--- a/drivers/oprofile/oprofile_files.c
45589+++ b/drivers/oprofile/oprofile_files.c
45590@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45591
45592 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45593
45594-static ssize_t timeout_read(struct file *file, char __user *buf,
45595+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45596 size_t count, loff_t *offset)
45597 {
45598 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45599diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45600index 917d28e..d62d981 100644
45601--- a/drivers/oprofile/oprofile_stats.c
45602+++ b/drivers/oprofile/oprofile_stats.c
45603@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45604 cpu_buf->sample_invalid_eip = 0;
45605 }
45606
45607- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45608- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45609- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45610- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45611- atomic_set(&oprofile_stats.multiplex_counter, 0);
45612+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45613+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45614+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45615+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45616+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45617 }
45618
45619
45620diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45621index 38b6fc0..b5cbfce 100644
45622--- a/drivers/oprofile/oprofile_stats.h
45623+++ b/drivers/oprofile/oprofile_stats.h
45624@@ -13,11 +13,11 @@
45625 #include <linux/atomic.h>
45626
45627 struct oprofile_stat_struct {
45628- atomic_t sample_lost_no_mm;
45629- atomic_t sample_lost_no_mapping;
45630- atomic_t bt_lost_no_mapping;
45631- atomic_t event_lost_overflow;
45632- atomic_t multiplex_counter;
45633+ atomic_unchecked_t sample_lost_no_mm;
45634+ atomic_unchecked_t sample_lost_no_mapping;
45635+ atomic_unchecked_t bt_lost_no_mapping;
45636+ atomic_unchecked_t event_lost_overflow;
45637+ atomic_unchecked_t multiplex_counter;
45638 };
45639
45640 extern struct oprofile_stat_struct oprofile_stats;
45641diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45642index 7c12d9c..558bf3bb 100644
45643--- a/drivers/oprofile/oprofilefs.c
45644+++ b/drivers/oprofile/oprofilefs.c
45645@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45646
45647
45648 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45649- char const *name, atomic_t *val)
45650+ char const *name, atomic_unchecked_t *val)
45651 {
45652 return __oprofilefs_create_file(sb, root, name,
45653 &atomic_ro_fops, 0444, val);
45654diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45655index 61be1d9..dec05d7 100644
45656--- a/drivers/oprofile/timer_int.c
45657+++ b/drivers/oprofile/timer_int.c
45658@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45659 return NOTIFY_OK;
45660 }
45661
45662-static struct notifier_block __refdata oprofile_cpu_notifier = {
45663+static struct notifier_block oprofile_cpu_notifier = {
45664 .notifier_call = oprofile_cpu_notify,
45665 };
45666
45667diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45668index 92ed045..62d39bd7 100644
45669--- a/drivers/parport/procfs.c
45670+++ b/drivers/parport/procfs.c
45671@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45672
45673 *ppos += len;
45674
45675- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45676+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45677 }
45678
45679 #ifdef CONFIG_PARPORT_1284
45680@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45681
45682 *ppos += len;
45683
45684- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45685+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45686 }
45687 #endif /* IEEE1284.3 support. */
45688
45689diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45690index c35e8ad..fc33beb 100644
45691--- a/drivers/pci/hotplug/acpiphp_ibm.c
45692+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45693@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45694 goto init_cleanup;
45695 }
45696
45697- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45698+ pax_open_kernel();
45699+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45700+ pax_close_kernel();
45701 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45702
45703 return retval;
45704diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45705index a6a71c4..c91097b 100644
45706--- a/drivers/pci/hotplug/cpcihp_generic.c
45707+++ b/drivers/pci/hotplug/cpcihp_generic.c
45708@@ -73,7 +73,6 @@ static u16 port;
45709 static unsigned int enum_bit;
45710 static u8 enum_mask;
45711
45712-static struct cpci_hp_controller_ops generic_hpc_ops;
45713 static struct cpci_hp_controller generic_hpc;
45714
45715 static int __init validate_parameters(void)
45716@@ -139,6 +138,10 @@ static int query_enum(void)
45717 return ((value & enum_mask) == enum_mask);
45718 }
45719
45720+static struct cpci_hp_controller_ops generic_hpc_ops = {
45721+ .query_enum = query_enum,
45722+};
45723+
45724 static int __init cpcihp_generic_init(void)
45725 {
45726 int status;
45727@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45728 pci_dev_put(dev);
45729
45730 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45731- generic_hpc_ops.query_enum = query_enum;
45732 generic_hpc.ops = &generic_hpc_ops;
45733
45734 status = cpci_hp_register_controller(&generic_hpc);
45735diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45736index 449b4bb..257e2e8 100644
45737--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45738+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45739@@ -59,7 +59,6 @@
45740 /* local variables */
45741 static bool debug;
45742 static bool poll;
45743-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45744 static struct cpci_hp_controller zt5550_hpc;
45745
45746 /* Primary cPCI bus bridge device */
45747@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45748 return 0;
45749 }
45750
45751+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45752+ .query_enum = zt5550_hc_query_enum,
45753+};
45754+
45755 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45756 {
45757 int status;
45758@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45759 dbg("returned from zt5550_hc_config");
45760
45761 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45762- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45763 zt5550_hpc.ops = &zt5550_hpc_ops;
45764 if(!poll) {
45765 zt5550_hpc.irq = hc_dev->irq;
45766 zt5550_hpc.irq_flags = IRQF_SHARED;
45767 zt5550_hpc.dev_id = hc_dev;
45768
45769- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45770- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45771- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45772+ pax_open_kernel();
45773+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45774+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45775+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45776+ pax_open_kernel();
45777 } else {
45778 info("using ENUM# polling mode");
45779 }
45780diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45781index 76ba8a1..20ca857 100644
45782--- a/drivers/pci/hotplug/cpqphp_nvram.c
45783+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45784@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45785
45786 void compaq_nvram_init (void __iomem *rom_start)
45787 {
45788+
45789+#ifndef CONFIG_PAX_KERNEXEC
45790 if (rom_start) {
45791 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45792 }
45793+#endif
45794+
45795 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45796
45797 /* initialize our int15 lock */
45798diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45799index ec20f74..c1d961e 100644
45800--- a/drivers/pci/hotplug/pci_hotplug_core.c
45801+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45802@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45803 return -EINVAL;
45804 }
45805
45806- slot->ops->owner = owner;
45807- slot->ops->mod_name = mod_name;
45808+ pax_open_kernel();
45809+ *(struct module **)&slot->ops->owner = owner;
45810+ *(const char **)&slot->ops->mod_name = mod_name;
45811+ pax_close_kernel();
45812
45813 mutex_lock(&pci_hp_mutex);
45814 /*
45815diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45816index 7d72c5e..edce02c 100644
45817--- a/drivers/pci/hotplug/pciehp_core.c
45818+++ b/drivers/pci/hotplug/pciehp_core.c
45819@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45820 struct slot *slot = ctrl->slot;
45821 struct hotplug_slot *hotplug = NULL;
45822 struct hotplug_slot_info *info = NULL;
45823- struct hotplug_slot_ops *ops = NULL;
45824+ hotplug_slot_ops_no_const *ops = NULL;
45825 char name[SLOT_NAME_SIZE];
45826 int retval = -ENOMEM;
45827
45828diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45829index c0dbe1f..94cf3d8 100644
45830--- a/drivers/pci/pci-sysfs.c
45831+++ b/drivers/pci/pci-sysfs.c
45832@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45833 {
45834 /* allocate attribute structure, piggyback attribute name */
45835 int name_len = write_combine ? 13 : 10;
45836- struct bin_attribute *res_attr;
45837+ bin_attribute_no_const *res_attr;
45838 int retval;
45839
45840 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45841@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45842 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45843 {
45844 int retval;
45845- struct bin_attribute *attr;
45846+ bin_attribute_no_const *attr;
45847
45848 /* If the device has VPD, try to expose it in sysfs. */
45849 if (dev->vpd) {
45850@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45851 {
45852 int retval;
45853 int rom_size = 0;
45854- struct bin_attribute *attr;
45855+ bin_attribute_no_const *attr;
45856
45857 if (!sysfs_initialized)
45858 return -EACCES;
45859diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45860index d1182c4..2a138ec 100644
45861--- a/drivers/pci/pci.h
45862+++ b/drivers/pci/pci.h
45863@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45864 struct pci_vpd {
45865 unsigned int len;
45866 const struct pci_vpd_ops *ops;
45867- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45868+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45869 };
45870
45871 int pci_vpd_pci22_init(struct pci_dev *dev);
45872diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45873index 403a443..034e050 100644
45874--- a/drivers/pci/pcie/aspm.c
45875+++ b/drivers/pci/pcie/aspm.c
45876@@ -27,9 +27,9 @@
45877 #define MODULE_PARAM_PREFIX "pcie_aspm."
45878
45879 /* Note: those are not register definitions */
45880-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45881-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45882-#define ASPM_STATE_L1 (4) /* L1 state */
45883+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45884+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45885+#define ASPM_STATE_L1 (4U) /* L1 state */
45886 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45887 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45888
45889diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45890index 46ada5c..20da716 100644
45891--- a/drivers/pci/probe.c
45892+++ b/drivers/pci/probe.c
45893@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45894 struct pci_bus_region region, inverted_region;
45895 bool bar_too_big = false, bar_disabled = false;
45896
45897- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45898+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45899
45900 /* No printks while decoding is disabled! */
45901 if (!dev->mmio_always_on) {
45902diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45903index cdc7836..528635c 100644
45904--- a/drivers/pci/proc.c
45905+++ b/drivers/pci/proc.c
45906@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45907 static int __init pci_proc_init(void)
45908 {
45909 struct pci_dev *dev = NULL;
45910+
45911+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45912+#ifdef CONFIG_GRKERNSEC_PROC_USER
45913+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45914+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45915+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45916+#endif
45917+#else
45918 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45919+#endif
45920 proc_create("devices", 0, proc_bus_pci_dir,
45921 &proc_bus_pci_dev_operations);
45922 proc_initialized = 1;
45923diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45924index 3e5b4497..dcdfb70 100644
45925--- a/drivers/platform/x86/chromeos_laptop.c
45926+++ b/drivers/platform/x86/chromeos_laptop.c
45927@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45928 return 0;
45929 }
45930
45931-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45932+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45933 {
45934 .ident = "Samsung Series 5 550 - Touchpad",
45935 .matches = {
45936diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45937index 62f8030..c7f2a45 100644
45938--- a/drivers/platform/x86/msi-laptop.c
45939+++ b/drivers/platform/x86/msi-laptop.c
45940@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45941
45942 if (!quirks->ec_read_only) {
45943 /* allow userland write sysfs file */
45944- dev_attr_bluetooth.store = store_bluetooth;
45945- dev_attr_wlan.store = store_wlan;
45946- dev_attr_threeg.store = store_threeg;
45947- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45948- dev_attr_wlan.attr.mode |= S_IWUSR;
45949- dev_attr_threeg.attr.mode |= S_IWUSR;
45950+ pax_open_kernel();
45951+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45952+ *(void **)&dev_attr_wlan.store = store_wlan;
45953+ *(void **)&dev_attr_threeg.store = store_threeg;
45954+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45955+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45956+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45957+ pax_close_kernel();
45958 }
45959
45960 /* disable hardware control by fn key */
45961diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45962index 3a1b6bf..b453930 100644
45963--- a/drivers/platform/x86/sony-laptop.c
45964+++ b/drivers/platform/x86/sony-laptop.c
45965@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45966 }
45967
45968 /* High speed charging function */
45969-static struct device_attribute *hsc_handle;
45970+static device_attribute_no_const *hsc_handle;
45971
45972 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45973 struct device_attribute *attr,
45974diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45975index 54d31c0..3f896d3 100644
45976--- a/drivers/platform/x86/thinkpad_acpi.c
45977+++ b/drivers/platform/x86/thinkpad_acpi.c
45978@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45979 return 0;
45980 }
45981
45982-void static hotkey_mask_warn_incomplete_mask(void)
45983+static void hotkey_mask_warn_incomplete_mask(void)
45984 {
45985 /* log only what the user can fix... */
45986 const u32 wantedmask = hotkey_driver_mask &
45987@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45988 }
45989 }
45990
45991-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45992- struct tp_nvram_state *newn,
45993- const u32 event_mask)
45994-{
45995-
45996 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45997 do { \
45998 if ((event_mask & (1 << __scancode)) && \
45999@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46000 tpacpi_hotkey_send_key(__scancode); \
46001 } while (0)
46002
46003- void issue_volchange(const unsigned int oldvol,
46004- const unsigned int newvol)
46005- {
46006- unsigned int i = oldvol;
46007+static void issue_volchange(const unsigned int oldvol,
46008+ const unsigned int newvol,
46009+ const u32 event_mask)
46010+{
46011+ unsigned int i = oldvol;
46012
46013- while (i > newvol) {
46014- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46015- i--;
46016- }
46017- while (i < newvol) {
46018- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46019- i++;
46020- }
46021+ while (i > newvol) {
46022+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46023+ i--;
46024 }
46025+ while (i < newvol) {
46026+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46027+ i++;
46028+ }
46029+}
46030
46031- void issue_brightnesschange(const unsigned int oldbrt,
46032- const unsigned int newbrt)
46033- {
46034- unsigned int i = oldbrt;
46035+static void issue_brightnesschange(const unsigned int oldbrt,
46036+ const unsigned int newbrt,
46037+ const u32 event_mask)
46038+{
46039+ unsigned int i = oldbrt;
46040
46041- while (i > newbrt) {
46042- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46043- i--;
46044- }
46045- while (i < newbrt) {
46046- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46047- i++;
46048- }
46049+ while (i > newbrt) {
46050+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46051+ i--;
46052+ }
46053+ while (i < newbrt) {
46054+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46055+ i++;
46056 }
46057+}
46058
46059+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46060+ struct tp_nvram_state *newn,
46061+ const u32 event_mask)
46062+{
46063 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
46064 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
46065 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
46066@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46067 oldn->volume_level != newn->volume_level) {
46068 /* recently muted, or repeated mute keypress, or
46069 * multiple presses ending in mute */
46070- issue_volchange(oldn->volume_level, newn->volume_level);
46071+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46072 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46073 }
46074 } else {
46075@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46076 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46077 }
46078 if (oldn->volume_level != newn->volume_level) {
46079- issue_volchange(oldn->volume_level, newn->volume_level);
46080+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46081 } else if (oldn->volume_toggle != newn->volume_toggle) {
46082 /* repeated vol up/down keypress at end of scale ? */
46083 if (newn->volume_level == 0)
46084@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46085 /* handle brightness */
46086 if (oldn->brightness_level != newn->brightness_level) {
46087 issue_brightnesschange(oldn->brightness_level,
46088- newn->brightness_level);
46089+ newn->brightness_level,
46090+ event_mask);
46091 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46092 /* repeated key presses that didn't change state */
46093 if (newn->brightness_level == 0)
46094@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46095 && !tp_features.bright_unkfw)
46096 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46097 }
46098+}
46099
46100 #undef TPACPI_COMPARE_KEY
46101 #undef TPACPI_MAY_SEND_KEY
46102-}
46103
46104 /*
46105 * Polling driver
46106diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46107index 769d265..a3a05ca 100644
46108--- a/drivers/pnp/pnpbios/bioscalls.c
46109+++ b/drivers/pnp/pnpbios/bioscalls.c
46110@@ -58,7 +58,7 @@ do { \
46111 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46112 } while(0)
46113
46114-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46115+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46116 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46117
46118 /*
46119@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46120
46121 cpu = get_cpu();
46122 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46123+
46124+ pax_open_kernel();
46125 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46126+ pax_close_kernel();
46127
46128 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46129 spin_lock_irqsave(&pnp_bios_lock, flags);
46130@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46131 :"memory");
46132 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46133
46134+ pax_open_kernel();
46135 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46136+ pax_close_kernel();
46137+
46138 put_cpu();
46139
46140 /* If we get here and this is set then the PnP BIOS faulted on us. */
46141@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46142 return status;
46143 }
46144
46145-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46146+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46147 {
46148 int i;
46149
46150@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46151 pnp_bios_callpoint.offset = header->fields.pm16offset;
46152 pnp_bios_callpoint.segment = PNP_CS16;
46153
46154+ pax_open_kernel();
46155+
46156 for_each_possible_cpu(i) {
46157 struct desc_struct *gdt = get_cpu_gdt_table(i);
46158 if (!gdt)
46159@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46160 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46161 (unsigned long)__va(header->fields.pm16dseg));
46162 }
46163+
46164+ pax_close_kernel();
46165 }
46166diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46167index d95e101..67f0c3f 100644
46168--- a/drivers/pnp/resource.c
46169+++ b/drivers/pnp/resource.c
46170@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46171 return 1;
46172
46173 /* check if the resource is valid */
46174- if (*irq < 0 || *irq > 15)
46175+ if (*irq > 15)
46176 return 0;
46177
46178 /* check if the resource is reserved */
46179@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46180 return 1;
46181
46182 /* check if the resource is valid */
46183- if (*dma < 0 || *dma == 4 || *dma > 7)
46184+ if (*dma == 4 || *dma > 7)
46185 return 0;
46186
46187 /* check if the resource is reserved */
46188diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46189index 0c52e2a..3421ab7 100644
46190--- a/drivers/power/pda_power.c
46191+++ b/drivers/power/pda_power.c
46192@@ -37,7 +37,11 @@ static int polling;
46193
46194 #if IS_ENABLED(CONFIG_USB_PHY)
46195 static struct usb_phy *transceiver;
46196-static struct notifier_block otg_nb;
46197+static int otg_handle_notification(struct notifier_block *nb,
46198+ unsigned long event, void *unused);
46199+static struct notifier_block otg_nb = {
46200+ .notifier_call = otg_handle_notification
46201+};
46202 #endif
46203
46204 static struct regulator *ac_draw;
46205@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46206
46207 #if IS_ENABLED(CONFIG_USB_PHY)
46208 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46209- otg_nb.notifier_call = otg_handle_notification;
46210 ret = usb_register_notifier(transceiver, &otg_nb);
46211 if (ret) {
46212 dev_err(dev, "failure to register otg notifier\n");
46213diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46214index cc439fd..8fa30df 100644
46215--- a/drivers/power/power_supply.h
46216+++ b/drivers/power/power_supply.h
46217@@ -16,12 +16,12 @@ struct power_supply;
46218
46219 #ifdef CONFIG_SYSFS
46220
46221-extern void power_supply_init_attrs(struct device_type *dev_type);
46222+extern void power_supply_init_attrs(void);
46223 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46224
46225 #else
46226
46227-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46228+static inline void power_supply_init_attrs(void) {}
46229 #define power_supply_uevent NULL
46230
46231 #endif /* CONFIG_SYSFS */
46232diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46233index 3b2d5df..3207114 100644
46234--- a/drivers/power/power_supply_core.c
46235+++ b/drivers/power/power_supply_core.c
46236@@ -24,7 +24,10 @@
46237 struct class *power_supply_class;
46238 EXPORT_SYMBOL_GPL(power_supply_class);
46239
46240-static struct device_type power_supply_dev_type;
46241+extern const struct attribute_group *power_supply_attr_groups[];
46242+static struct device_type power_supply_dev_type = {
46243+ .groups = power_supply_attr_groups,
46244+};
46245
46246 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46247 struct power_supply *supply)
46248@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
46249 return PTR_ERR(power_supply_class);
46250
46251 power_supply_class->dev_uevent = power_supply_uevent;
46252- power_supply_init_attrs(&power_supply_dev_type);
46253+ power_supply_init_attrs();
46254
46255 return 0;
46256 }
46257diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46258index 29178f7..c65f324 100644
46259--- a/drivers/power/power_supply_sysfs.c
46260+++ b/drivers/power/power_supply_sysfs.c
46261@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46262 .is_visible = power_supply_attr_is_visible,
46263 };
46264
46265-static const struct attribute_group *power_supply_attr_groups[] = {
46266+const struct attribute_group *power_supply_attr_groups[] = {
46267 &power_supply_attr_group,
46268 NULL,
46269 };
46270
46271-void power_supply_init_attrs(struct device_type *dev_type)
46272+void power_supply_init_attrs(void)
46273 {
46274 int i;
46275
46276- dev_type->groups = power_supply_attr_groups;
46277-
46278 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46279 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46280 }
46281diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46282index 288c75a..065bc84 100644
46283--- a/drivers/regulator/core.c
46284+++ b/drivers/regulator/core.c
46285@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46286 {
46287 const struct regulation_constraints *constraints = NULL;
46288 const struct regulator_init_data *init_data;
46289- static atomic_t regulator_no = ATOMIC_INIT(0);
46290+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46291 struct regulator_dev *rdev;
46292 struct device *dev;
46293 int ret, i;
46294@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46295 rdev->dev.of_node = config->of_node;
46296 rdev->dev.parent = dev;
46297 dev_set_name(&rdev->dev, "regulator.%d",
46298- atomic_inc_return(&regulator_no) - 1);
46299+ atomic_inc_return_unchecked(&regulator_no) - 1);
46300 ret = device_register(&rdev->dev);
46301 if (ret != 0) {
46302 put_device(&rdev->dev);
46303diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46304index d428ef9..fdc0357 100644
46305--- a/drivers/regulator/max8660.c
46306+++ b/drivers/regulator/max8660.c
46307@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46308 max8660->shadow_regs[MAX8660_OVER1] = 5;
46309 } else {
46310 /* Otherwise devices can be toggled via software */
46311- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46312- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46313+ pax_open_kernel();
46314+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46315+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46316+ pax_close_kernel();
46317 }
46318
46319 /*
46320diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46321index 0c5195a..637a453d 100644
46322--- a/drivers/regulator/max8973-regulator.c
46323+++ b/drivers/regulator/max8973-regulator.c
46324@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46325 if (!pdata || !pdata->enable_ext_control) {
46326 max->desc.enable_reg = MAX8973_VOUT;
46327 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46328- max->ops.enable = regulator_enable_regmap;
46329- max->ops.disable = regulator_disable_regmap;
46330- max->ops.is_enabled = regulator_is_enabled_regmap;
46331+ pax_open_kernel();
46332+ *(void **)&max->ops.enable = regulator_enable_regmap;
46333+ *(void **)&max->ops.disable = regulator_disable_regmap;
46334+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46335+ pax_close_kernel();
46336 }
46337
46338 if (pdata) {
46339diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46340index 1037e07..e64dea1 100644
46341--- a/drivers/regulator/mc13892-regulator.c
46342+++ b/drivers/regulator/mc13892-regulator.c
46343@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46344 }
46345 mc13xxx_unlock(mc13892);
46346
46347- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46348+ pax_open_kernel();
46349+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46350 = mc13892_vcam_set_mode;
46351- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46352+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46353 = mc13892_vcam_get_mode;
46354+ pax_close_kernel();
46355
46356 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46357 ARRAY_SIZE(mc13892_regulators));
46358diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46359index be06d71..264aee9 100644
46360--- a/drivers/rtc/rtc-cmos.c
46361+++ b/drivers/rtc/rtc-cmos.c
46362@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46363 hpet_rtc_timer_init();
46364
46365 /* export at least the first block of NVRAM */
46366- nvram.size = address_space - NVRAM_OFFSET;
46367+ pax_open_kernel();
46368+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46369+ pax_close_kernel();
46370 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46371 if (retval < 0) {
46372 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46373diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46374index d049393..bb20be0 100644
46375--- a/drivers/rtc/rtc-dev.c
46376+++ b/drivers/rtc/rtc-dev.c
46377@@ -16,6 +16,7 @@
46378 #include <linux/module.h>
46379 #include <linux/rtc.h>
46380 #include <linux/sched.h>
46381+#include <linux/grsecurity.h>
46382 #include "rtc-core.h"
46383
46384 static dev_t rtc_devt;
46385@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46386 if (copy_from_user(&tm, uarg, sizeof(tm)))
46387 return -EFAULT;
46388
46389+ gr_log_timechange();
46390+
46391 return rtc_set_time(rtc, &tm);
46392
46393 case RTC_PIE_ON:
46394diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46395index ca18fd1..055e42d 100644
46396--- a/drivers/rtc/rtc-ds1307.c
46397+++ b/drivers/rtc/rtc-ds1307.c
46398@@ -107,7 +107,7 @@ struct ds1307 {
46399 u8 offset; /* register's offset */
46400 u8 regs[11];
46401 u16 nvram_offset;
46402- struct bin_attribute *nvram;
46403+ bin_attribute_no_const *nvram;
46404 enum ds_type type;
46405 unsigned long flags;
46406 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46407diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46408index fcb0329..d77b7f2 100644
46409--- a/drivers/rtc/rtc-m48t59.c
46410+++ b/drivers/rtc/rtc-m48t59.c
46411@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46412 if (IS_ERR(m48t59->rtc))
46413 return PTR_ERR(m48t59->rtc);
46414
46415- m48t59_nvram_attr.size = pdata->offset;
46416+ pax_open_kernel();
46417+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46418+ pax_close_kernel();
46419
46420 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46421 if (ret)
46422diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46423index e693af6..2e525b6 100644
46424--- a/drivers/scsi/bfa/bfa_fcpim.h
46425+++ b/drivers/scsi/bfa/bfa_fcpim.h
46426@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46427
46428 struct bfa_itn_s {
46429 bfa_isr_func_t isr;
46430-};
46431+} __no_const;
46432
46433 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46434 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46435diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46436index 90814fe..4384138 100644
46437--- a/drivers/scsi/bfa/bfa_ioc.h
46438+++ b/drivers/scsi/bfa/bfa_ioc.h
46439@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46440 bfa_ioc_disable_cbfn_t disable_cbfn;
46441 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46442 bfa_ioc_reset_cbfn_t reset_cbfn;
46443-};
46444+} __no_const;
46445
46446 /*
46447 * IOC event notification mechanism.
46448@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46449 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46450 enum bfi_ioc_state fwstate);
46451 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46452-};
46453+} __no_const;
46454
46455 /*
46456 * Queue element to wait for room in request queue. FIFO order is
46457diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46458index c9382d6..6619864 100644
46459--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46460+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46461@@ -33,8 +33,8 @@
46462 */
46463 #include "libfcoe.h"
46464
46465-static atomic_t ctlr_num;
46466-static atomic_t fcf_num;
46467+static atomic_unchecked_t ctlr_num;
46468+static atomic_unchecked_t fcf_num;
46469
46470 /*
46471 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46472@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46473 if (!ctlr)
46474 goto out;
46475
46476- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46477+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46478 ctlr->f = f;
46479 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46480 INIT_LIST_HEAD(&ctlr->fcfs);
46481@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46482 fcf->dev.parent = &ctlr->dev;
46483 fcf->dev.bus = &fcoe_bus_type;
46484 fcf->dev.type = &fcoe_fcf_device_type;
46485- fcf->id = atomic_inc_return(&fcf_num) - 1;
46486+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46487 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46488
46489 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46490@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46491 {
46492 int error;
46493
46494- atomic_set(&ctlr_num, 0);
46495- atomic_set(&fcf_num, 0);
46496+ atomic_set_unchecked(&ctlr_num, 0);
46497+ atomic_set_unchecked(&fcf_num, 0);
46498
46499 error = bus_register(&fcoe_bus_type);
46500 if (error)
46501diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46502index df0c3c7..b00e1d0 100644
46503--- a/drivers/scsi/hosts.c
46504+++ b/drivers/scsi/hosts.c
46505@@ -42,7 +42,7 @@
46506 #include "scsi_logging.h"
46507
46508
46509-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46510+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46511
46512
46513 static void scsi_host_cls_release(struct device *dev)
46514@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46515 * subtract one because we increment first then return, but we need to
46516 * know what the next host number was before increment
46517 */
46518- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46519+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46520 shost->dma_channel = 0xff;
46521
46522 /* These three are default values which can be overridden */
46523diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46524index 7f4f790..b75b92a 100644
46525--- a/drivers/scsi/hpsa.c
46526+++ b/drivers/scsi/hpsa.c
46527@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46528 unsigned long flags;
46529
46530 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46531- return h->access.command_completed(h, q);
46532+ return h->access->command_completed(h, q);
46533
46534 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46535 a = rq->head[rq->current_entry];
46536@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46537 while (!list_empty(&h->reqQ)) {
46538 c = list_entry(h->reqQ.next, struct CommandList, list);
46539 /* can't do anything if fifo is full */
46540- if ((h->access.fifo_full(h))) {
46541+ if ((h->access->fifo_full(h))) {
46542 dev_warn(&h->pdev->dev, "fifo full\n");
46543 break;
46544 }
46545@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46546
46547 /* Tell the controller execute command */
46548 spin_unlock_irqrestore(&h->lock, flags);
46549- h->access.submit_command(h, c);
46550+ h->access->submit_command(h, c);
46551 spin_lock_irqsave(&h->lock, flags);
46552 }
46553 spin_unlock_irqrestore(&h->lock, flags);
46554@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46555
46556 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46557 {
46558- return h->access.command_completed(h, q);
46559+ return h->access->command_completed(h, q);
46560 }
46561
46562 static inline bool interrupt_pending(struct ctlr_info *h)
46563 {
46564- return h->access.intr_pending(h);
46565+ return h->access->intr_pending(h);
46566 }
46567
46568 static inline long interrupt_not_for_us(struct ctlr_info *h)
46569 {
46570- return (h->access.intr_pending(h) == 0) ||
46571+ return (h->access->intr_pending(h) == 0) ||
46572 (h->interrupts_enabled == 0);
46573 }
46574
46575@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46576 if (prod_index < 0)
46577 return -ENODEV;
46578 h->product_name = products[prod_index].product_name;
46579- h->access = *(products[prod_index].access);
46580+ h->access = products[prod_index].access;
46581
46582 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46583 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46584@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46585
46586 assert_spin_locked(&lockup_detector_lock);
46587 remove_ctlr_from_lockup_detector_list(h);
46588- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46589+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46590 spin_lock_irqsave(&h->lock, flags);
46591 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46592 spin_unlock_irqrestore(&h->lock, flags);
46593@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46594 }
46595
46596 /* make sure the board interrupts are off */
46597- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46598+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46599
46600 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46601 goto clean2;
46602@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46603 * fake ones to scoop up any residual completions.
46604 */
46605 spin_lock_irqsave(&h->lock, flags);
46606- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46607+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46608 spin_unlock_irqrestore(&h->lock, flags);
46609 free_irqs(h);
46610 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46611@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46612 dev_info(&h->pdev->dev, "Board READY.\n");
46613 dev_info(&h->pdev->dev,
46614 "Waiting for stale completions to drain.\n");
46615- h->access.set_intr_mask(h, HPSA_INTR_ON);
46616+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46617 msleep(10000);
46618- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46619+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46620
46621 rc = controller_reset_failed(h->cfgtable);
46622 if (rc)
46623@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46624 }
46625
46626 /* Turn the interrupts on so we can service requests */
46627- h->access.set_intr_mask(h, HPSA_INTR_ON);
46628+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46629
46630 hpsa_hba_inquiry(h);
46631 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46632@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46633 * To write all data in the battery backed cache to disks
46634 */
46635 hpsa_flush_cache(h);
46636- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46637+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46638 hpsa_free_irqs_and_disable_msix(h);
46639 }
46640
46641@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46642 return;
46643 }
46644 /* Change the access methods to the performant access methods */
46645- h->access = SA5_performant_access;
46646+ h->access = &SA5_performant_access;
46647 h->transMethod = CFGTBL_Trans_Performant;
46648 }
46649
46650diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46651index 9816479..c5d4e97 100644
46652--- a/drivers/scsi/hpsa.h
46653+++ b/drivers/scsi/hpsa.h
46654@@ -79,7 +79,7 @@ struct ctlr_info {
46655 unsigned int msix_vector;
46656 unsigned int msi_vector;
46657 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46658- struct access_method access;
46659+ struct access_method *access;
46660
46661 /* queue and queue Info */
46662 struct list_head reqQ;
46663diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46664index 5879929..32b241d 100644
46665--- a/drivers/scsi/libfc/fc_exch.c
46666+++ b/drivers/scsi/libfc/fc_exch.c
46667@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46668 u16 pool_max_index;
46669
46670 struct {
46671- atomic_t no_free_exch;
46672- atomic_t no_free_exch_xid;
46673- atomic_t xid_not_found;
46674- atomic_t xid_busy;
46675- atomic_t seq_not_found;
46676- atomic_t non_bls_resp;
46677+ atomic_unchecked_t no_free_exch;
46678+ atomic_unchecked_t no_free_exch_xid;
46679+ atomic_unchecked_t xid_not_found;
46680+ atomic_unchecked_t xid_busy;
46681+ atomic_unchecked_t seq_not_found;
46682+ atomic_unchecked_t non_bls_resp;
46683 } stats;
46684 };
46685
46686@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46687 /* allocate memory for exchange */
46688 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46689 if (!ep) {
46690- atomic_inc(&mp->stats.no_free_exch);
46691+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46692 goto out;
46693 }
46694 memset(ep, 0, sizeof(*ep));
46695@@ -797,7 +797,7 @@ out:
46696 return ep;
46697 err:
46698 spin_unlock_bh(&pool->lock);
46699- atomic_inc(&mp->stats.no_free_exch_xid);
46700+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46701 mempool_free(ep, mp->ep_pool);
46702 return NULL;
46703 }
46704@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46705 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46706 ep = fc_exch_find(mp, xid);
46707 if (!ep) {
46708- atomic_inc(&mp->stats.xid_not_found);
46709+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46710 reject = FC_RJT_OX_ID;
46711 goto out;
46712 }
46713@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46714 ep = fc_exch_find(mp, xid);
46715 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46716 if (ep) {
46717- atomic_inc(&mp->stats.xid_busy);
46718+ atomic_inc_unchecked(&mp->stats.xid_busy);
46719 reject = FC_RJT_RX_ID;
46720 goto rel;
46721 }
46722@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46723 }
46724 xid = ep->xid; /* get our XID */
46725 } else if (!ep) {
46726- atomic_inc(&mp->stats.xid_not_found);
46727+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46728 reject = FC_RJT_RX_ID; /* XID not found */
46729 goto out;
46730 }
46731@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46732 } else {
46733 sp = &ep->seq;
46734 if (sp->id != fh->fh_seq_id) {
46735- atomic_inc(&mp->stats.seq_not_found);
46736+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46737 if (f_ctl & FC_FC_END_SEQ) {
46738 /*
46739 * Update sequence_id based on incoming last
46740@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46741
46742 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46743 if (!ep) {
46744- atomic_inc(&mp->stats.xid_not_found);
46745+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46746 goto out;
46747 }
46748 if (ep->esb_stat & ESB_ST_COMPLETE) {
46749- atomic_inc(&mp->stats.xid_not_found);
46750+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46751 goto rel;
46752 }
46753 if (ep->rxid == FC_XID_UNKNOWN)
46754 ep->rxid = ntohs(fh->fh_rx_id);
46755 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46756- atomic_inc(&mp->stats.xid_not_found);
46757+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46758 goto rel;
46759 }
46760 if (ep->did != ntoh24(fh->fh_s_id) &&
46761 ep->did != FC_FID_FLOGI) {
46762- atomic_inc(&mp->stats.xid_not_found);
46763+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46764 goto rel;
46765 }
46766 sof = fr_sof(fp);
46767@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46768 sp->ssb_stat |= SSB_ST_RESP;
46769 sp->id = fh->fh_seq_id;
46770 } else if (sp->id != fh->fh_seq_id) {
46771- atomic_inc(&mp->stats.seq_not_found);
46772+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46773 goto rel;
46774 }
46775
46776@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46777 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46778
46779 if (!sp)
46780- atomic_inc(&mp->stats.xid_not_found);
46781+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46782 else
46783- atomic_inc(&mp->stats.non_bls_resp);
46784+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46785
46786 fc_frame_free(fp);
46787 }
46788@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46789
46790 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46791 mp = ema->mp;
46792- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46793+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46794 st->fc_no_free_exch_xid +=
46795- atomic_read(&mp->stats.no_free_exch_xid);
46796- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46797- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46798- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46799- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46800+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46801+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46802+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46803+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46804+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46805 }
46806 }
46807 EXPORT_SYMBOL(fc_exch_update_stats);
46808diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46809index 161c98e..6d563b3 100644
46810--- a/drivers/scsi/libsas/sas_ata.c
46811+++ b/drivers/scsi/libsas/sas_ata.c
46812@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46813 .postreset = ata_std_postreset,
46814 .error_handler = ata_std_error_handler,
46815 .post_internal_cmd = sas_ata_post_internal,
46816- .qc_defer = ata_std_qc_defer,
46817+ .qc_defer = ata_std_qc_defer,
46818 .qc_prep = ata_noop_qc_prep,
46819 .qc_issue = sas_ata_qc_issue,
46820 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46821diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46822index 93f222d..73e977b 100644
46823--- a/drivers/scsi/lpfc/lpfc.h
46824+++ b/drivers/scsi/lpfc/lpfc.h
46825@@ -431,7 +431,7 @@ struct lpfc_vport {
46826 struct dentry *debug_nodelist;
46827 struct dentry *vport_debugfs_root;
46828 struct lpfc_debugfs_trc *disc_trc;
46829- atomic_t disc_trc_cnt;
46830+ atomic_unchecked_t disc_trc_cnt;
46831 #endif
46832 uint8_t stat_data_enabled;
46833 uint8_t stat_data_blocked;
46834@@ -865,8 +865,8 @@ struct lpfc_hba {
46835 struct timer_list fabric_block_timer;
46836 unsigned long bit_flags;
46837 #define FABRIC_COMANDS_BLOCKED 0
46838- atomic_t num_rsrc_err;
46839- atomic_t num_cmd_success;
46840+ atomic_unchecked_t num_rsrc_err;
46841+ atomic_unchecked_t num_cmd_success;
46842 unsigned long last_rsrc_error_time;
46843 unsigned long last_ramp_down_time;
46844 unsigned long last_ramp_up_time;
46845@@ -902,7 +902,7 @@ struct lpfc_hba {
46846
46847 struct dentry *debug_slow_ring_trc;
46848 struct lpfc_debugfs_trc *slow_ring_trc;
46849- atomic_t slow_ring_trc_cnt;
46850+ atomic_unchecked_t slow_ring_trc_cnt;
46851 /* iDiag debugfs sub-directory */
46852 struct dentry *idiag_root;
46853 struct dentry *idiag_pci_cfg;
46854diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46855index 60084e6..0e2e700 100644
46856--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46857+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46858@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46859
46860 #include <linux/debugfs.h>
46861
46862-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46863+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46864 static unsigned long lpfc_debugfs_start_time = 0L;
46865
46866 /* iDiag */
46867@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46868 lpfc_debugfs_enable = 0;
46869
46870 len = 0;
46871- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46872+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46873 (lpfc_debugfs_max_disc_trc - 1);
46874 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46875 dtp = vport->disc_trc + i;
46876@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46877 lpfc_debugfs_enable = 0;
46878
46879 len = 0;
46880- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46881+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46882 (lpfc_debugfs_max_slow_ring_trc - 1);
46883 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46884 dtp = phba->slow_ring_trc + i;
46885@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46886 !vport || !vport->disc_trc)
46887 return;
46888
46889- index = atomic_inc_return(&vport->disc_trc_cnt) &
46890+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46891 (lpfc_debugfs_max_disc_trc - 1);
46892 dtp = vport->disc_trc + index;
46893 dtp->fmt = fmt;
46894 dtp->data1 = data1;
46895 dtp->data2 = data2;
46896 dtp->data3 = data3;
46897- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46898+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46899 dtp->jif = jiffies;
46900 #endif
46901 return;
46902@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46903 !phba || !phba->slow_ring_trc)
46904 return;
46905
46906- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46907+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46908 (lpfc_debugfs_max_slow_ring_trc - 1);
46909 dtp = phba->slow_ring_trc + index;
46910 dtp->fmt = fmt;
46911 dtp->data1 = data1;
46912 dtp->data2 = data2;
46913 dtp->data3 = data3;
46914- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46915+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46916 dtp->jif = jiffies;
46917 #endif
46918 return;
46919@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46920 "slow_ring buffer\n");
46921 goto debug_failed;
46922 }
46923- atomic_set(&phba->slow_ring_trc_cnt, 0);
46924+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46925 memset(phba->slow_ring_trc, 0,
46926 (sizeof(struct lpfc_debugfs_trc) *
46927 lpfc_debugfs_max_slow_ring_trc));
46928@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46929 "buffer\n");
46930 goto debug_failed;
46931 }
46932- atomic_set(&vport->disc_trc_cnt, 0);
46933+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46934
46935 snprintf(name, sizeof(name), "discovery_trace");
46936 vport->debug_disc_trc =
46937diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46938index e0b20fa..30c2c0d 100644
46939--- a/drivers/scsi/lpfc/lpfc_init.c
46940+++ b/drivers/scsi/lpfc/lpfc_init.c
46941@@ -10936,8 +10936,10 @@ lpfc_init(void)
46942 "misc_register returned with status %d", error);
46943
46944 if (lpfc_enable_npiv) {
46945- lpfc_transport_functions.vport_create = lpfc_vport_create;
46946- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46947+ pax_open_kernel();
46948+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46949+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46950+ pax_close_kernel();
46951 }
46952 lpfc_transport_template =
46953 fc_attach_transport(&lpfc_transport_functions);
46954diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46955index 243de1d..f40e3e5 100644
46956--- a/drivers/scsi/lpfc/lpfc_scsi.c
46957+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46958@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46959 uint32_t evt_posted;
46960
46961 spin_lock_irqsave(&phba->hbalock, flags);
46962- atomic_inc(&phba->num_rsrc_err);
46963+ atomic_inc_unchecked(&phba->num_rsrc_err);
46964 phba->last_rsrc_error_time = jiffies;
46965
46966 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46967@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46968 unsigned long flags;
46969 struct lpfc_hba *phba = vport->phba;
46970 uint32_t evt_posted;
46971- atomic_inc(&phba->num_cmd_success);
46972+ atomic_inc_unchecked(&phba->num_cmd_success);
46973
46974 if (vport->cfg_lun_queue_depth <= queue_depth)
46975 return;
46976@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46977 unsigned long num_rsrc_err, num_cmd_success;
46978 int i;
46979
46980- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46981- num_cmd_success = atomic_read(&phba->num_cmd_success);
46982+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46983+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46984
46985 /*
46986 * The error and success command counters are global per
46987@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46988 }
46989 }
46990 lpfc_destroy_vport_work_array(phba, vports);
46991- atomic_set(&phba->num_rsrc_err, 0);
46992- atomic_set(&phba->num_cmd_success, 0);
46993+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46994+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46995 }
46996
46997 /**
46998@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46999 }
47000 }
47001 lpfc_destroy_vport_work_array(phba, vports);
47002- atomic_set(&phba->num_rsrc_err, 0);
47003- atomic_set(&phba->num_cmd_success, 0);
47004+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
47005+ atomic_set_unchecked(&phba->num_cmd_success, 0);
47006 }
47007
47008 /**
47009diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
47010index 1eb7b028..b2a6080 100644
47011--- a/drivers/scsi/pmcraid.c
47012+++ b/drivers/scsi/pmcraid.c
47013@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
47014 res->scsi_dev = scsi_dev;
47015 scsi_dev->hostdata = res;
47016 res->change_detected = 0;
47017- atomic_set(&res->read_failures, 0);
47018- atomic_set(&res->write_failures, 0);
47019+ atomic_set_unchecked(&res->read_failures, 0);
47020+ atomic_set_unchecked(&res->write_failures, 0);
47021 rc = 0;
47022 }
47023 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
47024@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
47025
47026 /* If this was a SCSI read/write command keep count of errors */
47027 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
47028- atomic_inc(&res->read_failures);
47029+ atomic_inc_unchecked(&res->read_failures);
47030 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
47031- atomic_inc(&res->write_failures);
47032+ atomic_inc_unchecked(&res->write_failures);
47033
47034 if (!RES_IS_GSCSI(res->cfg_entry) &&
47035 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
47036@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
47037 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47038 * hrrq_id assigned here in queuecommand
47039 */
47040- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47041+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47042 pinstance->num_hrrq;
47043 cmd->cmd_done = pmcraid_io_done;
47044
47045@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
47046 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47047 * hrrq_id assigned here in queuecommand
47048 */
47049- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47050+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47051 pinstance->num_hrrq;
47052
47053 if (request_size) {
47054@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
47055
47056 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
47057 /* add resources only after host is added into system */
47058- if (!atomic_read(&pinstance->expose_resources))
47059+ if (!atomic_read_unchecked(&pinstance->expose_resources))
47060 return;
47061
47062 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
47063@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
47064 init_waitqueue_head(&pinstance->reset_wait_q);
47065
47066 atomic_set(&pinstance->outstanding_cmds, 0);
47067- atomic_set(&pinstance->last_message_id, 0);
47068- atomic_set(&pinstance->expose_resources, 0);
47069+ atomic_set_unchecked(&pinstance->last_message_id, 0);
47070+ atomic_set_unchecked(&pinstance->expose_resources, 0);
47071
47072 INIT_LIST_HEAD(&pinstance->free_res_q);
47073 INIT_LIST_HEAD(&pinstance->used_res_q);
47074@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47075 /* Schedule worker thread to handle CCN and take care of adding and
47076 * removing devices to OS
47077 */
47078- atomic_set(&pinstance->expose_resources, 1);
47079+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47080 schedule_work(&pinstance->worker_q);
47081 return rc;
47082
47083diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47084index e1d150f..6c6df44 100644
47085--- a/drivers/scsi/pmcraid.h
47086+++ b/drivers/scsi/pmcraid.h
47087@@ -748,7 +748,7 @@ struct pmcraid_instance {
47088 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47089
47090 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47091- atomic_t last_message_id;
47092+ atomic_unchecked_t last_message_id;
47093
47094 /* configuration table */
47095 struct pmcraid_config_table *cfg_table;
47096@@ -777,7 +777,7 @@ struct pmcraid_instance {
47097 atomic_t outstanding_cmds;
47098
47099 /* should add/delete resources to mid-layer now ?*/
47100- atomic_t expose_resources;
47101+ atomic_unchecked_t expose_resources;
47102
47103
47104
47105@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47106 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47107 };
47108 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47109- atomic_t read_failures; /* count of failed READ commands */
47110- atomic_t write_failures; /* count of failed WRITE commands */
47111+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47112+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47113
47114 /* To indicate add/delete/modify during CCN */
47115 u8 change_detected;
47116diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47117index d7a99ae..801df70 100644
47118--- a/drivers/scsi/qla2xxx/qla_attr.c
47119+++ b/drivers/scsi/qla2xxx/qla_attr.c
47120@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47121 return 0;
47122 }
47123
47124-struct fc_function_template qla2xxx_transport_functions = {
47125+fc_function_template_no_const qla2xxx_transport_functions = {
47126
47127 .show_host_node_name = 1,
47128 .show_host_port_name = 1,
47129@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47130 .bsg_timeout = qla24xx_bsg_timeout,
47131 };
47132
47133-struct fc_function_template qla2xxx_transport_vport_functions = {
47134+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47135
47136 .show_host_node_name = 1,
47137 .show_host_port_name = 1,
47138diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47139index 2d98232..a84298e 100644
47140--- a/drivers/scsi/qla2xxx/qla_gbl.h
47141+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47142@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47143 struct device_attribute;
47144 extern struct device_attribute *qla2x00_host_attrs[];
47145 struct fc_function_template;
47146-extern struct fc_function_template qla2xxx_transport_functions;
47147-extern struct fc_function_template qla2xxx_transport_vport_functions;
47148+extern fc_function_template_no_const qla2xxx_transport_functions;
47149+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47150 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47151 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47152 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47153diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47154index 3e21e9f..426ba79 100644
47155--- a/drivers/scsi/qla2xxx/qla_os.c
47156+++ b/drivers/scsi/qla2xxx/qla_os.c
47157@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47158 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47159 /* Ok, a 64bit DMA mask is applicable. */
47160 ha->flags.enable_64bit_addressing = 1;
47161- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47162- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47163+ pax_open_kernel();
47164+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47165+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47166+ pax_close_kernel();
47167 return;
47168 }
47169 }
47170diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47171index ddf16a8..80f4dd0 100644
47172--- a/drivers/scsi/qla4xxx/ql4_def.h
47173+++ b/drivers/scsi/qla4xxx/ql4_def.h
47174@@ -291,7 +291,7 @@ struct ddb_entry {
47175 * (4000 only) */
47176 atomic_t relogin_timer; /* Max Time to wait for
47177 * relogin to complete */
47178- atomic_t relogin_retry_count; /* Num of times relogin has been
47179+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47180 * retried */
47181 uint32_t default_time2wait; /* Default Min time between
47182 * relogins (+aens) */
47183diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47184index b246b3c..897004d 100644
47185--- a/drivers/scsi/qla4xxx/ql4_os.c
47186+++ b/drivers/scsi/qla4xxx/ql4_os.c
47187@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47188 */
47189 if (!iscsi_is_session_online(cls_sess)) {
47190 /* Reset retry relogin timer */
47191- atomic_inc(&ddb_entry->relogin_retry_count);
47192+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47193 DEBUG2(ql4_printk(KERN_INFO, ha,
47194 "%s: index[%d] relogin timed out-retrying"
47195 " relogin (%d), retry (%d)\n", __func__,
47196 ddb_entry->fw_ddb_index,
47197- atomic_read(&ddb_entry->relogin_retry_count),
47198+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47199 ddb_entry->default_time2wait + 4));
47200 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47201 atomic_set(&ddb_entry->retry_relogin_timer,
47202@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47203
47204 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47205 atomic_set(&ddb_entry->relogin_timer, 0);
47206- atomic_set(&ddb_entry->relogin_retry_count, 0);
47207+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47208 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47209 ddb_entry->default_relogin_timeout =
47210 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47211diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47212index eaa808e..95f8841 100644
47213--- a/drivers/scsi/scsi.c
47214+++ b/drivers/scsi/scsi.c
47215@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47216 unsigned long timeout;
47217 int rtn = 0;
47218
47219- atomic_inc(&cmd->device->iorequest_cnt);
47220+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47221
47222 /* check if the device is still usable */
47223 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47224diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47225index 124392f..75eb43e 100644
47226--- a/drivers/scsi/scsi_lib.c
47227+++ b/drivers/scsi/scsi_lib.c
47228@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47229 shost = sdev->host;
47230 scsi_init_cmd_errh(cmd);
47231 cmd->result = DID_NO_CONNECT << 16;
47232- atomic_inc(&cmd->device->iorequest_cnt);
47233+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47234
47235 /*
47236 * SCSI request completion path will do scsi_device_unbusy(),
47237@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47238
47239 INIT_LIST_HEAD(&cmd->eh_entry);
47240
47241- atomic_inc(&cmd->device->iodone_cnt);
47242+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47243 if (cmd->result)
47244- atomic_inc(&cmd->device->ioerr_cnt);
47245+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47246
47247 disposition = scsi_decide_disposition(cmd);
47248 if (disposition != SUCCESS &&
47249diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47250index 7e50061..71db7a6 100644
47251--- a/drivers/scsi/scsi_sysfs.c
47252+++ b/drivers/scsi/scsi_sysfs.c
47253@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47254 char *buf) \
47255 { \
47256 struct scsi_device *sdev = to_scsi_device(dev); \
47257- unsigned long long count = atomic_read(&sdev->field); \
47258+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47259 return snprintf(buf, 20, "0x%llx\n", count); \
47260 } \
47261 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47262diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47263index 84a1fdf..693b0d6 100644
47264--- a/drivers/scsi/scsi_tgt_lib.c
47265+++ b/drivers/scsi/scsi_tgt_lib.c
47266@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47267 int err;
47268
47269 dprintk("%lx %u\n", uaddr, len);
47270- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47271+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47272 if (err) {
47273 /*
47274 * TODO: need to fixup sg_tablesize, max_segment_size,
47275diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47276index 4628fd5..a94a1c2 100644
47277--- a/drivers/scsi/scsi_transport_fc.c
47278+++ b/drivers/scsi/scsi_transport_fc.c
47279@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47280 * Netlink Infrastructure
47281 */
47282
47283-static atomic_t fc_event_seq;
47284+static atomic_unchecked_t fc_event_seq;
47285
47286 /**
47287 * fc_get_event_number - Obtain the next sequential FC event number
47288@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47289 u32
47290 fc_get_event_number(void)
47291 {
47292- return atomic_add_return(1, &fc_event_seq);
47293+ return atomic_add_return_unchecked(1, &fc_event_seq);
47294 }
47295 EXPORT_SYMBOL(fc_get_event_number);
47296
47297@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47298 {
47299 int error;
47300
47301- atomic_set(&fc_event_seq, 0);
47302+ atomic_set_unchecked(&fc_event_seq, 0);
47303
47304 error = transport_class_register(&fc_host_class);
47305 if (error)
47306@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47307 char *cp;
47308
47309 *val = simple_strtoul(buf, &cp, 0);
47310- if ((*cp && (*cp != '\n')) || (*val < 0))
47311+ if (*cp && (*cp != '\n'))
47312 return -EINVAL;
47313 /*
47314 * Check for overflow; dev_loss_tmo is u32
47315diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47316index abf7c40..c3240ed 100644
47317--- a/drivers/scsi/scsi_transport_iscsi.c
47318+++ b/drivers/scsi/scsi_transport_iscsi.c
47319@@ -80,7 +80,7 @@ struct iscsi_internal {
47320 struct transport_container session_cont;
47321 };
47322
47323-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47324+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47325 static struct workqueue_struct *iscsi_eh_timer_workq;
47326
47327 static DEFINE_IDA(iscsi_sess_ida);
47328@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47329 int err;
47330
47331 ihost = shost->shost_data;
47332- session->sid = atomic_add_return(1, &iscsi_session_nr);
47333+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47334
47335 if (target_id == ISCSI_MAX_TARGET) {
47336 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47337@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47338 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47339 ISCSI_TRANSPORT_VERSION);
47340
47341- atomic_set(&iscsi_session_nr, 0);
47342+ atomic_set_unchecked(&iscsi_session_nr, 0);
47343
47344 err = class_register(&iscsi_transport_class);
47345 if (err)
47346diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47347index f379c7f..e8fc69c 100644
47348--- a/drivers/scsi/scsi_transport_srp.c
47349+++ b/drivers/scsi/scsi_transport_srp.c
47350@@ -33,7 +33,7 @@
47351 #include "scsi_transport_srp_internal.h"
47352
47353 struct srp_host_attrs {
47354- atomic_t next_port_id;
47355+ atomic_unchecked_t next_port_id;
47356 };
47357 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47358
47359@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47360 struct Scsi_Host *shost = dev_to_shost(dev);
47361 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47362
47363- atomic_set(&srp_host->next_port_id, 0);
47364+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47365 return 0;
47366 }
47367
47368@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47369 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47370 rport->roles = ids->roles;
47371
47372- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47373+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47374 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47375
47376 transport_setup_device(&rport->dev);
47377diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47378index 86fcf2c..26d8594 100644
47379--- a/drivers/scsi/sd.c
47380+++ b/drivers/scsi/sd.c
47381@@ -2938,7 +2938,7 @@ static int sd_probe(struct device *dev)
47382 sdkp->disk = gd;
47383 sdkp->index = index;
47384 atomic_set(&sdkp->openers, 0);
47385- atomic_set(&sdkp->device->ioerr_cnt, 0);
47386+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47387
47388 if (!sdp->request_queue->rq_timeout) {
47389 if (sdp->type != TYPE_MOD)
47390diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47391index df5e961..df6b97f 100644
47392--- a/drivers/scsi/sg.c
47393+++ b/drivers/scsi/sg.c
47394@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47395 sdp->disk->disk_name,
47396 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47397 NULL,
47398- (char *)arg);
47399+ (char __user *)arg);
47400 case BLKTRACESTART:
47401 return blk_trace_startstop(sdp->device->request_queue, 1);
47402 case BLKTRACESTOP:
47403diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47404index 978dda2..cb19aa0 100644
47405--- a/drivers/spi/spi.c
47406+++ b/drivers/spi/spi.c
47407@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47408 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47409
47410 /* portable code must never pass more than 32 bytes */
47411-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47412+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47413
47414 static u8 *buf;
47415
47416diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47417index ee3a57f..18368c1 100644
47418--- a/drivers/staging/android/timed_output.c
47419+++ b/drivers/staging/android/timed_output.c
47420@@ -25,7 +25,7 @@
47421 #include "timed_output.h"
47422
47423 static struct class *timed_output_class;
47424-static atomic_t device_count;
47425+static atomic_unchecked_t device_count;
47426
47427 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47428 char *buf)
47429@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47430 timed_output_class = class_create(THIS_MODULE, "timed_output");
47431 if (IS_ERR(timed_output_class))
47432 return PTR_ERR(timed_output_class);
47433- atomic_set(&device_count, 0);
47434+ atomic_set_unchecked(&device_count, 0);
47435 }
47436
47437 return 0;
47438@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47439 if (ret < 0)
47440 return ret;
47441
47442- tdev->index = atomic_inc_return(&device_count);
47443+ tdev->index = atomic_inc_return_unchecked(&device_count);
47444 tdev->dev = device_create(timed_output_class, NULL,
47445 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47446 if (IS_ERR(tdev->dev))
47447diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47448index 3675020..e80d92c 100644
47449--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47450+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47451@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47452
47453 static int solo_sysfs_init(struct solo_dev *solo_dev)
47454 {
47455- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47456+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47457 struct device *dev = &solo_dev->dev;
47458 const char *driver;
47459 int i;
47460diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47461index 3335941..2b26186 100644
47462--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47463+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47464@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47465
47466 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47467 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47468- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47469+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47470 if (p2m_id < 0)
47471 p2m_id = -p2m_id;
47472 }
47473diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47474index 6f91d2e..3f011d2 100644
47475--- a/drivers/staging/media/solo6x10/solo6x10.h
47476+++ b/drivers/staging/media/solo6x10/solo6x10.h
47477@@ -238,7 +238,7 @@ struct solo_dev {
47478
47479 /* P2M DMA Engine */
47480 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47481- atomic_t p2m_count;
47482+ atomic_unchecked_t p2m_count;
47483 int p2m_jiffies;
47484 unsigned int p2m_timeouts;
47485
47486diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47487index 34afc16..ffe44dd 100644
47488--- a/drivers/staging/octeon/ethernet-rx.c
47489+++ b/drivers/staging/octeon/ethernet-rx.c
47490@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47491 /* Increment RX stats for virtual ports */
47492 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47493 #ifdef CONFIG_64BIT
47494- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47495- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47496+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47497+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47498 #else
47499- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47500- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47501+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47502+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47503 #endif
47504 }
47505 netif_receive_skb(skb);
47506@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47507 dev->name);
47508 */
47509 #ifdef CONFIG_64BIT
47510- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47511+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47512 #else
47513- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47514+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47515 #endif
47516 dev_kfree_skb_irq(skb);
47517 }
47518diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47519index c3a90e7..023619a 100644
47520--- a/drivers/staging/octeon/ethernet.c
47521+++ b/drivers/staging/octeon/ethernet.c
47522@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47523 * since the RX tasklet also increments it.
47524 */
47525 #ifdef CONFIG_64BIT
47526- atomic64_add(rx_status.dropped_packets,
47527- (atomic64_t *)&priv->stats.rx_dropped);
47528+ atomic64_add_unchecked(rx_status.dropped_packets,
47529+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47530 #else
47531- atomic_add(rx_status.dropped_packets,
47532- (atomic_t *)&priv->stats.rx_dropped);
47533+ atomic_add_unchecked(rx_status.dropped_packets,
47534+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47535 #endif
47536 }
47537
47538diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47539index dc23395..cf7e9b1 100644
47540--- a/drivers/staging/rtl8712/rtl871x_io.h
47541+++ b/drivers/staging/rtl8712/rtl871x_io.h
47542@@ -108,7 +108,7 @@ struct _io_ops {
47543 u8 *pmem);
47544 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47545 u8 *pmem);
47546-};
47547+} __no_const;
47548
47549 struct io_req {
47550 struct list_head list;
47551diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47552index 1f5088b..0e59820 100644
47553--- a/drivers/staging/sbe-2t3e3/netdev.c
47554+++ b/drivers/staging/sbe-2t3e3/netdev.c
47555@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47556 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47557
47558 if (rlen)
47559- if (copy_to_user(data, &resp, rlen))
47560+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47561 return -EFAULT;
47562
47563 return 0;
47564diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47565index a863a98..d272795 100644
47566--- a/drivers/staging/usbip/vhci.h
47567+++ b/drivers/staging/usbip/vhci.h
47568@@ -83,7 +83,7 @@ struct vhci_hcd {
47569 unsigned resuming:1;
47570 unsigned long re_timeout;
47571
47572- atomic_t seqnum;
47573+ atomic_unchecked_t seqnum;
47574
47575 /*
47576 * NOTE:
47577diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47578index d7974cb..d78076b 100644
47579--- a/drivers/staging/usbip/vhci_hcd.c
47580+++ b/drivers/staging/usbip/vhci_hcd.c
47581@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47582
47583 spin_lock(&vdev->priv_lock);
47584
47585- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47586+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47587 if (priv->seqnum == 0xffff)
47588 dev_info(&urb->dev->dev, "seqnum max\n");
47589
47590@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47591 return -ENOMEM;
47592 }
47593
47594- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47595+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47596 if (unlink->seqnum == 0xffff)
47597 pr_info("seqnum max\n");
47598
47599@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47600 vdev->rhport = rhport;
47601 }
47602
47603- atomic_set(&vhci->seqnum, 0);
47604+ atomic_set_unchecked(&vhci->seqnum, 0);
47605 spin_lock_init(&vhci->lock);
47606
47607 hcd->power_budget = 0; /* no limit */
47608diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47609index d07fcb5..358e1e1 100644
47610--- a/drivers/staging/usbip/vhci_rx.c
47611+++ b/drivers/staging/usbip/vhci_rx.c
47612@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47613 if (!urb) {
47614 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47615 pr_info("max seqnum %d\n",
47616- atomic_read(&the_controller->seqnum));
47617+ atomic_read_unchecked(&the_controller->seqnum));
47618 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47619 return;
47620 }
47621diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47622index 57a08c5..5b4bb7c 100644
47623--- a/drivers/staging/vt6655/hostap.c
47624+++ b/drivers/staging/vt6655/hostap.c
47625@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47626 *
47627 */
47628
47629+static net_device_ops_no_const apdev_netdev_ops;
47630+
47631 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47632 {
47633 PSDevice apdev_priv;
47634 struct net_device *dev = pDevice->dev;
47635 int ret;
47636- const struct net_device_ops apdev_netdev_ops = {
47637- .ndo_start_xmit = pDevice->tx_80211,
47638- };
47639
47640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47641
47642@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47643 *apdev_priv = *pDevice;
47644 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47645
47646+ /* only half broken now */
47647+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47648 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47649
47650 pDevice->apdev->type = ARPHRD_IEEE80211;
47651diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47652index c699a30..b90a5fd 100644
47653--- a/drivers/staging/vt6656/hostap.c
47654+++ b/drivers/staging/vt6656/hostap.c
47655@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47656 *
47657 */
47658
47659+static net_device_ops_no_const apdev_netdev_ops;
47660+
47661 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47662 {
47663 struct vnt_private *apdev_priv;
47664 struct net_device *dev = pDevice->dev;
47665 int ret;
47666- const struct net_device_ops apdev_netdev_ops = {
47667- .ndo_start_xmit = pDevice->tx_80211,
47668- };
47669
47670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47671
47672@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47673 *apdev_priv = *pDevice;
47674 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47675
47676+ /* only half broken now */
47677+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47678 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47679
47680 pDevice->apdev->type = ARPHRD_IEEE80211;
47681diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47682index d128ce2..fc1f9a1 100644
47683--- a/drivers/staging/zcache/tmem.h
47684+++ b/drivers/staging/zcache/tmem.h
47685@@ -225,7 +225,7 @@ struct tmem_pamops {
47686 bool (*is_remote)(void *);
47687 int (*replace_in_obj)(void *, struct tmem_obj *);
47688 #endif
47689-};
47690+} __no_const;
47691 extern void tmem_register_pamops(struct tmem_pamops *m);
47692
47693 /* memory allocation methods provided by the host implementation */
47694@@ -234,7 +234,7 @@ struct tmem_hostops {
47695 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47696 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47697 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47698-};
47699+} __no_const;
47700 extern void tmem_register_hostops(struct tmem_hostops *m);
47701
47702 /* core tmem accessor functions */
47703diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47704index e51b09a..5ebac31 100644
47705--- a/drivers/target/sbp/sbp_target.c
47706+++ b/drivers/target/sbp/sbp_target.c
47707@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47708
47709 #define SESSION_MAINTENANCE_INTERVAL HZ
47710
47711-static atomic_t login_id = ATOMIC_INIT(0);
47712+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47713
47714 static void session_maintenance_work(struct work_struct *);
47715 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47716@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47717 login->lun = se_lun;
47718 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47719 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47720- login->login_id = atomic_inc_return(&login_id);
47721+ login->login_id = atomic_inc_return_unchecked(&login_id);
47722
47723 login->tgt_agt = sbp_target_agent_register(login);
47724 if (IS_ERR(login->tgt_agt)) {
47725diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47726index 8f4142f..b127f7d 100644
47727--- a/drivers/target/target_core_device.c
47728+++ b/drivers/target/target_core_device.c
47729@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47730 spin_lock_init(&dev->se_port_lock);
47731 spin_lock_init(&dev->se_tmr_lock);
47732 spin_lock_init(&dev->qf_cmd_lock);
47733- atomic_set(&dev->dev_ordered_id, 0);
47734+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47735 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47736 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47737 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47738diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47739index d8e49d7..6fcfdec 100644
47740--- a/drivers/target/target_core_transport.c
47741+++ b/drivers/target/target_core_transport.c
47742@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47743 * Used to determine when ORDERED commands should go from
47744 * Dormant to Active status.
47745 */
47746- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47747+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47748 smp_mb__after_atomic_inc();
47749 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47750 cmd->se_ordered_id, cmd->sam_task_attr,
47751diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47752index 33f83fe..d80f8e1 100644
47753--- a/drivers/tty/cyclades.c
47754+++ b/drivers/tty/cyclades.c
47755@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47756 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47757 info->port.count);
47758 #endif
47759- info->port.count++;
47760+ atomic_inc(&info->port.count);
47761 #ifdef CY_DEBUG_COUNT
47762 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47763- current->pid, info->port.count);
47764+ current->pid, atomic_read(&info->port.count));
47765 #endif
47766
47767 /*
47768@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47769 for (j = 0; j < cy_card[i].nports; j++) {
47770 info = &cy_card[i].ports[j];
47771
47772- if (info->port.count) {
47773+ if (atomic_read(&info->port.count)) {
47774 /* XXX is the ldisc num worth this? */
47775 struct tty_struct *tty;
47776 struct tty_ldisc *ld;
47777diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47778index eb255e8..f637a57 100644
47779--- a/drivers/tty/hvc/hvc_console.c
47780+++ b/drivers/tty/hvc/hvc_console.c
47781@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47782
47783 spin_lock_irqsave(&hp->port.lock, flags);
47784 /* Check and then increment for fast path open. */
47785- if (hp->port.count++ > 0) {
47786+ if (atomic_inc_return(&hp->port.count) > 1) {
47787 spin_unlock_irqrestore(&hp->port.lock, flags);
47788 hvc_kick();
47789 return 0;
47790@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47791
47792 spin_lock_irqsave(&hp->port.lock, flags);
47793
47794- if (--hp->port.count == 0) {
47795+ if (atomic_dec_return(&hp->port.count) == 0) {
47796 spin_unlock_irqrestore(&hp->port.lock, flags);
47797 /* We are done with the tty pointer now. */
47798 tty_port_tty_set(&hp->port, NULL);
47799@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47800 */
47801 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47802 } else {
47803- if (hp->port.count < 0)
47804+ if (atomic_read(&hp->port.count) < 0)
47805 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47806- hp->vtermno, hp->port.count);
47807+ hp->vtermno, atomic_read(&hp->port.count));
47808 spin_unlock_irqrestore(&hp->port.lock, flags);
47809 }
47810 }
47811@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47812 * open->hangup case this can be called after the final close so prevent
47813 * that from happening for now.
47814 */
47815- if (hp->port.count <= 0) {
47816+ if (atomic_read(&hp->port.count) <= 0) {
47817 spin_unlock_irqrestore(&hp->port.lock, flags);
47818 return;
47819 }
47820
47821- hp->port.count = 0;
47822+ atomic_set(&hp->port.count, 0);
47823 spin_unlock_irqrestore(&hp->port.lock, flags);
47824 tty_port_tty_set(&hp->port, NULL);
47825
47826@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47827 return -EPIPE;
47828
47829 /* FIXME what's this (unprotected) check for? */
47830- if (hp->port.count <= 0)
47831+ if (atomic_read(&hp->port.count) <= 0)
47832 return -EIO;
47833
47834 spin_lock_irqsave(&hp->lock, flags);
47835diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47836index 81e939e..95ead10 100644
47837--- a/drivers/tty/hvc/hvcs.c
47838+++ b/drivers/tty/hvc/hvcs.c
47839@@ -83,6 +83,7 @@
47840 #include <asm/hvcserver.h>
47841 #include <asm/uaccess.h>
47842 #include <asm/vio.h>
47843+#include <asm/local.h>
47844
47845 /*
47846 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47847@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47848
47849 spin_lock_irqsave(&hvcsd->lock, flags);
47850
47851- if (hvcsd->port.count > 0) {
47852+ if (atomic_read(&hvcsd->port.count) > 0) {
47853 spin_unlock_irqrestore(&hvcsd->lock, flags);
47854 printk(KERN_INFO "HVCS: vterm state unchanged. "
47855 "The hvcs device node is still in use.\n");
47856@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47857 }
47858 }
47859
47860- hvcsd->port.count = 0;
47861+ atomic_set(&hvcsd->port.count, 0);
47862 hvcsd->port.tty = tty;
47863 tty->driver_data = hvcsd;
47864
47865@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47866 unsigned long flags;
47867
47868 spin_lock_irqsave(&hvcsd->lock, flags);
47869- hvcsd->port.count++;
47870+ atomic_inc(&hvcsd->port.count);
47871 hvcsd->todo_mask |= HVCS_SCHED_READ;
47872 spin_unlock_irqrestore(&hvcsd->lock, flags);
47873
47874@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47875 hvcsd = tty->driver_data;
47876
47877 spin_lock_irqsave(&hvcsd->lock, flags);
47878- if (--hvcsd->port.count == 0) {
47879+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47880
47881 vio_disable_interrupts(hvcsd->vdev);
47882
47883@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47884
47885 free_irq(irq, hvcsd);
47886 return;
47887- } else if (hvcsd->port.count < 0) {
47888+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47889 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47890 " is missmanaged.\n",
47891- hvcsd->vdev->unit_address, hvcsd->port.count);
47892+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47893 }
47894
47895 spin_unlock_irqrestore(&hvcsd->lock, flags);
47896@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47897
47898 spin_lock_irqsave(&hvcsd->lock, flags);
47899 /* Preserve this so that we know how many kref refs to put */
47900- temp_open_count = hvcsd->port.count;
47901+ temp_open_count = atomic_read(&hvcsd->port.count);
47902
47903 /*
47904 * Don't kref put inside the spinlock because the destruction
47905@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47906 tty->driver_data = NULL;
47907 hvcsd->port.tty = NULL;
47908
47909- hvcsd->port.count = 0;
47910+ atomic_set(&hvcsd->port.count, 0);
47911
47912 /* This will drop any buffered data on the floor which is OK in a hangup
47913 * scenario. */
47914@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47915 * the middle of a write operation? This is a crummy place to do this
47916 * but we want to keep it all in the spinlock.
47917 */
47918- if (hvcsd->port.count <= 0) {
47919+ if (atomic_read(&hvcsd->port.count) <= 0) {
47920 spin_unlock_irqrestore(&hvcsd->lock, flags);
47921 return -ENODEV;
47922 }
47923@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47924 {
47925 struct hvcs_struct *hvcsd = tty->driver_data;
47926
47927- if (!hvcsd || hvcsd->port.count <= 0)
47928+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47929 return 0;
47930
47931 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47932diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47933index 4190199..48f2920 100644
47934--- a/drivers/tty/hvc/hvsi.c
47935+++ b/drivers/tty/hvc/hvsi.c
47936@@ -85,7 +85,7 @@ struct hvsi_struct {
47937 int n_outbuf;
47938 uint32_t vtermno;
47939 uint32_t virq;
47940- atomic_t seqno; /* HVSI packet sequence number */
47941+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47942 uint16_t mctrl;
47943 uint8_t state; /* HVSI protocol state */
47944 uint8_t flags;
47945@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47946
47947 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47948 packet.hdr.len = sizeof(struct hvsi_query_response);
47949- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47950+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47951 packet.verb = VSV_SEND_VERSION_NUMBER;
47952 packet.u.version = HVSI_VERSION;
47953 packet.query_seqno = query_seqno+1;
47954@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47955
47956 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47957 packet.hdr.len = sizeof(struct hvsi_query);
47958- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47959+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47960 packet.verb = verb;
47961
47962 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47963@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47964 int wrote;
47965
47966 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47967- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47968+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47969 packet.hdr.len = sizeof(struct hvsi_control);
47970 packet.verb = VSV_SET_MODEM_CTL;
47971 packet.mask = HVSI_TSDTR;
47972@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47973 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47974
47975 packet.hdr.type = VS_DATA_PACKET_HEADER;
47976- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47977+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47978 packet.hdr.len = count + sizeof(struct hvsi_header);
47979 memcpy(&packet.data, buf, count);
47980
47981@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47982 struct hvsi_control packet __ALIGNED__;
47983
47984 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47985- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47986+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47987 packet.hdr.len = 6;
47988 packet.verb = VSV_CLOSE_PROTOCOL;
47989
47990diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47991index ac27671..0f627ee 100644
47992--- a/drivers/tty/hvc/hvsi_lib.c
47993+++ b/drivers/tty/hvc/hvsi_lib.c
47994@@ -9,7 +9,7 @@
47995
47996 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47997 {
47998- packet->seqno = atomic_inc_return(&pv->seqno);
47999+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
48000
48001 /* Assumes that always succeeds, works in practice */
48002 return pv->put_chars(pv->termno, (char *)packet, packet->len);
48003@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
48004
48005 /* Reset state */
48006 pv->established = 0;
48007- atomic_set(&pv->seqno, 0);
48008+ atomic_set_unchecked(&pv->seqno, 0);
48009
48010 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
48011
48012@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
48013 pv->mctrl_update = 0;
48014 q.hdr.type = VS_QUERY_PACKET_HEADER;
48015 q.hdr.len = sizeof(struct hvsi_query);
48016- q.hdr.seqno = atomic_inc_return(&pv->seqno);
48017+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
48018 q.verb = VSV_SEND_MODEM_CTL_STATUS;
48019 rc = hvsi_send_packet(pv, &q.hdr);
48020 if (rc <= 0) {
48021diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
48022index 8fd72ff..34a0bed 100644
48023--- a/drivers/tty/ipwireless/tty.c
48024+++ b/drivers/tty/ipwireless/tty.c
48025@@ -29,6 +29,7 @@
48026 #include <linux/tty_driver.h>
48027 #include <linux/tty_flip.h>
48028 #include <linux/uaccess.h>
48029+#include <asm/local.h>
48030
48031 #include "tty.h"
48032 #include "network.h"
48033@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48034 mutex_unlock(&tty->ipw_tty_mutex);
48035 return -ENODEV;
48036 }
48037- if (tty->port.count == 0)
48038+ if (atomic_read(&tty->port.count) == 0)
48039 tty->tx_bytes_queued = 0;
48040
48041- tty->port.count++;
48042+ atomic_inc(&tty->port.count);
48043
48044 tty->port.tty = linux_tty;
48045 linux_tty->driver_data = tty;
48046@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48047
48048 static void do_ipw_close(struct ipw_tty *tty)
48049 {
48050- tty->port.count--;
48051-
48052- if (tty->port.count == 0) {
48053+ if (atomic_dec_return(&tty->port.count) == 0) {
48054 struct tty_struct *linux_tty = tty->port.tty;
48055
48056 if (linux_tty != NULL) {
48057@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
48058 return;
48059
48060 mutex_lock(&tty->ipw_tty_mutex);
48061- if (tty->port.count == 0) {
48062+ if (atomic_read(&tty->port.count) == 0) {
48063 mutex_unlock(&tty->ipw_tty_mutex);
48064 return;
48065 }
48066@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48067
48068 mutex_lock(&tty->ipw_tty_mutex);
48069
48070- if (!tty->port.count) {
48071+ if (!atomic_read(&tty->port.count)) {
48072 mutex_unlock(&tty->ipw_tty_mutex);
48073 return;
48074 }
48075@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48076 return -ENODEV;
48077
48078 mutex_lock(&tty->ipw_tty_mutex);
48079- if (!tty->port.count) {
48080+ if (!atomic_read(&tty->port.count)) {
48081 mutex_unlock(&tty->ipw_tty_mutex);
48082 return -EINVAL;
48083 }
48084@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48085 if (!tty)
48086 return -ENODEV;
48087
48088- if (!tty->port.count)
48089+ if (!atomic_read(&tty->port.count))
48090 return -EINVAL;
48091
48092 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48093@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48094 if (!tty)
48095 return 0;
48096
48097- if (!tty->port.count)
48098+ if (!atomic_read(&tty->port.count))
48099 return 0;
48100
48101 return tty->tx_bytes_queued;
48102@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48103 if (!tty)
48104 return -ENODEV;
48105
48106- if (!tty->port.count)
48107+ if (!atomic_read(&tty->port.count))
48108 return -EINVAL;
48109
48110 return get_control_lines(tty);
48111@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48112 if (!tty)
48113 return -ENODEV;
48114
48115- if (!tty->port.count)
48116+ if (!atomic_read(&tty->port.count))
48117 return -EINVAL;
48118
48119 return set_control_lines(tty, set, clear);
48120@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48121 if (!tty)
48122 return -ENODEV;
48123
48124- if (!tty->port.count)
48125+ if (!atomic_read(&tty->port.count))
48126 return -EINVAL;
48127
48128 /* FIXME: Exactly how is the tty object locked here .. */
48129@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48130 * are gone */
48131 mutex_lock(&ttyj->ipw_tty_mutex);
48132 }
48133- while (ttyj->port.count)
48134+ while (atomic_read(&ttyj->port.count))
48135 do_ipw_close(ttyj);
48136 ipwireless_disassociate_network_ttys(network,
48137 ttyj->channel_idx);
48138diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48139index 1deaca4..c8582d4 100644
48140--- a/drivers/tty/moxa.c
48141+++ b/drivers/tty/moxa.c
48142@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48143 }
48144
48145 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48146- ch->port.count++;
48147+ atomic_inc(&ch->port.count);
48148 tty->driver_data = ch;
48149 tty_port_tty_set(&ch->port, tty);
48150 mutex_lock(&ch->port.mutex);
48151diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48152index 6422390..49003ac8 100644
48153--- a/drivers/tty/n_gsm.c
48154+++ b/drivers/tty/n_gsm.c
48155@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48156 spin_lock_init(&dlci->lock);
48157 mutex_init(&dlci->mutex);
48158 dlci->fifo = &dlci->_fifo;
48159- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48160+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48161 kfree(dlci);
48162 return NULL;
48163 }
48164@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48165 struct gsm_dlci *dlci = tty->driver_data;
48166 struct tty_port *port = &dlci->port;
48167
48168- port->count++;
48169+ atomic_inc(&port->count);
48170 dlci_get(dlci);
48171 dlci_get(dlci->gsm->dlci[0]);
48172 mux_get(dlci->gsm);
48173diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48174index 4bf0fc0..433bd58 100644
48175--- a/drivers/tty/n_tty.c
48176+++ b/drivers/tty/n_tty.c
48177@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48178 {
48179 *ops = tty_ldisc_N_TTY;
48180 ops->owner = NULL;
48181- ops->refcount = ops->flags = 0;
48182+ atomic_set(&ops->refcount, 0);
48183+ ops->flags = 0;
48184 }
48185 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48186diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48187index abfd990..5ab5da9 100644
48188--- a/drivers/tty/pty.c
48189+++ b/drivers/tty/pty.c
48190@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48191 panic("Couldn't register Unix98 pts driver");
48192
48193 /* Now create the /dev/ptmx special device */
48194+ pax_open_kernel();
48195 tty_default_fops(&ptmx_fops);
48196- ptmx_fops.open = ptmx_open;
48197+ *(void **)&ptmx_fops.open = ptmx_open;
48198+ pax_close_kernel();
48199
48200 cdev_init(&ptmx_cdev, &ptmx_fops);
48201 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48202diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48203index 354564e..fe50d9a 100644
48204--- a/drivers/tty/rocket.c
48205+++ b/drivers/tty/rocket.c
48206@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48207 tty->driver_data = info;
48208 tty_port_tty_set(port, tty);
48209
48210- if (port->count++ == 0) {
48211+ if (atomic_inc_return(&port->count) == 1) {
48212 atomic_inc(&rp_num_ports_open);
48213
48214 #ifdef ROCKET_DEBUG_OPEN
48215@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48216 #endif
48217 }
48218 #ifdef ROCKET_DEBUG_OPEN
48219- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48220+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48221 #endif
48222
48223 /*
48224@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48225 spin_unlock_irqrestore(&info->port.lock, flags);
48226 return;
48227 }
48228- if (info->port.count)
48229+ if (atomic_read(&info->port.count))
48230 atomic_dec(&rp_num_ports_open);
48231 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48232 spin_unlock_irqrestore(&info->port.lock, flags);
48233diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48234index e2520ab..034e20b 100644
48235--- a/drivers/tty/serial/ioc4_serial.c
48236+++ b/drivers/tty/serial/ioc4_serial.c
48237@@ -437,7 +437,7 @@ struct ioc4_soft {
48238 } is_intr_info[MAX_IOC4_INTR_ENTS];
48239
48240 /* Number of entries active in the above array */
48241- atomic_t is_num_intrs;
48242+ atomic_unchecked_t is_num_intrs;
48243 } is_intr_type[IOC4_NUM_INTR_TYPES];
48244
48245 /* is_ir_lock must be held while
48246@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48247 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48248 || (type == IOC4_OTHER_INTR_TYPE)));
48249
48250- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48251+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48252 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48253
48254 /* Save off the lower level interrupt handler */
48255@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48256
48257 soft = arg;
48258 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48259- num_intrs = (int)atomic_read(
48260+ num_intrs = (int)atomic_read_unchecked(
48261 &soft->is_intr_type[intr_type].is_num_intrs);
48262
48263 this_mir = this_ir = pending_intrs(soft, intr_type);
48264diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48265index 1002054..dd644a8 100644
48266--- a/drivers/tty/serial/kgdboc.c
48267+++ b/drivers/tty/serial/kgdboc.c
48268@@ -24,8 +24,9 @@
48269 #define MAX_CONFIG_LEN 40
48270
48271 static struct kgdb_io kgdboc_io_ops;
48272+static struct kgdb_io kgdboc_io_ops_console;
48273
48274-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48275+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48276 static int configured = -1;
48277
48278 static char config[MAX_CONFIG_LEN];
48279@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48280 kgdboc_unregister_kbd();
48281 if (configured == 1)
48282 kgdb_unregister_io_module(&kgdboc_io_ops);
48283+ else if (configured == 2)
48284+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48285 }
48286
48287 static int configure_kgdboc(void)
48288@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48289 int err;
48290 char *cptr = config;
48291 struct console *cons;
48292+ int is_console = 0;
48293
48294 err = kgdboc_option_setup(config);
48295 if (err || !strlen(config) || isspace(config[0]))
48296 goto noconfig;
48297
48298 err = -ENODEV;
48299- kgdboc_io_ops.is_console = 0;
48300 kgdb_tty_driver = NULL;
48301
48302 kgdboc_use_kms = 0;
48303@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48304 int idx;
48305 if (cons->device && cons->device(cons, &idx) == p &&
48306 idx == tty_line) {
48307- kgdboc_io_ops.is_console = 1;
48308+ is_console = 1;
48309 break;
48310 }
48311 cons = cons->next;
48312@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48313 kgdb_tty_line = tty_line;
48314
48315 do_register:
48316- err = kgdb_register_io_module(&kgdboc_io_ops);
48317+ if (is_console) {
48318+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48319+ configured = 2;
48320+ } else {
48321+ err = kgdb_register_io_module(&kgdboc_io_ops);
48322+ configured = 1;
48323+ }
48324 if (err)
48325 goto noconfig;
48326
48327@@ -205,8 +214,6 @@ do_register:
48328 if (err)
48329 goto nmi_con_failed;
48330
48331- configured = 1;
48332-
48333 return 0;
48334
48335 nmi_con_failed:
48336@@ -223,7 +230,7 @@ noconfig:
48337 static int __init init_kgdboc(void)
48338 {
48339 /* Already configured? */
48340- if (configured == 1)
48341+ if (configured >= 1)
48342 return 0;
48343
48344 return configure_kgdboc();
48345@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48346 if (config[len - 1] == '\n')
48347 config[len - 1] = '\0';
48348
48349- if (configured == 1)
48350+ if (configured >= 1)
48351 cleanup_kgdboc();
48352
48353 /* Go and configure with the new params. */
48354@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48355 .post_exception = kgdboc_post_exp_handler,
48356 };
48357
48358+static struct kgdb_io kgdboc_io_ops_console = {
48359+ .name = "kgdboc",
48360+ .read_char = kgdboc_get_char,
48361+ .write_char = kgdboc_put_char,
48362+ .pre_exception = kgdboc_pre_exp_handler,
48363+ .post_exception = kgdboc_post_exp_handler,
48364+ .is_console = 1
48365+};
48366+
48367 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48368 /* This is only available if kgdboc is a built in for early debugging */
48369 static int __init kgdboc_early_init(char *opt)
48370diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48371index 2c6cfb3..048274e 100644
48372--- a/drivers/tty/serial/msm_serial.c
48373+++ b/drivers/tty/serial/msm_serial.c
48374@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48375 .cons = MSM_CONSOLE,
48376 };
48377
48378-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48379+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48380
48381 static int __init msm_serial_probe(struct platform_device *pdev)
48382 {
48383@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48384 int irq;
48385
48386 if (pdev->id == -1)
48387- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48388+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48389
48390 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48391 return -ENXIO;
48392diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48393index 376079b..d8de7aa 100644
48394--- a/drivers/tty/serial/samsung.c
48395+++ b/drivers/tty/serial/samsung.c
48396@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48397 }
48398 }
48399
48400+static int s3c64xx_serial_startup(struct uart_port *port);
48401 static int s3c24xx_serial_startup(struct uart_port *port)
48402 {
48403 struct s3c24xx_uart_port *ourport = to_ourport(port);
48404 int ret;
48405
48406+ /* Startup sequence is different for s3c64xx and higher SoC's */
48407+ if (s3c24xx_serial_has_interrupt_mask(port))
48408+ return s3c64xx_serial_startup(port);
48409+
48410 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48411 port->mapbase, port->membase);
48412
48413@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48414 /* setup info for port */
48415 port->dev = &platdev->dev;
48416
48417- /* Startup sequence is different for s3c64xx and higher SoC's */
48418- if (s3c24xx_serial_has_interrupt_mask(port))
48419- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48420-
48421 port->uartclk = 1;
48422
48423 if (cfg->uart_flags & UPF_CONS_FLOW) {
48424diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48425index 28cdd28..56f1d60 100644
48426--- a/drivers/tty/serial/serial_core.c
48427+++ b/drivers/tty/serial/serial_core.c
48428@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48429 uart_flush_buffer(tty);
48430 uart_shutdown(tty, state);
48431 spin_lock_irqsave(&port->lock, flags);
48432- port->count = 0;
48433+ atomic_set(&port->count, 0);
48434 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48435 spin_unlock_irqrestore(&port->lock, flags);
48436 tty_port_tty_set(port, NULL);
48437@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48438 goto end;
48439 }
48440
48441- port->count++;
48442+ atomic_inc(&port->count);
48443 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48444 retval = -ENXIO;
48445 goto err_dec_count;
48446@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48447 /*
48448 * Make sure the device is in D0 state.
48449 */
48450- if (port->count == 1)
48451+ if (atomic_read(&port->count) == 1)
48452 uart_change_pm(state, UART_PM_STATE_ON);
48453
48454 /*
48455@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48456 end:
48457 return retval;
48458 err_dec_count:
48459- port->count--;
48460+ atomic_inc(&port->count);
48461 mutex_unlock(&port->mutex);
48462 goto end;
48463 }
48464diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48465index 8eaf1ab..85c030d 100644
48466--- a/drivers/tty/synclink.c
48467+++ b/drivers/tty/synclink.c
48468@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48469
48470 if (debug_level >= DEBUG_LEVEL_INFO)
48471 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48472- __FILE__,__LINE__, info->device_name, info->port.count);
48473+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48474
48475 if (tty_port_close_start(&info->port, tty, filp) == 0)
48476 goto cleanup;
48477@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48478 cleanup:
48479 if (debug_level >= DEBUG_LEVEL_INFO)
48480 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48481- tty->driver->name, info->port.count);
48482+ tty->driver->name, atomic_read(&info->port.count));
48483
48484 } /* end of mgsl_close() */
48485
48486@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48487
48488 mgsl_flush_buffer(tty);
48489 shutdown(info);
48490-
48491- info->port.count = 0;
48492+
48493+ atomic_set(&info->port.count, 0);
48494 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48495 info->port.tty = NULL;
48496
48497@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48498
48499 if (debug_level >= DEBUG_LEVEL_INFO)
48500 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48501- __FILE__,__LINE__, tty->driver->name, port->count );
48502+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48503
48504 spin_lock_irqsave(&info->irq_spinlock, flags);
48505 if (!tty_hung_up_p(filp)) {
48506 extra_count = true;
48507- port->count--;
48508+ atomic_dec(&port->count);
48509 }
48510 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48511 port->blocked_open++;
48512@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48513
48514 if (debug_level >= DEBUG_LEVEL_INFO)
48515 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48516- __FILE__,__LINE__, tty->driver->name, port->count );
48517+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48518
48519 tty_unlock(tty);
48520 schedule();
48521@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48522
48523 /* FIXME: Racy on hangup during close wait */
48524 if (extra_count)
48525- port->count++;
48526+ atomic_inc(&port->count);
48527 port->blocked_open--;
48528
48529 if (debug_level >= DEBUG_LEVEL_INFO)
48530 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48531- __FILE__,__LINE__, tty->driver->name, port->count );
48532+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48533
48534 if (!retval)
48535 port->flags |= ASYNC_NORMAL_ACTIVE;
48536@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48537
48538 if (debug_level >= DEBUG_LEVEL_INFO)
48539 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48540- __FILE__,__LINE__,tty->driver->name, info->port.count);
48541+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48542
48543 /* If port is closing, signal caller to try again */
48544 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48545@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48546 spin_unlock_irqrestore(&info->netlock, flags);
48547 goto cleanup;
48548 }
48549- info->port.count++;
48550+ atomic_inc(&info->port.count);
48551 spin_unlock_irqrestore(&info->netlock, flags);
48552
48553- if (info->port.count == 1) {
48554+ if (atomic_read(&info->port.count) == 1) {
48555 /* 1st open on this device, init hardware */
48556 retval = startup(info);
48557 if (retval < 0)
48558@@ -3446,8 +3446,8 @@ cleanup:
48559 if (retval) {
48560 if (tty->count == 1)
48561 info->port.tty = NULL; /* tty layer will release tty struct */
48562- if(info->port.count)
48563- info->port.count--;
48564+ if (atomic_read(&info->port.count))
48565+ atomic_dec(&info->port.count);
48566 }
48567
48568 return retval;
48569@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48570 unsigned short new_crctype;
48571
48572 /* return error if TTY interface open */
48573- if (info->port.count)
48574+ if (atomic_read(&info->port.count))
48575 return -EBUSY;
48576
48577 switch (encoding)
48578@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48579
48580 /* arbitrate between network and tty opens */
48581 spin_lock_irqsave(&info->netlock, flags);
48582- if (info->port.count != 0 || info->netcount != 0) {
48583+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48584 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48585 spin_unlock_irqrestore(&info->netlock, flags);
48586 return -EBUSY;
48587@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48588 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48589
48590 /* return error if TTY interface open */
48591- if (info->port.count)
48592+ if (atomic_read(&info->port.count))
48593 return -EBUSY;
48594
48595 if (cmd != SIOCWANDEV)
48596diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48597index 1abf946..1ee34fc 100644
48598--- a/drivers/tty/synclink_gt.c
48599+++ b/drivers/tty/synclink_gt.c
48600@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48601 tty->driver_data = info;
48602 info->port.tty = tty;
48603
48604- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48605+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48606
48607 /* If port is closing, signal caller to try again */
48608 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48609@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48610 mutex_unlock(&info->port.mutex);
48611 goto cleanup;
48612 }
48613- info->port.count++;
48614+ atomic_inc(&info->port.count);
48615 spin_unlock_irqrestore(&info->netlock, flags);
48616
48617- if (info->port.count == 1) {
48618+ if (atomic_read(&info->port.count) == 1) {
48619 /* 1st open on this device, init hardware */
48620 retval = startup(info);
48621 if (retval < 0) {
48622@@ -715,8 +715,8 @@ cleanup:
48623 if (retval) {
48624 if (tty->count == 1)
48625 info->port.tty = NULL; /* tty layer will release tty struct */
48626- if(info->port.count)
48627- info->port.count--;
48628+ if(atomic_read(&info->port.count))
48629+ atomic_dec(&info->port.count);
48630 }
48631
48632 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48633@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48634
48635 if (sanity_check(info, tty->name, "close"))
48636 return;
48637- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48638+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48639
48640 if (tty_port_close_start(&info->port, tty, filp) == 0)
48641 goto cleanup;
48642@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48643 tty_port_close_end(&info->port, tty);
48644 info->port.tty = NULL;
48645 cleanup:
48646- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48647+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48648 }
48649
48650 static void hangup(struct tty_struct *tty)
48651@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48652 shutdown(info);
48653
48654 spin_lock_irqsave(&info->port.lock, flags);
48655- info->port.count = 0;
48656+ atomic_set(&info->port.count, 0);
48657 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48658 info->port.tty = NULL;
48659 spin_unlock_irqrestore(&info->port.lock, flags);
48660@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48661 unsigned short new_crctype;
48662
48663 /* return error if TTY interface open */
48664- if (info->port.count)
48665+ if (atomic_read(&info->port.count))
48666 return -EBUSY;
48667
48668 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48669@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48670
48671 /* arbitrate between network and tty opens */
48672 spin_lock_irqsave(&info->netlock, flags);
48673- if (info->port.count != 0 || info->netcount != 0) {
48674+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48675 DBGINFO(("%s hdlc_open busy\n", dev->name));
48676 spin_unlock_irqrestore(&info->netlock, flags);
48677 return -EBUSY;
48678@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48679 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48680
48681 /* return error if TTY interface open */
48682- if (info->port.count)
48683+ if (atomic_read(&info->port.count))
48684 return -EBUSY;
48685
48686 if (cmd != SIOCWANDEV)
48687@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48688 if (port == NULL)
48689 continue;
48690 spin_lock(&port->lock);
48691- if ((port->port.count || port->netcount) &&
48692+ if ((atomic_read(&port->port.count) || port->netcount) &&
48693 port->pending_bh && !port->bh_running &&
48694 !port->bh_requested) {
48695 DBGISR(("%s bh queued\n", port->device_name));
48696@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48697 spin_lock_irqsave(&info->lock, flags);
48698 if (!tty_hung_up_p(filp)) {
48699 extra_count = true;
48700- port->count--;
48701+ atomic_dec(&port->count);
48702 }
48703 spin_unlock_irqrestore(&info->lock, flags);
48704 port->blocked_open++;
48705@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48706 remove_wait_queue(&port->open_wait, &wait);
48707
48708 if (extra_count)
48709- port->count++;
48710+ atomic_inc(&port->count);
48711 port->blocked_open--;
48712
48713 if (!retval)
48714diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48715index dc6e969..5dc8786 100644
48716--- a/drivers/tty/synclinkmp.c
48717+++ b/drivers/tty/synclinkmp.c
48718@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48719
48720 if (debug_level >= DEBUG_LEVEL_INFO)
48721 printk("%s(%d):%s open(), old ref count = %d\n",
48722- __FILE__,__LINE__,tty->driver->name, info->port.count);
48723+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48724
48725 /* If port is closing, signal caller to try again */
48726 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48727@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48728 spin_unlock_irqrestore(&info->netlock, flags);
48729 goto cleanup;
48730 }
48731- info->port.count++;
48732+ atomic_inc(&info->port.count);
48733 spin_unlock_irqrestore(&info->netlock, flags);
48734
48735- if (info->port.count == 1) {
48736+ if (atomic_read(&info->port.count) == 1) {
48737 /* 1st open on this device, init hardware */
48738 retval = startup(info);
48739 if (retval < 0)
48740@@ -796,8 +796,8 @@ cleanup:
48741 if (retval) {
48742 if (tty->count == 1)
48743 info->port.tty = NULL; /* tty layer will release tty struct */
48744- if(info->port.count)
48745- info->port.count--;
48746+ if(atomic_read(&info->port.count))
48747+ atomic_dec(&info->port.count);
48748 }
48749
48750 return retval;
48751@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48752
48753 if (debug_level >= DEBUG_LEVEL_INFO)
48754 printk("%s(%d):%s close() entry, count=%d\n",
48755- __FILE__,__LINE__, info->device_name, info->port.count);
48756+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48757
48758 if (tty_port_close_start(&info->port, tty, filp) == 0)
48759 goto cleanup;
48760@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48761 cleanup:
48762 if (debug_level >= DEBUG_LEVEL_INFO)
48763 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48764- tty->driver->name, info->port.count);
48765+ tty->driver->name, atomic_read(&info->port.count));
48766 }
48767
48768 /* Called by tty_hangup() when a hangup is signaled.
48769@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48770 shutdown(info);
48771
48772 spin_lock_irqsave(&info->port.lock, flags);
48773- info->port.count = 0;
48774+ atomic_set(&info->port.count, 0);
48775 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48776 info->port.tty = NULL;
48777 spin_unlock_irqrestore(&info->port.lock, flags);
48778@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48779 unsigned short new_crctype;
48780
48781 /* return error if TTY interface open */
48782- if (info->port.count)
48783+ if (atomic_read(&info->port.count))
48784 return -EBUSY;
48785
48786 switch (encoding)
48787@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48788
48789 /* arbitrate between network and tty opens */
48790 spin_lock_irqsave(&info->netlock, flags);
48791- if (info->port.count != 0 || info->netcount != 0) {
48792+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48793 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48794 spin_unlock_irqrestore(&info->netlock, flags);
48795 return -EBUSY;
48796@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48797 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48798
48799 /* return error if TTY interface open */
48800- if (info->port.count)
48801+ if (atomic_read(&info->port.count))
48802 return -EBUSY;
48803
48804 if (cmd != SIOCWANDEV)
48805@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48806 * do not request bottom half processing if the
48807 * device is not open in a normal mode.
48808 */
48809- if ( port && (port->port.count || port->netcount) &&
48810+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48811 port->pending_bh && !port->bh_running &&
48812 !port->bh_requested ) {
48813 if ( debug_level >= DEBUG_LEVEL_ISR )
48814@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48815
48816 if (debug_level >= DEBUG_LEVEL_INFO)
48817 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48818- __FILE__,__LINE__, tty->driver->name, port->count );
48819+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48820
48821 spin_lock_irqsave(&info->lock, flags);
48822 if (!tty_hung_up_p(filp)) {
48823 extra_count = true;
48824- port->count--;
48825+ atomic_dec(&port->count);
48826 }
48827 spin_unlock_irqrestore(&info->lock, flags);
48828 port->blocked_open++;
48829@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48830
48831 if (debug_level >= DEBUG_LEVEL_INFO)
48832 printk("%s(%d):%s block_til_ready() count=%d\n",
48833- __FILE__,__LINE__, tty->driver->name, port->count );
48834+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48835
48836 tty_unlock(tty);
48837 schedule();
48838@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48839 remove_wait_queue(&port->open_wait, &wait);
48840
48841 if (extra_count)
48842- port->count++;
48843+ atomic_inc(&port->count);
48844 port->blocked_open--;
48845
48846 if (debug_level >= DEBUG_LEVEL_INFO)
48847 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48848- __FILE__,__LINE__, tty->driver->name, port->count );
48849+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48850
48851 if (!retval)
48852 port->flags |= ASYNC_NORMAL_ACTIVE;
48853diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48854index d5cc3ac..3263411 100644
48855--- a/drivers/tty/sysrq.c
48856+++ b/drivers/tty/sysrq.c
48857@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48858 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48859 size_t count, loff_t *ppos)
48860 {
48861- if (count) {
48862+ if (count && capable(CAP_SYS_ADMIN)) {
48863 char c;
48864
48865 if (get_user(c, buf))
48866diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48867index 366af83..6db51c3 100644
48868--- a/drivers/tty/tty_io.c
48869+++ b/drivers/tty/tty_io.c
48870@@ -3467,7 +3467,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48871
48872 void tty_default_fops(struct file_operations *fops)
48873 {
48874- *fops = tty_fops;
48875+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48876 }
48877
48878 /*
48879diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48880index 1afe192..73d2c20 100644
48881--- a/drivers/tty/tty_ldisc.c
48882+++ b/drivers/tty/tty_ldisc.c
48883@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48884 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48885 tty_ldiscs[disc] = new_ldisc;
48886 new_ldisc->num = disc;
48887- new_ldisc->refcount = 0;
48888+ atomic_set(&new_ldisc->refcount, 0);
48889 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48890
48891 return ret;
48892@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48893 return -EINVAL;
48894
48895 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48896- if (tty_ldiscs[disc]->refcount)
48897+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48898 ret = -EBUSY;
48899 else
48900 tty_ldiscs[disc] = NULL;
48901@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48902 if (ldops) {
48903 ret = ERR_PTR(-EAGAIN);
48904 if (try_module_get(ldops->owner)) {
48905- ldops->refcount++;
48906+ atomic_inc(&ldops->refcount);
48907 ret = ldops;
48908 }
48909 }
48910@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48911 unsigned long flags;
48912
48913 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48914- ldops->refcount--;
48915+ atomic_dec(&ldops->refcount);
48916 module_put(ldops->owner);
48917 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48918 }
48919@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48920 /* unreleased reader reference(s) will cause this WARN */
48921 WARN_ON(!atomic_dec_and_test(&ld->users));
48922
48923- ld->ops->refcount--;
48924+ atomic_dec(&ld->ops->refcount);
48925 module_put(ld->ops->owner);
48926 kfree(ld);
48927 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48928diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48929index f597e88..b7f68ed 100644
48930--- a/drivers/tty/tty_port.c
48931+++ b/drivers/tty/tty_port.c
48932@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48933 unsigned long flags;
48934
48935 spin_lock_irqsave(&port->lock, flags);
48936- port->count = 0;
48937+ atomic_set(&port->count, 0);
48938 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48939 tty = port->tty;
48940 if (tty)
48941@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48942 /* The port lock protects the port counts */
48943 spin_lock_irqsave(&port->lock, flags);
48944 if (!tty_hung_up_p(filp))
48945- port->count--;
48946+ atomic_dec(&port->count);
48947 port->blocked_open++;
48948 spin_unlock_irqrestore(&port->lock, flags);
48949
48950@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48951 we must not mess that up further */
48952 spin_lock_irqsave(&port->lock, flags);
48953 if (!tty_hung_up_p(filp))
48954- port->count++;
48955+ atomic_inc(&port->count);
48956 port->blocked_open--;
48957 if (retval == 0)
48958 port->flags |= ASYNC_NORMAL_ACTIVE;
48959@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48960 return 0;
48961 }
48962
48963- if (tty->count == 1 && port->count != 1) {
48964+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48965 printk(KERN_WARNING
48966 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48967- port->count);
48968- port->count = 1;
48969+ atomic_read(&port->count));
48970+ atomic_set(&port->count, 1);
48971 }
48972- if (--port->count < 0) {
48973+ if (atomic_dec_return(&port->count) < 0) {
48974 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48975- port->count);
48976- port->count = 0;
48977+ atomic_read(&port->count));
48978+ atomic_set(&port->count, 0);
48979 }
48980
48981- if (port->count) {
48982+ if (atomic_read(&port->count)) {
48983 spin_unlock_irqrestore(&port->lock, flags);
48984 if (port->ops->drop)
48985 port->ops->drop(port);
48986@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48987 {
48988 spin_lock_irq(&port->lock);
48989 if (!tty_hung_up_p(filp))
48990- ++port->count;
48991+ atomic_inc(&port->count);
48992 spin_unlock_irq(&port->lock);
48993 tty_port_tty_set(port, tty);
48994
48995diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48996index a9af1b9a..1e08e7f 100644
48997--- a/drivers/tty/vt/keyboard.c
48998+++ b/drivers/tty/vt/keyboard.c
48999@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
49000 kbd->kbdmode == VC_OFF) &&
49001 value != KVAL(K_SAK))
49002 return; /* SAK is allowed even in raw mode */
49003+
49004+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49005+ {
49006+ void *func = fn_handler[value];
49007+ if (func == fn_show_state || func == fn_show_ptregs ||
49008+ func == fn_show_mem)
49009+ return;
49010+ }
49011+#endif
49012+
49013 fn_handler[value](vc);
49014 }
49015
49016@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49017 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
49018 return -EFAULT;
49019
49020- if (!capable(CAP_SYS_TTY_CONFIG))
49021- perm = 0;
49022-
49023 switch (cmd) {
49024 case KDGKBENT:
49025 /* Ensure another thread doesn't free it under us */
49026@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49027 spin_unlock_irqrestore(&kbd_event_lock, flags);
49028 return put_user(val, &user_kbe->kb_value);
49029 case KDSKBENT:
49030+ if (!capable(CAP_SYS_TTY_CONFIG))
49031+ perm = 0;
49032+
49033 if (!perm)
49034 return -EPERM;
49035 if (!i && v == K_NOSUCHMAP) {
49036@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49037 int i, j, k;
49038 int ret;
49039
49040- if (!capable(CAP_SYS_TTY_CONFIG))
49041- perm = 0;
49042-
49043 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
49044 if (!kbs) {
49045 ret = -ENOMEM;
49046@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49047 kfree(kbs);
49048 return ((p && *p) ? -EOVERFLOW : 0);
49049 case KDSKBSENT:
49050+ if (!capable(CAP_SYS_TTY_CONFIG))
49051+ perm = 0;
49052+
49053 if (!perm) {
49054 ret = -EPERM;
49055 goto reterr;
49056diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
49057index 3b96f18..026a9bf 100644
49058--- a/drivers/uio/uio.c
49059+++ b/drivers/uio/uio.c
49060@@ -25,6 +25,7 @@
49061 #include <linux/kobject.h>
49062 #include <linux/cdev.h>
49063 #include <linux/uio_driver.h>
49064+#include <asm/local.h>
49065
49066 #define UIO_MAX_DEVICES (1U << MINORBITS)
49067
49068@@ -32,10 +33,10 @@ struct uio_device {
49069 struct module *owner;
49070 struct device *dev;
49071 int minor;
49072- atomic_t event;
49073+ atomic_unchecked_t event;
49074 struct fasync_struct *async_queue;
49075 wait_queue_head_t wait;
49076- int vma_count;
49077+ local_t vma_count;
49078 struct uio_info *info;
49079 struct kobject *map_dir;
49080 struct kobject *portio_dir;
49081@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
49082 struct device_attribute *attr, char *buf)
49083 {
49084 struct uio_device *idev = dev_get_drvdata(dev);
49085- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49086+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49087 }
49088
49089 static struct device_attribute uio_class_attributes[] = {
49090@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
49091 {
49092 struct uio_device *idev = info->uio_dev;
49093
49094- atomic_inc(&idev->event);
49095+ atomic_inc_unchecked(&idev->event);
49096 wake_up_interruptible(&idev->wait);
49097 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49098 }
49099@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49100 }
49101
49102 listener->dev = idev;
49103- listener->event_count = atomic_read(&idev->event);
49104+ listener->event_count = atomic_read_unchecked(&idev->event);
49105 filep->private_data = listener;
49106
49107 if (idev->info->open) {
49108@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49109 return -EIO;
49110
49111 poll_wait(filep, &idev->wait, wait);
49112- if (listener->event_count != atomic_read(&idev->event))
49113+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49114 return POLLIN | POLLRDNORM;
49115 return 0;
49116 }
49117@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49118 do {
49119 set_current_state(TASK_INTERRUPTIBLE);
49120
49121- event_count = atomic_read(&idev->event);
49122+ event_count = atomic_read_unchecked(&idev->event);
49123 if (event_count != listener->event_count) {
49124 if (copy_to_user(buf, &event_count, count))
49125 retval = -EFAULT;
49126@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
49127 static void uio_vma_open(struct vm_area_struct *vma)
49128 {
49129 struct uio_device *idev = vma->vm_private_data;
49130- idev->vma_count++;
49131+ local_inc(&idev->vma_count);
49132 }
49133
49134 static void uio_vma_close(struct vm_area_struct *vma)
49135 {
49136 struct uio_device *idev = vma->vm_private_data;
49137- idev->vma_count--;
49138+ local_dec(&idev->vma_count);
49139 }
49140
49141 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49142@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49143 idev->owner = owner;
49144 idev->info = info;
49145 init_waitqueue_head(&idev->wait);
49146- atomic_set(&idev->event, 0);
49147+ atomic_set_unchecked(&idev->event, 0);
49148
49149 ret = uio_get_minor(idev);
49150 if (ret)
49151diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49152index 8a7eb77..c00402f 100644
49153--- a/drivers/usb/atm/cxacru.c
49154+++ b/drivers/usb/atm/cxacru.c
49155@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49156 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49157 if (ret < 2)
49158 return -EINVAL;
49159- if (index < 0 || index > 0x7f)
49160+ if (index > 0x7f)
49161 return -EINVAL;
49162 pos += tmp;
49163
49164diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49165index 5e0d33a..cc10579 100644
49166--- a/drivers/usb/atm/usbatm.c
49167+++ b/drivers/usb/atm/usbatm.c
49168@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49169 if (printk_ratelimit())
49170 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49171 __func__, vpi, vci);
49172- atomic_inc(&vcc->stats->rx_err);
49173+ atomic_inc_unchecked(&vcc->stats->rx_err);
49174 return;
49175 }
49176
49177@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49178 if (length > ATM_MAX_AAL5_PDU) {
49179 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49180 __func__, length, vcc);
49181- atomic_inc(&vcc->stats->rx_err);
49182+ atomic_inc_unchecked(&vcc->stats->rx_err);
49183 goto out;
49184 }
49185
49186@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49187 if (sarb->len < pdu_length) {
49188 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49189 __func__, pdu_length, sarb->len, vcc);
49190- atomic_inc(&vcc->stats->rx_err);
49191+ atomic_inc_unchecked(&vcc->stats->rx_err);
49192 goto out;
49193 }
49194
49195 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49196 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49197 __func__, vcc);
49198- atomic_inc(&vcc->stats->rx_err);
49199+ atomic_inc_unchecked(&vcc->stats->rx_err);
49200 goto out;
49201 }
49202
49203@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49204 if (printk_ratelimit())
49205 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49206 __func__, length);
49207- atomic_inc(&vcc->stats->rx_drop);
49208+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49209 goto out;
49210 }
49211
49212@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49213
49214 vcc->push(vcc, skb);
49215
49216- atomic_inc(&vcc->stats->rx);
49217+ atomic_inc_unchecked(&vcc->stats->rx);
49218 out:
49219 skb_trim(sarb, 0);
49220 }
49221@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49222 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49223
49224 usbatm_pop(vcc, skb);
49225- atomic_inc(&vcc->stats->tx);
49226+ atomic_inc_unchecked(&vcc->stats->tx);
49227
49228 skb = skb_dequeue(&instance->sndqueue);
49229 }
49230@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49231 if (!left--)
49232 return sprintf(page,
49233 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49234- atomic_read(&atm_dev->stats.aal5.tx),
49235- atomic_read(&atm_dev->stats.aal5.tx_err),
49236- atomic_read(&atm_dev->stats.aal5.rx),
49237- atomic_read(&atm_dev->stats.aal5.rx_err),
49238- atomic_read(&atm_dev->stats.aal5.rx_drop));
49239+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49240+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49241+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49242+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49243+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49244
49245 if (!left--) {
49246 if (instance->disconnected)
49247diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49248index 2a3bbdf..91d72cf 100644
49249--- a/drivers/usb/core/devices.c
49250+++ b/drivers/usb/core/devices.c
49251@@ -126,7 +126,7 @@ static const char format_endpt[] =
49252 * time it gets called.
49253 */
49254 static struct device_connect_event {
49255- atomic_t count;
49256+ atomic_unchecked_t count;
49257 wait_queue_head_t wait;
49258 } device_event = {
49259 .count = ATOMIC_INIT(1),
49260@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49261
49262 void usbfs_conn_disc_event(void)
49263 {
49264- atomic_add(2, &device_event.count);
49265+ atomic_add_unchecked(2, &device_event.count);
49266 wake_up(&device_event.wait);
49267 }
49268
49269@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49270
49271 poll_wait(file, &device_event.wait, wait);
49272
49273- event_count = atomic_read(&device_event.count);
49274+ event_count = atomic_read_unchecked(&device_event.count);
49275 if (file->f_version != event_count) {
49276 file->f_version = event_count;
49277 return POLLIN | POLLRDNORM;
49278diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49279index 014dc99..4d25fd7 100644
49280--- a/drivers/usb/core/hcd.c
49281+++ b/drivers/usb/core/hcd.c
49282@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49283 */
49284 usb_get_urb(urb);
49285 atomic_inc(&urb->use_count);
49286- atomic_inc(&urb->dev->urbnum);
49287+ atomic_inc_unchecked(&urb->dev->urbnum);
49288 usbmon_urb_submit(&hcd->self, urb);
49289
49290 /* NOTE requirements on root-hub callers (usbfs and the hub
49291@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49292 urb->hcpriv = NULL;
49293 INIT_LIST_HEAD(&urb->urb_list);
49294 atomic_dec(&urb->use_count);
49295- atomic_dec(&urb->dev->urbnum);
49296+ atomic_dec_unchecked(&urb->dev->urbnum);
49297 if (atomic_read(&urb->reject))
49298 wake_up(&usb_kill_urb_queue);
49299 usb_put_urb(urb);
49300diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49301index 558313d..8cadfa5 100644
49302--- a/drivers/usb/core/hub.c
49303+++ b/drivers/usb/core/hub.c
49304@@ -27,6 +27,7 @@
49305 #include <linux/freezer.h>
49306 #include <linux/random.h>
49307 #include <linux/pm_qos.h>
49308+#include <linux/grsecurity.h>
49309
49310 #include <asm/uaccess.h>
49311 #include <asm/byteorder.h>
49312@@ -4426,6 +4427,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49313 goto done;
49314 return;
49315 }
49316+
49317+ if (gr_handle_new_usb())
49318+ goto done;
49319+
49320 if (hub_is_superspeed(hub->hdev))
49321 unit_load = 150;
49322 else
49323diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49324index e7ee1e4..1dfc9ea4 100644
49325--- a/drivers/usb/core/message.c
49326+++ b/drivers/usb/core/message.c
49327@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49328 * method can wait for it to complete. Since you don't have a handle on the
49329 * URB used, you can't cancel the request.
49330 */
49331-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49332+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49333 __u8 requesttype, __u16 value, __u16 index, void *data,
49334 __u16 size, int timeout)
49335 {
49336diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49337index d9284b9..17023c7 100644
49338--- a/drivers/usb/core/sysfs.c
49339+++ b/drivers/usb/core/sysfs.c
49340@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49341 struct usb_device *udev;
49342
49343 udev = to_usb_device(dev);
49344- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49345+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49346 }
49347 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49348
49349diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49350index 7dad603..350f7a9 100644
49351--- a/drivers/usb/core/usb.c
49352+++ b/drivers/usb/core/usb.c
49353@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49354 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49355 dev->state = USB_STATE_ATTACHED;
49356 dev->lpm_disable_count = 1;
49357- atomic_set(&dev->urbnum, 0);
49358+ atomic_set_unchecked(&dev->urbnum, 0);
49359
49360 INIT_LIST_HEAD(&dev->ep0.urb_list);
49361 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49362diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49363index f77083f..f3e2e34 100644
49364--- a/drivers/usb/dwc3/gadget.c
49365+++ b/drivers/usb/dwc3/gadget.c
49366@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49367 if (!usb_endpoint_xfer_isoc(desc))
49368 return 0;
49369
49370- memset(&trb_link, 0, sizeof(trb_link));
49371-
49372 /* Link TRB for ISOC. The HWO bit is never reset */
49373 trb_st_hw = &dep->trb_pool[0];
49374
49375diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49376index 5e29dde..eca992f 100644
49377--- a/drivers/usb/early/ehci-dbgp.c
49378+++ b/drivers/usb/early/ehci-dbgp.c
49379@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49380
49381 #ifdef CONFIG_KGDB
49382 static struct kgdb_io kgdbdbgp_io_ops;
49383-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49384+static struct kgdb_io kgdbdbgp_io_ops_console;
49385+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49386 #else
49387 #define dbgp_kgdb_mode (0)
49388 #endif
49389@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49390 .write_char = kgdbdbgp_write_char,
49391 };
49392
49393+static struct kgdb_io kgdbdbgp_io_ops_console = {
49394+ .name = "kgdbdbgp",
49395+ .read_char = kgdbdbgp_read_char,
49396+ .write_char = kgdbdbgp_write_char,
49397+ .is_console = 1
49398+};
49399+
49400 static int kgdbdbgp_wait_time;
49401
49402 static int __init kgdbdbgp_parse_config(char *str)
49403@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49404 ptr++;
49405 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49406 }
49407- kgdb_register_io_module(&kgdbdbgp_io_ops);
49408- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49409+ if (early_dbgp_console.index != -1)
49410+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49411+ else
49412+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49413
49414 return 0;
49415 }
49416diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49417index b369292..9f3ba40 100644
49418--- a/drivers/usb/gadget/u_serial.c
49419+++ b/drivers/usb/gadget/u_serial.c
49420@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49421 spin_lock_irq(&port->port_lock);
49422
49423 /* already open? Great. */
49424- if (port->port.count) {
49425+ if (atomic_read(&port->port.count)) {
49426 status = 0;
49427- port->port.count++;
49428+ atomic_inc(&port->port.count);
49429
49430 /* currently opening/closing? wait ... */
49431 } else if (port->openclose) {
49432@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49433 tty->driver_data = port;
49434 port->port.tty = tty;
49435
49436- port->port.count = 1;
49437+ atomic_set(&port->port.count, 1);
49438 port->openclose = false;
49439
49440 /* if connected, start the I/O stream */
49441@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49442
49443 spin_lock_irq(&port->port_lock);
49444
49445- if (port->port.count != 1) {
49446- if (port->port.count == 0)
49447+ if (atomic_read(&port->port.count) != 1) {
49448+ if (atomic_read(&port->port.count) == 0)
49449 WARN_ON(1);
49450 else
49451- --port->port.count;
49452+ atomic_dec(&port->port.count);
49453 goto exit;
49454 }
49455
49456@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49457 * and sleep if necessary
49458 */
49459 port->openclose = true;
49460- port->port.count = 0;
49461+ atomic_set(&port->port.count, 0);
49462
49463 gser = port->port_usb;
49464 if (gser && gser->disconnect)
49465@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49466 int cond;
49467
49468 spin_lock_irq(&port->port_lock);
49469- cond = (port->port.count == 0) && !port->openclose;
49470+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49471 spin_unlock_irq(&port->port_lock);
49472 return cond;
49473 }
49474@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49475 /* if it's already open, start I/O ... and notify the serial
49476 * protocol about open/close status (connect/disconnect).
49477 */
49478- if (port->port.count) {
49479+ if (atomic_read(&port->port.count)) {
49480 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49481 gs_start_io(port);
49482 if (gser->connect)
49483@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49484
49485 port->port_usb = NULL;
49486 gser->ioport = NULL;
49487- if (port->port.count > 0 || port->openclose) {
49488+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49489 wake_up_interruptible(&port->drain_wait);
49490 if (port->port.tty)
49491 tty_hangup(port->port.tty);
49492@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49493
49494 /* finally, free any unused/unusable I/O buffers */
49495 spin_lock_irqsave(&port->port_lock, flags);
49496- if (port->port.count == 0 && !port->openclose)
49497+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49498 gs_buf_free(&port->port_write_buf);
49499 gs_free_requests(gser->out, &port->read_pool, NULL);
49500 gs_free_requests(gser->out, &port->read_queue, NULL);
49501diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49502index ba6a5d6..f88f7f3 100644
49503--- a/drivers/usb/misc/appledisplay.c
49504+++ b/drivers/usb/misc/appledisplay.c
49505@@ -83,7 +83,7 @@ struct appledisplay {
49506 spinlock_t lock;
49507 };
49508
49509-static atomic_t count_displays = ATOMIC_INIT(0);
49510+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49511 static struct workqueue_struct *wq;
49512
49513 static void appledisplay_complete(struct urb *urb)
49514@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49515
49516 /* Register backlight device */
49517 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49518- atomic_inc_return(&count_displays) - 1);
49519+ atomic_inc_return_unchecked(&count_displays) - 1);
49520 memset(&props, 0, sizeof(struct backlight_properties));
49521 props.type = BACKLIGHT_RAW;
49522 props.max_brightness = 0xff;
49523diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49524index afb50ea..7b0b1cf 100644
49525--- a/drivers/usb/serial/console.c
49526+++ b/drivers/usb/serial/console.c
49527@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49528
49529 info->port = port;
49530
49531- ++port->port.count;
49532+ atomic_inc(&port->port.count);
49533 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49534 if (serial->type->set_termios) {
49535 /*
49536@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49537 }
49538 /* Now that any required fake tty operations are completed restore
49539 * the tty port count */
49540- --port->port.count;
49541+ atomic_dec(&port->port.count);
49542 /* The console is special in terms of closing the device so
49543 * indicate this port is now acting as a system console. */
49544 port->port.console = 1;
49545@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49546 free_tty:
49547 kfree(tty);
49548 reset_open_count:
49549- port->port.count = 0;
49550+ atomic_set(&port->port.count, 0);
49551 usb_autopm_put_interface(serial->interface);
49552 error_get_interface:
49553 usb_serial_put(serial);
49554diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49555index 75f70f0..d467e1a 100644
49556--- a/drivers/usb/storage/usb.h
49557+++ b/drivers/usb/storage/usb.h
49558@@ -63,7 +63,7 @@ struct us_unusual_dev {
49559 __u8 useProtocol;
49560 __u8 useTransport;
49561 int (*initFunction)(struct us_data *);
49562-};
49563+} __do_const;
49564
49565
49566 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49567diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49568index d6bea3e..60b250e 100644
49569--- a/drivers/usb/wusbcore/wa-hc.h
49570+++ b/drivers/usb/wusbcore/wa-hc.h
49571@@ -192,7 +192,7 @@ struct wahc {
49572 struct list_head xfer_delayed_list;
49573 spinlock_t xfer_list_lock;
49574 struct work_struct xfer_work;
49575- atomic_t xfer_id_count;
49576+ atomic_unchecked_t xfer_id_count;
49577 };
49578
49579
49580@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49581 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49582 spin_lock_init(&wa->xfer_list_lock);
49583 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49584- atomic_set(&wa->xfer_id_count, 1);
49585+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49586 }
49587
49588 /**
49589diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49590index d3493ca..0c33b7e 100644
49591--- a/drivers/usb/wusbcore/wa-xfer.c
49592+++ b/drivers/usb/wusbcore/wa-xfer.c
49593@@ -297,7 +297,7 @@ out:
49594 */
49595 static void wa_xfer_id_init(struct wa_xfer *xfer)
49596 {
49597- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49598+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49599 }
49600
49601 /*
49602diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49603index 842f450..d1d7409 100644
49604--- a/drivers/vfio/vfio.c
49605+++ b/drivers/vfio/vfio.c
49606@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49607 return 0;
49608
49609 /* TODO Prevent device auto probing */
49610- WARN("Device %s added to live group %d!\n", dev_name(dev),
49611+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49612 iommu_group_id(group->iommu_group));
49613
49614 return 0;
49615diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49616index 5174eba..86e764a 100644
49617--- a/drivers/vhost/vringh.c
49618+++ b/drivers/vhost/vringh.c
49619@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49620
49621 static inline int putu16_kern(u16 *p, u16 val)
49622 {
49623- ACCESS_ONCE(*p) = val;
49624+ ACCESS_ONCE_RW(*p) = val;
49625 return 0;
49626 }
49627
49628diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49629index a4dfe8c..297ddd9 100644
49630--- a/drivers/video/aty/aty128fb.c
49631+++ b/drivers/video/aty/aty128fb.c
49632@@ -149,7 +149,7 @@ enum {
49633 };
49634
49635 /* Must match above enum */
49636-static char * const r128_family[] = {
49637+static const char * const r128_family[] = {
49638 "AGP",
49639 "PCI",
49640 "PRO AGP",
49641diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49642index 9b0f12c..024673d 100644
49643--- a/drivers/video/aty/atyfb_base.c
49644+++ b/drivers/video/aty/atyfb_base.c
49645@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49646 par->accel_flags = var->accel_flags; /* hack */
49647
49648 if (var->accel_flags) {
49649- info->fbops->fb_sync = atyfb_sync;
49650+ pax_open_kernel();
49651+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49652+ pax_close_kernel();
49653 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49654 } else {
49655- info->fbops->fb_sync = NULL;
49656+ pax_open_kernel();
49657+ *(void **)&info->fbops->fb_sync = NULL;
49658+ pax_close_kernel();
49659 info->flags |= FBINFO_HWACCEL_DISABLED;
49660 }
49661
49662diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49663index 95ec042..e6affdd 100644
49664--- a/drivers/video/aty/mach64_cursor.c
49665+++ b/drivers/video/aty/mach64_cursor.c
49666@@ -7,6 +7,7 @@
49667 #include <linux/string.h>
49668
49669 #include <asm/io.h>
49670+#include <asm/pgtable.h>
49671
49672 #ifdef __sparc__
49673 #include <asm/fbio.h>
49674@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49675 info->sprite.buf_align = 16; /* and 64 lines tall. */
49676 info->sprite.flags = FB_PIXMAP_IO;
49677
49678- info->fbops->fb_cursor = atyfb_cursor;
49679+ pax_open_kernel();
49680+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49681+ pax_close_kernel();
49682
49683 return 0;
49684 }
49685diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49686index bca6ccc..252107e 100644
49687--- a/drivers/video/backlight/kb3886_bl.c
49688+++ b/drivers/video/backlight/kb3886_bl.c
49689@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49690 static unsigned long kb3886bl_flags;
49691 #define KB3886BL_SUSPENDED 0x01
49692
49693-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49694+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49695 {
49696 .ident = "Sahara Touch-iT",
49697 .matches = {
49698diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49699index 900aa4e..6d49418 100644
49700--- a/drivers/video/fb_defio.c
49701+++ b/drivers/video/fb_defio.c
49702@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49703
49704 BUG_ON(!fbdefio);
49705 mutex_init(&fbdefio->lock);
49706- info->fbops->fb_mmap = fb_deferred_io_mmap;
49707+ pax_open_kernel();
49708+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49709+ pax_close_kernel();
49710 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49711 INIT_LIST_HEAD(&fbdefio->pagelist);
49712 if (fbdefio->delay == 0) /* set a default of 1 s */
49713@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49714 page->mapping = NULL;
49715 }
49716
49717- info->fbops->fb_mmap = NULL;
49718+ *(void **)&info->fbops->fb_mmap = NULL;
49719 mutex_destroy(&fbdefio->lock);
49720 }
49721 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49722diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49723index 5c3960d..15cf8fc 100644
49724--- a/drivers/video/fbcmap.c
49725+++ b/drivers/video/fbcmap.c
49726@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49727 rc = -ENODEV;
49728 goto out;
49729 }
49730- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49731- !info->fbops->fb_setcmap)) {
49732+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49733 rc = -EINVAL;
49734 goto out1;
49735 }
49736diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49737index 36e1fe2..c744820 100644
49738--- a/drivers/video/fbmem.c
49739+++ b/drivers/video/fbmem.c
49740@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49741 image->dx += image->width + 8;
49742 }
49743 } else if (rotate == FB_ROTATE_UD) {
49744- for (x = 0; x < num && image->dx >= 0; x++) {
49745+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49746 info->fbops->fb_imageblit(info, image);
49747 image->dx -= image->width + 8;
49748 }
49749@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49750 image->dy += image->height + 8;
49751 }
49752 } else if (rotate == FB_ROTATE_CCW) {
49753- for (x = 0; x < num && image->dy >= 0; x++) {
49754+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49755 info->fbops->fb_imageblit(info, image);
49756 image->dy -= image->height + 8;
49757 }
49758@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49759 return -EFAULT;
49760 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49761 return -EINVAL;
49762- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49763+ if (con2fb.framebuffer >= FB_MAX)
49764 return -EINVAL;
49765 if (!registered_fb[con2fb.framebuffer])
49766 request_module("fb%d", con2fb.framebuffer);
49767diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49768index d4d2c5f..ebbd113 100644
49769--- a/drivers/video/hyperv_fb.c
49770+++ b/drivers/video/hyperv_fb.c
49771@@ -233,7 +233,7 @@ static uint screen_fb_size;
49772 static inline int synthvid_send(struct hv_device *hdev,
49773 struct synthvid_msg *msg)
49774 {
49775- static atomic64_t request_id = ATOMIC64_INIT(0);
49776+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49777 int ret;
49778
49779 msg->pipe_hdr.type = PIPE_MSG_DATA;
49780@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49781
49782 ret = vmbus_sendpacket(hdev->channel, msg,
49783 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49784- atomic64_inc_return(&request_id),
49785+ atomic64_inc_return_unchecked(&request_id),
49786 VM_PKT_DATA_INBAND, 0);
49787
49788 if (ret)
49789diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49790index 7672d2e..b56437f 100644
49791--- a/drivers/video/i810/i810_accel.c
49792+++ b/drivers/video/i810/i810_accel.c
49793@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49794 }
49795 }
49796 printk("ringbuffer lockup!!!\n");
49797+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49798 i810_report_error(mmio);
49799 par->dev_flags |= LOCKUP;
49800 info->pixmap.scan_align = 1;
49801diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49802index 285d552..eafa544 100644
49803--- a/drivers/video/logo/logo_linux_clut224.ppm
49804+++ b/drivers/video/logo/logo_linux_clut224.ppm
49805@@ -1,883 +1,1123 @@
49806 P3
49807 80 80
49808 255
49809-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49810-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49811-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49812-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49813-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49814-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-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 0 0 0 0 0 0 0 0 0
49821-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49822-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49823-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49824-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49825-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49826-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-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 1 1 1 1 1 1 0 0 0
49832-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49833-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49834-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49835-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49836-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49837-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49838-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49839-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 1 1 1 0 0 0 0 0 0 0 0 0
49843-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49844-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49845-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49846-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49847-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49848-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49849-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49850-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 1 1 1 7 12 13 21 31 35 42 59 64
49854-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49855-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49856-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49857-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49858-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49859-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49860-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49861-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 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49865-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49866-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49867-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49868-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49869-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49870-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49871-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49872-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 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49876-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49877-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49878-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49879-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49880-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49881-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49883-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-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49887-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49888-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49889-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49890-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49891-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49892-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49894-0 0 0 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-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49898-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49899-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49900-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49901-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49902-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49903-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49904-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49905-0 0 0 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-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49909-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49910-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49911-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49912-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49913-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49914-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49916-0 0 0 0 0 0 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-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49920-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49921-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49922-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49923-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49924-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49925-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49927-0 0 0 0 0 0 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-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49931-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49932-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49933-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49934-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49935-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49936-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49937-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49938-0 0 0 0 0 0 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-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49942-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49943-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49944-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49945-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49946-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49947-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49948-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49949-0 0 0 0 0 0 0 0 0 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-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49953-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49954-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49955-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49956-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49957-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49958-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49959-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49960-0 0 0 0 0 0 0 0 0 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-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49964-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49965-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49966-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49967-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49968-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49969-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49970-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49971-0 0 0 0 0 0 0 0 0 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-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49975-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49976-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49977-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49978-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49979-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49980-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49981-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49982-0 0 0 0 0 0 0 0 0 0 0 0 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-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49986-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49987-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49988-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49989-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49990-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49991-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49993-0 0 0 0 0 0 0 0 0 0 0 0 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-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49997-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49998-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49999-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
50000-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
50001-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
50002-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50004-0 0 0 0 0 0 0 0 0 0 0 0 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-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
50008-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
50009-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
50010-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
50011-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
50012-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
50013-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
50014-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50015-0 0 0 0 0 0 0 0 0 0 0 0 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-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
50019-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
50020-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
50021-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
50022-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
50023-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
50024-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
50025-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50026-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
50030-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
50031-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
50032-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
50033-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
50034-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
50035-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50037-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
50041-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
50042-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
50043-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
50044-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
50045-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
50046-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50048-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
50052-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
50053-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
50054-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
50055-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
50056-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
50057-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
50058-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50059-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
50063-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
50064-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
50065-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
50066-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
50067-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
50068-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
50069-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50070-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
50074-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
50075-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
50076-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
50077-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
50078-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
50079-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
50080-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50081-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
50085-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
50086-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50087-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
50088-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
50089-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
50090-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
50091-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
50096-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
50097-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50098-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
50099-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
50100-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
50101-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
50102-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
50107-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
50108-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50109-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
50110-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
50111-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
50112-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
50113-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 11 15 17 31 45 49 26 35 39 3 5 6
50118-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
50119-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50120-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
50121-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
50122-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
50123-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
50124-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 1 1 15 22 25 36 54 60 18 25 28
50129-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
50130-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50131-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
50132-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
50133-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
50134-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
50135-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50136-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 1 1 27 40 45 35 52 58
50140-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50141-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50142-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
50143-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
50144-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50145-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
50146-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50147-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 7 12 13 33 49 54
50151-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50152-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50153-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
50154-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
50155-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50156-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50157-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50158-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 12 17 20
50162-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50163-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50164-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
50165-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
50166-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50167-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50168-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
50169-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
50173-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50174-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50175-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
50176-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 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-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50179-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
50180-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50181-0 0 0 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 0 0 0
50184-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50185-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
50186-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
50187-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 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 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50190-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
50191-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50192-0 0 0 0 0 0 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 0 0 0
50195-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
50196-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
50197-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
50198-253 253 253 253 253 253 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-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50201-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
50202-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50203-0 0 0 0 0 0 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 0 0 0
50206-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
50207-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
50208-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
50209-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
50210-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
50211-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
50212-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
50213-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50214-0 0 0 0 0 0 0 0 0 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 0 0 0
50217-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
50218-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
50219-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
50220-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
50221-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
50222-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
50223-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
50224-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50225-0 0 0 0 0 0 0 0 0 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 0 0 0
50228-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
50229-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
50230-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
50231-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
50232-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
50233-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
50234-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
50235-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50236-0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
50239-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
50240-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
50241-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
50242-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
50243-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
50244-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
50245-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
50246-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50247-0 0 0 0 0 0 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 0 0 0 0 0 0
50250-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
50251-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
50252-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
50253-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50254-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50255-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
50256-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
50257-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50258-0 0 0 0 0 0 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 0 0 0 0 0 0
50261-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
50262-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
50263-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
50264-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50265-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50266-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
50267-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
50268-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50269-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50270-
50271-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50272-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
50273-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
50274-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50275-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50276-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50277-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
50278-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
50279-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
50283-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
50284-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
50285-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50286-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50287-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50288-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
50289-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
50290-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 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 0 0 0
50294-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50295-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
50296-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50297-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50298-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50299-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
50300-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
50301-74 74 74 58 58 58 22 22 22 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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50306-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
50307-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50308-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50309-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50310-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
50311-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50312-42 42 42 74 74 74 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50317-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50318-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50319-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50320-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50321-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50322-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50323-10 10 10 86 86 86 38 38 38 10 10 10 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 0 0 0 0 0 0 0 0 0
50328-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50329-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50330-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50331-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50332-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50333-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50334-6 6 6 86 86 86 46 46 46 14 14 14 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 6 6 6
50339-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50340-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50341-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50342-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50343-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50344-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50345-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 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 10 10 10
50350-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50351-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50352-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50353-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50354-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50355-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50356-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 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 10 10 10
50361-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50362-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50363-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50364-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50365-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50366-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50367-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50371-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50372-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50373-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50374-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50375-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50376-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50377-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50378-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50379-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50380-
50381-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50382-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50383-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50384-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50385-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50386-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50387-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50388-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50389-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50390-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50391-
50392-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50393-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50394-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50395-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50396-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50397-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50398-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50399-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50400-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50401-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50402-
50403-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50404-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50405-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50406-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50407-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50408-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50409-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50410-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50411-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50412-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50413-
50414-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50415-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50416-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50417-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50418-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50419-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50420-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50421-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50422-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50423-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50424-
50425-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50426-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50427-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50428-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50429-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50430-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50431-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50432-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50433-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50434-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50435-
50436-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50437-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50438-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50439-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50440-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50441-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50442-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50443-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50444-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50445-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50446-
50447-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50448-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50449-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50450-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50451-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50452-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50453-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50454-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50455-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50456-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50457-
50458-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50459-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50460-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50461-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50462-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50463-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50464-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50465-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50466-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50467-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50468-
50469-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50470-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50471-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50472-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50473-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50474-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50475-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50476-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50477-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50478-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50479-
50480-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50481-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50482-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50483-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50484-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50485-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50486-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50487-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50488-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50489-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50490-
50491-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50492-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50493-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50494-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50495-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50496-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50497-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50498-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50499-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50500-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50501-
50502-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50503-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50504-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50505-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50506-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50507-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50508-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50509-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50510-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50511-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50512-
50513-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50514-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50515-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50516-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50517-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50518-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50519-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50520-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50521-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50522-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50523-
50524-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50525-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50526-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50527-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50528-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50529-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50530-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50531-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50532-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50533-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50534-
50535-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50536-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50537-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50538-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50539-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50540-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50541-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50542-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50543-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50544-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50545-
50546-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50547-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50548-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50549-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50550-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50551-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50552-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50553-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50554-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50555-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50556-
50557-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50558-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50559-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50560-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50561-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50562-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50563-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50564-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50565-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50566-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50567-
50568-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50569-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50570-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50571-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50572-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50573-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50574-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50575-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50576-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50577-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50578-
50579-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50580-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50581-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50582-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50583-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50584-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50585-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50586-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50587-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50588-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50589-
50590-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50591-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50592-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50593-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50594-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50595-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50596-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50597-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50598-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50599-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50600-
50601-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50602-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50603-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50604-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50605-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50606-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50607-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50608-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50609-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50610-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50611-
50612-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50613-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50614-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50615-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50616-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50617-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50618-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50619-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50620-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50621-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50622-
50623-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50624-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50625-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50626-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50627-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50628-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50629-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50630-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50631-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50632-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50633-
50634-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50635-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50636-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50637-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50638-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50639-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50640-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50641-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50642-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50643-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50644-
50645-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50646-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50647-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50648-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50649-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50650-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50651-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50652-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50653-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50654-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50655-
50656-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50657-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50658-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50659-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50660-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50661-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50662-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50663-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50664-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50665-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50666-
50667-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50668-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50669-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50670-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50671-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50672-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50673-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50674-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50675-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50676-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50677-
50678-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50679-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50680-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50681-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50682-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50683-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50684-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50685-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50686-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50687-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50688-
50689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50702+4 4 4 4 4 4
50703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50716+4 4 4 4 4 4
50717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50730+4 4 4 4 4 4
50731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50744+4 4 4 4 4 4
50745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50758+4 4 4 4 4 4
50759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50772+4 4 4 4 4 4
50773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50777+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50778+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
50779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50782+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50783+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50784+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50786+4 4 4 4 4 4
50787+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50791+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50792+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50793+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50796+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50797+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50798+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50799+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50800+4 4 4 4 4 4
50801+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50805+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50806+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50807+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50810+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50811+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50812+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50813+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50814+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50818+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50819+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50820+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50821+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50823+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50824+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50825+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50826+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50827+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50828+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 4 4 4 4 4 4 4 4 4 4 4 4
50832+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50833+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50834+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50835+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50836+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50837+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50838+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50839+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50840+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50841+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50842+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 4 4 4 4 4 4 4 4 4 5 5 5
50846+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50847+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50848+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50849+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50850+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50851+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50852+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50853+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50854+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50855+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50856+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 4 4 4 4 4 4 5 5 5 3 3 3
50860+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50861+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50862+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50863+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50864+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50865+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50866+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50867+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50868+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50869+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50870+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 4 4 4 2 2 2 0 0 0 4 0 0
50874+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50875+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50876+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50877+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50878+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50879+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50880+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50881+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50882+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50883+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50884+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50888+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50889+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50890+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50891+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50892+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50893+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50894+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50895+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50896+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50897+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50898+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50902+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50903+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50904+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50905+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50906+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50907+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50908+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50909+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50910+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50911+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50912+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 3 3 3 0 0 0
50915+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50916+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50917+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50918+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50919+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50920+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50921+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50922+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50923+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50924+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50925+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50926+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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50929+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50930+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50931+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50932+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50933+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50934+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50935+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50936+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50937+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50938+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50939+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50940+0 0 0 4 4 4
50941+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50942+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50943+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50944+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50945+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50946+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50947+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50948+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50949+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50950+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50951+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50952+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50953+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50954+2 0 0 0 0 0
50955+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50956+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50957+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50958+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50959+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50960+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50961+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50962+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50963+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50964+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50965+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50966+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50967+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50968+37 38 37 0 0 0
50969+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50970+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50971+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50972+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50973+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50974+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50975+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50976+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50977+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50978+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50979+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50980+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50981+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50982+85 115 134 4 0 0
50983+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50984+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50985+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50986+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50987+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50988+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50989+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50990+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50991+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50992+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50993+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50994+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50995+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50996+60 73 81 4 0 0
50997+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50998+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50999+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51000+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51001+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51002+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51003+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51004+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51005+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51006+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51007+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51008+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51009+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51010+16 19 21 4 0 0
51011+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51012+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51013+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51014+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51015+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51016+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51017+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51018+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51019+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51020+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51021+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51022+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51023+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51024+4 0 0 4 3 3
51025+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51026+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51027+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51029+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51030+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51031+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51032+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51033+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51034+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51035+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51036+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51037+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51038+3 2 2 4 4 4
51039+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51040+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51041+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51042+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51043+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51044+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51045+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51046+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51047+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51048+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51049+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51050+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51051+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51052+4 4 4 4 4 4
51053+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51054+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51055+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51056+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51057+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51058+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51059+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51060+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51061+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51062+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51063+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51064+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51065+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51066+4 4 4 4 4 4
51067+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51068+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51069+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51070+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51071+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51072+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51073+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51074+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51075+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51076+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51077+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51078+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51079+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51080+5 5 5 5 5 5
51081+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51082+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51083+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51084+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51085+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51086+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51087+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51088+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51089+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51090+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51091+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51092+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51093+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51094+5 5 5 4 4 4
51095+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51096+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51097+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51098+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51099+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51100+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51101+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51102+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51103+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51104+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51105+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51106+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51108+4 4 4 4 4 4
51109+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51110+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51111+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51112+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51113+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51114+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51115+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51116+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51117+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51118+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51119+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51120+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51122+4 4 4 4 4 4
51123+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51124+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51125+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51126+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51127+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51128+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51129+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51130+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51131+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51132+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51133+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51136+4 4 4 4 4 4
51137+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51138+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51139+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51140+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51141+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51142+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51143+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51144+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51145+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51146+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51147+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51150+4 4 4 4 4 4
51151+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51152+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51153+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51154+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51155+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51156+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51157+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51158+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51159+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51160+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51161+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51164+4 4 4 4 4 4
51165+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51166+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51167+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51168+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51169+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51170+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51171+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51172+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51173+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51174+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51175+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51178+4 4 4 4 4 4
51179+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51180+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51181+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51182+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51183+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51184+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51185+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51186+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51187+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51188+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51189+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51192+4 4 4 4 4 4
51193+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51194+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51195+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51196+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51197+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51198+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51199+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51200+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51201+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51202+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51203+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51206+4 4 4 4 4 4
51207+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51208+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51209+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51210+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51211+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51212+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51213+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51214+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51215+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51216+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51217+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51220+4 4 4 4 4 4
51221+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51222+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51223+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51224+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51225+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51226+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51227+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51228+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51229+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51230+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51231+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51234+4 4 4 4 4 4
51235+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51236+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51237+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51238+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51239+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51240+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51241+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51242+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51243+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51244+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51245+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
51249+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51250+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51251+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51252+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51253+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51254+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51255+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51256+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51257+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51258+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51259+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51260+4 4 4 4 4 4 4 4 4 4 4 4 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
51263+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51264+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51265+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51266+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51267+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51268+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51269+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51270+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51271+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51272+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51273+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51274+4 4 4 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
51277+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51278+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51279+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51280+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51281+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51282+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51283+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51284+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51285+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51286+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51287+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
51291+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51292+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51293+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51294+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51295+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51296+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51297+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51298+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51299+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51300+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51301+0 0 0 3 3 3 5 5 5 4 4 4 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
51305+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51306+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51307+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51308+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51309+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51310+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51311+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51312+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51313+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51314+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51315+0 0 0 3 3 3 5 5 5 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
51319+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51320+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51321+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51322+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51323+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51324+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51325+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51326+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51327+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51328+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51329+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51332+4 4 4 4 4 4
51333+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51334+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51335+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51336+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51337+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51338+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51339+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51340+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51341+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51342+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51343+0 0 0 3 3 3 5 5 5 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
51347+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51348+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51349+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51350+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51351+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51352+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51353+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51354+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51355+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51356+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51357+0 0 0 3 3 3 5 5 5 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
51361+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51362+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51363+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51364+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51365+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51366+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51367+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51368+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51369+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51370+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51371+0 0 0 3 3 3 5 5 5 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
51375+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51376+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51377+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51378+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51379+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51380+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51381+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51382+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51383+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51384+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51385+0 0 0 3 3 3 5 5 5 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
51389+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51390+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51391+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51392+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51393+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51394+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51395+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51396+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51397+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51398+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51399+0 0 0 3 3 3 5 5 5 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
51403+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51404+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51405+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51406+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51407+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51408+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51409+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51410+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51411+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51412+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51413+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51416+4 4 4 4 4 4
51417+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51418+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51419+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51420+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51421+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51422+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51423+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51424+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51425+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51426+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51427+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51430+4 4 4 4 4 4
51431+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51432+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51433+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51434+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51435+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51436+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51437+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51438+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51439+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51440+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51441+0 0 0 3 3 3 5 5 5 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
51445+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51446+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51447+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51448+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51449+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51450+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51451+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51452+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51453+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51454+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51455+0 0 0 3 3 3 5 5 5 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
51459+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51460+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51461+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51462+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51463+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51464+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51465+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51466+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51467+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51468+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51469+0 0 0 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
51473+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51474+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51475+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51476+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51478+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51479+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51480+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51481+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51482+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51483+4 3 3 5 5 5 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
51487+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51488+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51489+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51490+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51491+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51492+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51493+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51494+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51495+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51496+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51497+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51500+4 4 4 4 4 4
51501+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51502+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51503+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51504+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51505+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51506+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51507+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51508+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51509+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51510+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51514+4 4 4 4 4 4
51515+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51516+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51517+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51518+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51519+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51520+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51521+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51522+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51523+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51524+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51528+4 4 4 4 4 4
51529+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51530+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51531+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51532+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51533+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51534+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51535+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51536+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51537+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51538+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51542+4 4 4 4 4 4
51543+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51544+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51545+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51546+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51547+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51548+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51549+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51550+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51551+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51552+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51556+4 4 4 4 4 4
51557+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51558+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51559+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51560+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51561+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51562+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51563+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51564+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51565+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51570+4 4 4 4 4 4
51571+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51572+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51573+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51574+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51575+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51576+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51577+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51578+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51579+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51584+4 4 4 4 4 4
51585+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51586+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51587+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51588+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51589+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51590+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51591+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51592+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51593+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51598+4 4 4 4 4 4
51599+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51600+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51601+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51602+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51603+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51604+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51605+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51606+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51612+4 4 4 4 4 4
51613+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51614+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51615+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51616+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51617+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51618+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51619+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51620+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51626+4 4 4 4 4 4
51627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51628+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51629+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51630+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51631+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51632+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51633+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51634+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51640+4 4 4 4 4 4
51641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51642+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51643+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51644+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51645+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51646+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51647+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51648+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51654+4 4 4 4 4 4
51655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51656+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51657+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51658+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51659+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51660+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51661+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51662+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51668+4 4 4 4 4 4
51669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51671+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51672+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51673+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51674+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51675+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51676+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51682+4 4 4 4 4 4
51683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51686+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51687+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51688+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51689+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51696+4 4 4 4 4 4
51697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51700+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51701+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51702+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51703+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51710+4 4 4 4 4 4
51711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51714+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51715+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51716+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51717+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51724+4 4 4 4 4 4
51725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51728+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51729+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51730+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51731+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51738+4 4 4 4 4 4
51739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51743+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51744+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51745+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51752+4 4 4 4 4 4
51753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51757+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51758+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51759+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51766+4 4 4 4 4 4
51767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51771+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51772+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51773+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51780+4 4 4 4 4 4
51781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51785+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51786+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51794+4 4 4 4 4 4
51795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51799+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51800+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51808+4 4 4 4 4 4
51809diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51810index fe92eed..106e085 100644
51811--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51812+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51813@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51814 struct mb862xxfb_par *par = info->par;
51815
51816 if (info->var.bits_per_pixel == 32) {
51817- info->fbops->fb_fillrect = cfb_fillrect;
51818- info->fbops->fb_copyarea = cfb_copyarea;
51819- info->fbops->fb_imageblit = cfb_imageblit;
51820+ pax_open_kernel();
51821+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51822+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51823+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51824+ pax_close_kernel();
51825 } else {
51826 outreg(disp, GC_L0EM, 3);
51827- info->fbops->fb_fillrect = mb86290fb_fillrect;
51828- info->fbops->fb_copyarea = mb86290fb_copyarea;
51829- info->fbops->fb_imageblit = mb86290fb_imageblit;
51830+ pax_open_kernel();
51831+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51832+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51833+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51834+ pax_close_kernel();
51835 }
51836 outreg(draw, GDC_REG_DRAW_BASE, 0);
51837 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51838diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51839index ff22871..b129bed 100644
51840--- a/drivers/video/nvidia/nvidia.c
51841+++ b/drivers/video/nvidia/nvidia.c
51842@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51843 info->fix.line_length = (info->var.xres_virtual *
51844 info->var.bits_per_pixel) >> 3;
51845 if (info->var.accel_flags) {
51846- info->fbops->fb_imageblit = nvidiafb_imageblit;
51847- info->fbops->fb_fillrect = nvidiafb_fillrect;
51848- info->fbops->fb_copyarea = nvidiafb_copyarea;
51849- info->fbops->fb_sync = nvidiafb_sync;
51850+ pax_open_kernel();
51851+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51852+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51853+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51854+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51855+ pax_close_kernel();
51856 info->pixmap.scan_align = 4;
51857 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51858 info->flags |= FBINFO_READS_FAST;
51859 NVResetGraphics(info);
51860 } else {
51861- info->fbops->fb_imageblit = cfb_imageblit;
51862- info->fbops->fb_fillrect = cfb_fillrect;
51863- info->fbops->fb_copyarea = cfb_copyarea;
51864- info->fbops->fb_sync = NULL;
51865+ pax_open_kernel();
51866+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51867+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51868+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51869+ *(void **)&info->fbops->fb_sync = NULL;
51870+ pax_close_kernel();
51871 info->pixmap.scan_align = 1;
51872 info->flags |= FBINFO_HWACCEL_DISABLED;
51873 info->flags &= ~FBINFO_READS_FAST;
51874@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51875 info->pixmap.size = 8 * 1024;
51876 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51877
51878- if (!hwcur)
51879- info->fbops->fb_cursor = NULL;
51880+ if (!hwcur) {
51881+ pax_open_kernel();
51882+ *(void **)&info->fbops->fb_cursor = NULL;
51883+ pax_close_kernel();
51884+ }
51885
51886 info->var.accel_flags = (!noaccel);
51887
51888diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51889index 05c2dc3..ea1f391 100644
51890--- a/drivers/video/s1d13xxxfb.c
51891+++ b/drivers/video/s1d13xxxfb.c
51892@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51893
51894 switch(prod_id) {
51895 case S1D13506_PROD_ID: /* activate acceleration */
51896- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51897- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51898+ pax_open_kernel();
51899+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51900+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51901+ pax_close_kernel();
51902 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51903 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51904 break;
51905diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51906index e188ada..aac63c8 100644
51907--- a/drivers/video/smscufx.c
51908+++ b/drivers/video/smscufx.c
51909@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51910 fb_deferred_io_cleanup(info);
51911 kfree(info->fbdefio);
51912 info->fbdefio = NULL;
51913- info->fbops->fb_mmap = ufx_ops_mmap;
51914+ pax_open_kernel();
51915+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51916+ pax_close_kernel();
51917 }
51918
51919 pr_debug("released /dev/fb%d user=%d count=%d",
51920diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51921index d2e5bc3..4cb05d1 100644
51922--- a/drivers/video/udlfb.c
51923+++ b/drivers/video/udlfb.c
51924@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51925 dlfb_urb_completion(urb);
51926
51927 error:
51928- atomic_add(bytes_sent, &dev->bytes_sent);
51929- atomic_add(bytes_identical, &dev->bytes_identical);
51930- atomic_add(width*height*2, &dev->bytes_rendered);
51931+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51932+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51933+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51934 end_cycles = get_cycles();
51935- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51936+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51937 >> 10)), /* Kcycles */
51938 &dev->cpu_kcycles_used);
51939
51940@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51941 dlfb_urb_completion(urb);
51942
51943 error:
51944- atomic_add(bytes_sent, &dev->bytes_sent);
51945- atomic_add(bytes_identical, &dev->bytes_identical);
51946- atomic_add(bytes_rendered, &dev->bytes_rendered);
51947+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51948+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51949+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51950 end_cycles = get_cycles();
51951- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51952+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51953 >> 10)), /* Kcycles */
51954 &dev->cpu_kcycles_used);
51955 }
51956@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51957 fb_deferred_io_cleanup(info);
51958 kfree(info->fbdefio);
51959 info->fbdefio = NULL;
51960- info->fbops->fb_mmap = dlfb_ops_mmap;
51961+ pax_open_kernel();
51962+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51963+ pax_close_kernel();
51964 }
51965
51966 pr_warn("released /dev/fb%d user=%d count=%d\n",
51967@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51968 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51969 struct dlfb_data *dev = fb_info->par;
51970 return snprintf(buf, PAGE_SIZE, "%u\n",
51971- atomic_read(&dev->bytes_rendered));
51972+ atomic_read_unchecked(&dev->bytes_rendered));
51973 }
51974
51975 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51976@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51977 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51978 struct dlfb_data *dev = fb_info->par;
51979 return snprintf(buf, PAGE_SIZE, "%u\n",
51980- atomic_read(&dev->bytes_identical));
51981+ atomic_read_unchecked(&dev->bytes_identical));
51982 }
51983
51984 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51985@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51986 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51987 struct dlfb_data *dev = fb_info->par;
51988 return snprintf(buf, PAGE_SIZE, "%u\n",
51989- atomic_read(&dev->bytes_sent));
51990+ atomic_read_unchecked(&dev->bytes_sent));
51991 }
51992
51993 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51994@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51995 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51996 struct dlfb_data *dev = fb_info->par;
51997 return snprintf(buf, PAGE_SIZE, "%u\n",
51998- atomic_read(&dev->cpu_kcycles_used));
51999+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52000 }
52001
52002 static ssize_t edid_show(
52003@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52004 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52005 struct dlfb_data *dev = fb_info->par;
52006
52007- atomic_set(&dev->bytes_rendered, 0);
52008- atomic_set(&dev->bytes_identical, 0);
52009- atomic_set(&dev->bytes_sent, 0);
52010- atomic_set(&dev->cpu_kcycles_used, 0);
52011+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52012+ atomic_set_unchecked(&dev->bytes_identical, 0);
52013+ atomic_set_unchecked(&dev->bytes_sent, 0);
52014+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52015
52016 return count;
52017 }
52018diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52019index 7aec6f3..e3b2d55 100644
52020--- a/drivers/video/uvesafb.c
52021+++ b/drivers/video/uvesafb.c
52022@@ -19,6 +19,7 @@
52023 #include <linux/io.h>
52024 #include <linux/mutex.h>
52025 #include <linux/slab.h>
52026+#include <linux/moduleloader.h>
52027 #include <video/edid.h>
52028 #include <video/uvesafb.h>
52029 #ifdef CONFIG_X86
52030@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52031 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52032 par->pmi_setpal = par->ypan = 0;
52033 } else {
52034+
52035+#ifdef CONFIG_PAX_KERNEXEC
52036+#ifdef CONFIG_MODULES
52037+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52038+#endif
52039+ if (!par->pmi_code) {
52040+ par->pmi_setpal = par->ypan = 0;
52041+ return 0;
52042+ }
52043+#endif
52044+
52045 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52046 + task->t.regs.edi);
52047+
52048+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52049+ pax_open_kernel();
52050+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52051+ pax_close_kernel();
52052+
52053+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52054+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52055+#else
52056 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52057 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52058+#endif
52059+
52060 printk(KERN_INFO "uvesafb: protected mode interface info at "
52061 "%04x:%04x\n",
52062 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52063@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52064 par->ypan = ypan;
52065
52066 if (par->pmi_setpal || par->ypan) {
52067+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52068 if (__supported_pte_mask & _PAGE_NX) {
52069 par->pmi_setpal = par->ypan = 0;
52070 printk(KERN_WARNING "uvesafb: NX protection is active, "
52071 "better not use the PMI.\n");
52072- } else {
52073+ } else
52074+#endif
52075 uvesafb_vbe_getpmi(task, par);
52076- }
52077 }
52078 #else
52079 /* The protected mode interface is not available on non-x86. */
52080@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52081 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52082
52083 /* Disable blanking if the user requested so. */
52084- if (!blank)
52085- info->fbops->fb_blank = NULL;
52086+ if (!blank) {
52087+ pax_open_kernel();
52088+ *(void **)&info->fbops->fb_blank = NULL;
52089+ pax_close_kernel();
52090+ }
52091
52092 /*
52093 * Find out how much IO memory is required for the mode with
52094@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52095 info->flags = FBINFO_FLAG_DEFAULT |
52096 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52097
52098- if (!par->ypan)
52099- info->fbops->fb_pan_display = NULL;
52100+ if (!par->ypan) {
52101+ pax_open_kernel();
52102+ *(void **)&info->fbops->fb_pan_display = NULL;
52103+ pax_close_kernel();
52104+ }
52105 }
52106
52107 static void uvesafb_init_mtrr(struct fb_info *info)
52108@@ -1796,6 +1826,11 @@ out:
52109 if (par->vbe_modes)
52110 kfree(par->vbe_modes);
52111
52112+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52113+ if (par->pmi_code)
52114+ module_free_exec(NULL, par->pmi_code);
52115+#endif
52116+
52117 framebuffer_release(info);
52118 return err;
52119 }
52120@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
52121 kfree(par->vbe_state_orig);
52122 if (par->vbe_state_saved)
52123 kfree(par->vbe_state_saved);
52124+
52125+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52126+ if (par->pmi_code)
52127+ module_free_exec(NULL, par->pmi_code);
52128+#endif
52129+
52130 }
52131
52132 framebuffer_release(info);
52133diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52134index 501b340..d80aa17 100644
52135--- a/drivers/video/vesafb.c
52136+++ b/drivers/video/vesafb.c
52137@@ -9,6 +9,7 @@
52138 */
52139
52140 #include <linux/module.h>
52141+#include <linux/moduleloader.h>
52142 #include <linux/kernel.h>
52143 #include <linux/errno.h>
52144 #include <linux/string.h>
52145@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52146 static int vram_total __initdata; /* Set total amount of memory */
52147 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52148 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52149-static void (*pmi_start)(void) __read_mostly;
52150-static void (*pmi_pal) (void) __read_mostly;
52151+static void (*pmi_start)(void) __read_only;
52152+static void (*pmi_pal) (void) __read_only;
52153 static int depth __read_mostly;
52154 static int vga_compat __read_mostly;
52155 /* --------------------------------------------------------------------- */
52156@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52157 unsigned int size_vmode;
52158 unsigned int size_remap;
52159 unsigned int size_total;
52160+ void *pmi_code = NULL;
52161
52162 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52163 return -ENODEV;
52164@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52165 size_remap = size_total;
52166 vesafb_fix.smem_len = size_remap;
52167
52168-#ifndef __i386__
52169- screen_info.vesapm_seg = 0;
52170-#endif
52171-
52172 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52173 printk(KERN_WARNING
52174 "vesafb: cannot reserve video memory at 0x%lx\n",
52175@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52176 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52177 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52178
52179+#ifdef __i386__
52180+
52181+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52182+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52183+ if (!pmi_code)
52184+#elif !defined(CONFIG_PAX_KERNEXEC)
52185+ if (0)
52186+#endif
52187+
52188+#endif
52189+ screen_info.vesapm_seg = 0;
52190+
52191 if (screen_info.vesapm_seg) {
52192- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52193- screen_info.vesapm_seg,screen_info.vesapm_off);
52194+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52195+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52196 }
52197
52198 if (screen_info.vesapm_seg < 0xc000)
52199@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52200
52201 if (ypan || pmi_setpal) {
52202 unsigned short *pmi_base;
52203+
52204 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52205- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52206- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52207+
52208+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52209+ pax_open_kernel();
52210+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52211+#else
52212+ pmi_code = pmi_base;
52213+#endif
52214+
52215+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52216+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52217+
52218+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52219+ pmi_start = ktva_ktla(pmi_start);
52220+ pmi_pal = ktva_ktla(pmi_pal);
52221+ pax_close_kernel();
52222+#endif
52223+
52224 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52225 if (pmi_base[3]) {
52226 printk(KERN_INFO "vesafb: pmi: ports = ");
52227@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52228 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52229 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52230
52231- if (!ypan)
52232- info->fbops->fb_pan_display = NULL;
52233+ if (!ypan) {
52234+ pax_open_kernel();
52235+ *(void **)&info->fbops->fb_pan_display = NULL;
52236+ pax_close_kernel();
52237+ }
52238
52239 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52240 err = -ENOMEM;
52241@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52242 info->node, info->fix.id);
52243 return 0;
52244 err:
52245+
52246+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52247+ module_free_exec(NULL, pmi_code);
52248+#endif
52249+
52250 if (info->screen_base)
52251 iounmap(info->screen_base);
52252 framebuffer_release(info);
52253diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52254index 88714ae..16c2e11 100644
52255--- a/drivers/video/via/via_clock.h
52256+++ b/drivers/video/via/via_clock.h
52257@@ -56,7 +56,7 @@ struct via_clock {
52258
52259 void (*set_engine_pll_state)(u8 state);
52260 void (*set_engine_pll)(struct via_pll_config config);
52261-};
52262+} __no_const;
52263
52264
52265 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52266diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52267index fef20db..d28b1ab 100644
52268--- a/drivers/xen/xenfs/xenstored.c
52269+++ b/drivers/xen/xenfs/xenstored.c
52270@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52271 static int xsd_kva_open(struct inode *inode, struct file *file)
52272 {
52273 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52274+#ifdef CONFIG_GRKERNSEC_HIDESYM
52275+ NULL);
52276+#else
52277 xen_store_interface);
52278+#endif
52279+
52280 if (!file->private_data)
52281 return -ENOMEM;
52282 return 0;
52283diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52284index 9ff073f..05cef23 100644
52285--- a/fs/9p/vfs_addr.c
52286+++ b/fs/9p/vfs_addr.c
52287@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52288
52289 retval = v9fs_file_write_internal(inode,
52290 v9inode->writeback_fid,
52291- (__force const char __user *)buffer,
52292+ (const char __force_user *)buffer,
52293 len, &offset, 0);
52294 if (retval > 0)
52295 retval = 0;
52296diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52297index 25b018e..b941525 100644
52298--- a/fs/9p/vfs_inode.c
52299+++ b/fs/9p/vfs_inode.c
52300@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52301 void
52302 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52303 {
52304- char *s = nd_get_link(nd);
52305+ const char *s = nd_get_link(nd);
52306
52307 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52308 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52309diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52310index 370b24c..ff0be7b 100644
52311--- a/fs/Kconfig.binfmt
52312+++ b/fs/Kconfig.binfmt
52313@@ -103,7 +103,7 @@ config HAVE_AOUT
52314
52315 config BINFMT_AOUT
52316 tristate "Kernel support for a.out and ECOFF binaries"
52317- depends on HAVE_AOUT
52318+ depends on HAVE_AOUT && BROKEN
52319 ---help---
52320 A.out (Assembler.OUTput) is a set of formats for libraries and
52321 executables used in the earliest versions of UNIX. Linux used
52322diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52323index 789bc25..fafaeea 100644
52324--- a/fs/afs/inode.c
52325+++ b/fs/afs/inode.c
52326@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52327 struct afs_vnode *vnode;
52328 struct super_block *sb;
52329 struct inode *inode;
52330- static atomic_t afs_autocell_ino;
52331+ static atomic_unchecked_t afs_autocell_ino;
52332
52333 _enter("{%x:%u},%*.*s,",
52334 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52335@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52336 data.fid.unique = 0;
52337 data.fid.vnode = 0;
52338
52339- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52340+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52341 afs_iget5_autocell_test, afs_iget5_set,
52342 &data);
52343 if (!inode) {
52344diff --git a/fs/aio.c b/fs/aio.c
52345index 9b5ca11..c530886 100644
52346--- a/fs/aio.c
52347+++ b/fs/aio.c
52348@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52349 size += sizeof(struct io_event) * nr_events;
52350 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52351
52352- if (nr_pages < 0)
52353+ if (nr_pages <= 0)
52354 return -EINVAL;
52355
52356 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52357@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52358 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52359 {
52360 ssize_t ret;
52361+ struct iovec iovstack;
52362
52363 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52364
52365@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52366 if (compat)
52367 ret = compat_rw_copy_check_uvector(rw,
52368 (struct compat_iovec __user *)kiocb->ki_buf,
52369- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52370+ kiocb->ki_nr_segs, 1, &iovstack,
52371 &kiocb->ki_iovec);
52372 else
52373 #endif
52374 ret = rw_copy_check_uvector(rw,
52375 (struct iovec __user *)kiocb->ki_buf,
52376- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52377+ kiocb->ki_nr_segs, 1, &iovstack,
52378 &kiocb->ki_iovec);
52379 if (ret < 0)
52380 return ret;
52381
52382+ if (kiocb->ki_iovec == &iovstack) {
52383+ kiocb->ki_inline_vec = iovstack;
52384+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52385+ }
52386+
52387 /* ki_nbytes now reflect bytes instead of segs */
52388 kiocb->ki_nbytes = ret;
52389 return 0;
52390diff --git a/fs/attr.c b/fs/attr.c
52391index 1449adb..a2038c2 100644
52392--- a/fs/attr.c
52393+++ b/fs/attr.c
52394@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52395 unsigned long limit;
52396
52397 limit = rlimit(RLIMIT_FSIZE);
52398+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52399 if (limit != RLIM_INFINITY && offset > limit)
52400 goto out_sig;
52401 if (offset > inode->i_sb->s_maxbytes)
52402diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52403index 3db70da..7aeec5b 100644
52404--- a/fs/autofs4/waitq.c
52405+++ b/fs/autofs4/waitq.c
52406@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52407 {
52408 unsigned long sigpipe, flags;
52409 mm_segment_t fs;
52410- const char *data = (const char *)addr;
52411+ const char __user *data = (const char __force_user *)addr;
52412 ssize_t wr = 0;
52413
52414 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52415@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52416 return 1;
52417 }
52418
52419+#ifdef CONFIG_GRKERNSEC_HIDESYM
52420+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52421+#endif
52422+
52423 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52424 enum autofs_notify notify)
52425 {
52426@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52427
52428 /* If this is a direct mount request create a dummy name */
52429 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52430+#ifdef CONFIG_GRKERNSEC_HIDESYM
52431+ /* this name does get written to userland via autofs4_write() */
52432+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52433+#else
52434 qstr.len = sprintf(name, "%p", dentry);
52435+#endif
52436 else {
52437 qstr.len = autofs4_getpath(sbi, dentry, &name);
52438 if (!qstr.len) {
52439diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52440index 2722387..c8dd2a7 100644
52441--- a/fs/befs/endian.h
52442+++ b/fs/befs/endian.h
52443@@ -11,7 +11,7 @@
52444
52445 #include <asm/byteorder.h>
52446
52447-static inline u64
52448+static inline u64 __intentional_overflow(-1)
52449 fs64_to_cpu(const struct super_block *sb, fs64 n)
52450 {
52451 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52452@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52453 return (__force fs64)cpu_to_be64(n);
52454 }
52455
52456-static inline u32
52457+static inline u32 __intentional_overflow(-1)
52458 fs32_to_cpu(const struct super_block *sb, fs32 n)
52459 {
52460 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52461diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52462index e9c75e2..1baece1 100644
52463--- a/fs/befs/linuxvfs.c
52464+++ b/fs/befs/linuxvfs.c
52465@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52466 {
52467 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52468 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52469- char *link = nd_get_link(nd);
52470+ const char *link = nd_get_link(nd);
52471 if (!IS_ERR(link))
52472 kfree(link);
52473 }
52474diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52475index 89dec7f..361b0d75 100644
52476--- a/fs/binfmt_aout.c
52477+++ b/fs/binfmt_aout.c
52478@@ -16,6 +16,7 @@
52479 #include <linux/string.h>
52480 #include <linux/fs.h>
52481 #include <linux/file.h>
52482+#include <linux/security.h>
52483 #include <linux/stat.h>
52484 #include <linux/fcntl.h>
52485 #include <linux/ptrace.h>
52486@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52487 #endif
52488 # define START_STACK(u) ((void __user *)u.start_stack)
52489
52490+ memset(&dump, 0, sizeof(dump));
52491+
52492 fs = get_fs();
52493 set_fs(KERNEL_DS);
52494 has_dumped = 1;
52495@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52496
52497 /* If the size of the dump file exceeds the rlimit, then see what would happen
52498 if we wrote the stack, but not the data area. */
52499+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52500 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52501 dump.u_dsize = 0;
52502
52503 /* Make sure we have enough room to write the stack and data areas. */
52504+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52505 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52506 dump.u_ssize = 0;
52507
52508@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52509 rlim = rlimit(RLIMIT_DATA);
52510 if (rlim >= RLIM_INFINITY)
52511 rlim = ~0;
52512+
52513+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52514 if (ex.a_data + ex.a_bss > rlim)
52515 return -ENOMEM;
52516
52517@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52518
52519 install_exec_creds(bprm);
52520
52521+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52522+ current->mm->pax_flags = 0UL;
52523+#endif
52524+
52525+#ifdef CONFIG_PAX_PAGEEXEC
52526+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52527+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52528+
52529+#ifdef CONFIG_PAX_EMUTRAMP
52530+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52531+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52532+#endif
52533+
52534+#ifdef CONFIG_PAX_MPROTECT
52535+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52536+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52537+#endif
52538+
52539+ }
52540+#endif
52541+
52542 if (N_MAGIC(ex) == OMAGIC) {
52543 unsigned long text_addr, map_size;
52544 loff_t pos;
52545@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52546 }
52547
52548 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52549- PROT_READ | PROT_WRITE | PROT_EXEC,
52550+ PROT_READ | PROT_WRITE,
52551 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52552 fd_offset + ex.a_text);
52553 if (error != N_DATADDR(ex)) {
52554diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52555index 100edcc..244db37 100644
52556--- a/fs/binfmt_elf.c
52557+++ b/fs/binfmt_elf.c
52558@@ -34,6 +34,7 @@
52559 #include <linux/utsname.h>
52560 #include <linux/coredump.h>
52561 #include <linux/sched.h>
52562+#include <linux/xattr.h>
52563 #include <asm/uaccess.h>
52564 #include <asm/param.h>
52565 #include <asm/page.h>
52566@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52567 #define elf_core_dump NULL
52568 #endif
52569
52570+#ifdef CONFIG_PAX_MPROTECT
52571+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52572+#endif
52573+
52574+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52575+static void elf_handle_mmap(struct file *file);
52576+#endif
52577+
52578 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52579 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52580 #else
52581@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52582 .load_binary = load_elf_binary,
52583 .load_shlib = load_elf_library,
52584 .core_dump = elf_core_dump,
52585+
52586+#ifdef CONFIG_PAX_MPROTECT
52587+ .handle_mprotect= elf_handle_mprotect,
52588+#endif
52589+
52590+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52591+ .handle_mmap = elf_handle_mmap,
52592+#endif
52593+
52594 .min_coredump = ELF_EXEC_PAGESIZE,
52595 };
52596
52597@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52598
52599 static int set_brk(unsigned long start, unsigned long end)
52600 {
52601+ unsigned long e = end;
52602+
52603 start = ELF_PAGEALIGN(start);
52604 end = ELF_PAGEALIGN(end);
52605 if (end > start) {
52606@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52607 if (BAD_ADDR(addr))
52608 return addr;
52609 }
52610- current->mm->start_brk = current->mm->brk = end;
52611+ current->mm->start_brk = current->mm->brk = e;
52612 return 0;
52613 }
52614
52615@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52616 elf_addr_t __user *u_rand_bytes;
52617 const char *k_platform = ELF_PLATFORM;
52618 const char *k_base_platform = ELF_BASE_PLATFORM;
52619- unsigned char k_rand_bytes[16];
52620+ u32 k_rand_bytes[4];
52621 int items;
52622 elf_addr_t *elf_info;
52623 int ei_index = 0;
52624 const struct cred *cred = current_cred();
52625 struct vm_area_struct *vma;
52626+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52627
52628 /*
52629 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52630@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52631 * Generate 16 random bytes for userspace PRNG seeding.
52632 */
52633 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52634- u_rand_bytes = (elf_addr_t __user *)
52635- STACK_ALLOC(p, sizeof(k_rand_bytes));
52636+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52637+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52638+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52639+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52640+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52641+ u_rand_bytes = (elf_addr_t __user *) p;
52642 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52643 return -EFAULT;
52644
52645@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52646 return -EFAULT;
52647 current->mm->env_end = p;
52648
52649+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52650+
52651 /* Put the elf_info on the stack in the right place. */
52652 sp = (elf_addr_t __user *)envp + 1;
52653- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52654+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52655 return -EFAULT;
52656 return 0;
52657 }
52658@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52659 an ELF header */
52660
52661 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52662- struct file *interpreter, unsigned long *interp_map_addr,
52663- unsigned long no_base)
52664+ struct file *interpreter, unsigned long no_base)
52665 {
52666 struct elf_phdr *elf_phdata;
52667 struct elf_phdr *eppnt;
52668- unsigned long load_addr = 0;
52669+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52670 int load_addr_set = 0;
52671 unsigned long last_bss = 0, elf_bss = 0;
52672- unsigned long error = ~0UL;
52673+ unsigned long error = -EINVAL;
52674 unsigned long total_size;
52675 int retval, i, size;
52676
52677@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52678 goto out_close;
52679 }
52680
52681+#ifdef CONFIG_PAX_SEGMEXEC
52682+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52683+ pax_task_size = SEGMEXEC_TASK_SIZE;
52684+#endif
52685+
52686 eppnt = elf_phdata;
52687 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52688 if (eppnt->p_type == PT_LOAD) {
52689@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52690 map_addr = elf_map(interpreter, load_addr + vaddr,
52691 eppnt, elf_prot, elf_type, total_size);
52692 total_size = 0;
52693- if (!*interp_map_addr)
52694- *interp_map_addr = map_addr;
52695 error = map_addr;
52696 if (BAD_ADDR(map_addr))
52697 goto out_close;
52698@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52699 k = load_addr + eppnt->p_vaddr;
52700 if (BAD_ADDR(k) ||
52701 eppnt->p_filesz > eppnt->p_memsz ||
52702- eppnt->p_memsz > TASK_SIZE ||
52703- TASK_SIZE - eppnt->p_memsz < k) {
52704+ eppnt->p_memsz > pax_task_size ||
52705+ pax_task_size - eppnt->p_memsz < k) {
52706 error = -ENOMEM;
52707 goto out_close;
52708 }
52709@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52710 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52711
52712 /* Map the last of the bss segment */
52713- error = vm_brk(elf_bss, last_bss - elf_bss);
52714- if (BAD_ADDR(error))
52715- goto out_close;
52716+ if (last_bss > elf_bss) {
52717+ error = vm_brk(elf_bss, last_bss - elf_bss);
52718+ if (BAD_ADDR(error))
52719+ goto out_close;
52720+ }
52721 }
52722
52723 error = load_addr;
52724@@ -538,6 +569,315 @@ out:
52725 return error;
52726 }
52727
52728+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52729+#ifdef CONFIG_PAX_SOFTMODE
52730+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52731+{
52732+ unsigned long pax_flags = 0UL;
52733+
52734+#ifdef CONFIG_PAX_PAGEEXEC
52735+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52736+ pax_flags |= MF_PAX_PAGEEXEC;
52737+#endif
52738+
52739+#ifdef CONFIG_PAX_SEGMEXEC
52740+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52741+ pax_flags |= MF_PAX_SEGMEXEC;
52742+#endif
52743+
52744+#ifdef CONFIG_PAX_EMUTRAMP
52745+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52746+ pax_flags |= MF_PAX_EMUTRAMP;
52747+#endif
52748+
52749+#ifdef CONFIG_PAX_MPROTECT
52750+ if (elf_phdata->p_flags & PF_MPROTECT)
52751+ pax_flags |= MF_PAX_MPROTECT;
52752+#endif
52753+
52754+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52755+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52756+ pax_flags |= MF_PAX_RANDMMAP;
52757+#endif
52758+
52759+ return pax_flags;
52760+}
52761+#endif
52762+
52763+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52764+{
52765+ unsigned long pax_flags = 0UL;
52766+
52767+#ifdef CONFIG_PAX_PAGEEXEC
52768+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52769+ pax_flags |= MF_PAX_PAGEEXEC;
52770+#endif
52771+
52772+#ifdef CONFIG_PAX_SEGMEXEC
52773+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52774+ pax_flags |= MF_PAX_SEGMEXEC;
52775+#endif
52776+
52777+#ifdef CONFIG_PAX_EMUTRAMP
52778+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52779+ pax_flags |= MF_PAX_EMUTRAMP;
52780+#endif
52781+
52782+#ifdef CONFIG_PAX_MPROTECT
52783+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52784+ pax_flags |= MF_PAX_MPROTECT;
52785+#endif
52786+
52787+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52788+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52789+ pax_flags |= MF_PAX_RANDMMAP;
52790+#endif
52791+
52792+ return pax_flags;
52793+}
52794+#endif
52795+
52796+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52797+#ifdef CONFIG_PAX_SOFTMODE
52798+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52799+{
52800+ unsigned long pax_flags = 0UL;
52801+
52802+#ifdef CONFIG_PAX_PAGEEXEC
52803+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52804+ pax_flags |= MF_PAX_PAGEEXEC;
52805+#endif
52806+
52807+#ifdef CONFIG_PAX_SEGMEXEC
52808+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52809+ pax_flags |= MF_PAX_SEGMEXEC;
52810+#endif
52811+
52812+#ifdef CONFIG_PAX_EMUTRAMP
52813+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52814+ pax_flags |= MF_PAX_EMUTRAMP;
52815+#endif
52816+
52817+#ifdef CONFIG_PAX_MPROTECT
52818+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52819+ pax_flags |= MF_PAX_MPROTECT;
52820+#endif
52821+
52822+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52823+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52824+ pax_flags |= MF_PAX_RANDMMAP;
52825+#endif
52826+
52827+ return pax_flags;
52828+}
52829+#endif
52830+
52831+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52832+{
52833+ unsigned long pax_flags = 0UL;
52834+
52835+#ifdef CONFIG_PAX_PAGEEXEC
52836+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52837+ pax_flags |= MF_PAX_PAGEEXEC;
52838+#endif
52839+
52840+#ifdef CONFIG_PAX_SEGMEXEC
52841+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52842+ pax_flags |= MF_PAX_SEGMEXEC;
52843+#endif
52844+
52845+#ifdef CONFIG_PAX_EMUTRAMP
52846+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52847+ pax_flags |= MF_PAX_EMUTRAMP;
52848+#endif
52849+
52850+#ifdef CONFIG_PAX_MPROTECT
52851+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52852+ pax_flags |= MF_PAX_MPROTECT;
52853+#endif
52854+
52855+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52856+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52857+ pax_flags |= MF_PAX_RANDMMAP;
52858+#endif
52859+
52860+ return pax_flags;
52861+}
52862+#endif
52863+
52864+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52865+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52866+{
52867+ unsigned long pax_flags = 0UL;
52868+
52869+#ifdef CONFIG_PAX_EI_PAX
52870+
52871+#ifdef CONFIG_PAX_PAGEEXEC
52872+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52873+ pax_flags |= MF_PAX_PAGEEXEC;
52874+#endif
52875+
52876+#ifdef CONFIG_PAX_SEGMEXEC
52877+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52878+ pax_flags |= MF_PAX_SEGMEXEC;
52879+#endif
52880+
52881+#ifdef CONFIG_PAX_EMUTRAMP
52882+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52883+ pax_flags |= MF_PAX_EMUTRAMP;
52884+#endif
52885+
52886+#ifdef CONFIG_PAX_MPROTECT
52887+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52888+ pax_flags |= MF_PAX_MPROTECT;
52889+#endif
52890+
52891+#ifdef CONFIG_PAX_ASLR
52892+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52893+ pax_flags |= MF_PAX_RANDMMAP;
52894+#endif
52895+
52896+#else
52897+
52898+#ifdef CONFIG_PAX_PAGEEXEC
52899+ pax_flags |= MF_PAX_PAGEEXEC;
52900+#endif
52901+
52902+#ifdef CONFIG_PAX_SEGMEXEC
52903+ pax_flags |= MF_PAX_SEGMEXEC;
52904+#endif
52905+
52906+#ifdef CONFIG_PAX_MPROTECT
52907+ pax_flags |= MF_PAX_MPROTECT;
52908+#endif
52909+
52910+#ifdef CONFIG_PAX_RANDMMAP
52911+ if (randomize_va_space)
52912+ pax_flags |= MF_PAX_RANDMMAP;
52913+#endif
52914+
52915+#endif
52916+
52917+ return pax_flags;
52918+}
52919+
52920+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52921+{
52922+
52923+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52924+ unsigned long i;
52925+
52926+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52927+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52928+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52929+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52930+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52931+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52932+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52933+ return ~0UL;
52934+
52935+#ifdef CONFIG_PAX_SOFTMODE
52936+ if (pax_softmode)
52937+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52938+ else
52939+#endif
52940+
52941+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52942+ break;
52943+ }
52944+#endif
52945+
52946+ return ~0UL;
52947+}
52948+
52949+static unsigned long pax_parse_xattr_pax(struct file * const file)
52950+{
52951+
52952+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52953+ ssize_t xattr_size, i;
52954+ unsigned char xattr_value[sizeof("pemrs") - 1];
52955+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52956+
52957+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52958+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52959+ return ~0UL;
52960+
52961+ for (i = 0; i < xattr_size; i++)
52962+ switch (xattr_value[i]) {
52963+ default:
52964+ return ~0UL;
52965+
52966+#define parse_flag(option1, option2, flag) \
52967+ case option1: \
52968+ if (pax_flags_hardmode & MF_PAX_##flag) \
52969+ return ~0UL; \
52970+ pax_flags_hardmode |= MF_PAX_##flag; \
52971+ break; \
52972+ case option2: \
52973+ if (pax_flags_softmode & MF_PAX_##flag) \
52974+ return ~0UL; \
52975+ pax_flags_softmode |= MF_PAX_##flag; \
52976+ break;
52977+
52978+ parse_flag('p', 'P', PAGEEXEC);
52979+ parse_flag('e', 'E', EMUTRAMP);
52980+ parse_flag('m', 'M', MPROTECT);
52981+ parse_flag('r', 'R', RANDMMAP);
52982+ parse_flag('s', 'S', SEGMEXEC);
52983+
52984+#undef parse_flag
52985+ }
52986+
52987+ if (pax_flags_hardmode & pax_flags_softmode)
52988+ return ~0UL;
52989+
52990+#ifdef CONFIG_PAX_SOFTMODE
52991+ if (pax_softmode)
52992+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52993+ else
52994+#endif
52995+
52996+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52997+#else
52998+ return ~0UL;
52999+#endif
53000+
53001+}
53002+
53003+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53004+{
53005+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53006+
53007+ pax_flags = pax_parse_ei_pax(elf_ex);
53008+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53009+ xattr_pax_flags = pax_parse_xattr_pax(file);
53010+
53011+ if (pt_pax_flags == ~0UL)
53012+ pt_pax_flags = xattr_pax_flags;
53013+ else if (xattr_pax_flags == ~0UL)
53014+ xattr_pax_flags = pt_pax_flags;
53015+ if (pt_pax_flags != xattr_pax_flags)
53016+ return -EINVAL;
53017+ if (pt_pax_flags != ~0UL)
53018+ pax_flags = pt_pax_flags;
53019+
53020+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53021+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53022+ if ((__supported_pte_mask & _PAGE_NX))
53023+ pax_flags &= ~MF_PAX_SEGMEXEC;
53024+ else
53025+ pax_flags &= ~MF_PAX_PAGEEXEC;
53026+ }
53027+#endif
53028+
53029+ if (0 > pax_check_flags(&pax_flags))
53030+ return -EINVAL;
53031+
53032+ current->mm->pax_flags = pax_flags;
53033+ return 0;
53034+}
53035+#endif
53036+
53037 /*
53038 * These are the functions used to load ELF style executables and shared
53039 * libraries. There is no binary dependent code anywhere else.
53040@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53041 {
53042 unsigned int random_variable = 0;
53043
53044+#ifdef CONFIG_PAX_RANDUSTACK
53045+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53046+ return stack_top - current->mm->delta_stack;
53047+#endif
53048+
53049 if ((current->flags & PF_RANDOMIZE) &&
53050 !(current->personality & ADDR_NO_RANDOMIZE)) {
53051 random_variable = get_random_int() & STACK_RND_MASK;
53052@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53053 unsigned long load_addr = 0, load_bias = 0;
53054 int load_addr_set = 0;
53055 char * elf_interpreter = NULL;
53056- unsigned long error;
53057+ unsigned long error = 0;
53058 struct elf_phdr *elf_ppnt, *elf_phdata;
53059 unsigned long elf_bss, elf_brk;
53060 int retval, i;
53061@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53062 unsigned long start_code, end_code, start_data, end_data;
53063 unsigned long reloc_func_desc __maybe_unused = 0;
53064 int executable_stack = EXSTACK_DEFAULT;
53065- unsigned long def_flags = 0;
53066 struct pt_regs *regs = current_pt_regs();
53067 struct {
53068 struct elfhdr elf_ex;
53069 struct elfhdr interp_elf_ex;
53070 } *loc;
53071+ unsigned long pax_task_size = TASK_SIZE;
53072
53073 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53074 if (!loc) {
53075@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53076 goto out_free_dentry;
53077
53078 /* OK, This is the point of no return */
53079- current->mm->def_flags = def_flags;
53080+
53081+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53082+ current->mm->pax_flags = 0UL;
53083+#endif
53084+
53085+#ifdef CONFIG_PAX_DLRESOLVE
53086+ current->mm->call_dl_resolve = 0UL;
53087+#endif
53088+
53089+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53090+ current->mm->call_syscall = 0UL;
53091+#endif
53092+
53093+#ifdef CONFIG_PAX_ASLR
53094+ current->mm->delta_mmap = 0UL;
53095+ current->mm->delta_stack = 0UL;
53096+#endif
53097+
53098+ current->mm->def_flags = 0;
53099+
53100+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53101+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53102+ send_sig(SIGKILL, current, 0);
53103+ goto out_free_dentry;
53104+ }
53105+#endif
53106+
53107+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53108+ pax_set_initial_flags(bprm);
53109+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53110+ if (pax_set_initial_flags_func)
53111+ (pax_set_initial_flags_func)(bprm);
53112+#endif
53113+
53114+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53115+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53116+ current->mm->context.user_cs_limit = PAGE_SIZE;
53117+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53118+ }
53119+#endif
53120+
53121+#ifdef CONFIG_PAX_SEGMEXEC
53122+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53123+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53124+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53125+ pax_task_size = SEGMEXEC_TASK_SIZE;
53126+ current->mm->def_flags |= VM_NOHUGEPAGE;
53127+ }
53128+#endif
53129+
53130+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53131+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53132+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53133+ put_cpu();
53134+ }
53135+#endif
53136
53137 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53138 may depend on the personality. */
53139 SET_PERSONALITY(loc->elf_ex);
53140+
53141+#ifdef CONFIG_PAX_ASLR
53142+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53143+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53144+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53145+ }
53146+#endif
53147+
53148+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53149+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53150+ executable_stack = EXSTACK_DISABLE_X;
53151+ current->personality &= ~READ_IMPLIES_EXEC;
53152+ } else
53153+#endif
53154+
53155 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53156 current->personality |= READ_IMPLIES_EXEC;
53157
53158@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53159 #else
53160 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53161 #endif
53162+
53163+#ifdef CONFIG_PAX_RANDMMAP
53164+ /* PaX: randomize base address at the default exe base if requested */
53165+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53166+#ifdef CONFIG_SPARC64
53167+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53168+#else
53169+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53170+#endif
53171+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53172+ elf_flags |= MAP_FIXED;
53173+ }
53174+#endif
53175+
53176 }
53177
53178 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53179@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53180 * allowed task size. Note that p_filesz must always be
53181 * <= p_memsz so it is only necessary to check p_memsz.
53182 */
53183- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53184- elf_ppnt->p_memsz > TASK_SIZE ||
53185- TASK_SIZE - elf_ppnt->p_memsz < k) {
53186+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53187+ elf_ppnt->p_memsz > pax_task_size ||
53188+ pax_task_size - elf_ppnt->p_memsz < k) {
53189 /* set_brk can never work. Avoid overflows. */
53190 send_sig(SIGKILL, current, 0);
53191 retval = -EINVAL;
53192@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53193 goto out_free_dentry;
53194 }
53195 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53196- send_sig(SIGSEGV, current, 0);
53197- retval = -EFAULT; /* Nobody gets to see this, but.. */
53198- goto out_free_dentry;
53199+ /*
53200+ * This bss-zeroing can fail if the ELF
53201+ * file specifies odd protections. So
53202+ * we don't check the return value
53203+ */
53204 }
53205
53206+#ifdef CONFIG_PAX_RANDMMAP
53207+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53208+ unsigned long start, size, flags;
53209+ vm_flags_t vm_flags;
53210+
53211+ start = ELF_PAGEALIGN(elf_brk);
53212+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53213+ flags = MAP_FIXED | MAP_PRIVATE;
53214+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53215+
53216+ down_write(&current->mm->mmap_sem);
53217+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53218+ retval = -ENOMEM;
53219+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53220+// if (current->personality & ADDR_NO_RANDOMIZE)
53221+// vm_flags |= VM_READ | VM_MAYREAD;
53222+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53223+ retval = IS_ERR_VALUE(start) ? start : 0;
53224+ }
53225+ up_write(&current->mm->mmap_sem);
53226+ if (retval == 0)
53227+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53228+ if (retval < 0) {
53229+ send_sig(SIGKILL, current, 0);
53230+ goto out_free_dentry;
53231+ }
53232+ }
53233+#endif
53234+
53235 if (elf_interpreter) {
53236- unsigned long interp_map_addr = 0;
53237-
53238 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53239 interpreter,
53240- &interp_map_addr,
53241 load_bias);
53242 if (!IS_ERR((void *)elf_entry)) {
53243 /*
53244@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53245 * Decide what to dump of a segment, part, all or none.
53246 */
53247 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53248- unsigned long mm_flags)
53249+ unsigned long mm_flags, long signr)
53250 {
53251 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53252
53253@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53254 if (vma->vm_file == NULL)
53255 return 0;
53256
53257- if (FILTER(MAPPED_PRIVATE))
53258+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53259 goto whole;
53260
53261 /*
53262@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53263 {
53264 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53265 int i = 0;
53266- do
53267+ do {
53268 i += 2;
53269- while (auxv[i - 2] != AT_NULL);
53270+ } while (auxv[i - 2] != AT_NULL);
53271 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53272 }
53273
53274@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53275 {
53276 mm_segment_t old_fs = get_fs();
53277 set_fs(KERNEL_DS);
53278- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53279+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53280 set_fs(old_fs);
53281 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53282 }
53283@@ -2017,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53284 }
53285
53286 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53287- unsigned long mm_flags)
53288+ struct coredump_params *cprm)
53289 {
53290 struct vm_area_struct *vma;
53291 size_t size = 0;
53292
53293 for (vma = first_vma(current, gate_vma); vma != NULL;
53294 vma = next_vma(vma, gate_vma))
53295- size += vma_dump_size(vma, mm_flags);
53296+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53297 return size;
53298 }
53299
53300@@ -2117,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53301
53302 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53303
53304- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53305+ offset += elf_core_vma_data_size(gate_vma, cprm);
53306 offset += elf_core_extra_data_size();
53307 e_shoff = offset;
53308
53309@@ -2131,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53310 offset = dataoff;
53311
53312 size += sizeof(*elf);
53313+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53314 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53315 goto end_coredump;
53316
53317 size += sizeof(*phdr4note);
53318+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53319 if (size > cprm->limit
53320 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53321 goto end_coredump;
53322@@ -2148,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53323 phdr.p_offset = offset;
53324 phdr.p_vaddr = vma->vm_start;
53325 phdr.p_paddr = 0;
53326- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53327+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53328 phdr.p_memsz = vma->vm_end - vma->vm_start;
53329 offset += phdr.p_filesz;
53330 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53331@@ -2159,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53332 phdr.p_align = ELF_EXEC_PAGESIZE;
53333
53334 size += sizeof(phdr);
53335+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53336 if (size > cprm->limit
53337 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53338 goto end_coredump;
53339@@ -2183,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53340 unsigned long addr;
53341 unsigned long end;
53342
53343- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53344+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53345
53346 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53347 struct page *page;
53348@@ -2192,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53349 page = get_dump_page(addr);
53350 if (page) {
53351 void *kaddr = kmap(page);
53352+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53353 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53354 !dump_write(cprm->file, kaddr,
53355 PAGE_SIZE);
53356@@ -2209,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53357
53358 if (e_phnum == PN_XNUM) {
53359 size += sizeof(*shdr4extnum);
53360+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53361 if (size > cprm->limit
53362 || !dump_write(cprm->file, shdr4extnum,
53363 sizeof(*shdr4extnum)))
53364@@ -2229,6 +2691,167 @@ out:
53365
53366 #endif /* CONFIG_ELF_CORE */
53367
53368+#ifdef CONFIG_PAX_MPROTECT
53369+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53370+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53371+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53372+ *
53373+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53374+ * basis because we want to allow the common case and not the special ones.
53375+ */
53376+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53377+{
53378+ struct elfhdr elf_h;
53379+ struct elf_phdr elf_p;
53380+ unsigned long i;
53381+ unsigned long oldflags;
53382+ bool is_textrel_rw, is_textrel_rx, is_relro;
53383+
53384+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53385+ return;
53386+
53387+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53388+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53389+
53390+#ifdef CONFIG_PAX_ELFRELOCS
53391+ /* possible TEXTREL */
53392+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53393+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53394+#else
53395+ is_textrel_rw = false;
53396+ is_textrel_rx = false;
53397+#endif
53398+
53399+ /* possible RELRO */
53400+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53401+
53402+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53403+ return;
53404+
53405+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53406+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53407+
53408+#ifdef CONFIG_PAX_ETEXECRELOCS
53409+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53410+#else
53411+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53412+#endif
53413+
53414+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53415+ !elf_check_arch(&elf_h) ||
53416+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53417+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53418+ return;
53419+
53420+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53421+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53422+ return;
53423+ switch (elf_p.p_type) {
53424+ case PT_DYNAMIC:
53425+ if (!is_textrel_rw && !is_textrel_rx)
53426+ continue;
53427+ i = 0UL;
53428+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53429+ elf_dyn dyn;
53430+
53431+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53432+ break;
53433+ if (dyn.d_tag == DT_NULL)
53434+ break;
53435+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53436+ gr_log_textrel(vma);
53437+ if (is_textrel_rw)
53438+ vma->vm_flags |= VM_MAYWRITE;
53439+ else
53440+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53441+ vma->vm_flags &= ~VM_MAYWRITE;
53442+ break;
53443+ }
53444+ i++;
53445+ }
53446+ is_textrel_rw = false;
53447+ is_textrel_rx = false;
53448+ continue;
53449+
53450+ case PT_GNU_RELRO:
53451+ if (!is_relro)
53452+ continue;
53453+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53454+ vma->vm_flags &= ~VM_MAYWRITE;
53455+ is_relro = false;
53456+ continue;
53457+
53458+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53459+ case PT_PAX_FLAGS: {
53460+ const char *msg_mprotect = "", *msg_emutramp = "";
53461+ char *buffer_lib, *buffer_exe;
53462+
53463+ if (elf_p.p_flags & PF_NOMPROTECT)
53464+ msg_mprotect = "MPROTECT disabled";
53465+
53466+#ifdef CONFIG_PAX_EMUTRAMP
53467+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53468+ msg_emutramp = "EMUTRAMP enabled";
53469+#endif
53470+
53471+ if (!msg_mprotect[0] && !msg_emutramp[0])
53472+ continue;
53473+
53474+ if (!printk_ratelimit())
53475+ continue;
53476+
53477+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53478+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53479+ if (buffer_lib && buffer_exe) {
53480+ char *path_lib, *path_exe;
53481+
53482+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53483+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53484+
53485+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53486+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53487+
53488+ }
53489+ free_page((unsigned long)buffer_exe);
53490+ free_page((unsigned long)buffer_lib);
53491+ continue;
53492+ }
53493+#endif
53494+
53495+ }
53496+ }
53497+}
53498+#endif
53499+
53500+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53501+
53502+extern int grsec_enable_log_rwxmaps;
53503+
53504+static void elf_handle_mmap(struct file *file)
53505+{
53506+ struct elfhdr elf_h;
53507+ struct elf_phdr elf_p;
53508+ unsigned long i;
53509+
53510+ if (!grsec_enable_log_rwxmaps)
53511+ return;
53512+
53513+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53514+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53515+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53516+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53517+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53518+ return;
53519+
53520+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53521+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53522+ return;
53523+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53524+ gr_log_ptgnustack(file);
53525+ }
53526+}
53527+#endif
53528+
53529 static int __init init_elf_binfmt(void)
53530 {
53531 register_binfmt(&elf_format);
53532diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53533index d50bbe5..af3b649 100644
53534--- a/fs/binfmt_flat.c
53535+++ b/fs/binfmt_flat.c
53536@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53537 realdatastart = (unsigned long) -ENOMEM;
53538 printk("Unable to allocate RAM for process data, errno %d\n",
53539 (int)-realdatastart);
53540+ down_write(&current->mm->mmap_sem);
53541 vm_munmap(textpos, text_len);
53542+ up_write(&current->mm->mmap_sem);
53543 ret = realdatastart;
53544 goto err;
53545 }
53546@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53547 }
53548 if (IS_ERR_VALUE(result)) {
53549 printk("Unable to read data+bss, errno %d\n", (int)-result);
53550+ down_write(&current->mm->mmap_sem);
53551 vm_munmap(textpos, text_len);
53552 vm_munmap(realdatastart, len);
53553+ up_write(&current->mm->mmap_sem);
53554 ret = result;
53555 goto err;
53556 }
53557@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53558 }
53559 if (IS_ERR_VALUE(result)) {
53560 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53561+ down_write(&current->mm->mmap_sem);
53562 vm_munmap(textpos, text_len + data_len + extra +
53563 MAX_SHARED_LIBS * sizeof(unsigned long));
53564+ up_write(&current->mm->mmap_sem);
53565 ret = result;
53566 goto err;
53567 }
53568diff --git a/fs/bio.c b/fs/bio.c
53569index c5eae72..599e3cf 100644
53570--- a/fs/bio.c
53571+++ b/fs/bio.c
53572@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53573 /*
53574 * Overflow, abort
53575 */
53576- if (end < start)
53577+ if (end < start || end - start > INT_MAX - nr_pages)
53578 return ERR_PTR(-EINVAL);
53579
53580 nr_pages += end - start;
53581@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53582 /*
53583 * Overflow, abort
53584 */
53585- if (end < start)
53586+ if (end < start || end - start > INT_MAX - nr_pages)
53587 return ERR_PTR(-EINVAL);
53588
53589 nr_pages += end - start;
53590@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53591 const int read = bio_data_dir(bio) == READ;
53592 struct bio_map_data *bmd = bio->bi_private;
53593 int i;
53594- char *p = bmd->sgvecs[0].iov_base;
53595+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53596
53597 bio_for_each_segment_all(bvec, bio, i) {
53598 char *addr = page_address(bvec->bv_page);
53599diff --git a/fs/block_dev.c b/fs/block_dev.c
53600index c7bda5c..2121e94 100644
53601--- a/fs/block_dev.c
53602+++ b/fs/block_dev.c
53603@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53604 else if (bdev->bd_contains == bdev)
53605 return true; /* is a whole device which isn't held */
53606
53607- else if (whole->bd_holder == bd_may_claim)
53608+ else if (whole->bd_holder == (void *)bd_may_claim)
53609 return true; /* is a partition of a device that is being partitioned */
53610 else if (whole->bd_holder != NULL)
53611 return false; /* is a partition of a held device */
53612diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53613index ed50460..fe84385 100644
53614--- a/fs/btrfs/ctree.c
53615+++ b/fs/btrfs/ctree.c
53616@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53617 free_extent_buffer(buf);
53618 add_root_to_dirty_list(root);
53619 } else {
53620- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53621- parent_start = parent->start;
53622- else
53623+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53624+ if (parent)
53625+ parent_start = parent->start;
53626+ else
53627+ parent_start = 0;
53628+ } else
53629 parent_start = 0;
53630
53631 WARN_ON(trans->transid != btrfs_header_generation(parent));
53632diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53633index 3755109..e3d457f 100644
53634--- a/fs/btrfs/delayed-inode.c
53635+++ b/fs/btrfs/delayed-inode.c
53636@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53637
53638 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53639 {
53640- int seq = atomic_inc_return(&delayed_root->items_seq);
53641+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53642 if ((atomic_dec_return(&delayed_root->items) <
53643 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53644 waitqueue_active(&delayed_root->wait))
53645@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53646 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53647 int seq, int count)
53648 {
53649- int val = atomic_read(&delayed_root->items_seq);
53650+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53651
53652 if (val < seq || val >= seq + count)
53653 return 1;
53654@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53655 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53656 return;
53657
53658- seq = atomic_read(&delayed_root->items_seq);
53659+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53660
53661 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53662 int ret;
53663diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53664index a4b38f9..f86a509 100644
53665--- a/fs/btrfs/delayed-inode.h
53666+++ b/fs/btrfs/delayed-inode.h
53667@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53668 */
53669 struct list_head prepare_list;
53670 atomic_t items; /* for delayed items */
53671- atomic_t items_seq; /* for delayed items */
53672+ atomic_unchecked_t items_seq; /* for delayed items */
53673 int nodes; /* for delayed nodes */
53674 wait_queue_head_t wait;
53675 };
53676@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53677 struct btrfs_delayed_root *delayed_root)
53678 {
53679 atomic_set(&delayed_root->items, 0);
53680- atomic_set(&delayed_root->items_seq, 0);
53681+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53682 delayed_root->nodes = 0;
53683 spin_lock_init(&delayed_root->lock);
53684 init_waitqueue_head(&delayed_root->wait);
53685diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53686index 238a055..1e33cd5 100644
53687--- a/fs/btrfs/ioctl.c
53688+++ b/fs/btrfs/ioctl.c
53689@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53690 for (i = 0; i < num_types; i++) {
53691 struct btrfs_space_info *tmp;
53692
53693+ /* Don't copy in more than we allocated */
53694 if (!slot_count)
53695 break;
53696
53697+ slot_count--;
53698+
53699 info = NULL;
53700 rcu_read_lock();
53701 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53702@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53703 memcpy(dest, &space, sizeof(space));
53704 dest++;
53705 space_args.total_spaces++;
53706- slot_count--;
53707 }
53708- if (!slot_count)
53709- break;
53710 }
53711 up_read(&info->groups_sem);
53712 }
53713diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53714index 8eb6191..eda91e2 100644
53715--- a/fs/btrfs/super.c
53716+++ b/fs/btrfs/super.c
53717@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53718 function, line, errstr);
53719 return;
53720 }
53721- ACCESS_ONCE(trans->transaction->aborted) = errno;
53722+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53723 /* Wake up anybody who may be waiting on this transaction */
53724 wake_up(&root->fs_info->transaction_wait);
53725 wake_up(&root->fs_info->transaction_blocked_wait);
53726diff --git a/fs/buffer.c b/fs/buffer.c
53727index 4d74335..b0df7f9 100644
53728--- a/fs/buffer.c
53729+++ b/fs/buffer.c
53730@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53731 bh_cachep = kmem_cache_create("buffer_head",
53732 sizeof(struct buffer_head), 0,
53733 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53734- SLAB_MEM_SPREAD),
53735+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53736 NULL);
53737
53738 /*
53739diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53740index 622f469..e8d2d55 100644
53741--- a/fs/cachefiles/bind.c
53742+++ b/fs/cachefiles/bind.c
53743@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53744 args);
53745
53746 /* start by checking things over */
53747- ASSERT(cache->fstop_percent >= 0 &&
53748- cache->fstop_percent < cache->fcull_percent &&
53749+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53750 cache->fcull_percent < cache->frun_percent &&
53751 cache->frun_percent < 100);
53752
53753- ASSERT(cache->bstop_percent >= 0 &&
53754- cache->bstop_percent < cache->bcull_percent &&
53755+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53756 cache->bcull_percent < cache->brun_percent &&
53757 cache->brun_percent < 100);
53758
53759diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53760index 0a1467b..6a53245 100644
53761--- a/fs/cachefiles/daemon.c
53762+++ b/fs/cachefiles/daemon.c
53763@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53764 if (n > buflen)
53765 return -EMSGSIZE;
53766
53767- if (copy_to_user(_buffer, buffer, n) != 0)
53768+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53769 return -EFAULT;
53770
53771 return n;
53772@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53773 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53774 return -EIO;
53775
53776- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53777+ if (datalen > PAGE_SIZE - 1)
53778 return -EOPNOTSUPP;
53779
53780 /* drag the command string into the kernel so we can parse it */
53781@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53782 if (args[0] != '%' || args[1] != '\0')
53783 return -EINVAL;
53784
53785- if (fstop < 0 || fstop >= cache->fcull_percent)
53786+ if (fstop >= cache->fcull_percent)
53787 return cachefiles_daemon_range_error(cache, args);
53788
53789 cache->fstop_percent = fstop;
53790@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53791 if (args[0] != '%' || args[1] != '\0')
53792 return -EINVAL;
53793
53794- if (bstop < 0 || bstop >= cache->bcull_percent)
53795+ if (bstop >= cache->bcull_percent)
53796 return cachefiles_daemon_range_error(cache, args);
53797
53798 cache->bstop_percent = bstop;
53799diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53800index 4938251..7e01445 100644
53801--- a/fs/cachefiles/internal.h
53802+++ b/fs/cachefiles/internal.h
53803@@ -59,7 +59,7 @@ struct cachefiles_cache {
53804 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53805 struct rb_root active_nodes; /* active nodes (can't be culled) */
53806 rwlock_t active_lock; /* lock for active_nodes */
53807- atomic_t gravecounter; /* graveyard uniquifier */
53808+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53809 unsigned frun_percent; /* when to stop culling (% files) */
53810 unsigned fcull_percent; /* when to start culling (% files) */
53811 unsigned fstop_percent; /* when to stop allocating (% files) */
53812@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53813 * proc.c
53814 */
53815 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53816-extern atomic_t cachefiles_lookup_histogram[HZ];
53817-extern atomic_t cachefiles_mkdir_histogram[HZ];
53818-extern atomic_t cachefiles_create_histogram[HZ];
53819+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53820+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53821+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53822
53823 extern int __init cachefiles_proc_init(void);
53824 extern void cachefiles_proc_cleanup(void);
53825 static inline
53826-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53827+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53828 {
53829 unsigned long jif = jiffies - start_jif;
53830 if (jif >= HZ)
53831 jif = HZ - 1;
53832- atomic_inc(&histogram[jif]);
53833+ atomic_inc_unchecked(&histogram[jif]);
53834 }
53835
53836 #else
53837diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53838index 25badd1..d70d918 100644
53839--- a/fs/cachefiles/namei.c
53840+++ b/fs/cachefiles/namei.c
53841@@ -317,7 +317,7 @@ try_again:
53842 /* first step is to make up a grave dentry in the graveyard */
53843 sprintf(nbuffer, "%08x%08x",
53844 (uint32_t) get_seconds(),
53845- (uint32_t) atomic_inc_return(&cache->gravecounter));
53846+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53847
53848 /* do the multiway lock magic */
53849 trap = lock_rename(cache->graveyard, dir);
53850diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53851index eccd339..4c1d995 100644
53852--- a/fs/cachefiles/proc.c
53853+++ b/fs/cachefiles/proc.c
53854@@ -14,9 +14,9 @@
53855 #include <linux/seq_file.h>
53856 #include "internal.h"
53857
53858-atomic_t cachefiles_lookup_histogram[HZ];
53859-atomic_t cachefiles_mkdir_histogram[HZ];
53860-atomic_t cachefiles_create_histogram[HZ];
53861+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53862+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53863+atomic_unchecked_t cachefiles_create_histogram[HZ];
53864
53865 /*
53866 * display the latency histogram
53867@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53868 return 0;
53869 default:
53870 index = (unsigned long) v - 3;
53871- x = atomic_read(&cachefiles_lookup_histogram[index]);
53872- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53873- z = atomic_read(&cachefiles_create_histogram[index]);
53874+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53875+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53876+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53877 if (x == 0 && y == 0 && z == 0)
53878 return 0;
53879
53880diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53881index ebaff36..7e3ea26 100644
53882--- a/fs/cachefiles/rdwr.c
53883+++ b/fs/cachefiles/rdwr.c
53884@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53885 old_fs = get_fs();
53886 set_fs(KERNEL_DS);
53887 ret = file->f_op->write(
53888- file, (const void __user *) data, len, &pos);
53889+ file, (const void __force_user *) data, len, &pos);
53890 set_fs(old_fs);
53891 kunmap(page);
53892 file_end_write(file);
53893diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53894index a40ceda..f43d17c 100644
53895--- a/fs/ceph/dir.c
53896+++ b/fs/ceph/dir.c
53897@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53898 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53899 struct ceph_mds_client *mdsc = fsc->mdsc;
53900 unsigned frag = fpos_frag(ctx->pos);
53901- int off = fpos_off(ctx->pos);
53902+ unsigned int off = fpos_off(ctx->pos);
53903 int err;
53904 u32 ftype;
53905 struct ceph_mds_reply_info_parsed *rinfo;
53906diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53907index 6627b26..634ec4b 100644
53908--- a/fs/ceph/super.c
53909+++ b/fs/ceph/super.c
53910@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53911 /*
53912 * construct our own bdi so we can control readahead, etc.
53913 */
53914-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53915+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53916
53917 static int ceph_register_bdi(struct super_block *sb,
53918 struct ceph_fs_client *fsc)
53919@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53920 default_backing_dev_info.ra_pages;
53921
53922 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53923- atomic_long_inc_return(&bdi_seq));
53924+ atomic_long_inc_return_unchecked(&bdi_seq));
53925 if (!err)
53926 sb->s_bdi = &fsc->backing_dev_info;
53927 return err;
53928diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53929index f3ac415..3d2420c 100644
53930--- a/fs/cifs/cifs_debug.c
53931+++ b/fs/cifs/cifs_debug.c
53932@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53933
53934 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53935 #ifdef CONFIG_CIFS_STATS2
53936- atomic_set(&totBufAllocCount, 0);
53937- atomic_set(&totSmBufAllocCount, 0);
53938+ atomic_set_unchecked(&totBufAllocCount, 0);
53939+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53940 #endif /* CONFIG_CIFS_STATS2 */
53941 spin_lock(&cifs_tcp_ses_lock);
53942 list_for_each(tmp1, &cifs_tcp_ses_list) {
53943@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53944 tcon = list_entry(tmp3,
53945 struct cifs_tcon,
53946 tcon_list);
53947- atomic_set(&tcon->num_smbs_sent, 0);
53948+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53949 if (server->ops->clear_stats)
53950 server->ops->clear_stats(tcon);
53951 }
53952@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53953 smBufAllocCount.counter, cifs_min_small);
53954 #ifdef CONFIG_CIFS_STATS2
53955 seq_printf(m, "Total Large %d Small %d Allocations\n",
53956- atomic_read(&totBufAllocCount),
53957- atomic_read(&totSmBufAllocCount));
53958+ atomic_read_unchecked(&totBufAllocCount),
53959+ atomic_read_unchecked(&totSmBufAllocCount));
53960 #endif /* CONFIG_CIFS_STATS2 */
53961
53962 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53963@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53964 if (tcon->need_reconnect)
53965 seq_puts(m, "\tDISCONNECTED ");
53966 seq_printf(m, "\nSMBs: %d",
53967- atomic_read(&tcon->num_smbs_sent));
53968+ atomic_read_unchecked(&tcon->num_smbs_sent));
53969 if (server->ops->print_stats)
53970 server->ops->print_stats(m, tcon);
53971 }
53972diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53973index 85ea98d..b3ed4d6 100644
53974--- a/fs/cifs/cifsfs.c
53975+++ b/fs/cifs/cifsfs.c
53976@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53977 */
53978 cifs_req_cachep = kmem_cache_create("cifs_request",
53979 CIFSMaxBufSize + max_hdr_size, 0,
53980- SLAB_HWCACHE_ALIGN, NULL);
53981+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53982 if (cifs_req_cachep == NULL)
53983 return -ENOMEM;
53984
53985@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53986 efficient to alloc 1 per page off the slab compared to 17K (5page)
53987 alloc of large cifs buffers even when page debugging is on */
53988 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53989- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53990+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53991 NULL);
53992 if (cifs_sm_req_cachep == NULL) {
53993 mempool_destroy(cifs_req_poolp);
53994@@ -1149,8 +1149,8 @@ init_cifs(void)
53995 atomic_set(&bufAllocCount, 0);
53996 atomic_set(&smBufAllocCount, 0);
53997 #ifdef CONFIG_CIFS_STATS2
53998- atomic_set(&totBufAllocCount, 0);
53999- atomic_set(&totSmBufAllocCount, 0);
54000+ atomic_set_unchecked(&totBufAllocCount, 0);
54001+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54002 #endif /* CONFIG_CIFS_STATS2 */
54003
54004 atomic_set(&midCount, 0);
54005diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54006index 52ca861..47f309c 100644
54007--- a/fs/cifs/cifsglob.h
54008+++ b/fs/cifs/cifsglob.h
54009@@ -756,35 +756,35 @@ struct cifs_tcon {
54010 __u16 Flags; /* optional support bits */
54011 enum statusEnum tidStatus;
54012 #ifdef CONFIG_CIFS_STATS
54013- atomic_t num_smbs_sent;
54014+ atomic_unchecked_t num_smbs_sent;
54015 union {
54016 struct {
54017- atomic_t num_writes;
54018- atomic_t num_reads;
54019- atomic_t num_flushes;
54020- atomic_t num_oplock_brks;
54021- atomic_t num_opens;
54022- atomic_t num_closes;
54023- atomic_t num_deletes;
54024- atomic_t num_mkdirs;
54025- atomic_t num_posixopens;
54026- atomic_t num_posixmkdirs;
54027- atomic_t num_rmdirs;
54028- atomic_t num_renames;
54029- atomic_t num_t2renames;
54030- atomic_t num_ffirst;
54031- atomic_t num_fnext;
54032- atomic_t num_fclose;
54033- atomic_t num_hardlinks;
54034- atomic_t num_symlinks;
54035- atomic_t num_locks;
54036- atomic_t num_acl_get;
54037- atomic_t num_acl_set;
54038+ atomic_unchecked_t num_writes;
54039+ atomic_unchecked_t num_reads;
54040+ atomic_unchecked_t num_flushes;
54041+ atomic_unchecked_t num_oplock_brks;
54042+ atomic_unchecked_t num_opens;
54043+ atomic_unchecked_t num_closes;
54044+ atomic_unchecked_t num_deletes;
54045+ atomic_unchecked_t num_mkdirs;
54046+ atomic_unchecked_t num_posixopens;
54047+ atomic_unchecked_t num_posixmkdirs;
54048+ atomic_unchecked_t num_rmdirs;
54049+ atomic_unchecked_t num_renames;
54050+ atomic_unchecked_t num_t2renames;
54051+ atomic_unchecked_t num_ffirst;
54052+ atomic_unchecked_t num_fnext;
54053+ atomic_unchecked_t num_fclose;
54054+ atomic_unchecked_t num_hardlinks;
54055+ atomic_unchecked_t num_symlinks;
54056+ atomic_unchecked_t num_locks;
54057+ atomic_unchecked_t num_acl_get;
54058+ atomic_unchecked_t num_acl_set;
54059 } cifs_stats;
54060 #ifdef CONFIG_CIFS_SMB2
54061 struct {
54062- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54063- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54064+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54065+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54066 } smb2_stats;
54067 #endif /* CONFIG_CIFS_SMB2 */
54068 } stats;
54069@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
54070 }
54071
54072 #ifdef CONFIG_CIFS_STATS
54073-#define cifs_stats_inc atomic_inc
54074+#define cifs_stats_inc atomic_inc_unchecked
54075
54076 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54077 unsigned int bytes)
54078@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54079 /* Various Debug counters */
54080 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54081 #ifdef CONFIG_CIFS_STATS2
54082-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54083-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54084+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54085+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54086 #endif
54087 GLOBAL_EXTERN atomic_t smBufAllocCount;
54088 GLOBAL_EXTERN atomic_t midCount;
54089diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54090index 562044f..4af6a17 100644
54091--- a/fs/cifs/link.c
54092+++ b/fs/cifs/link.c
54093@@ -638,7 +638,7 @@ symlink_exit:
54094
54095 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54096 {
54097- char *p = nd_get_link(nd);
54098+ const char *p = nd_get_link(nd);
54099 if (!IS_ERR(p))
54100 kfree(p);
54101 }
54102diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54103index f7d4b22..1254377 100644
54104--- a/fs/cifs/misc.c
54105+++ b/fs/cifs/misc.c
54106@@ -169,7 +169,7 @@ cifs_buf_get(void)
54107 memset(ret_buf, 0, buf_size + 3);
54108 atomic_inc(&bufAllocCount);
54109 #ifdef CONFIG_CIFS_STATS2
54110- atomic_inc(&totBufAllocCount);
54111+ atomic_inc_unchecked(&totBufAllocCount);
54112 #endif /* CONFIG_CIFS_STATS2 */
54113 }
54114
54115@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
54116 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54117 atomic_inc(&smBufAllocCount);
54118 #ifdef CONFIG_CIFS_STATS2
54119- atomic_inc(&totSmBufAllocCount);
54120+ atomic_inc_unchecked(&totSmBufAllocCount);
54121 #endif /* CONFIG_CIFS_STATS2 */
54122
54123 }
54124diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54125index 6094397..51e576f 100644
54126--- a/fs/cifs/smb1ops.c
54127+++ b/fs/cifs/smb1ops.c
54128@@ -590,27 +590,27 @@ static void
54129 cifs_clear_stats(struct cifs_tcon *tcon)
54130 {
54131 #ifdef CONFIG_CIFS_STATS
54132- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54133- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54134- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54135- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54136- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54137- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54138- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54139- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54140- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54141- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54142- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54143- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54144- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54145- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54146- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54147- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54148- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54149- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54150- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54151- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54152- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54153+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54154+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54155+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54156+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54157+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54158+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54159+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54160+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54161+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54162+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54163+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54164+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54165+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54166+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54167+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54168+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54169+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54170+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54171+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54172+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54173+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54174 #endif
54175 }
54176
54177@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54178 {
54179 #ifdef CONFIG_CIFS_STATS
54180 seq_printf(m, " Oplocks breaks: %d",
54181- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54182+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54183 seq_printf(m, "\nReads: %d Bytes: %llu",
54184- atomic_read(&tcon->stats.cifs_stats.num_reads),
54185+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54186 (long long)(tcon->bytes_read));
54187 seq_printf(m, "\nWrites: %d Bytes: %llu",
54188- atomic_read(&tcon->stats.cifs_stats.num_writes),
54189+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54190 (long long)(tcon->bytes_written));
54191 seq_printf(m, "\nFlushes: %d",
54192- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54193+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54194 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54195- atomic_read(&tcon->stats.cifs_stats.num_locks),
54196- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54197- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54198+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54199+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54200+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54201 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54202- atomic_read(&tcon->stats.cifs_stats.num_opens),
54203- atomic_read(&tcon->stats.cifs_stats.num_closes),
54204- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54205+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54206+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54207+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54208 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54209- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54210- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54211+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54212+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54213 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54214- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54215- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54216+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54217+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54218 seq_printf(m, "\nRenames: %d T2 Renames %d",
54219- atomic_read(&tcon->stats.cifs_stats.num_renames),
54220- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54221+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54222+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54223 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54224- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54225- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54226- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54227+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54228+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54229+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54230 #endif
54231 }
54232
54233diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54234index f259e6c..ca948ff 100644
54235--- a/fs/cifs/smb2ops.c
54236+++ b/fs/cifs/smb2ops.c
54237@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54238 #ifdef CONFIG_CIFS_STATS
54239 int i;
54240 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54241- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54242- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54243+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54244+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54245 }
54246 #endif
54247 }
54248@@ -310,65 +310,65 @@ static void
54249 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54250 {
54251 #ifdef CONFIG_CIFS_STATS
54252- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54253- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54254+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54255+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54256 seq_printf(m, "\nNegotiates: %d sent %d failed",
54257- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54258- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54259+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54260+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54261 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54262- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54263- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54264+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54265+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54266 seq_printf(m, "\nLogoffs: %d sent %d failed",
54267- atomic_read(&sent[SMB2_LOGOFF_HE]),
54268- atomic_read(&failed[SMB2_LOGOFF_HE]));
54269+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54270+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54271 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54272- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54273- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54274+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54275+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54276 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54277- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54278- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54279+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54280+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54281 seq_printf(m, "\nCreates: %d sent %d failed",
54282- atomic_read(&sent[SMB2_CREATE_HE]),
54283- atomic_read(&failed[SMB2_CREATE_HE]));
54284+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54285+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54286 seq_printf(m, "\nCloses: %d sent %d failed",
54287- atomic_read(&sent[SMB2_CLOSE_HE]),
54288- atomic_read(&failed[SMB2_CLOSE_HE]));
54289+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54290+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54291 seq_printf(m, "\nFlushes: %d sent %d failed",
54292- atomic_read(&sent[SMB2_FLUSH_HE]),
54293- atomic_read(&failed[SMB2_FLUSH_HE]));
54294+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54295+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54296 seq_printf(m, "\nReads: %d sent %d failed",
54297- atomic_read(&sent[SMB2_READ_HE]),
54298- atomic_read(&failed[SMB2_READ_HE]));
54299+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54300+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54301 seq_printf(m, "\nWrites: %d sent %d failed",
54302- atomic_read(&sent[SMB2_WRITE_HE]),
54303- atomic_read(&failed[SMB2_WRITE_HE]));
54304+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54305+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54306 seq_printf(m, "\nLocks: %d sent %d failed",
54307- atomic_read(&sent[SMB2_LOCK_HE]),
54308- atomic_read(&failed[SMB2_LOCK_HE]));
54309+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54310+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54311 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54312- atomic_read(&sent[SMB2_IOCTL_HE]),
54313- atomic_read(&failed[SMB2_IOCTL_HE]));
54314+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54315+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54316 seq_printf(m, "\nCancels: %d sent %d failed",
54317- atomic_read(&sent[SMB2_CANCEL_HE]),
54318- atomic_read(&failed[SMB2_CANCEL_HE]));
54319+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54320+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54321 seq_printf(m, "\nEchos: %d sent %d failed",
54322- atomic_read(&sent[SMB2_ECHO_HE]),
54323- atomic_read(&failed[SMB2_ECHO_HE]));
54324+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54325+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54326 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54327- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54328- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54329+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54330+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54331 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54332- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54333- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54334+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54335+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54336 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54337- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54338- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54339+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54340+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54341 seq_printf(m, "\nSetInfos: %d sent %d failed",
54342- atomic_read(&sent[SMB2_SET_INFO_HE]),
54343- atomic_read(&failed[SMB2_SET_INFO_HE]));
54344+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54345+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54346 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54347- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54348- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54349+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54350+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54351 #endif
54352 }
54353
54354diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54355index abc9c28..3fdae28 100644
54356--- a/fs/cifs/smb2pdu.c
54357+++ b/fs/cifs/smb2pdu.c
54358@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54359 default:
54360 cifs_dbg(VFS, "info level %u isn't supported\n",
54361 srch_inf->info_level);
54362- rc = -EINVAL;
54363- goto qdir_exit;
54364+ return -EINVAL;
54365 }
54366
54367 req->FileIndex = cpu_to_le32(index);
54368diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54369index 1da168c..8bc7ff6 100644
54370--- a/fs/coda/cache.c
54371+++ b/fs/coda/cache.c
54372@@ -24,7 +24,7 @@
54373 #include "coda_linux.h"
54374 #include "coda_cache.h"
54375
54376-static atomic_t permission_epoch = ATOMIC_INIT(0);
54377+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54378
54379 /* replace or extend an acl cache hit */
54380 void coda_cache_enter(struct inode *inode, int mask)
54381@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54382 struct coda_inode_info *cii = ITOC(inode);
54383
54384 spin_lock(&cii->c_lock);
54385- cii->c_cached_epoch = atomic_read(&permission_epoch);
54386+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54387 if (!uid_eq(cii->c_uid, current_fsuid())) {
54388 cii->c_uid = current_fsuid();
54389 cii->c_cached_perm = mask;
54390@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54391 {
54392 struct coda_inode_info *cii = ITOC(inode);
54393 spin_lock(&cii->c_lock);
54394- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54395+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54396 spin_unlock(&cii->c_lock);
54397 }
54398
54399 /* remove all acl caches */
54400 void coda_cache_clear_all(struct super_block *sb)
54401 {
54402- atomic_inc(&permission_epoch);
54403+ atomic_inc_unchecked(&permission_epoch);
54404 }
54405
54406
54407@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54408 spin_lock(&cii->c_lock);
54409 hit = (mask & cii->c_cached_perm) == mask &&
54410 uid_eq(cii->c_uid, current_fsuid()) &&
54411- cii->c_cached_epoch == atomic_read(&permission_epoch);
54412+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54413 spin_unlock(&cii->c_lock);
54414
54415 return hit;
54416diff --git a/fs/compat.c b/fs/compat.c
54417index 6af20de..fec3fbb 100644
54418--- a/fs/compat.c
54419+++ b/fs/compat.c
54420@@ -54,7 +54,7 @@
54421 #include <asm/ioctls.h>
54422 #include "internal.h"
54423
54424-int compat_log = 1;
54425+int compat_log = 0;
54426
54427 int compat_printk(const char *fmt, ...)
54428 {
54429@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54430
54431 set_fs(KERNEL_DS);
54432 /* The __user pointer cast is valid because of the set_fs() */
54433- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54434+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54435 set_fs(oldfs);
54436 /* truncating is ok because it's a user address */
54437 if (!ret)
54438@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54439 goto out;
54440
54441 ret = -EINVAL;
54442- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54443+ if (nr_segs > UIO_MAXIOV)
54444 goto out;
54445 if (nr_segs > fast_segs) {
54446 ret = -ENOMEM;
54447@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54448 struct compat_readdir_callback {
54449 struct dir_context ctx;
54450 struct compat_old_linux_dirent __user *dirent;
54451+ struct file * file;
54452 int result;
54453 };
54454
54455@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54456 buf->result = -EOVERFLOW;
54457 return -EOVERFLOW;
54458 }
54459+
54460+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54461+ return 0;
54462+
54463 buf->result++;
54464 dirent = buf->dirent;
54465 if (!access_ok(VERIFY_WRITE, dirent,
54466@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54467 if (!f.file)
54468 return -EBADF;
54469
54470+ buf.file = f.file;
54471 error = iterate_dir(f.file, &buf.ctx);
54472 if (buf.result)
54473 error = buf.result;
54474@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54475 struct dir_context ctx;
54476 struct compat_linux_dirent __user *current_dir;
54477 struct compat_linux_dirent __user *previous;
54478+ struct file * file;
54479 int count;
54480 int error;
54481 };
54482@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54483 buf->error = -EOVERFLOW;
54484 return -EOVERFLOW;
54485 }
54486+
54487+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54488+ return 0;
54489+
54490 dirent = buf->previous;
54491 if (dirent) {
54492 if (__put_user(offset, &dirent->d_off))
54493@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54494 if (!f.file)
54495 return -EBADF;
54496
54497+ buf.file = f.file;
54498 error = iterate_dir(f.file, &buf.ctx);
54499 if (error >= 0)
54500 error = buf.error;
54501@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54502 struct dir_context ctx;
54503 struct linux_dirent64 __user *current_dir;
54504 struct linux_dirent64 __user *previous;
54505+ struct file * file;
54506 int count;
54507 int error;
54508 };
54509@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54510 buf->error = -EINVAL; /* only used if we fail.. */
54511 if (reclen > buf->count)
54512 return -EINVAL;
54513+
54514+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54515+ return 0;
54516+
54517 dirent = buf->previous;
54518
54519 if (dirent) {
54520@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54521 if (!f.file)
54522 return -EBADF;
54523
54524+ buf.file = f.file;
54525 error = iterate_dir(f.file, &buf.ctx);
54526 if (error >= 0)
54527 error = buf.error;
54528diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54529index a81147e..20bf2b5 100644
54530--- a/fs/compat_binfmt_elf.c
54531+++ b/fs/compat_binfmt_elf.c
54532@@ -30,11 +30,13 @@
54533 #undef elf_phdr
54534 #undef elf_shdr
54535 #undef elf_note
54536+#undef elf_dyn
54537 #undef elf_addr_t
54538 #define elfhdr elf32_hdr
54539 #define elf_phdr elf32_phdr
54540 #define elf_shdr elf32_shdr
54541 #define elf_note elf32_note
54542+#define elf_dyn Elf32_Dyn
54543 #define elf_addr_t Elf32_Addr
54544
54545 /*
54546diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54547index 5d19acf..9ab093b 100644
54548--- a/fs/compat_ioctl.c
54549+++ b/fs/compat_ioctl.c
54550@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54551 return -EFAULT;
54552 if (__get_user(udata, &ss32->iomem_base))
54553 return -EFAULT;
54554- ss.iomem_base = compat_ptr(udata);
54555+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54556 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54557 __get_user(ss.port_high, &ss32->port_high))
54558 return -EFAULT;
54559@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54560 for (i = 0; i < nmsgs; i++) {
54561 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54562 return -EFAULT;
54563- if (get_user(datap, &umsgs[i].buf) ||
54564- put_user(compat_ptr(datap), &tmsgs[i].buf))
54565+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54566+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54567 return -EFAULT;
54568 }
54569 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54570@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54571 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54572 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54573 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54574- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54575+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54576 return -EFAULT;
54577
54578 return ioctl_preallocate(file, p);
54579@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54580 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54581 {
54582 unsigned int a, b;
54583- a = *(unsigned int *)p;
54584- b = *(unsigned int *)q;
54585+ a = *(const unsigned int *)p;
54586+ b = *(const unsigned int *)q;
54587 if (a > b)
54588 return 1;
54589 if (a < b)
54590diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54591index 277bd1b..f312c9e 100644
54592--- a/fs/configfs/dir.c
54593+++ b/fs/configfs/dir.c
54594@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54595 }
54596 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54597 struct configfs_dirent *next;
54598- const char *name;
54599+ const unsigned char * name;
54600+ char d_name[sizeof(next->s_dentry->d_iname)];
54601 int len;
54602 struct inode *inode = NULL;
54603
54604@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54605 continue;
54606
54607 name = configfs_get_name(next);
54608- len = strlen(name);
54609+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54610+ len = next->s_dentry->d_name.len;
54611+ memcpy(d_name, name, len);
54612+ name = d_name;
54613+ } else
54614+ len = strlen(name);
54615
54616 /*
54617 * We'll have a dentry and an inode for
54618diff --git a/fs/coredump.c b/fs/coredump.c
54619index 72f816d..1ba8eff 100644
54620--- a/fs/coredump.c
54621+++ b/fs/coredump.c
54622@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54623 struct pipe_inode_info *pipe = file->private_data;
54624
54625 pipe_lock(pipe);
54626- pipe->readers++;
54627- pipe->writers--;
54628+ atomic_inc(&pipe->readers);
54629+ atomic_dec(&pipe->writers);
54630 wake_up_interruptible_sync(&pipe->wait);
54631 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54632 pipe_unlock(pipe);
54633@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54634 * We actually want wait_event_freezable() but then we need
54635 * to clear TIF_SIGPENDING and improve dump_interrupted().
54636 */
54637- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54638+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54639
54640 pipe_lock(pipe);
54641- pipe->readers--;
54642- pipe->writers++;
54643+ atomic_dec(&pipe->readers);
54644+ atomic_inc(&pipe->writers);
54645 pipe_unlock(pipe);
54646 }
54647
54648@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54649 struct files_struct *displaced;
54650 bool need_nonrelative = false;
54651 bool core_dumped = false;
54652- static atomic_t core_dump_count = ATOMIC_INIT(0);
54653+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54654+ long signr = siginfo->si_signo;
54655 struct coredump_params cprm = {
54656 .siginfo = siginfo,
54657 .regs = signal_pt_regs(),
54658@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54659 .mm_flags = mm->flags,
54660 };
54661
54662- audit_core_dumps(siginfo->si_signo);
54663+ audit_core_dumps(signr);
54664+
54665+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54666+ gr_handle_brute_attach(cprm.mm_flags);
54667
54668 binfmt = mm->binfmt;
54669 if (!binfmt || !binfmt->core_dump)
54670@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54671 need_nonrelative = true;
54672 }
54673
54674- retval = coredump_wait(siginfo->si_signo, &core_state);
54675+ retval = coredump_wait(signr, &core_state);
54676 if (retval < 0)
54677 goto fail_creds;
54678
54679@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54680 }
54681 cprm.limit = RLIM_INFINITY;
54682
54683- dump_count = atomic_inc_return(&core_dump_count);
54684+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54685 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54686 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54687 task_tgid_vnr(current), current->comm);
54688@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54689 } else {
54690 struct inode *inode;
54691
54692+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54693+
54694 if (cprm.limit < binfmt->min_coredump)
54695 goto fail_unlock;
54696
54697@@ -664,7 +670,7 @@ close_fail:
54698 filp_close(cprm.file, NULL);
54699 fail_dropcount:
54700 if (ispipe)
54701- atomic_dec(&core_dump_count);
54702+ atomic_dec_unchecked(&core_dump_count);
54703 fail_unlock:
54704 kfree(cn.corename);
54705 coredump_finish(mm, core_dumped);
54706@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54707 {
54708 return !dump_interrupted() &&
54709 access_ok(VERIFY_READ, addr, nr) &&
54710- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54711+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54712 }
54713 EXPORT_SYMBOL(dump_write);
54714
54715diff --git a/fs/dcache.c b/fs/dcache.c
54716index b949af8..5978926 100644
54717--- a/fs/dcache.c
54718+++ b/fs/dcache.c
54719@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54720 mempages -= reserve;
54721
54722 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54723- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54724+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54725+ SLAB_NO_SANITIZE, NULL);
54726
54727 dcache_init();
54728 inode_init();
54729diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54730index c7c83ff..bda9461 100644
54731--- a/fs/debugfs/inode.c
54732+++ b/fs/debugfs/inode.c
54733@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54734 */
54735 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54736 {
54737+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54738+ return __create_file(name, S_IFDIR | S_IRWXU,
54739+#else
54740 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54741+#endif
54742 parent, NULL, NULL);
54743 }
54744 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54745diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54746index 67e9b63..a9adb68 100644
54747--- a/fs/ecryptfs/inode.c
54748+++ b/fs/ecryptfs/inode.c
54749@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54750 old_fs = get_fs();
54751 set_fs(get_ds());
54752 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54753- (char __user *)lower_buf,
54754+ (char __force_user *)lower_buf,
54755 PATH_MAX);
54756 set_fs(old_fs);
54757 if (rc < 0)
54758@@ -706,7 +706,7 @@ out:
54759 static void
54760 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54761 {
54762- char *buf = nd_get_link(nd);
54763+ const char *buf = nd_get_link(nd);
54764 if (!IS_ERR(buf)) {
54765 /* Free the char* */
54766 kfree(buf);
54767diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54768index e4141f2..d8263e8 100644
54769--- a/fs/ecryptfs/miscdev.c
54770+++ b/fs/ecryptfs/miscdev.c
54771@@ -304,7 +304,7 @@ check_list:
54772 goto out_unlock_msg_ctx;
54773 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54774 if (msg_ctx->msg) {
54775- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54776+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54777 goto out_unlock_msg_ctx;
54778 i += packet_length_size;
54779 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54780diff --git a/fs/exec.c b/fs/exec.c
54781index fd774c7..1c6a7bf 100644
54782--- a/fs/exec.c
54783+++ b/fs/exec.c
54784@@ -55,8 +55,20 @@
54785 #include <linux/pipe_fs_i.h>
54786 #include <linux/oom.h>
54787 #include <linux/compat.h>
54788+#include <linux/random.h>
54789+#include <linux/seq_file.h>
54790+#include <linux/coredump.h>
54791+#include <linux/mman.h>
54792+
54793+#ifdef CONFIG_PAX_REFCOUNT
54794+#include <linux/kallsyms.h>
54795+#include <linux/kdebug.h>
54796+#endif
54797+
54798+#include <trace/events/fs.h>
54799
54800 #include <asm/uaccess.h>
54801+#include <asm/sections.h>
54802 #include <asm/mmu_context.h>
54803 #include <asm/tlb.h>
54804
54805@@ -66,17 +78,32 @@
54806
54807 #include <trace/events/sched.h>
54808
54809+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54810+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54811+{
54812+ 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");
54813+}
54814+#endif
54815+
54816+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54817+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54818+EXPORT_SYMBOL(pax_set_initial_flags_func);
54819+#endif
54820+
54821 int suid_dumpable = 0;
54822
54823 static LIST_HEAD(formats);
54824 static DEFINE_RWLOCK(binfmt_lock);
54825
54826+extern int gr_process_kernel_exec_ban(void);
54827+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54828+
54829 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54830 {
54831 BUG_ON(!fmt);
54832 write_lock(&binfmt_lock);
54833- insert ? list_add(&fmt->lh, &formats) :
54834- list_add_tail(&fmt->lh, &formats);
54835+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54836+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54837 write_unlock(&binfmt_lock);
54838 }
54839
54840@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54841 void unregister_binfmt(struct linux_binfmt * fmt)
54842 {
54843 write_lock(&binfmt_lock);
54844- list_del(&fmt->lh);
54845+ pax_list_del((struct list_head *)&fmt->lh);
54846 write_unlock(&binfmt_lock);
54847 }
54848
54849@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54850 int write)
54851 {
54852 struct page *page;
54853- int ret;
54854
54855-#ifdef CONFIG_STACK_GROWSUP
54856- if (write) {
54857- ret = expand_downwards(bprm->vma, pos);
54858- if (ret < 0)
54859- return NULL;
54860- }
54861-#endif
54862- ret = get_user_pages(current, bprm->mm, pos,
54863- 1, write, 1, &page, NULL);
54864- if (ret <= 0)
54865+ if (0 > expand_downwards(bprm->vma, pos))
54866+ return NULL;
54867+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54868 return NULL;
54869
54870 if (write) {
54871@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54872 if (size <= ARG_MAX)
54873 return page;
54874
54875+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54876+ // only allow 512KB for argv+env on suid/sgid binaries
54877+ // to prevent easy ASLR exhaustion
54878+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54879+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54880+ (size > (512 * 1024))) {
54881+ put_page(page);
54882+ return NULL;
54883+ }
54884+#endif
54885+
54886 /*
54887 * Limit to 1/4-th the stack size for the argv+env strings.
54888 * This ensures that:
54889@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54890 vma->vm_end = STACK_TOP_MAX;
54891 vma->vm_start = vma->vm_end - PAGE_SIZE;
54892 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54893+
54894+#ifdef CONFIG_PAX_SEGMEXEC
54895+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54896+#endif
54897+
54898 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54899 INIT_LIST_HEAD(&vma->anon_vma_chain);
54900
54901@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54902 mm->stack_vm = mm->total_vm = 1;
54903 up_write(&mm->mmap_sem);
54904 bprm->p = vma->vm_end - sizeof(void *);
54905+
54906+#ifdef CONFIG_PAX_RANDUSTACK
54907+ if (randomize_va_space)
54908+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54909+#endif
54910+
54911 return 0;
54912 err:
54913 up_write(&mm->mmap_sem);
54914@@ -397,7 +438,7 @@ struct user_arg_ptr {
54915 } ptr;
54916 };
54917
54918-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54919+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54920 {
54921 const char __user *native;
54922
54923@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54924 compat_uptr_t compat;
54925
54926 if (get_user(compat, argv.ptr.compat + nr))
54927- return ERR_PTR(-EFAULT);
54928+ return (const char __force_user *)ERR_PTR(-EFAULT);
54929
54930 return compat_ptr(compat);
54931 }
54932 #endif
54933
54934 if (get_user(native, argv.ptr.native + nr))
54935- return ERR_PTR(-EFAULT);
54936+ return (const char __force_user *)ERR_PTR(-EFAULT);
54937
54938 return native;
54939 }
54940@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54941 if (!p)
54942 break;
54943
54944- if (IS_ERR(p))
54945+ if (IS_ERR((const char __force_kernel *)p))
54946 return -EFAULT;
54947
54948 if (i >= max)
54949@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54950
54951 ret = -EFAULT;
54952 str = get_user_arg_ptr(argv, argc);
54953- if (IS_ERR(str))
54954+ if (IS_ERR((const char __force_kernel *)str))
54955 goto out;
54956
54957 len = strnlen_user(str, MAX_ARG_STRLEN);
54958@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54959 int r;
54960 mm_segment_t oldfs = get_fs();
54961 struct user_arg_ptr argv = {
54962- .ptr.native = (const char __user *const __user *)__argv,
54963+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54964 };
54965
54966 set_fs(KERNEL_DS);
54967@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54968 unsigned long new_end = old_end - shift;
54969 struct mmu_gather tlb;
54970
54971- BUG_ON(new_start > new_end);
54972+ if (new_start >= new_end || new_start < mmap_min_addr)
54973+ return -ENOMEM;
54974
54975 /*
54976 * ensure there are no vmas between where we want to go
54977@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54978 if (vma != find_vma(mm, new_start))
54979 return -EFAULT;
54980
54981+#ifdef CONFIG_PAX_SEGMEXEC
54982+ BUG_ON(pax_find_mirror_vma(vma));
54983+#endif
54984+
54985 /*
54986 * cover the whole range: [new_start, old_end)
54987 */
54988@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54989 stack_top = arch_align_stack(stack_top);
54990 stack_top = PAGE_ALIGN(stack_top);
54991
54992- if (unlikely(stack_top < mmap_min_addr) ||
54993- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54994- return -ENOMEM;
54995-
54996 stack_shift = vma->vm_end - stack_top;
54997
54998 bprm->p -= stack_shift;
54999@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
55000 bprm->exec -= stack_shift;
55001
55002 down_write(&mm->mmap_sem);
55003+
55004+ /* Move stack pages down in memory. */
55005+ if (stack_shift) {
55006+ ret = shift_arg_pages(vma, stack_shift);
55007+ if (ret)
55008+ goto out_unlock;
55009+ }
55010+
55011 vm_flags = VM_STACK_FLAGS;
55012
55013+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55014+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55015+ vm_flags &= ~VM_EXEC;
55016+
55017+#ifdef CONFIG_PAX_MPROTECT
55018+ if (mm->pax_flags & MF_PAX_MPROTECT)
55019+ vm_flags &= ~VM_MAYEXEC;
55020+#endif
55021+
55022+ }
55023+#endif
55024+
55025 /*
55026 * Adjust stack execute permissions; explicitly enable for
55027 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55028@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55029 goto out_unlock;
55030 BUG_ON(prev != vma);
55031
55032- /* Move stack pages down in memory. */
55033- if (stack_shift) {
55034- ret = shift_arg_pages(vma, stack_shift);
55035- if (ret)
55036- goto out_unlock;
55037- }
55038-
55039 /* mprotect_fixup is overkill to remove the temporary stack flags */
55040 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55041
55042@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55043 #endif
55044 current->mm->start_stack = bprm->p;
55045 ret = expand_stack(vma, stack_base);
55046+
55047+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55048+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55049+ unsigned long size;
55050+ vm_flags_t vm_flags;
55051+
55052+ size = STACK_TOP - vma->vm_end;
55053+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55054+
55055+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55056+
55057+#ifdef CONFIG_X86
55058+ if (!ret) {
55059+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55060+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55061+ }
55062+#endif
55063+
55064+ }
55065+#endif
55066+
55067 if (ret)
55068 ret = -EFAULT;
55069
55070@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
55071
55072 fsnotify_open(file);
55073
55074+ trace_open_exec(name);
55075+
55076 err = deny_write_access(file);
55077 if (err)
55078 goto exit;
55079@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
55080 old_fs = get_fs();
55081 set_fs(get_ds());
55082 /* The cast to a user pointer is valid due to the set_fs() */
55083- result = vfs_read(file, (void __user *)addr, count, &pos);
55084+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55085 set_fs(old_fs);
55086 return result;
55087 }
55088@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55089 }
55090 rcu_read_unlock();
55091
55092- if (p->fs->users > n_fs) {
55093+ if (atomic_read(&p->fs->users) > n_fs) {
55094 bprm->unsafe |= LSM_UNSAFE_SHARE;
55095 } else {
55096 res = -EAGAIN;
55097@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
55098
55099 EXPORT_SYMBOL(search_binary_handler);
55100
55101+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55102+static DEFINE_PER_CPU(u64, exec_counter);
55103+static int __init init_exec_counters(void)
55104+{
55105+ unsigned int cpu;
55106+
55107+ for_each_possible_cpu(cpu) {
55108+ per_cpu(exec_counter, cpu) = (u64)cpu;
55109+ }
55110+
55111+ return 0;
55112+}
55113+early_initcall(init_exec_counters);
55114+static inline void increment_exec_counter(void)
55115+{
55116+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55117+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55118+}
55119+#else
55120+static inline void increment_exec_counter(void) {}
55121+#endif
55122+
55123+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55124+ struct user_arg_ptr argv);
55125+
55126 /*
55127 * sys_execve() executes a new program.
55128 */
55129@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
55130 struct user_arg_ptr argv,
55131 struct user_arg_ptr envp)
55132 {
55133+#ifdef CONFIG_GRKERNSEC
55134+ struct file *old_exec_file;
55135+ struct acl_subject_label *old_acl;
55136+ struct rlimit old_rlim[RLIM_NLIMITS];
55137+#endif
55138 struct linux_binprm *bprm;
55139 struct file *file;
55140 struct files_struct *displaced;
55141 bool clear_in_exec;
55142 int retval;
55143
55144+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
55145+
55146 /*
55147 * We move the actual failure in case of RLIMIT_NPROC excess from
55148 * set*uid() to execve() because too many poorly written programs
55149@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
55150 if (IS_ERR(file))
55151 goto out_unmark;
55152
55153+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55154+ retval = -EPERM;
55155+ goto out_file;
55156+ }
55157+
55158 sched_exec();
55159
55160 bprm->file = file;
55161 bprm->filename = filename;
55162 bprm->interp = filename;
55163
55164+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55165+ retval = -EACCES;
55166+ goto out_file;
55167+ }
55168+
55169 retval = bprm_mm_init(bprm);
55170 if (retval)
55171 goto out_file;
55172@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
55173 if (retval < 0)
55174 goto out;
55175
55176+#ifdef CONFIG_GRKERNSEC
55177+ old_acl = current->acl;
55178+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55179+ old_exec_file = current->exec_file;
55180+ get_file(file);
55181+ current->exec_file = file;
55182+#endif
55183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55184+ /* limit suid stack to 8MB
55185+ * we saved the old limits above and will restore them if this exec fails
55186+ */
55187+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55188+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55189+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55190+#endif
55191+
55192+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55193+ retval = -EPERM;
55194+ goto out_fail;
55195+ }
55196+
55197+ if (!gr_tpe_allow(file)) {
55198+ retval = -EACCES;
55199+ goto out_fail;
55200+ }
55201+
55202+ if (gr_check_crash_exec(file)) {
55203+ retval = -EACCES;
55204+ goto out_fail;
55205+ }
55206+
55207+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55208+ bprm->unsafe);
55209+ if (retval < 0)
55210+ goto out_fail;
55211+
55212 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55213 if (retval < 0)
55214- goto out;
55215+ goto out_fail;
55216
55217 bprm->exec = bprm->p;
55218 retval = copy_strings(bprm->envc, envp, bprm);
55219 if (retval < 0)
55220- goto out;
55221+ goto out_fail;
55222
55223 retval = copy_strings(bprm->argc, argv, bprm);
55224 if (retval < 0)
55225- goto out;
55226+ goto out_fail;
55227+
55228+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55229+
55230+ gr_handle_exec_args(bprm, argv);
55231
55232 retval = search_binary_handler(bprm);
55233 if (retval < 0)
55234- goto out;
55235+ goto out_fail;
55236+#ifdef CONFIG_GRKERNSEC
55237+ if (old_exec_file)
55238+ fput(old_exec_file);
55239+#endif
55240
55241 /* execve succeeded */
55242+
55243+ increment_exec_counter();
55244 current->fs->in_exec = 0;
55245 current->in_execve = 0;
55246 acct_update_integrals(current);
55247@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55248 put_files_struct(displaced);
55249 return retval;
55250
55251+out_fail:
55252+#ifdef CONFIG_GRKERNSEC
55253+ current->acl = old_acl;
55254+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55255+ fput(current->exec_file);
55256+ current->exec_file = old_exec_file;
55257+#endif
55258+
55259 out:
55260 if (bprm->mm) {
55261 acct_arg_size(bprm, 0);
55262@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55263 return error;
55264 }
55265 #endif
55266+
55267+int pax_check_flags(unsigned long *flags)
55268+{
55269+ int retval = 0;
55270+
55271+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55272+ if (*flags & MF_PAX_SEGMEXEC)
55273+ {
55274+ *flags &= ~MF_PAX_SEGMEXEC;
55275+ retval = -EINVAL;
55276+ }
55277+#endif
55278+
55279+ if ((*flags & MF_PAX_PAGEEXEC)
55280+
55281+#ifdef CONFIG_PAX_PAGEEXEC
55282+ && (*flags & MF_PAX_SEGMEXEC)
55283+#endif
55284+
55285+ )
55286+ {
55287+ *flags &= ~MF_PAX_PAGEEXEC;
55288+ retval = -EINVAL;
55289+ }
55290+
55291+ if ((*flags & MF_PAX_MPROTECT)
55292+
55293+#ifdef CONFIG_PAX_MPROTECT
55294+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55295+#endif
55296+
55297+ )
55298+ {
55299+ *flags &= ~MF_PAX_MPROTECT;
55300+ retval = -EINVAL;
55301+ }
55302+
55303+ if ((*flags & MF_PAX_EMUTRAMP)
55304+
55305+#ifdef CONFIG_PAX_EMUTRAMP
55306+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55307+#endif
55308+
55309+ )
55310+ {
55311+ *flags &= ~MF_PAX_EMUTRAMP;
55312+ retval = -EINVAL;
55313+ }
55314+
55315+ return retval;
55316+}
55317+
55318+EXPORT_SYMBOL(pax_check_flags);
55319+
55320+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55321+char *pax_get_path(const struct path *path, char *buf, int buflen)
55322+{
55323+ char *pathname = d_path(path, buf, buflen);
55324+
55325+ if (IS_ERR(pathname))
55326+ goto toolong;
55327+
55328+ pathname = mangle_path(buf, pathname, "\t\n\\");
55329+ if (!pathname)
55330+ goto toolong;
55331+
55332+ *pathname = 0;
55333+ return buf;
55334+
55335+toolong:
55336+ return "<path too long>";
55337+}
55338+EXPORT_SYMBOL(pax_get_path);
55339+
55340+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55341+{
55342+ struct task_struct *tsk = current;
55343+ struct mm_struct *mm = current->mm;
55344+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55345+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55346+ char *path_exec = NULL;
55347+ char *path_fault = NULL;
55348+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55349+ siginfo_t info = { };
55350+
55351+ if (buffer_exec && buffer_fault) {
55352+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55353+
55354+ down_read(&mm->mmap_sem);
55355+ vma = mm->mmap;
55356+ while (vma && (!vma_exec || !vma_fault)) {
55357+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55358+ vma_exec = vma;
55359+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55360+ vma_fault = vma;
55361+ vma = vma->vm_next;
55362+ }
55363+ if (vma_exec)
55364+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55365+ if (vma_fault) {
55366+ start = vma_fault->vm_start;
55367+ end = vma_fault->vm_end;
55368+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55369+ if (vma_fault->vm_file)
55370+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55371+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55372+ path_fault = "<heap>";
55373+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55374+ path_fault = "<stack>";
55375+ else
55376+ path_fault = "<anonymous mapping>";
55377+ }
55378+ up_read(&mm->mmap_sem);
55379+ }
55380+ if (tsk->signal->curr_ip)
55381+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55382+ else
55383+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55384+ 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),
55385+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55386+ free_page((unsigned long)buffer_exec);
55387+ free_page((unsigned long)buffer_fault);
55388+ pax_report_insns(regs, pc, sp);
55389+ info.si_signo = SIGKILL;
55390+ info.si_errno = 0;
55391+ info.si_code = SI_KERNEL;
55392+ info.si_pid = 0;
55393+ info.si_uid = 0;
55394+ do_coredump(&info);
55395+}
55396+#endif
55397+
55398+#ifdef CONFIG_PAX_REFCOUNT
55399+void pax_report_refcount_overflow(struct pt_regs *regs)
55400+{
55401+ if (current->signal->curr_ip)
55402+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55403+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55404+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55405+ else
55406+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55408+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55409+ preempt_disable();
55410+ show_regs(regs);
55411+ preempt_enable();
55412+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55413+}
55414+#endif
55415+
55416+#ifdef CONFIG_PAX_USERCOPY
55417+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55418+static noinline int check_stack_object(const void *obj, unsigned long len)
55419+{
55420+ const void * const stack = task_stack_page(current);
55421+ const void * const stackend = stack + THREAD_SIZE;
55422+
55423+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55424+ const void *frame = NULL;
55425+ const void *oldframe;
55426+#endif
55427+
55428+ if (obj + len < obj)
55429+ return -1;
55430+
55431+ if (obj + len <= stack || stackend <= obj)
55432+ return 0;
55433+
55434+ if (obj < stack || stackend < obj + len)
55435+ return -1;
55436+
55437+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55438+ oldframe = __builtin_frame_address(1);
55439+ if (oldframe)
55440+ frame = __builtin_frame_address(2);
55441+ /*
55442+ low ----------------------------------------------> high
55443+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55444+ ^----------------^
55445+ allow copies only within here
55446+ */
55447+ while (stack <= frame && frame < stackend) {
55448+ /* if obj + len extends past the last frame, this
55449+ check won't pass and the next frame will be 0,
55450+ causing us to bail out and correctly report
55451+ the copy as invalid
55452+ */
55453+ if (obj + len <= frame)
55454+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55455+ oldframe = frame;
55456+ frame = *(const void * const *)frame;
55457+ }
55458+ return -1;
55459+#else
55460+ return 1;
55461+#endif
55462+}
55463+
55464+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55465+{
55466+ if (current->signal->curr_ip)
55467+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55468+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55469+ else
55470+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55471+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55472+ dump_stack();
55473+ gr_handle_kernel_exploit();
55474+ do_group_exit(SIGKILL);
55475+}
55476+#endif
55477+
55478+#ifdef CONFIG_PAX_USERCOPY
55479+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55480+{
55481+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55482+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55483+#ifdef CONFIG_MODULES
55484+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55485+#else
55486+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55487+#endif
55488+
55489+#else
55490+ unsigned long textlow = (unsigned long)_stext;
55491+ unsigned long texthigh = (unsigned long)_etext;
55492+#endif
55493+
55494+ if (high <= textlow || low > texthigh)
55495+ return false;
55496+ else
55497+ return true;
55498+}
55499+#endif
55500+
55501+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55502+{
55503+
55504+#ifdef CONFIG_PAX_USERCOPY
55505+ const char *type;
55506+
55507+ if (!n)
55508+ return;
55509+
55510+ type = check_heap_object(ptr, n);
55511+ if (!type) {
55512+ int ret = check_stack_object(ptr, n);
55513+ if (ret == 1 || ret == 2)
55514+ return;
55515+ if (ret == 0) {
55516+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55517+ type = "<kernel text>";
55518+ else
55519+ return;
55520+ } else
55521+ type = "<process stack>";
55522+ }
55523+
55524+ pax_report_usercopy(ptr, n, to_user, type);
55525+#endif
55526+
55527+}
55528+EXPORT_SYMBOL(__check_object_size);
55529+
55530+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55531+void pax_track_stack(void)
55532+{
55533+ unsigned long sp = (unsigned long)&sp;
55534+ if (sp < current_thread_info()->lowest_stack &&
55535+ sp > (unsigned long)task_stack_page(current))
55536+ current_thread_info()->lowest_stack = sp;
55537+}
55538+EXPORT_SYMBOL(pax_track_stack);
55539+#endif
55540+
55541+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55542+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55543+{
55544+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55545+ dump_stack();
55546+ do_group_exit(SIGKILL);
55547+}
55548+EXPORT_SYMBOL(report_size_overflow);
55549+#endif
55550diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55551index 9f9992b..8b59411 100644
55552--- a/fs/ext2/balloc.c
55553+++ b/fs/ext2/balloc.c
55554@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55555
55556 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55557 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55558- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55559+ if (free_blocks < root_blocks + 1 &&
55560 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55561 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55562- !in_group_p (sbi->s_resgid))) {
55563+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55564 return 0;
55565 }
55566 return 1;
55567diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55568index 22548f5..41521d8 100644
55569--- a/fs/ext3/balloc.c
55570+++ b/fs/ext3/balloc.c
55571@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55572
55573 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55574 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55575- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55576+ if (free_blocks < root_blocks + 1 &&
55577 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55578 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55579- !in_group_p (sbi->s_resgid))) {
55580+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55581 return 0;
55582 }
55583 return 1;
55584diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55585index ddd715e..c772f88 100644
55586--- a/fs/ext4/balloc.c
55587+++ b/fs/ext4/balloc.c
55588@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55589 /* Hm, nope. Are (enough) root reserved clusters available? */
55590 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55591 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55592- capable(CAP_SYS_RESOURCE) ||
55593- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55594+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55595+ capable_nolog(CAP_SYS_RESOURCE)) {
55596
55597 if (free_clusters >= (nclusters + dirty_clusters +
55598 resv_clusters))
55599diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55600index 0ab26fb..b6ecb39 100644
55601--- a/fs/ext4/ext4.h
55602+++ b/fs/ext4/ext4.h
55603@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55604 unsigned long s_mb_last_start;
55605
55606 /* stats for buddy allocator */
55607- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55608- atomic_t s_bal_success; /* we found long enough chunks */
55609- atomic_t s_bal_allocated; /* in blocks */
55610- atomic_t s_bal_ex_scanned; /* total extents scanned */
55611- atomic_t s_bal_goals; /* goal hits */
55612- atomic_t s_bal_breaks; /* too long searches */
55613- atomic_t s_bal_2orders; /* 2^order hits */
55614+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55615+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55616+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55617+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55618+ atomic_unchecked_t s_bal_goals; /* goal hits */
55619+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55620+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55621 spinlock_t s_bal_lock;
55622 unsigned long s_mb_buddies_generated;
55623 unsigned long long s_mb_generation_time;
55624- atomic_t s_mb_lost_chunks;
55625- atomic_t s_mb_preallocated;
55626- atomic_t s_mb_discarded;
55627+ atomic_unchecked_t s_mb_lost_chunks;
55628+ atomic_unchecked_t s_mb_preallocated;
55629+ atomic_unchecked_t s_mb_discarded;
55630 atomic_t s_lock_busy;
55631
55632 /* locality groups */
55633diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55634index 4bbbf13b..dcceaeb 100644
55635--- a/fs/ext4/mballoc.c
55636+++ b/fs/ext4/mballoc.c
55637@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55638 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55639
55640 if (EXT4_SB(sb)->s_mb_stats)
55641- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55642+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55643
55644 break;
55645 }
55646@@ -2171,7 +2171,7 @@ repeat:
55647 ac->ac_status = AC_STATUS_CONTINUE;
55648 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55649 cr = 3;
55650- atomic_inc(&sbi->s_mb_lost_chunks);
55651+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55652 goto repeat;
55653 }
55654 }
55655@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55656 if (sbi->s_mb_stats) {
55657 ext4_msg(sb, KERN_INFO,
55658 "mballoc: %u blocks %u reqs (%u success)",
55659- atomic_read(&sbi->s_bal_allocated),
55660- atomic_read(&sbi->s_bal_reqs),
55661- atomic_read(&sbi->s_bal_success));
55662+ atomic_read_unchecked(&sbi->s_bal_allocated),
55663+ atomic_read_unchecked(&sbi->s_bal_reqs),
55664+ atomic_read_unchecked(&sbi->s_bal_success));
55665 ext4_msg(sb, KERN_INFO,
55666 "mballoc: %u extents scanned, %u goal hits, "
55667 "%u 2^N hits, %u breaks, %u lost",
55668- atomic_read(&sbi->s_bal_ex_scanned),
55669- atomic_read(&sbi->s_bal_goals),
55670- atomic_read(&sbi->s_bal_2orders),
55671- atomic_read(&sbi->s_bal_breaks),
55672- atomic_read(&sbi->s_mb_lost_chunks));
55673+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55674+ atomic_read_unchecked(&sbi->s_bal_goals),
55675+ atomic_read_unchecked(&sbi->s_bal_2orders),
55676+ atomic_read_unchecked(&sbi->s_bal_breaks),
55677+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55678 ext4_msg(sb, KERN_INFO,
55679 "mballoc: %lu generated and it took %Lu",
55680 sbi->s_mb_buddies_generated,
55681 sbi->s_mb_generation_time);
55682 ext4_msg(sb, KERN_INFO,
55683 "mballoc: %u preallocated, %u discarded",
55684- atomic_read(&sbi->s_mb_preallocated),
55685- atomic_read(&sbi->s_mb_discarded));
55686+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55687+ atomic_read_unchecked(&sbi->s_mb_discarded));
55688 }
55689
55690 free_percpu(sbi->s_locality_groups);
55691@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55692 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55693
55694 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55695- atomic_inc(&sbi->s_bal_reqs);
55696- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55697+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55698+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55699 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55700- atomic_inc(&sbi->s_bal_success);
55701- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55702+ atomic_inc_unchecked(&sbi->s_bal_success);
55703+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55704 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55705 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55706- atomic_inc(&sbi->s_bal_goals);
55707+ atomic_inc_unchecked(&sbi->s_bal_goals);
55708 if (ac->ac_found > sbi->s_mb_max_to_scan)
55709- atomic_inc(&sbi->s_bal_breaks);
55710+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55711 }
55712
55713 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55714@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55715 trace_ext4_mb_new_inode_pa(ac, pa);
55716
55717 ext4_mb_use_inode_pa(ac, pa);
55718- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55719+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55720
55721 ei = EXT4_I(ac->ac_inode);
55722 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55723@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55724 trace_ext4_mb_new_group_pa(ac, pa);
55725
55726 ext4_mb_use_group_pa(ac, pa);
55727- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55728+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55729
55730 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55731 lg = ac->ac_lg;
55732@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55733 * from the bitmap and continue.
55734 */
55735 }
55736- atomic_add(free, &sbi->s_mb_discarded);
55737+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55738
55739 return err;
55740 }
55741@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55742 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55743 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55744 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55745- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55746+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55747 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55748
55749 return 0;
55750diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55751index 214461e..3614c89 100644
55752--- a/fs/ext4/mmp.c
55753+++ b/fs/ext4/mmp.c
55754@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55755 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55756 const char *function, unsigned int line, const char *msg)
55757 {
55758- __ext4_warning(sb, function, line, msg);
55759+ __ext4_warning(sb, function, line, "%s", msg);
55760 __ext4_warning(sb, function, line,
55761 "MMP failure info: last update time: %llu, last update "
55762 "node: %s, last update device: %s\n",
55763diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55764index b59373b..f41c2b5 100644
55765--- a/fs/ext4/super.c
55766+++ b/fs/ext4/super.c
55767@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55768 }
55769
55770 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55771-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55772+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55773 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55774
55775 #ifdef CONFIG_QUOTA
55776@@ -2394,7 +2394,7 @@ struct ext4_attr {
55777 int offset;
55778 int deprecated_val;
55779 } u;
55780-};
55781+} __do_const;
55782
55783 static int parse_strtoull(const char *buf,
55784 unsigned long long max, unsigned long long *value)
55785diff --git a/fs/fcntl.c b/fs/fcntl.c
55786index 65343c3..9969dcf 100644
55787--- a/fs/fcntl.c
55788+++ b/fs/fcntl.c
55789@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55790 if (err)
55791 return err;
55792
55793+ if (gr_handle_chroot_fowner(pid, type))
55794+ return -ENOENT;
55795+ if (gr_check_protected_task_fowner(pid, type))
55796+ return -EACCES;
55797+
55798 f_modown(filp, pid, type, force);
55799 return 0;
55800 }
55801diff --git a/fs/fhandle.c b/fs/fhandle.c
55802index 999ff5c..41f4109 100644
55803--- a/fs/fhandle.c
55804+++ b/fs/fhandle.c
55805@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55806 } else
55807 retval = 0;
55808 /* copy the mount id */
55809- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55810- sizeof(*mnt_id)) ||
55811+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55812 copy_to_user(ufh, handle,
55813 sizeof(struct file_handle) + handle_bytes))
55814 retval = -EFAULT;
55815diff --git a/fs/file.c b/fs/file.c
55816index 4a78f98..9447397 100644
55817--- a/fs/file.c
55818+++ b/fs/file.c
55819@@ -16,6 +16,7 @@
55820 #include <linux/slab.h>
55821 #include <linux/vmalloc.h>
55822 #include <linux/file.h>
55823+#include <linux/security.h>
55824 #include <linux/fdtable.h>
55825 #include <linux/bitops.h>
55826 #include <linux/interrupt.h>
55827@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55828 if (!file)
55829 return __close_fd(files, fd);
55830
55831+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55832 if (fd >= rlimit(RLIMIT_NOFILE))
55833 return -EBADF;
55834
55835@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55836 if (unlikely(oldfd == newfd))
55837 return -EINVAL;
55838
55839+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55840 if (newfd >= rlimit(RLIMIT_NOFILE))
55841 return -EBADF;
55842
55843@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55844 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55845 {
55846 int err;
55847+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55848 if (from >= rlimit(RLIMIT_NOFILE))
55849 return -EINVAL;
55850 err = alloc_fd(from, flags);
55851diff --git a/fs/filesystems.c b/fs/filesystems.c
55852index 92567d9..fcd8cbf 100644
55853--- a/fs/filesystems.c
55854+++ b/fs/filesystems.c
55855@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55856 int len = dot ? dot - name : strlen(name);
55857
55858 fs = __get_fs_type(name, len);
55859+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55860+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55861+#else
55862 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55863+#endif
55864 fs = __get_fs_type(name, len);
55865
55866 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55867diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55868index d8ac61d..79a36f0 100644
55869--- a/fs/fs_struct.c
55870+++ b/fs/fs_struct.c
55871@@ -4,6 +4,7 @@
55872 #include <linux/path.h>
55873 #include <linux/slab.h>
55874 #include <linux/fs_struct.h>
55875+#include <linux/grsecurity.h>
55876 #include "internal.h"
55877
55878 /*
55879@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55880 write_seqcount_begin(&fs->seq);
55881 old_root = fs->root;
55882 fs->root = *path;
55883+ gr_set_chroot_entries(current, path);
55884 write_seqcount_end(&fs->seq);
55885 spin_unlock(&fs->lock);
55886 if (old_root.dentry)
55887@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55888 int hits = 0;
55889 spin_lock(&fs->lock);
55890 write_seqcount_begin(&fs->seq);
55891+ /* this root replacement is only done by pivot_root,
55892+ leave grsec's chroot tagging alone for this task
55893+ so that a pivoted root isn't treated as a chroot
55894+ */
55895 hits += replace_path(&fs->root, old_root, new_root);
55896 hits += replace_path(&fs->pwd, old_root, new_root);
55897 write_seqcount_end(&fs->seq);
55898@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55899 task_lock(tsk);
55900 spin_lock(&fs->lock);
55901 tsk->fs = NULL;
55902- kill = !--fs->users;
55903+ gr_clear_chroot_entries(tsk);
55904+ kill = !atomic_dec_return(&fs->users);
55905 spin_unlock(&fs->lock);
55906 task_unlock(tsk);
55907 if (kill)
55908@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55909 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55910 /* We don't need to lock fs - think why ;-) */
55911 if (fs) {
55912- fs->users = 1;
55913+ atomic_set(&fs->users, 1);
55914 fs->in_exec = 0;
55915 spin_lock_init(&fs->lock);
55916 seqcount_init(&fs->seq);
55917@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55918 spin_lock(&old->lock);
55919 fs->root = old->root;
55920 path_get(&fs->root);
55921+ /* instead of calling gr_set_chroot_entries here,
55922+ we call it from every caller of this function
55923+ */
55924 fs->pwd = old->pwd;
55925 path_get(&fs->pwd);
55926 spin_unlock(&old->lock);
55927@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55928
55929 task_lock(current);
55930 spin_lock(&fs->lock);
55931- kill = !--fs->users;
55932+ kill = !atomic_dec_return(&fs->users);
55933 current->fs = new_fs;
55934+ gr_set_chroot_entries(current, &new_fs->root);
55935 spin_unlock(&fs->lock);
55936 task_unlock(current);
55937
55938@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55939
55940 int current_umask(void)
55941 {
55942- return current->fs->umask;
55943+ return current->fs->umask | gr_acl_umask();
55944 }
55945 EXPORT_SYMBOL(current_umask);
55946
55947 /* to be mentioned only in INIT_TASK */
55948 struct fs_struct init_fs = {
55949- .users = 1,
55950+ .users = ATOMIC_INIT(1),
55951 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55952 .seq = SEQCNT_ZERO,
55953 .umask = 0022,
55954diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55955index 0e91a3c..6c6d2e0 100644
55956--- a/fs/fscache/cookie.c
55957+++ b/fs/fscache/cookie.c
55958@@ -19,7 +19,7 @@
55959
55960 struct kmem_cache *fscache_cookie_jar;
55961
55962-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55963+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55964
55965 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55966 static int fscache_alloc_object(struct fscache_cache *cache,
55967@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55968 parent ? (char *) parent->def->name : "<no-parent>",
55969 def->name, netfs_data);
55970
55971- fscache_stat(&fscache_n_acquires);
55972+ fscache_stat_unchecked(&fscache_n_acquires);
55973
55974 /* if there's no parent cookie, then we don't create one here either */
55975 if (!parent) {
55976- fscache_stat(&fscache_n_acquires_null);
55977+ fscache_stat_unchecked(&fscache_n_acquires_null);
55978 _leave(" [no parent]");
55979 return NULL;
55980 }
55981@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55982 /* allocate and initialise a cookie */
55983 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55984 if (!cookie) {
55985- fscache_stat(&fscache_n_acquires_oom);
55986+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55987 _leave(" [ENOMEM]");
55988 return NULL;
55989 }
55990@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55991
55992 switch (cookie->def->type) {
55993 case FSCACHE_COOKIE_TYPE_INDEX:
55994- fscache_stat(&fscache_n_cookie_index);
55995+ fscache_stat_unchecked(&fscache_n_cookie_index);
55996 break;
55997 case FSCACHE_COOKIE_TYPE_DATAFILE:
55998- fscache_stat(&fscache_n_cookie_data);
55999+ fscache_stat_unchecked(&fscache_n_cookie_data);
56000 break;
56001 default:
56002- fscache_stat(&fscache_n_cookie_special);
56003+ fscache_stat_unchecked(&fscache_n_cookie_special);
56004 break;
56005 }
56006
56007@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56008 if (fscache_acquire_non_index_cookie(cookie) < 0) {
56009 atomic_dec(&parent->n_children);
56010 __fscache_cookie_put(cookie);
56011- fscache_stat(&fscache_n_acquires_nobufs);
56012+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
56013 _leave(" = NULL");
56014 return NULL;
56015 }
56016 }
56017
56018- fscache_stat(&fscache_n_acquires_ok);
56019+ fscache_stat_unchecked(&fscache_n_acquires_ok);
56020 _leave(" = %p", cookie);
56021 return cookie;
56022 }
56023@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
56024 cache = fscache_select_cache_for_object(cookie->parent);
56025 if (!cache) {
56026 up_read(&fscache_addremove_sem);
56027- fscache_stat(&fscache_n_acquires_no_cache);
56028+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56029 _leave(" = -ENOMEDIUM [no cache]");
56030 return -ENOMEDIUM;
56031 }
56032@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56033 object = cache->ops->alloc_object(cache, cookie);
56034 fscache_stat_d(&fscache_n_cop_alloc_object);
56035 if (IS_ERR(object)) {
56036- fscache_stat(&fscache_n_object_no_alloc);
56037+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56038 ret = PTR_ERR(object);
56039 goto error;
56040 }
56041
56042- fscache_stat(&fscache_n_object_alloc);
56043+ fscache_stat_unchecked(&fscache_n_object_alloc);
56044
56045- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56046+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56047
56048 _debug("ALLOC OBJ%x: %s {%lx}",
56049 object->debug_id, cookie->def->name, object->events);
56050@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56051
56052 _enter("{%s}", cookie->def->name);
56053
56054- fscache_stat(&fscache_n_invalidates);
56055+ fscache_stat_unchecked(&fscache_n_invalidates);
56056
56057 /* Only permit invalidation of data files. Invalidating an index will
56058 * require the caller to release all its attachments to the tree rooted
56059@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56060 {
56061 struct fscache_object *object;
56062
56063- fscache_stat(&fscache_n_updates);
56064+ fscache_stat_unchecked(&fscache_n_updates);
56065
56066 if (!cookie) {
56067- fscache_stat(&fscache_n_updates_null);
56068+ fscache_stat_unchecked(&fscache_n_updates_null);
56069 _leave(" [no cookie]");
56070 return;
56071 }
56072@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56073 {
56074 struct fscache_object *object;
56075
56076- fscache_stat(&fscache_n_relinquishes);
56077+ fscache_stat_unchecked(&fscache_n_relinquishes);
56078 if (retire)
56079- fscache_stat(&fscache_n_relinquishes_retire);
56080+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56081
56082 if (!cookie) {
56083- fscache_stat(&fscache_n_relinquishes_null);
56084+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56085 _leave(" [no cookie]");
56086 return;
56087 }
56088diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56089index 12d505b..86473a3 100644
56090--- a/fs/fscache/internal.h
56091+++ b/fs/fscache/internal.h
56092@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
56093 * stats.c
56094 */
56095 #ifdef CONFIG_FSCACHE_STATS
56096-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56097-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56098+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56099+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56100
56101-extern atomic_t fscache_n_op_pend;
56102-extern atomic_t fscache_n_op_run;
56103-extern atomic_t fscache_n_op_enqueue;
56104-extern atomic_t fscache_n_op_deferred_release;
56105-extern atomic_t fscache_n_op_release;
56106-extern atomic_t fscache_n_op_gc;
56107-extern atomic_t fscache_n_op_cancelled;
56108-extern atomic_t fscache_n_op_rejected;
56109+extern atomic_unchecked_t fscache_n_op_pend;
56110+extern atomic_unchecked_t fscache_n_op_run;
56111+extern atomic_unchecked_t fscache_n_op_enqueue;
56112+extern atomic_unchecked_t fscache_n_op_deferred_release;
56113+extern atomic_unchecked_t fscache_n_op_release;
56114+extern atomic_unchecked_t fscache_n_op_gc;
56115+extern atomic_unchecked_t fscache_n_op_cancelled;
56116+extern atomic_unchecked_t fscache_n_op_rejected;
56117
56118-extern atomic_t fscache_n_attr_changed;
56119-extern atomic_t fscache_n_attr_changed_ok;
56120-extern atomic_t fscache_n_attr_changed_nobufs;
56121-extern atomic_t fscache_n_attr_changed_nomem;
56122-extern atomic_t fscache_n_attr_changed_calls;
56123+extern atomic_unchecked_t fscache_n_attr_changed;
56124+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56125+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56126+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56127+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56128
56129-extern atomic_t fscache_n_allocs;
56130-extern atomic_t fscache_n_allocs_ok;
56131-extern atomic_t fscache_n_allocs_wait;
56132-extern atomic_t fscache_n_allocs_nobufs;
56133-extern atomic_t fscache_n_allocs_intr;
56134-extern atomic_t fscache_n_allocs_object_dead;
56135-extern atomic_t fscache_n_alloc_ops;
56136-extern atomic_t fscache_n_alloc_op_waits;
56137+extern atomic_unchecked_t fscache_n_allocs;
56138+extern atomic_unchecked_t fscache_n_allocs_ok;
56139+extern atomic_unchecked_t fscache_n_allocs_wait;
56140+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56141+extern atomic_unchecked_t fscache_n_allocs_intr;
56142+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56143+extern atomic_unchecked_t fscache_n_alloc_ops;
56144+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56145
56146-extern atomic_t fscache_n_retrievals;
56147-extern atomic_t fscache_n_retrievals_ok;
56148-extern atomic_t fscache_n_retrievals_wait;
56149-extern atomic_t fscache_n_retrievals_nodata;
56150-extern atomic_t fscache_n_retrievals_nobufs;
56151-extern atomic_t fscache_n_retrievals_intr;
56152-extern atomic_t fscache_n_retrievals_nomem;
56153-extern atomic_t fscache_n_retrievals_object_dead;
56154-extern atomic_t fscache_n_retrieval_ops;
56155-extern atomic_t fscache_n_retrieval_op_waits;
56156+extern atomic_unchecked_t fscache_n_retrievals;
56157+extern atomic_unchecked_t fscache_n_retrievals_ok;
56158+extern atomic_unchecked_t fscache_n_retrievals_wait;
56159+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56160+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56161+extern atomic_unchecked_t fscache_n_retrievals_intr;
56162+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56163+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56164+extern atomic_unchecked_t fscache_n_retrieval_ops;
56165+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56166
56167-extern atomic_t fscache_n_stores;
56168-extern atomic_t fscache_n_stores_ok;
56169-extern atomic_t fscache_n_stores_again;
56170-extern atomic_t fscache_n_stores_nobufs;
56171-extern atomic_t fscache_n_stores_oom;
56172-extern atomic_t fscache_n_store_ops;
56173-extern atomic_t fscache_n_store_calls;
56174-extern atomic_t fscache_n_store_pages;
56175-extern atomic_t fscache_n_store_radix_deletes;
56176-extern atomic_t fscache_n_store_pages_over_limit;
56177+extern atomic_unchecked_t fscache_n_stores;
56178+extern atomic_unchecked_t fscache_n_stores_ok;
56179+extern atomic_unchecked_t fscache_n_stores_again;
56180+extern atomic_unchecked_t fscache_n_stores_nobufs;
56181+extern atomic_unchecked_t fscache_n_stores_oom;
56182+extern atomic_unchecked_t fscache_n_store_ops;
56183+extern atomic_unchecked_t fscache_n_store_calls;
56184+extern atomic_unchecked_t fscache_n_store_pages;
56185+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56186+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56187
56188-extern atomic_t fscache_n_store_vmscan_not_storing;
56189-extern atomic_t fscache_n_store_vmscan_gone;
56190-extern atomic_t fscache_n_store_vmscan_busy;
56191-extern atomic_t fscache_n_store_vmscan_cancelled;
56192-extern atomic_t fscache_n_store_vmscan_wait;
56193+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56194+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56195+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56196+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56197+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56198
56199-extern atomic_t fscache_n_marks;
56200-extern atomic_t fscache_n_uncaches;
56201+extern atomic_unchecked_t fscache_n_marks;
56202+extern atomic_unchecked_t fscache_n_uncaches;
56203
56204-extern atomic_t fscache_n_acquires;
56205-extern atomic_t fscache_n_acquires_null;
56206-extern atomic_t fscache_n_acquires_no_cache;
56207-extern atomic_t fscache_n_acquires_ok;
56208-extern atomic_t fscache_n_acquires_nobufs;
56209-extern atomic_t fscache_n_acquires_oom;
56210+extern atomic_unchecked_t fscache_n_acquires;
56211+extern atomic_unchecked_t fscache_n_acquires_null;
56212+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56213+extern atomic_unchecked_t fscache_n_acquires_ok;
56214+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56215+extern atomic_unchecked_t fscache_n_acquires_oom;
56216
56217-extern atomic_t fscache_n_invalidates;
56218-extern atomic_t fscache_n_invalidates_run;
56219+extern atomic_unchecked_t fscache_n_invalidates;
56220+extern atomic_unchecked_t fscache_n_invalidates_run;
56221
56222-extern atomic_t fscache_n_updates;
56223-extern atomic_t fscache_n_updates_null;
56224-extern atomic_t fscache_n_updates_run;
56225+extern atomic_unchecked_t fscache_n_updates;
56226+extern atomic_unchecked_t fscache_n_updates_null;
56227+extern atomic_unchecked_t fscache_n_updates_run;
56228
56229-extern atomic_t fscache_n_relinquishes;
56230-extern atomic_t fscache_n_relinquishes_null;
56231-extern atomic_t fscache_n_relinquishes_waitcrt;
56232-extern atomic_t fscache_n_relinquishes_retire;
56233+extern atomic_unchecked_t fscache_n_relinquishes;
56234+extern atomic_unchecked_t fscache_n_relinquishes_null;
56235+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56236+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56237
56238-extern atomic_t fscache_n_cookie_index;
56239-extern atomic_t fscache_n_cookie_data;
56240-extern atomic_t fscache_n_cookie_special;
56241+extern atomic_unchecked_t fscache_n_cookie_index;
56242+extern atomic_unchecked_t fscache_n_cookie_data;
56243+extern atomic_unchecked_t fscache_n_cookie_special;
56244
56245-extern atomic_t fscache_n_object_alloc;
56246-extern atomic_t fscache_n_object_no_alloc;
56247-extern atomic_t fscache_n_object_lookups;
56248-extern atomic_t fscache_n_object_lookups_negative;
56249-extern atomic_t fscache_n_object_lookups_positive;
56250-extern atomic_t fscache_n_object_lookups_timed_out;
56251-extern atomic_t fscache_n_object_created;
56252-extern atomic_t fscache_n_object_avail;
56253-extern atomic_t fscache_n_object_dead;
56254+extern atomic_unchecked_t fscache_n_object_alloc;
56255+extern atomic_unchecked_t fscache_n_object_no_alloc;
56256+extern atomic_unchecked_t fscache_n_object_lookups;
56257+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56258+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56259+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56260+extern atomic_unchecked_t fscache_n_object_created;
56261+extern atomic_unchecked_t fscache_n_object_avail;
56262+extern atomic_unchecked_t fscache_n_object_dead;
56263
56264-extern atomic_t fscache_n_checkaux_none;
56265-extern atomic_t fscache_n_checkaux_okay;
56266-extern atomic_t fscache_n_checkaux_update;
56267-extern atomic_t fscache_n_checkaux_obsolete;
56268+extern atomic_unchecked_t fscache_n_checkaux_none;
56269+extern atomic_unchecked_t fscache_n_checkaux_okay;
56270+extern atomic_unchecked_t fscache_n_checkaux_update;
56271+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56272
56273 extern atomic_t fscache_n_cop_alloc_object;
56274 extern atomic_t fscache_n_cop_lookup_object;
56275@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56276 atomic_inc(stat);
56277 }
56278
56279+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56280+{
56281+ atomic_inc_unchecked(stat);
56282+}
56283+
56284 static inline void fscache_stat_d(atomic_t *stat)
56285 {
56286 atomic_dec(stat);
56287@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56288
56289 #define __fscache_stat(stat) (NULL)
56290 #define fscache_stat(stat) do {} while (0)
56291+#define fscache_stat_unchecked(stat) do {} while (0)
56292 #define fscache_stat_d(stat) do {} while (0)
56293 #endif
56294
56295diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56296index 86d75a6..5f3d7a0 100644
56297--- a/fs/fscache/object.c
56298+++ b/fs/fscache/object.c
56299@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56300 _debug("LOOKUP \"%s\" in \"%s\"",
56301 cookie->def->name, object->cache->tag->name);
56302
56303- fscache_stat(&fscache_n_object_lookups);
56304+ fscache_stat_unchecked(&fscache_n_object_lookups);
56305 fscache_stat(&fscache_n_cop_lookup_object);
56306 ret = object->cache->ops->lookup_object(object);
56307 fscache_stat_d(&fscache_n_cop_lookup_object);
56308@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56309 if (ret == -ETIMEDOUT) {
56310 /* probably stuck behind another object, so move this one to
56311 * the back of the queue */
56312- fscache_stat(&fscache_n_object_lookups_timed_out);
56313+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56314 _leave(" [timeout]");
56315 return NO_TRANSIT;
56316 }
56317@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56318 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56319
56320 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56321- fscache_stat(&fscache_n_object_lookups_negative);
56322+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56323
56324 /* Allow write requests to begin stacking up and read requests to begin
56325 * returning ENODATA.
56326@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56327 /* if we were still looking up, then we must have a positive lookup
56328 * result, in which case there may be data available */
56329 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56330- fscache_stat(&fscache_n_object_lookups_positive);
56331+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56332
56333 /* We do (presumably) have data */
56334 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56335@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56336 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56337 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56338 } else {
56339- fscache_stat(&fscache_n_object_created);
56340+ fscache_stat_unchecked(&fscache_n_object_created);
56341 }
56342
56343 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56344@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56345 fscache_stat_d(&fscache_n_cop_lookup_complete);
56346
56347 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56348- fscache_stat(&fscache_n_object_avail);
56349+ fscache_stat_unchecked(&fscache_n_object_avail);
56350
56351 _leave("");
56352 return transit_to(JUMPSTART_DEPS);
56353@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56354
56355 /* this just shifts the object release to the work processor */
56356 fscache_put_object(object);
56357- fscache_stat(&fscache_n_object_dead);
56358+ fscache_stat_unchecked(&fscache_n_object_dead);
56359
56360 _leave("");
56361 return transit_to(OBJECT_DEAD);
56362@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56363 enum fscache_checkaux result;
56364
56365 if (!object->cookie->def->check_aux) {
56366- fscache_stat(&fscache_n_checkaux_none);
56367+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56368 return FSCACHE_CHECKAUX_OKAY;
56369 }
56370
56371@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56372 switch (result) {
56373 /* entry okay as is */
56374 case FSCACHE_CHECKAUX_OKAY:
56375- fscache_stat(&fscache_n_checkaux_okay);
56376+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56377 break;
56378
56379 /* entry requires update */
56380 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56381- fscache_stat(&fscache_n_checkaux_update);
56382+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56383 break;
56384
56385 /* entry requires deletion */
56386 case FSCACHE_CHECKAUX_OBSOLETE:
56387- fscache_stat(&fscache_n_checkaux_obsolete);
56388+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56389 break;
56390
56391 default:
56392@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56393 {
56394 const struct fscache_state *s;
56395
56396- fscache_stat(&fscache_n_invalidates_run);
56397+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56398 fscache_stat(&fscache_n_cop_invalidate_object);
56399 s = _fscache_invalidate_object(object, event);
56400 fscache_stat_d(&fscache_n_cop_invalidate_object);
56401@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56402 {
56403 _enter("{OBJ%x},%d", object->debug_id, event);
56404
56405- fscache_stat(&fscache_n_updates_run);
56406+ fscache_stat_unchecked(&fscache_n_updates_run);
56407 fscache_stat(&fscache_n_cop_update_object);
56408 object->cache->ops->update_object(object);
56409 fscache_stat_d(&fscache_n_cop_update_object);
56410diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56411index 318071a..379938b 100644
56412--- a/fs/fscache/operation.c
56413+++ b/fs/fscache/operation.c
56414@@ -17,7 +17,7 @@
56415 #include <linux/slab.h>
56416 #include "internal.h"
56417
56418-atomic_t fscache_op_debug_id;
56419+atomic_unchecked_t fscache_op_debug_id;
56420 EXPORT_SYMBOL(fscache_op_debug_id);
56421
56422 /**
56423@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56424 ASSERTCMP(atomic_read(&op->usage), >, 0);
56425 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56426
56427- fscache_stat(&fscache_n_op_enqueue);
56428+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56429 switch (op->flags & FSCACHE_OP_TYPE) {
56430 case FSCACHE_OP_ASYNC:
56431 _debug("queue async");
56432@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56433 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56434 if (op->processor)
56435 fscache_enqueue_operation(op);
56436- fscache_stat(&fscache_n_op_run);
56437+ fscache_stat_unchecked(&fscache_n_op_run);
56438 }
56439
56440 /*
56441@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56442 if (object->n_in_progress > 0) {
56443 atomic_inc(&op->usage);
56444 list_add_tail(&op->pend_link, &object->pending_ops);
56445- fscache_stat(&fscache_n_op_pend);
56446+ fscache_stat_unchecked(&fscache_n_op_pend);
56447 } else if (!list_empty(&object->pending_ops)) {
56448 atomic_inc(&op->usage);
56449 list_add_tail(&op->pend_link, &object->pending_ops);
56450- fscache_stat(&fscache_n_op_pend);
56451+ fscache_stat_unchecked(&fscache_n_op_pend);
56452 fscache_start_operations(object);
56453 } else {
56454 ASSERTCMP(object->n_in_progress, ==, 0);
56455@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56456 object->n_exclusive++; /* reads and writes must wait */
56457 atomic_inc(&op->usage);
56458 list_add_tail(&op->pend_link, &object->pending_ops);
56459- fscache_stat(&fscache_n_op_pend);
56460+ fscache_stat_unchecked(&fscache_n_op_pend);
56461 ret = 0;
56462 } else {
56463 /* If we're in any other state, there must have been an I/O
56464@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56465 if (object->n_exclusive > 0) {
56466 atomic_inc(&op->usage);
56467 list_add_tail(&op->pend_link, &object->pending_ops);
56468- fscache_stat(&fscache_n_op_pend);
56469+ fscache_stat_unchecked(&fscache_n_op_pend);
56470 } else if (!list_empty(&object->pending_ops)) {
56471 atomic_inc(&op->usage);
56472 list_add_tail(&op->pend_link, &object->pending_ops);
56473- fscache_stat(&fscache_n_op_pend);
56474+ fscache_stat_unchecked(&fscache_n_op_pend);
56475 fscache_start_operations(object);
56476 } else {
56477 ASSERTCMP(object->n_exclusive, ==, 0);
56478@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56479 object->n_ops++;
56480 atomic_inc(&op->usage);
56481 list_add_tail(&op->pend_link, &object->pending_ops);
56482- fscache_stat(&fscache_n_op_pend);
56483+ fscache_stat_unchecked(&fscache_n_op_pend);
56484 ret = 0;
56485 } else if (fscache_object_is_dying(object)) {
56486- fscache_stat(&fscache_n_op_rejected);
56487+ fscache_stat_unchecked(&fscache_n_op_rejected);
56488 op->state = FSCACHE_OP_ST_CANCELLED;
56489 ret = -ENOBUFS;
56490 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56491@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56492 ret = -EBUSY;
56493 if (op->state == FSCACHE_OP_ST_PENDING) {
56494 ASSERT(!list_empty(&op->pend_link));
56495- fscache_stat(&fscache_n_op_cancelled);
56496+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56497 list_del_init(&op->pend_link);
56498 if (do_cancel)
56499 do_cancel(op);
56500@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56501 while (!list_empty(&object->pending_ops)) {
56502 op = list_entry(object->pending_ops.next,
56503 struct fscache_operation, pend_link);
56504- fscache_stat(&fscache_n_op_cancelled);
56505+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56506 list_del_init(&op->pend_link);
56507
56508 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56509@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56510 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56511 op->state = FSCACHE_OP_ST_DEAD;
56512
56513- fscache_stat(&fscache_n_op_release);
56514+ fscache_stat_unchecked(&fscache_n_op_release);
56515
56516 if (op->release) {
56517 op->release(op);
56518@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56519 * lock, and defer it otherwise */
56520 if (!spin_trylock(&object->lock)) {
56521 _debug("defer put");
56522- fscache_stat(&fscache_n_op_deferred_release);
56523+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56524
56525 cache = object->cache;
56526 spin_lock(&cache->op_gc_list_lock);
56527@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56528
56529 _debug("GC DEFERRED REL OBJ%x OP%x",
56530 object->debug_id, op->debug_id);
56531- fscache_stat(&fscache_n_op_gc);
56532+ fscache_stat_unchecked(&fscache_n_op_gc);
56533
56534 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56535 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56536diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56537index d479ab3..727a7f2 100644
56538--- a/fs/fscache/page.c
56539+++ b/fs/fscache/page.c
56540@@ -61,7 +61,7 @@ try_again:
56541 val = radix_tree_lookup(&cookie->stores, page->index);
56542 if (!val) {
56543 rcu_read_unlock();
56544- fscache_stat(&fscache_n_store_vmscan_not_storing);
56545+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56546 __fscache_uncache_page(cookie, page);
56547 return true;
56548 }
56549@@ -91,11 +91,11 @@ try_again:
56550 spin_unlock(&cookie->stores_lock);
56551
56552 if (xpage) {
56553- fscache_stat(&fscache_n_store_vmscan_cancelled);
56554- fscache_stat(&fscache_n_store_radix_deletes);
56555+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56556+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56557 ASSERTCMP(xpage, ==, page);
56558 } else {
56559- fscache_stat(&fscache_n_store_vmscan_gone);
56560+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56561 }
56562
56563 wake_up_bit(&cookie->flags, 0);
56564@@ -110,11 +110,11 @@ page_busy:
56565 * sleeping on memory allocation, so we may need to impose a timeout
56566 * too. */
56567 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56568- fscache_stat(&fscache_n_store_vmscan_busy);
56569+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56570 return false;
56571 }
56572
56573- fscache_stat(&fscache_n_store_vmscan_wait);
56574+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56575 __fscache_wait_on_page_write(cookie, page);
56576 gfp &= ~__GFP_WAIT;
56577 goto try_again;
56578@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56579 FSCACHE_COOKIE_STORING_TAG);
56580 if (!radix_tree_tag_get(&cookie->stores, page->index,
56581 FSCACHE_COOKIE_PENDING_TAG)) {
56582- fscache_stat(&fscache_n_store_radix_deletes);
56583+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56584 xpage = radix_tree_delete(&cookie->stores, page->index);
56585 }
56586 spin_unlock(&cookie->stores_lock);
56587@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56588
56589 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56590
56591- fscache_stat(&fscache_n_attr_changed_calls);
56592+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56593
56594 if (fscache_object_is_active(object) &&
56595 fscache_use_cookie(object)) {
56596@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56597
56598 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56599
56600- fscache_stat(&fscache_n_attr_changed);
56601+ fscache_stat_unchecked(&fscache_n_attr_changed);
56602
56603 op = kzalloc(sizeof(*op), GFP_KERNEL);
56604 if (!op) {
56605- fscache_stat(&fscache_n_attr_changed_nomem);
56606+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56607 _leave(" = -ENOMEM");
56608 return -ENOMEM;
56609 }
56610@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56611 if (fscache_submit_exclusive_op(object, op) < 0)
56612 goto nobufs;
56613 spin_unlock(&cookie->lock);
56614- fscache_stat(&fscache_n_attr_changed_ok);
56615+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56616 fscache_put_operation(op);
56617 _leave(" = 0");
56618 return 0;
56619@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56620 nobufs:
56621 spin_unlock(&cookie->lock);
56622 kfree(op);
56623- fscache_stat(&fscache_n_attr_changed_nobufs);
56624+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56625 _leave(" = %d", -ENOBUFS);
56626 return -ENOBUFS;
56627 }
56628@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56629 /* allocate a retrieval operation and attempt to submit it */
56630 op = kzalloc(sizeof(*op), GFP_NOIO);
56631 if (!op) {
56632- fscache_stat(&fscache_n_retrievals_nomem);
56633+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56634 return NULL;
56635 }
56636
56637@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56638 return 0;
56639 }
56640
56641- fscache_stat(&fscache_n_retrievals_wait);
56642+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56643
56644 jif = jiffies;
56645 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56646 fscache_wait_bit_interruptible,
56647 TASK_INTERRUPTIBLE) != 0) {
56648- fscache_stat(&fscache_n_retrievals_intr);
56649+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56650 _leave(" = -ERESTARTSYS");
56651 return -ERESTARTSYS;
56652 }
56653@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56654 */
56655 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56656 struct fscache_retrieval *op,
56657- atomic_t *stat_op_waits,
56658- atomic_t *stat_object_dead)
56659+ atomic_unchecked_t *stat_op_waits,
56660+ atomic_unchecked_t *stat_object_dead)
56661 {
56662 int ret;
56663
56664@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56665 goto check_if_dead;
56666
56667 _debug(">>> WT");
56668- fscache_stat(stat_op_waits);
56669+ fscache_stat_unchecked(stat_op_waits);
56670 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56671 fscache_wait_bit_interruptible,
56672 TASK_INTERRUPTIBLE) != 0) {
56673@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56674
56675 check_if_dead:
56676 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56677- fscache_stat(stat_object_dead);
56678+ fscache_stat_unchecked(stat_object_dead);
56679 _leave(" = -ENOBUFS [cancelled]");
56680 return -ENOBUFS;
56681 }
56682 if (unlikely(fscache_object_is_dead(object))) {
56683 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56684 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56685- fscache_stat(stat_object_dead);
56686+ fscache_stat_unchecked(stat_object_dead);
56687 return -ENOBUFS;
56688 }
56689 return 0;
56690@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56691
56692 _enter("%p,%p,,,", cookie, page);
56693
56694- fscache_stat(&fscache_n_retrievals);
56695+ fscache_stat_unchecked(&fscache_n_retrievals);
56696
56697 if (hlist_empty(&cookie->backing_objects))
56698 goto nobufs;
56699@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56700 goto nobufs_unlock_dec;
56701 spin_unlock(&cookie->lock);
56702
56703- fscache_stat(&fscache_n_retrieval_ops);
56704+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56705
56706 /* pin the netfs read context in case we need to do the actual netfs
56707 * read because we've encountered a cache read failure */
56708@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56709
56710 error:
56711 if (ret == -ENOMEM)
56712- fscache_stat(&fscache_n_retrievals_nomem);
56713+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56714 else if (ret == -ERESTARTSYS)
56715- fscache_stat(&fscache_n_retrievals_intr);
56716+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56717 else if (ret == -ENODATA)
56718- fscache_stat(&fscache_n_retrievals_nodata);
56719+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56720 else if (ret < 0)
56721- fscache_stat(&fscache_n_retrievals_nobufs);
56722+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56723 else
56724- fscache_stat(&fscache_n_retrievals_ok);
56725+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56726
56727 fscache_put_retrieval(op);
56728 _leave(" = %d", ret);
56729@@ -475,7 +475,7 @@ nobufs_unlock:
56730 atomic_dec(&cookie->n_active);
56731 kfree(op);
56732 nobufs:
56733- fscache_stat(&fscache_n_retrievals_nobufs);
56734+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56735 _leave(" = -ENOBUFS");
56736 return -ENOBUFS;
56737 }
56738@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56739
56740 _enter("%p,,%d,,,", cookie, *nr_pages);
56741
56742- fscache_stat(&fscache_n_retrievals);
56743+ fscache_stat_unchecked(&fscache_n_retrievals);
56744
56745 if (hlist_empty(&cookie->backing_objects))
56746 goto nobufs;
56747@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56748 goto nobufs_unlock_dec;
56749 spin_unlock(&cookie->lock);
56750
56751- fscache_stat(&fscache_n_retrieval_ops);
56752+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56753
56754 /* pin the netfs read context in case we need to do the actual netfs
56755 * read because we've encountered a cache read failure */
56756@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56757
56758 error:
56759 if (ret == -ENOMEM)
56760- fscache_stat(&fscache_n_retrievals_nomem);
56761+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56762 else if (ret == -ERESTARTSYS)
56763- fscache_stat(&fscache_n_retrievals_intr);
56764+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56765 else if (ret == -ENODATA)
56766- fscache_stat(&fscache_n_retrievals_nodata);
56767+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56768 else if (ret < 0)
56769- fscache_stat(&fscache_n_retrievals_nobufs);
56770+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56771 else
56772- fscache_stat(&fscache_n_retrievals_ok);
56773+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56774
56775 fscache_put_retrieval(op);
56776 _leave(" = %d", ret);
56777@@ -600,7 +600,7 @@ nobufs_unlock:
56778 atomic_dec(&cookie->n_active);
56779 kfree(op);
56780 nobufs:
56781- fscache_stat(&fscache_n_retrievals_nobufs);
56782+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56783 _leave(" = -ENOBUFS");
56784 return -ENOBUFS;
56785 }
56786@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56787
56788 _enter("%p,%p,,,", cookie, page);
56789
56790- fscache_stat(&fscache_n_allocs);
56791+ fscache_stat_unchecked(&fscache_n_allocs);
56792
56793 if (hlist_empty(&cookie->backing_objects))
56794 goto nobufs;
56795@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56796 goto nobufs_unlock;
56797 spin_unlock(&cookie->lock);
56798
56799- fscache_stat(&fscache_n_alloc_ops);
56800+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56801
56802 ret = fscache_wait_for_retrieval_activation(
56803 object, op,
56804@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56805
56806 error:
56807 if (ret == -ERESTARTSYS)
56808- fscache_stat(&fscache_n_allocs_intr);
56809+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56810 else if (ret < 0)
56811- fscache_stat(&fscache_n_allocs_nobufs);
56812+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56813 else
56814- fscache_stat(&fscache_n_allocs_ok);
56815+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56816
56817 fscache_put_retrieval(op);
56818 _leave(" = %d", ret);
56819@@ -687,7 +687,7 @@ nobufs_unlock:
56820 atomic_dec(&cookie->n_active);
56821 kfree(op);
56822 nobufs:
56823- fscache_stat(&fscache_n_allocs_nobufs);
56824+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56825 _leave(" = -ENOBUFS");
56826 return -ENOBUFS;
56827 }
56828@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56829
56830 spin_lock(&cookie->stores_lock);
56831
56832- fscache_stat(&fscache_n_store_calls);
56833+ fscache_stat_unchecked(&fscache_n_store_calls);
56834
56835 /* find a page to store */
56836 page = NULL;
56837@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56838 page = results[0];
56839 _debug("gang %d [%lx]", n, page->index);
56840 if (page->index > op->store_limit) {
56841- fscache_stat(&fscache_n_store_pages_over_limit);
56842+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56843 goto superseded;
56844 }
56845
56846@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56847 spin_unlock(&cookie->stores_lock);
56848 spin_unlock(&object->lock);
56849
56850- fscache_stat(&fscache_n_store_pages);
56851+ fscache_stat_unchecked(&fscache_n_store_pages);
56852 fscache_stat(&fscache_n_cop_write_page);
56853 ret = object->cache->ops->write_page(op, page);
56854 fscache_stat_d(&fscache_n_cop_write_page);
56855@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56856 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56857 ASSERT(PageFsCache(page));
56858
56859- fscache_stat(&fscache_n_stores);
56860+ fscache_stat_unchecked(&fscache_n_stores);
56861
56862 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56863 _leave(" = -ENOBUFS [invalidating]");
56864@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56865 spin_unlock(&cookie->stores_lock);
56866 spin_unlock(&object->lock);
56867
56868- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56869+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56870 op->store_limit = object->store_limit;
56871
56872 atomic_inc(&cookie->n_active);
56873@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56874
56875 spin_unlock(&cookie->lock);
56876 radix_tree_preload_end();
56877- fscache_stat(&fscache_n_store_ops);
56878- fscache_stat(&fscache_n_stores_ok);
56879+ fscache_stat_unchecked(&fscache_n_store_ops);
56880+ fscache_stat_unchecked(&fscache_n_stores_ok);
56881
56882 /* the work queue now carries its own ref on the object */
56883 fscache_put_operation(&op->op);
56884@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56885 return 0;
56886
56887 already_queued:
56888- fscache_stat(&fscache_n_stores_again);
56889+ fscache_stat_unchecked(&fscache_n_stores_again);
56890 already_pending:
56891 spin_unlock(&cookie->stores_lock);
56892 spin_unlock(&object->lock);
56893 spin_unlock(&cookie->lock);
56894 radix_tree_preload_end();
56895 kfree(op);
56896- fscache_stat(&fscache_n_stores_ok);
56897+ fscache_stat_unchecked(&fscache_n_stores_ok);
56898 _leave(" = 0");
56899 return 0;
56900
56901@@ -976,14 +976,14 @@ nobufs:
56902 spin_unlock(&cookie->lock);
56903 radix_tree_preload_end();
56904 kfree(op);
56905- fscache_stat(&fscache_n_stores_nobufs);
56906+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56907 _leave(" = -ENOBUFS");
56908 return -ENOBUFS;
56909
56910 nomem_free:
56911 kfree(op);
56912 nomem:
56913- fscache_stat(&fscache_n_stores_oom);
56914+ fscache_stat_unchecked(&fscache_n_stores_oom);
56915 _leave(" = -ENOMEM");
56916 return -ENOMEM;
56917 }
56918@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56919 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56920 ASSERTCMP(page, !=, NULL);
56921
56922- fscache_stat(&fscache_n_uncaches);
56923+ fscache_stat_unchecked(&fscache_n_uncaches);
56924
56925 /* cache withdrawal may beat us to it */
56926 if (!PageFsCache(page))
56927@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56928 struct fscache_cookie *cookie = op->op.object->cookie;
56929
56930 #ifdef CONFIG_FSCACHE_STATS
56931- atomic_inc(&fscache_n_marks);
56932+ atomic_inc_unchecked(&fscache_n_marks);
56933 #endif
56934
56935 _debug("- mark %p{%lx}", page, page->index);
56936diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56937index 40d13c7..ddf52b9 100644
56938--- a/fs/fscache/stats.c
56939+++ b/fs/fscache/stats.c
56940@@ -18,99 +18,99 @@
56941 /*
56942 * operation counters
56943 */
56944-atomic_t fscache_n_op_pend;
56945-atomic_t fscache_n_op_run;
56946-atomic_t fscache_n_op_enqueue;
56947-atomic_t fscache_n_op_requeue;
56948-atomic_t fscache_n_op_deferred_release;
56949-atomic_t fscache_n_op_release;
56950-atomic_t fscache_n_op_gc;
56951-atomic_t fscache_n_op_cancelled;
56952-atomic_t fscache_n_op_rejected;
56953+atomic_unchecked_t fscache_n_op_pend;
56954+atomic_unchecked_t fscache_n_op_run;
56955+atomic_unchecked_t fscache_n_op_enqueue;
56956+atomic_unchecked_t fscache_n_op_requeue;
56957+atomic_unchecked_t fscache_n_op_deferred_release;
56958+atomic_unchecked_t fscache_n_op_release;
56959+atomic_unchecked_t fscache_n_op_gc;
56960+atomic_unchecked_t fscache_n_op_cancelled;
56961+atomic_unchecked_t fscache_n_op_rejected;
56962
56963-atomic_t fscache_n_attr_changed;
56964-atomic_t fscache_n_attr_changed_ok;
56965-atomic_t fscache_n_attr_changed_nobufs;
56966-atomic_t fscache_n_attr_changed_nomem;
56967-atomic_t fscache_n_attr_changed_calls;
56968+atomic_unchecked_t fscache_n_attr_changed;
56969+atomic_unchecked_t fscache_n_attr_changed_ok;
56970+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56971+atomic_unchecked_t fscache_n_attr_changed_nomem;
56972+atomic_unchecked_t fscache_n_attr_changed_calls;
56973
56974-atomic_t fscache_n_allocs;
56975-atomic_t fscache_n_allocs_ok;
56976-atomic_t fscache_n_allocs_wait;
56977-atomic_t fscache_n_allocs_nobufs;
56978-atomic_t fscache_n_allocs_intr;
56979-atomic_t fscache_n_allocs_object_dead;
56980-atomic_t fscache_n_alloc_ops;
56981-atomic_t fscache_n_alloc_op_waits;
56982+atomic_unchecked_t fscache_n_allocs;
56983+atomic_unchecked_t fscache_n_allocs_ok;
56984+atomic_unchecked_t fscache_n_allocs_wait;
56985+atomic_unchecked_t fscache_n_allocs_nobufs;
56986+atomic_unchecked_t fscache_n_allocs_intr;
56987+atomic_unchecked_t fscache_n_allocs_object_dead;
56988+atomic_unchecked_t fscache_n_alloc_ops;
56989+atomic_unchecked_t fscache_n_alloc_op_waits;
56990
56991-atomic_t fscache_n_retrievals;
56992-atomic_t fscache_n_retrievals_ok;
56993-atomic_t fscache_n_retrievals_wait;
56994-atomic_t fscache_n_retrievals_nodata;
56995-atomic_t fscache_n_retrievals_nobufs;
56996-atomic_t fscache_n_retrievals_intr;
56997-atomic_t fscache_n_retrievals_nomem;
56998-atomic_t fscache_n_retrievals_object_dead;
56999-atomic_t fscache_n_retrieval_ops;
57000-atomic_t fscache_n_retrieval_op_waits;
57001+atomic_unchecked_t fscache_n_retrievals;
57002+atomic_unchecked_t fscache_n_retrievals_ok;
57003+atomic_unchecked_t fscache_n_retrievals_wait;
57004+atomic_unchecked_t fscache_n_retrievals_nodata;
57005+atomic_unchecked_t fscache_n_retrievals_nobufs;
57006+atomic_unchecked_t fscache_n_retrievals_intr;
57007+atomic_unchecked_t fscache_n_retrievals_nomem;
57008+atomic_unchecked_t fscache_n_retrievals_object_dead;
57009+atomic_unchecked_t fscache_n_retrieval_ops;
57010+atomic_unchecked_t fscache_n_retrieval_op_waits;
57011
57012-atomic_t fscache_n_stores;
57013-atomic_t fscache_n_stores_ok;
57014-atomic_t fscache_n_stores_again;
57015-atomic_t fscache_n_stores_nobufs;
57016-atomic_t fscache_n_stores_oom;
57017-atomic_t fscache_n_store_ops;
57018-atomic_t fscache_n_store_calls;
57019-atomic_t fscache_n_store_pages;
57020-atomic_t fscache_n_store_radix_deletes;
57021-atomic_t fscache_n_store_pages_over_limit;
57022+atomic_unchecked_t fscache_n_stores;
57023+atomic_unchecked_t fscache_n_stores_ok;
57024+atomic_unchecked_t fscache_n_stores_again;
57025+atomic_unchecked_t fscache_n_stores_nobufs;
57026+atomic_unchecked_t fscache_n_stores_oom;
57027+atomic_unchecked_t fscache_n_store_ops;
57028+atomic_unchecked_t fscache_n_store_calls;
57029+atomic_unchecked_t fscache_n_store_pages;
57030+atomic_unchecked_t fscache_n_store_radix_deletes;
57031+atomic_unchecked_t fscache_n_store_pages_over_limit;
57032
57033-atomic_t fscache_n_store_vmscan_not_storing;
57034-atomic_t fscache_n_store_vmscan_gone;
57035-atomic_t fscache_n_store_vmscan_busy;
57036-atomic_t fscache_n_store_vmscan_cancelled;
57037-atomic_t fscache_n_store_vmscan_wait;
57038+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57039+atomic_unchecked_t fscache_n_store_vmscan_gone;
57040+atomic_unchecked_t fscache_n_store_vmscan_busy;
57041+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57042+atomic_unchecked_t fscache_n_store_vmscan_wait;
57043
57044-atomic_t fscache_n_marks;
57045-atomic_t fscache_n_uncaches;
57046+atomic_unchecked_t fscache_n_marks;
57047+atomic_unchecked_t fscache_n_uncaches;
57048
57049-atomic_t fscache_n_acquires;
57050-atomic_t fscache_n_acquires_null;
57051-atomic_t fscache_n_acquires_no_cache;
57052-atomic_t fscache_n_acquires_ok;
57053-atomic_t fscache_n_acquires_nobufs;
57054-atomic_t fscache_n_acquires_oom;
57055+atomic_unchecked_t fscache_n_acquires;
57056+atomic_unchecked_t fscache_n_acquires_null;
57057+atomic_unchecked_t fscache_n_acquires_no_cache;
57058+atomic_unchecked_t fscache_n_acquires_ok;
57059+atomic_unchecked_t fscache_n_acquires_nobufs;
57060+atomic_unchecked_t fscache_n_acquires_oom;
57061
57062-atomic_t fscache_n_invalidates;
57063-atomic_t fscache_n_invalidates_run;
57064+atomic_unchecked_t fscache_n_invalidates;
57065+atomic_unchecked_t fscache_n_invalidates_run;
57066
57067-atomic_t fscache_n_updates;
57068-atomic_t fscache_n_updates_null;
57069-atomic_t fscache_n_updates_run;
57070+atomic_unchecked_t fscache_n_updates;
57071+atomic_unchecked_t fscache_n_updates_null;
57072+atomic_unchecked_t fscache_n_updates_run;
57073
57074-atomic_t fscache_n_relinquishes;
57075-atomic_t fscache_n_relinquishes_null;
57076-atomic_t fscache_n_relinquishes_waitcrt;
57077-atomic_t fscache_n_relinquishes_retire;
57078+atomic_unchecked_t fscache_n_relinquishes;
57079+atomic_unchecked_t fscache_n_relinquishes_null;
57080+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57081+atomic_unchecked_t fscache_n_relinquishes_retire;
57082
57083-atomic_t fscache_n_cookie_index;
57084-atomic_t fscache_n_cookie_data;
57085-atomic_t fscache_n_cookie_special;
57086+atomic_unchecked_t fscache_n_cookie_index;
57087+atomic_unchecked_t fscache_n_cookie_data;
57088+atomic_unchecked_t fscache_n_cookie_special;
57089
57090-atomic_t fscache_n_object_alloc;
57091-atomic_t fscache_n_object_no_alloc;
57092-atomic_t fscache_n_object_lookups;
57093-atomic_t fscache_n_object_lookups_negative;
57094-atomic_t fscache_n_object_lookups_positive;
57095-atomic_t fscache_n_object_lookups_timed_out;
57096-atomic_t fscache_n_object_created;
57097-atomic_t fscache_n_object_avail;
57098-atomic_t fscache_n_object_dead;
57099+atomic_unchecked_t fscache_n_object_alloc;
57100+atomic_unchecked_t fscache_n_object_no_alloc;
57101+atomic_unchecked_t fscache_n_object_lookups;
57102+atomic_unchecked_t fscache_n_object_lookups_negative;
57103+atomic_unchecked_t fscache_n_object_lookups_positive;
57104+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57105+atomic_unchecked_t fscache_n_object_created;
57106+atomic_unchecked_t fscache_n_object_avail;
57107+atomic_unchecked_t fscache_n_object_dead;
57108
57109-atomic_t fscache_n_checkaux_none;
57110-atomic_t fscache_n_checkaux_okay;
57111-atomic_t fscache_n_checkaux_update;
57112-atomic_t fscache_n_checkaux_obsolete;
57113+atomic_unchecked_t fscache_n_checkaux_none;
57114+atomic_unchecked_t fscache_n_checkaux_okay;
57115+atomic_unchecked_t fscache_n_checkaux_update;
57116+atomic_unchecked_t fscache_n_checkaux_obsolete;
57117
57118 atomic_t fscache_n_cop_alloc_object;
57119 atomic_t fscache_n_cop_lookup_object;
57120@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57121 seq_puts(m, "FS-Cache statistics\n");
57122
57123 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57124- atomic_read(&fscache_n_cookie_index),
57125- atomic_read(&fscache_n_cookie_data),
57126- atomic_read(&fscache_n_cookie_special));
57127+ atomic_read_unchecked(&fscache_n_cookie_index),
57128+ atomic_read_unchecked(&fscache_n_cookie_data),
57129+ atomic_read_unchecked(&fscache_n_cookie_special));
57130
57131 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57132- atomic_read(&fscache_n_object_alloc),
57133- atomic_read(&fscache_n_object_no_alloc),
57134- atomic_read(&fscache_n_object_avail),
57135- atomic_read(&fscache_n_object_dead));
57136+ atomic_read_unchecked(&fscache_n_object_alloc),
57137+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57138+ atomic_read_unchecked(&fscache_n_object_avail),
57139+ atomic_read_unchecked(&fscache_n_object_dead));
57140 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57141- atomic_read(&fscache_n_checkaux_none),
57142- atomic_read(&fscache_n_checkaux_okay),
57143- atomic_read(&fscache_n_checkaux_update),
57144- atomic_read(&fscache_n_checkaux_obsolete));
57145+ atomic_read_unchecked(&fscache_n_checkaux_none),
57146+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57147+ atomic_read_unchecked(&fscache_n_checkaux_update),
57148+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57149
57150 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57151- atomic_read(&fscache_n_marks),
57152- atomic_read(&fscache_n_uncaches));
57153+ atomic_read_unchecked(&fscache_n_marks),
57154+ atomic_read_unchecked(&fscache_n_uncaches));
57155
57156 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57157 " oom=%u\n",
57158- atomic_read(&fscache_n_acquires),
57159- atomic_read(&fscache_n_acquires_null),
57160- atomic_read(&fscache_n_acquires_no_cache),
57161- atomic_read(&fscache_n_acquires_ok),
57162- atomic_read(&fscache_n_acquires_nobufs),
57163- atomic_read(&fscache_n_acquires_oom));
57164+ atomic_read_unchecked(&fscache_n_acquires),
57165+ atomic_read_unchecked(&fscache_n_acquires_null),
57166+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57167+ atomic_read_unchecked(&fscache_n_acquires_ok),
57168+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57169+ atomic_read_unchecked(&fscache_n_acquires_oom));
57170
57171 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57172- atomic_read(&fscache_n_object_lookups),
57173- atomic_read(&fscache_n_object_lookups_negative),
57174- atomic_read(&fscache_n_object_lookups_positive),
57175- atomic_read(&fscache_n_object_created),
57176- atomic_read(&fscache_n_object_lookups_timed_out));
57177+ atomic_read_unchecked(&fscache_n_object_lookups),
57178+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57179+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57180+ atomic_read_unchecked(&fscache_n_object_created),
57181+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57182
57183 seq_printf(m, "Invals : n=%u run=%u\n",
57184- atomic_read(&fscache_n_invalidates),
57185- atomic_read(&fscache_n_invalidates_run));
57186+ atomic_read_unchecked(&fscache_n_invalidates),
57187+ atomic_read_unchecked(&fscache_n_invalidates_run));
57188
57189 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57190- atomic_read(&fscache_n_updates),
57191- atomic_read(&fscache_n_updates_null),
57192- atomic_read(&fscache_n_updates_run));
57193+ atomic_read_unchecked(&fscache_n_updates),
57194+ atomic_read_unchecked(&fscache_n_updates_null),
57195+ atomic_read_unchecked(&fscache_n_updates_run));
57196
57197 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57198- atomic_read(&fscache_n_relinquishes),
57199- atomic_read(&fscache_n_relinquishes_null),
57200- atomic_read(&fscache_n_relinquishes_waitcrt),
57201- atomic_read(&fscache_n_relinquishes_retire));
57202+ atomic_read_unchecked(&fscache_n_relinquishes),
57203+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57204+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57205+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57206
57207 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57208- atomic_read(&fscache_n_attr_changed),
57209- atomic_read(&fscache_n_attr_changed_ok),
57210- atomic_read(&fscache_n_attr_changed_nobufs),
57211- atomic_read(&fscache_n_attr_changed_nomem),
57212- atomic_read(&fscache_n_attr_changed_calls));
57213+ atomic_read_unchecked(&fscache_n_attr_changed),
57214+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57215+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57216+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57217+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57218
57219 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57220- atomic_read(&fscache_n_allocs),
57221- atomic_read(&fscache_n_allocs_ok),
57222- atomic_read(&fscache_n_allocs_wait),
57223- atomic_read(&fscache_n_allocs_nobufs),
57224- atomic_read(&fscache_n_allocs_intr));
57225+ atomic_read_unchecked(&fscache_n_allocs),
57226+ atomic_read_unchecked(&fscache_n_allocs_ok),
57227+ atomic_read_unchecked(&fscache_n_allocs_wait),
57228+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57229+ atomic_read_unchecked(&fscache_n_allocs_intr));
57230 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57231- atomic_read(&fscache_n_alloc_ops),
57232- atomic_read(&fscache_n_alloc_op_waits),
57233- atomic_read(&fscache_n_allocs_object_dead));
57234+ atomic_read_unchecked(&fscache_n_alloc_ops),
57235+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57236+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57237
57238 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57239 " int=%u oom=%u\n",
57240- atomic_read(&fscache_n_retrievals),
57241- atomic_read(&fscache_n_retrievals_ok),
57242- atomic_read(&fscache_n_retrievals_wait),
57243- atomic_read(&fscache_n_retrievals_nodata),
57244- atomic_read(&fscache_n_retrievals_nobufs),
57245- atomic_read(&fscache_n_retrievals_intr),
57246- atomic_read(&fscache_n_retrievals_nomem));
57247+ atomic_read_unchecked(&fscache_n_retrievals),
57248+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57249+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57250+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57251+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57252+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57253+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57254 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57255- atomic_read(&fscache_n_retrieval_ops),
57256- atomic_read(&fscache_n_retrieval_op_waits),
57257- atomic_read(&fscache_n_retrievals_object_dead));
57258+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57259+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57260+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57261
57262 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57263- atomic_read(&fscache_n_stores),
57264- atomic_read(&fscache_n_stores_ok),
57265- atomic_read(&fscache_n_stores_again),
57266- atomic_read(&fscache_n_stores_nobufs),
57267- atomic_read(&fscache_n_stores_oom));
57268+ atomic_read_unchecked(&fscache_n_stores),
57269+ atomic_read_unchecked(&fscache_n_stores_ok),
57270+ atomic_read_unchecked(&fscache_n_stores_again),
57271+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57272+ atomic_read_unchecked(&fscache_n_stores_oom));
57273 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57274- atomic_read(&fscache_n_store_ops),
57275- atomic_read(&fscache_n_store_calls),
57276- atomic_read(&fscache_n_store_pages),
57277- atomic_read(&fscache_n_store_radix_deletes),
57278- atomic_read(&fscache_n_store_pages_over_limit));
57279+ atomic_read_unchecked(&fscache_n_store_ops),
57280+ atomic_read_unchecked(&fscache_n_store_calls),
57281+ atomic_read_unchecked(&fscache_n_store_pages),
57282+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57283+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57284
57285 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57286- atomic_read(&fscache_n_store_vmscan_not_storing),
57287- atomic_read(&fscache_n_store_vmscan_gone),
57288- atomic_read(&fscache_n_store_vmscan_busy),
57289- atomic_read(&fscache_n_store_vmscan_cancelled),
57290- atomic_read(&fscache_n_store_vmscan_wait));
57291+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57292+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57293+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57294+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57295+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57296
57297 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57298- atomic_read(&fscache_n_op_pend),
57299- atomic_read(&fscache_n_op_run),
57300- atomic_read(&fscache_n_op_enqueue),
57301- atomic_read(&fscache_n_op_cancelled),
57302- atomic_read(&fscache_n_op_rejected));
57303+ atomic_read_unchecked(&fscache_n_op_pend),
57304+ atomic_read_unchecked(&fscache_n_op_run),
57305+ atomic_read_unchecked(&fscache_n_op_enqueue),
57306+ atomic_read_unchecked(&fscache_n_op_cancelled),
57307+ atomic_read_unchecked(&fscache_n_op_rejected));
57308 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57309- atomic_read(&fscache_n_op_deferred_release),
57310- atomic_read(&fscache_n_op_release),
57311- atomic_read(&fscache_n_op_gc));
57312+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57313+ atomic_read_unchecked(&fscache_n_op_release),
57314+ atomic_read_unchecked(&fscache_n_op_gc));
57315
57316 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57317 atomic_read(&fscache_n_cop_alloc_object),
57318diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57319index aef34b1..59bfd7b 100644
57320--- a/fs/fuse/cuse.c
57321+++ b/fs/fuse/cuse.c
57322@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57323 INIT_LIST_HEAD(&cuse_conntbl[i]);
57324
57325 /* inherit and extend fuse_dev_operations */
57326- cuse_channel_fops = fuse_dev_operations;
57327- cuse_channel_fops.owner = THIS_MODULE;
57328- cuse_channel_fops.open = cuse_channel_open;
57329- cuse_channel_fops.release = cuse_channel_release;
57330+ pax_open_kernel();
57331+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57332+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57333+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57334+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57335+ pax_close_kernel();
57336
57337 cuse_class = class_create(THIS_MODULE, "cuse");
57338 if (IS_ERR(cuse_class))
57339diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57340index 1d55f94..088da65 100644
57341--- a/fs/fuse/dev.c
57342+++ b/fs/fuse/dev.c
57343@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57344 ret = 0;
57345 pipe_lock(pipe);
57346
57347- if (!pipe->readers) {
57348+ if (!atomic_read(&pipe->readers)) {
57349 send_sig(SIGPIPE, current, 0);
57350 if (!ret)
57351 ret = -EPIPE;
57352@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57353 page_nr++;
57354 ret += buf->len;
57355
57356- if (pipe->files)
57357+ if (atomic_read(&pipe->files))
57358 do_wakeup = 1;
57359 }
57360
57361diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57362index 72a5d5b..c991011 100644
57363--- a/fs/fuse/dir.c
57364+++ b/fs/fuse/dir.c
57365@@ -1433,7 +1433,7 @@ static char *read_link(struct dentry *dentry)
57366 return link;
57367 }
57368
57369-static void free_link(char *link)
57370+static void free_link(const char *link)
57371 {
57372 if (!IS_ERR(link))
57373 free_page((unsigned long) link);
57374diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57375index 64915ee..6bed500 100644
57376--- a/fs/gfs2/inode.c
57377+++ b/fs/gfs2/inode.c
57378@@ -1506,7 +1506,7 @@ out:
57379
57380 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57381 {
57382- char *s = nd_get_link(nd);
57383+ const char *s = nd_get_link(nd);
57384 if (!IS_ERR(s))
57385 kfree(s);
57386 }
57387diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57388index d19b30a..ef89c36 100644
57389--- a/fs/hugetlbfs/inode.c
57390+++ b/fs/hugetlbfs/inode.c
57391@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57392 struct mm_struct *mm = current->mm;
57393 struct vm_area_struct *vma;
57394 struct hstate *h = hstate_file(file);
57395+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57396 struct vm_unmapped_area_info info;
57397
57398 if (len & ~huge_page_mask(h))
57399@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57400 return addr;
57401 }
57402
57403+#ifdef CONFIG_PAX_RANDMMAP
57404+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57405+#endif
57406+
57407 if (addr) {
57408 addr = ALIGN(addr, huge_page_size(h));
57409 vma = find_vma(mm, addr);
57410- if (TASK_SIZE - len >= addr &&
57411- (!vma || addr + len <= vma->vm_start))
57412+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57413 return addr;
57414 }
57415
57416 info.flags = 0;
57417 info.length = len;
57418 info.low_limit = TASK_UNMAPPED_BASE;
57419+
57420+#ifdef CONFIG_PAX_RANDMMAP
57421+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57422+ info.low_limit += mm->delta_mmap;
57423+#endif
57424+
57425 info.high_limit = TASK_SIZE;
57426 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57427 info.align_offset = 0;
57428@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57429 };
57430 MODULE_ALIAS_FS("hugetlbfs");
57431
57432-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57433+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57434
57435 static int can_do_hugetlb_shm(void)
57436 {
57437diff --git a/fs/inode.c b/fs/inode.c
57438index d6dfb09..602e77e 100644
57439--- a/fs/inode.c
57440+++ b/fs/inode.c
57441@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57442
57443 #ifdef CONFIG_SMP
57444 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57445- static atomic_t shared_last_ino;
57446- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57447+ static atomic_unchecked_t shared_last_ino;
57448+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57449
57450 res = next - LAST_INO_BATCH;
57451 }
57452diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57453index 4a6cf28..d3a29d3 100644
57454--- a/fs/jffs2/erase.c
57455+++ b/fs/jffs2/erase.c
57456@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57457 struct jffs2_unknown_node marker = {
57458 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57459 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57460- .totlen = cpu_to_je32(c->cleanmarker_size)
57461+ .totlen = cpu_to_je32(c->cleanmarker_size),
57462+ .hdr_crc = cpu_to_je32(0)
57463 };
57464
57465 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57466diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57467index a6597d6..41b30ec 100644
57468--- a/fs/jffs2/wbuf.c
57469+++ b/fs/jffs2/wbuf.c
57470@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57471 {
57472 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57473 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57474- .totlen = constant_cpu_to_je32(8)
57475+ .totlen = constant_cpu_to_je32(8),
57476+ .hdr_crc = constant_cpu_to_je32(0)
57477 };
57478
57479 /*
57480diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57481index 6669aa2..36b033d 100644
57482--- a/fs/jfs/super.c
57483+++ b/fs/jfs/super.c
57484@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57485
57486 jfs_inode_cachep =
57487 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57488- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57489+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57490 init_once);
57491 if (jfs_inode_cachep == NULL)
57492 return -ENOMEM;
57493diff --git a/fs/libfs.c b/fs/libfs.c
57494index 3a3a9b5..3a9b074 100644
57495--- a/fs/libfs.c
57496+++ b/fs/libfs.c
57497@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57498
57499 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57500 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57501+ char d_name[sizeof(next->d_iname)];
57502+ const unsigned char *name;
57503+
57504 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57505 if (!simple_positive(next)) {
57506 spin_unlock(&next->d_lock);
57507@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57508
57509 spin_unlock(&next->d_lock);
57510 spin_unlock(&dentry->d_lock);
57511- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57512+ name = next->d_name.name;
57513+ if (name == next->d_iname) {
57514+ memcpy(d_name, name, next->d_name.len);
57515+ name = d_name;
57516+ }
57517+ if (!dir_emit(ctx, name, next->d_name.len,
57518 next->d_inode->i_ino, dt_type(next->d_inode)))
57519 return 0;
57520 spin_lock(&dentry->d_lock);
57521diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57522index acd3947..1f896e2 100644
57523--- a/fs/lockd/clntproc.c
57524+++ b/fs/lockd/clntproc.c
57525@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57526 /*
57527 * Cookie counter for NLM requests
57528 */
57529-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57530+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57531
57532 void nlmclnt_next_cookie(struct nlm_cookie *c)
57533 {
57534- u32 cookie = atomic_inc_return(&nlm_cookie);
57535+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57536
57537 memcpy(c->data, &cookie, 4);
57538 c->len=4;
57539diff --git a/fs/locks.c b/fs/locks.c
57540index b27a300..4156d0b 100644
57541--- a/fs/locks.c
57542+++ b/fs/locks.c
57543@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57544 return;
57545
57546 if (filp->f_op && filp->f_op->flock) {
57547- struct file_lock fl = {
57548+ struct file_lock flock = {
57549 .fl_pid = current->tgid,
57550 .fl_file = filp,
57551 .fl_flags = FL_FLOCK,
57552 .fl_type = F_UNLCK,
57553 .fl_end = OFFSET_MAX,
57554 };
57555- filp->f_op->flock(filp, F_SETLKW, &fl);
57556- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57557- fl.fl_ops->fl_release_private(&fl);
57558+ filp->f_op->flock(filp, F_SETLKW, &flock);
57559+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57560+ flock.fl_ops->fl_release_private(&flock);
57561 }
57562
57563 spin_lock(&inode->i_lock);
57564diff --git a/fs/namei.c b/fs/namei.c
57565index 7720fbd..7934bb2 100644
57566--- a/fs/namei.c
57567+++ b/fs/namei.c
57568@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57569 if (ret != -EACCES)
57570 return ret;
57571
57572+#ifdef CONFIG_GRKERNSEC
57573+ /* we'll block if we have to log due to a denied capability use */
57574+ if (mask & MAY_NOT_BLOCK)
57575+ return -ECHILD;
57576+#endif
57577+
57578 if (S_ISDIR(inode->i_mode)) {
57579 /* DACs are overridable for directories */
57580- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57581- return 0;
57582 if (!(mask & MAY_WRITE))
57583- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57584+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57585+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57586 return 0;
57587+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57588+ return 0;
57589 return -EACCES;
57590 }
57591 /*
57592+ * Searching includes executable on directories, else just read.
57593+ */
57594+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57595+ if (mask == MAY_READ)
57596+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57597+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57598+ return 0;
57599+
57600+ /*
57601 * Read/write DACs are always overridable.
57602 * Executable DACs are overridable when there is
57603 * at least one exec bit set.
57604@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57605 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57606 return 0;
57607
57608- /*
57609- * Searching includes executable on directories, else just read.
57610- */
57611- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57612- if (mask == MAY_READ)
57613- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57614- return 0;
57615-
57616 return -EACCES;
57617 }
57618
57619@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57620 {
57621 struct dentry *dentry = link->dentry;
57622 int error;
57623- char *s;
57624+ const char *s;
57625
57626 BUG_ON(nd->flags & LOOKUP_RCU);
57627
57628@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57629 if (error)
57630 goto out_put_nd_path;
57631
57632+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57633+ dentry->d_inode, dentry, nd->path.mnt)) {
57634+ error = -EACCES;
57635+ goto out_put_nd_path;
57636+ }
57637+
57638 nd->last_type = LAST_BIND;
57639 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57640 error = PTR_ERR(*p);
57641@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57642 if (res)
57643 break;
57644 res = walk_component(nd, path, LOOKUP_FOLLOW);
57645+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57646+ res = -EACCES;
57647 put_link(nd, &link, cookie);
57648 } while (res > 0);
57649
57650@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57651 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57652 {
57653 unsigned long a, b, adata, bdata, mask, hash, len;
57654- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57655+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57656
57657 hash = a = 0;
57658 len = -sizeof(unsigned long);
57659@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57660 if (err)
57661 break;
57662 err = lookup_last(nd, &path);
57663+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57664+ err = -EACCES;
57665 put_link(nd, &link, cookie);
57666 }
57667 }
57668@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57669 if (!err)
57670 err = complete_walk(nd);
57671
57672+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57673+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57674+ path_put(&nd->path);
57675+ err = -ENOENT;
57676+ }
57677+ }
57678+
57679 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57680 if (!can_lookup(nd->inode)) {
57681 path_put(&nd->path);
57682@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57683 retval = path_lookupat(dfd, name->name,
57684 flags | LOOKUP_REVAL, nd);
57685
57686- if (likely(!retval))
57687+ if (likely(!retval)) {
57688 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57689+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57690+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57691+ path_put(&nd->path);
57692+ return -ENOENT;
57693+ }
57694+ }
57695+ }
57696 return retval;
57697 }
57698
57699@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57700 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57701 return -EPERM;
57702
57703+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57704+ return -EPERM;
57705+ if (gr_handle_rawio(inode))
57706+ return -EPERM;
57707+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57708+ return -EACCES;
57709+
57710 return 0;
57711 }
57712
57713@@ -2601,7 +2640,7 @@ looked_up:
57714 * cleared otherwise prior to returning.
57715 */
57716 static int lookup_open(struct nameidata *nd, struct path *path,
57717- struct file *file,
57718+ struct path *link, struct file *file,
57719 const struct open_flags *op,
57720 bool got_write, int *opened)
57721 {
57722@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57723 /* Negative dentry, just create the file */
57724 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57725 umode_t mode = op->mode;
57726+
57727+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57728+ error = -EACCES;
57729+ goto out_dput;
57730+ }
57731+
57732+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57733+ error = -EACCES;
57734+ goto out_dput;
57735+ }
57736+
57737 if (!IS_POSIXACL(dir->d_inode))
57738 mode &= ~current_umask();
57739 /*
57740@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57741 nd->flags & LOOKUP_EXCL);
57742 if (error)
57743 goto out_dput;
57744+ else
57745+ gr_handle_create(dentry, nd->path.mnt);
57746 }
57747 out_no_open:
57748 path->dentry = dentry;
57749@@ -2671,7 +2723,7 @@ out_dput:
57750 /*
57751 * Handle the last step of open()
57752 */
57753-static int do_last(struct nameidata *nd, struct path *path,
57754+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57755 struct file *file, const struct open_flags *op,
57756 int *opened, struct filename *name)
57757 {
57758@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57759 if (error)
57760 return error;
57761
57762+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57763+ error = -ENOENT;
57764+ goto out;
57765+ }
57766+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57767+ error = -EACCES;
57768+ goto out;
57769+ }
57770+
57771 audit_inode(name, dir, LOOKUP_PARENT);
57772 error = -EISDIR;
57773 /* trailing slashes? */
57774@@ -2740,7 +2801,7 @@ retry_lookup:
57775 */
57776 }
57777 mutex_lock(&dir->d_inode->i_mutex);
57778- error = lookup_open(nd, path, file, op, got_write, opened);
57779+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57780 mutex_unlock(&dir->d_inode->i_mutex);
57781
57782 if (error <= 0) {
57783@@ -2764,11 +2825,28 @@ retry_lookup:
57784 goto finish_open_created;
57785 }
57786
57787+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57788+ error = -ENOENT;
57789+ goto exit_dput;
57790+ }
57791+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57792+ error = -EACCES;
57793+ goto exit_dput;
57794+ }
57795+
57796 /*
57797 * create/update audit record if it already exists.
57798 */
57799- if (path->dentry->d_inode)
57800+ if (path->dentry->d_inode) {
57801+ /* only check if O_CREAT is specified, all other checks need to go
57802+ into may_open */
57803+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57804+ error = -EACCES;
57805+ goto exit_dput;
57806+ }
57807+
57808 audit_inode(name, path->dentry, 0);
57809+ }
57810
57811 /*
57812 * If atomic_open() acquired write access it is dropped now due to
57813@@ -2809,6 +2887,11 @@ finish_lookup:
57814 }
57815 }
57816 BUG_ON(inode != path->dentry->d_inode);
57817+ /* if we're resolving a symlink to another symlink */
57818+ if (link && gr_handle_symlink_owner(link, inode)) {
57819+ error = -EACCES;
57820+ goto out;
57821+ }
57822 return 1;
57823 }
57824
57825@@ -2818,7 +2901,6 @@ finish_lookup:
57826 save_parent.dentry = nd->path.dentry;
57827 save_parent.mnt = mntget(path->mnt);
57828 nd->path.dentry = path->dentry;
57829-
57830 }
57831 nd->inode = inode;
57832 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57833@@ -2828,7 +2910,18 @@ finish_open:
57834 path_put(&save_parent);
57835 return error;
57836 }
57837+
57838+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57839+ error = -ENOENT;
57840+ goto out;
57841+ }
57842+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57843+ error = -EACCES;
57844+ goto out;
57845+ }
57846+
57847 audit_inode(name, nd->path.dentry, 0);
57848+
57849 error = -EISDIR;
57850 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57851 goto out;
57852@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57853 if (unlikely(error))
57854 goto out;
57855
57856- error = do_last(nd, &path, file, op, &opened, pathname);
57857+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57858 while (unlikely(error > 0)) { /* trailing symlink */
57859 struct path link = path;
57860 void *cookie;
57861@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57862 error = follow_link(&link, nd, &cookie);
57863 if (unlikely(error))
57864 break;
57865- error = do_last(nd, &path, file, op, &opened, pathname);
57866+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57867 put_link(nd, &link, cookie);
57868 }
57869 out:
57870@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57871 goto unlock;
57872
57873 error = -EEXIST;
57874- if (dentry->d_inode)
57875+ if (dentry->d_inode) {
57876+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57877+ error = -ENOENT;
57878+ }
57879 goto fail;
57880+ }
57881 /*
57882 * Special case - lookup gave negative, but... we had foo/bar/
57883 * From the vfs_mknod() POV we just have a negative dentry -
57884@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57885 }
57886 EXPORT_SYMBOL(user_path_create);
57887
57888+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57889+{
57890+ struct filename *tmp = getname(pathname);
57891+ struct dentry *res;
57892+ if (IS_ERR(tmp))
57893+ return ERR_CAST(tmp);
57894+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57895+ if (IS_ERR(res))
57896+ putname(tmp);
57897+ else
57898+ *to = tmp;
57899+ return res;
57900+}
57901+
57902 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57903 {
57904 int error = may_create(dir, dentry);
57905@@ -3224,6 +3335,17 @@ retry:
57906
57907 if (!IS_POSIXACL(path.dentry->d_inode))
57908 mode &= ~current_umask();
57909+
57910+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57911+ error = -EPERM;
57912+ goto out;
57913+ }
57914+
57915+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57916+ error = -EACCES;
57917+ goto out;
57918+ }
57919+
57920 error = security_path_mknod(&path, dentry, mode, dev);
57921 if (error)
57922 goto out;
57923@@ -3240,6 +3362,8 @@ retry:
57924 break;
57925 }
57926 out:
57927+ if (!error)
57928+ gr_handle_create(dentry, path.mnt);
57929 done_path_create(&path, dentry);
57930 if (retry_estale(error, lookup_flags)) {
57931 lookup_flags |= LOOKUP_REVAL;
57932@@ -3292,9 +3416,16 @@ retry:
57933
57934 if (!IS_POSIXACL(path.dentry->d_inode))
57935 mode &= ~current_umask();
57936+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57937+ error = -EACCES;
57938+ goto out;
57939+ }
57940 error = security_path_mkdir(&path, dentry, mode);
57941 if (!error)
57942 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57943+ if (!error)
57944+ gr_handle_create(dentry, path.mnt);
57945+out:
57946 done_path_create(&path, dentry);
57947 if (retry_estale(error, lookup_flags)) {
57948 lookup_flags |= LOOKUP_REVAL;
57949@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57950 struct filename *name;
57951 struct dentry *dentry;
57952 struct nameidata nd;
57953+ ino_t saved_ino = 0;
57954+ dev_t saved_dev = 0;
57955 unsigned int lookup_flags = 0;
57956 retry:
57957 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57958@@ -3407,10 +3540,21 @@ retry:
57959 error = -ENOENT;
57960 goto exit3;
57961 }
57962+
57963+ saved_ino = dentry->d_inode->i_ino;
57964+ saved_dev = gr_get_dev_from_dentry(dentry);
57965+
57966+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57967+ error = -EACCES;
57968+ goto exit3;
57969+ }
57970+
57971 error = security_path_rmdir(&nd.path, dentry);
57972 if (error)
57973 goto exit3;
57974 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57975+ if (!error && (saved_dev || saved_ino))
57976+ gr_handle_delete(saved_ino, saved_dev);
57977 exit3:
57978 dput(dentry);
57979 exit2:
57980@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57981 struct dentry *dentry;
57982 struct nameidata nd;
57983 struct inode *inode = NULL;
57984+ ino_t saved_ino = 0;
57985+ dev_t saved_dev = 0;
57986 unsigned int lookup_flags = 0;
57987 retry:
57988 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57989@@ -3502,10 +3648,22 @@ retry:
57990 if (!inode)
57991 goto slashes;
57992 ihold(inode);
57993+
57994+ if (inode->i_nlink <= 1) {
57995+ saved_ino = inode->i_ino;
57996+ saved_dev = gr_get_dev_from_dentry(dentry);
57997+ }
57998+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57999+ error = -EACCES;
58000+ goto exit2;
58001+ }
58002+
58003 error = security_path_unlink(&nd.path, dentry);
58004 if (error)
58005 goto exit2;
58006 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
58007+ if (!error && (saved_ino || saved_dev))
58008+ gr_handle_delete(saved_ino, saved_dev);
58009 exit2:
58010 dput(dentry);
58011 }
58012@@ -3583,9 +3741,17 @@ retry:
58013 if (IS_ERR(dentry))
58014 goto out_putname;
58015
58016+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
58017+ error = -EACCES;
58018+ goto out;
58019+ }
58020+
58021 error = security_path_symlink(&path, dentry, from->name);
58022 if (!error)
58023 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
58024+ if (!error)
58025+ gr_handle_create(dentry, path.mnt);
58026+out:
58027 done_path_create(&path, dentry);
58028 if (retry_estale(error, lookup_flags)) {
58029 lookup_flags |= LOOKUP_REVAL;
58030@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58031 {
58032 struct dentry *new_dentry;
58033 struct path old_path, new_path;
58034+ struct filename *to = NULL;
58035 int how = 0;
58036 int error;
58037
58038@@ -3688,7 +3855,7 @@ retry:
58039 if (error)
58040 return error;
58041
58042- new_dentry = user_path_create(newdfd, newname, &new_path,
58043+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58044 (how & LOOKUP_REVAL));
58045 error = PTR_ERR(new_dentry);
58046 if (IS_ERR(new_dentry))
58047@@ -3700,11 +3867,28 @@ retry:
58048 error = may_linkat(&old_path);
58049 if (unlikely(error))
58050 goto out_dput;
58051+
58052+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58053+ old_path.dentry->d_inode,
58054+ old_path.dentry->d_inode->i_mode, to)) {
58055+ error = -EACCES;
58056+ goto out_dput;
58057+ }
58058+
58059+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58060+ old_path.dentry, old_path.mnt, to)) {
58061+ error = -EACCES;
58062+ goto out_dput;
58063+ }
58064+
58065 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58066 if (error)
58067 goto out_dput;
58068 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58069+ if (!error)
58070+ gr_handle_create(new_dentry, new_path.mnt);
58071 out_dput:
58072+ putname(to);
58073 done_path_create(&new_path, new_dentry);
58074 if (retry_estale(error, how)) {
58075 how |= LOOKUP_REVAL;
58076@@ -3950,12 +4134,21 @@ retry:
58077 if (new_dentry == trap)
58078 goto exit5;
58079
58080+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58081+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58082+ to);
58083+ if (error)
58084+ goto exit5;
58085+
58086 error = security_path_rename(&oldnd.path, old_dentry,
58087 &newnd.path, new_dentry);
58088 if (error)
58089 goto exit5;
58090 error = vfs_rename(old_dir->d_inode, old_dentry,
58091 new_dir->d_inode, new_dentry);
58092+ if (!error)
58093+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58094+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58095 exit5:
58096 dput(new_dentry);
58097 exit4:
58098@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58099
58100 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58101 {
58102+ char tmpbuf[64];
58103+ const char *newlink;
58104 int len;
58105
58106 len = PTR_ERR(link);
58107@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58108 len = strlen(link);
58109 if (len > (unsigned) buflen)
58110 len = buflen;
58111- if (copy_to_user(buffer, link, len))
58112+
58113+ if (len < sizeof(tmpbuf)) {
58114+ memcpy(tmpbuf, link, len);
58115+ newlink = tmpbuf;
58116+ } else
58117+ newlink = link;
58118+
58119+ if (copy_to_user(buffer, newlink, len))
58120 len = -EFAULT;
58121 out:
58122 return len;
58123diff --git a/fs/namespace.c b/fs/namespace.c
58124index a45ba4f..b4c7d07 100644
58125--- a/fs/namespace.c
58126+++ b/fs/namespace.c
58127@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
58128 if (!(sb->s_flags & MS_RDONLY))
58129 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58130 up_write(&sb->s_umount);
58131+
58132+ gr_log_remount(mnt->mnt_devname, retval);
58133+
58134 return retval;
58135 }
58136
58137@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
58138 }
58139 br_write_unlock(&vfsmount_lock);
58140 namespace_unlock();
58141+
58142+ gr_log_unmount(mnt->mnt_devname, retval);
58143+
58144 return retval;
58145 }
58146
58147@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
58148 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58149 */
58150
58151-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58152+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58153 {
58154 struct path path;
58155 struct mount *mnt;
58156@@ -1342,7 +1348,7 @@ out:
58157 /*
58158 * The 2.0 compatible umount. No flags.
58159 */
58160-SYSCALL_DEFINE1(oldumount, char __user *, name)
58161+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58162 {
58163 return sys_umount(name, 0);
58164 }
58165@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58166 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58167 MS_STRICTATIME);
58168
58169+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58170+ retval = -EPERM;
58171+ goto dput_out;
58172+ }
58173+
58174+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58175+ retval = -EPERM;
58176+ goto dput_out;
58177+ }
58178+
58179 if (flags & MS_REMOUNT)
58180 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58181 data_page);
58182@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58183 dev_name, data_page);
58184 dput_out:
58185 path_put(&path);
58186+
58187+ gr_log_mount(dev_name, dir_name, retval);
58188+
58189 return retval;
58190 }
58191
58192@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58193 * number incrementing at 10Ghz will take 12,427 years to wrap which
58194 * is effectively never, so we can ignore the possibility.
58195 */
58196-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58197+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58198
58199 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58200 {
58201@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58202 kfree(new_ns);
58203 return ERR_PTR(ret);
58204 }
58205- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58206+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58207 atomic_set(&new_ns->count, 1);
58208 new_ns->root = NULL;
58209 INIT_LIST_HEAD(&new_ns->list);
58210@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58211 * Allocate a new namespace structure and populate it with contents
58212 * copied from the namespace of the passed in task structure.
58213 */
58214-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58215+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58216 struct user_namespace *user_ns, struct fs_struct *fs)
58217 {
58218 struct mnt_namespace *new_ns;
58219@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58220 }
58221 EXPORT_SYMBOL(mount_subtree);
58222
58223-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58224- char __user *, type, unsigned long, flags, void __user *, data)
58225+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58226+ const char __user *, type, unsigned long, flags, void __user *, data)
58227 {
58228 int ret;
58229 char *kernel_type;
58230@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58231 if (error)
58232 goto out2;
58233
58234+ if (gr_handle_chroot_pivot()) {
58235+ error = -EPERM;
58236+ goto out2;
58237+ }
58238+
58239 get_fs_root(current->fs, &root);
58240 old_mp = lock_mount(&old);
58241 error = PTR_ERR(old_mp);
58242@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58243 !nsown_capable(CAP_SYS_ADMIN))
58244 return -EPERM;
58245
58246- if (fs->users != 1)
58247+ if (atomic_read(&fs->users) != 1)
58248 return -EINVAL;
58249
58250 get_mnt_ns(mnt_ns);
58251diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58252index f4ccfe6..a5cf064 100644
58253--- a/fs/nfs/callback_xdr.c
58254+++ b/fs/nfs/callback_xdr.c
58255@@ -51,7 +51,7 @@ struct callback_op {
58256 callback_decode_arg_t decode_args;
58257 callback_encode_res_t encode_res;
58258 long res_maxsize;
58259-};
58260+} __do_const;
58261
58262 static struct callback_op callback_ops[];
58263
58264diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58265index 941246f..17d8724 100644
58266--- a/fs/nfs/inode.c
58267+++ b/fs/nfs/inode.c
58268@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58269 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58270 }
58271
58272-static atomic_long_t nfs_attr_generation_counter;
58273+static atomic_long_unchecked_t nfs_attr_generation_counter;
58274
58275 static unsigned long nfs_read_attr_generation_counter(void)
58276 {
58277- return atomic_long_read(&nfs_attr_generation_counter);
58278+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58279 }
58280
58281 unsigned long nfs_inc_attr_generation_counter(void)
58282 {
58283- return atomic_long_inc_return(&nfs_attr_generation_counter);
58284+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58285 }
58286
58287 void nfs_fattr_init(struct nfs_fattr *fattr)
58288diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58289index 419572f..5414a23 100644
58290--- a/fs/nfsd/nfs4proc.c
58291+++ b/fs/nfsd/nfs4proc.c
58292@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58293 nfsd4op_rsize op_rsize_bop;
58294 stateid_getter op_get_currentstateid;
58295 stateid_setter op_set_currentstateid;
58296-};
58297+} __do_const;
58298
58299 static struct nfsd4_operation nfsd4_ops[];
58300
58301diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58302index c2a4701..fd80e29 100644
58303--- a/fs/nfsd/nfs4xdr.c
58304+++ b/fs/nfsd/nfs4xdr.c
58305@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58306
58307 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58308
58309-static nfsd4_dec nfsd4_dec_ops[] = {
58310+static const nfsd4_dec nfsd4_dec_ops[] = {
58311 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58312 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58313 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58314@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58315 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58316 };
58317
58318-static nfsd4_dec nfsd41_dec_ops[] = {
58319+static const nfsd4_dec nfsd41_dec_ops[] = {
58320 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58321 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58322 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58323@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58324 };
58325
58326 struct nfsd4_minorversion_ops {
58327- nfsd4_dec *decoders;
58328+ const nfsd4_dec *decoders;
58329 int nops;
58330 };
58331
58332diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58333index e76244e..9fe8f2f1 100644
58334--- a/fs/nfsd/nfscache.c
58335+++ b/fs/nfsd/nfscache.c
58336@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58337 {
58338 struct svc_cacherep *rp = rqstp->rq_cacherep;
58339 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58340- int len;
58341+ long len;
58342 size_t bufsize = 0;
58343
58344 if (!rp)
58345 return;
58346
58347- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58348- len >>= 2;
58349+ if (statp) {
58350+ len = (char*)statp - (char*)resv->iov_base;
58351+ len = resv->iov_len - len;
58352+ len >>= 2;
58353+ }
58354
58355 /* Don't cache excessive amounts of data and XDR failures */
58356 if (!statp || len > (256 >> 2)) {
58357diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58358index c827acb..b253b77 100644
58359--- a/fs/nfsd/vfs.c
58360+++ b/fs/nfsd/vfs.c
58361@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58362 } else {
58363 oldfs = get_fs();
58364 set_fs(KERNEL_DS);
58365- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58366+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58367 set_fs(oldfs);
58368 }
58369
58370@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58371
58372 /* Write the data. */
58373 oldfs = get_fs(); set_fs(KERNEL_DS);
58374- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58375+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58376 set_fs(oldfs);
58377 if (host_err < 0)
58378 goto out_nfserr;
58379@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58380 */
58381
58382 oldfs = get_fs(); set_fs(KERNEL_DS);
58383- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58384+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58385 set_fs(oldfs);
58386
58387 if (host_err < 0)
58388diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58389index fea6bd5..8ee9d81 100644
58390--- a/fs/nls/nls_base.c
58391+++ b/fs/nls/nls_base.c
58392@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58393
58394 int register_nls(struct nls_table * nls)
58395 {
58396- struct nls_table ** tmp = &tables;
58397+ struct nls_table *tmp = tables;
58398
58399 if (nls->next)
58400 return -EBUSY;
58401
58402 spin_lock(&nls_lock);
58403- while (*tmp) {
58404- if (nls == *tmp) {
58405+ while (tmp) {
58406+ if (nls == tmp) {
58407 spin_unlock(&nls_lock);
58408 return -EBUSY;
58409 }
58410- tmp = &(*tmp)->next;
58411+ tmp = tmp->next;
58412 }
58413- nls->next = tables;
58414+ pax_open_kernel();
58415+ *(struct nls_table **)&nls->next = tables;
58416+ pax_close_kernel();
58417 tables = nls;
58418 spin_unlock(&nls_lock);
58419 return 0;
58420@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58421
58422 int unregister_nls(struct nls_table * nls)
58423 {
58424- struct nls_table ** tmp = &tables;
58425+ struct nls_table * const * tmp = &tables;
58426
58427 spin_lock(&nls_lock);
58428 while (*tmp) {
58429 if (nls == *tmp) {
58430- *tmp = nls->next;
58431+ pax_open_kernel();
58432+ *(struct nls_table **)tmp = nls->next;
58433+ pax_close_kernel();
58434 spin_unlock(&nls_lock);
58435 return 0;
58436 }
58437diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58438index 7424929..35f6be5 100644
58439--- a/fs/nls/nls_euc-jp.c
58440+++ b/fs/nls/nls_euc-jp.c
58441@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58442 p_nls = load_nls("cp932");
58443
58444 if (p_nls) {
58445- table.charset2upper = p_nls->charset2upper;
58446- table.charset2lower = p_nls->charset2lower;
58447+ pax_open_kernel();
58448+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58449+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58450+ pax_close_kernel();
58451 return register_nls(&table);
58452 }
58453
58454diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58455index e7bc1d7..06bd4bb 100644
58456--- a/fs/nls/nls_koi8-ru.c
58457+++ b/fs/nls/nls_koi8-ru.c
58458@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58459 p_nls = load_nls("koi8-u");
58460
58461 if (p_nls) {
58462- table.charset2upper = p_nls->charset2upper;
58463- table.charset2lower = p_nls->charset2lower;
58464+ pax_open_kernel();
58465+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58466+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58467+ pax_close_kernel();
58468 return register_nls(&table);
58469 }
58470
58471diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58472index e44cb64..4807084 100644
58473--- a/fs/notify/fanotify/fanotify_user.c
58474+++ b/fs/notify/fanotify/fanotify_user.c
58475@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58476
58477 fd = fanotify_event_metadata.fd;
58478 ret = -EFAULT;
58479- if (copy_to_user(buf, &fanotify_event_metadata,
58480- fanotify_event_metadata.event_len))
58481+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58482+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58483 goto out_close_fd;
58484
58485 ret = prepare_for_access_response(group, event, fd);
58486diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58487index 7b51b05..5ea5ef6 100644
58488--- a/fs/notify/notification.c
58489+++ b/fs/notify/notification.c
58490@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58491 * get set to 0 so it will never get 'freed'
58492 */
58493 static struct fsnotify_event *q_overflow_event;
58494-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58495+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58496
58497 /**
58498 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58499@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58500 */
58501 u32 fsnotify_get_cookie(void)
58502 {
58503- return atomic_inc_return(&fsnotify_sync_cookie);
58504+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58505 }
58506 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58507
58508diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58509index 9e38daf..5727cae 100644
58510--- a/fs/ntfs/dir.c
58511+++ b/fs/ntfs/dir.c
58512@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58513 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58514 ~(s64)(ndir->itype.index.block_size - 1)));
58515 /* Bounds checks. */
58516- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58517+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58518 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58519 "inode 0x%lx or driver bug.", vdir->i_ino);
58520 goto err_out;
58521diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58522index c5670b8..d590213 100644
58523--- a/fs/ntfs/file.c
58524+++ b/fs/ntfs/file.c
58525@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58526 char *addr;
58527 size_t total = 0;
58528 unsigned len;
58529- int left;
58530+ unsigned left;
58531
58532 do {
58533 len = PAGE_CACHE_SIZE - ofs;
58534diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58535index 82650d5..db37dcf 100644
58536--- a/fs/ntfs/super.c
58537+++ b/fs/ntfs/super.c
58538@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58539 if (!silent)
58540 ntfs_error(sb, "Primary boot sector is invalid.");
58541 } else if (!silent)
58542- ntfs_error(sb, read_err_str, "primary");
58543+ ntfs_error(sb, read_err_str, "%s", "primary");
58544 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58545 if (bh_primary)
58546 brelse(bh_primary);
58547@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58548 goto hotfix_primary_boot_sector;
58549 brelse(bh_backup);
58550 } else if (!silent)
58551- ntfs_error(sb, read_err_str, "backup");
58552+ ntfs_error(sb, read_err_str, "%s", "backup");
58553 /* Try to read NT3.51- backup boot sector. */
58554 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58555 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58556@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58557 "sector.");
58558 brelse(bh_backup);
58559 } else if (!silent)
58560- ntfs_error(sb, read_err_str, "backup");
58561+ ntfs_error(sb, read_err_str, "%s", "backup");
58562 /* We failed. Cleanup and return. */
58563 if (bh_primary)
58564 brelse(bh_primary);
58565diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58566index aebeacd..0dcdd26 100644
58567--- a/fs/ocfs2/localalloc.c
58568+++ b/fs/ocfs2/localalloc.c
58569@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58570 goto bail;
58571 }
58572
58573- atomic_inc(&osb->alloc_stats.moves);
58574+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58575
58576 bail:
58577 if (handle)
58578diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58579index 3a90347..c40bef8 100644
58580--- a/fs/ocfs2/ocfs2.h
58581+++ b/fs/ocfs2/ocfs2.h
58582@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58583
58584 struct ocfs2_alloc_stats
58585 {
58586- atomic_t moves;
58587- atomic_t local_data;
58588- atomic_t bitmap_data;
58589- atomic_t bg_allocs;
58590- atomic_t bg_extends;
58591+ atomic_unchecked_t moves;
58592+ atomic_unchecked_t local_data;
58593+ atomic_unchecked_t bitmap_data;
58594+ atomic_unchecked_t bg_allocs;
58595+ atomic_unchecked_t bg_extends;
58596 };
58597
58598 enum ocfs2_local_alloc_state
58599diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58600index 5397c07..54afc55 100644
58601--- a/fs/ocfs2/suballoc.c
58602+++ b/fs/ocfs2/suballoc.c
58603@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58604 mlog_errno(status);
58605 goto bail;
58606 }
58607- atomic_inc(&osb->alloc_stats.bg_extends);
58608+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58609
58610 /* You should never ask for this much metadata */
58611 BUG_ON(bits_wanted >
58612@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58613 mlog_errno(status);
58614 goto bail;
58615 }
58616- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58617+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58618
58619 *suballoc_loc = res.sr_bg_blkno;
58620 *suballoc_bit_start = res.sr_bit_offset;
58621@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58622 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58623 res->sr_bits);
58624
58625- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58626+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58627
58628 BUG_ON(res->sr_bits != 1);
58629
58630@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58631 mlog_errno(status);
58632 goto bail;
58633 }
58634- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58635+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58636
58637 BUG_ON(res.sr_bits != 1);
58638
58639@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58640 cluster_start,
58641 num_clusters);
58642 if (!status)
58643- atomic_inc(&osb->alloc_stats.local_data);
58644+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58645 } else {
58646 if (min_clusters > (osb->bitmap_cpg - 1)) {
58647 /* The only paths asking for contiguousness
58648@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58649 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58650 res.sr_bg_blkno,
58651 res.sr_bit_offset);
58652- atomic_inc(&osb->alloc_stats.bitmap_data);
58653+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58654 *num_clusters = res.sr_bits;
58655 }
58656 }
58657diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58658index 121da2d..a0232bc 100644
58659--- a/fs/ocfs2/super.c
58660+++ b/fs/ocfs2/super.c
58661@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58662 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58663 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58664 "Stats",
58665- atomic_read(&osb->alloc_stats.bitmap_data),
58666- atomic_read(&osb->alloc_stats.local_data),
58667- atomic_read(&osb->alloc_stats.bg_allocs),
58668- atomic_read(&osb->alloc_stats.moves),
58669- atomic_read(&osb->alloc_stats.bg_extends));
58670+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58671+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58672+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58673+ atomic_read_unchecked(&osb->alloc_stats.moves),
58674+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58675
58676 out += snprintf(buf + out, len - out,
58677 "%10s => State: %u Descriptor: %llu Size: %u bits "
58678@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58679 spin_lock_init(&osb->osb_xattr_lock);
58680 ocfs2_init_steal_slots(osb);
58681
58682- atomic_set(&osb->alloc_stats.moves, 0);
58683- atomic_set(&osb->alloc_stats.local_data, 0);
58684- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58685- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58686- atomic_set(&osb->alloc_stats.bg_extends, 0);
58687+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58688+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58689+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58690+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58691+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58692
58693 /* Copy the blockcheck stats from the superblock probe */
58694 osb->osb_ecc_stats = *stats;
58695diff --git a/fs/open.c b/fs/open.c
58696index 7931f76..7b03f3b 100644
58697--- a/fs/open.c
58698+++ b/fs/open.c
58699@@ -32,6 +32,8 @@
58700 #include <linux/dnotify.h>
58701 #include <linux/compat.h>
58702
58703+#define CREATE_TRACE_POINTS
58704+#include <trace/events/fs.h>
58705 #include "internal.h"
58706
58707 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58708@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58709 error = locks_verify_truncate(inode, NULL, length);
58710 if (!error)
58711 error = security_path_truncate(path);
58712+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58713+ error = -EACCES;
58714 if (!error)
58715 error = do_truncate(path->dentry, length, 0, NULL);
58716
58717@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58718 error = locks_verify_truncate(inode, f.file, length);
58719 if (!error)
58720 error = security_path_truncate(&f.file->f_path);
58721+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58722+ error = -EACCES;
58723 if (!error)
58724 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58725 sb_end_write(inode->i_sb);
58726@@ -360,6 +366,9 @@ retry:
58727 if (__mnt_is_readonly(path.mnt))
58728 res = -EROFS;
58729
58730+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58731+ res = -EACCES;
58732+
58733 out_path_release:
58734 path_put(&path);
58735 if (retry_estale(res, lookup_flags)) {
58736@@ -391,6 +400,8 @@ retry:
58737 if (error)
58738 goto dput_and_out;
58739
58740+ gr_log_chdir(path.dentry, path.mnt);
58741+
58742 set_fs_pwd(current->fs, &path);
58743
58744 dput_and_out:
58745@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58746 goto out_putf;
58747
58748 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58749+
58750+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58751+ error = -EPERM;
58752+
58753+ if (!error)
58754+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58755+
58756 if (!error)
58757 set_fs_pwd(current->fs, &f.file->f_path);
58758 out_putf:
58759@@ -449,7 +467,13 @@ retry:
58760 if (error)
58761 goto dput_and_out;
58762
58763+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58764+ goto dput_and_out;
58765+
58766 set_fs_root(current->fs, &path);
58767+
58768+ gr_handle_chroot_chdir(&path);
58769+
58770 error = 0;
58771 dput_and_out:
58772 path_put(&path);
58773@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58774 if (error)
58775 return error;
58776 mutex_lock(&inode->i_mutex);
58777+
58778+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58779+ error = -EACCES;
58780+ goto out_unlock;
58781+ }
58782+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58783+ error = -EACCES;
58784+ goto out_unlock;
58785+ }
58786+
58787 error = security_path_chmod(path, mode);
58788 if (error)
58789 goto out_unlock;
58790@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58791 uid = make_kuid(current_user_ns(), user);
58792 gid = make_kgid(current_user_ns(), group);
58793
58794+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58795+ return -EACCES;
58796+
58797 newattrs.ia_valid = ATTR_CTIME;
58798 if (user != (uid_t) -1) {
58799 if (!uid_valid(uid))
58800@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58801 } else {
58802 fsnotify_open(f);
58803 fd_install(fd, f);
58804+ trace_do_sys_open(tmp->name, flags, mode);
58805 }
58806 }
58807 putname(tmp);
58808diff --git a/fs/pipe.c b/fs/pipe.c
58809index d2c45e1..009fe1c 100644
58810--- a/fs/pipe.c
58811+++ b/fs/pipe.c
58812@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58813
58814 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58815 {
58816- if (pipe->files)
58817+ if (atomic_read(&pipe->files))
58818 mutex_lock_nested(&pipe->mutex, subclass);
58819 }
58820
58821@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58822
58823 void pipe_unlock(struct pipe_inode_info *pipe)
58824 {
58825- if (pipe->files)
58826+ if (atomic_read(&pipe->files))
58827 mutex_unlock(&pipe->mutex);
58828 }
58829 EXPORT_SYMBOL(pipe_unlock);
58830@@ -449,9 +449,9 @@ redo:
58831 }
58832 if (bufs) /* More to do? */
58833 continue;
58834- if (!pipe->writers)
58835+ if (!atomic_read(&pipe->writers))
58836 break;
58837- if (!pipe->waiting_writers) {
58838+ if (!atomic_read(&pipe->waiting_writers)) {
58839 /* syscall merging: Usually we must not sleep
58840 * if O_NONBLOCK is set, or if we got some data.
58841 * But if a writer sleeps in kernel space, then
58842@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58843 ret = 0;
58844 __pipe_lock(pipe);
58845
58846- if (!pipe->readers) {
58847+ if (!atomic_read(&pipe->readers)) {
58848 send_sig(SIGPIPE, current, 0);
58849 ret = -EPIPE;
58850 goto out;
58851@@ -562,7 +562,7 @@ redo1:
58852 for (;;) {
58853 int bufs;
58854
58855- if (!pipe->readers) {
58856+ if (!atomic_read(&pipe->readers)) {
58857 send_sig(SIGPIPE, current, 0);
58858 if (!ret)
58859 ret = -EPIPE;
58860@@ -653,9 +653,9 @@ redo2:
58861 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58862 do_wakeup = 0;
58863 }
58864- pipe->waiting_writers++;
58865+ atomic_inc(&pipe->waiting_writers);
58866 pipe_wait(pipe);
58867- pipe->waiting_writers--;
58868+ atomic_dec(&pipe->waiting_writers);
58869 }
58870 out:
58871 __pipe_unlock(pipe);
58872@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58873 mask = 0;
58874 if (filp->f_mode & FMODE_READ) {
58875 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58876- if (!pipe->writers && filp->f_version != pipe->w_counter)
58877+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58878 mask |= POLLHUP;
58879 }
58880
58881@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58882 * Most Unices do not set POLLERR for FIFOs but on Linux they
58883 * behave exactly like pipes for poll().
58884 */
58885- if (!pipe->readers)
58886+ if (!atomic_read(&pipe->readers))
58887 mask |= POLLERR;
58888 }
58889
58890@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58891
58892 __pipe_lock(pipe);
58893 if (file->f_mode & FMODE_READ)
58894- pipe->readers--;
58895+ atomic_dec(&pipe->readers);
58896 if (file->f_mode & FMODE_WRITE)
58897- pipe->writers--;
58898+ atomic_dec(&pipe->writers);
58899
58900- if (pipe->readers || pipe->writers) {
58901+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58902 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58903 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58904 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58905 }
58906 spin_lock(&inode->i_lock);
58907- if (!--pipe->files) {
58908+ if (atomic_dec_and_test(&pipe->files)) {
58909 inode->i_pipe = NULL;
58910 kill = 1;
58911 }
58912@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58913 kfree(pipe);
58914 }
58915
58916-static struct vfsmount *pipe_mnt __read_mostly;
58917+struct vfsmount *pipe_mnt __read_mostly;
58918
58919 /*
58920 * pipefs_dname() is called from d_path().
58921@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58922 goto fail_iput;
58923
58924 inode->i_pipe = pipe;
58925- pipe->files = 2;
58926- pipe->readers = pipe->writers = 1;
58927+ atomic_set(&pipe->files, 2);
58928+ atomic_set(&pipe->readers, 1);
58929+ atomic_set(&pipe->writers, 1);
58930 inode->i_fop = &pipefifo_fops;
58931
58932 /*
58933@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58934 spin_lock(&inode->i_lock);
58935 if (inode->i_pipe) {
58936 pipe = inode->i_pipe;
58937- pipe->files++;
58938+ atomic_inc(&pipe->files);
58939 spin_unlock(&inode->i_lock);
58940 } else {
58941 spin_unlock(&inode->i_lock);
58942 pipe = alloc_pipe_info();
58943 if (!pipe)
58944 return -ENOMEM;
58945- pipe->files = 1;
58946+ atomic_set(&pipe->files, 1);
58947 spin_lock(&inode->i_lock);
58948 if (unlikely(inode->i_pipe)) {
58949- inode->i_pipe->files++;
58950+ atomic_inc(&inode->i_pipe->files);
58951 spin_unlock(&inode->i_lock);
58952 free_pipe_info(pipe);
58953 pipe = inode->i_pipe;
58954@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58955 * opened, even when there is no process writing the FIFO.
58956 */
58957 pipe->r_counter++;
58958- if (pipe->readers++ == 0)
58959+ if (atomic_inc_return(&pipe->readers) == 1)
58960 wake_up_partner(pipe);
58961
58962- if (!is_pipe && !pipe->writers) {
58963+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58964 if ((filp->f_flags & O_NONBLOCK)) {
58965 /* suppress POLLHUP until we have
58966 * seen a writer */
58967@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58968 * errno=ENXIO when there is no process reading the FIFO.
58969 */
58970 ret = -ENXIO;
58971- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58972+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58973 goto err;
58974
58975 pipe->w_counter++;
58976- if (!pipe->writers++)
58977+ if (atomic_inc_return(&pipe->writers) == 1)
58978 wake_up_partner(pipe);
58979
58980- if (!is_pipe && !pipe->readers) {
58981+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58982 if (wait_for_partner(pipe, &pipe->r_counter))
58983 goto err_wr;
58984 }
58985@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58986 * the process can at least talk to itself.
58987 */
58988
58989- pipe->readers++;
58990- pipe->writers++;
58991+ atomic_inc(&pipe->readers);
58992+ atomic_inc(&pipe->writers);
58993 pipe->r_counter++;
58994 pipe->w_counter++;
58995- if (pipe->readers == 1 || pipe->writers == 1)
58996+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58997 wake_up_partner(pipe);
58998 break;
58999
59000@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
59001 return 0;
59002
59003 err_rd:
59004- if (!--pipe->readers)
59005+ if (atomic_dec_and_test(&pipe->readers))
59006 wake_up_interruptible(&pipe->wait);
59007 ret = -ERESTARTSYS;
59008 goto err;
59009
59010 err_wr:
59011- if (!--pipe->writers)
59012+ if (atomic_dec_and_test(&pipe->writers))
59013 wake_up_interruptible(&pipe->wait);
59014 ret = -ERESTARTSYS;
59015 goto err;
59016
59017 err:
59018 spin_lock(&inode->i_lock);
59019- if (!--pipe->files) {
59020+ if (atomic_dec_and_test(&pipe->files)) {
59021 inode->i_pipe = NULL;
59022 kill = 1;
59023 }
59024diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
59025index 15af622..0e9f4467 100644
59026--- a/fs/proc/Kconfig
59027+++ b/fs/proc/Kconfig
59028@@ -30,12 +30,12 @@ config PROC_FS
59029
59030 config PROC_KCORE
59031 bool "/proc/kcore support" if !ARM
59032- depends on PROC_FS && MMU
59033+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
59034
59035 config PROC_VMCORE
59036 bool "/proc/vmcore support"
59037- depends on PROC_FS && CRASH_DUMP
59038- default y
59039+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
59040+ default n
59041 help
59042 Exports the dump image of crashed kernel in ELF format.
59043
59044@@ -59,8 +59,8 @@ config PROC_SYSCTL
59045 limited in memory.
59046
59047 config PROC_PAGE_MONITOR
59048- default y
59049- depends on PROC_FS && MMU
59050+ default n
59051+ depends on PROC_FS && MMU && !GRKERNSEC
59052 bool "Enable /proc page monitoring" if EXPERT
59053 help
59054 Various /proc files exist to monitor process memory utilization:
59055diff --git a/fs/proc/array.c b/fs/proc/array.c
59056index cbd0f1b..adec3f0 100644
59057--- a/fs/proc/array.c
59058+++ b/fs/proc/array.c
59059@@ -60,6 +60,7 @@
59060 #include <linux/tty.h>
59061 #include <linux/string.h>
59062 #include <linux/mman.h>
59063+#include <linux/grsecurity.h>
59064 #include <linux/proc_fs.h>
59065 #include <linux/ioport.h>
59066 #include <linux/uaccess.h>
59067@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
59068 seq_putc(m, '\n');
59069 }
59070
59071+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59072+static inline void task_pax(struct seq_file *m, struct task_struct *p)
59073+{
59074+ if (p->mm)
59075+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
59076+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
59077+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
59078+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
59079+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
59080+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
59081+ else
59082+ seq_printf(m, "PaX:\t-----\n");
59083+}
59084+#endif
59085+
59086 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59087 struct pid *pid, struct task_struct *task)
59088 {
59089@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59090 task_cpus_allowed(m, task);
59091 cpuset_task_status_allowed(m, task);
59092 task_context_switch_counts(m, task);
59093+
59094+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59095+ task_pax(m, task);
59096+#endif
59097+
59098+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
59099+ task_grsec_rbac(m, task);
59100+#endif
59101+
59102 return 0;
59103 }
59104
59105+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59106+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59107+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59108+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59109+#endif
59110+
59111 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59112 struct pid *pid, struct task_struct *task, int whole)
59113 {
59114@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59115 char tcomm[sizeof(task->comm)];
59116 unsigned long flags;
59117
59118+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59119+ if (current->exec_id != m->exec_id) {
59120+ gr_log_badprocpid("stat");
59121+ return 0;
59122+ }
59123+#endif
59124+
59125 state = *get_task_state(task);
59126 vsize = eip = esp = 0;
59127 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59128@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59129 gtime = task_gtime(task);
59130 }
59131
59132+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59133+ if (PAX_RAND_FLAGS(mm)) {
59134+ eip = 0;
59135+ esp = 0;
59136+ wchan = 0;
59137+ }
59138+#endif
59139+#ifdef CONFIG_GRKERNSEC_HIDESYM
59140+ wchan = 0;
59141+ eip =0;
59142+ esp =0;
59143+#endif
59144+
59145 /* scale priority and nice values from timeslices to -20..20 */
59146 /* to make it look like a "normal" Unix priority/nice value */
59147 priority = task_prio(task);
59148@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59149 seq_put_decimal_ull(m, ' ', vsize);
59150 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59151 seq_put_decimal_ull(m, ' ', rsslim);
59152+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59153+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59154+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59155+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59156+#else
59157 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59158 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59159 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59160+#endif
59161 seq_put_decimal_ull(m, ' ', esp);
59162 seq_put_decimal_ull(m, ' ', eip);
59163 /* The signal information here is obsolete.
59164@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59165 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59166 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59167
59168- if (mm && permitted) {
59169+ if (mm && permitted
59170+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59171+ && !PAX_RAND_FLAGS(mm)
59172+#endif
59173+ ) {
59174 seq_put_decimal_ull(m, ' ', mm->start_data);
59175 seq_put_decimal_ull(m, ' ', mm->end_data);
59176 seq_put_decimal_ull(m, ' ', mm->start_brk);
59177@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59178 struct pid *pid, struct task_struct *task)
59179 {
59180 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59181- struct mm_struct *mm = get_task_mm(task);
59182+ struct mm_struct *mm;
59183
59184+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59185+ if (current->exec_id != m->exec_id) {
59186+ gr_log_badprocpid("statm");
59187+ return 0;
59188+ }
59189+#endif
59190+ mm = get_task_mm(task);
59191 if (mm) {
59192 size = task_statm(mm, &shared, &text, &data, &resident);
59193 mmput(mm);
59194@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59195 return 0;
59196 }
59197
59198+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59199+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59200+{
59201+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59202+}
59203+#endif
59204+
59205 #ifdef CONFIG_CHECKPOINT_RESTORE
59206 static struct pid *
59207 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59208diff --git a/fs/proc/base.c b/fs/proc/base.c
59209index 1485e38..8ad4236 100644
59210--- a/fs/proc/base.c
59211+++ b/fs/proc/base.c
59212@@ -113,6 +113,14 @@ struct pid_entry {
59213 union proc_op op;
59214 };
59215
59216+struct getdents_callback {
59217+ struct linux_dirent __user * current_dir;
59218+ struct linux_dirent __user * previous;
59219+ struct file * file;
59220+ int count;
59221+ int error;
59222+};
59223+
59224 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59225 .name = (NAME), \
59226 .len = sizeof(NAME) - 1, \
59227@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59228 if (!mm->arg_end)
59229 goto out_mm; /* Shh! No looking before we're done */
59230
59231+ if (gr_acl_handle_procpidmem(task))
59232+ goto out_mm;
59233+
59234 len = mm->arg_end - mm->arg_start;
59235
59236 if (len > PAGE_SIZE)
59237@@ -237,12 +248,28 @@ out:
59238 return res;
59239 }
59240
59241+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59242+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59243+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59244+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59245+#endif
59246+
59247 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59248 {
59249 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59250 int res = PTR_ERR(mm);
59251 if (mm && !IS_ERR(mm)) {
59252 unsigned int nwords = 0;
59253+
59254+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59255+ /* allow if we're currently ptracing this task */
59256+ if (PAX_RAND_FLAGS(mm) &&
59257+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59258+ mmput(mm);
59259+ return 0;
59260+ }
59261+#endif
59262+
59263 do {
59264 nwords += 2;
59265 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59266@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59267 }
59268
59269
59270-#ifdef CONFIG_KALLSYMS
59271+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59272 /*
59273 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59274 * Returns the resolved symbol. If that fails, simply return the address.
59275@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59276 mutex_unlock(&task->signal->cred_guard_mutex);
59277 }
59278
59279-#ifdef CONFIG_STACKTRACE
59280+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59281
59282 #define MAX_STACK_TRACE_DEPTH 64
59283
59284@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59285 return count;
59286 }
59287
59288-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59289+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59290 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59291 {
59292 long nr;
59293@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59294 /************************************************************************/
59295
59296 /* permission checks */
59297-static int proc_fd_access_allowed(struct inode *inode)
59298+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59299 {
59300 struct task_struct *task;
59301 int allowed = 0;
59302@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59303 */
59304 task = get_proc_task(inode);
59305 if (task) {
59306- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59307+ if (log)
59308+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59309+ else
59310+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59311 put_task_struct(task);
59312 }
59313 return allowed;
59314@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59315 struct task_struct *task,
59316 int hide_pid_min)
59317 {
59318+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59319+ return false;
59320+
59321+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59322+ rcu_read_lock();
59323+ {
59324+ const struct cred *tmpcred = current_cred();
59325+ const struct cred *cred = __task_cred(task);
59326+
59327+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59328+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59329+ || in_group_p(grsec_proc_gid)
59330+#endif
59331+ ) {
59332+ rcu_read_unlock();
59333+ return true;
59334+ }
59335+ }
59336+ rcu_read_unlock();
59337+
59338+ if (!pid->hide_pid)
59339+ return false;
59340+#endif
59341+
59342 if (pid->hide_pid < hide_pid_min)
59343 return true;
59344 if (in_group_p(pid->pid_gid))
59345 return true;
59346+
59347 return ptrace_may_access(task, PTRACE_MODE_READ);
59348 }
59349
59350@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59351 put_task_struct(task);
59352
59353 if (!has_perms) {
59354+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59355+ {
59356+#else
59357 if (pid->hide_pid == 2) {
59358+#endif
59359 /*
59360 * Let's make getdents(), stat(), and open()
59361 * consistent with each other. If a process
59362@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59363 if (!task)
59364 return -ESRCH;
59365
59366+ if (gr_acl_handle_procpidmem(task)) {
59367+ put_task_struct(task);
59368+ return -EPERM;
59369+ }
59370+
59371 mm = mm_access(task, mode);
59372 put_task_struct(task);
59373
59374@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59375
59376 file->private_data = mm;
59377
59378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59379+ file->f_version = current->exec_id;
59380+#endif
59381+
59382 return 0;
59383 }
59384
59385@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59386 ssize_t copied;
59387 char *page;
59388
59389+#ifdef CONFIG_GRKERNSEC
59390+ if (write)
59391+ return -EPERM;
59392+#endif
59393+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59394+ if (file->f_version != current->exec_id) {
59395+ gr_log_badprocpid("mem");
59396+ return 0;
59397+ }
59398+#endif
59399+
59400 if (!mm)
59401 return 0;
59402
59403@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59404 goto free;
59405
59406 while (count > 0) {
59407- int this_len = min_t(int, count, PAGE_SIZE);
59408+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59409
59410 if (write && copy_from_user(page, buf, this_len)) {
59411 copied = -EFAULT;
59412@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59413 if (!mm)
59414 return 0;
59415
59416+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59417+ if (file->f_version != current->exec_id) {
59418+ gr_log_badprocpid("environ");
59419+ return 0;
59420+ }
59421+#endif
59422+
59423 page = (char *)__get_free_page(GFP_TEMPORARY);
59424 if (!page)
59425 return -ENOMEM;
59426@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59427 goto free;
59428 while (count > 0) {
59429 size_t this_len, max_len;
59430- int retval;
59431+ ssize_t retval;
59432
59433 if (src >= (mm->env_end - mm->env_start))
59434 break;
59435@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59436 int error = -EACCES;
59437
59438 /* Are we allowed to snoop on the tasks file descriptors? */
59439- if (!proc_fd_access_allowed(inode))
59440+ if (!proc_fd_access_allowed(inode, 0))
59441 goto out;
59442
59443 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59444@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59445 struct path path;
59446
59447 /* Are we allowed to snoop on the tasks file descriptors? */
59448- if (!proc_fd_access_allowed(inode))
59449- goto out;
59450+ /* logging this is needed for learning on chromium to work properly,
59451+ but we don't want to flood the logs from 'ps' which does a readlink
59452+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59453+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59454+ */
59455+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59456+ if (!proc_fd_access_allowed(inode,0))
59457+ goto out;
59458+ } else {
59459+ if (!proc_fd_access_allowed(inode,1))
59460+ goto out;
59461+ }
59462
59463 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59464 if (error)
59465@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59466 rcu_read_lock();
59467 cred = __task_cred(task);
59468 inode->i_uid = cred->euid;
59469+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59470+ inode->i_gid = grsec_proc_gid;
59471+#else
59472 inode->i_gid = cred->egid;
59473+#endif
59474 rcu_read_unlock();
59475 }
59476 security_task_to_inode(task, inode);
59477@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59478 return -ENOENT;
59479 }
59480 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59481+#ifdef CONFIG_GRKERNSEC_PROC_USER
59482+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59483+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59484+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59485+#endif
59486 task_dumpable(task)) {
59487 cred = __task_cred(task);
59488 stat->uid = cred->euid;
59489+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59490+ stat->gid = grsec_proc_gid;
59491+#else
59492 stat->gid = cred->egid;
59493+#endif
59494 }
59495 }
59496 rcu_read_unlock();
59497@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59498
59499 if (task) {
59500 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59501+#ifdef CONFIG_GRKERNSEC_PROC_USER
59502+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59503+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59504+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59505+#endif
59506 task_dumpable(task)) {
59507 rcu_read_lock();
59508 cred = __task_cred(task);
59509 inode->i_uid = cred->euid;
59510+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59511+ inode->i_gid = grsec_proc_gid;
59512+#else
59513 inode->i_gid = cred->egid;
59514+#endif
59515 rcu_read_unlock();
59516 } else {
59517 inode->i_uid = GLOBAL_ROOT_UID;
59518@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59519 if (!task)
59520 goto out_no_task;
59521
59522+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59523+ goto out;
59524+
59525 /*
59526 * Yes, it does not scale. And it should not. Don't add
59527 * new entries into /proc/<tgid>/ without very good reasons.
59528@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59529 if (!task)
59530 return -ENOENT;
59531
59532+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59533+ goto out;
59534+
59535 if (!dir_emit_dots(file, ctx))
59536 goto out;
59537
59538@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59539 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59540 #endif
59541 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59542-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59543+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59544 INF("syscall", S_IRUGO, proc_pid_syscall),
59545 #endif
59546 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59547@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59548 #ifdef CONFIG_SECURITY
59549 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59550 #endif
59551-#ifdef CONFIG_KALLSYMS
59552+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59553 INF("wchan", S_IRUGO, proc_pid_wchan),
59554 #endif
59555-#ifdef CONFIG_STACKTRACE
59556+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59557 ONE("stack", S_IRUGO, proc_pid_stack),
59558 #endif
59559 #ifdef CONFIG_SCHEDSTATS
59560@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59561 #ifdef CONFIG_HARDWALL
59562 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59563 #endif
59564+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59565+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59566+#endif
59567 #ifdef CONFIG_USER_NS
59568 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59569 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59570@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59571 if (!inode)
59572 goto out;
59573
59574+#ifdef CONFIG_GRKERNSEC_PROC_USER
59575+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59576+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59577+ inode->i_gid = grsec_proc_gid;
59578+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59579+#else
59580 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59581+#endif
59582 inode->i_op = &proc_tgid_base_inode_operations;
59583 inode->i_fop = &proc_tgid_base_operations;
59584 inode->i_flags|=S_IMMUTABLE;
59585@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59586 if (!task)
59587 goto out;
59588
59589+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59590+ goto out_put_task;
59591+
59592 result = proc_pid_instantiate(dir, dentry, task, NULL);
59593+out_put_task:
59594 put_task_struct(task);
59595 out:
59596 return ERR_PTR(result);
59597@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59598 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59599 #endif
59600 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59601-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59602+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59603 INF("syscall", S_IRUGO, proc_pid_syscall),
59604 #endif
59605 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59606@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59607 #ifdef CONFIG_SECURITY
59608 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59609 #endif
59610-#ifdef CONFIG_KALLSYMS
59611+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59612 INF("wchan", S_IRUGO, proc_pid_wchan),
59613 #endif
59614-#ifdef CONFIG_STACKTRACE
59615+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59616 ONE("stack", S_IRUGO, proc_pid_stack),
59617 #endif
59618 #ifdef CONFIG_SCHEDSTATS
59619diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59620index 82676e3..5f8518a 100644
59621--- a/fs/proc/cmdline.c
59622+++ b/fs/proc/cmdline.c
59623@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59624
59625 static int __init proc_cmdline_init(void)
59626 {
59627+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59628+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59629+#else
59630 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59631+#endif
59632 return 0;
59633 }
59634 module_init(proc_cmdline_init);
59635diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59636index b143471..bb105e5 100644
59637--- a/fs/proc/devices.c
59638+++ b/fs/proc/devices.c
59639@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59640
59641 static int __init proc_devices_init(void)
59642 {
59643+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59644+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59645+#else
59646 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59647+#endif
59648 return 0;
59649 }
59650 module_init(proc_devices_init);
59651diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59652index 0ff80f9..a1d7500 100644
59653--- a/fs/proc/fd.c
59654+++ b/fs/proc/fd.c
59655@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59656 if (!task)
59657 return -ENOENT;
59658
59659- files = get_files_struct(task);
59660+ if (!gr_acl_handle_procpidmem(task))
59661+ files = get_files_struct(task);
59662 put_task_struct(task);
59663
59664 if (files) {
59665@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59666 */
59667 int proc_fd_permission(struct inode *inode, int mask)
59668 {
59669+ struct task_struct *task;
59670 int rv = generic_permission(inode, mask);
59671- if (rv == 0)
59672- return 0;
59673+
59674 if (task_pid(current) == proc_pid(inode))
59675 rv = 0;
59676+
59677+ task = get_proc_task(inode);
59678+ if (task == NULL)
59679+ return rv;
59680+
59681+ if (gr_acl_handle_procpidmem(task))
59682+ rv = -EACCES;
59683+
59684+ put_task_struct(task);
59685+
59686 return rv;
59687 }
59688
59689diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59690index 073aea6..0630370 100644
59691--- a/fs/proc/inode.c
59692+++ b/fs/proc/inode.c
59693@@ -23,11 +23,17 @@
59694 #include <linux/slab.h>
59695 #include <linux/mount.h>
59696 #include <linux/magic.h>
59697+#include <linux/grsecurity.h>
59698
59699 #include <asm/uaccess.h>
59700
59701 #include "internal.h"
59702
59703+#ifdef CONFIG_PROC_SYSCTL
59704+extern const struct inode_operations proc_sys_inode_operations;
59705+extern const struct inode_operations proc_sys_dir_operations;
59706+#endif
59707+
59708 static void proc_evict_inode(struct inode *inode)
59709 {
59710 struct proc_dir_entry *de;
59711@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59712 ns = PROC_I(inode)->ns.ns;
59713 if (ns_ops && ns)
59714 ns_ops->put(ns);
59715+
59716+#ifdef CONFIG_PROC_SYSCTL
59717+ if (inode->i_op == &proc_sys_inode_operations ||
59718+ inode->i_op == &proc_sys_dir_operations)
59719+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59720+#endif
59721+
59722 }
59723
59724 static struct kmem_cache * proc_inode_cachep;
59725@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59726 if (de->mode) {
59727 inode->i_mode = de->mode;
59728 inode->i_uid = de->uid;
59729+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59730+ inode->i_gid = grsec_proc_gid;
59731+#else
59732 inode->i_gid = de->gid;
59733+#endif
59734 }
59735 if (de->size)
59736 inode->i_size = de->size;
59737diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59738index 651d09a..60c73ae 100644
59739--- a/fs/proc/internal.h
59740+++ b/fs/proc/internal.h
59741@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59742 struct pid *, struct task_struct *);
59743 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59744 struct pid *, struct task_struct *);
59745+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59746+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59747+#endif
59748
59749 /*
59750 * base.c
59751diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59752index 06ea155..9a798c7 100644
59753--- a/fs/proc/kcore.c
59754+++ b/fs/proc/kcore.c
59755@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59756 * the addresses in the elf_phdr on our list.
59757 */
59758 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59759- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59760+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59761+ if (tsz > buflen)
59762 tsz = buflen;
59763-
59764+
59765 while (buflen) {
59766 struct kcore_list *m;
59767
59768@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59769 kfree(elf_buf);
59770 } else {
59771 if (kern_addr_valid(start)) {
59772- unsigned long n;
59773+ char *elf_buf;
59774+ mm_segment_t oldfs;
59775
59776- n = copy_to_user(buffer, (char *)start, tsz);
59777- /*
59778- * We cannot distinguish between fault on source
59779- * and fault on destination. When this happens
59780- * we clear too and hope it will trigger the
59781- * EFAULT again.
59782- */
59783- if (n) {
59784- if (clear_user(buffer + tsz - n,
59785- n))
59786+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59787+ if (!elf_buf)
59788+ return -ENOMEM;
59789+ oldfs = get_fs();
59790+ set_fs(KERNEL_DS);
59791+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59792+ set_fs(oldfs);
59793+ if (copy_to_user(buffer, elf_buf, tsz)) {
59794+ kfree(elf_buf);
59795 return -EFAULT;
59796+ }
59797 }
59798+ set_fs(oldfs);
59799+ kfree(elf_buf);
59800 } else {
59801 if (clear_user(buffer, tsz))
59802 return -EFAULT;
59803@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59804
59805 static int open_kcore(struct inode *inode, struct file *filp)
59806 {
59807+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59808+ return -EPERM;
59809+#endif
59810 if (!capable(CAP_SYS_RAWIO))
59811 return -EPERM;
59812 if (kcore_need_update)
59813diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59814index 5aa847a..f77c8d4 100644
59815--- a/fs/proc/meminfo.c
59816+++ b/fs/proc/meminfo.c
59817@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59818 vmi.used >> 10,
59819 vmi.largest_chunk >> 10
59820 #ifdef CONFIG_MEMORY_FAILURE
59821- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59822+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59823 #endif
59824 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59825 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59826diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59827index ccfd99b..1b7e255 100644
59828--- a/fs/proc/nommu.c
59829+++ b/fs/proc/nommu.c
59830@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59831 if (len < 1)
59832 len = 1;
59833 seq_printf(m, "%*c", len, ' ');
59834- seq_path(m, &file->f_path, "");
59835+ seq_path(m, &file->f_path, "\n\\");
59836 }
59837
59838 seq_putc(m, '\n');
59839diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59840index 4677bb7..408e936 100644
59841--- a/fs/proc/proc_net.c
59842+++ b/fs/proc/proc_net.c
59843@@ -23,6 +23,7 @@
59844 #include <linux/nsproxy.h>
59845 #include <net/net_namespace.h>
59846 #include <linux/seq_file.h>
59847+#include <linux/grsecurity.h>
59848
59849 #include "internal.h"
59850
59851@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59852 struct task_struct *task;
59853 struct nsproxy *ns;
59854 struct net *net = NULL;
59855+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59856+ const struct cred *cred = current_cred();
59857+#endif
59858+
59859+#ifdef CONFIG_GRKERNSEC_PROC_USER
59860+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59861+ return net;
59862+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59863+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59864+ return net;
59865+#endif
59866
59867 rcu_read_lock();
59868 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59869diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59870index 7129046..f2779c6 100644
59871--- a/fs/proc/proc_sysctl.c
59872+++ b/fs/proc/proc_sysctl.c
59873@@ -13,11 +13,15 @@
59874 #include <linux/module.h>
59875 #include "internal.h"
59876
59877+extern int gr_handle_chroot_sysctl(const int op);
59878+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59879+ const int op);
59880+
59881 static const struct dentry_operations proc_sys_dentry_operations;
59882 static const struct file_operations proc_sys_file_operations;
59883-static const struct inode_operations proc_sys_inode_operations;
59884+const struct inode_operations proc_sys_inode_operations;
59885 static const struct file_operations proc_sys_dir_file_operations;
59886-static const struct inode_operations proc_sys_dir_operations;
59887+const struct inode_operations proc_sys_dir_operations;
59888
59889 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59890 {
59891@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59892
59893 err = NULL;
59894 d_set_d_op(dentry, &proc_sys_dentry_operations);
59895+
59896+ gr_handle_proc_create(dentry, inode);
59897+
59898 d_add(dentry, inode);
59899
59900 out:
59901@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59902 struct inode *inode = file_inode(filp);
59903 struct ctl_table_header *head = grab_header(inode);
59904 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59905+ int op = write ? MAY_WRITE : MAY_READ;
59906 ssize_t error;
59907 size_t res;
59908
59909@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59910 * and won't be until we finish.
59911 */
59912 error = -EPERM;
59913- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59914+ if (sysctl_perm(head, table, op))
59915 goto out;
59916
59917 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59918@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59919 if (!table->proc_handler)
59920 goto out;
59921
59922+#ifdef CONFIG_GRKERNSEC
59923+ error = -EPERM;
59924+ if (gr_handle_chroot_sysctl(op))
59925+ goto out;
59926+ dget(filp->f_path.dentry);
59927+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59928+ dput(filp->f_path.dentry);
59929+ goto out;
59930+ }
59931+ dput(filp->f_path.dentry);
59932+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59933+ goto out;
59934+ if (write && !capable(CAP_SYS_ADMIN))
59935+ goto out;
59936+#endif
59937+
59938 /* careful: calling conventions are nasty here */
59939 res = count;
59940 error = table->proc_handler(table, write, buf, &res, ppos);
59941@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59942 return false;
59943 } else {
59944 d_set_d_op(child, &proc_sys_dentry_operations);
59945+
59946+ gr_handle_proc_create(child, inode);
59947+
59948 d_add(child, inode);
59949 }
59950 } else {
59951@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59952 if ((*pos)++ < ctx->pos)
59953 return true;
59954
59955+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59956+ return 0;
59957+
59958 if (unlikely(S_ISLNK(table->mode)))
59959 res = proc_sys_link_fill_cache(file, ctx, head, table);
59960 else
59961@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59962 if (IS_ERR(head))
59963 return PTR_ERR(head);
59964
59965+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59966+ return -ENOENT;
59967+
59968 generic_fillattr(inode, stat);
59969 if (table)
59970 stat->mode = (stat->mode & S_IFMT) | table->mode;
59971@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59972 .llseek = generic_file_llseek,
59973 };
59974
59975-static const struct inode_operations proc_sys_inode_operations = {
59976+const struct inode_operations proc_sys_inode_operations = {
59977 .permission = proc_sys_permission,
59978 .setattr = proc_sys_setattr,
59979 .getattr = proc_sys_getattr,
59980 };
59981
59982-static const struct inode_operations proc_sys_dir_operations = {
59983+const struct inode_operations proc_sys_dir_operations = {
59984 .lookup = proc_sys_lookup,
59985 .permission = proc_sys_permission,
59986 .setattr = proc_sys_setattr,
59987@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59988 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59989 const char *name, int namelen)
59990 {
59991- struct ctl_table *table;
59992+ ctl_table_no_const *table;
59993 struct ctl_dir *new;
59994 struct ctl_node *node;
59995 char *new_name;
59996@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59997 return NULL;
59998
59999 node = (struct ctl_node *)(new + 1);
60000- table = (struct ctl_table *)(node + 1);
60001+ table = (ctl_table_no_const *)(node + 1);
60002 new_name = (char *)(table + 2);
60003 memcpy(new_name, name, namelen);
60004 new_name[namelen] = '\0';
60005@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
60006 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
60007 struct ctl_table_root *link_root)
60008 {
60009- struct ctl_table *link_table, *entry, *link;
60010+ ctl_table_no_const *link_table, *link;
60011+ struct ctl_table *entry;
60012 struct ctl_table_header *links;
60013 struct ctl_node *node;
60014 char *link_name;
60015@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
60016 return NULL;
60017
60018 node = (struct ctl_node *)(links + 1);
60019- link_table = (struct ctl_table *)(node + nr_entries);
60020+ link_table = (ctl_table_no_const *)(node + nr_entries);
60021 link_name = (char *)&link_table[nr_entries + 1];
60022
60023 for (link = link_table, entry = table; entry->procname; link++, entry++) {
60024@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60025 struct ctl_table_header ***subheader, struct ctl_table_set *set,
60026 struct ctl_table *table)
60027 {
60028- struct ctl_table *ctl_table_arg = NULL;
60029- struct ctl_table *entry, *files;
60030+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
60031+ struct ctl_table *entry;
60032 int nr_files = 0;
60033 int nr_dirs = 0;
60034 int err = -ENOMEM;
60035@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60036 nr_files++;
60037 }
60038
60039- files = table;
60040 /* If there are mixed files and directories we need a new table */
60041 if (nr_dirs && nr_files) {
60042- struct ctl_table *new;
60043+ ctl_table_no_const *new;
60044 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
60045 GFP_KERNEL);
60046 if (!files)
60047@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60048 /* Register everything except a directory full of subdirectories */
60049 if (nr_files || !nr_dirs) {
60050 struct ctl_table_header *header;
60051- header = __register_sysctl_table(set, path, files);
60052+ header = __register_sysctl_table(set, path, files ? files : table);
60053 if (!header) {
60054 kfree(ctl_table_arg);
60055 goto out;
60056diff --git a/fs/proc/root.c b/fs/proc/root.c
60057index e0a790d..21e095e 100644
60058--- a/fs/proc/root.c
60059+++ b/fs/proc/root.c
60060@@ -182,7 +182,15 @@ void __init proc_root_init(void)
60061 #ifdef CONFIG_PROC_DEVICETREE
60062 proc_device_tree_init();
60063 #endif
60064+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60065+#ifdef CONFIG_GRKERNSEC_PROC_USER
60066+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
60067+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60068+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
60069+#endif
60070+#else
60071 proc_mkdir("bus", NULL);
60072+#endif
60073 proc_sys_init();
60074 }
60075
60076diff --git a/fs/proc/self.c b/fs/proc/self.c
60077index 6b6a993..807cccc 100644
60078--- a/fs/proc/self.c
60079+++ b/fs/proc/self.c
60080@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
60081 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
60082 void *cookie)
60083 {
60084- char *s = nd_get_link(nd);
60085+ const char *s = nd_get_link(nd);
60086 if (!IS_ERR(s))
60087 kfree(s);
60088 }
60089diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
60090index 107d026..c715aeb 100644
60091--- a/fs/proc/task_mmu.c
60092+++ b/fs/proc/task_mmu.c
60093@@ -12,12 +12,19 @@
60094 #include <linux/swap.h>
60095 #include <linux/swapops.h>
60096 #include <linux/mmu_notifier.h>
60097+#include <linux/grsecurity.h>
60098
60099 #include <asm/elf.h>
60100 #include <asm/uaccess.h>
60101 #include <asm/tlbflush.h>
60102 #include "internal.h"
60103
60104+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60105+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60106+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60107+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60108+#endif
60109+
60110 void task_mem(struct seq_file *m, struct mm_struct *mm)
60111 {
60112 unsigned long data, text, lib, swap;
60113@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60114 "VmExe:\t%8lu kB\n"
60115 "VmLib:\t%8lu kB\n"
60116 "VmPTE:\t%8lu kB\n"
60117- "VmSwap:\t%8lu kB\n",
60118- hiwater_vm << (PAGE_SHIFT-10),
60119+ "VmSwap:\t%8lu kB\n"
60120+
60121+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60122+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
60123+#endif
60124+
60125+ ,hiwater_vm << (PAGE_SHIFT-10),
60126 total_vm << (PAGE_SHIFT-10),
60127 mm->locked_vm << (PAGE_SHIFT-10),
60128 mm->pinned_vm << (PAGE_SHIFT-10),
60129@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60130 data << (PAGE_SHIFT-10),
60131 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
60132 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
60133- swap << (PAGE_SHIFT-10));
60134+ swap << (PAGE_SHIFT-10)
60135+
60136+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60137+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60138+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
60139+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60140+#else
60141+ , mm->context.user_cs_base
60142+ , mm->context.user_cs_limit
60143+#endif
60144+#endif
60145+
60146+ );
60147 }
60148
60149 unsigned long task_vsize(struct mm_struct *mm)
60150@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60151 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60152 }
60153
60154- /* We don't show the stack guard page in /proc/maps */
60155+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60156+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60157+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60158+#else
60159 start = vma->vm_start;
60160- if (stack_guard_page_start(vma, start))
60161- start += PAGE_SIZE;
60162 end = vma->vm_end;
60163- if (stack_guard_page_end(vma, end))
60164- end -= PAGE_SIZE;
60165+#endif
60166
60167 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60168 start,
60169@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60170 flags & VM_WRITE ? 'w' : '-',
60171 flags & VM_EXEC ? 'x' : '-',
60172 flags & VM_MAYSHARE ? 's' : 'p',
60173+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60174+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60175+#else
60176 pgoff,
60177+#endif
60178 MAJOR(dev), MINOR(dev), ino, &len);
60179
60180 /*
60181@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60182 */
60183 if (file) {
60184 pad_len_spaces(m, len);
60185- seq_path(m, &file->f_path, "\n");
60186+ seq_path(m, &file->f_path, "\n\\");
60187 goto done;
60188 }
60189
60190@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60191 * Thread stack in /proc/PID/task/TID/maps or
60192 * the main process stack.
60193 */
60194- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60195- vma->vm_end >= mm->start_stack)) {
60196+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60197+ (vma->vm_start <= mm->start_stack &&
60198+ vma->vm_end >= mm->start_stack)) {
60199 name = "[stack]";
60200 } else {
60201 /* Thread stack in /proc/PID/maps */
60202@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60203 struct proc_maps_private *priv = m->private;
60204 struct task_struct *task = priv->task;
60205
60206+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60207+ if (current->exec_id != m->exec_id) {
60208+ gr_log_badprocpid("maps");
60209+ return 0;
60210+ }
60211+#endif
60212+
60213 show_map_vma(m, vma, is_pid);
60214
60215 if (m->count < m->size) /* vma is copied successfully */
60216@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60217 .private = &mss,
60218 };
60219
60220+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60221+ if (current->exec_id != m->exec_id) {
60222+ gr_log_badprocpid("smaps");
60223+ return 0;
60224+ }
60225+#endif
60226 memset(&mss, 0, sizeof mss);
60227- mss.vma = vma;
60228- /* mmap_sem is held in m_start */
60229- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60230- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60231-
60232+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60233+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60234+#endif
60235+ mss.vma = vma;
60236+ /* mmap_sem is held in m_start */
60237+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60238+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60240+ }
60241+#endif
60242 show_map_vma(m, vma, is_pid);
60243
60244 seq_printf(m,
60245@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60246 "KernelPageSize: %8lu kB\n"
60247 "MMUPageSize: %8lu kB\n"
60248 "Locked: %8lu kB\n",
60249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60250+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60251+#else
60252 (vma->vm_end - vma->vm_start) >> 10,
60253+#endif
60254 mss.resident >> 10,
60255 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60256 mss.shared_clean >> 10,
60257@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60258 int n;
60259 char buffer[50];
60260
60261+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60262+ if (current->exec_id != m->exec_id) {
60263+ gr_log_badprocpid("numa_maps");
60264+ return 0;
60265+ }
60266+#endif
60267+
60268 if (!mm)
60269 return 0;
60270
60271@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60272 mpol_to_str(buffer, sizeof(buffer), pol);
60273 mpol_cond_put(pol);
60274
60275+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60276+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60277+#else
60278 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60279+#endif
60280
60281 if (file) {
60282 seq_printf(m, " file=");
60283- seq_path(m, &file->f_path, "\n\t= ");
60284+ seq_path(m, &file->f_path, "\n\t\\= ");
60285 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60286 seq_printf(m, " heap");
60287 } else {
60288diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60289index 56123a6..5a2f6ec 100644
60290--- a/fs/proc/task_nommu.c
60291+++ b/fs/proc/task_nommu.c
60292@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60293 else
60294 bytes += kobjsize(mm);
60295
60296- if (current->fs && current->fs->users > 1)
60297+ if (current->fs && atomic_read(&current->fs->users) > 1)
60298 sbytes += kobjsize(current->fs);
60299 else
60300 bytes += kobjsize(current->fs);
60301@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60302
60303 if (file) {
60304 pad_len_spaces(m, len);
60305- seq_path(m, &file->f_path, "");
60306+ seq_path(m, &file->f_path, "\n\\");
60307 } else if (mm) {
60308 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60309
60310diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60311index a1a16eb..6be46ed 100644
60312--- a/fs/proc/vmcore.c
60313+++ b/fs/proc/vmcore.c
60314@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60315 nr_bytes = count;
60316
60317 /* If pfn is not ram, return zeros for sparse dump files */
60318- if (pfn_is_ram(pfn) == 0)
60319- memset(buf, 0, nr_bytes);
60320- else {
60321+ if (pfn_is_ram(pfn) == 0) {
60322+ if (userbuf) {
60323+ if (clear_user((char __force_user *)buf, nr_bytes))
60324+ return -EFAULT;
60325+ } else
60326+ memset(buf, 0, nr_bytes);
60327+ } else {
60328 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60329 offset, userbuf);
60330 if (tmp < 0)
60331@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60332 if (*fpos < m->offset + m->size) {
60333 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60334 start = m->paddr + *fpos - m->offset;
60335- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60336+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60337 if (tmp < 0)
60338 return tmp;
60339 buflen -= tsz;
60340diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60341index b00fcc9..e0c6381 100644
60342--- a/fs/qnx6/qnx6.h
60343+++ b/fs/qnx6/qnx6.h
60344@@ -74,7 +74,7 @@ enum {
60345 BYTESEX_BE,
60346 };
60347
60348-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60349+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60350 {
60351 if (sbi->s_bytesex == BYTESEX_LE)
60352 return le64_to_cpu((__force __le64)n);
60353@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60354 return (__force __fs64)cpu_to_be64(n);
60355 }
60356
60357-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60358+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60359 {
60360 if (sbi->s_bytesex == BYTESEX_LE)
60361 return le32_to_cpu((__force __le32)n);
60362diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60363index 16e8abb..2dcf914 100644
60364--- a/fs/quota/netlink.c
60365+++ b/fs/quota/netlink.c
60366@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60367 void quota_send_warning(struct kqid qid, dev_t dev,
60368 const char warntype)
60369 {
60370- static atomic_t seq;
60371+ static atomic_unchecked_t seq;
60372 struct sk_buff *skb;
60373 void *msg_head;
60374 int ret;
60375@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60376 "VFS: Not enough memory to send quota warning.\n");
60377 return;
60378 }
60379- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60380+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60381 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60382 if (!msg_head) {
60383 printk(KERN_ERR
60384diff --git a/fs/read_write.c b/fs/read_write.c
60385index 122a384..0b7ecf2 100644
60386--- a/fs/read_write.c
60387+++ b/fs/read_write.c
60388@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60389
60390 old_fs = get_fs();
60391 set_fs(get_ds());
60392- p = (__force const char __user *)buf;
60393+ p = (const char __force_user *)buf;
60394 if (count > MAX_RW_COUNT)
60395 count = MAX_RW_COUNT;
60396 if (file->f_op->write)
60397diff --git a/fs/readdir.c b/fs/readdir.c
60398index 93d71e5..6a14be8 100644
60399--- a/fs/readdir.c
60400+++ b/fs/readdir.c
60401@@ -17,6 +17,7 @@
60402 #include <linux/security.h>
60403 #include <linux/syscalls.h>
60404 #include <linux/unistd.h>
60405+#include <linux/namei.h>
60406
60407 #include <asm/uaccess.h>
60408
60409@@ -69,6 +70,7 @@ struct old_linux_dirent {
60410 struct readdir_callback {
60411 struct dir_context ctx;
60412 struct old_linux_dirent __user * dirent;
60413+ struct file * file;
60414 int result;
60415 };
60416
60417@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60418 buf->result = -EOVERFLOW;
60419 return -EOVERFLOW;
60420 }
60421+
60422+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60423+ return 0;
60424+
60425 buf->result++;
60426 dirent = buf->dirent;
60427 if (!access_ok(VERIFY_WRITE, dirent,
60428@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60429 if (!f.file)
60430 return -EBADF;
60431
60432+ buf.file = f.file;
60433 error = iterate_dir(f.file, &buf.ctx);
60434 if (buf.result)
60435 error = buf.result;
60436@@ -142,6 +149,7 @@ struct getdents_callback {
60437 struct dir_context ctx;
60438 struct linux_dirent __user * current_dir;
60439 struct linux_dirent __user * previous;
60440+ struct file * file;
60441 int count;
60442 int error;
60443 };
60444@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60445 buf->error = -EOVERFLOW;
60446 return -EOVERFLOW;
60447 }
60448+
60449+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60450+ return 0;
60451+
60452 dirent = buf->previous;
60453 if (dirent) {
60454 if (__put_user(offset, &dirent->d_off))
60455@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60456 if (!f.file)
60457 return -EBADF;
60458
60459+ buf.file = f.file;
60460 error = iterate_dir(f.file, &buf.ctx);
60461 if (error >= 0)
60462 error = buf.error;
60463@@ -226,6 +239,7 @@ struct getdents_callback64 {
60464 struct dir_context ctx;
60465 struct linux_dirent64 __user * current_dir;
60466 struct linux_dirent64 __user * previous;
60467+ struct file *file;
60468 int count;
60469 int error;
60470 };
60471@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60472 buf->error = -EINVAL; /* only used if we fail.. */
60473 if (reclen > buf->count)
60474 return -EINVAL;
60475+
60476+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60477+ return 0;
60478+
60479 dirent = buf->previous;
60480 if (dirent) {
60481 if (__put_user(offset, &dirent->d_off))
60482@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60483 if (!f.file)
60484 return -EBADF;
60485
60486+ buf.file = f.file;
60487 error = iterate_dir(f.file, &buf.ctx);
60488 if (error >= 0)
60489 error = buf.error;
60490diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60491index 2b7882b..1c5ef48 100644
60492--- a/fs/reiserfs/do_balan.c
60493+++ b/fs/reiserfs/do_balan.c
60494@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60495 return;
60496 }
60497
60498- atomic_inc(&(fs_generation(tb->tb_sb)));
60499+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60500 do_balance_starts(tb);
60501
60502 /* balance leaf returns 0 except if combining L R and S into
60503diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60504index a958444..42b2323 100644
60505--- a/fs/reiserfs/procfs.c
60506+++ b/fs/reiserfs/procfs.c
60507@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60508 "SMALL_TAILS " : "NO_TAILS ",
60509 replay_only(sb) ? "REPLAY_ONLY " : "",
60510 convert_reiserfs(sb) ? "CONV " : "",
60511- atomic_read(&r->s_generation_counter),
60512+ atomic_read_unchecked(&r->s_generation_counter),
60513 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60514 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60515 SF(s_good_search_by_key_reada), SF(s_bmaps),
60516diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60517index 3df5ce6..8c0f4b0 100644
60518--- a/fs/reiserfs/reiserfs.h
60519+++ b/fs/reiserfs/reiserfs.h
60520@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60521 /* Comment? -Hans */
60522 wait_queue_head_t s_wait;
60523 /* To be obsoleted soon by per buffer seals.. -Hans */
60524- atomic_t s_generation_counter; // increased by one every time the
60525+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60526 // tree gets re-balanced
60527 unsigned long s_properties; /* File system properties. Currently holds
60528 on-disk FS format */
60529@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60530 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60531
60532 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60533-#define get_generation(s) atomic_read (&fs_generation(s))
60534+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60535 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60536 #define __fs_changed(gen,s) (gen != get_generation (s))
60537 #define fs_changed(gen,s) \
60538diff --git a/fs/select.c b/fs/select.c
60539index 35d4adc7..d6c60db 100644
60540--- a/fs/select.c
60541+++ b/fs/select.c
60542@@ -20,6 +20,7 @@
60543 #include <linux/export.h>
60544 #include <linux/slab.h>
60545 #include <linux/poll.h>
60546+#include <linux/security.h>
60547 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60548 #include <linux/file.h>
60549 #include <linux/fdtable.h>
60550@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60551 struct poll_list *walk = head;
60552 unsigned long todo = nfds;
60553
60554+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60555 if (nfds > rlimit(RLIMIT_NOFILE))
60556 return -EINVAL;
60557
60558diff --git a/fs/seq_file.c b/fs/seq_file.c
60559index 3135c25..d0395dd 100644
60560--- a/fs/seq_file.c
60561+++ b/fs/seq_file.c
60562@@ -10,6 +10,7 @@
60563 #include <linux/seq_file.h>
60564 #include <linux/slab.h>
60565 #include <linux/cred.h>
60566+#include <linux/sched.h>
60567
60568 #include <asm/uaccess.h>
60569 #include <asm/page.h>
60570@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60571 #ifdef CONFIG_USER_NS
60572 p->user_ns = file->f_cred->user_ns;
60573 #endif
60574+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60575+ p->exec_id = current->exec_id;
60576+#endif
60577
60578 /*
60579 * Wrappers around seq_open(e.g. swaps_open) need to be
60580@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60581 return 0;
60582 }
60583 if (!m->buf) {
60584- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60585+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60586 if (!m->buf)
60587 return -ENOMEM;
60588 }
60589@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60590 Eoverflow:
60591 m->op->stop(m, p);
60592 kfree(m->buf);
60593- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60594+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60595 return !m->buf ? -ENOMEM : -EAGAIN;
60596 }
60597
60598@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60599
60600 /* grab buffer if we didn't have one */
60601 if (!m->buf) {
60602- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60603+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60604 if (!m->buf)
60605 goto Enomem;
60606 }
60607@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60608 goto Fill;
60609 m->op->stop(m, p);
60610 kfree(m->buf);
60611- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60612+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60613 if (!m->buf)
60614 goto Enomem;
60615 m->count = 0;
60616@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60617 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60618 void *data)
60619 {
60620- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60621+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60622 int res = -ENOMEM;
60623
60624 if (op) {
60625diff --git a/fs/splice.c b/fs/splice.c
60626index 3b7ee65..87fc2e4 100644
60627--- a/fs/splice.c
60628+++ b/fs/splice.c
60629@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60630 pipe_lock(pipe);
60631
60632 for (;;) {
60633- if (!pipe->readers) {
60634+ if (!atomic_read(&pipe->readers)) {
60635 send_sig(SIGPIPE, current, 0);
60636 if (!ret)
60637 ret = -EPIPE;
60638@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60639 page_nr++;
60640 ret += buf->len;
60641
60642- if (pipe->files)
60643+ if (atomic_read(&pipe->files))
60644 do_wakeup = 1;
60645
60646 if (!--spd->nr_pages)
60647@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60648 do_wakeup = 0;
60649 }
60650
60651- pipe->waiting_writers++;
60652+ atomic_inc(&pipe->waiting_writers);
60653 pipe_wait(pipe);
60654- pipe->waiting_writers--;
60655+ atomic_dec(&pipe->waiting_writers);
60656 }
60657
60658 pipe_unlock(pipe);
60659@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60660 old_fs = get_fs();
60661 set_fs(get_ds());
60662 /* The cast to a user pointer is valid due to the set_fs() */
60663- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60664+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60665 set_fs(old_fs);
60666
60667 return res;
60668@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60669 old_fs = get_fs();
60670 set_fs(get_ds());
60671 /* The cast to a user pointer is valid due to the set_fs() */
60672- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60673+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60674 set_fs(old_fs);
60675
60676 return res;
60677@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60678 goto err;
60679
60680 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60681- vec[i].iov_base = (void __user *) page_address(page);
60682+ vec[i].iov_base = (void __force_user *) page_address(page);
60683 vec[i].iov_len = this_len;
60684 spd.pages[i] = page;
60685 spd.nr_pages++;
60686@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60687 ops->release(pipe, buf);
60688 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60689 pipe->nrbufs--;
60690- if (pipe->files)
60691+ if (atomic_read(&pipe->files))
60692 sd->need_wakeup = true;
60693 }
60694
60695@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60696 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60697 {
60698 while (!pipe->nrbufs) {
60699- if (!pipe->writers)
60700+ if (!atomic_read(&pipe->writers))
60701 return 0;
60702
60703- if (!pipe->waiting_writers && sd->num_spliced)
60704+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60705 return 0;
60706
60707 if (sd->flags & SPLICE_F_NONBLOCK)
60708@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60709 * out of the pipe right after the splice_to_pipe(). So set
60710 * PIPE_READERS appropriately.
60711 */
60712- pipe->readers = 1;
60713+ atomic_set(&pipe->readers, 1);
60714
60715 current->splice_pipe = pipe;
60716 }
60717@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60718
60719 partial[buffers].offset = off;
60720 partial[buffers].len = plen;
60721+ partial[buffers].private = 0;
60722
60723 off = 0;
60724 len -= plen;
60725@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60726 ret = -ERESTARTSYS;
60727 break;
60728 }
60729- if (!pipe->writers)
60730+ if (!atomic_read(&pipe->writers))
60731 break;
60732- if (!pipe->waiting_writers) {
60733+ if (!atomic_read(&pipe->waiting_writers)) {
60734 if (flags & SPLICE_F_NONBLOCK) {
60735 ret = -EAGAIN;
60736 break;
60737@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60738 pipe_lock(pipe);
60739
60740 while (pipe->nrbufs >= pipe->buffers) {
60741- if (!pipe->readers) {
60742+ if (!atomic_read(&pipe->readers)) {
60743 send_sig(SIGPIPE, current, 0);
60744 ret = -EPIPE;
60745 break;
60746@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60747 ret = -ERESTARTSYS;
60748 break;
60749 }
60750- pipe->waiting_writers++;
60751+ atomic_inc(&pipe->waiting_writers);
60752 pipe_wait(pipe);
60753- pipe->waiting_writers--;
60754+ atomic_dec(&pipe->waiting_writers);
60755 }
60756
60757 pipe_unlock(pipe);
60758@@ -1862,14 +1863,14 @@ retry:
60759 pipe_double_lock(ipipe, opipe);
60760
60761 do {
60762- if (!opipe->readers) {
60763+ if (!atomic_read(&opipe->readers)) {
60764 send_sig(SIGPIPE, current, 0);
60765 if (!ret)
60766 ret = -EPIPE;
60767 break;
60768 }
60769
60770- if (!ipipe->nrbufs && !ipipe->writers)
60771+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60772 break;
60773
60774 /*
60775@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60776 pipe_double_lock(ipipe, opipe);
60777
60778 do {
60779- if (!opipe->readers) {
60780+ if (!atomic_read(&opipe->readers)) {
60781 send_sig(SIGPIPE, current, 0);
60782 if (!ret)
60783 ret = -EPIPE;
60784@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60785 * return EAGAIN if we have the potential of some data in the
60786 * future, otherwise just return 0
60787 */
60788- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60789+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60790 ret = -EAGAIN;
60791
60792 pipe_unlock(ipipe);
60793diff --git a/fs/stat.c b/fs/stat.c
60794index 04ce1ac..a13dd1e 100644
60795--- a/fs/stat.c
60796+++ b/fs/stat.c
60797@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60798 stat->gid = inode->i_gid;
60799 stat->rdev = inode->i_rdev;
60800 stat->size = i_size_read(inode);
60801- stat->atime = inode->i_atime;
60802- stat->mtime = inode->i_mtime;
60803+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60804+ stat->atime = inode->i_ctime;
60805+ stat->mtime = inode->i_ctime;
60806+ } else {
60807+ stat->atime = inode->i_atime;
60808+ stat->mtime = inode->i_mtime;
60809+ }
60810 stat->ctime = inode->i_ctime;
60811 stat->blksize = (1 << inode->i_blkbits);
60812 stat->blocks = inode->i_blocks;
60813@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60814 if (retval)
60815 return retval;
60816
60817- if (inode->i_op->getattr)
60818- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60819+ if (inode->i_op->getattr) {
60820+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60821+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60822+ stat->atime = stat->ctime;
60823+ stat->mtime = stat->ctime;
60824+ }
60825+ return retval;
60826+ }
60827
60828 generic_fillattr(inode, stat);
60829 return 0;
60830diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60831index 15c68f9..36a8b3e 100644
60832--- a/fs/sysfs/bin.c
60833+++ b/fs/sysfs/bin.c
60834@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60835 return ret;
60836 }
60837
60838-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60839- void *buf, int len, int write)
60840+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60841+ void *buf, size_t len, int write)
60842 {
60843 struct file *file = vma->vm_file;
60844 struct bin_buffer *bb = file->private_data;
60845 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60846- int ret;
60847+ ssize_t ret;
60848
60849 if (!bb->vm_ops)
60850 return -EINVAL;
60851diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60852index e068e74..92edeb8 100644
60853--- a/fs/sysfs/dir.c
60854+++ b/fs/sysfs/dir.c
60855@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60856 *
60857 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60858 */
60859-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60860+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60861 {
60862 unsigned long hash = init_name_hash();
60863 unsigned int len = strlen(name);
60864@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60865 struct sysfs_dirent *sd;
60866 int rc;
60867
60868+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60869+ const char *parent_name = parent_sd->s_name;
60870+
60871+ mode = S_IFDIR | S_IRWXU;
60872+
60873+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60874+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60875+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60876+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60877+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60878+#endif
60879+
60880 /* allocate */
60881 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60882 if (!sd)
60883diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60884index d2bb7ed..fe8c331 100644
60885--- a/fs/sysfs/file.c
60886+++ b/fs/sysfs/file.c
60887@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60888
60889 struct sysfs_open_dirent {
60890 atomic_t refcnt;
60891- atomic_t event;
60892+ atomic_unchecked_t event;
60893 wait_queue_head_t poll;
60894 struct list_head buffers; /* goes through sysfs_buffer.list */
60895 };
60896@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60897 if (!sysfs_get_active(attr_sd))
60898 return -ENODEV;
60899
60900- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60901+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60902 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60903
60904 sysfs_put_active(attr_sd);
60905@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60906 return -ENOMEM;
60907
60908 atomic_set(&new_od->refcnt, 0);
60909- atomic_set(&new_od->event, 1);
60910+ atomic_set_unchecked(&new_od->event, 1);
60911 init_waitqueue_head(&new_od->poll);
60912 INIT_LIST_HEAD(&new_od->buffers);
60913 goto retry;
60914@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60915
60916 sysfs_put_active(attr_sd);
60917
60918- if (buffer->event != atomic_read(&od->event))
60919+ if (buffer->event != atomic_read_unchecked(&od->event))
60920 goto trigger;
60921
60922 return DEFAULT_POLLMASK;
60923@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60924 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60925 od = sd->s_attr.open;
60926 if (od) {
60927- atomic_inc(&od->event);
60928+ atomic_inc_unchecked(&od->event);
60929 wake_up_interruptible(&od->poll);
60930 }
60931 }
60932diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60933index 8c940df..25b733e 100644
60934--- a/fs/sysfs/symlink.c
60935+++ b/fs/sysfs/symlink.c
60936@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60937
60938 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60939 {
60940- char *page = nd_get_link(nd);
60941+ const char *page = nd_get_link(nd);
60942 if (!IS_ERR(page))
60943 free_page((unsigned long)page);
60944 }
60945diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60946index 69d4889..a810bd4 100644
60947--- a/fs/sysv/sysv.h
60948+++ b/fs/sysv/sysv.h
60949@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60950 #endif
60951 }
60952
60953-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60954+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60955 {
60956 if (sbi->s_bytesex == BYTESEX_PDP)
60957 return PDP_swab((__force __u32)n);
60958diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60959index e18b988..f1d4ad0f 100644
60960--- a/fs/ubifs/io.c
60961+++ b/fs/ubifs/io.c
60962@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60963 return err;
60964 }
60965
60966-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60967+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60968 {
60969 int err;
60970
60971diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60972index c175b4d..8f36a16 100644
60973--- a/fs/udf/misc.c
60974+++ b/fs/udf/misc.c
60975@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60976
60977 u8 udf_tag_checksum(const struct tag *t)
60978 {
60979- u8 *data = (u8 *)t;
60980+ const u8 *data = (const u8 *)t;
60981 u8 checksum = 0;
60982 int i;
60983 for (i = 0; i < sizeof(struct tag); ++i)
60984diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60985index 8d974c4..b82f6ec 100644
60986--- a/fs/ufs/swab.h
60987+++ b/fs/ufs/swab.h
60988@@ -22,7 +22,7 @@ enum {
60989 BYTESEX_BE
60990 };
60991
60992-static inline u64
60993+static inline u64 __intentional_overflow(-1)
60994 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60995 {
60996 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60997@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60998 return (__force __fs64)cpu_to_be64(n);
60999 }
61000
61001-static inline u32
61002+static inline u32 __intentional_overflow(-1)
61003 fs32_to_cpu(struct super_block *sbp, __fs32 n)
61004 {
61005 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
61006diff --git a/fs/utimes.c b/fs/utimes.c
61007index f4fb7ec..3fe03c0 100644
61008--- a/fs/utimes.c
61009+++ b/fs/utimes.c
61010@@ -1,6 +1,7 @@
61011 #include <linux/compiler.h>
61012 #include <linux/file.h>
61013 #include <linux/fs.h>
61014+#include <linux/security.h>
61015 #include <linux/linkage.h>
61016 #include <linux/mount.h>
61017 #include <linux/namei.h>
61018@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
61019 goto mnt_drop_write_and_out;
61020 }
61021 }
61022+
61023+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
61024+ error = -EACCES;
61025+ goto mnt_drop_write_and_out;
61026+ }
61027+
61028 mutex_lock(&inode->i_mutex);
61029 error = notify_change(path->dentry, &newattrs);
61030 mutex_unlock(&inode->i_mutex);
61031diff --git a/fs/xattr.c b/fs/xattr.c
61032index 3377dff..4d074d9 100644
61033--- a/fs/xattr.c
61034+++ b/fs/xattr.c
61035@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
61036 return rc;
61037 }
61038
61039+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
61040+ssize_t
61041+pax_getxattr(struct dentry *dentry, void *value, size_t size)
61042+{
61043+ struct inode *inode = dentry->d_inode;
61044+ ssize_t error;
61045+
61046+ error = inode_permission(inode, MAY_EXEC);
61047+ if (error)
61048+ return error;
61049+
61050+ if (inode->i_op->getxattr)
61051+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
61052+ else
61053+ error = -EOPNOTSUPP;
61054+
61055+ return error;
61056+}
61057+EXPORT_SYMBOL(pax_getxattr);
61058+#endif
61059+
61060 ssize_t
61061 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
61062 {
61063@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
61064 * Extended attribute SET operations
61065 */
61066 static long
61067-setxattr(struct dentry *d, const char __user *name, const void __user *value,
61068+setxattr(struct path *path, const char __user *name, const void __user *value,
61069 size_t size, int flags)
61070 {
61071 int error;
61072@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
61073 posix_acl_fix_xattr_from_user(kvalue, size);
61074 }
61075
61076- error = vfs_setxattr(d, kname, kvalue, size, flags);
61077+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
61078+ error = -EACCES;
61079+ goto out;
61080+ }
61081+
61082+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
61083 out:
61084 if (vvalue)
61085 vfree(vvalue);
61086@@ -377,7 +403,7 @@ retry:
61087 return error;
61088 error = mnt_want_write(path.mnt);
61089 if (!error) {
61090- error = setxattr(path.dentry, name, value, size, flags);
61091+ error = setxattr(&path, name, value, size, flags);
61092 mnt_drop_write(path.mnt);
61093 }
61094 path_put(&path);
61095@@ -401,7 +427,7 @@ retry:
61096 return error;
61097 error = mnt_want_write(path.mnt);
61098 if (!error) {
61099- error = setxattr(path.dentry, name, value, size, flags);
61100+ error = setxattr(&path, name, value, size, flags);
61101 mnt_drop_write(path.mnt);
61102 }
61103 path_put(&path);
61104@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
61105 const void __user *,value, size_t, size, int, flags)
61106 {
61107 struct fd f = fdget(fd);
61108- struct dentry *dentry;
61109 int error = -EBADF;
61110
61111 if (!f.file)
61112 return error;
61113- dentry = f.file->f_path.dentry;
61114- audit_inode(NULL, dentry, 0);
61115+ audit_inode(NULL, f.file->f_path.dentry, 0);
61116 error = mnt_want_write_file(f.file);
61117 if (!error) {
61118- error = setxattr(dentry, name, value, size, flags);
61119+ error = setxattr(&f.file->f_path, name, value, size, flags);
61120 mnt_drop_write_file(f.file);
61121 }
61122 fdput(f);
61123diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
61124index 9fbea87..6b19972 100644
61125--- a/fs/xattr_acl.c
61126+++ b/fs/xattr_acl.c
61127@@ -76,8 +76,8 @@ struct posix_acl *
61128 posix_acl_from_xattr(struct user_namespace *user_ns,
61129 const void *value, size_t size)
61130 {
61131- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
61132- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
61133+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
61134+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
61135 int count;
61136 struct posix_acl *acl;
61137 struct posix_acl_entry *acl_e;
61138diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
61139index 05c698c..6b918af 100644
61140--- a/fs/xfs/xfs_bmap.c
61141+++ b/fs/xfs/xfs_bmap.c
61142@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
61143
61144 #else
61145 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61146-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61147+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61148 #endif /* DEBUG */
61149
61150 /*
61151diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
61152index 97676a3..399a75d 100644
61153--- a/fs/xfs/xfs_dir2_sf.c
61154+++ b/fs/xfs/xfs_dir2_sf.c
61155@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
61156
61157 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
61158 ctx->pos = off & 0x7fffffff;
61159- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61160+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61161+ char name[sfep->namelen];
61162+ memcpy(name, sfep->name, sfep->namelen);
61163+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
61164+ return 0;
61165+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61166 ino, DT_UNKNOWN))
61167 return 0;
61168 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
61169diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61170index 6e2bca5..6ce80d3 100644
61171--- a/fs/xfs/xfs_ioctl.c
61172+++ b/fs/xfs/xfs_ioctl.c
61173@@ -127,7 +127,7 @@ xfs_find_handle(
61174 }
61175
61176 error = -EFAULT;
61177- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61178+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61179 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61180 goto out_put;
61181
61182diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61183index 96dda62..d6c6a52 100644
61184--- a/fs/xfs/xfs_iops.c
61185+++ b/fs/xfs/xfs_iops.c
61186@@ -395,7 +395,7 @@ xfs_vn_put_link(
61187 struct nameidata *nd,
61188 void *p)
61189 {
61190- char *s = nd_get_link(nd);
61191+ const char *s = nd_get_link(nd);
61192
61193 if (!IS_ERR(s))
61194 kfree(s);
61195diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61196new file mode 100644
61197index 0000000..0fd7c82
61198--- /dev/null
61199+++ b/grsecurity/Kconfig
61200@@ -0,0 +1,1080 @@
61201+#
61202+# grecurity configuration
61203+#
61204+menu "Memory Protections"
61205+depends on GRKERNSEC
61206+
61207+config GRKERNSEC_KMEM
61208+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61209+ default y if GRKERNSEC_CONFIG_AUTO
61210+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61211+ help
61212+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61213+ be written to or read from to modify or leak the contents of the running
61214+ kernel. /dev/port will also not be allowed to be opened and support
61215+ for /dev/cpu/*/msr will be removed. If you have module
61216+ support disabled, enabling this will close up five ways that are
61217+ currently used to insert malicious code into the running kernel.
61218+
61219+ Even with all these features enabled, we still highly recommend that
61220+ you use the RBAC system, as it is still possible for an attacker to
61221+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61222+
61223+ If you are not using XFree86, you may be able to stop this additional
61224+ case by enabling the 'Disable privileged I/O' option. Though nothing
61225+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61226+ but only to video memory, which is the only writing we allow in this
61227+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61228+ not be allowed to mprotect it with PROT_WRITE later.
61229+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61230+ from working.
61231+
61232+ It is highly recommended that you say Y here if you meet all the
61233+ conditions above.
61234+
61235+config GRKERNSEC_VM86
61236+ bool "Restrict VM86 mode"
61237+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61238+ depends on X86_32
61239+
61240+ help
61241+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61242+ make use of a special execution mode on 32bit x86 processors called
61243+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61244+ video cards and will still work with this option enabled. The purpose
61245+ of the option is to prevent exploitation of emulation errors in
61246+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61247+ Nearly all users should be able to enable this option.
61248+
61249+config GRKERNSEC_IO
61250+ bool "Disable privileged I/O"
61251+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61252+ depends on X86
61253+ select RTC_CLASS
61254+ select RTC_INTF_DEV
61255+ select RTC_DRV_CMOS
61256+
61257+ help
61258+ If you say Y here, all ioperm and iopl calls will return an error.
61259+ Ioperm and iopl can be used to modify the running kernel.
61260+ Unfortunately, some programs need this access to operate properly,
61261+ the most notable of which are XFree86 and hwclock. hwclock can be
61262+ remedied by having RTC support in the kernel, so real-time
61263+ clock support is enabled if this option is enabled, to ensure
61264+ that hwclock operates correctly. XFree86 still will not
61265+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61266+ IF YOU USE XFree86. If you use XFree86 and you still want to
61267+ protect your kernel against modification, use the RBAC system.
61268+
61269+config GRKERNSEC_JIT_HARDEN
61270+ bool "Harden BPF JIT against spray attacks"
61271+ default y if GRKERNSEC_CONFIG_AUTO
61272+ depends on BPF_JIT
61273+ help
61274+ If you say Y here, the native code generated by the kernel's Berkeley
61275+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61276+ attacks that attempt to fit attacker-beneficial instructions in
61277+ 32bit immediate fields of JIT-generated native instructions. The
61278+ attacker will generally aim to cause an unintended instruction sequence
61279+ of JIT-generated native code to execute by jumping into the middle of
61280+ a generated instruction. This feature effectively randomizes the 32bit
61281+ immediate constants present in the generated code to thwart such attacks.
61282+
61283+ If you're using KERNEXEC, it's recommended that you enable this option
61284+ to supplement the hardening of the kernel.
61285+
61286+config GRKERNSEC_PERF_HARDEN
61287+ bool "Disable unprivileged PERF_EVENTS usage by default"
61288+ default y if GRKERNSEC_CONFIG_AUTO
61289+ depends on PERF_EVENTS
61290+ help
61291+ If you say Y here, the range of acceptable values for the
61292+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61293+ default to a new value: 3. When the sysctl is set to this value, no
61294+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61295+
61296+ Though PERF_EVENTS can be used legitimately for performance monitoring
61297+ and low-level application profiling, it is forced on regardless of
61298+ configuration, has been at fault for several vulnerabilities, and
61299+ creates new opportunities for side channels and other information leaks.
61300+
61301+ This feature puts PERF_EVENTS into a secure default state and permits
61302+ the administrator to change out of it temporarily if unprivileged
61303+ application profiling is needed.
61304+
61305+config GRKERNSEC_RAND_THREADSTACK
61306+ bool "Insert random gaps between thread stacks"
61307+ default y if GRKERNSEC_CONFIG_AUTO
61308+ depends on PAX_RANDMMAP && !PPC
61309+ help
61310+ If you say Y here, a random-sized gap will be enforced between allocated
61311+ thread stacks. Glibc's NPTL and other threading libraries that
61312+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61313+ The implementation currently provides 8 bits of entropy for the gap.
61314+
61315+ Many distributions do not compile threaded remote services with the
61316+ -fstack-check argument to GCC, causing the variable-sized stack-based
61317+ allocator, alloca(), to not probe the stack on allocation. This
61318+ permits an unbounded alloca() to skip over any guard page and potentially
61319+ modify another thread's stack reliably. An enforced random gap
61320+ reduces the reliability of such an attack and increases the chance
61321+ that such a read/write to another thread's stack instead lands in
61322+ an unmapped area, causing a crash and triggering grsecurity's
61323+ anti-bruteforcing logic.
61324+
61325+config GRKERNSEC_PROC_MEMMAP
61326+ bool "Harden ASLR against information leaks and entropy reduction"
61327+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61328+ depends on PAX_NOEXEC || PAX_ASLR
61329+ help
61330+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61331+ give no information about the addresses of its mappings if
61332+ PaX features that rely on random addresses are enabled on the task.
61333+ In addition to sanitizing this information and disabling other
61334+ dangerous sources of information, this option causes reads of sensitive
61335+ /proc/<pid> entries where the file descriptor was opened in a different
61336+ task than the one performing the read. Such attempts are logged.
61337+ This option also limits argv/env strings for suid/sgid binaries
61338+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61339+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61340+ binaries to prevent alternative mmap layouts from being abused.
61341+
61342+ If you use PaX it is essential that you say Y here as it closes up
61343+ several holes that make full ASLR useless locally.
61344+
61345+config GRKERNSEC_BRUTE
61346+ bool "Deter exploit bruteforcing"
61347+ default y if GRKERNSEC_CONFIG_AUTO
61348+ help
61349+ If you say Y here, attempts to bruteforce exploits against forking
61350+ daemons such as apache or sshd, as well as against suid/sgid binaries
61351+ will be deterred. When a child of a forking daemon is killed by PaX
61352+ or crashes due to an illegal instruction or other suspicious signal,
61353+ the parent process will be delayed 30 seconds upon every subsequent
61354+ fork until the administrator is able to assess the situation and
61355+ restart the daemon.
61356+ In the suid/sgid case, the attempt is logged, the user has all their
61357+ existing instances of the suid/sgid binary terminated and will
61358+ be unable to execute any suid/sgid binaries for 15 minutes.
61359+
61360+ It is recommended that you also enable signal logging in the auditing
61361+ section so that logs are generated when a process triggers a suspicious
61362+ signal.
61363+ If the sysctl option is enabled, a sysctl option with name
61364+ "deter_bruteforce" is created.
61365+
61366+
61367+config GRKERNSEC_MODHARDEN
61368+ bool "Harden module auto-loading"
61369+ default y if GRKERNSEC_CONFIG_AUTO
61370+ depends on MODULES
61371+ help
61372+ If you say Y here, module auto-loading in response to use of some
61373+ feature implemented by an unloaded module will be restricted to
61374+ root users. Enabling this option helps defend against attacks
61375+ by unprivileged users who abuse the auto-loading behavior to
61376+ cause a vulnerable module to load that is then exploited.
61377+
61378+ If this option prevents a legitimate use of auto-loading for a
61379+ non-root user, the administrator can execute modprobe manually
61380+ with the exact name of the module mentioned in the alert log.
61381+ Alternatively, the administrator can add the module to the list
61382+ of modules loaded at boot by modifying init scripts.
61383+
61384+ Modification of init scripts will most likely be needed on
61385+ Ubuntu servers with encrypted home directory support enabled,
61386+ as the first non-root user logging in will cause the ecb(aes),
61387+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61388+
61389+config GRKERNSEC_HIDESYM
61390+ bool "Hide kernel symbols"
61391+ default y if GRKERNSEC_CONFIG_AUTO
61392+ select PAX_USERCOPY_SLABS
61393+ help
61394+ If you say Y here, getting information on loaded modules, and
61395+ displaying all kernel symbols through a syscall will be restricted
61396+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61397+ /proc/kallsyms will be restricted to the root user. The RBAC
61398+ system can hide that entry even from root.
61399+
61400+ This option also prevents leaking of kernel addresses through
61401+ several /proc entries.
61402+
61403+ Note that this option is only effective provided the following
61404+ conditions are met:
61405+ 1) The kernel using grsecurity is not precompiled by some distribution
61406+ 2) You have also enabled GRKERNSEC_DMESG
61407+ 3) You are using the RBAC system and hiding other files such as your
61408+ kernel image and System.map. Alternatively, enabling this option
61409+ causes the permissions on /boot, /lib/modules, and the kernel
61410+ source directory to change at compile time to prevent
61411+ reading by non-root users.
61412+ If the above conditions are met, this option will aid in providing a
61413+ useful protection against local kernel exploitation of overflows
61414+ and arbitrary read/write vulnerabilities.
61415+
61416+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61417+ in addition to this feature.
61418+
61419+config GRKERNSEC_KERN_LOCKOUT
61420+ bool "Active kernel exploit response"
61421+ default y if GRKERNSEC_CONFIG_AUTO
61422+ depends on X86 || ARM || PPC || SPARC
61423+ help
61424+ If you say Y here, when a PaX alert is triggered due to suspicious
61425+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61426+ or an OOPS occurs due to bad memory accesses, instead of just
61427+ terminating the offending process (and potentially allowing
61428+ a subsequent exploit from the same user), we will take one of two
61429+ actions:
61430+ If the user was root, we will panic the system
61431+ If the user was non-root, we will log the attempt, terminate
61432+ all processes owned by the user, then prevent them from creating
61433+ any new processes until the system is restarted
61434+ This deters repeated kernel exploitation/bruteforcing attempts
61435+ and is useful for later forensics.
61436+
61437+endmenu
61438+menu "Role Based Access Control Options"
61439+depends on GRKERNSEC
61440+
61441+config GRKERNSEC_RBAC_DEBUG
61442+ bool
61443+
61444+config GRKERNSEC_NO_RBAC
61445+ bool "Disable RBAC system"
61446+ help
61447+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61448+ preventing the RBAC system from being enabled. You should only say Y
61449+ here if you have no intention of using the RBAC system, so as to prevent
61450+ an attacker with root access from misusing the RBAC system to hide files
61451+ and processes when loadable module support and /dev/[k]mem have been
61452+ locked down.
61453+
61454+config GRKERNSEC_ACL_HIDEKERN
61455+ bool "Hide kernel processes"
61456+ help
61457+ If you say Y here, all kernel threads will be hidden to all
61458+ processes but those whose subject has the "view hidden processes"
61459+ flag.
61460+
61461+config GRKERNSEC_ACL_MAXTRIES
61462+ int "Maximum tries before password lockout"
61463+ default 3
61464+ help
61465+ This option enforces the maximum number of times a user can attempt
61466+ to authorize themselves with the grsecurity RBAC system before being
61467+ denied the ability to attempt authorization again for a specified time.
61468+ The lower the number, the harder it will be to brute-force a password.
61469+
61470+config GRKERNSEC_ACL_TIMEOUT
61471+ int "Time to wait after max password tries, in seconds"
61472+ default 30
61473+ help
61474+ This option specifies the time the user must wait after attempting to
61475+ authorize to the RBAC system with the maximum number of invalid
61476+ passwords. The higher the number, the harder it will be to brute-force
61477+ a password.
61478+
61479+endmenu
61480+menu "Filesystem Protections"
61481+depends on GRKERNSEC
61482+
61483+config GRKERNSEC_PROC
61484+ bool "Proc restrictions"
61485+ default y if GRKERNSEC_CONFIG_AUTO
61486+ help
61487+ If you say Y here, the permissions of the /proc filesystem
61488+ will be altered to enhance system security and privacy. You MUST
61489+ choose either a user only restriction or a user and group restriction.
61490+ Depending upon the option you choose, you can either restrict users to
61491+ see only the processes they themselves run, or choose a group that can
61492+ view all processes and files normally restricted to root if you choose
61493+ the "restrict to user only" option. NOTE: If you're running identd or
61494+ ntpd as a non-root user, you will have to run it as the group you
61495+ specify here.
61496+
61497+config GRKERNSEC_PROC_USER
61498+ bool "Restrict /proc to user only"
61499+ depends on GRKERNSEC_PROC
61500+ help
61501+ If you say Y here, non-root users will only be able to view their own
61502+ processes, and restricts them from viewing network-related information,
61503+ and viewing kernel symbol and module information.
61504+
61505+config GRKERNSEC_PROC_USERGROUP
61506+ bool "Allow special group"
61507+ default y if GRKERNSEC_CONFIG_AUTO
61508+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61509+ help
61510+ If you say Y here, you will be able to select a group that will be
61511+ able to view all processes and network-related information. If you've
61512+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61513+ remain hidden. This option is useful if you want to run identd as
61514+ a non-root user. The group you select may also be chosen at boot time
61515+ via "grsec_proc_gid=" on the kernel commandline.
61516+
61517+config GRKERNSEC_PROC_GID
61518+ int "GID for special group"
61519+ depends on GRKERNSEC_PROC_USERGROUP
61520+ default 1001
61521+
61522+config GRKERNSEC_PROC_ADD
61523+ bool "Additional restrictions"
61524+ default y if GRKERNSEC_CONFIG_AUTO
61525+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61526+ help
61527+ If you say Y here, additional restrictions will be placed on
61528+ /proc that keep normal users from viewing device information and
61529+ slabinfo information that could be useful for exploits.
61530+
61531+config GRKERNSEC_LINK
61532+ bool "Linking restrictions"
61533+ default y if GRKERNSEC_CONFIG_AUTO
61534+ help
61535+ If you say Y here, /tmp race exploits will be prevented, since users
61536+ will no longer be able to follow symlinks owned by other users in
61537+ world-writable +t directories (e.g. /tmp), unless the owner of the
61538+ symlink is the owner of the directory. users will also not be
61539+ able to hardlink to files they do not own. If the sysctl option is
61540+ enabled, a sysctl option with name "linking_restrictions" is created.
61541+
61542+config GRKERNSEC_SYMLINKOWN
61543+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61544+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61545+ help
61546+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61547+ that prevents it from being used as a security feature. As Apache
61548+ verifies the symlink by performing a stat() against the target of
61549+ the symlink before it is followed, an attacker can setup a symlink
61550+ to point to a same-owned file, then replace the symlink with one
61551+ that targets another user's file just after Apache "validates" the
61552+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61553+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61554+ will be in place for the group you specify. If the sysctl option
61555+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61556+ created.
61557+
61558+config GRKERNSEC_SYMLINKOWN_GID
61559+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61560+ depends on GRKERNSEC_SYMLINKOWN
61561+ default 1006
61562+ help
61563+ Setting this GID determines what group kernel-enforced
61564+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61565+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61566+
61567+config GRKERNSEC_FIFO
61568+ bool "FIFO restrictions"
61569+ default y if GRKERNSEC_CONFIG_AUTO
61570+ help
61571+ If you say Y here, users will not be able to write to FIFOs they don't
61572+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61573+ the FIFO is the same owner of the directory it's held in. If the sysctl
61574+ option is enabled, a sysctl option with name "fifo_restrictions" is
61575+ created.
61576+
61577+config GRKERNSEC_SYSFS_RESTRICT
61578+ bool "Sysfs/debugfs restriction"
61579+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61580+ depends on SYSFS
61581+ help
61582+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61583+ any filesystem normally mounted under it (e.g. debugfs) will be
61584+ mostly accessible only by root. These filesystems generally provide access
61585+ to hardware and debug information that isn't appropriate for unprivileged
61586+ users of the system. Sysfs and debugfs have also become a large source
61587+ of new vulnerabilities, ranging from infoleaks to local compromise.
61588+ There has been very little oversight with an eye toward security involved
61589+ in adding new exporters of information to these filesystems, so their
61590+ use is discouraged.
61591+ For reasons of compatibility, a few directories have been whitelisted
61592+ for access by non-root users:
61593+ /sys/fs/selinux
61594+ /sys/fs/fuse
61595+ /sys/devices/system/cpu
61596+
61597+config GRKERNSEC_ROFS
61598+ bool "Runtime read-only mount protection"
61599+ depends on SYSCTL
61600+ help
61601+ If you say Y here, a sysctl option with name "romount_protect" will
61602+ be created. By setting this option to 1 at runtime, filesystems
61603+ will be protected in the following ways:
61604+ * No new writable mounts will be allowed
61605+ * Existing read-only mounts won't be able to be remounted read/write
61606+ * Write operations will be denied on all block devices
61607+ This option acts independently of grsec_lock: once it is set to 1,
61608+ it cannot be turned off. Therefore, please be mindful of the resulting
61609+ behavior if this option is enabled in an init script on a read-only
61610+ filesystem. This feature is mainly intended for secure embedded systems.
61611+
61612+config GRKERNSEC_DEVICE_SIDECHANNEL
61613+ bool "Eliminate stat/notify-based device sidechannels"
61614+ default y if GRKERNSEC_CONFIG_AUTO
61615+ help
61616+ If you say Y here, timing analyses on block or character
61617+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61618+ will be thwarted for unprivileged users. If a process without
61619+ CAP_MKNOD stats such a device, the last access and last modify times
61620+ will match the device's create time. No access or modify events
61621+ will be triggered through inotify/dnotify/fanotify for such devices.
61622+ This feature will prevent attacks that may at a minimum
61623+ allow an attacker to determine the administrator's password length.
61624+
61625+config GRKERNSEC_CHROOT
61626+ bool "Chroot jail restrictions"
61627+ default y if GRKERNSEC_CONFIG_AUTO
61628+ help
61629+ If you say Y here, you will be able to choose several options that will
61630+ make breaking out of a chrooted jail much more difficult. If you
61631+ encounter no software incompatibilities with the following options, it
61632+ is recommended that you enable each one.
61633+
61634+config GRKERNSEC_CHROOT_MOUNT
61635+ bool "Deny mounts"
61636+ default y if GRKERNSEC_CONFIG_AUTO
61637+ depends on GRKERNSEC_CHROOT
61638+ help
61639+ If you say Y here, processes inside a chroot will not be able to
61640+ mount or remount filesystems. If the sysctl option is enabled, a
61641+ sysctl option with name "chroot_deny_mount" is created.
61642+
61643+config GRKERNSEC_CHROOT_DOUBLE
61644+ bool "Deny double-chroots"
61645+ default y if GRKERNSEC_CONFIG_AUTO
61646+ depends on GRKERNSEC_CHROOT
61647+ help
61648+ If you say Y here, processes inside a chroot will not be able to chroot
61649+ again outside the chroot. This is a widely used method of breaking
61650+ out of a chroot jail and should not be allowed. If the sysctl
61651+ option is enabled, a sysctl option with name
61652+ "chroot_deny_chroot" is created.
61653+
61654+config GRKERNSEC_CHROOT_PIVOT
61655+ bool "Deny pivot_root in chroot"
61656+ default y if GRKERNSEC_CONFIG_AUTO
61657+ depends on GRKERNSEC_CHROOT
61658+ help
61659+ If you say Y here, processes inside a chroot will not be able to use
61660+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61661+ works similar to chroot in that it changes the root filesystem. This
61662+ function could be misused in a chrooted process to attempt to break out
61663+ of the chroot, and therefore should not be allowed. If the sysctl
61664+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61665+ created.
61666+
61667+config GRKERNSEC_CHROOT_CHDIR
61668+ bool "Enforce chdir(\"/\") on all chroots"
61669+ default y if GRKERNSEC_CONFIG_AUTO
61670+ depends on GRKERNSEC_CHROOT
61671+ help
61672+ If you say Y here, the current working directory of all newly-chrooted
61673+ applications will be set to the the root directory of the chroot.
61674+ The man page on chroot(2) states:
61675+ Note that this call does not change the current working
61676+ directory, so that `.' can be outside the tree rooted at
61677+ `/'. In particular, the super-user can escape from a
61678+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61679+
61680+ It is recommended that you say Y here, since it's not known to break
61681+ any software. If the sysctl option is enabled, a sysctl option with
61682+ name "chroot_enforce_chdir" is created.
61683+
61684+config GRKERNSEC_CHROOT_CHMOD
61685+ bool "Deny (f)chmod +s"
61686+ default y if GRKERNSEC_CONFIG_AUTO
61687+ depends on GRKERNSEC_CHROOT
61688+ help
61689+ If you say Y here, processes inside a chroot will not be able to chmod
61690+ or fchmod files to make them have suid or sgid bits. This protects
61691+ against another published method of breaking a chroot. If the sysctl
61692+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61693+ created.
61694+
61695+config GRKERNSEC_CHROOT_FCHDIR
61696+ bool "Deny fchdir out of chroot"
61697+ default y if GRKERNSEC_CONFIG_AUTO
61698+ depends on GRKERNSEC_CHROOT
61699+ help
61700+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61701+ to a file descriptor of the chrooting process that points to a directory
61702+ outside the filesystem will be stopped. If the sysctl option
61703+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61704+
61705+config GRKERNSEC_CHROOT_MKNOD
61706+ bool "Deny mknod"
61707+ default y if GRKERNSEC_CONFIG_AUTO
61708+ depends on GRKERNSEC_CHROOT
61709+ help
61710+ If you say Y here, processes inside a chroot will not be allowed to
61711+ mknod. The problem with using mknod inside a chroot is that it
61712+ would allow an attacker to create a device entry that is the same
61713+ as one on the physical root of your system, which could range from
61714+ anything from the console device to a device for your harddrive (which
61715+ they could then use to wipe the drive or steal data). It is recommended
61716+ that you say Y here, unless you run into software incompatibilities.
61717+ If the sysctl option is enabled, a sysctl option with name
61718+ "chroot_deny_mknod" is created.
61719+
61720+config GRKERNSEC_CHROOT_SHMAT
61721+ bool "Deny shmat() out of chroot"
61722+ default y if GRKERNSEC_CONFIG_AUTO
61723+ depends on GRKERNSEC_CHROOT
61724+ help
61725+ If you say Y here, processes inside a chroot will not be able to attach
61726+ to shared memory segments that were created outside of the chroot jail.
61727+ It is recommended that you say Y here. If the sysctl option is enabled,
61728+ a sysctl option with name "chroot_deny_shmat" is created.
61729+
61730+config GRKERNSEC_CHROOT_UNIX
61731+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61732+ default y if GRKERNSEC_CONFIG_AUTO
61733+ depends on GRKERNSEC_CHROOT
61734+ help
61735+ If you say Y here, processes inside a chroot will not be able to
61736+ connect to abstract (meaning not belonging to a filesystem) Unix
61737+ domain sockets that were bound outside of a chroot. It is recommended
61738+ that you say Y here. If the sysctl option is enabled, a sysctl option
61739+ with name "chroot_deny_unix" is created.
61740+
61741+config GRKERNSEC_CHROOT_FINDTASK
61742+ bool "Protect outside processes"
61743+ default y if GRKERNSEC_CONFIG_AUTO
61744+ depends on GRKERNSEC_CHROOT
61745+ help
61746+ If you say Y here, processes inside a chroot will not be able to
61747+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61748+ getsid, or view any process outside of the chroot. If the sysctl
61749+ option is enabled, a sysctl option with name "chroot_findtask" is
61750+ created.
61751+
61752+config GRKERNSEC_CHROOT_NICE
61753+ bool "Restrict priority changes"
61754+ default y if GRKERNSEC_CONFIG_AUTO
61755+ depends on GRKERNSEC_CHROOT
61756+ help
61757+ If you say Y here, processes inside a chroot will not be able to raise
61758+ the priority of processes in the chroot, or alter the priority of
61759+ processes outside the chroot. This provides more security than simply
61760+ removing CAP_SYS_NICE from the process' capability set. If the
61761+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61762+ is created.
61763+
61764+config GRKERNSEC_CHROOT_SYSCTL
61765+ bool "Deny sysctl writes"
61766+ default y if GRKERNSEC_CONFIG_AUTO
61767+ depends on GRKERNSEC_CHROOT
61768+ help
61769+ If you say Y here, an attacker in a chroot will not be able to
61770+ write to sysctl entries, either by sysctl(2) or through a /proc
61771+ interface. It is strongly recommended that you say Y here. If the
61772+ sysctl option is enabled, a sysctl option with name
61773+ "chroot_deny_sysctl" is created.
61774+
61775+config GRKERNSEC_CHROOT_CAPS
61776+ bool "Capability restrictions"
61777+ default y if GRKERNSEC_CONFIG_AUTO
61778+ depends on GRKERNSEC_CHROOT
61779+ help
61780+ If you say Y here, the capabilities on all processes within a
61781+ chroot jail will be lowered to stop module insertion, raw i/o,
61782+ system and net admin tasks, rebooting the system, modifying immutable
61783+ files, modifying IPC owned by another, and changing the system time.
61784+ This is left an option because it can break some apps. Disable this
61785+ if your chrooted apps are having problems performing those kinds of
61786+ tasks. If the sysctl option is enabled, a sysctl option with
61787+ name "chroot_caps" is created.
61788+
61789+config GRKERNSEC_CHROOT_INITRD
61790+ bool "Exempt initrd tasks from restrictions"
61791+ default y if GRKERNSEC_CONFIG_AUTO
61792+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61793+ help
61794+ If you say Y here, tasks started prior to init will be exempted from
61795+ grsecurity's chroot restrictions. This option is mainly meant to
61796+ resolve Plymouth's performing privileged operations unnecessarily
61797+ in a chroot.
61798+
61799+endmenu
61800+menu "Kernel Auditing"
61801+depends on GRKERNSEC
61802+
61803+config GRKERNSEC_AUDIT_GROUP
61804+ bool "Single group for auditing"
61805+ help
61806+ If you say Y here, the exec and chdir logging features will only operate
61807+ on a group you specify. This option is recommended if you only want to
61808+ watch certain users instead of having a large amount of logs from the
61809+ entire system. If the sysctl option is enabled, a sysctl option with
61810+ name "audit_group" is created.
61811+
61812+config GRKERNSEC_AUDIT_GID
61813+ int "GID for auditing"
61814+ depends on GRKERNSEC_AUDIT_GROUP
61815+ default 1007
61816+
61817+config GRKERNSEC_EXECLOG
61818+ bool "Exec logging"
61819+ help
61820+ If you say Y here, all execve() calls will be logged (since the
61821+ other exec*() calls are frontends to execve(), all execution
61822+ will be logged). Useful for shell-servers that like to keep track
61823+ of their users. If the sysctl option is enabled, a sysctl option with
61824+ name "exec_logging" is created.
61825+ WARNING: This option when enabled will produce a LOT of logs, especially
61826+ on an active system.
61827+
61828+config GRKERNSEC_RESLOG
61829+ bool "Resource logging"
61830+ default y if GRKERNSEC_CONFIG_AUTO
61831+ help
61832+ If you say Y here, all attempts to overstep resource limits will
61833+ be logged with the resource name, the requested size, and the current
61834+ limit. It is highly recommended that you say Y here. If the sysctl
61835+ option is enabled, a sysctl option with name "resource_logging" is
61836+ created. If the RBAC system is enabled, the sysctl value is ignored.
61837+
61838+config GRKERNSEC_CHROOT_EXECLOG
61839+ bool "Log execs within chroot"
61840+ help
61841+ If you say Y here, all executions inside a chroot jail will be logged
61842+ to syslog. This can cause a large amount of logs if certain
61843+ applications (eg. djb's daemontools) are installed on the system, and
61844+ is therefore left as an option. If the sysctl option is enabled, a
61845+ sysctl option with name "chroot_execlog" is created.
61846+
61847+config GRKERNSEC_AUDIT_PTRACE
61848+ bool "Ptrace logging"
61849+ help
61850+ If you say Y here, all attempts to attach to a process via ptrace
61851+ will be logged. If the sysctl option is enabled, a sysctl option
61852+ with name "audit_ptrace" is created.
61853+
61854+config GRKERNSEC_AUDIT_CHDIR
61855+ bool "Chdir logging"
61856+ help
61857+ If you say Y here, all chdir() calls will be logged. If the sysctl
61858+ option is enabled, a sysctl option with name "audit_chdir" is created.
61859+
61860+config GRKERNSEC_AUDIT_MOUNT
61861+ bool "(Un)Mount logging"
61862+ help
61863+ If you say Y here, all mounts and unmounts will be logged. If the
61864+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61865+ created.
61866+
61867+config GRKERNSEC_SIGNAL
61868+ bool "Signal logging"
61869+ default y if GRKERNSEC_CONFIG_AUTO
61870+ help
61871+ If you say Y here, certain important signals will be logged, such as
61872+ SIGSEGV, which will as a result inform you of when a error in a program
61873+ occurred, which in some cases could mean a possible exploit attempt.
61874+ If the sysctl option is enabled, a sysctl option with name
61875+ "signal_logging" is created.
61876+
61877+config GRKERNSEC_FORKFAIL
61878+ bool "Fork failure logging"
61879+ help
61880+ If you say Y here, all failed fork() attempts will be logged.
61881+ This could suggest a fork bomb, or someone attempting to overstep
61882+ their process limit. If the sysctl option is enabled, a sysctl option
61883+ with name "forkfail_logging" is created.
61884+
61885+config GRKERNSEC_TIME
61886+ bool "Time change logging"
61887+ default y if GRKERNSEC_CONFIG_AUTO
61888+ help
61889+ If you say Y here, any changes of the system clock will be logged.
61890+ If the sysctl option is enabled, a sysctl option with name
61891+ "timechange_logging" is created.
61892+
61893+config GRKERNSEC_PROC_IPADDR
61894+ bool "/proc/<pid>/ipaddr support"
61895+ default y if GRKERNSEC_CONFIG_AUTO
61896+ help
61897+ If you say Y here, a new entry will be added to each /proc/<pid>
61898+ directory that contains the IP address of the person using the task.
61899+ The IP is carried across local TCP and AF_UNIX stream sockets.
61900+ This information can be useful for IDS/IPSes to perform remote response
61901+ to a local attack. The entry is readable by only the owner of the
61902+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61903+ the RBAC system), and thus does not create privacy concerns.
61904+
61905+config GRKERNSEC_RWXMAP_LOG
61906+ bool 'Denied RWX mmap/mprotect logging'
61907+ default y if GRKERNSEC_CONFIG_AUTO
61908+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61909+ help
61910+ If you say Y here, calls to mmap() and mprotect() with explicit
61911+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61912+ denied by the PAX_MPROTECT feature. This feature will also
61913+ log other problematic scenarios that can occur when PAX_MPROTECT
61914+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61915+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61916+ is created.
61917+
61918+endmenu
61919+
61920+menu "Executable Protections"
61921+depends on GRKERNSEC
61922+
61923+config GRKERNSEC_DMESG
61924+ bool "Dmesg(8) restriction"
61925+ default y if GRKERNSEC_CONFIG_AUTO
61926+ help
61927+ If you say Y here, non-root users will not be able to use dmesg(8)
61928+ to view the contents of the kernel's circular log buffer.
61929+ The kernel's log buffer often contains kernel addresses and other
61930+ identifying information useful to an attacker in fingerprinting a
61931+ system for a targeted exploit.
61932+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61933+ created.
61934+
61935+config GRKERNSEC_HARDEN_PTRACE
61936+ bool "Deter ptrace-based process snooping"
61937+ default y if GRKERNSEC_CONFIG_AUTO
61938+ help
61939+ If you say Y here, TTY sniffers and other malicious monitoring
61940+ programs implemented through ptrace will be defeated. If you
61941+ have been using the RBAC system, this option has already been
61942+ enabled for several years for all users, with the ability to make
61943+ fine-grained exceptions.
61944+
61945+ This option only affects the ability of non-root users to ptrace
61946+ processes that are not a descendent of the ptracing process.
61947+ This means that strace ./binary and gdb ./binary will still work,
61948+ but attaching to arbitrary processes will not. If the sysctl
61949+ option is enabled, a sysctl option with name "harden_ptrace" is
61950+ created.
61951+
61952+config GRKERNSEC_PTRACE_READEXEC
61953+ bool "Require read access to ptrace sensitive binaries"
61954+ default y if GRKERNSEC_CONFIG_AUTO
61955+ help
61956+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61957+ binaries. This option is useful in environments that
61958+ remove the read bits (e.g. file mode 4711) from suid binaries to
61959+ prevent infoleaking of their contents. This option adds
61960+ consistency to the use of that file mode, as the binary could normally
61961+ be read out when run without privileges while ptracing.
61962+
61963+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61964+ is created.
61965+
61966+config GRKERNSEC_SETXID
61967+ bool "Enforce consistent multithreaded privileges"
61968+ default y if GRKERNSEC_CONFIG_AUTO
61969+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61970+ help
61971+ If you say Y here, a change from a root uid to a non-root uid
61972+ in a multithreaded application will cause the resulting uids,
61973+ gids, supplementary groups, and capabilities in that thread
61974+ to be propagated to the other threads of the process. In most
61975+ cases this is unnecessary, as glibc will emulate this behavior
61976+ on behalf of the application. Other libcs do not act in the
61977+ same way, allowing the other threads of the process to continue
61978+ running with root privileges. If the sysctl option is enabled,
61979+ a sysctl option with name "consistent_setxid" is created.
61980+
61981+config GRKERNSEC_TPE
61982+ bool "Trusted Path Execution (TPE)"
61983+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61984+ help
61985+ If you say Y here, you will be able to choose a gid to add to the
61986+ supplementary groups of users you want to mark as "untrusted."
61987+ These users will not be able to execute any files that are not in
61988+ root-owned directories writable only by root. If the sysctl option
61989+ is enabled, a sysctl option with name "tpe" is created.
61990+
61991+config GRKERNSEC_TPE_ALL
61992+ bool "Partially restrict all non-root users"
61993+ depends on GRKERNSEC_TPE
61994+ help
61995+ If you say Y here, all non-root users will be covered under
61996+ a weaker TPE restriction. This is separate from, and in addition to,
61997+ the main TPE options that you have selected elsewhere. Thus, if a
61998+ "trusted" GID is chosen, this restriction applies to even that GID.
61999+ Under this restriction, all non-root users will only be allowed to
62000+ execute files in directories they own that are not group or
62001+ world-writable, or in directories owned by root and writable only by
62002+ root. If the sysctl option is enabled, a sysctl option with name
62003+ "tpe_restrict_all" is created.
62004+
62005+config GRKERNSEC_TPE_INVERT
62006+ bool "Invert GID option"
62007+ depends on GRKERNSEC_TPE
62008+ help
62009+ If you say Y here, the group you specify in the TPE configuration will
62010+ decide what group TPE restrictions will be *disabled* for. This
62011+ option is useful if you want TPE restrictions to be applied to most
62012+ users on the system. If the sysctl option is enabled, a sysctl option
62013+ with name "tpe_invert" is created. Unlike other sysctl options, this
62014+ entry will default to on for backward-compatibility.
62015+
62016+config GRKERNSEC_TPE_GID
62017+ int
62018+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
62019+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
62020+
62021+config GRKERNSEC_TPE_UNTRUSTED_GID
62022+ int "GID for TPE-untrusted users"
62023+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
62024+ default 1005
62025+ help
62026+ Setting this GID determines what group TPE restrictions will be
62027+ *enabled* for. If the sysctl option is enabled, a sysctl option
62028+ with name "tpe_gid" is created.
62029+
62030+config GRKERNSEC_TPE_TRUSTED_GID
62031+ int "GID for TPE-trusted users"
62032+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
62033+ default 1005
62034+ help
62035+ Setting this GID determines what group TPE restrictions will be
62036+ *disabled* for. If the sysctl option is enabled, a sysctl option
62037+ with name "tpe_gid" is created.
62038+
62039+endmenu
62040+menu "Network Protections"
62041+depends on GRKERNSEC
62042+
62043+config GRKERNSEC_RANDNET
62044+ bool "Larger entropy pools"
62045+ default y if GRKERNSEC_CONFIG_AUTO
62046+ help
62047+ If you say Y here, the entropy pools used for many features of Linux
62048+ and grsecurity will be doubled in size. Since several grsecurity
62049+ features use additional randomness, it is recommended that you say Y
62050+ here. Saying Y here has a similar effect as modifying
62051+ /proc/sys/kernel/random/poolsize.
62052+
62053+config GRKERNSEC_BLACKHOLE
62054+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
62055+ default y if GRKERNSEC_CONFIG_AUTO
62056+ depends on NET
62057+ help
62058+ If you say Y here, neither TCP resets nor ICMP
62059+ destination-unreachable packets will be sent in response to packets
62060+ sent to ports for which no associated listening process exists.
62061+ This feature supports both IPV4 and IPV6 and exempts the
62062+ loopback interface from blackholing. Enabling this feature
62063+ makes a host more resilient to DoS attacks and reduces network
62064+ visibility against scanners.
62065+
62066+ The blackhole feature as-implemented is equivalent to the FreeBSD
62067+ blackhole feature, as it prevents RST responses to all packets, not
62068+ just SYNs. Under most application behavior this causes no
62069+ problems, but applications (like haproxy) may not close certain
62070+ connections in a way that cleanly terminates them on the remote
62071+ end, leaving the remote host in LAST_ACK state. Because of this
62072+ side-effect and to prevent intentional LAST_ACK DoSes, this
62073+ feature also adds automatic mitigation against such attacks.
62074+ The mitigation drastically reduces the amount of time a socket
62075+ can spend in LAST_ACK state. If you're using haproxy and not
62076+ all servers it connects to have this option enabled, consider
62077+ disabling this feature on the haproxy host.
62078+
62079+ If the sysctl option is enabled, two sysctl options with names
62080+ "ip_blackhole" and "lastack_retries" will be created.
62081+ While "ip_blackhole" takes the standard zero/non-zero on/off
62082+ toggle, "lastack_retries" uses the same kinds of values as
62083+ "tcp_retries1" and "tcp_retries2". The default value of 4
62084+ prevents a socket from lasting more than 45 seconds in LAST_ACK
62085+ state.
62086+
62087+config GRKERNSEC_NO_SIMULT_CONNECT
62088+ bool "Disable TCP Simultaneous Connect"
62089+ default y if GRKERNSEC_CONFIG_AUTO
62090+ depends on NET
62091+ help
62092+ If you say Y here, a feature by Willy Tarreau will be enabled that
62093+ removes a weakness in Linux's strict implementation of TCP that
62094+ allows two clients to connect to each other without either entering
62095+ a listening state. The weakness allows an attacker to easily prevent
62096+ a client from connecting to a known server provided the source port
62097+ for the connection is guessed correctly.
62098+
62099+ As the weakness could be used to prevent an antivirus or IPS from
62100+ fetching updates, or prevent an SSL gateway from fetching a CRL,
62101+ it should be eliminated by enabling this option. Though Linux is
62102+ one of few operating systems supporting simultaneous connect, it
62103+ has no legitimate use in practice and is rarely supported by firewalls.
62104+
62105+config GRKERNSEC_SOCKET
62106+ bool "Socket restrictions"
62107+ depends on NET
62108+ help
62109+ If you say Y here, you will be able to choose from several options.
62110+ If you assign a GID on your system and add it to the supplementary
62111+ groups of users you want to restrict socket access to, this patch
62112+ will perform up to three things, based on the option(s) you choose.
62113+
62114+config GRKERNSEC_SOCKET_ALL
62115+ bool "Deny any sockets to group"
62116+ depends on GRKERNSEC_SOCKET
62117+ help
62118+ If you say Y here, you will be able to choose a GID of whose users will
62119+ be unable to connect to other hosts from your machine or run server
62120+ applications from your machine. If the sysctl option is enabled, a
62121+ sysctl option with name "socket_all" is created.
62122+
62123+config GRKERNSEC_SOCKET_ALL_GID
62124+ int "GID to deny all sockets for"
62125+ depends on GRKERNSEC_SOCKET_ALL
62126+ default 1004
62127+ help
62128+ Here you can choose the GID to disable socket access for. Remember to
62129+ add the users you want socket access disabled for to the GID
62130+ specified here. If the sysctl option is enabled, a sysctl option
62131+ with name "socket_all_gid" is created.
62132+
62133+config GRKERNSEC_SOCKET_CLIENT
62134+ bool "Deny client sockets to group"
62135+ depends on GRKERNSEC_SOCKET
62136+ help
62137+ If you say Y here, you will be able to choose a GID of whose users will
62138+ be unable to connect to other hosts from your machine, but will be
62139+ able to run servers. If this option is enabled, all users in the group
62140+ you specify will have to use passive mode when initiating ftp transfers
62141+ from the shell on your machine. If the sysctl option is enabled, a
62142+ sysctl option with name "socket_client" is created.
62143+
62144+config GRKERNSEC_SOCKET_CLIENT_GID
62145+ int "GID to deny client sockets for"
62146+ depends on GRKERNSEC_SOCKET_CLIENT
62147+ default 1003
62148+ help
62149+ Here you can choose the GID to disable client socket access for.
62150+ Remember to add the users you want client socket access disabled for to
62151+ the GID specified here. If the sysctl option is enabled, a sysctl
62152+ option with name "socket_client_gid" is created.
62153+
62154+config GRKERNSEC_SOCKET_SERVER
62155+ bool "Deny server sockets to group"
62156+ depends on GRKERNSEC_SOCKET
62157+ help
62158+ If you say Y here, you will be able to choose a GID of whose users will
62159+ be unable to run server applications from your machine. If the sysctl
62160+ option is enabled, a sysctl option with name "socket_server" is created.
62161+
62162+config GRKERNSEC_SOCKET_SERVER_GID
62163+ int "GID to deny server sockets for"
62164+ depends on GRKERNSEC_SOCKET_SERVER
62165+ default 1002
62166+ help
62167+ Here you can choose the GID to disable server socket access for.
62168+ Remember to add the users you want server socket access disabled for to
62169+ the GID specified here. If the sysctl option is enabled, a sysctl
62170+ option with name "socket_server_gid" is created.
62171+
62172+endmenu
62173+
62174+menu "Physical Protections"
62175+depends on GRKERNSEC
62176+
62177+config GRKERNSEC_DENYUSB
62178+ bool "Deny new USB connections after toggle"
62179+ default y if GRKERNSEC_CONFIG_AUTO
62180+ depends on SYSCTL && USB_SUPPORT
62181+ help
62182+ If you say Y here, a new sysctl option with name "deny_new_usb"
62183+ will be created. Setting its value to 1 will prevent any new
62184+ USB devices from being recognized by the OS. Any attempted USB
62185+ device insertion will be logged. This option is intended to be
62186+ used against custom USB devices designed to exploit vulnerabilities
62187+ in various USB device drivers.
62188+
62189+ For greatest effectiveness, this sysctl should be set after any
62190+ relevant init scripts. This option is safe to enable in distros
62191+ as each user can choose whether or not to toggle the sysctl.
62192+
62193+config GRKERNSEC_DENYUSB_FORCE
62194+ bool "Reject all USB devices not connected at boot"
62195+ select USB
62196+ depends on GRKERNSEC_DENYUSB
62197+ help
62198+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62199+ that doesn't involve a sysctl entry. This option should only be
62200+ enabled if you're sure you want to deny all new USB connections
62201+ at runtime and don't want to modify init scripts. This should not
62202+ be enabled by distros. It forces the core USB code to be built
62203+ into the kernel image so that all devices connected at boot time
62204+ can be recognized and new USB device connections can be prevented
62205+ prior to init running.
62206+
62207+endmenu
62208+
62209+menu "Sysctl Support"
62210+depends on GRKERNSEC && SYSCTL
62211+
62212+config GRKERNSEC_SYSCTL
62213+ bool "Sysctl support"
62214+ default y if GRKERNSEC_CONFIG_AUTO
62215+ help
62216+ If you say Y here, you will be able to change the options that
62217+ grsecurity runs with at bootup, without having to recompile your
62218+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62219+ to enable (1) or disable (0) various features. All the sysctl entries
62220+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62221+ All features enabled in the kernel configuration are disabled at boot
62222+ if you do not say Y to the "Turn on features by default" option.
62223+ All options should be set at startup, and the grsec_lock entry should
62224+ be set to a non-zero value after all the options are set.
62225+ *THIS IS EXTREMELY IMPORTANT*
62226+
62227+config GRKERNSEC_SYSCTL_DISTRO
62228+ bool "Extra sysctl support for distro makers (READ HELP)"
62229+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62230+ help
62231+ If you say Y here, additional sysctl options will be created
62232+ for features that affect processes running as root. Therefore,
62233+ it is critical when using this option that the grsec_lock entry be
62234+ enabled after boot. Only distros with prebuilt kernel packages
62235+ with this option enabled that can ensure grsec_lock is enabled
62236+ after boot should use this option.
62237+ *Failure to set grsec_lock after boot makes all grsec features
62238+ this option covers useless*
62239+
62240+ Currently this option creates the following sysctl entries:
62241+ "Disable Privileged I/O": "disable_priv_io"
62242+
62243+config GRKERNSEC_SYSCTL_ON
62244+ bool "Turn on features by default"
62245+ default y if GRKERNSEC_CONFIG_AUTO
62246+ depends on GRKERNSEC_SYSCTL
62247+ help
62248+ If you say Y here, instead of having all features enabled in the
62249+ kernel configuration disabled at boot time, the features will be
62250+ enabled at boot time. It is recommended you say Y here unless
62251+ there is some reason you would want all sysctl-tunable features to
62252+ be disabled by default. As mentioned elsewhere, it is important
62253+ to enable the grsec_lock entry once you have finished modifying
62254+ the sysctl entries.
62255+
62256+endmenu
62257+menu "Logging Options"
62258+depends on GRKERNSEC
62259+
62260+config GRKERNSEC_FLOODTIME
62261+ int "Seconds in between log messages (minimum)"
62262+ default 10
62263+ help
62264+ This option allows you to enforce the number of seconds between
62265+ grsecurity log messages. The default should be suitable for most
62266+ people, however, if you choose to change it, choose a value small enough
62267+ to allow informative logs to be produced, but large enough to
62268+ prevent flooding.
62269+
62270+config GRKERNSEC_FLOODBURST
62271+ int "Number of messages in a burst (maximum)"
62272+ default 6
62273+ help
62274+ This option allows you to choose the maximum number of messages allowed
62275+ within the flood time interval you chose in a separate option. The
62276+ default should be suitable for most people, however if you find that
62277+ many of your logs are being interpreted as flooding, you may want to
62278+ raise this value.
62279+
62280+endmenu
62281diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62282new file mode 100644
62283index 0000000..b0b77d5
62284--- /dev/null
62285+++ b/grsecurity/Makefile
62286@@ -0,0 +1,43 @@
62287+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62288+# during 2001-2009 it has been completely redesigned by Brad Spengler
62289+# into an RBAC system
62290+#
62291+# All code in this directory and various hooks inserted throughout the kernel
62292+# are copyright Brad Spengler - Open Source Security, Inc., and released
62293+# under the GPL v2 or higher
62294+
62295+KBUILD_CFLAGS += -Werror
62296+
62297+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62298+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62299+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62300+ grsec_usb.o
62301+
62302+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62303+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62304+ gracl_learn.o grsec_log.o
62305+ifdef CONFIG_COMPAT
62306+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62307+endif
62308+
62309+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62310+
62311+ifdef CONFIG_NET
62312+obj-y += grsec_sock.o
62313+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62314+endif
62315+
62316+ifndef CONFIG_GRKERNSEC
62317+obj-y += grsec_disabled.o
62318+endif
62319+
62320+ifdef CONFIG_GRKERNSEC_HIDESYM
62321+extra-y := grsec_hidesym.o
62322+$(obj)/grsec_hidesym.o:
62323+ @-chmod -f 500 /boot
62324+ @-chmod -f 500 /lib/modules
62325+ @-chmod -f 500 /lib64/modules
62326+ @-chmod -f 500 /lib32/modules
62327+ @-chmod -f 700 .
62328+ @echo ' grsec: protected kernel image paths'
62329+endif
62330diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62331new file mode 100644
62332index 0000000..c0793fd
62333--- /dev/null
62334+++ b/grsecurity/gracl.c
62335@@ -0,0 +1,4178 @@
62336+#include <linux/kernel.h>
62337+#include <linux/module.h>
62338+#include <linux/sched.h>
62339+#include <linux/mm.h>
62340+#include <linux/file.h>
62341+#include <linux/fs.h>
62342+#include <linux/namei.h>
62343+#include <linux/mount.h>
62344+#include <linux/tty.h>
62345+#include <linux/proc_fs.h>
62346+#include <linux/lglock.h>
62347+#include <linux/slab.h>
62348+#include <linux/vmalloc.h>
62349+#include <linux/types.h>
62350+#include <linux/sysctl.h>
62351+#include <linux/netdevice.h>
62352+#include <linux/ptrace.h>
62353+#include <linux/gracl.h>
62354+#include <linux/gralloc.h>
62355+#include <linux/security.h>
62356+#include <linux/grinternal.h>
62357+#include <linux/pid_namespace.h>
62358+#include <linux/stop_machine.h>
62359+#include <linux/fdtable.h>
62360+#include <linux/percpu.h>
62361+#include <linux/lglock.h>
62362+#include <linux/hugetlb.h>
62363+#include <linux/posix-timers.h>
62364+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62365+#include <linux/magic.h>
62366+#include <linux/pagemap.h>
62367+#include "../fs/btrfs/async-thread.h"
62368+#include "../fs/btrfs/ctree.h"
62369+#include "../fs/btrfs/btrfs_inode.h"
62370+#endif
62371+#include "../fs/mount.h"
62372+
62373+#include <asm/uaccess.h>
62374+#include <asm/errno.h>
62375+#include <asm/mman.h>
62376+
62377+extern struct lglock vfsmount_lock;
62378+
62379+static struct acl_role_db acl_role_set;
62380+static struct name_db name_set;
62381+static struct inodev_db inodev_set;
62382+
62383+/* for keeping track of userspace pointers used for subjects, so we
62384+ can share references in the kernel as well
62385+*/
62386+
62387+static struct path real_root;
62388+
62389+static struct acl_subj_map_db subj_map_set;
62390+
62391+static struct acl_role_label *default_role;
62392+
62393+static struct acl_role_label *role_list;
62394+
62395+static u16 acl_sp_role_value;
62396+
62397+extern char *gr_shared_page[4];
62398+static DEFINE_MUTEX(gr_dev_mutex);
62399+DEFINE_RWLOCK(gr_inode_lock);
62400+
62401+struct gr_arg *gr_usermode;
62402+
62403+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62404+
62405+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62406+extern void gr_clear_learn_entries(void);
62407+
62408+unsigned char *gr_system_salt;
62409+unsigned char *gr_system_sum;
62410+
62411+static struct sprole_pw **acl_special_roles = NULL;
62412+static __u16 num_sprole_pws = 0;
62413+
62414+static struct acl_role_label *kernel_role = NULL;
62415+
62416+static unsigned int gr_auth_attempts = 0;
62417+static unsigned long gr_auth_expires = 0UL;
62418+
62419+#ifdef CONFIG_NET
62420+extern struct vfsmount *sock_mnt;
62421+#endif
62422+
62423+extern struct vfsmount *pipe_mnt;
62424+extern struct vfsmount *shm_mnt;
62425+
62426+#ifdef CONFIG_HUGETLBFS
62427+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62428+#endif
62429+
62430+static struct acl_object_label *fakefs_obj_rw;
62431+static struct acl_object_label *fakefs_obj_rwx;
62432+
62433+extern int gr_init_uidset(void);
62434+extern void gr_free_uidset(void);
62435+extern void gr_remove_uid(uid_t uid);
62436+extern int gr_find_uid(uid_t uid);
62437+
62438+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62439+{
62440+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62441+ return -EFAULT;
62442+
62443+ return 0;
62444+}
62445+
62446+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62447+{
62448+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62449+ return -EFAULT;
62450+
62451+ return 0;
62452+}
62453+
62454+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62455+{
62456+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62457+ return -EFAULT;
62458+
62459+ return 0;
62460+}
62461+
62462+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62463+{
62464+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62465+ return -EFAULT;
62466+
62467+ return 0;
62468+}
62469+
62470+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62471+{
62472+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62473+ return -EFAULT;
62474+
62475+ return 0;
62476+}
62477+
62478+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62479+{
62480+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62481+ return -EFAULT;
62482+
62483+ return 0;
62484+}
62485+
62486+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62487+{
62488+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62489+ return -EFAULT;
62490+
62491+ return 0;
62492+}
62493+
62494+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62495+{
62496+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62497+ return -EFAULT;
62498+
62499+ return 0;
62500+}
62501+
62502+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62503+{
62504+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62505+ return -EFAULT;
62506+
62507+ return 0;
62508+}
62509+
62510+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62511+{
62512+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62513+ return -EFAULT;
62514+
62515+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62516+ return -EINVAL;
62517+
62518+ return 0;
62519+}
62520+
62521+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62522+{
62523+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62524+ return -EFAULT;
62525+
62526+ return 0;
62527+}
62528+
62529+static size_t get_gr_arg_wrapper_size_normal(void)
62530+{
62531+ return sizeof(struct gr_arg_wrapper);
62532+}
62533+
62534+#ifdef CONFIG_COMPAT
62535+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62536+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62537+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62538+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62539+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62540+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62541+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62542+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62543+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62544+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62545+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62546+extern size_t get_gr_arg_wrapper_size_compat(void);
62547+
62548+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62549+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62550+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62551+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62552+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62553+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62554+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62555+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62556+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62557+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62558+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62559+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62560+
62561+#else
62562+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62563+#define copy_gr_arg copy_gr_arg_normal
62564+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62565+#define copy_acl_object_label copy_acl_object_label_normal
62566+#define copy_acl_subject_label copy_acl_subject_label_normal
62567+#define copy_acl_role_label copy_acl_role_label_normal
62568+#define copy_acl_ip_label copy_acl_ip_label_normal
62569+#define copy_pointer_from_array copy_pointer_from_array_normal
62570+#define copy_sprole_pw copy_sprole_pw_normal
62571+#define copy_role_transition copy_role_transition_normal
62572+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62573+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62574+#endif
62575+
62576+__inline__ int
62577+gr_acl_is_enabled(void)
62578+{
62579+ return (gr_status & GR_READY);
62580+}
62581+
62582+static inline dev_t __get_dev(const struct dentry *dentry)
62583+{
62584+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62585+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62586+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62587+ else
62588+#endif
62589+ return dentry->d_sb->s_dev;
62590+}
62591+
62592+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62593+{
62594+ return __get_dev(dentry);
62595+}
62596+
62597+static char gr_task_roletype_to_char(struct task_struct *task)
62598+{
62599+ switch (task->role->roletype &
62600+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62601+ GR_ROLE_SPECIAL)) {
62602+ case GR_ROLE_DEFAULT:
62603+ return 'D';
62604+ case GR_ROLE_USER:
62605+ return 'U';
62606+ case GR_ROLE_GROUP:
62607+ return 'G';
62608+ case GR_ROLE_SPECIAL:
62609+ return 'S';
62610+ }
62611+
62612+ return 'X';
62613+}
62614+
62615+char gr_roletype_to_char(void)
62616+{
62617+ return gr_task_roletype_to_char(current);
62618+}
62619+
62620+__inline__ int
62621+gr_acl_tpe_check(void)
62622+{
62623+ if (unlikely(!(gr_status & GR_READY)))
62624+ return 0;
62625+ if (current->role->roletype & GR_ROLE_TPE)
62626+ return 1;
62627+ else
62628+ return 0;
62629+}
62630+
62631+int
62632+gr_handle_rawio(const struct inode *inode)
62633+{
62634+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62635+ if (inode && S_ISBLK(inode->i_mode) &&
62636+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62637+ !capable(CAP_SYS_RAWIO))
62638+ return 1;
62639+#endif
62640+ return 0;
62641+}
62642+
62643+static int
62644+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62645+{
62646+ if (likely(lena != lenb))
62647+ return 0;
62648+
62649+ return !memcmp(a, b, lena);
62650+}
62651+
62652+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62653+{
62654+ *buflen -= namelen;
62655+ if (*buflen < 0)
62656+ return -ENAMETOOLONG;
62657+ *buffer -= namelen;
62658+ memcpy(*buffer, str, namelen);
62659+ return 0;
62660+}
62661+
62662+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62663+{
62664+ return prepend(buffer, buflen, name->name, name->len);
62665+}
62666+
62667+static int prepend_path(const struct path *path, struct path *root,
62668+ char **buffer, int *buflen)
62669+{
62670+ struct dentry *dentry = path->dentry;
62671+ struct vfsmount *vfsmnt = path->mnt;
62672+ struct mount *mnt = real_mount(vfsmnt);
62673+ bool slash = false;
62674+ int error = 0;
62675+
62676+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62677+ struct dentry * parent;
62678+
62679+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62680+ /* Global root? */
62681+ if (!mnt_has_parent(mnt)) {
62682+ goto out;
62683+ }
62684+ dentry = mnt->mnt_mountpoint;
62685+ mnt = mnt->mnt_parent;
62686+ vfsmnt = &mnt->mnt;
62687+ continue;
62688+ }
62689+ parent = dentry->d_parent;
62690+ prefetch(parent);
62691+ spin_lock(&dentry->d_lock);
62692+ error = prepend_name(buffer, buflen, &dentry->d_name);
62693+ spin_unlock(&dentry->d_lock);
62694+ if (!error)
62695+ error = prepend(buffer, buflen, "/", 1);
62696+ if (error)
62697+ break;
62698+
62699+ slash = true;
62700+ dentry = parent;
62701+ }
62702+
62703+out:
62704+ if (!error && !slash)
62705+ error = prepend(buffer, buflen, "/", 1);
62706+
62707+ return error;
62708+}
62709+
62710+/* this must be called with vfsmount_lock and rename_lock held */
62711+
62712+static char *__our_d_path(const struct path *path, struct path *root,
62713+ char *buf, int buflen)
62714+{
62715+ char *res = buf + buflen;
62716+ int error;
62717+
62718+ prepend(&res, &buflen, "\0", 1);
62719+ error = prepend_path(path, root, &res, &buflen);
62720+ if (error)
62721+ return ERR_PTR(error);
62722+
62723+ return res;
62724+}
62725+
62726+static char *
62727+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62728+{
62729+ char *retval;
62730+
62731+ retval = __our_d_path(path, root, buf, buflen);
62732+ if (unlikely(IS_ERR(retval)))
62733+ retval = strcpy(buf, "<path too long>");
62734+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62735+ retval[1] = '\0';
62736+
62737+ return retval;
62738+}
62739+
62740+static char *
62741+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62742+ char *buf, int buflen)
62743+{
62744+ struct path path;
62745+ char *res;
62746+
62747+ path.dentry = (struct dentry *)dentry;
62748+ path.mnt = (struct vfsmount *)vfsmnt;
62749+
62750+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62751+ by the RBAC system */
62752+ res = gen_full_path(&path, &real_root, buf, buflen);
62753+
62754+ return res;
62755+}
62756+
62757+static char *
62758+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62759+ char *buf, int buflen)
62760+{
62761+ char *res;
62762+ struct path path;
62763+ struct path root;
62764+ struct task_struct *reaper = init_pid_ns.child_reaper;
62765+
62766+ path.dentry = (struct dentry *)dentry;
62767+ path.mnt = (struct vfsmount *)vfsmnt;
62768+
62769+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62770+ get_fs_root(reaper->fs, &root);
62771+
62772+ br_read_lock(&vfsmount_lock);
62773+ write_seqlock(&rename_lock);
62774+ res = gen_full_path(&path, &root, buf, buflen);
62775+ write_sequnlock(&rename_lock);
62776+ br_read_unlock(&vfsmount_lock);
62777+
62778+ path_put(&root);
62779+ return res;
62780+}
62781+
62782+static char *
62783+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62784+{
62785+ char *ret;
62786+ br_read_lock(&vfsmount_lock);
62787+ write_seqlock(&rename_lock);
62788+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62789+ PAGE_SIZE);
62790+ write_sequnlock(&rename_lock);
62791+ br_read_unlock(&vfsmount_lock);
62792+ return ret;
62793+}
62794+
62795+static char *
62796+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62797+{
62798+ char *ret;
62799+ char *buf;
62800+ int buflen;
62801+
62802+ br_read_lock(&vfsmount_lock);
62803+ write_seqlock(&rename_lock);
62804+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62805+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62806+ buflen = (int)(ret - buf);
62807+ if (buflen >= 5)
62808+ prepend(&ret, &buflen, "/proc", 5);
62809+ else
62810+ ret = strcpy(buf, "<path too long>");
62811+ write_sequnlock(&rename_lock);
62812+ br_read_unlock(&vfsmount_lock);
62813+ return ret;
62814+}
62815+
62816+char *
62817+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62818+{
62819+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62820+ PAGE_SIZE);
62821+}
62822+
62823+char *
62824+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62825+{
62826+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62827+ PAGE_SIZE);
62828+}
62829+
62830+char *
62831+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62832+{
62833+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62834+ PAGE_SIZE);
62835+}
62836+
62837+char *
62838+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62839+{
62840+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62841+ PAGE_SIZE);
62842+}
62843+
62844+char *
62845+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62846+{
62847+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62848+ PAGE_SIZE);
62849+}
62850+
62851+__inline__ __u32
62852+to_gr_audit(const __u32 reqmode)
62853+{
62854+ /* masks off auditable permission flags, then shifts them to create
62855+ auditing flags, and adds the special case of append auditing if
62856+ we're requesting write */
62857+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62858+}
62859+
62860+struct acl_subject_label *
62861+lookup_subject_map(const struct acl_subject_label *userp)
62862+{
62863+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62864+ struct subject_map *match;
62865+
62866+ match = subj_map_set.s_hash[index];
62867+
62868+ while (match && match->user != userp)
62869+ match = match->next;
62870+
62871+ if (match != NULL)
62872+ return match->kernel;
62873+ else
62874+ return NULL;
62875+}
62876+
62877+static void
62878+insert_subj_map_entry(struct subject_map *subjmap)
62879+{
62880+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62881+ struct subject_map **curr;
62882+
62883+ subjmap->prev = NULL;
62884+
62885+ curr = &subj_map_set.s_hash[index];
62886+ if (*curr != NULL)
62887+ (*curr)->prev = subjmap;
62888+
62889+ subjmap->next = *curr;
62890+ *curr = subjmap;
62891+
62892+ return;
62893+}
62894+
62895+static struct acl_role_label *
62896+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62897+ const gid_t gid)
62898+{
62899+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62900+ struct acl_role_label *match;
62901+ struct role_allowed_ip *ipp;
62902+ unsigned int x;
62903+ u32 curr_ip = task->signal->curr_ip;
62904+
62905+ task->signal->saved_ip = curr_ip;
62906+
62907+ match = acl_role_set.r_hash[index];
62908+
62909+ while (match) {
62910+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62911+ for (x = 0; x < match->domain_child_num; x++) {
62912+ if (match->domain_children[x] == uid)
62913+ goto found;
62914+ }
62915+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62916+ break;
62917+ match = match->next;
62918+ }
62919+found:
62920+ if (match == NULL) {
62921+ try_group:
62922+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62923+ match = acl_role_set.r_hash[index];
62924+
62925+ while (match) {
62926+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62927+ for (x = 0; x < match->domain_child_num; x++) {
62928+ if (match->domain_children[x] == gid)
62929+ goto found2;
62930+ }
62931+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62932+ break;
62933+ match = match->next;
62934+ }
62935+found2:
62936+ if (match == NULL)
62937+ match = default_role;
62938+ if (match->allowed_ips == NULL)
62939+ return match;
62940+ else {
62941+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62942+ if (likely
62943+ ((ntohl(curr_ip) & ipp->netmask) ==
62944+ (ntohl(ipp->addr) & ipp->netmask)))
62945+ return match;
62946+ }
62947+ match = default_role;
62948+ }
62949+ } else if (match->allowed_ips == NULL) {
62950+ return match;
62951+ } else {
62952+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62953+ if (likely
62954+ ((ntohl(curr_ip) & ipp->netmask) ==
62955+ (ntohl(ipp->addr) & ipp->netmask)))
62956+ return match;
62957+ }
62958+ goto try_group;
62959+ }
62960+
62961+ return match;
62962+}
62963+
62964+struct acl_subject_label *
62965+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62966+ const struct acl_role_label *role)
62967+{
62968+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62969+ struct acl_subject_label *match;
62970+
62971+ match = role->subj_hash[index];
62972+
62973+ while (match && (match->inode != ino || match->device != dev ||
62974+ (match->mode & GR_DELETED))) {
62975+ match = match->next;
62976+ }
62977+
62978+ if (match && !(match->mode & GR_DELETED))
62979+ return match;
62980+ else
62981+ return NULL;
62982+}
62983+
62984+struct acl_subject_label *
62985+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62986+ const struct acl_role_label *role)
62987+{
62988+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62989+ struct acl_subject_label *match;
62990+
62991+ match = role->subj_hash[index];
62992+
62993+ while (match && (match->inode != ino || match->device != dev ||
62994+ !(match->mode & GR_DELETED))) {
62995+ match = match->next;
62996+ }
62997+
62998+ if (match && (match->mode & GR_DELETED))
62999+ return match;
63000+ else
63001+ return NULL;
63002+}
63003+
63004+static struct acl_object_label *
63005+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
63006+ const struct acl_subject_label *subj)
63007+{
63008+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63009+ struct acl_object_label *match;
63010+
63011+ match = subj->obj_hash[index];
63012+
63013+ while (match && (match->inode != ino || match->device != dev ||
63014+ (match->mode & GR_DELETED))) {
63015+ match = match->next;
63016+ }
63017+
63018+ if (match && !(match->mode & GR_DELETED))
63019+ return match;
63020+ else
63021+ return NULL;
63022+}
63023+
63024+static struct acl_object_label *
63025+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
63026+ const struct acl_subject_label *subj)
63027+{
63028+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63029+ struct acl_object_label *match;
63030+
63031+ match = subj->obj_hash[index];
63032+
63033+ while (match && (match->inode != ino || match->device != dev ||
63034+ !(match->mode & GR_DELETED))) {
63035+ match = match->next;
63036+ }
63037+
63038+ if (match && (match->mode & GR_DELETED))
63039+ return match;
63040+
63041+ match = subj->obj_hash[index];
63042+
63043+ while (match && (match->inode != ino || match->device != dev ||
63044+ (match->mode & GR_DELETED))) {
63045+ match = match->next;
63046+ }
63047+
63048+ if (match && !(match->mode & GR_DELETED))
63049+ return match;
63050+ else
63051+ return NULL;
63052+}
63053+
63054+static struct name_entry *
63055+lookup_name_entry(const char *name)
63056+{
63057+ unsigned int len = strlen(name);
63058+ unsigned int key = full_name_hash(name, len);
63059+ unsigned int index = key % name_set.n_size;
63060+ struct name_entry *match;
63061+
63062+ match = name_set.n_hash[index];
63063+
63064+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
63065+ match = match->next;
63066+
63067+ return match;
63068+}
63069+
63070+static struct name_entry *
63071+lookup_name_entry_create(const char *name)
63072+{
63073+ unsigned int len = strlen(name);
63074+ unsigned int key = full_name_hash(name, len);
63075+ unsigned int index = key % name_set.n_size;
63076+ struct name_entry *match;
63077+
63078+ match = name_set.n_hash[index];
63079+
63080+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63081+ !match->deleted))
63082+ match = match->next;
63083+
63084+ if (match && match->deleted)
63085+ return match;
63086+
63087+ match = name_set.n_hash[index];
63088+
63089+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63090+ match->deleted))
63091+ match = match->next;
63092+
63093+ if (match && !match->deleted)
63094+ return match;
63095+ else
63096+ return NULL;
63097+}
63098+
63099+static struct inodev_entry *
63100+lookup_inodev_entry(const ino_t ino, const dev_t dev)
63101+{
63102+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
63103+ struct inodev_entry *match;
63104+
63105+ match = inodev_set.i_hash[index];
63106+
63107+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
63108+ match = match->next;
63109+
63110+ return match;
63111+}
63112+
63113+static void
63114+insert_inodev_entry(struct inodev_entry *entry)
63115+{
63116+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
63117+ inodev_set.i_size);
63118+ struct inodev_entry **curr;
63119+
63120+ entry->prev = NULL;
63121+
63122+ curr = &inodev_set.i_hash[index];
63123+ if (*curr != NULL)
63124+ (*curr)->prev = entry;
63125+
63126+ entry->next = *curr;
63127+ *curr = entry;
63128+
63129+ return;
63130+}
63131+
63132+static void
63133+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
63134+{
63135+ unsigned int index =
63136+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
63137+ struct acl_role_label **curr;
63138+ struct acl_role_label *tmp, *tmp2;
63139+
63140+ curr = &acl_role_set.r_hash[index];
63141+
63142+ /* simple case, slot is empty, just set it to our role */
63143+ if (*curr == NULL) {
63144+ *curr = role;
63145+ } else {
63146+ /* example:
63147+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
63148+ 2 -> 3
63149+ */
63150+ /* first check to see if we can already be reached via this slot */
63151+ tmp = *curr;
63152+ while (tmp && tmp != role)
63153+ tmp = tmp->next;
63154+ if (tmp == role) {
63155+ /* we don't need to add ourselves to this slot's chain */
63156+ return;
63157+ }
63158+ /* we need to add ourselves to this chain, two cases */
63159+ if (role->next == NULL) {
63160+ /* simple case, append the current chain to our role */
63161+ role->next = *curr;
63162+ *curr = role;
63163+ } else {
63164+ /* 1 -> 2 -> 3 -> 4
63165+ 2 -> 3 -> 4
63166+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
63167+ */
63168+ /* trickier case: walk our role's chain until we find
63169+ the role for the start of the current slot's chain */
63170+ tmp = role;
63171+ tmp2 = *curr;
63172+ while (tmp->next && tmp->next != tmp2)
63173+ tmp = tmp->next;
63174+ if (tmp->next == tmp2) {
63175+ /* from example above, we found 3, so just
63176+ replace this slot's chain with ours */
63177+ *curr = role;
63178+ } else {
63179+ /* we didn't find a subset of our role's chain
63180+ in the current slot's chain, so append their
63181+ chain to ours, and set us as the first role in
63182+ the slot's chain
63183+
63184+ we could fold this case with the case above,
63185+ but making it explicit for clarity
63186+ */
63187+ tmp->next = tmp2;
63188+ *curr = role;
63189+ }
63190+ }
63191+ }
63192+
63193+ return;
63194+}
63195+
63196+static void
63197+insert_acl_role_label(struct acl_role_label *role)
63198+{
63199+ int i;
63200+
63201+ if (role_list == NULL) {
63202+ role_list = role;
63203+ role->prev = NULL;
63204+ } else {
63205+ role->prev = role_list;
63206+ role_list = role;
63207+ }
63208+
63209+ /* used for hash chains */
63210+ role->next = NULL;
63211+
63212+ if (role->roletype & GR_ROLE_DOMAIN) {
63213+ for (i = 0; i < role->domain_child_num; i++)
63214+ __insert_acl_role_label(role, role->domain_children[i]);
63215+ } else
63216+ __insert_acl_role_label(role, role->uidgid);
63217+}
63218+
63219+static int
63220+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63221+{
63222+ struct name_entry **curr, *nentry;
63223+ struct inodev_entry *ientry;
63224+ unsigned int len = strlen(name);
63225+ unsigned int key = full_name_hash(name, len);
63226+ unsigned int index = key % name_set.n_size;
63227+
63228+ curr = &name_set.n_hash[index];
63229+
63230+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63231+ curr = &((*curr)->next);
63232+
63233+ if (*curr != NULL)
63234+ return 1;
63235+
63236+ nentry = acl_alloc(sizeof (struct name_entry));
63237+ if (nentry == NULL)
63238+ return 0;
63239+ ientry = acl_alloc(sizeof (struct inodev_entry));
63240+ if (ientry == NULL)
63241+ return 0;
63242+ ientry->nentry = nentry;
63243+
63244+ nentry->key = key;
63245+ nentry->name = name;
63246+ nentry->inode = inode;
63247+ nentry->device = device;
63248+ nentry->len = len;
63249+ nentry->deleted = deleted;
63250+
63251+ nentry->prev = NULL;
63252+ curr = &name_set.n_hash[index];
63253+ if (*curr != NULL)
63254+ (*curr)->prev = nentry;
63255+ nentry->next = *curr;
63256+ *curr = nentry;
63257+
63258+ /* insert us into the table searchable by inode/dev */
63259+ insert_inodev_entry(ientry);
63260+
63261+ return 1;
63262+}
63263+
63264+static void
63265+insert_acl_obj_label(struct acl_object_label *obj,
63266+ struct acl_subject_label *subj)
63267+{
63268+ unsigned int index =
63269+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63270+ struct acl_object_label **curr;
63271+
63272+
63273+ obj->prev = NULL;
63274+
63275+ curr = &subj->obj_hash[index];
63276+ if (*curr != NULL)
63277+ (*curr)->prev = obj;
63278+
63279+ obj->next = *curr;
63280+ *curr = obj;
63281+
63282+ return;
63283+}
63284+
63285+static void
63286+insert_acl_subj_label(struct acl_subject_label *obj,
63287+ struct acl_role_label *role)
63288+{
63289+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63290+ struct acl_subject_label **curr;
63291+
63292+ obj->prev = NULL;
63293+
63294+ curr = &role->subj_hash[index];
63295+ if (*curr != NULL)
63296+ (*curr)->prev = obj;
63297+
63298+ obj->next = *curr;
63299+ *curr = obj;
63300+
63301+ return;
63302+}
63303+
63304+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63305+
63306+static void *
63307+create_table(__u32 * len, int elementsize)
63308+{
63309+ unsigned int table_sizes[] = {
63310+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63311+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63312+ 4194301, 8388593, 16777213, 33554393, 67108859
63313+ };
63314+ void *newtable = NULL;
63315+ unsigned int pwr = 0;
63316+
63317+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63318+ table_sizes[pwr] <= *len)
63319+ pwr++;
63320+
63321+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63322+ return newtable;
63323+
63324+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63325+ newtable =
63326+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63327+ else
63328+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63329+
63330+ *len = table_sizes[pwr];
63331+
63332+ return newtable;
63333+}
63334+
63335+static int
63336+init_variables(const struct gr_arg *arg)
63337+{
63338+ struct task_struct *reaper = init_pid_ns.child_reaper;
63339+ unsigned int stacksize;
63340+
63341+ subj_map_set.s_size = arg->role_db.num_subjects;
63342+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63343+ name_set.n_size = arg->role_db.num_objects;
63344+ inodev_set.i_size = arg->role_db.num_objects;
63345+
63346+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63347+ !name_set.n_size || !inodev_set.i_size)
63348+ return 1;
63349+
63350+ if (!gr_init_uidset())
63351+ return 1;
63352+
63353+ /* set up the stack that holds allocation info */
63354+
63355+ stacksize = arg->role_db.num_pointers + 5;
63356+
63357+ if (!acl_alloc_stack_init(stacksize))
63358+ return 1;
63359+
63360+ /* grab reference for the real root dentry and vfsmount */
63361+ get_fs_root(reaper->fs, &real_root);
63362+
63363+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63364+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63365+#endif
63366+
63367+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63368+ if (fakefs_obj_rw == NULL)
63369+ return 1;
63370+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63371+
63372+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63373+ if (fakefs_obj_rwx == NULL)
63374+ return 1;
63375+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63376+
63377+ subj_map_set.s_hash =
63378+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63379+ acl_role_set.r_hash =
63380+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63381+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63382+ inodev_set.i_hash =
63383+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63384+
63385+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63386+ !name_set.n_hash || !inodev_set.i_hash)
63387+ return 1;
63388+
63389+ memset(subj_map_set.s_hash, 0,
63390+ sizeof(struct subject_map *) * subj_map_set.s_size);
63391+ memset(acl_role_set.r_hash, 0,
63392+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63393+ memset(name_set.n_hash, 0,
63394+ sizeof (struct name_entry *) * name_set.n_size);
63395+ memset(inodev_set.i_hash, 0,
63396+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63397+
63398+ return 0;
63399+}
63400+
63401+/* free information not needed after startup
63402+ currently contains user->kernel pointer mappings for subjects
63403+*/
63404+
63405+static void
63406+free_init_variables(void)
63407+{
63408+ __u32 i;
63409+
63410+ if (subj_map_set.s_hash) {
63411+ for (i = 0; i < subj_map_set.s_size; i++) {
63412+ if (subj_map_set.s_hash[i]) {
63413+ kfree(subj_map_set.s_hash[i]);
63414+ subj_map_set.s_hash[i] = NULL;
63415+ }
63416+ }
63417+
63418+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63419+ PAGE_SIZE)
63420+ kfree(subj_map_set.s_hash);
63421+ else
63422+ vfree(subj_map_set.s_hash);
63423+ }
63424+
63425+ return;
63426+}
63427+
63428+static void
63429+free_variables(void)
63430+{
63431+ struct acl_subject_label *s;
63432+ struct acl_role_label *r;
63433+ struct task_struct *task, *task2;
63434+ unsigned int x;
63435+
63436+ gr_clear_learn_entries();
63437+
63438+ read_lock(&tasklist_lock);
63439+ do_each_thread(task2, task) {
63440+ task->acl_sp_role = 0;
63441+ task->acl_role_id = 0;
63442+ task->acl = NULL;
63443+ task->role = NULL;
63444+ } while_each_thread(task2, task);
63445+ read_unlock(&tasklist_lock);
63446+
63447+ /* release the reference to the real root dentry and vfsmount */
63448+ path_put(&real_root);
63449+ memset(&real_root, 0, sizeof(real_root));
63450+
63451+ /* free all object hash tables */
63452+
63453+ FOR_EACH_ROLE_START(r)
63454+ if (r->subj_hash == NULL)
63455+ goto next_role;
63456+ FOR_EACH_SUBJECT_START(r, s, x)
63457+ if (s->obj_hash == NULL)
63458+ break;
63459+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63460+ kfree(s->obj_hash);
63461+ else
63462+ vfree(s->obj_hash);
63463+ FOR_EACH_SUBJECT_END(s, x)
63464+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63465+ if (s->obj_hash == NULL)
63466+ break;
63467+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63468+ kfree(s->obj_hash);
63469+ else
63470+ vfree(s->obj_hash);
63471+ FOR_EACH_NESTED_SUBJECT_END(s)
63472+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63473+ kfree(r->subj_hash);
63474+ else
63475+ vfree(r->subj_hash);
63476+ r->subj_hash = NULL;
63477+next_role:
63478+ FOR_EACH_ROLE_END(r)
63479+
63480+ acl_free_all();
63481+
63482+ if (acl_role_set.r_hash) {
63483+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63484+ PAGE_SIZE)
63485+ kfree(acl_role_set.r_hash);
63486+ else
63487+ vfree(acl_role_set.r_hash);
63488+ }
63489+ if (name_set.n_hash) {
63490+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63491+ PAGE_SIZE)
63492+ kfree(name_set.n_hash);
63493+ else
63494+ vfree(name_set.n_hash);
63495+ }
63496+
63497+ if (inodev_set.i_hash) {
63498+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63499+ PAGE_SIZE)
63500+ kfree(inodev_set.i_hash);
63501+ else
63502+ vfree(inodev_set.i_hash);
63503+ }
63504+
63505+ gr_free_uidset();
63506+
63507+ memset(&name_set, 0, sizeof (struct name_db));
63508+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63509+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63510+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63511+
63512+ default_role = NULL;
63513+ kernel_role = NULL;
63514+ role_list = NULL;
63515+
63516+ return;
63517+}
63518+
63519+static struct acl_subject_label *
63520+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63521+
63522+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63523+{
63524+ unsigned int len = strnlen_user(*name, maxlen);
63525+ char *tmp;
63526+
63527+ if (!len || len >= maxlen)
63528+ return -EINVAL;
63529+
63530+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63531+ return -ENOMEM;
63532+
63533+ if (copy_from_user(tmp, *name, len))
63534+ return -EFAULT;
63535+
63536+ tmp[len-1] = '\0';
63537+ *name = tmp;
63538+
63539+ return 0;
63540+}
63541+
63542+static int
63543+copy_user_glob(struct acl_object_label *obj)
63544+{
63545+ struct acl_object_label *g_tmp, **guser;
63546+ int error;
63547+
63548+ if (obj->globbed == NULL)
63549+ return 0;
63550+
63551+ guser = &obj->globbed;
63552+ while (*guser) {
63553+ g_tmp = (struct acl_object_label *)
63554+ acl_alloc(sizeof (struct acl_object_label));
63555+ if (g_tmp == NULL)
63556+ return -ENOMEM;
63557+
63558+ if (copy_acl_object_label(g_tmp, *guser))
63559+ return -EFAULT;
63560+
63561+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63562+ if (error)
63563+ return error;
63564+
63565+ *guser = g_tmp;
63566+ guser = &(g_tmp->next);
63567+ }
63568+
63569+ return 0;
63570+}
63571+
63572+static int
63573+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63574+ struct acl_role_label *role)
63575+{
63576+ struct acl_object_label *o_tmp;
63577+ int ret;
63578+
63579+ while (userp) {
63580+ if ((o_tmp = (struct acl_object_label *)
63581+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63582+ return -ENOMEM;
63583+
63584+ if (copy_acl_object_label(o_tmp, userp))
63585+ return -EFAULT;
63586+
63587+ userp = o_tmp->prev;
63588+
63589+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63590+ if (ret)
63591+ return ret;
63592+
63593+ insert_acl_obj_label(o_tmp, subj);
63594+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63595+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63596+ return -ENOMEM;
63597+
63598+ ret = copy_user_glob(o_tmp);
63599+ if (ret)
63600+ return ret;
63601+
63602+ if (o_tmp->nested) {
63603+ int already_copied;
63604+
63605+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63606+ if (IS_ERR(o_tmp->nested))
63607+ return PTR_ERR(o_tmp->nested);
63608+
63609+ /* insert into nested subject list if we haven't copied this one yet
63610+ to prevent duplicate entries */
63611+ if (!already_copied) {
63612+ o_tmp->nested->next = role->hash->first;
63613+ role->hash->first = o_tmp->nested;
63614+ }
63615+ }
63616+ }
63617+
63618+ return 0;
63619+}
63620+
63621+static __u32
63622+count_user_subjs(struct acl_subject_label *userp)
63623+{
63624+ struct acl_subject_label s_tmp;
63625+ __u32 num = 0;
63626+
63627+ while (userp) {
63628+ if (copy_acl_subject_label(&s_tmp, userp))
63629+ break;
63630+
63631+ userp = s_tmp.prev;
63632+ }
63633+
63634+ return num;
63635+}
63636+
63637+static int
63638+copy_user_allowedips(struct acl_role_label *rolep)
63639+{
63640+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63641+
63642+ ruserip = rolep->allowed_ips;
63643+
63644+ while (ruserip) {
63645+ rlast = rtmp;
63646+
63647+ if ((rtmp = (struct role_allowed_ip *)
63648+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63649+ return -ENOMEM;
63650+
63651+ if (copy_role_allowed_ip(rtmp, ruserip))
63652+ return -EFAULT;
63653+
63654+ ruserip = rtmp->prev;
63655+
63656+ if (!rlast) {
63657+ rtmp->prev = NULL;
63658+ rolep->allowed_ips = rtmp;
63659+ } else {
63660+ rlast->next = rtmp;
63661+ rtmp->prev = rlast;
63662+ }
63663+
63664+ if (!ruserip)
63665+ rtmp->next = NULL;
63666+ }
63667+
63668+ return 0;
63669+}
63670+
63671+static int
63672+copy_user_transitions(struct acl_role_label *rolep)
63673+{
63674+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63675+ int error;
63676+
63677+ rusertp = rolep->transitions;
63678+
63679+ while (rusertp) {
63680+ rlast = rtmp;
63681+
63682+ if ((rtmp = (struct role_transition *)
63683+ acl_alloc(sizeof (struct role_transition))) == NULL)
63684+ return -ENOMEM;
63685+
63686+ if (copy_role_transition(rtmp, rusertp))
63687+ return -EFAULT;
63688+
63689+ rusertp = rtmp->prev;
63690+
63691+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63692+ if (error)
63693+ return error;
63694+
63695+ if (!rlast) {
63696+ rtmp->prev = NULL;
63697+ rolep->transitions = rtmp;
63698+ } else {
63699+ rlast->next = rtmp;
63700+ rtmp->prev = rlast;
63701+ }
63702+
63703+ if (!rusertp)
63704+ rtmp->next = NULL;
63705+ }
63706+
63707+ return 0;
63708+}
63709+
63710+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63711+{
63712+ struct acl_object_label o_tmp;
63713+ __u32 num = 0;
63714+
63715+ while (userp) {
63716+ if (copy_acl_object_label(&o_tmp, userp))
63717+ break;
63718+
63719+ userp = o_tmp.prev;
63720+ num++;
63721+ }
63722+
63723+ return num;
63724+}
63725+
63726+static struct acl_subject_label *
63727+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63728+{
63729+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63730+ __u32 num_objs;
63731+ struct acl_ip_label **i_tmp, *i_utmp2;
63732+ struct gr_hash_struct ghash;
63733+ struct subject_map *subjmap;
63734+ unsigned int i_num;
63735+ int err;
63736+
63737+ if (already_copied != NULL)
63738+ *already_copied = 0;
63739+
63740+ s_tmp = lookup_subject_map(userp);
63741+
63742+ /* we've already copied this subject into the kernel, just return
63743+ the reference to it, and don't copy it over again
63744+ */
63745+ if (s_tmp) {
63746+ if (already_copied != NULL)
63747+ *already_copied = 1;
63748+ return(s_tmp);
63749+ }
63750+
63751+ if ((s_tmp = (struct acl_subject_label *)
63752+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63753+ return ERR_PTR(-ENOMEM);
63754+
63755+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63756+ if (subjmap == NULL)
63757+ return ERR_PTR(-ENOMEM);
63758+
63759+ subjmap->user = userp;
63760+ subjmap->kernel = s_tmp;
63761+ insert_subj_map_entry(subjmap);
63762+
63763+ if (copy_acl_subject_label(s_tmp, userp))
63764+ return ERR_PTR(-EFAULT);
63765+
63766+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63767+ if (err)
63768+ return ERR_PTR(err);
63769+
63770+ if (!strcmp(s_tmp->filename, "/"))
63771+ role->root_label = s_tmp;
63772+
63773+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63774+ return ERR_PTR(-EFAULT);
63775+
63776+ /* copy user and group transition tables */
63777+
63778+ if (s_tmp->user_trans_num) {
63779+ uid_t *uidlist;
63780+
63781+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63782+ if (uidlist == NULL)
63783+ return ERR_PTR(-ENOMEM);
63784+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63785+ return ERR_PTR(-EFAULT);
63786+
63787+ s_tmp->user_transitions = uidlist;
63788+ }
63789+
63790+ if (s_tmp->group_trans_num) {
63791+ gid_t *gidlist;
63792+
63793+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63794+ if (gidlist == NULL)
63795+ return ERR_PTR(-ENOMEM);
63796+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63797+ return ERR_PTR(-EFAULT);
63798+
63799+ s_tmp->group_transitions = gidlist;
63800+ }
63801+
63802+ /* set up object hash table */
63803+ num_objs = count_user_objs(ghash.first);
63804+
63805+ s_tmp->obj_hash_size = num_objs;
63806+ s_tmp->obj_hash =
63807+ (struct acl_object_label **)
63808+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63809+
63810+ if (!s_tmp->obj_hash)
63811+ return ERR_PTR(-ENOMEM);
63812+
63813+ memset(s_tmp->obj_hash, 0,
63814+ s_tmp->obj_hash_size *
63815+ sizeof (struct acl_object_label *));
63816+
63817+ /* add in objects */
63818+ err = copy_user_objs(ghash.first, s_tmp, role);
63819+
63820+ if (err)
63821+ return ERR_PTR(err);
63822+
63823+ /* set pointer for parent subject */
63824+ if (s_tmp->parent_subject) {
63825+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63826+
63827+ if (IS_ERR(s_tmp2))
63828+ return s_tmp2;
63829+
63830+ s_tmp->parent_subject = s_tmp2;
63831+ }
63832+
63833+ /* add in ip acls */
63834+
63835+ if (!s_tmp->ip_num) {
63836+ s_tmp->ips = NULL;
63837+ goto insert;
63838+ }
63839+
63840+ i_tmp =
63841+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63842+ sizeof (struct acl_ip_label *));
63843+
63844+ if (!i_tmp)
63845+ return ERR_PTR(-ENOMEM);
63846+
63847+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63848+ *(i_tmp + i_num) =
63849+ (struct acl_ip_label *)
63850+ acl_alloc(sizeof (struct acl_ip_label));
63851+ if (!*(i_tmp + i_num))
63852+ return ERR_PTR(-ENOMEM);
63853+
63854+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63855+ return ERR_PTR(-EFAULT);
63856+
63857+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63858+ return ERR_PTR(-EFAULT);
63859+
63860+ if ((*(i_tmp + i_num))->iface == NULL)
63861+ continue;
63862+
63863+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63864+ if (err)
63865+ return ERR_PTR(err);
63866+ }
63867+
63868+ s_tmp->ips = i_tmp;
63869+
63870+insert:
63871+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63872+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63873+ return ERR_PTR(-ENOMEM);
63874+
63875+ return s_tmp;
63876+}
63877+
63878+static int
63879+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63880+{
63881+ struct acl_subject_label s_pre;
63882+ struct acl_subject_label * ret;
63883+ int err;
63884+
63885+ while (userp) {
63886+ if (copy_acl_subject_label(&s_pre, userp))
63887+ return -EFAULT;
63888+
63889+ ret = do_copy_user_subj(userp, role, NULL);
63890+
63891+ err = PTR_ERR(ret);
63892+ if (IS_ERR(ret))
63893+ return err;
63894+
63895+ insert_acl_subj_label(ret, role);
63896+
63897+ userp = s_pre.prev;
63898+ }
63899+
63900+ return 0;
63901+}
63902+
63903+static int
63904+copy_user_acl(struct gr_arg *arg)
63905+{
63906+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63907+ struct acl_subject_label *subj_list;
63908+ struct sprole_pw *sptmp;
63909+ struct gr_hash_struct *ghash;
63910+ uid_t *domainlist;
63911+ unsigned int r_num;
63912+ int err = 0;
63913+ __u16 i;
63914+ __u32 num_subjs;
63915+
63916+ /* we need a default and kernel role */
63917+ if (arg->role_db.num_roles < 2)
63918+ return -EINVAL;
63919+
63920+ /* copy special role authentication info from userspace */
63921+
63922+ num_sprole_pws = arg->num_sprole_pws;
63923+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63924+
63925+ if (!acl_special_roles && num_sprole_pws)
63926+ return -ENOMEM;
63927+
63928+ for (i = 0; i < num_sprole_pws; i++) {
63929+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63930+ if (!sptmp)
63931+ return -ENOMEM;
63932+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63933+ return -EFAULT;
63934+
63935+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63936+ if (err)
63937+ return err;
63938+
63939+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63940+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63941+#endif
63942+
63943+ acl_special_roles[i] = sptmp;
63944+ }
63945+
63946+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63947+
63948+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63949+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63950+
63951+ if (!r_tmp)
63952+ return -ENOMEM;
63953+
63954+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63955+ return -EFAULT;
63956+
63957+ if (copy_acl_role_label(r_tmp, r_utmp2))
63958+ return -EFAULT;
63959+
63960+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63961+ if (err)
63962+ return err;
63963+
63964+ if (!strcmp(r_tmp->rolename, "default")
63965+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63966+ default_role = r_tmp;
63967+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63968+ kernel_role = r_tmp;
63969+ }
63970+
63971+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63972+ return -ENOMEM;
63973+
63974+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63975+ return -EFAULT;
63976+
63977+ r_tmp->hash = ghash;
63978+
63979+ num_subjs = count_user_subjs(r_tmp->hash->first);
63980+
63981+ r_tmp->subj_hash_size = num_subjs;
63982+ r_tmp->subj_hash =
63983+ (struct acl_subject_label **)
63984+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63985+
63986+ if (!r_tmp->subj_hash)
63987+ return -ENOMEM;
63988+
63989+ err = copy_user_allowedips(r_tmp);
63990+ if (err)
63991+ return err;
63992+
63993+ /* copy domain info */
63994+ if (r_tmp->domain_children != NULL) {
63995+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63996+ if (domainlist == NULL)
63997+ return -ENOMEM;
63998+
63999+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
64000+ return -EFAULT;
64001+
64002+ r_tmp->domain_children = domainlist;
64003+ }
64004+
64005+ err = copy_user_transitions(r_tmp);
64006+ if (err)
64007+ return err;
64008+
64009+ memset(r_tmp->subj_hash, 0,
64010+ r_tmp->subj_hash_size *
64011+ sizeof (struct acl_subject_label *));
64012+
64013+ /* acquire the list of subjects, then NULL out
64014+ the list prior to parsing the subjects for this role,
64015+ as during this parsing the list is replaced with a list
64016+ of *nested* subjects for the role
64017+ */
64018+ subj_list = r_tmp->hash->first;
64019+
64020+ /* set nested subject list to null */
64021+ r_tmp->hash->first = NULL;
64022+
64023+ err = copy_user_subjs(subj_list, r_tmp);
64024+
64025+ if (err)
64026+ return err;
64027+
64028+ insert_acl_role_label(r_tmp);
64029+ }
64030+
64031+ if (default_role == NULL || kernel_role == NULL)
64032+ return -EINVAL;
64033+
64034+ return err;
64035+}
64036+
64037+static int
64038+gracl_init(struct gr_arg *args)
64039+{
64040+ int error = 0;
64041+
64042+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
64043+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
64044+
64045+ if (init_variables(args)) {
64046+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
64047+ error = -ENOMEM;
64048+ free_variables();
64049+ goto out;
64050+ }
64051+
64052+ error = copy_user_acl(args);
64053+ free_init_variables();
64054+ if (error) {
64055+ free_variables();
64056+ goto out;
64057+ }
64058+
64059+ if ((error = gr_set_acls(0))) {
64060+ free_variables();
64061+ goto out;
64062+ }
64063+
64064+ pax_open_kernel();
64065+ gr_status |= GR_READY;
64066+ pax_close_kernel();
64067+
64068+ out:
64069+ return error;
64070+}
64071+
64072+/* derived from glibc fnmatch() 0: match, 1: no match*/
64073+
64074+static int
64075+glob_match(const char *p, const char *n)
64076+{
64077+ char c;
64078+
64079+ while ((c = *p++) != '\0') {
64080+ switch (c) {
64081+ case '?':
64082+ if (*n == '\0')
64083+ return 1;
64084+ else if (*n == '/')
64085+ return 1;
64086+ break;
64087+ case '\\':
64088+ if (*n != c)
64089+ return 1;
64090+ break;
64091+ case '*':
64092+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
64093+ if (*n == '/')
64094+ return 1;
64095+ else if (c == '?') {
64096+ if (*n == '\0')
64097+ return 1;
64098+ else
64099+ ++n;
64100+ }
64101+ }
64102+ if (c == '\0') {
64103+ return 0;
64104+ } else {
64105+ const char *endp;
64106+
64107+ if ((endp = strchr(n, '/')) == NULL)
64108+ endp = n + strlen(n);
64109+
64110+ if (c == '[') {
64111+ for (--p; n < endp; ++n)
64112+ if (!glob_match(p, n))
64113+ return 0;
64114+ } else if (c == '/') {
64115+ while (*n != '\0' && *n != '/')
64116+ ++n;
64117+ if (*n == '/' && !glob_match(p, n + 1))
64118+ return 0;
64119+ } else {
64120+ for (--p; n < endp; ++n)
64121+ if (*n == c && !glob_match(p, n))
64122+ return 0;
64123+ }
64124+
64125+ return 1;
64126+ }
64127+ case '[':
64128+ {
64129+ int not;
64130+ char cold;
64131+
64132+ if (*n == '\0' || *n == '/')
64133+ return 1;
64134+
64135+ not = (*p == '!' || *p == '^');
64136+ if (not)
64137+ ++p;
64138+
64139+ c = *p++;
64140+ for (;;) {
64141+ unsigned char fn = (unsigned char)*n;
64142+
64143+ if (c == '\0')
64144+ return 1;
64145+ else {
64146+ if (c == fn)
64147+ goto matched;
64148+ cold = c;
64149+ c = *p++;
64150+
64151+ if (c == '-' && *p != ']') {
64152+ unsigned char cend = *p++;
64153+
64154+ if (cend == '\0')
64155+ return 1;
64156+
64157+ if (cold <= fn && fn <= cend)
64158+ goto matched;
64159+
64160+ c = *p++;
64161+ }
64162+ }
64163+
64164+ if (c == ']')
64165+ break;
64166+ }
64167+ if (!not)
64168+ return 1;
64169+ break;
64170+ matched:
64171+ while (c != ']') {
64172+ if (c == '\0')
64173+ return 1;
64174+
64175+ c = *p++;
64176+ }
64177+ if (not)
64178+ return 1;
64179+ }
64180+ break;
64181+ default:
64182+ if (c != *n)
64183+ return 1;
64184+ }
64185+
64186+ ++n;
64187+ }
64188+
64189+ if (*n == '\0')
64190+ return 0;
64191+
64192+ if (*n == '/')
64193+ return 0;
64194+
64195+ return 1;
64196+}
64197+
64198+static struct acl_object_label *
64199+chk_glob_label(struct acl_object_label *globbed,
64200+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64201+{
64202+ struct acl_object_label *tmp;
64203+
64204+ if (*path == NULL)
64205+ *path = gr_to_filename_nolock(dentry, mnt);
64206+
64207+ tmp = globbed;
64208+
64209+ while (tmp) {
64210+ if (!glob_match(tmp->filename, *path))
64211+ return tmp;
64212+ tmp = tmp->next;
64213+ }
64214+
64215+ return NULL;
64216+}
64217+
64218+static struct acl_object_label *
64219+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64220+ const ino_t curr_ino, const dev_t curr_dev,
64221+ const struct acl_subject_label *subj, char **path, const int checkglob)
64222+{
64223+ struct acl_subject_label *tmpsubj;
64224+ struct acl_object_label *retval;
64225+ struct acl_object_label *retval2;
64226+
64227+ tmpsubj = (struct acl_subject_label *) subj;
64228+ read_lock(&gr_inode_lock);
64229+ do {
64230+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64231+ if (retval) {
64232+ if (checkglob && retval->globbed) {
64233+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64234+ if (retval2)
64235+ retval = retval2;
64236+ }
64237+ break;
64238+ }
64239+ } while ((tmpsubj = tmpsubj->parent_subject));
64240+ read_unlock(&gr_inode_lock);
64241+
64242+ return retval;
64243+}
64244+
64245+static __inline__ struct acl_object_label *
64246+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64247+ struct dentry *curr_dentry,
64248+ const struct acl_subject_label *subj, char **path, const int checkglob)
64249+{
64250+ int newglob = checkglob;
64251+ ino_t inode;
64252+ dev_t device;
64253+
64254+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64255+ as we don't want a / * rule to match instead of the / object
64256+ don't do this for create lookups that call this function though, since they're looking up
64257+ on the parent and thus need globbing checks on all paths
64258+ */
64259+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64260+ newglob = GR_NO_GLOB;
64261+
64262+ spin_lock(&curr_dentry->d_lock);
64263+ inode = curr_dentry->d_inode->i_ino;
64264+ device = __get_dev(curr_dentry);
64265+ spin_unlock(&curr_dentry->d_lock);
64266+
64267+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64268+}
64269+
64270+#ifdef CONFIG_HUGETLBFS
64271+static inline bool
64272+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64273+{
64274+ int i;
64275+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64276+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64277+ return true;
64278+ }
64279+
64280+ return false;
64281+}
64282+#endif
64283+
64284+static struct acl_object_label *
64285+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64286+ const struct acl_subject_label *subj, char *path, const int checkglob)
64287+{
64288+ struct dentry *dentry = (struct dentry *) l_dentry;
64289+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64290+ struct mount *real_mnt = real_mount(mnt);
64291+ struct acl_object_label *retval;
64292+ struct dentry *parent;
64293+
64294+ br_read_lock(&vfsmount_lock);
64295+ write_seqlock(&rename_lock);
64296+
64297+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64298+#ifdef CONFIG_NET
64299+ mnt == sock_mnt ||
64300+#endif
64301+#ifdef CONFIG_HUGETLBFS
64302+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64303+#endif
64304+ /* ignore Eric Biederman */
64305+ IS_PRIVATE(l_dentry->d_inode))) {
64306+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64307+ goto out;
64308+ }
64309+
64310+ for (;;) {
64311+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64312+ break;
64313+
64314+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64315+ if (!mnt_has_parent(real_mnt))
64316+ break;
64317+
64318+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64319+ if (retval != NULL)
64320+ goto out;
64321+
64322+ dentry = real_mnt->mnt_mountpoint;
64323+ real_mnt = real_mnt->mnt_parent;
64324+ mnt = &real_mnt->mnt;
64325+ continue;
64326+ }
64327+
64328+ parent = dentry->d_parent;
64329+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64330+ if (retval != NULL)
64331+ goto out;
64332+
64333+ dentry = parent;
64334+ }
64335+
64336+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64337+
64338+ /* real_root is pinned so we don't have to hold a reference */
64339+ if (retval == NULL)
64340+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64341+out:
64342+ write_sequnlock(&rename_lock);
64343+ br_read_unlock(&vfsmount_lock);
64344+
64345+ BUG_ON(retval == NULL);
64346+
64347+ return retval;
64348+}
64349+
64350+static __inline__ struct acl_object_label *
64351+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64352+ const struct acl_subject_label *subj)
64353+{
64354+ char *path = NULL;
64355+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64356+}
64357+
64358+static __inline__ struct acl_object_label *
64359+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64360+ const struct acl_subject_label *subj)
64361+{
64362+ char *path = NULL;
64363+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64364+}
64365+
64366+static __inline__ struct acl_object_label *
64367+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64368+ const struct acl_subject_label *subj, char *path)
64369+{
64370+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64371+}
64372+
64373+static struct acl_subject_label *
64374+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64375+ const struct acl_role_label *role)
64376+{
64377+ struct dentry *dentry = (struct dentry *) l_dentry;
64378+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64379+ struct mount *real_mnt = real_mount(mnt);
64380+ struct acl_subject_label *retval;
64381+ struct dentry *parent;
64382+
64383+ br_read_lock(&vfsmount_lock);
64384+ write_seqlock(&rename_lock);
64385+
64386+ for (;;) {
64387+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64388+ break;
64389+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64390+ if (!mnt_has_parent(real_mnt))
64391+ break;
64392+
64393+ spin_lock(&dentry->d_lock);
64394+ read_lock(&gr_inode_lock);
64395+ retval =
64396+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64397+ __get_dev(dentry), role);
64398+ read_unlock(&gr_inode_lock);
64399+ spin_unlock(&dentry->d_lock);
64400+ if (retval != NULL)
64401+ goto out;
64402+
64403+ dentry = real_mnt->mnt_mountpoint;
64404+ real_mnt = real_mnt->mnt_parent;
64405+ mnt = &real_mnt->mnt;
64406+ continue;
64407+ }
64408+
64409+ spin_lock(&dentry->d_lock);
64410+ read_lock(&gr_inode_lock);
64411+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64412+ __get_dev(dentry), role);
64413+ read_unlock(&gr_inode_lock);
64414+ parent = dentry->d_parent;
64415+ spin_unlock(&dentry->d_lock);
64416+
64417+ if (retval != NULL)
64418+ goto out;
64419+
64420+ dentry = parent;
64421+ }
64422+
64423+ spin_lock(&dentry->d_lock);
64424+ read_lock(&gr_inode_lock);
64425+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64426+ __get_dev(dentry), role);
64427+ read_unlock(&gr_inode_lock);
64428+ spin_unlock(&dentry->d_lock);
64429+
64430+ if (unlikely(retval == NULL)) {
64431+ /* real_root is pinned, we don't need to hold a reference */
64432+ read_lock(&gr_inode_lock);
64433+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64434+ __get_dev(real_root.dentry), role);
64435+ read_unlock(&gr_inode_lock);
64436+ }
64437+out:
64438+ write_sequnlock(&rename_lock);
64439+ br_read_unlock(&vfsmount_lock);
64440+
64441+ BUG_ON(retval == NULL);
64442+
64443+ return retval;
64444+}
64445+
64446+static void
64447+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64448+{
64449+ struct task_struct *task = current;
64450+ const struct cred *cred = current_cred();
64451+
64452+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64453+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64454+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64455+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64456+
64457+ return;
64458+}
64459+
64460+static void
64461+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64462+{
64463+ struct task_struct *task = current;
64464+ const struct cred *cred = current_cred();
64465+
64466+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64467+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64468+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64469+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64470+
64471+ return;
64472+}
64473+
64474+static void
64475+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64476+{
64477+ struct task_struct *task = current;
64478+ const struct cred *cred = current_cred();
64479+
64480+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64481+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64482+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64483+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64484+
64485+ return;
64486+}
64487+
64488+__u32
64489+gr_search_file(const struct dentry * dentry, const __u32 mode,
64490+ const struct vfsmount * mnt)
64491+{
64492+ __u32 retval = mode;
64493+ struct acl_subject_label *curracl;
64494+ struct acl_object_label *currobj;
64495+
64496+ if (unlikely(!(gr_status & GR_READY)))
64497+ return (mode & ~GR_AUDITS);
64498+
64499+ curracl = current->acl;
64500+
64501+ currobj = chk_obj_label(dentry, mnt, curracl);
64502+ retval = currobj->mode & mode;
64503+
64504+ /* if we're opening a specified transfer file for writing
64505+ (e.g. /dev/initctl), then transfer our role to init
64506+ */
64507+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64508+ current->role->roletype & GR_ROLE_PERSIST)) {
64509+ struct task_struct *task = init_pid_ns.child_reaper;
64510+
64511+ if (task->role != current->role) {
64512+ task->acl_sp_role = 0;
64513+ task->acl_role_id = current->acl_role_id;
64514+ task->role = current->role;
64515+ rcu_read_lock();
64516+ read_lock(&grsec_exec_file_lock);
64517+ gr_apply_subject_to_task(task);
64518+ read_unlock(&grsec_exec_file_lock);
64519+ rcu_read_unlock();
64520+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64521+ }
64522+ }
64523+
64524+ if (unlikely
64525+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64526+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64527+ __u32 new_mode = mode;
64528+
64529+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64530+
64531+ retval = new_mode;
64532+
64533+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64534+ new_mode |= GR_INHERIT;
64535+
64536+ if (!(mode & GR_NOLEARN))
64537+ gr_log_learn(dentry, mnt, new_mode);
64538+ }
64539+
64540+ return retval;
64541+}
64542+
64543+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64544+ const struct dentry *parent,
64545+ const struct vfsmount *mnt)
64546+{
64547+ struct name_entry *match;
64548+ struct acl_object_label *matchpo;
64549+ struct acl_subject_label *curracl;
64550+ char *path;
64551+
64552+ if (unlikely(!(gr_status & GR_READY)))
64553+ return NULL;
64554+
64555+ preempt_disable();
64556+ path = gr_to_filename_rbac(new_dentry, mnt);
64557+ match = lookup_name_entry_create(path);
64558+
64559+ curracl = current->acl;
64560+
64561+ if (match) {
64562+ read_lock(&gr_inode_lock);
64563+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64564+ read_unlock(&gr_inode_lock);
64565+
64566+ if (matchpo) {
64567+ preempt_enable();
64568+ return matchpo;
64569+ }
64570+ }
64571+
64572+ // lookup parent
64573+
64574+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64575+
64576+ preempt_enable();
64577+ return matchpo;
64578+}
64579+
64580+__u32
64581+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64582+ const struct vfsmount * mnt, const __u32 mode)
64583+{
64584+ struct acl_object_label *matchpo;
64585+ __u32 retval;
64586+
64587+ if (unlikely(!(gr_status & GR_READY)))
64588+ return (mode & ~GR_AUDITS);
64589+
64590+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64591+
64592+ retval = matchpo->mode & mode;
64593+
64594+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64595+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64596+ __u32 new_mode = mode;
64597+
64598+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64599+
64600+ gr_log_learn(new_dentry, mnt, new_mode);
64601+ return new_mode;
64602+ }
64603+
64604+ return retval;
64605+}
64606+
64607+__u32
64608+gr_check_link(const struct dentry * new_dentry,
64609+ const struct dentry * parent_dentry,
64610+ const struct vfsmount * parent_mnt,
64611+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64612+{
64613+ struct acl_object_label *obj;
64614+ __u32 oldmode, newmode;
64615+ __u32 needmode;
64616+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64617+ GR_DELETE | GR_INHERIT;
64618+
64619+ if (unlikely(!(gr_status & GR_READY)))
64620+ return (GR_CREATE | GR_LINK);
64621+
64622+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64623+ oldmode = obj->mode;
64624+
64625+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64626+ newmode = obj->mode;
64627+
64628+ needmode = newmode & checkmodes;
64629+
64630+ // old name for hardlink must have at least the permissions of the new name
64631+ if ((oldmode & needmode) != needmode)
64632+ goto bad;
64633+
64634+ // if old name had restrictions/auditing, make sure the new name does as well
64635+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64636+
64637+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64638+ if (is_privileged_binary(old_dentry))
64639+ needmode |= GR_SETID;
64640+
64641+ if ((newmode & needmode) != needmode)
64642+ goto bad;
64643+
64644+ // enforce minimum permissions
64645+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64646+ return newmode;
64647+bad:
64648+ needmode = oldmode;
64649+ if (is_privileged_binary(old_dentry))
64650+ needmode |= GR_SETID;
64651+
64652+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64653+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64654+ return (GR_CREATE | GR_LINK);
64655+ } else if (newmode & GR_SUPPRESS)
64656+ return GR_SUPPRESS;
64657+ else
64658+ return 0;
64659+}
64660+
64661+int
64662+gr_check_hidden_task(const struct task_struct *task)
64663+{
64664+ if (unlikely(!(gr_status & GR_READY)))
64665+ return 0;
64666+
64667+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64668+ return 1;
64669+
64670+ return 0;
64671+}
64672+
64673+int
64674+gr_check_protected_task(const struct task_struct *task)
64675+{
64676+ if (unlikely(!(gr_status & GR_READY) || !task))
64677+ return 0;
64678+
64679+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64680+ task->acl != current->acl)
64681+ return 1;
64682+
64683+ return 0;
64684+}
64685+
64686+int
64687+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64688+{
64689+ struct task_struct *p;
64690+ int ret = 0;
64691+
64692+ if (unlikely(!(gr_status & GR_READY) || !pid))
64693+ return ret;
64694+
64695+ read_lock(&tasklist_lock);
64696+ do_each_pid_task(pid, type, p) {
64697+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64698+ p->acl != current->acl) {
64699+ ret = 1;
64700+ goto out;
64701+ }
64702+ } while_each_pid_task(pid, type, p);
64703+out:
64704+ read_unlock(&tasklist_lock);
64705+
64706+ return ret;
64707+}
64708+
64709+void
64710+gr_copy_label(struct task_struct *tsk)
64711+{
64712+ tsk->signal->used_accept = 0;
64713+ tsk->acl_sp_role = 0;
64714+ tsk->acl_role_id = current->acl_role_id;
64715+ tsk->acl = current->acl;
64716+ tsk->role = current->role;
64717+ tsk->signal->curr_ip = current->signal->curr_ip;
64718+ tsk->signal->saved_ip = current->signal->saved_ip;
64719+ if (current->exec_file)
64720+ get_file(current->exec_file);
64721+ tsk->exec_file = current->exec_file;
64722+ tsk->is_writable = current->is_writable;
64723+ if (unlikely(current->signal->used_accept)) {
64724+ current->signal->curr_ip = 0;
64725+ current->signal->saved_ip = 0;
64726+ }
64727+
64728+ return;
64729+}
64730+
64731+static void
64732+gr_set_proc_res(struct task_struct *task)
64733+{
64734+ struct acl_subject_label *proc;
64735+ unsigned short i;
64736+
64737+ proc = task->acl;
64738+
64739+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64740+ return;
64741+
64742+ for (i = 0; i < RLIM_NLIMITS; i++) {
64743+ if (!(proc->resmask & (1U << i)))
64744+ continue;
64745+
64746+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64747+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64748+
64749+ if (i == RLIMIT_CPU)
64750+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64751+ }
64752+
64753+ return;
64754+}
64755+
64756+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64757+
64758+int
64759+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64760+{
64761+ unsigned int i;
64762+ __u16 num;
64763+ uid_t *uidlist;
64764+ uid_t curuid;
64765+ int realok = 0;
64766+ int effectiveok = 0;
64767+ int fsok = 0;
64768+ uid_t globalreal, globaleffective, globalfs;
64769+
64770+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64771+ struct user_struct *user;
64772+
64773+ if (!uid_valid(real))
64774+ goto skipit;
64775+
64776+ /* find user based on global namespace */
64777+
64778+ globalreal = GR_GLOBAL_UID(real);
64779+
64780+ user = find_user(make_kuid(&init_user_ns, globalreal));
64781+ if (user == NULL)
64782+ goto skipit;
64783+
64784+ if (gr_process_kernel_setuid_ban(user)) {
64785+ /* for find_user */
64786+ free_uid(user);
64787+ return 1;
64788+ }
64789+
64790+ /* for find_user */
64791+ free_uid(user);
64792+
64793+skipit:
64794+#endif
64795+
64796+ if (unlikely(!(gr_status & GR_READY)))
64797+ return 0;
64798+
64799+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64800+ gr_log_learn_uid_change(real, effective, fs);
64801+
64802+ num = current->acl->user_trans_num;
64803+ uidlist = current->acl->user_transitions;
64804+
64805+ if (uidlist == NULL)
64806+ return 0;
64807+
64808+ if (!uid_valid(real)) {
64809+ realok = 1;
64810+ globalreal = (uid_t)-1;
64811+ } else {
64812+ globalreal = GR_GLOBAL_UID(real);
64813+ }
64814+ if (!uid_valid(effective)) {
64815+ effectiveok = 1;
64816+ globaleffective = (uid_t)-1;
64817+ } else {
64818+ globaleffective = GR_GLOBAL_UID(effective);
64819+ }
64820+ if (!uid_valid(fs)) {
64821+ fsok = 1;
64822+ globalfs = (uid_t)-1;
64823+ } else {
64824+ globalfs = GR_GLOBAL_UID(fs);
64825+ }
64826+
64827+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64828+ for (i = 0; i < num; i++) {
64829+ curuid = uidlist[i];
64830+ if (globalreal == curuid)
64831+ realok = 1;
64832+ if (globaleffective == curuid)
64833+ effectiveok = 1;
64834+ if (globalfs == curuid)
64835+ fsok = 1;
64836+ }
64837+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64838+ for (i = 0; i < num; i++) {
64839+ curuid = uidlist[i];
64840+ if (globalreal == curuid)
64841+ break;
64842+ if (globaleffective == curuid)
64843+ break;
64844+ if (globalfs == curuid)
64845+ break;
64846+ }
64847+ /* not in deny list */
64848+ if (i == num) {
64849+ realok = 1;
64850+ effectiveok = 1;
64851+ fsok = 1;
64852+ }
64853+ }
64854+
64855+ if (realok && effectiveok && fsok)
64856+ return 0;
64857+ else {
64858+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64859+ return 1;
64860+ }
64861+}
64862+
64863+int
64864+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64865+{
64866+ unsigned int i;
64867+ __u16 num;
64868+ gid_t *gidlist;
64869+ gid_t curgid;
64870+ int realok = 0;
64871+ int effectiveok = 0;
64872+ int fsok = 0;
64873+ gid_t globalreal, globaleffective, globalfs;
64874+
64875+ if (unlikely(!(gr_status & GR_READY)))
64876+ return 0;
64877+
64878+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64879+ gr_log_learn_gid_change(real, effective, fs);
64880+
64881+ num = current->acl->group_trans_num;
64882+ gidlist = current->acl->group_transitions;
64883+
64884+ if (gidlist == NULL)
64885+ return 0;
64886+
64887+ if (!gid_valid(real)) {
64888+ realok = 1;
64889+ globalreal = (gid_t)-1;
64890+ } else {
64891+ globalreal = GR_GLOBAL_GID(real);
64892+ }
64893+ if (!gid_valid(effective)) {
64894+ effectiveok = 1;
64895+ globaleffective = (gid_t)-1;
64896+ } else {
64897+ globaleffective = GR_GLOBAL_GID(effective);
64898+ }
64899+ if (!gid_valid(fs)) {
64900+ fsok = 1;
64901+ globalfs = (gid_t)-1;
64902+ } else {
64903+ globalfs = GR_GLOBAL_GID(fs);
64904+ }
64905+
64906+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64907+ for (i = 0; i < num; i++) {
64908+ curgid = gidlist[i];
64909+ if (globalreal == curgid)
64910+ realok = 1;
64911+ if (globaleffective == curgid)
64912+ effectiveok = 1;
64913+ if (globalfs == curgid)
64914+ fsok = 1;
64915+ }
64916+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64917+ for (i = 0; i < num; i++) {
64918+ curgid = gidlist[i];
64919+ if (globalreal == curgid)
64920+ break;
64921+ if (globaleffective == curgid)
64922+ break;
64923+ if (globalfs == curgid)
64924+ break;
64925+ }
64926+ /* not in deny list */
64927+ if (i == num) {
64928+ realok = 1;
64929+ effectiveok = 1;
64930+ fsok = 1;
64931+ }
64932+ }
64933+
64934+ if (realok && effectiveok && fsok)
64935+ return 0;
64936+ else {
64937+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64938+ return 1;
64939+ }
64940+}
64941+
64942+extern int gr_acl_is_capable(const int cap);
64943+
64944+void
64945+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64946+{
64947+ struct acl_role_label *role = task->role;
64948+ struct acl_subject_label *subj = NULL;
64949+ struct acl_object_label *obj;
64950+ struct file *filp;
64951+ uid_t uid;
64952+ gid_t gid;
64953+
64954+ if (unlikely(!(gr_status & GR_READY)))
64955+ return;
64956+
64957+ uid = GR_GLOBAL_UID(kuid);
64958+ gid = GR_GLOBAL_GID(kgid);
64959+
64960+ filp = task->exec_file;
64961+
64962+ /* kernel process, we'll give them the kernel role */
64963+ if (unlikely(!filp)) {
64964+ task->role = kernel_role;
64965+ task->acl = kernel_role->root_label;
64966+ return;
64967+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64968+ role = lookup_acl_role_label(task, uid, gid);
64969+
64970+ /* don't change the role if we're not a privileged process */
64971+ if (role && task->role != role &&
64972+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64973+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64974+ return;
64975+
64976+ /* perform subject lookup in possibly new role
64977+ we can use this result below in the case where role == task->role
64978+ */
64979+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64980+
64981+ /* if we changed uid/gid, but result in the same role
64982+ and are using inheritance, don't lose the inherited subject
64983+ if current subject is other than what normal lookup
64984+ would result in, we arrived via inheritance, don't
64985+ lose subject
64986+ */
64987+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64988+ (subj == task->acl)))
64989+ task->acl = subj;
64990+
64991+ task->role = role;
64992+
64993+ task->is_writable = 0;
64994+
64995+ /* ignore additional mmap checks for processes that are writable
64996+ by the default ACL */
64997+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64998+ if (unlikely(obj->mode & GR_WRITE))
64999+ task->is_writable = 1;
65000+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65001+ if (unlikely(obj->mode & GR_WRITE))
65002+ task->is_writable = 1;
65003+
65004+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65005+ 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);
65006+#endif
65007+
65008+ gr_set_proc_res(task);
65009+
65010+ return;
65011+}
65012+
65013+int
65014+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
65015+ const int unsafe_flags)
65016+{
65017+ struct task_struct *task = current;
65018+ struct acl_subject_label *newacl;
65019+ struct acl_object_label *obj;
65020+ __u32 retmode;
65021+
65022+ if (unlikely(!(gr_status & GR_READY)))
65023+ return 0;
65024+
65025+ newacl = chk_subj_label(dentry, mnt, task->role);
65026+
65027+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
65028+ did an exec
65029+ */
65030+ rcu_read_lock();
65031+ read_lock(&tasklist_lock);
65032+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
65033+ (task->parent->acl->mode & GR_POVERRIDE))) {
65034+ read_unlock(&tasklist_lock);
65035+ rcu_read_unlock();
65036+ goto skip_check;
65037+ }
65038+ read_unlock(&tasklist_lock);
65039+ rcu_read_unlock();
65040+
65041+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
65042+ !(task->role->roletype & GR_ROLE_GOD) &&
65043+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
65044+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65045+ if (unsafe_flags & LSM_UNSAFE_SHARE)
65046+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
65047+ else
65048+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
65049+ return -EACCES;
65050+ }
65051+
65052+skip_check:
65053+
65054+ obj = chk_obj_label(dentry, mnt, task->acl);
65055+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
65056+
65057+ if (!(task->acl->mode & GR_INHERITLEARN) &&
65058+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
65059+ if (obj->nested)
65060+ task->acl = obj->nested;
65061+ else
65062+ task->acl = newacl;
65063+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
65064+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
65065+
65066+ task->is_writable = 0;
65067+
65068+ /* ignore additional mmap checks for processes that are writable
65069+ by the default ACL */
65070+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
65071+ if (unlikely(obj->mode & GR_WRITE))
65072+ task->is_writable = 1;
65073+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
65074+ if (unlikely(obj->mode & GR_WRITE))
65075+ task->is_writable = 1;
65076+
65077+ gr_set_proc_res(task);
65078+
65079+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65080+ 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);
65081+#endif
65082+ return 0;
65083+}
65084+
65085+/* always called with valid inodev ptr */
65086+static void
65087+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
65088+{
65089+ struct acl_object_label *matchpo;
65090+ struct acl_subject_label *matchps;
65091+ struct acl_subject_label *subj;
65092+ struct acl_role_label *role;
65093+ unsigned int x;
65094+
65095+ FOR_EACH_ROLE_START(role)
65096+ FOR_EACH_SUBJECT_START(role, subj, x)
65097+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65098+ matchpo->mode |= GR_DELETED;
65099+ FOR_EACH_SUBJECT_END(subj,x)
65100+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65101+ /* nested subjects aren't in the role's subj_hash table */
65102+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65103+ matchpo->mode |= GR_DELETED;
65104+ FOR_EACH_NESTED_SUBJECT_END(subj)
65105+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
65106+ matchps->mode |= GR_DELETED;
65107+ FOR_EACH_ROLE_END(role)
65108+
65109+ inodev->nentry->deleted = 1;
65110+
65111+ return;
65112+}
65113+
65114+void
65115+gr_handle_delete(const ino_t ino, const dev_t dev)
65116+{
65117+ struct inodev_entry *inodev;
65118+
65119+ if (unlikely(!(gr_status & GR_READY)))
65120+ return;
65121+
65122+ write_lock(&gr_inode_lock);
65123+ inodev = lookup_inodev_entry(ino, dev);
65124+ if (inodev != NULL)
65125+ do_handle_delete(inodev, ino, dev);
65126+ write_unlock(&gr_inode_lock);
65127+
65128+ return;
65129+}
65130+
65131+static void
65132+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
65133+ const ino_t newinode, const dev_t newdevice,
65134+ struct acl_subject_label *subj)
65135+{
65136+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
65137+ struct acl_object_label *match;
65138+
65139+ match = subj->obj_hash[index];
65140+
65141+ while (match && (match->inode != oldinode ||
65142+ match->device != olddevice ||
65143+ !(match->mode & GR_DELETED)))
65144+ match = match->next;
65145+
65146+ if (match && (match->inode == oldinode)
65147+ && (match->device == olddevice)
65148+ && (match->mode & GR_DELETED)) {
65149+ if (match->prev == NULL) {
65150+ subj->obj_hash[index] = match->next;
65151+ if (match->next != NULL)
65152+ match->next->prev = NULL;
65153+ } else {
65154+ match->prev->next = match->next;
65155+ if (match->next != NULL)
65156+ match->next->prev = match->prev;
65157+ }
65158+ match->prev = NULL;
65159+ match->next = NULL;
65160+ match->inode = newinode;
65161+ match->device = newdevice;
65162+ match->mode &= ~GR_DELETED;
65163+
65164+ insert_acl_obj_label(match, subj);
65165+ }
65166+
65167+ return;
65168+}
65169+
65170+static void
65171+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65172+ const ino_t newinode, const dev_t newdevice,
65173+ struct acl_role_label *role)
65174+{
65175+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65176+ struct acl_subject_label *match;
65177+
65178+ match = role->subj_hash[index];
65179+
65180+ while (match && (match->inode != oldinode ||
65181+ match->device != olddevice ||
65182+ !(match->mode & GR_DELETED)))
65183+ match = match->next;
65184+
65185+ if (match && (match->inode == oldinode)
65186+ && (match->device == olddevice)
65187+ && (match->mode & GR_DELETED)) {
65188+ if (match->prev == NULL) {
65189+ role->subj_hash[index] = match->next;
65190+ if (match->next != NULL)
65191+ match->next->prev = NULL;
65192+ } else {
65193+ match->prev->next = match->next;
65194+ if (match->next != NULL)
65195+ match->next->prev = match->prev;
65196+ }
65197+ match->prev = NULL;
65198+ match->next = NULL;
65199+ match->inode = newinode;
65200+ match->device = newdevice;
65201+ match->mode &= ~GR_DELETED;
65202+
65203+ insert_acl_subj_label(match, role);
65204+ }
65205+
65206+ return;
65207+}
65208+
65209+static void
65210+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65211+ const ino_t newinode, const dev_t newdevice)
65212+{
65213+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65214+ struct inodev_entry *match;
65215+
65216+ match = inodev_set.i_hash[index];
65217+
65218+ while (match && (match->nentry->inode != oldinode ||
65219+ match->nentry->device != olddevice || !match->nentry->deleted))
65220+ match = match->next;
65221+
65222+ if (match && (match->nentry->inode == oldinode)
65223+ && (match->nentry->device == olddevice) &&
65224+ match->nentry->deleted) {
65225+ if (match->prev == NULL) {
65226+ inodev_set.i_hash[index] = match->next;
65227+ if (match->next != NULL)
65228+ match->next->prev = NULL;
65229+ } else {
65230+ match->prev->next = match->next;
65231+ if (match->next != NULL)
65232+ match->next->prev = match->prev;
65233+ }
65234+ match->prev = NULL;
65235+ match->next = NULL;
65236+ match->nentry->inode = newinode;
65237+ match->nentry->device = newdevice;
65238+ match->nentry->deleted = 0;
65239+
65240+ insert_inodev_entry(match);
65241+ }
65242+
65243+ return;
65244+}
65245+
65246+static void
65247+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65248+{
65249+ struct acl_subject_label *subj;
65250+ struct acl_role_label *role;
65251+ unsigned int x;
65252+
65253+ FOR_EACH_ROLE_START(role)
65254+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65255+
65256+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65257+ if ((subj->inode == ino) && (subj->device == dev)) {
65258+ subj->inode = ino;
65259+ subj->device = dev;
65260+ }
65261+ /* nested subjects aren't in the role's subj_hash table */
65262+ update_acl_obj_label(matchn->inode, matchn->device,
65263+ ino, dev, subj);
65264+ FOR_EACH_NESTED_SUBJECT_END(subj)
65265+ FOR_EACH_SUBJECT_START(role, subj, x)
65266+ update_acl_obj_label(matchn->inode, matchn->device,
65267+ ino, dev, subj);
65268+ FOR_EACH_SUBJECT_END(subj,x)
65269+ FOR_EACH_ROLE_END(role)
65270+
65271+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65272+
65273+ return;
65274+}
65275+
65276+static void
65277+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65278+ const struct vfsmount *mnt)
65279+{
65280+ ino_t ino = dentry->d_inode->i_ino;
65281+ dev_t dev = __get_dev(dentry);
65282+
65283+ __do_handle_create(matchn, ino, dev);
65284+
65285+ return;
65286+}
65287+
65288+void
65289+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65290+{
65291+ struct name_entry *matchn;
65292+
65293+ if (unlikely(!(gr_status & GR_READY)))
65294+ return;
65295+
65296+ preempt_disable();
65297+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65298+
65299+ if (unlikely((unsigned long)matchn)) {
65300+ write_lock(&gr_inode_lock);
65301+ do_handle_create(matchn, dentry, mnt);
65302+ write_unlock(&gr_inode_lock);
65303+ }
65304+ preempt_enable();
65305+
65306+ return;
65307+}
65308+
65309+void
65310+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65311+{
65312+ struct name_entry *matchn;
65313+
65314+ if (unlikely(!(gr_status & GR_READY)))
65315+ return;
65316+
65317+ preempt_disable();
65318+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65319+
65320+ if (unlikely((unsigned long)matchn)) {
65321+ write_lock(&gr_inode_lock);
65322+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65323+ write_unlock(&gr_inode_lock);
65324+ }
65325+ preempt_enable();
65326+
65327+ return;
65328+}
65329+
65330+void
65331+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65332+ struct dentry *old_dentry,
65333+ struct dentry *new_dentry,
65334+ struct vfsmount *mnt, const __u8 replace)
65335+{
65336+ struct name_entry *matchn;
65337+ struct inodev_entry *inodev;
65338+ struct inode *inode = new_dentry->d_inode;
65339+ ino_t old_ino = old_dentry->d_inode->i_ino;
65340+ dev_t old_dev = __get_dev(old_dentry);
65341+
65342+ /* vfs_rename swaps the name and parent link for old_dentry and
65343+ new_dentry
65344+ at this point, old_dentry has the new name, parent link, and inode
65345+ for the renamed file
65346+ if a file is being replaced by a rename, new_dentry has the inode
65347+ and name for the replaced file
65348+ */
65349+
65350+ if (unlikely(!(gr_status & GR_READY)))
65351+ return;
65352+
65353+ preempt_disable();
65354+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65355+
65356+ /* we wouldn't have to check d_inode if it weren't for
65357+ NFS silly-renaming
65358+ */
65359+
65360+ write_lock(&gr_inode_lock);
65361+ if (unlikely(replace && inode)) {
65362+ ino_t new_ino = inode->i_ino;
65363+ dev_t new_dev = __get_dev(new_dentry);
65364+
65365+ inodev = lookup_inodev_entry(new_ino, new_dev);
65366+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65367+ do_handle_delete(inodev, new_ino, new_dev);
65368+ }
65369+
65370+ inodev = lookup_inodev_entry(old_ino, old_dev);
65371+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65372+ do_handle_delete(inodev, old_ino, old_dev);
65373+
65374+ if (unlikely((unsigned long)matchn))
65375+ do_handle_create(matchn, old_dentry, mnt);
65376+
65377+ write_unlock(&gr_inode_lock);
65378+ preempt_enable();
65379+
65380+ return;
65381+}
65382+
65383+static int
65384+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65385+ unsigned char **sum)
65386+{
65387+ struct acl_role_label *r;
65388+ struct role_allowed_ip *ipp;
65389+ struct role_transition *trans;
65390+ unsigned int i;
65391+ int found = 0;
65392+ u32 curr_ip = current->signal->curr_ip;
65393+
65394+ current->signal->saved_ip = curr_ip;
65395+
65396+ /* check transition table */
65397+
65398+ for (trans = current->role->transitions; trans; trans = trans->next) {
65399+ if (!strcmp(rolename, trans->rolename)) {
65400+ found = 1;
65401+ break;
65402+ }
65403+ }
65404+
65405+ if (!found)
65406+ return 0;
65407+
65408+ /* handle special roles that do not require authentication
65409+ and check ip */
65410+
65411+ FOR_EACH_ROLE_START(r)
65412+ if (!strcmp(rolename, r->rolename) &&
65413+ (r->roletype & GR_ROLE_SPECIAL)) {
65414+ found = 0;
65415+ if (r->allowed_ips != NULL) {
65416+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65417+ if ((ntohl(curr_ip) & ipp->netmask) ==
65418+ (ntohl(ipp->addr) & ipp->netmask))
65419+ found = 1;
65420+ }
65421+ } else
65422+ found = 2;
65423+ if (!found)
65424+ return 0;
65425+
65426+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65427+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65428+ *salt = NULL;
65429+ *sum = NULL;
65430+ return 1;
65431+ }
65432+ }
65433+ FOR_EACH_ROLE_END(r)
65434+
65435+ for (i = 0; i < num_sprole_pws; i++) {
65436+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65437+ *salt = acl_special_roles[i]->salt;
65438+ *sum = acl_special_roles[i]->sum;
65439+ return 1;
65440+ }
65441+ }
65442+
65443+ return 0;
65444+}
65445+
65446+static void
65447+assign_special_role(char *rolename)
65448+{
65449+ struct acl_object_label *obj;
65450+ struct acl_role_label *r;
65451+ struct acl_role_label *assigned = NULL;
65452+ struct task_struct *tsk;
65453+ struct file *filp;
65454+
65455+ FOR_EACH_ROLE_START(r)
65456+ if (!strcmp(rolename, r->rolename) &&
65457+ (r->roletype & GR_ROLE_SPECIAL)) {
65458+ assigned = r;
65459+ break;
65460+ }
65461+ FOR_EACH_ROLE_END(r)
65462+
65463+ if (!assigned)
65464+ return;
65465+
65466+ read_lock(&tasklist_lock);
65467+ read_lock(&grsec_exec_file_lock);
65468+
65469+ tsk = current->real_parent;
65470+ if (tsk == NULL)
65471+ goto out_unlock;
65472+
65473+ filp = tsk->exec_file;
65474+ if (filp == NULL)
65475+ goto out_unlock;
65476+
65477+ tsk->is_writable = 0;
65478+
65479+ tsk->acl_sp_role = 1;
65480+ tsk->acl_role_id = ++acl_sp_role_value;
65481+ tsk->role = assigned;
65482+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65483+
65484+ /* ignore additional mmap checks for processes that are writable
65485+ by the default ACL */
65486+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65487+ if (unlikely(obj->mode & GR_WRITE))
65488+ tsk->is_writable = 1;
65489+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65490+ if (unlikely(obj->mode & GR_WRITE))
65491+ tsk->is_writable = 1;
65492+
65493+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65494+ 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));
65495+#endif
65496+
65497+out_unlock:
65498+ read_unlock(&grsec_exec_file_lock);
65499+ read_unlock(&tasklist_lock);
65500+ return;
65501+}
65502+
65503+int gr_check_secure_terminal(struct task_struct *task)
65504+{
65505+ struct task_struct *p, *p2, *p3;
65506+ struct files_struct *files;
65507+ struct fdtable *fdt;
65508+ struct file *our_file = NULL, *file;
65509+ int i;
65510+
65511+ if (task->signal->tty == NULL)
65512+ return 1;
65513+
65514+ files = get_files_struct(task);
65515+ if (files != NULL) {
65516+ rcu_read_lock();
65517+ fdt = files_fdtable(files);
65518+ for (i=0; i < fdt->max_fds; i++) {
65519+ file = fcheck_files(files, i);
65520+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65521+ get_file(file);
65522+ our_file = file;
65523+ }
65524+ }
65525+ rcu_read_unlock();
65526+ put_files_struct(files);
65527+ }
65528+
65529+ if (our_file == NULL)
65530+ return 1;
65531+
65532+ read_lock(&tasklist_lock);
65533+ do_each_thread(p2, p) {
65534+ files = get_files_struct(p);
65535+ if (files == NULL ||
65536+ (p->signal && p->signal->tty == task->signal->tty)) {
65537+ if (files != NULL)
65538+ put_files_struct(files);
65539+ continue;
65540+ }
65541+ rcu_read_lock();
65542+ fdt = files_fdtable(files);
65543+ for (i=0; i < fdt->max_fds; i++) {
65544+ file = fcheck_files(files, i);
65545+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65546+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65547+ p3 = task;
65548+ while (task_pid_nr(p3) > 0) {
65549+ if (p3 == p)
65550+ break;
65551+ p3 = p3->real_parent;
65552+ }
65553+ if (p3 == p)
65554+ break;
65555+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65556+ gr_handle_alertkill(p);
65557+ rcu_read_unlock();
65558+ put_files_struct(files);
65559+ read_unlock(&tasklist_lock);
65560+ fput(our_file);
65561+ return 0;
65562+ }
65563+ }
65564+ rcu_read_unlock();
65565+ put_files_struct(files);
65566+ } while_each_thread(p2, p);
65567+ read_unlock(&tasklist_lock);
65568+
65569+ fput(our_file);
65570+ return 1;
65571+}
65572+
65573+static int gr_rbac_disable(void *unused)
65574+{
65575+ pax_open_kernel();
65576+ gr_status &= ~GR_READY;
65577+ pax_close_kernel();
65578+
65579+ return 0;
65580+}
65581+
65582+ssize_t
65583+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65584+{
65585+ struct gr_arg_wrapper uwrap;
65586+ unsigned char *sprole_salt = NULL;
65587+ unsigned char *sprole_sum = NULL;
65588+ int error = 0;
65589+ int error2 = 0;
65590+ size_t req_count = 0;
65591+
65592+ mutex_lock(&gr_dev_mutex);
65593+
65594+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65595+ error = -EPERM;
65596+ goto out;
65597+ }
65598+
65599+#ifdef CONFIG_COMPAT
65600+ pax_open_kernel();
65601+ if (is_compat_task()) {
65602+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65603+ copy_gr_arg = &copy_gr_arg_compat;
65604+ copy_acl_object_label = &copy_acl_object_label_compat;
65605+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65606+ copy_acl_role_label = &copy_acl_role_label_compat;
65607+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65608+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65609+ copy_role_transition = &copy_role_transition_compat;
65610+ copy_sprole_pw = &copy_sprole_pw_compat;
65611+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65612+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65613+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65614+ } else {
65615+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65616+ copy_gr_arg = &copy_gr_arg_normal;
65617+ copy_acl_object_label = &copy_acl_object_label_normal;
65618+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65619+ copy_acl_role_label = &copy_acl_role_label_normal;
65620+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65621+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65622+ copy_role_transition = &copy_role_transition_normal;
65623+ copy_sprole_pw = &copy_sprole_pw_normal;
65624+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65625+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65626+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65627+ }
65628+ pax_close_kernel();
65629+#endif
65630+
65631+ req_count = get_gr_arg_wrapper_size();
65632+
65633+ if (count != req_count) {
65634+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65635+ error = -EINVAL;
65636+ goto out;
65637+ }
65638+
65639+
65640+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65641+ gr_auth_expires = 0;
65642+ gr_auth_attempts = 0;
65643+ }
65644+
65645+ error = copy_gr_arg_wrapper(buf, &uwrap);
65646+ if (error)
65647+ goto out;
65648+
65649+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65650+ if (error)
65651+ goto out;
65652+
65653+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65654+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65655+ time_after(gr_auth_expires, get_seconds())) {
65656+ error = -EBUSY;
65657+ goto out;
65658+ }
65659+
65660+ /* if non-root trying to do anything other than use a special role,
65661+ do not attempt authentication, do not count towards authentication
65662+ locking
65663+ */
65664+
65665+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65666+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65667+ gr_is_global_nonroot(current_uid())) {
65668+ error = -EPERM;
65669+ goto out;
65670+ }
65671+
65672+ /* ensure pw and special role name are null terminated */
65673+
65674+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65675+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65676+
65677+ /* Okay.
65678+ * We have our enough of the argument structure..(we have yet
65679+ * to copy_from_user the tables themselves) . Copy the tables
65680+ * only if we need them, i.e. for loading operations. */
65681+
65682+ switch (gr_usermode->mode) {
65683+ case GR_STATUS:
65684+ if (gr_status & GR_READY) {
65685+ error = 1;
65686+ if (!gr_check_secure_terminal(current))
65687+ error = 3;
65688+ } else
65689+ error = 2;
65690+ goto out;
65691+ case GR_SHUTDOWN:
65692+ if ((gr_status & GR_READY)
65693+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65694+ stop_machine(gr_rbac_disable, NULL, NULL);
65695+ free_variables();
65696+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65697+ memset(gr_system_salt, 0, GR_SALT_LEN);
65698+ memset(gr_system_sum, 0, GR_SHA_LEN);
65699+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65700+ } else if (gr_status & GR_READY) {
65701+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65702+ error = -EPERM;
65703+ } else {
65704+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65705+ error = -EAGAIN;
65706+ }
65707+ break;
65708+ case GR_ENABLE:
65709+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65710+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65711+ else {
65712+ if (gr_status & GR_READY)
65713+ error = -EAGAIN;
65714+ else
65715+ error = error2;
65716+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65717+ }
65718+ break;
65719+ case GR_RELOAD:
65720+ if (!(gr_status & GR_READY)) {
65721+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65722+ error = -EAGAIN;
65723+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65724+ stop_machine(gr_rbac_disable, NULL, NULL);
65725+ free_variables();
65726+ error2 = gracl_init(gr_usermode);
65727+ if (!error2)
65728+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65729+ else {
65730+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65731+ error = error2;
65732+ }
65733+ } else {
65734+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65735+ error = -EPERM;
65736+ }
65737+ break;
65738+ case GR_SEGVMOD:
65739+ if (unlikely(!(gr_status & GR_READY))) {
65740+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65741+ error = -EAGAIN;
65742+ break;
65743+ }
65744+
65745+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65746+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65747+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65748+ struct acl_subject_label *segvacl;
65749+ segvacl =
65750+ lookup_acl_subj_label(gr_usermode->segv_inode,
65751+ gr_usermode->segv_device,
65752+ current->role);
65753+ if (segvacl) {
65754+ segvacl->crashes = 0;
65755+ segvacl->expires = 0;
65756+ }
65757+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65758+ gr_remove_uid(gr_usermode->segv_uid);
65759+ }
65760+ } else {
65761+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65762+ error = -EPERM;
65763+ }
65764+ break;
65765+ case GR_SPROLE:
65766+ case GR_SPROLEPAM:
65767+ if (unlikely(!(gr_status & GR_READY))) {
65768+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65769+ error = -EAGAIN;
65770+ break;
65771+ }
65772+
65773+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65774+ current->role->expires = 0;
65775+ current->role->auth_attempts = 0;
65776+ }
65777+
65778+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65779+ time_after(current->role->expires, get_seconds())) {
65780+ error = -EBUSY;
65781+ goto out;
65782+ }
65783+
65784+ if (lookup_special_role_auth
65785+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65786+ && ((!sprole_salt && !sprole_sum)
65787+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65788+ char *p = "";
65789+ assign_special_role(gr_usermode->sp_role);
65790+ read_lock(&tasklist_lock);
65791+ if (current->real_parent)
65792+ p = current->real_parent->role->rolename;
65793+ read_unlock(&tasklist_lock);
65794+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65795+ p, acl_sp_role_value);
65796+ } else {
65797+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65798+ error = -EPERM;
65799+ if(!(current->role->auth_attempts++))
65800+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65801+
65802+ goto out;
65803+ }
65804+ break;
65805+ case GR_UNSPROLE:
65806+ if (unlikely(!(gr_status & GR_READY))) {
65807+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65808+ error = -EAGAIN;
65809+ break;
65810+ }
65811+
65812+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65813+ char *p = "";
65814+ int i = 0;
65815+
65816+ read_lock(&tasklist_lock);
65817+ if (current->real_parent) {
65818+ p = current->real_parent->role->rolename;
65819+ i = current->real_parent->acl_role_id;
65820+ }
65821+ read_unlock(&tasklist_lock);
65822+
65823+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65824+ gr_set_acls(1);
65825+ } else {
65826+ error = -EPERM;
65827+ goto out;
65828+ }
65829+ break;
65830+ default:
65831+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65832+ error = -EINVAL;
65833+ break;
65834+ }
65835+
65836+ if (error != -EPERM)
65837+ goto out;
65838+
65839+ if(!(gr_auth_attempts++))
65840+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65841+
65842+ out:
65843+ mutex_unlock(&gr_dev_mutex);
65844+
65845+ if (!error)
65846+ error = req_count;
65847+
65848+ return error;
65849+}
65850+
65851+/* must be called with
65852+ rcu_read_lock();
65853+ read_lock(&tasklist_lock);
65854+ read_lock(&grsec_exec_file_lock);
65855+*/
65856+int gr_apply_subject_to_task(struct task_struct *task)
65857+{
65858+ struct acl_object_label *obj;
65859+ char *tmpname;
65860+ struct acl_subject_label *tmpsubj;
65861+ struct file *filp;
65862+ struct name_entry *nmatch;
65863+
65864+ filp = task->exec_file;
65865+ if (filp == NULL)
65866+ return 0;
65867+
65868+ /* the following is to apply the correct subject
65869+ on binaries running when the RBAC system
65870+ is enabled, when the binaries have been
65871+ replaced or deleted since their execution
65872+ -----
65873+ when the RBAC system starts, the inode/dev
65874+ from exec_file will be one the RBAC system
65875+ is unaware of. It only knows the inode/dev
65876+ of the present file on disk, or the absence
65877+ of it.
65878+ */
65879+ preempt_disable();
65880+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65881+
65882+ nmatch = lookup_name_entry(tmpname);
65883+ preempt_enable();
65884+ tmpsubj = NULL;
65885+ if (nmatch) {
65886+ if (nmatch->deleted)
65887+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65888+ else
65889+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65890+ if (tmpsubj != NULL)
65891+ task->acl = tmpsubj;
65892+ }
65893+ if (tmpsubj == NULL)
65894+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65895+ task->role);
65896+ if (task->acl) {
65897+ task->is_writable = 0;
65898+ /* ignore additional mmap checks for processes that are writable
65899+ by the default ACL */
65900+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65901+ if (unlikely(obj->mode & GR_WRITE))
65902+ task->is_writable = 1;
65903+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65904+ if (unlikely(obj->mode & GR_WRITE))
65905+ task->is_writable = 1;
65906+
65907+ gr_set_proc_res(task);
65908+
65909+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65910+ 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);
65911+#endif
65912+ } else {
65913+ return 1;
65914+ }
65915+
65916+ return 0;
65917+}
65918+
65919+int
65920+gr_set_acls(const int type)
65921+{
65922+ struct task_struct *task, *task2;
65923+ struct acl_role_label *role = current->role;
65924+ __u16 acl_role_id = current->acl_role_id;
65925+ const struct cred *cred;
65926+ int ret;
65927+
65928+ rcu_read_lock();
65929+ read_lock(&tasklist_lock);
65930+ read_lock(&grsec_exec_file_lock);
65931+ do_each_thread(task2, task) {
65932+ /* check to see if we're called from the exit handler,
65933+ if so, only replace ACLs that have inherited the admin
65934+ ACL */
65935+
65936+ if (type && (task->role != role ||
65937+ task->acl_role_id != acl_role_id))
65938+ continue;
65939+
65940+ task->acl_role_id = 0;
65941+ task->acl_sp_role = 0;
65942+
65943+ if (task->exec_file) {
65944+ cred = __task_cred(task);
65945+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65946+ ret = gr_apply_subject_to_task(task);
65947+ if (ret) {
65948+ read_unlock(&grsec_exec_file_lock);
65949+ read_unlock(&tasklist_lock);
65950+ rcu_read_unlock();
65951+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65952+ return ret;
65953+ }
65954+ } else {
65955+ // it's a kernel process
65956+ task->role = kernel_role;
65957+ task->acl = kernel_role->root_label;
65958+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65959+ task->acl->mode &= ~GR_PROCFIND;
65960+#endif
65961+ }
65962+ } while_each_thread(task2, task);
65963+ read_unlock(&grsec_exec_file_lock);
65964+ read_unlock(&tasklist_lock);
65965+ rcu_read_unlock();
65966+
65967+ return 0;
65968+}
65969+
65970+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65971+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65972+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65973+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65974+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65975+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65976+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65977+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65978+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65979+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65980+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65981+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65982+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65983+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65984+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65985+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65986+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65987+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65988+};
65989+
65990+void
65991+gr_learn_resource(const struct task_struct *task,
65992+ const int res, const unsigned long wanted, const int gt)
65993+{
65994+ struct acl_subject_label *acl;
65995+ const struct cred *cred;
65996+
65997+ if (unlikely((gr_status & GR_READY) &&
65998+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65999+ goto skip_reslog;
66000+
66001+ gr_log_resource(task, res, wanted, gt);
66002+skip_reslog:
66003+
66004+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
66005+ return;
66006+
66007+ acl = task->acl;
66008+
66009+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
66010+ !(acl->resmask & (1U << (unsigned short) res))))
66011+ return;
66012+
66013+ if (wanted >= acl->res[res].rlim_cur) {
66014+ unsigned long res_add;
66015+
66016+ res_add = wanted + res_learn_bumps[res];
66017+
66018+ acl->res[res].rlim_cur = res_add;
66019+
66020+ if (wanted > acl->res[res].rlim_max)
66021+ acl->res[res].rlim_max = res_add;
66022+
66023+ /* only log the subject filename, since resource logging is supported for
66024+ single-subject learning only */
66025+ rcu_read_lock();
66026+ cred = __task_cred(task);
66027+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66028+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
66029+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
66030+ "", (unsigned long) res, &task->signal->saved_ip);
66031+ rcu_read_unlock();
66032+ }
66033+
66034+ return;
66035+}
66036+EXPORT_SYMBOL(gr_learn_resource);
66037+#endif
66038+
66039+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
66040+void
66041+pax_set_initial_flags(struct linux_binprm *bprm)
66042+{
66043+ struct task_struct *task = current;
66044+ struct acl_subject_label *proc;
66045+ unsigned long flags;
66046+
66047+ if (unlikely(!(gr_status & GR_READY)))
66048+ return;
66049+
66050+ flags = pax_get_flags(task);
66051+
66052+ proc = task->acl;
66053+
66054+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
66055+ flags &= ~MF_PAX_PAGEEXEC;
66056+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
66057+ flags &= ~MF_PAX_SEGMEXEC;
66058+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
66059+ flags &= ~MF_PAX_RANDMMAP;
66060+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
66061+ flags &= ~MF_PAX_EMUTRAMP;
66062+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
66063+ flags &= ~MF_PAX_MPROTECT;
66064+
66065+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
66066+ flags |= MF_PAX_PAGEEXEC;
66067+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
66068+ flags |= MF_PAX_SEGMEXEC;
66069+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
66070+ flags |= MF_PAX_RANDMMAP;
66071+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
66072+ flags |= MF_PAX_EMUTRAMP;
66073+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
66074+ flags |= MF_PAX_MPROTECT;
66075+
66076+ pax_set_flags(task, flags);
66077+
66078+ return;
66079+}
66080+#endif
66081+
66082+int
66083+gr_handle_proc_ptrace(struct task_struct *task)
66084+{
66085+ struct file *filp;
66086+ struct task_struct *tmp = task;
66087+ struct task_struct *curtemp = current;
66088+ __u32 retmode;
66089+
66090+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66091+ if (unlikely(!(gr_status & GR_READY)))
66092+ return 0;
66093+#endif
66094+
66095+ read_lock(&tasklist_lock);
66096+ read_lock(&grsec_exec_file_lock);
66097+ filp = task->exec_file;
66098+
66099+ while (task_pid_nr(tmp) > 0) {
66100+ if (tmp == curtemp)
66101+ break;
66102+ tmp = tmp->real_parent;
66103+ }
66104+
66105+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66106+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
66107+ read_unlock(&grsec_exec_file_lock);
66108+ read_unlock(&tasklist_lock);
66109+ return 1;
66110+ }
66111+
66112+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66113+ if (!(gr_status & GR_READY)) {
66114+ read_unlock(&grsec_exec_file_lock);
66115+ read_unlock(&tasklist_lock);
66116+ return 0;
66117+ }
66118+#endif
66119+
66120+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
66121+ read_unlock(&grsec_exec_file_lock);
66122+ read_unlock(&tasklist_lock);
66123+
66124+ if (retmode & GR_NOPTRACE)
66125+ return 1;
66126+
66127+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
66128+ && (current->acl != task->acl || (current->acl != current->role->root_label
66129+ && task_pid_nr(current) != task_pid_nr(task))))
66130+ return 1;
66131+
66132+ return 0;
66133+}
66134+
66135+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
66136+{
66137+ if (unlikely(!(gr_status & GR_READY)))
66138+ return;
66139+
66140+ if (!(current->role->roletype & GR_ROLE_GOD))
66141+ return;
66142+
66143+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
66144+ p->role->rolename, gr_task_roletype_to_char(p),
66145+ p->acl->filename);
66146+}
66147+
66148+int
66149+gr_handle_ptrace(struct task_struct *task, const long request)
66150+{
66151+ struct task_struct *tmp = task;
66152+ struct task_struct *curtemp = current;
66153+ __u32 retmode;
66154+
66155+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66156+ if (unlikely(!(gr_status & GR_READY)))
66157+ return 0;
66158+#endif
66159+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66160+ read_lock(&tasklist_lock);
66161+ while (task_pid_nr(tmp) > 0) {
66162+ if (tmp == curtemp)
66163+ break;
66164+ tmp = tmp->real_parent;
66165+ }
66166+
66167+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66168+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66169+ read_unlock(&tasklist_lock);
66170+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66171+ return 1;
66172+ }
66173+ read_unlock(&tasklist_lock);
66174+ }
66175+
66176+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66177+ if (!(gr_status & GR_READY))
66178+ return 0;
66179+#endif
66180+
66181+ read_lock(&grsec_exec_file_lock);
66182+ if (unlikely(!task->exec_file)) {
66183+ read_unlock(&grsec_exec_file_lock);
66184+ return 0;
66185+ }
66186+
66187+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66188+ read_unlock(&grsec_exec_file_lock);
66189+
66190+ if (retmode & GR_NOPTRACE) {
66191+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66192+ return 1;
66193+ }
66194+
66195+ if (retmode & GR_PTRACERD) {
66196+ switch (request) {
66197+ case PTRACE_SEIZE:
66198+ case PTRACE_POKETEXT:
66199+ case PTRACE_POKEDATA:
66200+ case PTRACE_POKEUSR:
66201+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66202+ case PTRACE_SETREGS:
66203+ case PTRACE_SETFPREGS:
66204+#endif
66205+#ifdef CONFIG_X86
66206+ case PTRACE_SETFPXREGS:
66207+#endif
66208+#ifdef CONFIG_ALTIVEC
66209+ case PTRACE_SETVRREGS:
66210+#endif
66211+ return 1;
66212+ default:
66213+ return 0;
66214+ }
66215+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66216+ !(current->role->roletype & GR_ROLE_GOD) &&
66217+ (current->acl != task->acl)) {
66218+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66219+ return 1;
66220+ }
66221+
66222+ return 0;
66223+}
66224+
66225+static int is_writable_mmap(const struct file *filp)
66226+{
66227+ struct task_struct *task = current;
66228+ struct acl_object_label *obj, *obj2;
66229+
66230+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66231+ !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))) {
66232+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66233+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66234+ task->role->root_label);
66235+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66236+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66237+ return 1;
66238+ }
66239+ }
66240+ return 0;
66241+}
66242+
66243+int
66244+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66245+{
66246+ __u32 mode;
66247+
66248+ if (unlikely(!file || !(prot & PROT_EXEC)))
66249+ return 1;
66250+
66251+ if (is_writable_mmap(file))
66252+ return 0;
66253+
66254+ mode =
66255+ gr_search_file(file->f_path.dentry,
66256+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66257+ file->f_path.mnt);
66258+
66259+ if (!gr_tpe_allow(file))
66260+ return 0;
66261+
66262+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66263+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66264+ return 0;
66265+ } else if (unlikely(!(mode & GR_EXEC))) {
66266+ return 0;
66267+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66268+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66269+ return 1;
66270+ }
66271+
66272+ return 1;
66273+}
66274+
66275+int
66276+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66277+{
66278+ __u32 mode;
66279+
66280+ if (unlikely(!file || !(prot & PROT_EXEC)))
66281+ return 1;
66282+
66283+ if (is_writable_mmap(file))
66284+ return 0;
66285+
66286+ mode =
66287+ gr_search_file(file->f_path.dentry,
66288+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66289+ file->f_path.mnt);
66290+
66291+ if (!gr_tpe_allow(file))
66292+ return 0;
66293+
66294+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66295+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66296+ return 0;
66297+ } else if (unlikely(!(mode & GR_EXEC))) {
66298+ return 0;
66299+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66300+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66301+ return 1;
66302+ }
66303+
66304+ return 1;
66305+}
66306+
66307+void
66308+gr_acl_handle_psacct(struct task_struct *task, const long code)
66309+{
66310+ unsigned long runtime;
66311+ unsigned long cputime;
66312+ unsigned int wday, cday;
66313+ __u8 whr, chr;
66314+ __u8 wmin, cmin;
66315+ __u8 wsec, csec;
66316+ struct timespec timeval;
66317+
66318+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66319+ !(task->acl->mode & GR_PROCACCT)))
66320+ return;
66321+
66322+ do_posix_clock_monotonic_gettime(&timeval);
66323+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66324+ wday = runtime / (3600 * 24);
66325+ runtime -= wday * (3600 * 24);
66326+ whr = runtime / 3600;
66327+ runtime -= whr * 3600;
66328+ wmin = runtime / 60;
66329+ runtime -= wmin * 60;
66330+ wsec = runtime;
66331+
66332+ cputime = (task->utime + task->stime) / HZ;
66333+ cday = cputime / (3600 * 24);
66334+ cputime -= cday * (3600 * 24);
66335+ chr = cputime / 3600;
66336+ cputime -= chr * 3600;
66337+ cmin = cputime / 60;
66338+ cputime -= cmin * 60;
66339+ csec = cputime;
66340+
66341+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66342+
66343+ return;
66344+}
66345+
66346+void gr_set_kernel_label(struct task_struct *task)
66347+{
66348+ if (gr_status & GR_READY) {
66349+ task->role = kernel_role;
66350+ task->acl = kernel_role->root_label;
66351+ }
66352+ return;
66353+}
66354+
66355+#ifdef CONFIG_TASKSTATS
66356+int gr_is_taskstats_denied(int pid)
66357+{
66358+ struct task_struct *task;
66359+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66360+ const struct cred *cred;
66361+#endif
66362+ int ret = 0;
66363+
66364+ /* restrict taskstats viewing to un-chrooted root users
66365+ who have the 'view' subject flag if the RBAC system is enabled
66366+ */
66367+
66368+ rcu_read_lock();
66369+ read_lock(&tasklist_lock);
66370+ task = find_task_by_vpid(pid);
66371+ if (task) {
66372+#ifdef CONFIG_GRKERNSEC_CHROOT
66373+ if (proc_is_chrooted(task))
66374+ ret = -EACCES;
66375+#endif
66376+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66377+ cred = __task_cred(task);
66378+#ifdef CONFIG_GRKERNSEC_PROC_USER
66379+ if (gr_is_global_nonroot(cred->uid))
66380+ ret = -EACCES;
66381+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66382+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66383+ ret = -EACCES;
66384+#endif
66385+#endif
66386+ if (gr_status & GR_READY) {
66387+ if (!(task->acl->mode & GR_VIEW))
66388+ ret = -EACCES;
66389+ }
66390+ } else
66391+ ret = -ENOENT;
66392+
66393+ read_unlock(&tasklist_lock);
66394+ rcu_read_unlock();
66395+
66396+ return ret;
66397+}
66398+#endif
66399+
66400+/* AUXV entries are filled via a descendant of search_binary_handler
66401+ after we've already applied the subject for the target
66402+*/
66403+int gr_acl_enable_at_secure(void)
66404+{
66405+ if (unlikely(!(gr_status & GR_READY)))
66406+ return 0;
66407+
66408+ if (current->acl->mode & GR_ATSECURE)
66409+ return 1;
66410+
66411+ return 0;
66412+}
66413+
66414+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66415+{
66416+ struct task_struct *task = current;
66417+ struct dentry *dentry = file->f_path.dentry;
66418+ struct vfsmount *mnt = file->f_path.mnt;
66419+ struct acl_object_label *obj, *tmp;
66420+ struct acl_subject_label *subj;
66421+ unsigned int bufsize;
66422+ int is_not_root;
66423+ char *path;
66424+ dev_t dev = __get_dev(dentry);
66425+
66426+ if (unlikely(!(gr_status & GR_READY)))
66427+ return 1;
66428+
66429+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66430+ return 1;
66431+
66432+ /* ignore Eric Biederman */
66433+ if (IS_PRIVATE(dentry->d_inode))
66434+ return 1;
66435+
66436+ subj = task->acl;
66437+ read_lock(&gr_inode_lock);
66438+ do {
66439+ obj = lookup_acl_obj_label(ino, dev, subj);
66440+ if (obj != NULL) {
66441+ read_unlock(&gr_inode_lock);
66442+ return (obj->mode & GR_FIND) ? 1 : 0;
66443+ }
66444+ } while ((subj = subj->parent_subject));
66445+ read_unlock(&gr_inode_lock);
66446+
66447+ /* this is purely an optimization since we're looking for an object
66448+ for the directory we're doing a readdir on
66449+ if it's possible for any globbed object to match the entry we're
66450+ filling into the directory, then the object we find here will be
66451+ an anchor point with attached globbed objects
66452+ */
66453+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66454+ if (obj->globbed == NULL)
66455+ return (obj->mode & GR_FIND) ? 1 : 0;
66456+
66457+ is_not_root = ((obj->filename[0] == '/') &&
66458+ (obj->filename[1] == '\0')) ? 0 : 1;
66459+ bufsize = PAGE_SIZE - namelen - is_not_root;
66460+
66461+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66462+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66463+ return 1;
66464+
66465+ preempt_disable();
66466+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66467+ bufsize);
66468+
66469+ bufsize = strlen(path);
66470+
66471+ /* if base is "/", don't append an additional slash */
66472+ if (is_not_root)
66473+ *(path + bufsize) = '/';
66474+ memcpy(path + bufsize + is_not_root, name, namelen);
66475+ *(path + bufsize + namelen + is_not_root) = '\0';
66476+
66477+ tmp = obj->globbed;
66478+ while (tmp) {
66479+ if (!glob_match(tmp->filename, path)) {
66480+ preempt_enable();
66481+ return (tmp->mode & GR_FIND) ? 1 : 0;
66482+ }
66483+ tmp = tmp->next;
66484+ }
66485+ preempt_enable();
66486+ return (obj->mode & GR_FIND) ? 1 : 0;
66487+}
66488+
66489+void gr_put_exec_file(struct task_struct *task)
66490+{
66491+ struct file *filp;
66492+
66493+ write_lock(&grsec_exec_file_lock);
66494+ filp = task->exec_file;
66495+ task->exec_file = NULL;
66496+ write_unlock(&grsec_exec_file_lock);
66497+
66498+ if (filp)
66499+ fput(filp);
66500+
66501+ return;
66502+}
66503+
66504+
66505+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66506+EXPORT_SYMBOL(gr_acl_is_enabled);
66507+#endif
66508+EXPORT_SYMBOL(gr_set_kernel_label);
66509+#ifdef CONFIG_SECURITY
66510+EXPORT_SYMBOL(gr_check_user_change);
66511+EXPORT_SYMBOL(gr_check_group_change);
66512+#endif
66513+
66514diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66515new file mode 100644
66516index 0000000..34fefda
66517--- /dev/null
66518+++ b/grsecurity/gracl_alloc.c
66519@@ -0,0 +1,105 @@
66520+#include <linux/kernel.h>
66521+#include <linux/mm.h>
66522+#include <linux/slab.h>
66523+#include <linux/vmalloc.h>
66524+#include <linux/gracl.h>
66525+#include <linux/grsecurity.h>
66526+
66527+static unsigned long alloc_stack_next = 1;
66528+static unsigned long alloc_stack_size = 1;
66529+static void **alloc_stack;
66530+
66531+static __inline__ int
66532+alloc_pop(void)
66533+{
66534+ if (alloc_stack_next == 1)
66535+ return 0;
66536+
66537+ kfree(alloc_stack[alloc_stack_next - 2]);
66538+
66539+ alloc_stack_next--;
66540+
66541+ return 1;
66542+}
66543+
66544+static __inline__ int
66545+alloc_push(void *buf)
66546+{
66547+ if (alloc_stack_next >= alloc_stack_size)
66548+ return 1;
66549+
66550+ alloc_stack[alloc_stack_next - 1] = buf;
66551+
66552+ alloc_stack_next++;
66553+
66554+ return 0;
66555+}
66556+
66557+void *
66558+acl_alloc(unsigned long len)
66559+{
66560+ void *ret = NULL;
66561+
66562+ if (!len || len > PAGE_SIZE)
66563+ goto out;
66564+
66565+ ret = kmalloc(len, GFP_KERNEL);
66566+
66567+ if (ret) {
66568+ if (alloc_push(ret)) {
66569+ kfree(ret);
66570+ ret = NULL;
66571+ }
66572+ }
66573+
66574+out:
66575+ return ret;
66576+}
66577+
66578+void *
66579+acl_alloc_num(unsigned long num, unsigned long len)
66580+{
66581+ if (!len || (num > (PAGE_SIZE / len)))
66582+ return NULL;
66583+
66584+ return acl_alloc(num * len);
66585+}
66586+
66587+void
66588+acl_free_all(void)
66589+{
66590+ if (gr_acl_is_enabled() || !alloc_stack)
66591+ return;
66592+
66593+ while (alloc_pop()) ;
66594+
66595+ if (alloc_stack) {
66596+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66597+ kfree(alloc_stack);
66598+ else
66599+ vfree(alloc_stack);
66600+ }
66601+
66602+ alloc_stack = NULL;
66603+ alloc_stack_size = 1;
66604+ alloc_stack_next = 1;
66605+
66606+ return;
66607+}
66608+
66609+int
66610+acl_alloc_stack_init(unsigned long size)
66611+{
66612+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66613+ alloc_stack =
66614+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66615+ else
66616+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66617+
66618+ alloc_stack_size = size;
66619+
66620+ if (!alloc_stack)
66621+ return 0;
66622+ else
66623+ return 1;
66624+}
66625diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66626new file mode 100644
66627index 0000000..bdd51ea
66628--- /dev/null
66629+++ b/grsecurity/gracl_cap.c
66630@@ -0,0 +1,110 @@
66631+#include <linux/kernel.h>
66632+#include <linux/module.h>
66633+#include <linux/sched.h>
66634+#include <linux/gracl.h>
66635+#include <linux/grsecurity.h>
66636+#include <linux/grinternal.h>
66637+
66638+extern const char *captab_log[];
66639+extern int captab_log_entries;
66640+
66641+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66642+{
66643+ struct acl_subject_label *curracl;
66644+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66645+ kernel_cap_t cap_audit = __cap_empty_set;
66646+
66647+ if (!gr_acl_is_enabled())
66648+ return 1;
66649+
66650+ curracl = task->acl;
66651+
66652+ cap_drop = curracl->cap_lower;
66653+ cap_mask = curracl->cap_mask;
66654+ cap_audit = curracl->cap_invert_audit;
66655+
66656+ while ((curracl = curracl->parent_subject)) {
66657+ /* if the cap isn't specified in the current computed mask but is specified in the
66658+ current level subject, and is lowered in the current level subject, then add
66659+ it to the set of dropped capabilities
66660+ otherwise, add the current level subject's mask to the current computed mask
66661+ */
66662+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66663+ cap_raise(cap_mask, cap);
66664+ if (cap_raised(curracl->cap_lower, cap))
66665+ cap_raise(cap_drop, cap);
66666+ if (cap_raised(curracl->cap_invert_audit, cap))
66667+ cap_raise(cap_audit, cap);
66668+ }
66669+ }
66670+
66671+ if (!cap_raised(cap_drop, cap)) {
66672+ if (cap_raised(cap_audit, cap))
66673+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66674+ return 1;
66675+ }
66676+
66677+ curracl = task->acl;
66678+
66679+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66680+ && cap_raised(cred->cap_effective, cap)) {
66681+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66682+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66683+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66684+ gr_to_filename(task->exec_file->f_path.dentry,
66685+ task->exec_file->f_path.mnt) : curracl->filename,
66686+ curracl->filename, 0UL,
66687+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66688+ return 1;
66689+ }
66690+
66691+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66692+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66693+
66694+ return 0;
66695+}
66696+
66697+int
66698+gr_acl_is_capable(const int cap)
66699+{
66700+ return gr_task_acl_is_capable(current, current_cred(), cap);
66701+}
66702+
66703+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66704+{
66705+ struct acl_subject_label *curracl;
66706+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66707+
66708+ if (!gr_acl_is_enabled())
66709+ return 1;
66710+
66711+ curracl = task->acl;
66712+
66713+ cap_drop = curracl->cap_lower;
66714+ cap_mask = curracl->cap_mask;
66715+
66716+ while ((curracl = curracl->parent_subject)) {
66717+ /* if the cap isn't specified in the current computed mask but is specified in the
66718+ current level subject, and is lowered in the current level subject, then add
66719+ it to the set of dropped capabilities
66720+ otherwise, add the current level subject's mask to the current computed mask
66721+ */
66722+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66723+ cap_raise(cap_mask, cap);
66724+ if (cap_raised(curracl->cap_lower, cap))
66725+ cap_raise(cap_drop, cap);
66726+ }
66727+ }
66728+
66729+ if (!cap_raised(cap_drop, cap))
66730+ return 1;
66731+
66732+ return 0;
66733+}
66734+
66735+int
66736+gr_acl_is_capable_nolog(const int cap)
66737+{
66738+ return gr_task_acl_is_capable_nolog(current, cap);
66739+}
66740+
66741diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66742new file mode 100644
66743index 0000000..a43dd06
66744--- /dev/null
66745+++ b/grsecurity/gracl_compat.c
66746@@ -0,0 +1,269 @@
66747+#include <linux/kernel.h>
66748+#include <linux/gracl.h>
66749+#include <linux/compat.h>
66750+#include <linux/gracl_compat.h>
66751+
66752+#include <asm/uaccess.h>
66753+
66754+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66755+{
66756+ struct gr_arg_wrapper_compat uwrapcompat;
66757+
66758+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66759+ return -EFAULT;
66760+
66761+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66762+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66763+ return -EINVAL;
66764+
66765+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66766+ uwrap->version = uwrapcompat.version;
66767+ uwrap->size = sizeof(struct gr_arg);
66768+
66769+ return 0;
66770+}
66771+
66772+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66773+{
66774+ struct gr_arg_compat argcompat;
66775+
66776+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66777+ return -EFAULT;
66778+
66779+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66780+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66781+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66782+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66783+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66784+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66785+
66786+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66787+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66788+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66789+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66790+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66791+ arg->segv_device = argcompat.segv_device;
66792+ arg->segv_inode = argcompat.segv_inode;
66793+ arg->segv_uid = argcompat.segv_uid;
66794+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66795+ arg->mode = argcompat.mode;
66796+
66797+ return 0;
66798+}
66799+
66800+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66801+{
66802+ struct acl_object_label_compat objcompat;
66803+
66804+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66805+ return -EFAULT;
66806+
66807+ obj->filename = compat_ptr(objcompat.filename);
66808+ obj->inode = objcompat.inode;
66809+ obj->device = objcompat.device;
66810+ obj->mode = objcompat.mode;
66811+
66812+ obj->nested = compat_ptr(objcompat.nested);
66813+ obj->globbed = compat_ptr(objcompat.globbed);
66814+
66815+ obj->prev = compat_ptr(objcompat.prev);
66816+ obj->next = compat_ptr(objcompat.next);
66817+
66818+ return 0;
66819+}
66820+
66821+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66822+{
66823+ unsigned int i;
66824+ struct acl_subject_label_compat subjcompat;
66825+
66826+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66827+ return -EFAULT;
66828+
66829+ subj->filename = compat_ptr(subjcompat.filename);
66830+ subj->inode = subjcompat.inode;
66831+ subj->device = subjcompat.device;
66832+ subj->mode = subjcompat.mode;
66833+ subj->cap_mask = subjcompat.cap_mask;
66834+ subj->cap_lower = subjcompat.cap_lower;
66835+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66836+
66837+ for (i = 0; i < GR_NLIMITS; i++) {
66838+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66839+ subj->res[i].rlim_cur = RLIM_INFINITY;
66840+ else
66841+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66842+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66843+ subj->res[i].rlim_max = RLIM_INFINITY;
66844+ else
66845+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66846+ }
66847+ subj->resmask = subjcompat.resmask;
66848+
66849+ subj->user_trans_type = subjcompat.user_trans_type;
66850+ subj->group_trans_type = subjcompat.group_trans_type;
66851+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66852+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66853+ subj->user_trans_num = subjcompat.user_trans_num;
66854+ subj->group_trans_num = subjcompat.group_trans_num;
66855+
66856+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66857+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66858+ subj->ip_type = subjcompat.ip_type;
66859+ subj->ips = compat_ptr(subjcompat.ips);
66860+ subj->ip_num = subjcompat.ip_num;
66861+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66862+
66863+ subj->crashes = subjcompat.crashes;
66864+ subj->expires = subjcompat.expires;
66865+
66866+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66867+ subj->hash = compat_ptr(subjcompat.hash);
66868+ subj->prev = compat_ptr(subjcompat.prev);
66869+ subj->next = compat_ptr(subjcompat.next);
66870+
66871+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66872+ subj->obj_hash_size = subjcompat.obj_hash_size;
66873+ subj->pax_flags = subjcompat.pax_flags;
66874+
66875+ return 0;
66876+}
66877+
66878+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66879+{
66880+ struct acl_role_label_compat rolecompat;
66881+
66882+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66883+ return -EFAULT;
66884+
66885+ role->rolename = compat_ptr(rolecompat.rolename);
66886+ role->uidgid = rolecompat.uidgid;
66887+ role->roletype = rolecompat.roletype;
66888+
66889+ role->auth_attempts = rolecompat.auth_attempts;
66890+ role->expires = rolecompat.expires;
66891+
66892+ role->root_label = compat_ptr(rolecompat.root_label);
66893+ role->hash = compat_ptr(rolecompat.hash);
66894+
66895+ role->prev = compat_ptr(rolecompat.prev);
66896+ role->next = compat_ptr(rolecompat.next);
66897+
66898+ role->transitions = compat_ptr(rolecompat.transitions);
66899+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66900+ role->domain_children = compat_ptr(rolecompat.domain_children);
66901+ role->domain_child_num = rolecompat.domain_child_num;
66902+
66903+ role->umask = rolecompat.umask;
66904+
66905+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66906+ role->subj_hash_size = rolecompat.subj_hash_size;
66907+
66908+ return 0;
66909+}
66910+
66911+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66912+{
66913+ struct role_allowed_ip_compat roleip_compat;
66914+
66915+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66916+ return -EFAULT;
66917+
66918+ roleip->addr = roleip_compat.addr;
66919+ roleip->netmask = roleip_compat.netmask;
66920+
66921+ roleip->prev = compat_ptr(roleip_compat.prev);
66922+ roleip->next = compat_ptr(roleip_compat.next);
66923+
66924+ return 0;
66925+}
66926+
66927+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66928+{
66929+ struct role_transition_compat trans_compat;
66930+
66931+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66932+ return -EFAULT;
66933+
66934+ trans->rolename = compat_ptr(trans_compat.rolename);
66935+
66936+ trans->prev = compat_ptr(trans_compat.prev);
66937+ trans->next = compat_ptr(trans_compat.next);
66938+
66939+ return 0;
66940+
66941+}
66942+
66943+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66944+{
66945+ struct gr_hash_struct_compat hash_compat;
66946+
66947+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66948+ return -EFAULT;
66949+
66950+ hash->table = compat_ptr(hash_compat.table);
66951+ hash->nametable = compat_ptr(hash_compat.nametable);
66952+ hash->first = compat_ptr(hash_compat.first);
66953+
66954+ hash->table_size = hash_compat.table_size;
66955+ hash->used_size = hash_compat.used_size;
66956+
66957+ hash->type = hash_compat.type;
66958+
66959+ return 0;
66960+}
66961+
66962+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66963+{
66964+ compat_uptr_t ptrcompat;
66965+
66966+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66967+ return -EFAULT;
66968+
66969+ *(void **)ptr = compat_ptr(ptrcompat);
66970+
66971+ return 0;
66972+}
66973+
66974+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66975+{
66976+ struct acl_ip_label_compat ip_compat;
66977+
66978+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66979+ return -EFAULT;
66980+
66981+ ip->iface = compat_ptr(ip_compat.iface);
66982+ ip->addr = ip_compat.addr;
66983+ ip->netmask = ip_compat.netmask;
66984+ ip->low = ip_compat.low;
66985+ ip->high = ip_compat.high;
66986+ ip->mode = ip_compat.mode;
66987+ ip->type = ip_compat.type;
66988+
66989+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66990+
66991+ ip->prev = compat_ptr(ip_compat.prev);
66992+ ip->next = compat_ptr(ip_compat.next);
66993+
66994+ return 0;
66995+}
66996+
66997+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66998+{
66999+ struct sprole_pw_compat pw_compat;
67000+
67001+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
67002+ return -EFAULT;
67003+
67004+ pw->rolename = compat_ptr(pw_compat.rolename);
67005+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
67006+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
67007+
67008+ return 0;
67009+}
67010+
67011+size_t get_gr_arg_wrapper_size_compat(void)
67012+{
67013+ return sizeof(struct gr_arg_wrapper_compat);
67014+}
67015+
67016diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
67017new file mode 100644
67018index 0000000..a340c17
67019--- /dev/null
67020+++ b/grsecurity/gracl_fs.c
67021@@ -0,0 +1,431 @@
67022+#include <linux/kernel.h>
67023+#include <linux/sched.h>
67024+#include <linux/types.h>
67025+#include <linux/fs.h>
67026+#include <linux/file.h>
67027+#include <linux/stat.h>
67028+#include <linux/grsecurity.h>
67029+#include <linux/grinternal.h>
67030+#include <linux/gracl.h>
67031+
67032+umode_t
67033+gr_acl_umask(void)
67034+{
67035+ if (unlikely(!gr_acl_is_enabled()))
67036+ return 0;
67037+
67038+ return current->role->umask;
67039+}
67040+
67041+__u32
67042+gr_acl_handle_hidden_file(const struct dentry * dentry,
67043+ const struct vfsmount * mnt)
67044+{
67045+ __u32 mode;
67046+
67047+ if (unlikely(!dentry->d_inode))
67048+ return GR_FIND;
67049+
67050+ mode =
67051+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
67052+
67053+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
67054+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
67055+ return mode;
67056+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
67057+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
67058+ return 0;
67059+ } else if (unlikely(!(mode & GR_FIND)))
67060+ return 0;
67061+
67062+ return GR_FIND;
67063+}
67064+
67065+__u32
67066+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
67067+ int acc_mode)
67068+{
67069+ __u32 reqmode = GR_FIND;
67070+ __u32 mode;
67071+
67072+ if (unlikely(!dentry->d_inode))
67073+ return reqmode;
67074+
67075+ if (acc_mode & MAY_APPEND)
67076+ reqmode |= GR_APPEND;
67077+ else if (acc_mode & MAY_WRITE)
67078+ reqmode |= GR_WRITE;
67079+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
67080+ reqmode |= GR_READ;
67081+
67082+ mode =
67083+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67084+ mnt);
67085+
67086+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67087+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
67088+ reqmode & GR_READ ? " reading" : "",
67089+ reqmode & GR_WRITE ? " writing" : reqmode &
67090+ GR_APPEND ? " appending" : "");
67091+ return reqmode;
67092+ } else
67093+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67094+ {
67095+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
67096+ reqmode & GR_READ ? " reading" : "",
67097+ reqmode & GR_WRITE ? " writing" : reqmode &
67098+ GR_APPEND ? " appending" : "");
67099+ return 0;
67100+ } else if (unlikely((mode & reqmode) != reqmode))
67101+ return 0;
67102+
67103+ return reqmode;
67104+}
67105+
67106+__u32
67107+gr_acl_handle_creat(const struct dentry * dentry,
67108+ const struct dentry * p_dentry,
67109+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
67110+ const int imode)
67111+{
67112+ __u32 reqmode = GR_WRITE | GR_CREATE;
67113+ __u32 mode;
67114+
67115+ if (acc_mode & MAY_APPEND)
67116+ reqmode |= GR_APPEND;
67117+ // if a directory was required or the directory already exists, then
67118+ // don't count this open as a read
67119+ if ((acc_mode & MAY_READ) &&
67120+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
67121+ reqmode |= GR_READ;
67122+ if ((open_flags & O_CREAT) &&
67123+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67124+ reqmode |= GR_SETID;
67125+
67126+ mode =
67127+ gr_check_create(dentry, p_dentry, p_mnt,
67128+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67129+
67130+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67131+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67132+ reqmode & GR_READ ? " reading" : "",
67133+ reqmode & GR_WRITE ? " writing" : reqmode &
67134+ GR_APPEND ? " appending" : "");
67135+ return reqmode;
67136+ } else
67137+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67138+ {
67139+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67140+ reqmode & GR_READ ? " reading" : "",
67141+ reqmode & GR_WRITE ? " writing" : reqmode &
67142+ GR_APPEND ? " appending" : "");
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_access(const struct dentry * dentry, const struct vfsmount * mnt,
67152+ const int fmode)
67153+{
67154+ __u32 mode, reqmode = GR_FIND;
67155+
67156+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67157+ reqmode |= GR_EXEC;
67158+ if (fmode & S_IWOTH)
67159+ reqmode |= GR_WRITE;
67160+ if (fmode & S_IROTH)
67161+ reqmode |= GR_READ;
67162+
67163+ mode =
67164+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67165+ mnt);
67166+
67167+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67168+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67169+ reqmode & GR_READ ? " reading" : "",
67170+ reqmode & GR_WRITE ? " writing" : "",
67171+ reqmode & GR_EXEC ? " executing" : "");
67172+ return reqmode;
67173+ } else
67174+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67175+ {
67176+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67177+ reqmode & GR_READ ? " reading" : "",
67178+ reqmode & GR_WRITE ? " writing" : "",
67179+ reqmode & GR_EXEC ? " executing" : "");
67180+ return 0;
67181+ } else if (unlikely((mode & reqmode) != reqmode))
67182+ return 0;
67183+
67184+ return reqmode;
67185+}
67186+
67187+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67188+{
67189+ __u32 mode;
67190+
67191+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67192+
67193+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67194+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67195+ return mode;
67196+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67197+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67198+ return 0;
67199+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67200+ return 0;
67201+
67202+ return (reqmode);
67203+}
67204+
67205+__u32
67206+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67207+{
67208+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67209+}
67210+
67211+__u32
67212+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67213+{
67214+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67215+}
67216+
67217+__u32
67218+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67219+{
67220+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67221+}
67222+
67223+__u32
67224+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67225+{
67226+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67227+}
67228+
67229+__u32
67230+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67231+ umode_t *modeptr)
67232+{
67233+ umode_t mode;
67234+
67235+ *modeptr &= ~gr_acl_umask();
67236+ mode = *modeptr;
67237+
67238+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67239+ return 1;
67240+
67241+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67242+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67243+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67244+ GR_CHMOD_ACL_MSG);
67245+ } else {
67246+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67247+ }
67248+}
67249+
67250+__u32
67251+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67252+{
67253+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67254+}
67255+
67256+__u32
67257+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67258+{
67259+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67260+}
67261+
67262+__u32
67263+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67264+{
67265+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67266+}
67267+
67268+__u32
67269+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67270+{
67271+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67272+ GR_UNIXCONNECT_ACL_MSG);
67273+}
67274+
67275+/* hardlinks require at minimum create and link permission,
67276+ any additional privilege required is based on the
67277+ privilege of the file being linked to
67278+*/
67279+__u32
67280+gr_acl_handle_link(const struct dentry * new_dentry,
67281+ const struct dentry * parent_dentry,
67282+ const struct vfsmount * parent_mnt,
67283+ const struct dentry * old_dentry,
67284+ const struct vfsmount * old_mnt, const struct filename *to)
67285+{
67286+ __u32 mode;
67287+ __u32 needmode = GR_CREATE | GR_LINK;
67288+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67289+
67290+ mode =
67291+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67292+ old_mnt);
67293+
67294+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67295+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67296+ return mode;
67297+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67298+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67299+ return 0;
67300+ } else if (unlikely((mode & needmode) != needmode))
67301+ return 0;
67302+
67303+ return 1;
67304+}
67305+
67306+__u32
67307+gr_acl_handle_symlink(const struct dentry * new_dentry,
67308+ const struct dentry * parent_dentry,
67309+ const struct vfsmount * parent_mnt, const struct filename *from)
67310+{
67311+ __u32 needmode = GR_WRITE | GR_CREATE;
67312+ __u32 mode;
67313+
67314+ mode =
67315+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67316+ GR_CREATE | GR_AUDIT_CREATE |
67317+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67318+
67319+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67320+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67321+ return mode;
67322+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67323+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67324+ return 0;
67325+ } else if (unlikely((mode & needmode) != needmode))
67326+ return 0;
67327+
67328+ return (GR_WRITE | GR_CREATE);
67329+}
67330+
67331+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)
67332+{
67333+ __u32 mode;
67334+
67335+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67336+
67337+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67338+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67339+ return mode;
67340+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67341+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67342+ return 0;
67343+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67344+ return 0;
67345+
67346+ return (reqmode);
67347+}
67348+
67349+__u32
67350+gr_acl_handle_mknod(const struct dentry * new_dentry,
67351+ const struct dentry * parent_dentry,
67352+ const struct vfsmount * parent_mnt,
67353+ const int mode)
67354+{
67355+ __u32 reqmode = GR_WRITE | GR_CREATE;
67356+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67357+ reqmode |= GR_SETID;
67358+
67359+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67360+ reqmode, GR_MKNOD_ACL_MSG);
67361+}
67362+
67363+__u32
67364+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67365+ const struct dentry *parent_dentry,
67366+ const struct vfsmount *parent_mnt)
67367+{
67368+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67369+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67370+}
67371+
67372+#define RENAME_CHECK_SUCCESS(old, new) \
67373+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67374+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67375+
67376+int
67377+gr_acl_handle_rename(struct dentry *new_dentry,
67378+ struct dentry *parent_dentry,
67379+ const struct vfsmount *parent_mnt,
67380+ struct dentry *old_dentry,
67381+ struct inode *old_parent_inode,
67382+ struct vfsmount *old_mnt, const struct filename *newname)
67383+{
67384+ __u32 comp1, comp2;
67385+ int error = 0;
67386+
67387+ if (unlikely(!gr_acl_is_enabled()))
67388+ return 0;
67389+
67390+ if (!new_dentry->d_inode) {
67391+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67392+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67393+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67394+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67395+ GR_DELETE | GR_AUDIT_DELETE |
67396+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67397+ GR_SUPPRESS, old_mnt);
67398+ } else {
67399+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67400+ GR_CREATE | GR_DELETE |
67401+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67402+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67403+ GR_SUPPRESS, parent_mnt);
67404+ comp2 =
67405+ gr_search_file(old_dentry,
67406+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67407+ GR_DELETE | GR_AUDIT_DELETE |
67408+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67409+ }
67410+
67411+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67412+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67413+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67414+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67415+ && !(comp2 & GR_SUPPRESS)) {
67416+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67417+ error = -EACCES;
67418+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67419+ error = -EACCES;
67420+
67421+ return error;
67422+}
67423+
67424+void
67425+gr_acl_handle_exit(void)
67426+{
67427+ u16 id;
67428+ char *rolename;
67429+
67430+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67431+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67432+ id = current->acl_role_id;
67433+ rolename = current->role->rolename;
67434+ gr_set_acls(1);
67435+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67436+ }
67437+
67438+ gr_put_exec_file(current);
67439+ return;
67440+}
67441+
67442+int
67443+gr_acl_handle_procpidmem(const struct task_struct *task)
67444+{
67445+ if (unlikely(!gr_acl_is_enabled()))
67446+ return 0;
67447+
67448+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67449+ return -EACCES;
67450+
67451+ return 0;
67452+}
67453diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67454new file mode 100644
67455index 0000000..8132048
67456--- /dev/null
67457+++ b/grsecurity/gracl_ip.c
67458@@ -0,0 +1,387 @@
67459+#include <linux/kernel.h>
67460+#include <asm/uaccess.h>
67461+#include <asm/errno.h>
67462+#include <net/sock.h>
67463+#include <linux/file.h>
67464+#include <linux/fs.h>
67465+#include <linux/net.h>
67466+#include <linux/in.h>
67467+#include <linux/skbuff.h>
67468+#include <linux/ip.h>
67469+#include <linux/udp.h>
67470+#include <linux/types.h>
67471+#include <linux/sched.h>
67472+#include <linux/netdevice.h>
67473+#include <linux/inetdevice.h>
67474+#include <linux/gracl.h>
67475+#include <linux/grsecurity.h>
67476+#include <linux/grinternal.h>
67477+
67478+#define GR_BIND 0x01
67479+#define GR_CONNECT 0x02
67480+#define GR_INVERT 0x04
67481+#define GR_BINDOVERRIDE 0x08
67482+#define GR_CONNECTOVERRIDE 0x10
67483+#define GR_SOCK_FAMILY 0x20
67484+
67485+static const char * gr_protocols[IPPROTO_MAX] = {
67486+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67487+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67488+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67489+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67490+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67491+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67492+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67493+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67494+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67495+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67496+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67497+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67498+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67499+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67500+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67501+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67502+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67503+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67504+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67505+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67506+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67507+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67508+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67509+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67510+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67511+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67512+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67513+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67514+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67515+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67516+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67517+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67518+ };
67519+
67520+static const char * gr_socktypes[SOCK_MAX] = {
67521+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67522+ "unknown:7", "unknown:8", "unknown:9", "packet"
67523+ };
67524+
67525+static const char * gr_sockfamilies[AF_MAX+1] = {
67526+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67527+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67528+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67529+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67530+ };
67531+
67532+const char *
67533+gr_proto_to_name(unsigned char proto)
67534+{
67535+ return gr_protocols[proto];
67536+}
67537+
67538+const char *
67539+gr_socktype_to_name(unsigned char type)
67540+{
67541+ return gr_socktypes[type];
67542+}
67543+
67544+const char *
67545+gr_sockfamily_to_name(unsigned char family)
67546+{
67547+ return gr_sockfamilies[family];
67548+}
67549+
67550+int
67551+gr_search_socket(const int domain, const int type, const int protocol)
67552+{
67553+ struct acl_subject_label *curr;
67554+ const struct cred *cred = current_cred();
67555+
67556+ if (unlikely(!gr_acl_is_enabled()))
67557+ goto exit;
67558+
67559+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67560+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67561+ goto exit; // let the kernel handle it
67562+
67563+ curr = current->acl;
67564+
67565+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67566+ /* the family is allowed, if this is PF_INET allow it only if
67567+ the extra sock type/protocol checks pass */
67568+ if (domain == PF_INET)
67569+ goto inet_check;
67570+ goto exit;
67571+ } else {
67572+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67573+ __u32 fakeip = 0;
67574+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67575+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67576+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67577+ gr_to_filename(current->exec_file->f_path.dentry,
67578+ current->exec_file->f_path.mnt) :
67579+ curr->filename, curr->filename,
67580+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67581+ &current->signal->saved_ip);
67582+ goto exit;
67583+ }
67584+ goto exit_fail;
67585+ }
67586+
67587+inet_check:
67588+ /* the rest of this checking is for IPv4 only */
67589+ if (!curr->ips)
67590+ goto exit;
67591+
67592+ if ((curr->ip_type & (1U << type)) &&
67593+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67594+ goto exit;
67595+
67596+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67597+ /* we don't place acls on raw sockets , and sometimes
67598+ dgram/ip sockets are opened for ioctl and not
67599+ bind/connect, so we'll fake a bind learn log */
67600+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67601+ __u32 fakeip = 0;
67602+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67603+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67604+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67605+ gr_to_filename(current->exec_file->f_path.dentry,
67606+ current->exec_file->f_path.mnt) :
67607+ curr->filename, curr->filename,
67608+ &fakeip, 0, type,
67609+ protocol, GR_CONNECT, &current->signal->saved_ip);
67610+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67611+ __u32 fakeip = 0;
67612+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67613+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67614+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67615+ gr_to_filename(current->exec_file->f_path.dentry,
67616+ current->exec_file->f_path.mnt) :
67617+ curr->filename, curr->filename,
67618+ &fakeip, 0, type,
67619+ protocol, GR_BIND, &current->signal->saved_ip);
67620+ }
67621+ /* we'll log when they use connect or bind */
67622+ goto exit;
67623+ }
67624+
67625+exit_fail:
67626+ if (domain == PF_INET)
67627+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67628+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67629+ else
67630+#ifndef CONFIG_IPV6
67631+ if (domain != PF_INET6)
67632+#endif
67633+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67634+ gr_socktype_to_name(type), protocol);
67635+
67636+ return 0;
67637+exit:
67638+ return 1;
67639+}
67640+
67641+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)
67642+{
67643+ if ((ip->mode & mode) &&
67644+ (ip_port >= ip->low) &&
67645+ (ip_port <= ip->high) &&
67646+ ((ntohl(ip_addr) & our_netmask) ==
67647+ (ntohl(our_addr) & our_netmask))
67648+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67649+ && (ip->type & (1U << type))) {
67650+ if (ip->mode & GR_INVERT)
67651+ return 2; // specifically denied
67652+ else
67653+ return 1; // allowed
67654+ }
67655+
67656+ return 0; // not specifically allowed, may continue parsing
67657+}
67658+
67659+static int
67660+gr_search_connectbind(const int full_mode, struct sock *sk,
67661+ struct sockaddr_in *addr, const int type)
67662+{
67663+ char iface[IFNAMSIZ] = {0};
67664+ struct acl_subject_label *curr;
67665+ struct acl_ip_label *ip;
67666+ struct inet_sock *isk;
67667+ struct net_device *dev;
67668+ struct in_device *idev;
67669+ unsigned long i;
67670+ int ret;
67671+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67672+ __u32 ip_addr = 0;
67673+ __u32 our_addr;
67674+ __u32 our_netmask;
67675+ char *p;
67676+ __u16 ip_port = 0;
67677+ const struct cred *cred = current_cred();
67678+
67679+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67680+ return 0;
67681+
67682+ curr = current->acl;
67683+ isk = inet_sk(sk);
67684+
67685+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67686+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67687+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67688+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67689+ struct sockaddr_in saddr;
67690+ int err;
67691+
67692+ saddr.sin_family = AF_INET;
67693+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67694+ saddr.sin_port = isk->inet_sport;
67695+
67696+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67697+ if (err)
67698+ return err;
67699+
67700+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67701+ if (err)
67702+ return err;
67703+ }
67704+
67705+ if (!curr->ips)
67706+ return 0;
67707+
67708+ ip_addr = addr->sin_addr.s_addr;
67709+ ip_port = ntohs(addr->sin_port);
67710+
67711+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67712+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67713+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67714+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67715+ gr_to_filename(current->exec_file->f_path.dentry,
67716+ current->exec_file->f_path.mnt) :
67717+ curr->filename, curr->filename,
67718+ &ip_addr, ip_port, type,
67719+ sk->sk_protocol, mode, &current->signal->saved_ip);
67720+ return 0;
67721+ }
67722+
67723+ for (i = 0; i < curr->ip_num; i++) {
67724+ ip = *(curr->ips + i);
67725+ if (ip->iface != NULL) {
67726+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67727+ p = strchr(iface, ':');
67728+ if (p != NULL)
67729+ *p = '\0';
67730+ dev = dev_get_by_name(sock_net(sk), iface);
67731+ if (dev == NULL)
67732+ continue;
67733+ idev = in_dev_get(dev);
67734+ if (idev == NULL) {
67735+ dev_put(dev);
67736+ continue;
67737+ }
67738+ rcu_read_lock();
67739+ for_ifa(idev) {
67740+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67741+ our_addr = ifa->ifa_address;
67742+ our_netmask = 0xffffffff;
67743+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67744+ if (ret == 1) {
67745+ rcu_read_unlock();
67746+ in_dev_put(idev);
67747+ dev_put(dev);
67748+ return 0;
67749+ } else if (ret == 2) {
67750+ rcu_read_unlock();
67751+ in_dev_put(idev);
67752+ dev_put(dev);
67753+ goto denied;
67754+ }
67755+ }
67756+ } endfor_ifa(idev);
67757+ rcu_read_unlock();
67758+ in_dev_put(idev);
67759+ dev_put(dev);
67760+ } else {
67761+ our_addr = ip->addr;
67762+ our_netmask = ip->netmask;
67763+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67764+ if (ret == 1)
67765+ return 0;
67766+ else if (ret == 2)
67767+ goto denied;
67768+ }
67769+ }
67770+
67771+denied:
67772+ if (mode == GR_BIND)
67773+ 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));
67774+ else if (mode == GR_CONNECT)
67775+ 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));
67776+
67777+ return -EACCES;
67778+}
67779+
67780+int
67781+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67782+{
67783+ /* always allow disconnection of dgram sockets with connect */
67784+ if (addr->sin_family == AF_UNSPEC)
67785+ return 0;
67786+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67787+}
67788+
67789+int
67790+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67791+{
67792+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67793+}
67794+
67795+int gr_search_listen(struct socket *sock)
67796+{
67797+ struct sock *sk = sock->sk;
67798+ struct sockaddr_in addr;
67799+
67800+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67801+ addr.sin_port = inet_sk(sk)->inet_sport;
67802+
67803+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67804+}
67805+
67806+int gr_search_accept(struct socket *sock)
67807+{
67808+ struct sock *sk = sock->sk;
67809+ struct sockaddr_in addr;
67810+
67811+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67812+ addr.sin_port = inet_sk(sk)->inet_sport;
67813+
67814+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67815+}
67816+
67817+int
67818+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67819+{
67820+ if (addr)
67821+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67822+ else {
67823+ struct sockaddr_in sin;
67824+ const struct inet_sock *inet = inet_sk(sk);
67825+
67826+ sin.sin_addr.s_addr = inet->inet_daddr;
67827+ sin.sin_port = inet->inet_dport;
67828+
67829+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67830+ }
67831+}
67832+
67833+int
67834+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67835+{
67836+ struct sockaddr_in sin;
67837+
67838+ if (unlikely(skb->len < sizeof (struct udphdr)))
67839+ return 0; // skip this packet
67840+
67841+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67842+ sin.sin_port = udp_hdr(skb)->source;
67843+
67844+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67845+}
67846diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67847new file mode 100644
67848index 0000000..25f54ef
67849--- /dev/null
67850+++ b/grsecurity/gracl_learn.c
67851@@ -0,0 +1,207 @@
67852+#include <linux/kernel.h>
67853+#include <linux/mm.h>
67854+#include <linux/sched.h>
67855+#include <linux/poll.h>
67856+#include <linux/string.h>
67857+#include <linux/file.h>
67858+#include <linux/types.h>
67859+#include <linux/vmalloc.h>
67860+#include <linux/grinternal.h>
67861+
67862+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67863+ size_t count, loff_t *ppos);
67864+extern int gr_acl_is_enabled(void);
67865+
67866+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67867+static int gr_learn_attached;
67868+
67869+/* use a 512k buffer */
67870+#define LEARN_BUFFER_SIZE (512 * 1024)
67871+
67872+static DEFINE_SPINLOCK(gr_learn_lock);
67873+static DEFINE_MUTEX(gr_learn_user_mutex);
67874+
67875+/* we need to maintain two buffers, so that the kernel context of grlearn
67876+ uses a semaphore around the userspace copying, and the other kernel contexts
67877+ use a spinlock when copying into the buffer, since they cannot sleep
67878+*/
67879+static char *learn_buffer;
67880+static char *learn_buffer_user;
67881+static int learn_buffer_len;
67882+static int learn_buffer_user_len;
67883+
67884+static ssize_t
67885+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67886+{
67887+ DECLARE_WAITQUEUE(wait, current);
67888+ ssize_t retval = 0;
67889+
67890+ add_wait_queue(&learn_wait, &wait);
67891+ set_current_state(TASK_INTERRUPTIBLE);
67892+ do {
67893+ mutex_lock(&gr_learn_user_mutex);
67894+ spin_lock(&gr_learn_lock);
67895+ if (learn_buffer_len)
67896+ break;
67897+ spin_unlock(&gr_learn_lock);
67898+ mutex_unlock(&gr_learn_user_mutex);
67899+ if (file->f_flags & O_NONBLOCK) {
67900+ retval = -EAGAIN;
67901+ goto out;
67902+ }
67903+ if (signal_pending(current)) {
67904+ retval = -ERESTARTSYS;
67905+ goto out;
67906+ }
67907+
67908+ schedule();
67909+ } while (1);
67910+
67911+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67912+ learn_buffer_user_len = learn_buffer_len;
67913+ retval = learn_buffer_len;
67914+ learn_buffer_len = 0;
67915+
67916+ spin_unlock(&gr_learn_lock);
67917+
67918+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67919+ retval = -EFAULT;
67920+
67921+ mutex_unlock(&gr_learn_user_mutex);
67922+out:
67923+ set_current_state(TASK_RUNNING);
67924+ remove_wait_queue(&learn_wait, &wait);
67925+ return retval;
67926+}
67927+
67928+static unsigned int
67929+poll_learn(struct file * file, poll_table * wait)
67930+{
67931+ poll_wait(file, &learn_wait, wait);
67932+
67933+ if (learn_buffer_len)
67934+ return (POLLIN | POLLRDNORM);
67935+
67936+ return 0;
67937+}
67938+
67939+void
67940+gr_clear_learn_entries(void)
67941+{
67942+ char *tmp;
67943+
67944+ mutex_lock(&gr_learn_user_mutex);
67945+ spin_lock(&gr_learn_lock);
67946+ tmp = learn_buffer;
67947+ learn_buffer = NULL;
67948+ spin_unlock(&gr_learn_lock);
67949+ if (tmp)
67950+ vfree(tmp);
67951+ if (learn_buffer_user != NULL) {
67952+ vfree(learn_buffer_user);
67953+ learn_buffer_user = NULL;
67954+ }
67955+ learn_buffer_len = 0;
67956+ mutex_unlock(&gr_learn_user_mutex);
67957+
67958+ return;
67959+}
67960+
67961+void
67962+gr_add_learn_entry(const char *fmt, ...)
67963+{
67964+ va_list args;
67965+ unsigned int len;
67966+
67967+ if (!gr_learn_attached)
67968+ return;
67969+
67970+ spin_lock(&gr_learn_lock);
67971+
67972+ /* leave a gap at the end so we know when it's "full" but don't have to
67973+ compute the exact length of the string we're trying to append
67974+ */
67975+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67976+ spin_unlock(&gr_learn_lock);
67977+ wake_up_interruptible(&learn_wait);
67978+ return;
67979+ }
67980+ if (learn_buffer == NULL) {
67981+ spin_unlock(&gr_learn_lock);
67982+ return;
67983+ }
67984+
67985+ va_start(args, fmt);
67986+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67987+ va_end(args);
67988+
67989+ learn_buffer_len += len + 1;
67990+
67991+ spin_unlock(&gr_learn_lock);
67992+ wake_up_interruptible(&learn_wait);
67993+
67994+ return;
67995+}
67996+
67997+static int
67998+open_learn(struct inode *inode, struct file *file)
67999+{
68000+ if (file->f_mode & FMODE_READ && gr_learn_attached)
68001+ return -EBUSY;
68002+ if (file->f_mode & FMODE_READ) {
68003+ int retval = 0;
68004+ mutex_lock(&gr_learn_user_mutex);
68005+ if (learn_buffer == NULL)
68006+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
68007+ if (learn_buffer_user == NULL)
68008+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
68009+ if (learn_buffer == NULL) {
68010+ retval = -ENOMEM;
68011+ goto out_error;
68012+ }
68013+ if (learn_buffer_user == NULL) {
68014+ retval = -ENOMEM;
68015+ goto out_error;
68016+ }
68017+ learn_buffer_len = 0;
68018+ learn_buffer_user_len = 0;
68019+ gr_learn_attached = 1;
68020+out_error:
68021+ mutex_unlock(&gr_learn_user_mutex);
68022+ return retval;
68023+ }
68024+ return 0;
68025+}
68026+
68027+static int
68028+close_learn(struct inode *inode, struct file *file)
68029+{
68030+ if (file->f_mode & FMODE_READ) {
68031+ char *tmp = NULL;
68032+ mutex_lock(&gr_learn_user_mutex);
68033+ spin_lock(&gr_learn_lock);
68034+ tmp = learn_buffer;
68035+ learn_buffer = NULL;
68036+ spin_unlock(&gr_learn_lock);
68037+ if (tmp)
68038+ vfree(tmp);
68039+ if (learn_buffer_user != NULL) {
68040+ vfree(learn_buffer_user);
68041+ learn_buffer_user = NULL;
68042+ }
68043+ learn_buffer_len = 0;
68044+ learn_buffer_user_len = 0;
68045+ gr_learn_attached = 0;
68046+ mutex_unlock(&gr_learn_user_mutex);
68047+ }
68048+
68049+ return 0;
68050+}
68051+
68052+const struct file_operations grsec_fops = {
68053+ .read = read_learn,
68054+ .write = write_grsec_handler,
68055+ .open = open_learn,
68056+ .release = close_learn,
68057+ .poll = poll_learn,
68058+};
68059diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
68060new file mode 100644
68061index 0000000..39645c9
68062--- /dev/null
68063+++ b/grsecurity/gracl_res.c
68064@@ -0,0 +1,68 @@
68065+#include <linux/kernel.h>
68066+#include <linux/sched.h>
68067+#include <linux/gracl.h>
68068+#include <linux/grinternal.h>
68069+
68070+static const char *restab_log[] = {
68071+ [RLIMIT_CPU] = "RLIMIT_CPU",
68072+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
68073+ [RLIMIT_DATA] = "RLIMIT_DATA",
68074+ [RLIMIT_STACK] = "RLIMIT_STACK",
68075+ [RLIMIT_CORE] = "RLIMIT_CORE",
68076+ [RLIMIT_RSS] = "RLIMIT_RSS",
68077+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
68078+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
68079+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
68080+ [RLIMIT_AS] = "RLIMIT_AS",
68081+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
68082+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
68083+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
68084+ [RLIMIT_NICE] = "RLIMIT_NICE",
68085+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
68086+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
68087+ [GR_CRASH_RES] = "RLIMIT_CRASH"
68088+};
68089+
68090+void
68091+gr_log_resource(const struct task_struct *task,
68092+ const int res, const unsigned long wanted, const int gt)
68093+{
68094+ const struct cred *cred;
68095+ unsigned long rlim;
68096+
68097+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
68098+ return;
68099+
68100+ // not yet supported resource
68101+ if (unlikely(!restab_log[res]))
68102+ return;
68103+
68104+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
68105+ rlim = task_rlimit_max(task, res);
68106+ else
68107+ rlim = task_rlimit(task, res);
68108+
68109+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
68110+ return;
68111+
68112+ rcu_read_lock();
68113+ cred = __task_cred(task);
68114+
68115+ if (res == RLIMIT_NPROC &&
68116+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
68117+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
68118+ goto out_rcu_unlock;
68119+ else if (res == RLIMIT_MEMLOCK &&
68120+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
68121+ goto out_rcu_unlock;
68122+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
68123+ goto out_rcu_unlock;
68124+ rcu_read_unlock();
68125+
68126+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
68127+
68128+ return;
68129+out_rcu_unlock:
68130+ rcu_read_unlock();
68131+ return;
68132+}
68133diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
68134new file mode 100644
68135index 0000000..3c38bfe
68136--- /dev/null
68137+++ b/grsecurity/gracl_segv.c
68138@@ -0,0 +1,305 @@
68139+#include <linux/kernel.h>
68140+#include <linux/mm.h>
68141+#include <asm/uaccess.h>
68142+#include <asm/errno.h>
68143+#include <asm/mman.h>
68144+#include <net/sock.h>
68145+#include <linux/file.h>
68146+#include <linux/fs.h>
68147+#include <linux/net.h>
68148+#include <linux/in.h>
68149+#include <linux/slab.h>
68150+#include <linux/types.h>
68151+#include <linux/sched.h>
68152+#include <linux/timer.h>
68153+#include <linux/gracl.h>
68154+#include <linux/grsecurity.h>
68155+#include <linux/grinternal.h>
68156+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68157+#include <linux/magic.h>
68158+#include <linux/pagemap.h>
68159+#include "../fs/btrfs/async-thread.h"
68160+#include "../fs/btrfs/ctree.h"
68161+#include "../fs/btrfs/btrfs_inode.h"
68162+#endif
68163+
68164+static struct crash_uid *uid_set;
68165+static unsigned short uid_used;
68166+static DEFINE_SPINLOCK(gr_uid_lock);
68167+extern rwlock_t gr_inode_lock;
68168+extern struct acl_subject_label *
68169+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68170+ struct acl_role_label *role);
68171+
68172+static inline dev_t __get_dev(const struct dentry *dentry)
68173+{
68174+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68175+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68176+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68177+ else
68178+#endif
68179+ return dentry->d_sb->s_dev;
68180+}
68181+
68182+int
68183+gr_init_uidset(void)
68184+{
68185+ uid_set =
68186+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68187+ uid_used = 0;
68188+
68189+ return uid_set ? 1 : 0;
68190+}
68191+
68192+void
68193+gr_free_uidset(void)
68194+{
68195+ if (uid_set)
68196+ kfree(uid_set);
68197+
68198+ return;
68199+}
68200+
68201+int
68202+gr_find_uid(const uid_t uid)
68203+{
68204+ struct crash_uid *tmp = uid_set;
68205+ uid_t buid;
68206+ int low = 0, high = uid_used - 1, mid;
68207+
68208+ while (high >= low) {
68209+ mid = (low + high) >> 1;
68210+ buid = tmp[mid].uid;
68211+ if (buid == uid)
68212+ return mid;
68213+ if (buid > uid)
68214+ high = mid - 1;
68215+ if (buid < uid)
68216+ low = mid + 1;
68217+ }
68218+
68219+ return -1;
68220+}
68221+
68222+static __inline__ void
68223+gr_insertsort(void)
68224+{
68225+ unsigned short i, j;
68226+ struct crash_uid index;
68227+
68228+ for (i = 1; i < uid_used; i++) {
68229+ index = uid_set[i];
68230+ j = i;
68231+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68232+ uid_set[j] = uid_set[j - 1];
68233+ j--;
68234+ }
68235+ uid_set[j] = index;
68236+ }
68237+
68238+ return;
68239+}
68240+
68241+static __inline__ void
68242+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68243+{
68244+ int loc;
68245+ uid_t uid = GR_GLOBAL_UID(kuid);
68246+
68247+ if (uid_used == GR_UIDTABLE_MAX)
68248+ return;
68249+
68250+ loc = gr_find_uid(uid);
68251+
68252+ if (loc >= 0) {
68253+ uid_set[loc].expires = expires;
68254+ return;
68255+ }
68256+
68257+ uid_set[uid_used].uid = uid;
68258+ uid_set[uid_used].expires = expires;
68259+ uid_used++;
68260+
68261+ gr_insertsort();
68262+
68263+ return;
68264+}
68265+
68266+void
68267+gr_remove_uid(const unsigned short loc)
68268+{
68269+ unsigned short i;
68270+
68271+ for (i = loc + 1; i < uid_used; i++)
68272+ uid_set[i - 1] = uid_set[i];
68273+
68274+ uid_used--;
68275+
68276+ return;
68277+}
68278+
68279+int
68280+gr_check_crash_uid(const kuid_t kuid)
68281+{
68282+ int loc;
68283+ int ret = 0;
68284+ uid_t uid;
68285+
68286+ if (unlikely(!gr_acl_is_enabled()))
68287+ return 0;
68288+
68289+ uid = GR_GLOBAL_UID(kuid);
68290+
68291+ spin_lock(&gr_uid_lock);
68292+ loc = gr_find_uid(uid);
68293+
68294+ if (loc < 0)
68295+ goto out_unlock;
68296+
68297+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68298+ gr_remove_uid(loc);
68299+ else
68300+ ret = 1;
68301+
68302+out_unlock:
68303+ spin_unlock(&gr_uid_lock);
68304+ return ret;
68305+}
68306+
68307+static __inline__ int
68308+proc_is_setxid(const struct cred *cred)
68309+{
68310+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68311+ !uid_eq(cred->uid, cred->fsuid))
68312+ return 1;
68313+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68314+ !gid_eq(cred->gid, cred->fsgid))
68315+ return 1;
68316+
68317+ return 0;
68318+}
68319+
68320+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68321+
68322+void
68323+gr_handle_crash(struct task_struct *task, const int sig)
68324+{
68325+ struct acl_subject_label *curr;
68326+ struct task_struct *tsk, *tsk2;
68327+ const struct cred *cred;
68328+ const struct cred *cred2;
68329+
68330+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68331+ return;
68332+
68333+ if (unlikely(!gr_acl_is_enabled()))
68334+ return;
68335+
68336+ curr = task->acl;
68337+
68338+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68339+ return;
68340+
68341+ if (time_before_eq(curr->expires, get_seconds())) {
68342+ curr->expires = 0;
68343+ curr->crashes = 0;
68344+ }
68345+
68346+ curr->crashes++;
68347+
68348+ if (!curr->expires)
68349+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68350+
68351+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68352+ time_after(curr->expires, get_seconds())) {
68353+ rcu_read_lock();
68354+ cred = __task_cred(task);
68355+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68356+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68357+ spin_lock(&gr_uid_lock);
68358+ gr_insert_uid(cred->uid, curr->expires);
68359+ spin_unlock(&gr_uid_lock);
68360+ curr->expires = 0;
68361+ curr->crashes = 0;
68362+ read_lock(&tasklist_lock);
68363+ do_each_thread(tsk2, tsk) {
68364+ cred2 = __task_cred(tsk);
68365+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68366+ gr_fake_force_sig(SIGKILL, tsk);
68367+ } while_each_thread(tsk2, tsk);
68368+ read_unlock(&tasklist_lock);
68369+ } else {
68370+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68371+ read_lock(&tasklist_lock);
68372+ read_lock(&grsec_exec_file_lock);
68373+ do_each_thread(tsk2, tsk) {
68374+ if (likely(tsk != task)) {
68375+ // if this thread has the same subject as the one that triggered
68376+ // RES_CRASH and it's the same binary, kill it
68377+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68378+ gr_fake_force_sig(SIGKILL, tsk);
68379+ }
68380+ } while_each_thread(tsk2, tsk);
68381+ read_unlock(&grsec_exec_file_lock);
68382+ read_unlock(&tasklist_lock);
68383+ }
68384+ rcu_read_unlock();
68385+ }
68386+
68387+ return;
68388+}
68389+
68390+int
68391+gr_check_crash_exec(const struct file *filp)
68392+{
68393+ struct acl_subject_label *curr;
68394+
68395+ if (unlikely(!gr_acl_is_enabled()))
68396+ return 0;
68397+
68398+ read_lock(&gr_inode_lock);
68399+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68400+ __get_dev(filp->f_path.dentry),
68401+ current->role);
68402+ read_unlock(&gr_inode_lock);
68403+
68404+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68405+ (!curr->crashes && !curr->expires))
68406+ return 0;
68407+
68408+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68409+ time_after(curr->expires, get_seconds()))
68410+ return 1;
68411+ else if (time_before_eq(curr->expires, get_seconds())) {
68412+ curr->crashes = 0;
68413+ curr->expires = 0;
68414+ }
68415+
68416+ return 0;
68417+}
68418+
68419+void
68420+gr_handle_alertkill(struct task_struct *task)
68421+{
68422+ struct acl_subject_label *curracl;
68423+ __u32 curr_ip;
68424+ struct task_struct *p, *p2;
68425+
68426+ if (unlikely(!gr_acl_is_enabled()))
68427+ return;
68428+
68429+ curracl = task->acl;
68430+ curr_ip = task->signal->curr_ip;
68431+
68432+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68433+ read_lock(&tasklist_lock);
68434+ do_each_thread(p2, p) {
68435+ if (p->signal->curr_ip == curr_ip)
68436+ gr_fake_force_sig(SIGKILL, p);
68437+ } while_each_thread(p2, p);
68438+ read_unlock(&tasklist_lock);
68439+ } else if (curracl->mode & GR_KILLPROC)
68440+ gr_fake_force_sig(SIGKILL, task);
68441+
68442+ return;
68443+}
68444diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68445new file mode 100644
68446index 0000000..98011b0
68447--- /dev/null
68448+++ b/grsecurity/gracl_shm.c
68449@@ -0,0 +1,40 @@
68450+#include <linux/kernel.h>
68451+#include <linux/mm.h>
68452+#include <linux/sched.h>
68453+#include <linux/file.h>
68454+#include <linux/ipc.h>
68455+#include <linux/gracl.h>
68456+#include <linux/grsecurity.h>
68457+#include <linux/grinternal.h>
68458+
68459+int
68460+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68461+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68462+{
68463+ struct task_struct *task;
68464+
68465+ if (!gr_acl_is_enabled())
68466+ return 1;
68467+
68468+ rcu_read_lock();
68469+ read_lock(&tasklist_lock);
68470+
68471+ task = find_task_by_vpid(shm_cprid);
68472+
68473+ if (unlikely(!task))
68474+ task = find_task_by_vpid(shm_lapid);
68475+
68476+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68477+ (task_pid_nr(task) == shm_lapid)) &&
68478+ (task->acl->mode & GR_PROTSHM) &&
68479+ (task->acl != current->acl))) {
68480+ read_unlock(&tasklist_lock);
68481+ rcu_read_unlock();
68482+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68483+ return 0;
68484+ }
68485+ read_unlock(&tasklist_lock);
68486+ rcu_read_unlock();
68487+
68488+ return 1;
68489+}
68490diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68491new file mode 100644
68492index 0000000..bc0be01
68493--- /dev/null
68494+++ b/grsecurity/grsec_chdir.c
68495@@ -0,0 +1,19 @@
68496+#include <linux/kernel.h>
68497+#include <linux/sched.h>
68498+#include <linux/fs.h>
68499+#include <linux/file.h>
68500+#include <linux/grsecurity.h>
68501+#include <linux/grinternal.h>
68502+
68503+void
68504+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68505+{
68506+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68507+ if ((grsec_enable_chdir && grsec_enable_group &&
68508+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68509+ !grsec_enable_group)) {
68510+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68511+ }
68512+#endif
68513+ return;
68514+}
68515diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68516new file mode 100644
68517index 0000000..bd6e105
68518--- /dev/null
68519+++ b/grsecurity/grsec_chroot.c
68520@@ -0,0 +1,370 @@
68521+#include <linux/kernel.h>
68522+#include <linux/module.h>
68523+#include <linux/sched.h>
68524+#include <linux/file.h>
68525+#include <linux/fs.h>
68526+#include <linux/mount.h>
68527+#include <linux/types.h>
68528+#include "../fs/mount.h"
68529+#include <linux/grsecurity.h>
68530+#include <linux/grinternal.h>
68531+
68532+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68533+static int gr_init_ran;
68534+#endif
68535+
68536+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68537+{
68538+#ifdef CONFIG_GRKERNSEC
68539+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68540+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68541+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68542+ && gr_init_ran
68543+#endif
68544+ )
68545+ task->gr_is_chrooted = 1;
68546+ else {
68547+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68548+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68549+ gr_init_ran = 1;
68550+#endif
68551+ task->gr_is_chrooted = 0;
68552+ }
68553+
68554+ task->gr_chroot_dentry = path->dentry;
68555+#endif
68556+ return;
68557+}
68558+
68559+void gr_clear_chroot_entries(struct task_struct *task)
68560+{
68561+#ifdef CONFIG_GRKERNSEC
68562+ task->gr_is_chrooted = 0;
68563+ task->gr_chroot_dentry = NULL;
68564+#endif
68565+ return;
68566+}
68567+
68568+int
68569+gr_handle_chroot_unix(const pid_t pid)
68570+{
68571+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68572+ struct task_struct *p;
68573+
68574+ if (unlikely(!grsec_enable_chroot_unix))
68575+ return 1;
68576+
68577+ if (likely(!proc_is_chrooted(current)))
68578+ return 1;
68579+
68580+ rcu_read_lock();
68581+ read_lock(&tasklist_lock);
68582+ p = find_task_by_vpid_unrestricted(pid);
68583+ if (unlikely(p && !have_same_root(current, p))) {
68584+ read_unlock(&tasklist_lock);
68585+ rcu_read_unlock();
68586+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68587+ return 0;
68588+ }
68589+ read_unlock(&tasklist_lock);
68590+ rcu_read_unlock();
68591+#endif
68592+ return 1;
68593+}
68594+
68595+int
68596+gr_handle_chroot_nice(void)
68597+{
68598+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68599+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68600+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68601+ return -EPERM;
68602+ }
68603+#endif
68604+ return 0;
68605+}
68606+
68607+int
68608+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68609+{
68610+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68611+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68612+ && proc_is_chrooted(current)) {
68613+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68614+ return -EACCES;
68615+ }
68616+#endif
68617+ return 0;
68618+}
68619+
68620+int
68621+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68622+{
68623+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68624+ struct task_struct *p;
68625+ int ret = 0;
68626+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68627+ return ret;
68628+
68629+ read_lock(&tasklist_lock);
68630+ do_each_pid_task(pid, type, p) {
68631+ if (!have_same_root(current, p)) {
68632+ ret = 1;
68633+ goto out;
68634+ }
68635+ } while_each_pid_task(pid, type, p);
68636+out:
68637+ read_unlock(&tasklist_lock);
68638+ return ret;
68639+#endif
68640+ return 0;
68641+}
68642+
68643+int
68644+gr_pid_is_chrooted(struct task_struct *p)
68645+{
68646+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68647+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68648+ return 0;
68649+
68650+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68651+ !have_same_root(current, p)) {
68652+ return 1;
68653+ }
68654+#endif
68655+ return 0;
68656+}
68657+
68658+EXPORT_SYMBOL(gr_pid_is_chrooted);
68659+
68660+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68661+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68662+{
68663+ struct path path, currentroot;
68664+ int ret = 0;
68665+
68666+ path.dentry = (struct dentry *)u_dentry;
68667+ path.mnt = (struct vfsmount *)u_mnt;
68668+ get_fs_root(current->fs, &currentroot);
68669+ if (path_is_under(&path, &currentroot))
68670+ ret = 1;
68671+ path_put(&currentroot);
68672+
68673+ return ret;
68674+}
68675+#endif
68676+
68677+int
68678+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68679+{
68680+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68681+ if (!grsec_enable_chroot_fchdir)
68682+ return 1;
68683+
68684+ if (!proc_is_chrooted(current))
68685+ return 1;
68686+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68687+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68688+ return 0;
68689+ }
68690+#endif
68691+ return 1;
68692+}
68693+
68694+int
68695+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68696+ const time_t shm_createtime)
68697+{
68698+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68699+ struct task_struct *p;
68700+ time_t starttime;
68701+
68702+ if (unlikely(!grsec_enable_chroot_shmat))
68703+ return 1;
68704+
68705+ if (likely(!proc_is_chrooted(current)))
68706+ return 1;
68707+
68708+ rcu_read_lock();
68709+ read_lock(&tasklist_lock);
68710+
68711+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68712+ starttime = p->start_time.tv_sec;
68713+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68714+ if (have_same_root(current, p)) {
68715+ goto allow;
68716+ } else {
68717+ read_unlock(&tasklist_lock);
68718+ rcu_read_unlock();
68719+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68720+ return 0;
68721+ }
68722+ }
68723+ /* creator exited, pid reuse, fall through to next check */
68724+ }
68725+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68726+ if (unlikely(!have_same_root(current, p))) {
68727+ read_unlock(&tasklist_lock);
68728+ rcu_read_unlock();
68729+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68730+ return 0;
68731+ }
68732+ }
68733+
68734+allow:
68735+ read_unlock(&tasklist_lock);
68736+ rcu_read_unlock();
68737+#endif
68738+ return 1;
68739+}
68740+
68741+void
68742+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68743+{
68744+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68745+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68746+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68747+#endif
68748+ return;
68749+}
68750+
68751+int
68752+gr_handle_chroot_mknod(const struct dentry *dentry,
68753+ const struct vfsmount *mnt, const int mode)
68754+{
68755+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68756+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68757+ proc_is_chrooted(current)) {
68758+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68759+ return -EPERM;
68760+ }
68761+#endif
68762+ return 0;
68763+}
68764+
68765+int
68766+gr_handle_chroot_mount(const struct dentry *dentry,
68767+ const struct vfsmount *mnt, const char *dev_name)
68768+{
68769+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68770+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68771+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68772+ return -EPERM;
68773+ }
68774+#endif
68775+ return 0;
68776+}
68777+
68778+int
68779+gr_handle_chroot_pivot(void)
68780+{
68781+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68782+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68783+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68784+ return -EPERM;
68785+ }
68786+#endif
68787+ return 0;
68788+}
68789+
68790+int
68791+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68792+{
68793+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68794+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68795+ !gr_is_outside_chroot(dentry, mnt)) {
68796+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68797+ return -EPERM;
68798+ }
68799+#endif
68800+ return 0;
68801+}
68802+
68803+extern const char *captab_log[];
68804+extern int captab_log_entries;
68805+
68806+int
68807+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68808+{
68809+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68810+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68811+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68812+ if (cap_raised(chroot_caps, cap)) {
68813+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68814+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68815+ }
68816+ return 0;
68817+ }
68818+ }
68819+#endif
68820+ return 1;
68821+}
68822+
68823+int
68824+gr_chroot_is_capable(const int cap)
68825+{
68826+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68827+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68828+#endif
68829+ return 1;
68830+}
68831+
68832+int
68833+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68834+{
68835+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68836+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68837+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68838+ if (cap_raised(chroot_caps, cap)) {
68839+ return 0;
68840+ }
68841+ }
68842+#endif
68843+ return 1;
68844+}
68845+
68846+int
68847+gr_chroot_is_capable_nolog(const int cap)
68848+{
68849+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68850+ return gr_task_chroot_is_capable_nolog(current, cap);
68851+#endif
68852+ return 1;
68853+}
68854+
68855+int
68856+gr_handle_chroot_sysctl(const int op)
68857+{
68858+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68859+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68860+ proc_is_chrooted(current))
68861+ return -EACCES;
68862+#endif
68863+ return 0;
68864+}
68865+
68866+void
68867+gr_handle_chroot_chdir(const struct path *path)
68868+{
68869+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68870+ if (grsec_enable_chroot_chdir)
68871+ set_fs_pwd(current->fs, path);
68872+#endif
68873+ return;
68874+}
68875+
68876+int
68877+gr_handle_chroot_chmod(const struct dentry *dentry,
68878+ const struct vfsmount *mnt, const int mode)
68879+{
68880+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68881+ /* allow chmod +s on directories, but not files */
68882+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68883+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68884+ proc_is_chrooted(current)) {
68885+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68886+ return -EPERM;
68887+ }
68888+#endif
68889+ return 0;
68890+}
68891diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68892new file mode 100644
68893index 0000000..ce65ceb
68894--- /dev/null
68895+++ b/grsecurity/grsec_disabled.c
68896@@ -0,0 +1,434 @@
68897+#include <linux/kernel.h>
68898+#include <linux/module.h>
68899+#include <linux/sched.h>
68900+#include <linux/file.h>
68901+#include <linux/fs.h>
68902+#include <linux/kdev_t.h>
68903+#include <linux/net.h>
68904+#include <linux/in.h>
68905+#include <linux/ip.h>
68906+#include <linux/skbuff.h>
68907+#include <linux/sysctl.h>
68908+
68909+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68910+void
68911+pax_set_initial_flags(struct linux_binprm *bprm)
68912+{
68913+ return;
68914+}
68915+#endif
68916+
68917+#ifdef CONFIG_SYSCTL
68918+__u32
68919+gr_handle_sysctl(const struct ctl_table * table, const int op)
68920+{
68921+ return 0;
68922+}
68923+#endif
68924+
68925+#ifdef CONFIG_TASKSTATS
68926+int gr_is_taskstats_denied(int pid)
68927+{
68928+ return 0;
68929+}
68930+#endif
68931+
68932+int
68933+gr_acl_is_enabled(void)
68934+{
68935+ return 0;
68936+}
68937+
68938+void
68939+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68940+{
68941+ return;
68942+}
68943+
68944+int
68945+gr_handle_rawio(const struct inode *inode)
68946+{
68947+ return 0;
68948+}
68949+
68950+void
68951+gr_acl_handle_psacct(struct task_struct *task, const long code)
68952+{
68953+ return;
68954+}
68955+
68956+int
68957+gr_handle_ptrace(struct task_struct *task, const long request)
68958+{
68959+ return 0;
68960+}
68961+
68962+int
68963+gr_handle_proc_ptrace(struct task_struct *task)
68964+{
68965+ return 0;
68966+}
68967+
68968+int
68969+gr_set_acls(const int type)
68970+{
68971+ return 0;
68972+}
68973+
68974+int
68975+gr_check_hidden_task(const struct task_struct *tsk)
68976+{
68977+ return 0;
68978+}
68979+
68980+int
68981+gr_check_protected_task(const struct task_struct *task)
68982+{
68983+ return 0;
68984+}
68985+
68986+int
68987+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68988+{
68989+ return 0;
68990+}
68991+
68992+void
68993+gr_copy_label(struct task_struct *tsk)
68994+{
68995+ return;
68996+}
68997+
68998+void
68999+gr_set_pax_flags(struct task_struct *task)
69000+{
69001+ return;
69002+}
69003+
69004+int
69005+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69006+ const int unsafe_share)
69007+{
69008+ return 0;
69009+}
69010+
69011+void
69012+gr_handle_delete(const ino_t ino, const dev_t dev)
69013+{
69014+ return;
69015+}
69016+
69017+void
69018+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69019+{
69020+ return;
69021+}
69022+
69023+void
69024+gr_handle_crash(struct task_struct *task, const int sig)
69025+{
69026+ return;
69027+}
69028+
69029+int
69030+gr_check_crash_exec(const struct file *filp)
69031+{
69032+ return 0;
69033+}
69034+
69035+int
69036+gr_check_crash_uid(const kuid_t uid)
69037+{
69038+ return 0;
69039+}
69040+
69041+void
69042+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69043+ struct dentry *old_dentry,
69044+ struct dentry *new_dentry,
69045+ struct vfsmount *mnt, const __u8 replace)
69046+{
69047+ return;
69048+}
69049+
69050+int
69051+gr_search_socket(const int family, const int type, const int protocol)
69052+{
69053+ return 1;
69054+}
69055+
69056+int
69057+gr_search_connectbind(const int mode, const struct socket *sock,
69058+ const struct sockaddr_in *addr)
69059+{
69060+ return 0;
69061+}
69062+
69063+void
69064+gr_handle_alertkill(struct task_struct *task)
69065+{
69066+ return;
69067+}
69068+
69069+__u32
69070+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
69071+{
69072+ return 1;
69073+}
69074+
69075+__u32
69076+gr_acl_handle_hidden_file(const struct dentry * dentry,
69077+ const struct vfsmount * mnt)
69078+{
69079+ return 1;
69080+}
69081+
69082+__u32
69083+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69084+ int acc_mode)
69085+{
69086+ return 1;
69087+}
69088+
69089+__u32
69090+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69091+{
69092+ return 1;
69093+}
69094+
69095+__u32
69096+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
69097+{
69098+ return 1;
69099+}
69100+
69101+int
69102+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
69103+ unsigned int *vm_flags)
69104+{
69105+ return 1;
69106+}
69107+
69108+__u32
69109+gr_acl_handle_truncate(const struct dentry * dentry,
69110+ const struct vfsmount * mnt)
69111+{
69112+ return 1;
69113+}
69114+
69115+__u32
69116+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
69117+{
69118+ return 1;
69119+}
69120+
69121+__u32
69122+gr_acl_handle_access(const struct dentry * dentry,
69123+ const struct vfsmount * mnt, const int fmode)
69124+{
69125+ return 1;
69126+}
69127+
69128+__u32
69129+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
69130+ umode_t *mode)
69131+{
69132+ return 1;
69133+}
69134+
69135+__u32
69136+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
69137+{
69138+ return 1;
69139+}
69140+
69141+__u32
69142+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69143+{
69144+ return 1;
69145+}
69146+
69147+void
69148+grsecurity_init(void)
69149+{
69150+ return;
69151+}
69152+
69153+umode_t gr_acl_umask(void)
69154+{
69155+ return 0;
69156+}
69157+
69158+__u32
69159+gr_acl_handle_mknod(const struct dentry * new_dentry,
69160+ const struct dentry * parent_dentry,
69161+ const struct vfsmount * parent_mnt,
69162+ const int mode)
69163+{
69164+ return 1;
69165+}
69166+
69167+__u32
69168+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69169+ const struct dentry * parent_dentry,
69170+ const struct vfsmount * parent_mnt)
69171+{
69172+ return 1;
69173+}
69174+
69175+__u32
69176+gr_acl_handle_symlink(const struct dentry * new_dentry,
69177+ const struct dentry * parent_dentry,
69178+ const struct vfsmount * parent_mnt, const struct filename *from)
69179+{
69180+ return 1;
69181+}
69182+
69183+__u32
69184+gr_acl_handle_link(const struct dentry * new_dentry,
69185+ const struct dentry * parent_dentry,
69186+ const struct vfsmount * parent_mnt,
69187+ const struct dentry * old_dentry,
69188+ const struct vfsmount * old_mnt, const struct filename *to)
69189+{
69190+ return 1;
69191+}
69192+
69193+int
69194+gr_acl_handle_rename(const struct dentry *new_dentry,
69195+ const struct dentry *parent_dentry,
69196+ const struct vfsmount *parent_mnt,
69197+ const struct dentry *old_dentry,
69198+ const struct inode *old_parent_inode,
69199+ const struct vfsmount *old_mnt, const struct filename *newname)
69200+{
69201+ return 0;
69202+}
69203+
69204+int
69205+gr_acl_handle_filldir(const struct file *file, const char *name,
69206+ const int namelen, const ino_t ino)
69207+{
69208+ return 1;
69209+}
69210+
69211+int
69212+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69213+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69214+{
69215+ return 1;
69216+}
69217+
69218+int
69219+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69220+{
69221+ return 0;
69222+}
69223+
69224+int
69225+gr_search_accept(const struct socket *sock)
69226+{
69227+ return 0;
69228+}
69229+
69230+int
69231+gr_search_listen(const struct socket *sock)
69232+{
69233+ return 0;
69234+}
69235+
69236+int
69237+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69238+{
69239+ return 0;
69240+}
69241+
69242+__u32
69243+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69244+{
69245+ return 1;
69246+}
69247+
69248+__u32
69249+gr_acl_handle_creat(const struct dentry * dentry,
69250+ const struct dentry * p_dentry,
69251+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69252+ const int imode)
69253+{
69254+ return 1;
69255+}
69256+
69257+void
69258+gr_acl_handle_exit(void)
69259+{
69260+ return;
69261+}
69262+
69263+int
69264+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69265+{
69266+ return 1;
69267+}
69268+
69269+void
69270+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69271+{
69272+ return;
69273+}
69274+
69275+int
69276+gr_acl_handle_procpidmem(const struct task_struct *task)
69277+{
69278+ return 0;
69279+}
69280+
69281+int
69282+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69283+{
69284+ return 0;
69285+}
69286+
69287+int
69288+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69289+{
69290+ return 0;
69291+}
69292+
69293+void
69294+gr_set_kernel_label(struct task_struct *task)
69295+{
69296+ return;
69297+}
69298+
69299+int
69300+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69301+{
69302+ return 0;
69303+}
69304+
69305+int
69306+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69307+{
69308+ return 0;
69309+}
69310+
69311+int gr_acl_enable_at_secure(void)
69312+{
69313+ return 0;
69314+}
69315+
69316+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69317+{
69318+ return dentry->d_sb->s_dev;
69319+}
69320+
69321+void gr_put_exec_file(struct task_struct *task)
69322+{
69323+ return;
69324+}
69325+
69326+EXPORT_SYMBOL(gr_set_kernel_label);
69327+#ifdef CONFIG_SECURITY
69328+EXPORT_SYMBOL(gr_check_user_change);
69329+EXPORT_SYMBOL(gr_check_group_change);
69330+#endif
69331diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69332new file mode 100644
69333index 0000000..387032b
69334--- /dev/null
69335+++ b/grsecurity/grsec_exec.c
69336@@ -0,0 +1,187 @@
69337+#include <linux/kernel.h>
69338+#include <linux/sched.h>
69339+#include <linux/file.h>
69340+#include <linux/binfmts.h>
69341+#include <linux/fs.h>
69342+#include <linux/types.h>
69343+#include <linux/grdefs.h>
69344+#include <linux/grsecurity.h>
69345+#include <linux/grinternal.h>
69346+#include <linux/capability.h>
69347+#include <linux/module.h>
69348+#include <linux/compat.h>
69349+
69350+#include <asm/uaccess.h>
69351+
69352+#ifdef CONFIG_GRKERNSEC_EXECLOG
69353+static char gr_exec_arg_buf[132];
69354+static DEFINE_MUTEX(gr_exec_arg_mutex);
69355+#endif
69356+
69357+struct user_arg_ptr {
69358+#ifdef CONFIG_COMPAT
69359+ bool is_compat;
69360+#endif
69361+ union {
69362+ const char __user *const __user *native;
69363+#ifdef CONFIG_COMPAT
69364+ const compat_uptr_t __user *compat;
69365+#endif
69366+ } ptr;
69367+};
69368+
69369+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69370+
69371+void
69372+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69373+{
69374+#ifdef CONFIG_GRKERNSEC_EXECLOG
69375+ char *grarg = gr_exec_arg_buf;
69376+ unsigned int i, x, execlen = 0;
69377+ char c;
69378+
69379+ if (!((grsec_enable_execlog && grsec_enable_group &&
69380+ in_group_p(grsec_audit_gid))
69381+ || (grsec_enable_execlog && !grsec_enable_group)))
69382+ return;
69383+
69384+ mutex_lock(&gr_exec_arg_mutex);
69385+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69386+
69387+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69388+ const char __user *p;
69389+ unsigned int len;
69390+
69391+ p = get_user_arg_ptr(argv, i);
69392+ if (IS_ERR(p))
69393+ goto log;
69394+
69395+ len = strnlen_user(p, 128 - execlen);
69396+ if (len > 128 - execlen)
69397+ len = 128 - execlen;
69398+ else if (len > 0)
69399+ len--;
69400+ if (copy_from_user(grarg + execlen, p, len))
69401+ goto log;
69402+
69403+ /* rewrite unprintable characters */
69404+ for (x = 0; x < len; x++) {
69405+ c = *(grarg + execlen + x);
69406+ if (c < 32 || c > 126)
69407+ *(grarg + execlen + x) = ' ';
69408+ }
69409+
69410+ execlen += len;
69411+ *(grarg + execlen) = ' ';
69412+ *(grarg + execlen + 1) = '\0';
69413+ execlen++;
69414+ }
69415+
69416+ log:
69417+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69418+ bprm->file->f_path.mnt, grarg);
69419+ mutex_unlock(&gr_exec_arg_mutex);
69420+#endif
69421+ return;
69422+}
69423+
69424+#ifdef CONFIG_GRKERNSEC
69425+extern int gr_acl_is_capable(const int cap);
69426+extern int gr_acl_is_capable_nolog(const int cap);
69427+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69428+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69429+extern int gr_chroot_is_capable(const int cap);
69430+extern int gr_chroot_is_capable_nolog(const int cap);
69431+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69432+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69433+#endif
69434+
69435+const char *captab_log[] = {
69436+ "CAP_CHOWN",
69437+ "CAP_DAC_OVERRIDE",
69438+ "CAP_DAC_READ_SEARCH",
69439+ "CAP_FOWNER",
69440+ "CAP_FSETID",
69441+ "CAP_KILL",
69442+ "CAP_SETGID",
69443+ "CAP_SETUID",
69444+ "CAP_SETPCAP",
69445+ "CAP_LINUX_IMMUTABLE",
69446+ "CAP_NET_BIND_SERVICE",
69447+ "CAP_NET_BROADCAST",
69448+ "CAP_NET_ADMIN",
69449+ "CAP_NET_RAW",
69450+ "CAP_IPC_LOCK",
69451+ "CAP_IPC_OWNER",
69452+ "CAP_SYS_MODULE",
69453+ "CAP_SYS_RAWIO",
69454+ "CAP_SYS_CHROOT",
69455+ "CAP_SYS_PTRACE",
69456+ "CAP_SYS_PACCT",
69457+ "CAP_SYS_ADMIN",
69458+ "CAP_SYS_BOOT",
69459+ "CAP_SYS_NICE",
69460+ "CAP_SYS_RESOURCE",
69461+ "CAP_SYS_TIME",
69462+ "CAP_SYS_TTY_CONFIG",
69463+ "CAP_MKNOD",
69464+ "CAP_LEASE",
69465+ "CAP_AUDIT_WRITE",
69466+ "CAP_AUDIT_CONTROL",
69467+ "CAP_SETFCAP",
69468+ "CAP_MAC_OVERRIDE",
69469+ "CAP_MAC_ADMIN",
69470+ "CAP_SYSLOG",
69471+ "CAP_WAKE_ALARM"
69472+};
69473+
69474+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69475+
69476+int gr_is_capable(const int cap)
69477+{
69478+#ifdef CONFIG_GRKERNSEC
69479+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69480+ return 1;
69481+ return 0;
69482+#else
69483+ return 1;
69484+#endif
69485+}
69486+
69487+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69488+{
69489+#ifdef CONFIG_GRKERNSEC
69490+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69491+ return 1;
69492+ return 0;
69493+#else
69494+ return 1;
69495+#endif
69496+}
69497+
69498+int gr_is_capable_nolog(const int cap)
69499+{
69500+#ifdef CONFIG_GRKERNSEC
69501+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69502+ return 1;
69503+ return 0;
69504+#else
69505+ return 1;
69506+#endif
69507+}
69508+
69509+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69510+{
69511+#ifdef CONFIG_GRKERNSEC
69512+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69513+ return 1;
69514+ return 0;
69515+#else
69516+ return 1;
69517+#endif
69518+}
69519+
69520+EXPORT_SYMBOL(gr_is_capable);
69521+EXPORT_SYMBOL(gr_is_capable_nolog);
69522+EXPORT_SYMBOL(gr_task_is_capable);
69523+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69524diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69525new file mode 100644
69526index 0000000..06cc6ea
69527--- /dev/null
69528+++ b/grsecurity/grsec_fifo.c
69529@@ -0,0 +1,24 @@
69530+#include <linux/kernel.h>
69531+#include <linux/sched.h>
69532+#include <linux/fs.h>
69533+#include <linux/file.h>
69534+#include <linux/grinternal.h>
69535+
69536+int
69537+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69538+ const struct dentry *dir, const int flag, const int acc_mode)
69539+{
69540+#ifdef CONFIG_GRKERNSEC_FIFO
69541+ const struct cred *cred = current_cred();
69542+
69543+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69544+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69545+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69546+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69547+ if (!inode_permission(dentry->d_inode, acc_mode))
69548+ 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));
69549+ return -EACCES;
69550+ }
69551+#endif
69552+ return 0;
69553+}
69554diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69555new file mode 100644
69556index 0000000..8ca18bf
69557--- /dev/null
69558+++ b/grsecurity/grsec_fork.c
69559@@ -0,0 +1,23 @@
69560+#include <linux/kernel.h>
69561+#include <linux/sched.h>
69562+#include <linux/grsecurity.h>
69563+#include <linux/grinternal.h>
69564+#include <linux/errno.h>
69565+
69566+void
69567+gr_log_forkfail(const int retval)
69568+{
69569+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69570+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69571+ switch (retval) {
69572+ case -EAGAIN:
69573+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69574+ break;
69575+ case -ENOMEM:
69576+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69577+ break;
69578+ }
69579+ }
69580+#endif
69581+ return;
69582+}
69583diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69584new file mode 100644
69585index 0000000..99a0cb9
69586--- /dev/null
69587+++ b/grsecurity/grsec_init.c
69588@@ -0,0 +1,283 @@
69589+#include <linux/kernel.h>
69590+#include <linux/sched.h>
69591+#include <linux/mm.h>
69592+#include <linux/gracl.h>
69593+#include <linux/slab.h>
69594+#include <linux/vmalloc.h>
69595+#include <linux/percpu.h>
69596+#include <linux/module.h>
69597+
69598+int grsec_enable_ptrace_readexec;
69599+int grsec_enable_setxid;
69600+int grsec_enable_symlinkown;
69601+kgid_t grsec_symlinkown_gid;
69602+int grsec_enable_brute;
69603+int grsec_enable_link;
69604+int grsec_enable_dmesg;
69605+int grsec_enable_harden_ptrace;
69606+int grsec_enable_fifo;
69607+int grsec_enable_execlog;
69608+int grsec_enable_signal;
69609+int grsec_enable_forkfail;
69610+int grsec_enable_audit_ptrace;
69611+int grsec_enable_time;
69612+int grsec_enable_group;
69613+kgid_t grsec_audit_gid;
69614+int grsec_enable_chdir;
69615+int grsec_enable_mount;
69616+int grsec_enable_rofs;
69617+int grsec_deny_new_usb;
69618+int grsec_enable_chroot_findtask;
69619+int grsec_enable_chroot_mount;
69620+int grsec_enable_chroot_shmat;
69621+int grsec_enable_chroot_fchdir;
69622+int grsec_enable_chroot_double;
69623+int grsec_enable_chroot_pivot;
69624+int grsec_enable_chroot_chdir;
69625+int grsec_enable_chroot_chmod;
69626+int grsec_enable_chroot_mknod;
69627+int grsec_enable_chroot_nice;
69628+int grsec_enable_chroot_execlog;
69629+int grsec_enable_chroot_caps;
69630+int grsec_enable_chroot_sysctl;
69631+int grsec_enable_chroot_unix;
69632+int grsec_enable_tpe;
69633+kgid_t grsec_tpe_gid;
69634+int grsec_enable_blackhole;
69635+#ifdef CONFIG_IPV6_MODULE
69636+EXPORT_SYMBOL(grsec_enable_blackhole);
69637+#endif
69638+int grsec_lastack_retries;
69639+int grsec_enable_tpe_all;
69640+int grsec_enable_tpe_invert;
69641+int grsec_enable_socket_all;
69642+kgid_t grsec_socket_all_gid;
69643+int grsec_enable_socket_client;
69644+kgid_t grsec_socket_client_gid;
69645+int grsec_enable_socket_server;
69646+kgid_t grsec_socket_server_gid;
69647+int grsec_resource_logging;
69648+int grsec_disable_privio;
69649+int grsec_enable_log_rwxmaps;
69650+int grsec_lock;
69651+
69652+DEFINE_SPINLOCK(grsec_alert_lock);
69653+unsigned long grsec_alert_wtime = 0;
69654+unsigned long grsec_alert_fyet = 0;
69655+
69656+DEFINE_SPINLOCK(grsec_audit_lock);
69657+
69658+DEFINE_RWLOCK(grsec_exec_file_lock);
69659+
69660+char *gr_shared_page[4];
69661+
69662+char *gr_alert_log_fmt;
69663+char *gr_audit_log_fmt;
69664+char *gr_alert_log_buf;
69665+char *gr_audit_log_buf;
69666+
69667+extern struct gr_arg *gr_usermode;
69668+extern unsigned char *gr_system_salt;
69669+extern unsigned char *gr_system_sum;
69670+
69671+void __init
69672+grsecurity_init(void)
69673+{
69674+ int j;
69675+ /* create the per-cpu shared pages */
69676+
69677+#ifdef CONFIG_X86
69678+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69679+#endif
69680+
69681+ for (j = 0; j < 4; j++) {
69682+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69683+ if (gr_shared_page[j] == NULL) {
69684+ panic("Unable to allocate grsecurity shared page");
69685+ return;
69686+ }
69687+ }
69688+
69689+ /* allocate log buffers */
69690+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69691+ if (!gr_alert_log_fmt) {
69692+ panic("Unable to allocate grsecurity alert log format buffer");
69693+ return;
69694+ }
69695+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69696+ if (!gr_audit_log_fmt) {
69697+ panic("Unable to allocate grsecurity audit log format buffer");
69698+ return;
69699+ }
69700+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69701+ if (!gr_alert_log_buf) {
69702+ panic("Unable to allocate grsecurity alert log buffer");
69703+ return;
69704+ }
69705+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69706+ if (!gr_audit_log_buf) {
69707+ panic("Unable to allocate grsecurity audit log buffer");
69708+ return;
69709+ }
69710+
69711+ /* allocate memory for authentication structure */
69712+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69713+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69714+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69715+
69716+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69717+ panic("Unable to allocate grsecurity authentication structure");
69718+ return;
69719+ }
69720+
69721+
69722+#ifdef CONFIG_GRKERNSEC_IO
69723+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69724+ grsec_disable_privio = 1;
69725+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69726+ grsec_disable_privio = 1;
69727+#else
69728+ grsec_disable_privio = 0;
69729+#endif
69730+#endif
69731+
69732+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69733+ /* for backward compatibility, tpe_invert always defaults to on if
69734+ enabled in the kernel
69735+ */
69736+ grsec_enable_tpe_invert = 1;
69737+#endif
69738+
69739+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69740+#ifndef CONFIG_GRKERNSEC_SYSCTL
69741+ grsec_lock = 1;
69742+#endif
69743+
69744+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69745+ grsec_enable_log_rwxmaps = 1;
69746+#endif
69747+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69748+ grsec_enable_group = 1;
69749+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69750+#endif
69751+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69752+ grsec_enable_ptrace_readexec = 1;
69753+#endif
69754+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69755+ grsec_enable_chdir = 1;
69756+#endif
69757+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69758+ grsec_enable_harden_ptrace = 1;
69759+#endif
69760+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69761+ grsec_enable_mount = 1;
69762+#endif
69763+#ifdef CONFIG_GRKERNSEC_LINK
69764+ grsec_enable_link = 1;
69765+#endif
69766+#ifdef CONFIG_GRKERNSEC_BRUTE
69767+ grsec_enable_brute = 1;
69768+#endif
69769+#ifdef CONFIG_GRKERNSEC_DMESG
69770+ grsec_enable_dmesg = 1;
69771+#endif
69772+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69773+ grsec_enable_blackhole = 1;
69774+ grsec_lastack_retries = 4;
69775+#endif
69776+#ifdef CONFIG_GRKERNSEC_FIFO
69777+ grsec_enable_fifo = 1;
69778+#endif
69779+#ifdef CONFIG_GRKERNSEC_EXECLOG
69780+ grsec_enable_execlog = 1;
69781+#endif
69782+#ifdef CONFIG_GRKERNSEC_SETXID
69783+ grsec_enable_setxid = 1;
69784+#endif
69785+#ifdef CONFIG_GRKERNSEC_SIGNAL
69786+ grsec_enable_signal = 1;
69787+#endif
69788+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69789+ grsec_enable_forkfail = 1;
69790+#endif
69791+#ifdef CONFIG_GRKERNSEC_TIME
69792+ grsec_enable_time = 1;
69793+#endif
69794+#ifdef CONFIG_GRKERNSEC_RESLOG
69795+ grsec_resource_logging = 1;
69796+#endif
69797+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69798+ grsec_enable_chroot_findtask = 1;
69799+#endif
69800+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69801+ grsec_enable_chroot_unix = 1;
69802+#endif
69803+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69804+ grsec_enable_chroot_mount = 1;
69805+#endif
69806+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69807+ grsec_enable_chroot_fchdir = 1;
69808+#endif
69809+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69810+ grsec_enable_chroot_shmat = 1;
69811+#endif
69812+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69813+ grsec_enable_audit_ptrace = 1;
69814+#endif
69815+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69816+ grsec_enable_chroot_double = 1;
69817+#endif
69818+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69819+ grsec_enable_chroot_pivot = 1;
69820+#endif
69821+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69822+ grsec_enable_chroot_chdir = 1;
69823+#endif
69824+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69825+ grsec_enable_chroot_chmod = 1;
69826+#endif
69827+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69828+ grsec_enable_chroot_mknod = 1;
69829+#endif
69830+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69831+ grsec_enable_chroot_nice = 1;
69832+#endif
69833+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69834+ grsec_enable_chroot_execlog = 1;
69835+#endif
69836+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69837+ grsec_enable_chroot_caps = 1;
69838+#endif
69839+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69840+ grsec_enable_chroot_sysctl = 1;
69841+#endif
69842+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69843+ grsec_enable_symlinkown = 1;
69844+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69845+#endif
69846+#ifdef CONFIG_GRKERNSEC_TPE
69847+ grsec_enable_tpe = 1;
69848+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69849+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69850+ grsec_enable_tpe_all = 1;
69851+#endif
69852+#endif
69853+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69854+ grsec_enable_socket_all = 1;
69855+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69856+#endif
69857+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69858+ grsec_enable_socket_client = 1;
69859+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69860+#endif
69861+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69862+ grsec_enable_socket_server = 1;
69863+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69864+#endif
69865+#endif
69866+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69867+ grsec_deny_new_usb = 1;
69868+#endif
69869+
69870+ return;
69871+}
69872diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69873new file mode 100644
69874index 0000000..5e05e20
69875--- /dev/null
69876+++ b/grsecurity/grsec_link.c
69877@@ -0,0 +1,58 @@
69878+#include <linux/kernel.h>
69879+#include <linux/sched.h>
69880+#include <linux/fs.h>
69881+#include <linux/file.h>
69882+#include <linux/grinternal.h>
69883+
69884+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69885+{
69886+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69887+ const struct inode *link_inode = link->dentry->d_inode;
69888+
69889+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69890+ /* ignore root-owned links, e.g. /proc/self */
69891+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69892+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69893+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69894+ return 1;
69895+ }
69896+#endif
69897+ return 0;
69898+}
69899+
69900+int
69901+gr_handle_follow_link(const struct inode *parent,
69902+ const struct inode *inode,
69903+ const struct dentry *dentry, const struct vfsmount *mnt)
69904+{
69905+#ifdef CONFIG_GRKERNSEC_LINK
69906+ const struct cred *cred = current_cred();
69907+
69908+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69909+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69910+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69911+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69912+ return -EACCES;
69913+ }
69914+#endif
69915+ return 0;
69916+}
69917+
69918+int
69919+gr_handle_hardlink(const struct dentry *dentry,
69920+ const struct vfsmount *mnt,
69921+ struct inode *inode, const int mode, const struct filename *to)
69922+{
69923+#ifdef CONFIG_GRKERNSEC_LINK
69924+ const struct cred *cred = current_cred();
69925+
69926+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69927+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69928+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69929+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69930+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69931+ return -EPERM;
69932+ }
69933+#endif
69934+ return 0;
69935+}
69936diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69937new file mode 100644
69938index 0000000..dbe0a6b
69939--- /dev/null
69940+++ b/grsecurity/grsec_log.c
69941@@ -0,0 +1,341 @@
69942+#include <linux/kernel.h>
69943+#include <linux/sched.h>
69944+#include <linux/file.h>
69945+#include <linux/tty.h>
69946+#include <linux/fs.h>
69947+#include <linux/mm.h>
69948+#include <linux/grinternal.h>
69949+
69950+#ifdef CONFIG_TREE_PREEMPT_RCU
69951+#define DISABLE_PREEMPT() preempt_disable()
69952+#define ENABLE_PREEMPT() preempt_enable()
69953+#else
69954+#define DISABLE_PREEMPT()
69955+#define ENABLE_PREEMPT()
69956+#endif
69957+
69958+#define BEGIN_LOCKS(x) \
69959+ DISABLE_PREEMPT(); \
69960+ rcu_read_lock(); \
69961+ read_lock(&tasklist_lock); \
69962+ read_lock(&grsec_exec_file_lock); \
69963+ if (x != GR_DO_AUDIT) \
69964+ spin_lock(&grsec_alert_lock); \
69965+ else \
69966+ spin_lock(&grsec_audit_lock)
69967+
69968+#define END_LOCKS(x) \
69969+ if (x != GR_DO_AUDIT) \
69970+ spin_unlock(&grsec_alert_lock); \
69971+ else \
69972+ spin_unlock(&grsec_audit_lock); \
69973+ read_unlock(&grsec_exec_file_lock); \
69974+ read_unlock(&tasklist_lock); \
69975+ rcu_read_unlock(); \
69976+ ENABLE_PREEMPT(); \
69977+ if (x == GR_DONT_AUDIT) \
69978+ gr_handle_alertkill(current)
69979+
69980+enum {
69981+ FLOODING,
69982+ NO_FLOODING
69983+};
69984+
69985+extern char *gr_alert_log_fmt;
69986+extern char *gr_audit_log_fmt;
69987+extern char *gr_alert_log_buf;
69988+extern char *gr_audit_log_buf;
69989+
69990+static int gr_log_start(int audit)
69991+{
69992+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69993+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69994+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69995+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69996+ unsigned long curr_secs = get_seconds();
69997+
69998+ if (audit == GR_DO_AUDIT)
69999+ goto set_fmt;
70000+
70001+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
70002+ grsec_alert_wtime = curr_secs;
70003+ grsec_alert_fyet = 0;
70004+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
70005+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
70006+ grsec_alert_fyet++;
70007+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
70008+ grsec_alert_wtime = curr_secs;
70009+ grsec_alert_fyet++;
70010+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
70011+ return FLOODING;
70012+ }
70013+ else return FLOODING;
70014+
70015+set_fmt:
70016+#endif
70017+ memset(buf, 0, PAGE_SIZE);
70018+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
70019+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
70020+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70021+ } else if (current->signal->curr_ip) {
70022+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
70023+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
70024+ } else if (gr_acl_is_enabled()) {
70025+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
70026+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70027+ } else {
70028+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
70029+ strcpy(buf, fmt);
70030+ }
70031+
70032+ return NO_FLOODING;
70033+}
70034+
70035+static void gr_log_middle(int audit, const char *msg, va_list ap)
70036+ __attribute__ ((format (printf, 2, 0)));
70037+
70038+static void gr_log_middle(int audit, const char *msg, va_list ap)
70039+{
70040+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70041+ unsigned int len = strlen(buf);
70042+
70043+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70044+
70045+ return;
70046+}
70047+
70048+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70049+ __attribute__ ((format (printf, 2, 3)));
70050+
70051+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70052+{
70053+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70054+ unsigned int len = strlen(buf);
70055+ va_list ap;
70056+
70057+ va_start(ap, msg);
70058+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70059+ va_end(ap);
70060+
70061+ return;
70062+}
70063+
70064+static void gr_log_end(int audit, int append_default)
70065+{
70066+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70067+ if (append_default) {
70068+ struct task_struct *task = current;
70069+ struct task_struct *parent = task->real_parent;
70070+ const struct cred *cred = __task_cred(task);
70071+ const struct cred *pcred = __task_cred(parent);
70072+ unsigned int len = strlen(buf);
70073+
70074+ 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));
70075+ }
70076+
70077+ printk("%s\n", buf);
70078+
70079+ return;
70080+}
70081+
70082+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
70083+{
70084+ int logtype;
70085+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
70086+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
70087+ void *voidptr = NULL;
70088+ int num1 = 0, num2 = 0;
70089+ unsigned long ulong1 = 0, ulong2 = 0;
70090+ struct dentry *dentry = NULL;
70091+ struct vfsmount *mnt = NULL;
70092+ struct file *file = NULL;
70093+ struct task_struct *task = NULL;
70094+ struct vm_area_struct *vma = NULL;
70095+ const struct cred *cred, *pcred;
70096+ va_list ap;
70097+
70098+ BEGIN_LOCKS(audit);
70099+ logtype = gr_log_start(audit);
70100+ if (logtype == FLOODING) {
70101+ END_LOCKS(audit);
70102+ return;
70103+ }
70104+ va_start(ap, argtypes);
70105+ switch (argtypes) {
70106+ case GR_TTYSNIFF:
70107+ task = va_arg(ap, struct task_struct *);
70108+ 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));
70109+ break;
70110+ case GR_SYSCTL_HIDDEN:
70111+ str1 = va_arg(ap, char *);
70112+ gr_log_middle_varargs(audit, msg, result, str1);
70113+ break;
70114+ case GR_RBAC:
70115+ dentry = va_arg(ap, struct dentry *);
70116+ mnt = va_arg(ap, struct vfsmount *);
70117+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
70118+ break;
70119+ case GR_RBAC_STR:
70120+ dentry = va_arg(ap, struct dentry *);
70121+ mnt = va_arg(ap, struct vfsmount *);
70122+ str1 = va_arg(ap, char *);
70123+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
70124+ break;
70125+ case GR_STR_RBAC:
70126+ str1 = va_arg(ap, char *);
70127+ dentry = va_arg(ap, struct dentry *);
70128+ mnt = va_arg(ap, struct vfsmount *);
70129+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
70130+ break;
70131+ case GR_RBAC_MODE2:
70132+ dentry = va_arg(ap, struct dentry *);
70133+ mnt = va_arg(ap, struct vfsmount *);
70134+ str1 = va_arg(ap, char *);
70135+ str2 = va_arg(ap, char *);
70136+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
70137+ break;
70138+ case GR_RBAC_MODE3:
70139+ dentry = va_arg(ap, struct dentry *);
70140+ mnt = va_arg(ap, struct vfsmount *);
70141+ str1 = va_arg(ap, char *);
70142+ str2 = va_arg(ap, char *);
70143+ str3 = va_arg(ap, char *);
70144+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70145+ break;
70146+ case GR_FILENAME:
70147+ dentry = va_arg(ap, struct dentry *);
70148+ mnt = va_arg(ap, struct vfsmount *);
70149+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70150+ break;
70151+ case GR_STR_FILENAME:
70152+ str1 = va_arg(ap, char *);
70153+ dentry = va_arg(ap, struct dentry *);
70154+ mnt = va_arg(ap, struct vfsmount *);
70155+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70156+ break;
70157+ case GR_FILENAME_STR:
70158+ dentry = va_arg(ap, struct dentry *);
70159+ mnt = va_arg(ap, struct vfsmount *);
70160+ str1 = va_arg(ap, char *);
70161+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70162+ break;
70163+ case GR_FILENAME_TWO_INT:
70164+ dentry = va_arg(ap, struct dentry *);
70165+ mnt = va_arg(ap, struct vfsmount *);
70166+ num1 = va_arg(ap, int);
70167+ num2 = va_arg(ap, int);
70168+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70169+ break;
70170+ case GR_FILENAME_TWO_INT_STR:
70171+ dentry = va_arg(ap, struct dentry *);
70172+ mnt = va_arg(ap, struct vfsmount *);
70173+ num1 = va_arg(ap, int);
70174+ num2 = va_arg(ap, int);
70175+ str1 = va_arg(ap, char *);
70176+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70177+ break;
70178+ case GR_TEXTREL:
70179+ file = va_arg(ap, struct file *);
70180+ ulong1 = va_arg(ap, unsigned long);
70181+ ulong2 = va_arg(ap, unsigned long);
70182+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70183+ break;
70184+ case GR_PTRACE:
70185+ task = va_arg(ap, struct task_struct *);
70186+ 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));
70187+ break;
70188+ case GR_RESOURCE:
70189+ task = va_arg(ap, struct task_struct *);
70190+ cred = __task_cred(task);
70191+ pcred = __task_cred(task->real_parent);
70192+ ulong1 = va_arg(ap, unsigned long);
70193+ str1 = va_arg(ap, char *);
70194+ ulong2 = va_arg(ap, unsigned long);
70195+ 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));
70196+ break;
70197+ case GR_CAP:
70198+ task = va_arg(ap, struct task_struct *);
70199+ cred = __task_cred(task);
70200+ pcred = __task_cred(task->real_parent);
70201+ str1 = va_arg(ap, char *);
70202+ 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));
70203+ break;
70204+ case GR_SIG:
70205+ str1 = va_arg(ap, char *);
70206+ voidptr = va_arg(ap, void *);
70207+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70208+ break;
70209+ case GR_SIG2:
70210+ task = va_arg(ap, struct task_struct *);
70211+ cred = __task_cred(task);
70212+ pcred = __task_cred(task->real_parent);
70213+ num1 = va_arg(ap, int);
70214+ 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));
70215+ break;
70216+ case GR_CRASH1:
70217+ task = va_arg(ap, struct task_struct *);
70218+ cred = __task_cred(task);
70219+ pcred = __task_cred(task->real_parent);
70220+ ulong1 = va_arg(ap, unsigned long);
70221+ 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);
70222+ break;
70223+ case GR_CRASH2:
70224+ task = va_arg(ap, struct task_struct *);
70225+ cred = __task_cred(task);
70226+ pcred = __task_cred(task->real_parent);
70227+ ulong1 = va_arg(ap, unsigned long);
70228+ 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);
70229+ break;
70230+ case GR_RWXMAP:
70231+ file = va_arg(ap, struct file *);
70232+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70233+ break;
70234+ case GR_RWXMAPVMA:
70235+ vma = va_arg(ap, struct vm_area_struct *);
70236+ if (vma->vm_file)
70237+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70238+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70239+ str1 = "<stack>";
70240+ else if (vma->vm_start <= current->mm->brk &&
70241+ vma->vm_end >= current->mm->start_brk)
70242+ str1 = "<heap>";
70243+ else
70244+ str1 = "<anonymous mapping>";
70245+ gr_log_middle_varargs(audit, msg, str1);
70246+ break;
70247+ case GR_PSACCT:
70248+ {
70249+ unsigned int wday, cday;
70250+ __u8 whr, chr;
70251+ __u8 wmin, cmin;
70252+ __u8 wsec, csec;
70253+ char cur_tty[64] = { 0 };
70254+ char parent_tty[64] = { 0 };
70255+
70256+ task = va_arg(ap, struct task_struct *);
70257+ wday = va_arg(ap, unsigned int);
70258+ cday = va_arg(ap, unsigned int);
70259+ whr = va_arg(ap, int);
70260+ chr = va_arg(ap, int);
70261+ wmin = va_arg(ap, int);
70262+ cmin = va_arg(ap, int);
70263+ wsec = va_arg(ap, int);
70264+ csec = va_arg(ap, int);
70265+ ulong1 = va_arg(ap, unsigned long);
70266+ cred = __task_cred(task);
70267+ pcred = __task_cred(task->real_parent);
70268+
70269+ 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));
70270+ }
70271+ break;
70272+ default:
70273+ gr_log_middle(audit, msg, ap);
70274+ }
70275+ va_end(ap);
70276+ // these don't need DEFAULTSECARGS printed on the end
70277+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70278+ gr_log_end(audit, 0);
70279+ else
70280+ gr_log_end(audit, 1);
70281+ END_LOCKS(audit);
70282+}
70283diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70284new file mode 100644
70285index 0000000..f536303
70286--- /dev/null
70287+++ b/grsecurity/grsec_mem.c
70288@@ -0,0 +1,40 @@
70289+#include <linux/kernel.h>
70290+#include <linux/sched.h>
70291+#include <linux/mm.h>
70292+#include <linux/mman.h>
70293+#include <linux/grinternal.h>
70294+
70295+void
70296+gr_handle_ioperm(void)
70297+{
70298+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70299+ return;
70300+}
70301+
70302+void
70303+gr_handle_iopl(void)
70304+{
70305+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70306+ return;
70307+}
70308+
70309+void
70310+gr_handle_mem_readwrite(u64 from, u64 to)
70311+{
70312+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70313+ return;
70314+}
70315+
70316+void
70317+gr_handle_vm86(void)
70318+{
70319+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70320+ return;
70321+}
70322+
70323+void
70324+gr_log_badprocpid(const char *entry)
70325+{
70326+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70327+ return;
70328+}
70329diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70330new file mode 100644
70331index 0000000..2131422
70332--- /dev/null
70333+++ b/grsecurity/grsec_mount.c
70334@@ -0,0 +1,62 @@
70335+#include <linux/kernel.h>
70336+#include <linux/sched.h>
70337+#include <linux/mount.h>
70338+#include <linux/grsecurity.h>
70339+#include <linux/grinternal.h>
70340+
70341+void
70342+gr_log_remount(const char *devname, const int retval)
70343+{
70344+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70345+ if (grsec_enable_mount && (retval >= 0))
70346+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70347+#endif
70348+ return;
70349+}
70350+
70351+void
70352+gr_log_unmount(const char *devname, const int retval)
70353+{
70354+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70355+ if (grsec_enable_mount && (retval >= 0))
70356+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70357+#endif
70358+ return;
70359+}
70360+
70361+void
70362+gr_log_mount(const char *from, const char *to, const int retval)
70363+{
70364+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70365+ if (grsec_enable_mount && (retval >= 0))
70366+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70367+#endif
70368+ return;
70369+}
70370+
70371+int
70372+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70373+{
70374+#ifdef CONFIG_GRKERNSEC_ROFS
70375+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70376+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70377+ return -EPERM;
70378+ } else
70379+ return 0;
70380+#endif
70381+ return 0;
70382+}
70383+
70384+int
70385+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70386+{
70387+#ifdef CONFIG_GRKERNSEC_ROFS
70388+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70389+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70390+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70391+ return -EPERM;
70392+ } else
70393+ return 0;
70394+#endif
70395+ return 0;
70396+}
70397diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70398new file mode 100644
70399index 0000000..6ee9d50
70400--- /dev/null
70401+++ b/grsecurity/grsec_pax.c
70402@@ -0,0 +1,45 @@
70403+#include <linux/kernel.h>
70404+#include <linux/sched.h>
70405+#include <linux/mm.h>
70406+#include <linux/file.h>
70407+#include <linux/grinternal.h>
70408+#include <linux/grsecurity.h>
70409+
70410+void
70411+gr_log_textrel(struct vm_area_struct * vma)
70412+{
70413+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70414+ if (grsec_enable_log_rwxmaps)
70415+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70416+#endif
70417+ return;
70418+}
70419+
70420+void gr_log_ptgnustack(struct file *file)
70421+{
70422+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70423+ if (grsec_enable_log_rwxmaps)
70424+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70425+#endif
70426+ return;
70427+}
70428+
70429+void
70430+gr_log_rwxmmap(struct file *file)
70431+{
70432+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70433+ if (grsec_enable_log_rwxmaps)
70434+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70435+#endif
70436+ return;
70437+}
70438+
70439+void
70440+gr_log_rwxmprotect(struct vm_area_struct *vma)
70441+{
70442+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70443+ if (grsec_enable_log_rwxmaps)
70444+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70445+#endif
70446+ return;
70447+}
70448diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70449new file mode 100644
70450index 0000000..f7f29aa
70451--- /dev/null
70452+++ b/grsecurity/grsec_ptrace.c
70453@@ -0,0 +1,30 @@
70454+#include <linux/kernel.h>
70455+#include <linux/sched.h>
70456+#include <linux/grinternal.h>
70457+#include <linux/security.h>
70458+
70459+void
70460+gr_audit_ptrace(struct task_struct *task)
70461+{
70462+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70463+ if (grsec_enable_audit_ptrace)
70464+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70465+#endif
70466+ return;
70467+}
70468+
70469+int
70470+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70471+{
70472+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70473+ const struct dentry *dentry = file->f_path.dentry;
70474+ const struct vfsmount *mnt = file->f_path.mnt;
70475+
70476+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70477+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70478+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70479+ return -EACCES;
70480+ }
70481+#endif
70482+ return 0;
70483+}
70484diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70485new file mode 100644
70486index 0000000..4e29cc7
70487--- /dev/null
70488+++ b/grsecurity/grsec_sig.c
70489@@ -0,0 +1,246 @@
70490+#include <linux/kernel.h>
70491+#include <linux/sched.h>
70492+#include <linux/fs.h>
70493+#include <linux/delay.h>
70494+#include <linux/grsecurity.h>
70495+#include <linux/grinternal.h>
70496+#include <linux/hardirq.h>
70497+
70498+char *signames[] = {
70499+ [SIGSEGV] = "Segmentation fault",
70500+ [SIGILL] = "Illegal instruction",
70501+ [SIGABRT] = "Abort",
70502+ [SIGBUS] = "Invalid alignment/Bus error"
70503+};
70504+
70505+void
70506+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70507+{
70508+#ifdef CONFIG_GRKERNSEC_SIGNAL
70509+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70510+ (sig == SIGABRT) || (sig == SIGBUS))) {
70511+ if (task_pid_nr(t) == task_pid_nr(current)) {
70512+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70513+ } else {
70514+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70515+ }
70516+ }
70517+#endif
70518+ return;
70519+}
70520+
70521+int
70522+gr_handle_signal(const struct task_struct *p, const int sig)
70523+{
70524+#ifdef CONFIG_GRKERNSEC
70525+ /* ignore the 0 signal for protected task checks */
70526+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70527+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70528+ return -EPERM;
70529+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70530+ return -EPERM;
70531+ }
70532+#endif
70533+ return 0;
70534+}
70535+
70536+#ifdef CONFIG_GRKERNSEC
70537+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70538+
70539+int gr_fake_force_sig(int sig, struct task_struct *t)
70540+{
70541+ unsigned long int flags;
70542+ int ret, blocked, ignored;
70543+ struct k_sigaction *action;
70544+
70545+ spin_lock_irqsave(&t->sighand->siglock, flags);
70546+ action = &t->sighand->action[sig-1];
70547+ ignored = action->sa.sa_handler == SIG_IGN;
70548+ blocked = sigismember(&t->blocked, sig);
70549+ if (blocked || ignored) {
70550+ action->sa.sa_handler = SIG_DFL;
70551+ if (blocked) {
70552+ sigdelset(&t->blocked, sig);
70553+ recalc_sigpending_and_wake(t);
70554+ }
70555+ }
70556+ if (action->sa.sa_handler == SIG_DFL)
70557+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70558+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70559+
70560+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70561+
70562+ return ret;
70563+}
70564+#endif
70565+
70566+#ifdef CONFIG_GRKERNSEC_BRUTE
70567+#define GR_USER_BAN_TIME (15 * 60)
70568+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70569+
70570+static int __get_dumpable(unsigned long mm_flags)
70571+{
70572+ int ret;
70573+
70574+ ret = mm_flags & MMF_DUMPABLE_MASK;
70575+ return (ret >= 2) ? 2 : ret;
70576+}
70577+#endif
70578+
70579+void gr_handle_brute_attach(unsigned long mm_flags)
70580+{
70581+#ifdef CONFIG_GRKERNSEC_BRUTE
70582+ struct task_struct *p = current;
70583+ kuid_t uid = GLOBAL_ROOT_UID;
70584+ int daemon = 0;
70585+
70586+ if (!grsec_enable_brute)
70587+ return;
70588+
70589+ rcu_read_lock();
70590+ read_lock(&tasklist_lock);
70591+ read_lock(&grsec_exec_file_lock);
70592+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70593+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70594+ p->real_parent->brute = 1;
70595+ daemon = 1;
70596+ } else {
70597+ const struct cred *cred = __task_cred(p), *cred2;
70598+ struct task_struct *tsk, *tsk2;
70599+
70600+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70601+ struct user_struct *user;
70602+
70603+ uid = cred->uid;
70604+
70605+ /* this is put upon execution past expiration */
70606+ user = find_user(uid);
70607+ if (user == NULL)
70608+ goto unlock;
70609+ user->suid_banned = 1;
70610+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70611+ if (user->suid_ban_expires == ~0UL)
70612+ user->suid_ban_expires--;
70613+
70614+ /* only kill other threads of the same binary, from the same user */
70615+ do_each_thread(tsk2, tsk) {
70616+ cred2 = __task_cred(tsk);
70617+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70618+ gr_fake_force_sig(SIGKILL, tsk);
70619+ } while_each_thread(tsk2, tsk);
70620+ }
70621+ }
70622+unlock:
70623+ read_unlock(&grsec_exec_file_lock);
70624+ read_unlock(&tasklist_lock);
70625+ rcu_read_unlock();
70626+
70627+ if (gr_is_global_nonroot(uid))
70628+ 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);
70629+ else if (daemon)
70630+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70631+
70632+#endif
70633+ return;
70634+}
70635+
70636+void gr_handle_brute_check(void)
70637+{
70638+#ifdef CONFIG_GRKERNSEC_BRUTE
70639+ struct task_struct *p = current;
70640+
70641+ if (unlikely(p->brute)) {
70642+ if (!grsec_enable_brute)
70643+ p->brute = 0;
70644+ else if (time_before(get_seconds(), p->brute_expires))
70645+ msleep(30 * 1000);
70646+ }
70647+#endif
70648+ return;
70649+}
70650+
70651+void gr_handle_kernel_exploit(void)
70652+{
70653+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70654+ const struct cred *cred;
70655+ struct task_struct *tsk, *tsk2;
70656+ struct user_struct *user;
70657+ kuid_t uid;
70658+
70659+ if (in_irq() || in_serving_softirq() || in_nmi())
70660+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70661+
70662+ uid = current_uid();
70663+
70664+ if (gr_is_global_root(uid))
70665+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70666+ else {
70667+ /* kill all the processes of this user, hold a reference
70668+ to their creds struct, and prevent them from creating
70669+ another process until system reset
70670+ */
70671+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70672+ GR_GLOBAL_UID(uid));
70673+ /* we intentionally leak this ref */
70674+ user = get_uid(current->cred->user);
70675+ if (user)
70676+ user->kernel_banned = 1;
70677+
70678+ /* kill all processes of this user */
70679+ read_lock(&tasklist_lock);
70680+ do_each_thread(tsk2, tsk) {
70681+ cred = __task_cred(tsk);
70682+ if (uid_eq(cred->uid, uid))
70683+ gr_fake_force_sig(SIGKILL, tsk);
70684+ } while_each_thread(tsk2, tsk);
70685+ read_unlock(&tasklist_lock);
70686+ }
70687+#endif
70688+}
70689+
70690+#ifdef CONFIG_GRKERNSEC_BRUTE
70691+static bool suid_ban_expired(struct user_struct *user)
70692+{
70693+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70694+ user->suid_banned = 0;
70695+ user->suid_ban_expires = 0;
70696+ free_uid(user);
70697+ return true;
70698+ }
70699+
70700+ return false;
70701+}
70702+#endif
70703+
70704+int gr_process_kernel_exec_ban(void)
70705+{
70706+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70707+ if (unlikely(current->cred->user->kernel_banned))
70708+ return -EPERM;
70709+#endif
70710+ return 0;
70711+}
70712+
70713+int gr_process_kernel_setuid_ban(struct user_struct *user)
70714+{
70715+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70716+ if (unlikely(user->kernel_banned))
70717+ gr_fake_force_sig(SIGKILL, current);
70718+#endif
70719+ return 0;
70720+}
70721+
70722+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70723+{
70724+#ifdef CONFIG_GRKERNSEC_BRUTE
70725+ struct user_struct *user = current->cred->user;
70726+ if (unlikely(user->suid_banned)) {
70727+ if (suid_ban_expired(user))
70728+ return 0;
70729+ /* disallow execution of suid binaries only */
70730+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70731+ return -EPERM;
70732+ }
70733+#endif
70734+ return 0;
70735+}
70736diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70737new file mode 100644
70738index 0000000..4030d57
70739--- /dev/null
70740+++ b/grsecurity/grsec_sock.c
70741@@ -0,0 +1,244 @@
70742+#include <linux/kernel.h>
70743+#include <linux/module.h>
70744+#include <linux/sched.h>
70745+#include <linux/file.h>
70746+#include <linux/net.h>
70747+#include <linux/in.h>
70748+#include <linux/ip.h>
70749+#include <net/sock.h>
70750+#include <net/inet_sock.h>
70751+#include <linux/grsecurity.h>
70752+#include <linux/grinternal.h>
70753+#include <linux/gracl.h>
70754+
70755+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70756+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70757+
70758+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70759+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70760+
70761+#ifdef CONFIG_UNIX_MODULE
70762+EXPORT_SYMBOL(gr_acl_handle_unix);
70763+EXPORT_SYMBOL(gr_acl_handle_mknod);
70764+EXPORT_SYMBOL(gr_handle_chroot_unix);
70765+EXPORT_SYMBOL(gr_handle_create);
70766+#endif
70767+
70768+#ifdef CONFIG_GRKERNSEC
70769+#define gr_conn_table_size 32749
70770+struct conn_table_entry {
70771+ struct conn_table_entry *next;
70772+ struct signal_struct *sig;
70773+};
70774+
70775+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70776+DEFINE_SPINLOCK(gr_conn_table_lock);
70777+
70778+extern const char * gr_socktype_to_name(unsigned char type);
70779+extern const char * gr_proto_to_name(unsigned char proto);
70780+extern const char * gr_sockfamily_to_name(unsigned char family);
70781+
70782+static __inline__ int
70783+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70784+{
70785+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70786+}
70787+
70788+static __inline__ int
70789+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70790+ __u16 sport, __u16 dport)
70791+{
70792+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70793+ sig->gr_sport == sport && sig->gr_dport == dport))
70794+ return 1;
70795+ else
70796+ return 0;
70797+}
70798+
70799+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70800+{
70801+ struct conn_table_entry **match;
70802+ unsigned int index;
70803+
70804+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70805+ sig->gr_sport, sig->gr_dport,
70806+ gr_conn_table_size);
70807+
70808+ newent->sig = sig;
70809+
70810+ match = &gr_conn_table[index];
70811+ newent->next = *match;
70812+ *match = newent;
70813+
70814+ return;
70815+}
70816+
70817+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70818+{
70819+ struct conn_table_entry *match, *last = NULL;
70820+ unsigned int index;
70821+
70822+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70823+ sig->gr_sport, sig->gr_dport,
70824+ gr_conn_table_size);
70825+
70826+ match = gr_conn_table[index];
70827+ while (match && !conn_match(match->sig,
70828+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70829+ sig->gr_dport)) {
70830+ last = match;
70831+ match = match->next;
70832+ }
70833+
70834+ if (match) {
70835+ if (last)
70836+ last->next = match->next;
70837+ else
70838+ gr_conn_table[index] = NULL;
70839+ kfree(match);
70840+ }
70841+
70842+ return;
70843+}
70844+
70845+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70846+ __u16 sport, __u16 dport)
70847+{
70848+ struct conn_table_entry *match;
70849+ unsigned int index;
70850+
70851+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70852+
70853+ match = gr_conn_table[index];
70854+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70855+ match = match->next;
70856+
70857+ if (match)
70858+ return match->sig;
70859+ else
70860+ return NULL;
70861+}
70862+
70863+#endif
70864+
70865+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70866+{
70867+#ifdef CONFIG_GRKERNSEC
70868+ struct signal_struct *sig = task->signal;
70869+ struct conn_table_entry *newent;
70870+
70871+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70872+ if (newent == NULL)
70873+ return;
70874+ /* no bh lock needed since we are called with bh disabled */
70875+ spin_lock(&gr_conn_table_lock);
70876+ gr_del_task_from_ip_table_nolock(sig);
70877+ sig->gr_saddr = inet->inet_rcv_saddr;
70878+ sig->gr_daddr = inet->inet_daddr;
70879+ sig->gr_sport = inet->inet_sport;
70880+ sig->gr_dport = inet->inet_dport;
70881+ gr_add_to_task_ip_table_nolock(sig, newent);
70882+ spin_unlock(&gr_conn_table_lock);
70883+#endif
70884+ return;
70885+}
70886+
70887+void gr_del_task_from_ip_table(struct task_struct *task)
70888+{
70889+#ifdef CONFIG_GRKERNSEC
70890+ spin_lock_bh(&gr_conn_table_lock);
70891+ gr_del_task_from_ip_table_nolock(task->signal);
70892+ spin_unlock_bh(&gr_conn_table_lock);
70893+#endif
70894+ return;
70895+}
70896+
70897+void
70898+gr_attach_curr_ip(const struct sock *sk)
70899+{
70900+#ifdef CONFIG_GRKERNSEC
70901+ struct signal_struct *p, *set;
70902+ const struct inet_sock *inet = inet_sk(sk);
70903+
70904+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70905+ return;
70906+
70907+ set = current->signal;
70908+
70909+ spin_lock_bh(&gr_conn_table_lock);
70910+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70911+ inet->inet_dport, inet->inet_sport);
70912+ if (unlikely(p != NULL)) {
70913+ set->curr_ip = p->curr_ip;
70914+ set->used_accept = 1;
70915+ gr_del_task_from_ip_table_nolock(p);
70916+ spin_unlock_bh(&gr_conn_table_lock);
70917+ return;
70918+ }
70919+ spin_unlock_bh(&gr_conn_table_lock);
70920+
70921+ set->curr_ip = inet->inet_daddr;
70922+ set->used_accept = 1;
70923+#endif
70924+ return;
70925+}
70926+
70927+int
70928+gr_handle_sock_all(const int family, const int type, const int protocol)
70929+{
70930+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70931+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70932+ (family != AF_UNIX)) {
70933+ if (family == AF_INET)
70934+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70935+ else
70936+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70937+ return -EACCES;
70938+ }
70939+#endif
70940+ return 0;
70941+}
70942+
70943+int
70944+gr_handle_sock_server(const struct sockaddr *sck)
70945+{
70946+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70947+ if (grsec_enable_socket_server &&
70948+ in_group_p(grsec_socket_server_gid) &&
70949+ sck && (sck->sa_family != AF_UNIX) &&
70950+ (sck->sa_family != AF_LOCAL)) {
70951+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70952+ return -EACCES;
70953+ }
70954+#endif
70955+ return 0;
70956+}
70957+
70958+int
70959+gr_handle_sock_server_other(const struct sock *sck)
70960+{
70961+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70962+ if (grsec_enable_socket_server &&
70963+ in_group_p(grsec_socket_server_gid) &&
70964+ sck && (sck->sk_family != AF_UNIX) &&
70965+ (sck->sk_family != AF_LOCAL)) {
70966+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70967+ return -EACCES;
70968+ }
70969+#endif
70970+ return 0;
70971+}
70972+
70973+int
70974+gr_handle_sock_client(const struct sockaddr *sck)
70975+{
70976+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70977+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70978+ sck && (sck->sa_family != AF_UNIX) &&
70979+ (sck->sa_family != AF_LOCAL)) {
70980+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70981+ return -EACCES;
70982+ }
70983+#endif
70984+ return 0;
70985+}
70986diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70987new file mode 100644
70988index 0000000..a147ae7
70989--- /dev/null
70990+++ b/grsecurity/grsec_sysctl.c
70991@@ -0,0 +1,470 @@
70992+#include <linux/kernel.h>
70993+#include <linux/sched.h>
70994+#include <linux/sysctl.h>
70995+#include <linux/grsecurity.h>
70996+#include <linux/grinternal.h>
70997+
70998+int
70999+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
71000+{
71001+#ifdef CONFIG_GRKERNSEC_SYSCTL
71002+ if (dirname == NULL || name == NULL)
71003+ return 0;
71004+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
71005+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
71006+ return -EACCES;
71007+ }
71008+#endif
71009+ return 0;
71010+}
71011+
71012+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
71013+static int __maybe_unused __read_only one = 1;
71014+#endif
71015+
71016+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
71017+ defined(CONFIG_GRKERNSEC_DENYUSB)
71018+struct ctl_table grsecurity_table[] = {
71019+#ifdef CONFIG_GRKERNSEC_SYSCTL
71020+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
71021+#ifdef CONFIG_GRKERNSEC_IO
71022+ {
71023+ .procname = "disable_priv_io",
71024+ .data = &grsec_disable_privio,
71025+ .maxlen = sizeof(int),
71026+ .mode = 0600,
71027+ .proc_handler = &proc_dointvec,
71028+ },
71029+#endif
71030+#endif
71031+#ifdef CONFIG_GRKERNSEC_LINK
71032+ {
71033+ .procname = "linking_restrictions",
71034+ .data = &grsec_enable_link,
71035+ .maxlen = sizeof(int),
71036+ .mode = 0600,
71037+ .proc_handler = &proc_dointvec,
71038+ },
71039+#endif
71040+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71041+ {
71042+ .procname = "enforce_symlinksifowner",
71043+ .data = &grsec_enable_symlinkown,
71044+ .maxlen = sizeof(int),
71045+ .mode = 0600,
71046+ .proc_handler = &proc_dointvec,
71047+ },
71048+ {
71049+ .procname = "symlinkown_gid",
71050+ .data = &grsec_symlinkown_gid,
71051+ .maxlen = sizeof(int),
71052+ .mode = 0600,
71053+ .proc_handler = &proc_dointvec,
71054+ },
71055+#endif
71056+#ifdef CONFIG_GRKERNSEC_BRUTE
71057+ {
71058+ .procname = "deter_bruteforce",
71059+ .data = &grsec_enable_brute,
71060+ .maxlen = sizeof(int),
71061+ .mode = 0600,
71062+ .proc_handler = &proc_dointvec,
71063+ },
71064+#endif
71065+#ifdef CONFIG_GRKERNSEC_FIFO
71066+ {
71067+ .procname = "fifo_restrictions",
71068+ .data = &grsec_enable_fifo,
71069+ .maxlen = sizeof(int),
71070+ .mode = 0600,
71071+ .proc_handler = &proc_dointvec,
71072+ },
71073+#endif
71074+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71075+ {
71076+ .procname = "ptrace_readexec",
71077+ .data = &grsec_enable_ptrace_readexec,
71078+ .maxlen = sizeof(int),
71079+ .mode = 0600,
71080+ .proc_handler = &proc_dointvec,
71081+ },
71082+#endif
71083+#ifdef CONFIG_GRKERNSEC_SETXID
71084+ {
71085+ .procname = "consistent_setxid",
71086+ .data = &grsec_enable_setxid,
71087+ .maxlen = sizeof(int),
71088+ .mode = 0600,
71089+ .proc_handler = &proc_dointvec,
71090+ },
71091+#endif
71092+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71093+ {
71094+ .procname = "ip_blackhole",
71095+ .data = &grsec_enable_blackhole,
71096+ .maxlen = sizeof(int),
71097+ .mode = 0600,
71098+ .proc_handler = &proc_dointvec,
71099+ },
71100+ {
71101+ .procname = "lastack_retries",
71102+ .data = &grsec_lastack_retries,
71103+ .maxlen = sizeof(int),
71104+ .mode = 0600,
71105+ .proc_handler = &proc_dointvec,
71106+ },
71107+#endif
71108+#ifdef CONFIG_GRKERNSEC_EXECLOG
71109+ {
71110+ .procname = "exec_logging",
71111+ .data = &grsec_enable_execlog,
71112+ .maxlen = sizeof(int),
71113+ .mode = 0600,
71114+ .proc_handler = &proc_dointvec,
71115+ },
71116+#endif
71117+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71118+ {
71119+ .procname = "rwxmap_logging",
71120+ .data = &grsec_enable_log_rwxmaps,
71121+ .maxlen = sizeof(int),
71122+ .mode = 0600,
71123+ .proc_handler = &proc_dointvec,
71124+ },
71125+#endif
71126+#ifdef CONFIG_GRKERNSEC_SIGNAL
71127+ {
71128+ .procname = "signal_logging",
71129+ .data = &grsec_enable_signal,
71130+ .maxlen = sizeof(int),
71131+ .mode = 0600,
71132+ .proc_handler = &proc_dointvec,
71133+ },
71134+#endif
71135+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71136+ {
71137+ .procname = "forkfail_logging",
71138+ .data = &grsec_enable_forkfail,
71139+ .maxlen = sizeof(int),
71140+ .mode = 0600,
71141+ .proc_handler = &proc_dointvec,
71142+ },
71143+#endif
71144+#ifdef CONFIG_GRKERNSEC_TIME
71145+ {
71146+ .procname = "timechange_logging",
71147+ .data = &grsec_enable_time,
71148+ .maxlen = sizeof(int),
71149+ .mode = 0600,
71150+ .proc_handler = &proc_dointvec,
71151+ },
71152+#endif
71153+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71154+ {
71155+ .procname = "chroot_deny_shmat",
71156+ .data = &grsec_enable_chroot_shmat,
71157+ .maxlen = sizeof(int),
71158+ .mode = 0600,
71159+ .proc_handler = &proc_dointvec,
71160+ },
71161+#endif
71162+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71163+ {
71164+ .procname = "chroot_deny_unix",
71165+ .data = &grsec_enable_chroot_unix,
71166+ .maxlen = sizeof(int),
71167+ .mode = 0600,
71168+ .proc_handler = &proc_dointvec,
71169+ },
71170+#endif
71171+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71172+ {
71173+ .procname = "chroot_deny_mount",
71174+ .data = &grsec_enable_chroot_mount,
71175+ .maxlen = sizeof(int),
71176+ .mode = 0600,
71177+ .proc_handler = &proc_dointvec,
71178+ },
71179+#endif
71180+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71181+ {
71182+ .procname = "chroot_deny_fchdir",
71183+ .data = &grsec_enable_chroot_fchdir,
71184+ .maxlen = sizeof(int),
71185+ .mode = 0600,
71186+ .proc_handler = &proc_dointvec,
71187+ },
71188+#endif
71189+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71190+ {
71191+ .procname = "chroot_deny_chroot",
71192+ .data = &grsec_enable_chroot_double,
71193+ .maxlen = sizeof(int),
71194+ .mode = 0600,
71195+ .proc_handler = &proc_dointvec,
71196+ },
71197+#endif
71198+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71199+ {
71200+ .procname = "chroot_deny_pivot",
71201+ .data = &grsec_enable_chroot_pivot,
71202+ .maxlen = sizeof(int),
71203+ .mode = 0600,
71204+ .proc_handler = &proc_dointvec,
71205+ },
71206+#endif
71207+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71208+ {
71209+ .procname = "chroot_enforce_chdir",
71210+ .data = &grsec_enable_chroot_chdir,
71211+ .maxlen = sizeof(int),
71212+ .mode = 0600,
71213+ .proc_handler = &proc_dointvec,
71214+ },
71215+#endif
71216+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71217+ {
71218+ .procname = "chroot_deny_chmod",
71219+ .data = &grsec_enable_chroot_chmod,
71220+ .maxlen = sizeof(int),
71221+ .mode = 0600,
71222+ .proc_handler = &proc_dointvec,
71223+ },
71224+#endif
71225+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71226+ {
71227+ .procname = "chroot_deny_mknod",
71228+ .data = &grsec_enable_chroot_mknod,
71229+ .maxlen = sizeof(int),
71230+ .mode = 0600,
71231+ .proc_handler = &proc_dointvec,
71232+ },
71233+#endif
71234+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71235+ {
71236+ .procname = "chroot_restrict_nice",
71237+ .data = &grsec_enable_chroot_nice,
71238+ .maxlen = sizeof(int),
71239+ .mode = 0600,
71240+ .proc_handler = &proc_dointvec,
71241+ },
71242+#endif
71243+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71244+ {
71245+ .procname = "chroot_execlog",
71246+ .data = &grsec_enable_chroot_execlog,
71247+ .maxlen = sizeof(int),
71248+ .mode = 0600,
71249+ .proc_handler = &proc_dointvec,
71250+ },
71251+#endif
71252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71253+ {
71254+ .procname = "chroot_caps",
71255+ .data = &grsec_enable_chroot_caps,
71256+ .maxlen = sizeof(int),
71257+ .mode = 0600,
71258+ .proc_handler = &proc_dointvec,
71259+ },
71260+#endif
71261+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71262+ {
71263+ .procname = "chroot_deny_sysctl",
71264+ .data = &grsec_enable_chroot_sysctl,
71265+ .maxlen = sizeof(int),
71266+ .mode = 0600,
71267+ .proc_handler = &proc_dointvec,
71268+ },
71269+#endif
71270+#ifdef CONFIG_GRKERNSEC_TPE
71271+ {
71272+ .procname = "tpe",
71273+ .data = &grsec_enable_tpe,
71274+ .maxlen = sizeof(int),
71275+ .mode = 0600,
71276+ .proc_handler = &proc_dointvec,
71277+ },
71278+ {
71279+ .procname = "tpe_gid",
71280+ .data = &grsec_tpe_gid,
71281+ .maxlen = sizeof(int),
71282+ .mode = 0600,
71283+ .proc_handler = &proc_dointvec,
71284+ },
71285+#endif
71286+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71287+ {
71288+ .procname = "tpe_invert",
71289+ .data = &grsec_enable_tpe_invert,
71290+ .maxlen = sizeof(int),
71291+ .mode = 0600,
71292+ .proc_handler = &proc_dointvec,
71293+ },
71294+#endif
71295+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71296+ {
71297+ .procname = "tpe_restrict_all",
71298+ .data = &grsec_enable_tpe_all,
71299+ .maxlen = sizeof(int),
71300+ .mode = 0600,
71301+ .proc_handler = &proc_dointvec,
71302+ },
71303+#endif
71304+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71305+ {
71306+ .procname = "socket_all",
71307+ .data = &grsec_enable_socket_all,
71308+ .maxlen = sizeof(int),
71309+ .mode = 0600,
71310+ .proc_handler = &proc_dointvec,
71311+ },
71312+ {
71313+ .procname = "socket_all_gid",
71314+ .data = &grsec_socket_all_gid,
71315+ .maxlen = sizeof(int),
71316+ .mode = 0600,
71317+ .proc_handler = &proc_dointvec,
71318+ },
71319+#endif
71320+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71321+ {
71322+ .procname = "socket_client",
71323+ .data = &grsec_enable_socket_client,
71324+ .maxlen = sizeof(int),
71325+ .mode = 0600,
71326+ .proc_handler = &proc_dointvec,
71327+ },
71328+ {
71329+ .procname = "socket_client_gid",
71330+ .data = &grsec_socket_client_gid,
71331+ .maxlen = sizeof(int),
71332+ .mode = 0600,
71333+ .proc_handler = &proc_dointvec,
71334+ },
71335+#endif
71336+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71337+ {
71338+ .procname = "socket_server",
71339+ .data = &grsec_enable_socket_server,
71340+ .maxlen = sizeof(int),
71341+ .mode = 0600,
71342+ .proc_handler = &proc_dointvec,
71343+ },
71344+ {
71345+ .procname = "socket_server_gid",
71346+ .data = &grsec_socket_server_gid,
71347+ .maxlen = sizeof(int),
71348+ .mode = 0600,
71349+ .proc_handler = &proc_dointvec,
71350+ },
71351+#endif
71352+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71353+ {
71354+ .procname = "audit_group",
71355+ .data = &grsec_enable_group,
71356+ .maxlen = sizeof(int),
71357+ .mode = 0600,
71358+ .proc_handler = &proc_dointvec,
71359+ },
71360+ {
71361+ .procname = "audit_gid",
71362+ .data = &grsec_audit_gid,
71363+ .maxlen = sizeof(int),
71364+ .mode = 0600,
71365+ .proc_handler = &proc_dointvec,
71366+ },
71367+#endif
71368+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71369+ {
71370+ .procname = "audit_chdir",
71371+ .data = &grsec_enable_chdir,
71372+ .maxlen = sizeof(int),
71373+ .mode = 0600,
71374+ .proc_handler = &proc_dointvec,
71375+ },
71376+#endif
71377+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71378+ {
71379+ .procname = "audit_mount",
71380+ .data = &grsec_enable_mount,
71381+ .maxlen = sizeof(int),
71382+ .mode = 0600,
71383+ .proc_handler = &proc_dointvec,
71384+ },
71385+#endif
71386+#ifdef CONFIG_GRKERNSEC_DMESG
71387+ {
71388+ .procname = "dmesg",
71389+ .data = &grsec_enable_dmesg,
71390+ .maxlen = sizeof(int),
71391+ .mode = 0600,
71392+ .proc_handler = &proc_dointvec,
71393+ },
71394+#endif
71395+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71396+ {
71397+ .procname = "chroot_findtask",
71398+ .data = &grsec_enable_chroot_findtask,
71399+ .maxlen = sizeof(int),
71400+ .mode = 0600,
71401+ .proc_handler = &proc_dointvec,
71402+ },
71403+#endif
71404+#ifdef CONFIG_GRKERNSEC_RESLOG
71405+ {
71406+ .procname = "resource_logging",
71407+ .data = &grsec_resource_logging,
71408+ .maxlen = sizeof(int),
71409+ .mode = 0600,
71410+ .proc_handler = &proc_dointvec,
71411+ },
71412+#endif
71413+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71414+ {
71415+ .procname = "audit_ptrace",
71416+ .data = &grsec_enable_audit_ptrace,
71417+ .maxlen = sizeof(int),
71418+ .mode = 0600,
71419+ .proc_handler = &proc_dointvec,
71420+ },
71421+#endif
71422+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71423+ {
71424+ .procname = "harden_ptrace",
71425+ .data = &grsec_enable_harden_ptrace,
71426+ .maxlen = sizeof(int),
71427+ .mode = 0600,
71428+ .proc_handler = &proc_dointvec,
71429+ },
71430+#endif
71431+ {
71432+ .procname = "grsec_lock",
71433+ .data = &grsec_lock,
71434+ .maxlen = sizeof(int),
71435+ .mode = 0600,
71436+ .proc_handler = &proc_dointvec,
71437+ },
71438+#endif
71439+#ifdef CONFIG_GRKERNSEC_ROFS
71440+ {
71441+ .procname = "romount_protect",
71442+ .data = &grsec_enable_rofs,
71443+ .maxlen = sizeof(int),
71444+ .mode = 0600,
71445+ .proc_handler = &proc_dointvec_minmax,
71446+ .extra1 = &one,
71447+ .extra2 = &one,
71448+ },
71449+#endif
71450+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71451+ {
71452+ .procname = "deny_new_usb",
71453+ .data = &grsec_deny_new_usb,
71454+ .maxlen = sizeof(int),
71455+ .mode = 0600,
71456+ .proc_handler = &proc_dointvec,
71457+ },
71458+#endif
71459+ { }
71460+};
71461+#endif
71462diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71463new file mode 100644
71464index 0000000..0dc13c3
71465--- /dev/null
71466+++ b/grsecurity/grsec_time.c
71467@@ -0,0 +1,16 @@
71468+#include <linux/kernel.h>
71469+#include <linux/sched.h>
71470+#include <linux/grinternal.h>
71471+#include <linux/module.h>
71472+
71473+void
71474+gr_log_timechange(void)
71475+{
71476+#ifdef CONFIG_GRKERNSEC_TIME
71477+ if (grsec_enable_time)
71478+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71479+#endif
71480+ return;
71481+}
71482+
71483+EXPORT_SYMBOL(gr_log_timechange);
71484diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71485new file mode 100644
71486index 0000000..ee57dcf
71487--- /dev/null
71488+++ b/grsecurity/grsec_tpe.c
71489@@ -0,0 +1,73 @@
71490+#include <linux/kernel.h>
71491+#include <linux/sched.h>
71492+#include <linux/file.h>
71493+#include <linux/fs.h>
71494+#include <linux/grinternal.h>
71495+
71496+extern int gr_acl_tpe_check(void);
71497+
71498+int
71499+gr_tpe_allow(const struct file *file)
71500+{
71501+#ifdef CONFIG_GRKERNSEC
71502+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71503+ const struct cred *cred = current_cred();
71504+ char *msg = NULL;
71505+ char *msg2 = NULL;
71506+
71507+ // never restrict root
71508+ if (gr_is_global_root(cred->uid))
71509+ return 1;
71510+
71511+ if (grsec_enable_tpe) {
71512+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71513+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71514+ msg = "not being in trusted group";
71515+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71516+ msg = "being in untrusted group";
71517+#else
71518+ if (in_group_p(grsec_tpe_gid))
71519+ msg = "being in untrusted group";
71520+#endif
71521+ }
71522+ if (!msg && gr_acl_tpe_check())
71523+ msg = "being in untrusted role";
71524+
71525+ // not in any affected group/role
71526+ if (!msg)
71527+ goto next_check;
71528+
71529+ if (gr_is_global_nonroot(inode->i_uid))
71530+ msg2 = "file in non-root-owned directory";
71531+ else if (inode->i_mode & S_IWOTH)
71532+ msg2 = "file in world-writable directory";
71533+ else if (inode->i_mode & S_IWGRP)
71534+ msg2 = "file in group-writable directory";
71535+
71536+ if (msg && msg2) {
71537+ char fullmsg[70] = {0};
71538+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71539+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71540+ return 0;
71541+ }
71542+ msg = NULL;
71543+next_check:
71544+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71545+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71546+ return 1;
71547+
71548+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71549+ msg = "directory not owned by user";
71550+ else if (inode->i_mode & S_IWOTH)
71551+ msg = "file in world-writable directory";
71552+ else if (inode->i_mode & S_IWGRP)
71553+ msg = "file in group-writable directory";
71554+
71555+ if (msg) {
71556+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71557+ return 0;
71558+ }
71559+#endif
71560+#endif
71561+ return 1;
71562+}
71563diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71564new file mode 100644
71565index 0000000..ae02d8e
71566--- /dev/null
71567+++ b/grsecurity/grsec_usb.c
71568@@ -0,0 +1,15 @@
71569+#include <linux/kernel.h>
71570+#include <linux/grinternal.h>
71571+#include <linux/module.h>
71572+
71573+int gr_handle_new_usb(void)
71574+{
71575+#ifdef CONFIG_GRKERNSEC_DENYUSB
71576+ if (grsec_deny_new_usb) {
71577+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71578+ return 1;
71579+ }
71580+#endif
71581+ return 0;
71582+}
71583+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71584diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71585new file mode 100644
71586index 0000000..9f7b1ac
71587--- /dev/null
71588+++ b/grsecurity/grsum.c
71589@@ -0,0 +1,61 @@
71590+#include <linux/err.h>
71591+#include <linux/kernel.h>
71592+#include <linux/sched.h>
71593+#include <linux/mm.h>
71594+#include <linux/scatterlist.h>
71595+#include <linux/crypto.h>
71596+#include <linux/gracl.h>
71597+
71598+
71599+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71600+#error "crypto and sha256 must be built into the kernel"
71601+#endif
71602+
71603+int
71604+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71605+{
71606+ char *p;
71607+ struct crypto_hash *tfm;
71608+ struct hash_desc desc;
71609+ struct scatterlist sg;
71610+ unsigned char temp_sum[GR_SHA_LEN];
71611+ volatile int retval = 0;
71612+ volatile int dummy = 0;
71613+ unsigned int i;
71614+
71615+ sg_init_table(&sg, 1);
71616+
71617+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71618+ if (IS_ERR(tfm)) {
71619+ /* should never happen, since sha256 should be built in */
71620+ return 1;
71621+ }
71622+
71623+ desc.tfm = tfm;
71624+ desc.flags = 0;
71625+
71626+ crypto_hash_init(&desc);
71627+
71628+ p = salt;
71629+ sg_set_buf(&sg, p, GR_SALT_LEN);
71630+ crypto_hash_update(&desc, &sg, sg.length);
71631+
71632+ p = entry->pw;
71633+ sg_set_buf(&sg, p, strlen(p));
71634+
71635+ crypto_hash_update(&desc, &sg, sg.length);
71636+
71637+ crypto_hash_final(&desc, temp_sum);
71638+
71639+ memset(entry->pw, 0, GR_PW_LEN);
71640+
71641+ for (i = 0; i < GR_SHA_LEN; i++)
71642+ if (sum[i] != temp_sum[i])
71643+ retval = 1;
71644+ else
71645+ dummy = 1; // waste a cycle
71646+
71647+ crypto_free_hash(tfm);
71648+
71649+ return retval;
71650+}
71651diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71652index 77ff547..181834f 100644
71653--- a/include/asm-generic/4level-fixup.h
71654+++ b/include/asm-generic/4level-fixup.h
71655@@ -13,8 +13,10 @@
71656 #define pmd_alloc(mm, pud, address) \
71657 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71658 NULL: pmd_offset(pud, address))
71659+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71660
71661 #define pud_alloc(mm, pgd, address) (pgd)
71662+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71663 #define pud_offset(pgd, start) (pgd)
71664 #define pud_none(pud) 0
71665 #define pud_bad(pud) 0
71666diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71667index b7babf0..04ad282 100644
71668--- a/include/asm-generic/atomic-long.h
71669+++ b/include/asm-generic/atomic-long.h
71670@@ -22,6 +22,12 @@
71671
71672 typedef atomic64_t atomic_long_t;
71673
71674+#ifdef CONFIG_PAX_REFCOUNT
71675+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71676+#else
71677+typedef atomic64_t atomic_long_unchecked_t;
71678+#endif
71679+
71680 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71681
71682 static inline long atomic_long_read(atomic_long_t *l)
71683@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71684 return (long)atomic64_read(v);
71685 }
71686
71687+#ifdef CONFIG_PAX_REFCOUNT
71688+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71689+{
71690+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71691+
71692+ return (long)atomic64_read_unchecked(v);
71693+}
71694+#endif
71695+
71696 static inline void atomic_long_set(atomic_long_t *l, long i)
71697 {
71698 atomic64_t *v = (atomic64_t *)l;
71699@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71700 atomic64_set(v, i);
71701 }
71702
71703+#ifdef CONFIG_PAX_REFCOUNT
71704+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71705+{
71706+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71707+
71708+ atomic64_set_unchecked(v, i);
71709+}
71710+#endif
71711+
71712 static inline void atomic_long_inc(atomic_long_t *l)
71713 {
71714 atomic64_t *v = (atomic64_t *)l;
71715@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71716 atomic64_inc(v);
71717 }
71718
71719+#ifdef CONFIG_PAX_REFCOUNT
71720+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71721+{
71722+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71723+
71724+ atomic64_inc_unchecked(v);
71725+}
71726+#endif
71727+
71728 static inline void atomic_long_dec(atomic_long_t *l)
71729 {
71730 atomic64_t *v = (atomic64_t *)l;
71731@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71732 atomic64_dec(v);
71733 }
71734
71735+#ifdef CONFIG_PAX_REFCOUNT
71736+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71737+{
71738+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71739+
71740+ atomic64_dec_unchecked(v);
71741+}
71742+#endif
71743+
71744 static inline void atomic_long_add(long i, atomic_long_t *l)
71745 {
71746 atomic64_t *v = (atomic64_t *)l;
71747@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71748 atomic64_add(i, v);
71749 }
71750
71751+#ifdef CONFIG_PAX_REFCOUNT
71752+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71753+{
71754+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71755+
71756+ atomic64_add_unchecked(i, v);
71757+}
71758+#endif
71759+
71760 static inline void atomic_long_sub(long i, atomic_long_t *l)
71761 {
71762 atomic64_t *v = (atomic64_t *)l;
71763@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71764 atomic64_sub(i, v);
71765 }
71766
71767+#ifdef CONFIG_PAX_REFCOUNT
71768+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71769+{
71770+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71771+
71772+ atomic64_sub_unchecked(i, v);
71773+}
71774+#endif
71775+
71776 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71777 {
71778 atomic64_t *v = (atomic64_t *)l;
71779@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71780 return (long)atomic64_add_return(i, v);
71781 }
71782
71783+#ifdef CONFIG_PAX_REFCOUNT
71784+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71785+{
71786+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71787+
71788+ return (long)atomic64_add_return_unchecked(i, v);
71789+}
71790+#endif
71791+
71792 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71793 {
71794 atomic64_t *v = (atomic64_t *)l;
71795@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71796 return (long)atomic64_inc_return(v);
71797 }
71798
71799+#ifdef CONFIG_PAX_REFCOUNT
71800+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71801+{
71802+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71803+
71804+ return (long)atomic64_inc_return_unchecked(v);
71805+}
71806+#endif
71807+
71808 static inline long atomic_long_dec_return(atomic_long_t *l)
71809 {
71810 atomic64_t *v = (atomic64_t *)l;
71811@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71812
71813 typedef atomic_t atomic_long_t;
71814
71815+#ifdef CONFIG_PAX_REFCOUNT
71816+typedef atomic_unchecked_t atomic_long_unchecked_t;
71817+#else
71818+typedef atomic_t atomic_long_unchecked_t;
71819+#endif
71820+
71821 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71822 static inline long atomic_long_read(atomic_long_t *l)
71823 {
71824@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71825 return (long)atomic_read(v);
71826 }
71827
71828+#ifdef CONFIG_PAX_REFCOUNT
71829+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71830+{
71831+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71832+
71833+ return (long)atomic_read_unchecked(v);
71834+}
71835+#endif
71836+
71837 static inline void atomic_long_set(atomic_long_t *l, long i)
71838 {
71839 atomic_t *v = (atomic_t *)l;
71840@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71841 atomic_set(v, i);
71842 }
71843
71844+#ifdef CONFIG_PAX_REFCOUNT
71845+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71846+{
71847+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71848+
71849+ atomic_set_unchecked(v, i);
71850+}
71851+#endif
71852+
71853 static inline void atomic_long_inc(atomic_long_t *l)
71854 {
71855 atomic_t *v = (atomic_t *)l;
71856@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71857 atomic_inc(v);
71858 }
71859
71860+#ifdef CONFIG_PAX_REFCOUNT
71861+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71862+{
71863+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71864+
71865+ atomic_inc_unchecked(v);
71866+}
71867+#endif
71868+
71869 static inline void atomic_long_dec(atomic_long_t *l)
71870 {
71871 atomic_t *v = (atomic_t *)l;
71872@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71873 atomic_dec(v);
71874 }
71875
71876+#ifdef CONFIG_PAX_REFCOUNT
71877+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71878+{
71879+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71880+
71881+ atomic_dec_unchecked(v);
71882+}
71883+#endif
71884+
71885 static inline void atomic_long_add(long i, atomic_long_t *l)
71886 {
71887 atomic_t *v = (atomic_t *)l;
71888@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71889 atomic_add(i, v);
71890 }
71891
71892+#ifdef CONFIG_PAX_REFCOUNT
71893+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71894+{
71895+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71896+
71897+ atomic_add_unchecked(i, v);
71898+}
71899+#endif
71900+
71901 static inline void atomic_long_sub(long i, atomic_long_t *l)
71902 {
71903 atomic_t *v = (atomic_t *)l;
71904@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71905 atomic_sub(i, v);
71906 }
71907
71908+#ifdef CONFIG_PAX_REFCOUNT
71909+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71910+{
71911+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71912+
71913+ atomic_sub_unchecked(i, v);
71914+}
71915+#endif
71916+
71917 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71918 {
71919 atomic_t *v = (atomic_t *)l;
71920@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71921 return (long)atomic_add_return(i, v);
71922 }
71923
71924+#ifdef CONFIG_PAX_REFCOUNT
71925+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71926+{
71927+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71928+
71929+ return (long)atomic_add_return_unchecked(i, v);
71930+}
71931+
71932+#endif
71933+
71934 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71935 {
71936 atomic_t *v = (atomic_t *)l;
71937@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71938 return (long)atomic_inc_return(v);
71939 }
71940
71941+#ifdef CONFIG_PAX_REFCOUNT
71942+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71943+{
71944+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71945+
71946+ return (long)atomic_inc_return_unchecked(v);
71947+}
71948+#endif
71949+
71950 static inline long atomic_long_dec_return(atomic_long_t *l)
71951 {
71952 atomic_t *v = (atomic_t *)l;
71953@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71954
71955 #endif /* BITS_PER_LONG == 64 */
71956
71957+#ifdef CONFIG_PAX_REFCOUNT
71958+static inline void pax_refcount_needs_these_functions(void)
71959+{
71960+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71961+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71962+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71963+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71964+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71965+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71966+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71967+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71968+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71969+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71970+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71971+#ifdef CONFIG_X86
71972+ atomic_clear_mask_unchecked(0, NULL);
71973+ atomic_set_mask_unchecked(0, NULL);
71974+#endif
71975+
71976+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71977+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71978+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71979+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71980+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71981+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71982+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71983+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71984+}
71985+#else
71986+#define atomic_read_unchecked(v) atomic_read(v)
71987+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71988+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71989+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71990+#define atomic_inc_unchecked(v) atomic_inc(v)
71991+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71992+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71993+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71994+#define atomic_dec_unchecked(v) atomic_dec(v)
71995+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71996+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71997+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71998+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71999+
72000+#define atomic_long_read_unchecked(v) atomic_long_read(v)
72001+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
72002+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
72003+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
72004+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
72005+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
72006+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
72007+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
72008+#endif
72009+
72010 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
72011diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
72012index 33bd2de..f31bff97 100644
72013--- a/include/asm-generic/atomic.h
72014+++ b/include/asm-generic/atomic.h
72015@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
72016 * Atomically clears the bits set in @mask from @v
72017 */
72018 #ifndef atomic_clear_mask
72019-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
72020+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
72021 {
72022 unsigned long flags;
72023
72024diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
72025index b18ce4f..2ee2843 100644
72026--- a/include/asm-generic/atomic64.h
72027+++ b/include/asm-generic/atomic64.h
72028@@ -16,6 +16,8 @@ typedef struct {
72029 long long counter;
72030 } atomic64_t;
72031
72032+typedef atomic64_t atomic64_unchecked_t;
72033+
72034 #define ATOMIC64_INIT(i) { (i) }
72035
72036 extern long long atomic64_read(const atomic64_t *v);
72037@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
72038 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
72039 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
72040
72041+#define atomic64_read_unchecked(v) atomic64_read(v)
72042+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
72043+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
72044+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
72045+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
72046+#define atomic64_inc_unchecked(v) atomic64_inc(v)
72047+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
72048+#define atomic64_dec_unchecked(v) atomic64_dec(v)
72049+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
72050+
72051 #endif /* _ASM_GENERIC_ATOMIC64_H */
72052diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
72053index 1bfcfe5..e04c5c9 100644
72054--- a/include/asm-generic/cache.h
72055+++ b/include/asm-generic/cache.h
72056@@ -6,7 +6,7 @@
72057 * cache lines need to provide their own cache.h.
72058 */
72059
72060-#define L1_CACHE_SHIFT 5
72061-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
72062+#define L1_CACHE_SHIFT 5UL
72063+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
72064
72065 #endif /* __ASM_GENERIC_CACHE_H */
72066diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
72067index 0d68a1e..b74a761 100644
72068--- a/include/asm-generic/emergency-restart.h
72069+++ b/include/asm-generic/emergency-restart.h
72070@@ -1,7 +1,7 @@
72071 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
72072 #define _ASM_GENERIC_EMERGENCY_RESTART_H
72073
72074-static inline void machine_emergency_restart(void)
72075+static inline __noreturn void machine_emergency_restart(void)
72076 {
72077 machine_restart(NULL);
72078 }
72079diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
72080index 90f99c7..00ce236 100644
72081--- a/include/asm-generic/kmap_types.h
72082+++ b/include/asm-generic/kmap_types.h
72083@@ -2,9 +2,9 @@
72084 #define _ASM_GENERIC_KMAP_TYPES_H
72085
72086 #ifdef __WITH_KM_FENCE
72087-# define KM_TYPE_NR 41
72088+# define KM_TYPE_NR 42
72089 #else
72090-# define KM_TYPE_NR 20
72091+# define KM_TYPE_NR 21
72092 #endif
72093
72094 #endif
72095diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
72096index 9ceb03b..62b0b8f 100644
72097--- a/include/asm-generic/local.h
72098+++ b/include/asm-generic/local.h
72099@@ -23,24 +23,37 @@ typedef struct
72100 atomic_long_t a;
72101 } local_t;
72102
72103+typedef struct {
72104+ atomic_long_unchecked_t a;
72105+} local_unchecked_t;
72106+
72107 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
72108
72109 #define local_read(l) atomic_long_read(&(l)->a)
72110+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
72111 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
72112+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
72113 #define local_inc(l) atomic_long_inc(&(l)->a)
72114+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
72115 #define local_dec(l) atomic_long_dec(&(l)->a)
72116+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
72117 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
72118+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
72119 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
72120+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
72121
72122 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
72123 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
72124 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
72125 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
72126 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
72127+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
72128 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
72129 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
72130+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
72131
72132 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72133+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72134 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
72135 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
72136 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
72137diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
72138index 725612b..9cc513a 100644
72139--- a/include/asm-generic/pgtable-nopmd.h
72140+++ b/include/asm-generic/pgtable-nopmd.h
72141@@ -1,14 +1,19 @@
72142 #ifndef _PGTABLE_NOPMD_H
72143 #define _PGTABLE_NOPMD_H
72144
72145-#ifndef __ASSEMBLY__
72146-
72147 #include <asm-generic/pgtable-nopud.h>
72148
72149-struct mm_struct;
72150-
72151 #define __PAGETABLE_PMD_FOLDED
72152
72153+#define PMD_SHIFT PUD_SHIFT
72154+#define PTRS_PER_PMD 1
72155+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72156+#define PMD_MASK (~(PMD_SIZE-1))
72157+
72158+#ifndef __ASSEMBLY__
72159+
72160+struct mm_struct;
72161+
72162 /*
72163 * Having the pmd type consist of a pud gets the size right, and allows
72164 * us to conceptually access the pud entry that this pmd is folded into
72165@@ -16,11 +21,6 @@ struct mm_struct;
72166 */
72167 typedef struct { pud_t pud; } pmd_t;
72168
72169-#define PMD_SHIFT PUD_SHIFT
72170-#define PTRS_PER_PMD 1
72171-#define PMD_SIZE (1UL << PMD_SHIFT)
72172-#define PMD_MASK (~(PMD_SIZE-1))
72173-
72174 /*
72175 * The "pud_xxx()" functions here are trivial for a folded two-level
72176 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72177diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72178index 810431d..0ec4804f 100644
72179--- a/include/asm-generic/pgtable-nopud.h
72180+++ b/include/asm-generic/pgtable-nopud.h
72181@@ -1,10 +1,15 @@
72182 #ifndef _PGTABLE_NOPUD_H
72183 #define _PGTABLE_NOPUD_H
72184
72185-#ifndef __ASSEMBLY__
72186-
72187 #define __PAGETABLE_PUD_FOLDED
72188
72189+#define PUD_SHIFT PGDIR_SHIFT
72190+#define PTRS_PER_PUD 1
72191+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72192+#define PUD_MASK (~(PUD_SIZE-1))
72193+
72194+#ifndef __ASSEMBLY__
72195+
72196 /*
72197 * Having the pud type consist of a pgd gets the size right, and allows
72198 * us to conceptually access the pgd entry that this pud is folded into
72199@@ -12,11 +17,6 @@
72200 */
72201 typedef struct { pgd_t pgd; } pud_t;
72202
72203-#define PUD_SHIFT PGDIR_SHIFT
72204-#define PTRS_PER_PUD 1
72205-#define PUD_SIZE (1UL << PUD_SHIFT)
72206-#define PUD_MASK (~(PUD_SIZE-1))
72207-
72208 /*
72209 * The "pgd_xxx()" functions here are trivial for a folded two-level
72210 * setup: the pud is never bad, and a pud always exists (as it's folded
72211@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72212 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72213
72214 #define pgd_populate(mm, pgd, pud) do { } while (0)
72215+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72216 /*
72217 * (puds are folded into pgds so this doesn't get actually called,
72218 * but the define is needed for a generic inline function.)
72219diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72220index 0807ddf..cd67747 100644
72221--- a/include/asm-generic/pgtable.h
72222+++ b/include/asm-generic/pgtable.h
72223@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72224 }
72225 #endif /* CONFIG_NUMA_BALANCING */
72226
72227+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72228+#ifdef CONFIG_PAX_KERNEXEC
72229+#error KERNEXEC requires pax_open_kernel
72230+#else
72231+static inline unsigned long pax_open_kernel(void) { return 0; }
72232+#endif
72233+#endif
72234+
72235+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72236+#ifdef CONFIG_PAX_KERNEXEC
72237+#error KERNEXEC requires pax_close_kernel
72238+#else
72239+static inline unsigned long pax_close_kernel(void) { return 0; }
72240+#endif
72241+#endif
72242+
72243 #endif /* CONFIG_MMU */
72244
72245 #endif /* !__ASSEMBLY__ */
72246diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72247index dc1269c..48a4f51 100644
72248--- a/include/asm-generic/uaccess.h
72249+++ b/include/asm-generic/uaccess.h
72250@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72251 return __clear_user(to, n);
72252 }
72253
72254+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72255+#ifdef CONFIG_PAX_MEMORY_UDEREF
72256+#error UDEREF requires pax_open_userland
72257+#else
72258+static inline unsigned long pax_open_userland(void) { return 0; }
72259+#endif
72260+#endif
72261+
72262+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72263+#ifdef CONFIG_PAX_MEMORY_UDEREF
72264+#error UDEREF requires pax_close_userland
72265+#else
72266+static inline unsigned long pax_close_userland(void) { return 0; }
72267+#endif
72268+#endif
72269+
72270 #endif /* __ASM_GENERIC_UACCESS_H */
72271diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72272index 69732d2..cbe16d9 100644
72273--- a/include/asm-generic/vmlinux.lds.h
72274+++ b/include/asm-generic/vmlinux.lds.h
72275@@ -227,6 +227,7 @@
72276 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72277 VMLINUX_SYMBOL(__start_rodata) = .; \
72278 *(.rodata) *(.rodata.*) \
72279+ *(.data..read_only) \
72280 *(__vermagic) /* Kernel version magic */ \
72281 . = ALIGN(8); \
72282 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72283@@ -710,17 +711,18 @@
72284 * section in the linker script will go there too. @phdr should have
72285 * a leading colon.
72286 *
72287- * Note that this macros defines __per_cpu_load as an absolute symbol.
72288+ * Note that this macros defines per_cpu_load as an absolute symbol.
72289 * If there is no need to put the percpu section at a predetermined
72290 * address, use PERCPU_SECTION.
72291 */
72292 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72293- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72294- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72295+ per_cpu_load = .; \
72296+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72297 - LOAD_OFFSET) { \
72298+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72299 PERCPU_INPUT(cacheline) \
72300 } phdr \
72301- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72302+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72303
72304 /**
72305 * PERCPU_SECTION - define output section for percpu area, simple version
72306diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72307index 418d270..bfd2794 100644
72308--- a/include/crypto/algapi.h
72309+++ b/include/crypto/algapi.h
72310@@ -34,7 +34,7 @@ struct crypto_type {
72311 unsigned int maskclear;
72312 unsigned int maskset;
72313 unsigned int tfmsize;
72314-};
72315+} __do_const;
72316
72317 struct crypto_instance {
72318 struct crypto_alg alg;
72319diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72320index 12083dc..39740ec 100644
72321--- a/include/drm/drmP.h
72322+++ b/include/drm/drmP.h
72323@@ -69,6 +69,7 @@
72324 #include <linux/workqueue.h>
72325 #include <linux/poll.h>
72326 #include <asm/pgalloc.h>
72327+#include <asm/local.h>
72328 #include <drm/drm.h>
72329 #include <drm/drm_sarea.h>
72330
72331@@ -293,10 +294,12 @@ do { \
72332 * \param cmd command.
72333 * \param arg argument.
72334 */
72335-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72336+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72337+ struct drm_file *file_priv);
72338+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72339 struct drm_file *file_priv);
72340
72341-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72342+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72343 unsigned long arg);
72344
72345 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72346@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72347 struct drm_ioctl_desc {
72348 unsigned int cmd;
72349 int flags;
72350- drm_ioctl_t *func;
72351+ drm_ioctl_t func;
72352 unsigned int cmd_drv;
72353 const char *name;
72354-};
72355+} __do_const;
72356
72357 /**
72358 * Creates a driver or general drm_ioctl_desc array entry for the given
72359@@ -1015,7 +1018,7 @@ struct drm_info_list {
72360 int (*show)(struct seq_file*, void*); /** show callback */
72361 u32 driver_features; /**< Required driver features for this entry */
72362 void *data;
72363-};
72364+} __do_const;
72365
72366 /**
72367 * debugfs node structure. This structure represents a debugfs file.
72368@@ -1088,7 +1091,7 @@ struct drm_device {
72369
72370 /** \name Usage Counters */
72371 /*@{ */
72372- int open_count; /**< Outstanding files open */
72373+ local_t open_count; /**< Outstanding files open */
72374 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72375 atomic_t vma_count; /**< Outstanding vma areas open */
72376 int buf_use; /**< Buffers in use -- cannot alloc */
72377@@ -1099,7 +1102,7 @@ struct drm_device {
72378 /*@{ */
72379 unsigned long counters;
72380 enum drm_stat_type types[15];
72381- atomic_t counts[15];
72382+ atomic_unchecked_t counts[15];
72383 /*@} */
72384
72385 struct list_head filelist;
72386diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72387index f43d556..94d9343 100644
72388--- a/include/drm/drm_crtc_helper.h
72389+++ b/include/drm/drm_crtc_helper.h
72390@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72391 struct drm_connector *connector);
72392 /* disable encoder when not in use - more explicit than dpms off */
72393 void (*disable)(struct drm_encoder *encoder);
72394-};
72395+} __no_const;
72396
72397 /**
72398 * drm_connector_helper_funcs - helper operations for connectors
72399diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72400index 72dcbe8..8db58d7 100644
72401--- a/include/drm/ttm/ttm_memory.h
72402+++ b/include/drm/ttm/ttm_memory.h
72403@@ -48,7 +48,7 @@
72404
72405 struct ttm_mem_shrink {
72406 int (*do_shrink) (struct ttm_mem_shrink *);
72407-};
72408+} __no_const;
72409
72410 /**
72411 * struct ttm_mem_global - Global memory accounting structure.
72412diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72413index 4b840e8..155d235 100644
72414--- a/include/keys/asymmetric-subtype.h
72415+++ b/include/keys/asymmetric-subtype.h
72416@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72417 /* Verify the signature on a key of this subtype (optional) */
72418 int (*verify_signature)(const struct key *key,
72419 const struct public_key_signature *sig);
72420-};
72421+} __do_const;
72422
72423 /**
72424 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72425diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72426index c1da539..1dcec55 100644
72427--- a/include/linux/atmdev.h
72428+++ b/include/linux/atmdev.h
72429@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72430 #endif
72431
72432 struct k_atm_aal_stats {
72433-#define __HANDLE_ITEM(i) atomic_t i
72434+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72435 __AAL_STAT_ITEMS
72436 #undef __HANDLE_ITEM
72437 };
72438@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72439 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72440 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72441 struct module *owner;
72442-};
72443+} __do_const ;
72444
72445 struct atmphy_ops {
72446 int (*start)(struct atm_dev *dev);
72447diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72448index 70cf138..0418ee2 100644
72449--- a/include/linux/binfmts.h
72450+++ b/include/linux/binfmts.h
72451@@ -73,8 +73,10 @@ struct linux_binfmt {
72452 int (*load_binary)(struct linux_binprm *);
72453 int (*load_shlib)(struct file *);
72454 int (*core_dump)(struct coredump_params *cprm);
72455+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72456+ void (*handle_mmap)(struct file *);
72457 unsigned long min_coredump; /* minimal dump size */
72458-};
72459+} __do_const;
72460
72461 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72462
72463diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72464index 2fdb4a4..54aad7e 100644
72465--- a/include/linux/blkdev.h
72466+++ b/include/linux/blkdev.h
72467@@ -1526,7 +1526,7 @@ struct block_device_operations {
72468 /* this callback is with swap_lock and sometimes page table lock held */
72469 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72470 struct module *owner;
72471-};
72472+} __do_const;
72473
72474 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72475 unsigned long);
72476diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72477index 7c2e030..b72475d 100644
72478--- a/include/linux/blktrace_api.h
72479+++ b/include/linux/blktrace_api.h
72480@@ -23,7 +23,7 @@ struct blk_trace {
72481 struct dentry *dir;
72482 struct dentry *dropped_file;
72483 struct dentry *msg_file;
72484- atomic_t dropped;
72485+ atomic_unchecked_t dropped;
72486 };
72487
72488 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72489diff --git a/include/linux/cache.h b/include/linux/cache.h
72490index 4c57065..40346da 100644
72491--- a/include/linux/cache.h
72492+++ b/include/linux/cache.h
72493@@ -16,6 +16,14 @@
72494 #define __read_mostly
72495 #endif
72496
72497+#ifndef __read_only
72498+#ifdef CONFIG_PAX_KERNEXEC
72499+#error KERNEXEC requires __read_only
72500+#else
72501+#define __read_only __read_mostly
72502+#endif
72503+#endif
72504+
72505 #ifndef ____cacheline_aligned
72506 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72507 #endif
72508diff --git a/include/linux/capability.h b/include/linux/capability.h
72509index d9a4f7f4..19f77d6 100644
72510--- a/include/linux/capability.h
72511+++ b/include/linux/capability.h
72512@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72513 extern bool nsown_capable(int cap);
72514 extern bool inode_capable(const struct inode *inode, int cap);
72515 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72516+extern bool capable_nolog(int cap);
72517+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72518+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72519
72520 /* audit system wants to get cap info from files as well */
72521 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72522
72523+extern int is_privileged_binary(const struct dentry *dentry);
72524+
72525 #endif /* !_LINUX_CAPABILITY_H */
72526diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72527index 8609d57..86e4d79 100644
72528--- a/include/linux/cdrom.h
72529+++ b/include/linux/cdrom.h
72530@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72531
72532 /* driver specifications */
72533 const int capability; /* capability flags */
72534- int n_minors; /* number of active minor devices */
72535 /* handle uniform packets for scsi type devices (scsi,atapi) */
72536 int (*generic_packet) (struct cdrom_device_info *,
72537 struct packet_command *);
72538diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72539index 4ce9056..86caac6 100644
72540--- a/include/linux/cleancache.h
72541+++ b/include/linux/cleancache.h
72542@@ -31,7 +31,7 @@ struct cleancache_ops {
72543 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72544 void (*invalidate_inode)(int, struct cleancache_filekey);
72545 void (*invalidate_fs)(int);
72546-};
72547+} __no_const;
72548
72549 extern struct cleancache_ops *
72550 cleancache_register_ops(struct cleancache_ops *ops);
72551diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72552index 1ec14a7..d0654a2 100644
72553--- a/include/linux/clk-provider.h
72554+++ b/include/linux/clk-provider.h
72555@@ -132,6 +132,7 @@ struct clk_ops {
72556 unsigned long);
72557 void (*init)(struct clk_hw *hw);
72558 };
72559+typedef struct clk_ops __no_const clk_ops_no_const;
72560
72561 /**
72562 * struct clk_init_data - holds init data that's common to all clocks and is
72563diff --git a/include/linux/compat.h b/include/linux/compat.h
72564index 7f0c1dd..206ac34 100644
72565--- a/include/linux/compat.h
72566+++ b/include/linux/compat.h
72567@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72568 compat_size_t __user *len_ptr);
72569
72570 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72571-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72572+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72573 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72574 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72575 compat_ssize_t msgsz, int msgflg);
72576@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72577 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72578 compat_ulong_t addr, compat_ulong_t data);
72579 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72580- compat_long_t addr, compat_long_t data);
72581+ compat_ulong_t addr, compat_ulong_t data);
72582
72583 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72584 /*
72585@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
72586
72587 int compat_restore_altstack(const compat_stack_t __user *uss);
72588 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
72589+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
72590
72591 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
72592 struct compat_timespec __user *interval);
72593diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72594index 842de22..7f3a41f 100644
72595--- a/include/linux/compiler-gcc4.h
72596+++ b/include/linux/compiler-gcc4.h
72597@@ -39,9 +39,29 @@
72598 # define __compiletime_warning(message) __attribute__((warning(message)))
72599 # define __compiletime_error(message) __attribute__((error(message)))
72600 #endif /* __CHECKER__ */
72601+
72602+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72603+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72604+#define __bos0(ptr) __bos((ptr), 0)
72605+#define __bos1(ptr) __bos((ptr), 1)
72606 #endif /* GCC_VERSION >= 40300 */
72607
72608 #if GCC_VERSION >= 40500
72609+
72610+#ifdef CONSTIFY_PLUGIN
72611+#define __no_const __attribute__((no_const))
72612+#define __do_const __attribute__((do_const))
72613+#endif
72614+
72615+#ifdef SIZE_OVERFLOW_PLUGIN
72616+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72617+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72618+#endif
72619+
72620+#ifdef LATENT_ENTROPY_PLUGIN
72621+#define __latent_entropy __attribute__((latent_entropy))
72622+#endif
72623+
72624 /*
72625 * Mark a position in code as unreachable. This can be used to
72626 * suppress control flow warnings after asm blocks that transfer
72627diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72628index 92669cd..1771a15 100644
72629--- a/include/linux/compiler.h
72630+++ b/include/linux/compiler.h
72631@@ -5,11 +5,14 @@
72632
72633 #ifdef __CHECKER__
72634 # define __user __attribute__((noderef, address_space(1)))
72635+# define __force_user __force __user
72636 # define __kernel __attribute__((address_space(0)))
72637+# define __force_kernel __force __kernel
72638 # define __safe __attribute__((safe))
72639 # define __force __attribute__((force))
72640 # define __nocast __attribute__((nocast))
72641 # define __iomem __attribute__((noderef, address_space(2)))
72642+# define __force_iomem __force __iomem
72643 # define __must_hold(x) __attribute__((context(x,1,1)))
72644 # define __acquires(x) __attribute__((context(x,0,1)))
72645 # define __releases(x) __attribute__((context(x,1,0)))
72646@@ -17,20 +20,37 @@
72647 # define __release(x) __context__(x,-1)
72648 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72649 # define __percpu __attribute__((noderef, address_space(3)))
72650+# define __force_percpu __force __percpu
72651 #ifdef CONFIG_SPARSE_RCU_POINTER
72652 # define __rcu __attribute__((noderef, address_space(4)))
72653+# define __force_rcu __force __rcu
72654 #else
72655 # define __rcu
72656+# define __force_rcu
72657 #endif
72658 extern void __chk_user_ptr(const volatile void __user *);
72659 extern void __chk_io_ptr(const volatile void __iomem *);
72660 #else
72661-# define __user
72662-# define __kernel
72663+# ifdef CHECKER_PLUGIN
72664+//# define __user
72665+//# define __force_user
72666+//# define __kernel
72667+//# define __force_kernel
72668+# else
72669+# ifdef STRUCTLEAK_PLUGIN
72670+# define __user __attribute__((user))
72671+# else
72672+# define __user
72673+# endif
72674+# define __force_user
72675+# define __kernel
72676+# define __force_kernel
72677+# endif
72678 # define __safe
72679 # define __force
72680 # define __nocast
72681 # define __iomem
72682+# define __force_iomem
72683 # define __chk_user_ptr(x) (void)0
72684 # define __chk_io_ptr(x) (void)0
72685 # define __builtin_warning(x, y...) (1)
72686@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72687 # define __release(x) (void)0
72688 # define __cond_lock(x,c) (c)
72689 # define __percpu
72690+# define __force_percpu
72691 # define __rcu
72692+# define __force_rcu
72693 #endif
72694
72695 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72696@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72697 # define __attribute_const__ /* unimplemented */
72698 #endif
72699
72700+#ifndef __no_const
72701+# define __no_const
72702+#endif
72703+
72704+#ifndef __do_const
72705+# define __do_const
72706+#endif
72707+
72708+#ifndef __size_overflow
72709+# define __size_overflow(...)
72710+#endif
72711+
72712+#ifndef __intentional_overflow
72713+# define __intentional_overflow(...)
72714+#endif
72715+
72716+#ifndef __latent_entropy
72717+# define __latent_entropy
72718+#endif
72719+
72720 /*
72721 * Tell gcc if a function is cold. The compiler will assume any path
72722 * directly leading to the call is unlikely.
72723@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72724 #define __cold
72725 #endif
72726
72727+#ifndef __alloc_size
72728+#define __alloc_size(...)
72729+#endif
72730+
72731+#ifndef __bos
72732+#define __bos(ptr, arg)
72733+#endif
72734+
72735+#ifndef __bos0
72736+#define __bos0(ptr)
72737+#endif
72738+
72739+#ifndef __bos1
72740+#define __bos1(ptr)
72741+#endif
72742+
72743 /* Simple shorthand for a section definition */
72744 #ifndef __section
72745 # define __section(S) __attribute__ ((__section__(#S)))
72746@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72747 * use is to mediate communication between process-level code and irq/NMI
72748 * handlers, all running on the same CPU.
72749 */
72750-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72751+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72752+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72753
72754 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72755 #ifdef CONFIG_KPROBES
72756diff --git a/include/linux/completion.h b/include/linux/completion.h
72757index 3cd574d..adce5fa 100644
72758--- a/include/linux/completion.h
72759+++ b/include/linux/completion.h
72760@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72761 extern void wait_for_completion(struct completion *);
72762 extern void wait_for_completion_io(struct completion *);
72763 extern int wait_for_completion_interruptible(struct completion *x);
72764-extern int wait_for_completion_killable(struct completion *x);
72765+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72766 extern unsigned long wait_for_completion_timeout(struct completion *x,
72767 unsigned long timeout);
72768 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72769 unsigned long timeout);
72770 extern long wait_for_completion_interruptible_timeout(
72771- struct completion *x, unsigned long timeout);
72772+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72773 extern long wait_for_completion_killable_timeout(
72774- struct completion *x, unsigned long timeout);
72775+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72776 extern bool try_wait_for_completion(struct completion *x);
72777 extern bool completion_done(struct completion *x);
72778
72779diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72780index 34025df..d94bbbc 100644
72781--- a/include/linux/configfs.h
72782+++ b/include/linux/configfs.h
72783@@ -125,7 +125,7 @@ struct configfs_attribute {
72784 const char *ca_name;
72785 struct module *ca_owner;
72786 umode_t ca_mode;
72787-};
72788+} __do_const;
72789
72790 /*
72791 * Users often need to create attribute structures for their configurable
72792diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72793index 90d5a15..950cb80 100644
72794--- a/include/linux/cpufreq.h
72795+++ b/include/linux/cpufreq.h
72796@@ -266,7 +266,7 @@ struct cpufreq_driver {
72797 int (*suspend) (struct cpufreq_policy *policy);
72798 int (*resume) (struct cpufreq_policy *policy);
72799 struct freq_attr **attr;
72800-};
72801+} __do_const;
72802
72803 /* flags */
72804
72805@@ -325,6 +325,7 @@ struct global_attr {
72806 ssize_t (*store)(struct kobject *a, struct attribute *b,
72807 const char *c, size_t count);
72808 };
72809+typedef struct global_attr __no_const global_attr_no_const;
72810
72811 #define define_one_global_ro(_name) \
72812 static struct global_attr _name = \
72813diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72814index 0bc4b74..973b368 100644
72815--- a/include/linux/cpuidle.h
72816+++ b/include/linux/cpuidle.h
72817@@ -52,7 +52,8 @@ struct cpuidle_state {
72818 int index);
72819
72820 int (*enter_dead) (struct cpuidle_device *dev, int index);
72821-};
72822+} __do_const;
72823+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72824
72825 /* Idle State Flags */
72826 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72827@@ -191,7 +192,7 @@ struct cpuidle_governor {
72828 void (*reflect) (struct cpuidle_device *dev, int index);
72829
72830 struct module *owner;
72831-};
72832+} __do_const;
72833
72834 #ifdef CONFIG_CPU_IDLE
72835
72836diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72837index d08e4d2..95fad61 100644
72838--- a/include/linux/cpumask.h
72839+++ b/include/linux/cpumask.h
72840@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72841 }
72842
72843 /* Valid inputs for n are -1 and 0. */
72844-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72845+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72846 {
72847 return n+1;
72848 }
72849
72850-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72851+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72852 {
72853 return n+1;
72854 }
72855
72856-static inline unsigned int cpumask_next_and(int n,
72857+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72858 const struct cpumask *srcp,
72859 const struct cpumask *andp)
72860 {
72861@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72862 *
72863 * Returns >= nr_cpu_ids if no further cpus set.
72864 */
72865-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72866+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72867 {
72868 /* -1 is a legal arg here. */
72869 if (n != -1)
72870@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72871 *
72872 * Returns >= nr_cpu_ids if no further cpus unset.
72873 */
72874-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72875+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72876 {
72877 /* -1 is a legal arg here. */
72878 if (n != -1)
72879@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72880 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72881 }
72882
72883-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72884+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72885 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72886
72887 /**
72888diff --git a/include/linux/cred.h b/include/linux/cred.h
72889index 04421e8..6bce4ef 100644
72890--- a/include/linux/cred.h
72891+++ b/include/linux/cred.h
72892@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72893 static inline void validate_process_creds(void)
72894 {
72895 }
72896+static inline void validate_task_creds(struct task_struct *task)
72897+{
72898+}
72899 #endif
72900
72901 /**
72902diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72903index b92eadf..b4ecdc1 100644
72904--- a/include/linux/crypto.h
72905+++ b/include/linux/crypto.h
72906@@ -373,7 +373,7 @@ struct cipher_tfm {
72907 const u8 *key, unsigned int keylen);
72908 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72909 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72910-};
72911+} __no_const;
72912
72913 struct hash_tfm {
72914 int (*init)(struct hash_desc *desc);
72915@@ -394,13 +394,13 @@ struct compress_tfm {
72916 int (*cot_decompress)(struct crypto_tfm *tfm,
72917 const u8 *src, unsigned int slen,
72918 u8 *dst, unsigned int *dlen);
72919-};
72920+} __no_const;
72921
72922 struct rng_tfm {
72923 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72924 unsigned int dlen);
72925 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72926-};
72927+} __no_const;
72928
72929 #define crt_ablkcipher crt_u.ablkcipher
72930 #define crt_aead crt_u.aead
72931diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72932index 653589e..4ef254a 100644
72933--- a/include/linux/ctype.h
72934+++ b/include/linux/ctype.h
72935@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72936 * Fast implementation of tolower() for internal usage. Do not use in your
72937 * code.
72938 */
72939-static inline char _tolower(const char c)
72940+static inline unsigned char _tolower(const unsigned char c)
72941 {
72942 return c | 0x20;
72943 }
72944diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72945index 7925bf0..d5143d2 100644
72946--- a/include/linux/decompress/mm.h
72947+++ b/include/linux/decompress/mm.h
72948@@ -77,7 +77,7 @@ static void free(void *where)
72949 * warnings when not needed (indeed large_malloc / large_free are not
72950 * needed by inflate */
72951
72952-#define malloc(a) kmalloc(a, GFP_KERNEL)
72953+#define malloc(a) kmalloc((a), GFP_KERNEL)
72954 #define free(a) kfree(a)
72955
72956 #define large_malloc(a) vmalloc(a)
72957diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72958index 5f1ab92..39c35ae 100644
72959--- a/include/linux/devfreq.h
72960+++ b/include/linux/devfreq.h
72961@@ -114,7 +114,7 @@ struct devfreq_governor {
72962 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72963 int (*event_handler)(struct devfreq *devfreq,
72964 unsigned int event, void *data);
72965-};
72966+} __do_const;
72967
72968 /**
72969 * struct devfreq - Device devfreq structure
72970diff --git a/include/linux/device.h b/include/linux/device.h
72971index 22b546a..a573dc9 100644
72972--- a/include/linux/device.h
72973+++ b/include/linux/device.h
72974@@ -305,7 +305,7 @@ struct subsys_interface {
72975 struct list_head node;
72976 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72977 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72978-};
72979+} __do_const;
72980
72981 int subsys_interface_register(struct subsys_interface *sif);
72982 void subsys_interface_unregister(struct subsys_interface *sif);
72983@@ -493,7 +493,7 @@ struct device_type {
72984 void (*release)(struct device *dev);
72985
72986 const struct dev_pm_ops *pm;
72987-};
72988+} __do_const;
72989
72990 /* interface for exporting device attributes */
72991 struct device_attribute {
72992@@ -503,11 +503,12 @@ struct device_attribute {
72993 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72994 const char *buf, size_t count);
72995 };
72996+typedef struct device_attribute __no_const device_attribute_no_const;
72997
72998 struct dev_ext_attribute {
72999 struct device_attribute attr;
73000 void *var;
73001-};
73002+} __do_const;
73003
73004 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
73005 char *buf);
73006diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
73007index 94af418..b1ca7a2 100644
73008--- a/include/linux/dma-mapping.h
73009+++ b/include/linux/dma-mapping.h
73010@@ -54,7 +54,7 @@ struct dma_map_ops {
73011 u64 (*get_required_mask)(struct device *dev);
73012 #endif
73013 int is_phys;
73014-};
73015+} __do_const;
73016
73017 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
73018
73019diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
73020index cb286b1..923d066 100644
73021--- a/include/linux/dmaengine.h
73022+++ b/include/linux/dmaengine.h
73023@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
73024 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
73025 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
73026
73027-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73028+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73029 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
73030-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73031+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73032 struct dma_pinned_list *pinned_list, struct page *page,
73033 unsigned int offset, size_t len);
73034
73035diff --git a/include/linux/efi.h b/include/linux/efi.h
73036index 5f8f176..62a0556 100644
73037--- a/include/linux/efi.h
73038+++ b/include/linux/efi.h
73039@@ -745,6 +745,7 @@ struct efivar_operations {
73040 efi_set_variable_t *set_variable;
73041 efi_query_variable_store_t *query_variable_store;
73042 };
73043+typedef struct efivar_operations __no_const efivar_operations_no_const;
73044
73045 struct efivars {
73046 /*
73047diff --git a/include/linux/elf.h b/include/linux/elf.h
73048index 40a3c0e..4c45a38 100644
73049--- a/include/linux/elf.h
73050+++ b/include/linux/elf.h
73051@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
73052 #define elf_note elf32_note
73053 #define elf_addr_t Elf32_Off
73054 #define Elf_Half Elf32_Half
73055+#define elf_dyn Elf32_Dyn
73056
73057 #else
73058
73059@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
73060 #define elf_note elf64_note
73061 #define elf_addr_t Elf64_Off
73062 #define Elf_Half Elf64_Half
73063+#define elf_dyn Elf64_Dyn
73064
73065 #endif
73066
73067diff --git a/include/linux/err.h b/include/linux/err.h
73068index 221fcfb..f29e5e2 100644
73069--- a/include/linux/err.h
73070+++ b/include/linux/err.h
73071@@ -19,12 +19,12 @@
73072
73073 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
73074
73075-static inline void * __must_check ERR_PTR(long error)
73076+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
73077 {
73078 return (void *) error;
73079 }
73080
73081-static inline long __must_check PTR_ERR(__force const void *ptr)
73082+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
73083 {
73084 return (long) ptr;
73085 }
73086diff --git a/include/linux/extcon.h b/include/linux/extcon.h
73087index fcb51c8..bdafcf6 100644
73088--- a/include/linux/extcon.h
73089+++ b/include/linux/extcon.h
73090@@ -134,7 +134,7 @@ struct extcon_dev {
73091 /* /sys/class/extcon/.../mutually_exclusive/... */
73092 struct attribute_group attr_g_muex;
73093 struct attribute **attrs_muex;
73094- struct device_attribute *d_attrs_muex;
73095+ device_attribute_no_const *d_attrs_muex;
73096 };
73097
73098 /**
73099diff --git a/include/linux/fb.h b/include/linux/fb.h
73100index ffac70a..ca3e711 100644
73101--- a/include/linux/fb.h
73102+++ b/include/linux/fb.h
73103@@ -304,7 +304,7 @@ struct fb_ops {
73104 /* called at KDB enter and leave time to prepare the console */
73105 int (*fb_debug_enter)(struct fb_info *info);
73106 int (*fb_debug_leave)(struct fb_info *info);
73107-};
73108+} __do_const;
73109
73110 #ifdef CONFIG_FB_TILEBLITTING
73111 #define FB_TILE_CURSOR_NONE 0
73112diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
73113index 085197b..0fa6f0b 100644
73114--- a/include/linux/fdtable.h
73115+++ b/include/linux/fdtable.h
73116@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
73117 void put_files_struct(struct files_struct *fs);
73118 void reset_files_struct(struct files_struct *);
73119 int unshare_files(struct files_struct **);
73120-struct files_struct *dup_fd(struct files_struct *, int *);
73121+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
73122 void do_close_on_exec(struct files_struct *);
73123 int iterate_fd(struct files_struct *, unsigned,
73124 int (*)(const void *, struct file *, unsigned),
73125diff --git a/include/linux/filter.h b/include/linux/filter.h
73126index a6ac848..a104a76 100644
73127--- a/include/linux/filter.h
73128+++ b/include/linux/filter.h
73129@@ -20,6 +20,7 @@ struct compat_sock_fprog {
73130
73131 struct sk_buff;
73132 struct sock;
73133+struct bpf_jit_work;
73134
73135 struct sk_filter
73136 {
73137@@ -27,6 +28,9 @@ struct sk_filter
73138 unsigned int len; /* Number of filter blocks */
73139 unsigned int (*bpf_func)(const struct sk_buff *skb,
73140 const struct sock_filter *filter);
73141+#ifdef CONFIG_BPF_JIT
73142+ struct bpf_jit_work *work;
73143+#endif
73144 struct rcu_head rcu;
73145 struct sock_filter insns[0];
73146 };
73147diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73148index 8293262..2b3b8bd 100644
73149--- a/include/linux/frontswap.h
73150+++ b/include/linux/frontswap.h
73151@@ -11,7 +11,7 @@ struct frontswap_ops {
73152 int (*load)(unsigned, pgoff_t, struct page *);
73153 void (*invalidate_page)(unsigned, pgoff_t);
73154 void (*invalidate_area)(unsigned);
73155-};
73156+} __no_const;
73157
73158 extern bool frontswap_enabled;
73159 extern struct frontswap_ops *
73160diff --git a/include/linux/fs.h b/include/linux/fs.h
73161index 9818747..788bfbd 100644
73162--- a/include/linux/fs.h
73163+++ b/include/linux/fs.h
73164@@ -1554,7 +1554,8 @@ struct file_operations {
73165 long (*fallocate)(struct file *file, int mode, loff_t offset,
73166 loff_t len);
73167 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73168-};
73169+} __do_const;
73170+typedef struct file_operations __no_const file_operations_no_const;
73171
73172 struct inode_operations {
73173 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73174@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
73175 return !IS_DEADDIR(inode);
73176 }
73177
73178+static inline bool is_sidechannel_device(const struct inode *inode)
73179+{
73180+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73181+ umode_t mode = inode->i_mode;
73182+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73183+#else
73184+ return false;
73185+#endif
73186+}
73187+
73188 #endif /* _LINUX_FS_H */
73189diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73190index 2b93a9a..855d94a 100644
73191--- a/include/linux/fs_struct.h
73192+++ b/include/linux/fs_struct.h
73193@@ -6,7 +6,7 @@
73194 #include <linux/seqlock.h>
73195
73196 struct fs_struct {
73197- int users;
73198+ atomic_t users;
73199 spinlock_t lock;
73200 seqcount_t seq;
73201 int umask;
73202diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73203index a9ff9a3..1ba1788 100644
73204--- a/include/linux/fscache-cache.h
73205+++ b/include/linux/fscache-cache.h
73206@@ -113,7 +113,7 @@ struct fscache_operation {
73207 fscache_operation_release_t release;
73208 };
73209
73210-extern atomic_t fscache_op_debug_id;
73211+extern atomic_unchecked_t fscache_op_debug_id;
73212 extern void fscache_op_work_func(struct work_struct *work);
73213
73214 extern void fscache_enqueue_operation(struct fscache_operation *);
73215@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73216 INIT_WORK(&op->work, fscache_op_work_func);
73217 atomic_set(&op->usage, 1);
73218 op->state = FSCACHE_OP_ST_INITIALISED;
73219- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73220+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73221 op->processor = processor;
73222 op->release = release;
73223 INIT_LIST_HEAD(&op->pend_link);
73224diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73225index 7a08623..4c07b0f 100644
73226--- a/include/linux/fscache.h
73227+++ b/include/linux/fscache.h
73228@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73229 * - this is mandatory for any object that may have data
73230 */
73231 void (*now_uncached)(void *cookie_netfs_data);
73232-};
73233+} __do_const;
73234
73235 /*
73236 * fscache cached network filesystem type
73237diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73238index 1c804b0..1432c2b 100644
73239--- a/include/linux/fsnotify.h
73240+++ b/include/linux/fsnotify.h
73241@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73242 struct inode *inode = file_inode(file);
73243 __u32 mask = FS_ACCESS;
73244
73245+ if (is_sidechannel_device(inode))
73246+ return;
73247+
73248 if (S_ISDIR(inode->i_mode))
73249 mask |= FS_ISDIR;
73250
73251@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73252 struct inode *inode = file_inode(file);
73253 __u32 mask = FS_MODIFY;
73254
73255+ if (is_sidechannel_device(inode))
73256+ return;
73257+
73258 if (S_ISDIR(inode->i_mode))
73259 mask |= FS_ISDIR;
73260
73261@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73262 */
73263 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73264 {
73265- return kstrdup(name, GFP_KERNEL);
73266+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73267 }
73268
73269 /*
73270diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73271index 9f3c275..8bdff5d 100644
73272--- a/include/linux/genhd.h
73273+++ b/include/linux/genhd.h
73274@@ -194,7 +194,7 @@ struct gendisk {
73275 struct kobject *slave_dir;
73276
73277 struct timer_rand_state *random;
73278- atomic_t sync_io; /* RAID */
73279+ atomic_unchecked_t sync_io; /* RAID */
73280 struct disk_events *ev;
73281 #ifdef CONFIG_BLK_DEV_INTEGRITY
73282 struct blk_integrity *integrity;
73283@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73284 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73285
73286 /* drivers/char/random.c */
73287-extern void add_disk_randomness(struct gendisk *disk);
73288+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73289 extern void rand_initialize_disk(struct gendisk *disk);
73290
73291 static inline sector_t get_start_sect(struct block_device *bdev)
73292diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73293index 023bc34..b02b46a 100644
73294--- a/include/linux/genl_magic_func.h
73295+++ b/include/linux/genl_magic_func.h
73296@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73297 },
73298
73299 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73300-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73301+static struct genl_ops ZZZ_genl_ops[] = {
73302 #include GENL_MAGIC_INCLUDE_FILE
73303 };
73304
73305diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73306index 9b4dd49..61fd41d 100644
73307--- a/include/linux/gfp.h
73308+++ b/include/linux/gfp.h
73309@@ -35,6 +35,13 @@ struct vm_area_struct;
73310 #define ___GFP_NO_KSWAPD 0x400000u
73311 #define ___GFP_OTHER_NODE 0x800000u
73312 #define ___GFP_WRITE 0x1000000u
73313+
73314+#ifdef CONFIG_PAX_USERCOPY_SLABS
73315+#define ___GFP_USERCOPY 0x2000000u
73316+#else
73317+#define ___GFP_USERCOPY 0
73318+#endif
73319+
73320 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73321
73322 /*
73323@@ -92,6 +99,7 @@ struct vm_area_struct;
73324 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73325 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73326 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73327+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73328
73329 /*
73330 * This may seem redundant, but it's a way of annotating false positives vs.
73331@@ -99,7 +107,7 @@ struct vm_area_struct;
73332 */
73333 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73334
73335-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73336+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73337 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73338
73339 /* This equals 0, but use constants in case they ever change */
73340@@ -153,6 +161,8 @@ struct vm_area_struct;
73341 /* 4GB DMA on some platforms */
73342 #define GFP_DMA32 __GFP_DMA32
73343
73344+#define GFP_USERCOPY __GFP_USERCOPY
73345+
73346 /* Convert GFP flags to their corresponding migrate type */
73347 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73348 {
73349diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73350new file mode 100644
73351index 0000000..ebe6d72
73352--- /dev/null
73353+++ b/include/linux/gracl.h
73354@@ -0,0 +1,319 @@
73355+#ifndef GR_ACL_H
73356+#define GR_ACL_H
73357+
73358+#include <linux/grdefs.h>
73359+#include <linux/resource.h>
73360+#include <linux/capability.h>
73361+#include <linux/dcache.h>
73362+#include <asm/resource.h>
73363+
73364+/* Major status information */
73365+
73366+#define GR_VERSION "grsecurity 2.9.1"
73367+#define GRSECURITY_VERSION 0x2901
73368+
73369+enum {
73370+ GR_SHUTDOWN = 0,
73371+ GR_ENABLE = 1,
73372+ GR_SPROLE = 2,
73373+ GR_RELOAD = 3,
73374+ GR_SEGVMOD = 4,
73375+ GR_STATUS = 5,
73376+ GR_UNSPROLE = 6,
73377+ GR_PASSSET = 7,
73378+ GR_SPROLEPAM = 8,
73379+};
73380+
73381+/* Password setup definitions
73382+ * kernel/grhash.c */
73383+enum {
73384+ GR_PW_LEN = 128,
73385+ GR_SALT_LEN = 16,
73386+ GR_SHA_LEN = 32,
73387+};
73388+
73389+enum {
73390+ GR_SPROLE_LEN = 64,
73391+};
73392+
73393+enum {
73394+ GR_NO_GLOB = 0,
73395+ GR_REG_GLOB,
73396+ GR_CREATE_GLOB
73397+};
73398+
73399+#define GR_NLIMITS 32
73400+
73401+/* Begin Data Structures */
73402+
73403+struct sprole_pw {
73404+ unsigned char *rolename;
73405+ unsigned char salt[GR_SALT_LEN];
73406+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73407+};
73408+
73409+struct name_entry {
73410+ __u32 key;
73411+ ino_t inode;
73412+ dev_t device;
73413+ char *name;
73414+ __u16 len;
73415+ __u8 deleted;
73416+ struct name_entry *prev;
73417+ struct name_entry *next;
73418+};
73419+
73420+struct inodev_entry {
73421+ struct name_entry *nentry;
73422+ struct inodev_entry *prev;
73423+ struct inodev_entry *next;
73424+};
73425+
73426+struct acl_role_db {
73427+ struct acl_role_label **r_hash;
73428+ __u32 r_size;
73429+};
73430+
73431+struct inodev_db {
73432+ struct inodev_entry **i_hash;
73433+ __u32 i_size;
73434+};
73435+
73436+struct name_db {
73437+ struct name_entry **n_hash;
73438+ __u32 n_size;
73439+};
73440+
73441+struct crash_uid {
73442+ uid_t uid;
73443+ unsigned long expires;
73444+};
73445+
73446+struct gr_hash_struct {
73447+ void **table;
73448+ void **nametable;
73449+ void *first;
73450+ __u32 table_size;
73451+ __u32 used_size;
73452+ int type;
73453+};
73454+
73455+/* Userspace Grsecurity ACL data structures */
73456+
73457+struct acl_subject_label {
73458+ char *filename;
73459+ ino_t inode;
73460+ dev_t device;
73461+ __u32 mode;
73462+ kernel_cap_t cap_mask;
73463+ kernel_cap_t cap_lower;
73464+ kernel_cap_t cap_invert_audit;
73465+
73466+ struct rlimit res[GR_NLIMITS];
73467+ __u32 resmask;
73468+
73469+ __u8 user_trans_type;
73470+ __u8 group_trans_type;
73471+ uid_t *user_transitions;
73472+ gid_t *group_transitions;
73473+ __u16 user_trans_num;
73474+ __u16 group_trans_num;
73475+
73476+ __u32 sock_families[2];
73477+ __u32 ip_proto[8];
73478+ __u32 ip_type;
73479+ struct acl_ip_label **ips;
73480+ __u32 ip_num;
73481+ __u32 inaddr_any_override;
73482+
73483+ __u32 crashes;
73484+ unsigned long expires;
73485+
73486+ struct acl_subject_label *parent_subject;
73487+ struct gr_hash_struct *hash;
73488+ struct acl_subject_label *prev;
73489+ struct acl_subject_label *next;
73490+
73491+ struct acl_object_label **obj_hash;
73492+ __u32 obj_hash_size;
73493+ __u16 pax_flags;
73494+};
73495+
73496+struct role_allowed_ip {
73497+ __u32 addr;
73498+ __u32 netmask;
73499+
73500+ struct role_allowed_ip *prev;
73501+ struct role_allowed_ip *next;
73502+};
73503+
73504+struct role_transition {
73505+ char *rolename;
73506+
73507+ struct role_transition *prev;
73508+ struct role_transition *next;
73509+};
73510+
73511+struct acl_role_label {
73512+ char *rolename;
73513+ uid_t uidgid;
73514+ __u16 roletype;
73515+
73516+ __u16 auth_attempts;
73517+ unsigned long expires;
73518+
73519+ struct acl_subject_label *root_label;
73520+ struct gr_hash_struct *hash;
73521+
73522+ struct acl_role_label *prev;
73523+ struct acl_role_label *next;
73524+
73525+ struct role_transition *transitions;
73526+ struct role_allowed_ip *allowed_ips;
73527+ uid_t *domain_children;
73528+ __u16 domain_child_num;
73529+
73530+ umode_t umask;
73531+
73532+ struct acl_subject_label **subj_hash;
73533+ __u32 subj_hash_size;
73534+};
73535+
73536+struct user_acl_role_db {
73537+ struct acl_role_label **r_table;
73538+ __u32 num_pointers; /* Number of allocations to track */
73539+ __u32 num_roles; /* Number of roles */
73540+ __u32 num_domain_children; /* Number of domain children */
73541+ __u32 num_subjects; /* Number of subjects */
73542+ __u32 num_objects; /* Number of objects */
73543+};
73544+
73545+struct acl_object_label {
73546+ char *filename;
73547+ ino_t inode;
73548+ dev_t device;
73549+ __u32 mode;
73550+
73551+ struct acl_subject_label *nested;
73552+ struct acl_object_label *globbed;
73553+
73554+ /* next two structures not used */
73555+
73556+ struct acl_object_label *prev;
73557+ struct acl_object_label *next;
73558+};
73559+
73560+struct acl_ip_label {
73561+ char *iface;
73562+ __u32 addr;
73563+ __u32 netmask;
73564+ __u16 low, high;
73565+ __u8 mode;
73566+ __u32 type;
73567+ __u32 proto[8];
73568+
73569+ /* next two structures not used */
73570+
73571+ struct acl_ip_label *prev;
73572+ struct acl_ip_label *next;
73573+};
73574+
73575+struct gr_arg {
73576+ struct user_acl_role_db role_db;
73577+ unsigned char pw[GR_PW_LEN];
73578+ unsigned char salt[GR_SALT_LEN];
73579+ unsigned char sum[GR_SHA_LEN];
73580+ unsigned char sp_role[GR_SPROLE_LEN];
73581+ struct sprole_pw *sprole_pws;
73582+ dev_t segv_device;
73583+ ino_t segv_inode;
73584+ uid_t segv_uid;
73585+ __u16 num_sprole_pws;
73586+ __u16 mode;
73587+};
73588+
73589+struct gr_arg_wrapper {
73590+ struct gr_arg *arg;
73591+ __u32 version;
73592+ __u32 size;
73593+};
73594+
73595+struct subject_map {
73596+ struct acl_subject_label *user;
73597+ struct acl_subject_label *kernel;
73598+ struct subject_map *prev;
73599+ struct subject_map *next;
73600+};
73601+
73602+struct acl_subj_map_db {
73603+ struct subject_map **s_hash;
73604+ __u32 s_size;
73605+};
73606+
73607+/* End Data Structures Section */
73608+
73609+/* Hash functions generated by empirical testing by Brad Spengler
73610+ Makes good use of the low bits of the inode. Generally 0-1 times
73611+ in loop for successful match. 0-3 for unsuccessful match.
73612+ Shift/add algorithm with modulus of table size and an XOR*/
73613+
73614+static __inline__ unsigned int
73615+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73616+{
73617+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73618+}
73619+
73620+ static __inline__ unsigned int
73621+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73622+{
73623+ return ((const unsigned long)userp % sz);
73624+}
73625+
73626+static __inline__ unsigned int
73627+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73628+{
73629+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73630+}
73631+
73632+static __inline__ unsigned int
73633+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73634+{
73635+ return full_name_hash((const unsigned char *)name, len) % sz;
73636+}
73637+
73638+#define FOR_EACH_ROLE_START(role) \
73639+ role = role_list; \
73640+ while (role) {
73641+
73642+#define FOR_EACH_ROLE_END(role) \
73643+ role = role->prev; \
73644+ }
73645+
73646+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73647+ subj = NULL; \
73648+ iter = 0; \
73649+ while (iter < role->subj_hash_size) { \
73650+ if (subj == NULL) \
73651+ subj = role->subj_hash[iter]; \
73652+ if (subj == NULL) { \
73653+ iter++; \
73654+ continue; \
73655+ }
73656+
73657+#define FOR_EACH_SUBJECT_END(subj,iter) \
73658+ subj = subj->next; \
73659+ if (subj == NULL) \
73660+ iter++; \
73661+ }
73662+
73663+
73664+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73665+ subj = role->hash->first; \
73666+ while (subj != NULL) {
73667+
73668+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73669+ subj = subj->next; \
73670+ }
73671+
73672+#endif
73673+
73674diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73675new file mode 100644
73676index 0000000..33ebd1f
73677--- /dev/null
73678+++ b/include/linux/gracl_compat.h
73679@@ -0,0 +1,156 @@
73680+#ifndef GR_ACL_COMPAT_H
73681+#define GR_ACL_COMPAT_H
73682+
73683+#include <linux/resource.h>
73684+#include <asm/resource.h>
73685+
73686+struct sprole_pw_compat {
73687+ compat_uptr_t rolename;
73688+ unsigned char salt[GR_SALT_LEN];
73689+ unsigned char sum[GR_SHA_LEN];
73690+};
73691+
73692+struct gr_hash_struct_compat {
73693+ compat_uptr_t table;
73694+ compat_uptr_t nametable;
73695+ compat_uptr_t first;
73696+ __u32 table_size;
73697+ __u32 used_size;
73698+ int type;
73699+};
73700+
73701+struct acl_subject_label_compat {
73702+ compat_uptr_t filename;
73703+ compat_ino_t inode;
73704+ __u32 device;
73705+ __u32 mode;
73706+ kernel_cap_t cap_mask;
73707+ kernel_cap_t cap_lower;
73708+ kernel_cap_t cap_invert_audit;
73709+
73710+ struct compat_rlimit res[GR_NLIMITS];
73711+ __u32 resmask;
73712+
73713+ __u8 user_trans_type;
73714+ __u8 group_trans_type;
73715+ compat_uptr_t user_transitions;
73716+ compat_uptr_t group_transitions;
73717+ __u16 user_trans_num;
73718+ __u16 group_trans_num;
73719+
73720+ __u32 sock_families[2];
73721+ __u32 ip_proto[8];
73722+ __u32 ip_type;
73723+ compat_uptr_t ips;
73724+ __u32 ip_num;
73725+ __u32 inaddr_any_override;
73726+
73727+ __u32 crashes;
73728+ compat_ulong_t expires;
73729+
73730+ compat_uptr_t parent_subject;
73731+ compat_uptr_t hash;
73732+ compat_uptr_t prev;
73733+ compat_uptr_t next;
73734+
73735+ compat_uptr_t obj_hash;
73736+ __u32 obj_hash_size;
73737+ __u16 pax_flags;
73738+};
73739+
73740+struct role_allowed_ip_compat {
73741+ __u32 addr;
73742+ __u32 netmask;
73743+
73744+ compat_uptr_t prev;
73745+ compat_uptr_t next;
73746+};
73747+
73748+struct role_transition_compat {
73749+ compat_uptr_t rolename;
73750+
73751+ compat_uptr_t prev;
73752+ compat_uptr_t next;
73753+};
73754+
73755+struct acl_role_label_compat {
73756+ compat_uptr_t rolename;
73757+ uid_t uidgid;
73758+ __u16 roletype;
73759+
73760+ __u16 auth_attempts;
73761+ compat_ulong_t expires;
73762+
73763+ compat_uptr_t root_label;
73764+ compat_uptr_t hash;
73765+
73766+ compat_uptr_t prev;
73767+ compat_uptr_t next;
73768+
73769+ compat_uptr_t transitions;
73770+ compat_uptr_t allowed_ips;
73771+ compat_uptr_t domain_children;
73772+ __u16 domain_child_num;
73773+
73774+ umode_t umask;
73775+
73776+ compat_uptr_t subj_hash;
73777+ __u32 subj_hash_size;
73778+};
73779+
73780+struct user_acl_role_db_compat {
73781+ compat_uptr_t r_table;
73782+ __u32 num_pointers;
73783+ __u32 num_roles;
73784+ __u32 num_domain_children;
73785+ __u32 num_subjects;
73786+ __u32 num_objects;
73787+};
73788+
73789+struct acl_object_label_compat {
73790+ compat_uptr_t filename;
73791+ compat_ino_t inode;
73792+ __u32 device;
73793+ __u32 mode;
73794+
73795+ compat_uptr_t nested;
73796+ compat_uptr_t globbed;
73797+
73798+ compat_uptr_t prev;
73799+ compat_uptr_t next;
73800+};
73801+
73802+struct acl_ip_label_compat {
73803+ compat_uptr_t iface;
73804+ __u32 addr;
73805+ __u32 netmask;
73806+ __u16 low, high;
73807+ __u8 mode;
73808+ __u32 type;
73809+ __u32 proto[8];
73810+
73811+ compat_uptr_t prev;
73812+ compat_uptr_t next;
73813+};
73814+
73815+struct gr_arg_compat {
73816+ struct user_acl_role_db_compat role_db;
73817+ unsigned char pw[GR_PW_LEN];
73818+ unsigned char salt[GR_SALT_LEN];
73819+ unsigned char sum[GR_SHA_LEN];
73820+ unsigned char sp_role[GR_SPROLE_LEN];
73821+ compat_uptr_t sprole_pws;
73822+ __u32 segv_device;
73823+ compat_ino_t segv_inode;
73824+ uid_t segv_uid;
73825+ __u16 num_sprole_pws;
73826+ __u16 mode;
73827+};
73828+
73829+struct gr_arg_wrapper_compat {
73830+ compat_uptr_t arg;
73831+ __u32 version;
73832+ __u32 size;
73833+};
73834+
73835+#endif
73836diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73837new file mode 100644
73838index 0000000..323ecf2
73839--- /dev/null
73840+++ b/include/linux/gralloc.h
73841@@ -0,0 +1,9 @@
73842+#ifndef __GRALLOC_H
73843+#define __GRALLOC_H
73844+
73845+void acl_free_all(void);
73846+int acl_alloc_stack_init(unsigned long size);
73847+void *acl_alloc(unsigned long len);
73848+void *acl_alloc_num(unsigned long num, unsigned long len);
73849+
73850+#endif
73851diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73852new file mode 100644
73853index 0000000..be66033
73854--- /dev/null
73855+++ b/include/linux/grdefs.h
73856@@ -0,0 +1,140 @@
73857+#ifndef GRDEFS_H
73858+#define GRDEFS_H
73859+
73860+/* Begin grsecurity status declarations */
73861+
73862+enum {
73863+ GR_READY = 0x01,
73864+ GR_STATUS_INIT = 0x00 // disabled state
73865+};
73866+
73867+/* Begin ACL declarations */
73868+
73869+/* Role flags */
73870+
73871+enum {
73872+ GR_ROLE_USER = 0x0001,
73873+ GR_ROLE_GROUP = 0x0002,
73874+ GR_ROLE_DEFAULT = 0x0004,
73875+ GR_ROLE_SPECIAL = 0x0008,
73876+ GR_ROLE_AUTH = 0x0010,
73877+ GR_ROLE_NOPW = 0x0020,
73878+ GR_ROLE_GOD = 0x0040,
73879+ GR_ROLE_LEARN = 0x0080,
73880+ GR_ROLE_TPE = 0x0100,
73881+ GR_ROLE_DOMAIN = 0x0200,
73882+ GR_ROLE_PAM = 0x0400,
73883+ GR_ROLE_PERSIST = 0x0800
73884+};
73885+
73886+/* ACL Subject and Object mode flags */
73887+enum {
73888+ GR_DELETED = 0x80000000
73889+};
73890+
73891+/* ACL Object-only mode flags */
73892+enum {
73893+ GR_READ = 0x00000001,
73894+ GR_APPEND = 0x00000002,
73895+ GR_WRITE = 0x00000004,
73896+ GR_EXEC = 0x00000008,
73897+ GR_FIND = 0x00000010,
73898+ GR_INHERIT = 0x00000020,
73899+ GR_SETID = 0x00000040,
73900+ GR_CREATE = 0x00000080,
73901+ GR_DELETE = 0x00000100,
73902+ GR_LINK = 0x00000200,
73903+ GR_AUDIT_READ = 0x00000400,
73904+ GR_AUDIT_APPEND = 0x00000800,
73905+ GR_AUDIT_WRITE = 0x00001000,
73906+ GR_AUDIT_EXEC = 0x00002000,
73907+ GR_AUDIT_FIND = 0x00004000,
73908+ GR_AUDIT_INHERIT= 0x00008000,
73909+ GR_AUDIT_SETID = 0x00010000,
73910+ GR_AUDIT_CREATE = 0x00020000,
73911+ GR_AUDIT_DELETE = 0x00040000,
73912+ GR_AUDIT_LINK = 0x00080000,
73913+ GR_PTRACERD = 0x00100000,
73914+ GR_NOPTRACE = 0x00200000,
73915+ GR_SUPPRESS = 0x00400000,
73916+ GR_NOLEARN = 0x00800000,
73917+ GR_INIT_TRANSFER= 0x01000000
73918+};
73919+
73920+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73921+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73922+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73923+
73924+/* ACL subject-only mode flags */
73925+enum {
73926+ GR_KILL = 0x00000001,
73927+ GR_VIEW = 0x00000002,
73928+ GR_PROTECTED = 0x00000004,
73929+ GR_LEARN = 0x00000008,
73930+ GR_OVERRIDE = 0x00000010,
73931+ /* just a placeholder, this mode is only used in userspace */
73932+ GR_DUMMY = 0x00000020,
73933+ GR_PROTSHM = 0x00000040,
73934+ GR_KILLPROC = 0x00000080,
73935+ GR_KILLIPPROC = 0x00000100,
73936+ /* just a placeholder, this mode is only used in userspace */
73937+ GR_NOTROJAN = 0x00000200,
73938+ GR_PROTPROCFD = 0x00000400,
73939+ GR_PROCACCT = 0x00000800,
73940+ GR_RELAXPTRACE = 0x00001000,
73941+ //GR_NESTED = 0x00002000,
73942+ GR_INHERITLEARN = 0x00004000,
73943+ GR_PROCFIND = 0x00008000,
73944+ GR_POVERRIDE = 0x00010000,
73945+ GR_KERNELAUTH = 0x00020000,
73946+ GR_ATSECURE = 0x00040000,
73947+ GR_SHMEXEC = 0x00080000
73948+};
73949+
73950+enum {
73951+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73952+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73953+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73954+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73955+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73956+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73957+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73958+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73959+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73960+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73961+};
73962+
73963+enum {
73964+ GR_ID_USER = 0x01,
73965+ GR_ID_GROUP = 0x02,
73966+};
73967+
73968+enum {
73969+ GR_ID_ALLOW = 0x01,
73970+ GR_ID_DENY = 0x02,
73971+};
73972+
73973+#define GR_CRASH_RES 31
73974+#define GR_UIDTABLE_MAX 500
73975+
73976+/* begin resource learning section */
73977+enum {
73978+ GR_RLIM_CPU_BUMP = 60,
73979+ GR_RLIM_FSIZE_BUMP = 50000,
73980+ GR_RLIM_DATA_BUMP = 10000,
73981+ GR_RLIM_STACK_BUMP = 1000,
73982+ GR_RLIM_CORE_BUMP = 10000,
73983+ GR_RLIM_RSS_BUMP = 500000,
73984+ GR_RLIM_NPROC_BUMP = 1,
73985+ GR_RLIM_NOFILE_BUMP = 5,
73986+ GR_RLIM_MEMLOCK_BUMP = 50000,
73987+ GR_RLIM_AS_BUMP = 500000,
73988+ GR_RLIM_LOCKS_BUMP = 2,
73989+ GR_RLIM_SIGPENDING_BUMP = 5,
73990+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73991+ GR_RLIM_NICE_BUMP = 1,
73992+ GR_RLIM_RTPRIO_BUMP = 1,
73993+ GR_RLIM_RTTIME_BUMP = 1000000
73994+};
73995+
73996+#endif
73997diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73998new file mode 100644
73999index 0000000..e337683
74000--- /dev/null
74001+++ b/include/linux/grinternal.h
74002@@ -0,0 +1,229 @@
74003+#ifndef __GRINTERNAL_H
74004+#define __GRINTERNAL_H
74005+
74006+#ifdef CONFIG_GRKERNSEC
74007+
74008+#include <linux/fs.h>
74009+#include <linux/mnt_namespace.h>
74010+#include <linux/nsproxy.h>
74011+#include <linux/gracl.h>
74012+#include <linux/grdefs.h>
74013+#include <linux/grmsg.h>
74014+
74015+void gr_add_learn_entry(const char *fmt, ...)
74016+ __attribute__ ((format (printf, 1, 2)));
74017+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
74018+ const struct vfsmount *mnt);
74019+__u32 gr_check_create(const struct dentry *new_dentry,
74020+ const struct dentry *parent,
74021+ const struct vfsmount *mnt, const __u32 mode);
74022+int gr_check_protected_task(const struct task_struct *task);
74023+__u32 to_gr_audit(const __u32 reqmode);
74024+int gr_set_acls(const int type);
74025+int gr_apply_subject_to_task(struct task_struct *task);
74026+int gr_acl_is_enabled(void);
74027+char gr_roletype_to_char(void);
74028+
74029+void gr_handle_alertkill(struct task_struct *task);
74030+char *gr_to_filename(const struct dentry *dentry,
74031+ const struct vfsmount *mnt);
74032+char *gr_to_filename1(const struct dentry *dentry,
74033+ const struct vfsmount *mnt);
74034+char *gr_to_filename2(const struct dentry *dentry,
74035+ const struct vfsmount *mnt);
74036+char *gr_to_filename3(const struct dentry *dentry,
74037+ const struct vfsmount *mnt);
74038+
74039+extern int grsec_enable_ptrace_readexec;
74040+extern int grsec_enable_harden_ptrace;
74041+extern int grsec_enable_link;
74042+extern int grsec_enable_fifo;
74043+extern int grsec_enable_execve;
74044+extern int grsec_enable_shm;
74045+extern int grsec_enable_execlog;
74046+extern int grsec_enable_signal;
74047+extern int grsec_enable_audit_ptrace;
74048+extern int grsec_enable_forkfail;
74049+extern int grsec_enable_time;
74050+extern int grsec_enable_rofs;
74051+extern int grsec_deny_new_usb;
74052+extern int grsec_enable_chroot_shmat;
74053+extern int grsec_enable_chroot_mount;
74054+extern int grsec_enable_chroot_double;
74055+extern int grsec_enable_chroot_pivot;
74056+extern int grsec_enable_chroot_chdir;
74057+extern int grsec_enable_chroot_chmod;
74058+extern int grsec_enable_chroot_mknod;
74059+extern int grsec_enable_chroot_fchdir;
74060+extern int grsec_enable_chroot_nice;
74061+extern int grsec_enable_chroot_execlog;
74062+extern int grsec_enable_chroot_caps;
74063+extern int grsec_enable_chroot_sysctl;
74064+extern int grsec_enable_chroot_unix;
74065+extern int grsec_enable_symlinkown;
74066+extern kgid_t grsec_symlinkown_gid;
74067+extern int grsec_enable_tpe;
74068+extern kgid_t grsec_tpe_gid;
74069+extern int grsec_enable_tpe_all;
74070+extern int grsec_enable_tpe_invert;
74071+extern int grsec_enable_socket_all;
74072+extern kgid_t grsec_socket_all_gid;
74073+extern int grsec_enable_socket_client;
74074+extern kgid_t grsec_socket_client_gid;
74075+extern int grsec_enable_socket_server;
74076+extern kgid_t grsec_socket_server_gid;
74077+extern kgid_t grsec_audit_gid;
74078+extern int grsec_enable_group;
74079+extern int grsec_enable_log_rwxmaps;
74080+extern int grsec_enable_mount;
74081+extern int grsec_enable_chdir;
74082+extern int grsec_resource_logging;
74083+extern int grsec_enable_blackhole;
74084+extern int grsec_lastack_retries;
74085+extern int grsec_enable_brute;
74086+extern int grsec_lock;
74087+
74088+extern spinlock_t grsec_alert_lock;
74089+extern unsigned long grsec_alert_wtime;
74090+extern unsigned long grsec_alert_fyet;
74091+
74092+extern spinlock_t grsec_audit_lock;
74093+
74094+extern rwlock_t grsec_exec_file_lock;
74095+
74096+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
74097+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
74098+ (tsk)->exec_file->f_path.mnt) : "/")
74099+
74100+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
74101+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
74102+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74103+
74104+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
74105+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
74106+ (tsk)->exec_file->f_path.mnt) : "/")
74107+
74108+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
74109+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
74110+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74111+
74112+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
74113+
74114+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
74115+
74116+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
74117+{
74118+ if (file1 && file2) {
74119+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
74120+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
74121+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
74122+ return true;
74123+ }
74124+
74125+ return false;
74126+}
74127+
74128+#define GR_CHROOT_CAPS {{ \
74129+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
74130+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
74131+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
74132+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
74133+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
74134+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
74135+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
74136+
74137+#define security_learn(normal_msg,args...) \
74138+({ \
74139+ read_lock(&grsec_exec_file_lock); \
74140+ gr_add_learn_entry(normal_msg "\n", ## args); \
74141+ read_unlock(&grsec_exec_file_lock); \
74142+})
74143+
74144+enum {
74145+ GR_DO_AUDIT,
74146+ GR_DONT_AUDIT,
74147+ /* used for non-audit messages that we shouldn't kill the task on */
74148+ GR_DONT_AUDIT_GOOD
74149+};
74150+
74151+enum {
74152+ GR_TTYSNIFF,
74153+ GR_RBAC,
74154+ GR_RBAC_STR,
74155+ GR_STR_RBAC,
74156+ GR_RBAC_MODE2,
74157+ GR_RBAC_MODE3,
74158+ GR_FILENAME,
74159+ GR_SYSCTL_HIDDEN,
74160+ GR_NOARGS,
74161+ GR_ONE_INT,
74162+ GR_ONE_INT_TWO_STR,
74163+ GR_ONE_STR,
74164+ GR_STR_INT,
74165+ GR_TWO_STR_INT,
74166+ GR_TWO_INT,
74167+ GR_TWO_U64,
74168+ GR_THREE_INT,
74169+ GR_FIVE_INT_TWO_STR,
74170+ GR_TWO_STR,
74171+ GR_THREE_STR,
74172+ GR_FOUR_STR,
74173+ GR_STR_FILENAME,
74174+ GR_FILENAME_STR,
74175+ GR_FILENAME_TWO_INT,
74176+ GR_FILENAME_TWO_INT_STR,
74177+ GR_TEXTREL,
74178+ GR_PTRACE,
74179+ GR_RESOURCE,
74180+ GR_CAP,
74181+ GR_SIG,
74182+ GR_SIG2,
74183+ GR_CRASH1,
74184+ GR_CRASH2,
74185+ GR_PSACCT,
74186+ GR_RWXMAP,
74187+ GR_RWXMAPVMA
74188+};
74189+
74190+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74191+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74192+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74193+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74194+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74195+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74196+#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)
74197+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74198+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74199+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74200+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74201+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74202+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74203+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74204+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74205+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74206+#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)
74207+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74208+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74209+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74210+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74211+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74212+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74213+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74214+#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)
74215+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74216+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74217+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74218+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74219+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74220+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74221+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74222+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74223+#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)
74224+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74225+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74226+
74227+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74228+
74229+#endif
74230+
74231+#endif
74232diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74233new file mode 100644
74234index 0000000..a4396b5
74235--- /dev/null
74236+++ b/include/linux/grmsg.h
74237@@ -0,0 +1,113 @@
74238+#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"
74239+#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"
74240+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74241+#define GR_STOPMOD_MSG "denied modification of module state by "
74242+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74243+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74244+#define GR_IOPERM_MSG "denied use of ioperm() by "
74245+#define GR_IOPL_MSG "denied use of iopl() by "
74246+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74247+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74248+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74249+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74250+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74251+#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"
74252+#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"
74253+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74254+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74255+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74256+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74257+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74258+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74259+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74260+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74261+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74262+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74263+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74264+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74265+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74266+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74267+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74268+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74269+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74270+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74271+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74272+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74273+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74274+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74275+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74276+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74277+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74278+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74279+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74280+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74281+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74282+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74283+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74284+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74285+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74286+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74287+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74288+#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"
74289+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74290+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74291+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74292+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74293+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74294+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74295+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74296+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74297+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74298+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74299+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74300+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74301+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74302+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74303+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74304+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74305+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74306+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74307+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74308+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74309+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74310+#define GR_NICE_CHROOT_MSG "denied priority change by "
74311+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74312+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74313+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74314+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74315+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74316+#define GR_TIME_MSG "time set by "
74317+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74318+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74319+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74320+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74321+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74322+#define GR_BIND_MSG "denied bind() by "
74323+#define GR_CONNECT_MSG "denied connect() by "
74324+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74325+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74326+#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"
74327+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74328+#define GR_CAP_ACL_MSG "use of %s denied for "
74329+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74330+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74331+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74332+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74333+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74334+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74335+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74336+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74337+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74338+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74339+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74340+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74341+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74342+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74343+#define GR_VM86_MSG "denied use of vm86 by "
74344+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74345+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74346+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74347+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74348+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74349+#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 "
74350+#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 "
74351diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74352new file mode 100644
74353index 0000000..d6f5a21
74354--- /dev/null
74355+++ b/include/linux/grsecurity.h
74356@@ -0,0 +1,244 @@
74357+#ifndef GR_SECURITY_H
74358+#define GR_SECURITY_H
74359+#include <linux/fs.h>
74360+#include <linux/fs_struct.h>
74361+#include <linux/binfmts.h>
74362+#include <linux/gracl.h>
74363+
74364+/* notify of brain-dead configs */
74365+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74366+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74367+#endif
74368+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74369+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74370+#endif
74371+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74372+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74373+#endif
74374+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74375+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74376+#endif
74377+
74378+int gr_handle_new_usb(void);
74379+
74380+void gr_handle_brute_attach(unsigned long mm_flags);
74381+void gr_handle_brute_check(void);
74382+void gr_handle_kernel_exploit(void);
74383+
74384+char gr_roletype_to_char(void);
74385+
74386+int gr_acl_enable_at_secure(void);
74387+
74388+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74389+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74390+
74391+void gr_del_task_from_ip_table(struct task_struct *p);
74392+
74393+int gr_pid_is_chrooted(struct task_struct *p);
74394+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74395+int gr_handle_chroot_nice(void);
74396+int gr_handle_chroot_sysctl(const int op);
74397+int gr_handle_chroot_setpriority(struct task_struct *p,
74398+ const int niceval);
74399+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74400+int gr_handle_chroot_chroot(const struct dentry *dentry,
74401+ const struct vfsmount *mnt);
74402+void gr_handle_chroot_chdir(const struct path *path);
74403+int gr_handle_chroot_chmod(const struct dentry *dentry,
74404+ const struct vfsmount *mnt, const int mode);
74405+int gr_handle_chroot_mknod(const struct dentry *dentry,
74406+ const struct vfsmount *mnt, const int mode);
74407+int gr_handle_chroot_mount(const struct dentry *dentry,
74408+ const struct vfsmount *mnt,
74409+ const char *dev_name);
74410+int gr_handle_chroot_pivot(void);
74411+int gr_handle_chroot_unix(const pid_t pid);
74412+
74413+int gr_handle_rawio(const struct inode *inode);
74414+
74415+void gr_handle_ioperm(void);
74416+void gr_handle_iopl(void);
74417+
74418+umode_t gr_acl_umask(void);
74419+
74420+int gr_tpe_allow(const struct file *file);
74421+
74422+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74423+void gr_clear_chroot_entries(struct task_struct *task);
74424+
74425+void gr_log_forkfail(const int retval);
74426+void gr_log_timechange(void);
74427+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74428+void gr_log_chdir(const struct dentry *dentry,
74429+ const struct vfsmount *mnt);
74430+void gr_log_chroot_exec(const struct dentry *dentry,
74431+ const struct vfsmount *mnt);
74432+void gr_log_remount(const char *devname, const int retval);
74433+void gr_log_unmount(const char *devname, const int retval);
74434+void gr_log_mount(const char *from, const char *to, const int retval);
74435+void gr_log_textrel(struct vm_area_struct *vma);
74436+void gr_log_ptgnustack(struct file *file);
74437+void gr_log_rwxmmap(struct file *file);
74438+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74439+
74440+int gr_handle_follow_link(const struct inode *parent,
74441+ const struct inode *inode,
74442+ const struct dentry *dentry,
74443+ const struct vfsmount *mnt);
74444+int gr_handle_fifo(const struct dentry *dentry,
74445+ const struct vfsmount *mnt,
74446+ const struct dentry *dir, const int flag,
74447+ const int acc_mode);
74448+int gr_handle_hardlink(const struct dentry *dentry,
74449+ const struct vfsmount *mnt,
74450+ struct inode *inode,
74451+ const int mode, const struct filename *to);
74452+
74453+int gr_is_capable(const int cap);
74454+int gr_is_capable_nolog(const int cap);
74455+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74456+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74457+
74458+void gr_copy_label(struct task_struct *tsk);
74459+void gr_handle_crash(struct task_struct *task, const int sig);
74460+int gr_handle_signal(const struct task_struct *p, const int sig);
74461+int gr_check_crash_uid(const kuid_t uid);
74462+int gr_check_protected_task(const struct task_struct *task);
74463+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74464+int gr_acl_handle_mmap(const struct file *file,
74465+ const unsigned long prot);
74466+int gr_acl_handle_mprotect(const struct file *file,
74467+ const unsigned long prot);
74468+int gr_check_hidden_task(const struct task_struct *tsk);
74469+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74470+ const struct vfsmount *mnt);
74471+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74472+ const struct vfsmount *mnt);
74473+__u32 gr_acl_handle_access(const struct dentry *dentry,
74474+ const struct vfsmount *mnt, const int fmode);
74475+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74476+ const struct vfsmount *mnt, umode_t *mode);
74477+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74478+ const struct vfsmount *mnt);
74479+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74480+ const struct vfsmount *mnt);
74481+int gr_handle_ptrace(struct task_struct *task, const long request);
74482+int gr_handle_proc_ptrace(struct task_struct *task);
74483+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74484+ const struct vfsmount *mnt);
74485+int gr_check_crash_exec(const struct file *filp);
74486+int gr_acl_is_enabled(void);
74487+void gr_set_kernel_label(struct task_struct *task);
74488+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74489+ const kgid_t gid);
74490+int gr_set_proc_label(const struct dentry *dentry,
74491+ const struct vfsmount *mnt,
74492+ const int unsafe_flags);
74493+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74494+ const struct vfsmount *mnt);
74495+__u32 gr_acl_handle_open(const struct dentry *dentry,
74496+ const struct vfsmount *mnt, int acc_mode);
74497+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74498+ const struct dentry *p_dentry,
74499+ const struct vfsmount *p_mnt,
74500+ int open_flags, int acc_mode, const int imode);
74501+void gr_handle_create(const struct dentry *dentry,
74502+ const struct vfsmount *mnt);
74503+void gr_handle_proc_create(const struct dentry *dentry,
74504+ const struct inode *inode);
74505+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74506+ const struct dentry *parent_dentry,
74507+ const struct vfsmount *parent_mnt,
74508+ const int mode);
74509+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74510+ const struct dentry *parent_dentry,
74511+ const struct vfsmount *parent_mnt);
74512+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74513+ const struct vfsmount *mnt);
74514+void gr_handle_delete(const ino_t ino, const dev_t dev);
74515+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74516+ const struct vfsmount *mnt);
74517+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74518+ const struct dentry *parent_dentry,
74519+ const struct vfsmount *parent_mnt,
74520+ const struct filename *from);
74521+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74522+ const struct dentry *parent_dentry,
74523+ const struct vfsmount *parent_mnt,
74524+ const struct dentry *old_dentry,
74525+ const struct vfsmount *old_mnt, const struct filename *to);
74526+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74527+int gr_acl_handle_rename(struct dentry *new_dentry,
74528+ struct dentry *parent_dentry,
74529+ const struct vfsmount *parent_mnt,
74530+ struct dentry *old_dentry,
74531+ struct inode *old_parent_inode,
74532+ struct vfsmount *old_mnt, const struct filename *newname);
74533+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74534+ struct dentry *old_dentry,
74535+ struct dentry *new_dentry,
74536+ struct vfsmount *mnt, const __u8 replace);
74537+__u32 gr_check_link(const struct dentry *new_dentry,
74538+ const struct dentry *parent_dentry,
74539+ const struct vfsmount *parent_mnt,
74540+ const struct dentry *old_dentry,
74541+ const struct vfsmount *old_mnt);
74542+int gr_acl_handle_filldir(const struct file *file, const char *name,
74543+ const unsigned int namelen, const ino_t ino);
74544+
74545+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74546+ const struct vfsmount *mnt);
74547+void gr_acl_handle_exit(void);
74548+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74549+int gr_acl_handle_procpidmem(const struct task_struct *task);
74550+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74551+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74552+void gr_audit_ptrace(struct task_struct *task);
74553+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74554+void gr_put_exec_file(struct task_struct *task);
74555+
74556+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74557+
74558+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74559+extern void gr_learn_resource(const struct task_struct *task, const int res,
74560+ const unsigned long wanted, const int gt);
74561+#else
74562+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74563+ const unsigned long wanted, const int gt)
74564+{
74565+}
74566+#endif
74567+
74568+#ifdef CONFIG_GRKERNSEC_RESLOG
74569+extern void gr_log_resource(const struct task_struct *task, const int res,
74570+ const unsigned long wanted, const int gt);
74571+#else
74572+static inline void gr_log_resource(const struct task_struct *task, const int res,
74573+ const unsigned long wanted, const int gt)
74574+{
74575+}
74576+#endif
74577+
74578+#ifdef CONFIG_GRKERNSEC
74579+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74580+void gr_handle_vm86(void);
74581+void gr_handle_mem_readwrite(u64 from, u64 to);
74582+
74583+void gr_log_badprocpid(const char *entry);
74584+
74585+extern int grsec_enable_dmesg;
74586+extern int grsec_disable_privio;
74587+
74588+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74589+extern kgid_t grsec_proc_gid;
74590+#endif
74591+
74592+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74593+extern int grsec_enable_chroot_findtask;
74594+#endif
74595+#ifdef CONFIG_GRKERNSEC_SETXID
74596+extern int grsec_enable_setxid;
74597+#endif
74598+#endif
74599+
74600+#endif
74601diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74602new file mode 100644
74603index 0000000..e7ffaaf
74604--- /dev/null
74605+++ b/include/linux/grsock.h
74606@@ -0,0 +1,19 @@
74607+#ifndef __GRSOCK_H
74608+#define __GRSOCK_H
74609+
74610+extern void gr_attach_curr_ip(const struct sock *sk);
74611+extern int gr_handle_sock_all(const int family, const int type,
74612+ const int protocol);
74613+extern int gr_handle_sock_server(const struct sockaddr *sck);
74614+extern int gr_handle_sock_server_other(const struct sock *sck);
74615+extern int gr_handle_sock_client(const struct sockaddr *sck);
74616+extern int gr_search_connect(struct socket * sock,
74617+ struct sockaddr_in * addr);
74618+extern int gr_search_bind(struct socket * sock,
74619+ struct sockaddr_in * addr);
74620+extern int gr_search_listen(struct socket * sock);
74621+extern int gr_search_accept(struct socket * sock);
74622+extern int gr_search_socket(const int domain, const int type,
74623+ const int protocol);
74624+
74625+#endif
74626diff --git a/include/linux/hid.h b/include/linux/hid.h
74627index 0c48991..76e41d8 100644
74628--- a/include/linux/hid.h
74629+++ b/include/linux/hid.h
74630@@ -393,10 +393,12 @@ struct hid_report {
74631 struct hid_device *device; /* associated device */
74632 };
74633
74634+#define HID_MAX_IDS 256
74635+
74636 struct hid_report_enum {
74637 unsigned numbered;
74638 struct list_head report_list;
74639- struct hid_report *report_id_hash[256];
74640+ struct hid_report *report_id_hash[HID_MAX_IDS];
74641 };
74642
74643 #define HID_REPORT_TYPES 3
74644@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
74645 struct hid_device *hid_allocate_device(void);
74646 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
74647 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
74648+struct hid_report *hid_validate_report(struct hid_device *hid,
74649+ unsigned int type, unsigned int id,
74650+ unsigned int fields,
74651+ unsigned int report_counts);
74652 int hid_open_report(struct hid_device *device);
74653 int hid_check_keys_pressed(struct hid_device *hid);
74654 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
74655diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74656index 7fb31da..08b5114 100644
74657--- a/include/linux/highmem.h
74658+++ b/include/linux/highmem.h
74659@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74660 kunmap_atomic(kaddr);
74661 }
74662
74663+static inline void sanitize_highpage(struct page *page)
74664+{
74665+ void *kaddr;
74666+ unsigned long flags;
74667+
74668+ local_irq_save(flags);
74669+ kaddr = kmap_atomic(page);
74670+ clear_page(kaddr);
74671+ kunmap_atomic(kaddr);
74672+ local_irq_restore(flags);
74673+}
74674+
74675 static inline void zero_user_segments(struct page *page,
74676 unsigned start1, unsigned end1,
74677 unsigned start2, unsigned end2)
74678diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74679index 1c7b89a..7f52502 100644
74680--- a/include/linux/hwmon-sysfs.h
74681+++ b/include/linux/hwmon-sysfs.h
74682@@ -25,7 +25,8 @@
74683 struct sensor_device_attribute{
74684 struct device_attribute dev_attr;
74685 int index;
74686-};
74687+} __do_const;
74688+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74689 #define to_sensor_dev_attr(_dev_attr) \
74690 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74691
74692@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74693 struct device_attribute dev_attr;
74694 u8 index;
74695 u8 nr;
74696-};
74697+} __do_const;
74698 #define to_sensor_dev_attr_2(_dev_attr) \
74699 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74700
74701diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74702index e988fa9..ff9f17e 100644
74703--- a/include/linux/i2c.h
74704+++ b/include/linux/i2c.h
74705@@ -366,6 +366,7 @@ struct i2c_algorithm {
74706 /* To determine what the adapter supports */
74707 u32 (*functionality) (struct i2c_adapter *);
74708 };
74709+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74710
74711 /**
74712 * struct i2c_bus_recovery_info - I2C bus recovery information
74713diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74714index d23c3c2..eb63c81 100644
74715--- a/include/linux/i2o.h
74716+++ b/include/linux/i2o.h
74717@@ -565,7 +565,7 @@ struct i2o_controller {
74718 struct i2o_device *exec; /* Executive */
74719 #if BITS_PER_LONG == 64
74720 spinlock_t context_list_lock; /* lock for context_list */
74721- atomic_t context_list_counter; /* needed for unique contexts */
74722+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74723 struct list_head context_list; /* list of context id's
74724 and pointers */
74725 #endif
74726diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74727index aff7ad8..3942bbd 100644
74728--- a/include/linux/if_pppox.h
74729+++ b/include/linux/if_pppox.h
74730@@ -76,7 +76,7 @@ struct pppox_proto {
74731 int (*ioctl)(struct socket *sock, unsigned int cmd,
74732 unsigned long arg);
74733 struct module *owner;
74734-};
74735+} __do_const;
74736
74737 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74738 extern void unregister_pppox_proto(int proto_num);
74739diff --git a/include/linux/init.h b/include/linux/init.h
74740index e73f2b7..cc996e0 100644
74741--- a/include/linux/init.h
74742+++ b/include/linux/init.h
74743@@ -39,9 +39,17 @@
74744 * Also note, that this data cannot be "const".
74745 */
74746
74747+#define add_init_latent_entropy __latent_entropy
74748+
74749+#ifdef CONFIG_MEMORY_HOTPLUG
74750+#define add_meminit_latent_entropy
74751+#else
74752+#define add_meminit_latent_entropy __latent_entropy
74753+#endif
74754+
74755 /* These are for everybody (although not all archs will actually
74756 discard it in modules) */
74757-#define __init __section(.init.text) __cold notrace
74758+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74759 #define __initdata __section(.init.data)
74760 #define __initconst __constsection(.init.rodata)
74761 #define __exitdata __section(.exit.data)
74762@@ -102,7 +110,7 @@
74763 #define __cpuexitconst
74764
74765 /* Used for MEMORY_HOTPLUG */
74766-#define __meminit __section(.meminit.text) __cold notrace
74767+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74768 #define __meminitdata __section(.meminit.data)
74769 #define __meminitconst __constsection(.meminit.rodata)
74770 #define __memexit __section(.memexit.text) __exitused __cold notrace
74771diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74772index 5cd0f09..c9f67cc 100644
74773--- a/include/linux/init_task.h
74774+++ b/include/linux/init_task.h
74775@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74776
74777 #define INIT_TASK_COMM "swapper"
74778
74779+#ifdef CONFIG_X86
74780+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74781+#else
74782+#define INIT_TASK_THREAD_INFO
74783+#endif
74784+
74785 /*
74786 * INIT_TASK is used to set up the first task table, touch at
74787 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74788@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74789 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74790 .comm = INIT_TASK_COMM, \
74791 .thread = INIT_THREAD, \
74792+ INIT_TASK_THREAD_INFO \
74793 .fs = &init_fs, \
74794 .files = &init_files, \
74795 .signal = &init_signals, \
74796diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74797index 5fa5afe..ac55b25 100644
74798--- a/include/linux/interrupt.h
74799+++ b/include/linux/interrupt.h
74800@@ -430,7 +430,7 @@ enum
74801 /* map softirq index to softirq name. update 'softirq_to_name' in
74802 * kernel/softirq.c when adding a new softirq.
74803 */
74804-extern char *softirq_to_name[NR_SOFTIRQS];
74805+extern const char * const softirq_to_name[NR_SOFTIRQS];
74806
74807 /* softirq mask and active fields moved to irq_cpustat_t in
74808 * asm/hardirq.h to get better cache usage. KAO
74809@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74810
74811 struct softirq_action
74812 {
74813- void (*action)(struct softirq_action *);
74814-};
74815+ void (*action)(void);
74816+} __no_const;
74817
74818 asmlinkage void do_softirq(void);
74819 asmlinkage void __do_softirq(void);
74820-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74821+extern void open_softirq(int nr, void (*action)(void));
74822 extern void softirq_init(void);
74823 extern void __raise_softirq_irqoff(unsigned int nr);
74824
74825diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74826index 3aeb730..2177f39 100644
74827--- a/include/linux/iommu.h
74828+++ b/include/linux/iommu.h
74829@@ -113,7 +113,7 @@ struct iommu_ops {
74830 u32 (*domain_get_windows)(struct iommu_domain *domain);
74831
74832 unsigned long pgsize_bitmap;
74833-};
74834+} __do_const;
74835
74836 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74837 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74838diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74839index 89b7c24..382af74 100644
74840--- a/include/linux/ioport.h
74841+++ b/include/linux/ioport.h
74842@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74843 int adjust_resource(struct resource *res, resource_size_t start,
74844 resource_size_t size);
74845 resource_size_t resource_alignment(struct resource *res);
74846-static inline resource_size_t resource_size(const struct resource *res)
74847+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74848 {
74849 return res->end - res->start + 1;
74850 }
74851diff --git a/include/linux/irq.h b/include/linux/irq.h
74852index f04d3ba..bcf2cfb 100644
74853--- a/include/linux/irq.h
74854+++ b/include/linux/irq.h
74855@@ -333,7 +333,8 @@ struct irq_chip {
74856 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74857
74858 unsigned long flags;
74859-};
74860+} __do_const;
74861+typedef struct irq_chip __no_const irq_chip_no_const;
74862
74863 /*
74864 * irq_chip specific flags
74865diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74866index 3e203eb..3fe68d0 100644
74867--- a/include/linux/irqchip/arm-gic.h
74868+++ b/include/linux/irqchip/arm-gic.h
74869@@ -59,9 +59,11 @@
74870
74871 #ifndef __ASSEMBLY__
74872
74873+#include <linux/irq.h>
74874+
74875 struct device_node;
74876
74877-extern struct irq_chip gic_arch_extn;
74878+extern irq_chip_no_const gic_arch_extn;
74879
74880 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74881 u32 offset, struct device_node *);
74882diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74883index 6883e19..e854fcb 100644
74884--- a/include/linux/kallsyms.h
74885+++ b/include/linux/kallsyms.h
74886@@ -15,7 +15,8 @@
74887
74888 struct module;
74889
74890-#ifdef CONFIG_KALLSYMS
74891+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74892+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74893 /* Lookup the address for a symbol. Returns 0 if not found. */
74894 unsigned long kallsyms_lookup_name(const char *name);
74895
74896@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74897 /* Stupid that this does nothing, but I didn't create this mess. */
74898 #define __print_symbol(fmt, addr)
74899 #endif /*CONFIG_KALLSYMS*/
74900+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74901+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74902+extern unsigned long kallsyms_lookup_name(const char *name);
74903+extern void __print_symbol(const char *fmt, unsigned long address);
74904+extern int sprint_backtrace(char *buffer, unsigned long address);
74905+extern int sprint_symbol(char *buffer, unsigned long address);
74906+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74907+const char *kallsyms_lookup(unsigned long addr,
74908+ unsigned long *symbolsize,
74909+ unsigned long *offset,
74910+ char **modname, char *namebuf);
74911+extern int kallsyms_lookup_size_offset(unsigned long addr,
74912+ unsigned long *symbolsize,
74913+ unsigned long *offset);
74914+#endif
74915
74916 /* This macro allows us to keep printk typechecking */
74917 static __printf(1, 2)
74918diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74919index 518a53a..5e28358 100644
74920--- a/include/linux/key-type.h
74921+++ b/include/linux/key-type.h
74922@@ -125,7 +125,7 @@ struct key_type {
74923 /* internal fields */
74924 struct list_head link; /* link in types list */
74925 struct lock_class_key lock_class; /* key->sem lock class */
74926-};
74927+} __do_const;
74928
74929 extern struct key_type key_type_keyring;
74930
74931diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74932index c6e091b..a940adf 100644
74933--- a/include/linux/kgdb.h
74934+++ b/include/linux/kgdb.h
74935@@ -52,7 +52,7 @@ extern int kgdb_connected;
74936 extern int kgdb_io_module_registered;
74937
74938 extern atomic_t kgdb_setting_breakpoint;
74939-extern atomic_t kgdb_cpu_doing_single_step;
74940+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74941
74942 extern struct task_struct *kgdb_usethread;
74943 extern struct task_struct *kgdb_contthread;
74944@@ -254,7 +254,7 @@ struct kgdb_arch {
74945 void (*correct_hw_break)(void);
74946
74947 void (*enable_nmi)(bool on);
74948-};
74949+} __do_const;
74950
74951 /**
74952 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74953@@ -279,7 +279,7 @@ struct kgdb_io {
74954 void (*pre_exception) (void);
74955 void (*post_exception) (void);
74956 int is_console;
74957-};
74958+} __do_const;
74959
74960 extern struct kgdb_arch arch_kgdb_ops;
74961
74962diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74963index 0555cc6..b16a7a4 100644
74964--- a/include/linux/kmod.h
74965+++ b/include/linux/kmod.h
74966@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74967 * usually useless though. */
74968 extern __printf(2, 3)
74969 int __request_module(bool wait, const char *name, ...);
74970+extern __printf(3, 4)
74971+int ___request_module(bool wait, char *param_name, const char *name, ...);
74972 #define request_module(mod...) __request_module(true, mod)
74973 #define request_module_nowait(mod...) __request_module(false, mod)
74974 #define try_then_request_module(x, mod...) \
74975diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74976index 939b112..ed6ed51 100644
74977--- a/include/linux/kobject.h
74978+++ b/include/linux/kobject.h
74979@@ -111,7 +111,7 @@ struct kobj_type {
74980 struct attribute **default_attrs;
74981 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74982 const void *(*namespace)(struct kobject *kobj);
74983-};
74984+} __do_const;
74985
74986 struct kobj_uevent_env {
74987 char *envp[UEVENT_NUM_ENVP];
74988@@ -134,6 +134,7 @@ struct kobj_attribute {
74989 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74990 const char *buf, size_t count);
74991 };
74992+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74993
74994 extern const struct sysfs_ops kobj_sysfs_ops;
74995
74996diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74997index f66b065..c2c29b4 100644
74998--- a/include/linux/kobject_ns.h
74999+++ b/include/linux/kobject_ns.h
75000@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
75001 const void *(*netlink_ns)(struct sock *sk);
75002 const void *(*initial_ns)(void);
75003 void (*drop_ns)(void *);
75004-};
75005+} __do_const;
75006
75007 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
75008 int kobj_ns_type_registered(enum kobj_ns_type type);
75009diff --git a/include/linux/kref.h b/include/linux/kref.h
75010index 484604d..0f6c5b6 100644
75011--- a/include/linux/kref.h
75012+++ b/include/linux/kref.h
75013@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
75014 static inline int kref_sub(struct kref *kref, unsigned int count,
75015 void (*release)(struct kref *kref))
75016 {
75017- WARN_ON(release == NULL);
75018+ BUG_ON(release == NULL);
75019
75020 if (atomic_sub_and_test((int) count, &kref->refcount)) {
75021 release(kref);
75022diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
75023index a63d83e..77fd685 100644
75024--- a/include/linux/kvm_host.h
75025+++ b/include/linux/kvm_host.h
75026@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
75027 {
75028 }
75029 #endif
75030-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75031+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75032 struct module *module);
75033 void kvm_exit(void);
75034
75035@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
75036 struct kvm_guest_debug *dbg);
75037 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
75038
75039-int kvm_arch_init(void *opaque);
75040+int kvm_arch_init(const void *opaque);
75041 void kvm_arch_exit(void);
75042
75043 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
75044diff --git a/include/linux/libata.h b/include/linux/libata.h
75045index 4ea55bb..dcd2601 100644
75046--- a/include/linux/libata.h
75047+++ b/include/linux/libata.h
75048@@ -924,7 +924,7 @@ struct ata_port_operations {
75049 * fields must be pointers.
75050 */
75051 const struct ata_port_operations *inherits;
75052-};
75053+} __do_const;
75054
75055 struct ata_port_info {
75056 unsigned long flags;
75057diff --git a/include/linux/linkage.h b/include/linux/linkage.h
75058index d3e8ad2..a949f68 100644
75059--- a/include/linux/linkage.h
75060+++ b/include/linux/linkage.h
75061@@ -31,6 +31,7 @@
75062 #endif
75063
75064 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
75065+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
75066 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
75067
75068 /*
75069diff --git a/include/linux/list.h b/include/linux/list.h
75070index f4d8a2f..38e6e46 100644
75071--- a/include/linux/list.h
75072+++ b/include/linux/list.h
75073@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
75074 extern void list_del(struct list_head *entry);
75075 #endif
75076
75077+extern void __pax_list_add(struct list_head *new,
75078+ struct list_head *prev,
75079+ struct list_head *next);
75080+static inline void pax_list_add(struct list_head *new, struct list_head *head)
75081+{
75082+ __pax_list_add(new, head, head->next);
75083+}
75084+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
75085+{
75086+ __pax_list_add(new, head->prev, head);
75087+}
75088+extern void pax_list_del(struct list_head *entry);
75089+
75090 /**
75091 * list_replace - replace old entry by new one
75092 * @old : the element to be replaced
75093@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
75094 INIT_LIST_HEAD(entry);
75095 }
75096
75097+extern void pax_list_del_init(struct list_head *entry);
75098+
75099 /**
75100 * list_move - delete from one list and add as another's head
75101 * @list: the entry to move
75102diff --git a/include/linux/math64.h b/include/linux/math64.h
75103index 2913b86..8dcbb1e 100644
75104--- a/include/linux/math64.h
75105+++ b/include/linux/math64.h
75106@@ -15,7 +15,7 @@
75107 * This is commonly provided by 32bit archs to provide an optimized 64bit
75108 * divide.
75109 */
75110-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75111+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75112 {
75113 *remainder = dividend % divisor;
75114 return dividend / divisor;
75115@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
75116 /**
75117 * div64_u64 - unsigned 64bit divide with 64bit divisor
75118 */
75119-static inline u64 div64_u64(u64 dividend, u64 divisor)
75120+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
75121 {
75122 return dividend / divisor;
75123 }
75124@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
75125 #define div64_ul(x, y) div_u64((x), (y))
75126
75127 #ifndef div_u64_rem
75128-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75129+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75130 {
75131 *remainder = do_div(dividend, divisor);
75132 return dividend;
75133@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
75134 * divide.
75135 */
75136 #ifndef div_u64
75137-static inline u64 div_u64(u64 dividend, u32 divisor)
75138+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
75139 {
75140 u32 remainder;
75141 return div_u64_rem(dividend, divisor, &remainder);
75142diff --git a/include/linux/mm.h b/include/linux/mm.h
75143index f022460..6ecf4f9 100644
75144--- a/include/linux/mm.h
75145+++ b/include/linux/mm.h
75146@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
75147 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
75148 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
75149 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
75150+
75151+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75152+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
75153+#endif
75154+
75155 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
75156
75157 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
75158@@ -208,8 +213,8 @@ struct vm_operations_struct {
75159 /* called by access_process_vm when get_user_pages() fails, typically
75160 * for use by special VMAs that can switch between memory and hardware
75161 */
75162- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75163- void *buf, int len, int write);
75164+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75165+ void *buf, size_t len, int write);
75166 #ifdef CONFIG_NUMA
75167 /*
75168 * set_policy() op must add a reference to any non-NULL @new mempolicy
75169@@ -239,6 +244,7 @@ struct vm_operations_struct {
75170 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75171 unsigned long size, pgoff_t pgoff);
75172 };
75173+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75174
75175 struct mmu_gather;
75176 struct inode;
75177@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75178 unsigned long *pfn);
75179 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75180 unsigned int flags, unsigned long *prot, resource_size_t *phys);
75181-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75182- void *buf, int len, int write);
75183+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75184+ void *buf, size_t len, int write);
75185
75186 static inline void unmap_shared_mapping_range(struct address_space *mapping,
75187 loff_t const holebegin, loff_t const holelen)
75188@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
75189 }
75190 #endif
75191
75192-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
75193-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
75194- void *buf, int len, int write);
75195+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
75196+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
75197+ void *buf, size_t len, int write);
75198
75199 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75200 unsigned long start, unsigned long nr_pages,
75201@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
75202 int set_page_dirty_lock(struct page *page);
75203 int clear_page_dirty_for_io(struct page *page);
75204
75205-/* Is the vma a continuation of the stack vma above it? */
75206-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
75207-{
75208- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
75209-}
75210-
75211-static inline int stack_guard_page_start(struct vm_area_struct *vma,
75212- unsigned long addr)
75213-{
75214- return (vma->vm_flags & VM_GROWSDOWN) &&
75215- (vma->vm_start == addr) &&
75216- !vma_growsdown(vma->vm_prev, addr);
75217-}
75218-
75219-/* Is the vma a continuation of the stack vma below it? */
75220-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
75221-{
75222- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75223-}
75224-
75225-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75226- unsigned long addr)
75227-{
75228- return (vma->vm_flags & VM_GROWSUP) &&
75229- (vma->vm_end == addr) &&
75230- !vma_growsup(vma->vm_next, addr);
75231-}
75232-
75233 extern pid_t
75234 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75235
75236@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75237 }
75238 #endif
75239
75240+#ifdef CONFIG_MMU
75241+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75242+#else
75243+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75244+{
75245+ return __pgprot(0);
75246+}
75247+#endif
75248+
75249 int vma_wants_writenotify(struct vm_area_struct *vma);
75250
75251 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75252@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75253 {
75254 return 0;
75255 }
75256+
75257+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75258+ unsigned long address)
75259+{
75260+ return 0;
75261+}
75262 #else
75263 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75264+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75265 #endif
75266
75267 #ifdef __PAGETABLE_PMD_FOLDED
75268@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75269 {
75270 return 0;
75271 }
75272+
75273+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75274+ unsigned long address)
75275+{
75276+ return 0;
75277+}
75278 #else
75279 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75280+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75281 #endif
75282
75283 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75284@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75285 NULL: pud_offset(pgd, address);
75286 }
75287
75288+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75289+{
75290+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75291+ NULL: pud_offset(pgd, address);
75292+}
75293+
75294 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75295 {
75296 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75297 NULL: pmd_offset(pud, address);
75298 }
75299+
75300+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75301+{
75302+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75303+ NULL: pmd_offset(pud, address);
75304+}
75305 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75306
75307 #if USE_SPLIT_PTLOCKS
75308@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75309 unsigned long len, unsigned long prot, unsigned long flags,
75310 unsigned long pgoff, unsigned long *populate);
75311 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75312+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75313
75314 #ifdef CONFIG_MMU
75315 extern int __mm_populate(unsigned long addr, unsigned long len,
75316@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75317 unsigned long high_limit;
75318 unsigned long align_mask;
75319 unsigned long align_offset;
75320+ unsigned long threadstack_offset;
75321 };
75322
75323-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75324-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75325+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75326+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75327
75328 /*
75329 * Search for an unmapped address range.
75330@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75331 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75332 */
75333 static inline unsigned long
75334-vm_unmapped_area(struct vm_unmapped_area_info *info)
75335+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75336 {
75337 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75338 return unmapped_area(info);
75339@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75340 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75341 struct vm_area_struct **pprev);
75342
75343+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75344+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75345+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75346+
75347 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75348 NULL if none. Assume start_addr < end_addr. */
75349 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75350@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75351 return vma;
75352 }
75353
75354-#ifdef CONFIG_MMU
75355-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75356-#else
75357-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75358-{
75359- return __pgprot(0);
75360-}
75361-#endif
75362-
75363 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75364 unsigned long change_prot_numa(struct vm_area_struct *vma,
75365 unsigned long start, unsigned long end);
75366@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75367 static inline void vm_stat_account(struct mm_struct *mm,
75368 unsigned long flags, struct file *file, long pages)
75369 {
75370+
75371+#ifdef CONFIG_PAX_RANDMMAP
75372+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75373+#endif
75374+
75375 mm->total_vm += pages;
75376 }
75377 #endif /* CONFIG_PROC_FS */
75378@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75379 extern int sysctl_memory_failure_early_kill;
75380 extern int sysctl_memory_failure_recovery;
75381 extern void shake_page(struct page *p, int access);
75382-extern atomic_long_t num_poisoned_pages;
75383+extern atomic_long_unchecked_t num_poisoned_pages;
75384 extern int soft_offline_page(struct page *page, int flags);
75385
75386 extern void dump_page(struct page *page);
75387@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75388 static inline void setup_nr_node_ids(void) {}
75389 #endif
75390
75391+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75392+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75393+#else
75394+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75395+#endif
75396+
75397 #endif /* __KERNEL__ */
75398 #endif /* _LINUX_MM_H */
75399diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75400index faf4b7c..1e70c6e 100644
75401--- a/include/linux/mm_types.h
75402+++ b/include/linux/mm_types.h
75403@@ -289,6 +289,8 @@ struct vm_area_struct {
75404 #ifdef CONFIG_NUMA
75405 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75406 #endif
75407+
75408+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75409 };
75410
75411 struct core_thread {
75412@@ -435,6 +437,24 @@ struct mm_struct {
75413 int first_nid;
75414 #endif
75415 struct uprobes_state uprobes_state;
75416+
75417+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75418+ unsigned long pax_flags;
75419+#endif
75420+
75421+#ifdef CONFIG_PAX_DLRESOLVE
75422+ unsigned long call_dl_resolve;
75423+#endif
75424+
75425+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75426+ unsigned long call_syscall;
75427+#endif
75428+
75429+#ifdef CONFIG_PAX_ASLR
75430+ unsigned long delta_mmap; /* randomized offset */
75431+ unsigned long delta_stack; /* randomized offset */
75432+#endif
75433+
75434 };
75435
75436 /* first nid will either be a valid NID or one of these values */
75437diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75438index c5d5278..f0b68c8 100644
75439--- a/include/linux/mmiotrace.h
75440+++ b/include/linux/mmiotrace.h
75441@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75442 /* Called from ioremap.c */
75443 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75444 void __iomem *addr);
75445-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75446+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75447
75448 /* For anyone to insert markers. Remember trailing newline. */
75449 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75450@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75451 {
75452 }
75453
75454-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75455+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75456 {
75457 }
75458
75459diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75460index af4a3b7..9ad8889 100644
75461--- a/include/linux/mmzone.h
75462+++ b/include/linux/mmzone.h
75463@@ -396,7 +396,7 @@ struct zone {
75464 unsigned long flags; /* zone flags, see below */
75465
75466 /* Zone statistics */
75467- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75468+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75469
75470 /*
75471 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75472diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75473index 45e9214..a7227d6 100644
75474--- a/include/linux/mod_devicetable.h
75475+++ b/include/linux/mod_devicetable.h
75476@@ -13,7 +13,7 @@
75477 typedef unsigned long kernel_ulong_t;
75478 #endif
75479
75480-#define PCI_ANY_ID (~0)
75481+#define PCI_ANY_ID ((__u16)~0)
75482
75483 struct pci_device_id {
75484 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75485@@ -139,7 +139,7 @@ struct usb_device_id {
75486 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75487 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75488
75489-#define HID_ANY_ID (~0)
75490+#define HID_ANY_ID (~0U)
75491 #define HID_BUS_ANY 0xffff
75492 #define HID_GROUP_ANY 0x0000
75493
75494@@ -467,7 +467,7 @@ struct dmi_system_id {
75495 const char *ident;
75496 struct dmi_strmatch matches[4];
75497 void *driver_data;
75498-};
75499+} __do_const;
75500 /*
75501 * struct dmi_device_id appears during expansion of
75502 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75503diff --git a/include/linux/module.h b/include/linux/module.h
75504index 46f1ea0..a34ca37 100644
75505--- a/include/linux/module.h
75506+++ b/include/linux/module.h
75507@@ -17,9 +17,11 @@
75508 #include <linux/moduleparam.h>
75509 #include <linux/tracepoint.h>
75510 #include <linux/export.h>
75511+#include <linux/fs.h>
75512
75513 #include <linux/percpu.h>
75514 #include <asm/module.h>
75515+#include <asm/pgtable.h>
75516
75517 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75518 #define MODULE_SIG_STRING "~Module signature appended~\n"
75519@@ -54,12 +56,13 @@ struct module_attribute {
75520 int (*test)(struct module *);
75521 void (*free)(struct module *);
75522 };
75523+typedef struct module_attribute __no_const module_attribute_no_const;
75524
75525 struct module_version_attribute {
75526 struct module_attribute mattr;
75527 const char *module_name;
75528 const char *version;
75529-} __attribute__ ((__aligned__(sizeof(void *))));
75530+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75531
75532 extern ssize_t __modver_version_show(struct module_attribute *,
75533 struct module_kobject *, char *);
75534@@ -232,7 +235,7 @@ struct module
75535
75536 /* Sysfs stuff. */
75537 struct module_kobject mkobj;
75538- struct module_attribute *modinfo_attrs;
75539+ module_attribute_no_const *modinfo_attrs;
75540 const char *version;
75541 const char *srcversion;
75542 struct kobject *holders_dir;
75543@@ -281,19 +284,16 @@ struct module
75544 int (*init)(void);
75545
75546 /* If this is non-NULL, vfree after init() returns */
75547- void *module_init;
75548+ void *module_init_rx, *module_init_rw;
75549
75550 /* Here is the actual code + data, vfree'd on unload. */
75551- void *module_core;
75552+ void *module_core_rx, *module_core_rw;
75553
75554 /* Here are the sizes of the init and core sections */
75555- unsigned int init_size, core_size;
75556+ unsigned int init_size_rw, core_size_rw;
75557
75558 /* The size of the executable code in each section. */
75559- unsigned int init_text_size, core_text_size;
75560-
75561- /* Size of RO sections of the module (text+rodata) */
75562- unsigned int init_ro_size, core_ro_size;
75563+ unsigned int init_size_rx, core_size_rx;
75564
75565 /* Arch-specific module values */
75566 struct mod_arch_specific arch;
75567@@ -349,6 +349,10 @@ struct module
75568 #ifdef CONFIG_EVENT_TRACING
75569 struct ftrace_event_call **trace_events;
75570 unsigned int num_trace_events;
75571+ struct file_operations trace_id;
75572+ struct file_operations trace_enable;
75573+ struct file_operations trace_format;
75574+ struct file_operations trace_filter;
75575 #endif
75576 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75577 unsigned int num_ftrace_callsites;
75578@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75579 bool is_module_percpu_address(unsigned long addr);
75580 bool is_module_text_address(unsigned long addr);
75581
75582+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75583+{
75584+
75585+#ifdef CONFIG_PAX_KERNEXEC
75586+ if (ktla_ktva(addr) >= (unsigned long)start &&
75587+ ktla_ktva(addr) < (unsigned long)start + size)
75588+ return 1;
75589+#endif
75590+
75591+ return ((void *)addr >= start && (void *)addr < start + size);
75592+}
75593+
75594+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75595+{
75596+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75597+}
75598+
75599+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75600+{
75601+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75602+}
75603+
75604+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75605+{
75606+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75607+}
75608+
75609+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75610+{
75611+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75612+}
75613+
75614 static inline int within_module_core(unsigned long addr, const struct module *mod)
75615 {
75616- return (unsigned long)mod->module_core <= addr &&
75617- addr < (unsigned long)mod->module_core + mod->core_size;
75618+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75619 }
75620
75621 static inline int within_module_init(unsigned long addr, const struct module *mod)
75622 {
75623- return (unsigned long)mod->module_init <= addr &&
75624- addr < (unsigned long)mod->module_init + mod->init_size;
75625+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75626 }
75627
75628 /* Search for module by name: must hold module_mutex. */
75629diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75630index 560ca53..ef621ef 100644
75631--- a/include/linux/moduleloader.h
75632+++ b/include/linux/moduleloader.h
75633@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75634 sections. Returns NULL on failure. */
75635 void *module_alloc(unsigned long size);
75636
75637+#ifdef CONFIG_PAX_KERNEXEC
75638+void *module_alloc_exec(unsigned long size);
75639+#else
75640+#define module_alloc_exec(x) module_alloc(x)
75641+#endif
75642+
75643 /* Free memory returned from module_alloc. */
75644 void module_free(struct module *mod, void *module_region);
75645
75646+#ifdef CONFIG_PAX_KERNEXEC
75647+void module_free_exec(struct module *mod, void *module_region);
75648+#else
75649+#define module_free_exec(x, y) module_free((x), (y))
75650+#endif
75651+
75652 /*
75653 * Apply the given relocation to the (simplified) ELF. Return -error
75654 * or 0.
75655@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75656 unsigned int relsec,
75657 struct module *me)
75658 {
75659+#ifdef CONFIG_MODULES
75660 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75661+#endif
75662 return -ENOEXEC;
75663 }
75664 #endif
75665@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75666 unsigned int relsec,
75667 struct module *me)
75668 {
75669+#ifdef CONFIG_MODULES
75670 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75671+#endif
75672 return -ENOEXEC;
75673 }
75674 #endif
75675diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75676index 27d9da3..5d94aa3 100644
75677--- a/include/linux/moduleparam.h
75678+++ b/include/linux/moduleparam.h
75679@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75680 * @len is usually just sizeof(string).
75681 */
75682 #define module_param_string(name, string, len, perm) \
75683- static const struct kparam_string __param_string_##name \
75684+ static const struct kparam_string __param_string_##name __used \
75685 = { len, string }; \
75686 __module_param_call(MODULE_PARAM_PREFIX, name, \
75687 &param_ops_string, \
75688@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75689 */
75690 #define module_param_array_named(name, array, type, nump, perm) \
75691 param_check_##type(name, &(array)[0]); \
75692- static const struct kparam_array __param_arr_##name \
75693+ static const struct kparam_array __param_arr_##name __used \
75694 = { .max = ARRAY_SIZE(array), .num = nump, \
75695 .ops = &param_ops_##type, \
75696 .elemsize = sizeof(array[0]), .elem = array }; \
75697diff --git a/include/linux/namei.h b/include/linux/namei.h
75698index 5a5ff57..5ae5070 100644
75699--- a/include/linux/namei.h
75700+++ b/include/linux/namei.h
75701@@ -19,7 +19,7 @@ struct nameidata {
75702 unsigned seq;
75703 int last_type;
75704 unsigned depth;
75705- char *saved_names[MAX_NESTED_LINKS + 1];
75706+ const char *saved_names[MAX_NESTED_LINKS + 1];
75707 };
75708
75709 /*
75710@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75711
75712 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75713
75714-static inline void nd_set_link(struct nameidata *nd, char *path)
75715+static inline void nd_set_link(struct nameidata *nd, const char *path)
75716 {
75717 nd->saved_names[nd->depth] = path;
75718 }
75719
75720-static inline char *nd_get_link(struct nameidata *nd)
75721+static inline const char *nd_get_link(const struct nameidata *nd)
75722 {
75723 return nd->saved_names[nd->depth];
75724 }
75725diff --git a/include/linux/net.h b/include/linux/net.h
75726index 4f27575..fc8a65f 100644
75727--- a/include/linux/net.h
75728+++ b/include/linux/net.h
75729@@ -183,7 +183,7 @@ struct net_proto_family {
75730 int (*create)(struct net *net, struct socket *sock,
75731 int protocol, int kern);
75732 struct module *owner;
75733-};
75734+} __do_const;
75735
75736 struct iovec;
75737 struct kvec;
75738diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75739index 9a41568..203d903 100644
75740--- a/include/linux/netdevice.h
75741+++ b/include/linux/netdevice.h
75742@@ -1061,6 +1061,7 @@ struct net_device_ops {
75743 int (*ndo_change_carrier)(struct net_device *dev,
75744 bool new_carrier);
75745 };
75746+typedef struct net_device_ops __no_const net_device_ops_no_const;
75747
75748 /*
75749 * The DEVICE structure.
75750@@ -1131,7 +1132,7 @@ struct net_device {
75751 int iflink;
75752
75753 struct net_device_stats stats;
75754- atomic_long_t rx_dropped; /* dropped packets by core network
75755+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75756 * Do not use this in drivers.
75757 */
75758
75759diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75760index de70f7b..2675e91 100644
75761--- a/include/linux/netfilter.h
75762+++ b/include/linux/netfilter.h
75763@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75764 #endif
75765 /* Use the module struct to lock set/get code in place */
75766 struct module *owner;
75767-};
75768+} __do_const;
75769
75770 /* Function to register/unregister hook points. */
75771 int nf_register_hook(struct nf_hook_ops *reg);
75772diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75773index d80e275..c3510b8 100644
75774--- a/include/linux/netfilter/ipset/ip_set.h
75775+++ b/include/linux/netfilter/ipset/ip_set.h
75776@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75777 /* Return true if "b" set is the same as "a"
75778 * according to the create set parameters */
75779 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75780-};
75781+} __do_const;
75782
75783 /* The core set type structure */
75784 struct ip_set_type {
75785diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75786index cadb740..d7c37c0 100644
75787--- a/include/linux/netfilter/nfnetlink.h
75788+++ b/include/linux/netfilter/nfnetlink.h
75789@@ -16,7 +16,7 @@ struct nfnl_callback {
75790 const struct nlattr * const cda[]);
75791 const struct nla_policy *policy; /* netlink attribute policy */
75792 const u_int16_t attr_count; /* number of nlattr's */
75793-};
75794+} __do_const;
75795
75796 struct nfnetlink_subsystem {
75797 const char *name;
75798diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75799new file mode 100644
75800index 0000000..33f4af8
75801--- /dev/null
75802+++ b/include/linux/netfilter/xt_gradm.h
75803@@ -0,0 +1,9 @@
75804+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75805+#define _LINUX_NETFILTER_XT_GRADM_H 1
75806+
75807+struct xt_gradm_mtinfo {
75808+ __u16 flags;
75809+ __u16 invflags;
75810+};
75811+
75812+#endif
75813diff --git a/include/linux/nls.h b/include/linux/nls.h
75814index 5dc635f..35f5e11 100644
75815--- a/include/linux/nls.h
75816+++ b/include/linux/nls.h
75817@@ -31,7 +31,7 @@ struct nls_table {
75818 const unsigned char *charset2upper;
75819 struct module *owner;
75820 struct nls_table *next;
75821-};
75822+} __do_const;
75823
75824 /* this value hold the maximum octet of charset */
75825 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75826diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75827index d14a4c3..a078786 100644
75828--- a/include/linux/notifier.h
75829+++ b/include/linux/notifier.h
75830@@ -54,7 +54,8 @@ struct notifier_block {
75831 notifier_fn_t notifier_call;
75832 struct notifier_block __rcu *next;
75833 int priority;
75834-};
75835+} __do_const;
75836+typedef struct notifier_block __no_const notifier_block_no_const;
75837
75838 struct atomic_notifier_head {
75839 spinlock_t lock;
75840diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75841index a4c5624..79d6d88 100644
75842--- a/include/linux/oprofile.h
75843+++ b/include/linux/oprofile.h
75844@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75845 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75846 char const * name, ulong * val);
75847
75848-/** Create a file for read-only access to an atomic_t. */
75849+/** Create a file for read-only access to an atomic_unchecked_t. */
75850 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75851- char const * name, atomic_t * val);
75852+ char const * name, atomic_unchecked_t * val);
75853
75854 /** create a directory */
75855 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75856diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75857index 8db71dc..a76bf2c 100644
75858--- a/include/linux/pci_hotplug.h
75859+++ b/include/linux/pci_hotplug.h
75860@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75861 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75862 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75863 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75864-};
75865+} __do_const;
75866+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75867
75868 /**
75869 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75870diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75871index c43f6ea..2d4416f 100644
75872--- a/include/linux/perf_event.h
75873+++ b/include/linux/perf_event.h
75874@@ -328,8 +328,8 @@ struct perf_event {
75875
75876 enum perf_event_active_state state;
75877 unsigned int attach_state;
75878- local64_t count;
75879- atomic64_t child_count;
75880+ local64_t count; /* PaX: fix it one day */
75881+ atomic64_unchecked_t child_count;
75882
75883 /*
75884 * These are the total time in nanoseconds that the event
75885@@ -380,8 +380,8 @@ struct perf_event {
75886 * These accumulate total time (in nanoseconds) that children
75887 * events have been enabled and running, respectively.
75888 */
75889- atomic64_t child_total_time_enabled;
75890- atomic64_t child_total_time_running;
75891+ atomic64_unchecked_t child_total_time_enabled;
75892+ atomic64_unchecked_t child_total_time_running;
75893
75894 /*
75895 * Protect attach/detach and child_list:
75896@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75897 entry->ip[entry->nr++] = ip;
75898 }
75899
75900-extern int sysctl_perf_event_paranoid;
75901+extern int sysctl_perf_event_legitimately_concerned;
75902 extern int sysctl_perf_event_mlock;
75903 extern int sysctl_perf_event_sample_rate;
75904 extern int sysctl_perf_cpu_time_max_percent;
75905@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75906 loff_t *ppos);
75907
75908
75909+static inline bool perf_paranoid_any(void)
75910+{
75911+ return sysctl_perf_event_legitimately_concerned > 2;
75912+}
75913+
75914 static inline bool perf_paranoid_tracepoint_raw(void)
75915 {
75916- return sysctl_perf_event_paranoid > -1;
75917+ return sysctl_perf_event_legitimately_concerned > -1;
75918 }
75919
75920 static inline bool perf_paranoid_cpu(void)
75921 {
75922- return sysctl_perf_event_paranoid > 0;
75923+ return sysctl_perf_event_legitimately_concerned > 0;
75924 }
75925
75926 static inline bool perf_paranoid_kernel(void)
75927 {
75928- return sysctl_perf_event_paranoid > 1;
75929+ return sysctl_perf_event_legitimately_concerned > 1;
75930 }
75931
75932 extern void perf_event_init(void);
75933@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75934 struct device_attribute attr;
75935 u64 id;
75936 const char *event_str;
75937-};
75938+} __do_const;
75939
75940 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75941 static struct perf_pmu_events_attr _var = { \
75942diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75943index b8809fe..ae4ccd0 100644
75944--- a/include/linux/pipe_fs_i.h
75945+++ b/include/linux/pipe_fs_i.h
75946@@ -47,10 +47,10 @@ struct pipe_inode_info {
75947 struct mutex mutex;
75948 wait_queue_head_t wait;
75949 unsigned int nrbufs, curbuf, buffers;
75950- unsigned int readers;
75951- unsigned int writers;
75952- unsigned int files;
75953- unsigned int waiting_writers;
75954+ atomic_t readers;
75955+ atomic_t writers;
75956+ atomic_t files;
75957+ atomic_t waiting_writers;
75958 unsigned int r_counter;
75959 unsigned int w_counter;
75960 struct page *tmp_page;
75961diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75962index 5f28cae..3d23723 100644
75963--- a/include/linux/platform_data/usb-ehci-s5p.h
75964+++ b/include/linux/platform_data/usb-ehci-s5p.h
75965@@ -14,7 +14,7 @@
75966 struct s5p_ehci_platdata {
75967 int (*phy_init)(struct platform_device *pdev, int type);
75968 int (*phy_exit)(struct platform_device *pdev, int type);
75969-};
75970+} __no_const;
75971
75972 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75973
75974diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75975index c256c59..8ea94c7 100644
75976--- a/include/linux/platform_data/usb-ohci-exynos.h
75977+++ b/include/linux/platform_data/usb-ohci-exynos.h
75978@@ -14,7 +14,7 @@
75979 struct exynos4_ohci_platdata {
75980 int (*phy_init)(struct platform_device *pdev, int type);
75981 int (*phy_exit)(struct platform_device *pdev, int type);
75982-};
75983+} __no_const;
75984
75985 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75986
75987diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75988index 7c1d252..c5c773e 100644
75989--- a/include/linux/pm_domain.h
75990+++ b/include/linux/pm_domain.h
75991@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75992
75993 struct gpd_cpu_data {
75994 unsigned int saved_exit_latency;
75995- struct cpuidle_state *idle_state;
75996+ cpuidle_state_no_const *idle_state;
75997 };
75998
75999 struct generic_pm_domain {
76000diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
76001index 6fa7cea..7bf6415 100644
76002--- a/include/linux/pm_runtime.h
76003+++ b/include/linux/pm_runtime.h
76004@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
76005
76006 static inline void pm_runtime_mark_last_busy(struct device *dev)
76007 {
76008- ACCESS_ONCE(dev->power.last_busy) = jiffies;
76009+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
76010 }
76011
76012 #else /* !CONFIG_PM_RUNTIME */
76013diff --git a/include/linux/pnp.h b/include/linux/pnp.h
76014index 195aafc..49a7bc2 100644
76015--- a/include/linux/pnp.h
76016+++ b/include/linux/pnp.h
76017@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
76018 struct pnp_fixup {
76019 char id[7];
76020 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
76021-};
76022+} __do_const;
76023
76024 /* config parameters */
76025 #define PNP_CONFIG_NORMAL 0x0001
76026diff --git a/include/linux/poison.h b/include/linux/poison.h
76027index 2110a81..13a11bb 100644
76028--- a/include/linux/poison.h
76029+++ b/include/linux/poison.h
76030@@ -19,8 +19,8 @@
76031 * under normal circumstances, used to verify that nobody uses
76032 * non-initialized list entries.
76033 */
76034-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
76035-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
76036+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
76037+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
76038
76039 /********** include/linux/timer.h **********/
76040 /*
76041diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
76042index d8b187c3..9a9257a 100644
76043--- a/include/linux/power/smartreflex.h
76044+++ b/include/linux/power/smartreflex.h
76045@@ -238,7 +238,7 @@ struct omap_sr_class_data {
76046 int (*notify)(struct omap_sr *sr, u32 status);
76047 u8 notify_flags;
76048 u8 class_type;
76049-};
76050+} __do_const;
76051
76052 /**
76053 * struct omap_sr_nvalue_table - Smartreflex n-target value info
76054diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
76055index 4ea1d37..80f4b33 100644
76056--- a/include/linux/ppp-comp.h
76057+++ b/include/linux/ppp-comp.h
76058@@ -84,7 +84,7 @@ struct compressor {
76059 struct module *owner;
76060 /* Extra skb space needed by the compressor algorithm */
76061 unsigned int comp_extra;
76062-};
76063+} __do_const;
76064
76065 /*
76066 * The return value from decompress routine is the length of the
76067diff --git a/include/linux/preempt.h b/include/linux/preempt.h
76068index f5d4723..a6ea2fa 100644
76069--- a/include/linux/preempt.h
76070+++ b/include/linux/preempt.h
76071@@ -18,8 +18,13 @@
76072 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76073 #endif
76074
76075+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
76076+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76077+
76078 #define inc_preempt_count() add_preempt_count(1)
76079+#define raw_inc_preempt_count() raw_add_preempt_count(1)
76080 #define dec_preempt_count() sub_preempt_count(1)
76081+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
76082
76083 #define preempt_count() (current_thread_info()->preempt_count)
76084
76085@@ -64,6 +69,12 @@ do { \
76086 barrier(); \
76087 } while (0)
76088
76089+#define raw_preempt_disable() \
76090+do { \
76091+ raw_inc_preempt_count(); \
76092+ barrier(); \
76093+} while (0)
76094+
76095 #define sched_preempt_enable_no_resched() \
76096 do { \
76097 barrier(); \
76098@@ -72,6 +83,12 @@ do { \
76099
76100 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
76101
76102+#define raw_preempt_enable_no_resched() \
76103+do { \
76104+ barrier(); \
76105+ raw_dec_preempt_count(); \
76106+} while (0)
76107+
76108 #define preempt_enable() \
76109 do { \
76110 preempt_enable_no_resched(); \
76111@@ -116,8 +133,10 @@ do { \
76112 * region.
76113 */
76114 #define preempt_disable() barrier()
76115+#define raw_preempt_disable() barrier()
76116 #define sched_preempt_enable_no_resched() barrier()
76117 #define preempt_enable_no_resched() barrier()
76118+#define raw_preempt_enable_no_resched() barrier()
76119 #define preempt_enable() barrier()
76120
76121 #define preempt_disable_notrace() barrier()
76122diff --git a/include/linux/printk.h b/include/linux/printk.h
76123index 22c7052..ad3fa0a 100644
76124--- a/include/linux/printk.h
76125+++ b/include/linux/printk.h
76126@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
76127 void early_printk(const char *s, ...) { }
76128 #endif
76129
76130+extern int kptr_restrict;
76131+
76132 #ifdef CONFIG_PRINTK
76133 asmlinkage __printf(5, 0)
76134 int vprintk_emit(int facility, int level,
76135@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
76136
76137 extern int printk_delay_msec;
76138 extern int dmesg_restrict;
76139-extern int kptr_restrict;
76140
76141 extern void wake_up_klogd(void);
76142
76143diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
76144index 608e60a..c26f864 100644
76145--- a/include/linux/proc_fs.h
76146+++ b/include/linux/proc_fs.h
76147@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
76148 return proc_create_data(name, mode, parent, proc_fops, NULL);
76149 }
76150
76151+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
76152+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
76153+{
76154+#ifdef CONFIG_GRKERNSEC_PROC_USER
76155+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
76156+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76157+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
76158+#else
76159+ return proc_create_data(name, mode, parent, proc_fops, NULL);
76160+#endif
76161+}
76162+
76163+
76164 extern void proc_set_size(struct proc_dir_entry *, loff_t);
76165 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
76166 extern void *PDE_DATA(const struct inode *);
76167diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
76168index 34a1e10..03a6d03 100644
76169--- a/include/linux/proc_ns.h
76170+++ b/include/linux/proc_ns.h
76171@@ -14,7 +14,7 @@ struct proc_ns_operations {
76172 void (*put)(void *ns);
76173 int (*install)(struct nsproxy *nsproxy, void *ns);
76174 unsigned int (*inum)(void *ns);
76175-};
76176+} __do_const;
76177
76178 struct proc_ns {
76179 void *ns;
76180diff --git a/include/linux/random.h b/include/linux/random.h
76181index 3b9377d..e418336 100644
76182--- a/include/linux/random.h
76183+++ b/include/linux/random.h
76184@@ -10,9 +10,19 @@
76185
76186
76187 extern void add_device_randomness(const void *, unsigned int);
76188+
76189+static inline void add_latent_entropy(void)
76190+{
76191+
76192+#ifdef LATENT_ENTROPY_PLUGIN
76193+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
76194+#endif
76195+
76196+}
76197+
76198 extern void add_input_randomness(unsigned int type, unsigned int code,
76199- unsigned int value);
76200-extern void add_interrupt_randomness(int irq, int irq_flags);
76201+ unsigned int value) __latent_entropy;
76202+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
76203
76204 extern void get_random_bytes(void *buf, int nbytes);
76205 extern void get_random_bytes_arch(void *buf, int nbytes);
76206@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
76207 u32 prandom_u32_state(struct rnd_state *);
76208 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
76209
76210+static inline unsigned long pax_get_random_long(void)
76211+{
76212+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
76213+}
76214+
76215 /*
76216 * Handle minimum values for seeds
76217 */
76218diff --git a/include/linux/rculist.h b/include/linux/rculist.h
76219index f4b1001..8ddb2b6 100644
76220--- a/include/linux/rculist.h
76221+++ b/include/linux/rculist.h
76222@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76223 struct list_head *prev, struct list_head *next);
76224 #endif
76225
76226+extern void __pax_list_add_rcu(struct list_head *new,
76227+ struct list_head *prev, struct list_head *next);
76228+
76229 /**
76230 * list_add_rcu - add a new entry to rcu-protected list
76231 * @new: new entry to be added
76232@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76233 __list_add_rcu(new, head, head->next);
76234 }
76235
76236+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76237+{
76238+ __pax_list_add_rcu(new, head, head->next);
76239+}
76240+
76241 /**
76242 * list_add_tail_rcu - add a new entry to rcu-protected list
76243 * @new: new entry to be added
76244@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76245 __list_add_rcu(new, head->prev, head);
76246 }
76247
76248+static inline void pax_list_add_tail_rcu(struct list_head *new,
76249+ struct list_head *head)
76250+{
76251+ __pax_list_add_rcu(new, head->prev, head);
76252+}
76253+
76254 /**
76255 * list_del_rcu - deletes entry from list without re-initialization
76256 * @entry: the element to delete from the list.
76257@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76258 entry->prev = LIST_POISON2;
76259 }
76260
76261+extern void pax_list_del_rcu(struct list_head *entry);
76262+
76263 /**
76264 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76265 * @n: the element to delete from the hash list.
76266diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76267index 8e00f9f..9449b55 100644
76268--- a/include/linux/reboot.h
76269+++ b/include/linux/reboot.h
76270@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76271 * Architecture-specific implementations of sys_reboot commands.
76272 */
76273
76274-extern void machine_restart(char *cmd);
76275-extern void machine_halt(void);
76276-extern void machine_power_off(void);
76277+extern void machine_restart(char *cmd) __noreturn;
76278+extern void machine_halt(void) __noreturn;
76279+extern void machine_power_off(void) __noreturn;
76280
76281 extern void machine_shutdown(void);
76282 struct pt_regs;
76283@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76284 */
76285
76286 extern void kernel_restart_prepare(char *cmd);
76287-extern void kernel_restart(char *cmd);
76288-extern void kernel_halt(void);
76289-extern void kernel_power_off(void);
76290+extern void kernel_restart(char *cmd) __noreturn;
76291+extern void kernel_halt(void) __noreturn;
76292+extern void kernel_power_off(void) __noreturn;
76293
76294 extern int C_A_D; /* for sysctl */
76295 void ctrl_alt_del(void);
76296@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76297 * Emergency restart, callable from an interrupt handler.
76298 */
76299
76300-extern void emergency_restart(void);
76301+extern void emergency_restart(void) __noreturn;
76302 #include <asm/emergency-restart.h>
76303
76304 #endif /* _LINUX_REBOOT_H */
76305diff --git a/include/linux/regset.h b/include/linux/regset.h
76306index 8e0c9fe..ac4d221 100644
76307--- a/include/linux/regset.h
76308+++ b/include/linux/regset.h
76309@@ -161,7 +161,8 @@ struct user_regset {
76310 unsigned int align;
76311 unsigned int bias;
76312 unsigned int core_note_type;
76313-};
76314+} __do_const;
76315+typedef struct user_regset __no_const user_regset_no_const;
76316
76317 /**
76318 * struct user_regset_view - available regsets
76319diff --git a/include/linux/relay.h b/include/linux/relay.h
76320index d7c8359..818daf5 100644
76321--- a/include/linux/relay.h
76322+++ b/include/linux/relay.h
76323@@ -157,7 +157,7 @@ struct rchan_callbacks
76324 * The callback should return 0 if successful, negative if not.
76325 */
76326 int (*remove_buf_file)(struct dentry *dentry);
76327-};
76328+} __no_const;
76329
76330 /*
76331 * CONFIG_RELAY kernel API, kernel/relay.c
76332diff --git a/include/linux/rio.h b/include/linux/rio.h
76333index b71d573..2f940bd 100644
76334--- a/include/linux/rio.h
76335+++ b/include/linux/rio.h
76336@@ -355,7 +355,7 @@ struct rio_ops {
76337 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76338 u64 rstart, u32 size, u32 flags);
76339 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76340-};
76341+} __no_const;
76342
76343 #define RIO_RESOURCE_MEM 0x00000100
76344 #define RIO_RESOURCE_DOORBELL 0x00000200
76345diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76346index 6dacb93..6174423 100644
76347--- a/include/linux/rmap.h
76348+++ b/include/linux/rmap.h
76349@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76350 void anon_vma_init(void); /* create anon_vma_cachep */
76351 int anon_vma_prepare(struct vm_area_struct *);
76352 void unlink_anon_vmas(struct vm_area_struct *);
76353-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76354-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76355+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76356+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76357
76358 static inline void anon_vma_merge(struct vm_area_struct *vma,
76359 struct vm_area_struct *next)
76360diff --git a/include/linux/sched.h b/include/linux/sched.h
76361index 078066d..4090b3b 100644
76362--- a/include/linux/sched.h
76363+++ b/include/linux/sched.h
76364@@ -62,6 +62,7 @@ struct bio_list;
76365 struct fs_struct;
76366 struct perf_event_context;
76367 struct blk_plug;
76368+struct linux_binprm;
76369
76370 /*
76371 * List of flags we want to share for kernel threads,
76372@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76373 extern int in_sched_functions(unsigned long addr);
76374
76375 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76376-extern signed long schedule_timeout(signed long timeout);
76377+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76378 extern signed long schedule_timeout_interruptible(signed long timeout);
76379 extern signed long schedule_timeout_killable(signed long timeout);
76380 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76381@@ -314,6 +315,19 @@ struct nsproxy;
76382 struct user_namespace;
76383
76384 #ifdef CONFIG_MMU
76385+
76386+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76387+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76388+#else
76389+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76390+{
76391+ return 0;
76392+}
76393+#endif
76394+
76395+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76396+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76397+
76398 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76399 extern unsigned long
76400 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76401@@ -589,6 +603,17 @@ struct signal_struct {
76402 #ifdef CONFIG_TASKSTATS
76403 struct taskstats *stats;
76404 #endif
76405+
76406+#ifdef CONFIG_GRKERNSEC
76407+ u32 curr_ip;
76408+ u32 saved_ip;
76409+ u32 gr_saddr;
76410+ u32 gr_daddr;
76411+ u16 gr_sport;
76412+ u16 gr_dport;
76413+ u8 used_accept:1;
76414+#endif
76415+
76416 #ifdef CONFIG_AUDIT
76417 unsigned audit_tty;
76418 unsigned audit_tty_log_passwd;
76419@@ -669,6 +694,14 @@ struct user_struct {
76420 struct key *session_keyring; /* UID's default session keyring */
76421 #endif
76422
76423+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76424+ unsigned char kernel_banned;
76425+#endif
76426+#ifdef CONFIG_GRKERNSEC_BRUTE
76427+ unsigned char suid_banned;
76428+ unsigned long suid_ban_expires;
76429+#endif
76430+
76431 /* Hash table maintenance information */
76432 struct hlist_node uidhash_node;
76433 kuid_t uid;
76434@@ -1151,8 +1184,8 @@ struct task_struct {
76435 struct list_head thread_group;
76436
76437 struct completion *vfork_done; /* for vfork() */
76438- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76439- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76440+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76441+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76442
76443 cputime_t utime, stime, utimescaled, stimescaled;
76444 cputime_t gtime;
76445@@ -1177,11 +1210,6 @@ struct task_struct {
76446 struct task_cputime cputime_expires;
76447 struct list_head cpu_timers[3];
76448
76449-/* process credentials */
76450- const struct cred __rcu *real_cred; /* objective and real subjective task
76451- * credentials (COW) */
76452- const struct cred __rcu *cred; /* effective (overridable) subjective task
76453- * credentials (COW) */
76454 char comm[TASK_COMM_LEN]; /* executable name excluding path
76455 - access with [gs]et_task_comm (which lock
76456 it with task_lock())
76457@@ -1198,6 +1226,10 @@ struct task_struct {
76458 #endif
76459 /* CPU-specific state of this task */
76460 struct thread_struct thread;
76461+/* thread_info moved to task_struct */
76462+#ifdef CONFIG_X86
76463+ struct thread_info tinfo;
76464+#endif
76465 /* filesystem information */
76466 struct fs_struct *fs;
76467 /* open file information */
76468@@ -1271,6 +1303,10 @@ struct task_struct {
76469 gfp_t lockdep_reclaim_gfp;
76470 #endif
76471
76472+/* process credentials */
76473+ const struct cred __rcu *real_cred; /* objective and real subjective task
76474+ * credentials (COW) */
76475+
76476 /* journalling filesystem info */
76477 void *journal_info;
76478
76479@@ -1309,6 +1345,10 @@ struct task_struct {
76480 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76481 struct list_head cg_list;
76482 #endif
76483+
76484+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76485+ * credentials (COW) */
76486+
76487 #ifdef CONFIG_FUTEX
76488 struct robust_list_head __user *robust_list;
76489 #ifdef CONFIG_COMPAT
76490@@ -1406,8 +1446,76 @@ struct task_struct {
76491 unsigned int sequential_io;
76492 unsigned int sequential_io_avg;
76493 #endif
76494+
76495+#ifdef CONFIG_GRKERNSEC
76496+ /* grsecurity */
76497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76498+ u64 exec_id;
76499+#endif
76500+#ifdef CONFIG_GRKERNSEC_SETXID
76501+ const struct cred *delayed_cred;
76502+#endif
76503+ struct dentry *gr_chroot_dentry;
76504+ struct acl_subject_label *acl;
76505+ struct acl_role_label *role;
76506+ struct file *exec_file;
76507+ unsigned long brute_expires;
76508+ u16 acl_role_id;
76509+ /* is this the task that authenticated to the special role */
76510+ u8 acl_sp_role;
76511+ u8 is_writable;
76512+ u8 brute;
76513+ u8 gr_is_chrooted;
76514+#endif
76515+
76516 };
76517
76518+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76519+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76520+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76521+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76522+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76523+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76524+
76525+#ifdef CONFIG_PAX_SOFTMODE
76526+extern int pax_softmode;
76527+#endif
76528+
76529+extern int pax_check_flags(unsigned long *);
76530+
76531+/* if tsk != current then task_lock must be held on it */
76532+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76533+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76534+{
76535+ if (likely(tsk->mm))
76536+ return tsk->mm->pax_flags;
76537+ else
76538+ return 0UL;
76539+}
76540+
76541+/* if tsk != current then task_lock must be held on it */
76542+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76543+{
76544+ if (likely(tsk->mm)) {
76545+ tsk->mm->pax_flags = flags;
76546+ return 0;
76547+ }
76548+ return -EINVAL;
76549+}
76550+#endif
76551+
76552+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76553+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76554+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76555+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76556+#endif
76557+
76558+struct path;
76559+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76560+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76561+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76562+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76563+
76564 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76565 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76566
76567@@ -1466,7 +1574,7 @@ struct pid_namespace;
76568 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76569 struct pid_namespace *ns);
76570
76571-static inline pid_t task_pid_nr(struct task_struct *tsk)
76572+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76573 {
76574 return tsk->pid;
76575 }
76576@@ -1916,7 +2024,9 @@ void yield(void);
76577 extern struct exec_domain default_exec_domain;
76578
76579 union thread_union {
76580+#ifndef CONFIG_X86
76581 struct thread_info thread_info;
76582+#endif
76583 unsigned long stack[THREAD_SIZE/sizeof(long)];
76584 };
76585
76586@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76587 */
76588
76589 extern struct task_struct *find_task_by_vpid(pid_t nr);
76590+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76591 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76592 struct pid_namespace *ns);
76593
76594@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76595 extern void exit_itimers(struct signal_struct *);
76596 extern void flush_itimer_signals(void);
76597
76598-extern void do_group_exit(int);
76599+extern __noreturn void do_group_exit(int);
76600
76601 extern int allow_signal(int);
76602 extern int disallow_signal(int);
76603@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76604
76605 #endif
76606
76607-static inline int object_is_on_stack(void *obj)
76608+static inline int object_starts_on_stack(void *obj)
76609 {
76610- void *stack = task_stack_page(current);
76611+ const void *stack = task_stack_page(current);
76612
76613 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76614 }
76615diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76616index bf8086b..962b035 100644
76617--- a/include/linux/sched/sysctl.h
76618+++ b/include/linux/sched/sysctl.h
76619@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76620 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76621
76622 extern int sysctl_max_map_count;
76623+extern unsigned long sysctl_heap_stack_gap;
76624
76625 extern unsigned int sysctl_sched_latency;
76626 extern unsigned int sysctl_sched_min_granularity;
76627diff --git a/include/linux/security.h b/include/linux/security.h
76628index 7ce53ae..8ee24a5 100644
76629--- a/include/linux/security.h
76630+++ b/include/linux/security.h
76631@@ -27,6 +27,7 @@
76632 #include <linux/slab.h>
76633 #include <linux/err.h>
76634 #include <linux/string.h>
76635+#include <linux/grsecurity.h>
76636
76637 struct linux_binprm;
76638 struct cred;
76639@@ -116,8 +117,6 @@ struct seq_file;
76640
76641 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76642
76643-void reset_security_ops(void);
76644-
76645 #ifdef CONFIG_MMU
76646 extern unsigned long mmap_min_addr;
76647 extern unsigned long dac_mmap_min_addr;
76648diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76649index 4e32edc..f8f2d18 100644
76650--- a/include/linux/seq_file.h
76651+++ b/include/linux/seq_file.h
76652@@ -26,6 +26,9 @@ struct seq_file {
76653 struct mutex lock;
76654 const struct seq_operations *op;
76655 int poll_event;
76656+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76657+ u64 exec_id;
76658+#endif
76659 #ifdef CONFIG_USER_NS
76660 struct user_namespace *user_ns;
76661 #endif
76662@@ -38,6 +41,7 @@ struct seq_operations {
76663 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76664 int (*show) (struct seq_file *m, void *v);
76665 };
76666+typedef struct seq_operations __no_const seq_operations_no_const;
76667
76668 #define SEQ_SKIP 1
76669
76670diff --git a/include/linux/shm.h b/include/linux/shm.h
76671index 429c199..4d42e38 100644
76672--- a/include/linux/shm.h
76673+++ b/include/linux/shm.h
76674@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76675
76676 /* The task created the shm object. NULL if the task is dead. */
76677 struct task_struct *shm_creator;
76678+#ifdef CONFIG_GRKERNSEC
76679+ time_t shm_createtime;
76680+ pid_t shm_lapid;
76681+#endif
76682 };
76683
76684 /* shm_mode upper byte flags */
76685diff --git a/include/linux/signal.h b/include/linux/signal.h
76686index d897484..323ba98 100644
76687--- a/include/linux/signal.h
76688+++ b/include/linux/signal.h
76689@@ -433,6 +433,7 @@ void signals_init(void);
76690
76691 int restore_altstack(const stack_t __user *);
76692 int __save_altstack(stack_t __user *, unsigned long);
76693+void __save_altstack_ex(stack_t __user *, unsigned long);
76694
76695 #ifdef CONFIG_PROC_FS
76696 struct seq_file;
76697diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76698index 3b71a4e..5c9f309 100644
76699--- a/include/linux/skbuff.h
76700+++ b/include/linux/skbuff.h
76701@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76702 extern struct sk_buff *__alloc_skb(unsigned int size,
76703 gfp_t priority, int flags, int node);
76704 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76705-static inline struct sk_buff *alloc_skb(unsigned int size,
76706+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76707 gfp_t priority)
76708 {
76709 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76710@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76711 */
76712 static inline int skb_queue_empty(const struct sk_buff_head *list)
76713 {
76714- return list->next == (struct sk_buff *)list;
76715+ return list->next == (const struct sk_buff *)list;
76716 }
76717
76718 /**
76719@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76720 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76721 const struct sk_buff *skb)
76722 {
76723- return skb->next == (struct sk_buff *)list;
76724+ return skb->next == (const struct sk_buff *)list;
76725 }
76726
76727 /**
76728@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76729 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76730 const struct sk_buff *skb)
76731 {
76732- return skb->prev == (struct sk_buff *)list;
76733+ return skb->prev == (const struct sk_buff *)list;
76734 }
76735
76736 /**
76737@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76738 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76739 */
76740 #ifndef NET_SKB_PAD
76741-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76742+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76743 #endif
76744
76745 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76746@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76747 int noblock, int *err);
76748 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76749 struct poll_table_struct *wait);
76750-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76751+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76752 int offset, struct iovec *to,
76753 int size);
76754 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76755@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76756 nf_bridge_put(skb->nf_bridge);
76757 skb->nf_bridge = NULL;
76758 #endif
76759+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76760+ skb->nf_trace = 0;
76761+#endif
76762 }
76763
76764 static inline void nf_reset_trace(struct sk_buff *skb)
76765diff --git a/include/linux/slab.h b/include/linux/slab.h
76766index 6c5cc0e..9ca0fd6 100644
76767--- a/include/linux/slab.h
76768+++ b/include/linux/slab.h
76769@@ -12,15 +12,29 @@
76770 #include <linux/gfp.h>
76771 #include <linux/types.h>
76772 #include <linux/workqueue.h>
76773-
76774+#include <linux/err.h>
76775
76776 /*
76777 * Flags to pass to kmem_cache_create().
76778 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76779 */
76780 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76781+
76782+#ifdef CONFIG_PAX_USERCOPY_SLABS
76783+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76784+#else
76785+#define SLAB_USERCOPY 0x00000000UL
76786+#endif
76787+
76788 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76789 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76790+
76791+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76792+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76793+#else
76794+#define SLAB_NO_SANITIZE 0x00000000UL
76795+#endif
76796+
76797 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76798 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76799 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76800@@ -89,10 +103,13 @@
76801 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76802 * Both make kfree a no-op.
76803 */
76804-#define ZERO_SIZE_PTR ((void *)16)
76805+#define ZERO_SIZE_PTR \
76806+({ \
76807+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76808+ (void *)(-MAX_ERRNO-1L); \
76809+})
76810
76811-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76812- (unsigned long)ZERO_SIZE_PTR)
76813+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76814
76815
76816 struct mem_cgroup;
76817@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76818 void kfree(const void *);
76819 void kzfree(const void *);
76820 size_t ksize(const void *);
76821+const char *check_heap_object(const void *ptr, unsigned long n);
76822+bool is_usercopy_object(const void *ptr);
76823
76824 /*
76825 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76826@@ -164,7 +183,7 @@ struct kmem_cache {
76827 unsigned int align; /* Alignment as calculated */
76828 unsigned long flags; /* Active flags on the slab */
76829 const char *name; /* Slab name for sysfs */
76830- int refcount; /* Use counter */
76831+ atomic_t refcount; /* Use counter */
76832 void (*ctor)(void *); /* Called on object slot creation */
76833 struct list_head list; /* List of all slab caches on the system */
76834 };
76835@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76836 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76837 #endif
76838
76839+#ifdef CONFIG_PAX_USERCOPY_SLABS
76840+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76841+#endif
76842+
76843 /*
76844 * Figure out which kmalloc slab an allocation of a certain size
76845 * belongs to.
76846@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76847 * 2 = 120 .. 192 bytes
76848 * n = 2^(n-1) .. 2^n -1
76849 */
76850-static __always_inline int kmalloc_index(size_t size)
76851+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76852 {
76853 if (!size)
76854 return 0;
76855@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76856 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76857 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76858 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76859-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76860+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76861 #define kmalloc_track_caller(size, flags) \
76862 __kmalloc_track_caller(size, flags, _RET_IP_)
76863 #else
76864@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76865 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76866 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76867 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76868-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76869+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76870 #define kmalloc_node_track_caller(size, flags, node) \
76871 __kmalloc_node_track_caller(size, flags, node, \
76872 _RET_IP_)
76873diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76874index cd40158..4e2f7af 100644
76875--- a/include/linux/slab_def.h
76876+++ b/include/linux/slab_def.h
76877@@ -50,7 +50,7 @@ struct kmem_cache {
76878 /* 4) cache creation/removal */
76879 const char *name;
76880 struct list_head list;
76881- int refcount;
76882+ atomic_t refcount;
76883 int object_size;
76884 int align;
76885
76886@@ -66,10 +66,14 @@ struct kmem_cache {
76887 unsigned long node_allocs;
76888 unsigned long node_frees;
76889 unsigned long node_overflow;
76890- atomic_t allochit;
76891- atomic_t allocmiss;
76892- atomic_t freehit;
76893- atomic_t freemiss;
76894+ atomic_unchecked_t allochit;
76895+ atomic_unchecked_t allocmiss;
76896+ atomic_unchecked_t freehit;
76897+ atomic_unchecked_t freemiss;
76898+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76899+ atomic_unchecked_t sanitized;
76900+ atomic_unchecked_t not_sanitized;
76901+#endif
76902
76903 /*
76904 * If debugging is enabled, then the allocator can add additional
76905@@ -103,7 +107,7 @@ struct kmem_cache {
76906 };
76907
76908 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76909-void *__kmalloc(size_t size, gfp_t flags);
76910+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76911
76912 #ifdef CONFIG_TRACING
76913 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76914@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76915 cachep = kmalloc_dma_caches[i];
76916 else
76917 #endif
76918+
76919+#ifdef CONFIG_PAX_USERCOPY_SLABS
76920+ if (flags & GFP_USERCOPY)
76921+ cachep = kmalloc_usercopy_caches[i];
76922+ else
76923+#endif
76924+
76925 cachep = kmalloc_caches[i];
76926
76927 ret = kmem_cache_alloc_trace(cachep, flags, size);
76928@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76929 }
76930
76931 #ifdef CONFIG_NUMA
76932-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76933+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76934 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76935
76936 #ifdef CONFIG_TRACING
76937@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76938 cachep = kmalloc_dma_caches[i];
76939 else
76940 #endif
76941+
76942+#ifdef CONFIG_PAX_USERCOPY_SLABS
76943+ if (flags & GFP_USERCOPY)
76944+ cachep = kmalloc_usercopy_caches[i];
76945+ else
76946+#endif
76947+
76948 cachep = kmalloc_caches[i];
76949
76950 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76951diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76952index 095a5a4..4b82027 100644
76953--- a/include/linux/slob_def.h
76954+++ b/include/linux/slob_def.h
76955@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76956 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76957 }
76958
76959-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76960+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76961
76962 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76963 {
76964@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76965 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76966 }
76967
76968-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76969+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76970 {
76971 return kmalloc(size, flags);
76972 }
76973diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76974index 027276f..092bfe8 100644
76975--- a/include/linux/slub_def.h
76976+++ b/include/linux/slub_def.h
76977@@ -80,7 +80,7 @@ struct kmem_cache {
76978 struct kmem_cache_order_objects max;
76979 struct kmem_cache_order_objects min;
76980 gfp_t allocflags; /* gfp flags to use on each alloc */
76981- int refcount; /* Refcount for slab cache destroy */
76982+ atomic_t refcount; /* Refcount for slab cache destroy */
76983 void (*ctor)(void *);
76984 int inuse; /* Offset to metadata */
76985 int align; /* Alignment */
76986@@ -105,7 +105,7 @@ struct kmem_cache {
76987 };
76988
76989 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76990-void *__kmalloc(size_t size, gfp_t flags);
76991+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76992
76993 static __always_inline void *
76994 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76995@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76996 }
76997 #endif
76998
76999-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
77000+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
77001 {
77002 unsigned int order = get_order(size);
77003 return kmalloc_order_trace(size, flags, order);
77004@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
77005 }
77006
77007 #ifdef CONFIG_NUMA
77008-void *__kmalloc_node(size_t size, gfp_t flags, int node);
77009+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
77010 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
77011
77012 #ifdef CONFIG_TRACING
77013diff --git a/include/linux/smp.h b/include/linux/smp.h
77014index c181399..09d7b92 100644
77015--- a/include/linux/smp.h
77016+++ b/include/linux/smp.h
77017@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
77018 #endif
77019
77020 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
77021+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
77022 #define put_cpu() preempt_enable()
77023+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
77024
77025 /*
77026 * Callback to arch code if there's nosmp or maxcpus=0 on the
77027diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
77028index 54f91d3..be2c379 100644
77029--- a/include/linux/sock_diag.h
77030+++ b/include/linux/sock_diag.h
77031@@ -11,7 +11,7 @@ struct sock;
77032 struct sock_diag_handler {
77033 __u8 family;
77034 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
77035-};
77036+} __do_const;
77037
77038 int sock_diag_register(const struct sock_diag_handler *h);
77039 void sock_diag_unregister(const struct sock_diag_handler *h);
77040diff --git a/include/linux/sonet.h b/include/linux/sonet.h
77041index 680f9a3..f13aeb0 100644
77042--- a/include/linux/sonet.h
77043+++ b/include/linux/sonet.h
77044@@ -7,7 +7,7 @@
77045 #include <uapi/linux/sonet.h>
77046
77047 struct k_sonet_stats {
77048-#define __HANDLE_ITEM(i) atomic_t i
77049+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77050 __SONET_ITEMS
77051 #undef __HANDLE_ITEM
77052 };
77053diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
77054index 07d8e53..dc934c9 100644
77055--- a/include/linux/sunrpc/addr.h
77056+++ b/include/linux/sunrpc/addr.h
77057@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
77058 {
77059 switch (sap->sa_family) {
77060 case AF_INET:
77061- return ntohs(((struct sockaddr_in *)sap)->sin_port);
77062+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
77063 case AF_INET6:
77064- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
77065+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
77066 }
77067 return 0;
77068 }
77069@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
77070 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
77071 const struct sockaddr *src)
77072 {
77073- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
77074+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
77075 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
77076
77077 dsin->sin_family = ssin->sin_family;
77078@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
77079 if (sa->sa_family != AF_INET6)
77080 return 0;
77081
77082- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
77083+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
77084 }
77085
77086 #endif /* _LINUX_SUNRPC_ADDR_H */
77087diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
77088index bfe11be..12bc8c4 100644
77089--- a/include/linux/sunrpc/clnt.h
77090+++ b/include/linux/sunrpc/clnt.h
77091@@ -96,7 +96,7 @@ struct rpc_procinfo {
77092 unsigned int p_timer; /* Which RTT timer to use */
77093 u32 p_statidx; /* Which procedure to account */
77094 const char * p_name; /* name of procedure */
77095-};
77096+} __do_const;
77097
77098 #ifdef __KERNEL__
77099
77100diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
77101index 1f0216b..6a4fa50 100644
77102--- a/include/linux/sunrpc/svc.h
77103+++ b/include/linux/sunrpc/svc.h
77104@@ -411,7 +411,7 @@ struct svc_procedure {
77105 unsigned int pc_count; /* call count */
77106 unsigned int pc_cachetype; /* cache info (NFS) */
77107 unsigned int pc_xdrressize; /* maximum size of XDR reply */
77108-};
77109+} __do_const;
77110
77111 /*
77112 * Function prototypes.
77113diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
77114index 0b8e3e6..33e0a01 100644
77115--- a/include/linux/sunrpc/svc_rdma.h
77116+++ b/include/linux/sunrpc/svc_rdma.h
77117@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
77118 extern unsigned int svcrdma_max_requests;
77119 extern unsigned int svcrdma_max_req_size;
77120
77121-extern atomic_t rdma_stat_recv;
77122-extern atomic_t rdma_stat_read;
77123-extern atomic_t rdma_stat_write;
77124-extern atomic_t rdma_stat_sq_starve;
77125-extern atomic_t rdma_stat_rq_starve;
77126-extern atomic_t rdma_stat_rq_poll;
77127-extern atomic_t rdma_stat_rq_prod;
77128-extern atomic_t rdma_stat_sq_poll;
77129-extern atomic_t rdma_stat_sq_prod;
77130+extern atomic_unchecked_t rdma_stat_recv;
77131+extern atomic_unchecked_t rdma_stat_read;
77132+extern atomic_unchecked_t rdma_stat_write;
77133+extern atomic_unchecked_t rdma_stat_sq_starve;
77134+extern atomic_unchecked_t rdma_stat_rq_starve;
77135+extern atomic_unchecked_t rdma_stat_rq_poll;
77136+extern atomic_unchecked_t rdma_stat_rq_prod;
77137+extern atomic_unchecked_t rdma_stat_sq_poll;
77138+extern atomic_unchecked_t rdma_stat_sq_prod;
77139
77140 #define RPCRDMA_VERSION 1
77141
77142diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
77143index 8d71d65..f79586e 100644
77144--- a/include/linux/sunrpc/svcauth.h
77145+++ b/include/linux/sunrpc/svcauth.h
77146@@ -120,7 +120,7 @@ struct auth_ops {
77147 int (*release)(struct svc_rqst *rq);
77148 void (*domain_release)(struct auth_domain *);
77149 int (*set_client)(struct svc_rqst *rq);
77150-};
77151+} __do_const;
77152
77153 #define SVC_GARBAGE 1
77154 #define SVC_SYSERR 2
77155diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77156index a5ffd32..0935dea 100644
77157--- a/include/linux/swiotlb.h
77158+++ b/include/linux/swiotlb.h
77159@@ -60,7 +60,8 @@ extern void
77160
77161 extern void
77162 swiotlb_free_coherent(struct device *hwdev, size_t size,
77163- void *vaddr, dma_addr_t dma_handle);
77164+ void *vaddr, dma_addr_t dma_handle,
77165+ struct dma_attrs *attrs);
77166
77167 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77168 unsigned long offset, size_t size,
77169diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77170index 84662ec..5271947 100644
77171--- a/include/linux/syscalls.h
77172+++ b/include/linux/syscalls.h
77173@@ -97,8 +97,14 @@ struct sigaltstack;
77174 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77175
77176 #define __SC_DECL(t, a) t a
77177+#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))
77178 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77179-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77180+#define __SC_LONG(t, a) __typeof( \
77181+ __builtin_choose_expr( \
77182+ sizeof(t) > sizeof(int), \
77183+ (t) 0, \
77184+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77185+ )) a
77186 #define __SC_CAST(t, a) (t) a
77187 #define __SC_ARGS(t, a) a
77188 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77189@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
77190 asmlinkage long sys_fsync(unsigned int fd);
77191 asmlinkage long sys_fdatasync(unsigned int fd);
77192 asmlinkage long sys_bdflush(int func, long data);
77193-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77194- char __user *type, unsigned long flags,
77195+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77196+ const char __user *type, unsigned long flags,
77197 void __user *data);
77198-asmlinkage long sys_umount(char __user *name, int flags);
77199-asmlinkage long sys_oldumount(char __user *name);
77200+asmlinkage long sys_umount(const char __user *name, int flags);
77201+asmlinkage long sys_oldumount(const char __user *name);
77202 asmlinkage long sys_truncate(const char __user *path, long length);
77203 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77204 asmlinkage long sys_stat(const char __user *filename,
77205@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77206 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77207 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77208 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77209- struct sockaddr __user *, int);
77210+ struct sockaddr __user *, int) __intentional_overflow(0);
77211 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77212 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77213 unsigned int vlen, unsigned flags);
77214diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77215index 27b3b0b..e093dd9 100644
77216--- a/include/linux/syscore_ops.h
77217+++ b/include/linux/syscore_ops.h
77218@@ -16,7 +16,7 @@ struct syscore_ops {
77219 int (*suspend)(void);
77220 void (*resume)(void);
77221 void (*shutdown)(void);
77222-};
77223+} __do_const;
77224
77225 extern void register_syscore_ops(struct syscore_ops *ops);
77226 extern void unregister_syscore_ops(struct syscore_ops *ops);
77227diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77228index 14a8ff2..af52bad 100644
77229--- a/include/linux/sysctl.h
77230+++ b/include/linux/sysctl.h
77231@@ -34,13 +34,13 @@ struct ctl_table_root;
77232 struct ctl_table_header;
77233 struct ctl_dir;
77234
77235-typedef struct ctl_table ctl_table;
77236-
77237 typedef int proc_handler (struct ctl_table *ctl, int write,
77238 void __user *buffer, size_t *lenp, loff_t *ppos);
77239
77240 extern int proc_dostring(struct ctl_table *, int,
77241 void __user *, size_t *, loff_t *);
77242+extern int proc_dostring_modpriv(struct ctl_table *, int,
77243+ void __user *, size_t *, loff_t *);
77244 extern int proc_dointvec(struct ctl_table *, int,
77245 void __user *, size_t *, loff_t *);
77246 extern int proc_dointvec_minmax(struct ctl_table *, int,
77247@@ -115,7 +115,9 @@ struct ctl_table
77248 struct ctl_table_poll *poll;
77249 void *extra1;
77250 void *extra2;
77251-};
77252+} __do_const;
77253+typedef struct ctl_table __no_const ctl_table_no_const;
77254+typedef struct ctl_table ctl_table;
77255
77256 struct ctl_node {
77257 struct rb_node node;
77258diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77259index 9e8a9b5..753de68 100644
77260--- a/include/linux/sysfs.h
77261+++ b/include/linux/sysfs.h
77262@@ -33,7 +33,8 @@ struct attribute {
77263 struct lock_class_key *key;
77264 struct lock_class_key skey;
77265 #endif
77266-};
77267+} __do_const;
77268+typedef struct attribute __no_const attribute_no_const;
77269
77270 /**
77271 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77272@@ -62,7 +63,8 @@ struct attribute_group {
77273 struct attribute *, int);
77274 struct attribute **attrs;
77275 struct bin_attribute **bin_attrs;
77276-};
77277+} __do_const;
77278+typedef struct attribute_group __no_const attribute_group_no_const;
77279
77280 /**
77281 * Use these macros to make defining attributes easier. See include/linux/device.h
77282@@ -123,7 +125,8 @@ struct bin_attribute {
77283 char *, loff_t, size_t);
77284 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77285 struct vm_area_struct *vma);
77286-};
77287+} __do_const;
77288+typedef struct bin_attribute __no_const bin_attribute_no_const;
77289
77290 /**
77291 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77292diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77293index 7faf933..9b85a0c 100644
77294--- a/include/linux/sysrq.h
77295+++ b/include/linux/sysrq.h
77296@@ -16,6 +16,7 @@
77297
77298 #include <linux/errno.h>
77299 #include <linux/types.h>
77300+#include <linux/compiler.h>
77301
77302 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77303 #define SYSRQ_DEFAULT_ENABLE 1
77304@@ -36,7 +37,7 @@ struct sysrq_key_op {
77305 char *help_msg;
77306 char *action_msg;
77307 int enable_mask;
77308-};
77309+} __do_const;
77310
77311 #ifdef CONFIG_MAGIC_SYSRQ
77312
77313diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77314index e7e0473..7989295 100644
77315--- a/include/linux/thread_info.h
77316+++ b/include/linux/thread_info.h
77317@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77318 #error "no set_restore_sigmask() provided and default one won't work"
77319 #endif
77320
77321+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77322+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77323+{
77324+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77325+ if (!__builtin_constant_p(n))
77326+#endif
77327+ __check_object_size(ptr, n, to_user);
77328+}
77329+
77330 #endif /* __KERNEL__ */
77331
77332 #endif /* _LINUX_THREAD_INFO_H */
77333diff --git a/include/linux/tty.h b/include/linux/tty.h
77334index 01ac30e..bf18a71 100644
77335--- a/include/linux/tty.h
77336+++ b/include/linux/tty.h
77337@@ -194,7 +194,7 @@ struct tty_port {
77338 const struct tty_port_operations *ops; /* Port operations */
77339 spinlock_t lock; /* Lock protecting tty field */
77340 int blocked_open; /* Waiting to open */
77341- int count; /* Usage count */
77342+ atomic_t count; /* Usage count */
77343 wait_queue_head_t open_wait; /* Open waiters */
77344 wait_queue_head_t close_wait; /* Close waiters */
77345 wait_queue_head_t delta_msr_wait; /* Modem status change */
77346@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77347 struct tty_struct *tty, struct file *filp);
77348 static inline int tty_port_users(struct tty_port *port)
77349 {
77350- return port->count + port->blocked_open;
77351+ return atomic_read(&port->count) + port->blocked_open;
77352 }
77353
77354 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77355diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77356index 756a609..b302dd6 100644
77357--- a/include/linux/tty_driver.h
77358+++ b/include/linux/tty_driver.h
77359@@ -285,7 +285,7 @@ struct tty_operations {
77360 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77361 #endif
77362 const struct file_operations *proc_fops;
77363-};
77364+} __do_const;
77365
77366 struct tty_driver {
77367 int magic; /* magic number for this structure */
77368diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77369index a1b0489..f02e17c 100644
77370--- a/include/linux/tty_ldisc.h
77371+++ b/include/linux/tty_ldisc.h
77372@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77373
77374 struct module *owner;
77375
77376- int refcount;
77377+ atomic_t refcount;
77378 };
77379
77380 struct tty_ldisc {
77381diff --git a/include/linux/types.h b/include/linux/types.h
77382index 4d118ba..c3ee9bf 100644
77383--- a/include/linux/types.h
77384+++ b/include/linux/types.h
77385@@ -176,10 +176,26 @@ typedef struct {
77386 int counter;
77387 } atomic_t;
77388
77389+#ifdef CONFIG_PAX_REFCOUNT
77390+typedef struct {
77391+ int counter;
77392+} atomic_unchecked_t;
77393+#else
77394+typedef atomic_t atomic_unchecked_t;
77395+#endif
77396+
77397 #ifdef CONFIG_64BIT
77398 typedef struct {
77399 long counter;
77400 } atomic64_t;
77401+
77402+#ifdef CONFIG_PAX_REFCOUNT
77403+typedef struct {
77404+ long counter;
77405+} atomic64_unchecked_t;
77406+#else
77407+typedef atomic64_t atomic64_unchecked_t;
77408+#endif
77409 #endif
77410
77411 struct list_head {
77412diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77413index 5ca0951..ab496a5 100644
77414--- a/include/linux/uaccess.h
77415+++ b/include/linux/uaccess.h
77416@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77417 long ret; \
77418 mm_segment_t old_fs = get_fs(); \
77419 \
77420- set_fs(KERNEL_DS); \
77421 pagefault_disable(); \
77422- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77423- pagefault_enable(); \
77424+ set_fs(KERNEL_DS); \
77425+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77426 set_fs(old_fs); \
77427+ pagefault_enable(); \
77428 ret; \
77429 })
77430
77431diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77432index 8e522cbc..aa8572d 100644
77433--- a/include/linux/uidgid.h
77434+++ b/include/linux/uidgid.h
77435@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77436
77437 #endif /* CONFIG_USER_NS */
77438
77439+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77440+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77441+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77442+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77443+
77444 #endif /* _LINUX_UIDGID_H */
77445diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77446index 99c1b4d..562e6f3 100644
77447--- a/include/linux/unaligned/access_ok.h
77448+++ b/include/linux/unaligned/access_ok.h
77449@@ -4,34 +4,34 @@
77450 #include <linux/kernel.h>
77451 #include <asm/byteorder.h>
77452
77453-static inline u16 get_unaligned_le16(const void *p)
77454+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77455 {
77456- return le16_to_cpup((__le16 *)p);
77457+ return le16_to_cpup((const __le16 *)p);
77458 }
77459
77460-static inline u32 get_unaligned_le32(const void *p)
77461+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77462 {
77463- return le32_to_cpup((__le32 *)p);
77464+ return le32_to_cpup((const __le32 *)p);
77465 }
77466
77467-static inline u64 get_unaligned_le64(const void *p)
77468+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77469 {
77470- return le64_to_cpup((__le64 *)p);
77471+ return le64_to_cpup((const __le64 *)p);
77472 }
77473
77474-static inline u16 get_unaligned_be16(const void *p)
77475+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77476 {
77477- return be16_to_cpup((__be16 *)p);
77478+ return be16_to_cpup((const __be16 *)p);
77479 }
77480
77481-static inline u32 get_unaligned_be32(const void *p)
77482+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77483 {
77484- return be32_to_cpup((__be32 *)p);
77485+ return be32_to_cpup((const __be32 *)p);
77486 }
77487
77488-static inline u64 get_unaligned_be64(const void *p)
77489+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77490 {
77491- return be64_to_cpup((__be64 *)p);
77492+ return be64_to_cpup((const __be64 *)p);
77493 }
77494
77495 static inline void put_unaligned_le16(u16 val, void *p)
77496diff --git a/include/linux/usb.h b/include/linux/usb.h
77497index 0eec268..4496526 100644
77498--- a/include/linux/usb.h
77499+++ b/include/linux/usb.h
77500@@ -560,7 +560,7 @@ struct usb_device {
77501 int maxchild;
77502
77503 u32 quirks;
77504- atomic_t urbnum;
77505+ atomic_unchecked_t urbnum;
77506
77507 unsigned long active_duration;
77508
77509@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77510
77511 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77512 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77513- void *data, __u16 size, int timeout);
77514+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77515 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77516 void *data, int len, int *actual_length, int timeout);
77517 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77518diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77519index e452ba6..78f8e80 100644
77520--- a/include/linux/usb/renesas_usbhs.h
77521+++ b/include/linux/usb/renesas_usbhs.h
77522@@ -39,7 +39,7 @@ enum {
77523 */
77524 struct renesas_usbhs_driver_callback {
77525 int (*notify_hotplug)(struct platform_device *pdev);
77526-};
77527+} __no_const;
77528
77529 /*
77530 * callback functions for platform
77531diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77532index 6f8fbcf..8259001 100644
77533--- a/include/linux/vermagic.h
77534+++ b/include/linux/vermagic.h
77535@@ -25,9 +25,35 @@
77536 #define MODULE_ARCH_VERMAGIC ""
77537 #endif
77538
77539+#ifdef CONFIG_PAX_REFCOUNT
77540+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77541+#else
77542+#define MODULE_PAX_REFCOUNT ""
77543+#endif
77544+
77545+#ifdef CONSTIFY_PLUGIN
77546+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77547+#else
77548+#define MODULE_CONSTIFY_PLUGIN ""
77549+#endif
77550+
77551+#ifdef STACKLEAK_PLUGIN
77552+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77553+#else
77554+#define MODULE_STACKLEAK_PLUGIN ""
77555+#endif
77556+
77557+#ifdef CONFIG_GRKERNSEC
77558+#define MODULE_GRSEC "GRSEC "
77559+#else
77560+#define MODULE_GRSEC ""
77561+#endif
77562+
77563 #define VERMAGIC_STRING \
77564 UTS_RELEASE " " \
77565 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77566 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77567- MODULE_ARCH_VERMAGIC
77568+ MODULE_ARCH_VERMAGIC \
77569+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77570+ MODULE_GRSEC
77571
77572diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77573index 4b8a891..c20e936 100644
77574--- a/include/linux/vmalloc.h
77575+++ b/include/linux/vmalloc.h
77576@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77577 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77578 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77579 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77580+
77581+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77582+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77583+#endif
77584+
77585 /* bits [20..32] reserved for arch specific ioremap internals */
77586
77587 /*
77588@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77589 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77590 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77591 unsigned long start, unsigned long end, gfp_t gfp_mask,
77592- pgprot_t prot, int node, const void *caller);
77593+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77594 extern void vfree(const void *addr);
77595
77596 extern void *vmap(struct page **pages, unsigned int count,
77597@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77598 extern void free_vm_area(struct vm_struct *area);
77599
77600 /* for /dev/kmem */
77601-extern long vread(char *buf, char *addr, unsigned long count);
77602-extern long vwrite(char *buf, char *addr, unsigned long count);
77603+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77604+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77605
77606 /*
77607 * Internals. Dont't use..
77608diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77609index c586679..f06b389 100644
77610--- a/include/linux/vmstat.h
77611+++ b/include/linux/vmstat.h
77612@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77613 /*
77614 * Zone based page accounting with per cpu differentials.
77615 */
77616-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77617+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77618
77619 static inline void zone_page_state_add(long x, struct zone *zone,
77620 enum zone_stat_item item)
77621 {
77622- atomic_long_add(x, &zone->vm_stat[item]);
77623- atomic_long_add(x, &vm_stat[item]);
77624+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77625+ atomic_long_add_unchecked(x, &vm_stat[item]);
77626 }
77627
77628 static inline unsigned long global_page_state(enum zone_stat_item item)
77629 {
77630- long x = atomic_long_read(&vm_stat[item]);
77631+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77632 #ifdef CONFIG_SMP
77633 if (x < 0)
77634 x = 0;
77635@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77636 static inline unsigned long zone_page_state(struct zone *zone,
77637 enum zone_stat_item item)
77638 {
77639- long x = atomic_long_read(&zone->vm_stat[item]);
77640+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77641 #ifdef CONFIG_SMP
77642 if (x < 0)
77643 x = 0;
77644@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77645 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77646 enum zone_stat_item item)
77647 {
77648- long x = atomic_long_read(&zone->vm_stat[item]);
77649+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77650
77651 #ifdef CONFIG_SMP
77652 int cpu;
77653@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77654
77655 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77656 {
77657- atomic_long_inc(&zone->vm_stat[item]);
77658- atomic_long_inc(&vm_stat[item]);
77659+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77660+ atomic_long_inc_unchecked(&vm_stat[item]);
77661 }
77662
77663 static inline void __inc_zone_page_state(struct page *page,
77664@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77665
77666 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77667 {
77668- atomic_long_dec(&zone->vm_stat[item]);
77669- atomic_long_dec(&vm_stat[item]);
77670+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77671+ atomic_long_dec_unchecked(&vm_stat[item]);
77672 }
77673
77674 static inline void __dec_zone_page_state(struct page *page,
77675diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77676index fdbafc6..49dfe4f 100644
77677--- a/include/linux/xattr.h
77678+++ b/include/linux/xattr.h
77679@@ -28,7 +28,7 @@ struct xattr_handler {
77680 size_t size, int handler_flags);
77681 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77682 size_t size, int flags, int handler_flags);
77683-};
77684+} __do_const;
77685
77686 struct xattr {
77687 char *name;
77688@@ -37,6 +37,9 @@ struct xattr {
77689 };
77690
77691 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77692+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77693+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77694+#endif
77695 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77696 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77697 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77698diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77699index 9c5a6b4..09c9438 100644
77700--- a/include/linux/zlib.h
77701+++ b/include/linux/zlib.h
77702@@ -31,6 +31,7 @@
77703 #define _ZLIB_H
77704
77705 #include <linux/zconf.h>
77706+#include <linux/compiler.h>
77707
77708 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77709 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77710@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77711
77712 /* basic functions */
77713
77714-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77715+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77716 /*
77717 Returns the number of bytes that needs to be allocated for a per-
77718 stream workspace with the specified parameters. A pointer to this
77719diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77720index c768c9f..bdcaa5a 100644
77721--- a/include/media/v4l2-dev.h
77722+++ b/include/media/v4l2-dev.h
77723@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77724 int (*mmap) (struct file *, struct vm_area_struct *);
77725 int (*open) (struct file *);
77726 int (*release) (struct file *);
77727-};
77728+} __do_const;
77729
77730 /*
77731 * Newer version of video_device, handled by videodev2.c
77732diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77733index c9b1593..a572459 100644
77734--- a/include/media/v4l2-device.h
77735+++ b/include/media/v4l2-device.h
77736@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77737 this function returns 0. If the name ends with a digit (e.g. cx18),
77738 then the name will be set to cx18-0 since cx180 looks really odd. */
77739 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77740- atomic_t *instance);
77741+ atomic_unchecked_t *instance);
77742
77743 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77744 Since the parent disappears this ensures that v4l2_dev doesn't have an
77745diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77746index d9fa68f..45c88d1 100644
77747--- a/include/net/9p/transport.h
77748+++ b/include/net/9p/transport.h
77749@@ -63,7 +63,7 @@ struct p9_trans_module {
77750 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77751 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77752 char *, char *, int , int, int, int);
77753-};
77754+} __do_const;
77755
77756 void v9fs_register_trans(struct p9_trans_module *m);
77757 void v9fs_unregister_trans(struct p9_trans_module *m);
77758diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77759index 1a966af..2767cf6 100644
77760--- a/include/net/bluetooth/l2cap.h
77761+++ b/include/net/bluetooth/l2cap.h
77762@@ -551,7 +551,7 @@ struct l2cap_ops {
77763 void (*defer) (struct l2cap_chan *chan);
77764 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77765 unsigned long len, int nb);
77766-};
77767+} __do_const;
77768
77769 struct l2cap_conn {
77770 struct hci_conn *hcon;
77771diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77772index f2ae33d..c457cf0 100644
77773--- a/include/net/caif/cfctrl.h
77774+++ b/include/net/caif/cfctrl.h
77775@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77776 void (*radioset_rsp)(void);
77777 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77778 struct cflayer *client_layer);
77779-};
77780+} __no_const;
77781
77782 /* Link Setup Parameters for CAIF-Links. */
77783 struct cfctrl_link_param {
77784@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77785 struct cfctrl {
77786 struct cfsrvl serv;
77787 struct cfctrl_rsp res;
77788- atomic_t req_seq_no;
77789- atomic_t rsp_seq_no;
77790+ atomic_unchecked_t req_seq_no;
77791+ atomic_unchecked_t rsp_seq_no;
77792 struct list_head list;
77793 /* Protects from simultaneous access to first_req list */
77794 spinlock_t info_list_lock;
77795diff --git a/include/net/flow.h b/include/net/flow.h
77796index 628e11b..4c475df 100644
77797--- a/include/net/flow.h
77798+++ b/include/net/flow.h
77799@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77800
77801 extern void flow_cache_flush(void);
77802 extern void flow_cache_flush_deferred(void);
77803-extern atomic_t flow_cache_genid;
77804+extern atomic_unchecked_t flow_cache_genid;
77805
77806 #endif
77807diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77808index 8e0b6c8..73cf605 100644
77809--- a/include/net/genetlink.h
77810+++ b/include/net/genetlink.h
77811@@ -120,7 +120,7 @@ struct genl_ops {
77812 struct netlink_callback *cb);
77813 int (*done)(struct netlink_callback *cb);
77814 struct list_head ops_list;
77815-};
77816+} __do_const;
77817
77818 extern int __genl_register_family(struct genl_family *family);
77819
77820diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77821index 734d9b5..48a9a4b 100644
77822--- a/include/net/gro_cells.h
77823+++ b/include/net/gro_cells.h
77824@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77825 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77826
77827 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77828- atomic_long_inc(&dev->rx_dropped);
77829+ atomic_long_inc_unchecked(&dev->rx_dropped);
77830 kfree_skb(skb);
77831 return;
77832 }
77833diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77834index de2c785..0588a6b 100644
77835--- a/include/net/inet_connection_sock.h
77836+++ b/include/net/inet_connection_sock.h
77837@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77838 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77839 int (*bind_conflict)(const struct sock *sk,
77840 const struct inet_bind_bucket *tb, bool relax);
77841-};
77842+} __do_const;
77843
77844 /** inet_connection_sock - INET connection oriented sock
77845 *
77846diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77847index 53f464d..0bd0b49 100644
77848--- a/include/net/inetpeer.h
77849+++ b/include/net/inetpeer.h
77850@@ -47,8 +47,8 @@ struct inet_peer {
77851 */
77852 union {
77853 struct {
77854- atomic_t rid; /* Frag reception counter */
77855- atomic_t ip_id_count; /* IP ID for the next packet */
77856+ atomic_unchecked_t rid; /* Frag reception counter */
77857+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77858 };
77859 struct rcu_head rcu;
77860 struct inet_peer *gc_next;
77861@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77862 /* can be called with or without local BH being disabled */
77863 static inline int inet_getid(struct inet_peer *p, int more)
77864 {
77865- int old, new;
77866+ int id;
77867 more++;
77868 inet_peer_refcheck(p);
77869- do {
77870- old = atomic_read(&p->ip_id_count);
77871- new = old + more;
77872- if (!new)
77873- new = 1;
77874- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77875- return new;
77876+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77877+ if (!id)
77878+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77879+ return id;
77880 }
77881
77882 #endif /* _NET_INETPEER_H */
77883diff --git a/include/net/ip.h b/include/net/ip.h
77884index a68f838..74518ab 100644
77885--- a/include/net/ip.h
77886+++ b/include/net/ip.h
77887@@ -202,7 +202,7 @@ extern struct local_ports {
77888 } sysctl_local_ports;
77889 extern void inet_get_local_port_range(int *low, int *high);
77890
77891-extern unsigned long *sysctl_local_reserved_ports;
77892+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77893 static inline int inet_is_reserved_local_port(int port)
77894 {
77895 return test_bit(port, sysctl_local_reserved_ports);
77896diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77897index cbf2be3..3683f6d 100644
77898--- a/include/net/ip_fib.h
77899+++ b/include/net/ip_fib.h
77900@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77901
77902 #define FIB_RES_SADDR(net, res) \
77903 ((FIB_RES_NH(res).nh_saddr_genid == \
77904- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77905+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77906 FIB_RES_NH(res).nh_saddr : \
77907 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77908 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77909diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77910index f0d70f0..185f15b 100644
77911--- a/include/net/ip_vs.h
77912+++ b/include/net/ip_vs.h
77913@@ -588,7 +588,7 @@ struct ip_vs_conn {
77914 struct ip_vs_conn *control; /* Master control connection */
77915 atomic_t n_control; /* Number of controlled ones */
77916 struct ip_vs_dest *dest; /* real server */
77917- atomic_t in_pkts; /* incoming packet counter */
77918+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77919
77920 /* packet transmitter for different forwarding methods. If it
77921 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77922@@ -737,7 +737,7 @@ struct ip_vs_dest {
77923 __be16 port; /* port number of the server */
77924 union nf_inet_addr addr; /* IP address of the server */
77925 volatile unsigned int flags; /* dest status flags */
77926- atomic_t conn_flags; /* flags to copy to conn */
77927+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77928 atomic_t weight; /* server weight */
77929
77930 atomic_t refcnt; /* reference counter */
77931@@ -993,11 +993,11 @@ struct netns_ipvs {
77932 /* ip_vs_lblc */
77933 int sysctl_lblc_expiration;
77934 struct ctl_table_header *lblc_ctl_header;
77935- struct ctl_table *lblc_ctl_table;
77936+ ctl_table_no_const *lblc_ctl_table;
77937 /* ip_vs_lblcr */
77938 int sysctl_lblcr_expiration;
77939 struct ctl_table_header *lblcr_ctl_header;
77940- struct ctl_table *lblcr_ctl_table;
77941+ ctl_table_no_const *lblcr_ctl_table;
77942 /* ip_vs_est */
77943 struct list_head est_list; /* estimator list */
77944 spinlock_t est_lock;
77945diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77946index 80ffde3..968b0f4 100644
77947--- a/include/net/irda/ircomm_tty.h
77948+++ b/include/net/irda/ircomm_tty.h
77949@@ -35,6 +35,7 @@
77950 #include <linux/termios.h>
77951 #include <linux/timer.h>
77952 #include <linux/tty.h> /* struct tty_struct */
77953+#include <asm/local.h>
77954
77955 #include <net/irda/irias_object.h>
77956 #include <net/irda/ircomm_core.h>
77957diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77958index 714cc9a..ea05f3e 100644
77959--- a/include/net/iucv/af_iucv.h
77960+++ b/include/net/iucv/af_iucv.h
77961@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77962 struct iucv_sock_list {
77963 struct hlist_head head;
77964 rwlock_t lock;
77965- atomic_t autobind_name;
77966+ atomic_unchecked_t autobind_name;
77967 };
77968
77969 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77970diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77971index df83f69..9b640b8 100644
77972--- a/include/net/llc_c_ac.h
77973+++ b/include/net/llc_c_ac.h
77974@@ -87,7 +87,7 @@
77975 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77976 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77977
77978-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77979+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77980
77981 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77982 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77983diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77984index 6ca3113..f8026dd 100644
77985--- a/include/net/llc_c_ev.h
77986+++ b/include/net/llc_c_ev.h
77987@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77988 return (struct llc_conn_state_ev *)skb->cb;
77989 }
77990
77991-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77992-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77993+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77994+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77995
77996 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77997 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77998diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77999index 0e79cfb..f46db31 100644
78000--- a/include/net/llc_c_st.h
78001+++ b/include/net/llc_c_st.h
78002@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
78003 u8 next_state;
78004 llc_conn_ev_qfyr_t *ev_qualifiers;
78005 llc_conn_action_t *ev_actions;
78006-};
78007+} __do_const;
78008
78009 struct llc_conn_state {
78010 u8 current_state;
78011diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
78012index 37a3bbd..55a4241 100644
78013--- a/include/net/llc_s_ac.h
78014+++ b/include/net/llc_s_ac.h
78015@@ -23,7 +23,7 @@
78016 #define SAP_ACT_TEST_IND 9
78017
78018 /* All action functions must look like this */
78019-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78020+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78021
78022 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
78023 struct sk_buff *skb);
78024diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
78025index 567c681..cd73ac0 100644
78026--- a/include/net/llc_s_st.h
78027+++ b/include/net/llc_s_st.h
78028@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
78029 llc_sap_ev_t ev;
78030 u8 next_state;
78031 llc_sap_action_t *ev_actions;
78032-};
78033+} __do_const;
78034
78035 struct llc_sap_state {
78036 u8 curr_state;
78037diff --git a/include/net/mac80211.h b/include/net/mac80211.h
78038index 551ba6a..11c99c1 100644
78039--- a/include/net/mac80211.h
78040+++ b/include/net/mac80211.h
78041@@ -4221,7 +4221,7 @@ struct rate_control_ops {
78042 void (*add_sta_debugfs)(void *priv, void *priv_sta,
78043 struct dentry *dir);
78044 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
78045-};
78046+} __do_const;
78047
78048 static inline int rate_supported(struct ieee80211_sta *sta,
78049 enum ieee80211_band band,
78050diff --git a/include/net/neighbour.h b/include/net/neighbour.h
78051index 7e748ad..5c6229b 100644
78052--- a/include/net/neighbour.h
78053+++ b/include/net/neighbour.h
78054@@ -123,7 +123,7 @@ struct neigh_ops {
78055 void (*error_report)(struct neighbour *, struct sk_buff *);
78056 int (*output)(struct neighbour *, struct sk_buff *);
78057 int (*connected_output)(struct neighbour *, struct sk_buff *);
78058-};
78059+} __do_const;
78060
78061 struct pneigh_entry {
78062 struct pneigh_entry *next;
78063diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
78064index 84e37b1..8eba19a 100644
78065--- a/include/net/net_namespace.h
78066+++ b/include/net/net_namespace.h
78067@@ -119,8 +119,8 @@ struct net {
78068 struct netns_ipvs *ipvs;
78069 #endif
78070 struct sock *diag_nlsk;
78071- atomic_t rt_genid;
78072- atomic_t fnhe_genid;
78073+ atomic_unchecked_t rt_genid;
78074+ atomic_unchecked_t fnhe_genid;
78075 };
78076
78077 /*
78078@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
78079 #define __net_init __init
78080 #define __net_exit __exit_refok
78081 #define __net_initdata __initdata
78082+#ifdef CONSTIFY_PLUGIN
78083 #define __net_initconst __initconst
78084+#else
78085+#define __net_initconst __initdata
78086+#endif
78087 #endif
78088
78089 struct pernet_operations {
78090@@ -287,7 +291,7 @@ struct pernet_operations {
78091 void (*exit_batch)(struct list_head *net_exit_list);
78092 int *id;
78093 size_t size;
78094-};
78095+} __do_const;
78096
78097 /*
78098 * Use these carefully. If you implement a network device and it
78099@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
78100
78101 static inline int rt_genid(struct net *net)
78102 {
78103- return atomic_read(&net->rt_genid);
78104+ return atomic_read_unchecked(&net->rt_genid);
78105 }
78106
78107 static inline void rt_genid_bump(struct net *net)
78108 {
78109- atomic_inc(&net->rt_genid);
78110+ atomic_inc_unchecked(&net->rt_genid);
78111 }
78112
78113 static inline int fnhe_genid(struct net *net)
78114 {
78115- return atomic_read(&net->fnhe_genid);
78116+ return atomic_read_unchecked(&net->fnhe_genid);
78117 }
78118
78119 static inline void fnhe_genid_bump(struct net *net)
78120 {
78121- atomic_inc(&net->fnhe_genid);
78122+ atomic_inc_unchecked(&net->fnhe_genid);
78123 }
78124
78125 #endif /* __NET_NET_NAMESPACE_H */
78126diff --git a/include/net/netdma.h b/include/net/netdma.h
78127index 8ba8ce2..99b7fff 100644
78128--- a/include/net/netdma.h
78129+++ b/include/net/netdma.h
78130@@ -24,7 +24,7 @@
78131 #include <linux/dmaengine.h>
78132 #include <linux/skbuff.h>
78133
78134-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78135+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78136 struct sk_buff *skb, int offset, struct iovec *to,
78137 size_t len, struct dma_pinned_list *pinned_list);
78138
78139diff --git a/include/net/netlink.h b/include/net/netlink.h
78140index 9690b0f..87aded7 100644
78141--- a/include/net/netlink.h
78142+++ b/include/net/netlink.h
78143@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
78144 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
78145 {
78146 if (mark)
78147- skb_trim(skb, (unsigned char *) mark - skb->data);
78148+ skb_trim(skb, (const unsigned char *) mark - skb->data);
78149 }
78150
78151 /**
78152diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78153index c9c0c53..53f24c3 100644
78154--- a/include/net/netns/conntrack.h
78155+++ b/include/net/netns/conntrack.h
78156@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78157 struct nf_proto_net {
78158 #ifdef CONFIG_SYSCTL
78159 struct ctl_table_header *ctl_table_header;
78160- struct ctl_table *ctl_table;
78161+ ctl_table_no_const *ctl_table;
78162 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78163 struct ctl_table_header *ctl_compat_header;
78164- struct ctl_table *ctl_compat_table;
78165+ ctl_table_no_const *ctl_compat_table;
78166 #endif
78167 #endif
78168 unsigned int users;
78169@@ -58,7 +58,7 @@ struct nf_ip_net {
78170 struct nf_icmp_net icmpv6;
78171 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78172 struct ctl_table_header *ctl_table_header;
78173- struct ctl_table *ctl_table;
78174+ ctl_table_no_const *ctl_table;
78175 #endif
78176 };
78177
78178diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78179index 2ba9de8..47bd6c7 100644
78180--- a/include/net/netns/ipv4.h
78181+++ b/include/net/netns/ipv4.h
78182@@ -67,7 +67,7 @@ struct netns_ipv4 {
78183 kgid_t sysctl_ping_group_range[2];
78184 long sysctl_tcp_mem[3];
78185
78186- atomic_t dev_addr_genid;
78187+ atomic_unchecked_t dev_addr_genid;
78188
78189 #ifdef CONFIG_IP_MROUTE
78190 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78191diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78192index 005e2c2..023d340 100644
78193--- a/include/net/netns/ipv6.h
78194+++ b/include/net/netns/ipv6.h
78195@@ -71,7 +71,7 @@ struct netns_ipv6 {
78196 struct fib_rules_ops *mr6_rules_ops;
78197 #endif
78198 #endif
78199- atomic_t dev_addr_genid;
78200+ atomic_unchecked_t dev_addr_genid;
78201 };
78202
78203 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
78204diff --git a/include/net/ping.h b/include/net/ping.h
78205index 5db0224..0d65365 100644
78206--- a/include/net/ping.h
78207+++ b/include/net/ping.h
78208@@ -55,7 +55,7 @@ struct ping_iter_state {
78209 extern struct proto ping_prot;
78210 extern struct ping_table ping_table;
78211 #if IS_ENABLED(CONFIG_IPV6)
78212-extern struct pingv6_ops pingv6_ops;
78213+extern struct pingv6_ops *pingv6_ops;
78214 #endif
78215
78216 struct pingfakehdr {
78217diff --git a/include/net/protocol.h b/include/net/protocol.h
78218index 047c047..b9dad15 100644
78219--- a/include/net/protocol.h
78220+++ b/include/net/protocol.h
78221@@ -44,7 +44,7 @@ struct net_protocol {
78222 void (*err_handler)(struct sk_buff *skb, u32 info);
78223 unsigned int no_policy:1,
78224 netns_ok:1;
78225-};
78226+} __do_const;
78227
78228 #if IS_ENABLED(CONFIG_IPV6)
78229 struct inet6_protocol {
78230@@ -57,7 +57,7 @@ struct inet6_protocol {
78231 u8 type, u8 code, int offset,
78232 __be32 info);
78233 unsigned int flags; /* INET6_PROTO_xxx */
78234-};
78235+} __do_const;
78236
78237 #define INET6_PROTO_NOPOLICY 0x1
78238 #define INET6_PROTO_FINAL 0x2
78239diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78240index 7026648..584cc8c 100644
78241--- a/include/net/rtnetlink.h
78242+++ b/include/net/rtnetlink.h
78243@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78244 const struct net_device *dev);
78245 unsigned int (*get_num_tx_queues)(void);
78246 unsigned int (*get_num_rx_queues)(void);
78247-};
78248+} __do_const;
78249
78250 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78251 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78252diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78253index 2a82d13..62a31c2 100644
78254--- a/include/net/sctp/sm.h
78255+++ b/include/net/sctp/sm.h
78256@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78257 typedef struct {
78258 sctp_state_fn_t *fn;
78259 const char *name;
78260-} sctp_sm_table_entry_t;
78261+} __do_const sctp_sm_table_entry_t;
78262
78263 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78264 * currently in use.
78265@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78266 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78267
78268 /* Extern declarations for major data structures. */
78269-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78270+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78271
78272
78273 /* Get the size of a DATA chunk payload. */
78274diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78275index e745c92..3641448 100644
78276--- a/include/net/sctp/structs.h
78277+++ b/include/net/sctp/structs.h
78278@@ -516,7 +516,7 @@ struct sctp_pf {
78279 struct sctp_association *asoc);
78280 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78281 struct sctp_af *af;
78282-};
78283+} __do_const;
78284
78285
78286 /* Structure to track chunk fragments that have been acked, but peer
78287diff --git a/include/net/sock.h b/include/net/sock.h
78288index 31d5cfb..9ee0602 100644
78289--- a/include/net/sock.h
78290+++ b/include/net/sock.h
78291@@ -331,7 +331,7 @@ struct sock {
78292 unsigned int sk_napi_id;
78293 unsigned int sk_ll_usec;
78294 #endif
78295- atomic_t sk_drops;
78296+ atomic_unchecked_t sk_drops;
78297 int sk_rcvbuf;
78298
78299 struct sk_filter __rcu *sk_filter;
78300@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78301 }
78302
78303 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78304- char __user *from, char *to,
78305+ char __user *from, unsigned char *to,
78306 int copy, int offset)
78307 {
78308 if (skb->ip_summed == CHECKSUM_NONE) {
78309@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78310 }
78311 }
78312
78313-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78314+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78315
78316 /**
78317 * sk_page_frag - return an appropriate page_frag
78318diff --git a/include/net/tcp.h b/include/net/tcp.h
78319index d198005..c974a393 100644
78320--- a/include/net/tcp.h
78321+++ b/include/net/tcp.h
78322@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78323 extern void tcp_xmit_retransmit_queue(struct sock *);
78324 extern void tcp_simple_retransmit(struct sock *);
78325 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78326-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78327+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78328
78329 extern void tcp_send_probe0(struct sock *);
78330 extern void tcp_send_partial(struct sock *);
78331@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78332 struct inet6_skb_parm h6;
78333 #endif
78334 } header; /* For incoming frames */
78335- __u32 seq; /* Starting sequence number */
78336- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78337+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78338+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78339 __u32 when; /* used to compute rtt's */
78340 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78341
78342@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78343
78344 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78345 /* 1 byte hole */
78346- __u32 ack_seq; /* Sequence number ACK'd */
78347+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78348 };
78349
78350 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78351diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78352index e823786..53b0608 100644
78353--- a/include/net/xfrm.h
78354+++ b/include/net/xfrm.h
78355@@ -287,7 +287,6 @@ struct xfrm_dst;
78356 struct xfrm_policy_afinfo {
78357 unsigned short family;
78358 struct dst_ops *dst_ops;
78359- void (*garbage_collect)(struct net *net);
78360 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78361 const xfrm_address_t *saddr,
78362 const xfrm_address_t *daddr);
78363@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78364 struct net_device *dev,
78365 const struct flowi *fl);
78366 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78367-};
78368+} __do_const;
78369
78370 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78371 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78372@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78373 int (*transport_finish)(struct sk_buff *skb,
78374 int async);
78375 void (*local_error)(struct sk_buff *skb, u32 mtu);
78376-};
78377+} __do_const;
78378
78379 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78380 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78381@@ -427,7 +426,7 @@ struct xfrm_mode {
78382 struct module *owner;
78383 unsigned int encap;
78384 int flags;
78385-};
78386+} __do_const;
78387
78388 /* Flags for xfrm_mode. */
78389 enum {
78390@@ -524,7 +523,7 @@ struct xfrm_policy {
78391 struct timer_list timer;
78392
78393 struct flow_cache_object flo;
78394- atomic_t genid;
78395+ atomic_unchecked_t genid;
78396 u32 priority;
78397 u32 index;
78398 struct xfrm_mark mark;
78399@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78400 }
78401
78402 extern void xfrm_garbage_collect(struct net *net);
78403+extern void xfrm_garbage_collect_deferred(struct net *net);
78404
78405 #else
78406
78407@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78408 static inline void xfrm_garbage_collect(struct net *net)
78409 {
78410 }
78411+static inline void xfrm_garbage_collect_deferred(struct net *net)
78412+{
78413+}
78414 #endif
78415
78416 static __inline__
78417diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78418index 1a046b1..ee0bef0 100644
78419--- a/include/rdma/iw_cm.h
78420+++ b/include/rdma/iw_cm.h
78421@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78422 int backlog);
78423
78424 int (*destroy_listen)(struct iw_cm_id *cm_id);
78425-};
78426+} __no_const;
78427
78428 /**
78429 * iw_create_cm_id - Create an IW CM identifier.
78430diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78431index e1379b4..67eafbe 100644
78432--- a/include/scsi/libfc.h
78433+++ b/include/scsi/libfc.h
78434@@ -762,6 +762,7 @@ struct libfc_function_template {
78435 */
78436 void (*disc_stop_final) (struct fc_lport *);
78437 };
78438+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78439
78440 /**
78441 * struct fc_disc - Discovery context
78442@@ -866,7 +867,7 @@ struct fc_lport {
78443 struct fc_vport *vport;
78444
78445 /* Operational Information */
78446- struct libfc_function_template tt;
78447+ libfc_function_template_no_const tt;
78448 u8 link_up;
78449 u8 qfull;
78450 enum fc_lport_state state;
78451diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78452index a44954c..5da04b2 100644
78453--- a/include/scsi/scsi_device.h
78454+++ b/include/scsi/scsi_device.h
78455@@ -172,9 +172,9 @@ struct scsi_device {
78456 unsigned int max_device_blocked; /* what device_blocked counts down from */
78457 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78458
78459- atomic_t iorequest_cnt;
78460- atomic_t iodone_cnt;
78461- atomic_t ioerr_cnt;
78462+ atomic_unchecked_t iorequest_cnt;
78463+ atomic_unchecked_t iodone_cnt;
78464+ atomic_unchecked_t ioerr_cnt;
78465
78466 struct device sdev_gendev,
78467 sdev_dev;
78468diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78469index b797e8f..8e2c3aa 100644
78470--- a/include/scsi/scsi_transport_fc.h
78471+++ b/include/scsi/scsi_transport_fc.h
78472@@ -751,7 +751,8 @@ struct fc_function_template {
78473 unsigned long show_host_system_hostname:1;
78474
78475 unsigned long disable_target_scan:1;
78476-};
78477+} __do_const;
78478+typedef struct fc_function_template __no_const fc_function_template_no_const;
78479
78480
78481 /**
78482diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78483index 9031a26..750d592 100644
78484--- a/include/sound/compress_driver.h
78485+++ b/include/sound/compress_driver.h
78486@@ -128,7 +128,7 @@ struct snd_compr_ops {
78487 struct snd_compr_caps *caps);
78488 int (*get_codec_caps) (struct snd_compr_stream *stream,
78489 struct snd_compr_codec_caps *codec);
78490-};
78491+} __no_const;
78492
78493 /**
78494 * struct snd_compr: Compressed device
78495diff --git a/include/sound/soc.h b/include/sound/soc.h
78496index 6eabee7..58afb50 100644
78497--- a/include/sound/soc.h
78498+++ b/include/sound/soc.h
78499@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78500 /* probe ordering - for components with runtime dependencies */
78501 int probe_order;
78502 int remove_order;
78503-};
78504+} __do_const;
78505
78506 /* SoC platform interface */
78507 struct snd_soc_platform_driver {
78508@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78509 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78510 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78511 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78512-};
78513+} __do_const;
78514
78515 struct snd_soc_platform {
78516 const char *name;
78517diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78518index e34fc90..ecefa2c 100644
78519--- a/include/target/target_core_base.h
78520+++ b/include/target/target_core_base.h
78521@@ -643,7 +643,7 @@ struct se_device {
78522 spinlock_t stats_lock;
78523 /* Active commands on this virtual SE device */
78524 atomic_t simple_cmds;
78525- atomic_t dev_ordered_id;
78526+ atomic_unchecked_t dev_ordered_id;
78527 atomic_t dev_ordered_sync;
78528 atomic_t dev_qf_count;
78529 int export_count;
78530diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78531new file mode 100644
78532index 0000000..fb634b7
78533--- /dev/null
78534+++ b/include/trace/events/fs.h
78535@@ -0,0 +1,53 @@
78536+#undef TRACE_SYSTEM
78537+#define TRACE_SYSTEM fs
78538+
78539+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78540+#define _TRACE_FS_H
78541+
78542+#include <linux/fs.h>
78543+#include <linux/tracepoint.h>
78544+
78545+TRACE_EVENT(do_sys_open,
78546+
78547+ TP_PROTO(const char *filename, int flags, int mode),
78548+
78549+ TP_ARGS(filename, flags, mode),
78550+
78551+ TP_STRUCT__entry(
78552+ __string( filename, filename )
78553+ __field( int, flags )
78554+ __field( int, mode )
78555+ ),
78556+
78557+ TP_fast_assign(
78558+ __assign_str(filename, filename);
78559+ __entry->flags = flags;
78560+ __entry->mode = mode;
78561+ ),
78562+
78563+ TP_printk("\"%s\" %x %o",
78564+ __get_str(filename), __entry->flags, __entry->mode)
78565+);
78566+
78567+TRACE_EVENT(open_exec,
78568+
78569+ TP_PROTO(const char *filename),
78570+
78571+ TP_ARGS(filename),
78572+
78573+ TP_STRUCT__entry(
78574+ __string( filename, filename )
78575+ ),
78576+
78577+ TP_fast_assign(
78578+ __assign_str(filename, filename);
78579+ ),
78580+
78581+ TP_printk("\"%s\"",
78582+ __get_str(filename))
78583+);
78584+
78585+#endif /* _TRACE_FS_H */
78586+
78587+/* This part must be outside protection */
78588+#include <trace/define_trace.h>
78589diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78590index 1c09820..7f5ec79 100644
78591--- a/include/trace/events/irq.h
78592+++ b/include/trace/events/irq.h
78593@@ -36,7 +36,7 @@ struct softirq_action;
78594 */
78595 TRACE_EVENT(irq_handler_entry,
78596
78597- TP_PROTO(int irq, struct irqaction *action),
78598+ TP_PROTO(int irq, const struct irqaction *action),
78599
78600 TP_ARGS(irq, action),
78601
78602@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78603 */
78604 TRACE_EVENT(irq_handler_exit,
78605
78606- TP_PROTO(int irq, struct irqaction *action, int ret),
78607+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78608
78609 TP_ARGS(irq, action, ret),
78610
78611diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78612index 7caf44c..23c6f27 100644
78613--- a/include/uapi/linux/a.out.h
78614+++ b/include/uapi/linux/a.out.h
78615@@ -39,6 +39,14 @@ enum machine_type {
78616 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78617 };
78618
78619+/* Constants for the N_FLAGS field */
78620+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78621+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78622+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78623+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78624+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78625+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78626+
78627 #if !defined (N_MAGIC)
78628 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78629 #endif
78630diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78631index d876736..ccce5c0 100644
78632--- a/include/uapi/linux/byteorder/little_endian.h
78633+++ b/include/uapi/linux/byteorder/little_endian.h
78634@@ -42,51 +42,51 @@
78635
78636 static inline __le64 __cpu_to_le64p(const __u64 *p)
78637 {
78638- return (__force __le64)*p;
78639+ return (__force const __le64)*p;
78640 }
78641-static inline __u64 __le64_to_cpup(const __le64 *p)
78642+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78643 {
78644- return (__force __u64)*p;
78645+ return (__force const __u64)*p;
78646 }
78647 static inline __le32 __cpu_to_le32p(const __u32 *p)
78648 {
78649- return (__force __le32)*p;
78650+ return (__force const __le32)*p;
78651 }
78652 static inline __u32 __le32_to_cpup(const __le32 *p)
78653 {
78654- return (__force __u32)*p;
78655+ return (__force const __u32)*p;
78656 }
78657 static inline __le16 __cpu_to_le16p(const __u16 *p)
78658 {
78659- return (__force __le16)*p;
78660+ return (__force const __le16)*p;
78661 }
78662 static inline __u16 __le16_to_cpup(const __le16 *p)
78663 {
78664- return (__force __u16)*p;
78665+ return (__force const __u16)*p;
78666 }
78667 static inline __be64 __cpu_to_be64p(const __u64 *p)
78668 {
78669- return (__force __be64)__swab64p(p);
78670+ return (__force const __be64)__swab64p(p);
78671 }
78672 static inline __u64 __be64_to_cpup(const __be64 *p)
78673 {
78674- return __swab64p((__u64 *)p);
78675+ return __swab64p((const __u64 *)p);
78676 }
78677 static inline __be32 __cpu_to_be32p(const __u32 *p)
78678 {
78679- return (__force __be32)__swab32p(p);
78680+ return (__force const __be32)__swab32p(p);
78681 }
78682-static inline __u32 __be32_to_cpup(const __be32 *p)
78683+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78684 {
78685- return __swab32p((__u32 *)p);
78686+ return __swab32p((const __u32 *)p);
78687 }
78688 static inline __be16 __cpu_to_be16p(const __u16 *p)
78689 {
78690- return (__force __be16)__swab16p(p);
78691+ return (__force const __be16)__swab16p(p);
78692 }
78693 static inline __u16 __be16_to_cpup(const __be16 *p)
78694 {
78695- return __swab16p((__u16 *)p);
78696+ return __swab16p((const __u16 *)p);
78697 }
78698 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78699 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78700diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78701index ef6103b..d4e65dd 100644
78702--- a/include/uapi/linux/elf.h
78703+++ b/include/uapi/linux/elf.h
78704@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78705 #define PT_GNU_EH_FRAME 0x6474e550
78706
78707 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78708+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78709+
78710+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78711+
78712+/* Constants for the e_flags field */
78713+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78714+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78715+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78716+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78717+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78718+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78719
78720 /*
78721 * Extended Numbering
78722@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78723 #define DT_DEBUG 21
78724 #define DT_TEXTREL 22
78725 #define DT_JMPREL 23
78726+#define DT_FLAGS 30
78727+ #define DF_TEXTREL 0x00000004
78728 #define DT_ENCODING 32
78729 #define OLD_DT_LOOS 0x60000000
78730 #define DT_LOOS 0x6000000d
78731@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78732 #define PF_W 0x2
78733 #define PF_X 0x1
78734
78735+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78736+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78737+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78738+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78739+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78740+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78741+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78742+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78743+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78744+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78745+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78746+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78747+
78748 typedef struct elf32_phdr{
78749 Elf32_Word p_type;
78750 Elf32_Off p_offset;
78751@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78752 #define EI_OSABI 7
78753 #define EI_PAD 8
78754
78755+#define EI_PAX 14
78756+
78757 #define ELFMAG0 0x7f /* EI_MAG */
78758 #define ELFMAG1 'E'
78759 #define ELFMAG2 'L'
78760diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78761index aa169c4..6a2771d 100644
78762--- a/include/uapi/linux/personality.h
78763+++ b/include/uapi/linux/personality.h
78764@@ -30,6 +30,7 @@ enum {
78765 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78766 ADDR_NO_RANDOMIZE | \
78767 ADDR_COMPAT_LAYOUT | \
78768+ ADDR_LIMIT_3GB | \
78769 MMAP_PAGE_ZERO)
78770
78771 /*
78772diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78773index 7530e74..e714828 100644
78774--- a/include/uapi/linux/screen_info.h
78775+++ b/include/uapi/linux/screen_info.h
78776@@ -43,7 +43,8 @@ struct screen_info {
78777 __u16 pages; /* 0x32 */
78778 __u16 vesa_attributes; /* 0x34 */
78779 __u32 capabilities; /* 0x36 */
78780- __u8 _reserved[6]; /* 0x3a */
78781+ __u16 vesapm_size; /* 0x3a */
78782+ __u8 _reserved[4]; /* 0x3c */
78783 } __attribute__((packed));
78784
78785 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78786diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78787index 0e011eb..82681b1 100644
78788--- a/include/uapi/linux/swab.h
78789+++ b/include/uapi/linux/swab.h
78790@@ -43,7 +43,7 @@
78791 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78792 */
78793
78794-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78795+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78796 {
78797 #ifdef __HAVE_BUILTIN_BSWAP16__
78798 return __builtin_bswap16(val);
78799@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78800 #endif
78801 }
78802
78803-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78804+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78805 {
78806 #ifdef __HAVE_BUILTIN_BSWAP32__
78807 return __builtin_bswap32(val);
78808@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78809 #endif
78810 }
78811
78812-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78813+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78814 {
78815 #ifdef __HAVE_BUILTIN_BSWAP64__
78816 return __builtin_bswap64(val);
78817diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78818index 6d67213..8dab561 100644
78819--- a/include/uapi/linux/sysctl.h
78820+++ b/include/uapi/linux/sysctl.h
78821@@ -155,7 +155,11 @@ enum
78822 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78823 };
78824
78825-
78826+#ifdef CONFIG_PAX_SOFTMODE
78827+enum {
78828+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78829+};
78830+#endif
78831
78832 /* CTL_VM names: */
78833 enum
78834diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78835index e4629b9..6958086 100644
78836--- a/include/uapi/linux/xattr.h
78837+++ b/include/uapi/linux/xattr.h
78838@@ -63,5 +63,9 @@
78839 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78840 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78841
78842+/* User namespace */
78843+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78844+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78845+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78846
78847 #endif /* _UAPI_LINUX_XATTR_H */
78848diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78849index f9466fa..f4e2b81 100644
78850--- a/include/video/udlfb.h
78851+++ b/include/video/udlfb.h
78852@@ -53,10 +53,10 @@ struct dlfb_data {
78853 u32 pseudo_palette[256];
78854 int blank_mode; /*one of FB_BLANK_ */
78855 /* blit-only rendering path metrics, exposed through sysfs */
78856- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78857- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78858- atomic_t bytes_sent; /* to usb, after compression including overhead */
78859- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78860+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78861+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78862+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78863+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78864 };
78865
78866 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78867diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78868index 30f5362..8ed8ac9 100644
78869--- a/include/video/uvesafb.h
78870+++ b/include/video/uvesafb.h
78871@@ -122,6 +122,7 @@ struct uvesafb_par {
78872 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78873 u8 pmi_setpal; /* PMI for palette changes */
78874 u16 *pmi_base; /* protected mode interface location */
78875+ u8 *pmi_code; /* protected mode code location */
78876 void *pmi_start;
78877 void *pmi_pal;
78878 u8 *vbe_state_orig; /*
78879diff --git a/init/Kconfig b/init/Kconfig
78880index fed81b5..0d3b964 100644
78881--- a/init/Kconfig
78882+++ b/init/Kconfig
78883@@ -1069,6 +1069,7 @@ endif # CGROUPS
78884
78885 config CHECKPOINT_RESTORE
78886 bool "Checkpoint/restore support" if EXPERT
78887+ depends on !GRKERNSEC
78888 default n
78889 help
78890 Enables additional kernel features in a sake of checkpoint/restore.
78891@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78892
78893 config COMPAT_BRK
78894 bool "Disable heap randomization"
78895- default y
78896+ default n
78897 help
78898 Randomizing heap placement makes heap exploits harder, but it
78899 also breaks ancient binaries (including anything libc5 based).
78900@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78901 config STOP_MACHINE
78902 bool
78903 default y
78904- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78905+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78906 help
78907 Need stop_machine() primitive.
78908
78909diff --git a/init/Makefile b/init/Makefile
78910index 7bc47ee..6da2dc7 100644
78911--- a/init/Makefile
78912+++ b/init/Makefile
78913@@ -2,6 +2,9 @@
78914 # Makefile for the linux kernel.
78915 #
78916
78917+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78918+asflags-y := $(GCC_PLUGINS_AFLAGS)
78919+
78920 obj-y := main.o version.o mounts.o
78921 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78922 obj-y += noinitramfs.o
78923diff --git a/init/do_mounts.c b/init/do_mounts.c
78924index 816014c..c2054db 100644
78925--- a/init/do_mounts.c
78926+++ b/init/do_mounts.c
78927@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78928 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78929 {
78930 struct super_block *s;
78931- int err = sys_mount(name, "/root", fs, flags, data);
78932+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78933 if (err)
78934 return err;
78935
78936- sys_chdir("/root");
78937+ sys_chdir((const char __force_user *)"/root");
78938 s = current->fs->pwd.dentry->d_sb;
78939 ROOT_DEV = s->s_dev;
78940 printk(KERN_INFO
78941@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78942 va_start(args, fmt);
78943 vsprintf(buf, fmt, args);
78944 va_end(args);
78945- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78946+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78947 if (fd >= 0) {
78948 sys_ioctl(fd, FDEJECT, 0);
78949 sys_close(fd);
78950 }
78951 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78952- fd = sys_open("/dev/console", O_RDWR, 0);
78953+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78954 if (fd >= 0) {
78955 sys_ioctl(fd, TCGETS, (long)&termios);
78956 termios.c_lflag &= ~ICANON;
78957 sys_ioctl(fd, TCSETSF, (long)&termios);
78958- sys_read(fd, &c, 1);
78959+ sys_read(fd, (char __user *)&c, 1);
78960 termios.c_lflag |= ICANON;
78961 sys_ioctl(fd, TCSETSF, (long)&termios);
78962 sys_close(fd);
78963@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78964 mount_root();
78965 out:
78966 devtmpfs_mount("dev");
78967- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78968- sys_chroot(".");
78969+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78970+ sys_chroot((const char __force_user *)".");
78971 }
78972diff --git a/init/do_mounts.h b/init/do_mounts.h
78973index f5b978a..69dbfe8 100644
78974--- a/init/do_mounts.h
78975+++ b/init/do_mounts.h
78976@@ -15,15 +15,15 @@ extern int root_mountflags;
78977
78978 static inline int create_dev(char *name, dev_t dev)
78979 {
78980- sys_unlink(name);
78981- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78982+ sys_unlink((char __force_user *)name);
78983+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78984 }
78985
78986 #if BITS_PER_LONG == 32
78987 static inline u32 bstat(char *name)
78988 {
78989 struct stat64 stat;
78990- if (sys_stat64(name, &stat) != 0)
78991+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78992 return 0;
78993 if (!S_ISBLK(stat.st_mode))
78994 return 0;
78995@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78996 static inline u32 bstat(char *name)
78997 {
78998 struct stat stat;
78999- if (sys_newstat(name, &stat) != 0)
79000+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
79001 return 0;
79002 if (!S_ISBLK(stat.st_mode))
79003 return 0;
79004diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
79005index 3e0878e..8a9d7a0 100644
79006--- a/init/do_mounts_initrd.c
79007+++ b/init/do_mounts_initrd.c
79008@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
79009 {
79010 sys_unshare(CLONE_FS | CLONE_FILES);
79011 /* stdin/stdout/stderr for /linuxrc */
79012- sys_open("/dev/console", O_RDWR, 0);
79013+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
79014 sys_dup(0);
79015 sys_dup(0);
79016 /* move initrd over / and chdir/chroot in initrd root */
79017- sys_chdir("/root");
79018- sys_mount(".", "/", NULL, MS_MOVE, NULL);
79019- sys_chroot(".");
79020+ sys_chdir((const char __force_user *)"/root");
79021+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
79022+ sys_chroot((const char __force_user *)".");
79023 sys_setsid();
79024 return 0;
79025 }
79026@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
79027 create_dev("/dev/root.old", Root_RAM0);
79028 /* mount initrd on rootfs' /root */
79029 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
79030- sys_mkdir("/old", 0700);
79031- sys_chdir("/old");
79032+ sys_mkdir((const char __force_user *)"/old", 0700);
79033+ sys_chdir((const char __force_user *)"/old");
79034
79035 /* try loading default modules from initrd */
79036 load_default_modules();
79037@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
79038 current->flags &= ~PF_FREEZER_SKIP;
79039
79040 /* move initrd to rootfs' /old */
79041- sys_mount("..", ".", NULL, MS_MOVE, NULL);
79042+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
79043 /* switch root and cwd back to / of rootfs */
79044- sys_chroot("..");
79045+ sys_chroot((const char __force_user *)"..");
79046
79047 if (new_decode_dev(real_root_dev) == Root_RAM0) {
79048- sys_chdir("/old");
79049+ sys_chdir((const char __force_user *)"/old");
79050 return;
79051 }
79052
79053- sys_chdir("/");
79054+ sys_chdir((const char __force_user *)"/");
79055 ROOT_DEV = new_decode_dev(real_root_dev);
79056 mount_root();
79057
79058 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
79059- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
79060+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
79061 if (!error)
79062 printk("okay\n");
79063 else {
79064- int fd = sys_open("/dev/root.old", O_RDWR, 0);
79065+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
79066 if (error == -ENOENT)
79067 printk("/initrd does not exist. Ignored.\n");
79068 else
79069 printk("failed\n");
79070 printk(KERN_NOTICE "Unmounting old root\n");
79071- sys_umount("/old", MNT_DETACH);
79072+ sys_umount((char __force_user *)"/old", MNT_DETACH);
79073 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
79074 if (fd < 0) {
79075 error = fd;
79076@@ -127,11 +127,11 @@ int __init initrd_load(void)
79077 * mounted in the normal path.
79078 */
79079 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
79080- sys_unlink("/initrd.image");
79081+ sys_unlink((const char __force_user *)"/initrd.image");
79082 handle_initrd();
79083 return 1;
79084 }
79085 }
79086- sys_unlink("/initrd.image");
79087+ sys_unlink((const char __force_user *)"/initrd.image");
79088 return 0;
79089 }
79090diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
79091index 8cb6db5..d729f50 100644
79092--- a/init/do_mounts_md.c
79093+++ b/init/do_mounts_md.c
79094@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
79095 partitioned ? "_d" : "", minor,
79096 md_setup_args[ent].device_names);
79097
79098- fd = sys_open(name, 0, 0);
79099+ fd = sys_open((char __force_user *)name, 0, 0);
79100 if (fd < 0) {
79101 printk(KERN_ERR "md: open failed - cannot start "
79102 "array %s\n", name);
79103@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
79104 * array without it
79105 */
79106 sys_close(fd);
79107- fd = sys_open(name, 0, 0);
79108+ fd = sys_open((char __force_user *)name, 0, 0);
79109 sys_ioctl(fd, BLKRRPART, 0);
79110 }
79111 sys_close(fd);
79112@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
79113
79114 wait_for_device_probe();
79115
79116- fd = sys_open("/dev/md0", 0, 0);
79117+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
79118 if (fd >= 0) {
79119 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
79120 sys_close(fd);
79121diff --git a/init/init_task.c b/init/init_task.c
79122index ba0a7f36..2bcf1d5 100644
79123--- a/init/init_task.c
79124+++ b/init/init_task.c
79125@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
79126 * Initial thread structure. Alignment of this is handled by a special
79127 * linker map entry.
79128 */
79129+#ifdef CONFIG_X86
79130+union thread_union init_thread_union __init_task_data;
79131+#else
79132 union thread_union init_thread_union __init_task_data =
79133 { INIT_THREAD_INFO(init_task) };
79134+#endif
79135diff --git a/init/initramfs.c b/init/initramfs.c
79136index a67ef9d..2d17ed9 100644
79137--- a/init/initramfs.c
79138+++ b/init/initramfs.c
79139@@ -84,7 +84,7 @@ static void __init free_hash(void)
79140 }
79141 }
79142
79143-static long __init do_utime(char *filename, time_t mtime)
79144+static long __init do_utime(char __force_user *filename, time_t mtime)
79145 {
79146 struct timespec t[2];
79147
79148@@ -119,7 +119,7 @@ static void __init dir_utime(void)
79149 struct dir_entry *de, *tmp;
79150 list_for_each_entry_safe(de, tmp, &dir_list, list) {
79151 list_del(&de->list);
79152- do_utime(de->name, de->mtime);
79153+ do_utime((char __force_user *)de->name, de->mtime);
79154 kfree(de->name);
79155 kfree(de);
79156 }
79157@@ -281,7 +281,7 @@ static int __init maybe_link(void)
79158 if (nlink >= 2) {
79159 char *old = find_link(major, minor, ino, mode, collected);
79160 if (old)
79161- return (sys_link(old, collected) < 0) ? -1 : 1;
79162+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
79163 }
79164 return 0;
79165 }
79166@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
79167 {
79168 struct stat st;
79169
79170- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
79171+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
79172 if (S_ISDIR(st.st_mode))
79173- sys_rmdir(path);
79174+ sys_rmdir((char __force_user *)path);
79175 else
79176- sys_unlink(path);
79177+ sys_unlink((char __force_user *)path);
79178 }
79179 }
79180
79181@@ -315,7 +315,7 @@ static int __init do_name(void)
79182 int openflags = O_WRONLY|O_CREAT;
79183 if (ml != 1)
79184 openflags |= O_TRUNC;
79185- wfd = sys_open(collected, openflags, mode);
79186+ wfd = sys_open((char __force_user *)collected, openflags, mode);
79187
79188 if (wfd >= 0) {
79189 sys_fchown(wfd, uid, gid);
79190@@ -327,17 +327,17 @@ static int __init do_name(void)
79191 }
79192 }
79193 } else if (S_ISDIR(mode)) {
79194- sys_mkdir(collected, mode);
79195- sys_chown(collected, uid, gid);
79196- sys_chmod(collected, mode);
79197+ sys_mkdir((char __force_user *)collected, mode);
79198+ sys_chown((char __force_user *)collected, uid, gid);
79199+ sys_chmod((char __force_user *)collected, mode);
79200 dir_add(collected, mtime);
79201 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
79202 S_ISFIFO(mode) || S_ISSOCK(mode)) {
79203 if (maybe_link() == 0) {
79204- sys_mknod(collected, mode, rdev);
79205- sys_chown(collected, uid, gid);
79206- sys_chmod(collected, mode);
79207- do_utime(collected, mtime);
79208+ sys_mknod((char __force_user *)collected, mode, rdev);
79209+ sys_chown((char __force_user *)collected, uid, gid);
79210+ sys_chmod((char __force_user *)collected, mode);
79211+ do_utime((char __force_user *)collected, mtime);
79212 }
79213 }
79214 return 0;
79215@@ -346,15 +346,15 @@ static int __init do_name(void)
79216 static int __init do_copy(void)
79217 {
79218 if (count >= body_len) {
79219- sys_write(wfd, victim, body_len);
79220+ sys_write(wfd, (char __force_user *)victim, body_len);
79221 sys_close(wfd);
79222- do_utime(vcollected, mtime);
79223+ do_utime((char __force_user *)vcollected, mtime);
79224 kfree(vcollected);
79225 eat(body_len);
79226 state = SkipIt;
79227 return 0;
79228 } else {
79229- sys_write(wfd, victim, count);
79230+ sys_write(wfd, (char __force_user *)victim, count);
79231 body_len -= count;
79232 eat(count);
79233 return 1;
79234@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79235 {
79236 collected[N_ALIGN(name_len) + body_len] = '\0';
79237 clean_path(collected, 0);
79238- sys_symlink(collected + N_ALIGN(name_len), collected);
79239- sys_lchown(collected, uid, gid);
79240- do_utime(collected, mtime);
79241+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79242+ sys_lchown((char __force_user *)collected, uid, gid);
79243+ do_utime((char __force_user *)collected, mtime);
79244 state = SkipIt;
79245 next_state = Reset;
79246 return 0;
79247@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79248 {
79249 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79250 if (err)
79251- panic(err); /* Failed to decompress INTERNAL initramfs */
79252+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79253 if (initrd_start) {
79254 #ifdef CONFIG_BLK_DEV_RAM
79255 int fd;
79256diff --git a/init/main.c b/init/main.c
79257index d03d2ec..9fc4737 100644
79258--- a/init/main.c
79259+++ b/init/main.c
79260@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
79261 extern void tc_init(void);
79262 #endif
79263
79264+extern void grsecurity_init(void);
79265+
79266 /*
79267 * Debug helper: via this flag we know that we are in 'early bootup code'
79268 * where only the boot processor is running with IRQ disabled. This means
79269@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
79270
79271 __setup("reset_devices", set_reset_devices);
79272
79273+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79274+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79275+static int __init setup_grsec_proc_gid(char *str)
79276+{
79277+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79278+ return 1;
79279+}
79280+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79281+#endif
79282+
79283+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79284+unsigned long pax_user_shadow_base __read_only;
79285+EXPORT_SYMBOL(pax_user_shadow_base);
79286+extern char pax_enter_kernel_user[];
79287+extern char pax_exit_kernel_user[];
79288+#endif
79289+
79290+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79291+static int __init setup_pax_nouderef(char *str)
79292+{
79293+#ifdef CONFIG_X86_32
79294+ unsigned int cpu;
79295+ struct desc_struct *gdt;
79296+
79297+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79298+ gdt = get_cpu_gdt_table(cpu);
79299+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79300+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79301+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79302+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79303+ }
79304+ loadsegment(ds, __KERNEL_DS);
79305+ loadsegment(es, __KERNEL_DS);
79306+ loadsegment(ss, __KERNEL_DS);
79307+#else
79308+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79309+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79310+ clone_pgd_mask = ~(pgdval_t)0UL;
79311+ pax_user_shadow_base = 0UL;
79312+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79313+#endif
79314+
79315+ return 0;
79316+}
79317+early_param("pax_nouderef", setup_pax_nouderef);
79318+
79319+#ifdef CONFIG_X86_64
79320+static int __init setup_pax_weakuderef(char *str)
79321+{
79322+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79323+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79324+ return 1;
79325+}
79326+__setup("pax_weakuderef", setup_pax_weakuderef);
79327+#endif
79328+#endif
79329+
79330+#ifdef CONFIG_PAX_SOFTMODE
79331+int pax_softmode;
79332+
79333+static int __init setup_pax_softmode(char *str)
79334+{
79335+ get_option(&str, &pax_softmode);
79336+ return 1;
79337+}
79338+__setup("pax_softmode=", setup_pax_softmode);
79339+#endif
79340+
79341 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79342 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79343 static const char *panic_later, *panic_param;
79344@@ -679,25 +749,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79345 {
79346 int count = preempt_count();
79347 int ret;
79348- char msgbuf[64];
79349+ const char *msg1 = "", *msg2 = "";
79350
79351 if (initcall_debug)
79352 ret = do_one_initcall_debug(fn);
79353 else
79354 ret = fn();
79355
79356- msgbuf[0] = 0;
79357-
79358 if (preempt_count() != count) {
79359- sprintf(msgbuf, "preemption imbalance ");
79360+ msg1 = " preemption imbalance";
79361 preempt_count() = count;
79362 }
79363 if (irqs_disabled()) {
79364- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79365+ msg2 = " disabled interrupts";
79366 local_irq_enable();
79367 }
79368- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79369+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79370
79371+ add_latent_entropy();
79372 return ret;
79373 }
79374
79375@@ -803,8 +872,8 @@ static int run_init_process(const char *init_filename)
79376 {
79377 argv_init[0] = init_filename;
79378 return do_execve(init_filename,
79379- (const char __user *const __user *)argv_init,
79380- (const char __user *const __user *)envp_init);
79381+ (const char __user *const __force_user *)argv_init,
79382+ (const char __user *const __force_user *)envp_init);
79383 }
79384
79385 static noinline void __init kernel_init_freeable(void);
79386@@ -881,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
79387 do_basic_setup();
79388
79389 /* Open the /dev/console on the rootfs, this should never fail */
79390- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79391+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79392 pr_err("Warning: unable to open an initial console.\n");
79393
79394 (void) sys_dup(0);
79395@@ -894,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
79396 if (!ramdisk_execute_command)
79397 ramdisk_execute_command = "/init";
79398
79399- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79400+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79401 ramdisk_execute_command = NULL;
79402 prepare_namespace();
79403 }
79404
79405+ grsecurity_init();
79406+
79407 /*
79408 * Ok, we have completed the initial bootup, and
79409 * we're essentially up and running. Get rid of the
79410diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79411index 130dfec..cc88451 100644
79412--- a/ipc/ipc_sysctl.c
79413+++ b/ipc/ipc_sysctl.c
79414@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79415 static int proc_ipc_dointvec(ctl_table *table, int write,
79416 void __user *buffer, size_t *lenp, loff_t *ppos)
79417 {
79418- struct ctl_table ipc_table;
79419+ ctl_table_no_const ipc_table;
79420
79421 memcpy(&ipc_table, table, sizeof(ipc_table));
79422 ipc_table.data = get_ipc(table);
79423@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79424 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79425 void __user *buffer, size_t *lenp, loff_t *ppos)
79426 {
79427- struct ctl_table ipc_table;
79428+ ctl_table_no_const ipc_table;
79429
79430 memcpy(&ipc_table, table, sizeof(ipc_table));
79431 ipc_table.data = get_ipc(table);
79432@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79433 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79434 void __user *buffer, size_t *lenp, loff_t *ppos)
79435 {
79436- struct ctl_table ipc_table;
79437+ ctl_table_no_const ipc_table;
79438 size_t lenp_bef = *lenp;
79439 int rc;
79440
79441@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79442 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79443 void __user *buffer, size_t *lenp, loff_t *ppos)
79444 {
79445- struct ctl_table ipc_table;
79446+ ctl_table_no_const ipc_table;
79447 memcpy(&ipc_table, table, sizeof(ipc_table));
79448 ipc_table.data = get_ipc(table);
79449
79450@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79451 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79452 void __user *buffer, size_t *lenp, loff_t *ppos)
79453 {
79454- struct ctl_table ipc_table;
79455+ ctl_table_no_const ipc_table;
79456 size_t lenp_bef = *lenp;
79457 int oldval;
79458 int rc;
79459diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79460index 383d638..943fdbb 100644
79461--- a/ipc/mq_sysctl.c
79462+++ b/ipc/mq_sysctl.c
79463@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79464 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79465 void __user *buffer, size_t *lenp, loff_t *ppos)
79466 {
79467- struct ctl_table mq_table;
79468+ ctl_table_no_const mq_table;
79469 memcpy(&mq_table, table, sizeof(mq_table));
79470 mq_table.data = get_mq(table);
79471
79472diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79473index ae1996d..a35f2cc 100644
79474--- a/ipc/mqueue.c
79475+++ b/ipc/mqueue.c
79476@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79477 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79478 info->attr.mq_msgsize);
79479
79480+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79481 spin_lock(&mq_lock);
79482 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79483 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79484diff --git a/ipc/msg.c b/ipc/msg.c
79485index 9f29d9e..8f284e0 100644
79486--- a/ipc/msg.c
79487+++ b/ipc/msg.c
79488@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79489 return security_msg_queue_associate(msq, msgflg);
79490 }
79491
79492+static struct ipc_ops msg_ops = {
79493+ .getnew = newque,
79494+ .associate = msg_security,
79495+ .more_checks = NULL
79496+};
79497+
79498 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79499 {
79500 struct ipc_namespace *ns;
79501- struct ipc_ops msg_ops;
79502 struct ipc_params msg_params;
79503
79504 ns = current->nsproxy->ipc_ns;
79505
79506- msg_ops.getnew = newque;
79507- msg_ops.associate = msg_security;
79508- msg_ops.more_checks = NULL;
79509-
79510 msg_params.key = key;
79511 msg_params.flg = msgflg;
79512
79513diff --git a/ipc/sem.c b/ipc/sem.c
79514index 4108889..511ada1 100644
79515--- a/ipc/sem.c
79516+++ b/ipc/sem.c
79517@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79518 return 0;
79519 }
79520
79521+static struct ipc_ops sem_ops = {
79522+ .getnew = newary,
79523+ .associate = sem_security,
79524+ .more_checks = sem_more_checks
79525+};
79526+
79527 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79528 {
79529 struct ipc_namespace *ns;
79530- struct ipc_ops sem_ops;
79531 struct ipc_params sem_params;
79532
79533 ns = current->nsproxy->ipc_ns;
79534@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79535 if (nsems < 0 || nsems > ns->sc_semmsl)
79536 return -EINVAL;
79537
79538- sem_ops.getnew = newary;
79539- sem_ops.associate = sem_security;
79540- sem_ops.more_checks = sem_more_checks;
79541-
79542 sem_params.key = key;
79543 sem_params.flg = semflg;
79544 sem_params.u.nsems = nsems;
79545diff --git a/ipc/shm.c b/ipc/shm.c
79546index c6b4ad5..3ec3254 100644
79547--- a/ipc/shm.c
79548+++ b/ipc/shm.c
79549@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79550 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79551 #endif
79552
79553+#ifdef CONFIG_GRKERNSEC
79554+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79555+ const time_t shm_createtime, const kuid_t cuid,
79556+ const int shmid);
79557+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79558+ const time_t shm_createtime);
79559+#endif
79560+
79561 void shm_init_ns(struct ipc_namespace *ns)
79562 {
79563 ns->shm_ctlmax = SHMMAX;
79564@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79565 shp->shm_lprid = 0;
79566 shp->shm_atim = shp->shm_dtim = 0;
79567 shp->shm_ctim = get_seconds();
79568+#ifdef CONFIG_GRKERNSEC
79569+ {
79570+ struct timespec timeval;
79571+ do_posix_clock_monotonic_gettime(&timeval);
79572+
79573+ shp->shm_createtime = timeval.tv_sec;
79574+ }
79575+#endif
79576 shp->shm_segsz = size;
79577 shp->shm_nattch = 0;
79578 shp->shm_file = file;
79579@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79580 return 0;
79581 }
79582
79583+static struct ipc_ops shm_ops = {
79584+ .getnew = newseg,
79585+ .associate = shm_security,
79586+ .more_checks = shm_more_checks
79587+};
79588+
79589 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79590 {
79591 struct ipc_namespace *ns;
79592- struct ipc_ops shm_ops;
79593 struct ipc_params shm_params;
79594
79595 ns = current->nsproxy->ipc_ns;
79596
79597- shm_ops.getnew = newseg;
79598- shm_ops.associate = shm_security;
79599- shm_ops.more_checks = shm_more_checks;
79600-
79601 shm_params.key = key;
79602 shm_params.flg = shmflg;
79603 shm_params.u.size = size;
79604@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79605 f_mode = FMODE_READ | FMODE_WRITE;
79606 }
79607 if (shmflg & SHM_EXEC) {
79608+
79609+#ifdef CONFIG_PAX_MPROTECT
79610+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79611+ goto out;
79612+#endif
79613+
79614 prot |= PROT_EXEC;
79615 acc_mode |= S_IXUGO;
79616 }
79617@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79618 if (err)
79619 goto out_unlock;
79620
79621+#ifdef CONFIG_GRKERNSEC
79622+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79623+ shp->shm_perm.cuid, shmid) ||
79624+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79625+ err = -EACCES;
79626+ goto out_unlock;
79627+ }
79628+#endif
79629+
79630 path = shp->shm_file->f_path;
79631 path_get(&path);
79632 shp->shm_nattch++;
79633+#ifdef CONFIG_GRKERNSEC
79634+ shp->shm_lapid = current->pid;
79635+#endif
79636 size = i_size_read(path.dentry->d_inode);
79637 shm_unlock(shp);
79638
79639diff --git a/kernel/acct.c b/kernel/acct.c
79640index 8d6e145..33e0b1e 100644
79641--- a/kernel/acct.c
79642+++ b/kernel/acct.c
79643@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79644 */
79645 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79646 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79647- file->f_op->write(file, (char *)&ac,
79648+ file->f_op->write(file, (char __force_user *)&ac,
79649 sizeof(acct_t), &file->f_pos);
79650 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79651 set_fs(fs);
79652diff --git a/kernel/audit.c b/kernel/audit.c
79653index 91e53d0..d9e3ec4 100644
79654--- a/kernel/audit.c
79655+++ b/kernel/audit.c
79656@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79657 3) suppressed due to audit_rate_limit
79658 4) suppressed due to audit_backlog_limit
79659 */
79660-static atomic_t audit_lost = ATOMIC_INIT(0);
79661+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79662
79663 /* The netlink socket. */
79664 static struct sock *audit_sock;
79665@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79666 unsigned long now;
79667 int print;
79668
79669- atomic_inc(&audit_lost);
79670+ atomic_inc_unchecked(&audit_lost);
79671
79672 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79673
79674@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79675 printk(KERN_WARNING
79676 "audit: audit_lost=%d audit_rate_limit=%d "
79677 "audit_backlog_limit=%d\n",
79678- atomic_read(&audit_lost),
79679+ atomic_read_unchecked(&audit_lost),
79680 audit_rate_limit,
79681 audit_backlog_limit);
79682 audit_panic(message);
79683@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79684 status_set.pid = audit_pid;
79685 status_set.rate_limit = audit_rate_limit;
79686 status_set.backlog_limit = audit_backlog_limit;
79687- status_set.lost = atomic_read(&audit_lost);
79688+ status_set.lost = atomic_read_unchecked(&audit_lost);
79689 status_set.backlog = skb_queue_len(&audit_skb_queue);
79690 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79691 &status_set, sizeof(status_set));
79692diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79693index 9845cb3..3ec9369 100644
79694--- a/kernel/auditsc.c
79695+++ b/kernel/auditsc.c
79696@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79697 }
79698
79699 /* global counter which is incremented every time something logs in */
79700-static atomic_t session_id = ATOMIC_INIT(0);
79701+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79702
79703 /**
79704 * audit_set_loginuid - set current task's audit_context loginuid
79705@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79706 return -EPERM;
79707 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79708
79709- sessionid = atomic_inc_return(&session_id);
79710+ sessionid = atomic_inc_return_unchecked(&session_id);
79711 if (context && context->in_syscall) {
79712 struct audit_buffer *ab;
79713
79714diff --git a/kernel/capability.c b/kernel/capability.c
79715index f6c2ce5..982c0f9 100644
79716--- a/kernel/capability.c
79717+++ b/kernel/capability.c
79718@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79719 * before modification is attempted and the application
79720 * fails.
79721 */
79722+ if (tocopy > ARRAY_SIZE(kdata))
79723+ return -EFAULT;
79724+
79725 if (copy_to_user(dataptr, kdata, tocopy
79726 * sizeof(struct __user_cap_data_struct))) {
79727 return -EFAULT;
79728@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79729 int ret;
79730
79731 rcu_read_lock();
79732- ret = security_capable(__task_cred(t), ns, cap);
79733+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79734+ gr_task_is_capable(t, __task_cred(t), cap);
79735 rcu_read_unlock();
79736
79737- return (ret == 0);
79738+ return ret;
79739 }
79740
79741 /**
79742@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79743 int ret;
79744
79745 rcu_read_lock();
79746- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79747+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79748 rcu_read_unlock();
79749
79750- return (ret == 0);
79751+ return ret;
79752 }
79753
79754 /**
79755@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79756 BUG();
79757 }
79758
79759- if (security_capable(current_cred(), ns, cap) == 0) {
79760+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79761 current->flags |= PF_SUPERPRIV;
79762 return true;
79763 }
79764@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79765 }
79766 EXPORT_SYMBOL(ns_capable);
79767
79768+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79769+{
79770+ if (unlikely(!cap_valid(cap))) {
79771+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79772+ BUG();
79773+ }
79774+
79775+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79776+ current->flags |= PF_SUPERPRIV;
79777+ return true;
79778+ }
79779+ return false;
79780+}
79781+EXPORT_SYMBOL(ns_capable_nolog);
79782+
79783 /**
79784 * file_ns_capable - Determine if the file's opener had a capability in effect
79785 * @file: The file we want to check
79786@@ -432,6 +451,12 @@ bool capable(int cap)
79787 }
79788 EXPORT_SYMBOL(capable);
79789
79790+bool capable_nolog(int cap)
79791+{
79792+ return ns_capable_nolog(&init_user_ns, cap);
79793+}
79794+EXPORT_SYMBOL(capable_nolog);
79795+
79796 /**
79797 * nsown_capable - Check superior capability to one's own user_ns
79798 * @cap: The capability in question
79799@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79800
79801 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79802 }
79803+
79804+bool inode_capable_nolog(const struct inode *inode, int cap)
79805+{
79806+ struct user_namespace *ns = current_user_ns();
79807+
79808+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79809+}
79810diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79811index e919633..f46b08f 100644
79812--- a/kernel/cgroup.c
79813+++ b/kernel/cgroup.c
79814@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79815 struct css_set *cset = link->cset;
79816 struct task_struct *task;
79817 int count = 0;
79818- seq_printf(seq, "css_set %p\n", cset);
79819+ seq_printf(seq, "css_set %pK\n", cset);
79820 list_for_each_entry(task, &cset->tasks, cg_list) {
79821 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79822 seq_puts(seq, " ...\n");
79823diff --git a/kernel/compat.c b/kernel/compat.c
79824index 0a09e48..f44f3f0 100644
79825--- a/kernel/compat.c
79826+++ b/kernel/compat.c
79827@@ -13,6 +13,7 @@
79828
79829 #include <linux/linkage.h>
79830 #include <linux/compat.h>
79831+#include <linux/module.h>
79832 #include <linux/errno.h>
79833 #include <linux/time.h>
79834 #include <linux/signal.h>
79835@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79836 mm_segment_t oldfs;
79837 long ret;
79838
79839- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79840+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79841 oldfs = get_fs();
79842 set_fs(KERNEL_DS);
79843 ret = hrtimer_nanosleep_restart(restart);
79844@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79845 oldfs = get_fs();
79846 set_fs(KERNEL_DS);
79847 ret = hrtimer_nanosleep(&tu,
79848- rmtp ? (struct timespec __user *)&rmt : NULL,
79849+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79850 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79851 set_fs(oldfs);
79852
79853@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79854 mm_segment_t old_fs = get_fs();
79855
79856 set_fs(KERNEL_DS);
79857- ret = sys_sigpending((old_sigset_t __user *) &s);
79858+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79859 set_fs(old_fs);
79860 if (ret == 0)
79861 ret = put_user(s, set);
79862@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79863 mm_segment_t old_fs = get_fs();
79864
79865 set_fs(KERNEL_DS);
79866- ret = sys_old_getrlimit(resource, &r);
79867+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79868 set_fs(old_fs);
79869
79870 if (!ret) {
79871@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79872 set_fs (KERNEL_DS);
79873 ret = sys_wait4(pid,
79874 (stat_addr ?
79875- (unsigned int __user *) &status : NULL),
79876- options, (struct rusage __user *) &r);
79877+ (unsigned int __force_user *) &status : NULL),
79878+ options, (struct rusage __force_user *) &r);
79879 set_fs (old_fs);
79880
79881 if (ret > 0) {
79882@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79883 memset(&info, 0, sizeof(info));
79884
79885 set_fs(KERNEL_DS);
79886- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79887- uru ? (struct rusage __user *)&ru : NULL);
79888+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79889+ uru ? (struct rusage __force_user *)&ru : NULL);
79890 set_fs(old_fs);
79891
79892 if ((ret < 0) || (info.si_signo == 0))
79893@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79894 oldfs = get_fs();
79895 set_fs(KERNEL_DS);
79896 err = sys_timer_settime(timer_id, flags,
79897- (struct itimerspec __user *) &newts,
79898- (struct itimerspec __user *) &oldts);
79899+ (struct itimerspec __force_user *) &newts,
79900+ (struct itimerspec __force_user *) &oldts);
79901 set_fs(oldfs);
79902 if (!err && old && put_compat_itimerspec(old, &oldts))
79903 return -EFAULT;
79904@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79905 oldfs = get_fs();
79906 set_fs(KERNEL_DS);
79907 err = sys_timer_gettime(timer_id,
79908- (struct itimerspec __user *) &ts);
79909+ (struct itimerspec __force_user *) &ts);
79910 set_fs(oldfs);
79911 if (!err && put_compat_itimerspec(setting, &ts))
79912 return -EFAULT;
79913@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79914 oldfs = get_fs();
79915 set_fs(KERNEL_DS);
79916 err = sys_clock_settime(which_clock,
79917- (struct timespec __user *) &ts);
79918+ (struct timespec __force_user *) &ts);
79919 set_fs(oldfs);
79920 return err;
79921 }
79922@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79923 oldfs = get_fs();
79924 set_fs(KERNEL_DS);
79925 err = sys_clock_gettime(which_clock,
79926- (struct timespec __user *) &ts);
79927+ (struct timespec __force_user *) &ts);
79928 set_fs(oldfs);
79929 if (!err && put_compat_timespec(&ts, tp))
79930 return -EFAULT;
79931@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79932
79933 oldfs = get_fs();
79934 set_fs(KERNEL_DS);
79935- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79936+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79937 set_fs(oldfs);
79938
79939 err = compat_put_timex(utp, &txc);
79940@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79941 oldfs = get_fs();
79942 set_fs(KERNEL_DS);
79943 err = sys_clock_getres(which_clock,
79944- (struct timespec __user *) &ts);
79945+ (struct timespec __force_user *) &ts);
79946 set_fs(oldfs);
79947 if (!err && tp && put_compat_timespec(&ts, tp))
79948 return -EFAULT;
79949@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79950 long err;
79951 mm_segment_t oldfs;
79952 struct timespec tu;
79953- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79954+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79955
79956- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79957+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79958 oldfs = get_fs();
79959 set_fs(KERNEL_DS);
79960 err = clock_nanosleep_restart(restart);
79961@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79962 oldfs = get_fs();
79963 set_fs(KERNEL_DS);
79964 err = sys_clock_nanosleep(which_clock, flags,
79965- (struct timespec __user *) &in,
79966- (struct timespec __user *) &out);
79967+ (struct timespec __force_user *) &in,
79968+ (struct timespec __force_user *) &out);
79969 set_fs(oldfs);
79970
79971 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79972diff --git a/kernel/configs.c b/kernel/configs.c
79973index c18b1f1..b9a0132 100644
79974--- a/kernel/configs.c
79975+++ b/kernel/configs.c
79976@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79977 struct proc_dir_entry *entry;
79978
79979 /* create the current config file */
79980+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79981+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79982+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79983+ &ikconfig_file_ops);
79984+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79985+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79986+ &ikconfig_file_ops);
79987+#endif
79988+#else
79989 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79990 &ikconfig_file_ops);
79991+#endif
79992+
79993 if (!entry)
79994 return -ENOMEM;
79995
79996diff --git a/kernel/cred.c b/kernel/cred.c
79997index e0573a4..3874e41 100644
79998--- a/kernel/cred.c
79999+++ b/kernel/cred.c
80000@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
80001 validate_creds(cred);
80002 alter_cred_subscribers(cred, -1);
80003 put_cred(cred);
80004+
80005+#ifdef CONFIG_GRKERNSEC_SETXID
80006+ cred = (struct cred *) tsk->delayed_cred;
80007+ if (cred != NULL) {
80008+ tsk->delayed_cred = NULL;
80009+ validate_creds(cred);
80010+ alter_cred_subscribers(cred, -1);
80011+ put_cred(cred);
80012+ }
80013+#endif
80014 }
80015
80016 /**
80017@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
80018 * Always returns 0 thus allowing this function to be tail-called at the end
80019 * of, say, sys_setgid().
80020 */
80021-int commit_creds(struct cred *new)
80022+static int __commit_creds(struct cred *new)
80023 {
80024 struct task_struct *task = current;
80025 const struct cred *old = task->real_cred;
80026@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
80027
80028 get_cred(new); /* we will require a ref for the subj creds too */
80029
80030+ gr_set_role_label(task, new->uid, new->gid);
80031+
80032 /* dumpability changes */
80033 if (!uid_eq(old->euid, new->euid) ||
80034 !gid_eq(old->egid, new->egid) ||
80035@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
80036 put_cred(old);
80037 return 0;
80038 }
80039+#ifdef CONFIG_GRKERNSEC_SETXID
80040+extern int set_user(struct cred *new);
80041+
80042+void gr_delayed_cred_worker(void)
80043+{
80044+ const struct cred *new = current->delayed_cred;
80045+ struct cred *ncred;
80046+
80047+ current->delayed_cred = NULL;
80048+
80049+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
80050+ // from doing get_cred on it when queueing this
80051+ put_cred(new);
80052+ return;
80053+ } else if (new == NULL)
80054+ return;
80055+
80056+ ncred = prepare_creds();
80057+ if (!ncred)
80058+ goto die;
80059+ // uids
80060+ ncred->uid = new->uid;
80061+ ncred->euid = new->euid;
80062+ ncred->suid = new->suid;
80063+ ncred->fsuid = new->fsuid;
80064+ // gids
80065+ ncred->gid = new->gid;
80066+ ncred->egid = new->egid;
80067+ ncred->sgid = new->sgid;
80068+ ncred->fsgid = new->fsgid;
80069+ // groups
80070+ if (set_groups(ncred, new->group_info) < 0) {
80071+ abort_creds(ncred);
80072+ goto die;
80073+ }
80074+ // caps
80075+ ncred->securebits = new->securebits;
80076+ ncred->cap_inheritable = new->cap_inheritable;
80077+ ncred->cap_permitted = new->cap_permitted;
80078+ ncred->cap_effective = new->cap_effective;
80079+ ncred->cap_bset = new->cap_bset;
80080+
80081+ if (set_user(ncred)) {
80082+ abort_creds(ncred);
80083+ goto die;
80084+ }
80085+
80086+ // from doing get_cred on it when queueing this
80087+ put_cred(new);
80088+
80089+ __commit_creds(ncred);
80090+ return;
80091+die:
80092+ // from doing get_cred on it when queueing this
80093+ put_cred(new);
80094+ do_group_exit(SIGKILL);
80095+}
80096+#endif
80097+
80098+int commit_creds(struct cred *new)
80099+{
80100+#ifdef CONFIG_GRKERNSEC_SETXID
80101+ int ret;
80102+ int schedule_it = 0;
80103+ struct task_struct *t;
80104+
80105+ /* we won't get called with tasklist_lock held for writing
80106+ and interrupts disabled as the cred struct in that case is
80107+ init_cred
80108+ */
80109+ if (grsec_enable_setxid && !current_is_single_threaded() &&
80110+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
80111+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
80112+ schedule_it = 1;
80113+ }
80114+ ret = __commit_creds(new);
80115+ if (schedule_it) {
80116+ rcu_read_lock();
80117+ read_lock(&tasklist_lock);
80118+ for (t = next_thread(current); t != current;
80119+ t = next_thread(t)) {
80120+ if (t->delayed_cred == NULL) {
80121+ t->delayed_cred = get_cred(new);
80122+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
80123+ set_tsk_need_resched(t);
80124+ }
80125+ }
80126+ read_unlock(&tasklist_lock);
80127+ rcu_read_unlock();
80128+ }
80129+ return ret;
80130+#else
80131+ return __commit_creds(new);
80132+#endif
80133+}
80134+
80135 EXPORT_SYMBOL(commit_creds);
80136
80137 /**
80138diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
80139index 0506d44..2c20034 100644
80140--- a/kernel/debug/debug_core.c
80141+++ b/kernel/debug/debug_core.c
80142@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
80143 */
80144 static atomic_t masters_in_kgdb;
80145 static atomic_t slaves_in_kgdb;
80146-static atomic_t kgdb_break_tasklet_var;
80147+static atomic_unchecked_t kgdb_break_tasklet_var;
80148 atomic_t kgdb_setting_breakpoint;
80149
80150 struct task_struct *kgdb_usethread;
80151@@ -133,7 +133,7 @@ int kgdb_single_step;
80152 static pid_t kgdb_sstep_pid;
80153
80154 /* to keep track of the CPU which is doing the single stepping*/
80155-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80156+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80157
80158 /*
80159 * If you are debugging a problem where roundup (the collection of
80160@@ -541,7 +541,7 @@ return_normal:
80161 * kernel will only try for the value of sstep_tries before
80162 * giving up and continuing on.
80163 */
80164- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
80165+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
80166 (kgdb_info[cpu].task &&
80167 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
80168 atomic_set(&kgdb_active, -1);
80169@@ -635,8 +635,8 @@ cpu_master_loop:
80170 }
80171
80172 kgdb_restore:
80173- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
80174- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
80175+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
80176+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
80177 if (kgdb_info[sstep_cpu].task)
80178 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
80179 else
80180@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
80181 static void kgdb_tasklet_bpt(unsigned long ing)
80182 {
80183 kgdb_breakpoint();
80184- atomic_set(&kgdb_break_tasklet_var, 0);
80185+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
80186 }
80187
80188 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80189
80190 void kgdb_schedule_breakpoint(void)
80191 {
80192- if (atomic_read(&kgdb_break_tasklet_var) ||
80193+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80194 atomic_read(&kgdb_active) != -1 ||
80195 atomic_read(&kgdb_setting_breakpoint))
80196 return;
80197- atomic_inc(&kgdb_break_tasklet_var);
80198+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80199 tasklet_schedule(&kgdb_tasklet_breakpoint);
80200 }
80201 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80202diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80203index 00eb8f7..d7e3244 100644
80204--- a/kernel/debug/kdb/kdb_main.c
80205+++ b/kernel/debug/kdb/kdb_main.c
80206@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80207 continue;
80208
80209 kdb_printf("%-20s%8u 0x%p ", mod->name,
80210- mod->core_size, (void *)mod);
80211+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80212 #ifdef CONFIG_MODULE_UNLOAD
80213 kdb_printf("%4ld ", module_refcount(mod));
80214 #endif
80215@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80216 kdb_printf(" (Loading)");
80217 else
80218 kdb_printf(" (Live)");
80219- kdb_printf(" 0x%p", mod->module_core);
80220+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80221
80222 #ifdef CONFIG_MODULE_UNLOAD
80223 {
80224diff --git a/kernel/events/core.c b/kernel/events/core.c
80225index f86599e..b18b180 100644
80226--- a/kernel/events/core.c
80227+++ b/kernel/events/core.c
80228@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80229 * 0 - disallow raw tracepoint access for unpriv
80230 * 1 - disallow cpu events for unpriv
80231 * 2 - disallow kernel profiling for unpriv
80232+ * 3 - disallow all unpriv perf event use
80233 */
80234-int sysctl_perf_event_paranoid __read_mostly = 1;
80235+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80236+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80237+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80238+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80239+#else
80240+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80241+#endif
80242
80243 /* Minimum for 512 kiB + 1 user control page */
80244 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80245@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80246 update_perf_cpu_limits();
80247 }
80248
80249-static atomic64_t perf_event_id;
80250+static atomic64_unchecked_t perf_event_id;
80251
80252 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80253 enum event_type_t event_type);
80254@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80255
80256 static inline u64 perf_event_count(struct perf_event *event)
80257 {
80258- return local64_read(&event->count) + atomic64_read(&event->child_count);
80259+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80260 }
80261
80262 static u64 perf_event_read(struct perf_event *event)
80263@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80264 mutex_lock(&event->child_mutex);
80265 total += perf_event_read(event);
80266 *enabled += event->total_time_enabled +
80267- atomic64_read(&event->child_total_time_enabled);
80268+ atomic64_read_unchecked(&event->child_total_time_enabled);
80269 *running += event->total_time_running +
80270- atomic64_read(&event->child_total_time_running);
80271+ atomic64_read_unchecked(&event->child_total_time_running);
80272
80273 list_for_each_entry(child, &event->child_list, child_list) {
80274 total += perf_event_read(child);
80275@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80276 userpg->offset -= local64_read(&event->hw.prev_count);
80277
80278 userpg->time_enabled = enabled +
80279- atomic64_read(&event->child_total_time_enabled);
80280+ atomic64_read_unchecked(&event->child_total_time_enabled);
80281
80282 userpg->time_running = running +
80283- atomic64_read(&event->child_total_time_running);
80284+ atomic64_read_unchecked(&event->child_total_time_running);
80285
80286 arch_perf_update_userpage(userpg, now);
80287
80288@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80289
80290 /* Data. */
80291 sp = perf_user_stack_pointer(regs);
80292- rem = __output_copy_user(handle, (void *) sp, dump_size);
80293+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80294 dyn_size = dump_size - rem;
80295
80296 perf_output_skip(handle, rem);
80297@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80298 values[n++] = perf_event_count(event);
80299 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80300 values[n++] = enabled +
80301- atomic64_read(&event->child_total_time_enabled);
80302+ atomic64_read_unchecked(&event->child_total_time_enabled);
80303 }
80304 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80305 values[n++] = running +
80306- atomic64_read(&event->child_total_time_running);
80307+ atomic64_read_unchecked(&event->child_total_time_running);
80308 }
80309 if (read_format & PERF_FORMAT_ID)
80310 values[n++] = primary_event_id(event);
80311@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80312 * need to add enough zero bytes after the string to handle
80313 * the 64bit alignment we do later.
80314 */
80315- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80316+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80317 if (!buf) {
80318 name = strncpy(tmp, "//enomem", sizeof(tmp));
80319 goto got_name;
80320 }
80321- name = d_path(&file->f_path, buf, PATH_MAX);
80322+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80323 if (IS_ERR(name)) {
80324 name = strncpy(tmp, "//toolong", sizeof(tmp));
80325 goto got_name;
80326@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80327 event->parent = parent_event;
80328
80329 event->ns = get_pid_ns(task_active_pid_ns(current));
80330- event->id = atomic64_inc_return(&perf_event_id);
80331+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80332
80333 event->state = PERF_EVENT_STATE_INACTIVE;
80334
80335@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80336 if (flags & ~PERF_FLAG_ALL)
80337 return -EINVAL;
80338
80339+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80340+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80341+ return -EACCES;
80342+#endif
80343+
80344 err = perf_copy_attr(attr_uptr, &attr);
80345 if (err)
80346 return err;
80347@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80348 /*
80349 * Add back the child's count to the parent's count:
80350 */
80351- atomic64_add(child_val, &parent_event->child_count);
80352- atomic64_add(child_event->total_time_enabled,
80353+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80354+ atomic64_add_unchecked(child_event->total_time_enabled,
80355 &parent_event->child_total_time_enabled);
80356- atomic64_add(child_event->total_time_running,
80357+ atomic64_add_unchecked(child_event->total_time_running,
80358 &parent_event->child_total_time_running);
80359
80360 /*
80361diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80362index ca65997..60df03d 100644
80363--- a/kernel/events/internal.h
80364+++ b/kernel/events/internal.h
80365@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80366 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80367 }
80368
80369-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80370-static inline unsigned int \
80371+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80372+static inline unsigned long \
80373 func_name(struct perf_output_handle *handle, \
80374- const void *buf, unsigned int len) \
80375+ const void user *buf, unsigned long len) \
80376 { \
80377 unsigned long size, written; \
80378 \
80379@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80380 return n;
80381 }
80382
80383-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80384+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80385
80386 #define MEMCPY_SKIP(dst, src, n) (n)
80387
80388-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80389+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80390
80391 #ifndef arch_perf_out_copy_user
80392 #define arch_perf_out_copy_user __copy_from_user_inatomic
80393 #endif
80394
80395-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80396+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80397
80398 /* Callchain handling */
80399 extern struct perf_callchain_entry *
80400diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80401index f356974..cb8c570 100644
80402--- a/kernel/events/uprobes.c
80403+++ b/kernel/events/uprobes.c
80404@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80405 {
80406 struct page *page;
80407 uprobe_opcode_t opcode;
80408- int result;
80409+ long result;
80410
80411 pagefault_disable();
80412 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80413diff --git a/kernel/exit.c b/kernel/exit.c
80414index a949819..a5f127d 100644
80415--- a/kernel/exit.c
80416+++ b/kernel/exit.c
80417@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80418 struct task_struct *leader;
80419 int zap_leader;
80420 repeat:
80421+#ifdef CONFIG_NET
80422+ gr_del_task_from_ip_table(p);
80423+#endif
80424+
80425 /* don't need to get the RCU readlock here - the process is dead and
80426 * can't be modifying its own credentials. But shut RCU-lockdep up */
80427 rcu_read_lock();
80428@@ -329,7 +333,7 @@ int allow_signal(int sig)
80429 * know it'll be handled, so that they don't get converted to
80430 * SIGKILL or just silently dropped.
80431 */
80432- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80433+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80434 recalc_sigpending();
80435 spin_unlock_irq(&current->sighand->siglock);
80436 return 0;
80437@@ -698,6 +702,8 @@ void do_exit(long code)
80438 struct task_struct *tsk = current;
80439 int group_dead;
80440
80441+ set_fs(USER_DS);
80442+
80443 profile_task_exit(tsk);
80444
80445 WARN_ON(blk_needs_flush_plug(tsk));
80446@@ -714,7 +720,6 @@ void do_exit(long code)
80447 * mm_release()->clear_child_tid() from writing to a user-controlled
80448 * kernel address.
80449 */
80450- set_fs(USER_DS);
80451
80452 ptrace_event(PTRACE_EVENT_EXIT, code);
80453
80454@@ -773,6 +778,9 @@ void do_exit(long code)
80455 tsk->exit_code = code;
80456 taskstats_exit(tsk, group_dead);
80457
80458+ gr_acl_handle_psacct(tsk, code);
80459+ gr_acl_handle_exit();
80460+
80461 exit_mm(tsk);
80462
80463 if (group_dead)
80464@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80465 * Take down every thread in the group. This is called by fatal signals
80466 * as well as by sys_exit_group (below).
80467 */
80468-void
80469+__noreturn void
80470 do_group_exit(int exit_code)
80471 {
80472 struct signal_struct *sig = current->signal;
80473diff --git a/kernel/fork.c b/kernel/fork.c
80474index bf46287..2af185d 100644
80475--- a/kernel/fork.c
80476+++ b/kernel/fork.c
80477@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80478 *stackend = STACK_END_MAGIC; /* for overflow detection */
80479
80480 #ifdef CONFIG_CC_STACKPROTECTOR
80481- tsk->stack_canary = get_random_int();
80482+ tsk->stack_canary = pax_get_random_long();
80483 #endif
80484
80485 /*
80486@@ -345,13 +345,81 @@ free_tsk:
80487 }
80488
80489 #ifdef CONFIG_MMU
80490-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80491+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80492 {
80493- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80494- struct rb_node **rb_link, *rb_parent;
80495- int retval;
80496+ struct vm_area_struct *tmp;
80497 unsigned long charge;
80498 struct mempolicy *pol;
80499+ struct file *file;
80500+
80501+ charge = 0;
80502+ if (mpnt->vm_flags & VM_ACCOUNT) {
80503+ unsigned long len = vma_pages(mpnt);
80504+
80505+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80506+ goto fail_nomem;
80507+ charge = len;
80508+ }
80509+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80510+ if (!tmp)
80511+ goto fail_nomem;
80512+ *tmp = *mpnt;
80513+ tmp->vm_mm = mm;
80514+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80515+ pol = mpol_dup(vma_policy(mpnt));
80516+ if (IS_ERR(pol))
80517+ goto fail_nomem_policy;
80518+ vma_set_policy(tmp, pol);
80519+ if (anon_vma_fork(tmp, mpnt))
80520+ goto fail_nomem_anon_vma_fork;
80521+ tmp->vm_flags &= ~VM_LOCKED;
80522+ tmp->vm_next = tmp->vm_prev = NULL;
80523+ tmp->vm_mirror = NULL;
80524+ file = tmp->vm_file;
80525+ if (file) {
80526+ struct inode *inode = file_inode(file);
80527+ struct address_space *mapping = file->f_mapping;
80528+
80529+ get_file(file);
80530+ if (tmp->vm_flags & VM_DENYWRITE)
80531+ atomic_dec(&inode->i_writecount);
80532+ mutex_lock(&mapping->i_mmap_mutex);
80533+ if (tmp->vm_flags & VM_SHARED)
80534+ mapping->i_mmap_writable++;
80535+ flush_dcache_mmap_lock(mapping);
80536+ /* insert tmp into the share list, just after mpnt */
80537+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80538+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80539+ else
80540+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80541+ flush_dcache_mmap_unlock(mapping);
80542+ mutex_unlock(&mapping->i_mmap_mutex);
80543+ }
80544+
80545+ /*
80546+ * Clear hugetlb-related page reserves for children. This only
80547+ * affects MAP_PRIVATE mappings. Faults generated by the child
80548+ * are not guaranteed to succeed, even if read-only
80549+ */
80550+ if (is_vm_hugetlb_page(tmp))
80551+ reset_vma_resv_huge_pages(tmp);
80552+
80553+ return tmp;
80554+
80555+fail_nomem_anon_vma_fork:
80556+ mpol_put(pol);
80557+fail_nomem_policy:
80558+ kmem_cache_free(vm_area_cachep, tmp);
80559+fail_nomem:
80560+ vm_unacct_memory(charge);
80561+ return NULL;
80562+}
80563+
80564+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80565+{
80566+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80567+ struct rb_node **rb_link, *rb_parent;
80568+ int retval;
80569
80570 uprobe_start_dup_mmap();
80571 down_write(&oldmm->mmap_sem);
80572@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80573
80574 prev = NULL;
80575 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80576- struct file *file;
80577-
80578 if (mpnt->vm_flags & VM_DONTCOPY) {
80579 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80580 -vma_pages(mpnt));
80581 continue;
80582 }
80583- charge = 0;
80584- if (mpnt->vm_flags & VM_ACCOUNT) {
80585- unsigned long len = vma_pages(mpnt);
80586-
80587- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80588- goto fail_nomem;
80589- charge = len;
80590- }
80591- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80592- if (!tmp)
80593- goto fail_nomem;
80594- *tmp = *mpnt;
80595- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80596- pol = mpol_dup(vma_policy(mpnt));
80597- retval = PTR_ERR(pol);
80598- if (IS_ERR(pol))
80599- goto fail_nomem_policy;
80600- vma_set_policy(tmp, pol);
80601- tmp->vm_mm = mm;
80602- if (anon_vma_fork(tmp, mpnt))
80603- goto fail_nomem_anon_vma_fork;
80604- tmp->vm_flags &= ~VM_LOCKED;
80605- tmp->vm_next = tmp->vm_prev = NULL;
80606- file = tmp->vm_file;
80607- if (file) {
80608- struct inode *inode = file_inode(file);
80609- struct address_space *mapping = file->f_mapping;
80610-
80611- get_file(file);
80612- if (tmp->vm_flags & VM_DENYWRITE)
80613- atomic_dec(&inode->i_writecount);
80614- mutex_lock(&mapping->i_mmap_mutex);
80615- if (tmp->vm_flags & VM_SHARED)
80616- mapping->i_mmap_writable++;
80617- flush_dcache_mmap_lock(mapping);
80618- /* insert tmp into the share list, just after mpnt */
80619- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80620- vma_nonlinear_insert(tmp,
80621- &mapping->i_mmap_nonlinear);
80622- else
80623- vma_interval_tree_insert_after(tmp, mpnt,
80624- &mapping->i_mmap);
80625- flush_dcache_mmap_unlock(mapping);
80626- mutex_unlock(&mapping->i_mmap_mutex);
80627+ tmp = dup_vma(mm, oldmm, mpnt);
80628+ if (!tmp) {
80629+ retval = -ENOMEM;
80630+ goto out;
80631 }
80632
80633 /*
80634@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80635 if (retval)
80636 goto out;
80637 }
80638+
80639+#ifdef CONFIG_PAX_SEGMEXEC
80640+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80641+ struct vm_area_struct *mpnt_m;
80642+
80643+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80644+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80645+
80646+ if (!mpnt->vm_mirror)
80647+ continue;
80648+
80649+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80650+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80651+ mpnt->vm_mirror = mpnt_m;
80652+ } else {
80653+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80654+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80655+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80656+ mpnt->vm_mirror->vm_mirror = mpnt;
80657+ }
80658+ }
80659+ BUG_ON(mpnt_m);
80660+ }
80661+#endif
80662+
80663 /* a new mm has just been created */
80664 arch_dup_mmap(oldmm, mm);
80665 retval = 0;
80666@@ -471,14 +522,6 @@ out:
80667 up_write(&oldmm->mmap_sem);
80668 uprobe_end_dup_mmap();
80669 return retval;
80670-fail_nomem_anon_vma_fork:
80671- mpol_put(pol);
80672-fail_nomem_policy:
80673- kmem_cache_free(vm_area_cachep, tmp);
80674-fail_nomem:
80675- retval = -ENOMEM;
80676- vm_unacct_memory(charge);
80677- goto out;
80678 }
80679
80680 static inline int mm_alloc_pgd(struct mm_struct *mm)
80681@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80682 return ERR_PTR(err);
80683
80684 mm = get_task_mm(task);
80685- if (mm && mm != current->mm &&
80686- !ptrace_may_access(task, mode)) {
80687+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80688+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80689 mmput(mm);
80690 mm = ERR_PTR(-EACCES);
80691 }
80692@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80693 spin_unlock(&fs->lock);
80694 return -EAGAIN;
80695 }
80696- fs->users++;
80697+ atomic_inc(&fs->users);
80698 spin_unlock(&fs->lock);
80699 return 0;
80700 }
80701 tsk->fs = copy_fs_struct(fs);
80702 if (!tsk->fs)
80703 return -ENOMEM;
80704+ /* Carry through gr_chroot_dentry and is_chrooted instead
80705+ of recomputing it here. Already copied when the task struct
80706+ is duplicated. This allows pivot_root to not be treated as
80707+ a chroot
80708+ */
80709+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80710+
80711 return 0;
80712 }
80713
80714@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80715 * parts of the process environment (as per the clone
80716 * flags). The actual kick-off is left to the caller.
80717 */
80718-static struct task_struct *copy_process(unsigned long clone_flags,
80719+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80720 unsigned long stack_start,
80721 unsigned long stack_size,
80722 int __user *child_tidptr,
80723@@ -1200,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80724 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80725 #endif
80726 retval = -EAGAIN;
80727+
80728+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80729+
80730 if (atomic_read(&p->real_cred->user->processes) >=
80731 task_rlimit(p, RLIMIT_NPROC)) {
80732 if (p->real_cred->user != INIT_USER &&
80733@@ -1449,6 +1502,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80734 goto bad_fork_free_pid;
80735 }
80736
80737+ /* synchronizes with gr_set_acls()
80738+ we need to call this past the point of no return for fork()
80739+ */
80740+ gr_copy_label(p);
80741+
80742 if (likely(p->pid)) {
80743 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80744
80745@@ -1534,6 +1592,8 @@ bad_fork_cleanup_count:
80746 bad_fork_free:
80747 free_task(p);
80748 fork_out:
80749+ gr_log_forkfail(retval);
80750+
80751 return ERR_PTR(retval);
80752 }
80753
80754@@ -1604,6 +1664,7 @@ long do_fork(unsigned long clone_flags,
80755
80756 p = copy_process(clone_flags, stack_start, stack_size,
80757 child_tidptr, NULL, trace);
80758+ add_latent_entropy();
80759 /*
80760 * Do this prior waking up the new thread - the thread pointer
80761 * might get invalid after that point, if the thread exits quickly.
80762@@ -1618,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
80763 if (clone_flags & CLONE_PARENT_SETTID)
80764 put_user(nr, parent_tidptr);
80765
80766+ gr_handle_brute_check();
80767+
80768 if (clone_flags & CLONE_VFORK) {
80769 p->vfork_done = &vfork;
80770 init_completion(&vfork);
80771@@ -1734,7 +1797,7 @@ void __init proc_caches_init(void)
80772 mm_cachep = kmem_cache_create("mm_struct",
80773 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80774 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80775- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80776+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80777 mmap_init();
80778 nsproxy_cache_init();
80779 }
80780@@ -1774,7 +1837,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80781 return 0;
80782
80783 /* don't need lock here; in the worst case we'll do useless copy */
80784- if (fs->users == 1)
80785+ if (atomic_read(&fs->users) == 1)
80786 return 0;
80787
80788 *new_fsp = copy_fs_struct(fs);
80789@@ -1886,7 +1949,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80790 fs = current->fs;
80791 spin_lock(&fs->lock);
80792 current->fs = new_fs;
80793- if (--fs->users)
80794+ gr_set_chroot_entries(current, &current->fs->root);
80795+ if (atomic_dec_return(&fs->users))
80796 new_fs = NULL;
80797 else
80798 new_fs = fs;
80799diff --git a/kernel/futex.c b/kernel/futex.c
80800index c3a1a55..e32b4a98 100644
80801--- a/kernel/futex.c
80802+++ b/kernel/futex.c
80803@@ -54,6 +54,7 @@
80804 #include <linux/mount.h>
80805 #include <linux/pagemap.h>
80806 #include <linux/syscalls.h>
80807+#include <linux/ptrace.h>
80808 #include <linux/signal.h>
80809 #include <linux/export.h>
80810 #include <linux/magic.h>
80811@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80812 struct page *page, *page_head;
80813 int err, ro = 0;
80814
80815+#ifdef CONFIG_PAX_SEGMEXEC
80816+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80817+ return -EFAULT;
80818+#endif
80819+
80820 /*
80821 * The futex address must be "naturally" aligned.
80822 */
80823@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80824
80825 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80826 {
80827- int ret;
80828+ unsigned long ret;
80829
80830 pagefault_disable();
80831 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80832@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80833 {
80834 u32 curval;
80835 int i;
80836+ mm_segment_t oldfs;
80837
80838 /*
80839 * This will fail and we want it. Some arch implementations do
80840@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80841 * implementation, the non-functional ones will return
80842 * -ENOSYS.
80843 */
80844+ oldfs = get_fs();
80845+ set_fs(USER_DS);
80846 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80847 futex_cmpxchg_enabled = 1;
80848+ set_fs(oldfs);
80849
80850 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80851 plist_head_init(&futex_queues[i].chain);
80852diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80853index f9f44fd..29885e4 100644
80854--- a/kernel/futex_compat.c
80855+++ b/kernel/futex_compat.c
80856@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80857 return 0;
80858 }
80859
80860-static void __user *futex_uaddr(struct robust_list __user *entry,
80861+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80862 compat_long_t futex_offset)
80863 {
80864 compat_uptr_t base = ptr_to_compat(entry);
80865diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80866index 9b22d03..6295b62 100644
80867--- a/kernel/gcov/base.c
80868+++ b/kernel/gcov/base.c
80869@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80870 }
80871
80872 #ifdef CONFIG_MODULES
80873-static inline int within(void *addr, void *start, unsigned long size)
80874-{
80875- return ((addr >= start) && (addr < start + size));
80876-}
80877-
80878 /* Update list and generate events when modules are unloaded. */
80879 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80880 void *data)
80881@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80882 prev = NULL;
80883 /* Remove entries located in module from linked list. */
80884 for (info = gcov_info_head; info; info = info->next) {
80885- if (within(info, mod->module_core, mod->core_size)) {
80886+ if (within_module_core_rw((unsigned long)info, mod)) {
80887 if (prev)
80888 prev->next = info->next;
80889 else
80890diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80891index 383319b..56ebb13 100644
80892--- a/kernel/hrtimer.c
80893+++ b/kernel/hrtimer.c
80894@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80895 local_irq_restore(flags);
80896 }
80897
80898-static void run_hrtimer_softirq(struct softirq_action *h)
80899+static __latent_entropy void run_hrtimer_softirq(void)
80900 {
80901 hrtimer_peek_ahead_timers();
80902 }
80903diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80904index 55fcce6..0e4cf34 100644
80905--- a/kernel/irq_work.c
80906+++ b/kernel/irq_work.c
80907@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80908 return NOTIFY_OK;
80909 }
80910
80911-static struct notifier_block cpu_notify;
80912+static struct notifier_block cpu_notify = {
80913+ .notifier_call = irq_work_cpu_notify,
80914+ .priority = 0,
80915+};
80916
80917 static __init int irq_work_init_cpu_notifier(void)
80918 {
80919- cpu_notify.notifier_call = irq_work_cpu_notify;
80920- cpu_notify.priority = 0;
80921 register_cpu_notifier(&cpu_notify);
80922 return 0;
80923 }
80924diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80925index 60f48fa..7f3a770 100644
80926--- a/kernel/jump_label.c
80927+++ b/kernel/jump_label.c
80928@@ -13,6 +13,7 @@
80929 #include <linux/sort.h>
80930 #include <linux/err.h>
80931 #include <linux/static_key.h>
80932+#include <linux/mm.h>
80933
80934 #ifdef HAVE_JUMP_LABEL
80935
80936@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80937
80938 size = (((unsigned long)stop - (unsigned long)start)
80939 / sizeof(struct jump_entry));
80940+ pax_open_kernel();
80941 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80942+ pax_close_kernel();
80943 }
80944
80945 static void jump_label_update(struct static_key *key, int enable);
80946@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80947 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80948 struct jump_entry *iter;
80949
80950+ pax_open_kernel();
80951 for (iter = iter_start; iter < iter_stop; iter++) {
80952 if (within_module_init(iter->code, mod))
80953 iter->code = 0;
80954 }
80955+ pax_close_kernel();
80956 }
80957
80958 static int
80959diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80960index 3127ad5..159d880 100644
80961--- a/kernel/kallsyms.c
80962+++ b/kernel/kallsyms.c
80963@@ -11,6 +11,9 @@
80964 * Changed the compression method from stem compression to "table lookup"
80965 * compression (see scripts/kallsyms.c for a more complete description)
80966 */
80967+#ifdef CONFIG_GRKERNSEC_HIDESYM
80968+#define __INCLUDED_BY_HIDESYM 1
80969+#endif
80970 #include <linux/kallsyms.h>
80971 #include <linux/module.h>
80972 #include <linux/init.h>
80973@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80974
80975 static inline int is_kernel_inittext(unsigned long addr)
80976 {
80977+ if (system_state != SYSTEM_BOOTING)
80978+ return 0;
80979+
80980 if (addr >= (unsigned long)_sinittext
80981 && addr <= (unsigned long)_einittext)
80982 return 1;
80983 return 0;
80984 }
80985
80986+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80987+#ifdef CONFIG_MODULES
80988+static inline int is_module_text(unsigned long addr)
80989+{
80990+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80991+ return 1;
80992+
80993+ addr = ktla_ktva(addr);
80994+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80995+}
80996+#else
80997+static inline int is_module_text(unsigned long addr)
80998+{
80999+ return 0;
81000+}
81001+#endif
81002+#endif
81003+
81004 static inline int is_kernel_text(unsigned long addr)
81005 {
81006 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
81007@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
81008
81009 static inline int is_kernel(unsigned long addr)
81010 {
81011+
81012+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81013+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
81014+ return 1;
81015+
81016+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
81017+#else
81018 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
81019+#endif
81020+
81021 return 1;
81022 return in_gate_area_no_mm(addr);
81023 }
81024
81025 static int is_ksym_addr(unsigned long addr)
81026 {
81027+
81028+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81029+ if (is_module_text(addr))
81030+ return 0;
81031+#endif
81032+
81033 if (all_var)
81034 return is_kernel(addr);
81035
81036@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
81037
81038 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
81039 {
81040- iter->name[0] = '\0';
81041 iter->nameoff = get_symbol_offset(new_pos);
81042 iter->pos = new_pos;
81043 }
81044@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
81045 {
81046 struct kallsym_iter *iter = m->private;
81047
81048+#ifdef CONFIG_GRKERNSEC_HIDESYM
81049+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
81050+ return 0;
81051+#endif
81052+
81053 /* Some debugging symbols have no name. Ignore them. */
81054 if (!iter->name[0])
81055 return 0;
81056@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
81057 */
81058 type = iter->exported ? toupper(iter->type) :
81059 tolower(iter->type);
81060+
81061 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
81062 type, iter->name, iter->module_name);
81063 } else
81064@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
81065 struct kallsym_iter *iter;
81066 int ret;
81067
81068- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
81069+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
81070 if (!iter)
81071 return -ENOMEM;
81072 reset_iter(iter, 0);
81073diff --git a/kernel/kcmp.c b/kernel/kcmp.c
81074index e30ac0f..3528cac 100644
81075--- a/kernel/kcmp.c
81076+++ b/kernel/kcmp.c
81077@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
81078 struct task_struct *task1, *task2;
81079 int ret;
81080
81081+#ifdef CONFIG_GRKERNSEC
81082+ return -ENOSYS;
81083+#endif
81084+
81085 rcu_read_lock();
81086
81087 /*
81088diff --git a/kernel/kexec.c b/kernel/kexec.c
81089index 59f7b55..4022f65 100644
81090--- a/kernel/kexec.c
81091+++ b/kernel/kexec.c
81092@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
81093 unsigned long flags)
81094 {
81095 struct compat_kexec_segment in;
81096- struct kexec_segment out, __user *ksegments;
81097+ struct kexec_segment out;
81098+ struct kexec_segment __user *ksegments;
81099 unsigned long i, result;
81100
81101 /* Don't allow clients that don't understand the native
81102diff --git a/kernel/kmod.c b/kernel/kmod.c
81103index fb32636..2fe8775 100644
81104--- a/kernel/kmod.c
81105+++ b/kernel/kmod.c
81106@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
81107 kfree(info->argv);
81108 }
81109
81110-static int call_modprobe(char *module_name, int wait)
81111+static int call_modprobe(char *module_name, char *module_param, int wait)
81112 {
81113 struct subprocess_info *info;
81114 static char *envp[] = {
81115@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
81116 NULL
81117 };
81118
81119- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
81120+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
81121 if (!argv)
81122 goto out;
81123
81124@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
81125 argv[1] = "-q";
81126 argv[2] = "--";
81127 argv[3] = module_name; /* check free_modprobe_argv() */
81128- argv[4] = NULL;
81129+ argv[4] = module_param;
81130+ argv[5] = NULL;
81131
81132 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
81133 NULL, free_modprobe_argv, NULL);
81134@@ -129,9 +130,8 @@ out:
81135 * If module auto-loading support is disabled then this function
81136 * becomes a no-operation.
81137 */
81138-int __request_module(bool wait, const char *fmt, ...)
81139+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
81140 {
81141- va_list args;
81142 char module_name[MODULE_NAME_LEN];
81143 unsigned int max_modprobes;
81144 int ret;
81145@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
81146 if (!modprobe_path[0])
81147 return 0;
81148
81149- va_start(args, fmt);
81150- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
81151- va_end(args);
81152+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
81153 if (ret >= MODULE_NAME_LEN)
81154 return -ENAMETOOLONG;
81155
81156@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
81157 if (ret)
81158 return ret;
81159
81160+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81161+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81162+ /* hack to workaround consolekit/udisks stupidity */
81163+ read_lock(&tasklist_lock);
81164+ if (!strcmp(current->comm, "mount") &&
81165+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
81166+ read_unlock(&tasklist_lock);
81167+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
81168+ return -EPERM;
81169+ }
81170+ read_unlock(&tasklist_lock);
81171+ }
81172+#endif
81173+
81174 /* If modprobe needs a service that is in a module, we get a recursive
81175 * loop. Limit the number of running kmod threads to max_threads/2 or
81176 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
81177@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
81178
81179 trace_module_request(module_name, wait, _RET_IP_);
81180
81181- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81182+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81183
81184 atomic_dec(&kmod_concurrent);
81185 return ret;
81186 }
81187+
81188+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81189+{
81190+ va_list args;
81191+ int ret;
81192+
81193+ va_start(args, fmt);
81194+ ret = ____request_module(wait, module_param, fmt, args);
81195+ va_end(args);
81196+
81197+ return ret;
81198+}
81199+
81200+int __request_module(bool wait, const char *fmt, ...)
81201+{
81202+ va_list args;
81203+ int ret;
81204+
81205+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81206+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81207+ char module_param[MODULE_NAME_LEN];
81208+
81209+ memset(module_param, 0, sizeof(module_param));
81210+
81211+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81212+
81213+ va_start(args, fmt);
81214+ ret = ____request_module(wait, module_param, fmt, args);
81215+ va_end(args);
81216+
81217+ return ret;
81218+ }
81219+#endif
81220+
81221+ va_start(args, fmt);
81222+ ret = ____request_module(wait, NULL, fmt, args);
81223+ va_end(args);
81224+
81225+ return ret;
81226+}
81227+
81228 EXPORT_SYMBOL(__request_module);
81229 #endif /* CONFIG_MODULES */
81230
81231@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81232 *
81233 * Thus the __user pointer cast is valid here.
81234 */
81235- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81236+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81237
81238 /*
81239 * If ret is 0, either ____call_usermodehelper failed and the
81240@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81241 static int proc_cap_handler(struct ctl_table *table, int write,
81242 void __user *buffer, size_t *lenp, loff_t *ppos)
81243 {
81244- struct ctl_table t;
81245+ ctl_table_no_const t;
81246 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81247 kernel_cap_t new_cap;
81248 int err, i;
81249diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81250index 6e33498..3133bd3 100644
81251--- a/kernel/kprobes.c
81252+++ b/kernel/kprobes.c
81253@@ -31,6 +31,9 @@
81254 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81255 * <prasanna@in.ibm.com> added function-return probes.
81256 */
81257+#ifdef CONFIG_GRKERNSEC_HIDESYM
81258+#define __INCLUDED_BY_HIDESYM 1
81259+#endif
81260 #include <linux/kprobes.h>
81261 #include <linux/hash.h>
81262 #include <linux/init.h>
81263@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81264 * kernel image and loaded module images reside. This is required
81265 * so x86_64 can correctly handle the %rip-relative fixups.
81266 */
81267- kip->insns = module_alloc(PAGE_SIZE);
81268+ kip->insns = module_alloc_exec(PAGE_SIZE);
81269 if (!kip->insns) {
81270 kfree(kip);
81271 return NULL;
81272@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81273 */
81274 if (!list_is_singular(&kip->list)) {
81275 list_del(&kip->list);
81276- module_free(NULL, kip->insns);
81277+ module_free_exec(NULL, kip->insns);
81278 kfree(kip);
81279 }
81280 return 1;
81281@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81282 {
81283 int i, err = 0;
81284 unsigned long offset = 0, size = 0;
81285- char *modname, namebuf[128];
81286+ char *modname, namebuf[KSYM_NAME_LEN];
81287 const char *symbol_name;
81288 void *addr;
81289 struct kprobe_blackpoint *kb;
81290@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81291 kprobe_type = "k";
81292
81293 if (sym)
81294- seq_printf(pi, "%p %s %s+0x%x %s ",
81295+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81296 p->addr, kprobe_type, sym, offset,
81297 (modname ? modname : " "));
81298 else
81299- seq_printf(pi, "%p %s %p ",
81300+ seq_printf(pi, "%pK %s %pK ",
81301 p->addr, kprobe_type, p->addr);
81302
81303 if (!pp)
81304@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81305 const char *sym = NULL;
81306 unsigned int i = *(loff_t *) v;
81307 unsigned long offset = 0;
81308- char *modname, namebuf[128];
81309+ char *modname, namebuf[KSYM_NAME_LEN];
81310
81311 head = &kprobe_table[i];
81312 preempt_disable();
81313diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81314index 6ada93c..dce7d5d 100644
81315--- a/kernel/ksysfs.c
81316+++ b/kernel/ksysfs.c
81317@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81318 {
81319 if (count+1 > UEVENT_HELPER_PATH_LEN)
81320 return -ENOENT;
81321+ if (!capable(CAP_SYS_ADMIN))
81322+ return -EPERM;
81323 memcpy(uevent_helper, buf, count);
81324 uevent_helper[count] = '\0';
81325 if (count && uevent_helper[count-1] == '\n')
81326@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81327 return count;
81328 }
81329
81330-static struct bin_attribute notes_attr = {
81331+static bin_attribute_no_const notes_attr __read_only = {
81332 .attr = {
81333 .name = "notes",
81334 .mode = S_IRUGO,
81335diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81336index e16c45b..6f49c48 100644
81337--- a/kernel/lockdep.c
81338+++ b/kernel/lockdep.c
81339@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81340 end = (unsigned long) &_end,
81341 addr = (unsigned long) obj;
81342
81343+#ifdef CONFIG_PAX_KERNEXEC
81344+ start = ktla_ktva(start);
81345+#endif
81346+
81347 /*
81348 * static variable?
81349 */
81350@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81351 if (!static_obj(lock->key)) {
81352 debug_locks_off();
81353 printk("INFO: trying to register non-static key.\n");
81354+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81355 printk("the code is fine but needs lockdep annotation.\n");
81356 printk("turning off the locking correctness validator.\n");
81357 dump_stack();
81358@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81359 if (!class)
81360 return 0;
81361 }
81362- atomic_inc((atomic_t *)&class->ops);
81363+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81364 if (very_verbose(class)) {
81365 printk("\nacquire class [%p] %s", class->key, class->name);
81366 if (class->name_version > 1)
81367diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81368index b2c71c5..7b88d63 100644
81369--- a/kernel/lockdep_proc.c
81370+++ b/kernel/lockdep_proc.c
81371@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81372 return 0;
81373 }
81374
81375- seq_printf(m, "%p", class->key);
81376+ seq_printf(m, "%pK", class->key);
81377 #ifdef CONFIG_DEBUG_LOCKDEP
81378 seq_printf(m, " OPS:%8ld", class->ops);
81379 #endif
81380@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81381
81382 list_for_each_entry(entry, &class->locks_after, entry) {
81383 if (entry->distance == 1) {
81384- seq_printf(m, " -> [%p] ", entry->class->key);
81385+ seq_printf(m, " -> [%pK] ", entry->class->key);
81386 print_name(m, entry->class);
81387 seq_puts(m, "\n");
81388 }
81389@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81390 if (!class->key)
81391 continue;
81392
81393- seq_printf(m, "[%p] ", class->key);
81394+ seq_printf(m, "[%pK] ", class->key);
81395 print_name(m, class);
81396 seq_puts(m, "\n");
81397 }
81398@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81399 if (!i)
81400 seq_line(m, '-', 40-namelen, namelen);
81401
81402- snprintf(ip, sizeof(ip), "[<%p>]",
81403+ snprintf(ip, sizeof(ip), "[<%pK>]",
81404 (void *)class->contention_point[i]);
81405 seq_printf(m, "%40s %14lu %29s %pS\n",
81406 name, stats->contention_point[i],
81407@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81408 if (!i)
81409 seq_line(m, '-', 40-namelen, namelen);
81410
81411- snprintf(ip, sizeof(ip), "[<%p>]",
81412+ snprintf(ip, sizeof(ip), "[<%pK>]",
81413 (void *)class->contending_point[i]);
81414 seq_printf(m, "%40s %14lu %29s %pS\n",
81415 name, stats->contending_point[i],
81416diff --git a/kernel/module.c b/kernel/module.c
81417index 2069158..71101bb 100644
81418--- a/kernel/module.c
81419+++ b/kernel/module.c
81420@@ -61,6 +61,7 @@
81421 #include <linux/pfn.h>
81422 #include <linux/bsearch.h>
81423 #include <linux/fips.h>
81424+#include <linux/grsecurity.h>
81425 #include <uapi/linux/module.h>
81426 #include "module-internal.h"
81427
81428@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81429
81430 /* Bounds of module allocation, for speeding __module_address.
81431 * Protected by module_mutex. */
81432-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81433+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81434+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81435
81436 int register_module_notifier(struct notifier_block * nb)
81437 {
81438@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81439 return true;
81440
81441 list_for_each_entry_rcu(mod, &modules, list) {
81442- struct symsearch arr[] = {
81443+ struct symsearch modarr[] = {
81444 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81445 NOT_GPL_ONLY, false },
81446 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81447@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81448 if (mod->state == MODULE_STATE_UNFORMED)
81449 continue;
81450
81451- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81452+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81453 return true;
81454 }
81455 return false;
81456@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81457 if (!pcpusec->sh_size)
81458 return 0;
81459
81460- if (align > PAGE_SIZE) {
81461+ if (align-1 >= PAGE_SIZE) {
81462 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81463 mod->name, align, PAGE_SIZE);
81464 align = PAGE_SIZE;
81465@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81466 static ssize_t show_coresize(struct module_attribute *mattr,
81467 struct module_kobject *mk, char *buffer)
81468 {
81469- return sprintf(buffer, "%u\n", mk->mod->core_size);
81470+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81471 }
81472
81473 static struct module_attribute modinfo_coresize =
81474@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81475 static ssize_t show_initsize(struct module_attribute *mattr,
81476 struct module_kobject *mk, char *buffer)
81477 {
81478- return sprintf(buffer, "%u\n", mk->mod->init_size);
81479+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81480 }
81481
81482 static struct module_attribute modinfo_initsize =
81483@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81484 */
81485 #ifdef CONFIG_SYSFS
81486
81487-#ifdef CONFIG_KALLSYMS
81488+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81489 static inline bool sect_empty(const Elf_Shdr *sect)
81490 {
81491 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81492@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81493 {
81494 unsigned int notes, loaded, i;
81495 struct module_notes_attrs *notes_attrs;
81496- struct bin_attribute *nattr;
81497+ bin_attribute_no_const *nattr;
81498
81499 /* failed to create section attributes, so can't create notes */
81500 if (!mod->sect_attrs)
81501@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81502 static int module_add_modinfo_attrs(struct module *mod)
81503 {
81504 struct module_attribute *attr;
81505- struct module_attribute *temp_attr;
81506+ module_attribute_no_const *temp_attr;
81507 int error = 0;
81508 int i;
81509
81510@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81511
81512 static void unset_module_core_ro_nx(struct module *mod)
81513 {
81514- set_page_attributes(mod->module_core + mod->core_text_size,
81515- mod->module_core + mod->core_size,
81516+ set_page_attributes(mod->module_core_rw,
81517+ mod->module_core_rw + mod->core_size_rw,
81518 set_memory_x);
81519- set_page_attributes(mod->module_core,
81520- mod->module_core + mod->core_ro_size,
81521+ set_page_attributes(mod->module_core_rx,
81522+ mod->module_core_rx + mod->core_size_rx,
81523 set_memory_rw);
81524 }
81525
81526 static void unset_module_init_ro_nx(struct module *mod)
81527 {
81528- set_page_attributes(mod->module_init + mod->init_text_size,
81529- mod->module_init + mod->init_size,
81530+ set_page_attributes(mod->module_init_rw,
81531+ mod->module_init_rw + mod->init_size_rw,
81532 set_memory_x);
81533- set_page_attributes(mod->module_init,
81534- mod->module_init + mod->init_ro_size,
81535+ set_page_attributes(mod->module_init_rx,
81536+ mod->module_init_rx + mod->init_size_rx,
81537 set_memory_rw);
81538 }
81539
81540@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81541 list_for_each_entry_rcu(mod, &modules, list) {
81542 if (mod->state == MODULE_STATE_UNFORMED)
81543 continue;
81544- if ((mod->module_core) && (mod->core_text_size)) {
81545- set_page_attributes(mod->module_core,
81546- mod->module_core + mod->core_text_size,
81547+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81548+ set_page_attributes(mod->module_core_rx,
81549+ mod->module_core_rx + mod->core_size_rx,
81550 set_memory_rw);
81551 }
81552- if ((mod->module_init) && (mod->init_text_size)) {
81553- set_page_attributes(mod->module_init,
81554- mod->module_init + mod->init_text_size,
81555+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81556+ set_page_attributes(mod->module_init_rx,
81557+ mod->module_init_rx + mod->init_size_rx,
81558 set_memory_rw);
81559 }
81560 }
81561@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81562 list_for_each_entry_rcu(mod, &modules, list) {
81563 if (mod->state == MODULE_STATE_UNFORMED)
81564 continue;
81565- if ((mod->module_core) && (mod->core_text_size)) {
81566- set_page_attributes(mod->module_core,
81567- mod->module_core + mod->core_text_size,
81568+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81569+ set_page_attributes(mod->module_core_rx,
81570+ mod->module_core_rx + mod->core_size_rx,
81571 set_memory_ro);
81572 }
81573- if ((mod->module_init) && (mod->init_text_size)) {
81574- set_page_attributes(mod->module_init,
81575- mod->module_init + mod->init_text_size,
81576+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81577+ set_page_attributes(mod->module_init_rx,
81578+ mod->module_init_rx + mod->init_size_rx,
81579 set_memory_ro);
81580 }
81581 }
81582@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81583
81584 /* This may be NULL, but that's OK */
81585 unset_module_init_ro_nx(mod);
81586- module_free(mod, mod->module_init);
81587+ module_free(mod, mod->module_init_rw);
81588+ module_free_exec(mod, mod->module_init_rx);
81589 kfree(mod->args);
81590 percpu_modfree(mod);
81591
81592 /* Free lock-classes: */
81593- lockdep_free_key_range(mod->module_core, mod->core_size);
81594+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81595+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81596
81597 /* Finally, free the core (containing the module structure) */
81598 unset_module_core_ro_nx(mod);
81599- module_free(mod, mod->module_core);
81600+ module_free_exec(mod, mod->module_core_rx);
81601+ module_free(mod, mod->module_core_rw);
81602
81603 #ifdef CONFIG_MPU
81604 update_protections(current->mm);
81605@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81606 int ret = 0;
81607 const struct kernel_symbol *ksym;
81608
81609+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81610+ int is_fs_load = 0;
81611+ int register_filesystem_found = 0;
81612+ char *p;
81613+
81614+ p = strstr(mod->args, "grsec_modharden_fs");
81615+ if (p) {
81616+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81617+ /* copy \0 as well */
81618+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81619+ is_fs_load = 1;
81620+ }
81621+#endif
81622+
81623 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81624 const char *name = info->strtab + sym[i].st_name;
81625
81626+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81627+ /* it's a real shame this will never get ripped and copied
81628+ upstream! ;(
81629+ */
81630+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81631+ register_filesystem_found = 1;
81632+#endif
81633+
81634 switch (sym[i].st_shndx) {
81635 case SHN_COMMON:
81636 /* We compiled with -fno-common. These are not
81637@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81638 ksym = resolve_symbol_wait(mod, info, name);
81639 /* Ok if resolved. */
81640 if (ksym && !IS_ERR(ksym)) {
81641+ pax_open_kernel();
81642 sym[i].st_value = ksym->value;
81643+ pax_close_kernel();
81644 break;
81645 }
81646
81647@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81648 secbase = (unsigned long)mod_percpu(mod);
81649 else
81650 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81651+ pax_open_kernel();
81652 sym[i].st_value += secbase;
81653+ pax_close_kernel();
81654 break;
81655 }
81656 }
81657
81658+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81659+ if (is_fs_load && !register_filesystem_found) {
81660+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81661+ ret = -EPERM;
81662+ }
81663+#endif
81664+
81665 return ret;
81666 }
81667
81668@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81669 || s->sh_entsize != ~0UL
81670 || strstarts(sname, ".init"))
81671 continue;
81672- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81673+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81674+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81675+ else
81676+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81677 pr_debug("\t%s\n", sname);
81678 }
81679- switch (m) {
81680- case 0: /* executable */
81681- mod->core_size = debug_align(mod->core_size);
81682- mod->core_text_size = mod->core_size;
81683- break;
81684- case 1: /* RO: text and ro-data */
81685- mod->core_size = debug_align(mod->core_size);
81686- mod->core_ro_size = mod->core_size;
81687- break;
81688- case 3: /* whole core */
81689- mod->core_size = debug_align(mod->core_size);
81690- break;
81691- }
81692 }
81693
81694 pr_debug("Init section allocation order:\n");
81695@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81696 || s->sh_entsize != ~0UL
81697 || !strstarts(sname, ".init"))
81698 continue;
81699- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81700- | INIT_OFFSET_MASK);
81701+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81702+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81703+ else
81704+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81705+ s->sh_entsize |= INIT_OFFSET_MASK;
81706 pr_debug("\t%s\n", sname);
81707 }
81708- switch (m) {
81709- case 0: /* executable */
81710- mod->init_size = debug_align(mod->init_size);
81711- mod->init_text_size = mod->init_size;
81712- break;
81713- case 1: /* RO: text and ro-data */
81714- mod->init_size = debug_align(mod->init_size);
81715- mod->init_ro_size = mod->init_size;
81716- break;
81717- case 3: /* whole init */
81718- mod->init_size = debug_align(mod->init_size);
81719- break;
81720- }
81721 }
81722 }
81723
81724@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81725
81726 /* Put symbol section at end of init part of module. */
81727 symsect->sh_flags |= SHF_ALLOC;
81728- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81729+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81730 info->index.sym) | INIT_OFFSET_MASK;
81731 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81732
81733@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81734 }
81735
81736 /* Append room for core symbols at end of core part. */
81737- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81738- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81739- mod->core_size += strtab_size;
81740+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81741+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81742+ mod->core_size_rx += strtab_size;
81743
81744 /* Put string table section at end of init part of module. */
81745 strsect->sh_flags |= SHF_ALLOC;
81746- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81747+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81748 info->index.str) | INIT_OFFSET_MASK;
81749 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81750 }
81751@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81752 /* Make sure we get permanent strtab: don't use info->strtab. */
81753 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81754
81755+ pax_open_kernel();
81756+
81757 /* Set types up while we still have access to sections. */
81758 for (i = 0; i < mod->num_symtab; i++)
81759 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81760
81761- mod->core_symtab = dst = mod->module_core + info->symoffs;
81762- mod->core_strtab = s = mod->module_core + info->stroffs;
81763+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81764+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81765 src = mod->symtab;
81766 for (ndst = i = 0; i < mod->num_symtab; i++) {
81767 if (i == 0 ||
81768@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81769 }
81770 }
81771 mod->core_num_syms = ndst;
81772+
81773+ pax_close_kernel();
81774 }
81775 #else
81776 static inline void layout_symtab(struct module *mod, struct load_info *info)
81777@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81778 return vmalloc_exec(size);
81779 }
81780
81781-static void *module_alloc_update_bounds(unsigned long size)
81782+static void *module_alloc_update_bounds_rw(unsigned long size)
81783 {
81784 void *ret = module_alloc(size);
81785
81786 if (ret) {
81787 mutex_lock(&module_mutex);
81788 /* Update module bounds. */
81789- if ((unsigned long)ret < module_addr_min)
81790- module_addr_min = (unsigned long)ret;
81791- if ((unsigned long)ret + size > module_addr_max)
81792- module_addr_max = (unsigned long)ret + size;
81793+ if ((unsigned long)ret < module_addr_min_rw)
81794+ module_addr_min_rw = (unsigned long)ret;
81795+ if ((unsigned long)ret + size > module_addr_max_rw)
81796+ module_addr_max_rw = (unsigned long)ret + size;
81797+ mutex_unlock(&module_mutex);
81798+ }
81799+ return ret;
81800+}
81801+
81802+static void *module_alloc_update_bounds_rx(unsigned long size)
81803+{
81804+ void *ret = module_alloc_exec(size);
81805+
81806+ if (ret) {
81807+ mutex_lock(&module_mutex);
81808+ /* Update module bounds. */
81809+ if ((unsigned long)ret < module_addr_min_rx)
81810+ module_addr_min_rx = (unsigned long)ret;
81811+ if ((unsigned long)ret + size > module_addr_max_rx)
81812+ module_addr_max_rx = (unsigned long)ret + size;
81813 mutex_unlock(&module_mutex);
81814 }
81815 return ret;
81816@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81817 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81818 {
81819 const char *modmagic = get_modinfo(info, "vermagic");
81820+ const char *license = get_modinfo(info, "license");
81821 int err;
81822
81823+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81824+ if (!license || !license_is_gpl_compatible(license))
81825+ return -ENOEXEC;
81826+#endif
81827+
81828 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81829 modmagic = NULL;
81830
81831@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81832 }
81833
81834 /* Set up license info based on the info section */
81835- set_license(mod, get_modinfo(info, "license"));
81836+ set_license(mod, license);
81837
81838 return 0;
81839 }
81840@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81841 void *ptr;
81842
81843 /* Do the allocs. */
81844- ptr = module_alloc_update_bounds(mod->core_size);
81845+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81846 /*
81847 * The pointer to this block is stored in the module structure
81848 * which is inside the block. Just mark it as not being a
81849@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81850 if (!ptr)
81851 return -ENOMEM;
81852
81853- memset(ptr, 0, mod->core_size);
81854- mod->module_core = ptr;
81855+ memset(ptr, 0, mod->core_size_rw);
81856+ mod->module_core_rw = ptr;
81857
81858- if (mod->init_size) {
81859- ptr = module_alloc_update_bounds(mod->init_size);
81860+ if (mod->init_size_rw) {
81861+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81862 /*
81863 * The pointer to this block is stored in the module structure
81864 * which is inside the block. This block doesn't need to be
81865@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81866 */
81867 kmemleak_ignore(ptr);
81868 if (!ptr) {
81869- module_free(mod, mod->module_core);
81870+ module_free(mod, mod->module_core_rw);
81871 return -ENOMEM;
81872 }
81873- memset(ptr, 0, mod->init_size);
81874- mod->module_init = ptr;
81875+ memset(ptr, 0, mod->init_size_rw);
81876+ mod->module_init_rw = ptr;
81877 } else
81878- mod->module_init = NULL;
81879+ mod->module_init_rw = NULL;
81880+
81881+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81882+ kmemleak_not_leak(ptr);
81883+ if (!ptr) {
81884+ if (mod->module_init_rw)
81885+ module_free(mod, mod->module_init_rw);
81886+ module_free(mod, mod->module_core_rw);
81887+ return -ENOMEM;
81888+ }
81889+
81890+ pax_open_kernel();
81891+ memset(ptr, 0, mod->core_size_rx);
81892+ pax_close_kernel();
81893+ mod->module_core_rx = ptr;
81894+
81895+ if (mod->init_size_rx) {
81896+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81897+ kmemleak_ignore(ptr);
81898+ if (!ptr && mod->init_size_rx) {
81899+ module_free_exec(mod, mod->module_core_rx);
81900+ if (mod->module_init_rw)
81901+ module_free(mod, mod->module_init_rw);
81902+ module_free(mod, mod->module_core_rw);
81903+ return -ENOMEM;
81904+ }
81905+
81906+ pax_open_kernel();
81907+ memset(ptr, 0, mod->init_size_rx);
81908+ pax_close_kernel();
81909+ mod->module_init_rx = ptr;
81910+ } else
81911+ mod->module_init_rx = NULL;
81912
81913 /* Transfer each section which specifies SHF_ALLOC */
81914 pr_debug("final section addresses:\n");
81915@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81916 if (!(shdr->sh_flags & SHF_ALLOC))
81917 continue;
81918
81919- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81920- dest = mod->module_init
81921- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81922- else
81923- dest = mod->module_core + shdr->sh_entsize;
81924+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81925+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81926+ dest = mod->module_init_rw
81927+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81928+ else
81929+ dest = mod->module_init_rx
81930+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81931+ } else {
81932+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81933+ dest = mod->module_core_rw + shdr->sh_entsize;
81934+ else
81935+ dest = mod->module_core_rx + shdr->sh_entsize;
81936+ }
81937+
81938+ if (shdr->sh_type != SHT_NOBITS) {
81939+
81940+#ifdef CONFIG_PAX_KERNEXEC
81941+#ifdef CONFIG_X86_64
81942+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81943+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81944+#endif
81945+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81946+ pax_open_kernel();
81947+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81948+ pax_close_kernel();
81949+ } else
81950+#endif
81951
81952- if (shdr->sh_type != SHT_NOBITS)
81953 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81954+ }
81955 /* Update sh_addr to point to copy in image. */
81956- shdr->sh_addr = (unsigned long)dest;
81957+
81958+#ifdef CONFIG_PAX_KERNEXEC
81959+ if (shdr->sh_flags & SHF_EXECINSTR)
81960+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81961+ else
81962+#endif
81963+
81964+ shdr->sh_addr = (unsigned long)dest;
81965 pr_debug("\t0x%lx %s\n",
81966 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81967 }
81968@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81969 * Do it before processing of module parameters, so the module
81970 * can provide parameter accessor functions of its own.
81971 */
81972- if (mod->module_init)
81973- flush_icache_range((unsigned long)mod->module_init,
81974- (unsigned long)mod->module_init
81975- + mod->init_size);
81976- flush_icache_range((unsigned long)mod->module_core,
81977- (unsigned long)mod->module_core + mod->core_size);
81978+ if (mod->module_init_rx)
81979+ flush_icache_range((unsigned long)mod->module_init_rx,
81980+ (unsigned long)mod->module_init_rx
81981+ + mod->init_size_rx);
81982+ flush_icache_range((unsigned long)mod->module_core_rx,
81983+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81984
81985 set_fs(old_fs);
81986 }
81987@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81988 static void module_deallocate(struct module *mod, struct load_info *info)
81989 {
81990 percpu_modfree(mod);
81991- module_free(mod, mod->module_init);
81992- module_free(mod, mod->module_core);
81993+ module_free_exec(mod, mod->module_init_rx);
81994+ module_free_exec(mod, mod->module_core_rx);
81995+ module_free(mod, mod->module_init_rw);
81996+ module_free(mod, mod->module_core_rw);
81997 }
81998
81999 int __weak module_finalize(const Elf_Ehdr *hdr,
82000@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
82001 static int post_relocation(struct module *mod, const struct load_info *info)
82002 {
82003 /* Sort exception table now relocations are done. */
82004+ pax_open_kernel();
82005 sort_extable(mod->extable, mod->extable + mod->num_exentries);
82006+ pax_close_kernel();
82007
82008 /* Copy relocated percpu area over. */
82009 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
82010@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
82011 MODULE_STATE_COMING, mod);
82012
82013 /* Set RO and NX regions for core */
82014- set_section_ro_nx(mod->module_core,
82015- mod->core_text_size,
82016- mod->core_ro_size,
82017- mod->core_size);
82018+ set_section_ro_nx(mod->module_core_rx,
82019+ mod->core_size_rx,
82020+ mod->core_size_rx,
82021+ mod->core_size_rx);
82022
82023 /* Set RO and NX regions for init */
82024- set_section_ro_nx(mod->module_init,
82025- mod->init_text_size,
82026- mod->init_ro_size,
82027- mod->init_size);
82028+ set_section_ro_nx(mod->module_init_rx,
82029+ mod->init_size_rx,
82030+ mod->init_size_rx,
82031+ mod->init_size_rx);
82032
82033 do_mod_ctors(mod);
82034 /* Start the module */
82035@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
82036 mod->strtab = mod->core_strtab;
82037 #endif
82038 unset_module_init_ro_nx(mod);
82039- module_free(mod, mod->module_init);
82040- mod->module_init = NULL;
82041- mod->init_size = 0;
82042- mod->init_ro_size = 0;
82043- mod->init_text_size = 0;
82044+ module_free(mod, mod->module_init_rw);
82045+ module_free_exec(mod, mod->module_init_rx);
82046+ mod->module_init_rw = NULL;
82047+ mod->module_init_rx = NULL;
82048+ mod->init_size_rw = 0;
82049+ mod->init_size_rx = 0;
82050 mutex_unlock(&module_mutex);
82051 wake_up_all(&module_wq);
82052
82053@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
82054 if (err)
82055 goto free_unload;
82056
82057+ /* Now copy in args */
82058+ mod->args = strndup_user(uargs, ~0UL >> 1);
82059+ if (IS_ERR(mod->args)) {
82060+ err = PTR_ERR(mod->args);
82061+ goto free_unload;
82062+ }
82063+
82064 /* Set up MODINFO_ATTR fields */
82065 setup_modinfo(mod, info);
82066
82067+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82068+ {
82069+ char *p, *p2;
82070+
82071+ if (strstr(mod->args, "grsec_modharden_netdev")) {
82072+ 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);
82073+ err = -EPERM;
82074+ goto free_modinfo;
82075+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
82076+ p += sizeof("grsec_modharden_normal") - 1;
82077+ p2 = strstr(p, "_");
82078+ if (p2) {
82079+ *p2 = '\0';
82080+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
82081+ *p2 = '_';
82082+ }
82083+ err = -EPERM;
82084+ goto free_modinfo;
82085+ }
82086+ }
82087+#endif
82088+
82089 /* Fix up syms, so that st_value is a pointer to location. */
82090 err = simplify_symbols(mod, info);
82091 if (err < 0)
82092@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
82093
82094 flush_module_icache(mod);
82095
82096- /* Now copy in args */
82097- mod->args = strndup_user(uargs, ~0UL >> 1);
82098- if (IS_ERR(mod->args)) {
82099- err = PTR_ERR(mod->args);
82100- goto free_arch_cleanup;
82101- }
82102-
82103 dynamic_debug_setup(info->debug, info->num_debug);
82104
82105 /* Finally it's fully formed, ready to start executing. */
82106@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
82107 ddebug_cleanup:
82108 dynamic_debug_remove(info->debug);
82109 synchronize_sched();
82110- kfree(mod->args);
82111- free_arch_cleanup:
82112 module_arch_cleanup(mod);
82113 free_modinfo:
82114 free_modinfo(mod);
82115+ kfree(mod->args);
82116 free_unload:
82117 module_unload_free(mod);
82118 unlink_mod:
82119@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
82120 unsigned long nextval;
82121
82122 /* At worse, next value is at end of module */
82123- if (within_module_init(addr, mod))
82124- nextval = (unsigned long)mod->module_init+mod->init_text_size;
82125+ if (within_module_init_rx(addr, mod))
82126+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
82127+ else if (within_module_init_rw(addr, mod))
82128+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
82129+ else if (within_module_core_rx(addr, mod))
82130+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
82131+ else if (within_module_core_rw(addr, mod))
82132+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
82133 else
82134- nextval = (unsigned long)mod->module_core+mod->core_text_size;
82135+ return NULL;
82136
82137 /* Scan for closest preceding symbol, and next symbol. (ELF
82138 starts real symbols at 1). */
82139@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
82140 return 0;
82141
82142 seq_printf(m, "%s %u",
82143- mod->name, mod->init_size + mod->core_size);
82144+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
82145 print_unload_info(m, mod);
82146
82147 /* Informative for users. */
82148@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
82149 mod->state == MODULE_STATE_COMING ? "Loading":
82150 "Live");
82151 /* Used by oprofile and other similar tools. */
82152- seq_printf(m, " 0x%pK", mod->module_core);
82153+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
82154
82155 /* Taints info */
82156 if (mod->taints)
82157@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
82158
82159 static int __init proc_modules_init(void)
82160 {
82161+#ifndef CONFIG_GRKERNSEC_HIDESYM
82162+#ifdef CONFIG_GRKERNSEC_PROC_USER
82163+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82164+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82165+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
82166+#else
82167 proc_create("modules", 0, NULL, &proc_modules_operations);
82168+#endif
82169+#else
82170+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82171+#endif
82172 return 0;
82173 }
82174 module_init(proc_modules_init);
82175@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
82176 {
82177 struct module *mod;
82178
82179- if (addr < module_addr_min || addr > module_addr_max)
82180+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
82181+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
82182 return NULL;
82183
82184 list_for_each_entry_rcu(mod, &modules, list) {
82185 if (mod->state == MODULE_STATE_UNFORMED)
82186 continue;
82187- if (within_module_core(addr, mod)
82188- || within_module_init(addr, mod))
82189+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82190 return mod;
82191 }
82192 return NULL;
82193@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82194 */
82195 struct module *__module_text_address(unsigned long addr)
82196 {
82197- struct module *mod = __module_address(addr);
82198+ struct module *mod;
82199+
82200+#ifdef CONFIG_X86_32
82201+ addr = ktla_ktva(addr);
82202+#endif
82203+
82204+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82205+ return NULL;
82206+
82207+ mod = __module_address(addr);
82208+
82209 if (mod) {
82210 /* Make sure it's within the text section. */
82211- if (!within(addr, mod->module_init, mod->init_text_size)
82212- && !within(addr, mod->module_core, mod->core_text_size))
82213+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82214 mod = NULL;
82215 }
82216 return mod;
82217diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82218index 7e3443f..b2a1e6b 100644
82219--- a/kernel/mutex-debug.c
82220+++ b/kernel/mutex-debug.c
82221@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82222 }
82223
82224 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82225- struct thread_info *ti)
82226+ struct task_struct *task)
82227 {
82228 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82229
82230 /* Mark the current thread as blocked on the lock: */
82231- ti->task->blocked_on = waiter;
82232+ task->blocked_on = waiter;
82233 }
82234
82235 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82236- struct thread_info *ti)
82237+ struct task_struct *task)
82238 {
82239 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82240- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82241- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82242- ti->task->blocked_on = NULL;
82243+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82244+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82245+ task->blocked_on = NULL;
82246
82247 list_del_init(&waiter->list);
82248 waiter->task = NULL;
82249diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82250index 0799fd3..d06ae3b 100644
82251--- a/kernel/mutex-debug.h
82252+++ b/kernel/mutex-debug.h
82253@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82254 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82255 extern void debug_mutex_add_waiter(struct mutex *lock,
82256 struct mutex_waiter *waiter,
82257- struct thread_info *ti);
82258+ struct task_struct *task);
82259 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82260- struct thread_info *ti);
82261+ struct task_struct *task);
82262 extern void debug_mutex_unlock(struct mutex *lock);
82263 extern void debug_mutex_init(struct mutex *lock, const char *name,
82264 struct lock_class_key *key);
82265diff --git a/kernel/mutex.c b/kernel/mutex.c
82266index a52ee7bb..f361f16 100644
82267--- a/kernel/mutex.c
82268+++ b/kernel/mutex.c
82269@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82270 node->locked = 1;
82271 return;
82272 }
82273- ACCESS_ONCE(prev->next) = node;
82274+ ACCESS_ONCE_RW(prev->next) = node;
82275 smp_wmb();
82276 /* Wait until the lock holder passes the lock down */
82277 while (!ACCESS_ONCE(node->locked))
82278@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82279 while (!(next = ACCESS_ONCE(node->next)))
82280 arch_mutex_cpu_relax();
82281 }
82282- ACCESS_ONCE(next->locked) = 1;
82283+ ACCESS_ONCE_RW(next->locked) = 1;
82284 smp_wmb();
82285 }
82286
82287@@ -514,7 +514,7 @@ slowpath:
82288 spin_lock_mutex(&lock->wait_lock, flags);
82289
82290 debug_mutex_lock_common(lock, &waiter);
82291- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82292+ debug_mutex_add_waiter(lock, &waiter, task);
82293
82294 /* add waiting tasks to the end of the waitqueue (FIFO): */
82295 list_add_tail(&waiter.list, &lock->wait_list);
82296@@ -565,7 +565,7 @@ slowpath:
82297 done:
82298 lock_acquired(&lock->dep_map, ip);
82299 /* got the lock - rejoice! */
82300- mutex_remove_waiter(lock, &waiter, current_thread_info());
82301+ mutex_remove_waiter(lock, &waiter, task);
82302 mutex_set_owner(lock);
82303
82304 if (!__builtin_constant_p(ww_ctx == NULL)) {
82305@@ -604,7 +604,7 @@ done:
82306 return 0;
82307
82308 err:
82309- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82310+ mutex_remove_waiter(lock, &waiter, task);
82311 spin_unlock_mutex(&lock->wait_lock, flags);
82312 debug_mutex_free_waiter(&waiter);
82313 mutex_release(&lock->dep_map, 1, ip);
82314diff --git a/kernel/notifier.c b/kernel/notifier.c
82315index 2d5cc4c..d9ea600 100644
82316--- a/kernel/notifier.c
82317+++ b/kernel/notifier.c
82318@@ -5,6 +5,7 @@
82319 #include <linux/rcupdate.h>
82320 #include <linux/vmalloc.h>
82321 #include <linux/reboot.h>
82322+#include <linux/mm.h>
82323
82324 /*
82325 * Notifier list for kernel code which wants to be called
82326@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82327 while ((*nl) != NULL) {
82328 if (n->priority > (*nl)->priority)
82329 break;
82330- nl = &((*nl)->next);
82331+ nl = (struct notifier_block **)&((*nl)->next);
82332 }
82333- n->next = *nl;
82334+ pax_open_kernel();
82335+ *(const void **)&n->next = *nl;
82336 rcu_assign_pointer(*nl, n);
82337+ pax_close_kernel();
82338 return 0;
82339 }
82340
82341@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82342 return 0;
82343 if (n->priority > (*nl)->priority)
82344 break;
82345- nl = &((*nl)->next);
82346+ nl = (struct notifier_block **)&((*nl)->next);
82347 }
82348- n->next = *nl;
82349+ pax_open_kernel();
82350+ *(const void **)&n->next = *nl;
82351 rcu_assign_pointer(*nl, n);
82352+ pax_close_kernel();
82353 return 0;
82354 }
82355
82356@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82357 {
82358 while ((*nl) != NULL) {
82359 if ((*nl) == n) {
82360+ pax_open_kernel();
82361 rcu_assign_pointer(*nl, n->next);
82362+ pax_close_kernel();
82363 return 0;
82364 }
82365- nl = &((*nl)->next);
82366+ nl = (struct notifier_block **)&((*nl)->next);
82367 }
82368 return -ENOENT;
82369 }
82370diff --git a/kernel/panic.c b/kernel/panic.c
82371index 8018646..b6a5b4f 100644
82372--- a/kernel/panic.c
82373+++ b/kernel/panic.c
82374@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82375 disable_trace_on_warning();
82376
82377 pr_warn("------------[ cut here ]------------\n");
82378- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82379+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82380 raw_smp_processor_id(), current->pid, file, line, caller);
82381
82382 if (args)
82383@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82384 */
82385 void __stack_chk_fail(void)
82386 {
82387- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82388+ dump_stack();
82389+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82390 __builtin_return_address(0));
82391 }
82392 EXPORT_SYMBOL(__stack_chk_fail);
82393diff --git a/kernel/pid.c b/kernel/pid.c
82394index 66505c1..87af12c 100644
82395--- a/kernel/pid.c
82396+++ b/kernel/pid.c
82397@@ -33,6 +33,7 @@
82398 #include <linux/rculist.h>
82399 #include <linux/bootmem.h>
82400 #include <linux/hash.h>
82401+#include <linux/security.h>
82402 #include <linux/pid_namespace.h>
82403 #include <linux/init_task.h>
82404 #include <linux/syscalls.h>
82405@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82406
82407 int pid_max = PID_MAX_DEFAULT;
82408
82409-#define RESERVED_PIDS 300
82410+#define RESERVED_PIDS 500
82411
82412 int pid_max_min = RESERVED_PIDS + 1;
82413 int pid_max_max = PID_MAX_LIMIT;
82414@@ -439,10 +440,18 @@ EXPORT_SYMBOL(pid_task);
82415 */
82416 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82417 {
82418+ struct task_struct *task;
82419+
82420 rcu_lockdep_assert(rcu_read_lock_held(),
82421 "find_task_by_pid_ns() needs rcu_read_lock()"
82422 " protection");
82423- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82424+
82425+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82426+
82427+ if (gr_pid_is_chrooted(task))
82428+ return NULL;
82429+
82430+ return task;
82431 }
82432
82433 struct task_struct *find_task_by_vpid(pid_t vnr)
82434@@ -450,6 +459,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82435 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82436 }
82437
82438+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82439+{
82440+ rcu_lockdep_assert(rcu_read_lock_held(),
82441+ "find_task_by_pid_ns() needs rcu_read_lock()"
82442+ " protection");
82443+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82444+}
82445+
82446 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82447 {
82448 struct pid *pid;
82449diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82450index 601bb36..f7e6f34 100644
82451--- a/kernel/pid_namespace.c
82452+++ b/kernel/pid_namespace.c
82453@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82454 void __user *buffer, size_t *lenp, loff_t *ppos)
82455 {
82456 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82457- struct ctl_table tmp = *table;
82458+ ctl_table_no_const tmp = *table;
82459
82460 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82461 return -EPERM;
82462diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82463index c7f31aa..2b44977 100644
82464--- a/kernel/posix-cpu-timers.c
82465+++ b/kernel/posix-cpu-timers.c
82466@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82467
82468 static __init int init_posix_cpu_timers(void)
82469 {
82470- struct k_clock process = {
82471+ static struct k_clock process = {
82472 .clock_getres = process_cpu_clock_getres,
82473 .clock_get = process_cpu_clock_get,
82474 .timer_create = process_cpu_timer_create,
82475 .nsleep = process_cpu_nsleep,
82476 .nsleep_restart = process_cpu_nsleep_restart,
82477 };
82478- struct k_clock thread = {
82479+ static struct k_clock thread = {
82480 .clock_getres = thread_cpu_clock_getres,
82481 .clock_get = thread_cpu_clock_get,
82482 .timer_create = thread_cpu_timer_create,
82483diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82484index 424c2d4..679242f 100644
82485--- a/kernel/posix-timers.c
82486+++ b/kernel/posix-timers.c
82487@@ -43,6 +43,7 @@
82488 #include <linux/hash.h>
82489 #include <linux/posix-clock.h>
82490 #include <linux/posix-timers.h>
82491+#include <linux/grsecurity.h>
82492 #include <linux/syscalls.h>
82493 #include <linux/wait.h>
82494 #include <linux/workqueue.h>
82495@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82496 * which we beg off on and pass to do_sys_settimeofday().
82497 */
82498
82499-static struct k_clock posix_clocks[MAX_CLOCKS];
82500+static struct k_clock *posix_clocks[MAX_CLOCKS];
82501
82502 /*
82503 * These ones are defined below.
82504@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82505 */
82506 static __init int init_posix_timers(void)
82507 {
82508- struct k_clock clock_realtime = {
82509+ static struct k_clock clock_realtime = {
82510 .clock_getres = hrtimer_get_res,
82511 .clock_get = posix_clock_realtime_get,
82512 .clock_set = posix_clock_realtime_set,
82513@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82514 .timer_get = common_timer_get,
82515 .timer_del = common_timer_del,
82516 };
82517- struct k_clock clock_monotonic = {
82518+ static struct k_clock clock_monotonic = {
82519 .clock_getres = hrtimer_get_res,
82520 .clock_get = posix_ktime_get_ts,
82521 .nsleep = common_nsleep,
82522@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82523 .timer_get = common_timer_get,
82524 .timer_del = common_timer_del,
82525 };
82526- struct k_clock clock_monotonic_raw = {
82527+ static struct k_clock clock_monotonic_raw = {
82528 .clock_getres = hrtimer_get_res,
82529 .clock_get = posix_get_monotonic_raw,
82530 };
82531- struct k_clock clock_realtime_coarse = {
82532+ static struct k_clock clock_realtime_coarse = {
82533 .clock_getres = posix_get_coarse_res,
82534 .clock_get = posix_get_realtime_coarse,
82535 };
82536- struct k_clock clock_monotonic_coarse = {
82537+ static struct k_clock clock_monotonic_coarse = {
82538 .clock_getres = posix_get_coarse_res,
82539 .clock_get = posix_get_monotonic_coarse,
82540 };
82541- struct k_clock clock_tai = {
82542+ static struct k_clock clock_tai = {
82543 .clock_getres = hrtimer_get_res,
82544 .clock_get = posix_get_tai,
82545 .nsleep = common_nsleep,
82546@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82547 .timer_get = common_timer_get,
82548 .timer_del = common_timer_del,
82549 };
82550- struct k_clock clock_boottime = {
82551+ static struct k_clock clock_boottime = {
82552 .clock_getres = hrtimer_get_res,
82553 .clock_get = posix_get_boottime,
82554 .nsleep = common_nsleep,
82555@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82556 return;
82557 }
82558
82559- posix_clocks[clock_id] = *new_clock;
82560+ posix_clocks[clock_id] = new_clock;
82561 }
82562 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82563
82564@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82565 return (id & CLOCKFD_MASK) == CLOCKFD ?
82566 &clock_posix_dynamic : &clock_posix_cpu;
82567
82568- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82569+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82570 return NULL;
82571- return &posix_clocks[id];
82572+ return posix_clocks[id];
82573 }
82574
82575 static int common_timer_create(struct k_itimer *new_timer)
82576@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82577 struct k_clock *kc = clockid_to_kclock(which_clock);
82578 struct k_itimer *new_timer;
82579 int error, new_timer_id;
82580- sigevent_t event;
82581+ sigevent_t event = { };
82582 int it_id_set = IT_ID_NOT_SET;
82583
82584 if (!kc)
82585@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82586 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82587 return -EFAULT;
82588
82589+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82590+ have their clock_set fptr set to a nosettime dummy function
82591+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82592+ call common_clock_set, which calls do_sys_settimeofday, which
82593+ we hook
82594+ */
82595+
82596 return kc->clock_set(which_clock, &new_tp);
82597 }
82598
82599diff --git a/kernel/power/process.c b/kernel/power/process.c
82600index 06ec886..9dba35e 100644
82601--- a/kernel/power/process.c
82602+++ b/kernel/power/process.c
82603@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82604 unsigned int elapsed_msecs;
82605 bool wakeup = false;
82606 int sleep_usecs = USEC_PER_MSEC;
82607+ bool timedout = false;
82608
82609 do_gettimeofday(&start);
82610
82611@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82612
82613 while (true) {
82614 todo = 0;
82615+ if (time_after(jiffies, end_time))
82616+ timedout = true;
82617 read_lock(&tasklist_lock);
82618 do_each_thread(g, p) {
82619 if (p == current || !freeze_task(p))
82620 continue;
82621
82622- if (!freezer_should_skip(p))
82623+ if (!freezer_should_skip(p)) {
82624 todo++;
82625+ if (timedout) {
82626+ printk(KERN_ERR "Task refusing to freeze:\n");
82627+ sched_show_task(p);
82628+ }
82629+ }
82630 } while_each_thread(g, p);
82631 read_unlock(&tasklist_lock);
82632
82633@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82634 todo += wq_busy;
82635 }
82636
82637- if (!todo || time_after(jiffies, end_time))
82638+ if (!todo || timedout)
82639 break;
82640
82641 if (pm_wakeup_pending()) {
82642diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82643index 5b5a708..ec7637e 100644
82644--- a/kernel/printk/printk.c
82645+++ b/kernel/printk/printk.c
82646@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82647 if (from_file && type != SYSLOG_ACTION_OPEN)
82648 return 0;
82649
82650+#ifdef CONFIG_GRKERNSEC_DMESG
82651+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82652+ return -EPERM;
82653+#endif
82654+
82655 if (syslog_action_restricted(type)) {
82656 if (capable(CAP_SYSLOG))
82657 return 0;
82658diff --git a/kernel/profile.c b/kernel/profile.c
82659index 6631e1e..310c266 100644
82660--- a/kernel/profile.c
82661+++ b/kernel/profile.c
82662@@ -37,7 +37,7 @@ struct profile_hit {
82663 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82664 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82665
82666-static atomic_t *prof_buffer;
82667+static atomic_unchecked_t *prof_buffer;
82668 static unsigned long prof_len, prof_shift;
82669
82670 int prof_on __read_mostly;
82671@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82672 hits[i].pc = 0;
82673 continue;
82674 }
82675- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82676+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82677 hits[i].hits = hits[i].pc = 0;
82678 }
82679 }
82680@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82681 * Add the current hit(s) and flush the write-queue out
82682 * to the global buffer:
82683 */
82684- atomic_add(nr_hits, &prof_buffer[pc]);
82685+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82686 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82687- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82688+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82689 hits[i].pc = hits[i].hits = 0;
82690 }
82691 out:
82692@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82693 {
82694 unsigned long pc;
82695 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82696- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82697+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82698 }
82699 #endif /* !CONFIG_SMP */
82700
82701@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82702 return -EFAULT;
82703 buf++; p++; count--; read++;
82704 }
82705- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82706+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82707 if (copy_to_user(buf, (void *)pnt, count))
82708 return -EFAULT;
82709 read += count;
82710@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82711 }
82712 #endif
82713 profile_discard_flip_buffers();
82714- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82715+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82716 return count;
82717 }
82718
82719diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82720index a146ee3..ffed4c3 100644
82721--- a/kernel/ptrace.c
82722+++ b/kernel/ptrace.c
82723@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82724 if (seize)
82725 flags |= PT_SEIZED;
82726 rcu_read_lock();
82727- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82728+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82729 flags |= PT_PTRACE_CAP;
82730 rcu_read_unlock();
82731 task->ptrace = flags;
82732@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82733 break;
82734 return -EIO;
82735 }
82736- if (copy_to_user(dst, buf, retval))
82737+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82738 return -EFAULT;
82739 copied += retval;
82740 src += retval;
82741@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82742 bool seized = child->ptrace & PT_SEIZED;
82743 int ret = -EIO;
82744 siginfo_t siginfo, *si;
82745- void __user *datavp = (void __user *) data;
82746+ void __user *datavp = (__force void __user *) data;
82747 unsigned long __user *datalp = datavp;
82748 unsigned long flags;
82749
82750@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82751 goto out;
82752 }
82753
82754+ if (gr_handle_ptrace(child, request)) {
82755+ ret = -EPERM;
82756+ goto out_put_task_struct;
82757+ }
82758+
82759 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82760 ret = ptrace_attach(child, request, addr, data);
82761 /*
82762 * Some architectures need to do book-keeping after
82763 * a ptrace attach.
82764 */
82765- if (!ret)
82766+ if (!ret) {
82767 arch_ptrace_attach(child);
82768+ gr_audit_ptrace(child);
82769+ }
82770 goto out_put_task_struct;
82771 }
82772
82773@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82774 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82775 if (copied != sizeof(tmp))
82776 return -EIO;
82777- return put_user(tmp, (unsigned long __user *)data);
82778+ return put_user(tmp, (__force unsigned long __user *)data);
82779 }
82780
82781 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82782@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82783 }
82784
82785 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82786- compat_long_t addr, compat_long_t data)
82787+ compat_ulong_t addr, compat_ulong_t data)
82788 {
82789 struct task_struct *child;
82790 long ret;
82791@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82792 goto out;
82793 }
82794
82795+ if (gr_handle_ptrace(child, request)) {
82796+ ret = -EPERM;
82797+ goto out_put_task_struct;
82798+ }
82799+
82800 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82801 ret = ptrace_attach(child, request, addr, data);
82802 /*
82803 * Some architectures need to do book-keeping after
82804 * a ptrace attach.
82805 */
82806- if (!ret)
82807+ if (!ret) {
82808 arch_ptrace_attach(child);
82809+ gr_audit_ptrace(child);
82810+ }
82811 goto out_put_task_struct;
82812 }
82813
82814diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82815index cce6ba8..7c758b1f 100644
82816--- a/kernel/rcupdate.c
82817+++ b/kernel/rcupdate.c
82818@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82819 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82820 */
82821 if (till_stall_check < 3) {
82822- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82823+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82824 till_stall_check = 3;
82825 } else if (till_stall_check > 300) {
82826- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82827+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82828 till_stall_check = 300;
82829 }
82830 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82831diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82832index aa34411..4832cd4 100644
82833--- a/kernel/rcutiny.c
82834+++ b/kernel/rcutiny.c
82835@@ -45,7 +45,7 @@
82836 /* Forward declarations for rcutiny_plugin.h. */
82837 struct rcu_ctrlblk;
82838 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82839-static void rcu_process_callbacks(struct softirq_action *unused);
82840+static void rcu_process_callbacks(void);
82841 static void __call_rcu(struct rcu_head *head,
82842 void (*func)(struct rcu_head *rcu),
82843 struct rcu_ctrlblk *rcp);
82844@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82845 false));
82846 }
82847
82848-static void rcu_process_callbacks(struct softirq_action *unused)
82849+static __latent_entropy void rcu_process_callbacks(void)
82850 {
82851 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82852 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82853diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82854index f4871e5..8ef5741 100644
82855--- a/kernel/rcutorture.c
82856+++ b/kernel/rcutorture.c
82857@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82858 { 0 };
82859 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82860 { 0 };
82861-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82862-static atomic_t n_rcu_torture_alloc;
82863-static atomic_t n_rcu_torture_alloc_fail;
82864-static atomic_t n_rcu_torture_free;
82865-static atomic_t n_rcu_torture_mberror;
82866-static atomic_t n_rcu_torture_error;
82867+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82868+static atomic_unchecked_t n_rcu_torture_alloc;
82869+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82870+static atomic_unchecked_t n_rcu_torture_free;
82871+static atomic_unchecked_t n_rcu_torture_mberror;
82872+static atomic_unchecked_t n_rcu_torture_error;
82873 static long n_rcu_torture_barrier_error;
82874 static long n_rcu_torture_boost_ktrerror;
82875 static long n_rcu_torture_boost_rterror;
82876@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82877
82878 spin_lock_bh(&rcu_torture_lock);
82879 if (list_empty(&rcu_torture_freelist)) {
82880- atomic_inc(&n_rcu_torture_alloc_fail);
82881+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82882 spin_unlock_bh(&rcu_torture_lock);
82883 return NULL;
82884 }
82885- atomic_inc(&n_rcu_torture_alloc);
82886+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82887 p = rcu_torture_freelist.next;
82888 list_del_init(p);
82889 spin_unlock_bh(&rcu_torture_lock);
82890@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82891 static void
82892 rcu_torture_free(struct rcu_torture *p)
82893 {
82894- atomic_inc(&n_rcu_torture_free);
82895+ atomic_inc_unchecked(&n_rcu_torture_free);
82896 spin_lock_bh(&rcu_torture_lock);
82897 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82898 spin_unlock_bh(&rcu_torture_lock);
82899@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82900 i = rp->rtort_pipe_count;
82901 if (i > RCU_TORTURE_PIPE_LEN)
82902 i = RCU_TORTURE_PIPE_LEN;
82903- atomic_inc(&rcu_torture_wcount[i]);
82904+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82905 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82906 rp->rtort_mbtest = 0;
82907 rcu_torture_free(rp);
82908@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82909 i = rp->rtort_pipe_count;
82910 if (i > RCU_TORTURE_PIPE_LEN)
82911 i = RCU_TORTURE_PIPE_LEN;
82912- atomic_inc(&rcu_torture_wcount[i]);
82913+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82914 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82915 rp->rtort_mbtest = 0;
82916 list_del(&rp->rtort_free);
82917@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82918 i = old_rp->rtort_pipe_count;
82919 if (i > RCU_TORTURE_PIPE_LEN)
82920 i = RCU_TORTURE_PIPE_LEN;
82921- atomic_inc(&rcu_torture_wcount[i]);
82922+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82923 old_rp->rtort_pipe_count++;
82924 cur_ops->deferred_free(old_rp);
82925 }
82926@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82927 return;
82928 }
82929 if (p->rtort_mbtest == 0)
82930- atomic_inc(&n_rcu_torture_mberror);
82931+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82932 spin_lock(&rand_lock);
82933 cur_ops->read_delay(&rand);
82934 n_rcu_torture_timers++;
82935@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82936 continue;
82937 }
82938 if (p->rtort_mbtest == 0)
82939- atomic_inc(&n_rcu_torture_mberror);
82940+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82941 cur_ops->read_delay(&rand);
82942 preempt_disable();
82943 pipe_count = p->rtort_pipe_count;
82944@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82945 rcu_torture_current,
82946 rcu_torture_current_version,
82947 list_empty(&rcu_torture_freelist),
82948- atomic_read(&n_rcu_torture_alloc),
82949- atomic_read(&n_rcu_torture_alloc_fail),
82950- atomic_read(&n_rcu_torture_free));
82951+ atomic_read_unchecked(&n_rcu_torture_alloc),
82952+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82953+ atomic_read_unchecked(&n_rcu_torture_free));
82954 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82955- atomic_read(&n_rcu_torture_mberror),
82956+ atomic_read_unchecked(&n_rcu_torture_mberror),
82957 n_rcu_torture_boost_ktrerror,
82958 n_rcu_torture_boost_rterror);
82959 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82960@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82961 n_barrier_attempts,
82962 n_rcu_torture_barrier_error);
82963 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82964- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82965+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82966 n_rcu_torture_barrier_error != 0 ||
82967 n_rcu_torture_boost_ktrerror != 0 ||
82968 n_rcu_torture_boost_rterror != 0 ||
82969 n_rcu_torture_boost_failure != 0 ||
82970 i > 1) {
82971 cnt += sprintf(&page[cnt], "!!! ");
82972- atomic_inc(&n_rcu_torture_error);
82973+ atomic_inc_unchecked(&n_rcu_torture_error);
82974 WARN_ON_ONCE(1);
82975 }
82976 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82977@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82978 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82979 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82980 cnt += sprintf(&page[cnt], " %d",
82981- atomic_read(&rcu_torture_wcount[i]));
82982+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82983 }
82984 cnt += sprintf(&page[cnt], "\n");
82985 if (cur_ops->stats)
82986@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82987
82988 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82989
82990- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82991+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82992 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82993 else if (n_online_successes != n_online_attempts ||
82994 n_offline_successes != n_offline_attempts)
82995@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82996
82997 rcu_torture_current = NULL;
82998 rcu_torture_current_version = 0;
82999- atomic_set(&n_rcu_torture_alloc, 0);
83000- atomic_set(&n_rcu_torture_alloc_fail, 0);
83001- atomic_set(&n_rcu_torture_free, 0);
83002- atomic_set(&n_rcu_torture_mberror, 0);
83003- atomic_set(&n_rcu_torture_error, 0);
83004+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
83005+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
83006+ atomic_set_unchecked(&n_rcu_torture_free, 0);
83007+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
83008+ atomic_set_unchecked(&n_rcu_torture_error, 0);
83009 n_rcu_torture_barrier_error = 0;
83010 n_rcu_torture_boost_ktrerror = 0;
83011 n_rcu_torture_boost_rterror = 0;
83012 n_rcu_torture_boost_failure = 0;
83013 n_rcu_torture_boosts = 0;
83014 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
83015- atomic_set(&rcu_torture_wcount[i], 0);
83016+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
83017 for_each_possible_cpu(cpu) {
83018 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
83019 per_cpu(rcu_torture_count, cpu)[i] = 0;
83020diff --git a/kernel/rcutree.c b/kernel/rcutree.c
83021index 068de3a..5e7db2f 100644
83022--- a/kernel/rcutree.c
83023+++ b/kernel/rcutree.c
83024@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
83025 rcu_prepare_for_idle(smp_processor_id());
83026 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83027 smp_mb__before_atomic_inc(); /* See above. */
83028- atomic_inc(&rdtp->dynticks);
83029+ atomic_inc_unchecked(&rdtp->dynticks);
83030 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
83031- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83032+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83033
83034 /*
83035 * It is illegal to enter an extended quiescent state while
83036@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
83037 int user)
83038 {
83039 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
83040- atomic_inc(&rdtp->dynticks);
83041+ atomic_inc_unchecked(&rdtp->dynticks);
83042 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83043 smp_mb__after_atomic_inc(); /* See above. */
83044- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83045+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83046 rcu_cleanup_after_idle(smp_processor_id());
83047 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
83048 if (!user && !is_idle_task(current)) {
83049@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
83050 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
83051
83052 if (rdtp->dynticks_nmi_nesting == 0 &&
83053- (atomic_read(&rdtp->dynticks) & 0x1))
83054+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
83055 return;
83056 rdtp->dynticks_nmi_nesting++;
83057 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
83058- atomic_inc(&rdtp->dynticks);
83059+ atomic_inc_unchecked(&rdtp->dynticks);
83060 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83061 smp_mb__after_atomic_inc(); /* See above. */
83062- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83063+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83064 }
83065
83066 /**
83067@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
83068 return;
83069 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83070 smp_mb__before_atomic_inc(); /* See above. */
83071- atomic_inc(&rdtp->dynticks);
83072+ atomic_inc_unchecked(&rdtp->dynticks);
83073 smp_mb__after_atomic_inc(); /* Force delay to next write. */
83074- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83075+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83076 }
83077
83078 /**
83079@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
83080 int ret;
83081
83082 preempt_disable();
83083- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
83084+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
83085 preempt_enable();
83086 return ret;
83087 }
83088@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
83089 */
83090 static int dyntick_save_progress_counter(struct rcu_data *rdp)
83091 {
83092- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
83093+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
83094 return (rdp->dynticks_snap & 0x1) == 0;
83095 }
83096
83097@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
83098 unsigned int curr;
83099 unsigned int snap;
83100
83101- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
83102+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
83103 snap = (unsigned int)rdp->dynticks_snap;
83104
83105 /*
83106@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
83107 rdp = this_cpu_ptr(rsp->rda);
83108 rcu_preempt_check_blocked_tasks(rnp);
83109 rnp->qsmask = rnp->qsmaskinit;
83110- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
83111+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
83112 WARN_ON_ONCE(rnp->completed != rsp->completed);
83113- ACCESS_ONCE(rnp->completed) = rsp->completed;
83114+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
83115 if (rnp == rdp->mynode)
83116 __note_gp_changes(rsp, rnp, rdp);
83117 rcu_preempt_boost_start_gp(rnp);
83118@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
83119 */
83120 rcu_for_each_node_breadth_first(rsp, rnp) {
83121 raw_spin_lock_irq(&rnp->lock);
83122- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
83123+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
83124 rdp = this_cpu_ptr(rsp->rda);
83125 if (rnp == rdp->mynode)
83126 __note_gp_changes(rsp, rnp, rdp);
83127@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
83128 rsp->qlen += rdp->qlen;
83129 rdp->n_cbs_orphaned += rdp->qlen;
83130 rdp->qlen_lazy = 0;
83131- ACCESS_ONCE(rdp->qlen) = 0;
83132+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83133 }
83134
83135 /*
83136@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
83137 }
83138 smp_mb(); /* List handling before counting for rcu_barrier(). */
83139 rdp->qlen_lazy -= count_lazy;
83140- ACCESS_ONCE(rdp->qlen) -= count;
83141+ ACCESS_ONCE_RW(rdp->qlen) -= count;
83142 rdp->n_cbs_invoked += count;
83143
83144 /* Reinstate batch limit if we have worked down the excess. */
83145@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
83146 /*
83147 * Do RCU core processing for the current CPU.
83148 */
83149-static void rcu_process_callbacks(struct softirq_action *unused)
83150+static __latent_entropy void rcu_process_callbacks(void)
83151 {
83152 struct rcu_state *rsp;
83153
83154@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
83155 local_irq_restore(flags);
83156 return;
83157 }
83158- ACCESS_ONCE(rdp->qlen)++;
83159+ ACCESS_ONCE_RW(rdp->qlen)++;
83160 if (lazy)
83161 rdp->qlen_lazy++;
83162 else
83163@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
83164 * counter wrap on a 32-bit system. Quite a few more CPUs would of
83165 * course be required on a 64-bit system.
83166 */
83167- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
83168+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
83169 (ulong)atomic_long_read(&rsp->expedited_done) +
83170 ULONG_MAX / 8)) {
83171 synchronize_sched();
83172- atomic_long_inc(&rsp->expedited_wrap);
83173+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
83174 return;
83175 }
83176
83177@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
83178 * Take a ticket. Note that atomic_inc_return() implies a
83179 * full memory barrier.
83180 */
83181- snap = atomic_long_inc_return(&rsp->expedited_start);
83182+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
83183 firstsnap = snap;
83184 get_online_cpus();
83185 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
83186@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83187 synchronize_sched_expedited_cpu_stop,
83188 NULL) == -EAGAIN) {
83189 put_online_cpus();
83190- atomic_long_inc(&rsp->expedited_tryfail);
83191+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83192
83193 /* Check to see if someone else did our work for us. */
83194 s = atomic_long_read(&rsp->expedited_done);
83195 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83196 /* ensure test happens before caller kfree */
83197 smp_mb__before_atomic_inc(); /* ^^^ */
83198- atomic_long_inc(&rsp->expedited_workdone1);
83199+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83200 return;
83201 }
83202
83203@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83204 udelay(trycount * num_online_cpus());
83205 } else {
83206 wait_rcu_gp(call_rcu_sched);
83207- atomic_long_inc(&rsp->expedited_normal);
83208+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83209 return;
83210 }
83211
83212@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83213 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83214 /* ensure test happens before caller kfree */
83215 smp_mb__before_atomic_inc(); /* ^^^ */
83216- atomic_long_inc(&rsp->expedited_workdone2);
83217+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83218 return;
83219 }
83220
83221@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83222 * period works for us.
83223 */
83224 get_online_cpus();
83225- snap = atomic_long_read(&rsp->expedited_start);
83226+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83227 smp_mb(); /* ensure read is before try_stop_cpus(). */
83228 }
83229- atomic_long_inc(&rsp->expedited_stoppedcpus);
83230+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83231
83232 /*
83233 * Everyone up to our most recent fetch is covered by our grace
83234@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83235 * than we did already did their update.
83236 */
83237 do {
83238- atomic_long_inc(&rsp->expedited_done_tries);
83239+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83240 s = atomic_long_read(&rsp->expedited_done);
83241 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83242 /* ensure test happens before caller kfree */
83243 smp_mb__before_atomic_inc(); /* ^^^ */
83244- atomic_long_inc(&rsp->expedited_done_lost);
83245+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83246 break;
83247 }
83248 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83249- atomic_long_inc(&rsp->expedited_done_exit);
83250+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83251
83252 put_online_cpus();
83253 }
83254@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83255 * ACCESS_ONCE() to prevent the compiler from speculating
83256 * the increment to precede the early-exit check.
83257 */
83258- ACCESS_ONCE(rsp->n_barrier_done)++;
83259+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83260 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83261 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83262 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83263@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83264
83265 /* Increment ->n_barrier_done to prevent duplicate work. */
83266 smp_mb(); /* Keep increment after above mechanism. */
83267- ACCESS_ONCE(rsp->n_barrier_done)++;
83268+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83269 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83270 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83271 smp_mb(); /* Keep increment before caller's subsequent code. */
83272@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83273 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83274 init_callback_list(rdp);
83275 rdp->qlen_lazy = 0;
83276- ACCESS_ONCE(rdp->qlen) = 0;
83277+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83278 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83279 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83280- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83281+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83282 rdp->cpu = cpu;
83283 rdp->rsp = rsp;
83284 rcu_boot_init_nocb_percpu_data(rdp);
83285@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83286 rdp->blimit = blimit;
83287 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83288 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83289- atomic_set(&rdp->dynticks->dynticks,
83290- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83291+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83292+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83293 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83294
83295 /* Add CPU to rcu_node bitmasks. */
83296diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83297index b383258..2440c1e 100644
83298--- a/kernel/rcutree.h
83299+++ b/kernel/rcutree.h
83300@@ -87,7 +87,7 @@ struct rcu_dynticks {
83301 long long dynticks_nesting; /* Track irq/process nesting level. */
83302 /* Process level is worth LLONG_MAX/2. */
83303 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83304- atomic_t dynticks; /* Even value for idle, else odd. */
83305+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83306 #ifdef CONFIG_RCU_FAST_NO_HZ
83307 bool all_lazy; /* Are all CPU's CBs lazy? */
83308 unsigned long nonlazy_posted;
83309@@ -419,17 +419,17 @@ struct rcu_state {
83310 /* _rcu_barrier(). */
83311 /* End of fields guarded by barrier_mutex. */
83312
83313- atomic_long_t expedited_start; /* Starting ticket. */
83314- atomic_long_t expedited_done; /* Done ticket. */
83315- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83316- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83317- atomic_long_t expedited_workdone1; /* # done by others #1. */
83318- atomic_long_t expedited_workdone2; /* # done by others #2. */
83319- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83320- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83321- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83322- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83323- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83324+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83325+ atomic_long_t expedited_done; /* Done ticket. */
83326+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83327+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83328+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83329+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83330+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83331+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83332+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83333+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83334+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83335
83336 unsigned long jiffies_force_qs; /* Time at which to invoke */
83337 /* force_quiescent_state(). */
83338diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83339index 769e12e..7b2139b 100644
83340--- a/kernel/rcutree_plugin.h
83341+++ b/kernel/rcutree_plugin.h
83342@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83343
83344 /* Clean up and exit. */
83345 smp_mb(); /* ensure expedited GP seen before counter increment. */
83346- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83347+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83348 unlock_mb_ret:
83349 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83350 mb_ret:
83351@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83352 free_cpumask_var(cm);
83353 }
83354
83355-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83356+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83357 .store = &rcu_cpu_kthread_task,
83358 .thread_should_run = rcu_cpu_kthread_should_run,
83359 .thread_fn = rcu_cpu_kthread,
83360@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83361 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83362 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83363 cpu, ticks_value, ticks_title,
83364- atomic_read(&rdtp->dynticks) & 0xfff,
83365+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83366 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83367 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83368 fast_no_hz);
83369@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83370
83371 /* Enqueue the callback on the nocb list and update counts. */
83372 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83373- ACCESS_ONCE(*old_rhpp) = rhp;
83374+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83375 atomic_long_add(rhcount, &rdp->nocb_q_count);
83376 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83377
83378@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83379 * Extract queued callbacks, update counts, and wait
83380 * for a grace period to elapse.
83381 */
83382- ACCESS_ONCE(rdp->nocb_head) = NULL;
83383+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83384 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83385 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83386 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83387- ACCESS_ONCE(rdp->nocb_p_count) += c;
83388- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83389+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83390+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83391 rcu_nocb_wait_gp(rdp);
83392
83393 /* Each pass through the following loop invokes a callback. */
83394@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83395 list = next;
83396 }
83397 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83398- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83399- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83400+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83401+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83402 rdp->n_nocbs_invoked += c;
83403 }
83404 return 0;
83405@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83406 t = kthread_run(rcu_nocb_kthread, rdp,
83407 "rcuo%c/%d", rsp->abbr, cpu);
83408 BUG_ON(IS_ERR(t));
83409- ACCESS_ONCE(rdp->nocb_kthread) = t;
83410+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83411 }
83412 }
83413
83414diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83415index cf6c174..a8f4b50 100644
83416--- a/kernel/rcutree_trace.c
83417+++ b/kernel/rcutree_trace.c
83418@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83419 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83420 rdp->passed_quiesce, rdp->qs_pending);
83421 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83422- atomic_read(&rdp->dynticks->dynticks),
83423+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83424 rdp->dynticks->dynticks_nesting,
83425 rdp->dynticks->dynticks_nmi_nesting,
83426 rdp->dynticks_fqs);
83427@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83428 struct rcu_state *rsp = (struct rcu_state *)m->private;
83429
83430 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",
83431- atomic_long_read(&rsp->expedited_start),
83432+ atomic_long_read_unchecked(&rsp->expedited_start),
83433 atomic_long_read(&rsp->expedited_done),
83434- atomic_long_read(&rsp->expedited_wrap),
83435- atomic_long_read(&rsp->expedited_tryfail),
83436- atomic_long_read(&rsp->expedited_workdone1),
83437- atomic_long_read(&rsp->expedited_workdone2),
83438- atomic_long_read(&rsp->expedited_normal),
83439- atomic_long_read(&rsp->expedited_stoppedcpus),
83440- atomic_long_read(&rsp->expedited_done_tries),
83441- atomic_long_read(&rsp->expedited_done_lost),
83442- atomic_long_read(&rsp->expedited_done_exit));
83443+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83444+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83445+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83446+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83447+ atomic_long_read_unchecked(&rsp->expedited_normal),
83448+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83449+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83450+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83451+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83452 return 0;
83453 }
83454
83455diff --git a/kernel/resource.c b/kernel/resource.c
83456index 3f285dc..5755f62 100644
83457--- a/kernel/resource.c
83458+++ b/kernel/resource.c
83459@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83460
83461 static int __init ioresources_init(void)
83462 {
83463+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83464+#ifdef CONFIG_GRKERNSEC_PROC_USER
83465+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83466+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83467+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83468+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83469+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83470+#endif
83471+#else
83472 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83473 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83474+#endif
83475 return 0;
83476 }
83477 __initcall(ioresources_init);
83478diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83479index 1d96dd0..994ff19 100644
83480--- a/kernel/rtmutex-tester.c
83481+++ b/kernel/rtmutex-tester.c
83482@@ -22,7 +22,7 @@
83483 #define MAX_RT_TEST_MUTEXES 8
83484
83485 static spinlock_t rttest_lock;
83486-static atomic_t rttest_event;
83487+static atomic_unchecked_t rttest_event;
83488
83489 struct test_thread_data {
83490 int opcode;
83491@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83492
83493 case RTTEST_LOCKCONT:
83494 td->mutexes[td->opdata] = 1;
83495- td->event = atomic_add_return(1, &rttest_event);
83496+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83497 return 0;
83498
83499 case RTTEST_RESET:
83500@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83501 return 0;
83502
83503 case RTTEST_RESETEVENT:
83504- atomic_set(&rttest_event, 0);
83505+ atomic_set_unchecked(&rttest_event, 0);
83506 return 0;
83507
83508 default:
83509@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83510 return ret;
83511
83512 td->mutexes[id] = 1;
83513- td->event = atomic_add_return(1, &rttest_event);
83514+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83515 rt_mutex_lock(&mutexes[id]);
83516- td->event = atomic_add_return(1, &rttest_event);
83517+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83518 td->mutexes[id] = 4;
83519 return 0;
83520
83521@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83522 return ret;
83523
83524 td->mutexes[id] = 1;
83525- td->event = atomic_add_return(1, &rttest_event);
83526+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83527 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83528- td->event = atomic_add_return(1, &rttest_event);
83529+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83530 td->mutexes[id] = ret ? 0 : 4;
83531 return ret ? -EINTR : 0;
83532
83533@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83534 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83535 return ret;
83536
83537- td->event = atomic_add_return(1, &rttest_event);
83538+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83539 rt_mutex_unlock(&mutexes[id]);
83540- td->event = atomic_add_return(1, &rttest_event);
83541+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83542 td->mutexes[id] = 0;
83543 return 0;
83544
83545@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83546 break;
83547
83548 td->mutexes[dat] = 2;
83549- td->event = atomic_add_return(1, &rttest_event);
83550+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83551 break;
83552
83553 default:
83554@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83555 return;
83556
83557 td->mutexes[dat] = 3;
83558- td->event = atomic_add_return(1, &rttest_event);
83559+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83560 break;
83561
83562 case RTTEST_LOCKNOWAIT:
83563@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83564 return;
83565
83566 td->mutexes[dat] = 1;
83567- td->event = atomic_add_return(1, &rttest_event);
83568+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83569 return;
83570
83571 default:
83572diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83573index 4a07353..66b5291 100644
83574--- a/kernel/sched/auto_group.c
83575+++ b/kernel/sched/auto_group.c
83576@@ -11,7 +11,7 @@
83577
83578 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83579 static struct autogroup autogroup_default;
83580-static atomic_t autogroup_seq_nr;
83581+static atomic_unchecked_t autogroup_seq_nr;
83582
83583 void __init autogroup_init(struct task_struct *init_task)
83584 {
83585@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83586
83587 kref_init(&ag->kref);
83588 init_rwsem(&ag->lock);
83589- ag->id = atomic_inc_return(&autogroup_seq_nr);
83590+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83591 ag->tg = tg;
83592 #ifdef CONFIG_RT_GROUP_SCHED
83593 /*
83594diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83595index 05c39f0..442e6fe 100644
83596--- a/kernel/sched/core.c
83597+++ b/kernel/sched/core.c
83598@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83599 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83600 * or number of jiffies left till timeout) if completed.
83601 */
83602-long __sched
83603+long __sched __intentional_overflow(-1)
83604 wait_for_completion_interruptible_timeout(struct completion *x,
83605 unsigned long timeout)
83606 {
83607@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83608 *
83609 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83610 */
83611-int __sched wait_for_completion_killable(struct completion *x)
83612+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83613 {
83614 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83615 if (t == -ERESTARTSYS)
83616@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83617 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83618 * or number of jiffies left till timeout) if completed.
83619 */
83620-long __sched
83621+long __sched __intentional_overflow(-1)
83622 wait_for_completion_killable_timeout(struct completion *x,
83623 unsigned long timeout)
83624 {
83625@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83626 /* convert nice value [19,-20] to rlimit style value [1,40] */
83627 int nice_rlim = 20 - nice;
83628
83629+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83630+
83631 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83632 capable(CAP_SYS_NICE));
83633 }
83634@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83635 if (nice > 19)
83636 nice = 19;
83637
83638- if (increment < 0 && !can_nice(current, nice))
83639+ if (increment < 0 && (!can_nice(current, nice) ||
83640+ gr_handle_chroot_nice()))
83641 return -EPERM;
83642
83643 retval = security_task_setnice(current, nice);
83644@@ -3344,6 +3347,7 @@ recheck:
83645 unsigned long rlim_rtprio =
83646 task_rlimit(p, RLIMIT_RTPRIO);
83647
83648+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83649 /* can't set/change the rt policy */
83650 if (policy != p->policy && !rlim_rtprio)
83651 return -EPERM;
83652@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83653
83654 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83655
83656-static struct ctl_table sd_ctl_dir[] = {
83657+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83658 {
83659 .procname = "sched_domain",
83660 .mode = 0555,
83661@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83662 {}
83663 };
83664
83665-static struct ctl_table *sd_alloc_ctl_entry(int n)
83666+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83667 {
83668- struct ctl_table *entry =
83669+ ctl_table_no_const *entry =
83670 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83671
83672 return entry;
83673 }
83674
83675-static void sd_free_ctl_entry(struct ctl_table **tablep)
83676+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83677 {
83678- struct ctl_table *entry;
83679+ ctl_table_no_const *entry;
83680
83681 /*
83682 * In the intermediate directories, both the child directory and
83683@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83684 * will always be set. In the lowest directory the names are
83685 * static strings and all have proc handlers.
83686 */
83687- for (entry = *tablep; entry->mode; entry++) {
83688- if (entry->child)
83689- sd_free_ctl_entry(&entry->child);
83690+ for (entry = tablep; entry->mode; entry++) {
83691+ if (entry->child) {
83692+ sd_free_ctl_entry(entry->child);
83693+ pax_open_kernel();
83694+ entry->child = NULL;
83695+ pax_close_kernel();
83696+ }
83697 if (entry->proc_handler == NULL)
83698 kfree(entry->procname);
83699 }
83700
83701- kfree(*tablep);
83702- *tablep = NULL;
83703+ kfree(tablep);
83704 }
83705
83706 static int min_load_idx = 0;
83707 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83708
83709 static void
83710-set_table_entry(struct ctl_table *entry,
83711+set_table_entry(ctl_table_no_const *entry,
83712 const char *procname, void *data, int maxlen,
83713 umode_t mode, proc_handler *proc_handler,
83714 bool load_idx)
83715@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83716 static struct ctl_table *
83717 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83718 {
83719- struct ctl_table *table = sd_alloc_ctl_entry(13);
83720+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83721
83722 if (table == NULL)
83723 return NULL;
83724@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83725 return table;
83726 }
83727
83728-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83729+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83730 {
83731- struct ctl_table *entry, *table;
83732+ ctl_table_no_const *entry, *table;
83733 struct sched_domain *sd;
83734 int domain_num = 0, i;
83735 char buf[32];
83736@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83737 static void register_sched_domain_sysctl(void)
83738 {
83739 int i, cpu_num = num_possible_cpus();
83740- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83741+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83742 char buf[32];
83743
83744 WARN_ON(sd_ctl_dir[0].child);
83745+ pax_open_kernel();
83746 sd_ctl_dir[0].child = entry;
83747+ pax_close_kernel();
83748
83749 if (entry == NULL)
83750 return;
83751@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83752 if (sd_sysctl_header)
83753 unregister_sysctl_table(sd_sysctl_header);
83754 sd_sysctl_header = NULL;
83755- if (sd_ctl_dir[0].child)
83756- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83757+ if (sd_ctl_dir[0].child) {
83758+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83759+ pax_open_kernel();
83760+ sd_ctl_dir[0].child = NULL;
83761+ pax_close_kernel();
83762+ }
83763 }
83764 #else
83765 static void register_sched_domain_sysctl(void)
83766diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83767index 68f1609..2a9fe8a 100644
83768--- a/kernel/sched/fair.c
83769+++ b/kernel/sched/fair.c
83770@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83771
83772 static void reset_ptenuma_scan(struct task_struct *p)
83773 {
83774- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83775+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83776 p->mm->numa_scan_offset = 0;
83777 }
83778
83779@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83780 * run_rebalance_domains is triggered when needed from the scheduler tick.
83781 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83782 */
83783-static void run_rebalance_domains(struct softirq_action *h)
83784+static __latent_entropy void run_rebalance_domains(void)
83785 {
83786 int this_cpu = smp_processor_id();
83787 struct rq *this_rq = cpu_rq(this_cpu);
83788diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83789index ef0a7b2..1b728c1 100644
83790--- a/kernel/sched/sched.h
83791+++ b/kernel/sched/sched.h
83792@@ -1004,7 +1004,7 @@ struct sched_class {
83793 #ifdef CONFIG_FAIR_GROUP_SCHED
83794 void (*task_move_group) (struct task_struct *p, int on_rq);
83795 #endif
83796-};
83797+} __do_const;
83798
83799 #define sched_class_highest (&stop_sched_class)
83800 #define for_each_class(class) \
83801diff --git a/kernel/signal.c b/kernel/signal.c
83802index 50e4107..08bcb94 100644
83803--- a/kernel/signal.c
83804+++ b/kernel/signal.c
83805@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83806
83807 int print_fatal_signals __read_mostly;
83808
83809-static void __user *sig_handler(struct task_struct *t, int sig)
83810+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83811 {
83812 return t->sighand->action[sig - 1].sa.sa_handler;
83813 }
83814
83815-static int sig_handler_ignored(void __user *handler, int sig)
83816+static int sig_handler_ignored(__sighandler_t handler, int sig)
83817 {
83818 /* Is it explicitly or implicitly ignored? */
83819 return handler == SIG_IGN ||
83820@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83821
83822 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83823 {
83824- void __user *handler;
83825+ __sighandler_t handler;
83826
83827 handler = sig_handler(t, sig);
83828
83829@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83830 atomic_inc(&user->sigpending);
83831 rcu_read_unlock();
83832
83833+ if (!override_rlimit)
83834+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83835+
83836 if (override_rlimit ||
83837 atomic_read(&user->sigpending) <=
83838 task_rlimit(t, RLIMIT_SIGPENDING)) {
83839@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83840
83841 int unhandled_signal(struct task_struct *tsk, int sig)
83842 {
83843- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83844+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83845 if (is_global_init(tsk))
83846 return 1;
83847 if (handler != SIG_IGN && handler != SIG_DFL)
83848@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83849 }
83850 }
83851
83852+ /* allow glibc communication via tgkill to other threads in our
83853+ thread group */
83854+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83855+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83856+ && gr_handle_signal(t, sig))
83857+ return -EPERM;
83858+
83859 return security_task_kill(t, info, sig, 0);
83860 }
83861
83862@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83863 return send_signal(sig, info, p, 1);
83864 }
83865
83866-static int
83867+int
83868 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83869 {
83870 return send_signal(sig, info, t, 0);
83871@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83872 unsigned long int flags;
83873 int ret, blocked, ignored;
83874 struct k_sigaction *action;
83875+ int is_unhandled = 0;
83876
83877 spin_lock_irqsave(&t->sighand->siglock, flags);
83878 action = &t->sighand->action[sig-1];
83879@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83880 }
83881 if (action->sa.sa_handler == SIG_DFL)
83882 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83883+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83884+ is_unhandled = 1;
83885 ret = specific_send_sig_info(sig, info, t);
83886 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83887
83888+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83889+ normal operation */
83890+ if (is_unhandled) {
83891+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83892+ gr_handle_crash(t, sig);
83893+ }
83894+
83895 return ret;
83896 }
83897
83898@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83899 ret = check_kill_permission(sig, info, p);
83900 rcu_read_unlock();
83901
83902- if (!ret && sig)
83903+ if (!ret && sig) {
83904 ret = do_send_sig_info(sig, info, p, true);
83905+ if (!ret)
83906+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83907+ }
83908
83909 return ret;
83910 }
83911@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83912 int error = -ESRCH;
83913
83914 rcu_read_lock();
83915- p = find_task_by_vpid(pid);
83916+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83917+ /* allow glibc communication via tgkill to other threads in our
83918+ thread group */
83919+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83920+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83921+ p = find_task_by_vpid_unrestricted(pid);
83922+ else
83923+#endif
83924+ p = find_task_by_vpid(pid);
83925 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83926 error = check_kill_permission(sig, info, p);
83927 /*
83928@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
83929 __put_user(t->sas_ss_size, &uss->ss_size);
83930 }
83931
83932+#ifdef CONFIG_X86
83933+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
83934+{
83935+ struct task_struct *t = current;
83936+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
83937+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83938+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83939+}
83940+#endif
83941+
83942 #ifdef CONFIG_COMPAT
83943 COMPAT_SYSCALL_DEFINE2(sigaltstack,
83944 const compat_stack_t __user *, uss_ptr,
83945@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83946 }
83947 seg = get_fs();
83948 set_fs(KERNEL_DS);
83949- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83950- (stack_t __force __user *) &uoss,
83951+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83952+ (stack_t __force_user *) &uoss,
83953 compat_user_stack_pointer());
83954 set_fs(seg);
83955 if (ret >= 0 && uoss_ptr) {
83956@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
83957 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
83958 __put_user(t->sas_ss_size, &uss->ss_size);
83959 }
83960+
83961+#ifdef CONFIG_X86
83962+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
83963+{
83964+ struct task_struct *t = current;
83965+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
83966+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83967+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83968+}
83969+#endif
83970 #endif
83971
83972 #ifdef __ARCH_WANT_SYS_SIGPENDING
83973diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83974index eb89e18..a4e6792 100644
83975--- a/kernel/smpboot.c
83976+++ b/kernel/smpboot.c
83977@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83978 }
83979 smpboot_unpark_thread(plug_thread, cpu);
83980 }
83981- list_add(&plug_thread->list, &hotplug_threads);
83982+ pax_list_add(&plug_thread->list, &hotplug_threads);
83983 out:
83984 mutex_unlock(&smpboot_threads_lock);
83985 return ret;
83986@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83987 {
83988 get_online_cpus();
83989 mutex_lock(&smpboot_threads_lock);
83990- list_del(&plug_thread->list);
83991+ pax_list_del(&plug_thread->list);
83992 smpboot_destroy_threads(plug_thread);
83993 mutex_unlock(&smpboot_threads_lock);
83994 put_online_cpus();
83995diff --git a/kernel/softirq.c b/kernel/softirq.c
83996index be3d351..e57af82 100644
83997--- a/kernel/softirq.c
83998+++ b/kernel/softirq.c
83999@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
84000 EXPORT_SYMBOL(irq_stat);
84001 #endif
84002
84003-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
84004+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
84005
84006 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
84007
84008-char *softirq_to_name[NR_SOFTIRQS] = {
84009+const char * const softirq_to_name[NR_SOFTIRQS] = {
84010 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
84011 "TASKLET", "SCHED", "HRTIMER", "RCU"
84012 };
84013@@ -248,7 +248,7 @@ restart:
84014 kstat_incr_softirqs_this_cpu(vec_nr);
84015
84016 trace_softirq_entry(vec_nr);
84017- h->action(h);
84018+ h->action();
84019 trace_softirq_exit(vec_nr);
84020 if (unlikely(prev_count != preempt_count())) {
84021 printk(KERN_ERR "huh, entered softirq %u %s %p"
84022@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
84023 or_softirq_pending(1UL << nr);
84024 }
84025
84026-void open_softirq(int nr, void (*action)(struct softirq_action *))
84027+void __init open_softirq(int nr, void (*action)(void))
84028 {
84029 softirq_vec[nr].action = action;
84030 }
84031@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
84032
84033 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
84034
84035-static void tasklet_action(struct softirq_action *a)
84036+static __latent_entropy void tasklet_action(void)
84037 {
84038 struct tasklet_struct *list;
84039
84040@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
84041 }
84042 }
84043
84044-static void tasklet_hi_action(struct softirq_action *a)
84045+static __latent_entropy void tasklet_hi_action(void)
84046 {
84047 struct tasklet_struct *list;
84048
84049@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
84050 .notifier_call = cpu_callback
84051 };
84052
84053-static struct smp_hotplug_thread softirq_threads = {
84054+static struct smp_hotplug_thread softirq_threads __read_only = {
84055 .store = &ksoftirqd,
84056 .thread_should_run = ksoftirqd_should_run,
84057 .thread_fn = run_ksoftirqd,
84058diff --git a/kernel/srcu.c b/kernel/srcu.c
84059index 01d5ccb..cdcbee6 100644
84060--- a/kernel/srcu.c
84061+++ b/kernel/srcu.c
84062@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
84063
84064 idx = ACCESS_ONCE(sp->completed) & 0x1;
84065 preempt_disable();
84066- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84067+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84068 smp_mb(); /* B */ /* Avoid leaking the critical section. */
84069- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
84070+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
84071 preempt_enable();
84072 return idx;
84073 }
84074diff --git a/kernel/sys.c b/kernel/sys.c
84075index 771129b..dc0c7e3 100644
84076--- a/kernel/sys.c
84077+++ b/kernel/sys.c
84078@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
84079 error = -EACCES;
84080 goto out;
84081 }
84082+
84083+ if (gr_handle_chroot_setpriority(p, niceval)) {
84084+ error = -EACCES;
84085+ goto out;
84086+ }
84087+
84088 no_nice = security_task_setnice(p, niceval);
84089 if (no_nice) {
84090 error = no_nice;
84091@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
84092 goto error;
84093 }
84094
84095+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
84096+ goto error;
84097+
84098 if (rgid != (gid_t) -1 ||
84099 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
84100 new->sgid = new->egid;
84101@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
84102 old = current_cred();
84103
84104 retval = -EPERM;
84105+
84106+ if (gr_check_group_change(kgid, kgid, kgid))
84107+ goto error;
84108+
84109 if (nsown_capable(CAP_SETGID))
84110 new->gid = new->egid = new->sgid = new->fsgid = kgid;
84111 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
84112@@ -404,7 +417,7 @@ error:
84113 /*
84114 * change the user struct in a credentials set to match the new UID
84115 */
84116-static int set_user(struct cred *new)
84117+int set_user(struct cred *new)
84118 {
84119 struct user_struct *new_user;
84120
84121@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
84122 goto error;
84123 }
84124
84125+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
84126+ goto error;
84127+
84128 if (!uid_eq(new->uid, old->uid)) {
84129 retval = set_user(new);
84130 if (retval < 0)
84131@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
84132 old = current_cred();
84133
84134 retval = -EPERM;
84135+
84136+ if (gr_check_crash_uid(kuid))
84137+ goto error;
84138+ if (gr_check_user_change(kuid, kuid, kuid))
84139+ goto error;
84140+
84141 if (nsown_capable(CAP_SETUID)) {
84142 new->suid = new->uid = kuid;
84143 if (!uid_eq(kuid, old->uid)) {
84144@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
84145 goto error;
84146 }
84147
84148+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
84149+ goto error;
84150+
84151 if (ruid != (uid_t) -1) {
84152 new->uid = kruid;
84153 if (!uid_eq(kruid, old->uid)) {
84154@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
84155 goto error;
84156 }
84157
84158+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
84159+ goto error;
84160+
84161 if (rgid != (gid_t) -1)
84162 new->gid = krgid;
84163 if (egid != (gid_t) -1)
84164@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
84165 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
84166 nsown_capable(CAP_SETUID)) {
84167 if (!uid_eq(kuid, old->fsuid)) {
84168+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
84169+ goto error;
84170+
84171 new->fsuid = kuid;
84172 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
84173 goto change_okay;
84174 }
84175 }
84176
84177+error:
84178 abort_creds(new);
84179 return old_fsuid;
84180
84181@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
84182 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
84183 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
84184 nsown_capable(CAP_SETGID)) {
84185+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
84186+ goto error;
84187+
84188 if (!gid_eq(kgid, old->fsgid)) {
84189 new->fsgid = kgid;
84190 goto change_okay;
84191 }
84192 }
84193
84194+error:
84195 abort_creds(new);
84196 return old_fsgid;
84197
84198@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
84199 return -EFAULT;
84200
84201 down_read(&uts_sem);
84202- error = __copy_to_user(&name->sysname, &utsname()->sysname,
84203+ error = __copy_to_user(name->sysname, &utsname()->sysname,
84204 __OLD_UTS_LEN);
84205 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
84206- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
84207+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
84208 __OLD_UTS_LEN);
84209 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
84210- error |= __copy_to_user(&name->release, &utsname()->release,
84211+ error |= __copy_to_user(name->release, &utsname()->release,
84212 __OLD_UTS_LEN);
84213 error |= __put_user(0, name->release + __OLD_UTS_LEN);
84214- error |= __copy_to_user(&name->version, &utsname()->version,
84215+ error |= __copy_to_user(name->version, &utsname()->version,
84216 __OLD_UTS_LEN);
84217 error |= __put_user(0, name->version + __OLD_UTS_LEN);
84218- error |= __copy_to_user(&name->machine, &utsname()->machine,
84219+ error |= __copy_to_user(name->machine, &utsname()->machine,
84220 __OLD_UTS_LEN);
84221 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84222 up_read(&uts_sem);
84223@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84224 */
84225 new_rlim->rlim_cur = 1;
84226 }
84227+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84228+ is changed to a lower value. Since tasks can be created by the same
84229+ user in between this limit change and an execve by this task, force
84230+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84231+ */
84232+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84233+ tsk->flags |= PF_NPROC_EXCEEDED;
84234 }
84235 if (!retval) {
84236 if (old_rlim)
84237diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84238index 07f6fc4..65fb3d4 100644
84239--- a/kernel/sysctl.c
84240+++ b/kernel/sysctl.c
84241@@ -93,7 +93,6 @@
84242
84243
84244 #if defined(CONFIG_SYSCTL)
84245-
84246 /* External variables not in a header file. */
84247 extern int sysctl_overcommit_memory;
84248 extern int sysctl_overcommit_ratio;
84249@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84250
84251 /* Constants used for minimum and maximum */
84252 #ifdef CONFIG_LOCKUP_DETECTOR
84253-static int sixty = 60;
84254+static int sixty __read_only = 60;
84255 #endif
84256
84257-static int zero;
84258-static int __maybe_unused one = 1;
84259-static int __maybe_unused two = 2;
84260-static int __maybe_unused three = 3;
84261-static unsigned long one_ul = 1;
84262-static int one_hundred = 100;
84263+static int neg_one __read_only = -1;
84264+static int zero __read_only = 0;
84265+static int __maybe_unused one __read_only = 1;
84266+static int __maybe_unused two __read_only = 2;
84267+static int __maybe_unused three __read_only = 3;
84268+static unsigned long one_ul __read_only = 1;
84269+static int one_hundred __read_only = 100;
84270 #ifdef CONFIG_PRINTK
84271-static int ten_thousand = 10000;
84272+static int ten_thousand __read_only = 10000;
84273 #endif
84274
84275 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84276@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84277 void __user *buffer, size_t *lenp, loff_t *ppos);
84278 #endif
84279
84280-#ifdef CONFIG_PRINTK
84281 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84282 void __user *buffer, size_t *lenp, loff_t *ppos);
84283-#endif
84284
84285 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84286 void __user *buffer, size_t *lenp, loff_t *ppos);
84287@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84288
84289 #endif
84290
84291+extern struct ctl_table grsecurity_table[];
84292+
84293 static struct ctl_table kern_table[];
84294 static struct ctl_table vm_table[];
84295 static struct ctl_table fs_table[];
84296@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84297 int sysctl_legacy_va_layout;
84298 #endif
84299
84300+#ifdef CONFIG_PAX_SOFTMODE
84301+static ctl_table pax_table[] = {
84302+ {
84303+ .procname = "softmode",
84304+ .data = &pax_softmode,
84305+ .maxlen = sizeof(unsigned int),
84306+ .mode = 0600,
84307+ .proc_handler = &proc_dointvec,
84308+ },
84309+
84310+ { }
84311+};
84312+#endif
84313+
84314 /* The default sysctl tables: */
84315
84316 static struct ctl_table sysctl_base_table[] = {
84317@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84318 #endif
84319
84320 static struct ctl_table kern_table[] = {
84321+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84322+ {
84323+ .procname = "grsecurity",
84324+ .mode = 0500,
84325+ .child = grsecurity_table,
84326+ },
84327+#endif
84328+
84329+#ifdef CONFIG_PAX_SOFTMODE
84330+ {
84331+ .procname = "pax",
84332+ .mode = 0500,
84333+ .child = pax_table,
84334+ },
84335+#endif
84336+
84337 {
84338 .procname = "sched_child_runs_first",
84339 .data = &sysctl_sched_child_runs_first,
84340@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84341 .data = &modprobe_path,
84342 .maxlen = KMOD_PATH_LEN,
84343 .mode = 0644,
84344- .proc_handler = proc_dostring,
84345+ .proc_handler = proc_dostring_modpriv,
84346 },
84347 {
84348 .procname = "modules_disabled",
84349@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84350 .extra1 = &zero,
84351 .extra2 = &one,
84352 },
84353+#endif
84354 {
84355 .procname = "kptr_restrict",
84356 .data = &kptr_restrict,
84357 .maxlen = sizeof(int),
84358 .mode = 0644,
84359 .proc_handler = proc_dointvec_minmax_sysadmin,
84360+#ifdef CONFIG_GRKERNSEC_HIDESYM
84361+ .extra1 = &two,
84362+#else
84363 .extra1 = &zero,
84364+#endif
84365 .extra2 = &two,
84366 },
84367-#endif
84368 {
84369 .procname = "ngroups_max",
84370 .data = &ngroups_max,
84371@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84372 */
84373 {
84374 .procname = "perf_event_paranoid",
84375- .data = &sysctl_perf_event_paranoid,
84376- .maxlen = sizeof(sysctl_perf_event_paranoid),
84377+ .data = &sysctl_perf_event_legitimately_concerned,
84378+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84379 .mode = 0644,
84380- .proc_handler = proc_dointvec,
84381+ /* go ahead, be a hero */
84382+ .proc_handler = proc_dointvec_minmax_sysadmin,
84383+ .extra1 = &neg_one,
84384+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84385+ .extra2 = &three,
84386+#else
84387+ .extra2 = &two,
84388+#endif
84389 },
84390 {
84391 .procname = "perf_event_mlock_kb",
84392@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84393 .proc_handler = proc_dointvec_minmax,
84394 .extra1 = &zero,
84395 },
84396+ {
84397+ .procname = "heap_stack_gap",
84398+ .data = &sysctl_heap_stack_gap,
84399+ .maxlen = sizeof(sysctl_heap_stack_gap),
84400+ .mode = 0644,
84401+ .proc_handler = proc_doulongvec_minmax,
84402+ },
84403 #else
84404 {
84405 .procname = "nr_trim_pages",
84406@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84407 buffer, lenp, ppos);
84408 }
84409
84410+int proc_dostring_modpriv(struct ctl_table *table, int write,
84411+ void __user *buffer, size_t *lenp, loff_t *ppos)
84412+{
84413+ if (write && !capable(CAP_SYS_MODULE))
84414+ return -EPERM;
84415+
84416+ return _proc_do_string(table->data, table->maxlen, write,
84417+ buffer, lenp, ppos);
84418+}
84419+
84420 static size_t proc_skip_spaces(char **buf)
84421 {
84422 size_t ret;
84423@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84424 len = strlen(tmp);
84425 if (len > *size)
84426 len = *size;
84427+ if (len > sizeof(tmp))
84428+ len = sizeof(tmp);
84429 if (copy_to_user(*buf, tmp, len))
84430 return -EFAULT;
84431 *size -= len;
84432@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84433 static int proc_taint(struct ctl_table *table, int write,
84434 void __user *buffer, size_t *lenp, loff_t *ppos)
84435 {
84436- struct ctl_table t;
84437+ ctl_table_no_const t;
84438 unsigned long tmptaint = get_taint();
84439 int err;
84440
84441@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84442 return err;
84443 }
84444
84445-#ifdef CONFIG_PRINTK
84446 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84447 void __user *buffer, size_t *lenp, loff_t *ppos)
84448 {
84449@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84450
84451 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84452 }
84453-#endif
84454
84455 struct do_proc_dointvec_minmax_conv_param {
84456 int *min;
84457@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84458 *i = val;
84459 } else {
84460 val = convdiv * (*i) / convmul;
84461- if (!first)
84462+ if (!first) {
84463 err = proc_put_char(&buffer, &left, '\t');
84464+ if (err)
84465+ break;
84466+ }
84467 err = proc_put_long(&buffer, &left, val, false);
84468 if (err)
84469 break;
84470@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84471 return -ENOSYS;
84472 }
84473
84474+int proc_dostring_modpriv(struct ctl_table *table, int write,
84475+ void __user *buffer, size_t *lenp, loff_t *ppos)
84476+{
84477+ return -ENOSYS;
84478+}
84479+
84480 int proc_dointvec(struct ctl_table *table, int write,
84481 void __user *buffer, size_t *lenp, loff_t *ppos)
84482 {
84483@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84484 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84485 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84486 EXPORT_SYMBOL(proc_dostring);
84487+EXPORT_SYMBOL(proc_dostring_modpriv);
84488 EXPORT_SYMBOL(proc_doulongvec_minmax);
84489 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84490diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84491index 145bb4d..b2aa969 100644
84492--- a/kernel/taskstats.c
84493+++ b/kernel/taskstats.c
84494@@ -28,9 +28,12 @@
84495 #include <linux/fs.h>
84496 #include <linux/file.h>
84497 #include <linux/pid_namespace.h>
84498+#include <linux/grsecurity.h>
84499 #include <net/genetlink.h>
84500 #include <linux/atomic.h>
84501
84502+extern int gr_is_taskstats_denied(int pid);
84503+
84504 /*
84505 * Maximum length of a cpumask that can be specified in
84506 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84507@@ -570,6 +573,9 @@ err:
84508
84509 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84510 {
84511+ if (gr_is_taskstats_denied(current->pid))
84512+ return -EACCES;
84513+
84514 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84515 return cmd_attr_register_cpumask(info);
84516 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84517diff --git a/kernel/time.c b/kernel/time.c
84518index 7c7964c..784a599 100644
84519--- a/kernel/time.c
84520+++ b/kernel/time.c
84521@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84522 return error;
84523
84524 if (tz) {
84525+ /* we log in do_settimeofday called below, so don't log twice
84526+ */
84527+ if (!tv)
84528+ gr_log_timechange();
84529+
84530 sys_tz = *tz;
84531 update_vsyscall_tz();
84532 if (firsttime) {
84533@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84534 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84535 * value to a scaled second value.
84536 */
84537-unsigned long
84538+unsigned long __intentional_overflow(-1)
84539 timespec_to_jiffies(const struct timespec *value)
84540 {
84541 unsigned long sec = value->tv_sec;
84542diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84543index eec50fc..65e5df6 100644
84544--- a/kernel/time/alarmtimer.c
84545+++ b/kernel/time/alarmtimer.c
84546@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84547 struct platform_device *pdev;
84548 int error = 0;
84549 int i;
84550- struct k_clock alarm_clock = {
84551+ static struct k_clock alarm_clock = {
84552 .clock_getres = alarm_clock_getres,
84553 .clock_get = alarm_clock_get,
84554 .timer_create = alarm_timer_create,
84555diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84556index 48b9fff..9e07e5f 100644
84557--- a/kernel/time/timekeeping.c
84558+++ b/kernel/time/timekeeping.c
84559@@ -15,6 +15,7 @@
84560 #include <linux/init.h>
84561 #include <linux/mm.h>
84562 #include <linux/sched.h>
84563+#include <linux/grsecurity.h>
84564 #include <linux/syscore_ops.h>
84565 #include <linux/clocksource.h>
84566 #include <linux/jiffies.h>
84567@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84568 if (!timespec_valid_strict(tv))
84569 return -EINVAL;
84570
84571+ gr_log_timechange();
84572+
84573 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84574 write_seqcount_begin(&timekeeper_seq);
84575
84576diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84577index 61ed862..3b52c65 100644
84578--- a/kernel/time/timer_list.c
84579+++ b/kernel/time/timer_list.c
84580@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84581
84582 static void print_name_offset(struct seq_file *m, void *sym)
84583 {
84584+#ifdef CONFIG_GRKERNSEC_HIDESYM
84585+ SEQ_printf(m, "<%p>", NULL);
84586+#else
84587 char symname[KSYM_NAME_LEN];
84588
84589 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84590 SEQ_printf(m, "<%pK>", sym);
84591 else
84592 SEQ_printf(m, "%s", symname);
84593+#endif
84594 }
84595
84596 static void
84597@@ -119,7 +123,11 @@ next_one:
84598 static void
84599 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84600 {
84601+#ifdef CONFIG_GRKERNSEC_HIDESYM
84602+ SEQ_printf(m, " .base: %p\n", NULL);
84603+#else
84604 SEQ_printf(m, " .base: %pK\n", base);
84605+#endif
84606 SEQ_printf(m, " .index: %d\n",
84607 base->index);
84608 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84609@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84610 {
84611 struct proc_dir_entry *pe;
84612
84613+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84614+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84615+#else
84616 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84617+#endif
84618 if (!pe)
84619 return -ENOMEM;
84620 return 0;
84621diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84622index 0b537f2..40d6c20 100644
84623--- a/kernel/time/timer_stats.c
84624+++ b/kernel/time/timer_stats.c
84625@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84626 static unsigned long nr_entries;
84627 static struct entry entries[MAX_ENTRIES];
84628
84629-static atomic_t overflow_count;
84630+static atomic_unchecked_t overflow_count;
84631
84632 /*
84633 * The entries are in a hash-table, for fast lookup:
84634@@ -140,7 +140,7 @@ static void reset_entries(void)
84635 nr_entries = 0;
84636 memset(entries, 0, sizeof(entries));
84637 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84638- atomic_set(&overflow_count, 0);
84639+ atomic_set_unchecked(&overflow_count, 0);
84640 }
84641
84642 static struct entry *alloc_entry(void)
84643@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84644 if (likely(entry))
84645 entry->count++;
84646 else
84647- atomic_inc(&overflow_count);
84648+ atomic_inc_unchecked(&overflow_count);
84649
84650 out_unlock:
84651 raw_spin_unlock_irqrestore(lock, flags);
84652@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84653
84654 static void print_name_offset(struct seq_file *m, unsigned long addr)
84655 {
84656+#ifdef CONFIG_GRKERNSEC_HIDESYM
84657+ seq_printf(m, "<%p>", NULL);
84658+#else
84659 char symname[KSYM_NAME_LEN];
84660
84661 if (lookup_symbol_name(addr, symname) < 0)
84662- seq_printf(m, "<%p>", (void *)addr);
84663+ seq_printf(m, "<%pK>", (void *)addr);
84664 else
84665 seq_printf(m, "%s", symname);
84666+#endif
84667 }
84668
84669 static int tstats_show(struct seq_file *m, void *v)
84670@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84671
84672 seq_puts(m, "Timer Stats Version: v0.2\n");
84673 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84674- if (atomic_read(&overflow_count))
84675+ if (atomic_read_unchecked(&overflow_count))
84676 seq_printf(m, "Overflow: %d entries\n",
84677- atomic_read(&overflow_count));
84678+ atomic_read_unchecked(&overflow_count));
84679
84680 for (i = 0; i < nr_entries; i++) {
84681 entry = entries + i;
84682@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84683 {
84684 struct proc_dir_entry *pe;
84685
84686+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84687+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84688+#else
84689 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84690+#endif
84691 if (!pe)
84692 return -ENOMEM;
84693 return 0;
84694diff --git a/kernel/timer.c b/kernel/timer.c
84695index 4296d13..0164b04 100644
84696--- a/kernel/timer.c
84697+++ b/kernel/timer.c
84698@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84699 /*
84700 * This function runs timers and the timer-tq in bottom half context.
84701 */
84702-static void run_timer_softirq(struct softirq_action *h)
84703+static __latent_entropy void run_timer_softirq(void)
84704 {
84705 struct tvec_base *base = __this_cpu_read(tvec_bases);
84706
84707@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84708 *
84709 * In all cases the return value is guaranteed to be non-negative.
84710 */
84711-signed long __sched schedule_timeout(signed long timeout)
84712+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84713 {
84714 struct timer_list timer;
84715 unsigned long expire;
84716diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84717index b8b8560..75b1a09 100644
84718--- a/kernel/trace/blktrace.c
84719+++ b/kernel/trace/blktrace.c
84720@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84721 struct blk_trace *bt = filp->private_data;
84722 char buf[16];
84723
84724- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84725+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84726
84727 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84728 }
84729@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84730 return 1;
84731
84732 bt = buf->chan->private_data;
84733- atomic_inc(&bt->dropped);
84734+ atomic_inc_unchecked(&bt->dropped);
84735 return 0;
84736 }
84737
84738@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84739
84740 bt->dir = dir;
84741 bt->dev = dev;
84742- atomic_set(&bt->dropped, 0);
84743+ atomic_set_unchecked(&bt->dropped, 0);
84744
84745 ret = -EIO;
84746 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84747diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84748index a6d098c..bb8cf65 100644
84749--- a/kernel/trace/ftrace.c
84750+++ b/kernel/trace/ftrace.c
84751@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84752 if (unlikely(ftrace_disabled))
84753 return 0;
84754
84755+ ret = ftrace_arch_code_modify_prepare();
84756+ FTRACE_WARN_ON(ret);
84757+ if (ret)
84758+ return 0;
84759+
84760 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84761+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84762 if (ret) {
84763 ftrace_bug(ret, ip);
84764- return 0;
84765 }
84766- return 1;
84767+ return ret ? 0 : 1;
84768 }
84769
84770 /*
84771@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84772 if (!count)
84773 return 0;
84774
84775+ pax_open_kernel();
84776 sort(start, count, sizeof(*start),
84777 ftrace_cmp_ips, ftrace_swap_ips);
84778+ pax_close_kernel();
84779
84780 start_pg = ftrace_allocate_pages(count);
84781 if (!start_pg)
84782@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84783 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84784
84785 static int ftrace_graph_active;
84786-static struct notifier_block ftrace_suspend_notifier;
84787-
84788 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84789 {
84790 return 0;
84791@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84792 return NOTIFY_DONE;
84793 }
84794
84795+static struct notifier_block ftrace_suspend_notifier = {
84796+ .notifier_call = ftrace_suspend_notifier_call
84797+};
84798+
84799 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84800 trace_func_graph_ent_t entryfunc)
84801 {
84802@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84803 goto out;
84804 }
84805
84806- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84807 register_pm_notifier(&ftrace_suspend_notifier);
84808
84809 ftrace_graph_active++;
84810diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84811index cc2f66f..05edd54 100644
84812--- a/kernel/trace/ring_buffer.c
84813+++ b/kernel/trace/ring_buffer.c
84814@@ -352,9 +352,9 @@ struct buffer_data_page {
84815 */
84816 struct buffer_page {
84817 struct list_head list; /* list of buffer pages */
84818- local_t write; /* index for next write */
84819+ local_unchecked_t write; /* index for next write */
84820 unsigned read; /* index for next read */
84821- local_t entries; /* entries on this page */
84822+ local_unchecked_t entries; /* entries on this page */
84823 unsigned long real_end; /* real end of data */
84824 struct buffer_data_page *page; /* Actual data page */
84825 };
84826@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84827 unsigned long last_overrun;
84828 local_t entries_bytes;
84829 local_t entries;
84830- local_t overrun;
84831- local_t commit_overrun;
84832+ local_unchecked_t overrun;
84833+ local_unchecked_t commit_overrun;
84834 local_t dropped_events;
84835 local_t committing;
84836 local_t commits;
84837@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84838 *
84839 * We add a counter to the write field to denote this.
84840 */
84841- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84842- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84843+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84844+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84845
84846 /*
84847 * Just make sure we have seen our old_write and synchronize
84848@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84849 * cmpxchg to only update if an interrupt did not already
84850 * do it for us. If the cmpxchg fails, we don't care.
84851 */
84852- (void)local_cmpxchg(&next_page->write, old_write, val);
84853- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84854+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84855+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84856
84857 /*
84858 * No need to worry about races with clearing out the commit.
84859@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84860
84861 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84862 {
84863- return local_read(&bpage->entries) & RB_WRITE_MASK;
84864+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84865 }
84866
84867 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84868 {
84869- return local_read(&bpage->write) & RB_WRITE_MASK;
84870+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84871 }
84872
84873 static int
84874@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84875 * bytes consumed in ring buffer from here.
84876 * Increment overrun to account for the lost events.
84877 */
84878- local_add(page_entries, &cpu_buffer->overrun);
84879+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84880 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84881 }
84882
84883@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84884 * it is our responsibility to update
84885 * the counters.
84886 */
84887- local_add(entries, &cpu_buffer->overrun);
84888+ local_add_unchecked(entries, &cpu_buffer->overrun);
84889 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84890
84891 /*
84892@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84893 if (tail == BUF_PAGE_SIZE)
84894 tail_page->real_end = 0;
84895
84896- local_sub(length, &tail_page->write);
84897+ local_sub_unchecked(length, &tail_page->write);
84898 return;
84899 }
84900
84901@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84902 rb_event_set_padding(event);
84903
84904 /* Set the write back to the previous setting */
84905- local_sub(length, &tail_page->write);
84906+ local_sub_unchecked(length, &tail_page->write);
84907 return;
84908 }
84909
84910@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84911
84912 /* Set write to end of buffer */
84913 length = (tail + length) - BUF_PAGE_SIZE;
84914- local_sub(length, &tail_page->write);
84915+ local_sub_unchecked(length, &tail_page->write);
84916 }
84917
84918 /*
84919@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84920 * about it.
84921 */
84922 if (unlikely(next_page == commit_page)) {
84923- local_inc(&cpu_buffer->commit_overrun);
84924+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84925 goto out_reset;
84926 }
84927
84928@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84929 cpu_buffer->tail_page) &&
84930 (cpu_buffer->commit_page ==
84931 cpu_buffer->reader_page))) {
84932- local_inc(&cpu_buffer->commit_overrun);
84933+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84934 goto out_reset;
84935 }
84936 }
84937@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84938 length += RB_LEN_TIME_EXTEND;
84939
84940 tail_page = cpu_buffer->tail_page;
84941- write = local_add_return(length, &tail_page->write);
84942+ write = local_add_return_unchecked(length, &tail_page->write);
84943
84944 /* set write to only the index of the write */
84945 write &= RB_WRITE_MASK;
84946@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84947 kmemcheck_annotate_bitfield(event, bitfield);
84948 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84949
84950- local_inc(&tail_page->entries);
84951+ local_inc_unchecked(&tail_page->entries);
84952
84953 /*
84954 * If this is the first commit on the page, then update
84955@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84956
84957 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84958 unsigned long write_mask =
84959- local_read(&bpage->write) & ~RB_WRITE_MASK;
84960+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84961 unsigned long event_length = rb_event_length(event);
84962 /*
84963 * This is on the tail page. It is possible that
84964@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84965 */
84966 old_index += write_mask;
84967 new_index += write_mask;
84968- index = local_cmpxchg(&bpage->write, old_index, new_index);
84969+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84970 if (index == old_index) {
84971 /* update counters */
84972 local_sub(event_length, &cpu_buffer->entries_bytes);
84973@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84974
84975 /* Do the likely case first */
84976 if (likely(bpage->page == (void *)addr)) {
84977- local_dec(&bpage->entries);
84978+ local_dec_unchecked(&bpage->entries);
84979 return;
84980 }
84981
84982@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84983 start = bpage;
84984 do {
84985 if (bpage->page == (void *)addr) {
84986- local_dec(&bpage->entries);
84987+ local_dec_unchecked(&bpage->entries);
84988 return;
84989 }
84990 rb_inc_page(cpu_buffer, &bpage);
84991@@ -3139,7 +3139,7 @@ static inline unsigned long
84992 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84993 {
84994 return local_read(&cpu_buffer->entries) -
84995- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84996+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84997 }
84998
84999 /**
85000@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
85001 return 0;
85002
85003 cpu_buffer = buffer->buffers[cpu];
85004- ret = local_read(&cpu_buffer->overrun);
85005+ ret = local_read_unchecked(&cpu_buffer->overrun);
85006
85007 return ret;
85008 }
85009@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
85010 return 0;
85011
85012 cpu_buffer = buffer->buffers[cpu];
85013- ret = local_read(&cpu_buffer->commit_overrun);
85014+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
85015
85016 return ret;
85017 }
85018@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
85019 /* if you care about this being correct, lock the buffer */
85020 for_each_buffer_cpu(buffer, cpu) {
85021 cpu_buffer = buffer->buffers[cpu];
85022- overruns += local_read(&cpu_buffer->overrun);
85023+ overruns += local_read_unchecked(&cpu_buffer->overrun);
85024 }
85025
85026 return overruns;
85027@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
85028 /*
85029 * Reset the reader page to size zero.
85030 */
85031- local_set(&cpu_buffer->reader_page->write, 0);
85032- local_set(&cpu_buffer->reader_page->entries, 0);
85033+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
85034+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
85035 local_set(&cpu_buffer->reader_page->page->commit, 0);
85036 cpu_buffer->reader_page->real_end = 0;
85037
85038@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
85039 * want to compare with the last_overrun.
85040 */
85041 smp_mb();
85042- overwrite = local_read(&(cpu_buffer->overrun));
85043+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
85044
85045 /*
85046 * Here's the tricky part.
85047@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85048
85049 cpu_buffer->head_page
85050 = list_entry(cpu_buffer->pages, struct buffer_page, list);
85051- local_set(&cpu_buffer->head_page->write, 0);
85052- local_set(&cpu_buffer->head_page->entries, 0);
85053+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
85054+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
85055 local_set(&cpu_buffer->head_page->page->commit, 0);
85056
85057 cpu_buffer->head_page->read = 0;
85058@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85059
85060 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
85061 INIT_LIST_HEAD(&cpu_buffer->new_pages);
85062- local_set(&cpu_buffer->reader_page->write, 0);
85063- local_set(&cpu_buffer->reader_page->entries, 0);
85064+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
85065+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
85066 local_set(&cpu_buffer->reader_page->page->commit, 0);
85067 cpu_buffer->reader_page->read = 0;
85068
85069 local_set(&cpu_buffer->entries_bytes, 0);
85070- local_set(&cpu_buffer->overrun, 0);
85071- local_set(&cpu_buffer->commit_overrun, 0);
85072+ local_set_unchecked(&cpu_buffer->overrun, 0);
85073+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
85074 local_set(&cpu_buffer->dropped_events, 0);
85075 local_set(&cpu_buffer->entries, 0);
85076 local_set(&cpu_buffer->committing, 0);
85077@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
85078 rb_init_page(bpage);
85079 bpage = reader->page;
85080 reader->page = *data_page;
85081- local_set(&reader->write, 0);
85082- local_set(&reader->entries, 0);
85083+ local_set_unchecked(&reader->write, 0);
85084+ local_set_unchecked(&reader->entries, 0);
85085 reader->read = 0;
85086 *data_page = bpage;
85087
85088diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
85089index 496f94d..754aeea 100644
85090--- a/kernel/trace/trace.c
85091+++ b/kernel/trace/trace.c
85092@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
85093 return 0;
85094 }
85095
85096-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
85097+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
85098 {
85099 /* do nothing if flag is already set */
85100 if (!!(trace_flags & mask) == !!enabled)
85101diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
85102index afaae41..64871f8 100644
85103--- a/kernel/trace/trace.h
85104+++ b/kernel/trace/trace.h
85105@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
85106 void trace_printk_init_buffers(void);
85107 void trace_printk_start_comm(void);
85108 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
85109-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
85110+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
85111
85112 /*
85113 * Normal trace_printk() and friends allocates special buffers
85114diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
85115index 26dc348..8708ca7 100644
85116--- a/kernel/trace/trace_clock.c
85117+++ b/kernel/trace/trace_clock.c
85118@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
85119 return now;
85120 }
85121
85122-static atomic64_t trace_counter;
85123+static atomic64_unchecked_t trace_counter;
85124
85125 /*
85126 * trace_clock_counter(): simply an atomic counter.
85127@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
85128 */
85129 u64 notrace trace_clock_counter(void)
85130 {
85131- return atomic64_add_return(1, &trace_counter);
85132+ return atomic64_inc_return_unchecked(&trace_counter);
85133 }
85134diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
85135index 29a7ebc..eb473cf 100644
85136--- a/kernel/trace/trace_events.c
85137+++ b/kernel/trace/trace_events.c
85138@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
85139 struct ftrace_module_file_ops {
85140 struct list_head list;
85141 struct module *mod;
85142- struct file_operations id;
85143- struct file_operations enable;
85144- struct file_operations format;
85145- struct file_operations filter;
85146 };
85147
85148 static struct ftrace_module_file_ops *
85149@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
85150
85151 file_ops->mod = mod;
85152
85153- file_ops->id = ftrace_event_id_fops;
85154- file_ops->id.owner = mod;
85155-
85156- file_ops->enable = ftrace_enable_fops;
85157- file_ops->enable.owner = mod;
85158-
85159- file_ops->filter = ftrace_event_filter_fops;
85160- file_ops->filter.owner = mod;
85161-
85162- file_ops->format = ftrace_event_format_fops;
85163- file_ops->format.owner = mod;
85164+ pax_open_kernel();
85165+ mod->trace_id.owner = mod;
85166+ mod->trace_enable.owner = mod;
85167+ mod->trace_filter.owner = mod;
85168+ mod->trace_format.owner = mod;
85169+ pax_close_kernel();
85170
85171 list_add(&file_ops->list, &ftrace_module_file_list);
85172
85173@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
85174 struct ftrace_module_file_ops *file_ops)
85175 {
85176 return __trace_add_new_event(call, tr,
85177- &file_ops->id, &file_ops->enable,
85178- &file_ops->filter, &file_ops->format);
85179+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
85180+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
85181 }
85182
85183 #else
85184diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
85185index b3dcfb2..ebee344 100644
85186--- a/kernel/trace/trace_mmiotrace.c
85187+++ b/kernel/trace/trace_mmiotrace.c
85188@@ -24,7 +24,7 @@ struct header_iter {
85189 static struct trace_array *mmio_trace_array;
85190 static bool overrun_detected;
85191 static unsigned long prev_overruns;
85192-static atomic_t dropped_count;
85193+static atomic_unchecked_t dropped_count;
85194
85195 static void mmio_reset_data(struct trace_array *tr)
85196 {
85197@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
85198
85199 static unsigned long count_overruns(struct trace_iterator *iter)
85200 {
85201- unsigned long cnt = atomic_xchg(&dropped_count, 0);
85202+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
85203 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
85204
85205 if (over > prev_overruns)
85206@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
85207 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
85208 sizeof(*entry), 0, pc);
85209 if (!event) {
85210- atomic_inc(&dropped_count);
85211+ atomic_inc_unchecked(&dropped_count);
85212 return;
85213 }
85214 entry = ring_buffer_event_data(event);
85215@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
85216 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
85217 sizeof(*entry), 0, pc);
85218 if (!event) {
85219- atomic_inc(&dropped_count);
85220+ atomic_inc_unchecked(&dropped_count);
85221 return;
85222 }
85223 entry = ring_buffer_event_data(event);
85224diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85225index 34e7cba..6f9a729 100644
85226--- a/kernel/trace/trace_output.c
85227+++ b/kernel/trace/trace_output.c
85228@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85229
85230 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85231 if (!IS_ERR(p)) {
85232- p = mangle_path(s->buffer + s->len, p, "\n");
85233+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85234 if (p) {
85235 s->len = p - s->buffer;
85236 return 1;
85237@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85238 goto out;
85239 }
85240
85241+ pax_open_kernel();
85242 if (event->funcs->trace == NULL)
85243- event->funcs->trace = trace_nop_print;
85244+ *(void **)&event->funcs->trace = trace_nop_print;
85245 if (event->funcs->raw == NULL)
85246- event->funcs->raw = trace_nop_print;
85247+ *(void **)&event->funcs->raw = trace_nop_print;
85248 if (event->funcs->hex == NULL)
85249- event->funcs->hex = trace_nop_print;
85250+ *(void **)&event->funcs->hex = trace_nop_print;
85251 if (event->funcs->binary == NULL)
85252- event->funcs->binary = trace_nop_print;
85253+ *(void **)&event->funcs->binary = trace_nop_print;
85254+ pax_close_kernel();
85255
85256 key = event->type & (EVENT_HASHSIZE - 1);
85257
85258diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85259index b20428c..4845a10 100644
85260--- a/kernel/trace/trace_stack.c
85261+++ b/kernel/trace/trace_stack.c
85262@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85263 return;
85264
85265 /* we do not handle interrupt stacks yet */
85266- if (!object_is_on_stack(stack))
85267+ if (!object_starts_on_stack(stack))
85268 return;
85269
85270 local_irq_save(flags);
85271diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85272index 9064b91..1f5d2f8 100644
85273--- a/kernel/user_namespace.c
85274+++ b/kernel/user_namespace.c
85275@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85276 !kgid_has_mapping(parent_ns, group))
85277 return -EPERM;
85278
85279+#ifdef CONFIG_GRKERNSEC
85280+ /*
85281+ * This doesn't really inspire confidence:
85282+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85283+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85284+ * Increases kernel attack surface in areas developers
85285+ * previously cared little about ("low importance due
85286+ * to requiring "root" capability")
85287+ * To be removed when this code receives *proper* review
85288+ */
85289+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85290+ !capable(CAP_SETGID))
85291+ return -EPERM;
85292+#endif
85293+
85294 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85295 if (!ns)
85296 return -ENOMEM;
85297@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85298 if (atomic_read(&current->mm->mm_users) > 1)
85299 return -EINVAL;
85300
85301- if (current->fs->users != 1)
85302+ if (atomic_read(&current->fs->users) != 1)
85303 return -EINVAL;
85304
85305 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85306diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85307index 4f69f9a..7c6f8f8 100644
85308--- a/kernel/utsname_sysctl.c
85309+++ b/kernel/utsname_sysctl.c
85310@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85311 static int proc_do_uts_string(ctl_table *table, int write,
85312 void __user *buffer, size_t *lenp, loff_t *ppos)
85313 {
85314- struct ctl_table uts_table;
85315+ ctl_table_no_const uts_table;
85316 int r;
85317 memcpy(&uts_table, table, sizeof(uts_table));
85318 uts_table.data = get_uts(table, write);
85319diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85320index 1241d8c..d5cfc28 100644
85321--- a/kernel/watchdog.c
85322+++ b/kernel/watchdog.c
85323@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85324 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85325 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85326
85327-static struct smp_hotplug_thread watchdog_threads = {
85328+static struct smp_hotplug_thread watchdog_threads __read_only = {
85329 .store = &softlockup_watchdog,
85330 .thread_should_run = watchdog_should_run,
85331 .thread_fn = watchdog,
85332diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85333index e93f7b9..989fcd7 100644
85334--- a/kernel/workqueue.c
85335+++ b/kernel/workqueue.c
85336@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85337 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85338 worker_flags |= WORKER_REBOUND;
85339 worker_flags &= ~WORKER_UNBOUND;
85340- ACCESS_ONCE(worker->flags) = worker_flags;
85341+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85342 }
85343
85344 spin_unlock_irq(&pool->lock);
85345diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85346index 1501aa5..e771896 100644
85347--- a/lib/Kconfig.debug
85348+++ b/lib/Kconfig.debug
85349@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85350
85351 config DEBUG_WW_MUTEX_SLOWPATH
85352 bool "Wait/wound mutex debugging: Slowpath testing"
85353- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85354+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85355 select DEBUG_LOCK_ALLOC
85356 select DEBUG_SPINLOCK
85357 select DEBUG_MUTEXES
85358@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85359
85360 config DEBUG_LOCK_ALLOC
85361 bool "Lock debugging: detect incorrect freeing of live locks"
85362- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85363+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85364 select DEBUG_SPINLOCK
85365 select DEBUG_MUTEXES
85366 select LOCKDEP
85367@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85368
85369 config PROVE_LOCKING
85370 bool "Lock debugging: prove locking correctness"
85371- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85372+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85373 select LOCKDEP
85374 select DEBUG_SPINLOCK
85375 select DEBUG_MUTEXES
85376@@ -914,7 +914,7 @@ config LOCKDEP
85377
85378 config LOCK_STAT
85379 bool "Lock usage statistics"
85380- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85381+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85382 select LOCKDEP
85383 select DEBUG_SPINLOCK
85384 select DEBUG_MUTEXES
85385@@ -1357,6 +1357,7 @@ config LATENCYTOP
85386 depends on DEBUG_KERNEL
85387 depends on STACKTRACE_SUPPORT
85388 depends on PROC_FS
85389+ depends on !GRKERNSEC_HIDESYM
85390 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85391 select KALLSYMS
85392 select KALLSYMS_ALL
85393@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85394 config DEBUG_STRICT_USER_COPY_CHECKS
85395 bool "Strict user copy size checks"
85396 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85397- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85398+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85399 help
85400 Enabling this option turns a certain set of sanity checks for user
85401 copy operations into compile time failures.
85402@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85403
85404 config PROVIDE_OHCI1394_DMA_INIT
85405 bool "Remote debugging over FireWire early on boot"
85406- depends on PCI && X86
85407+ depends on PCI && X86 && !GRKERNSEC
85408 help
85409 If you want to debug problems which hang or crash the kernel early
85410 on boot and the crashing machine has a FireWire port, you can use
85411@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85412
85413 config FIREWIRE_OHCI_REMOTE_DMA
85414 bool "Remote debugging over FireWire with firewire-ohci"
85415- depends on FIREWIRE_OHCI
85416+ depends on FIREWIRE_OHCI && !GRKERNSEC
85417 help
85418 This option lets you use the FireWire bus for remote debugging
85419 with help of the firewire-ohci driver. It enables unfiltered
85420diff --git a/lib/Makefile b/lib/Makefile
85421index 7baccfd..3ceb95f 100644
85422--- a/lib/Makefile
85423+++ b/lib/Makefile
85424@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85425
85426 obj-$(CONFIG_BTREE) += btree.o
85427 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85428-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85429+obj-y += list_debug.o
85430 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85431
85432 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85433diff --git a/lib/bitmap.c b/lib/bitmap.c
85434index 06f7e4f..f3cf2b0 100644
85435--- a/lib/bitmap.c
85436+++ b/lib/bitmap.c
85437@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85438 {
85439 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85440 u32 chunk;
85441- const char __user __force *ubuf = (const char __user __force *)buf;
85442+ const char __user *ubuf = (const char __force_user *)buf;
85443
85444 bitmap_zero(maskp, nmaskbits);
85445
85446@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85447 {
85448 if (!access_ok(VERIFY_READ, ubuf, ulen))
85449 return -EFAULT;
85450- return __bitmap_parse((const char __force *)ubuf,
85451+ return __bitmap_parse((const char __force_kernel *)ubuf,
85452 ulen, 1, maskp, nmaskbits);
85453
85454 }
85455@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85456 {
85457 unsigned a, b;
85458 int c, old_c, totaldigits;
85459- const char __user __force *ubuf = (const char __user __force *)buf;
85460+ const char __user *ubuf = (const char __force_user *)buf;
85461 int exp_digit, in_range;
85462
85463 totaldigits = c = 0;
85464@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85465 {
85466 if (!access_ok(VERIFY_READ, ubuf, ulen))
85467 return -EFAULT;
85468- return __bitmap_parselist((const char __force *)ubuf,
85469+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85470 ulen, 1, maskp, nmaskbits);
85471 }
85472 EXPORT_SYMBOL(bitmap_parselist_user);
85473diff --git a/lib/bug.c b/lib/bug.c
85474index 1686034..a9c00c8 100644
85475--- a/lib/bug.c
85476+++ b/lib/bug.c
85477@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85478 return BUG_TRAP_TYPE_NONE;
85479
85480 bug = find_bug(bugaddr);
85481+ if (!bug)
85482+ return BUG_TRAP_TYPE_NONE;
85483
85484 file = NULL;
85485 line = 0;
85486diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85487index 37061ed..da83f48 100644
85488--- a/lib/debugobjects.c
85489+++ b/lib/debugobjects.c
85490@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85491 if (limit > 4)
85492 return;
85493
85494- is_on_stack = object_is_on_stack(addr);
85495+ is_on_stack = object_starts_on_stack(addr);
85496 if (is_on_stack == onstack)
85497 return;
85498
85499diff --git a/lib/devres.c b/lib/devres.c
85500index 8235331..5881053 100644
85501--- a/lib/devres.c
85502+++ b/lib/devres.c
85503@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85504 void devm_iounmap(struct device *dev, void __iomem *addr)
85505 {
85506 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85507- (void *)addr));
85508+ (void __force *)addr));
85509 iounmap(addr);
85510 }
85511 EXPORT_SYMBOL(devm_iounmap);
85512@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85513 {
85514 ioport_unmap(addr);
85515 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85516- devm_ioport_map_match, (void *)addr));
85517+ devm_ioport_map_match, (void __force *)addr));
85518 }
85519 EXPORT_SYMBOL(devm_ioport_unmap);
85520 #endif /* CONFIG_HAS_IOPORT */
85521diff --git a/lib/div64.c b/lib/div64.c
85522index a163b6c..9618fa5 100644
85523--- a/lib/div64.c
85524+++ b/lib/div64.c
85525@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85526 EXPORT_SYMBOL(__div64_32);
85527
85528 #ifndef div_s64_rem
85529-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85530+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85531 {
85532 u64 quotient;
85533
85534@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85535 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85536 */
85537 #ifndef div64_u64
85538-u64 div64_u64(u64 dividend, u64 divisor)
85539+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85540 {
85541 u32 high = divisor >> 32;
85542 u64 quot;
85543diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85544index d87a17a..ac0d79a 100644
85545--- a/lib/dma-debug.c
85546+++ b/lib/dma-debug.c
85547@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85548
85549 void dma_debug_add_bus(struct bus_type *bus)
85550 {
85551- struct notifier_block *nb;
85552+ notifier_block_no_const *nb;
85553
85554 if (global_disable)
85555 return;
85556@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85557
85558 static void check_for_stack(struct device *dev, void *addr)
85559 {
85560- if (object_is_on_stack(addr))
85561+ if (object_starts_on_stack(addr))
85562 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85563 "stack [addr=%p]\n", addr);
85564 }
85565diff --git a/lib/inflate.c b/lib/inflate.c
85566index 013a761..c28f3fc 100644
85567--- a/lib/inflate.c
85568+++ b/lib/inflate.c
85569@@ -269,7 +269,7 @@ static void free(void *where)
85570 malloc_ptr = free_mem_ptr;
85571 }
85572 #else
85573-#define malloc(a) kmalloc(a, GFP_KERNEL)
85574+#define malloc(a) kmalloc((a), GFP_KERNEL)
85575 #define free(a) kfree(a)
85576 #endif
85577
85578diff --git a/lib/ioremap.c b/lib/ioremap.c
85579index 0c9216c..863bd89 100644
85580--- a/lib/ioremap.c
85581+++ b/lib/ioremap.c
85582@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85583 unsigned long next;
85584
85585 phys_addr -= addr;
85586- pmd = pmd_alloc(&init_mm, pud, addr);
85587+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85588 if (!pmd)
85589 return -ENOMEM;
85590 do {
85591@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85592 unsigned long next;
85593
85594 phys_addr -= addr;
85595- pud = pud_alloc(&init_mm, pgd, addr);
85596+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85597 if (!pud)
85598 return -ENOMEM;
85599 do {
85600diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85601index bd2bea9..6b3c95e 100644
85602--- a/lib/is_single_threaded.c
85603+++ b/lib/is_single_threaded.c
85604@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85605 struct task_struct *p, *t;
85606 bool ret;
85607
85608+ if (!mm)
85609+ return true;
85610+
85611 if (atomic_read(&task->signal->live) != 1)
85612 return false;
85613
85614diff --git a/lib/kobject.c b/lib/kobject.c
85615index 4a1f33d..2f3ca75 100644
85616--- a/lib/kobject.c
85617+++ b/lib/kobject.c
85618@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85619
85620
85621 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85622-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85623+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85624
85625-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85626+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85627 {
85628 enum kobj_ns_type type = ops->type;
85629 int error;
85630diff --git a/lib/list_debug.c b/lib/list_debug.c
85631index c24c2f7..06e070b 100644
85632--- a/lib/list_debug.c
85633+++ b/lib/list_debug.c
85634@@ -11,7 +11,9 @@
85635 #include <linux/bug.h>
85636 #include <linux/kernel.h>
85637 #include <linux/rculist.h>
85638+#include <linux/mm.h>
85639
85640+#ifdef CONFIG_DEBUG_LIST
85641 /*
85642 * Insert a new entry between two known consecutive entries.
85643 *
85644@@ -19,21 +21,32 @@
85645 * the prev/next entries already!
85646 */
85647
85648-void __list_add(struct list_head *new,
85649- struct list_head *prev,
85650- struct list_head *next)
85651+static bool __list_add_debug(struct list_head *new,
85652+ struct list_head *prev,
85653+ struct list_head *next)
85654 {
85655- WARN(next->prev != prev,
85656+ if (WARN(next->prev != prev,
85657 "list_add corruption. next->prev should be "
85658 "prev (%p), but was %p. (next=%p).\n",
85659- prev, next->prev, next);
85660- WARN(prev->next != next,
85661+ prev, next->prev, next) ||
85662+ WARN(prev->next != next,
85663 "list_add corruption. prev->next should be "
85664 "next (%p), but was %p. (prev=%p).\n",
85665- next, prev->next, prev);
85666- WARN(new == prev || new == next,
85667- "list_add double add: new=%p, prev=%p, next=%p.\n",
85668- new, prev, next);
85669+ next, prev->next, prev) ||
85670+ WARN(new == prev || new == next,
85671+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85672+ new, prev, next))
85673+ return false;
85674+ return true;
85675+}
85676+
85677+void __list_add(struct list_head *new,
85678+ struct list_head *prev,
85679+ struct list_head *next)
85680+{
85681+ if (!__list_add_debug(new, prev, next))
85682+ return;
85683+
85684 next->prev = new;
85685 new->next = next;
85686 new->prev = prev;
85687@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85688 }
85689 EXPORT_SYMBOL(__list_add);
85690
85691-void __list_del_entry(struct list_head *entry)
85692+static bool __list_del_entry_debug(struct list_head *entry)
85693 {
85694 struct list_head *prev, *next;
85695
85696@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85697 WARN(next->prev != entry,
85698 "list_del corruption. next->prev should be %p, "
85699 "but was %p\n", entry, next->prev))
85700+ return false;
85701+ return true;
85702+}
85703+
85704+void __list_del_entry(struct list_head *entry)
85705+{
85706+ if (!__list_del_entry_debug(entry))
85707 return;
85708
85709- __list_del(prev, next);
85710+ __list_del(entry->prev, entry->next);
85711 }
85712 EXPORT_SYMBOL(__list_del_entry);
85713
85714@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85715 void __list_add_rcu(struct list_head *new,
85716 struct list_head *prev, struct list_head *next)
85717 {
85718- WARN(next->prev != prev,
85719- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85720- prev, next->prev, next);
85721- WARN(prev->next != next,
85722- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85723- next, prev->next, prev);
85724+ if (!__list_add_debug(new, prev, next))
85725+ return;
85726+
85727 new->next = next;
85728 new->prev = prev;
85729 rcu_assign_pointer(list_next_rcu(prev), new);
85730 next->prev = new;
85731 }
85732 EXPORT_SYMBOL(__list_add_rcu);
85733+#endif
85734+
85735+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85736+{
85737+#ifdef CONFIG_DEBUG_LIST
85738+ if (!__list_add_debug(new, prev, next))
85739+ return;
85740+#endif
85741+
85742+ pax_open_kernel();
85743+ next->prev = new;
85744+ new->next = next;
85745+ new->prev = prev;
85746+ prev->next = new;
85747+ pax_close_kernel();
85748+}
85749+EXPORT_SYMBOL(__pax_list_add);
85750+
85751+void pax_list_del(struct list_head *entry)
85752+{
85753+#ifdef CONFIG_DEBUG_LIST
85754+ if (!__list_del_entry_debug(entry))
85755+ return;
85756+#endif
85757+
85758+ pax_open_kernel();
85759+ __list_del(entry->prev, entry->next);
85760+ entry->next = LIST_POISON1;
85761+ entry->prev = LIST_POISON2;
85762+ pax_close_kernel();
85763+}
85764+EXPORT_SYMBOL(pax_list_del);
85765+
85766+void pax_list_del_init(struct list_head *entry)
85767+{
85768+ pax_open_kernel();
85769+ __list_del(entry->prev, entry->next);
85770+ INIT_LIST_HEAD(entry);
85771+ pax_close_kernel();
85772+}
85773+EXPORT_SYMBOL(pax_list_del_init);
85774+
85775+void __pax_list_add_rcu(struct list_head *new,
85776+ struct list_head *prev, struct list_head *next)
85777+{
85778+#ifdef CONFIG_DEBUG_LIST
85779+ if (!__list_add_debug(new, prev, next))
85780+ return;
85781+#endif
85782+
85783+ pax_open_kernel();
85784+ new->next = next;
85785+ new->prev = prev;
85786+ rcu_assign_pointer(list_next_rcu(prev), new);
85787+ next->prev = new;
85788+ pax_close_kernel();
85789+}
85790+EXPORT_SYMBOL(__pax_list_add_rcu);
85791+
85792+void pax_list_del_rcu(struct list_head *entry)
85793+{
85794+#ifdef CONFIG_DEBUG_LIST
85795+ if (!__list_del_entry_debug(entry))
85796+ return;
85797+#endif
85798+
85799+ pax_open_kernel();
85800+ __list_del(entry->prev, entry->next);
85801+ entry->next = LIST_POISON1;
85802+ entry->prev = LIST_POISON2;
85803+ pax_close_kernel();
85804+}
85805+EXPORT_SYMBOL(pax_list_del_rcu);
85806diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85807index 7deeb62..144eb47 100644
85808--- a/lib/percpu-refcount.c
85809+++ b/lib/percpu-refcount.c
85810@@ -29,7 +29,7 @@
85811 * can't hit 0 before we've added up all the percpu refs.
85812 */
85813
85814-#define PCPU_COUNT_BIAS (1U << 31)
85815+#define PCPU_COUNT_BIAS (1U << 30)
85816
85817 /**
85818 * percpu_ref_init - initialize a percpu refcount
85819diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85820index e796429..6e38f9f 100644
85821--- a/lib/radix-tree.c
85822+++ b/lib/radix-tree.c
85823@@ -92,7 +92,7 @@ struct radix_tree_preload {
85824 int nr;
85825 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85826 };
85827-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85828+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85829
85830 static inline void *ptr_to_indirect(void *ptr)
85831 {
85832diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85833index bb2b201..46abaf9 100644
85834--- a/lib/strncpy_from_user.c
85835+++ b/lib/strncpy_from_user.c
85836@@ -21,7 +21,7 @@
85837 */
85838 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85839 {
85840- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85841+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85842 long res = 0;
85843
85844 /*
85845diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85846index a28df52..3d55877 100644
85847--- a/lib/strnlen_user.c
85848+++ b/lib/strnlen_user.c
85849@@ -26,7 +26,7 @@
85850 */
85851 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85852 {
85853- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85854+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85855 long align, res = 0;
85856 unsigned long c;
85857
85858diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85859index d23762e..e21eab2 100644
85860--- a/lib/swiotlb.c
85861+++ b/lib/swiotlb.c
85862@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85863
85864 void
85865 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85866- dma_addr_t dev_addr)
85867+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85868 {
85869 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85870
85871diff --git a/lib/usercopy.c b/lib/usercopy.c
85872index 4f5b1dd..7cab418 100644
85873--- a/lib/usercopy.c
85874+++ b/lib/usercopy.c
85875@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85876 WARN(1, "Buffer overflow detected!\n");
85877 }
85878 EXPORT_SYMBOL(copy_from_user_overflow);
85879+
85880+void copy_to_user_overflow(void)
85881+{
85882+ WARN(1, "Buffer overflow detected!\n");
85883+}
85884+EXPORT_SYMBOL(copy_to_user_overflow);
85885diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85886index 739a363..aa668d7 100644
85887--- a/lib/vsprintf.c
85888+++ b/lib/vsprintf.c
85889@@ -16,6 +16,9 @@
85890 * - scnprintf and vscnprintf
85891 */
85892
85893+#ifdef CONFIG_GRKERNSEC_HIDESYM
85894+#define __INCLUDED_BY_HIDESYM 1
85895+#endif
85896 #include <stdarg.h>
85897 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85898 #include <linux/types.h>
85899@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85900 return number(buf, end, *(const netdev_features_t *)addr, spec);
85901 }
85902
85903+#ifdef CONFIG_GRKERNSEC_HIDESYM
85904+int kptr_restrict __read_mostly = 2;
85905+#else
85906 int kptr_restrict __read_mostly;
85907+#endif
85908
85909 /*
85910 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85911@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85912 * - 'f' For simple symbolic function names without offset
85913 * - 'S' For symbolic direct pointers with offset
85914 * - 's' For symbolic direct pointers without offset
85915+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85916 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85917 * - 'B' For backtraced symbolic direct pointers with offset
85918 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85919@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85920
85921 if (!ptr && *fmt != 'K') {
85922 /*
85923- * Print (null) with the same width as a pointer so it makes
85924+ * Print (nil) with the same width as a pointer so it makes
85925 * tabular output look nice.
85926 */
85927 if (spec.field_width == -1)
85928 spec.field_width = default_width;
85929- return string(buf, end, "(null)", spec);
85930+ return string(buf, end, "(nil)", spec);
85931 }
85932
85933 switch (*fmt) {
85934@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85935 /* Fallthrough */
85936 case 'S':
85937 case 's':
85938+#ifdef CONFIG_GRKERNSEC_HIDESYM
85939+ break;
85940+#else
85941+ return symbol_string(buf, end, ptr, spec, fmt);
85942+#endif
85943+ case 'A':
85944 case 'B':
85945 return symbol_string(buf, end, ptr, spec, fmt);
85946 case 'R':
85947@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85948 va_end(va);
85949 return buf;
85950 }
85951+ case 'P':
85952+ break;
85953 case 'K':
85954 /*
85955 * %pK cannot be used in IRQ context because its test
85956@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85957 return number(buf, end,
85958 (unsigned long long) *((phys_addr_t *)ptr), spec);
85959 }
85960+
85961+#ifdef CONFIG_GRKERNSEC_HIDESYM
85962+ /* 'P' = approved pointers to copy to userland,
85963+ as in the /proc/kallsyms case, as we make it display nothing
85964+ for non-root users, and the real contents for root users
85965+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85966+ above
85967+ */
85968+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85969+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85970+ dump_stack();
85971+ ptr = NULL;
85972+ }
85973+#endif
85974+
85975 spec.flags |= SMALL;
85976 if (spec.field_width == -1) {
85977 spec.field_width = default_width;
85978@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85979 typeof(type) value; \
85980 if (sizeof(type) == 8) { \
85981 args = PTR_ALIGN(args, sizeof(u32)); \
85982- *(u32 *)&value = *(u32 *)args; \
85983- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85984+ *(u32 *)&value = *(const u32 *)args; \
85985+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85986 } else { \
85987 args = PTR_ALIGN(args, sizeof(type)); \
85988- value = *(typeof(type) *)args; \
85989+ value = *(const typeof(type) *)args; \
85990 } \
85991 args += sizeof(type); \
85992 value; \
85993@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85994 case FORMAT_TYPE_STR: {
85995 const char *str_arg = args;
85996 args += strlen(str_arg) + 1;
85997- str = string(str, end, (char *)str_arg, spec);
85998+ str = string(str, end, str_arg, spec);
85999 break;
86000 }
86001
86002diff --git a/localversion-grsec b/localversion-grsec
86003new file mode 100644
86004index 0000000..7cd6065
86005--- /dev/null
86006+++ b/localversion-grsec
86007@@ -0,0 +1 @@
86008+-grsec
86009diff --git a/mm/Kconfig b/mm/Kconfig
86010index 8028dcc..9a2dbe7 100644
86011--- a/mm/Kconfig
86012+++ b/mm/Kconfig
86013@@ -317,10 +317,10 @@ config KSM
86014 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
86015
86016 config DEFAULT_MMAP_MIN_ADDR
86017- int "Low address space to protect from user allocation"
86018+ int "Low address space to protect from user allocation"
86019 depends on MMU
86020- default 4096
86021- help
86022+ default 65536
86023+ help
86024 This is the portion of low virtual memory which should be protected
86025 from userspace allocation. Keeping a user from writing to low pages
86026 can help reduce the impact of kernel NULL pointer bugs.
86027@@ -351,7 +351,7 @@ config MEMORY_FAILURE
86028
86029 config HWPOISON_INJECT
86030 tristate "HWPoison pages injector"
86031- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
86032+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
86033 select PROC_PAGE_MONITOR
86034
86035 config NOMMU_INITIAL_TRIM_EXCESS
86036diff --git a/mm/backing-dev.c b/mm/backing-dev.c
86037index e04454c..ca5be3e 100644
86038--- a/mm/backing-dev.c
86039+++ b/mm/backing-dev.c
86040@@ -12,7 +12,7 @@
86041 #include <linux/device.h>
86042 #include <trace/events/writeback.h>
86043
86044-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
86045+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
86046
86047 struct backing_dev_info default_backing_dev_info = {
86048 .name = "default",
86049@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
86050 return err;
86051
86052 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
86053- atomic_long_inc_return(&bdi_seq));
86054+ atomic_long_inc_return_unchecked(&bdi_seq));
86055 if (err) {
86056 bdi_destroy(bdi);
86057 return err;
86058diff --git a/mm/filemap.c b/mm/filemap.c
86059index 4b51ac1..5aa90ff 100644
86060--- a/mm/filemap.c
86061+++ b/mm/filemap.c
86062@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
86063 struct address_space *mapping = file->f_mapping;
86064
86065 if (!mapping->a_ops->readpage)
86066- return -ENOEXEC;
86067+ return -ENODEV;
86068 file_accessed(file);
86069 vma->vm_ops = &generic_file_vm_ops;
86070 return 0;
86071@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
86072
86073 while (bytes) {
86074 char __user *buf = iov->iov_base + base;
86075- int copy = min(bytes, iov->iov_len - base);
86076+ size_t copy = min(bytes, iov->iov_len - base);
86077
86078 base = 0;
86079 left = __copy_from_user_inatomic(vaddr, buf, copy);
86080@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
86081 BUG_ON(!in_atomic());
86082 kaddr = kmap_atomic(page);
86083 if (likely(i->nr_segs == 1)) {
86084- int left;
86085+ size_t left;
86086 char __user *buf = i->iov->iov_base + i->iov_offset;
86087 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
86088 copied = bytes - left;
86089@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
86090
86091 kaddr = kmap(page);
86092 if (likely(i->nr_segs == 1)) {
86093- int left;
86094+ size_t left;
86095 char __user *buf = i->iov->iov_base + i->iov_offset;
86096 left = __copy_from_user(kaddr + offset, buf, bytes);
86097 copied = bytes - left;
86098@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
86099 * zero-length segments (without overruning the iovec).
86100 */
86101 while (bytes || unlikely(i->count && !iov->iov_len)) {
86102- int copy;
86103+ size_t copy;
86104
86105 copy = min(bytes, iov->iov_len - base);
86106 BUG_ON(!i->count || i->count < copy);
86107@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
86108 *pos = i_size_read(inode);
86109
86110 if (limit != RLIM_INFINITY) {
86111+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
86112 if (*pos >= limit) {
86113 send_sig(SIGXFSZ, current, 0);
86114 return -EFBIG;
86115diff --git a/mm/fremap.c b/mm/fremap.c
86116index 5bff081..d8189a9 100644
86117--- a/mm/fremap.c
86118+++ b/mm/fremap.c
86119@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
86120 retry:
86121 vma = find_vma(mm, start);
86122
86123+#ifdef CONFIG_PAX_SEGMEXEC
86124+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
86125+ goto out;
86126+#endif
86127+
86128 /*
86129 * Make sure the vma is shared, that it supports prefaulting,
86130 * and that the remapped range is valid and fully within
86131diff --git a/mm/highmem.c b/mm/highmem.c
86132index b32b70c..e512eb0 100644
86133--- a/mm/highmem.c
86134+++ b/mm/highmem.c
86135@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
86136 * So no dangers, even with speculative execution.
86137 */
86138 page = pte_page(pkmap_page_table[i]);
86139+ pax_open_kernel();
86140 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
86141-
86142+ pax_close_kernel();
86143 set_page_address(page, NULL);
86144 need_flush = 1;
86145 }
86146@@ -198,9 +199,11 @@ start:
86147 }
86148 }
86149 vaddr = PKMAP_ADDR(last_pkmap_nr);
86150+
86151+ pax_open_kernel();
86152 set_pte_at(&init_mm, vaddr,
86153 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
86154-
86155+ pax_close_kernel();
86156 pkmap_count[last_pkmap_nr] = 1;
86157 set_page_address(page, (void *)vaddr);
86158
86159diff --git a/mm/hugetlb.c b/mm/hugetlb.c
86160index b60f330..ee7de7e 100644
86161--- a/mm/hugetlb.c
86162+++ b/mm/hugetlb.c
86163@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
86164 struct hstate *h = &default_hstate;
86165 unsigned long tmp;
86166 int ret;
86167+ ctl_table_no_const hugetlb_table;
86168
86169 tmp = h->max_huge_pages;
86170
86171 if (write && h->order >= MAX_ORDER)
86172 return -EINVAL;
86173
86174- table->data = &tmp;
86175- table->maxlen = sizeof(unsigned long);
86176- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86177+ hugetlb_table = *table;
86178+ hugetlb_table.data = &tmp;
86179+ hugetlb_table.maxlen = sizeof(unsigned long);
86180+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86181 if (ret)
86182 goto out;
86183
86184@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
86185 struct hstate *h = &default_hstate;
86186 unsigned long tmp;
86187 int ret;
86188+ ctl_table_no_const hugetlb_table;
86189
86190 tmp = h->nr_overcommit_huge_pages;
86191
86192 if (write && h->order >= MAX_ORDER)
86193 return -EINVAL;
86194
86195- table->data = &tmp;
86196- table->maxlen = sizeof(unsigned long);
86197- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86198+ hugetlb_table = *table;
86199+ hugetlb_table.data = &tmp;
86200+ hugetlb_table.maxlen = sizeof(unsigned long);
86201+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86202 if (ret)
86203 goto out;
86204
86205@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86206 return 1;
86207 }
86208
86209+#ifdef CONFIG_PAX_SEGMEXEC
86210+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86211+{
86212+ struct mm_struct *mm = vma->vm_mm;
86213+ struct vm_area_struct *vma_m;
86214+ unsigned long address_m;
86215+ pte_t *ptep_m;
86216+
86217+ vma_m = pax_find_mirror_vma(vma);
86218+ if (!vma_m)
86219+ return;
86220+
86221+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86222+ address_m = address + SEGMEXEC_TASK_SIZE;
86223+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86224+ get_page(page_m);
86225+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86226+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86227+}
86228+#endif
86229+
86230 /*
86231 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86232 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86233@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86234 make_huge_pte(vma, new_page, 1));
86235 page_remove_rmap(old_page);
86236 hugepage_add_new_anon_rmap(new_page, vma, address);
86237+
86238+#ifdef CONFIG_PAX_SEGMEXEC
86239+ pax_mirror_huge_pte(vma, address, new_page);
86240+#endif
86241+
86242 /* Make the old page be freed below */
86243 new_page = old_page;
86244 }
86245@@ -2821,6 +2851,10 @@ retry:
86246 && (vma->vm_flags & VM_SHARED)));
86247 set_huge_pte_at(mm, address, ptep, new_pte);
86248
86249+#ifdef CONFIG_PAX_SEGMEXEC
86250+ pax_mirror_huge_pte(vma, address, page);
86251+#endif
86252+
86253 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86254 /* Optimization, do the COW without a second fault */
86255 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86256@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86257 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86258 struct hstate *h = hstate_vma(vma);
86259
86260+#ifdef CONFIG_PAX_SEGMEXEC
86261+ struct vm_area_struct *vma_m;
86262+#endif
86263+
86264 address &= huge_page_mask(h);
86265
86266 ptep = huge_pte_offset(mm, address);
86267@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86268 VM_FAULT_SET_HINDEX(hstate_index(h));
86269 }
86270
86271+#ifdef CONFIG_PAX_SEGMEXEC
86272+ vma_m = pax_find_mirror_vma(vma);
86273+ if (vma_m) {
86274+ unsigned long address_m;
86275+
86276+ if (vma->vm_start > vma_m->vm_start) {
86277+ address_m = address;
86278+ address -= SEGMEXEC_TASK_SIZE;
86279+ vma = vma_m;
86280+ h = hstate_vma(vma);
86281+ } else
86282+ address_m = address + SEGMEXEC_TASK_SIZE;
86283+
86284+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86285+ return VM_FAULT_OOM;
86286+ address_m &= HPAGE_MASK;
86287+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86288+ }
86289+#endif
86290+
86291 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86292 if (!ptep)
86293 return VM_FAULT_OOM;
86294diff --git a/mm/internal.h b/mm/internal.h
86295index 4390ac6..fc60373c 100644
86296--- a/mm/internal.h
86297+++ b/mm/internal.h
86298@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86299 * in mm/page_alloc.c
86300 */
86301 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86302+extern void free_compound_page(struct page *page);
86303 extern void prep_compound_page(struct page *page, unsigned long order);
86304 #ifdef CONFIG_MEMORY_FAILURE
86305 extern bool is_free_buddy_page(struct page *page);
86306@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86307
86308 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86309 unsigned long, unsigned long,
86310- unsigned long, unsigned long);
86311+ unsigned long, unsigned long) __intentional_overflow(-1);
86312
86313 extern void set_pageblock_order(void);
86314 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86315diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86316index c8d7f31..2dbeffd 100644
86317--- a/mm/kmemleak.c
86318+++ b/mm/kmemleak.c
86319@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86320
86321 for (i = 0; i < object->trace_len; i++) {
86322 void *ptr = (void *)object->trace[i];
86323- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86324+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86325 }
86326 }
86327
86328@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86329 return -ENOMEM;
86330 }
86331
86332- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86333+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86334 &kmemleak_fops);
86335 if (!dentry)
86336 pr_warning("Failed to create the debugfs kmemleak file\n");
86337diff --git a/mm/maccess.c b/mm/maccess.c
86338index d53adf9..03a24bf 100644
86339--- a/mm/maccess.c
86340+++ b/mm/maccess.c
86341@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86342 set_fs(KERNEL_DS);
86343 pagefault_disable();
86344 ret = __copy_from_user_inatomic(dst,
86345- (__force const void __user *)src, size);
86346+ (const void __force_user *)src, size);
86347 pagefault_enable();
86348 set_fs(old_fs);
86349
86350@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86351
86352 set_fs(KERNEL_DS);
86353 pagefault_disable();
86354- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86355+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86356 pagefault_enable();
86357 set_fs(old_fs);
86358
86359diff --git a/mm/madvise.c b/mm/madvise.c
86360index 7055883..aafb1ed 100644
86361--- a/mm/madvise.c
86362+++ b/mm/madvise.c
86363@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86364 pgoff_t pgoff;
86365 unsigned long new_flags = vma->vm_flags;
86366
86367+#ifdef CONFIG_PAX_SEGMEXEC
86368+ struct vm_area_struct *vma_m;
86369+#endif
86370+
86371 switch (behavior) {
86372 case MADV_NORMAL:
86373 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86374@@ -126,6 +130,13 @@ success:
86375 /*
86376 * vm_flags is protected by the mmap_sem held in write mode.
86377 */
86378+
86379+#ifdef CONFIG_PAX_SEGMEXEC
86380+ vma_m = pax_find_mirror_vma(vma);
86381+ if (vma_m)
86382+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86383+#endif
86384+
86385 vma->vm_flags = new_flags;
86386
86387 out:
86388@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86389 struct vm_area_struct ** prev,
86390 unsigned long start, unsigned long end)
86391 {
86392+
86393+#ifdef CONFIG_PAX_SEGMEXEC
86394+ struct vm_area_struct *vma_m;
86395+#endif
86396+
86397 *prev = vma;
86398 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86399 return -EINVAL;
86400@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86401 zap_page_range(vma, start, end - start, &details);
86402 } else
86403 zap_page_range(vma, start, end - start, NULL);
86404+
86405+#ifdef CONFIG_PAX_SEGMEXEC
86406+ vma_m = pax_find_mirror_vma(vma);
86407+ if (vma_m) {
86408+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86409+ struct zap_details details = {
86410+ .nonlinear_vma = vma_m,
86411+ .last_index = ULONG_MAX,
86412+ };
86413+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86414+ } else
86415+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86416+ }
86417+#endif
86418+
86419 return 0;
86420 }
86421
86422@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86423 if (end < start)
86424 return error;
86425
86426+#ifdef CONFIG_PAX_SEGMEXEC
86427+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86428+ if (end > SEGMEXEC_TASK_SIZE)
86429+ return error;
86430+ } else
86431+#endif
86432+
86433+ if (end > TASK_SIZE)
86434+ return error;
86435+
86436 error = 0;
86437 if (end == start)
86438 return error;
86439diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86440index 2c13aa7..64cbc3f 100644
86441--- a/mm/memory-failure.c
86442+++ b/mm/memory-failure.c
86443@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86444
86445 int sysctl_memory_failure_recovery __read_mostly = 1;
86446
86447-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86448+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86449
86450 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86451
86452@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86453 pfn, t->comm, t->pid);
86454 si.si_signo = SIGBUS;
86455 si.si_errno = 0;
86456- si.si_addr = (void *)addr;
86457+ si.si_addr = (void __user *)addr;
86458 #ifdef __ARCH_SI_TRAPNO
86459 si.si_trapno = trapno;
86460 #endif
86461@@ -760,7 +760,7 @@ static struct page_state {
86462 unsigned long res;
86463 char *msg;
86464 int (*action)(struct page *p, unsigned long pfn);
86465-} error_states[] = {
86466+} __do_const error_states[] = {
86467 { reserved, reserved, "reserved kernel", me_kernel },
86468 /*
86469 * free pages are specially detected outside this table:
86470@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86471 nr_pages = 1 << compound_order(hpage);
86472 else /* normal page or thp */
86473 nr_pages = 1;
86474- atomic_long_add(nr_pages, &num_poisoned_pages);
86475+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86476
86477 /*
86478 * We need/can do nothing about count=0 pages.
86479@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86480 if (!PageHWPoison(hpage)
86481 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86482 || (p != hpage && TestSetPageHWPoison(hpage))) {
86483- atomic_long_sub(nr_pages, &num_poisoned_pages);
86484+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86485 return 0;
86486 }
86487 set_page_hwpoison_huge_page(hpage);
86488@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86489 }
86490 if (hwpoison_filter(p)) {
86491 if (TestClearPageHWPoison(p))
86492- atomic_long_sub(nr_pages, &num_poisoned_pages);
86493+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86494 unlock_page(hpage);
86495 put_page(hpage);
86496 return 0;
86497@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86498 return 0;
86499 }
86500 if (TestClearPageHWPoison(p))
86501- atomic_long_sub(nr_pages, &num_poisoned_pages);
86502+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86503 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86504 return 0;
86505 }
86506@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86507 */
86508 if (TestClearPageHWPoison(page)) {
86509 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86510- atomic_long_sub(nr_pages, &num_poisoned_pages);
86511+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86512 freeit = 1;
86513 if (PageHuge(page))
86514 clear_page_hwpoison_huge_page(page);
86515@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86516 } else {
86517 set_page_hwpoison_huge_page(hpage);
86518 dequeue_hwpoisoned_huge_page(hpage);
86519- atomic_long_add(1 << compound_trans_order(hpage),
86520+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86521 &num_poisoned_pages);
86522 }
86523 return ret;
86524@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86525 if (PageHuge(page)) {
86526 set_page_hwpoison_huge_page(hpage);
86527 dequeue_hwpoisoned_huge_page(hpage);
86528- atomic_long_add(1 << compound_trans_order(hpage),
86529+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86530 &num_poisoned_pages);
86531 } else {
86532 SetPageHWPoison(page);
86533- atomic_long_inc(&num_poisoned_pages);
86534+ atomic_long_inc_unchecked(&num_poisoned_pages);
86535 }
86536 }
86537 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86538@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86539 put_page(page);
86540 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86541 SetPageHWPoison(page);
86542- atomic_long_inc(&num_poisoned_pages);
86543+ atomic_long_inc_unchecked(&num_poisoned_pages);
86544 return 0;
86545 }
86546
86547@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86548 if (!is_free_buddy_page(page))
86549 pr_info("soft offline: %#lx: page leaked\n",
86550 pfn);
86551- atomic_long_inc(&num_poisoned_pages);
86552+ atomic_long_inc_unchecked(&num_poisoned_pages);
86553 }
86554 } else {
86555 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86556diff --git a/mm/memory.c b/mm/memory.c
86557index af84bc0..2ed0816 100644
86558--- a/mm/memory.c
86559+++ b/mm/memory.c
86560@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86561 free_pte_range(tlb, pmd, addr);
86562 } while (pmd++, addr = next, addr != end);
86563
86564+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86565 start &= PUD_MASK;
86566 if (start < floor)
86567 return;
86568@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86569 pmd = pmd_offset(pud, start);
86570 pud_clear(pud);
86571 pmd_free_tlb(tlb, pmd, start);
86572+#endif
86573+
86574 }
86575
86576 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86577@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86578 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86579 } while (pud++, addr = next, addr != end);
86580
86581+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86582 start &= PGDIR_MASK;
86583 if (start < floor)
86584 return;
86585@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86586 pud = pud_offset(pgd, start);
86587 pgd_clear(pgd);
86588 pud_free_tlb(tlb, pud, start);
86589+#endif
86590+
86591 }
86592
86593 /*
86594@@ -1645,12 +1651,6 @@ no_page_table:
86595 return page;
86596 }
86597
86598-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86599-{
86600- return stack_guard_page_start(vma, addr) ||
86601- stack_guard_page_end(vma, addr+PAGE_SIZE);
86602-}
86603-
86604 /**
86605 * __get_user_pages() - pin user pages in memory
86606 * @tsk: task_struct of target task
86607@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86608
86609 i = 0;
86610
86611- do {
86612+ while (nr_pages) {
86613 struct vm_area_struct *vma;
86614
86615- vma = find_extend_vma(mm, start);
86616+ vma = find_vma(mm, start);
86617 if (!vma && in_gate_area(mm, start)) {
86618 unsigned long pg = start & PAGE_MASK;
86619 pgd_t *pgd;
86620@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86621 goto next_page;
86622 }
86623
86624- if (!vma ||
86625+ if (!vma || start < vma->vm_start ||
86626 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86627 !(vm_flags & vma->vm_flags))
86628 return i ? : -EFAULT;
86629@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86630 int ret;
86631 unsigned int fault_flags = 0;
86632
86633- /* For mlock, just skip the stack guard page. */
86634- if (foll_flags & FOLL_MLOCK) {
86635- if (stack_guard_page(vma, start))
86636- goto next_page;
86637- }
86638 if (foll_flags & FOLL_WRITE)
86639 fault_flags |= FAULT_FLAG_WRITE;
86640 if (nonblocking)
86641@@ -1902,7 +1897,7 @@ next_page:
86642 start += page_increm * PAGE_SIZE;
86643 nr_pages -= page_increm;
86644 } while (nr_pages && start < vma->vm_end);
86645- } while (nr_pages);
86646+ }
86647 return i;
86648 }
86649 EXPORT_SYMBOL(__get_user_pages);
86650@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86651 page_add_file_rmap(page);
86652 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86653
86654+#ifdef CONFIG_PAX_SEGMEXEC
86655+ pax_mirror_file_pte(vma, addr, page, ptl);
86656+#endif
86657+
86658 retval = 0;
86659 pte_unmap_unlock(pte, ptl);
86660 return retval;
86661@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86662 if (!page_count(page))
86663 return -EINVAL;
86664 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86665+
86666+#ifdef CONFIG_PAX_SEGMEXEC
86667+ struct vm_area_struct *vma_m;
86668+#endif
86669+
86670 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86671 BUG_ON(vma->vm_flags & VM_PFNMAP);
86672 vma->vm_flags |= VM_MIXEDMAP;
86673+
86674+#ifdef CONFIG_PAX_SEGMEXEC
86675+ vma_m = pax_find_mirror_vma(vma);
86676+ if (vma_m)
86677+ vma_m->vm_flags |= VM_MIXEDMAP;
86678+#endif
86679+
86680 }
86681 return insert_page(vma, addr, page, vma->vm_page_prot);
86682 }
86683@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86684 unsigned long pfn)
86685 {
86686 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86687+ BUG_ON(vma->vm_mirror);
86688
86689 if (addr < vma->vm_start || addr >= vma->vm_end)
86690 return -EFAULT;
86691@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86692
86693 BUG_ON(pud_huge(*pud));
86694
86695- pmd = pmd_alloc(mm, pud, addr);
86696+ pmd = (mm == &init_mm) ?
86697+ pmd_alloc_kernel(mm, pud, addr) :
86698+ pmd_alloc(mm, pud, addr);
86699 if (!pmd)
86700 return -ENOMEM;
86701 do {
86702@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86703 unsigned long next;
86704 int err;
86705
86706- pud = pud_alloc(mm, pgd, addr);
86707+ pud = (mm == &init_mm) ?
86708+ pud_alloc_kernel(mm, pgd, addr) :
86709+ pud_alloc(mm, pgd, addr);
86710 if (!pud)
86711 return -ENOMEM;
86712 do {
86713@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86714 copy_user_highpage(dst, src, va, vma);
86715 }
86716
86717+#ifdef CONFIG_PAX_SEGMEXEC
86718+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86719+{
86720+ struct mm_struct *mm = vma->vm_mm;
86721+ spinlock_t *ptl;
86722+ pte_t *pte, entry;
86723+
86724+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86725+ entry = *pte;
86726+ if (!pte_present(entry)) {
86727+ if (!pte_none(entry)) {
86728+ BUG_ON(pte_file(entry));
86729+ free_swap_and_cache(pte_to_swp_entry(entry));
86730+ pte_clear_not_present_full(mm, address, pte, 0);
86731+ }
86732+ } else {
86733+ struct page *page;
86734+
86735+ flush_cache_page(vma, address, pte_pfn(entry));
86736+ entry = ptep_clear_flush(vma, address, pte);
86737+ BUG_ON(pte_dirty(entry));
86738+ page = vm_normal_page(vma, address, entry);
86739+ if (page) {
86740+ update_hiwater_rss(mm);
86741+ if (PageAnon(page))
86742+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86743+ else
86744+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86745+ page_remove_rmap(page);
86746+ page_cache_release(page);
86747+ }
86748+ }
86749+ pte_unmap_unlock(pte, ptl);
86750+}
86751+
86752+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86753+ *
86754+ * the ptl of the lower mapped page is held on entry and is not released on exit
86755+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86756+ */
86757+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86758+{
86759+ struct mm_struct *mm = vma->vm_mm;
86760+ unsigned long address_m;
86761+ spinlock_t *ptl_m;
86762+ struct vm_area_struct *vma_m;
86763+ pmd_t *pmd_m;
86764+ pte_t *pte_m, entry_m;
86765+
86766+ BUG_ON(!page_m || !PageAnon(page_m));
86767+
86768+ vma_m = pax_find_mirror_vma(vma);
86769+ if (!vma_m)
86770+ return;
86771+
86772+ BUG_ON(!PageLocked(page_m));
86773+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86774+ address_m = address + SEGMEXEC_TASK_SIZE;
86775+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86776+ pte_m = pte_offset_map(pmd_m, address_m);
86777+ ptl_m = pte_lockptr(mm, pmd_m);
86778+ if (ptl != ptl_m) {
86779+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86780+ if (!pte_none(*pte_m))
86781+ goto out;
86782+ }
86783+
86784+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86785+ page_cache_get(page_m);
86786+ page_add_anon_rmap(page_m, vma_m, address_m);
86787+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86788+ set_pte_at(mm, address_m, pte_m, entry_m);
86789+ update_mmu_cache(vma_m, address_m, pte_m);
86790+out:
86791+ if (ptl != ptl_m)
86792+ spin_unlock(ptl_m);
86793+ pte_unmap(pte_m);
86794+ unlock_page(page_m);
86795+}
86796+
86797+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86798+{
86799+ struct mm_struct *mm = vma->vm_mm;
86800+ unsigned long address_m;
86801+ spinlock_t *ptl_m;
86802+ struct vm_area_struct *vma_m;
86803+ pmd_t *pmd_m;
86804+ pte_t *pte_m, entry_m;
86805+
86806+ BUG_ON(!page_m || PageAnon(page_m));
86807+
86808+ vma_m = pax_find_mirror_vma(vma);
86809+ if (!vma_m)
86810+ return;
86811+
86812+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86813+ address_m = address + SEGMEXEC_TASK_SIZE;
86814+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86815+ pte_m = pte_offset_map(pmd_m, address_m);
86816+ ptl_m = pte_lockptr(mm, pmd_m);
86817+ if (ptl != ptl_m) {
86818+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86819+ if (!pte_none(*pte_m))
86820+ goto out;
86821+ }
86822+
86823+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86824+ page_cache_get(page_m);
86825+ page_add_file_rmap(page_m);
86826+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86827+ set_pte_at(mm, address_m, pte_m, entry_m);
86828+ update_mmu_cache(vma_m, address_m, pte_m);
86829+out:
86830+ if (ptl != ptl_m)
86831+ spin_unlock(ptl_m);
86832+ pte_unmap(pte_m);
86833+}
86834+
86835+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86836+{
86837+ struct mm_struct *mm = vma->vm_mm;
86838+ unsigned long address_m;
86839+ spinlock_t *ptl_m;
86840+ struct vm_area_struct *vma_m;
86841+ pmd_t *pmd_m;
86842+ pte_t *pte_m, entry_m;
86843+
86844+ vma_m = pax_find_mirror_vma(vma);
86845+ if (!vma_m)
86846+ return;
86847+
86848+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86849+ address_m = address + SEGMEXEC_TASK_SIZE;
86850+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86851+ pte_m = pte_offset_map(pmd_m, address_m);
86852+ ptl_m = pte_lockptr(mm, pmd_m);
86853+ if (ptl != ptl_m) {
86854+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86855+ if (!pte_none(*pte_m))
86856+ goto out;
86857+ }
86858+
86859+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86860+ set_pte_at(mm, address_m, pte_m, entry_m);
86861+out:
86862+ if (ptl != ptl_m)
86863+ spin_unlock(ptl_m);
86864+ pte_unmap(pte_m);
86865+}
86866+
86867+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86868+{
86869+ struct page *page_m;
86870+ pte_t entry;
86871+
86872+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86873+ goto out;
86874+
86875+ entry = *pte;
86876+ page_m = vm_normal_page(vma, address, entry);
86877+ if (!page_m)
86878+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86879+ else if (PageAnon(page_m)) {
86880+ if (pax_find_mirror_vma(vma)) {
86881+ pte_unmap_unlock(pte, ptl);
86882+ lock_page(page_m);
86883+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86884+ if (pte_same(entry, *pte))
86885+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86886+ else
86887+ unlock_page(page_m);
86888+ }
86889+ } else
86890+ pax_mirror_file_pte(vma, address, page_m, ptl);
86891+
86892+out:
86893+ pte_unmap_unlock(pte, ptl);
86894+}
86895+#endif
86896+
86897 /*
86898 * This routine handles present pages, when users try to write
86899 * to a shared page. It is done by copying the page to a new address
86900@@ -2809,6 +3005,12 @@ gotten:
86901 */
86902 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86903 if (likely(pte_same(*page_table, orig_pte))) {
86904+
86905+#ifdef CONFIG_PAX_SEGMEXEC
86906+ if (pax_find_mirror_vma(vma))
86907+ BUG_ON(!trylock_page(new_page));
86908+#endif
86909+
86910 if (old_page) {
86911 if (!PageAnon(old_page)) {
86912 dec_mm_counter_fast(mm, MM_FILEPAGES);
86913@@ -2860,6 +3062,10 @@ gotten:
86914 page_remove_rmap(old_page);
86915 }
86916
86917+#ifdef CONFIG_PAX_SEGMEXEC
86918+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86919+#endif
86920+
86921 /* Free the old page.. */
86922 new_page = old_page;
86923 ret |= VM_FAULT_WRITE;
86924@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86925 swap_free(entry);
86926 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86927 try_to_free_swap(page);
86928+
86929+#ifdef CONFIG_PAX_SEGMEXEC
86930+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86931+#endif
86932+
86933 unlock_page(page);
86934 if (page != swapcache) {
86935 /*
86936@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86937
86938 /* No need to invalidate - it was non-present before */
86939 update_mmu_cache(vma, address, page_table);
86940+
86941+#ifdef CONFIG_PAX_SEGMEXEC
86942+ pax_mirror_anon_pte(vma, address, page, ptl);
86943+#endif
86944+
86945 unlock:
86946 pte_unmap_unlock(page_table, ptl);
86947 out:
86948@@ -3179,40 +3395,6 @@ out_release:
86949 }
86950
86951 /*
86952- * This is like a special single-page "expand_{down|up}wards()",
86953- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86954- * doesn't hit another vma.
86955- */
86956-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86957-{
86958- address &= PAGE_MASK;
86959- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86960- struct vm_area_struct *prev = vma->vm_prev;
86961-
86962- /*
86963- * Is there a mapping abutting this one below?
86964- *
86965- * That's only ok if it's the same stack mapping
86966- * that has gotten split..
86967- */
86968- if (prev && prev->vm_end == address)
86969- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86970-
86971- expand_downwards(vma, address - PAGE_SIZE);
86972- }
86973- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86974- struct vm_area_struct *next = vma->vm_next;
86975-
86976- /* As VM_GROWSDOWN but s/below/above/ */
86977- if (next && next->vm_start == address + PAGE_SIZE)
86978- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86979-
86980- expand_upwards(vma, address + PAGE_SIZE);
86981- }
86982- return 0;
86983-}
86984-
86985-/*
86986 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86987 * but allow concurrent faults), and pte mapped but not yet locked.
86988 * We return with mmap_sem still held, but pte unmapped and unlocked.
86989@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86990 unsigned long address, pte_t *page_table, pmd_t *pmd,
86991 unsigned int flags)
86992 {
86993- struct page *page;
86994+ struct page *page = NULL;
86995 spinlock_t *ptl;
86996 pte_t entry;
86997
86998- pte_unmap(page_table);
86999-
87000- /* Check if we need to add a guard page to the stack */
87001- if (check_stack_guard_page(vma, address) < 0)
87002- return VM_FAULT_SIGBUS;
87003-
87004- /* Use the zero-page for reads */
87005 if (!(flags & FAULT_FLAG_WRITE)) {
87006 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
87007 vma->vm_page_prot));
87008- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
87009+ ptl = pte_lockptr(mm, pmd);
87010+ spin_lock(ptl);
87011 if (!pte_none(*page_table))
87012 goto unlock;
87013 goto setpte;
87014 }
87015
87016 /* Allocate our own private page. */
87017+ pte_unmap(page_table);
87018+
87019 if (unlikely(anon_vma_prepare(vma)))
87020 goto oom;
87021 page = alloc_zeroed_user_highpage_movable(vma, address);
87022@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
87023 if (!pte_none(*page_table))
87024 goto release;
87025
87026+#ifdef CONFIG_PAX_SEGMEXEC
87027+ if (pax_find_mirror_vma(vma))
87028+ BUG_ON(!trylock_page(page));
87029+#endif
87030+
87031 inc_mm_counter_fast(mm, MM_ANONPAGES);
87032 page_add_new_anon_rmap(page, vma, address);
87033 setpte:
87034@@ -3272,6 +3455,12 @@ setpte:
87035
87036 /* No need to invalidate - it was non-present before */
87037 update_mmu_cache(vma, address, page_table);
87038+
87039+#ifdef CONFIG_PAX_SEGMEXEC
87040+ if (page)
87041+ pax_mirror_anon_pte(vma, address, page, ptl);
87042+#endif
87043+
87044 unlock:
87045 pte_unmap_unlock(page_table, ptl);
87046 return 0;
87047@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87048 */
87049 /* Only go through if we didn't race with anybody else... */
87050 if (likely(pte_same(*page_table, orig_pte))) {
87051+
87052+#ifdef CONFIG_PAX_SEGMEXEC
87053+ if (anon && pax_find_mirror_vma(vma))
87054+ BUG_ON(!trylock_page(page));
87055+#endif
87056+
87057 flush_icache_page(vma, page);
87058 entry = mk_pte(page, vma->vm_page_prot);
87059 if (flags & FAULT_FLAG_WRITE)
87060@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87061
87062 /* no need to invalidate: a not-present page won't be cached */
87063 update_mmu_cache(vma, address, page_table);
87064+
87065+#ifdef CONFIG_PAX_SEGMEXEC
87066+ if (anon)
87067+ pax_mirror_anon_pte(vma, address, page, ptl);
87068+ else
87069+ pax_mirror_file_pte(vma, address, page, ptl);
87070+#endif
87071+
87072 } else {
87073 if (cow_page)
87074 mem_cgroup_uncharge_page(cow_page);
87075@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
87076 if (flags & FAULT_FLAG_WRITE)
87077 flush_tlb_fix_spurious_fault(vma, address);
87078 }
87079+
87080+#ifdef CONFIG_PAX_SEGMEXEC
87081+ pax_mirror_pte(vma, address, pte, pmd, ptl);
87082+ return 0;
87083+#endif
87084+
87085 unlock:
87086 pte_unmap_unlock(pte, ptl);
87087 return 0;
87088@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87089 pmd_t *pmd;
87090 pte_t *pte;
87091
87092+#ifdef CONFIG_PAX_SEGMEXEC
87093+ struct vm_area_struct *vma_m;
87094+#endif
87095+
87096 __set_current_state(TASK_RUNNING);
87097
87098 count_vm_event(PGFAULT);
87099@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87100 if (unlikely(is_vm_hugetlb_page(vma)))
87101 return hugetlb_fault(mm, vma, address, flags);
87102
87103+#ifdef CONFIG_PAX_SEGMEXEC
87104+ vma_m = pax_find_mirror_vma(vma);
87105+ if (vma_m) {
87106+ unsigned long address_m;
87107+ pgd_t *pgd_m;
87108+ pud_t *pud_m;
87109+ pmd_t *pmd_m;
87110+
87111+ if (vma->vm_start > vma_m->vm_start) {
87112+ address_m = address;
87113+ address -= SEGMEXEC_TASK_SIZE;
87114+ vma = vma_m;
87115+ } else
87116+ address_m = address + SEGMEXEC_TASK_SIZE;
87117+
87118+ pgd_m = pgd_offset(mm, address_m);
87119+ pud_m = pud_alloc(mm, pgd_m, address_m);
87120+ if (!pud_m)
87121+ return VM_FAULT_OOM;
87122+ pmd_m = pmd_alloc(mm, pud_m, address_m);
87123+ if (!pmd_m)
87124+ return VM_FAULT_OOM;
87125+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
87126+ return VM_FAULT_OOM;
87127+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
87128+ }
87129+#endif
87130+
87131 retry:
87132 pgd = pgd_offset(mm, address);
87133 pud = pud_alloc(mm, pgd, address);
87134@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
87135 spin_unlock(&mm->page_table_lock);
87136 return 0;
87137 }
87138+
87139+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
87140+{
87141+ pud_t *new = pud_alloc_one(mm, address);
87142+ if (!new)
87143+ return -ENOMEM;
87144+
87145+ smp_wmb(); /* See comment in __pte_alloc */
87146+
87147+ spin_lock(&mm->page_table_lock);
87148+ if (pgd_present(*pgd)) /* Another has populated it */
87149+ pud_free(mm, new);
87150+ else
87151+ pgd_populate_kernel(mm, pgd, new);
87152+ spin_unlock(&mm->page_table_lock);
87153+ return 0;
87154+}
87155 #endif /* __PAGETABLE_PUD_FOLDED */
87156
87157 #ifndef __PAGETABLE_PMD_FOLDED
87158@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
87159 spin_unlock(&mm->page_table_lock);
87160 return 0;
87161 }
87162+
87163+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
87164+{
87165+ pmd_t *new = pmd_alloc_one(mm, address);
87166+ if (!new)
87167+ return -ENOMEM;
87168+
87169+ smp_wmb(); /* See comment in __pte_alloc */
87170+
87171+ spin_lock(&mm->page_table_lock);
87172+#ifndef __ARCH_HAS_4LEVEL_HACK
87173+ if (pud_present(*pud)) /* Another has populated it */
87174+ pmd_free(mm, new);
87175+ else
87176+ pud_populate_kernel(mm, pud, new);
87177+#else
87178+ if (pgd_present(*pud)) /* Another has populated it */
87179+ pmd_free(mm, new);
87180+ else
87181+ pgd_populate_kernel(mm, pud, new);
87182+#endif /* __ARCH_HAS_4LEVEL_HACK */
87183+ spin_unlock(&mm->page_table_lock);
87184+ return 0;
87185+}
87186 #endif /* __PAGETABLE_PMD_FOLDED */
87187
87188 #if !defined(__HAVE_ARCH_GATE_AREA)
87189@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
87190 gate_vma.vm_start = FIXADDR_USER_START;
87191 gate_vma.vm_end = FIXADDR_USER_END;
87192 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87193- gate_vma.vm_page_prot = __P101;
87194+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87195
87196 return 0;
87197 }
87198@@ -4059,8 +4341,8 @@ out:
87199 return ret;
87200 }
87201
87202-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87203- void *buf, int len, int write)
87204+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87205+ void *buf, size_t len, int write)
87206 {
87207 resource_size_t phys_addr;
87208 unsigned long prot = 0;
87209@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87210 * Access another process' address space as given in mm. If non-NULL, use the
87211 * given task for page fault accounting.
87212 */
87213-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87214- unsigned long addr, void *buf, int len, int write)
87215+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87216+ unsigned long addr, void *buf, size_t len, int write)
87217 {
87218 struct vm_area_struct *vma;
87219 void *old_buf = buf;
87220@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87221 down_read(&mm->mmap_sem);
87222 /* ignore errors, just check how much was successfully transferred */
87223 while (len) {
87224- int bytes, ret, offset;
87225+ ssize_t bytes, ret, offset;
87226 void *maddr;
87227 struct page *page = NULL;
87228
87229@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87230 *
87231 * The caller must hold a reference on @mm.
87232 */
87233-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87234- void *buf, int len, int write)
87235+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87236+ void *buf, size_t len, int write)
87237 {
87238 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87239 }
87240@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87241 * Source/target buffer must be kernel space,
87242 * Do not walk the page table directly, use get_user_pages
87243 */
87244-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87245- void *buf, int len, int write)
87246+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87247+ void *buf, size_t len, int write)
87248 {
87249 struct mm_struct *mm;
87250- int ret;
87251+ ssize_t ret;
87252
87253 mm = get_task_mm(tsk);
87254 if (!mm)
87255diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87256index 4baf12e..5497066 100644
87257--- a/mm/mempolicy.c
87258+++ b/mm/mempolicy.c
87259@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87260 unsigned long vmstart;
87261 unsigned long vmend;
87262
87263+#ifdef CONFIG_PAX_SEGMEXEC
87264+ struct vm_area_struct *vma_m;
87265+#endif
87266+
87267 vma = find_vma(mm, start);
87268 if (!vma || vma->vm_start > start)
87269 return -EFAULT;
87270@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87271 err = vma_replace_policy(vma, new_pol);
87272 if (err)
87273 goto out;
87274+
87275+#ifdef CONFIG_PAX_SEGMEXEC
87276+ vma_m = pax_find_mirror_vma(vma);
87277+ if (vma_m) {
87278+ err = vma_replace_policy(vma_m, new_pol);
87279+ if (err)
87280+ goto out;
87281+ }
87282+#endif
87283+
87284 }
87285
87286 out:
87287@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87288
87289 if (end < start)
87290 return -EINVAL;
87291+
87292+#ifdef CONFIG_PAX_SEGMEXEC
87293+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87294+ if (end > SEGMEXEC_TASK_SIZE)
87295+ return -EINVAL;
87296+ } else
87297+#endif
87298+
87299+ if (end > TASK_SIZE)
87300+ return -EINVAL;
87301+
87302 if (end == start)
87303 return 0;
87304
87305@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87306 */
87307 tcred = __task_cred(task);
87308 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87309- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87310- !capable(CAP_SYS_NICE)) {
87311+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87312 rcu_read_unlock();
87313 err = -EPERM;
87314 goto out_put;
87315@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87316 goto out;
87317 }
87318
87319+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87320+ if (mm != current->mm &&
87321+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87322+ mmput(mm);
87323+ err = -EPERM;
87324+ goto out;
87325+ }
87326+#endif
87327+
87328 err = do_migrate_pages(mm, old, new,
87329 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87330
87331diff --git a/mm/migrate.c b/mm/migrate.c
87332index 6f0c244..6d1ae32 100644
87333--- a/mm/migrate.c
87334+++ b/mm/migrate.c
87335@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87336 */
87337 tcred = __task_cred(task);
87338 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87339- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87340- !capable(CAP_SYS_NICE)) {
87341+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87342 rcu_read_unlock();
87343 err = -EPERM;
87344 goto out;
87345diff --git a/mm/mlock.c b/mm/mlock.c
87346index 79b7cf7..9944291 100644
87347--- a/mm/mlock.c
87348+++ b/mm/mlock.c
87349@@ -13,6 +13,7 @@
87350 #include <linux/pagemap.h>
87351 #include <linux/mempolicy.h>
87352 #include <linux/syscalls.h>
87353+#include <linux/security.h>
87354 #include <linux/sched.h>
87355 #include <linux/export.h>
87356 #include <linux/rmap.h>
87357@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87358 {
87359 unsigned long nstart, end, tmp;
87360 struct vm_area_struct * vma, * prev;
87361- int error;
87362+ int error = 0;
87363
87364 VM_BUG_ON(start & ~PAGE_MASK);
87365 VM_BUG_ON(len != PAGE_ALIGN(len));
87366@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87367 return -EINVAL;
87368 if (end == start)
87369 return 0;
87370+ if (end > TASK_SIZE)
87371+ return -EINVAL;
87372+
87373 vma = find_vma(current->mm, start);
87374 if (!vma || vma->vm_start > start)
87375 return -ENOMEM;
87376@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87377 for (nstart = start ; ; ) {
87378 vm_flags_t newflags;
87379
87380+#ifdef CONFIG_PAX_SEGMEXEC
87381+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87382+ break;
87383+#endif
87384+
87385 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87386
87387 newflags = vma->vm_flags & ~VM_LOCKED;
87388@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87389 lock_limit >>= PAGE_SHIFT;
87390
87391 /* check against resource limits */
87392+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87393 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87394 error = do_mlock(start, len, 1);
87395 up_write(&current->mm->mmap_sem);
87396@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
87397 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87398 vm_flags_t newflags;
87399
87400+#ifdef CONFIG_PAX_SEGMEXEC
87401+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87402+ break;
87403+#endif
87404+
87405 newflags = vma->vm_flags & ~VM_LOCKED;
87406 if (flags & MCL_CURRENT)
87407 newflags |= VM_LOCKED;
87408@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87409 lock_limit >>= PAGE_SHIFT;
87410
87411 ret = -ENOMEM;
87412+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87413 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87414 capable(CAP_IPC_LOCK))
87415 ret = do_mlockall(flags);
87416diff --git a/mm/mmap.c b/mm/mmap.c
87417index f9c97d1..3468d3b 100644
87418--- a/mm/mmap.c
87419+++ b/mm/mmap.c
87420@@ -36,6 +36,7 @@
87421 #include <linux/sched/sysctl.h>
87422 #include <linux/notifier.h>
87423 #include <linux/memory.h>
87424+#include <linux/random.h>
87425
87426 #include <asm/uaccess.h>
87427 #include <asm/cacheflush.h>
87428@@ -52,6 +53,16 @@
87429 #define arch_rebalance_pgtables(addr, len) (addr)
87430 #endif
87431
87432+static inline void verify_mm_writelocked(struct mm_struct *mm)
87433+{
87434+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87435+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87436+ up_read(&mm->mmap_sem);
87437+ BUG();
87438+ }
87439+#endif
87440+}
87441+
87442 static void unmap_region(struct mm_struct *mm,
87443 struct vm_area_struct *vma, struct vm_area_struct *prev,
87444 unsigned long start, unsigned long end);
87445@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87446 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87447 *
87448 */
87449-pgprot_t protection_map[16] = {
87450+pgprot_t protection_map[16] __read_only = {
87451 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87452 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87453 };
87454
87455-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87456+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87457 {
87458- return __pgprot(pgprot_val(protection_map[vm_flags &
87459+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87460 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87461 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87462+
87463+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87464+ if (!(__supported_pte_mask & _PAGE_NX) &&
87465+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87466+ (vm_flags & (VM_READ | VM_WRITE)))
87467+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87468+#endif
87469+
87470+ return prot;
87471 }
87472 EXPORT_SYMBOL(vm_get_page_prot);
87473
87474@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87475 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87476 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87477 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87478+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87479 /*
87480 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87481 * other variables. It can be updated by several CPUs frequently.
87482@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87483 struct vm_area_struct *next = vma->vm_next;
87484
87485 might_sleep();
87486+ BUG_ON(vma->vm_mirror);
87487 if (vma->vm_ops && vma->vm_ops->close)
87488 vma->vm_ops->close(vma);
87489 if (vma->vm_file)
87490@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87491 * not page aligned -Ram Gupta
87492 */
87493 rlim = rlimit(RLIMIT_DATA);
87494+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87495 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87496 (mm->end_data - mm->start_data) > rlim)
87497 goto out;
87498@@ -933,6 +956,12 @@ static int
87499 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87500 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87501 {
87502+
87503+#ifdef CONFIG_PAX_SEGMEXEC
87504+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87505+ return 0;
87506+#endif
87507+
87508 if (is_mergeable_vma(vma, file, vm_flags) &&
87509 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87510 if (vma->vm_pgoff == vm_pgoff)
87511@@ -952,6 +981,12 @@ static int
87512 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87513 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87514 {
87515+
87516+#ifdef CONFIG_PAX_SEGMEXEC
87517+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87518+ return 0;
87519+#endif
87520+
87521 if (is_mergeable_vma(vma, file, vm_flags) &&
87522 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87523 pgoff_t vm_pglen;
87524@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87525 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87526 struct vm_area_struct *prev, unsigned long addr,
87527 unsigned long end, unsigned long vm_flags,
87528- struct anon_vma *anon_vma, struct file *file,
87529+ struct anon_vma *anon_vma, struct file *file,
87530 pgoff_t pgoff, struct mempolicy *policy)
87531 {
87532 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87533 struct vm_area_struct *area, *next;
87534 int err;
87535
87536+#ifdef CONFIG_PAX_SEGMEXEC
87537+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87538+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87539+
87540+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87541+#endif
87542+
87543 /*
87544 * We later require that vma->vm_flags == vm_flags,
87545 * so this tests vma->vm_flags & VM_SPECIAL, too.
87546@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87547 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87548 next = next->vm_next;
87549
87550+#ifdef CONFIG_PAX_SEGMEXEC
87551+ if (prev)
87552+ prev_m = pax_find_mirror_vma(prev);
87553+ if (area)
87554+ area_m = pax_find_mirror_vma(area);
87555+ if (next)
87556+ next_m = pax_find_mirror_vma(next);
87557+#endif
87558+
87559 /*
87560 * Can it merge with the predecessor?
87561 */
87562@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87563 /* cases 1, 6 */
87564 err = vma_adjust(prev, prev->vm_start,
87565 next->vm_end, prev->vm_pgoff, NULL);
87566- } else /* cases 2, 5, 7 */
87567+
87568+#ifdef CONFIG_PAX_SEGMEXEC
87569+ if (!err && prev_m)
87570+ err = vma_adjust(prev_m, prev_m->vm_start,
87571+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87572+#endif
87573+
87574+ } else { /* cases 2, 5, 7 */
87575 err = vma_adjust(prev, prev->vm_start,
87576 end, prev->vm_pgoff, NULL);
87577+
87578+#ifdef CONFIG_PAX_SEGMEXEC
87579+ if (!err && prev_m)
87580+ err = vma_adjust(prev_m, prev_m->vm_start,
87581+ end_m, prev_m->vm_pgoff, NULL);
87582+#endif
87583+
87584+ }
87585 if (err)
87586 return NULL;
87587 khugepaged_enter_vma_merge(prev);
87588@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87589 mpol_equal(policy, vma_policy(next)) &&
87590 can_vma_merge_before(next, vm_flags,
87591 anon_vma, file, pgoff+pglen)) {
87592- if (prev && addr < prev->vm_end) /* case 4 */
87593+ if (prev && addr < prev->vm_end) { /* case 4 */
87594 err = vma_adjust(prev, prev->vm_start,
87595 addr, prev->vm_pgoff, NULL);
87596- else /* cases 3, 8 */
87597+
87598+#ifdef CONFIG_PAX_SEGMEXEC
87599+ if (!err && prev_m)
87600+ err = vma_adjust(prev_m, prev_m->vm_start,
87601+ addr_m, prev_m->vm_pgoff, NULL);
87602+#endif
87603+
87604+ } else { /* cases 3, 8 */
87605 err = vma_adjust(area, addr, next->vm_end,
87606 next->vm_pgoff - pglen, NULL);
87607+
87608+#ifdef CONFIG_PAX_SEGMEXEC
87609+ if (!err && area_m)
87610+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87611+ next_m->vm_pgoff - pglen, NULL);
87612+#endif
87613+
87614+ }
87615 if (err)
87616 return NULL;
87617 khugepaged_enter_vma_merge(area);
87618@@ -1165,8 +1246,10 @@ none:
87619 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87620 struct file *file, long pages)
87621 {
87622- const unsigned long stack_flags
87623- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87624+
87625+#ifdef CONFIG_PAX_RANDMMAP
87626+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87627+#endif
87628
87629 mm->total_vm += pages;
87630
87631@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87632 mm->shared_vm += pages;
87633 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87634 mm->exec_vm += pages;
87635- } else if (flags & stack_flags)
87636+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87637 mm->stack_vm += pages;
87638 }
87639 #endif /* CONFIG_PROC_FS */
87640@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87641 * (the exception is when the underlying filesystem is noexec
87642 * mounted, in which case we dont add PROT_EXEC.)
87643 */
87644- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87645+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87646 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87647 prot |= PROT_EXEC;
87648
87649@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87650 /* Obtain the address to map to. we verify (or select) it and ensure
87651 * that it represents a valid section of the address space.
87652 */
87653- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87654+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87655 if (addr & ~PAGE_MASK)
87656 return addr;
87657
87658@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87659 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87660 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87661
87662+#ifdef CONFIG_PAX_MPROTECT
87663+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87664+
87665+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87666+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87667+ mm->binfmt->handle_mmap)
87668+ mm->binfmt->handle_mmap(file);
87669+#endif
87670+
87671+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87672+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87673+ gr_log_rwxmmap(file);
87674+
87675+#ifdef CONFIG_PAX_EMUPLT
87676+ vm_flags &= ~VM_EXEC;
87677+#else
87678+ return -EPERM;
87679+#endif
87680+
87681+ }
87682+
87683+ if (!(vm_flags & VM_EXEC))
87684+ vm_flags &= ~VM_MAYEXEC;
87685+#else
87686+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87687+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87688+#endif
87689+ else
87690+ vm_flags &= ~VM_MAYWRITE;
87691+ }
87692+#endif
87693+
87694+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87695+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87696+ vm_flags &= ~VM_PAGEEXEC;
87697+#endif
87698+
87699 if (flags & MAP_LOCKED)
87700 if (!can_do_mlock())
87701 return -EPERM;
87702@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87703 locked += mm->locked_vm;
87704 lock_limit = rlimit(RLIMIT_MEMLOCK);
87705 lock_limit >>= PAGE_SHIFT;
87706+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87707 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87708 return -EAGAIN;
87709 }
87710@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87711 vm_flags |= VM_NORESERVE;
87712 }
87713
87714+ if (!gr_acl_handle_mmap(file, prot))
87715+ return -EACCES;
87716+
87717 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87718 if (!IS_ERR_VALUE(addr) &&
87719 ((vm_flags & VM_LOCKED) ||
87720@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87721 vm_flags_t vm_flags = vma->vm_flags;
87722
87723 /* If it was private or non-writable, the write bit is already clear */
87724- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87725+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87726 return 0;
87727
87728 /* The backer wishes to know when pages are first written to? */
87729@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87730 unsigned long charged = 0;
87731 struct inode *inode = file ? file_inode(file) : NULL;
87732
87733+#ifdef CONFIG_PAX_SEGMEXEC
87734+ struct vm_area_struct *vma_m = NULL;
87735+#endif
87736+
87737+ /*
87738+ * mm->mmap_sem is required to protect against another thread
87739+ * changing the mappings in case we sleep.
87740+ */
87741+ verify_mm_writelocked(mm);
87742+
87743 /* Check against address space limit. */
87744+
87745+#ifdef CONFIG_PAX_RANDMMAP
87746+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87747+#endif
87748+
87749 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87750 unsigned long nr_pages;
87751
87752@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87753
87754 /* Clear old maps */
87755 error = -ENOMEM;
87756-munmap_back:
87757 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87758 if (do_munmap(mm, addr, len))
87759 return -ENOMEM;
87760- goto munmap_back;
87761+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87762 }
87763
87764 /*
87765@@ -1536,6 +1674,16 @@ munmap_back:
87766 goto unacct_error;
87767 }
87768
87769+#ifdef CONFIG_PAX_SEGMEXEC
87770+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87771+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87772+ if (!vma_m) {
87773+ error = -ENOMEM;
87774+ goto free_vma;
87775+ }
87776+ }
87777+#endif
87778+
87779 vma->vm_mm = mm;
87780 vma->vm_start = addr;
87781 vma->vm_end = addr + len;
87782@@ -1560,6 +1708,13 @@ munmap_back:
87783 if (error)
87784 goto unmap_and_free_vma;
87785
87786+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87787+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87788+ vma->vm_flags |= VM_PAGEEXEC;
87789+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87790+ }
87791+#endif
87792+
87793 /* Can addr have changed??
87794 *
87795 * Answer: Yes, several device drivers can do it in their
87796@@ -1598,6 +1753,11 @@ munmap_back:
87797 vma_link(mm, vma, prev, rb_link, rb_parent);
87798 file = vma->vm_file;
87799
87800+#ifdef CONFIG_PAX_SEGMEXEC
87801+ if (vma_m)
87802+ BUG_ON(pax_mirror_vma(vma_m, vma));
87803+#endif
87804+
87805 /* Once vma denies write, undo our temporary denial count */
87806 if (correct_wcount)
87807 atomic_inc(&inode->i_writecount);
87808@@ -1605,6 +1765,7 @@ out:
87809 perf_event_mmap(vma);
87810
87811 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87812+ track_exec_limit(mm, addr, addr + len, vm_flags);
87813 if (vm_flags & VM_LOCKED) {
87814 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87815 vma == get_gate_vma(current->mm)))
87816@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87817 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87818 charged = 0;
87819 free_vma:
87820+
87821+#ifdef CONFIG_PAX_SEGMEXEC
87822+ if (vma_m)
87823+ kmem_cache_free(vm_area_cachep, vma_m);
87824+#endif
87825+
87826 kmem_cache_free(vm_area_cachep, vma);
87827 unacct_error:
87828 if (charged)
87829@@ -1635,7 +1802,63 @@ unacct_error:
87830 return error;
87831 }
87832
87833-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87834+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87835+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87836+{
87837+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87838+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87839+
87840+ return 0;
87841+}
87842+#endif
87843+
87844+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87845+{
87846+ if (!vma) {
87847+#ifdef CONFIG_STACK_GROWSUP
87848+ if (addr > sysctl_heap_stack_gap)
87849+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87850+ else
87851+ vma = find_vma(current->mm, 0);
87852+ if (vma && (vma->vm_flags & VM_GROWSUP))
87853+ return false;
87854+#endif
87855+ return true;
87856+ }
87857+
87858+ if (addr + len > vma->vm_start)
87859+ return false;
87860+
87861+ if (vma->vm_flags & VM_GROWSDOWN)
87862+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87863+#ifdef CONFIG_STACK_GROWSUP
87864+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87865+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87866+#endif
87867+ else if (offset)
87868+ return offset <= vma->vm_start - addr - len;
87869+
87870+ return true;
87871+}
87872+
87873+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87874+{
87875+ if (vma->vm_start < len)
87876+ return -ENOMEM;
87877+
87878+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87879+ if (offset <= vma->vm_start - len)
87880+ return vma->vm_start - len - offset;
87881+ else
87882+ return -ENOMEM;
87883+ }
87884+
87885+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87886+ return vma->vm_start - len - sysctl_heap_stack_gap;
87887+ return -ENOMEM;
87888+}
87889+
87890+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87891 {
87892 /*
87893 * We implement the search by looking for an rbtree node that
87894@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87895 }
87896 }
87897
87898- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87899+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87900 check_current:
87901 /* Check if current node has a suitable gap */
87902 if (gap_start > high_limit)
87903 return -ENOMEM;
87904+
87905+ if (gap_end - gap_start > info->threadstack_offset)
87906+ gap_start += info->threadstack_offset;
87907+ else
87908+ gap_start = gap_end;
87909+
87910+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87911+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87912+ gap_start += sysctl_heap_stack_gap;
87913+ else
87914+ gap_start = gap_end;
87915+ }
87916+ if (vma->vm_flags & VM_GROWSDOWN) {
87917+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87918+ gap_end -= sysctl_heap_stack_gap;
87919+ else
87920+ gap_end = gap_start;
87921+ }
87922 if (gap_end >= low_limit && gap_end - gap_start >= length)
87923 goto found;
87924
87925@@ -1737,7 +1978,7 @@ found:
87926 return gap_start;
87927 }
87928
87929-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87930+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87931 {
87932 struct mm_struct *mm = current->mm;
87933 struct vm_area_struct *vma;
87934@@ -1791,6 +2032,24 @@ check_current:
87935 gap_end = vma->vm_start;
87936 if (gap_end < low_limit)
87937 return -ENOMEM;
87938+
87939+ if (gap_end - gap_start > info->threadstack_offset)
87940+ gap_end -= info->threadstack_offset;
87941+ else
87942+ gap_end = gap_start;
87943+
87944+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87945+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87946+ gap_start += sysctl_heap_stack_gap;
87947+ else
87948+ gap_start = gap_end;
87949+ }
87950+ if (vma->vm_flags & VM_GROWSDOWN) {
87951+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87952+ gap_end -= sysctl_heap_stack_gap;
87953+ else
87954+ gap_end = gap_start;
87955+ }
87956 if (gap_start <= high_limit && gap_end - gap_start >= length)
87957 goto found;
87958
87959@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87960 struct mm_struct *mm = current->mm;
87961 struct vm_area_struct *vma;
87962 struct vm_unmapped_area_info info;
87963+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87964
87965 if (len > TASK_SIZE)
87966 return -ENOMEM;
87967@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87968 if (flags & MAP_FIXED)
87969 return addr;
87970
87971+#ifdef CONFIG_PAX_RANDMMAP
87972+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87973+#endif
87974+
87975 if (addr) {
87976 addr = PAGE_ALIGN(addr);
87977 vma = find_vma(mm, addr);
87978- if (TASK_SIZE - len >= addr &&
87979- (!vma || addr + len <= vma->vm_start))
87980+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87981 return addr;
87982 }
87983
87984 info.flags = 0;
87985 info.length = len;
87986 info.low_limit = TASK_UNMAPPED_BASE;
87987+
87988+#ifdef CONFIG_PAX_RANDMMAP
87989+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87990+ info.low_limit += mm->delta_mmap;
87991+#endif
87992+
87993 info.high_limit = TASK_SIZE;
87994 info.align_mask = 0;
87995+ info.threadstack_offset = offset;
87996 return vm_unmapped_area(&info);
87997 }
87998 #endif
87999@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88000 struct mm_struct *mm = current->mm;
88001 unsigned long addr = addr0;
88002 struct vm_unmapped_area_info info;
88003+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
88004
88005 /* requested length too big for entire address space */
88006 if (len > TASK_SIZE)
88007@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88008 if (flags & MAP_FIXED)
88009 return addr;
88010
88011+#ifdef CONFIG_PAX_RANDMMAP
88012+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
88013+#endif
88014+
88015 /* requesting a specific address */
88016 if (addr) {
88017 addr = PAGE_ALIGN(addr);
88018 vma = find_vma(mm, addr);
88019- if (TASK_SIZE - len >= addr &&
88020- (!vma || addr + len <= vma->vm_start))
88021+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
88022 return addr;
88023 }
88024
88025@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88026 info.low_limit = PAGE_SIZE;
88027 info.high_limit = mm->mmap_base;
88028 info.align_mask = 0;
88029+ info.threadstack_offset = offset;
88030 addr = vm_unmapped_area(&info);
88031
88032 /*
88033@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88034 VM_BUG_ON(addr != -ENOMEM);
88035 info.flags = 0;
88036 info.low_limit = TASK_UNMAPPED_BASE;
88037+
88038+#ifdef CONFIG_PAX_RANDMMAP
88039+ if (mm->pax_flags & MF_PAX_RANDMMAP)
88040+ info.low_limit += mm->delta_mmap;
88041+#endif
88042+
88043 info.high_limit = TASK_SIZE;
88044 addr = vm_unmapped_area(&info);
88045 }
88046@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
88047 return vma;
88048 }
88049
88050+#ifdef CONFIG_PAX_SEGMEXEC
88051+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
88052+{
88053+ struct vm_area_struct *vma_m;
88054+
88055+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
88056+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
88057+ BUG_ON(vma->vm_mirror);
88058+ return NULL;
88059+ }
88060+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
88061+ vma_m = vma->vm_mirror;
88062+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
88063+ BUG_ON(vma->vm_file != vma_m->vm_file);
88064+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
88065+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
88066+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
88067+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
88068+ return vma_m;
88069+}
88070+#endif
88071+
88072 /*
88073 * Verify that the stack growth is acceptable and
88074 * update accounting. This is shared with both the
88075@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88076 return -ENOMEM;
88077
88078 /* Stack limit test */
88079+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
88080 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
88081 return -ENOMEM;
88082
88083@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88084 locked = mm->locked_vm + grow;
88085 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
88086 limit >>= PAGE_SHIFT;
88087+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88088 if (locked > limit && !capable(CAP_IPC_LOCK))
88089 return -ENOMEM;
88090 }
88091@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88092 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
88093 * vma is the last one with address > vma->vm_end. Have to extend vma.
88094 */
88095+#ifndef CONFIG_IA64
88096+static
88097+#endif
88098 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
88099 {
88100 int error;
88101+ bool locknext;
88102
88103 if (!(vma->vm_flags & VM_GROWSUP))
88104 return -EFAULT;
88105
88106+ /* Also guard against wrapping around to address 0. */
88107+ if (address < PAGE_ALIGN(address+1))
88108+ address = PAGE_ALIGN(address+1);
88109+ else
88110+ return -ENOMEM;
88111+
88112 /*
88113 * We must make sure the anon_vma is allocated
88114 * so that the anon_vma locking is not a noop.
88115 */
88116 if (unlikely(anon_vma_prepare(vma)))
88117 return -ENOMEM;
88118+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
88119+ if (locknext && anon_vma_prepare(vma->vm_next))
88120+ return -ENOMEM;
88121 vma_lock_anon_vma(vma);
88122+ if (locknext)
88123+ vma_lock_anon_vma(vma->vm_next);
88124
88125 /*
88126 * vma->vm_start/vm_end cannot change under us because the caller
88127 * is required to hold the mmap_sem in read mode. We need the
88128- * anon_vma lock to serialize against concurrent expand_stacks.
88129- * Also guard against wrapping around to address 0.
88130+ * anon_vma locks to serialize against concurrent expand_stacks
88131+ * and expand_upwards.
88132 */
88133- if (address < PAGE_ALIGN(address+4))
88134- address = PAGE_ALIGN(address+4);
88135- else {
88136- vma_unlock_anon_vma(vma);
88137- return -ENOMEM;
88138- }
88139 error = 0;
88140
88141 /* Somebody else might have raced and expanded it already */
88142- if (address > vma->vm_end) {
88143+ 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)
88144+ error = -ENOMEM;
88145+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
88146 unsigned long size, grow;
88147
88148 size = address - vma->vm_start;
88149@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
88150 }
88151 }
88152 }
88153+ if (locknext)
88154+ vma_unlock_anon_vma(vma->vm_next);
88155 vma_unlock_anon_vma(vma);
88156 khugepaged_enter_vma_merge(vma);
88157 validate_mm(vma->vm_mm);
88158@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
88159 unsigned long address)
88160 {
88161 int error;
88162+ bool lockprev = false;
88163+ struct vm_area_struct *prev;
88164
88165 /*
88166 * We must make sure the anon_vma is allocated
88167@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
88168 if (error)
88169 return error;
88170
88171+ prev = vma->vm_prev;
88172+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
88173+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
88174+#endif
88175+ if (lockprev && anon_vma_prepare(prev))
88176+ return -ENOMEM;
88177+ if (lockprev)
88178+ vma_lock_anon_vma(prev);
88179+
88180 vma_lock_anon_vma(vma);
88181
88182 /*
88183@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88184 */
88185
88186 /* Somebody else might have raced and expanded it already */
88187- if (address < vma->vm_start) {
88188+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88189+ error = -ENOMEM;
88190+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88191 unsigned long size, grow;
88192
88193+#ifdef CONFIG_PAX_SEGMEXEC
88194+ struct vm_area_struct *vma_m;
88195+
88196+ vma_m = pax_find_mirror_vma(vma);
88197+#endif
88198+
88199 size = vma->vm_end - address;
88200 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88201
88202@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88203 vma->vm_pgoff -= grow;
88204 anon_vma_interval_tree_post_update_vma(vma);
88205 vma_gap_update(vma);
88206+
88207+#ifdef CONFIG_PAX_SEGMEXEC
88208+ if (vma_m) {
88209+ anon_vma_interval_tree_pre_update_vma(vma_m);
88210+ vma_m->vm_start -= grow << PAGE_SHIFT;
88211+ vma_m->vm_pgoff -= grow;
88212+ anon_vma_interval_tree_post_update_vma(vma_m);
88213+ vma_gap_update(vma_m);
88214+ }
88215+#endif
88216+
88217 spin_unlock(&vma->vm_mm->page_table_lock);
88218
88219+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88220 perf_event_mmap(vma);
88221 }
88222 }
88223 }
88224 vma_unlock_anon_vma(vma);
88225+ if (lockprev)
88226+ vma_unlock_anon_vma(prev);
88227 khugepaged_enter_vma_merge(vma);
88228 validate_mm(vma->vm_mm);
88229 return error;
88230@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88231 do {
88232 long nrpages = vma_pages(vma);
88233
88234+#ifdef CONFIG_PAX_SEGMEXEC
88235+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88236+ vma = remove_vma(vma);
88237+ continue;
88238+ }
88239+#endif
88240+
88241 if (vma->vm_flags & VM_ACCOUNT)
88242 nr_accounted += nrpages;
88243 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88244@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88245 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88246 vma->vm_prev = NULL;
88247 do {
88248+
88249+#ifdef CONFIG_PAX_SEGMEXEC
88250+ if (vma->vm_mirror) {
88251+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88252+ vma->vm_mirror->vm_mirror = NULL;
88253+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88254+ vma->vm_mirror = NULL;
88255+ }
88256+#endif
88257+
88258 vma_rb_erase(vma, &mm->mm_rb);
88259 mm->map_count--;
88260 tail_vma = vma;
88261@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88262 struct vm_area_struct *new;
88263 int err = -ENOMEM;
88264
88265+#ifdef CONFIG_PAX_SEGMEXEC
88266+ struct vm_area_struct *vma_m, *new_m = NULL;
88267+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88268+#endif
88269+
88270 if (is_vm_hugetlb_page(vma) && (addr &
88271 ~(huge_page_mask(hstate_vma(vma)))))
88272 return -EINVAL;
88273
88274+#ifdef CONFIG_PAX_SEGMEXEC
88275+ vma_m = pax_find_mirror_vma(vma);
88276+#endif
88277+
88278 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88279 if (!new)
88280 goto out_err;
88281
88282+#ifdef CONFIG_PAX_SEGMEXEC
88283+ if (vma_m) {
88284+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88285+ if (!new_m) {
88286+ kmem_cache_free(vm_area_cachep, new);
88287+ goto out_err;
88288+ }
88289+ }
88290+#endif
88291+
88292 /* most fields are the same, copy all, and then fixup */
88293 *new = *vma;
88294
88295@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88296 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88297 }
88298
88299+#ifdef CONFIG_PAX_SEGMEXEC
88300+ if (vma_m) {
88301+ *new_m = *vma_m;
88302+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88303+ new_m->vm_mirror = new;
88304+ new->vm_mirror = new_m;
88305+
88306+ if (new_below)
88307+ new_m->vm_end = addr_m;
88308+ else {
88309+ new_m->vm_start = addr_m;
88310+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88311+ }
88312+ }
88313+#endif
88314+
88315 pol = mpol_dup(vma_policy(vma));
88316 if (IS_ERR(pol)) {
88317 err = PTR_ERR(pol);
88318@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88319 else
88320 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88321
88322+#ifdef CONFIG_PAX_SEGMEXEC
88323+ if (!err && vma_m) {
88324+ if (anon_vma_clone(new_m, vma_m))
88325+ goto out_free_mpol;
88326+
88327+ mpol_get(pol);
88328+ vma_set_policy(new_m, pol);
88329+
88330+ if (new_m->vm_file)
88331+ get_file(new_m->vm_file);
88332+
88333+ if (new_m->vm_ops && new_m->vm_ops->open)
88334+ new_m->vm_ops->open(new_m);
88335+
88336+ if (new_below)
88337+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88338+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88339+ else
88340+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88341+
88342+ if (err) {
88343+ if (new_m->vm_ops && new_m->vm_ops->close)
88344+ new_m->vm_ops->close(new_m);
88345+ if (new_m->vm_file)
88346+ fput(new_m->vm_file);
88347+ mpol_put(pol);
88348+ }
88349+ }
88350+#endif
88351+
88352 /* Success. */
88353 if (!err)
88354 return 0;
88355@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88356 new->vm_ops->close(new);
88357 if (new->vm_file)
88358 fput(new->vm_file);
88359- unlink_anon_vmas(new);
88360 out_free_mpol:
88361 mpol_put(pol);
88362 out_free_vma:
88363+
88364+#ifdef CONFIG_PAX_SEGMEXEC
88365+ if (new_m) {
88366+ unlink_anon_vmas(new_m);
88367+ kmem_cache_free(vm_area_cachep, new_m);
88368+ }
88369+#endif
88370+
88371+ unlink_anon_vmas(new);
88372 kmem_cache_free(vm_area_cachep, new);
88373 out_err:
88374 return err;
88375@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88376 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88377 unsigned long addr, int new_below)
88378 {
88379+
88380+#ifdef CONFIG_PAX_SEGMEXEC
88381+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88382+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88383+ if (mm->map_count >= sysctl_max_map_count-1)
88384+ return -ENOMEM;
88385+ } else
88386+#endif
88387+
88388 if (mm->map_count >= sysctl_max_map_count)
88389 return -ENOMEM;
88390
88391@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88392 * work. This now handles partial unmappings.
88393 * Jeremy Fitzhardinge <jeremy@goop.org>
88394 */
88395+#ifdef CONFIG_PAX_SEGMEXEC
88396 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88397 {
88398+ int ret = __do_munmap(mm, start, len);
88399+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88400+ return ret;
88401+
88402+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88403+}
88404+
88405+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88406+#else
88407+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88408+#endif
88409+{
88410 unsigned long end;
88411 struct vm_area_struct *vma, *prev, *last;
88412
88413+ /*
88414+ * mm->mmap_sem is required to protect against another thread
88415+ * changing the mappings in case we sleep.
88416+ */
88417+ verify_mm_writelocked(mm);
88418+
88419 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88420 return -EINVAL;
88421
88422@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88423 /* Fix up all other VM information */
88424 remove_vma_list(mm, vma);
88425
88426+ track_exec_limit(mm, start, end, 0UL);
88427+
88428 return 0;
88429 }
88430
88431@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88432 int ret;
88433 struct mm_struct *mm = current->mm;
88434
88435+
88436+#ifdef CONFIG_PAX_SEGMEXEC
88437+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88438+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88439+ return -EINVAL;
88440+#endif
88441+
88442 down_write(&mm->mmap_sem);
88443 ret = do_munmap(mm, start, len);
88444 up_write(&mm->mmap_sem);
88445@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88446 return vm_munmap(addr, len);
88447 }
88448
88449-static inline void verify_mm_writelocked(struct mm_struct *mm)
88450-{
88451-#ifdef CONFIG_DEBUG_VM
88452- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88453- WARN_ON(1);
88454- up_read(&mm->mmap_sem);
88455- }
88456-#endif
88457-}
88458-
88459 /*
88460 * this is really a simplified "do_mmap". it only handles
88461 * anonymous maps. eventually we may be able to do some
88462@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88463 struct rb_node ** rb_link, * rb_parent;
88464 pgoff_t pgoff = addr >> PAGE_SHIFT;
88465 int error;
88466+ unsigned long charged;
88467
88468 len = PAGE_ALIGN(len);
88469 if (!len)
88470@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88471
88472 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88473
88474+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88475+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88476+ flags &= ~VM_EXEC;
88477+
88478+#ifdef CONFIG_PAX_MPROTECT
88479+ if (mm->pax_flags & MF_PAX_MPROTECT)
88480+ flags &= ~VM_MAYEXEC;
88481+#endif
88482+
88483+ }
88484+#endif
88485+
88486 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88487 if (error & ~PAGE_MASK)
88488 return error;
88489
88490+ charged = len >> PAGE_SHIFT;
88491+
88492 /*
88493 * mlock MCL_FUTURE?
88494 */
88495 if (mm->def_flags & VM_LOCKED) {
88496 unsigned long locked, lock_limit;
88497- locked = len >> PAGE_SHIFT;
88498+ locked = charged;
88499 locked += mm->locked_vm;
88500 lock_limit = rlimit(RLIMIT_MEMLOCK);
88501 lock_limit >>= PAGE_SHIFT;
88502@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88503 /*
88504 * Clear old maps. this also does some error checking for us
88505 */
88506- munmap_back:
88507 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88508 if (do_munmap(mm, addr, len))
88509 return -ENOMEM;
88510- goto munmap_back;
88511+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88512 }
88513
88514 /* Check against address space limits *after* clearing old maps... */
88515- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88516+ if (!may_expand_vm(mm, charged))
88517 return -ENOMEM;
88518
88519 if (mm->map_count > sysctl_max_map_count)
88520 return -ENOMEM;
88521
88522- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88523+ if (security_vm_enough_memory_mm(mm, charged))
88524 return -ENOMEM;
88525
88526 /* Can we just expand an old private anonymous mapping? */
88527@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88528 */
88529 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88530 if (!vma) {
88531- vm_unacct_memory(len >> PAGE_SHIFT);
88532+ vm_unacct_memory(charged);
88533 return -ENOMEM;
88534 }
88535
88536@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88537 vma_link(mm, vma, prev, rb_link, rb_parent);
88538 out:
88539 perf_event_mmap(vma);
88540- mm->total_vm += len >> PAGE_SHIFT;
88541+ mm->total_vm += charged;
88542 if (flags & VM_LOCKED)
88543- mm->locked_vm += (len >> PAGE_SHIFT);
88544+ mm->locked_vm += charged;
88545+ track_exec_limit(mm, addr, addr + len, flags);
88546 return addr;
88547 }
88548
88549@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88550 while (vma) {
88551 if (vma->vm_flags & VM_ACCOUNT)
88552 nr_accounted += vma_pages(vma);
88553+ vma->vm_mirror = NULL;
88554 vma = remove_vma(vma);
88555 }
88556 vm_unacct_memory(nr_accounted);
88557@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88558 struct vm_area_struct *prev;
88559 struct rb_node **rb_link, *rb_parent;
88560
88561+#ifdef CONFIG_PAX_SEGMEXEC
88562+ struct vm_area_struct *vma_m = NULL;
88563+#endif
88564+
88565+ if (security_mmap_addr(vma->vm_start))
88566+ return -EPERM;
88567+
88568 /*
88569 * The vm_pgoff of a purely anonymous vma should be irrelevant
88570 * until its first write fault, when page's anon_vma and index
88571@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88572 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88573 return -ENOMEM;
88574
88575+#ifdef CONFIG_PAX_SEGMEXEC
88576+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88577+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88578+ if (!vma_m)
88579+ return -ENOMEM;
88580+ }
88581+#endif
88582+
88583 vma_link(mm, vma, prev, rb_link, rb_parent);
88584+
88585+#ifdef CONFIG_PAX_SEGMEXEC
88586+ if (vma_m)
88587+ BUG_ON(pax_mirror_vma(vma_m, vma));
88588+#endif
88589+
88590 return 0;
88591 }
88592
88593@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88594 struct mempolicy *pol;
88595 bool faulted_in_anon_vma = true;
88596
88597+ BUG_ON(vma->vm_mirror);
88598+
88599 /*
88600 * If anonymous vma has not yet been faulted, update new pgoff
88601 * to match new location, to increase its chance of merging.
88602@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88603 return NULL;
88604 }
88605
88606+#ifdef CONFIG_PAX_SEGMEXEC
88607+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88608+{
88609+ struct vm_area_struct *prev_m;
88610+ struct rb_node **rb_link_m, *rb_parent_m;
88611+ struct mempolicy *pol_m;
88612+
88613+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88614+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88615+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88616+ *vma_m = *vma;
88617+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88618+ if (anon_vma_clone(vma_m, vma))
88619+ return -ENOMEM;
88620+ pol_m = vma_policy(vma_m);
88621+ mpol_get(pol_m);
88622+ vma_set_policy(vma_m, pol_m);
88623+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88624+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88625+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88626+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88627+ if (vma_m->vm_file)
88628+ get_file(vma_m->vm_file);
88629+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88630+ vma_m->vm_ops->open(vma_m);
88631+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88632+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88633+ vma_m->vm_mirror = vma;
88634+ vma->vm_mirror = vma_m;
88635+ return 0;
88636+}
88637+#endif
88638+
88639 /*
88640 * Return true if the calling process may expand its vm space by the passed
88641 * number of pages
88642@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88643
88644 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88645
88646+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88647 if (cur + npages > lim)
88648 return 0;
88649 return 1;
88650@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88651 vma->vm_start = addr;
88652 vma->vm_end = addr + len;
88653
88654+#ifdef CONFIG_PAX_MPROTECT
88655+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88656+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88657+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88658+ return -EPERM;
88659+ if (!(vm_flags & VM_EXEC))
88660+ vm_flags &= ~VM_MAYEXEC;
88661+#else
88662+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88663+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88664+#endif
88665+ else
88666+ vm_flags &= ~VM_MAYWRITE;
88667+ }
88668+#endif
88669+
88670 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88671 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88672
88673diff --git a/mm/mprotect.c b/mm/mprotect.c
88674index 94722a4..e661e29 100644
88675--- a/mm/mprotect.c
88676+++ b/mm/mprotect.c
88677@@ -23,10 +23,18 @@
88678 #include <linux/mmu_notifier.h>
88679 #include <linux/migrate.h>
88680 #include <linux/perf_event.h>
88681+#include <linux/sched/sysctl.h>
88682+
88683+#ifdef CONFIG_PAX_MPROTECT
88684+#include <linux/elf.h>
88685+#include <linux/binfmts.h>
88686+#endif
88687+
88688 #include <asm/uaccess.h>
88689 #include <asm/pgtable.h>
88690 #include <asm/cacheflush.h>
88691 #include <asm/tlbflush.h>
88692+#include <asm/mmu_context.h>
88693
88694 #ifndef pgprot_modify
88695 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88696@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88697 return pages;
88698 }
88699
88700+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88701+/* called while holding the mmap semaphor for writing except stack expansion */
88702+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88703+{
88704+ unsigned long oldlimit, newlimit = 0UL;
88705+
88706+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88707+ return;
88708+
88709+ spin_lock(&mm->page_table_lock);
88710+ oldlimit = mm->context.user_cs_limit;
88711+ if ((prot & VM_EXEC) && oldlimit < end)
88712+ /* USER_CS limit moved up */
88713+ newlimit = end;
88714+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88715+ /* USER_CS limit moved down */
88716+ newlimit = start;
88717+
88718+ if (newlimit) {
88719+ mm->context.user_cs_limit = newlimit;
88720+
88721+#ifdef CONFIG_SMP
88722+ wmb();
88723+ cpus_clear(mm->context.cpu_user_cs_mask);
88724+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88725+#endif
88726+
88727+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88728+ }
88729+ spin_unlock(&mm->page_table_lock);
88730+ if (newlimit == end) {
88731+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88732+
88733+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88734+ if (is_vm_hugetlb_page(vma))
88735+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88736+ else
88737+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88738+ }
88739+}
88740+#endif
88741+
88742 int
88743 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88744 unsigned long start, unsigned long end, unsigned long newflags)
88745@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88746 int error;
88747 int dirty_accountable = 0;
88748
88749+#ifdef CONFIG_PAX_SEGMEXEC
88750+ struct vm_area_struct *vma_m = NULL;
88751+ unsigned long start_m, end_m;
88752+
88753+ start_m = start + SEGMEXEC_TASK_SIZE;
88754+ end_m = end + SEGMEXEC_TASK_SIZE;
88755+#endif
88756+
88757 if (newflags == oldflags) {
88758 *pprev = vma;
88759 return 0;
88760 }
88761
88762+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88763+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88764+
88765+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88766+ return -ENOMEM;
88767+
88768+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88769+ return -ENOMEM;
88770+ }
88771+
88772 /*
88773 * If we make a private mapping writable we increase our commit;
88774 * but (without finer accounting) cannot reduce our commit if we
88775@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88776 }
88777 }
88778
88779+#ifdef CONFIG_PAX_SEGMEXEC
88780+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88781+ if (start != vma->vm_start) {
88782+ error = split_vma(mm, vma, start, 1);
88783+ if (error)
88784+ goto fail;
88785+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88786+ *pprev = (*pprev)->vm_next;
88787+ }
88788+
88789+ if (end != vma->vm_end) {
88790+ error = split_vma(mm, vma, end, 0);
88791+ if (error)
88792+ goto fail;
88793+ }
88794+
88795+ if (pax_find_mirror_vma(vma)) {
88796+ error = __do_munmap(mm, start_m, end_m - start_m);
88797+ if (error)
88798+ goto fail;
88799+ } else {
88800+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88801+ if (!vma_m) {
88802+ error = -ENOMEM;
88803+ goto fail;
88804+ }
88805+ vma->vm_flags = newflags;
88806+ error = pax_mirror_vma(vma_m, vma);
88807+ if (error) {
88808+ vma->vm_flags = oldflags;
88809+ goto fail;
88810+ }
88811+ }
88812+ }
88813+#endif
88814+
88815 /*
88816 * First try to merge with previous and/or next vma.
88817 */
88818@@ -296,9 +400,21 @@ success:
88819 * vm_flags and vm_page_prot are protected by the mmap_sem
88820 * held in write mode.
88821 */
88822+
88823+#ifdef CONFIG_PAX_SEGMEXEC
88824+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88825+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88826+#endif
88827+
88828 vma->vm_flags = newflags;
88829+
88830+#ifdef CONFIG_PAX_MPROTECT
88831+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88832+ mm->binfmt->handle_mprotect(vma, newflags);
88833+#endif
88834+
88835 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88836- vm_get_page_prot(newflags));
88837+ vm_get_page_prot(vma->vm_flags));
88838
88839 if (vma_wants_writenotify(vma)) {
88840 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88841@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88842 end = start + len;
88843 if (end <= start)
88844 return -ENOMEM;
88845+
88846+#ifdef CONFIG_PAX_SEGMEXEC
88847+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88848+ if (end > SEGMEXEC_TASK_SIZE)
88849+ return -EINVAL;
88850+ } else
88851+#endif
88852+
88853+ if (end > TASK_SIZE)
88854+ return -EINVAL;
88855+
88856 if (!arch_validate_prot(prot))
88857 return -EINVAL;
88858
88859@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88860 /*
88861 * Does the application expect PROT_READ to imply PROT_EXEC:
88862 */
88863- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88864+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88865 prot |= PROT_EXEC;
88866
88867 vm_flags = calc_vm_prot_bits(prot);
88868@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88869 if (start > vma->vm_start)
88870 prev = vma;
88871
88872+#ifdef CONFIG_PAX_MPROTECT
88873+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88874+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88875+#endif
88876+
88877 for (nstart = start ; ; ) {
88878 unsigned long newflags;
88879
88880@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88881
88882 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88883 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88884+ if (prot & (PROT_WRITE | PROT_EXEC))
88885+ gr_log_rwxmprotect(vma);
88886+
88887+ error = -EACCES;
88888+ goto out;
88889+ }
88890+
88891+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88892 error = -EACCES;
88893 goto out;
88894 }
88895@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88896 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88897 if (error)
88898 goto out;
88899+
88900+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88901+
88902 nstart = tmp;
88903
88904 if (nstart < prev->vm_end)
88905diff --git a/mm/mremap.c b/mm/mremap.c
88906index 0843feb..5607f47 100644
88907--- a/mm/mremap.c
88908+++ b/mm/mremap.c
88909@@ -25,6 +25,7 @@
88910 #include <asm/uaccess.h>
88911 #include <asm/cacheflush.h>
88912 #include <asm/tlbflush.h>
88913+#include <asm/pgalloc.h>
88914
88915 #include "internal.h"
88916
88917@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88918 return NULL;
88919
88920 pmd = pmd_alloc(mm, pud, addr);
88921- if (!pmd)
88922+ if (!pmd) {
88923+ pud_free(mm, pud);
88924 return NULL;
88925+ }
88926
88927 VM_BUG_ON(pmd_trans_huge(*pmd));
88928
88929@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88930 continue;
88931 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88932 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88933+
88934+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88935+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88936+ pte = pte_exprotect(pte);
88937+#endif
88938+
88939 pte = move_soft_dirty_pte(pte);
88940 set_pte_at(mm, new_addr, new_pte, pte);
88941 }
88942@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88943 if (is_vm_hugetlb_page(vma))
88944 goto Einval;
88945
88946+#ifdef CONFIG_PAX_SEGMEXEC
88947+ if (pax_find_mirror_vma(vma))
88948+ goto Einval;
88949+#endif
88950+
88951 /* We can't remap across vm area boundaries */
88952 if (old_len > vma->vm_end - addr)
88953 goto Efault;
88954@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88955 unsigned long ret = -EINVAL;
88956 unsigned long charged = 0;
88957 unsigned long map_flags;
88958+ unsigned long pax_task_size = TASK_SIZE;
88959
88960 if (new_addr & ~PAGE_MASK)
88961 goto out;
88962
88963- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88964+#ifdef CONFIG_PAX_SEGMEXEC
88965+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88966+ pax_task_size = SEGMEXEC_TASK_SIZE;
88967+#endif
88968+
88969+ pax_task_size -= PAGE_SIZE;
88970+
88971+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88972 goto out;
88973
88974 /* Check if the location we're moving into overlaps the
88975 * old location at all, and fail if it does.
88976 */
88977- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88978- goto out;
88979-
88980- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88981+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88982 goto out;
88983
88984 ret = do_munmap(mm, new_addr, new_len);
88985@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88986 unsigned long ret = -EINVAL;
88987 unsigned long charged = 0;
88988 bool locked = false;
88989+ unsigned long pax_task_size = TASK_SIZE;
88990
88991 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88992 return ret;
88993@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88994 if (!new_len)
88995 return ret;
88996
88997+#ifdef CONFIG_PAX_SEGMEXEC
88998+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88999+ pax_task_size = SEGMEXEC_TASK_SIZE;
89000+#endif
89001+
89002+ pax_task_size -= PAGE_SIZE;
89003+
89004+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
89005+ old_len > pax_task_size || addr > pax_task_size-old_len)
89006+ return ret;
89007+
89008 down_write(&current->mm->mmap_sem);
89009
89010 if (flags & MREMAP_FIXED) {
89011@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89012 new_addr = addr;
89013 }
89014 ret = addr;
89015+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
89016 goto out;
89017 }
89018 }
89019@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89020 goto out;
89021 }
89022
89023+ map_flags = vma->vm_flags;
89024 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
89025+ if (!(ret & ~PAGE_MASK)) {
89026+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
89027+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
89028+ }
89029 }
89030 out:
89031 if (ret & ~PAGE_MASK)
89032diff --git a/mm/nommu.c b/mm/nommu.c
89033index ecd1f15..77039bd 100644
89034--- a/mm/nommu.c
89035+++ b/mm/nommu.c
89036@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
89037 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
89038 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
89039 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
89040-int heap_stack_gap = 0;
89041
89042 atomic_long_t mmap_pages_allocated;
89043
89044@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
89045 EXPORT_SYMBOL(find_vma);
89046
89047 /*
89048- * find a VMA
89049- * - we don't extend stack VMAs under NOMMU conditions
89050- */
89051-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
89052-{
89053- return find_vma(mm, addr);
89054-}
89055-
89056-/*
89057 * expand a stack to a given address
89058 * - not supported under NOMMU conditions
89059 */
89060@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89061
89062 /* most fields are the same, copy all, and then fixup */
89063 *new = *vma;
89064+ INIT_LIST_HEAD(&new->anon_vma_chain);
89065 *region = *vma->vm_region;
89066 new->vm_region = region;
89067
89068@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
89069 }
89070 EXPORT_SYMBOL(generic_file_remap_pages);
89071
89072-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89073- unsigned long addr, void *buf, int len, int write)
89074+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89075+ unsigned long addr, void *buf, size_t len, int write)
89076 {
89077 struct vm_area_struct *vma;
89078
89079@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89080 *
89081 * The caller must hold a reference on @mm.
89082 */
89083-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89084- void *buf, int len, int write)
89085+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
89086+ void *buf, size_t len, int write)
89087 {
89088 return __access_remote_vm(NULL, mm, addr, buf, len, write);
89089 }
89090@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89091 * Access another process' address space.
89092 * - source/target buffer must be kernel space
89093 */
89094-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
89095+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
89096 {
89097 struct mm_struct *mm;
89098
89099diff --git a/mm/page-writeback.c b/mm/page-writeback.c
89100index 3f0c895..60cd104 100644
89101--- a/mm/page-writeback.c
89102+++ b/mm/page-writeback.c
89103@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
89104 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
89105 * - the bdi dirty thresh drops quickly due to change of JBOD workload
89106 */
89107-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
89108+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
89109 unsigned long thresh,
89110 unsigned long bg_thresh,
89111 unsigned long dirty,
89112diff --git a/mm/page_alloc.c b/mm/page_alloc.c
89113index b100255..fba1254 100644
89114--- a/mm/page_alloc.c
89115+++ b/mm/page_alloc.c
89116@@ -60,6 +60,7 @@
89117 #include <linux/page-debug-flags.h>
89118 #include <linux/hugetlb.h>
89119 #include <linux/sched/rt.h>
89120+#include <linux/random.h>
89121
89122 #include <asm/sections.h>
89123 #include <asm/tlbflush.h>
89124@@ -353,7 +354,7 @@ out:
89125 * This usage means that zero-order pages may not be compound.
89126 */
89127
89128-static void free_compound_page(struct page *page)
89129+void free_compound_page(struct page *page)
89130 {
89131 __free_pages_ok(page, compound_order(page));
89132 }
89133@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
89134 int i;
89135 int bad = 0;
89136
89137+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89138+ unsigned long index = 1UL << order;
89139+#endif
89140+
89141 trace_mm_page_free(page, order);
89142 kmemcheck_free_shadow(page, order);
89143
89144@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
89145 debug_check_no_obj_freed(page_address(page),
89146 PAGE_SIZE << order);
89147 }
89148+
89149+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89150+ for (; index; --index)
89151+ sanitize_highpage(page + index - 1);
89152+#endif
89153+
89154 arch_free_page(page, order);
89155 kernel_map_pages(page, 1 << order, 0);
89156
89157@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
89158 local_irq_restore(flags);
89159 }
89160
89161+#ifdef CONFIG_PAX_LATENT_ENTROPY
89162+bool __meminitdata extra_latent_entropy;
89163+
89164+static int __init setup_pax_extra_latent_entropy(char *str)
89165+{
89166+ extra_latent_entropy = true;
89167+ return 0;
89168+}
89169+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
89170+
89171+volatile u64 latent_entropy;
89172+EXPORT_SYMBOL(latent_entropy);
89173+#endif
89174+
89175 void __init __free_pages_bootmem(struct page *page, unsigned int order)
89176 {
89177 unsigned int nr_pages = 1 << order;
89178@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
89179 set_page_count(p, 0);
89180 }
89181
89182+#ifdef CONFIG_PAX_LATENT_ENTROPY
89183+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
89184+ u64 hash = 0;
89185+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
89186+ const u64 *data = lowmem_page_address(page);
89187+
89188+ for (index = 0; index < end; index++)
89189+ hash ^= hash + data[index];
89190+ latent_entropy ^= hash;
89191+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89192+ }
89193+#endif
89194+
89195 page_zone(page)->managed_pages += 1 << order;
89196 set_page_refcounted(page);
89197 __free_pages(page, order);
89198@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89199 arch_alloc_page(page, order);
89200 kernel_map_pages(page, 1 << order, 1);
89201
89202+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89203 if (gfp_flags & __GFP_ZERO)
89204 prep_zero_page(page, order, gfp_flags);
89205+#endif
89206
89207 if (order && (gfp_flags & __GFP_COMP))
89208 prep_compound_page(page, order);
89209diff --git a/mm/page_io.c b/mm/page_io.c
89210index ba05b64..ef2f314 100644
89211--- a/mm/page_io.c
89212+++ b/mm/page_io.c
89213@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89214 struct file *swap_file = sis->swap_file;
89215 struct address_space *mapping = swap_file->f_mapping;
89216 struct iovec iov = {
89217- .iov_base = kmap(page),
89218+ .iov_base = (void __force_user *)kmap(page),
89219 .iov_len = PAGE_SIZE,
89220 };
89221
89222diff --git a/mm/percpu.c b/mm/percpu.c
89223index 8c8e08f..73a5cda 100644
89224--- a/mm/percpu.c
89225+++ b/mm/percpu.c
89226@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89227 static unsigned int pcpu_high_unit_cpu __read_mostly;
89228
89229 /* the address of the first chunk which starts with the kernel static area */
89230-void *pcpu_base_addr __read_mostly;
89231+void *pcpu_base_addr __read_only;
89232 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89233
89234 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89235diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89236index fd26d04..0cea1b0 100644
89237--- a/mm/process_vm_access.c
89238+++ b/mm/process_vm_access.c
89239@@ -13,6 +13,7 @@
89240 #include <linux/uio.h>
89241 #include <linux/sched.h>
89242 #include <linux/highmem.h>
89243+#include <linux/security.h>
89244 #include <linux/ptrace.h>
89245 #include <linux/slab.h>
89246 #include <linux/syscalls.h>
89247@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89248 size_t iov_l_curr_offset = 0;
89249 ssize_t iov_len;
89250
89251+ return -ENOSYS; // PaX: until properly audited
89252+
89253 /*
89254 * Work out how many pages of struct pages we're going to need
89255 * when eventually calling get_user_pages
89256 */
89257 for (i = 0; i < riovcnt; i++) {
89258 iov_len = rvec[i].iov_len;
89259- if (iov_len > 0) {
89260- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89261- + iov_len)
89262- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89263- / PAGE_SIZE + 1;
89264- nr_pages = max(nr_pages, nr_pages_iov);
89265- }
89266+ if (iov_len <= 0)
89267+ continue;
89268+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89269+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89270+ nr_pages = max(nr_pages, nr_pages_iov);
89271 }
89272
89273 if (nr_pages == 0)
89274@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89275 goto free_proc_pages;
89276 }
89277
89278+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89279+ rc = -EPERM;
89280+ goto put_task_struct;
89281+ }
89282+
89283 mm = mm_access(task, PTRACE_MODE_ATTACH);
89284 if (!mm || IS_ERR(mm)) {
89285 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89286diff --git a/mm/rmap.c b/mm/rmap.c
89287index b2e29ac..4168491 100644
89288--- a/mm/rmap.c
89289+++ b/mm/rmap.c
89290@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89291 struct anon_vma *anon_vma = vma->anon_vma;
89292 struct anon_vma_chain *avc;
89293
89294+#ifdef CONFIG_PAX_SEGMEXEC
89295+ struct anon_vma_chain *avc_m = NULL;
89296+#endif
89297+
89298 might_sleep();
89299 if (unlikely(!anon_vma)) {
89300 struct mm_struct *mm = vma->vm_mm;
89301@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89302 if (!avc)
89303 goto out_enomem;
89304
89305+#ifdef CONFIG_PAX_SEGMEXEC
89306+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89307+ if (!avc_m)
89308+ goto out_enomem_free_avc;
89309+#endif
89310+
89311 anon_vma = find_mergeable_anon_vma(vma);
89312 allocated = NULL;
89313 if (!anon_vma) {
89314@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89315 /* page_table_lock to protect against threads */
89316 spin_lock(&mm->page_table_lock);
89317 if (likely(!vma->anon_vma)) {
89318+
89319+#ifdef CONFIG_PAX_SEGMEXEC
89320+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89321+
89322+ if (vma_m) {
89323+ BUG_ON(vma_m->anon_vma);
89324+ vma_m->anon_vma = anon_vma;
89325+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89326+ avc_m = NULL;
89327+ }
89328+#endif
89329+
89330 vma->anon_vma = anon_vma;
89331 anon_vma_chain_link(vma, avc, anon_vma);
89332 allocated = NULL;
89333@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89334
89335 if (unlikely(allocated))
89336 put_anon_vma(allocated);
89337+
89338+#ifdef CONFIG_PAX_SEGMEXEC
89339+ if (unlikely(avc_m))
89340+ anon_vma_chain_free(avc_m);
89341+#endif
89342+
89343 if (unlikely(avc))
89344 anon_vma_chain_free(avc);
89345 }
89346 return 0;
89347
89348 out_enomem_free_avc:
89349+
89350+#ifdef CONFIG_PAX_SEGMEXEC
89351+ if (avc_m)
89352+ anon_vma_chain_free(avc_m);
89353+#endif
89354+
89355 anon_vma_chain_free(avc);
89356 out_enomem:
89357 return -ENOMEM;
89358@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89359 * Attach the anon_vmas from src to dst.
89360 * Returns 0 on success, -ENOMEM on failure.
89361 */
89362-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89363+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89364 {
89365 struct anon_vma_chain *avc, *pavc;
89366 struct anon_vma *root = NULL;
89367@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89368 * the corresponding VMA in the parent process is attached to.
89369 * Returns 0 on success, non-zero on failure.
89370 */
89371-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89372+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89373 {
89374 struct anon_vma_chain *avc;
89375 struct anon_vma *anon_vma;
89376@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89377 void __init anon_vma_init(void)
89378 {
89379 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89380- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89381- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89382+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89383+ anon_vma_ctor);
89384+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89385+ SLAB_PANIC|SLAB_NO_SANITIZE);
89386 }
89387
89388 /*
89389diff --git a/mm/shmem.c b/mm/shmem.c
89390index e43dc55..930e3a2 100644
89391--- a/mm/shmem.c
89392+++ b/mm/shmem.c
89393@@ -33,7 +33,7 @@
89394 #include <linux/swap.h>
89395 #include <linux/aio.h>
89396
89397-static struct vfsmount *shm_mnt;
89398+struct vfsmount *shm_mnt;
89399
89400 #ifdef CONFIG_SHMEM
89401 /*
89402@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89403 #define BOGO_DIRENT_SIZE 20
89404
89405 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89406-#define SHORT_SYMLINK_LEN 128
89407+#define SHORT_SYMLINK_LEN 64
89408
89409 /*
89410 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89411@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89412 static int shmem_xattr_validate(const char *name)
89413 {
89414 struct { const char *prefix; size_t len; } arr[] = {
89415+
89416+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89417+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89418+#endif
89419+
89420 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89421 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89422 };
89423@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89424 if (err)
89425 return err;
89426
89427+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89428+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89429+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89430+ return -EOPNOTSUPP;
89431+ if (size > 8)
89432+ return -EINVAL;
89433+ }
89434+#endif
89435+
89436 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89437 }
89438
89439@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89440 int err = -ENOMEM;
89441
89442 /* Round up to L1_CACHE_BYTES to resist false sharing */
89443- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89444- L1_CACHE_BYTES), GFP_KERNEL);
89445+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89446 if (!sbinfo)
89447 return -ENOMEM;
89448
89449diff --git a/mm/slab.c b/mm/slab.c
89450index 2580db0..0523956 100644
89451--- a/mm/slab.c
89452+++ b/mm/slab.c
89453@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89454 if ((x)->max_freeable < i) \
89455 (x)->max_freeable = i; \
89456 } while (0)
89457-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89458-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89459-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89460-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89461+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89462+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89463+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89464+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89465+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89466+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89467 #else
89468 #define STATS_INC_ACTIVE(x) do { } while (0)
89469 #define STATS_DEC_ACTIVE(x) do { } while (0)
89470@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89471 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89472 #define STATS_INC_FREEHIT(x) do { } while (0)
89473 #define STATS_INC_FREEMISS(x) do { } while (0)
89474+#define STATS_INC_SANITIZED(x) do { } while (0)
89475+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89476 #endif
89477
89478 #if DEBUG
89479@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89480 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89481 */
89482 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89483- const struct slab *slab, void *obj)
89484+ const struct slab *slab, const void *obj)
89485 {
89486 u32 offset = (obj - slab->s_mem);
89487 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89488@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89489 */
89490
89491 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89492- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89493+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89494
89495 if (INDEX_AC != INDEX_NODE)
89496 kmalloc_caches[INDEX_NODE] =
89497 create_kmalloc_cache("kmalloc-node",
89498- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89499+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89500
89501 slab_early_init = 0;
89502
89503@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89504 struct array_cache *ac = cpu_cache_get(cachep);
89505
89506 check_irq_off();
89507+
89508+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89509+ if (pax_sanitize_slab) {
89510+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89511+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89512+
89513+ if (cachep->ctor)
89514+ cachep->ctor(objp);
89515+
89516+ STATS_INC_SANITIZED(cachep);
89517+ } else
89518+ STATS_INC_NOT_SANITIZED(cachep);
89519+ }
89520+#endif
89521+
89522 kmemleak_free_recursive(objp, cachep->flags);
89523 objp = cache_free_debugcheck(cachep, objp, caller);
89524
89525@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89526
89527 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89528 return;
89529+ VM_BUG_ON(!virt_addr_valid(objp));
89530 local_irq_save(flags);
89531 kfree_debugcheck(objp);
89532 c = virt_to_cache(objp);
89533@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89534 }
89535 /* cpu stats */
89536 {
89537- unsigned long allochit = atomic_read(&cachep->allochit);
89538- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89539- unsigned long freehit = atomic_read(&cachep->freehit);
89540- unsigned long freemiss = atomic_read(&cachep->freemiss);
89541+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89542+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89543+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89544+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89545
89546 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89547 allochit, allocmiss, freehit, freemiss);
89548 }
89549+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89550+ {
89551+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89552+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89553+
89554+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89555+ }
89556+#endif
89557 #endif
89558 }
89559
89560@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89561 static int __init slab_proc_init(void)
89562 {
89563 #ifdef CONFIG_DEBUG_SLAB_LEAK
89564- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89565+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89566 #endif
89567 return 0;
89568 }
89569 module_init(slab_proc_init);
89570 #endif
89571
89572+bool is_usercopy_object(const void *ptr)
89573+{
89574+ struct page *page;
89575+ struct kmem_cache *cachep;
89576+
89577+ if (ZERO_OR_NULL_PTR(ptr))
89578+ return false;
89579+
89580+ if (!slab_is_available())
89581+ return false;
89582+
89583+ if (!virt_addr_valid(ptr))
89584+ return false;
89585+
89586+ page = virt_to_head_page(ptr);
89587+
89588+ if (!PageSlab(page))
89589+ return false;
89590+
89591+ cachep = page->slab_cache;
89592+ return cachep->flags & SLAB_USERCOPY;
89593+}
89594+
89595+#ifdef CONFIG_PAX_USERCOPY
89596+const char *check_heap_object(const void *ptr, unsigned long n)
89597+{
89598+ struct page *page;
89599+ struct kmem_cache *cachep;
89600+ struct slab *slabp;
89601+ unsigned int objnr;
89602+ unsigned long offset;
89603+
89604+ if (ZERO_OR_NULL_PTR(ptr))
89605+ return "<null>";
89606+
89607+ if (!virt_addr_valid(ptr))
89608+ return NULL;
89609+
89610+ page = virt_to_head_page(ptr);
89611+
89612+ if (!PageSlab(page))
89613+ return NULL;
89614+
89615+ cachep = page->slab_cache;
89616+ if (!(cachep->flags & SLAB_USERCOPY))
89617+ return cachep->name;
89618+
89619+ slabp = page->slab_page;
89620+ objnr = obj_to_index(cachep, slabp, ptr);
89621+ BUG_ON(objnr >= cachep->num);
89622+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89623+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89624+ return NULL;
89625+
89626+ return cachep->name;
89627+}
89628+#endif
89629+
89630 /**
89631 * ksize - get the actual amount of memory allocated for a given object
89632 * @objp: Pointer to the object
89633diff --git a/mm/slab.h b/mm/slab.h
89634index a535033..2f98fe5 100644
89635--- a/mm/slab.h
89636+++ b/mm/slab.h
89637@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89638 /* The slab cache that manages slab cache information */
89639 extern struct kmem_cache *kmem_cache;
89640
89641+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89642+#ifdef CONFIG_X86_64
89643+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89644+#else
89645+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89646+#endif
89647+extern bool pax_sanitize_slab;
89648+#endif
89649+
89650 unsigned long calculate_alignment(unsigned long flags,
89651 unsigned long align, unsigned long size);
89652
89653@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89654
89655 /* Legal flag mask for kmem_cache_create(), for various configurations */
89656 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89657- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89658+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89659+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89660
89661 #if defined(CONFIG_DEBUG_SLAB)
89662 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89663@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89664 return s;
89665
89666 page = virt_to_head_page(x);
89667+
89668+ BUG_ON(!PageSlab(page));
89669+
89670 cachep = page->slab_cache;
89671 if (slab_equal_or_root(cachep, s))
89672 return cachep;
89673diff --git a/mm/slab_common.c b/mm/slab_common.c
89674index 538bade..36fed99 100644
89675--- a/mm/slab_common.c
89676+++ b/mm/slab_common.c
89677@@ -22,11 +22,22 @@
89678
89679 #include "slab.h"
89680
89681-enum slab_state slab_state;
89682+enum slab_state slab_state __read_only;
89683 LIST_HEAD(slab_caches);
89684 DEFINE_MUTEX(slab_mutex);
89685 struct kmem_cache *kmem_cache;
89686
89687+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89688+bool pax_sanitize_slab __read_only = true;
89689+static int __init pax_sanitize_slab_setup(char *str)
89690+{
89691+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89692+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89693+ return 1;
89694+}
89695+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89696+#endif
89697+
89698 #ifdef CONFIG_DEBUG_VM
89699 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89700 size_t size)
89701@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89702
89703 err = __kmem_cache_create(s, flags);
89704 if (!err) {
89705- s->refcount = 1;
89706+ atomic_set(&s->refcount, 1);
89707 list_add(&s->list, &slab_caches);
89708 memcg_cache_list_add(memcg, s);
89709 } else {
89710@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89711
89712 get_online_cpus();
89713 mutex_lock(&slab_mutex);
89714- s->refcount--;
89715- if (!s->refcount) {
89716+ if (atomic_dec_and_test(&s->refcount)) {
89717 list_del(&s->list);
89718
89719 if (!__kmem_cache_shutdown(s)) {
89720@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89721 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89722 name, size, err);
89723
89724- s->refcount = -1; /* Exempt from merging for now */
89725+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89726 }
89727
89728 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89729@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89730
89731 create_boot_cache(s, name, size, flags);
89732 list_add(&s->list, &slab_caches);
89733- s->refcount = 1;
89734+ atomic_set(&s->refcount, 1);
89735 return s;
89736 }
89737
89738@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89739 EXPORT_SYMBOL(kmalloc_dma_caches);
89740 #endif
89741
89742+#ifdef CONFIG_PAX_USERCOPY_SLABS
89743+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89744+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89745+#endif
89746+
89747 /*
89748 * Conversion table for small slabs sizes / 8 to the index in the
89749 * kmalloc array. This is necessary for slabs < 192 since we have non power
89750@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89751 return kmalloc_dma_caches[index];
89752
89753 #endif
89754+
89755+#ifdef CONFIG_PAX_USERCOPY_SLABS
89756+ if (unlikely((flags & GFP_USERCOPY)))
89757+ return kmalloc_usercopy_caches[index];
89758+
89759+#endif
89760+
89761 return kmalloc_caches[index];
89762 }
89763
89764@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89765 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89766 if (!kmalloc_caches[i]) {
89767 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89768- 1 << i, flags);
89769+ 1 << i, SLAB_USERCOPY | flags);
89770 }
89771
89772 /*
89773@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89774 * earlier power of two caches
89775 */
89776 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89777- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89778+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89779
89780 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89781- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89782+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89783 }
89784
89785 /* Kmalloc array is now usable */
89786@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89787 }
89788 }
89789 #endif
89790+
89791+#ifdef CONFIG_PAX_USERCOPY_SLABS
89792+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89793+ struct kmem_cache *s = kmalloc_caches[i];
89794+
89795+ if (s) {
89796+ int size = kmalloc_size(i);
89797+ char *n = kasprintf(GFP_NOWAIT,
89798+ "usercopy-kmalloc-%d", size);
89799+
89800+ BUG_ON(!n);
89801+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89802+ size, SLAB_USERCOPY | flags);
89803+ }
89804+ }
89805+#endif
89806+
89807 }
89808 #endif /* !CONFIG_SLOB */
89809
89810@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89811 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89812 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89813 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89814+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89815+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89816+#endif
89817 #endif
89818 seq_putc(m, '\n');
89819 }
89820diff --git a/mm/slob.c b/mm/slob.c
89821index 91bd3f2..e2f549e 100644
89822--- a/mm/slob.c
89823+++ b/mm/slob.c
89824@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89825 /*
89826 * Return the size of a slob block.
89827 */
89828-static slobidx_t slob_units(slob_t *s)
89829+static slobidx_t slob_units(const slob_t *s)
89830 {
89831 if (s->units > 0)
89832 return s->units;
89833@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89834 /*
89835 * Return the next free slob block pointer after this one.
89836 */
89837-static slob_t *slob_next(slob_t *s)
89838+static slob_t *slob_next(const slob_t *s)
89839 {
89840 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89841 slobidx_t next;
89842@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89843 /*
89844 * Returns true if s is the last free block in its page.
89845 */
89846-static int slob_last(slob_t *s)
89847+static int slob_last(const slob_t *s)
89848 {
89849 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89850 }
89851
89852-static void *slob_new_pages(gfp_t gfp, int order, int node)
89853+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89854 {
89855- void *page;
89856+ struct page *page;
89857
89858 #ifdef CONFIG_NUMA
89859 if (node != NUMA_NO_NODE)
89860@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89861 if (!page)
89862 return NULL;
89863
89864- return page_address(page);
89865+ __SetPageSlab(page);
89866+ return page;
89867 }
89868
89869-static void slob_free_pages(void *b, int order)
89870+static void slob_free_pages(struct page *sp, int order)
89871 {
89872 if (current->reclaim_state)
89873 current->reclaim_state->reclaimed_slab += 1 << order;
89874- free_pages((unsigned long)b, order);
89875+ __ClearPageSlab(sp);
89876+ page_mapcount_reset(sp);
89877+ sp->private = 0;
89878+ __free_pages(sp, order);
89879 }
89880
89881 /*
89882@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89883
89884 /* Not enough space: must allocate a new page */
89885 if (!b) {
89886- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89887- if (!b)
89888+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89889+ if (!sp)
89890 return NULL;
89891- sp = virt_to_page(b);
89892- __SetPageSlab(sp);
89893+ b = page_address(sp);
89894
89895 spin_lock_irqsave(&slob_lock, flags);
89896 sp->units = SLOB_UNITS(PAGE_SIZE);
89897 sp->freelist = b;
89898+ sp->private = 0;
89899 INIT_LIST_HEAD(&sp->list);
89900 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89901 set_slob_page_free(sp, slob_list);
89902@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89903 if (slob_page_free(sp))
89904 clear_slob_page_free(sp);
89905 spin_unlock_irqrestore(&slob_lock, flags);
89906- __ClearPageSlab(sp);
89907- page_mapcount_reset(sp);
89908- slob_free_pages(b, 0);
89909+ slob_free_pages(sp, 0);
89910 return;
89911 }
89912
89913+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89914+ if (pax_sanitize_slab)
89915+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89916+#endif
89917+
89918 if (!slob_page_free(sp)) {
89919 /* This slob page is about to become partially free. Easy! */
89920 sp->units = units;
89921@@ -424,11 +431,10 @@ out:
89922 */
89923
89924 static __always_inline void *
89925-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89926+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89927 {
89928- unsigned int *m;
89929- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89930- void *ret;
89931+ slob_t *m;
89932+ void *ret = NULL;
89933
89934 gfp &= gfp_allowed_mask;
89935
89936@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89937
89938 if (!m)
89939 return NULL;
89940- *m = size;
89941+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89942+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89943+ m[0].units = size;
89944+ m[1].units = align;
89945 ret = (void *)m + align;
89946
89947 trace_kmalloc_node(caller, ret,
89948 size, size + align, gfp, node);
89949 } else {
89950 unsigned int order = get_order(size);
89951+ struct page *page;
89952
89953 if (likely(order))
89954 gfp |= __GFP_COMP;
89955- ret = slob_new_pages(gfp, order, node);
89956+ page = slob_new_pages(gfp, order, node);
89957+ if (page) {
89958+ ret = page_address(page);
89959+ page->private = size;
89960+ }
89961
89962 trace_kmalloc_node(caller, ret,
89963 size, PAGE_SIZE << order, gfp, node);
89964 }
89965
89966- kmemleak_alloc(ret, size, 1, gfp);
89967+ return ret;
89968+}
89969+
89970+static __always_inline void *
89971+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89972+{
89973+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89974+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89975+
89976+ if (!ZERO_OR_NULL_PTR(ret))
89977+ kmemleak_alloc(ret, size, 1, gfp);
89978 return ret;
89979 }
89980
89981@@ -493,34 +517,112 @@ void kfree(const void *block)
89982 return;
89983 kmemleak_free(block);
89984
89985+ VM_BUG_ON(!virt_addr_valid(block));
89986 sp = virt_to_page(block);
89987- if (PageSlab(sp)) {
89988+ VM_BUG_ON(!PageSlab(sp));
89989+ if (!sp->private) {
89990 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89991- unsigned int *m = (unsigned int *)(block - align);
89992- slob_free(m, *m + align);
89993- } else
89994+ slob_t *m = (slob_t *)(block - align);
89995+ slob_free(m, m[0].units + align);
89996+ } else {
89997+ __ClearPageSlab(sp);
89998+ page_mapcount_reset(sp);
89999+ sp->private = 0;
90000 __free_pages(sp, compound_order(sp));
90001+ }
90002 }
90003 EXPORT_SYMBOL(kfree);
90004
90005+bool is_usercopy_object(const void *ptr)
90006+{
90007+ if (!slab_is_available())
90008+ return false;
90009+
90010+ // PAX: TODO
90011+
90012+ return false;
90013+}
90014+
90015+#ifdef CONFIG_PAX_USERCOPY
90016+const char *check_heap_object(const void *ptr, unsigned long n)
90017+{
90018+ struct page *page;
90019+ const slob_t *free;
90020+ const void *base;
90021+ unsigned long flags;
90022+
90023+ if (ZERO_OR_NULL_PTR(ptr))
90024+ return "<null>";
90025+
90026+ if (!virt_addr_valid(ptr))
90027+ return NULL;
90028+
90029+ page = virt_to_head_page(ptr);
90030+ if (!PageSlab(page))
90031+ return NULL;
90032+
90033+ if (page->private) {
90034+ base = page;
90035+ if (base <= ptr && n <= page->private - (ptr - base))
90036+ return NULL;
90037+ return "<slob>";
90038+ }
90039+
90040+ /* some tricky double walking to find the chunk */
90041+ spin_lock_irqsave(&slob_lock, flags);
90042+ base = (void *)((unsigned long)ptr & PAGE_MASK);
90043+ free = page->freelist;
90044+
90045+ while (!slob_last(free) && (void *)free <= ptr) {
90046+ base = free + slob_units(free);
90047+ free = slob_next(free);
90048+ }
90049+
90050+ while (base < (void *)free) {
90051+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
90052+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
90053+ int offset;
90054+
90055+ if (ptr < base + align)
90056+ break;
90057+
90058+ offset = ptr - base - align;
90059+ if (offset >= m) {
90060+ base += size;
90061+ continue;
90062+ }
90063+
90064+ if (n > m - offset)
90065+ break;
90066+
90067+ spin_unlock_irqrestore(&slob_lock, flags);
90068+ return NULL;
90069+ }
90070+
90071+ spin_unlock_irqrestore(&slob_lock, flags);
90072+ return "<slob>";
90073+}
90074+#endif
90075+
90076 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
90077 size_t ksize(const void *block)
90078 {
90079 struct page *sp;
90080 int align;
90081- unsigned int *m;
90082+ slob_t *m;
90083
90084 BUG_ON(!block);
90085 if (unlikely(block == ZERO_SIZE_PTR))
90086 return 0;
90087
90088 sp = virt_to_page(block);
90089- if (unlikely(!PageSlab(sp)))
90090- return PAGE_SIZE << compound_order(sp);
90091+ VM_BUG_ON(!PageSlab(sp));
90092+ if (sp->private)
90093+ return sp->private;
90094
90095 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90096- m = (unsigned int *)(block - align);
90097- return SLOB_UNITS(*m) * SLOB_UNIT;
90098+ m = (slob_t *)(block - align);
90099+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
90100 }
90101 EXPORT_SYMBOL(ksize);
90102
90103@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
90104
90105 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
90106 {
90107- void *b;
90108+ void *b = NULL;
90109
90110 flags &= gfp_allowed_mask;
90111
90112 lockdep_trace_alloc(flags);
90113
90114+#ifdef CONFIG_PAX_USERCOPY_SLABS
90115+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
90116+#else
90117 if (c->size < PAGE_SIZE) {
90118 b = slob_alloc(c->size, flags, c->align, node);
90119 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
90120 SLOB_UNITS(c->size) * SLOB_UNIT,
90121 flags, node);
90122 } else {
90123- b = slob_new_pages(flags, get_order(c->size), node);
90124+ struct page *sp;
90125+
90126+ sp = slob_new_pages(flags, get_order(c->size), node);
90127+ if (sp) {
90128+ b = page_address(sp);
90129+ sp->private = c->size;
90130+ }
90131 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
90132 PAGE_SIZE << get_order(c->size),
90133 flags, node);
90134 }
90135+#endif
90136
90137 if (b && c->ctor)
90138 c->ctor(b);
90139@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
90140
90141 static void __kmem_cache_free(void *b, int size)
90142 {
90143- if (size < PAGE_SIZE)
90144+ struct page *sp;
90145+
90146+ sp = virt_to_page(b);
90147+ BUG_ON(!PageSlab(sp));
90148+ if (!sp->private)
90149 slob_free(b, size);
90150 else
90151- slob_free_pages(b, get_order(size));
90152+ slob_free_pages(sp, get_order(size));
90153 }
90154
90155 static void kmem_rcu_free(struct rcu_head *head)
90156@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
90157
90158 void kmem_cache_free(struct kmem_cache *c, void *b)
90159 {
90160+ int size = c->size;
90161+
90162+#ifdef CONFIG_PAX_USERCOPY_SLABS
90163+ if (size + c->align < PAGE_SIZE) {
90164+ size += c->align;
90165+ b -= c->align;
90166+ }
90167+#endif
90168+
90169 kmemleak_free_recursive(b, c->flags);
90170 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
90171 struct slob_rcu *slob_rcu;
90172- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
90173- slob_rcu->size = c->size;
90174+ slob_rcu = b + (size - sizeof(struct slob_rcu));
90175+ slob_rcu->size = size;
90176 call_rcu(&slob_rcu->head, kmem_rcu_free);
90177 } else {
90178- __kmem_cache_free(b, c->size);
90179+ __kmem_cache_free(b, size);
90180 }
90181
90182+#ifdef CONFIG_PAX_USERCOPY_SLABS
90183+ trace_kfree(_RET_IP_, b);
90184+#else
90185 trace_kmem_cache_free(_RET_IP_, b);
90186+#endif
90187+
90188 }
90189 EXPORT_SYMBOL(kmem_cache_free);
90190
90191diff --git a/mm/slub.c b/mm/slub.c
90192index e3ba1f2..bd45dac 100644
90193--- a/mm/slub.c
90194+++ b/mm/slub.c
90195@@ -207,7 +207,7 @@ struct track {
90196
90197 enum track_item { TRACK_ALLOC, TRACK_FREE };
90198
90199-#ifdef CONFIG_SYSFS
90200+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90201 static int sysfs_slab_add(struct kmem_cache *);
90202 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90203 static void sysfs_slab_remove(struct kmem_cache *);
90204@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90205 if (!t->addr)
90206 return;
90207
90208- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90209+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90210 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90211 #ifdef CONFIG_STACKTRACE
90212 {
90213@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90214
90215 slab_free_hook(s, x);
90216
90217+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90218+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90219+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90220+ if (s->ctor)
90221+ s->ctor(x);
90222+ }
90223+#endif
90224+
90225 redo:
90226 /*
90227 * Determine the currently cpus per cpu slab.
90228@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90229 * Merge control. If this is set then no merging of slab caches will occur.
90230 * (Could be removed. This was introduced to pacify the merge skeptics.)
90231 */
90232-static int slub_nomerge;
90233+static int slub_nomerge = 1;
90234
90235 /*
90236 * Calculate the order of allocation given an slab object size.
90237@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90238 s->inuse = size;
90239
90240 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90241+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90242+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90243+#endif
90244 s->ctor)) {
90245 /*
90246 * Relocate free pointer after the object if it is not
90247@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90248 EXPORT_SYMBOL(__kmalloc_node);
90249 #endif
90250
90251+bool is_usercopy_object(const void *ptr)
90252+{
90253+ struct page *page;
90254+ struct kmem_cache *s;
90255+
90256+ if (ZERO_OR_NULL_PTR(ptr))
90257+ return false;
90258+
90259+ if (!slab_is_available())
90260+ return false;
90261+
90262+ if (!virt_addr_valid(ptr))
90263+ return false;
90264+
90265+ page = virt_to_head_page(ptr);
90266+
90267+ if (!PageSlab(page))
90268+ return false;
90269+
90270+ s = page->slab_cache;
90271+ return s->flags & SLAB_USERCOPY;
90272+}
90273+
90274+#ifdef CONFIG_PAX_USERCOPY
90275+const char *check_heap_object(const void *ptr, unsigned long n)
90276+{
90277+ struct page *page;
90278+ struct kmem_cache *s;
90279+ unsigned long offset;
90280+
90281+ if (ZERO_OR_NULL_PTR(ptr))
90282+ return "<null>";
90283+
90284+ if (!virt_addr_valid(ptr))
90285+ return NULL;
90286+
90287+ page = virt_to_head_page(ptr);
90288+
90289+ if (!PageSlab(page))
90290+ return NULL;
90291+
90292+ s = page->slab_cache;
90293+ if (!(s->flags & SLAB_USERCOPY))
90294+ return s->name;
90295+
90296+ offset = (ptr - page_address(page)) % s->size;
90297+ if (offset <= s->object_size && n <= s->object_size - offset)
90298+ return NULL;
90299+
90300+ return s->name;
90301+}
90302+#endif
90303+
90304 size_t ksize(const void *object)
90305 {
90306 struct page *page;
90307@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90308 if (unlikely(ZERO_OR_NULL_PTR(x)))
90309 return;
90310
90311+ VM_BUG_ON(!virt_addr_valid(x));
90312 page = virt_to_head_page(x);
90313 if (unlikely(!PageSlab(page))) {
90314 BUG_ON(!PageCompound(page));
90315@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90316 /*
90317 * We may have set a slab to be unmergeable during bootstrap.
90318 */
90319- if (s->refcount < 0)
90320+ if (atomic_read(&s->refcount) < 0)
90321 return 1;
90322
90323 return 0;
90324@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90325
90326 s = find_mergeable(memcg, size, align, flags, name, ctor);
90327 if (s) {
90328- s->refcount++;
90329+ atomic_inc(&s->refcount);
90330 /*
90331 * Adjust the object sizes so that we clear
90332 * the complete object on kzalloc.
90333@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90334 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90335
90336 if (sysfs_slab_alias(s, name)) {
90337- s->refcount--;
90338+ atomic_dec(&s->refcount);
90339 s = NULL;
90340 }
90341 }
90342@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90343 }
90344 #endif
90345
90346-#ifdef CONFIG_SYSFS
90347+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90348 static int count_inuse(struct page *page)
90349 {
90350 return page->inuse;
90351@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90352 validate_slab_cache(kmalloc_caches[9]);
90353 }
90354 #else
90355-#ifdef CONFIG_SYSFS
90356+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90357 static void resiliency_test(void) {};
90358 #endif
90359 #endif
90360
90361-#ifdef CONFIG_SYSFS
90362+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90363 enum slab_stat_type {
90364 SL_ALL, /* All slabs */
90365 SL_PARTIAL, /* Only partially allocated slabs */
90366@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90367
90368 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90369 {
90370- return sprintf(buf, "%d\n", s->refcount - 1);
90371+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90372 }
90373 SLAB_ATTR_RO(aliases);
90374
90375@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90376 SLAB_ATTR_RO(cache_dma);
90377 #endif
90378
90379+#ifdef CONFIG_PAX_USERCOPY_SLABS
90380+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90381+{
90382+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90383+}
90384+SLAB_ATTR_RO(usercopy);
90385+#endif
90386+
90387 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90388 {
90389 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90390@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90391 #ifdef CONFIG_ZONE_DMA
90392 &cache_dma_attr.attr,
90393 #endif
90394+#ifdef CONFIG_PAX_USERCOPY_SLABS
90395+ &usercopy_attr.attr,
90396+#endif
90397 #ifdef CONFIG_NUMA
90398 &remote_node_defrag_ratio_attr.attr,
90399 #endif
90400@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90401 return name;
90402 }
90403
90404+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90405 static int sysfs_slab_add(struct kmem_cache *s)
90406 {
90407 int err;
90408@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90409 }
90410
90411 s->kobj.kset = slab_kset;
90412- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90413+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90414 if (err) {
90415 kobject_put(&s->kobj);
90416 return err;
90417@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90418 kobject_del(&s->kobj);
90419 kobject_put(&s->kobj);
90420 }
90421+#endif
90422
90423 /*
90424 * Need to buffer aliases during bootup until sysfs becomes
90425@@ -5213,6 +5291,7 @@ struct saved_alias {
90426
90427 static struct saved_alias *alias_list;
90428
90429+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90430 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90431 {
90432 struct saved_alias *al;
90433@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90434 alias_list = al;
90435 return 0;
90436 }
90437+#endif
90438
90439 static int __init slab_sysfs_init(void)
90440 {
90441diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90442index 27eeab3..7c3f7f2 100644
90443--- a/mm/sparse-vmemmap.c
90444+++ b/mm/sparse-vmemmap.c
90445@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90446 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90447 if (!p)
90448 return NULL;
90449- pud_populate(&init_mm, pud, p);
90450+ pud_populate_kernel(&init_mm, pud, p);
90451 }
90452 return pud;
90453 }
90454@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90455 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90456 if (!p)
90457 return NULL;
90458- pgd_populate(&init_mm, pgd, p);
90459+ pgd_populate_kernel(&init_mm, pgd, p);
90460 }
90461 return pgd;
90462 }
90463diff --git a/mm/sparse.c b/mm/sparse.c
90464index 308d503..3dbbd04 100644
90465--- a/mm/sparse.c
90466+++ b/mm/sparse.c
90467@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90468
90469 for (i = 0; i < PAGES_PER_SECTION; i++) {
90470 if (PageHWPoison(&memmap[i])) {
90471- atomic_long_sub(1, &num_poisoned_pages);
90472+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90473 ClearPageHWPoison(&memmap[i]);
90474 }
90475 }
90476diff --git a/mm/swap.c b/mm/swap.c
90477index 62b78a6..0bcf28f 100644
90478--- a/mm/swap.c
90479+++ b/mm/swap.c
90480@@ -31,6 +31,7 @@
90481 #include <linux/memcontrol.h>
90482 #include <linux/gfp.h>
90483 #include <linux/uio.h>
90484+#include <linux/hugetlb.h>
90485
90486 #include "internal.h"
90487
90488@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
90489
90490 __page_cache_release(page);
90491 dtor = get_compound_page_dtor(page);
90492+ if (!PageHuge(page))
90493+ BUG_ON(dtor != free_compound_page);
90494 (*dtor)(page);
90495 }
90496
90497diff --git a/mm/swapfile.c b/mm/swapfile.c
90498index 6cf2e60..d204b3e 100644
90499--- a/mm/swapfile.c
90500+++ b/mm/swapfile.c
90501@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90502
90503 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90504 /* Activity counter to indicate that a swapon or swapoff has occurred */
90505-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90506+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90507
90508 static inline unsigned char swap_count(unsigned char ent)
90509 {
90510@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90511 }
90512 filp_close(swap_file, NULL);
90513 err = 0;
90514- atomic_inc(&proc_poll_event);
90515+ atomic_inc_unchecked(&proc_poll_event);
90516 wake_up_interruptible(&proc_poll_wait);
90517
90518 out_dput:
90519@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90520
90521 poll_wait(file, &proc_poll_wait, wait);
90522
90523- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90524- seq->poll_event = atomic_read(&proc_poll_event);
90525+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90526+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90527 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90528 }
90529
90530@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90531 return ret;
90532
90533 seq = file->private_data;
90534- seq->poll_event = atomic_read(&proc_poll_event);
90535+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90536 return 0;
90537 }
90538
90539@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90540 (frontswap_map) ? "FS" : "");
90541
90542 mutex_unlock(&swapon_mutex);
90543- atomic_inc(&proc_poll_event);
90544+ atomic_inc_unchecked(&proc_poll_event);
90545 wake_up_interruptible(&proc_poll_wait);
90546
90547 if (S_ISREG(inode->i_mode))
90548diff --git a/mm/util.c b/mm/util.c
90549index 7441c41..c3de793 100644
90550--- a/mm/util.c
90551+++ b/mm/util.c
90552@@ -294,6 +294,12 @@ done:
90553 void arch_pick_mmap_layout(struct mm_struct *mm)
90554 {
90555 mm->mmap_base = TASK_UNMAPPED_BASE;
90556+
90557+#ifdef CONFIG_PAX_RANDMMAP
90558+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90559+ mm->mmap_base += mm->delta_mmap;
90560+#endif
90561+
90562 mm->get_unmapped_area = arch_get_unmapped_area;
90563 }
90564 #endif
90565diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90566index 13a5495..6707d97 100644
90567--- a/mm/vmalloc.c
90568+++ b/mm/vmalloc.c
90569@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90570
90571 pte = pte_offset_kernel(pmd, addr);
90572 do {
90573- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90574- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90575+
90576+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90577+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90578+ BUG_ON(!pte_exec(*pte));
90579+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90580+ continue;
90581+ }
90582+#endif
90583+
90584+ {
90585+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90586+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90587+ }
90588 } while (pte++, addr += PAGE_SIZE, addr != end);
90589 }
90590
90591@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90592 pte = pte_alloc_kernel(pmd, addr);
90593 if (!pte)
90594 return -ENOMEM;
90595+
90596+ pax_open_kernel();
90597 do {
90598 struct page *page = pages[*nr];
90599
90600- if (WARN_ON(!pte_none(*pte)))
90601+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90602+ if (pgprot_val(prot) & _PAGE_NX)
90603+#endif
90604+
90605+ if (!pte_none(*pte)) {
90606+ pax_close_kernel();
90607+ WARN_ON(1);
90608 return -EBUSY;
90609- if (WARN_ON(!page))
90610+ }
90611+ if (!page) {
90612+ pax_close_kernel();
90613+ WARN_ON(1);
90614 return -ENOMEM;
90615+ }
90616 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90617 (*nr)++;
90618 } while (pte++, addr += PAGE_SIZE, addr != end);
90619+ pax_close_kernel();
90620 return 0;
90621 }
90622
90623@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90624 pmd_t *pmd;
90625 unsigned long next;
90626
90627- pmd = pmd_alloc(&init_mm, pud, addr);
90628+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90629 if (!pmd)
90630 return -ENOMEM;
90631 do {
90632@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90633 pud_t *pud;
90634 unsigned long next;
90635
90636- pud = pud_alloc(&init_mm, pgd, addr);
90637+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90638 if (!pud)
90639 return -ENOMEM;
90640 do {
90641@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90642 if (addr >= MODULES_VADDR && addr < MODULES_END)
90643 return 1;
90644 #endif
90645+
90646+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90647+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90648+ return 1;
90649+#endif
90650+
90651 return is_vmalloc_addr(x);
90652 }
90653
90654@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90655
90656 if (!pgd_none(*pgd)) {
90657 pud_t *pud = pud_offset(pgd, addr);
90658+#ifdef CONFIG_X86
90659+ if (!pud_large(*pud))
90660+#endif
90661 if (!pud_none(*pud)) {
90662 pmd_t *pmd = pmd_offset(pud, addr);
90663+#ifdef CONFIG_X86
90664+ if (!pmd_large(*pmd))
90665+#endif
90666 if (!pmd_none(*pmd)) {
90667 pte_t *ptep, pte;
90668
90669@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90670 * Allocate a region of KVA of the specified size and alignment, within the
90671 * vstart and vend.
90672 */
90673-static struct vmap_area *alloc_vmap_area(unsigned long size,
90674+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90675 unsigned long align,
90676 unsigned long vstart, unsigned long vend,
90677 int node, gfp_t gfp_mask)
90678@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90679 struct vm_struct *area;
90680
90681 BUG_ON(in_interrupt());
90682+
90683+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90684+ if (flags & VM_KERNEXEC) {
90685+ if (start != VMALLOC_START || end != VMALLOC_END)
90686+ return NULL;
90687+ start = (unsigned long)MODULES_EXEC_VADDR;
90688+ end = (unsigned long)MODULES_EXEC_END;
90689+ }
90690+#endif
90691+
90692 if (flags & VM_IOREMAP)
90693 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90694
90695@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90696 if (count > totalram_pages)
90697 return NULL;
90698
90699+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90700+ if (!(pgprot_val(prot) & _PAGE_NX))
90701+ flags |= VM_KERNEXEC;
90702+#endif
90703+
90704 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90705 __builtin_return_address(0));
90706 if (!area)
90707@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90708 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90709 goto fail;
90710
90711+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90712+ if (!(pgprot_val(prot) & _PAGE_NX))
90713+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90714+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90715+ else
90716+#endif
90717+
90718 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90719 start, end, node, gfp_mask, caller);
90720 if (!area)
90721@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90722 * For tight control over page level allocator and protection flags
90723 * use __vmalloc() instead.
90724 */
90725-
90726 void *vmalloc_exec(unsigned long size)
90727 {
90728- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90729+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90730 NUMA_NO_NODE, __builtin_return_address(0));
90731 }
90732
90733@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90734 {
90735 struct vm_struct *area;
90736
90737+ BUG_ON(vma->vm_mirror);
90738+
90739 size = PAGE_ALIGN(size);
90740
90741 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90742@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90743 v->addr, v->addr + v->size, v->size);
90744
90745 if (v->caller)
90746+#ifdef CONFIG_GRKERNSEC_HIDESYM
90747+ seq_printf(m, " %pK", v->caller);
90748+#else
90749 seq_printf(m, " %pS", v->caller);
90750+#endif
90751
90752 if (v->nr_pages)
90753 seq_printf(m, " pages=%d", v->nr_pages);
90754diff --git a/mm/vmstat.c b/mm/vmstat.c
90755index 20c2ef4..15e7ab7 100644
90756--- a/mm/vmstat.c
90757+++ b/mm/vmstat.c
90758@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90759 *
90760 * vm_stat contains the global counters
90761 */
90762-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90763+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90764 EXPORT_SYMBOL(vm_stat);
90765
90766 #ifdef CONFIG_SMP
90767@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90768 v = p->vm_stat_diff[i];
90769 p->vm_stat_diff[i] = 0;
90770 local_irq_restore(flags);
90771- atomic_long_add(v, &zone->vm_stat[i]);
90772+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90773 global_diff[i] += v;
90774 #ifdef CONFIG_NUMA
90775 /* 3 seconds idle till flush */
90776@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90777
90778 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90779 if (global_diff[i])
90780- atomic_long_add(global_diff[i], &vm_stat[i]);
90781+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90782 }
90783
90784 /*
90785@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90786 if (pset->vm_stat_diff[i]) {
90787 int v = pset->vm_stat_diff[i];
90788 pset->vm_stat_diff[i] = 0;
90789- atomic_long_add(v, &zone->vm_stat[i]);
90790- atomic_long_add(v, &vm_stat[i]);
90791+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90792+ atomic_long_add_unchecked(v, &vm_stat[i]);
90793 }
90794 }
90795 #endif
90796@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90797 start_cpu_timer(cpu);
90798 #endif
90799 #ifdef CONFIG_PROC_FS
90800- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90801- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90802- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90803- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90804+ {
90805+ mode_t gr_mode = S_IRUGO;
90806+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90807+ gr_mode = S_IRUSR;
90808+#endif
90809+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90810+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90811+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90812+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90813+#else
90814+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90815+#endif
90816+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90817+ }
90818 #endif
90819 return 0;
90820 }
90821diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90822index 2fb2d88..8c06e40 100644
90823--- a/net/8021q/vlan.c
90824+++ b/net/8021q/vlan.c
90825@@ -469,7 +469,7 @@ out:
90826 return NOTIFY_DONE;
90827 }
90828
90829-static struct notifier_block vlan_notifier_block __read_mostly = {
90830+static struct notifier_block vlan_notifier_block = {
90831 .notifier_call = vlan_device_event,
90832 };
90833
90834@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90835 err = -EPERM;
90836 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90837 break;
90838- if ((args.u.name_type >= 0) &&
90839- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90840+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90841 struct vlan_net *vn;
90842
90843 vn = net_generic(net, vlan_net_id);
90844diff --git a/net/9p/mod.c b/net/9p/mod.c
90845index 6ab36ae..6f1841b 100644
90846--- a/net/9p/mod.c
90847+++ b/net/9p/mod.c
90848@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90849 void v9fs_register_trans(struct p9_trans_module *m)
90850 {
90851 spin_lock(&v9fs_trans_lock);
90852- list_add_tail(&m->list, &v9fs_trans_list);
90853+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90854 spin_unlock(&v9fs_trans_lock);
90855 }
90856 EXPORT_SYMBOL(v9fs_register_trans);
90857@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90858 void v9fs_unregister_trans(struct p9_trans_module *m)
90859 {
90860 spin_lock(&v9fs_trans_lock);
90861- list_del_init(&m->list);
90862+ pax_list_del_init((struct list_head *)&m->list);
90863 spin_unlock(&v9fs_trans_lock);
90864 }
90865 EXPORT_SYMBOL(v9fs_unregister_trans);
90866diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90867index 3ffda1b..fceac96 100644
90868--- a/net/9p/trans_fd.c
90869+++ b/net/9p/trans_fd.c
90870@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90871 oldfs = get_fs();
90872 set_fs(get_ds());
90873 /* The cast to a user pointer is valid due to the set_fs() */
90874- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90875+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90876 set_fs(oldfs);
90877
90878 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90879diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90880index 876fbe8..8bbea9f 100644
90881--- a/net/atm/atm_misc.c
90882+++ b/net/atm/atm_misc.c
90883@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90884 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90885 return 1;
90886 atm_return(vcc, truesize);
90887- atomic_inc(&vcc->stats->rx_drop);
90888+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90889 return 0;
90890 }
90891 EXPORT_SYMBOL(atm_charge);
90892@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90893 }
90894 }
90895 atm_return(vcc, guess);
90896- atomic_inc(&vcc->stats->rx_drop);
90897+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90898 return NULL;
90899 }
90900 EXPORT_SYMBOL(atm_alloc_charge);
90901@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90902
90903 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90904 {
90905-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90906+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90907 __SONET_ITEMS
90908 #undef __HANDLE_ITEM
90909 }
90910@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90911
90912 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90913 {
90914-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90915+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90916 __SONET_ITEMS
90917 #undef __HANDLE_ITEM
90918 }
90919diff --git a/net/atm/lec.h b/net/atm/lec.h
90920index 4149db1..f2ab682 100644
90921--- a/net/atm/lec.h
90922+++ b/net/atm/lec.h
90923@@ -48,7 +48,7 @@ struct lane2_ops {
90924 const u8 *tlvs, u32 sizeoftlvs);
90925 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90926 const u8 *tlvs, u32 sizeoftlvs);
90927-};
90928+} __no_const;
90929
90930 /*
90931 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90932diff --git a/net/atm/proc.c b/net/atm/proc.c
90933index bbb6461..cf04016 100644
90934--- a/net/atm/proc.c
90935+++ b/net/atm/proc.c
90936@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90937 const struct k_atm_aal_stats *stats)
90938 {
90939 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90940- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90941- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90942- atomic_read(&stats->rx_drop));
90943+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90944+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90945+ atomic_read_unchecked(&stats->rx_drop));
90946 }
90947
90948 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90949diff --git a/net/atm/resources.c b/net/atm/resources.c
90950index 0447d5d..3cf4728 100644
90951--- a/net/atm/resources.c
90952+++ b/net/atm/resources.c
90953@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90954 static void copy_aal_stats(struct k_atm_aal_stats *from,
90955 struct atm_aal_stats *to)
90956 {
90957-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90958+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90959 __AAL_STAT_ITEMS
90960 #undef __HANDLE_ITEM
90961 }
90962@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90963 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90964 struct atm_aal_stats *to)
90965 {
90966-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90967+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90968 __AAL_STAT_ITEMS
90969 #undef __HANDLE_ITEM
90970 }
90971diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90972index 919a5ce..cc6b444 100644
90973--- a/net/ax25/sysctl_net_ax25.c
90974+++ b/net/ax25/sysctl_net_ax25.c
90975@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90976 {
90977 char path[sizeof("net/ax25/") + IFNAMSIZ];
90978 int k;
90979- struct ctl_table *table;
90980+ ctl_table_no_const *table;
90981
90982 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90983 if (!table)
90984diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90985index 62da527..aa27535 100644
90986--- a/net/batman-adv/bat_iv_ogm.c
90987+++ b/net/batman-adv/bat_iv_ogm.c
90988@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90989
90990 /* randomize initial seqno to avoid collision */
90991 get_random_bytes(&random_seqno, sizeof(random_seqno));
90992- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90993+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90994
90995 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90996 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90997@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90998 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90999
91000 /* change sequence number to network order */
91001- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
91002+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
91003 batadv_ogm_packet->seqno = htonl(seqno);
91004- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
91005+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
91006
91007 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
91008 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
91009@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
91010 return;
91011
91012 /* could be changed by schedule_own_packet() */
91013- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
91014+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
91015
91016 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
91017 has_directlink_flag = 1;
91018diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
91019index c478e6b..469fd2f 100644
91020--- a/net/batman-adv/hard-interface.c
91021+++ b/net/batman-adv/hard-interface.c
91022@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
91023 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
91024 dev_add_pack(&hard_iface->batman_adv_ptype);
91025
91026- atomic_set(&hard_iface->frag_seqno, 1);
91027+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
91028 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
91029 hard_iface->net_dev->name);
91030
91031diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
91032index 0f04e1c..9c0ac11 100644
91033--- a/net/batman-adv/soft-interface.c
91034+++ b/net/batman-adv/soft-interface.c
91035@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
91036 primary_if->net_dev->dev_addr, ETH_ALEN);
91037
91038 /* set broadcast sequence number */
91039- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
91040+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
91041 bcast_packet->seqno = htonl(seqno);
91042
91043 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
91044@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
91045 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
91046
91047 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
91048- atomic_set(&bat_priv->bcast_seqno, 1);
91049+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
91050 atomic_set(&bat_priv->tt.vn, 0);
91051 atomic_set(&bat_priv->tt.local_changes, 0);
91052 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
91053diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
91054index b2c94e1..3d47e07 100644
91055--- a/net/batman-adv/types.h
91056+++ b/net/batman-adv/types.h
91057@@ -51,7 +51,7 @@
91058 struct batadv_hard_iface_bat_iv {
91059 unsigned char *ogm_buff;
91060 int ogm_buff_len;
91061- atomic_t ogm_seqno;
91062+ atomic_unchecked_t ogm_seqno;
91063 };
91064
91065 /**
91066@@ -76,7 +76,7 @@ struct batadv_hard_iface {
91067 int16_t if_num;
91068 char if_status;
91069 struct net_device *net_dev;
91070- atomic_t frag_seqno;
91071+ atomic_unchecked_t frag_seqno;
91072 uint8_t num_bcasts;
91073 struct kobject *hardif_obj;
91074 atomic_t refcount;
91075@@ -560,7 +560,7 @@ struct batadv_priv {
91076 #ifdef CONFIG_BATMAN_ADV_DEBUG
91077 atomic_t log_level;
91078 #endif
91079- atomic_t bcast_seqno;
91080+ atomic_unchecked_t bcast_seqno;
91081 atomic_t bcast_queue_left;
91082 atomic_t batman_queue_left;
91083 char num_ifaces;
91084diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
91085index 857e1b8..5ad07b2 100644
91086--- a/net/batman-adv/unicast.c
91087+++ b/net/batman-adv/unicast.c
91088@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
91089 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
91090 frag2->flags = large_tail;
91091
91092- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
91093+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
91094 frag1->seqno = htons(seqno - 1);
91095 frag2->seqno = htons(seqno);
91096
91097diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
91098index 9bd7d95..6c4884f 100644
91099--- a/net/bluetooth/hci_sock.c
91100+++ b/net/bluetooth/hci_sock.c
91101@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
91102 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
91103 }
91104
91105- len = min_t(unsigned int, len, sizeof(uf));
91106+ len = min((size_t)len, sizeof(uf));
91107 if (copy_from_user(&uf, optval, len)) {
91108 err = -EFAULT;
91109 break;
91110diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
91111index 8c3499b..2661c6a 100644
91112--- a/net/bluetooth/l2cap_core.c
91113+++ b/net/bluetooth/l2cap_core.c
91114@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
91115 break;
91116
91117 case L2CAP_CONF_RFC:
91118- if (olen == sizeof(rfc))
91119- memcpy(&rfc, (void *)val, olen);
91120+ if (olen != sizeof(rfc))
91121+ break;
91122+
91123+ memcpy(&rfc, (void *)val, olen);
91124
91125 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
91126 rfc.mode != chan->mode)
91127diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
91128index 0098af8..fb5a31f 100644
91129--- a/net/bluetooth/l2cap_sock.c
91130+++ b/net/bluetooth/l2cap_sock.c
91131@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
91132 struct sock *sk = sock->sk;
91133 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
91134 struct l2cap_options opts;
91135- int len, err = 0;
91136+ int err = 0;
91137+ size_t len = optlen;
91138 u32 opt;
91139
91140 BT_DBG("sk %p", sk);
91141@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
91142 opts.max_tx = chan->max_tx;
91143 opts.txwin_size = chan->tx_win;
91144
91145- len = min_t(unsigned int, sizeof(opts), optlen);
91146+ len = min(sizeof(opts), len);
91147 if (copy_from_user((char *) &opts, optval, len)) {
91148 err = -EFAULT;
91149 break;
91150@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91151 struct bt_security sec;
91152 struct bt_power pwr;
91153 struct l2cap_conn *conn;
91154- int len, err = 0;
91155+ int err = 0;
91156+ size_t len = optlen;
91157 u32 opt;
91158
91159 BT_DBG("sk %p", sk);
91160@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91161
91162 sec.level = BT_SECURITY_LOW;
91163
91164- len = min_t(unsigned int, sizeof(sec), optlen);
91165+ len = min(sizeof(sec), len);
91166 if (copy_from_user((char *) &sec, optval, len)) {
91167 err = -EFAULT;
91168 break;
91169@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91170
91171 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
91172
91173- len = min_t(unsigned int, sizeof(pwr), optlen);
91174+ len = min(sizeof(pwr), len);
91175 if (copy_from_user((char *) &pwr, optval, len)) {
91176 err = -EFAULT;
91177 break;
91178diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
91179index 30b3721..c1bd0a0 100644
91180--- a/net/bluetooth/rfcomm/sock.c
91181+++ b/net/bluetooth/rfcomm/sock.c
91182@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91183 struct sock *sk = sock->sk;
91184 struct bt_security sec;
91185 int err = 0;
91186- size_t len;
91187+ size_t len = optlen;
91188 u32 opt;
91189
91190 BT_DBG("sk %p", sk);
91191@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91192
91193 sec.level = BT_SECURITY_LOW;
91194
91195- len = min_t(unsigned int, sizeof(sec), optlen);
91196+ len = min(sizeof(sec), len);
91197 if (copy_from_user((char *) &sec, optval, len)) {
91198 err = -EFAULT;
91199 break;
91200diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91201index b6e44ad..5b0d514 100644
91202--- a/net/bluetooth/rfcomm/tty.c
91203+++ b/net/bluetooth/rfcomm/tty.c
91204@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91205 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91206
91207 spin_lock_irqsave(&dev->port.lock, flags);
91208- if (dev->port.count > 0) {
91209+ if (atomic_read(&dev->port.count) > 0) {
91210 spin_unlock_irqrestore(&dev->port.lock, flags);
91211 return;
91212 }
91213@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91214 return -ENODEV;
91215
91216 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91217- dev->channel, dev->port.count);
91218+ dev->channel, atomic_read(&dev->port.count));
91219
91220 spin_lock_irqsave(&dev->port.lock, flags);
91221- if (++dev->port.count > 1) {
91222+ if (atomic_inc_return(&dev->port.count) > 1) {
91223 spin_unlock_irqrestore(&dev->port.lock, flags);
91224 return 0;
91225 }
91226@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91227 return;
91228
91229 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91230- dev->port.count);
91231+ atomic_read(&dev->port.count));
91232
91233 spin_lock_irqsave(&dev->port.lock, flags);
91234- if (!--dev->port.count) {
91235+ if (!atomic_dec_return(&dev->port.count)) {
91236 spin_unlock_irqrestore(&dev->port.lock, flags);
91237 if (dev->tty_dev->parent)
91238 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91239diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91240index ac78024..161a80c 100644
91241--- a/net/bridge/netfilter/ebtables.c
91242+++ b/net/bridge/netfilter/ebtables.c
91243@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91244 tmp.valid_hooks = t->table->valid_hooks;
91245 }
91246 mutex_unlock(&ebt_mutex);
91247- if (copy_to_user(user, &tmp, *len) != 0){
91248+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91249 BUGPRINT("c2u Didn't work\n");
91250 ret = -EFAULT;
91251 break;
91252@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91253 goto out;
91254 tmp.valid_hooks = t->valid_hooks;
91255
91256- if (copy_to_user(user, &tmp, *len) != 0) {
91257+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91258 ret = -EFAULT;
91259 break;
91260 }
91261@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91262 tmp.entries_size = t->table->entries_size;
91263 tmp.valid_hooks = t->table->valid_hooks;
91264
91265- if (copy_to_user(user, &tmp, *len) != 0) {
91266+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91267 ret = -EFAULT;
91268 break;
91269 }
91270diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91271index 2bd4b58..0dc30a1 100644
91272--- a/net/caif/cfctrl.c
91273+++ b/net/caif/cfctrl.c
91274@@ -10,6 +10,7 @@
91275 #include <linux/spinlock.h>
91276 #include <linux/slab.h>
91277 #include <linux/pkt_sched.h>
91278+#include <linux/sched.h>
91279 #include <net/caif/caif_layer.h>
91280 #include <net/caif/cfpkt.h>
91281 #include <net/caif/cfctrl.h>
91282@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91283 memset(&dev_info, 0, sizeof(dev_info));
91284 dev_info.id = 0xff;
91285 cfsrvl_init(&this->serv, 0, &dev_info, false);
91286- atomic_set(&this->req_seq_no, 1);
91287- atomic_set(&this->rsp_seq_no, 1);
91288+ atomic_set_unchecked(&this->req_seq_no, 1);
91289+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91290 this->serv.layer.receive = cfctrl_recv;
91291 sprintf(this->serv.layer.name, "ctrl");
91292 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91293@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91294 struct cfctrl_request_info *req)
91295 {
91296 spin_lock_bh(&ctrl->info_list_lock);
91297- atomic_inc(&ctrl->req_seq_no);
91298- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91299+ atomic_inc_unchecked(&ctrl->req_seq_no);
91300+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91301 list_add_tail(&req->list, &ctrl->list);
91302 spin_unlock_bh(&ctrl->info_list_lock);
91303 }
91304@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91305 if (p != first)
91306 pr_warn("Requests are not received in order\n");
91307
91308- atomic_set(&ctrl->rsp_seq_no,
91309+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91310 p->sequence_no);
91311 list_del(&p->list);
91312 goto out;
91313diff --git a/net/can/af_can.c b/net/can/af_can.c
91314index 3ab8dd2..b9aef13 100644
91315--- a/net/can/af_can.c
91316+++ b/net/can/af_can.c
91317@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91318 };
91319
91320 /* notifier block for netdevice event */
91321-static struct notifier_block can_netdev_notifier __read_mostly = {
91322+static struct notifier_block can_netdev_notifier = {
91323 .notifier_call = can_notifier,
91324 };
91325
91326diff --git a/net/can/gw.c b/net/can/gw.c
91327index 2f291f9..98c986a 100644
91328--- a/net/can/gw.c
91329+++ b/net/can/gw.c
91330@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91331 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91332
91333 static HLIST_HEAD(cgw_list);
91334-static struct notifier_block notifier;
91335
91336 static struct kmem_cache *cgw_cache __read_mostly;
91337
91338@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91339 return err;
91340 }
91341
91342+static struct notifier_block notifier = {
91343+ .notifier_call = cgw_notifier
91344+};
91345+
91346 static __init int cgw_module_init(void)
91347 {
91348 /* sanitize given module parameter */
91349@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91350 return -ENOMEM;
91351
91352 /* set notifier */
91353- notifier.notifier_call = cgw_notifier;
91354 register_netdevice_notifier(&notifier);
91355
91356 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91357diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91358index eb0a46a..5f3bae8 100644
91359--- a/net/ceph/messenger.c
91360+++ b/net/ceph/messenger.c
91361@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91362 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91363
91364 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91365-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91366+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91367
91368 static struct page *zero_page; /* used in certain error cases */
91369
91370@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91371 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91372 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91373
91374- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91375+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91376 s = addr_str[i];
91377
91378 switch (ss->ss_family) {
91379diff --git a/net/compat.c b/net/compat.c
91380index f0a1ba6..0541331 100644
91381--- a/net/compat.c
91382+++ b/net/compat.c
91383@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91384 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91385 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91386 return -EFAULT;
91387- kmsg->msg_name = compat_ptr(tmp1);
91388- kmsg->msg_iov = compat_ptr(tmp2);
91389- kmsg->msg_control = compat_ptr(tmp3);
91390+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91391+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91392+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91393 return 0;
91394 }
91395
91396@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91397
91398 if (kern_msg->msg_namelen) {
91399 if (mode == VERIFY_READ) {
91400- int err = move_addr_to_kernel(kern_msg->msg_name,
91401+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91402 kern_msg->msg_namelen,
91403 kern_address);
91404 if (err < 0)
91405@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91406 kern_msg->msg_name = NULL;
91407
91408 tot_len = iov_from_user_compat_to_kern(kern_iov,
91409- (struct compat_iovec __user *)kern_msg->msg_iov,
91410+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91411 kern_msg->msg_iovlen);
91412 if (tot_len >= 0)
91413 kern_msg->msg_iov = kern_iov;
91414@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91415
91416 #define CMSG_COMPAT_FIRSTHDR(msg) \
91417 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91418- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91419+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91420 (struct compat_cmsghdr __user *)NULL)
91421
91422 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91423 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91424 (ucmlen) <= (unsigned long) \
91425 ((mhdr)->msg_controllen - \
91426- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91427+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91428
91429 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91430 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91431 {
91432 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91433- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91434+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91435 msg->msg_controllen)
91436 return NULL;
91437 return (struct compat_cmsghdr __user *)ptr;
91438@@ -219,7 +219,7 @@ Efault:
91439
91440 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91441 {
91442- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91443+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91444 struct compat_cmsghdr cmhdr;
91445 struct compat_timeval ctv;
91446 struct compat_timespec cts[3];
91447@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91448
91449 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91450 {
91451- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91452+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91453 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91454 int fdnum = scm->fp->count;
91455 struct file **fp = scm->fp->fp;
91456@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91457 return -EFAULT;
91458 old_fs = get_fs();
91459 set_fs(KERNEL_DS);
91460- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91461+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91462 set_fs(old_fs);
91463
91464 return err;
91465@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91466 len = sizeof(ktime);
91467 old_fs = get_fs();
91468 set_fs(KERNEL_DS);
91469- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91470+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91471 set_fs(old_fs);
91472
91473 if (!err) {
91474@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91475 case MCAST_JOIN_GROUP:
91476 case MCAST_LEAVE_GROUP:
91477 {
91478- struct compat_group_req __user *gr32 = (void *)optval;
91479+ struct compat_group_req __user *gr32 = (void __user *)optval;
91480 struct group_req __user *kgr =
91481 compat_alloc_user_space(sizeof(struct group_req));
91482 u32 interface;
91483@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91484 case MCAST_BLOCK_SOURCE:
91485 case MCAST_UNBLOCK_SOURCE:
91486 {
91487- struct compat_group_source_req __user *gsr32 = (void *)optval;
91488+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91489 struct group_source_req __user *kgsr = compat_alloc_user_space(
91490 sizeof(struct group_source_req));
91491 u32 interface;
91492@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91493 }
91494 case MCAST_MSFILTER:
91495 {
91496- struct compat_group_filter __user *gf32 = (void *)optval;
91497+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91498 struct group_filter __user *kgf;
91499 u32 interface, fmode, numsrc;
91500
91501@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91502 char __user *optval, int __user *optlen,
91503 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91504 {
91505- struct compat_group_filter __user *gf32 = (void *)optval;
91506+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91507 struct group_filter __user *kgf;
91508 int __user *koptlen;
91509 u32 interface, fmode, numsrc;
91510@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91511
91512 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91513 return -EINVAL;
91514- if (copy_from_user(a, args, nas[call]))
91515+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91516 return -EFAULT;
91517 a0 = a[0];
91518 a1 = a[1];
91519diff --git a/net/core/datagram.c b/net/core/datagram.c
91520index 8ab48cd..57b1a80 100644
91521--- a/net/core/datagram.c
91522+++ b/net/core/datagram.c
91523@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91524 }
91525
91526 kfree_skb(skb);
91527- atomic_inc(&sk->sk_drops);
91528+ atomic_inc_unchecked(&sk->sk_drops);
91529 sk_mem_reclaim_partial(sk);
91530
91531 return err;
91532diff --git a/net/core/dev.c b/net/core/dev.c
91533index 26755dd..2a232de 100644
91534--- a/net/core/dev.c
91535+++ b/net/core/dev.c
91536@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91537 {
91538 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91539 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91540- atomic_long_inc(&dev->rx_dropped);
91541+ atomic_long_inc_unchecked(&dev->rx_dropped);
91542 kfree_skb(skb);
91543 return NET_RX_DROP;
91544 }
91545 }
91546
91547 if (unlikely(!is_skb_forwardable(dev, skb))) {
91548- atomic_long_inc(&dev->rx_dropped);
91549+ atomic_long_inc_unchecked(&dev->rx_dropped);
91550 kfree_skb(skb);
91551 return NET_RX_DROP;
91552 }
91553@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91554
91555 struct dev_gso_cb {
91556 void (*destructor)(struct sk_buff *skb);
91557-};
91558+} __no_const;
91559
91560 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91561
91562@@ -3206,7 +3206,7 @@ enqueue:
91563
91564 local_irq_restore(flags);
91565
91566- atomic_long_inc(&skb->dev->rx_dropped);
91567+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91568 kfree_skb(skb);
91569 return NET_RX_DROP;
91570 }
91571@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91572 }
91573 EXPORT_SYMBOL(netif_rx_ni);
91574
91575-static void net_tx_action(struct softirq_action *h)
91576+static __latent_entropy void net_tx_action(void)
91577 {
91578 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91579
91580@@ -3612,7 +3612,7 @@ ncls:
91581 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91582 } else {
91583 drop:
91584- atomic_long_inc(&skb->dev->rx_dropped);
91585+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91586 kfree_skb(skb);
91587 /* Jamal, now you will not able to escape explaining
91588 * me how you were going to use this. :-)
91589@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91590 }
91591 EXPORT_SYMBOL(netif_napi_del);
91592
91593-static void net_rx_action(struct softirq_action *h)
91594+static __latent_entropy void net_rx_action(void)
91595 {
91596 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91597 unsigned long time_limit = jiffies + 2;
91598@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91599 } else {
91600 netdev_stats_to_stats64(storage, &dev->stats);
91601 }
91602- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91603+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91604 return storage;
91605 }
91606 EXPORT_SYMBOL(dev_get_stats);
91607diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91608index 5b7d0e1..cb960fc 100644
91609--- a/net/core/dev_ioctl.c
91610+++ b/net/core/dev_ioctl.c
91611@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91612 if (no_module && capable(CAP_NET_ADMIN))
91613 no_module = request_module("netdev-%s", name);
91614 if (no_module && capable(CAP_SYS_MODULE)) {
91615+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91616+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91617+#else
91618 if (!request_module("%s", name))
91619 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91620 name);
91621+#endif
91622 }
91623 }
91624 EXPORT_SYMBOL(dev_load);
91625diff --git a/net/core/flow.c b/net/core/flow.c
91626index dfa602c..3103d88 100644
91627--- a/net/core/flow.c
91628+++ b/net/core/flow.c
91629@@ -61,7 +61,7 @@ struct flow_cache {
91630 struct timer_list rnd_timer;
91631 };
91632
91633-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91634+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91635 EXPORT_SYMBOL(flow_cache_genid);
91636 static struct flow_cache flow_cache_global;
91637 static struct kmem_cache *flow_cachep __read_mostly;
91638@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91639
91640 static int flow_entry_valid(struct flow_cache_entry *fle)
91641 {
91642- if (atomic_read(&flow_cache_genid) != fle->genid)
91643+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91644 return 0;
91645 if (fle->object && !fle->object->ops->check(fle->object))
91646 return 0;
91647@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91648 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91649 fcp->hash_count++;
91650 }
91651- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91652+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91653 flo = fle->object;
91654 if (!flo)
91655 goto ret_object;
91656@@ -279,7 +279,7 @@ nocache:
91657 }
91658 flo = resolver(net, key, family, dir, flo, ctx);
91659 if (fle) {
91660- fle->genid = atomic_read(&flow_cache_genid);
91661+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91662 if (!IS_ERR(flo))
91663 fle->object = flo;
91664 else
91665diff --git a/net/core/iovec.c b/net/core/iovec.c
91666index de178e4..1dabd8b 100644
91667--- a/net/core/iovec.c
91668+++ b/net/core/iovec.c
91669@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91670 if (m->msg_namelen) {
91671 if (mode == VERIFY_READ) {
91672 void __user *namep;
91673- namep = (void __user __force *) m->msg_name;
91674+ namep = (void __force_user *) m->msg_name;
91675 err = move_addr_to_kernel(namep, m->msg_namelen,
91676 address);
91677 if (err < 0)
91678@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91679 }
91680
91681 size = m->msg_iovlen * sizeof(struct iovec);
91682- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91683+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91684 return -EFAULT;
91685
91686 m->msg_iov = iov;
91687diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91688index 60533db..14842cc 100644
91689--- a/net/core/neighbour.c
91690+++ b/net/core/neighbour.c
91691@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91692 void __user *buffer, size_t *lenp, loff_t *ppos)
91693 {
91694 int size, ret;
91695- struct ctl_table tmp = *ctl;
91696+ ctl_table_no_const tmp = *ctl;
91697
91698 tmp.extra1 = &zero;
91699 tmp.extra2 = &unres_qlen_max;
91700diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91701index 2bf8329..7960607 100644
91702--- a/net/core/net-procfs.c
91703+++ b/net/core/net-procfs.c
91704@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91705 else
91706 seq_printf(seq, "%04x", ntohs(pt->type));
91707
91708+#ifdef CONFIG_GRKERNSEC_HIDESYM
91709+ seq_printf(seq, " %-8s %pf\n",
91710+ pt->dev ? pt->dev->name : "", NULL);
91711+#else
91712 seq_printf(seq, " %-8s %pf\n",
91713 pt->dev ? pt->dev->name : "", pt->func);
91714+#endif
91715 }
91716
91717 return 0;
91718diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91719index 981fed3..536af34 100644
91720--- a/net/core/net-sysfs.c
91721+++ b/net/core/net-sysfs.c
91722@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91723 }
91724 EXPORT_SYMBOL(netdev_class_remove_file);
91725
91726-int netdev_kobject_init(void)
91727+int __init netdev_kobject_init(void)
91728 {
91729 kobj_ns_type_register(&net_ns_type_operations);
91730 return class_register(&net_class);
91731diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91732index f9765203..9feaef8 100644
91733--- a/net/core/net_namespace.c
91734+++ b/net/core/net_namespace.c
91735@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91736 int error;
91737 LIST_HEAD(net_exit_list);
91738
91739- list_add_tail(&ops->list, list);
91740+ pax_list_add_tail((struct list_head *)&ops->list, list);
91741 if (ops->init || (ops->id && ops->size)) {
91742 for_each_net(net) {
91743 error = ops_init(ops, net);
91744@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91745
91746 out_undo:
91747 /* If I have an error cleanup all namespaces I initialized */
91748- list_del(&ops->list);
91749+ pax_list_del((struct list_head *)&ops->list);
91750 ops_exit_list(ops, &net_exit_list);
91751 ops_free_list(ops, &net_exit_list);
91752 return error;
91753@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91754 struct net *net;
91755 LIST_HEAD(net_exit_list);
91756
91757- list_del(&ops->list);
91758+ pax_list_del((struct list_head *)&ops->list);
91759 for_each_net(net)
91760 list_add_tail(&net->exit_list, &net_exit_list);
91761 ops_exit_list(ops, &net_exit_list);
91762@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91763 mutex_lock(&net_mutex);
91764 error = register_pernet_operations(&pernet_list, ops);
91765 if (!error && (first_device == &pernet_list))
91766- first_device = &ops->list;
91767+ first_device = (struct list_head *)&ops->list;
91768 mutex_unlock(&net_mutex);
91769 return error;
91770 }
91771diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91772index 2c637e9..68c9087 100644
91773--- a/net/core/netpoll.c
91774+++ b/net/core/netpoll.c
91775@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91776 struct udphdr *udph;
91777 struct iphdr *iph;
91778 struct ethhdr *eth;
91779- static atomic_t ip_ident;
91780+ static atomic_unchecked_t ip_ident;
91781 struct ipv6hdr *ip6h;
91782
91783 udp_len = len + sizeof(*udph);
91784@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91785 put_unaligned(0x45, (unsigned char *)iph);
91786 iph->tos = 0;
91787 put_unaligned(htons(ip_len), &(iph->tot_len));
91788- iph->id = htons(atomic_inc_return(&ip_ident));
91789+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91790 iph->frag_off = 0;
91791 iph->ttl = 64;
91792 iph->protocol = IPPROTO_UDP;
91793diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91794index ca198c1d1..125372f 100644
91795--- a/net/core/rtnetlink.c
91796+++ b/net/core/rtnetlink.c
91797@@ -58,7 +58,7 @@ struct rtnl_link {
91798 rtnl_doit_func doit;
91799 rtnl_dumpit_func dumpit;
91800 rtnl_calcit_func calcit;
91801-};
91802+} __no_const;
91803
91804 static DEFINE_MUTEX(rtnl_mutex);
91805
91806@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91807 if (rtnl_link_ops_get(ops->kind))
91808 return -EEXIST;
91809
91810- if (!ops->dellink)
91811- ops->dellink = unregister_netdevice_queue;
91812+ if (!ops->dellink) {
91813+ pax_open_kernel();
91814+ *(void **)&ops->dellink = unregister_netdevice_queue;
91815+ pax_close_kernel();
91816+ }
91817
91818- list_add_tail(&ops->list, &link_ops);
91819+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91820 return 0;
91821 }
91822 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91823@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91824 for_each_net(net) {
91825 __rtnl_kill_links(net, ops);
91826 }
91827- list_del(&ops->list);
91828+ pax_list_del((struct list_head *)&ops->list);
91829 }
91830 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91831
91832diff --git a/net/core/scm.c b/net/core/scm.c
91833index b4da80b..98d6bdb 100644
91834--- a/net/core/scm.c
91835+++ b/net/core/scm.c
91836@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91837 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91838 {
91839 struct cmsghdr __user *cm
91840- = (__force struct cmsghdr __user *)msg->msg_control;
91841+ = (struct cmsghdr __force_user *)msg->msg_control;
91842 struct cmsghdr cmhdr;
91843 int cmlen = CMSG_LEN(len);
91844 int err;
91845@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91846 err = -EFAULT;
91847 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91848 goto out;
91849- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91850+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91851 goto out;
91852 cmlen = CMSG_SPACE(len);
91853 if (msg->msg_controllen < cmlen)
91854@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91855 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91856 {
91857 struct cmsghdr __user *cm
91858- = (__force struct cmsghdr __user*)msg->msg_control;
91859+ = (struct cmsghdr __force_user *)msg->msg_control;
91860
91861 int fdmax = 0;
91862 int fdnum = scm->fp->count;
91863@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91864 if (fdnum < fdmax)
91865 fdmax = fdnum;
91866
91867- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91868+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91869 i++, cmfptr++)
91870 {
91871 struct socket *sock;
91872diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91873index 2c3d0f5..f5a326f 100644
91874--- a/net/core/skbuff.c
91875+++ b/net/core/skbuff.c
91876@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91877 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91878 sizeof(struct sk_buff),
91879 0,
91880- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91881+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91882+ SLAB_NO_SANITIZE,
91883 NULL);
91884 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91885 (2*sizeof(struct sk_buff)) +
91886 sizeof(atomic_t),
91887 0,
91888- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91889+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91890+ SLAB_NO_SANITIZE,
91891 NULL);
91892 }
91893
91894diff --git a/net/core/sock.c b/net/core/sock.c
91895index 2c097c5..bf72858 100644
91896--- a/net/core/sock.c
91897+++ b/net/core/sock.c
91898@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91899 struct sk_buff_head *list = &sk->sk_receive_queue;
91900
91901 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91902- atomic_inc(&sk->sk_drops);
91903+ atomic_inc_unchecked(&sk->sk_drops);
91904 trace_sock_rcvqueue_full(sk, skb);
91905 return -ENOMEM;
91906 }
91907@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91908 return err;
91909
91910 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91911- atomic_inc(&sk->sk_drops);
91912+ atomic_inc_unchecked(&sk->sk_drops);
91913 return -ENOBUFS;
91914 }
91915
91916@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91917 skb_dst_force(skb);
91918
91919 spin_lock_irqsave(&list->lock, flags);
91920- skb->dropcount = atomic_read(&sk->sk_drops);
91921+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91922 __skb_queue_tail(list, skb);
91923 spin_unlock_irqrestore(&list->lock, flags);
91924
91925@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91926 skb->dev = NULL;
91927
91928 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91929- atomic_inc(&sk->sk_drops);
91930+ atomic_inc_unchecked(&sk->sk_drops);
91931 goto discard_and_relse;
91932 }
91933 if (nested)
91934@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91935 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91936 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91937 bh_unlock_sock(sk);
91938- atomic_inc(&sk->sk_drops);
91939+ atomic_inc_unchecked(&sk->sk_drops);
91940 goto discard_and_relse;
91941 }
91942
91943@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91944 struct timeval tm;
91945 } v;
91946
91947- int lv = sizeof(int);
91948- int len;
91949+ unsigned int lv = sizeof(int);
91950+ unsigned int len;
91951
91952 if (get_user(len, optlen))
91953 return -EFAULT;
91954- if (len < 0)
91955+ if (len > INT_MAX)
91956 return -EINVAL;
91957
91958 memset(&v, 0, sizeof(v));
91959@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91960
91961 case SO_PEERNAME:
91962 {
91963- char address[128];
91964+ char address[_K_SS_MAXSIZE];
91965
91966 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91967 return -ENOTCONN;
91968- if (lv < len)
91969+ if (lv < len || sizeof address < len)
91970 return -EINVAL;
91971 if (copy_to_user(optval, address, len))
91972 return -EFAULT;
91973@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91974
91975 if (len > lv)
91976 len = lv;
91977- if (copy_to_user(optval, &v, len))
91978+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91979 return -EFAULT;
91980 lenout:
91981 if (put_user(len, optlen))
91982@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91983 */
91984 smp_wmb();
91985 atomic_set(&sk->sk_refcnt, 1);
91986- atomic_set(&sk->sk_drops, 0);
91987+ atomic_set_unchecked(&sk->sk_drops, 0);
91988 }
91989 EXPORT_SYMBOL(sock_init_data);
91990
91991diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91992index a0e9cf6..ef7f9ed 100644
91993--- a/net/core/sock_diag.c
91994+++ b/net/core/sock_diag.c
91995@@ -9,26 +9,33 @@
91996 #include <linux/inet_diag.h>
91997 #include <linux/sock_diag.h>
91998
91999-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
92000+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
92001 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
92002 static DEFINE_MUTEX(sock_diag_table_mutex);
92003
92004 int sock_diag_check_cookie(void *sk, __u32 *cookie)
92005 {
92006+#ifndef CONFIG_GRKERNSEC_HIDESYM
92007 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
92008 cookie[1] != INET_DIAG_NOCOOKIE) &&
92009 ((u32)(unsigned long)sk != cookie[0] ||
92010 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
92011 return -ESTALE;
92012 else
92013+#endif
92014 return 0;
92015 }
92016 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
92017
92018 void sock_diag_save_cookie(void *sk, __u32 *cookie)
92019 {
92020+#ifdef CONFIG_GRKERNSEC_HIDESYM
92021+ cookie[0] = 0;
92022+ cookie[1] = 0;
92023+#else
92024 cookie[0] = (u32)(unsigned long)sk;
92025 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
92026+#endif
92027 }
92028 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
92029
92030@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
92031 mutex_lock(&sock_diag_table_mutex);
92032 if (sock_diag_handlers[hndl->family])
92033 err = -EBUSY;
92034- else
92035+ else {
92036+ pax_open_kernel();
92037 sock_diag_handlers[hndl->family] = hndl;
92038+ pax_close_kernel();
92039+ }
92040 mutex_unlock(&sock_diag_table_mutex);
92041
92042 return err;
92043@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
92044
92045 mutex_lock(&sock_diag_table_mutex);
92046 BUG_ON(sock_diag_handlers[family] != hnld);
92047+ pax_open_kernel();
92048 sock_diag_handlers[family] = NULL;
92049+ pax_close_kernel();
92050 mutex_unlock(&sock_diag_table_mutex);
92051 }
92052 EXPORT_SYMBOL_GPL(sock_diag_unregister);
92053diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
92054index 31107ab..ae03d5a 100644
92055--- a/net/core/sysctl_net_core.c
92056+++ b/net/core/sysctl_net_core.c
92057@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
92058 {
92059 unsigned int orig_size, size;
92060 int ret, i;
92061- struct ctl_table tmp = {
92062+ ctl_table_no_const tmp = {
92063 .data = &size,
92064 .maxlen = sizeof(size),
92065 .mode = table->mode
92066@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
92067
92068 static __net_init int sysctl_core_net_init(struct net *net)
92069 {
92070- struct ctl_table *tbl;
92071+ ctl_table_no_const *tbl = NULL;
92072
92073 net->core.sysctl_somaxconn = SOMAXCONN;
92074
92075- tbl = netns_core_table;
92076 if (!net_eq(net, &init_net)) {
92077- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
92078+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
92079 if (tbl == NULL)
92080 goto err_dup;
92081
92082@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
92083 if (net->user_ns != &init_user_ns) {
92084 tbl[0].procname = NULL;
92085 }
92086- }
92087-
92088- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
92089+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
92090+ } else
92091+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
92092 if (net->core.sysctl_hdr == NULL)
92093 goto err_reg;
92094
92095 return 0;
92096
92097 err_reg:
92098- if (tbl != netns_core_table)
92099- kfree(tbl);
92100+ kfree(tbl);
92101 err_dup:
92102 return -ENOMEM;
92103 }
92104@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
92105 kfree(tbl);
92106 }
92107
92108-static __net_initdata struct pernet_operations sysctl_core_ops = {
92109+static __net_initconst struct pernet_operations sysctl_core_ops = {
92110 .init = sysctl_core_net_init,
92111 .exit = sysctl_core_net_exit,
92112 };
92113diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
92114index dd4d506..fb2fb87 100644
92115--- a/net/decnet/af_decnet.c
92116+++ b/net/decnet/af_decnet.c
92117@@ -465,6 +465,7 @@ static struct proto dn_proto = {
92118 .sysctl_rmem = sysctl_decnet_rmem,
92119 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
92120 .obj_size = sizeof(struct dn_sock),
92121+ .slab_flags = SLAB_USERCOPY,
92122 };
92123
92124 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
92125diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
92126index 5325b54..a0d4d69 100644
92127--- a/net/decnet/sysctl_net_decnet.c
92128+++ b/net/decnet/sysctl_net_decnet.c
92129@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
92130
92131 if (len > *lenp) len = *lenp;
92132
92133- if (copy_to_user(buffer, addr, len))
92134+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
92135 return -EFAULT;
92136
92137 *lenp = len;
92138@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
92139
92140 if (len > *lenp) len = *lenp;
92141
92142- if (copy_to_user(buffer, devname, len))
92143+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
92144 return -EFAULT;
92145
92146 *lenp = len;
92147diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
92148index 3b9d5f2..d7015c6 100644
92149--- a/net/ieee802154/6lowpan.c
92150+++ b/net/ieee802154/6lowpan.c
92151@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
92152 hc06_ptr += 3;
92153 } else {
92154 /* compress nothing */
92155- memcpy(hc06_ptr, &hdr, 4);
92156+ memcpy(hc06_ptr, hdr, 4);
92157 /* replace the top byte with new ECN | DSCP format */
92158 *hc06_ptr = tmp;
92159 hc06_ptr += 4;
92160diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
92161index b4d0be2..443d0f0 100644
92162--- a/net/ipv4/af_inet.c
92163+++ b/net/ipv4/af_inet.c
92164@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
92165
92166 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
92167
92168- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
92169- if (!sysctl_local_reserved_ports)
92170- goto out;
92171-
92172 rc = proto_register(&tcp_prot, 1);
92173 if (rc)
92174- goto out_free_reserved_ports;
92175+ goto out;
92176
92177 rc = proto_register(&udp_prot, 1);
92178 if (rc)
92179@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
92180 proto_unregister(&udp_prot);
92181 out_unregister_tcp_proto:
92182 proto_unregister(&tcp_prot);
92183-out_free_reserved_ports:
92184- kfree(sysctl_local_reserved_ports);
92185 goto out;
92186 }
92187
92188diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92189index 34ca6d5..b6421e8 100644
92190--- a/net/ipv4/devinet.c
92191+++ b/net/ipv4/devinet.c
92192@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92193 idx = 0;
92194 head = &net->dev_index_head[h];
92195 rcu_read_lock();
92196- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92197+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92198 net->dev_base_seq;
92199 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92200 if (idx < s_idx)
92201@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92202 idx = 0;
92203 head = &net->dev_index_head[h];
92204 rcu_read_lock();
92205- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92206+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92207 net->dev_base_seq;
92208 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92209 if (idx < s_idx)
92210@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92211 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92212 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92213
92214-static struct devinet_sysctl_table {
92215+static const struct devinet_sysctl_table {
92216 struct ctl_table_header *sysctl_header;
92217 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92218 } devinet_sysctl = {
92219@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92220 int err;
92221 struct ipv4_devconf *all, *dflt;
92222 #ifdef CONFIG_SYSCTL
92223- struct ctl_table *tbl = ctl_forward_entry;
92224+ ctl_table_no_const *tbl = NULL;
92225 struct ctl_table_header *forw_hdr;
92226 #endif
92227
92228@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92229 goto err_alloc_dflt;
92230
92231 #ifdef CONFIG_SYSCTL
92232- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92233+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92234 if (tbl == NULL)
92235 goto err_alloc_ctl;
92236
92237@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92238 goto err_reg_dflt;
92239
92240 err = -ENOMEM;
92241- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92242+ if (!net_eq(net, &init_net))
92243+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92244+ else
92245+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92246 if (forw_hdr == NULL)
92247 goto err_reg_ctl;
92248 net->ipv4.forw_hdr = forw_hdr;
92249@@ -2240,8 +2243,7 @@ err_reg_ctl:
92250 err_reg_dflt:
92251 __devinet_sysctl_unregister(all);
92252 err_reg_all:
92253- if (tbl != ctl_forward_entry)
92254- kfree(tbl);
92255+ kfree(tbl);
92256 err_alloc_ctl:
92257 #endif
92258 if (dflt != &ipv4_devconf_dflt)
92259diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92260index b3f627a..b0f3e99 100644
92261--- a/net/ipv4/fib_frontend.c
92262+++ b/net/ipv4/fib_frontend.c
92263@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92264 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92265 fib_sync_up(dev);
92266 #endif
92267- atomic_inc(&net->ipv4.dev_addr_genid);
92268+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92269 rt_cache_flush(dev_net(dev));
92270 break;
92271 case NETDEV_DOWN:
92272 fib_del_ifaddr(ifa, NULL);
92273- atomic_inc(&net->ipv4.dev_addr_genid);
92274+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92275 if (ifa->ifa_dev->ifa_list == NULL) {
92276 /* Last address was deleted from this interface.
92277 * Disable IP.
92278@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92279 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92280 fib_sync_up(dev);
92281 #endif
92282- atomic_inc(&net->ipv4.dev_addr_genid);
92283+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92284 rt_cache_flush(net);
92285 break;
92286 case NETDEV_DOWN:
92287diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92288index d5dbca5..6251d5f 100644
92289--- a/net/ipv4/fib_semantics.c
92290+++ b/net/ipv4/fib_semantics.c
92291@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92292 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92293 nh->nh_gw,
92294 nh->nh_parent->fib_scope);
92295- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92296+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92297
92298 return nh->nh_saddr;
92299 }
92300diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92301index 6acb541..9ea617d 100644
92302--- a/net/ipv4/inet_connection_sock.c
92303+++ b/net/ipv4/inet_connection_sock.c
92304@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92305 .range = { 32768, 61000 },
92306 };
92307
92308-unsigned long *sysctl_local_reserved_ports;
92309+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92310 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92311
92312 void inet_get_local_port_range(int *low, int *high)
92313diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92314index 7bd8983..3abdcf6 100644
92315--- a/net/ipv4/inet_hashtables.c
92316+++ b/net/ipv4/inet_hashtables.c
92317@@ -18,12 +18,15 @@
92318 #include <linux/sched.h>
92319 #include <linux/slab.h>
92320 #include <linux/wait.h>
92321+#include <linux/security.h>
92322
92323 #include <net/inet_connection_sock.h>
92324 #include <net/inet_hashtables.h>
92325 #include <net/secure_seq.h>
92326 #include <net/ip.h>
92327
92328+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92329+
92330 /*
92331 * Allocate and initialize a new local port bind bucket.
92332 * The bindhash mutex for snum's hash chain must be held here.
92333@@ -554,6 +557,8 @@ ok:
92334 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92335 spin_unlock(&head->lock);
92336
92337+ gr_update_task_in_ip_table(current, inet_sk(sk));
92338+
92339 if (tw) {
92340 inet_twsk_deschedule(tw, death_row);
92341 while (twrefcnt) {
92342diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92343index 000e3d2..5472da3 100644
92344--- a/net/ipv4/inetpeer.c
92345+++ b/net/ipv4/inetpeer.c
92346@@ -503,8 +503,8 @@ relookup:
92347 if (p) {
92348 p->daddr = *daddr;
92349 atomic_set(&p->refcnt, 1);
92350- atomic_set(&p->rid, 0);
92351- atomic_set(&p->ip_id_count,
92352+ atomic_set_unchecked(&p->rid, 0);
92353+ atomic_set_unchecked(&p->ip_id_count,
92354 (daddr->family == AF_INET) ?
92355 secure_ip_id(daddr->addr.a4) :
92356 secure_ipv6_id(daddr->addr.a6));
92357diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92358index b66910a..cfe416e 100644
92359--- a/net/ipv4/ip_fragment.c
92360+++ b/net/ipv4/ip_fragment.c
92361@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92362 return 0;
92363
92364 start = qp->rid;
92365- end = atomic_inc_return(&peer->rid);
92366+ end = atomic_inc_return_unchecked(&peer->rid);
92367 qp->rid = end;
92368
92369 rc = qp->q.fragments && (end - start) > max;
92370@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92371
92372 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92373 {
92374- struct ctl_table *table;
92375+ ctl_table_no_const *table = NULL;
92376 struct ctl_table_header *hdr;
92377
92378- table = ip4_frags_ns_ctl_table;
92379 if (!net_eq(net, &init_net)) {
92380- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92381+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92382 if (table == NULL)
92383 goto err_alloc;
92384
92385@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92386 /* Don't export sysctls to unprivileged users */
92387 if (net->user_ns != &init_user_ns)
92388 table[0].procname = NULL;
92389- }
92390+ hdr = register_net_sysctl(net, "net/ipv4", table);
92391+ } else
92392+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92393
92394- hdr = register_net_sysctl(net, "net/ipv4", table);
92395 if (hdr == NULL)
92396 goto err_reg;
92397
92398@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92399 return 0;
92400
92401 err_reg:
92402- if (!net_eq(net, &init_net))
92403- kfree(table);
92404+ kfree(table);
92405 err_alloc:
92406 return -ENOMEM;
92407 }
92408diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92409index 8d6939e..19d0a95 100644
92410--- a/net/ipv4/ip_gre.c
92411+++ b/net/ipv4/ip_gre.c
92412@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92413 module_param(log_ecn_error, bool, 0644);
92414 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92415
92416-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92417+static struct rtnl_link_ops ipgre_link_ops;
92418 static int ipgre_tunnel_init(struct net_device *dev);
92419
92420 static int ipgre_net_id __read_mostly;
92421@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92422 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92423 };
92424
92425-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92426+static struct rtnl_link_ops ipgre_link_ops = {
92427 .kind = "gre",
92428 .maxtype = IFLA_GRE_MAX,
92429 .policy = ipgre_policy,
92430@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92431 .fill_info = ipgre_fill_info,
92432 };
92433
92434-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92435+static struct rtnl_link_ops ipgre_tap_ops = {
92436 .kind = "gretap",
92437 .maxtype = IFLA_GRE_MAX,
92438 .policy = ipgre_policy,
92439diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92440index d9c4f11..02b82dbc 100644
92441--- a/net/ipv4/ip_sockglue.c
92442+++ b/net/ipv4/ip_sockglue.c
92443@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92444 len = min_t(unsigned int, len, opt->optlen);
92445 if (put_user(len, optlen))
92446 return -EFAULT;
92447- if (copy_to_user(optval, opt->__data, len))
92448+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92449+ copy_to_user(optval, opt->__data, len))
92450 return -EFAULT;
92451 return 0;
92452 }
92453@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92454 if (sk->sk_type != SOCK_STREAM)
92455 return -ENOPROTOOPT;
92456
92457- msg.msg_control = optval;
92458+ msg.msg_control = (void __force_kernel *)optval;
92459 msg.msg_controllen = len;
92460 msg.msg_flags = flags;
92461
92462diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92463index 17cc0ff..63856c4 100644
92464--- a/net/ipv4/ip_vti.c
92465+++ b/net/ipv4/ip_vti.c
92466@@ -47,7 +47,7 @@
92467 #define HASH_SIZE 16
92468 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92469
92470-static struct rtnl_link_ops vti_link_ops __read_mostly;
92471+static struct rtnl_link_ops vti_link_ops;
92472
92473 static int vti_net_id __read_mostly;
92474 struct vti_net {
92475@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92476 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92477 };
92478
92479-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92480+static struct rtnl_link_ops vti_link_ops = {
92481 .kind = "vti",
92482 .maxtype = IFLA_VTI_MAX,
92483 .policy = vti_policy,
92484diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92485index efa1138..20dbba0 100644
92486--- a/net/ipv4/ipconfig.c
92487+++ b/net/ipv4/ipconfig.c
92488@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92489
92490 mm_segment_t oldfs = get_fs();
92491 set_fs(get_ds());
92492- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92493+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92494 set_fs(oldfs);
92495 return res;
92496 }
92497@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92498
92499 mm_segment_t oldfs = get_fs();
92500 set_fs(get_ds());
92501- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92502+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92503 set_fs(oldfs);
92504 return res;
92505 }
92506@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92507
92508 mm_segment_t oldfs = get_fs();
92509 set_fs(get_ds());
92510- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92511+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92512 set_fs(oldfs);
92513 return res;
92514 }
92515diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92516index b3ac3c3..ec6bd95 100644
92517--- a/net/ipv4/ipip.c
92518+++ b/net/ipv4/ipip.c
92519@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92520 static int ipip_net_id __read_mostly;
92521
92522 static int ipip_tunnel_init(struct net_device *dev);
92523-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92524+static struct rtnl_link_ops ipip_link_ops;
92525
92526 static int ipip_err(struct sk_buff *skb, u32 info)
92527 {
92528@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92529 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92530 };
92531
92532-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92533+static struct rtnl_link_ops ipip_link_ops = {
92534 .kind = "ipip",
92535 .maxtype = IFLA_IPTUN_MAX,
92536 .policy = ipip_policy,
92537diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92538index 85a4f21..1beb1f5 100644
92539--- a/net/ipv4/netfilter/arp_tables.c
92540+++ b/net/ipv4/netfilter/arp_tables.c
92541@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92542 #endif
92543
92544 static int get_info(struct net *net, void __user *user,
92545- const int *len, int compat)
92546+ int len, int compat)
92547 {
92548 char name[XT_TABLE_MAXNAMELEN];
92549 struct xt_table *t;
92550 int ret;
92551
92552- if (*len != sizeof(struct arpt_getinfo)) {
92553- duprintf("length %u != %Zu\n", *len,
92554+ if (len != sizeof(struct arpt_getinfo)) {
92555+ duprintf("length %u != %Zu\n", len,
92556 sizeof(struct arpt_getinfo));
92557 return -EINVAL;
92558 }
92559@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92560 info.size = private->size;
92561 strcpy(info.name, name);
92562
92563- if (copy_to_user(user, &info, *len) != 0)
92564+ if (copy_to_user(user, &info, len) != 0)
92565 ret = -EFAULT;
92566 else
92567 ret = 0;
92568@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92569
92570 switch (cmd) {
92571 case ARPT_SO_GET_INFO:
92572- ret = get_info(sock_net(sk), user, len, 1);
92573+ ret = get_info(sock_net(sk), user, *len, 1);
92574 break;
92575 case ARPT_SO_GET_ENTRIES:
92576 ret = compat_get_entries(sock_net(sk), user, len);
92577@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92578
92579 switch (cmd) {
92580 case ARPT_SO_GET_INFO:
92581- ret = get_info(sock_net(sk), user, len, 0);
92582+ ret = get_info(sock_net(sk), user, *len, 0);
92583 break;
92584
92585 case ARPT_SO_GET_ENTRIES:
92586diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92587index d23118d..6ad7277 100644
92588--- a/net/ipv4/netfilter/ip_tables.c
92589+++ b/net/ipv4/netfilter/ip_tables.c
92590@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92591 #endif
92592
92593 static int get_info(struct net *net, void __user *user,
92594- const int *len, int compat)
92595+ int len, int compat)
92596 {
92597 char name[XT_TABLE_MAXNAMELEN];
92598 struct xt_table *t;
92599 int ret;
92600
92601- if (*len != sizeof(struct ipt_getinfo)) {
92602- duprintf("length %u != %zu\n", *len,
92603+ if (len != sizeof(struct ipt_getinfo)) {
92604+ duprintf("length %u != %zu\n", len,
92605 sizeof(struct ipt_getinfo));
92606 return -EINVAL;
92607 }
92608@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92609 info.size = private->size;
92610 strcpy(info.name, name);
92611
92612- if (copy_to_user(user, &info, *len) != 0)
92613+ if (copy_to_user(user, &info, len) != 0)
92614 ret = -EFAULT;
92615 else
92616 ret = 0;
92617@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92618
92619 switch (cmd) {
92620 case IPT_SO_GET_INFO:
92621- ret = get_info(sock_net(sk), user, len, 1);
92622+ ret = get_info(sock_net(sk), user, *len, 1);
92623 break;
92624 case IPT_SO_GET_ENTRIES:
92625 ret = compat_get_entries(sock_net(sk), user, len);
92626@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92627
92628 switch (cmd) {
92629 case IPT_SO_GET_INFO:
92630- ret = get_info(sock_net(sk), user, len, 0);
92631+ ret = get_info(sock_net(sk), user, *len, 0);
92632 break;
92633
92634 case IPT_SO_GET_ENTRIES:
92635diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92636index 746427c..80eab72 100644
92637--- a/net/ipv4/ping.c
92638+++ b/net/ipv4/ping.c
92639@@ -55,7 +55,7 @@
92640
92641
92642 struct ping_table ping_table;
92643-struct pingv6_ops pingv6_ops;
92644+struct pingv6_ops *pingv6_ops;
92645 EXPORT_SYMBOL_GPL(pingv6_ops);
92646
92647 static u16 ping_port_rover;
92648@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92649 return -ENODEV;
92650 }
92651 }
92652- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92653+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92654 scoped);
92655 rcu_read_unlock();
92656
92657@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92658 }
92659 #if IS_ENABLED(CONFIG_IPV6)
92660 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92661- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92662+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92663 #endif
92664 }
92665
92666@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92667 info, (u8 *)icmph);
92668 #if IS_ENABLED(CONFIG_IPV6)
92669 } else if (family == AF_INET6) {
92670- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92671+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92672 info, (u8 *)icmph);
92673 #endif
92674 }
92675@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92676 return ip_recv_error(sk, msg, len);
92677 #if IS_ENABLED(CONFIG_IPV6)
92678 } else if (family == AF_INET6) {
92679- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92680+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92681 #endif
92682 }
92683 }
92684@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92685 IP6CB(skb)->iif);
92686
92687 if (inet6_sk(sk)->rxopt.all)
92688- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92689+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92690 #endif
92691 } else {
92692 BUG();
92693@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92694 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92695 0, sock_i_ino(sp),
92696 atomic_read(&sp->sk_refcnt), sp,
92697- atomic_read(&sp->sk_drops), len);
92698+ atomic_read_unchecked(&sp->sk_drops), len);
92699 }
92700
92701 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92702diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92703index 61e60d6..d6996cd 100644
92704--- a/net/ipv4/raw.c
92705+++ b/net/ipv4/raw.c
92706@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92707 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92708 {
92709 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92710- atomic_inc(&sk->sk_drops);
92711+ atomic_inc_unchecked(&sk->sk_drops);
92712 kfree_skb(skb);
92713 return NET_RX_DROP;
92714 }
92715@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92716
92717 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92718 {
92719+ struct icmp_filter filter;
92720+
92721 if (optlen > sizeof(struct icmp_filter))
92722 optlen = sizeof(struct icmp_filter);
92723- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92724+ if (copy_from_user(&filter, optval, optlen))
92725 return -EFAULT;
92726+ raw_sk(sk)->filter = filter;
92727 return 0;
92728 }
92729
92730 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92731 {
92732 int len, ret = -EFAULT;
92733+ struct icmp_filter filter;
92734
92735 if (get_user(len, optlen))
92736 goto out;
92737@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92738 if (len > sizeof(struct icmp_filter))
92739 len = sizeof(struct icmp_filter);
92740 ret = -EFAULT;
92741- if (put_user(len, optlen) ||
92742- copy_to_user(optval, &raw_sk(sk)->filter, len))
92743+ filter = raw_sk(sk)->filter;
92744+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92745 goto out;
92746 ret = 0;
92747 out: return ret;
92748@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92749 0, 0L, 0,
92750 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92751 0, sock_i_ino(sp),
92752- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92753+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92754 }
92755
92756 static int raw_seq_show(struct seq_file *seq, void *v)
92757diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92758index a9a54a2..647316e 100644
92759--- a/net/ipv4/route.c
92760+++ b/net/ipv4/route.c
92761@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92762 .maxlen = sizeof(int),
92763 .mode = 0200,
92764 .proc_handler = ipv4_sysctl_rtcache_flush,
92765+ .extra1 = &init_net,
92766 },
92767 { },
92768 };
92769
92770 static __net_init int sysctl_route_net_init(struct net *net)
92771 {
92772- struct ctl_table *tbl;
92773+ ctl_table_no_const *tbl = NULL;
92774
92775- tbl = ipv4_route_flush_table;
92776 if (!net_eq(net, &init_net)) {
92777- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92778+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92779 if (tbl == NULL)
92780 goto err_dup;
92781
92782 /* Don't export sysctls to unprivileged users */
92783 if (net->user_ns != &init_user_ns)
92784 tbl[0].procname = NULL;
92785- }
92786- tbl[0].extra1 = net;
92787+ tbl[0].extra1 = net;
92788+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92789+ } else
92790+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92791
92792- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92793 if (net->ipv4.route_hdr == NULL)
92794 goto err_reg;
92795 return 0;
92796
92797 err_reg:
92798- if (tbl != ipv4_route_flush_table)
92799- kfree(tbl);
92800+ kfree(tbl);
92801 err_dup:
92802 return -ENOMEM;
92803 }
92804@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92805
92806 static __net_init int rt_genid_init(struct net *net)
92807 {
92808- atomic_set(&net->rt_genid, 0);
92809- atomic_set(&net->fnhe_genid, 0);
92810+ atomic_set_unchecked(&net->rt_genid, 0);
92811+ atomic_set_unchecked(&net->fnhe_genid, 0);
92812 get_random_bytes(&net->ipv4.dev_addr_genid,
92813 sizeof(net->ipv4.dev_addr_genid));
92814 return 0;
92815diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92816index 610e324..fd42e75 100644
92817--- a/net/ipv4/sysctl_net_ipv4.c
92818+++ b/net/ipv4/sysctl_net_ipv4.c
92819@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92820 {
92821 int ret;
92822 int range[2];
92823- struct ctl_table tmp = {
92824+ ctl_table_no_const tmp = {
92825 .data = &range,
92826 .maxlen = sizeof(range),
92827 .mode = table->mode,
92828@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92829 int ret;
92830 gid_t urange[2];
92831 kgid_t low, high;
92832- struct ctl_table tmp = {
92833+ ctl_table_no_const tmp = {
92834 .data = &urange,
92835 .maxlen = sizeof(urange),
92836 .mode = table->mode,
92837@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92838 void __user *buffer, size_t *lenp, loff_t *ppos)
92839 {
92840 char val[TCP_CA_NAME_MAX];
92841- struct ctl_table tbl = {
92842+ ctl_table_no_const tbl = {
92843 .data = val,
92844 .maxlen = TCP_CA_NAME_MAX,
92845 };
92846@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92847 void __user *buffer, size_t *lenp,
92848 loff_t *ppos)
92849 {
92850- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92851+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92852 int ret;
92853
92854 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92855@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92856 void __user *buffer, size_t *lenp,
92857 loff_t *ppos)
92858 {
92859- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92860+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92861 int ret;
92862
92863 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92864@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92865 struct mem_cgroup *memcg;
92866 #endif
92867
92868- struct ctl_table tmp = {
92869+ ctl_table_no_const tmp = {
92870 .data = &vec,
92871 .maxlen = sizeof(vec),
92872 .mode = ctl->mode,
92873 };
92874
92875 if (!write) {
92876- ctl->data = &net->ipv4.sysctl_tcp_mem;
92877- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92878+ ctl_table_no_const tcp_mem = *ctl;
92879+
92880+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92881+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92882 }
92883
92884 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92885@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92886 void __user *buffer, size_t *lenp,
92887 loff_t *ppos)
92888 {
92889- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92890+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92891 struct tcp_fastopen_context *ctxt;
92892 int ret;
92893 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92894@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92895 },
92896 {
92897 .procname = "ip_local_reserved_ports",
92898- .data = NULL, /* initialized in sysctl_ipv4_init */
92899+ .data = sysctl_local_reserved_ports,
92900 .maxlen = 65536,
92901 .mode = 0644,
92902 .proc_handler = proc_do_large_bitmap,
92903@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92904
92905 static __net_init int ipv4_sysctl_init_net(struct net *net)
92906 {
92907- struct ctl_table *table;
92908+ ctl_table_no_const *table = NULL;
92909
92910- table = ipv4_net_table;
92911 if (!net_eq(net, &init_net)) {
92912- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92913+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92914 if (table == NULL)
92915 goto err_alloc;
92916
92917@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92918
92919 tcp_init_mem(net);
92920
92921- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92922+ if (!net_eq(net, &init_net))
92923+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92924+ else
92925+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92926 if (net->ipv4.ipv4_hdr == NULL)
92927 goto err_reg;
92928
92929 return 0;
92930
92931 err_reg:
92932- if (!net_eq(net, &init_net))
92933- kfree(table);
92934+ kfree(table);
92935 err_alloc:
92936 return -ENOMEM;
92937 }
92938@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92939 static __init int sysctl_ipv4_init(void)
92940 {
92941 struct ctl_table_header *hdr;
92942- struct ctl_table *i;
92943-
92944- for (i = ipv4_table; i->procname; i++) {
92945- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92946- i->data = sysctl_local_reserved_ports;
92947- break;
92948- }
92949- }
92950- if (!i->procname)
92951- return -EINVAL;
92952
92953 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92954 if (hdr == NULL)
92955diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92956index 3ca2139..c4cc060 100644
92957--- a/net/ipv4/tcp_input.c
92958+++ b/net/ipv4/tcp_input.c
92959@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92960 * simplifies code)
92961 */
92962 static void
92963-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92964+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92965 struct sk_buff *head, struct sk_buff *tail,
92966 u32 start, u32 end)
92967 {
92968@@ -5465,6 +5465,7 @@ discard:
92969 tcp_paws_reject(&tp->rx_opt, 0))
92970 goto discard_and_undo;
92971
92972+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92973 if (th->syn) {
92974 /* We see SYN without ACK. It is attempt of
92975 * simultaneous connect with crossed SYNs.
92976@@ -5515,6 +5516,7 @@ discard:
92977 goto discard;
92978 #endif
92979 }
92980+#endif
92981 /* "fifth, if neither of the SYN or RST bits is set then
92982 * drop the segment and return."
92983 */
92984@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92985 goto discard;
92986
92987 if (th->syn) {
92988- if (th->fin)
92989+ if (th->fin || th->urg || th->psh)
92990 goto discard;
92991 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92992 return 1;
92993diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92994index b299da5..097db06 100644
92995--- a/net/ipv4/tcp_ipv4.c
92996+++ b/net/ipv4/tcp_ipv4.c
92997@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92998 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92999
93000
93001+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93002+extern int grsec_enable_blackhole;
93003+#endif
93004+
93005 #ifdef CONFIG_TCP_MD5SIG
93006 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
93007 __be32 daddr, __be32 saddr, const struct tcphdr *th);
93008@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
93009 return 0;
93010
93011 reset:
93012+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93013+ if (!grsec_enable_blackhole)
93014+#endif
93015 tcp_v4_send_reset(rsk, skb);
93016 discard:
93017 kfree_skb(skb);
93018@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
93019 TCP_SKB_CB(skb)->sacked = 0;
93020
93021 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93022- if (!sk)
93023+ if (!sk) {
93024+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93025+ ret = 1;
93026+#endif
93027 goto no_tcp_socket;
93028-
93029+ }
93030 process:
93031- if (sk->sk_state == TCP_TIME_WAIT)
93032+ if (sk->sk_state == TCP_TIME_WAIT) {
93033+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93034+ ret = 2;
93035+#endif
93036 goto do_time_wait;
93037+ }
93038
93039 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
93040 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93041@@ -2034,6 +2048,10 @@ csum_error:
93042 bad_packet:
93043 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93044 } else {
93045+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93046+ if (!grsec_enable_blackhole || (ret == 1 &&
93047+ (skb->dev->flags & IFF_LOOPBACK)))
93048+#endif
93049 tcp_v4_send_reset(NULL, skb);
93050 }
93051
93052diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
93053index ab1c086..2a8d76b 100644
93054--- a/net/ipv4/tcp_minisocks.c
93055+++ b/net/ipv4/tcp_minisocks.c
93056@@ -27,6 +27,10 @@
93057 #include <net/inet_common.h>
93058 #include <net/xfrm.h>
93059
93060+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93061+extern int grsec_enable_blackhole;
93062+#endif
93063+
93064 int sysctl_tcp_syncookies __read_mostly = 1;
93065 EXPORT_SYMBOL(sysctl_tcp_syncookies);
93066
93067@@ -715,7 +719,10 @@ embryonic_reset:
93068 * avoid becoming vulnerable to outside attack aiming at
93069 * resetting legit local connections.
93070 */
93071- req->rsk_ops->send_reset(sk, skb);
93072+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93073+ if (!grsec_enable_blackhole)
93074+#endif
93075+ req->rsk_ops->send_reset(sk, skb);
93076 } else if (fastopen) { /* received a valid RST pkt */
93077 reqsk_fastopen_remove(sk, req, true);
93078 tcp_reset(sk);
93079diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
93080index d4943f6..e7a74a5 100644
93081--- a/net/ipv4/tcp_probe.c
93082+++ b/net/ipv4/tcp_probe.c
93083@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
93084 if (cnt + width >= len)
93085 break;
93086
93087- if (copy_to_user(buf + cnt, tbuf, width))
93088+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
93089 return -EFAULT;
93090 cnt += width;
93091 }
93092diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
93093index 4b85e6f..22f9ac9 100644
93094--- a/net/ipv4/tcp_timer.c
93095+++ b/net/ipv4/tcp_timer.c
93096@@ -22,6 +22,10 @@
93097 #include <linux/gfp.h>
93098 #include <net/tcp.h>
93099
93100+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93101+extern int grsec_lastack_retries;
93102+#endif
93103+
93104 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
93105 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
93106 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
93107@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
93108 }
93109 }
93110
93111+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93112+ if ((sk->sk_state == TCP_LAST_ACK) &&
93113+ (grsec_lastack_retries > 0) &&
93114+ (grsec_lastack_retries < retry_until))
93115+ retry_until = grsec_lastack_retries;
93116+#endif
93117+
93118 if (retransmits_timed_out(sk, retry_until,
93119 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
93120 /* Has it gone just too far? */
93121diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
93122index 766e6ba..aff2f8d 100644
93123--- a/net/ipv4/udp.c
93124+++ b/net/ipv4/udp.c
93125@@ -87,6 +87,7 @@
93126 #include <linux/types.h>
93127 #include <linux/fcntl.h>
93128 #include <linux/module.h>
93129+#include <linux/security.h>
93130 #include <linux/socket.h>
93131 #include <linux/sockios.h>
93132 #include <linux/igmp.h>
93133@@ -112,6 +113,10 @@
93134 #include <net/busy_poll.h>
93135 #include "udp_impl.h"
93136
93137+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93138+extern int grsec_enable_blackhole;
93139+#endif
93140+
93141 struct udp_table udp_table __read_mostly;
93142 EXPORT_SYMBOL(udp_table);
93143
93144@@ -595,6 +600,9 @@ found:
93145 return s;
93146 }
93147
93148+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93149+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93150+
93151 /*
93152 * This routine is called by the ICMP module when it gets some
93153 * sort of error condition. If err < 0 then the socket should
93154@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93155 dport = usin->sin_port;
93156 if (dport == 0)
93157 return -EINVAL;
93158+
93159+ err = gr_search_udp_sendmsg(sk, usin);
93160+ if (err)
93161+ return err;
93162 } else {
93163 if (sk->sk_state != TCP_ESTABLISHED)
93164 return -EDESTADDRREQ;
93165+
93166+ err = gr_search_udp_sendmsg(sk, NULL);
93167+ if (err)
93168+ return err;
93169+
93170 daddr = inet->inet_daddr;
93171 dport = inet->inet_dport;
93172 /* Open fast path for connected socket.
93173@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93174 IS_UDPLITE(sk));
93175 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93176 IS_UDPLITE(sk));
93177- atomic_inc(&sk->sk_drops);
93178+ atomic_inc_unchecked(&sk->sk_drops);
93179 __skb_unlink(skb, rcvq);
93180 __skb_queue_tail(&list_kill, skb);
93181 }
93182@@ -1223,6 +1240,10 @@ try_again:
93183 if (!skb)
93184 goto out;
93185
93186+ err = gr_search_udp_recvmsg(sk, skb);
93187+ if (err)
93188+ goto out_free;
93189+
93190 ulen = skb->len - sizeof(struct udphdr);
93191 copied = len;
93192 if (copied > ulen)
93193@@ -1256,7 +1277,7 @@ try_again:
93194 if (unlikely(err)) {
93195 trace_kfree_skb(skb, udp_recvmsg);
93196 if (!peeked) {
93197- atomic_inc(&sk->sk_drops);
93198+ atomic_inc_unchecked(&sk->sk_drops);
93199 UDP_INC_STATS_USER(sock_net(sk),
93200 UDP_MIB_INERRORS, is_udplite);
93201 }
93202@@ -1543,7 +1564,7 @@ csum_error:
93203 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93204 drop:
93205 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93206- atomic_inc(&sk->sk_drops);
93207+ atomic_inc_unchecked(&sk->sk_drops);
93208 kfree_skb(skb);
93209 return -1;
93210 }
93211@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93212 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93213
93214 if (!skb1) {
93215- atomic_inc(&sk->sk_drops);
93216+ atomic_inc_unchecked(&sk->sk_drops);
93217 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93218 IS_UDPLITE(sk));
93219 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93220@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93221 goto csum_error;
93222
93223 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93224+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93225+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93226+#endif
93227 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93228
93229 /*
93230@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93231 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93232 0, sock_i_ino(sp),
93233 atomic_read(&sp->sk_refcnt), sp,
93234- atomic_read(&sp->sk_drops), len);
93235+ atomic_read_unchecked(&sp->sk_drops), len);
93236 }
93237
93238 int udp4_seq_show(struct seq_file *seq, void *v)
93239diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93240index 9a459be..c7bc04c 100644
93241--- a/net/ipv4/xfrm4_policy.c
93242+++ b/net/ipv4/xfrm4_policy.c
93243@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93244 fl4->flowi4_tos = iph->tos;
93245 }
93246
93247-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93248+static int xfrm4_garbage_collect(struct dst_ops *ops)
93249 {
93250 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93251
93252- xfrm4_policy_afinfo.garbage_collect(net);
93253+ xfrm_garbage_collect_deferred(net);
93254 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93255 }
93256
93257@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93258
93259 static int __net_init xfrm4_net_init(struct net *net)
93260 {
93261- struct ctl_table *table;
93262+ ctl_table_no_const *table = NULL;
93263 struct ctl_table_header *hdr;
93264
93265- table = xfrm4_policy_table;
93266 if (!net_eq(net, &init_net)) {
93267- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93268+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93269 if (!table)
93270 goto err_alloc;
93271
93272 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93273- }
93274-
93275- hdr = register_net_sysctl(net, "net/ipv4", table);
93276+ hdr = register_net_sysctl(net, "net/ipv4", table);
93277+ } else
93278+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93279 if (!hdr)
93280 goto err_reg;
93281
93282@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93283 return 0;
93284
93285 err_reg:
93286- if (!net_eq(net, &init_net))
93287- kfree(table);
93288+ kfree(table);
93289 err_alloc:
93290 return -ENOMEM;
93291 }
93292diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93293index 498ea99..42501bc 100644
93294--- a/net/ipv6/addrconf.c
93295+++ b/net/ipv6/addrconf.c
93296@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93297 idx = 0;
93298 head = &net->dev_index_head[h];
93299 rcu_read_lock();
93300- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93301+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93302 net->dev_base_seq;
93303 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93304 if (idx < s_idx)
93305@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93306 p.iph.ihl = 5;
93307 p.iph.protocol = IPPROTO_IPV6;
93308 p.iph.ttl = 64;
93309- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93310+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93311
93312 if (ops->ndo_do_ioctl) {
93313 mm_segment_t oldfs = get_fs();
93314@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93315 s_ip_idx = ip_idx = cb->args[2];
93316
93317 rcu_read_lock();
93318- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93319+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93320 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93321 idx = 0;
93322 head = &net->dev_index_head[h];
93323@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93324 dst_free(&ifp->rt->dst);
93325 break;
93326 }
93327- atomic_inc(&net->ipv6.dev_addr_genid);
93328+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93329 }
93330
93331 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93332@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93333 int *valp = ctl->data;
93334 int val = *valp;
93335 loff_t pos = *ppos;
93336- struct ctl_table lctl;
93337+ ctl_table_no_const lctl;
93338 int ret;
93339
93340 /*
93341@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93342 int *valp = ctl->data;
93343 int val = *valp;
93344 loff_t pos = *ppos;
93345- struct ctl_table lctl;
93346+ ctl_table_no_const lctl;
93347 int ret;
93348
93349 /*
93350diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93351index 197e6f4..16d8396 100644
93352--- a/net/ipv6/datagram.c
93353+++ b/net/ipv6/datagram.c
93354@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93355 0,
93356 sock_i_ino(sp),
93357 atomic_read(&sp->sk_refcnt), sp,
93358- atomic_read(&sp->sk_drops));
93359+ atomic_read_unchecked(&sp->sk_drops));
93360 }
93361diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93362index 7cfc8d2..c5394b6 100644
93363--- a/net/ipv6/icmp.c
93364+++ b/net/ipv6/icmp.c
93365@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93366
93367 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93368 {
93369- struct ctl_table *table;
93370+ ctl_table_no_const *table;
93371
93372 table = kmemdup(ipv6_icmp_table_template,
93373 sizeof(ipv6_icmp_table_template),
93374diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93375index 90747f1..505320d 100644
93376--- a/net/ipv6/ip6_gre.c
93377+++ b/net/ipv6/ip6_gre.c
93378@@ -74,7 +74,7 @@ struct ip6gre_net {
93379 struct net_device *fb_tunnel_dev;
93380 };
93381
93382-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93383+static struct rtnl_link_ops ip6gre_link_ops;
93384 static int ip6gre_tunnel_init(struct net_device *dev);
93385 static void ip6gre_tunnel_setup(struct net_device *dev);
93386 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93387@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93388 }
93389
93390
93391-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93392+static struct inet6_protocol ip6gre_protocol = {
93393 .handler = ip6gre_rcv,
93394 .err_handler = ip6gre_err,
93395 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93396@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93397 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93398 };
93399
93400-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93401+static struct rtnl_link_ops ip6gre_link_ops = {
93402 .kind = "ip6gre",
93403 .maxtype = IFLA_GRE_MAX,
93404 .policy = ip6gre_policy,
93405@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93406 .fill_info = ip6gre_fill_info,
93407 };
93408
93409-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93410+static struct rtnl_link_ops ip6gre_tap_ops = {
93411 .kind = "ip6gretap",
93412 .maxtype = IFLA_GRE_MAX,
93413 .policy = ip6gre_policy,
93414diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93415index 46ba243..576f50e 100644
93416--- a/net/ipv6/ip6_tunnel.c
93417+++ b/net/ipv6/ip6_tunnel.c
93418@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93419
93420 static int ip6_tnl_dev_init(struct net_device *dev);
93421 static void ip6_tnl_dev_setup(struct net_device *dev);
93422-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93423+static struct rtnl_link_ops ip6_link_ops;
93424
93425 static int ip6_tnl_net_id __read_mostly;
93426 struct ip6_tnl_net {
93427@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93428 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93429 };
93430
93431-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93432+static struct rtnl_link_ops ip6_link_ops = {
93433 .kind = "ip6tnl",
93434 .maxtype = IFLA_IPTUN_MAX,
93435 .policy = ip6_tnl_policy,
93436diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93437index d1e2e8e..51c19ae 100644
93438--- a/net/ipv6/ipv6_sockglue.c
93439+++ b/net/ipv6/ipv6_sockglue.c
93440@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93441 if (sk->sk_type != SOCK_STREAM)
93442 return -ENOPROTOOPT;
93443
93444- msg.msg_control = optval;
93445+ msg.msg_control = (void __force_kernel *)optval;
93446 msg.msg_controllen = len;
93447 msg.msg_flags = flags;
93448
93449diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93450index 44400c2..8e11f52 100644
93451--- a/net/ipv6/netfilter/ip6_tables.c
93452+++ b/net/ipv6/netfilter/ip6_tables.c
93453@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93454 #endif
93455
93456 static int get_info(struct net *net, void __user *user,
93457- const int *len, int compat)
93458+ int len, int compat)
93459 {
93460 char name[XT_TABLE_MAXNAMELEN];
93461 struct xt_table *t;
93462 int ret;
93463
93464- if (*len != sizeof(struct ip6t_getinfo)) {
93465- duprintf("length %u != %zu\n", *len,
93466+ if (len != sizeof(struct ip6t_getinfo)) {
93467+ duprintf("length %u != %zu\n", len,
93468 sizeof(struct ip6t_getinfo));
93469 return -EINVAL;
93470 }
93471@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93472 info.size = private->size;
93473 strcpy(info.name, name);
93474
93475- if (copy_to_user(user, &info, *len) != 0)
93476+ if (copy_to_user(user, &info, len) != 0)
93477 ret = -EFAULT;
93478 else
93479 ret = 0;
93480@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93481
93482 switch (cmd) {
93483 case IP6T_SO_GET_INFO:
93484- ret = get_info(sock_net(sk), user, len, 1);
93485+ ret = get_info(sock_net(sk), user, *len, 1);
93486 break;
93487 case IP6T_SO_GET_ENTRIES:
93488 ret = compat_get_entries(sock_net(sk), user, len);
93489@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93490
93491 switch (cmd) {
93492 case IP6T_SO_GET_INFO:
93493- ret = get_info(sock_net(sk), user, len, 0);
93494+ ret = get_info(sock_net(sk), user, *len, 0);
93495 break;
93496
93497 case IP6T_SO_GET_ENTRIES:
93498diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93499index dffdc1a..ccc6678 100644
93500--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93501+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93502@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93503
93504 static int nf_ct_frag6_sysctl_register(struct net *net)
93505 {
93506- struct ctl_table *table;
93507+ ctl_table_no_const *table = NULL;
93508 struct ctl_table_header *hdr;
93509
93510- table = nf_ct_frag6_sysctl_table;
93511 if (!net_eq(net, &init_net)) {
93512- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93513+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93514 GFP_KERNEL);
93515 if (table == NULL)
93516 goto err_alloc;
93517@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93518 table[0].data = &net->nf_frag.frags.timeout;
93519 table[1].data = &net->nf_frag.frags.low_thresh;
93520 table[2].data = &net->nf_frag.frags.high_thresh;
93521- }
93522-
93523- hdr = register_net_sysctl(net, "net/netfilter", table);
93524+ hdr = register_net_sysctl(net, "net/netfilter", table);
93525+ } else
93526+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93527 if (hdr == NULL)
93528 goto err_reg;
93529
93530@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93531 return 0;
93532
93533 err_reg:
93534- if (!net_eq(net, &init_net))
93535- kfree(table);
93536+ kfree(table);
93537 err_alloc:
93538 return -ENOMEM;
93539 }
93540diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93541index ab92a36..bb4a528 100644
93542--- a/net/ipv6/output_core.c
93543+++ b/net/ipv6/output_core.c
93544@@ -8,8 +8,8 @@
93545
93546 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93547 {
93548- static atomic_t ipv6_fragmentation_id;
93549- int old, new;
93550+ static atomic_unchecked_t ipv6_fragmentation_id;
93551+ int id;
93552
93553 #if IS_ENABLED(CONFIG_IPV6)
93554 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93555@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93556 }
93557 }
93558 #endif
93559- do {
93560- old = atomic_read(&ipv6_fragmentation_id);
93561- new = old + 1;
93562- if (!new)
93563- new = 1;
93564- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93565- fhdr->identification = htonl(new);
93566+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93567+ if (!id)
93568+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93569+ fhdr->identification = htonl(id);
93570 }
93571 EXPORT_SYMBOL(ipv6_select_ident);
93572
93573diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93574index 18f19df..b46ada1 100644
93575--- a/net/ipv6/ping.c
93576+++ b/net/ipv6/ping.c
93577@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93578 };
93579 #endif
93580
93581+static struct pingv6_ops real_pingv6_ops = {
93582+ .ipv6_recv_error = ipv6_recv_error,
93583+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93584+ .icmpv6_err_convert = icmpv6_err_convert,
93585+ .ipv6_icmp_error = ipv6_icmp_error,
93586+ .ipv6_chk_addr = ipv6_chk_addr,
93587+};
93588+
93589+static struct pingv6_ops dummy_pingv6_ops = {
93590+ .ipv6_recv_error = dummy_ipv6_recv_error,
93591+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93592+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93593+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93594+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93595+};
93596+
93597 int __init pingv6_init(void)
93598 {
93599 #ifdef CONFIG_PROC_FS
93600@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93601 if (ret)
93602 return ret;
93603 #endif
93604- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93605- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93606- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93607- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93608- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93609+ pingv6_ops = &real_pingv6_ops;
93610 return inet6_register_protosw(&pingv6_protosw);
93611 }
93612
93613@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93614 */
93615 void pingv6_exit(void)
93616 {
93617- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93618- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93619- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93620- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93621- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93622+ pingv6_ops = &dummy_pingv6_ops;
93623 #ifdef CONFIG_PROC_FS
93624 unregister_pernet_subsys(&ping_v6_net_ops);
93625 #endif
93626diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93627index cdaed47..515edde9 100644
93628--- a/net/ipv6/raw.c
93629+++ b/net/ipv6/raw.c
93630@@ -108,7 +108,7 @@ found:
93631 */
93632 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93633 {
93634- struct icmp6hdr *_hdr;
93635+ struct icmp6hdr _hdr;
93636 const struct icmp6hdr *hdr;
93637
93638 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93639@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93640 {
93641 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93642 skb_checksum_complete(skb)) {
93643- atomic_inc(&sk->sk_drops);
93644+ atomic_inc_unchecked(&sk->sk_drops);
93645 kfree_skb(skb);
93646 return NET_RX_DROP;
93647 }
93648@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93649 struct raw6_sock *rp = raw6_sk(sk);
93650
93651 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93652- atomic_inc(&sk->sk_drops);
93653+ atomic_inc_unchecked(&sk->sk_drops);
93654 kfree_skb(skb);
93655 return NET_RX_DROP;
93656 }
93657@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93658
93659 if (inet->hdrincl) {
93660 if (skb_checksum_complete(skb)) {
93661- atomic_inc(&sk->sk_drops);
93662+ atomic_inc_unchecked(&sk->sk_drops);
93663 kfree_skb(skb);
93664 return NET_RX_DROP;
93665 }
93666@@ -602,7 +602,7 @@ out:
93667 return err;
93668 }
93669
93670-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93671+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93672 struct flowi6 *fl6, struct dst_entry **dstp,
93673 unsigned int flags)
93674 {
93675@@ -915,12 +915,15 @@ do_confirm:
93676 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93677 char __user *optval, int optlen)
93678 {
93679+ struct icmp6_filter filter;
93680+
93681 switch (optname) {
93682 case ICMPV6_FILTER:
93683 if (optlen > sizeof(struct icmp6_filter))
93684 optlen = sizeof(struct icmp6_filter);
93685- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93686+ if (copy_from_user(&filter, optval, optlen))
93687 return -EFAULT;
93688+ raw6_sk(sk)->filter = filter;
93689 return 0;
93690 default:
93691 return -ENOPROTOOPT;
93692@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93693 char __user *optval, int __user *optlen)
93694 {
93695 int len;
93696+ struct icmp6_filter filter;
93697
93698 switch (optname) {
93699 case ICMPV6_FILTER:
93700@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93701 len = sizeof(struct icmp6_filter);
93702 if (put_user(len, optlen))
93703 return -EFAULT;
93704- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93705+ filter = raw6_sk(sk)->filter;
93706+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93707 return -EFAULT;
93708 return 0;
93709 default:
93710diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93711index 1aeb473..bea761c 100644
93712--- a/net/ipv6/reassembly.c
93713+++ b/net/ipv6/reassembly.c
93714@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93715
93716 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93717 {
93718- struct ctl_table *table;
93719+ ctl_table_no_const *table = NULL;
93720 struct ctl_table_header *hdr;
93721
93722- table = ip6_frags_ns_ctl_table;
93723 if (!net_eq(net, &init_net)) {
93724- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93725+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93726 if (table == NULL)
93727 goto err_alloc;
93728
93729@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93730 /* Don't export sysctls to unprivileged users */
93731 if (net->user_ns != &init_user_ns)
93732 table[0].procname = NULL;
93733- }
93734+ hdr = register_net_sysctl(net, "net/ipv6", table);
93735+ } else
93736+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93737
93738- hdr = register_net_sysctl(net, "net/ipv6", table);
93739 if (hdr == NULL)
93740 goto err_reg;
93741
93742@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93743 return 0;
93744
93745 err_reg:
93746- if (!net_eq(net, &init_net))
93747- kfree(table);
93748+ kfree(table);
93749 err_alloc:
93750 return -ENOMEM;
93751 }
93752diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93753index 8d9a93ed..cd89616 100644
93754--- a/net/ipv6/route.c
93755+++ b/net/ipv6/route.c
93756@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93757
93758 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93759 {
93760- struct ctl_table *table;
93761+ ctl_table_no_const *table;
93762
93763 table = kmemdup(ipv6_route_table_template,
93764 sizeof(ipv6_route_table_template),
93765diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93766index 21b25dd..9a43e37 100644
93767--- a/net/ipv6/sit.c
93768+++ b/net/ipv6/sit.c
93769@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93770 static void ipip6_dev_free(struct net_device *dev);
93771 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93772 __be32 *v4dst);
93773-static struct rtnl_link_ops sit_link_ops __read_mostly;
93774+static struct rtnl_link_ops sit_link_ops;
93775
93776 static int sit_net_id __read_mostly;
93777 struct sit_net {
93778@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93779 #endif
93780 };
93781
93782-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93783+static struct rtnl_link_ops sit_link_ops = {
93784 .kind = "sit",
93785 .maxtype = IFLA_IPTUN_MAX,
93786 .policy = ipip6_policy,
93787diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93788index 107b2f1..72741a9 100644
93789--- a/net/ipv6/sysctl_net_ipv6.c
93790+++ b/net/ipv6/sysctl_net_ipv6.c
93791@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93792
93793 static int __net_init ipv6_sysctl_net_init(struct net *net)
93794 {
93795- struct ctl_table *ipv6_table;
93796+ ctl_table_no_const *ipv6_table;
93797 struct ctl_table *ipv6_route_table;
93798 struct ctl_table *ipv6_icmp_table;
93799 int err;
93800diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93801index 6e1649d..75ddb4c 100644
93802--- a/net/ipv6/tcp_ipv6.c
93803+++ b/net/ipv6/tcp_ipv6.c
93804@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93805 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93806 }
93807
93808+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93809+extern int grsec_enable_blackhole;
93810+#endif
93811+
93812 static void tcp_v6_hash(struct sock *sk)
93813 {
93814 if (sk->sk_state != TCP_CLOSE) {
93815@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93816 return 0;
93817
93818 reset:
93819+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93820+ if (!grsec_enable_blackhole)
93821+#endif
93822 tcp_v6_send_reset(sk, skb);
93823 discard:
93824 if (opt_skb)
93825@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93826 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93827 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93828 if (np->rxopt.bits.rxtclass)
93829- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93830+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93831 if (ipv6_opt_accepted(sk, opt_skb)) {
93832 skb_set_owner_r(opt_skb, sk);
93833 opt_skb = xchg(&np->pktoptions, opt_skb);
93834@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93835 TCP_SKB_CB(skb)->sacked = 0;
93836
93837 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93838- if (!sk)
93839+ if (!sk) {
93840+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93841+ ret = 1;
93842+#endif
93843 goto no_tcp_socket;
93844+ }
93845
93846 process:
93847- if (sk->sk_state == TCP_TIME_WAIT)
93848+ if (sk->sk_state == TCP_TIME_WAIT) {
93849+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93850+ ret = 2;
93851+#endif
93852 goto do_time_wait;
93853+ }
93854
93855 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93856 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93857@@ -1538,6 +1553,10 @@ csum_error:
93858 bad_packet:
93859 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93860 } else {
93861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93862+ if (!grsec_enable_blackhole || (ret == 1 &&
93863+ (skb->dev->flags & IFF_LOOPBACK)))
93864+#endif
93865 tcp_v6_send_reset(NULL, skb);
93866 }
93867
93868diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93869index f405815..45a68a6 100644
93870--- a/net/ipv6/udp.c
93871+++ b/net/ipv6/udp.c
93872@@ -53,6 +53,10 @@
93873 #include <trace/events/skb.h>
93874 #include "udp_impl.h"
93875
93876+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93877+extern int grsec_enable_blackhole;
93878+#endif
93879+
93880 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93881 {
93882 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93883@@ -420,7 +424,7 @@ try_again:
93884 if (unlikely(err)) {
93885 trace_kfree_skb(skb, udpv6_recvmsg);
93886 if (!peeked) {
93887- atomic_inc(&sk->sk_drops);
93888+ atomic_inc_unchecked(&sk->sk_drops);
93889 if (is_udp4)
93890 UDP_INC_STATS_USER(sock_net(sk),
93891 UDP_MIB_INERRORS,
93892@@ -666,7 +670,7 @@ csum_error:
93893 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93894 drop:
93895 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93896- atomic_inc(&sk->sk_drops);
93897+ atomic_inc_unchecked(&sk->sk_drops);
93898 kfree_skb(skb);
93899 return -1;
93900 }
93901@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93902 if (likely(skb1 == NULL))
93903 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93904 if (!skb1) {
93905- atomic_inc(&sk->sk_drops);
93906+ atomic_inc_unchecked(&sk->sk_drops);
93907 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93908 IS_UDPLITE(sk));
93909 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93910@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93911 goto csum_error;
93912
93913 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93914+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93915+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93916+#endif
93917 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93918
93919 kfree_skb(skb);
93920diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93921index 23ed03d..6532e67 100644
93922--- a/net/ipv6/xfrm6_policy.c
93923+++ b/net/ipv6/xfrm6_policy.c
93924@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93925 }
93926 }
93927
93928-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93929+static int xfrm6_garbage_collect(struct dst_ops *ops)
93930 {
93931 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93932
93933- xfrm6_policy_afinfo.garbage_collect(net);
93934+ xfrm_garbage_collect_deferred(net);
93935 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93936 }
93937
93938@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93939
93940 static int __net_init xfrm6_net_init(struct net *net)
93941 {
93942- struct ctl_table *table;
93943+ ctl_table_no_const *table = NULL;
93944 struct ctl_table_header *hdr;
93945
93946- table = xfrm6_policy_table;
93947 if (!net_eq(net, &init_net)) {
93948- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93949+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93950 if (!table)
93951 goto err_alloc;
93952
93953 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93954- }
93955+ hdr = register_net_sysctl(net, "net/ipv6", table);
93956+ } else
93957+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93958
93959- hdr = register_net_sysctl(net, "net/ipv6", table);
93960 if (!hdr)
93961 goto err_reg;
93962
93963@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93964 return 0;
93965
93966 err_reg:
93967- if (!net_eq(net, &init_net))
93968- kfree(table);
93969+ kfree(table);
93970 err_alloc:
93971 return -ENOMEM;
93972 }
93973diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93974index 41ac7938..75e3bb1 100644
93975--- a/net/irda/ircomm/ircomm_tty.c
93976+++ b/net/irda/ircomm/ircomm_tty.c
93977@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93978 add_wait_queue(&port->open_wait, &wait);
93979
93980 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93981- __FILE__, __LINE__, tty->driver->name, port->count);
93982+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93983
93984 spin_lock_irqsave(&port->lock, flags);
93985 if (!tty_hung_up_p(filp))
93986- port->count--;
93987+ atomic_dec(&port->count);
93988 port->blocked_open++;
93989 spin_unlock_irqrestore(&port->lock, flags);
93990
93991@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93992 }
93993
93994 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93995- __FILE__, __LINE__, tty->driver->name, port->count);
93996+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93997
93998 schedule();
93999 }
94000@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
94001
94002 spin_lock_irqsave(&port->lock, flags);
94003 if (!tty_hung_up_p(filp))
94004- port->count++;
94005+ atomic_inc(&port->count);
94006 port->blocked_open--;
94007 spin_unlock_irqrestore(&port->lock, flags);
94008
94009 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
94010- __FILE__, __LINE__, tty->driver->name, port->count);
94011+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
94012
94013 if (!retval)
94014 port->flags |= ASYNC_NORMAL_ACTIVE;
94015@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
94016
94017 /* ++ is not atomic, so this should be protected - Jean II */
94018 spin_lock_irqsave(&self->port.lock, flags);
94019- self->port.count++;
94020+ atomic_inc(&self->port.count);
94021 spin_unlock_irqrestore(&self->port.lock, flags);
94022 tty_port_tty_set(&self->port, tty);
94023
94024 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
94025- self->line, self->port.count);
94026+ self->line, atomic_read(&self->port.count));
94027
94028 /* Not really used by us, but lets do it anyway */
94029 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
94030@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
94031 tty_kref_put(port->tty);
94032 }
94033 port->tty = NULL;
94034- port->count = 0;
94035+ atomic_set(&port->count, 0);
94036 spin_unlock_irqrestore(&port->lock, flags);
94037
94038 wake_up_interruptible(&port->open_wait);
94039@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
94040 seq_putc(m, '\n');
94041
94042 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
94043- seq_printf(m, "Open count: %d\n", self->port.count);
94044+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
94045 seq_printf(m, "Max data size: %d\n", self->max_data_size);
94046 seq_printf(m, "Max header size: %d\n", self->max_header_size);
94047
94048diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
94049index 168aff5..9d43132 100644
94050--- a/net/iucv/af_iucv.c
94051+++ b/net/iucv/af_iucv.c
94052@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
94053
94054 write_lock_bh(&iucv_sk_list.lock);
94055
94056- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
94057+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94058 while (__iucv_get_sock_by_name(name)) {
94059 sprintf(name, "%08x",
94060- atomic_inc_return(&iucv_sk_list.autobind_name));
94061+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94062 }
94063
94064 write_unlock_bh(&iucv_sk_list.lock);
94065diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
94066index cd5b8ec..f205e6b 100644
94067--- a/net/iucv/iucv.c
94068+++ b/net/iucv/iucv.c
94069@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
94070 return NOTIFY_OK;
94071 }
94072
94073-static struct notifier_block __refdata iucv_cpu_notifier = {
94074+static struct notifier_block iucv_cpu_notifier = {
94075 .notifier_call = iucv_cpu_notify,
94076 };
94077
94078diff --git a/net/key/af_key.c b/net/key/af_key.c
94079index ab8bd2c..cd2d641 100644
94080--- a/net/key/af_key.c
94081+++ b/net/key/af_key.c
94082@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
94083 static u32 get_acqseq(void)
94084 {
94085 u32 res;
94086- static atomic_t acqseq;
94087+ static atomic_unchecked_t acqseq;
94088
94089 do {
94090- res = atomic_inc_return(&acqseq);
94091+ res = atomic_inc_return_unchecked(&acqseq);
94092 } while (!res);
94093 return res;
94094 }
94095diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94096index 43dd752..63a23bc 100644
94097--- a/net/mac80211/cfg.c
94098+++ b/net/mac80211/cfg.c
94099@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94100 ret = ieee80211_vif_use_channel(sdata, chandef,
94101 IEEE80211_CHANCTX_EXCLUSIVE);
94102 }
94103- } else if (local->open_count == local->monitors) {
94104+ } else if (local_read(&local->open_count) == local->monitors) {
94105 local->_oper_chandef = *chandef;
94106 ieee80211_hw_config(local, 0);
94107 }
94108@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94109 else
94110 local->probe_req_reg--;
94111
94112- if (!local->open_count)
94113+ if (!local_read(&local->open_count))
94114 break;
94115
94116 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94117@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94118 if (chanctx_conf) {
94119 *chandef = chanctx_conf->def;
94120 ret = 0;
94121- } else if (local->open_count > 0 &&
94122- local->open_count == local->monitors &&
94123+ } else if (local_read(&local->open_count) > 0 &&
94124+ local_read(&local->open_count) == local->monitors &&
94125 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94126 if (local->use_chanctx)
94127 *chandef = local->monitor_chandef;
94128diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94129index 8412a30..6e00181 100644
94130--- a/net/mac80211/ieee80211_i.h
94131+++ b/net/mac80211/ieee80211_i.h
94132@@ -28,6 +28,7 @@
94133 #include <net/ieee80211_radiotap.h>
94134 #include <net/cfg80211.h>
94135 #include <net/mac80211.h>
94136+#include <asm/local.h>
94137 #include "key.h"
94138 #include "sta_info.h"
94139 #include "debug.h"
94140@@ -907,7 +908,7 @@ struct ieee80211_local {
94141 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94142 spinlock_t queue_stop_reason_lock;
94143
94144- int open_count;
94145+ local_t open_count;
94146 int monitors, cooked_mntrs;
94147 /* number of interfaces with corresponding FIF_ flags */
94148 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94149diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94150index cc11759..11d5541 100644
94151--- a/net/mac80211/iface.c
94152+++ b/net/mac80211/iface.c
94153@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94154 break;
94155 }
94156
94157- if (local->open_count == 0) {
94158+ if (local_read(&local->open_count) == 0) {
94159 res = drv_start(local);
94160 if (res)
94161 goto err_del_bss;
94162@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94163 res = drv_add_interface(local, sdata);
94164 if (res)
94165 goto err_stop;
94166- } else if (local->monitors == 0 && local->open_count == 0) {
94167+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94168 res = ieee80211_add_virtual_monitor(local);
94169 if (res)
94170 goto err_stop;
94171@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94172 atomic_inc(&local->iff_promiscs);
94173
94174 if (coming_up)
94175- local->open_count++;
94176+ local_inc(&local->open_count);
94177
94178 if (hw_reconf_flags)
94179 ieee80211_hw_config(local, hw_reconf_flags);
94180@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94181 err_del_interface:
94182 drv_remove_interface(local, sdata);
94183 err_stop:
94184- if (!local->open_count)
94185+ if (!local_read(&local->open_count))
94186 drv_stop(local);
94187 err_del_bss:
94188 sdata->bss = NULL;
94189@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94190 }
94191
94192 if (going_down)
94193- local->open_count--;
94194+ local_dec(&local->open_count);
94195
94196 switch (sdata->vif.type) {
94197 case NL80211_IFTYPE_AP_VLAN:
94198@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94199 }
94200 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94201
94202- if (local->open_count == 0)
94203+ if (local_read(&local->open_count) == 0)
94204 ieee80211_clear_tx_pending(local);
94205
94206 /*
94207@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94208
94209 ieee80211_recalc_ps(local, -1);
94210
94211- if (local->open_count == 0) {
94212+ if (local_read(&local->open_count) == 0) {
94213 ieee80211_stop_device(local);
94214
94215 /* no reconfiguring after stop! */
94216@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94217 ieee80211_configure_filter(local);
94218 ieee80211_hw_config(local, hw_reconf_flags);
94219
94220- if (local->monitors == local->open_count)
94221+ if (local->monitors == local_read(&local->open_count))
94222 ieee80211_add_virtual_monitor(local);
94223 }
94224
94225diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94226index 091088a..daf43c7 100644
94227--- a/net/mac80211/main.c
94228+++ b/net/mac80211/main.c
94229@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94230 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94231 IEEE80211_CONF_CHANGE_POWER);
94232
94233- if (changed && local->open_count) {
94234+ if (changed && local_read(&local->open_count)) {
94235 ret = drv_config(local, changed);
94236 /*
94237 * Goal:
94238diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94239index 3401262..d5cd68d 100644
94240--- a/net/mac80211/pm.c
94241+++ b/net/mac80211/pm.c
94242@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94243 struct ieee80211_sub_if_data *sdata;
94244 struct sta_info *sta;
94245
94246- if (!local->open_count)
94247+ if (!local_read(&local->open_count))
94248 goto suspend;
94249
94250 ieee80211_scan_cancel(local);
94251@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94252 cancel_work_sync(&local->dynamic_ps_enable_work);
94253 del_timer_sync(&local->dynamic_ps_timer);
94254
94255- local->wowlan = wowlan && local->open_count;
94256+ local->wowlan = wowlan && local_read(&local->open_count);
94257 if (local->wowlan) {
94258 int err = drv_suspend(local, wowlan);
94259 if (err < 0) {
94260@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94261 WARN_ON(!list_empty(&local->chanctx_list));
94262
94263 /* stop hardware - this must stop RX */
94264- if (local->open_count)
94265+ if (local_read(&local->open_count))
94266 ieee80211_stop_device(local);
94267
94268 suspend:
94269diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94270index 30d58d2..449ac8e 100644
94271--- a/net/mac80211/rate.c
94272+++ b/net/mac80211/rate.c
94273@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94274
94275 ASSERT_RTNL();
94276
94277- if (local->open_count)
94278+ if (local_read(&local->open_count))
94279 return -EBUSY;
94280
94281 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94282diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94283index c97a065..ff61928 100644
94284--- a/net/mac80211/rc80211_pid_debugfs.c
94285+++ b/net/mac80211/rc80211_pid_debugfs.c
94286@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94287
94288 spin_unlock_irqrestore(&events->lock, status);
94289
94290- if (copy_to_user(buf, pb, p))
94291+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94292 return -EFAULT;
94293
94294 return p;
94295diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94296index 2265445..ba14971 100644
94297--- a/net/mac80211/util.c
94298+++ b/net/mac80211/util.c
94299@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94300 }
94301 #endif
94302 /* everything else happens only if HW was up & running */
94303- if (!local->open_count)
94304+ if (!local_read(&local->open_count))
94305 goto wake_up;
94306
94307 /*
94308@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94309 local->in_reconfig = false;
94310 barrier();
94311
94312- if (local->monitors == local->open_count && local->monitors > 0)
94313+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94314 ieee80211_add_virtual_monitor(local);
94315
94316 /*
94317diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94318index 56d22ca..87c778f 100644
94319--- a/net/netfilter/Kconfig
94320+++ b/net/netfilter/Kconfig
94321@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94322
94323 To compile it as a module, choose M here. If unsure, say N.
94324
94325+config NETFILTER_XT_MATCH_GRADM
94326+ tristate '"gradm" match support'
94327+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94328+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94329+ ---help---
94330+ The gradm match allows to match on grsecurity RBAC being enabled.
94331+ It is useful when iptables rules are applied early on bootup to
94332+ prevent connections to the machine (except from a trusted host)
94333+ while the RBAC system is disabled.
94334+
94335 config NETFILTER_XT_MATCH_HASHLIMIT
94336 tristate '"hashlimit" match support'
94337 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94338diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94339index a1abf87..dbcb7ee 100644
94340--- a/net/netfilter/Makefile
94341+++ b/net/netfilter/Makefile
94342@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94343 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94344 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94345 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94346+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94347 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94348 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94349 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94350diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94351index f771390..145b765 100644
94352--- a/net/netfilter/ipset/ip_set_core.c
94353+++ b/net/netfilter/ipset/ip_set_core.c
94354@@ -1820,7 +1820,7 @@ done:
94355 return ret;
94356 }
94357
94358-static struct nf_sockopt_ops so_set __read_mostly = {
94359+static struct nf_sockopt_ops so_set = {
94360 .pf = PF_INET,
94361 .get_optmin = SO_IP_SET,
94362 .get_optmax = SO_IP_SET + 1,
94363diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94364index 4c8e5c0..5a79b4d 100644
94365--- a/net/netfilter/ipvs/ip_vs_conn.c
94366+++ b/net/netfilter/ipvs/ip_vs_conn.c
94367@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94368 /* Increase the refcnt counter of the dest */
94369 ip_vs_dest_hold(dest);
94370
94371- conn_flags = atomic_read(&dest->conn_flags);
94372+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94373 if (cp->protocol != IPPROTO_UDP)
94374 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94375 flags = cp->flags;
94376@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94377
94378 cp->control = NULL;
94379 atomic_set(&cp->n_control, 0);
94380- atomic_set(&cp->in_pkts, 0);
94381+ atomic_set_unchecked(&cp->in_pkts, 0);
94382
94383 cp->packet_xmit = NULL;
94384 cp->app = NULL;
94385@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94386
94387 /* Don't drop the entry if its number of incoming packets is not
94388 located in [0, 8] */
94389- i = atomic_read(&cp->in_pkts);
94390+ i = atomic_read_unchecked(&cp->in_pkts);
94391 if (i > 8 || i < 0) return 0;
94392
94393 if (!todrop_rate[i]) return 0;
94394diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94395index 4f69e83..da2d8bf 100644
94396--- a/net/netfilter/ipvs/ip_vs_core.c
94397+++ b/net/netfilter/ipvs/ip_vs_core.c
94398@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94399 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94400 /* do not touch skb anymore */
94401
94402- atomic_inc(&cp->in_pkts);
94403+ atomic_inc_unchecked(&cp->in_pkts);
94404 ip_vs_conn_put(cp);
94405 return ret;
94406 }
94407@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94408 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94409 pkts = sysctl_sync_threshold(ipvs);
94410 else
94411- pkts = atomic_add_return(1, &cp->in_pkts);
94412+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94413
94414 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94415 ip_vs_sync_conn(net, cp, pkts);
94416diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94417index c8148e4..eff604f 100644
94418--- a/net/netfilter/ipvs/ip_vs_ctl.c
94419+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94420@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94421 */
94422 ip_vs_rs_hash(ipvs, dest);
94423 }
94424- atomic_set(&dest->conn_flags, conn_flags);
94425+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94426
94427 /* bind the service */
94428 if (!dest->svc) {
94429@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94430 * align with netns init in ip_vs_control_net_init()
94431 */
94432
94433-static struct ctl_table vs_vars[] = {
94434+static ctl_table_no_const vs_vars[] __read_only = {
94435 {
94436 .procname = "amemthresh",
94437 .maxlen = sizeof(int),
94438@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94439 " %-7s %-6d %-10d %-10d\n",
94440 &dest->addr.in6,
94441 ntohs(dest->port),
94442- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94443+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94444 atomic_read(&dest->weight),
94445 atomic_read(&dest->activeconns),
94446 atomic_read(&dest->inactconns));
94447@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94448 "%-7s %-6d %-10d %-10d\n",
94449 ntohl(dest->addr.ip),
94450 ntohs(dest->port),
94451- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94452+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94453 atomic_read(&dest->weight),
94454 atomic_read(&dest->activeconns),
94455 atomic_read(&dest->inactconns));
94456@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94457
94458 entry.addr = dest->addr.ip;
94459 entry.port = dest->port;
94460- entry.conn_flags = atomic_read(&dest->conn_flags);
94461+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94462 entry.weight = atomic_read(&dest->weight);
94463 entry.u_threshold = dest->u_threshold;
94464 entry.l_threshold = dest->l_threshold;
94465@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94466 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94467 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94468 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94469- (atomic_read(&dest->conn_flags) &
94470+ (atomic_read_unchecked(&dest->conn_flags) &
94471 IP_VS_CONN_F_FWD_MASK)) ||
94472 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94473 atomic_read(&dest->weight)) ||
94474@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94475 {
94476 int idx;
94477 struct netns_ipvs *ipvs = net_ipvs(net);
94478- struct ctl_table *tbl;
94479+ ctl_table_no_const *tbl;
94480
94481 atomic_set(&ipvs->dropentry, 0);
94482 spin_lock_init(&ipvs->dropentry_lock);
94483diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94484index 1383b0e..a486da1 100644
94485--- a/net/netfilter/ipvs/ip_vs_lblc.c
94486+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94487@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94488 * IPVS LBLC sysctl table
94489 */
94490 #ifdef CONFIG_SYSCTL
94491-static struct ctl_table vs_vars_table[] = {
94492+static ctl_table_no_const vs_vars_table[] __read_only = {
94493 {
94494 .procname = "lblc_expiration",
94495 .data = NULL,
94496diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94497index 3cd85b2..dfab2b8 100644
94498--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94499+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94500@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94501 * IPVS LBLCR sysctl table
94502 */
94503
94504-static struct ctl_table vs_vars_table[] = {
94505+static ctl_table_no_const vs_vars_table[] __read_only = {
94506 {
94507 .procname = "lblcr_expiration",
94508 .data = NULL,
94509diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94510index f448471..995f131 100644
94511--- a/net/netfilter/ipvs/ip_vs_sync.c
94512+++ b/net/netfilter/ipvs/ip_vs_sync.c
94513@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94514 cp = cp->control;
94515 if (cp) {
94516 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94517- pkts = atomic_add_return(1, &cp->in_pkts);
94518+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94519 else
94520 pkts = sysctl_sync_threshold(ipvs);
94521 ip_vs_sync_conn(net, cp->control, pkts);
94522@@ -771,7 +771,7 @@ control:
94523 if (!cp)
94524 return;
94525 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94526- pkts = atomic_add_return(1, &cp->in_pkts);
94527+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94528 else
94529 pkts = sysctl_sync_threshold(ipvs);
94530 goto sloop;
94531@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94532
94533 if (opt)
94534 memcpy(&cp->in_seq, opt, sizeof(*opt));
94535- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94536+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94537 cp->state = state;
94538 cp->old_state = cp->state;
94539 /*
94540diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94541index b75ff64..0c51bbe 100644
94542--- a/net/netfilter/ipvs/ip_vs_xmit.c
94543+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94544@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94545 else
94546 rc = NF_ACCEPT;
94547 /* do not touch skb anymore */
94548- atomic_inc(&cp->in_pkts);
94549+ atomic_inc_unchecked(&cp->in_pkts);
94550 goto out;
94551 }
94552
94553@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94554 else
94555 rc = NF_ACCEPT;
94556 /* do not touch skb anymore */
94557- atomic_inc(&cp->in_pkts);
94558+ atomic_inc_unchecked(&cp->in_pkts);
94559 goto out;
94560 }
94561
94562diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94563index 2d3030a..7ba1c0a 100644
94564--- a/net/netfilter/nf_conntrack_acct.c
94565+++ b/net/netfilter/nf_conntrack_acct.c
94566@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94567 #ifdef CONFIG_SYSCTL
94568 static int nf_conntrack_acct_init_sysctl(struct net *net)
94569 {
94570- struct ctl_table *table;
94571+ ctl_table_no_const *table;
94572
94573 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94574 GFP_KERNEL);
94575diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94576index 0283bae..5febcb0 100644
94577--- a/net/netfilter/nf_conntrack_core.c
94578+++ b/net/netfilter/nf_conntrack_core.c
94579@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94580 #define DYING_NULLS_VAL ((1<<30)+1)
94581 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94582
94583+#ifdef CONFIG_GRKERNSEC_HIDESYM
94584+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94585+#endif
94586+
94587 int nf_conntrack_init_net(struct net *net)
94588 {
94589 int ret;
94590@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94591 goto err_stat;
94592 }
94593
94594+#ifdef CONFIG_GRKERNSEC_HIDESYM
94595+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94596+#else
94597 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94598+#endif
94599 if (!net->ct.slabname) {
94600 ret = -ENOMEM;
94601 goto err_slabname;
94602diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94603index 1df1761..ce8b88a 100644
94604--- a/net/netfilter/nf_conntrack_ecache.c
94605+++ b/net/netfilter/nf_conntrack_ecache.c
94606@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94607 #ifdef CONFIG_SYSCTL
94608 static int nf_conntrack_event_init_sysctl(struct net *net)
94609 {
94610- struct ctl_table *table;
94611+ ctl_table_no_const *table;
94612
94613 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94614 GFP_KERNEL);
94615diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94616index 974a2a4..52cc6ff 100644
94617--- a/net/netfilter/nf_conntrack_helper.c
94618+++ b/net/netfilter/nf_conntrack_helper.c
94619@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94620
94621 static int nf_conntrack_helper_init_sysctl(struct net *net)
94622 {
94623- struct ctl_table *table;
94624+ ctl_table_no_const *table;
94625
94626 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94627 GFP_KERNEL);
94628diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94629index 0ab9636..cea3c6a 100644
94630--- a/net/netfilter/nf_conntrack_proto.c
94631+++ b/net/netfilter/nf_conntrack_proto.c
94632@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94633
94634 static void
94635 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94636- struct ctl_table **table,
94637+ ctl_table_no_const **table,
94638 unsigned int users)
94639 {
94640 if (users > 0)
94641diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94642index a99b6c3..cb372f9 100644
94643--- a/net/netfilter/nf_conntrack_proto_dccp.c
94644+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94645@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94646 const char *msg;
94647 u_int8_t state;
94648
94649- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94650+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94651 BUG_ON(dh == NULL);
94652
94653 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94654@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94655 out_invalid:
94656 if (LOG_INVALID(net, IPPROTO_DCCP))
94657 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94658- NULL, msg);
94659+ NULL, "%s", msg);
94660 return false;
94661 }
94662
94663@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94664 u_int8_t type, old_state, new_state;
94665 enum ct_dccp_roles role;
94666
94667- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94668+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94669 BUG_ON(dh == NULL);
94670 type = dh->dccph_type;
94671
94672@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94673 unsigned int cscov;
94674 const char *msg;
94675
94676- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94677+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94678 if (dh == NULL) {
94679 msg = "nf_ct_dccp: short packet ";
94680 goto out_invalid;
94681@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94682
94683 out_invalid:
94684 if (LOG_INVALID(net, IPPROTO_DCCP))
94685- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94686+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94687 return -NF_ACCEPT;
94688 }
94689
94690diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94691index f641751..d3c5b51 100644
94692--- a/net/netfilter/nf_conntrack_standalone.c
94693+++ b/net/netfilter/nf_conntrack_standalone.c
94694@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94695
94696 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94697 {
94698- struct ctl_table *table;
94699+ ctl_table_no_const *table;
94700
94701 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94702 GFP_KERNEL);
94703diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94704index 902fb0a..87f7fdb 100644
94705--- a/net/netfilter/nf_conntrack_timestamp.c
94706+++ b/net/netfilter/nf_conntrack_timestamp.c
94707@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94708 #ifdef CONFIG_SYSCTL
94709 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94710 {
94711- struct ctl_table *table;
94712+ ctl_table_no_const *table;
94713
94714 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94715 GFP_KERNEL);
94716diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94717index 85296d4..8becdec 100644
94718--- a/net/netfilter/nf_log.c
94719+++ b/net/netfilter/nf_log.c
94720@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94721
94722 #ifdef CONFIG_SYSCTL
94723 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94724-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94725+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94726
94727 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94728 void __user *buffer, size_t *lenp, loff_t *ppos)
94729@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94730 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94731 mutex_unlock(&nf_log_mutex);
94732 } else {
94733+ ctl_table_no_const nf_log_table = *table;
94734+
94735 mutex_lock(&nf_log_mutex);
94736 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94737 lockdep_is_held(&nf_log_mutex));
94738 if (!logger)
94739- table->data = "NONE";
94740+ nf_log_table.data = "NONE";
94741 else
94742- table->data = logger->name;
94743- r = proc_dostring(table, write, buffer, lenp, ppos);
94744+ nf_log_table.data = logger->name;
94745+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94746 mutex_unlock(&nf_log_mutex);
94747 }
94748
94749diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94750index f042ae5..30ea486 100644
94751--- a/net/netfilter/nf_sockopt.c
94752+++ b/net/netfilter/nf_sockopt.c
94753@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94754 }
94755 }
94756
94757- list_add(&reg->list, &nf_sockopts);
94758+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94759 out:
94760 mutex_unlock(&nf_sockopt_mutex);
94761 return ret;
94762@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94763 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94764 {
94765 mutex_lock(&nf_sockopt_mutex);
94766- list_del(&reg->list);
94767+ pax_list_del((struct list_head *)&reg->list);
94768 mutex_unlock(&nf_sockopt_mutex);
94769 }
94770 EXPORT_SYMBOL(nf_unregister_sockopt);
94771diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94772index d92cc31..e46f350 100644
94773--- a/net/netfilter/nfnetlink_log.c
94774+++ b/net/netfilter/nfnetlink_log.c
94775@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94776 struct nfnl_log_net {
94777 spinlock_t instances_lock;
94778 struct hlist_head instance_table[INSTANCE_BUCKETS];
94779- atomic_t global_seq;
94780+ atomic_unchecked_t global_seq;
94781 };
94782
94783 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94784@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94785 /* global sequence number */
94786 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94787 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94788- htonl(atomic_inc_return(&log->global_seq))))
94789+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94790 goto nla_put_failure;
94791
94792 if (data_len) {
94793diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94794new file mode 100644
94795index 0000000..c566332
94796--- /dev/null
94797+++ b/net/netfilter/xt_gradm.c
94798@@ -0,0 +1,51 @@
94799+/*
94800+ * gradm match for netfilter
94801