]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.7-201308182203.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.7-201308182203.patch
CommitLineData
79d77d1a
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 2fe6e76..889ee23 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@@ -1928,6 +1932,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@@ -2195,6 +2203,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 33e36ab..31f1dc8 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) KERNELRELASE 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@@ -1223,6 +1289,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@@ -1359,17 +1427,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@@ -1379,11 +1451,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 c2cbe4f..f7264b4 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
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 81a4342..348b927 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 b9e37ad..44c24e7 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1297,10 +1297,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@@ -1308,6 +1309,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@@ -1340,20 +1342,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 18a9f5e..ca910b7 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1766,7 +1766,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 cbdc7a2..32f44fe 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 18f5cef..25b8f43 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -41,6 +41,7 @@
1935 */
1936 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1937 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1938+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1939 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1940 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1941 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1942@@ -71,6 +72,7 @@
1943 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1944 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1945 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1946+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1947 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1948
1949 /*
1950diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1951index 86b8fe3..e25f975 100644
1952--- a/arch/arm/include/asm/pgtable-3level.h
1953+++ b/arch/arm/include/asm/pgtable-3level.h
1954@@ -74,6 +74,7 @@
1955 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1956 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1958+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1959 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1960 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1961 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1962@@ -82,6 +83,7 @@
1963 /*
1964 * To be used in assembly code with the upper page attributes.
1965 */
1966+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1967 #define L_PTE_XN_HIGH (1 << (54 - 32))
1968 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1969
1970diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1971index 9bcd262..fba731c 100644
1972--- a/arch/arm/include/asm/pgtable.h
1973+++ b/arch/arm/include/asm/pgtable.h
1974@@ -30,6 +30,9 @@
1975 #include <asm/pgtable-2level.h>
1976 #endif
1977
1978+#define ktla_ktva(addr) (addr)
1979+#define ktva_ktla(addr) (addr)
1980+
1981 /*
1982 * Just any arbitrary offset to the start of the vmalloc VM area: the
1983 * current 8MB value just means that there will be a 8MB "hole" after the
1984@@ -45,6 +48,9 @@
1985 #define LIBRARY_TEXT_START 0x0c000000
1986
1987 #ifndef __ASSEMBLY__
1988+extern pteval_t __supported_pte_mask;
1989+extern pmdval_t __supported_pmd_mask;
1990+
1991 extern void __pte_error(const char *file, int line, pte_t);
1992 extern void __pmd_error(const char *file, int line, pmd_t);
1993 extern void __pgd_error(const char *file, int line, pgd_t);
1994@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1995 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1996 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1997
1998+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1999+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2000+
2001+#ifdef CONFIG_PAX_KERNEXEC
2002+#include <asm/domain.h>
2003+#include <linux/thread_info.h>
2004+#include <linux/preempt.h>
2005+#endif
2006+
2007+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2008+static inline int test_domain(int domain, int domaintype)
2009+{
2010+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2011+}
2012+#endif
2013+
2014+#ifdef CONFIG_PAX_KERNEXEC
2015+static inline unsigned long pax_open_kernel(void) {
2016+#ifdef CONFIG_ARM_LPAE
2017+ /* TODO */
2018+#else
2019+ preempt_disable();
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2021+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2022+#endif
2023+ return 0;
2024+}
2025+
2026+static inline unsigned long pax_close_kernel(void) {
2027+#ifdef CONFIG_ARM_LPAE
2028+ /* TODO */
2029+#else
2030+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2031+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2032+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2033+ preempt_enable_no_resched();
2034+#endif
2035+ return 0;
2036+}
2037+#else
2038+static inline unsigned long pax_open_kernel(void) { return 0; }
2039+static inline unsigned long pax_close_kernel(void) { return 0; }
2040+#endif
2041+
2042 /*
2043 * This is the lowest virtual address we can permit any user space
2044 * mapping to be mapped at. This is particularly important for
2045@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2046 /*
2047 * The pgprot_* and protection_map entries will be fixed up in runtime
2048 * to include the cachable and bufferable bits based on memory policy,
2049- * as well as any architecture dependent bits like global/ASID and SMP
2050- * shared mapping bits.
2051+ * as well as any architecture dependent bits like global/ASID, PXN,
2052+ * and SMP shared mapping bits.
2053 */
2054 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2055
2056@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2057 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2058 {
2059 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2060- L_PTE_NONE | L_PTE_VALID;
2061+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2062 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2063 return pte;
2064 }
2065diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2066index f3628fb..a0672dd 100644
2067--- a/arch/arm/include/asm/proc-fns.h
2068+++ b/arch/arm/include/asm/proc-fns.h
2069@@ -75,7 +75,7 @@ extern struct processor {
2070 unsigned int suspend_size;
2071 void (*do_suspend)(void *);
2072 void (*do_resume)(void *);
2073-} processor;
2074+} __do_const processor;
2075
2076 #ifndef MULTI_CPU
2077 extern void cpu_proc_init(void);
2078diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2079index ce0dbe7..c085b6f 100644
2080--- a/arch/arm/include/asm/psci.h
2081+++ b/arch/arm/include/asm/psci.h
2082@@ -29,7 +29,7 @@ struct psci_operations {
2083 int (*cpu_off)(struct psci_power_state state);
2084 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2085 int (*migrate)(unsigned long cpuid);
2086-};
2087+} __no_const;
2088
2089 extern struct psci_operations psci_ops;
2090
2091diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2092index d3a22be..3a69ad5 100644
2093--- a/arch/arm/include/asm/smp.h
2094+++ b/arch/arm/include/asm/smp.h
2095@@ -107,7 +107,7 @@ struct smp_operations {
2096 int (*cpu_disable)(unsigned int cpu);
2097 #endif
2098 #endif
2099-};
2100+} __no_const;
2101
2102 /*
2103 * set platform specific SMP operations
2104diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2105index f00b569..aa5bb41 100644
2106--- a/arch/arm/include/asm/thread_info.h
2107+++ b/arch/arm/include/asm/thread_info.h
2108@@ -77,9 +77,9 @@ struct thread_info {
2109 .flags = 0, \
2110 .preempt_count = INIT_PREEMPT_COUNT, \
2111 .addr_limit = KERNEL_DS, \
2112- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2113- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2114- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2115+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2116+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2117+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2118 .restart_block = { \
2119 .fn = do_no_restart_syscall, \
2120 }, \
2121@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2122 #define TIF_SYSCALL_AUDIT 9
2123 #define TIF_SYSCALL_TRACEPOINT 10
2124 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2125-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2126+/* within 8 bits of TIF_SYSCALL_TRACE
2127+ * to meet flexible second operand requirements
2128+ */
2129+#define TIF_GRSEC_SETXID 12
2130+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2131 #define TIF_USING_IWMMXT 17
2132 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2133 #define TIF_RESTORE_SIGMASK 20
2134@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2135 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2136 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2137 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2138+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2139
2140 /* Checks for any syscall work in entry-common.S */
2141 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2142- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2143+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2144
2145 /*
2146 * Change these and you break ASM code in entry-common.S
2147diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h
2148index bdf2b84..aa9b4ac 100644
2149--- a/arch/arm/include/asm/tlb.h
2150+++ b/arch/arm/include/asm/tlb.h
2151@@ -43,6 +43,7 @@ struct mmu_gather {
2152 struct mm_struct *mm;
2153 unsigned int fullmm;
2154 struct vm_area_struct *vma;
2155+ unsigned long start, end;
2156 unsigned long range_start;
2157 unsigned long range_end;
2158 unsigned int nr;
2159@@ -107,10 +108,12 @@ static inline void tlb_flush_mmu(struct mmu_gather *tlb)
2160 }
2161
2162 static inline void
2163-tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int fullmm)
2164+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
2165 {
2166 tlb->mm = mm;
2167- tlb->fullmm = fullmm;
2168+ tlb->fullmm = !(start | (end+1));
2169+ tlb->start = start;
2170+ tlb->end = end;
2171 tlb->vma = NULL;
2172 tlb->max = ARRAY_SIZE(tlb->local);
2173 tlb->pages = tlb->local;
2174diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2175index 7e1f760..de33b13 100644
2176--- a/arch/arm/include/asm/uaccess.h
2177+++ b/arch/arm/include/asm/uaccess.h
2178@@ -18,6 +18,7 @@
2179 #include <asm/domain.h>
2180 #include <asm/unified.h>
2181 #include <asm/compiler.h>
2182+#include <asm/pgtable.h>
2183
2184 #define VERIFY_READ 0
2185 #define VERIFY_WRITE 1
2186@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2187 static inline void set_fs(mm_segment_t fs)
2188 {
2189 current_thread_info()->addr_limit = fs;
2190- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2191+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2192 }
2193
2194 #define segment_eq(a,b) ((a) == (b))
2195
2196+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2197+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2198+
2199+static inline void pax_open_userland(void)
2200+{
2201+
2202+#ifdef CONFIG_PAX_MEMORY_UDEREF
2203+ if (segment_eq(get_fs(), USER_DS)) {
2204+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2205+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2206+ }
2207+#endif
2208+
2209+}
2210+
2211+static inline void pax_close_userland(void)
2212+{
2213+
2214+#ifdef CONFIG_PAX_MEMORY_UDEREF
2215+ if (segment_eq(get_fs(), USER_DS)) {
2216+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2217+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2218+ }
2219+#endif
2220+
2221+}
2222+
2223 #define __addr_ok(addr) ({ \
2224 unsigned long flag; \
2225 __asm__("cmp %2, %0; movlo %0, #0" \
2226@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2227
2228 #define get_user(x,p) \
2229 ({ \
2230+ int __e; \
2231 might_fault(); \
2232- __get_user_check(x,p); \
2233+ pax_open_userland(); \
2234+ __e = __get_user_check(x,p); \
2235+ pax_close_userland(); \
2236+ __e; \
2237 })
2238
2239 extern int __put_user_1(void *, unsigned int);
2240@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2241
2242 #define put_user(x,p) \
2243 ({ \
2244+ int __e; \
2245 might_fault(); \
2246- __put_user_check(x,p); \
2247+ pax_open_userland(); \
2248+ __e = __put_user_check(x,p); \
2249+ pax_close_userland(); \
2250+ __e; \
2251 })
2252
2253 #else /* CONFIG_MMU */
2254@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2255 #define __get_user(x,ptr) \
2256 ({ \
2257 long __gu_err = 0; \
2258+ pax_open_userland(); \
2259 __get_user_err((x),(ptr),__gu_err); \
2260+ pax_close_userland(); \
2261 __gu_err; \
2262 })
2263
2264 #define __get_user_error(x,ptr,err) \
2265 ({ \
2266+ pax_open_userland(); \
2267 __get_user_err((x),(ptr),err); \
2268+ pax_close_userland(); \
2269 (void) 0; \
2270 })
2271
2272@@ -312,13 +352,17 @@ do { \
2273 #define __put_user(x,ptr) \
2274 ({ \
2275 long __pu_err = 0; \
2276+ pax_open_userland(); \
2277 __put_user_err((x),(ptr),__pu_err); \
2278+ pax_close_userland(); \
2279 __pu_err; \
2280 })
2281
2282 #define __put_user_error(x,ptr,err) \
2283 ({ \
2284+ pax_open_userland(); \
2285 __put_user_err((x),(ptr),err); \
2286+ pax_close_userland(); \
2287 (void) 0; \
2288 })
2289
2290@@ -418,11 +462,44 @@ do { \
2291
2292
2293 #ifdef CONFIG_MMU
2294-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2295-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2296+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2297+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2298+
2299+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2300+{
2301+ unsigned long ret;
2302+
2303+ check_object_size(to, n, false);
2304+ pax_open_userland();
2305+ ret = ___copy_from_user(to, from, n);
2306+ pax_close_userland();
2307+ return ret;
2308+}
2309+
2310+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2311+{
2312+ unsigned long ret;
2313+
2314+ check_object_size(from, n, true);
2315+ pax_open_userland();
2316+ ret = ___copy_to_user(to, from, n);
2317+ pax_close_userland();
2318+ return ret;
2319+}
2320+
2321 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2322-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2323+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2324 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2325+
2326+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2327+{
2328+ unsigned long ret;
2329+ pax_open_userland();
2330+ ret = ___clear_user(addr, n);
2331+ pax_close_userland();
2332+ return ret;
2333+}
2334+
2335 #else
2336 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2337 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2338@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2339
2340 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2341 {
2342+ if ((long)n < 0)
2343+ return n;
2344+
2345 if (access_ok(VERIFY_READ, from, n))
2346 n = __copy_from_user(to, from, n);
2347 else /* security hole - plug it */
2348@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2349
2350 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2351 {
2352+ if ((long)n < 0)
2353+ return n;
2354+
2355 if (access_ok(VERIFY_WRITE, to, n))
2356 n = __copy_to_user(to, from, n);
2357 return n;
2358diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2359index 96ee092..37f1844 100644
2360--- a/arch/arm/include/uapi/asm/ptrace.h
2361+++ b/arch/arm/include/uapi/asm/ptrace.h
2362@@ -73,7 +73,7 @@
2363 * ARMv7 groups of PSR bits
2364 */
2365 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2366-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2367+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2368 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2369 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2370
2371diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2372index 60d3b73..e5a0f22 100644
2373--- a/arch/arm/kernel/armksyms.c
2374+++ b/arch/arm/kernel/armksyms.c
2375@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2376
2377 /* networking */
2378 EXPORT_SYMBOL(csum_partial);
2379-EXPORT_SYMBOL(csum_partial_copy_from_user);
2380+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2381 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2382 EXPORT_SYMBOL(__csum_ipv6_magic);
2383
2384@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2385 #ifdef CONFIG_MMU
2386 EXPORT_SYMBOL(copy_page);
2387
2388-EXPORT_SYMBOL(__copy_from_user);
2389-EXPORT_SYMBOL(__copy_to_user);
2390-EXPORT_SYMBOL(__clear_user);
2391+EXPORT_SYMBOL(___copy_from_user);
2392+EXPORT_SYMBOL(___copy_to_user);
2393+EXPORT_SYMBOL(___clear_user);
2394
2395 EXPORT_SYMBOL(__get_user_1);
2396 EXPORT_SYMBOL(__get_user_2);
2397diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2398index d43c7e5..257c050 100644
2399--- a/arch/arm/kernel/entry-armv.S
2400+++ b/arch/arm/kernel/entry-armv.S
2401@@ -47,6 +47,87 @@
2402 9997:
2403 .endm
2404
2405+ .macro pax_enter_kernel
2406+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2407+ @ make aligned space for saved DACR
2408+ sub sp, sp, #8
2409+ @ save regs
2410+ stmdb sp!, {r1, r2}
2411+ @ read DACR from cpu_domain into r1
2412+ mov r2, sp
2413+ @ assume 8K pages, since we have to split the immediate in two
2414+ bic r2, r2, #(0x1fc0)
2415+ bic r2, r2, #(0x3f)
2416+ ldr r1, [r2, #TI_CPU_DOMAIN]
2417+ @ store old DACR on stack
2418+ str r1, [sp, #8]
2419+#ifdef CONFIG_PAX_KERNEXEC
2420+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2423+#endif
2424+#ifdef CONFIG_PAX_MEMORY_UDEREF
2425+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2426+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2427+#endif
2428+ @ write r1 to current_thread_info()->cpu_domain
2429+ str r1, [r2, #TI_CPU_DOMAIN]
2430+ @ write r1 to DACR
2431+ mcr p15, 0, r1, c3, c0, 0
2432+ @ instruction sync
2433+ instr_sync
2434+ @ restore regs
2435+ ldmia sp!, {r1, r2}
2436+#endif
2437+ .endm
2438+
2439+ .macro pax_open_userland
2440+#ifdef CONFIG_PAX_MEMORY_UDEREF
2441+ @ save regs
2442+ stmdb sp!, {r0, r1}
2443+ @ read DACR from cpu_domain into r1
2444+ mov r0, sp
2445+ @ assume 8K pages, since we have to split the immediate in two
2446+ bic r0, r0, #(0x1fc0)
2447+ bic r0, r0, #(0x3f)
2448+ ldr r1, [r0, #TI_CPU_DOMAIN]
2449+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2450+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2451+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2452+ @ write r1 to current_thread_info()->cpu_domain
2453+ str r1, [r0, #TI_CPU_DOMAIN]
2454+ @ write r1 to DACR
2455+ mcr p15, 0, r1, c3, c0, 0
2456+ @ instruction sync
2457+ instr_sync
2458+ @ restore regs
2459+ ldmia sp!, {r0, r1}
2460+#endif
2461+ .endm
2462+
2463+ .macro pax_close_userland
2464+#ifdef CONFIG_PAX_MEMORY_UDEREF
2465+ @ save regs
2466+ stmdb sp!, {r0, r1}
2467+ @ read DACR from cpu_domain into r1
2468+ mov r0, sp
2469+ @ assume 8K pages, since we have to split the immediate in two
2470+ bic r0, r0, #(0x1fc0)
2471+ bic r0, r0, #(0x3f)
2472+ ldr r1, [r0, #TI_CPU_DOMAIN]
2473+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2474+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2475+ @ write r1 to current_thread_info()->cpu_domain
2476+ str r1, [r0, #TI_CPU_DOMAIN]
2477+ @ write r1 to DACR
2478+ mcr p15, 0, r1, c3, c0, 0
2479+ @ instruction sync
2480+ instr_sync
2481+ @ restore regs
2482+ ldmia sp!, {r0, r1}
2483+#endif
2484+ .endm
2485+
2486 .macro pabt_helper
2487 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2488 #ifdef MULTI_PABORT
2489@@ -89,11 +170,15 @@
2490 * Invalid mode handlers
2491 */
2492 .macro inv_entry, reason
2493+
2494+ pax_enter_kernel
2495+
2496 sub sp, sp, #S_FRAME_SIZE
2497 ARM( stmib sp, {r1 - lr} )
2498 THUMB( stmia sp, {r0 - r12} )
2499 THUMB( str sp, [sp, #S_SP] )
2500 THUMB( str lr, [sp, #S_LR] )
2501+
2502 mov r1, #\reason
2503 .endm
2504
2505@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2506 .macro svc_entry, stack_hole=0
2507 UNWIND(.fnstart )
2508 UNWIND(.save {r0 - pc} )
2509+
2510+ pax_enter_kernel
2511+
2512 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2513+
2514 #ifdef CONFIG_THUMB2_KERNEL
2515 SPFIX( str r0, [sp] ) @ temporarily saved
2516 SPFIX( mov r0, sp )
2517@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2518 ldmia r0, {r3 - r5}
2519 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2520 mov r6, #-1 @ "" "" "" ""
2521+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2522+ @ offset sp by 8 as done in pax_enter_kernel
2523+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2524+#else
2525 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2526+#endif
2527 SPFIX( addeq r2, r2, #4 )
2528 str r3, [sp, #-4]! @ save the "real" r0 copied
2529 @ from the exception stack
2530@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2531 .macro usr_entry
2532 UNWIND(.fnstart )
2533 UNWIND(.cantunwind ) @ don't unwind the user space
2534+
2535+ pax_enter_kernel_user
2536+
2537 sub sp, sp, #S_FRAME_SIZE
2538 ARM( stmib sp, {r1 - r12} )
2539 THUMB( stmia sp, {r0 - r12} )
2540@@ -357,7 +454,8 @@ ENDPROC(__pabt_svc)
2541 .endm
2542
2543 .macro kuser_cmpxchg_check
2544-#if !defined(CONFIG_CPU_32v6K) && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
2545+#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) && \
2546+ !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
2547 #ifndef CONFIG_MMU
2548 #warning "NPTL on non MMU needs fixing"
2549 #else
2550@@ -414,7 +512,9 @@ __und_usr:
2551 tst r3, #PSR_T_BIT @ Thumb mode?
2552 bne __und_usr_thumb
2553 sub r4, r2, #4 @ ARM instr at LR - 4
2554+ pax_open_userland
2555 1: ldrt r0, [r4]
2556+ pax_close_userland
2557 #ifdef CONFIG_CPU_ENDIAN_BE8
2558 rev r0, r0 @ little endian instruction
2559 #endif
2560@@ -449,10 +549,14 @@ __und_usr_thumb:
2561 */
2562 .arch armv6t2
2563 #endif
2564+ pax_open_userland
2565 2: ldrht r5, [r4]
2566+ pax_close_userland
2567 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2568 blo __und_usr_fault_16 @ 16bit undefined instruction
2569+ pax_open_userland
2570 3: ldrht r0, [r2]
2571+ pax_close_userland
2572 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2573 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2574 orr r0, r0, r5, lsl #16
2575@@ -481,7 +585,8 @@ ENDPROC(__und_usr)
2576 */
2577 .pushsection .fixup, "ax"
2578 .align 2
2579-4: mov pc, r9
2580+4: pax_close_userland
2581+ mov pc, r9
2582 .popsection
2583 .pushsection __ex_table,"a"
2584 .long 1b, 4b
2585@@ -690,7 +795,7 @@ ENTRY(__switch_to)
2586 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2587 THUMB( str sp, [ip], #4 )
2588 THUMB( str lr, [ip], #4 )
2589-#ifdef CONFIG_CPU_USE_DOMAINS
2590+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2591 ldr r6, [r2, #TI_CPU_DOMAIN]
2592 #endif
2593 set_tls r3, r4, r5
2594@@ -699,7 +804,7 @@ ENTRY(__switch_to)
2595 ldr r8, =__stack_chk_guard
2596 ldr r7, [r7, #TSK_STACK_CANARY]
2597 #endif
2598-#ifdef CONFIG_CPU_USE_DOMAINS
2599+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2600 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2601 #endif
2602 mov r5, r0
2603diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2604index bc5bc0a..d0998ca 100644
2605--- a/arch/arm/kernel/entry-common.S
2606+++ b/arch/arm/kernel/entry-common.S
2607@@ -10,18 +10,46 @@
2608
2609 #include <asm/unistd.h>
2610 #include <asm/ftrace.h>
2611+#include <asm/domain.h>
2612 #include <asm/unwind.h>
2613
2614+#include "entry-header.S"
2615+
2616 #ifdef CONFIG_NEED_RET_TO_USER
2617 #include <mach/entry-macro.S>
2618 #else
2619 .macro arch_ret_to_user, tmp1, tmp2
2620+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2621+ @ save regs
2622+ stmdb sp!, {r1, r2}
2623+ @ read DACR from cpu_domain into r1
2624+ mov r2, sp
2625+ @ assume 8K pages, since we have to split the immediate in two
2626+ bic r2, r2, #(0x1fc0)
2627+ bic r2, r2, #(0x3f)
2628+ ldr r1, [r2, #TI_CPU_DOMAIN]
2629+#ifdef CONFIG_PAX_KERNEXEC
2630+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2631+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2632+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2633+#endif
2634+#ifdef CONFIG_PAX_MEMORY_UDEREF
2635+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2636+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2637+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2638+#endif
2639+ @ write r1 to current_thread_info()->cpu_domain
2640+ str r1, [r2, #TI_CPU_DOMAIN]
2641+ @ write r1 to DACR
2642+ mcr p15, 0, r1, c3, c0, 0
2643+ @ instruction sync
2644+ instr_sync
2645+ @ restore regs
2646+ ldmia sp!, {r1, r2}
2647+#endif
2648 .endm
2649 #endif
2650
2651-#include "entry-header.S"
2652-
2653-
2654 .align 5
2655 /*
2656 * This is the fast syscall return path. We do as little as
2657@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2658
2659 .align 5
2660 ENTRY(vector_swi)
2661+
2662 sub sp, sp, #S_FRAME_SIZE
2663 stmia sp, {r0 - r12} @ Calling r0 - r12
2664 ARM( add r8, sp, #S_PC )
2665@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2666 ldr scno, [lr, #-4] @ get SWI instruction
2667 #endif
2668
2669+ /*
2670+ * do this here to avoid a performance hit of wrapping the code above
2671+ * that directly dereferences userland to parse the SWI instruction
2672+ */
2673+ pax_enter_kernel_user
2674+
2675 #ifdef CONFIG_ALIGNMENT_TRAP
2676 ldr ip, __cr_alignment
2677 ldr ip, [ip]
2678diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2679index 160f337..db67ee4 100644
2680--- a/arch/arm/kernel/entry-header.S
2681+++ b/arch/arm/kernel/entry-header.S
2682@@ -73,6 +73,60 @@
2683 msr cpsr_c, \rtemp @ switch back to the SVC mode
2684 .endm
2685
2686+ .macro pax_enter_kernel_user
2687+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2688+ @ save regs
2689+ stmdb sp!, {r0, r1}
2690+ @ read DACR from cpu_domain into r1
2691+ mov r0, sp
2692+ @ assume 8K pages, since we have to split the immediate in two
2693+ bic r0, r0, #(0x1fc0)
2694+ bic r0, r0, #(0x3f)
2695+ ldr r1, [r0, #TI_CPU_DOMAIN]
2696+#ifdef CONFIG_PAX_MEMORY_UDEREF
2697+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2698+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2699+#endif
2700+#ifdef CONFIG_PAX_KERNEXEC
2701+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2702+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2703+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2704+#endif
2705+ @ write r1 to current_thread_info()->cpu_domain
2706+ str r1, [r0, #TI_CPU_DOMAIN]
2707+ @ write r1 to DACR
2708+ mcr p15, 0, r1, c3, c0, 0
2709+ @ instruction sync
2710+ instr_sync
2711+ @ restore regs
2712+ ldmia sp!, {r0, r1}
2713+#endif
2714+ .endm
2715+
2716+ .macro pax_exit_kernel
2717+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2718+ @ save regs
2719+ stmdb sp!, {r0, r1}
2720+ @ read old DACR from stack into r1
2721+ ldr r1, [sp, #(8 + S_SP)]
2722+ sub r1, r1, #8
2723+ ldr r1, [r1]
2724+
2725+ @ write r1 to current_thread_info()->cpu_domain
2726+ mov r0, sp
2727+ @ assume 8K pages, since we have to split the immediate in two
2728+ bic r0, r0, #(0x1fc0)
2729+ bic r0, r0, #(0x3f)
2730+ str r1, [r0, #TI_CPU_DOMAIN]
2731+ @ write r1 to DACR
2732+ mcr p15, 0, r1, c3, c0, 0
2733+ @ instruction sync
2734+ instr_sync
2735+ @ restore regs
2736+ ldmia sp!, {r0, r1}
2737+#endif
2738+ .endm
2739+
2740 #ifndef CONFIG_THUMB2_KERNEL
2741 .macro svc_exit, rpsr, irq = 0
2742 .if \irq != 0
2743@@ -92,6 +146,9 @@
2744 blne trace_hardirqs_off
2745 #endif
2746 .endif
2747+
2748+ pax_exit_kernel
2749+
2750 msr spsr_cxsf, \rpsr
2751 #if defined(CONFIG_CPU_V6)
2752 ldr r0, [sp]
2753@@ -155,6 +212,9 @@
2754 blne trace_hardirqs_off
2755 #endif
2756 .endif
2757+
2758+ pax_exit_kernel
2759+
2760 ldr lr, [sp, #S_SP] @ top of the stack
2761 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2762 clrex @ clear the exclusive monitor
2763diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2764index 25442f4..d4948fc 100644
2765--- a/arch/arm/kernel/fiq.c
2766+++ b/arch/arm/kernel/fiq.c
2767@@ -84,17 +84,16 @@ int show_fiq_list(struct seq_file *p, int prec)
2768
2769 void set_fiq_handler(void *start, unsigned int length)
2770 {
2771-#if defined(CONFIG_CPU_USE_DOMAINS)
2772- void *base = (void *)0xffff0000;
2773-#else
2774 void *base = vectors_page;
2775-#endif
2776 unsigned offset = FIQ_OFFSET;
2777
2778+ pax_open_kernel();
2779 memcpy(base + offset, start, length);
2780+ pax_close_kernel();
2781+
2782+ if (!cache_is_vipt_nonaliasing())
2783+ flush_icache_range(base + offset, offset + length);
2784 flush_icache_range(0xffff0000 + offset, 0xffff0000 + offset + length);
2785- if (!vectors_high())
2786- flush_icache_range(offset, offset + length);
2787 }
2788
2789 int claim_fiq(struct fiq_handler *f)
2790diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2791index 8bac553..caee108 100644
2792--- a/arch/arm/kernel/head.S
2793+++ b/arch/arm/kernel/head.S
2794@@ -52,7 +52,9 @@
2795 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2796
2797 .macro pgtbl, rd, phys
2798- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2799+ mov \rd, #TEXT_OFFSET
2800+ sub \rd, #PG_DIR_SIZE
2801+ add \rd, \rd, \phys
2802 .endm
2803
2804 /*
2805@@ -434,7 +436,7 @@ __enable_mmu:
2806 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2807 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2808 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2809- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2810+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2811 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2812 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2813 #endif
2814diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2815index 1fd749e..47adb08 100644
2816--- a/arch/arm/kernel/hw_breakpoint.c
2817+++ b/arch/arm/kernel/hw_breakpoint.c
2818@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2819 return NOTIFY_OK;
2820 }
2821
2822-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2823+static struct notifier_block dbg_reset_nb = {
2824 .notifier_call = dbg_reset_notify,
2825 };
2826
2827diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2828index 1e9be5d..03edbc2 100644
2829--- a/arch/arm/kernel/module.c
2830+++ b/arch/arm/kernel/module.c
2831@@ -37,12 +37,37 @@
2832 #endif
2833
2834 #ifdef CONFIG_MMU
2835-void *module_alloc(unsigned long size)
2836+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2837 {
2838+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2839+ return NULL;
2840 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2841- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2842+ GFP_KERNEL, prot, -1,
2843 __builtin_return_address(0));
2844 }
2845+
2846+void *module_alloc(unsigned long size)
2847+{
2848+
2849+#ifdef CONFIG_PAX_KERNEXEC
2850+ return __module_alloc(size, PAGE_KERNEL);
2851+#else
2852+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2853+#endif
2854+
2855+}
2856+
2857+#ifdef CONFIG_PAX_KERNEXEC
2858+void module_free_exec(struct module *mod, void *module_region)
2859+{
2860+ module_free(mod, module_region);
2861+}
2862+
2863+void *module_alloc_exec(unsigned long size)
2864+{
2865+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2866+}
2867+#endif
2868 #endif
2869
2870 int
2871diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2872index 07314af..c46655c 100644
2873--- a/arch/arm/kernel/patch.c
2874+++ b/arch/arm/kernel/patch.c
2875@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2876 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2877 int size;
2878
2879+ pax_open_kernel();
2880 if (thumb2 && __opcode_is_thumb16(insn)) {
2881 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2882 size = sizeof(u16);
2883@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2884 *(u32 *)addr = insn;
2885 size = sizeof(u32);
2886 }
2887+ pax_close_kernel();
2888
2889 flush_icache_range((uintptr_t)(addr),
2890 (uintptr_t)(addr) + size);
2891diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
2892index d9f5cd4..e186ee1 100644
2893--- a/arch/arm/kernel/perf_event.c
2894+++ b/arch/arm/kernel/perf_event.c
2895@@ -53,7 +53,12 @@ armpmu_map_cache_event(const unsigned (*cache_map)
2896 static int
2897 armpmu_map_hw_event(const unsigned (*event_map)[PERF_COUNT_HW_MAX], u64 config)
2898 {
2899- int mapping = (*event_map)[config];
2900+ int mapping;
2901+
2902+ if (config >= PERF_COUNT_HW_MAX)
2903+ return -EINVAL;
2904+
2905+ mapping = (*event_map)[config];
2906 return mapping == HW_OP_UNSUPPORTED ? -ENOENT : mapping;
2907 }
2908
2909@@ -253,6 +258,9 @@ validate_event(struct pmu_hw_events *hw_events,
2910 struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
2911 struct pmu *leader_pmu = event->group_leader->pmu;
2912
2913+ if (is_software_event(event))
2914+ return 1;
2915+
2916 if (event->pmu != leader_pmu || event->state < PERF_EVENT_STATE_OFF)
2917 return 1;
2918
2919diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2920index 1f2740e..b36e225 100644
2921--- a/arch/arm/kernel/perf_event_cpu.c
2922+++ b/arch/arm/kernel/perf_event_cpu.c
2923@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2924 return NOTIFY_OK;
2925 }
2926
2927-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2928+static struct notifier_block cpu_pmu_hotplug_notifier = {
2929 .notifier_call = cpu_pmu_notify,
2930 };
2931
2932diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2933index 5bc2615..4f1a0c2 100644
2934--- a/arch/arm/kernel/process.c
2935+++ b/arch/arm/kernel/process.c
2936@@ -28,10 +28,10 @@
2937 #include <linux/tick.h>
2938 #include <linux/utsname.h>
2939 #include <linux/uaccess.h>
2940-#include <linux/random.h>
2941 #include <linux/hw_breakpoint.h>
2942 #include <linux/cpuidle.h>
2943 #include <linux/leds.h>
2944+#include <linux/random.h>
2945
2946 #include <asm/cacheflush.h>
2947 #include <asm/idmap.h>
2948@@ -223,6 +223,7 @@ void machine_power_off(void)
2949
2950 if (pm_power_off)
2951 pm_power_off();
2952+ BUG();
2953 }
2954
2955 /*
2956@@ -236,7 +237,7 @@ void machine_power_off(void)
2957 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2958 * to use. Implementing such co-ordination would be essentially impossible.
2959 */
2960-void machine_restart(char *cmd)
2961+__noreturn void machine_restart(char *cmd)
2962 {
2963 smp_send_stop();
2964
2965@@ -258,8 +259,8 @@ void __show_regs(struct pt_regs *regs)
2966
2967 show_regs_print_info(KERN_DEFAULT);
2968
2969- print_symbol("PC is at %s\n", instruction_pointer(regs));
2970- print_symbol("LR is at %s\n", regs->ARM_lr);
2971+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2972+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2973 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2974 "sp : %08lx ip : %08lx fp : %08lx\n",
2975 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2976@@ -426,12 +427,6 @@ unsigned long get_wchan(struct task_struct *p)
2977 return 0;
2978 }
2979
2980-unsigned long arch_randomize_brk(struct mm_struct *mm)
2981-{
2982- unsigned long range_end = mm->brk + 0x02000000;
2983- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2984-}
2985-
2986 #ifdef CONFIG_MMU
2987 #ifdef CONFIG_KUSER_HELPERS
2988 /*
2989@@ -447,7 +442,7 @@ static struct vm_area_struct gate_vma = {
2990
2991 static int __init gate_vma_init(void)
2992 {
2993- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2994+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2995 return 0;
2996 }
2997 arch_initcall(gate_vma_init);
2998@@ -466,48 +461,23 @@ int in_gate_area_no_mm(unsigned long addr)
2999 {
3000 return in_gate_area(NULL, addr);
3001 }
3002-#define is_gate_vma(vma) ((vma) = &gate_vma)
3003+#define is_gate_vma(vma) ((vma) == &gate_vma)
3004 #else
3005 #define is_gate_vma(vma) 0
3006 #endif
3007
3008 const char *arch_vma_name(struct vm_area_struct *vma)
3009 {
3010- return is_gate_vma(vma) ? "[vectors]" :
3011- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3012- "[sigpage]" : NULL;
3013+ return is_gate_vma(vma) ? "[vectors]" : NULL;
3014 }
3015
3016-static struct page *signal_page;
3017-extern struct page *get_signal_page(void);
3018-
3019 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3020 {
3021 struct mm_struct *mm = current->mm;
3022- unsigned long addr;
3023- int ret;
3024-
3025- if (!signal_page)
3026- signal_page = get_signal_page();
3027- if (!signal_page)
3028- return -ENOMEM;
3029
3030 down_write(&mm->mmap_sem);
3031- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3032- if (IS_ERR_VALUE(addr)) {
3033- ret = addr;
3034- goto up_fail;
3035- }
3036-
3037- ret = install_special_mapping(mm, addr, PAGE_SIZE,
3038- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3039- &signal_page);
3040-
3041- if (ret == 0)
3042- mm->context.sigpage = addr;
3043-
3044- up_fail:
3045+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3046 up_write(&mm->mmap_sem);
3047- return ret;
3048+ return 0;
3049 }
3050 #endif
3051diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3052index 3653164..d83e55d 100644
3053--- a/arch/arm/kernel/psci.c
3054+++ b/arch/arm/kernel/psci.c
3055@@ -24,7 +24,7 @@
3056 #include <asm/opcodes-virt.h>
3057 #include <asm/psci.h>
3058
3059-struct psci_operations psci_ops;
3060+struct psci_operations psci_ops __read_only;
3061
3062 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3063
3064diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3065index 03deeff..741ce88 100644
3066--- a/arch/arm/kernel/ptrace.c
3067+++ b/arch/arm/kernel/ptrace.c
3068@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3069 return current_thread_info()->syscall;
3070 }
3071
3072+#ifdef CONFIG_GRKERNSEC_SETXID
3073+extern void gr_delayed_cred_worker(void);
3074+#endif
3075+
3076 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3077 {
3078 current_thread_info()->syscall = scno;
3079
3080+#ifdef CONFIG_GRKERNSEC_SETXID
3081+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3082+ gr_delayed_cred_worker();
3083+#endif
3084+
3085 /* Do the secure computing check first; failures should be fast. */
3086 if (secure_computing(scno) == -1)
3087 return -1;
3088diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3089index b4b1d39..efdc9be 100644
3090--- a/arch/arm/kernel/setup.c
3091+++ b/arch/arm/kernel/setup.c
3092@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
3093 unsigned int elf_hwcap __read_mostly;
3094 EXPORT_SYMBOL(elf_hwcap);
3095
3096+pteval_t __supported_pte_mask __read_only;
3097+pmdval_t __supported_pmd_mask __read_only;
3098
3099 #ifdef MULTI_CPU
3100-struct processor processor __read_mostly;
3101+struct processor processor;
3102 #endif
3103 #ifdef MULTI_TLB
3104-struct cpu_tlb_fns cpu_tlb __read_mostly;
3105+struct cpu_tlb_fns cpu_tlb __read_only;
3106 #endif
3107 #ifdef MULTI_USER
3108-struct cpu_user_fns cpu_user __read_mostly;
3109+struct cpu_user_fns cpu_user __read_only;
3110 #endif
3111 #ifdef MULTI_CACHE
3112-struct cpu_cache_fns cpu_cache __read_mostly;
3113+struct cpu_cache_fns cpu_cache __read_only;
3114 #endif
3115 #ifdef CONFIG_OUTER_CACHE
3116-struct outer_cache_fns outer_cache __read_mostly;
3117+struct outer_cache_fns outer_cache __read_only;
3118 EXPORT_SYMBOL(outer_cache);
3119 #endif
3120
3121@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
3122 asm("mrc p15, 0, %0, c0, c1, 4"
3123 : "=r" (mmfr0));
3124 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3125- (mmfr0 & 0x000000f0) >= 0x00000030)
3126+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3127 cpu_arch = CPU_ARCH_ARMv7;
3128- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3129+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3130+ __supported_pte_mask |= L_PTE_PXN;
3131+ __supported_pmd_mask |= PMD_PXNTABLE;
3132+ }
3133+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3134 (mmfr0 & 0x000000f0) == 0x00000020)
3135 cpu_arch = CPU_ARCH_ARMv6;
3136 else
3137@@ -479,7 +485,7 @@ static void __init setup_processor(void)
3138 __cpu_architecture = __get_cpu_architecture();
3139
3140 #ifdef MULTI_CPU
3141- processor = *list->proc;
3142+ memcpy((void *)&processor, list->proc, sizeof processor);
3143 #endif
3144 #ifdef MULTI_TLB
3145 cpu_tlb = *list->tlb;
3146diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3147index 5a42c12..a2bb7c6 100644
3148--- a/arch/arm/kernel/signal.c
3149+++ b/arch/arm/kernel/signal.c
3150@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3151 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3152 };
3153
3154-static unsigned long signal_return_offset;
3155-
3156 #ifdef CONFIG_CRUNCH
3157 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3158 {
3159@@ -406,8 +404,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3160 * except when the MPU has protected the vectors
3161 * page from PL0
3162 */
3163- retcode = mm->context.sigpage + signal_return_offset +
3164- (idx << 2) + thumb;
3165+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3166 } else
3167 #endif
3168 {
3169@@ -611,33 +608,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3170 } while (thread_flags & _TIF_WORK_MASK);
3171 return 0;
3172 }
3173-
3174-struct page *get_signal_page(void)
3175-{
3176- unsigned long ptr;
3177- unsigned offset;
3178- struct page *page;
3179- void *addr;
3180-
3181- page = alloc_pages(GFP_KERNEL, 0);
3182-
3183- if (!page)
3184- return NULL;
3185-
3186- addr = page_address(page);
3187-
3188- /* Give the signal return code some randomness */
3189- offset = 0x200 + (get_random_int() & 0x7fc);
3190- signal_return_offset = offset;
3191-
3192- /*
3193- * Copy signal return handlers into the vector page, and
3194- * set sigreturn to be a pointer to these.
3195- */
3196- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3197-
3198- ptr = (unsigned long)addr + offset;
3199- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3200-
3201- return page;
3202-}
3203diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3204index 5919eb4..b5d6dfe 100644
3205--- a/arch/arm/kernel/smp.c
3206+++ b/arch/arm/kernel/smp.c
3207@@ -70,7 +70,7 @@ enum ipi_msg_type {
3208
3209 static DECLARE_COMPLETION(cpu_running);
3210
3211-static struct smp_operations smp_ops;
3212+static struct smp_operations smp_ops __read_only;
3213
3214 void __init smp_set_ops(struct smp_operations *ops)
3215 {
3216diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3217index 6b9567e..b8af2d6 100644
3218--- a/arch/arm/kernel/traps.c
3219+++ b/arch/arm/kernel/traps.c
3220@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3221 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3222 {
3223 #ifdef CONFIG_KALLSYMS
3224- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3225+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3226 #else
3227 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3228 #endif
3229@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3230 static int die_owner = -1;
3231 static unsigned int die_nest_count;
3232
3233+extern void gr_handle_kernel_exploit(void);
3234+
3235 static unsigned long oops_begin(void)
3236 {
3237 int cpu;
3238@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3239 panic("Fatal exception in interrupt");
3240 if (panic_on_oops)
3241 panic("Fatal exception");
3242+
3243+ gr_handle_kernel_exploit();
3244+
3245 if (signr)
3246 do_exit(signr);
3247 }
3248@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3249 * The user helper at 0xffff0fe0 must be used instead.
3250 * (see entry-armv.S for details)
3251 */
3252+ pax_open_kernel();
3253 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3254+ pax_close_kernel();
3255 }
3256 return 0;
3257
3258@@ -848,5 +855,9 @@ void __init early_trap_init(void *vectors_base)
3259 kuser_init(vectors_base);
3260
3261 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3262- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3263+
3264+#ifndef CONFIG_PAX_MEMORY_UDEREF
3265+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3266+#endif
3267+
3268 }
3269diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3270index 33f2ea3..0b91824 100644
3271--- a/arch/arm/kernel/vmlinux.lds.S
3272+++ b/arch/arm/kernel/vmlinux.lds.S
3273@@ -8,7 +8,11 @@
3274 #include <asm/thread_info.h>
3275 #include <asm/memory.h>
3276 #include <asm/page.h>
3277-
3278+
3279+#ifdef CONFIG_PAX_KERNEXEC
3280+#include <asm/pgtable.h>
3281+#endif
3282+
3283 #define PROC_INFO \
3284 . = ALIGN(4); \
3285 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3286@@ -94,6 +98,11 @@ SECTIONS
3287 _text = .;
3288 HEAD_TEXT
3289 }
3290+
3291+#ifdef CONFIG_PAX_KERNEXEC
3292+ . = ALIGN(1<<SECTION_SHIFT);
3293+#endif
3294+
3295 .text : { /* Real text segment */
3296 _stext = .; /* Text and read-only data */
3297 __exception_text_start = .;
3298@@ -116,6 +125,8 @@ SECTIONS
3299 ARM_CPU_KEEP(PROC_INFO)
3300 }
3301
3302+ _etext = .; /* End of text section */
3303+
3304 RO_DATA(PAGE_SIZE)
3305
3306 . = ALIGN(4);
3307@@ -146,7 +157,9 @@ SECTIONS
3308
3309 NOTES
3310
3311- _etext = .; /* End of text and rodata section */
3312+#ifdef CONFIG_PAX_KERNEXEC
3313+ . = ALIGN(1<<SECTION_SHIFT);
3314+#endif
3315
3316 #ifndef CONFIG_XIP_KERNEL
3317 . = ALIGN(PAGE_SIZE);
3318@@ -224,6 +237,11 @@ SECTIONS
3319 . = PAGE_OFFSET + TEXT_OFFSET;
3320 #else
3321 __init_end = .;
3322+
3323+#ifdef CONFIG_PAX_KERNEXEC
3324+ . = ALIGN(1<<SECTION_SHIFT);
3325+#endif
3326+
3327 . = ALIGN(THREAD_SIZE);
3328 __data_loc = .;
3329 #endif
3330diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3331index 14a0d98..7771a7d 100644
3332--- a/arch/arm/lib/clear_user.S
3333+++ b/arch/arm/lib/clear_user.S
3334@@ -12,14 +12,14 @@
3335
3336 .text
3337
3338-/* Prototype: int __clear_user(void *addr, size_t sz)
3339+/* Prototype: int ___clear_user(void *addr, size_t sz)
3340 * Purpose : clear some user memory
3341 * Params : addr - user memory address to clear
3342 * : sz - number of bytes to clear
3343 * Returns : number of bytes NOT cleared
3344 */
3345 ENTRY(__clear_user_std)
3346-WEAK(__clear_user)
3347+WEAK(___clear_user)
3348 stmfd sp!, {r1, lr}
3349 mov r2, #0
3350 cmp r1, #4
3351@@ -44,7 +44,7 @@ WEAK(__clear_user)
3352 USER( strnebt r2, [r0])
3353 mov r0, #0
3354 ldmfd sp!, {r1, pc}
3355-ENDPROC(__clear_user)
3356+ENDPROC(___clear_user)
3357 ENDPROC(__clear_user_std)
3358
3359 .pushsection .fixup,"ax"
3360diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3361index 66a477a..bee61d3 100644
3362--- a/arch/arm/lib/copy_from_user.S
3363+++ b/arch/arm/lib/copy_from_user.S
3364@@ -16,7 +16,7 @@
3365 /*
3366 * Prototype:
3367 *
3368- * size_t __copy_from_user(void *to, const void *from, size_t n)
3369+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3370 *
3371 * Purpose:
3372 *
3373@@ -84,11 +84,11 @@
3374
3375 .text
3376
3377-ENTRY(__copy_from_user)
3378+ENTRY(___copy_from_user)
3379
3380 #include "copy_template.S"
3381
3382-ENDPROC(__copy_from_user)
3383+ENDPROC(___copy_from_user)
3384
3385 .pushsection .fixup,"ax"
3386 .align 0
3387diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3388index 6ee2f67..d1cce76 100644
3389--- a/arch/arm/lib/copy_page.S
3390+++ b/arch/arm/lib/copy_page.S
3391@@ -10,6 +10,7 @@
3392 * ASM optimised string functions
3393 */
3394 #include <linux/linkage.h>
3395+#include <linux/const.h>
3396 #include <asm/assembler.h>
3397 #include <asm/asm-offsets.h>
3398 #include <asm/cache.h>
3399diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3400index d066df6..df28194 100644
3401--- a/arch/arm/lib/copy_to_user.S
3402+++ b/arch/arm/lib/copy_to_user.S
3403@@ -16,7 +16,7 @@
3404 /*
3405 * Prototype:
3406 *
3407- * size_t __copy_to_user(void *to, const void *from, size_t n)
3408+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3409 *
3410 * Purpose:
3411 *
3412@@ -88,11 +88,11 @@
3413 .text
3414
3415 ENTRY(__copy_to_user_std)
3416-WEAK(__copy_to_user)
3417+WEAK(___copy_to_user)
3418
3419 #include "copy_template.S"
3420
3421-ENDPROC(__copy_to_user)
3422+ENDPROC(___copy_to_user)
3423 ENDPROC(__copy_to_user_std)
3424
3425 .pushsection .fixup,"ax"
3426diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3427index 7d08b43..f7ca7ea 100644
3428--- a/arch/arm/lib/csumpartialcopyuser.S
3429+++ b/arch/arm/lib/csumpartialcopyuser.S
3430@@ -57,8 +57,8 @@
3431 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3432 */
3433
3434-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3435-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3436+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3437+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3438
3439 #include "csumpartialcopygeneric.S"
3440
3441diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3442index 64dbfa5..84a3fd9 100644
3443--- a/arch/arm/lib/delay.c
3444+++ b/arch/arm/lib/delay.c
3445@@ -28,7 +28,7 @@
3446 /*
3447 * Default to the loop-based delay implementation.
3448 */
3449-struct arm_delay_ops arm_delay_ops = {
3450+struct arm_delay_ops arm_delay_ops __read_only = {
3451 .delay = __loop_delay,
3452 .const_udelay = __loop_const_udelay,
3453 .udelay = __loop_udelay,
3454diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3455index 025f742..8432b08 100644
3456--- a/arch/arm/lib/uaccess_with_memcpy.c
3457+++ b/arch/arm/lib/uaccess_with_memcpy.c
3458@@ -104,7 +104,7 @@ out:
3459 }
3460
3461 unsigned long
3462-__copy_to_user(void __user *to, const void *from, unsigned long n)
3463+___copy_to_user(void __user *to, const void *from, unsigned long n)
3464 {
3465 /*
3466 * This test is stubbed out of the main function above to keep
3467diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3468index f389228..592ef66 100644
3469--- a/arch/arm/mach-kirkwood/common.c
3470+++ b/arch/arm/mach-kirkwood/common.c
3471@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3472 clk_gate_ops.disable(hw);
3473 }
3474
3475-static struct clk_ops clk_gate_fn_ops;
3476+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3477+{
3478+ return clk_gate_ops.is_enabled(hw);
3479+}
3480+
3481+static struct clk_ops clk_gate_fn_ops = {
3482+ .enable = clk_gate_fn_enable,
3483+ .disable = clk_gate_fn_disable,
3484+ .is_enabled = clk_gate_fn_is_enabled,
3485+};
3486
3487 static struct clk __init *clk_register_gate_fn(struct device *dev,
3488 const char *name,
3489@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3490 gate_fn->fn_en = fn_en;
3491 gate_fn->fn_dis = fn_dis;
3492
3493- /* ops is the gate ops, but with our enable/disable functions */
3494- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3495- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3496- clk_gate_fn_ops = clk_gate_ops;
3497- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3498- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3499- }
3500-
3501 clk = clk_register(dev, &gate_fn->gate.hw);
3502
3503 if (IS_ERR(clk))
3504diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3505index f6eeb87..cc90868 100644
3506--- a/arch/arm/mach-omap2/board-n8x0.c
3507+++ b/arch/arm/mach-omap2/board-n8x0.c
3508@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3509 }
3510 #endif
3511
3512-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3513+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3514 .late_init = n8x0_menelaus_late_init,
3515 };
3516
3517diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3518index 6c4da12..d9ca72d 100644
3519--- a/arch/arm/mach-omap2/gpmc.c
3520+++ b/arch/arm/mach-omap2/gpmc.c
3521@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3522 };
3523
3524 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3525-static struct irq_chip gpmc_irq_chip;
3526 static unsigned gpmc_irq_start;
3527
3528 static struct resource gpmc_mem_root;
3529@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3530
3531 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3532
3533+static struct irq_chip gpmc_irq_chip = {
3534+ .name = "gpmc",
3535+ .irq_startup = gpmc_irq_noop_ret,
3536+ .irq_enable = gpmc_irq_enable,
3537+ .irq_disable = gpmc_irq_disable,
3538+ .irq_shutdown = gpmc_irq_noop,
3539+ .irq_ack = gpmc_irq_noop,
3540+ .irq_mask = gpmc_irq_noop,
3541+ .irq_unmask = gpmc_irq_noop,
3542+
3543+};
3544+
3545 static int gpmc_setup_irq(void)
3546 {
3547 int i;
3548@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3549 return gpmc_irq_start;
3550 }
3551
3552- gpmc_irq_chip.name = "gpmc";
3553- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3554- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3555- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3556- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3557- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3558- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3559- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3560-
3561 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3562 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3563
3564diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3565index f8bb3b9..831e7b8 100644
3566--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3567+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3568@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3569 return NOTIFY_OK;
3570 }
3571
3572-static struct notifier_block __refdata irq_hotplug_notifier = {
3573+static struct notifier_block irq_hotplug_notifier = {
3574 .notifier_call = irq_cpu_hotplug_notify,
3575 };
3576
3577diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3578index e6d2307..d057195 100644
3579--- a/arch/arm/mach-omap2/omap_device.c
3580+++ b/arch/arm/mach-omap2/omap_device.c
3581@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3582 struct platform_device __init *omap_device_build(const char *pdev_name,
3583 int pdev_id,
3584 struct omap_hwmod *oh,
3585- void *pdata, int pdata_len)
3586+ const void *pdata, int pdata_len)
3587 {
3588 struct omap_hwmod *ohs[] = { oh };
3589
3590@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3591 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3592 int pdev_id,
3593 struct omap_hwmod **ohs,
3594- int oh_cnt, void *pdata,
3595+ int oh_cnt, const void *pdata,
3596 int pdata_len)
3597 {
3598 int ret = -ENOMEM;
3599diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3600index 044c31d..2ee0861 100644
3601--- a/arch/arm/mach-omap2/omap_device.h
3602+++ b/arch/arm/mach-omap2/omap_device.h
3603@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3604 /* Core code interface */
3605
3606 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3607- struct omap_hwmod *oh, void *pdata,
3608+ struct omap_hwmod *oh, const void *pdata,
3609 int pdata_len);
3610
3611 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3612 struct omap_hwmod **oh, int oh_cnt,
3613- void *pdata, int pdata_len);
3614+ const void *pdata, int pdata_len);
3615
3616 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3617 struct omap_hwmod **ohs, int oh_cnt);
3618diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3619index 7341eff..fd75e34 100644
3620--- a/arch/arm/mach-omap2/omap_hwmod.c
3621+++ b/arch/arm/mach-omap2/omap_hwmod.c
3622@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3623 int (*init_clkdm)(struct omap_hwmod *oh);
3624 void (*update_context_lost)(struct omap_hwmod *oh);
3625 int (*get_context_lost)(struct omap_hwmod *oh);
3626-};
3627+} __no_const;
3628
3629 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3630-static struct omap_hwmod_soc_ops soc_ops;
3631+static struct omap_hwmod_soc_ops soc_ops __read_only;
3632
3633 /* omap_hwmod_list contains all registered struct omap_hwmods */
3634 static LIST_HEAD(omap_hwmod_list);
3635diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3636index d15c7bb..b2d1f0c 100644
3637--- a/arch/arm/mach-omap2/wd_timer.c
3638+++ b/arch/arm/mach-omap2/wd_timer.c
3639@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3640 struct omap_hwmod *oh;
3641 char *oh_name = "wd_timer2";
3642 char *dev_name = "omap_wdt";
3643- struct omap_wd_timer_platform_data pdata;
3644+ static struct omap_wd_timer_platform_data pdata = {
3645+ .read_reset_sources = prm_read_reset_sources
3646+ };
3647
3648 if (!cpu_class_is_omap2() || of_have_populated_dt())
3649 return 0;
3650@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3651 return -EINVAL;
3652 }
3653
3654- pdata.read_reset_sources = prm_read_reset_sources;
3655-
3656 pdev = omap_device_build(dev_name, id, oh, &pdata,
3657 sizeof(struct omap_wd_timer_platform_data));
3658 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3659diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3660index 0cdba8d..297993e 100644
3661--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3662+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3663@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3664 bool entered_lp2 = false;
3665
3666 if (tegra_pending_sgi())
3667- ACCESS_ONCE(abort_flag) = true;
3668+ ACCESS_ONCE_RW(abort_flag) = true;
3669
3670 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3671
3672diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3673index cad3ca86..1d79e0f 100644
3674--- a/arch/arm/mach-ux500/setup.h
3675+++ b/arch/arm/mach-ux500/setup.h
3676@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3677 .type = MT_DEVICE, \
3678 }
3679
3680-#define __MEM_DEV_DESC(x, sz) { \
3681- .virtual = IO_ADDRESS(x), \
3682- .pfn = __phys_to_pfn(x), \
3683- .length = sz, \
3684- .type = MT_MEMORY, \
3685-}
3686-
3687 extern struct smp_operations ux500_smp_ops;
3688 extern void ux500_cpu_die(unsigned int cpu);
3689
3690diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3691index 2950082..d0f0782 100644
3692--- a/arch/arm/mm/Kconfig
3693+++ b/arch/arm/mm/Kconfig
3694@@ -436,7 +436,7 @@ config CPU_32v5
3695
3696 config CPU_32v6
3697 bool
3698- select CPU_USE_DOMAINS if CPU_V6 && MMU
3699+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3700 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3701
3702 config CPU_32v6K
3703@@ -585,6 +585,7 @@ config CPU_CP15_MPU
3704
3705 config CPU_USE_DOMAINS
3706 bool
3707+ depends on !ARM_LPAE && !PAX_KERNEXEC
3708 help
3709 This option enables or disables the use of domain switching
3710 via the set_fs() function.
3711@@ -780,6 +781,7 @@ config NEED_KUSER_HELPERS
3712 config KUSER_HELPERS
3713 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3714 default y
3715+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3716 help
3717 Warning: disabling this option may break user programs.
3718
3719@@ -790,7 +792,7 @@ config KUSER_HELPERS
3720 run on ARMv4 through to ARMv7 without modification.
3721
3722 However, the fixed address nature of these helpers can be used
3723- by ROP (return orientated programming) authors when creating
3724+ by ROP (Return Oriented Programming) authors when creating
3725 exploits.
3726
3727 If all of the binaries and libraries which run on your platform
3728diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3729index 6f4585b..7b6f52b 100644
3730--- a/arch/arm/mm/alignment.c
3731+++ b/arch/arm/mm/alignment.c
3732@@ -211,10 +211,12 @@ union offset_union {
3733 #define __get16_unaligned_check(ins,val,addr) \
3734 do { \
3735 unsigned int err = 0, v, a = addr; \
3736+ pax_open_userland(); \
3737 __get8_unaligned_check(ins,v,a,err); \
3738 val = v << ((BE) ? 8 : 0); \
3739 __get8_unaligned_check(ins,v,a,err); \
3740 val |= v << ((BE) ? 0 : 8); \
3741+ pax_close_userland(); \
3742 if (err) \
3743 goto fault; \
3744 } while (0)
3745@@ -228,6 +230,7 @@ union offset_union {
3746 #define __get32_unaligned_check(ins,val,addr) \
3747 do { \
3748 unsigned int err = 0, v, a = addr; \
3749+ pax_open_userland(); \
3750 __get8_unaligned_check(ins,v,a,err); \
3751 val = v << ((BE) ? 24 : 0); \
3752 __get8_unaligned_check(ins,v,a,err); \
3753@@ -236,6 +239,7 @@ union offset_union {
3754 val |= v << ((BE) ? 8 : 16); \
3755 __get8_unaligned_check(ins,v,a,err); \
3756 val |= v << ((BE) ? 0 : 24); \
3757+ pax_close_userland(); \
3758 if (err) \
3759 goto fault; \
3760 } while (0)
3761@@ -249,6 +253,7 @@ union offset_union {
3762 #define __put16_unaligned_check(ins,val,addr) \
3763 do { \
3764 unsigned int err = 0, v = val, a = addr; \
3765+ pax_open_userland(); \
3766 __asm__( FIRST_BYTE_16 \
3767 ARM( "1: "ins" %1, [%2], #1\n" ) \
3768 THUMB( "1: "ins" %1, [%2]\n" ) \
3769@@ -268,6 +273,7 @@ union offset_union {
3770 " .popsection\n" \
3771 : "=r" (err), "=&r" (v), "=&r" (a) \
3772 : "0" (err), "1" (v), "2" (a)); \
3773+ pax_close_userland(); \
3774 if (err) \
3775 goto fault; \
3776 } while (0)
3777@@ -281,6 +287,7 @@ union offset_union {
3778 #define __put32_unaligned_check(ins,val,addr) \
3779 do { \
3780 unsigned int err = 0, v = val, a = addr; \
3781+ pax_open_userland(); \
3782 __asm__( FIRST_BYTE_32 \
3783 ARM( "1: "ins" %1, [%2], #1\n" ) \
3784 THUMB( "1: "ins" %1, [%2]\n" ) \
3785@@ -310,6 +317,7 @@ union offset_union {
3786 " .popsection\n" \
3787 : "=r" (err), "=&r" (v), "=&r" (a) \
3788 : "0" (err), "1" (v), "2" (a)); \
3789+ pax_close_userland(); \
3790 if (err) \
3791 goto fault; \
3792 } while (0)
3793diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3794index 5dbf13f..ee1ec24 100644
3795--- a/arch/arm/mm/fault.c
3796+++ b/arch/arm/mm/fault.c
3797@@ -25,6 +25,7 @@
3798 #include <asm/system_misc.h>
3799 #include <asm/system_info.h>
3800 #include <asm/tlbflush.h>
3801+#include <asm/sections.h>
3802
3803 #include "fault.h"
3804
3805@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3806 if (fixup_exception(regs))
3807 return;
3808
3809+#ifdef CONFIG_PAX_KERNEXEC
3810+ if ((fsr & FSR_WRITE) &&
3811+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3812+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3813+ {
3814+ if (current->signal->curr_ip)
3815+ 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),
3816+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3817+ else
3818+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3819+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3820+ }
3821+#endif
3822+
3823 /*
3824 * No handler, we'll have to terminate things with extreme prejudice.
3825 */
3826@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3827 }
3828 #endif
3829
3830+#ifdef CONFIG_PAX_PAGEEXEC
3831+ if (fsr & FSR_LNX_PF) {
3832+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3833+ do_group_exit(SIGKILL);
3834+ }
3835+#endif
3836+
3837 tsk->thread.address = addr;
3838 tsk->thread.error_code = fsr;
3839 tsk->thread.trap_no = 14;
3840@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3841 }
3842 #endif /* CONFIG_MMU */
3843
3844+#ifdef CONFIG_PAX_PAGEEXEC
3845+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3846+{
3847+ long i;
3848+
3849+ printk(KERN_ERR "PAX: bytes at PC: ");
3850+ for (i = 0; i < 20; i++) {
3851+ unsigned char c;
3852+ if (get_user(c, (__force unsigned char __user *)pc+i))
3853+ printk(KERN_CONT "?? ");
3854+ else
3855+ printk(KERN_CONT "%02x ", c);
3856+ }
3857+ printk("\n");
3858+
3859+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3860+ for (i = -1; i < 20; i++) {
3861+ unsigned long c;
3862+ if (get_user(c, (__force unsigned long __user *)sp+i))
3863+ printk(KERN_CONT "???????? ");
3864+ else
3865+ printk(KERN_CONT "%08lx ", c);
3866+ }
3867+ printk("\n");
3868+}
3869+#endif
3870+
3871 /*
3872 * First Level Translation Fault Handler
3873 *
3874@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3875 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3876 struct siginfo info;
3877
3878+#ifdef CONFIG_PAX_MEMORY_UDEREF
3879+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3880+ if (current->signal->curr_ip)
3881+ 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),
3882+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3883+ else
3884+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3885+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886+ goto die;
3887+ }
3888+#endif
3889+
3890 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3891 return;
3892
3893+die:
3894 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3895 inf->name, fsr, addr);
3896
3897@@ -569,15 +631,67 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3898 ifsr_info[nr].name = name;
3899 }
3900
3901+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3902+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3903+
3904 asmlinkage void __exception
3905 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3906 {
3907 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3908 struct siginfo info;
3909
3910+ if (user_mode(regs)) {
3911+ unsigned long sigpage = current->mm->context.sigpage;
3912+
3913+ if (sigpage <= addr && addr < sigpage + 7*4) {
3914+ if (addr < sigpage + 3*4)
3915+ sys_sigreturn(regs);
3916+ else
3917+ sys_rt_sigreturn(regs);
3918+ return;
3919+ }
3920+ if (addr == 0xffff0fe0UL) {
3921+ /*
3922+ * PaX: __kuser_get_tls emulation
3923+ */
3924+ regs->ARM_r0 = current_thread_info()->tp_value;
3925+ regs->ARM_pc = regs->ARM_lr;
3926+ return;
3927+ }
3928+ }
3929+
3930+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3931+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3932+ if (current->signal->curr_ip)
3933+ 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),
3934+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3935+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3936+ else
3937+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3938+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3939+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3940+ goto die;
3941+ }
3942+#endif
3943+
3944+#ifdef CONFIG_PAX_REFCOUNT
3945+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3946+ unsigned int bkpt;
3947+
3948+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3949+ current->thread.error_code = ifsr;
3950+ current->thread.trap_no = 0;
3951+ pax_report_refcount_overflow(regs);
3952+ fixup_exception(regs);
3953+ return;
3954+ }
3955+ }
3956+#endif
3957+
3958 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3959 return;
3960
3961+die:
3962 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3963 inf->name, ifsr, addr);
3964
3965diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3966index cf08bdf..772656c 100644
3967--- a/arch/arm/mm/fault.h
3968+++ b/arch/arm/mm/fault.h
3969@@ -3,6 +3,7 @@
3970
3971 /*
3972 * Fault status register encodings. We steal bit 31 for our own purposes.
3973+ * Set when the FSR value is from an instruction fault.
3974 */
3975 #define FSR_LNX_PF (1 << 31)
3976 #define FSR_WRITE (1 << 11)
3977@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3978 }
3979 #endif
3980
3981+/* valid for LPAE and !LPAE */
3982+static inline int is_xn_fault(unsigned int fsr)
3983+{
3984+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3985+}
3986+
3987+static inline int is_domain_fault(unsigned int fsr)
3988+{
3989+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3990+}
3991+
3992 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3993 unsigned long search_exception_table(unsigned long addr);
3994
3995diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3996index 0ecc43f..190b956 100644
3997--- a/arch/arm/mm/init.c
3998+++ b/arch/arm/mm/init.c
3999@@ -30,6 +30,8 @@
4000 #include <asm/setup.h>
4001 #include <asm/tlb.h>
4002 #include <asm/fixmap.h>
4003+#include <asm/system_info.h>
4004+#include <asm/cp15.h>
4005
4006 #include <asm/mach/arch.h>
4007 #include <asm/mach/map.h>
4008@@ -726,7 +728,46 @@ void free_initmem(void)
4009 {
4010 #ifdef CONFIG_HAVE_TCM
4011 extern char __tcm_start, __tcm_end;
4012+#endif
4013
4014+#ifdef CONFIG_PAX_KERNEXEC
4015+ unsigned long addr;
4016+ pgd_t *pgd;
4017+ pud_t *pud;
4018+ pmd_t *pmd;
4019+ int cpu_arch = cpu_architecture();
4020+ unsigned int cr = get_cr();
4021+
4022+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4023+ /* make pages tables, etc before .text NX */
4024+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4025+ pgd = pgd_offset_k(addr);
4026+ pud = pud_offset(pgd, addr);
4027+ pmd = pmd_offset(pud, addr);
4028+ __section_update(pmd, addr, PMD_SECT_XN);
4029+ }
4030+ /* make init NX */
4031+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4032+ pgd = pgd_offset_k(addr);
4033+ pud = pud_offset(pgd, addr);
4034+ pmd = pmd_offset(pud, addr);
4035+ __section_update(pmd, addr, PMD_SECT_XN);
4036+ }
4037+ /* make kernel code/rodata RX */
4038+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4039+ pgd = pgd_offset_k(addr);
4040+ pud = pud_offset(pgd, addr);
4041+ pmd = pmd_offset(pud, addr);
4042+#ifdef CONFIG_ARM_LPAE
4043+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4044+#else
4045+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4046+#endif
4047+ }
4048+ }
4049+#endif
4050+
4051+#ifdef CONFIG_HAVE_TCM
4052 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4053 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
4054 #endif
4055diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4056index 04d9006..c547d85 100644
4057--- a/arch/arm/mm/ioremap.c
4058+++ b/arch/arm/mm/ioremap.c
4059@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
4060 unsigned int mtype;
4061
4062 if (cached)
4063- mtype = MT_MEMORY;
4064+ mtype = MT_MEMORY_RX;
4065 else
4066- mtype = MT_MEMORY_NONCACHED;
4067+ mtype = MT_MEMORY_NONCACHED_RX;
4068
4069 return __arm_ioremap_caller(phys_addr, size, mtype,
4070 __builtin_return_address(0));
4071diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4072index 10062ce..8695745 100644
4073--- a/arch/arm/mm/mmap.c
4074+++ b/arch/arm/mm/mmap.c
4075@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4076 struct vm_area_struct *vma;
4077 int do_align = 0;
4078 int aliasing = cache_is_vipt_aliasing();
4079+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4080 struct vm_unmapped_area_info info;
4081
4082 /*
4083@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4084 if (len > TASK_SIZE)
4085 return -ENOMEM;
4086
4087+#ifdef CONFIG_PAX_RANDMMAP
4088+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4089+#endif
4090+
4091 if (addr) {
4092 if (do_align)
4093 addr = COLOUR_ALIGN(addr, pgoff);
4094@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4095 addr = PAGE_ALIGN(addr);
4096
4097 vma = find_vma(mm, addr);
4098- if (TASK_SIZE - len >= addr &&
4099- (!vma || addr + len <= vma->vm_start))
4100+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4101 return addr;
4102 }
4103
4104@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4105 info.high_limit = TASK_SIZE;
4106 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4107 info.align_offset = pgoff << PAGE_SHIFT;
4108+ info.threadstack_offset = offset;
4109 return vm_unmapped_area(&info);
4110 }
4111
4112@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4113 unsigned long addr = addr0;
4114 int do_align = 0;
4115 int aliasing = cache_is_vipt_aliasing();
4116+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4117 struct vm_unmapped_area_info info;
4118
4119 /*
4120@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4121 return addr;
4122 }
4123
4124+#ifdef CONFIG_PAX_RANDMMAP
4125+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4126+#endif
4127+
4128 /* requesting a specific address */
4129 if (addr) {
4130 if (do_align)
4131@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4132 else
4133 addr = PAGE_ALIGN(addr);
4134 vma = find_vma(mm, addr);
4135- if (TASK_SIZE - len >= addr &&
4136- (!vma || addr + len <= vma->vm_start))
4137+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4138 return addr;
4139 }
4140
4141@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4142 info.high_limit = mm->mmap_base;
4143 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4144 info.align_offset = pgoff << PAGE_SHIFT;
4145+ info.threadstack_offset = offset;
4146 addr = vm_unmapped_area(&info);
4147
4148 /*
4149@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4150 {
4151 unsigned long random_factor = 0UL;
4152
4153+#ifdef CONFIG_PAX_RANDMMAP
4154+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4155+#endif
4156+
4157 /* 8 bits of randomness in 20 address space bits */
4158 if ((current->flags & PF_RANDOMIZE) &&
4159 !(current->personality & ADDR_NO_RANDOMIZE))
4160@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4161
4162 if (mmap_is_legacy()) {
4163 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4164+
4165+#ifdef CONFIG_PAX_RANDMMAP
4166+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4167+ mm->mmap_base += mm->delta_mmap;
4168+#endif
4169+
4170 mm->get_unmapped_area = arch_get_unmapped_area;
4171 mm->unmap_area = arch_unmap_area;
4172 } else {
4173 mm->mmap_base = mmap_base(random_factor);
4174+
4175+#ifdef CONFIG_PAX_RANDMMAP
4176+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4177+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4178+#endif
4179+
4180 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4181 mm->unmap_area = arch_unmap_area_topdown;
4182 }
4183diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4184index daf336f..4e6392c 100644
4185--- a/arch/arm/mm/mmu.c
4186+++ b/arch/arm/mm/mmu.c
4187@@ -36,6 +36,22 @@
4188 #include "mm.h"
4189 #include "tcm.h"
4190
4191+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4192+void modify_domain(unsigned int dom, unsigned int type)
4193+{
4194+ struct thread_info *thread = current_thread_info();
4195+ unsigned int domain = thread->cpu_domain;
4196+ /*
4197+ * DOMAIN_MANAGER might be defined to some other value,
4198+ * use the arch-defined constant
4199+ */
4200+ domain &= ~domain_val(dom, 3);
4201+ thread->cpu_domain = domain | domain_val(dom, type);
4202+ set_domain(thread->cpu_domain);
4203+}
4204+EXPORT_SYMBOL(modify_domain);
4205+#endif
4206+
4207 /*
4208 * empty_zero_page is a special page that is used for
4209 * zero-initialized data and COW.
4210@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4211
4212 #endif /* ifdef CONFIG_CPU_CP15 / else */
4213
4214-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4215+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4216 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4217
4218-static struct mem_type mem_types[] = {
4219+#ifdef CONFIG_PAX_KERNEXEC
4220+#define L_PTE_KERNEXEC L_PTE_RDONLY
4221+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4222+#else
4223+#define L_PTE_KERNEXEC L_PTE_DIRTY
4224+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4225+#endif
4226+
4227+static struct mem_type mem_types[] __read_only = {
4228 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4229 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4230 L_PTE_SHARED,
4231@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4232 [MT_UNCACHED] = {
4233 .prot_pte = PROT_PTE_DEVICE,
4234 .prot_l1 = PMD_TYPE_TABLE,
4235- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4236+ .prot_sect = PROT_SECT_DEVICE,
4237 .domain = DOMAIN_IO,
4238 },
4239 [MT_CACHECLEAN] = {
4240- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4241+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4242 .domain = DOMAIN_KERNEL,
4243 },
4244 #ifndef CONFIG_ARM_LPAE
4245 [MT_MINICLEAN] = {
4246- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4247+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4248 .domain = DOMAIN_KERNEL,
4249 },
4250 #endif
4251@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4252 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4253 L_PTE_RDONLY,
4254 .prot_l1 = PMD_TYPE_TABLE,
4255- .domain = DOMAIN_USER,
4256+ .domain = DOMAIN_VECTORS,
4257 },
4258 [MT_HIGH_VECTORS] = {
4259 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4260 L_PTE_USER | L_PTE_RDONLY,
4261 .prot_l1 = PMD_TYPE_TABLE,
4262- .domain = DOMAIN_USER,
4263+ .domain = DOMAIN_VECTORS,
4264 },
4265- [MT_MEMORY] = {
4266+ [MT_MEMORY_RWX] = {
4267 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4268 .prot_l1 = PMD_TYPE_TABLE,
4269 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4270 .domain = DOMAIN_KERNEL,
4271 },
4272+ [MT_MEMORY_RW] = {
4273+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4274+ .prot_l1 = PMD_TYPE_TABLE,
4275+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4276+ .domain = DOMAIN_KERNEL,
4277+ },
4278+ [MT_MEMORY_RX] = {
4279+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4280+ .prot_l1 = PMD_TYPE_TABLE,
4281+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4282+ .domain = DOMAIN_KERNEL,
4283+ },
4284 [MT_ROM] = {
4285- .prot_sect = PMD_TYPE_SECT,
4286+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4287 .domain = DOMAIN_KERNEL,
4288 },
4289- [MT_MEMORY_NONCACHED] = {
4290+ [MT_MEMORY_NONCACHED_RW] = {
4291 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4292 L_PTE_MT_BUFFERABLE,
4293 .prot_l1 = PMD_TYPE_TABLE,
4294 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4295 .domain = DOMAIN_KERNEL,
4296 },
4297+ [MT_MEMORY_NONCACHED_RX] = {
4298+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4299+ L_PTE_MT_BUFFERABLE,
4300+ .prot_l1 = PMD_TYPE_TABLE,
4301+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4302+ .domain = DOMAIN_KERNEL,
4303+ },
4304 [MT_MEMORY_DTCM] = {
4305- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4306- L_PTE_XN,
4307+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4310+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4311 .domain = DOMAIN_KERNEL,
4312 },
4313 [MT_MEMORY_ITCM] = {
4314@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4315 },
4316 [MT_MEMORY_SO] = {
4317 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4318- L_PTE_MT_UNCACHED | L_PTE_XN,
4319+ L_PTE_MT_UNCACHED,
4320 .prot_l1 = PMD_TYPE_TABLE,
4321 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4322- PMD_SECT_UNCACHED | PMD_SECT_XN,
4323+ PMD_SECT_UNCACHED,
4324 .domain = DOMAIN_KERNEL,
4325 },
4326 [MT_MEMORY_DMA_READY] = {
4327@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4328 * to prevent speculative instruction fetches.
4329 */
4330 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4331+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4332 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4333+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4334 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4335+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4336 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4337+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4338+
4339+ /* Mark other regions on ARMv6+ as execute-never */
4340+
4341+#ifdef CONFIG_PAX_KERNEXEC
4342+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4343+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4344+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4345+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4346+#ifndef CONFIG_ARM_LPAE
4347+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4348+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4349+#endif
4350+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4351+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4352+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4353+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4354+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4355+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4356+#endif
4357+
4358+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4359+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4360 }
4361 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4362 /*
4363@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4364 * from SVC mode and no access from userspace.
4365 */
4366 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4367+#ifdef CONFIG_PAX_KERNEXEC
4368+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4369+#endif
4370 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4371 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4372 #endif
4373@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4374 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4375 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4376 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4377- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4378- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4379+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4380+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4381+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4382+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4383+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4384+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4385 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4386- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4387- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4388+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4389+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4390+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4391+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4392 }
4393 }
4394
4395@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4396 if (cpu_arch >= CPU_ARCH_ARMv6) {
4397 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4398 /* Non-cacheable Normal is XCB = 001 */
4399- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4400+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4401+ PMD_SECT_BUFFERED;
4402+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4403 PMD_SECT_BUFFERED;
4404 } else {
4405 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4406- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4407+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4408+ PMD_SECT_TEX(1);
4409+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4410 PMD_SECT_TEX(1);
4411 }
4412 } else {
4413- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4414+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4415+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4416 }
4417
4418 #ifdef CONFIG_ARM_LPAE
4419@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4420 vecs_pgprot |= PTE_EXT_AF;
4421 #endif
4422
4423+ user_pgprot |= __supported_pte_mask;
4424+
4425 for (i = 0; i < 16; i++) {
4426 pteval_t v = pgprot_val(protection_map[i]);
4427 protection_map[i] = __pgprot(v | user_pgprot);
4428@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4429
4430 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4431 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4432- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4433- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4434+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4435+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4436+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4437+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4438+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4439+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4440 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4441- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4442+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4443+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4444 mem_types[MT_ROM].prot_sect |= cp->pmd;
4445
4446 switch (cp->pmd) {
4447@@ -1166,18 +1255,15 @@ void __init arm_mm_memblock_reserve(void)
4448 * called function. This means you can't use any function or debugging
4449 * method which may touch any device, otherwise the kernel _will_ crash.
4450 */
4451+
4452+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4453+
4454 static void __init devicemaps_init(struct machine_desc *mdesc)
4455 {
4456 struct map_desc map;
4457 unsigned long addr;
4458- void *vectors;
4459
4460- /*
4461- * Allocate the vector page early.
4462- */
4463- vectors = early_alloc(PAGE_SIZE * 2);
4464-
4465- early_trap_init(vectors);
4466+ early_trap_init(&vectors);
4467
4468 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4469 pmd_clear(pmd_off_k(addr));
4470@@ -1217,7 +1303,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4471 * location (0xffff0000). If we aren't using high-vectors, also
4472 * create a mapping at the low-vectors virtual address.
4473 */
4474- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4475+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4476 map.virtual = 0xffff0000;
4477 map.length = PAGE_SIZE;
4478 #ifdef CONFIG_KUSER_HELPERS
4479@@ -1287,8 +1373,39 @@ static void __init map_lowmem(void)
4480 map.pfn = __phys_to_pfn(start);
4481 map.virtual = __phys_to_virt(start);
4482 map.length = end - start;
4483- map.type = MT_MEMORY;
4484
4485+#ifdef CONFIG_PAX_KERNEXEC
4486+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4487+ struct map_desc kernel;
4488+ struct map_desc initmap;
4489+
4490+ /* when freeing initmem we will make this RW */
4491+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4492+ initmap.virtual = (unsigned long)__init_begin;
4493+ initmap.length = _sdata - __init_begin;
4494+ initmap.type = MT_MEMORY_RWX;
4495+ create_mapping(&initmap);
4496+
4497+ /* when freeing initmem we will make this RX */
4498+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4499+ kernel.virtual = (unsigned long)_stext;
4500+ kernel.length = __init_begin - _stext;
4501+ kernel.type = MT_MEMORY_RWX;
4502+ create_mapping(&kernel);
4503+
4504+ if (map.virtual < (unsigned long)_stext) {
4505+ map.length = (unsigned long)_stext - map.virtual;
4506+ map.type = MT_MEMORY_RWX;
4507+ create_mapping(&map);
4508+ }
4509+
4510+ map.pfn = __phys_to_pfn(__pa(_sdata));
4511+ map.virtual = (unsigned long)_sdata;
4512+ map.length = end - __pa(_sdata);
4513+ }
4514+#endif
4515+
4516+ map.type = MT_MEMORY_RW;
4517 create_mapping(&map);
4518 }
4519 }
4520diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4521index a5bc92d..0bb4730 100644
4522--- a/arch/arm/plat-omap/sram.c
4523+++ b/arch/arm/plat-omap/sram.c
4524@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4525 * Looks like we need to preserve some bootloader code at the
4526 * beginning of SRAM for jumping to flash for reboot to work...
4527 */
4528+ pax_open_kernel();
4529 memset_io(omap_sram_base + omap_sram_skip, 0,
4530 omap_sram_size - omap_sram_skip);
4531+ pax_close_kernel();
4532 }
4533diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4534index ce6d763..cfea917 100644
4535--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4536+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4537@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4538 int (*started)(unsigned ch);
4539 int (*flush)(unsigned ch);
4540 int (*stop)(unsigned ch);
4541-};
4542+} __no_const;
4543
4544 extern void *samsung_dmadev_get_ops(void);
4545 extern void *s3c_dma_get_ops(void);
4546diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h
4547index 654f096..5546653 100644
4548--- a/arch/arm64/include/asm/tlb.h
4549+++ b/arch/arm64/include/asm/tlb.h
4550@@ -35,6 +35,7 @@ struct mmu_gather {
4551 struct mm_struct *mm;
4552 unsigned int fullmm;
4553 struct vm_area_struct *vma;
4554+ unsigned long start, end;
4555 unsigned long range_start;
4556 unsigned long range_end;
4557 unsigned int nr;
4558@@ -97,10 +98,12 @@ static inline void tlb_flush_mmu(struct mmu_gather *tlb)
4559 }
4560
4561 static inline void
4562-tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int fullmm)
4563+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
4564 {
4565 tlb->mm = mm;
4566- tlb->fullmm = fullmm;
4567+ tlb->fullmm = !(start | (end+1));
4568+ tlb->start = start;
4569+ tlb->end = end;
4570 tlb->vma = NULL;
4571 tlb->max = ARRAY_SIZE(tlb->local);
4572 tlb->pages = tlb->local;
4573diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4574index f4726dc..39ed646 100644
4575--- a/arch/arm64/kernel/debug-monitors.c
4576+++ b/arch/arm64/kernel/debug-monitors.c
4577@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4578 return NOTIFY_OK;
4579 }
4580
4581-static struct notifier_block __cpuinitdata os_lock_nb = {
4582+static struct notifier_block os_lock_nb = {
4583 .notifier_call = os_lock_notify,
4584 };
4585
4586diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4587index 5ab825c..96aaec8 100644
4588--- a/arch/arm64/kernel/hw_breakpoint.c
4589+++ b/arch/arm64/kernel/hw_breakpoint.c
4590@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4591 return NOTIFY_OK;
4592 }
4593
4594-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4595+static struct notifier_block hw_breakpoint_reset_nb = {
4596 .notifier_call = hw_breakpoint_reset_notify,
4597 };
4598
4599diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4600index c3a58a1..78fbf54 100644
4601--- a/arch/avr32/include/asm/cache.h
4602+++ b/arch/avr32/include/asm/cache.h
4603@@ -1,8 +1,10 @@
4604 #ifndef __ASM_AVR32_CACHE_H
4605 #define __ASM_AVR32_CACHE_H
4606
4607+#include <linux/const.h>
4608+
4609 #define L1_CACHE_SHIFT 5
4610-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4611+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4612
4613 /*
4614 * Memory returned by kmalloc() may be used for DMA, so we must make
4615diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4616index d232888..87c8df1 100644
4617--- a/arch/avr32/include/asm/elf.h
4618+++ b/arch/avr32/include/asm/elf.h
4619@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4620 the loader. We need to make sure that it is out of the way of the program
4621 that it will "exec", and that there is sufficient room for the brk. */
4622
4623-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4624+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4625
4626+#ifdef CONFIG_PAX_ASLR
4627+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4628+
4629+#define PAX_DELTA_MMAP_LEN 15
4630+#define PAX_DELTA_STACK_LEN 15
4631+#endif
4632
4633 /* This yields a mask that user programs can use to figure out what
4634 instruction set this CPU supports. This could be done in user space,
4635diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4636index 479330b..53717a8 100644
4637--- a/arch/avr32/include/asm/kmap_types.h
4638+++ b/arch/avr32/include/asm/kmap_types.h
4639@@ -2,9 +2,9 @@
4640 #define __ASM_AVR32_KMAP_TYPES_H
4641
4642 #ifdef CONFIG_DEBUG_HIGHMEM
4643-# define KM_TYPE_NR 29
4644+# define KM_TYPE_NR 30
4645 #else
4646-# define KM_TYPE_NR 14
4647+# define KM_TYPE_NR 15
4648 #endif
4649
4650 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4651diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4652index b2f2d2d..d1c85cb 100644
4653--- a/arch/avr32/mm/fault.c
4654+++ b/arch/avr32/mm/fault.c
4655@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4656
4657 int exception_trace = 1;
4658
4659+#ifdef CONFIG_PAX_PAGEEXEC
4660+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4661+{
4662+ unsigned long i;
4663+
4664+ printk(KERN_ERR "PAX: bytes at PC: ");
4665+ for (i = 0; i < 20; i++) {
4666+ unsigned char c;
4667+ if (get_user(c, (unsigned char *)pc+i))
4668+ printk(KERN_CONT "???????? ");
4669+ else
4670+ printk(KERN_CONT "%02x ", c);
4671+ }
4672+ printk("\n");
4673+}
4674+#endif
4675+
4676 /*
4677 * This routine handles page faults. It determines the address and the
4678 * problem, and then passes it off to one of the appropriate routines.
4679@@ -174,6 +191,16 @@ bad_area:
4680 up_read(&mm->mmap_sem);
4681
4682 if (user_mode(regs)) {
4683+
4684+#ifdef CONFIG_PAX_PAGEEXEC
4685+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4686+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4687+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4688+ do_group_exit(SIGKILL);
4689+ }
4690+ }
4691+#endif
4692+
4693 if (exception_trace && printk_ratelimit())
4694 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4695 "sp %08lx ecr %lu\n",
4696diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4697index 568885a..f8008df 100644
4698--- a/arch/blackfin/include/asm/cache.h
4699+++ b/arch/blackfin/include/asm/cache.h
4700@@ -7,6 +7,7 @@
4701 #ifndef __ARCH_BLACKFIN_CACHE_H
4702 #define __ARCH_BLACKFIN_CACHE_H
4703
4704+#include <linux/const.h>
4705 #include <linux/linkage.h> /* for asmlinkage */
4706
4707 /*
4708@@ -14,7 +15,7 @@
4709 * Blackfin loads 32 bytes for cache
4710 */
4711 #define L1_CACHE_SHIFT 5
4712-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4713+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4715
4716 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4717diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4718index aea2718..3639a60 100644
4719--- a/arch/cris/include/arch-v10/arch/cache.h
4720+++ b/arch/cris/include/arch-v10/arch/cache.h
4721@@ -1,8 +1,9 @@
4722 #ifndef _ASM_ARCH_CACHE_H
4723 #define _ASM_ARCH_CACHE_H
4724
4725+#include <linux/const.h>
4726 /* Etrax 100LX have 32-byte cache-lines. */
4727-#define L1_CACHE_BYTES 32
4728 #define L1_CACHE_SHIFT 5
4729+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4730
4731 #endif /* _ASM_ARCH_CACHE_H */
4732diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4733index 7caf25d..ee65ac5 100644
4734--- a/arch/cris/include/arch-v32/arch/cache.h
4735+++ b/arch/cris/include/arch-v32/arch/cache.h
4736@@ -1,11 +1,12 @@
4737 #ifndef _ASM_CRIS_ARCH_CACHE_H
4738 #define _ASM_CRIS_ARCH_CACHE_H
4739
4740+#include <linux/const.h>
4741 #include <arch/hwregs/dma.h>
4742
4743 /* A cache-line is 32 bytes. */
4744-#define L1_CACHE_BYTES 32
4745 #define L1_CACHE_SHIFT 5
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4749
4750diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4751index b86329d..6709906 100644
4752--- a/arch/frv/include/asm/atomic.h
4753+++ b/arch/frv/include/asm/atomic.h
4754@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4755 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4756 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4757
4758+#define atomic64_read_unchecked(v) atomic64_read(v)
4759+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4760+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4761+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4762+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4763+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4764+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4765+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4766+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4767+
4768 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4769 {
4770 int c, old;
4771diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4772index 2797163..c2a401d 100644
4773--- a/arch/frv/include/asm/cache.h
4774+++ b/arch/frv/include/asm/cache.h
4775@@ -12,10 +12,11 @@
4776 #ifndef __ASM_CACHE_H
4777 #define __ASM_CACHE_H
4778
4779+#include <linux/const.h>
4780
4781 /* bytes per L1 cache line */
4782 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4783-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4784+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4785
4786 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4787 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4788diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4789index 43901f2..0d8b865 100644
4790--- a/arch/frv/include/asm/kmap_types.h
4791+++ b/arch/frv/include/asm/kmap_types.h
4792@@ -2,6 +2,6 @@
4793 #ifndef _ASM_KMAP_TYPES_H
4794 #define _ASM_KMAP_TYPES_H
4795
4796-#define KM_TYPE_NR 17
4797+#define KM_TYPE_NR 18
4798
4799 #endif
4800diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4801index 836f147..4cf23f5 100644
4802--- a/arch/frv/mm/elf-fdpic.c
4803+++ b/arch/frv/mm/elf-fdpic.c
4804@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4805 {
4806 struct vm_area_struct *vma;
4807 struct vm_unmapped_area_info info;
4808+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4809
4810 if (len > TASK_SIZE)
4811 return -ENOMEM;
4812@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4813 if (addr) {
4814 addr = PAGE_ALIGN(addr);
4815 vma = find_vma(current->mm, addr);
4816- if (TASK_SIZE - len >= addr &&
4817- (!vma || addr + len <= vma->vm_start))
4818+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4819 goto success;
4820 }
4821
4822@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4823 info.high_limit = (current->mm->start_stack - 0x00200000);
4824 info.align_mask = 0;
4825 info.align_offset = 0;
4826+ info.threadstack_offset = offset;
4827 addr = vm_unmapped_area(&info);
4828 if (!(addr & ~PAGE_MASK))
4829 goto success;
4830diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4831index f4ca594..adc72fd6 100644
4832--- a/arch/hexagon/include/asm/cache.h
4833+++ b/arch/hexagon/include/asm/cache.h
4834@@ -21,9 +21,11 @@
4835 #ifndef __ASM_CACHE_H
4836 #define __ASM_CACHE_H
4837
4838+#include <linux/const.h>
4839+
4840 /* Bytes per L1 cache line */
4841-#define L1_CACHE_SHIFT (5)
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_SHIFT 5
4844+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4845
4846 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4847 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4848diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4849index 6e6fe18..a6ae668 100644
4850--- a/arch/ia64/include/asm/atomic.h
4851+++ b/arch/ia64/include/asm/atomic.h
4852@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4853 #define atomic64_inc(v) atomic64_add(1, (v))
4854 #define atomic64_dec(v) atomic64_sub(1, (v))
4855
4856+#define atomic64_read_unchecked(v) atomic64_read(v)
4857+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4858+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4859+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4860+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4861+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4862+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4863+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4864+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4865+
4866 /* Atomic operations are already serializing */
4867 #define smp_mb__before_atomic_dec() barrier()
4868 #define smp_mb__after_atomic_dec() barrier()
4869diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4870index 988254a..e1ee885 100644
4871--- a/arch/ia64/include/asm/cache.h
4872+++ b/arch/ia64/include/asm/cache.h
4873@@ -1,6 +1,7 @@
4874 #ifndef _ASM_IA64_CACHE_H
4875 #define _ASM_IA64_CACHE_H
4876
4877+#include <linux/const.h>
4878
4879 /*
4880 * Copyright (C) 1998-2000 Hewlett-Packard Co
4881@@ -9,7 +10,7 @@
4882
4883 /* Bytes per L1 (data) cache line. */
4884 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4885-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4886+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4887
4888 #ifdef CONFIG_SMP
4889 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4890diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4891index 5a83c5c..4d7f553 100644
4892--- a/arch/ia64/include/asm/elf.h
4893+++ b/arch/ia64/include/asm/elf.h
4894@@ -42,6 +42,13 @@
4895 */
4896 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4897
4898+#ifdef CONFIG_PAX_ASLR
4899+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4900+
4901+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4902+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4903+#endif
4904+
4905 #define PT_IA_64_UNWIND 0x70000001
4906
4907 /* IA-64 relocations: */
4908diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4909index 96a8d92..617a1cf 100644
4910--- a/arch/ia64/include/asm/pgalloc.h
4911+++ b/arch/ia64/include/asm/pgalloc.h
4912@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4913 pgd_val(*pgd_entry) = __pa(pud);
4914 }
4915
4916+static inline void
4917+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4918+{
4919+ pgd_populate(mm, pgd_entry, pud);
4920+}
4921+
4922 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4923 {
4924 return quicklist_alloc(0, GFP_KERNEL, NULL);
4925@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4926 pud_val(*pud_entry) = __pa(pmd);
4927 }
4928
4929+static inline void
4930+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4931+{
4932+ pud_populate(mm, pud_entry, pmd);
4933+}
4934+
4935 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4936 {
4937 return quicklist_alloc(0, GFP_KERNEL, NULL);
4938diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4939index 815810c..d60bd4c 100644
4940--- a/arch/ia64/include/asm/pgtable.h
4941+++ b/arch/ia64/include/asm/pgtable.h
4942@@ -12,7 +12,7 @@
4943 * David Mosberger-Tang <davidm@hpl.hp.com>
4944 */
4945
4946-
4947+#include <linux/const.h>
4948 #include <asm/mman.h>
4949 #include <asm/page.h>
4950 #include <asm/processor.h>
4951@@ -142,6 +142,17 @@
4952 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4953 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4954 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4955+
4956+#ifdef CONFIG_PAX_PAGEEXEC
4957+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4958+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4959+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4960+#else
4961+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4962+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4963+# define PAGE_COPY_NOEXEC PAGE_COPY
4964+#endif
4965+
4966 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4967 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4968 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4969diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4970index 54ff557..70c88b7 100644
4971--- a/arch/ia64/include/asm/spinlock.h
4972+++ b/arch/ia64/include/asm/spinlock.h
4973@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4974 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4975
4976 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4977- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4978+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4979 }
4980
4981 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4982diff --git a/arch/ia64/include/asm/tlb.h b/arch/ia64/include/asm/tlb.h
4983index ef3a9de..bc5efc7 100644
4984--- a/arch/ia64/include/asm/tlb.h
4985+++ b/arch/ia64/include/asm/tlb.h
4986@@ -22,7 +22,7 @@
4987 * unmapping a portion of the virtual address space, these hooks are called according to
4988 * the following template:
4989 *
4990- * tlb <- tlb_gather_mmu(mm, full_mm_flush); // start unmap for address space MM
4991+ * tlb <- tlb_gather_mmu(mm, start, end); // start unmap for address space MM
4992 * {
4993 * for each vma that needs a shootdown do {
4994 * tlb_start_vma(tlb, vma);
4995@@ -58,6 +58,7 @@ struct mmu_gather {
4996 unsigned int max;
4997 unsigned char fullmm; /* non-zero means full mm flush */
4998 unsigned char need_flush; /* really unmapped some PTEs? */
4999+ unsigned long start, end;
5000 unsigned long start_addr;
5001 unsigned long end_addr;
5002 struct page **pages;
5003@@ -155,13 +156,15 @@ static inline void __tlb_alloc_page(struct mmu_gather *tlb)
5004
5005
5006 static inline void
5007-tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int full_mm_flush)
5008+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
5009 {
5010 tlb->mm = mm;
5011 tlb->max = ARRAY_SIZE(tlb->local);
5012 tlb->pages = tlb->local;
5013 tlb->nr = 0;
5014- tlb->fullmm = full_mm_flush;
5015+ tlb->fullmm = !(start | (end+1));
5016+ tlb->start = start;
5017+ tlb->end = end;
5018 tlb->start_addr = ~0UL;
5019 }
5020
5021diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5022index 449c8c0..18965fb 100644
5023--- a/arch/ia64/include/asm/uaccess.h
5024+++ b/arch/ia64/include/asm/uaccess.h
5025@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5026 static inline unsigned long
5027 __copy_to_user (void __user *to, const void *from, unsigned long count)
5028 {
5029+ if (count > INT_MAX)
5030+ return count;
5031+
5032+ if (!__builtin_constant_p(count))
5033+ check_object_size(from, count, true);
5034+
5035 return __copy_user(to, (__force void __user *) from, count);
5036 }
5037
5038 static inline unsigned long
5039 __copy_from_user (void *to, const void __user *from, unsigned long count)
5040 {
5041+ if (count > INT_MAX)
5042+ return count;
5043+
5044+ if (!__builtin_constant_p(count))
5045+ check_object_size(to, count, false);
5046+
5047 return __copy_user((__force void __user *) to, from, count);
5048 }
5049
5050@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5051 ({ \
5052 void __user *__cu_to = (to); \
5053 const void *__cu_from = (from); \
5054- long __cu_len = (n); \
5055+ unsigned long __cu_len = (n); \
5056 \
5057- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5058+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5059+ if (!__builtin_constant_p(n)) \
5060+ check_object_size(__cu_from, __cu_len, true); \
5061 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5062+ } \
5063 __cu_len; \
5064 })
5065
5066@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5067 ({ \
5068 void *__cu_to = (to); \
5069 const void __user *__cu_from = (from); \
5070- long __cu_len = (n); \
5071+ unsigned long __cu_len = (n); \
5072 \
5073 __chk_user_ptr(__cu_from); \
5074- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5075+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5076+ if (!__builtin_constant_p(n)) \
5077+ check_object_size(__cu_to, __cu_len, false); \
5078 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5079+ } \
5080 __cu_len; \
5081 })
5082
5083diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
5084index 2d67317..07d8bfa 100644
5085--- a/arch/ia64/kernel/err_inject.c
5086+++ b/arch/ia64/kernel/err_inject.c
5087@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
5088 return NOTIFY_OK;
5089 }
5090
5091-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
5092+static struct notifier_block err_inject_cpu_notifier =
5093 {
5094 .notifier_call = err_inject_cpu_callback,
5095 };
5096diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
5097index d7396db..b33e873 100644
5098--- a/arch/ia64/kernel/mca.c
5099+++ b/arch/ia64/kernel/mca.c
5100@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
5101 return NOTIFY_OK;
5102 }
5103
5104-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
5105+static struct notifier_block mca_cpu_notifier = {
5106 .notifier_call = mca_cpu_callback
5107 };
5108
5109diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5110index 24603be..948052d 100644
5111--- a/arch/ia64/kernel/module.c
5112+++ b/arch/ia64/kernel/module.c
5113@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5114 void
5115 module_free (struct module *mod, void *module_region)
5116 {
5117- if (mod && mod->arch.init_unw_table &&
5118- module_region == mod->module_init) {
5119+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5120 unw_remove_unwind_table(mod->arch.init_unw_table);
5121 mod->arch.init_unw_table = NULL;
5122 }
5123@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5124 }
5125
5126 static inline int
5127+in_init_rx (const struct module *mod, uint64_t addr)
5128+{
5129+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5130+}
5131+
5132+static inline int
5133+in_init_rw (const struct module *mod, uint64_t addr)
5134+{
5135+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5136+}
5137+
5138+static inline int
5139 in_init (const struct module *mod, uint64_t addr)
5140 {
5141- return addr - (uint64_t) mod->module_init < mod->init_size;
5142+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5143+}
5144+
5145+static inline int
5146+in_core_rx (const struct module *mod, uint64_t addr)
5147+{
5148+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5149+}
5150+
5151+static inline int
5152+in_core_rw (const struct module *mod, uint64_t addr)
5153+{
5154+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5155 }
5156
5157 static inline int
5158 in_core (const struct module *mod, uint64_t addr)
5159 {
5160- return addr - (uint64_t) mod->module_core < mod->core_size;
5161+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5162 }
5163
5164 static inline int
5165@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5166 break;
5167
5168 case RV_BDREL:
5169- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5170+ if (in_init_rx(mod, val))
5171+ val -= (uint64_t) mod->module_init_rx;
5172+ else if (in_init_rw(mod, val))
5173+ val -= (uint64_t) mod->module_init_rw;
5174+ else if (in_core_rx(mod, val))
5175+ val -= (uint64_t) mod->module_core_rx;
5176+ else if (in_core_rw(mod, val))
5177+ val -= (uint64_t) mod->module_core_rw;
5178 break;
5179
5180 case RV_LTV:
5181@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5182 * addresses have been selected...
5183 */
5184 uint64_t gp;
5185- if (mod->core_size > MAX_LTOFF)
5186+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5187 /*
5188 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5189 * at the end of the module.
5190 */
5191- gp = mod->core_size - MAX_LTOFF / 2;
5192+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5193 else
5194- gp = mod->core_size / 2;
5195- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5196+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5197+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5198 mod->arch.gp = gp;
5199 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5200 }
5201diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5202index 2b3c2d7..a318d84 100644
5203--- a/arch/ia64/kernel/palinfo.c
5204+++ b/arch/ia64/kernel/palinfo.c
5205@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
5206 return NOTIFY_OK;
5207 }
5208
5209-static struct notifier_block __refdata palinfo_cpu_notifier =
5210+static struct notifier_block palinfo_cpu_notifier =
5211 {
5212 .notifier_call = palinfo_cpu_callback,
5213 .priority = 0,
5214diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
5215index 4bc580a..7767f24 100644
5216--- a/arch/ia64/kernel/salinfo.c
5217+++ b/arch/ia64/kernel/salinfo.c
5218@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
5219 return NOTIFY_OK;
5220 }
5221
5222-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5223+static struct notifier_block salinfo_cpu_notifier =
5224 {
5225 .notifier_call = salinfo_cpu_callback,
5226 .priority = 0,
5227diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5228index 41e33f8..65180b2 100644
5229--- a/arch/ia64/kernel/sys_ia64.c
5230+++ b/arch/ia64/kernel/sys_ia64.c
5231@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5232 unsigned long align_mask = 0;
5233 struct mm_struct *mm = current->mm;
5234 struct vm_unmapped_area_info info;
5235+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5236
5237 if (len > RGN_MAP_LIMIT)
5238 return -ENOMEM;
5239@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5240 if (REGION_NUMBER(addr) == RGN_HPAGE)
5241 addr = 0;
5242 #endif
5243+
5244+#ifdef CONFIG_PAX_RANDMMAP
5245+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5246+ addr = mm->free_area_cache;
5247+ else
5248+#endif
5249+
5250 if (!addr)
5251 addr = TASK_UNMAPPED_BASE;
5252
5253@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5254 info.high_limit = TASK_SIZE;
5255 info.align_mask = align_mask;
5256 info.align_offset = 0;
5257+ info.threadstack_offset = offset;
5258 return vm_unmapped_area(&info);
5259 }
5260
5261diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5262index dc00b2c..cce53c2 100644
5263--- a/arch/ia64/kernel/topology.c
5264+++ b/arch/ia64/kernel/topology.c
5265@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5266 return NOTIFY_OK;
5267 }
5268
5269-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5270+static struct notifier_block cache_cpu_notifier =
5271 {
5272 .notifier_call = cache_cpu_callback
5273 };
5274diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5275index 0ccb28f..8992469 100644
5276--- a/arch/ia64/kernel/vmlinux.lds.S
5277+++ b/arch/ia64/kernel/vmlinux.lds.S
5278@@ -198,7 +198,7 @@ SECTIONS {
5279 /* Per-cpu data: */
5280 . = ALIGN(PERCPU_PAGE_SIZE);
5281 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5282- __phys_per_cpu_start = __per_cpu_load;
5283+ __phys_per_cpu_start = per_cpu_load;
5284 /*
5285 * ensure percpu data fits
5286 * into percpu page size
5287diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5288index 6cf0341..d352594 100644
5289--- a/arch/ia64/mm/fault.c
5290+++ b/arch/ia64/mm/fault.c
5291@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5292 return pte_present(pte);
5293 }
5294
5295+#ifdef CONFIG_PAX_PAGEEXEC
5296+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5297+{
5298+ unsigned long i;
5299+
5300+ printk(KERN_ERR "PAX: bytes at PC: ");
5301+ for (i = 0; i < 8; i++) {
5302+ unsigned int c;
5303+ if (get_user(c, (unsigned int *)pc+i))
5304+ printk(KERN_CONT "???????? ");
5305+ else
5306+ printk(KERN_CONT "%08x ", c);
5307+ }
5308+ printk("\n");
5309+}
5310+#endif
5311+
5312 # define VM_READ_BIT 0
5313 # define VM_WRITE_BIT 1
5314 # define VM_EXEC_BIT 2
5315@@ -149,8 +166,21 @@ retry:
5316 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5317 goto bad_area;
5318
5319- if ((vma->vm_flags & mask) != mask)
5320+ if ((vma->vm_flags & mask) != mask) {
5321+
5322+#ifdef CONFIG_PAX_PAGEEXEC
5323+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5324+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5325+ goto bad_area;
5326+
5327+ up_read(&mm->mmap_sem);
5328+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5329+ do_group_exit(SIGKILL);
5330+ }
5331+#endif
5332+
5333 goto bad_area;
5334+ }
5335
5336 /*
5337 * If for any reason at all we couldn't handle the fault, make
5338diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5339index 76069c1..c2aa816 100644
5340--- a/arch/ia64/mm/hugetlbpage.c
5341+++ b/arch/ia64/mm/hugetlbpage.c
5342@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5343 unsigned long pgoff, unsigned long flags)
5344 {
5345 struct vm_unmapped_area_info info;
5346+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5347
5348 if (len > RGN_MAP_LIMIT)
5349 return -ENOMEM;
5350@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5351 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5352 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5353 info.align_offset = 0;
5354+ info.threadstack_offset = offset;
5355 return vm_unmapped_area(&info);
5356 }
5357
5358diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5359index d1fe4b4..2628f37 100644
5360--- a/arch/ia64/mm/init.c
5361+++ b/arch/ia64/mm/init.c
5362@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5363 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5364 vma->vm_end = vma->vm_start + PAGE_SIZE;
5365 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5366+
5367+#ifdef CONFIG_PAX_PAGEEXEC
5368+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5369+ vma->vm_flags &= ~VM_EXEC;
5370+
5371+#ifdef CONFIG_PAX_MPROTECT
5372+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5373+ vma->vm_flags &= ~VM_MAYEXEC;
5374+#endif
5375+
5376+ }
5377+#endif
5378+
5379 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5380 down_write(&current->mm->mmap_sem);
5381 if (insert_vm_struct(current->mm, vma)) {
5382diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5383index 40b3ee9..8c2c112 100644
5384--- a/arch/m32r/include/asm/cache.h
5385+++ b/arch/m32r/include/asm/cache.h
5386@@ -1,8 +1,10 @@
5387 #ifndef _ASM_M32R_CACHE_H
5388 #define _ASM_M32R_CACHE_H
5389
5390+#include <linux/const.h>
5391+
5392 /* L1 cache line size */
5393 #define L1_CACHE_SHIFT 4
5394-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5395+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5396
5397 #endif /* _ASM_M32R_CACHE_H */
5398diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5399index 82abd15..d95ae5d 100644
5400--- a/arch/m32r/lib/usercopy.c
5401+++ b/arch/m32r/lib/usercopy.c
5402@@ -14,6 +14,9 @@
5403 unsigned long
5404 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5405 {
5406+ if ((long)n < 0)
5407+ return n;
5408+
5409 prefetch(from);
5410 if (access_ok(VERIFY_WRITE, to, n))
5411 __copy_user(to,from,n);
5412@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5413 unsigned long
5414 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5415 {
5416+ if ((long)n < 0)
5417+ return n;
5418+
5419 prefetchw(to);
5420 if (access_ok(VERIFY_READ, from, n))
5421 __copy_user_zeroing(to,from,n);
5422diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5423index 0395c51..5f26031 100644
5424--- a/arch/m68k/include/asm/cache.h
5425+++ b/arch/m68k/include/asm/cache.h
5426@@ -4,9 +4,11 @@
5427 #ifndef __ARCH_M68K_CACHE_H
5428 #define __ARCH_M68K_CACHE_H
5429
5430+#include <linux/const.h>
5431+
5432 /* bytes per L1 cache line */
5433 #define L1_CACHE_SHIFT 4
5434-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5435+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5436
5437 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5438
5439diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5440index 3c52fa6..11b2ad8 100644
5441--- a/arch/metag/mm/hugetlbpage.c
5442+++ b/arch/metag/mm/hugetlbpage.c
5443@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5444 info.high_limit = TASK_SIZE;
5445 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5446 info.align_offset = 0;
5447+ info.threadstack_offset = 0;
5448 return vm_unmapped_area(&info);
5449 }
5450
5451diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5452index 4efe96a..60e8699 100644
5453--- a/arch/microblaze/include/asm/cache.h
5454+++ b/arch/microblaze/include/asm/cache.h
5455@@ -13,11 +13,12 @@
5456 #ifndef _ASM_MICROBLAZE_CACHE_H
5457 #define _ASM_MICROBLAZE_CACHE_H
5458
5459+#include <linux/const.h>
5460 #include <asm/registers.h>
5461
5462 #define L1_CACHE_SHIFT 5
5463 /* word-granular cache in microblaze */
5464-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5465+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5466
5467 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5468
5469diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5470index 08b6079..eb272cf 100644
5471--- a/arch/mips/include/asm/atomic.h
5472+++ b/arch/mips/include/asm/atomic.h
5473@@ -21,6 +21,10 @@
5474 #include <asm/cmpxchg.h>
5475 #include <asm/war.h>
5476
5477+#ifdef CONFIG_GENERIC_ATOMIC64
5478+#include <asm-generic/atomic64.h>
5479+#endif
5480+
5481 #define ATOMIC_INIT(i) { (i) }
5482
5483 /*
5484@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5485 */
5486 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5487
5488+#define atomic64_read_unchecked(v) atomic64_read(v)
5489+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5490+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5491+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5492+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5493+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5494+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5495+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5496+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5497+
5498 #endif /* CONFIG_64BIT */
5499
5500 /*
5501diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5502index b4db69f..8f3b093 100644
5503--- a/arch/mips/include/asm/cache.h
5504+++ b/arch/mips/include/asm/cache.h
5505@@ -9,10 +9,11 @@
5506 #ifndef _ASM_CACHE_H
5507 #define _ASM_CACHE_H
5508
5509+#include <linux/const.h>
5510 #include <kmalloc.h>
5511
5512 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5513-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5514+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5515
5516 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5517 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5518diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5519index cf3ae24..238d22f 100644
5520--- a/arch/mips/include/asm/elf.h
5521+++ b/arch/mips/include/asm/elf.h
5522@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5523 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5524 #endif
5525
5526+#ifdef CONFIG_PAX_ASLR
5527+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5528+
5529+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5530+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5531+#endif
5532+
5533 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5534 struct linux_binprm;
5535 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5536 int uses_interp);
5537
5538-struct mm_struct;
5539-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5540-#define arch_randomize_brk arch_randomize_brk
5541-
5542 #endif /* _ASM_ELF_H */
5543diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5544index c1f6afa..38cc6e9 100644
5545--- a/arch/mips/include/asm/exec.h
5546+++ b/arch/mips/include/asm/exec.h
5547@@ -12,6 +12,6 @@
5548 #ifndef _ASM_EXEC_H
5549 #define _ASM_EXEC_H
5550
5551-extern unsigned long arch_align_stack(unsigned long sp);
5552+#define arch_align_stack(x) ((x) & ~0xfUL)
5553
5554 #endif /* _ASM_EXEC_H */
5555diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
5556index d44622c..64990d2 100644
5557--- a/arch/mips/include/asm/local.h
5558+++ b/arch/mips/include/asm/local.h
5559@@ -12,15 +12,25 @@ typedef struct
5560 atomic_long_t a;
5561 } local_t;
5562
5563+typedef struct {
5564+ atomic_long_unchecked_t a;
5565+} local_unchecked_t;
5566+
5567 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
5568
5569 #define local_read(l) atomic_long_read(&(l)->a)
5570+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
5571 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
5572+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
5573
5574 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
5575+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
5576 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
5577+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
5578 #define local_inc(l) atomic_long_inc(&(l)->a)
5579+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
5580 #define local_dec(l) atomic_long_dec(&(l)->a)
5581+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
5582
5583 /*
5584 * Same as above, but return the result value
5585@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
5586 return result;
5587 }
5588
5589+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
5590+{
5591+ unsigned long result;
5592+
5593+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5594+ unsigned long temp;
5595+
5596+ __asm__ __volatile__(
5597+ " .set mips3 \n"
5598+ "1:" __LL "%1, %2 # local_add_return \n"
5599+ " addu %0, %1, %3 \n"
5600+ __SC "%0, %2 \n"
5601+ " beqzl %0, 1b \n"
5602+ " addu %0, %1, %3 \n"
5603+ " .set mips0 \n"
5604+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
5605+ : "Ir" (i), "m" (l->a.counter)
5606+ : "memory");
5607+ } else if (kernel_uses_llsc) {
5608+ unsigned long temp;
5609+
5610+ __asm__ __volatile__(
5611+ " .set mips3 \n"
5612+ "1:" __LL "%1, %2 # local_add_return \n"
5613+ " addu %0, %1, %3 \n"
5614+ __SC "%0, %2 \n"
5615+ " beqz %0, 1b \n"
5616+ " addu %0, %1, %3 \n"
5617+ " .set mips0 \n"
5618+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
5619+ : "Ir" (i), "m" (l->a.counter)
5620+ : "memory");
5621+ } else {
5622+ unsigned long flags;
5623+
5624+ local_irq_save(flags);
5625+ result = l->a.counter;
5626+ result += i;
5627+ l->a.counter = result;
5628+ local_irq_restore(flags);
5629+ }
5630+
5631+ return result;
5632+}
5633+
5634 static __inline__ long local_sub_return(long i, local_t * l)
5635 {
5636 unsigned long result;
5637@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
5638
5639 #define local_cmpxchg(l, o, n) \
5640 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
5641+#define local_cmpxchg_unchecked(l, o, n) \
5642+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
5643 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
5644
5645 /**
5646diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5647index f59552f..3abe9b9 100644
5648--- a/arch/mips/include/asm/page.h
5649+++ b/arch/mips/include/asm/page.h
5650@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5651 #ifdef CONFIG_CPU_MIPS32
5652 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5653 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5654- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5655+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5656 #else
5657 typedef struct { unsigned long long pte; } pte_t;
5658 #define pte_val(x) ((x).pte)
5659diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5660index 881d18b..cea38bc 100644
5661--- a/arch/mips/include/asm/pgalloc.h
5662+++ b/arch/mips/include/asm/pgalloc.h
5663@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5664 {
5665 set_pud(pud, __pud((unsigned long)pmd));
5666 }
5667+
5668+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5669+{
5670+ pud_populate(mm, pud, pmd);
5671+}
5672 #endif
5673
5674 /*
5675diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5676index 895320e..bf63e10 100644
5677--- a/arch/mips/include/asm/thread_info.h
5678+++ b/arch/mips/include/asm/thread_info.h
5679@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
5680 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5681 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5682 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5683+/* li takes a 32bit immediate */
5684+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5685 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5686
5687 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5688@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
5689 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5690 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5691 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5692+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5693+
5694+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5695
5696 /* work to do in syscall_trace_leave() */
5697-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5698+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5699
5700 /* work to do on interrupt/exception return */
5701 #define _TIF_WORK_MASK \
5702 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5703 /* work to do on any return to u-space */
5704-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5705+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5706
5707 #endif /* __KERNEL__ */
5708
5709diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5710index 1188e00..41cf144 100644
5711--- a/arch/mips/kernel/binfmt_elfn32.c
5712+++ b/arch/mips/kernel/binfmt_elfn32.c
5713@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5714 #undef ELF_ET_DYN_BASE
5715 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5716
5717+#ifdef CONFIG_PAX_ASLR
5718+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5719+
5720+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5721+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5722+#endif
5723+
5724 #include <asm/processor.h>
5725 #include <linux/module.h>
5726 #include <linux/elfcore.h>
5727diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5728index 202e581..689ca79 100644
5729--- a/arch/mips/kernel/binfmt_elfo32.c
5730+++ b/arch/mips/kernel/binfmt_elfo32.c
5731@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5732 #undef ELF_ET_DYN_BASE
5733 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5734
5735+#ifdef CONFIG_PAX_ASLR
5736+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5737+
5738+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5739+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5740+#endif
5741+
5742 #include <asm/processor.h>
5743
5744 /*
5745diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5746index c6a041d..b3e7318 100644
5747--- a/arch/mips/kernel/process.c
5748+++ b/arch/mips/kernel/process.c
5749@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
5750 out:
5751 return pc;
5752 }
5753-
5754-/*
5755- * Don't forget that the stack pointer must be aligned on a 8 bytes
5756- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5757- */
5758-unsigned long arch_align_stack(unsigned long sp)
5759-{
5760- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5761- sp -= get_random_int() & ~PAGE_MASK;
5762-
5763- return sp & ALMASK;
5764-}
5765diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5766index 9c6299c..2fb4c22 100644
5767--- a/arch/mips/kernel/ptrace.c
5768+++ b/arch/mips/kernel/ptrace.c
5769@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5770 return arch;
5771 }
5772
5773+#ifdef CONFIG_GRKERNSEC_SETXID
5774+extern void gr_delayed_cred_worker(void);
5775+#endif
5776+
5777 /*
5778 * Notification of system call entry/exit
5779 * - triggered by current->work.syscall_trace
5780@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5781 /* do the secure computing check first */
5782 secure_computing_strict(regs->regs[2]);
5783
5784+#ifdef CONFIG_GRKERNSEC_SETXID
5785+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5786+ gr_delayed_cred_worker();
5787+#endif
5788+
5789 if (!(current->ptrace & PT_PTRACED))
5790 goto out;
5791
5792diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5793index 9b36424..e7f4154 100644
5794--- a/arch/mips/kernel/scall32-o32.S
5795+++ b/arch/mips/kernel/scall32-o32.S
5796@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5797
5798 stack_done:
5799 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5800- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5801+ li t1, _TIF_SYSCALL_WORK
5802 and t0, t1
5803 bnez t0, syscall_trace_entry # -> yes
5804
5805diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5806index 97a5909..59622f8 100644
5807--- a/arch/mips/kernel/scall64-64.S
5808+++ b/arch/mips/kernel/scall64-64.S
5809@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5810
5811 sd a3, PT_R26(sp) # save a3 for syscall restarting
5812
5813- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5814+ li t1, _TIF_SYSCALL_WORK
5815 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5816 and t0, t1, t0
5817 bnez t0, syscall_trace_entry
5818diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5819index edcb659..fb2ab09 100644
5820--- a/arch/mips/kernel/scall64-n32.S
5821+++ b/arch/mips/kernel/scall64-n32.S
5822@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5823
5824 sd a3, PT_R26(sp) # save a3 for syscall restarting
5825
5826- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5827+ li t1, _TIF_SYSCALL_WORK
5828 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5829 and t0, t1, t0
5830 bnez t0, n32_syscall_trace_entry
5831diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5832index 74f485d..47d2c38 100644
5833--- a/arch/mips/kernel/scall64-o32.S
5834+++ b/arch/mips/kernel/scall64-o32.S
5835@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5836 PTR 4b, bad_stack
5837 .previous
5838
5839- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5840+ li t1, _TIF_SYSCALL_WORK
5841 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5842 and t0, t1, t0
5843 bnez t0, trace_a_syscall
5844diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5845index 0fead53..eeb00a6 100644
5846--- a/arch/mips/mm/fault.c
5847+++ b/arch/mips/mm/fault.c
5848@@ -27,6 +27,23 @@
5849 #include <asm/highmem.h> /* For VMALLOC_END */
5850 #include <linux/kdebug.h>
5851
5852+#ifdef CONFIG_PAX_PAGEEXEC
5853+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5854+{
5855+ unsigned long i;
5856+
5857+ printk(KERN_ERR "PAX: bytes at PC: ");
5858+ for (i = 0; i < 5; i++) {
5859+ unsigned int c;
5860+ if (get_user(c, (unsigned int *)pc+i))
5861+ printk(KERN_CONT "???????? ");
5862+ else
5863+ printk(KERN_CONT "%08x ", c);
5864+ }
5865+ printk("\n");
5866+}
5867+#endif
5868+
5869 /*
5870 * This routine handles page faults. It determines the address,
5871 * and the problem, and then passes it off to one of the appropriate
5872@@ -196,6 +213,14 @@ bad_area:
5873 bad_area_nosemaphore:
5874 /* User mode accesses just cause a SIGSEGV */
5875 if (user_mode(regs)) {
5876+
5877+#ifdef CONFIG_PAX_PAGEEXEC
5878+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
5879+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
5880+ do_group_exit(SIGKILL);
5881+ }
5882+#endif
5883+
5884 tsk->thread.cp0_badvaddr = address;
5885 tsk->thread.error_code = write;
5886 #if 0
5887diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5888index 7e5fe27..9656513 100644
5889--- a/arch/mips/mm/mmap.c
5890+++ b/arch/mips/mm/mmap.c
5891@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5892 struct vm_area_struct *vma;
5893 unsigned long addr = addr0;
5894 int do_color_align;
5895+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5896 struct vm_unmapped_area_info info;
5897
5898 if (unlikely(len > TASK_SIZE))
5899@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5900 do_color_align = 1;
5901
5902 /* requesting a specific address */
5903+
5904+#ifdef CONFIG_PAX_RANDMMAP
5905+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5906+#endif
5907+
5908 if (addr) {
5909 if (do_color_align)
5910 addr = COLOUR_ALIGN(addr, pgoff);
5911@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5912 addr = PAGE_ALIGN(addr);
5913
5914 vma = find_vma(mm, addr);
5915- if (TASK_SIZE - len >= addr &&
5916- (!vma || addr + len <= vma->vm_start))
5917+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5918 return addr;
5919 }
5920
5921 info.length = len;
5922 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5923 info.align_offset = pgoff << PAGE_SHIFT;
5924+ info.threadstack_offset = offset;
5925
5926 if (dir == DOWN) {
5927 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5928@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5929 {
5930 unsigned long random_factor = 0UL;
5931
5932+#ifdef CONFIG_PAX_RANDMMAP
5933+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5934+#endif
5935+
5936 if (current->flags & PF_RANDOMIZE) {
5937 random_factor = get_random_int();
5938 random_factor = random_factor << PAGE_SHIFT;
5939@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5940
5941 if (mmap_is_legacy()) {
5942 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5943+
5944+#ifdef CONFIG_PAX_RANDMMAP
5945+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5946+ mm->mmap_base += mm->delta_mmap;
5947+#endif
5948+
5949 mm->get_unmapped_area = arch_get_unmapped_area;
5950 mm->unmap_area = arch_unmap_area;
5951 } else {
5952 mm->mmap_base = mmap_base(random_factor);
5953+
5954+#ifdef CONFIG_PAX_RANDMMAP
5955+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5956+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5957+#endif
5958+
5959 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5960 mm->unmap_area = arch_unmap_area_topdown;
5961 }
5962 }
5963
5964-static inline unsigned long brk_rnd(void)
5965-{
5966- unsigned long rnd = get_random_int();
5967-
5968- rnd = rnd << PAGE_SHIFT;
5969- /* 8MB for 32bit, 256MB for 64bit */
5970- if (TASK_IS_32BIT_ADDR)
5971- rnd = rnd & 0x7ffffful;
5972- else
5973- rnd = rnd & 0xffffffful;
5974-
5975- return rnd;
5976-}
5977-
5978-unsigned long arch_randomize_brk(struct mm_struct *mm)
5979-{
5980- unsigned long base = mm->brk;
5981- unsigned long ret;
5982-
5983- ret = PAGE_ALIGN(base + brk_rnd());
5984-
5985- if (ret < mm->brk)
5986- return mm->brk;
5987-
5988- return ret;
5989-}
5990-
5991 int __virt_addr_valid(const volatile void *kaddr)
5992 {
5993 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5994diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5995index 967d144..db12197 100644
5996--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5997+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5998@@ -11,12 +11,14 @@
5999 #ifndef _ASM_PROC_CACHE_H
6000 #define _ASM_PROC_CACHE_H
6001
6002+#include <linux/const.h>
6003+
6004 /* L1 cache */
6005
6006 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6007 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6008-#define L1_CACHE_BYTES 16 /* bytes per entry */
6009 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6010+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6011 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6012
6013 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6014diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6015index bcb5df2..84fabd2 100644
6016--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6017+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6018@@ -16,13 +16,15 @@
6019 #ifndef _ASM_PROC_CACHE_H
6020 #define _ASM_PROC_CACHE_H
6021
6022+#include <linux/const.h>
6023+
6024 /*
6025 * L1 cache
6026 */
6027 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6028 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6029-#define L1_CACHE_BYTES 32 /* bytes per entry */
6030 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6031+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6032 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6033
6034 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6035diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6036index 4ce7a01..449202a 100644
6037--- a/arch/openrisc/include/asm/cache.h
6038+++ b/arch/openrisc/include/asm/cache.h
6039@@ -19,11 +19,13 @@
6040 #ifndef __ASM_OPENRISC_CACHE_H
6041 #define __ASM_OPENRISC_CACHE_H
6042
6043+#include <linux/const.h>
6044+
6045 /* FIXME: How can we replace these with values from the CPU...
6046 * they shouldn't be hard-coded!
6047 */
6048
6049-#define L1_CACHE_BYTES 16
6050 #define L1_CACHE_SHIFT 4
6051+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6052
6053 #endif /* __ASM_OPENRISC_CACHE_H */
6054diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6055index 472886c..00e7df9 100644
6056--- a/arch/parisc/include/asm/atomic.h
6057+++ b/arch/parisc/include/asm/atomic.h
6058@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6059 return dec;
6060 }
6061
6062+#define atomic64_read_unchecked(v) atomic64_read(v)
6063+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6064+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6065+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6066+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6067+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6068+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6069+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6070+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6071+
6072 #endif /* !CONFIG_64BIT */
6073
6074
6075diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6076index 47f11c7..3420df2 100644
6077--- a/arch/parisc/include/asm/cache.h
6078+++ b/arch/parisc/include/asm/cache.h
6079@@ -5,6 +5,7 @@
6080 #ifndef __ARCH_PARISC_CACHE_H
6081 #define __ARCH_PARISC_CACHE_H
6082
6083+#include <linux/const.h>
6084
6085 /*
6086 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6087@@ -15,13 +16,13 @@
6088 * just ruin performance.
6089 */
6090 #ifdef CONFIG_PA20
6091-#define L1_CACHE_BYTES 64
6092 #define L1_CACHE_SHIFT 6
6093 #else
6094-#define L1_CACHE_BYTES 32
6095 #define L1_CACHE_SHIFT 5
6096 #endif
6097
6098+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6099+
6100 #ifndef __ASSEMBLY__
6101
6102 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6103diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6104index ad2b503..bdf1651 100644
6105--- a/arch/parisc/include/asm/elf.h
6106+++ b/arch/parisc/include/asm/elf.h
6107@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
6108
6109 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
6110
6111+#ifdef CONFIG_PAX_ASLR
6112+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6113+
6114+#define PAX_DELTA_MMAP_LEN 16
6115+#define PAX_DELTA_STACK_LEN 16
6116+#endif
6117+
6118 /* This yields a mask that user programs can use to figure out what
6119 instruction set this CPU supports. This could be done in user space,
6120 but it's not easy, and we've already done it here. */
6121diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
6122index fc987a1..6e068ef 100644
6123--- a/arch/parisc/include/asm/pgalloc.h
6124+++ b/arch/parisc/include/asm/pgalloc.h
6125@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6126 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
6127 }
6128
6129+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6130+{
6131+ pgd_populate(mm, pgd, pmd);
6132+}
6133+
6134 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
6135 {
6136 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
6137@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
6138 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
6139 #define pmd_free(mm, x) do { } while (0)
6140 #define pgd_populate(mm, pmd, pte) BUG()
6141+#define pgd_populate_kernel(mm, pmd, pte) BUG()
6142
6143 #endif
6144
6145diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
6146index 1e40d7f..a3eb445 100644
6147--- a/arch/parisc/include/asm/pgtable.h
6148+++ b/arch/parisc/include/asm/pgtable.h
6149@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6150 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
6151 #define PAGE_COPY PAGE_EXECREAD
6152 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
6153+
6154+#ifdef CONFIG_PAX_PAGEEXEC
6155+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
6156+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6157+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6158+#else
6159+# define PAGE_SHARED_NOEXEC PAGE_SHARED
6160+# define PAGE_COPY_NOEXEC PAGE_COPY
6161+# define PAGE_READONLY_NOEXEC PAGE_READONLY
6162+#endif
6163+
6164 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
6165 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
6166 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
6167diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
6168index e0a8235..ce2f1e1 100644
6169--- a/arch/parisc/include/asm/uaccess.h
6170+++ b/arch/parisc/include/asm/uaccess.h
6171@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
6172 const void __user *from,
6173 unsigned long n)
6174 {
6175- int sz = __compiletime_object_size(to);
6176+ size_t sz = __compiletime_object_size(to);
6177 int ret = -EFAULT;
6178
6179- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
6180+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
6181 ret = __copy_from_user(to, from, n);
6182 else
6183 copy_from_user_overflow();
6184diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
6185index 2a625fb..9908930 100644
6186--- a/arch/parisc/kernel/module.c
6187+++ b/arch/parisc/kernel/module.c
6188@@ -98,16 +98,38 @@
6189
6190 /* three functions to determine where in the module core
6191 * or init pieces the location is */
6192+static inline int in_init_rx(struct module *me, void *loc)
6193+{
6194+ return (loc >= me->module_init_rx &&
6195+ loc < (me->module_init_rx + me->init_size_rx));
6196+}
6197+
6198+static inline int in_init_rw(struct module *me, void *loc)
6199+{
6200+ return (loc >= me->module_init_rw &&
6201+ loc < (me->module_init_rw + me->init_size_rw));
6202+}
6203+
6204 static inline int in_init(struct module *me, void *loc)
6205 {
6206- return (loc >= me->module_init &&
6207- loc <= (me->module_init + me->init_size));
6208+ return in_init_rx(me, loc) || in_init_rw(me, loc);
6209+}
6210+
6211+static inline int in_core_rx(struct module *me, void *loc)
6212+{
6213+ return (loc >= me->module_core_rx &&
6214+ loc < (me->module_core_rx + me->core_size_rx));
6215+}
6216+
6217+static inline int in_core_rw(struct module *me, void *loc)
6218+{
6219+ return (loc >= me->module_core_rw &&
6220+ loc < (me->module_core_rw + me->core_size_rw));
6221 }
6222
6223 static inline int in_core(struct module *me, void *loc)
6224 {
6225- return (loc >= me->module_core &&
6226- loc <= (me->module_core + me->core_size));
6227+ return in_core_rx(me, loc) || in_core_rw(me, loc);
6228 }
6229
6230 static inline int in_local(struct module *me, void *loc)
6231@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
6232 }
6233
6234 /* align things a bit */
6235- me->core_size = ALIGN(me->core_size, 16);
6236- me->arch.got_offset = me->core_size;
6237- me->core_size += gots * sizeof(struct got_entry);
6238+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6239+ me->arch.got_offset = me->core_size_rw;
6240+ me->core_size_rw += gots * sizeof(struct got_entry);
6241
6242- me->core_size = ALIGN(me->core_size, 16);
6243- me->arch.fdesc_offset = me->core_size;
6244- me->core_size += fdescs * sizeof(Elf_Fdesc);
6245+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
6246+ me->arch.fdesc_offset = me->core_size_rw;
6247+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
6248
6249 me->arch.got_max = gots;
6250 me->arch.fdesc_max = fdescs;
6251@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6252
6253 BUG_ON(value == 0);
6254
6255- got = me->module_core + me->arch.got_offset;
6256+ got = me->module_core_rw + me->arch.got_offset;
6257 for (i = 0; got[i].addr; i++)
6258 if (got[i].addr == value)
6259 goto out;
6260@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
6261 #ifdef CONFIG_64BIT
6262 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6263 {
6264- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
6265+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
6266
6267 if (!value) {
6268 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
6269@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
6270
6271 /* Create new one */
6272 fdesc->addr = value;
6273- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6274+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6275 return (Elf_Addr)fdesc;
6276 }
6277 #endif /* CONFIG_64BIT */
6278@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
6279
6280 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
6281 end = table + sechdrs[me->arch.unwind_section].sh_size;
6282- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
6283+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
6284
6285 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
6286 me->arch.unwind_section, table, end, gp);
6287diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
6288index 5dfd248..64914ac 100644
6289--- a/arch/parisc/kernel/sys_parisc.c
6290+++ b/arch/parisc/kernel/sys_parisc.c
6291@@ -33,9 +33,11 @@
6292 #include <linux/utsname.h>
6293 #include <linux/personality.h>
6294
6295-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6296+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
6297+ unsigned long flags)
6298 {
6299 struct vm_unmapped_area_info info;
6300+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6301
6302 info.flags = 0;
6303 info.length = len;
6304@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
6305 info.high_limit = TASK_SIZE;
6306 info.align_mask = 0;
6307 info.align_offset = 0;
6308+ info.threadstack_offset = offset;
6309 return vm_unmapped_area(&info);
6310 }
6311
6312@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
6313 return (unsigned long) mapping >> 8;
6314 }
6315
6316-static unsigned long get_shared_area(struct address_space *mapping,
6317- unsigned long addr, unsigned long len, unsigned long pgoff)
6318+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
6319+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6320 {
6321 struct vm_unmapped_area_info info;
6322+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6323
6324 info.flags = 0;
6325 info.length = len;
6326@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
6327 info.high_limit = TASK_SIZE;
6328 info.align_mask = PAGE_MASK & (SHMLBA - 1);
6329 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
6330+ info.threadstack_offset = offset;
6331 return vm_unmapped_area(&info);
6332 }
6333
6334@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6335 return -EINVAL;
6336 return addr;
6337 }
6338- if (!addr)
6339+ if (!addr) {
6340 addr = TASK_UNMAPPED_BASE;
6341
6342+#ifdef CONFIG_PAX_RANDMMAP
6343+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
6344+ addr += current->mm->delta_mmap;
6345+#endif
6346+
6347+ }
6348+
6349 if (filp) {
6350- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6351+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6352 } else if(flags & MAP_SHARED) {
6353- addr = get_shared_area(NULL, addr, len, pgoff);
6354+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6355 } else {
6356- addr = get_unshared_area(addr, len);
6357+ addr = get_unshared_area(filp, addr, len, flags);
6358 }
6359 return addr;
6360 }
6361diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6362index 04e47c6..7a8faf6 100644
6363--- a/arch/parisc/kernel/traps.c
6364+++ b/arch/parisc/kernel/traps.c
6365@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6366
6367 down_read(&current->mm->mmap_sem);
6368 vma = find_vma(current->mm,regs->iaoq[0]);
6369- if (vma && (regs->iaoq[0] >= vma->vm_start)
6370- && (vma->vm_flags & VM_EXEC)) {
6371-
6372+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6373 fault_address = regs->iaoq[0];
6374 fault_space = regs->iasq[0];
6375
6376diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6377index f247a34..dc0f219 100644
6378--- a/arch/parisc/mm/fault.c
6379+++ b/arch/parisc/mm/fault.c
6380@@ -15,6 +15,7 @@
6381 #include <linux/sched.h>
6382 #include <linux/interrupt.h>
6383 #include <linux/module.h>
6384+#include <linux/unistd.h>
6385
6386 #include <asm/uaccess.h>
6387 #include <asm/traps.h>
6388@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6389 static unsigned long
6390 parisc_acctyp(unsigned long code, unsigned int inst)
6391 {
6392- if (code == 6 || code == 16)
6393+ if (code == 6 || code == 7 || code == 16)
6394 return VM_EXEC;
6395
6396 switch (inst & 0xf0000000) {
6397@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6398 }
6399 #endif
6400
6401+#ifdef CONFIG_PAX_PAGEEXEC
6402+/*
6403+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6404+ *
6405+ * returns 1 when task should be killed
6406+ * 2 when rt_sigreturn trampoline was detected
6407+ * 3 when unpatched PLT trampoline was detected
6408+ */
6409+static int pax_handle_fetch_fault(struct pt_regs *regs)
6410+{
6411+
6412+#ifdef CONFIG_PAX_EMUPLT
6413+ int err;
6414+
6415+ do { /* PaX: unpatched PLT emulation */
6416+ unsigned int bl, depwi;
6417+
6418+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6419+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6420+
6421+ if (err)
6422+ break;
6423+
6424+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6425+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6426+
6427+ err = get_user(ldw, (unsigned int *)addr);
6428+ err |= get_user(bv, (unsigned int *)(addr+4));
6429+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6430+
6431+ if (err)
6432+ break;
6433+
6434+ if (ldw == 0x0E801096U &&
6435+ bv == 0xEAC0C000U &&
6436+ ldw2 == 0x0E881095U)
6437+ {
6438+ unsigned int resolver, map;
6439+
6440+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6441+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6442+ if (err)
6443+ break;
6444+
6445+ regs->gr[20] = instruction_pointer(regs)+8;
6446+ regs->gr[21] = map;
6447+ regs->gr[22] = resolver;
6448+ regs->iaoq[0] = resolver | 3UL;
6449+ regs->iaoq[1] = regs->iaoq[0] + 4;
6450+ return 3;
6451+ }
6452+ }
6453+ } while (0);
6454+#endif
6455+
6456+#ifdef CONFIG_PAX_EMUTRAMP
6457+
6458+#ifndef CONFIG_PAX_EMUSIGRT
6459+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6460+ return 1;
6461+#endif
6462+
6463+ do { /* PaX: rt_sigreturn emulation */
6464+ unsigned int ldi1, ldi2, bel, nop;
6465+
6466+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6467+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6468+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6469+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6470+
6471+ if (err)
6472+ break;
6473+
6474+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6475+ ldi2 == 0x3414015AU &&
6476+ bel == 0xE4008200U &&
6477+ nop == 0x08000240U)
6478+ {
6479+ regs->gr[25] = (ldi1 & 2) >> 1;
6480+ regs->gr[20] = __NR_rt_sigreturn;
6481+ regs->gr[31] = regs->iaoq[1] + 16;
6482+ regs->sr[0] = regs->iasq[1];
6483+ regs->iaoq[0] = 0x100UL;
6484+ regs->iaoq[1] = regs->iaoq[0] + 4;
6485+ regs->iasq[0] = regs->sr[2];
6486+ regs->iasq[1] = regs->sr[2];
6487+ return 2;
6488+ }
6489+ } while (0);
6490+#endif
6491+
6492+ return 1;
6493+}
6494+
6495+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6496+{
6497+ unsigned long i;
6498+
6499+ printk(KERN_ERR "PAX: bytes at PC: ");
6500+ for (i = 0; i < 5; i++) {
6501+ unsigned int c;
6502+ if (get_user(c, (unsigned int *)pc+i))
6503+ printk(KERN_CONT "???????? ");
6504+ else
6505+ printk(KERN_CONT "%08x ", c);
6506+ }
6507+ printk("\n");
6508+}
6509+#endif
6510+
6511 int fixup_exception(struct pt_regs *regs)
6512 {
6513 const struct exception_table_entry *fix;
6514@@ -194,8 +305,33 @@ good_area:
6515
6516 acc_type = parisc_acctyp(code,regs->iir);
6517
6518- if ((vma->vm_flags & acc_type) != acc_type)
6519+ if ((vma->vm_flags & acc_type) != acc_type) {
6520+
6521+#ifdef CONFIG_PAX_PAGEEXEC
6522+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6523+ (address & ~3UL) == instruction_pointer(regs))
6524+ {
6525+ up_read(&mm->mmap_sem);
6526+ switch (pax_handle_fetch_fault(regs)) {
6527+
6528+#ifdef CONFIG_PAX_EMUPLT
6529+ case 3:
6530+ return;
6531+#endif
6532+
6533+#ifdef CONFIG_PAX_EMUTRAMP
6534+ case 2:
6535+ return;
6536+#endif
6537+
6538+ }
6539+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6540+ do_group_exit(SIGKILL);
6541+ }
6542+#endif
6543+
6544 goto bad_area;
6545+ }
6546
6547 /*
6548 * If for any reason at all we couldn't handle the fault, make
6549diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6550index e3b1d41..8e81edf 100644
6551--- a/arch/powerpc/include/asm/atomic.h
6552+++ b/arch/powerpc/include/asm/atomic.h
6553@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6554 return t1;
6555 }
6556
6557+#define atomic64_read_unchecked(v) atomic64_read(v)
6558+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6559+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6560+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6561+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6562+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6563+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6564+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6565+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6566+
6567 #endif /* __powerpc64__ */
6568
6569 #endif /* __KERNEL__ */
6570diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6571index 9e495c9..b6878e5 100644
6572--- a/arch/powerpc/include/asm/cache.h
6573+++ b/arch/powerpc/include/asm/cache.h
6574@@ -3,6 +3,7 @@
6575
6576 #ifdef __KERNEL__
6577
6578+#include <linux/const.h>
6579
6580 /* bytes per L1 cache line */
6581 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6582@@ -22,7 +23,7 @@
6583 #define L1_CACHE_SHIFT 7
6584 #endif
6585
6586-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6587+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6588
6589 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6590
6591diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6592index cc0655a..13eac2e 100644
6593--- a/arch/powerpc/include/asm/elf.h
6594+++ b/arch/powerpc/include/asm/elf.h
6595@@ -28,8 +28,19 @@
6596 the loader. We need to make sure that it is out of the way of the program
6597 that it will "exec", and that there is sufficient room for the brk. */
6598
6599-extern unsigned long randomize_et_dyn(unsigned long base);
6600-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6601+#define ELF_ET_DYN_BASE (0x20000000)
6602+
6603+#ifdef CONFIG_PAX_ASLR
6604+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6605+
6606+#ifdef __powerpc64__
6607+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6608+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6609+#else
6610+#define PAX_DELTA_MMAP_LEN 15
6611+#define PAX_DELTA_STACK_LEN 15
6612+#endif
6613+#endif
6614
6615 /*
6616 * Our registers are always unsigned longs, whether we're a 32 bit
6617@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6618 (0x7ff >> (PAGE_SHIFT - 12)) : \
6619 (0x3ffff >> (PAGE_SHIFT - 12)))
6620
6621-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6622-#define arch_randomize_brk arch_randomize_brk
6623-
6624-
6625 #ifdef CONFIG_SPU_BASE
6626 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6627 #define NT_SPU 1
6628diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6629index 8196e9c..d83a9f3 100644
6630--- a/arch/powerpc/include/asm/exec.h
6631+++ b/arch/powerpc/include/asm/exec.h
6632@@ -4,6 +4,6 @@
6633 #ifndef _ASM_POWERPC_EXEC_H
6634 #define _ASM_POWERPC_EXEC_H
6635
6636-extern unsigned long arch_align_stack(unsigned long sp);
6637+#define arch_align_stack(x) ((x) & ~0xfUL)
6638
6639 #endif /* _ASM_POWERPC_EXEC_H */
6640diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6641index 5acabbd..7ea14fa 100644
6642--- a/arch/powerpc/include/asm/kmap_types.h
6643+++ b/arch/powerpc/include/asm/kmap_types.h
6644@@ -10,7 +10,7 @@
6645 * 2 of the License, or (at your option) any later version.
6646 */
6647
6648-#define KM_TYPE_NR 16
6649+#define KM_TYPE_NR 17
6650
6651 #endif /* __KERNEL__ */
6652 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6653diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6654index 8565c25..2865190 100644
6655--- a/arch/powerpc/include/asm/mman.h
6656+++ b/arch/powerpc/include/asm/mman.h
6657@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6658 }
6659 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6660
6661-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6662+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6663 {
6664 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6665 }
6666diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6667index 988c812..63c7d70 100644
6668--- a/arch/powerpc/include/asm/page.h
6669+++ b/arch/powerpc/include/asm/page.h
6670@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6671 * and needs to be executable. This means the whole heap ends
6672 * up being executable.
6673 */
6674-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6675- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6676+#define VM_DATA_DEFAULT_FLAGS32 \
6677+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6678+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6679
6680 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6681 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6682@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6683 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6684 #endif
6685
6686+#define ktla_ktva(addr) (addr)
6687+#define ktva_ktla(addr) (addr)
6688+
6689 #ifndef CONFIG_PPC_BOOK3S_64
6690 /*
6691 * Use the top bit of the higher-level page table entries to indicate whether
6692diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6693index 88693ce..ac6f9ab 100644
6694--- a/arch/powerpc/include/asm/page_64.h
6695+++ b/arch/powerpc/include/asm/page_64.h
6696@@ -153,15 +153,18 @@ do { \
6697 * stack by default, so in the absence of a PT_GNU_STACK program header
6698 * we turn execute permission off.
6699 */
6700-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6701- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6702+#define VM_STACK_DEFAULT_FLAGS32 \
6703+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6704+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6705
6706 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6707 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6708
6709+#ifndef CONFIG_PAX_PAGEEXEC
6710 #define VM_STACK_DEFAULT_FLAGS \
6711 (is_32bit_task() ? \
6712 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6713+#endif
6714
6715 #include <asm-generic/getorder.h>
6716
6717diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6718index b66ae72..4a378cd 100644
6719--- a/arch/powerpc/include/asm/pgalloc-64.h
6720+++ b/arch/powerpc/include/asm/pgalloc-64.h
6721@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6722 #ifndef CONFIG_PPC_64K_PAGES
6723
6724 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6725+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6726
6727 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6728 {
6729@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6730 pud_set(pud, (unsigned long)pmd);
6731 }
6732
6733+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6734+{
6735+ pud_populate(mm, pud, pmd);
6736+}
6737+
6738 #define pmd_populate(mm, pmd, pte_page) \
6739 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6740 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6741@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
6742 #endif
6743
6744 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6745+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6746
6747 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6748 pte_t *pte)
6749diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6750index 7aeb955..19f748e 100644
6751--- a/arch/powerpc/include/asm/pgtable.h
6752+++ b/arch/powerpc/include/asm/pgtable.h
6753@@ -2,6 +2,7 @@
6754 #define _ASM_POWERPC_PGTABLE_H
6755 #ifdef __KERNEL__
6756
6757+#include <linux/const.h>
6758 #ifndef __ASSEMBLY__
6759 #include <asm/processor.h> /* For TASK_SIZE */
6760 #include <asm/mmu.h>
6761diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6762index 4aad413..85d86bf 100644
6763--- a/arch/powerpc/include/asm/pte-hash32.h
6764+++ b/arch/powerpc/include/asm/pte-hash32.h
6765@@ -21,6 +21,7 @@
6766 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6767 #define _PAGE_USER 0x004 /* usermode access allowed */
6768 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6769+#define _PAGE_EXEC _PAGE_GUARDED
6770 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6771 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6772 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6773diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6774index e1fb161..2290d1d 100644
6775--- a/arch/powerpc/include/asm/reg.h
6776+++ b/arch/powerpc/include/asm/reg.h
6777@@ -234,6 +234,7 @@
6778 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6779 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6780 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6781+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6782 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6783 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6784 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6785diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6786index 48cfc85..891382f 100644
6787--- a/arch/powerpc/include/asm/smp.h
6788+++ b/arch/powerpc/include/asm/smp.h
6789@@ -50,7 +50,7 @@ struct smp_ops_t {
6790 int (*cpu_disable)(void);
6791 void (*cpu_die)(unsigned int nr);
6792 int (*cpu_bootable)(unsigned int nr);
6793-};
6794+} __no_const;
6795
6796 extern void smp_send_debugger_break(void);
6797 extern void start_secondary_resume(void);
6798diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6799index ba7b197..d292e26 100644
6800--- a/arch/powerpc/include/asm/thread_info.h
6801+++ b/arch/powerpc/include/asm/thread_info.h
6802@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
6803 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
6804 TIF_NEED_RESCHED */
6805 #define TIF_32BIT 4 /* 32 bit binary */
6806-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
6807 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6808 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6809 #define TIF_SINGLESTEP 8 /* singlestepping active */
6810@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
6811 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6812 for stack store? */
6813 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6814+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
6815+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6816+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
6817
6818 /* as above, but as bit values */
6819 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6820@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
6821 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6822 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6823 #define _TIF_NOHZ (1<<TIF_NOHZ)
6824+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6825 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6826 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6827- _TIF_NOHZ)
6828+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
6829
6830 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6831 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6832diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6833index 4db4959..aba5c41 100644
6834--- a/arch/powerpc/include/asm/uaccess.h
6835+++ b/arch/powerpc/include/asm/uaccess.h
6836@@ -318,52 +318,6 @@ do { \
6837 extern unsigned long __copy_tofrom_user(void __user *to,
6838 const void __user *from, unsigned long size);
6839
6840-#ifndef __powerpc64__
6841-
6842-static inline unsigned long copy_from_user(void *to,
6843- const void __user *from, unsigned long n)
6844-{
6845- unsigned long over;
6846-
6847- if (access_ok(VERIFY_READ, from, n))
6848- return __copy_tofrom_user((__force void __user *)to, from, n);
6849- if ((unsigned long)from < TASK_SIZE) {
6850- over = (unsigned long)from + n - TASK_SIZE;
6851- return __copy_tofrom_user((__force void __user *)to, from,
6852- n - over) + over;
6853- }
6854- return n;
6855-}
6856-
6857-static inline unsigned long copy_to_user(void __user *to,
6858- const void *from, unsigned long n)
6859-{
6860- unsigned long over;
6861-
6862- if (access_ok(VERIFY_WRITE, to, n))
6863- return __copy_tofrom_user(to, (__force void __user *)from, n);
6864- if ((unsigned long)to < TASK_SIZE) {
6865- over = (unsigned long)to + n - TASK_SIZE;
6866- return __copy_tofrom_user(to, (__force void __user *)from,
6867- n - over) + over;
6868- }
6869- return n;
6870-}
6871-
6872-#else /* __powerpc64__ */
6873-
6874-#define __copy_in_user(to, from, size) \
6875- __copy_tofrom_user((to), (from), (size))
6876-
6877-extern unsigned long copy_from_user(void *to, const void __user *from,
6878- unsigned long n);
6879-extern unsigned long copy_to_user(void __user *to, const void *from,
6880- unsigned long n);
6881-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6882- unsigned long n);
6883-
6884-#endif /* __powerpc64__ */
6885-
6886 static inline unsigned long __copy_from_user_inatomic(void *to,
6887 const void __user *from, unsigned long n)
6888 {
6889@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6890 if (ret == 0)
6891 return 0;
6892 }
6893+
6894+ if (!__builtin_constant_p(n))
6895+ check_object_size(to, n, false);
6896+
6897 return __copy_tofrom_user((__force void __user *)to, from, n);
6898 }
6899
6900@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6901 if (ret == 0)
6902 return 0;
6903 }
6904+
6905+ if (!__builtin_constant_p(n))
6906+ check_object_size(from, n, true);
6907+
6908 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6909 }
6910
6911@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6912 return __copy_to_user_inatomic(to, from, size);
6913 }
6914
6915+#ifndef __powerpc64__
6916+
6917+static inline unsigned long __must_check copy_from_user(void *to,
6918+ const void __user *from, unsigned long n)
6919+{
6920+ unsigned long over;
6921+
6922+ if ((long)n < 0)
6923+ return n;
6924+
6925+ if (access_ok(VERIFY_READ, from, n)) {
6926+ if (!__builtin_constant_p(n))
6927+ check_object_size(to, n, false);
6928+ return __copy_tofrom_user((__force void __user *)to, from, n);
6929+ }
6930+ if ((unsigned long)from < TASK_SIZE) {
6931+ over = (unsigned long)from + n - TASK_SIZE;
6932+ if (!__builtin_constant_p(n - over))
6933+ check_object_size(to, n - over, false);
6934+ return __copy_tofrom_user((__force void __user *)to, from,
6935+ n - over) + over;
6936+ }
6937+ return n;
6938+}
6939+
6940+static inline unsigned long __must_check copy_to_user(void __user *to,
6941+ const void *from, unsigned long n)
6942+{
6943+ unsigned long over;
6944+
6945+ if ((long)n < 0)
6946+ return n;
6947+
6948+ if (access_ok(VERIFY_WRITE, to, n)) {
6949+ if (!__builtin_constant_p(n))
6950+ check_object_size(from, n, true);
6951+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6952+ }
6953+ if ((unsigned long)to < TASK_SIZE) {
6954+ over = (unsigned long)to + n - TASK_SIZE;
6955+ if (!__builtin_constant_p(n))
6956+ check_object_size(from, n - over, true);
6957+ return __copy_tofrom_user(to, (__force void __user *)from,
6958+ n - over) + over;
6959+ }
6960+ return n;
6961+}
6962+
6963+#else /* __powerpc64__ */
6964+
6965+#define __copy_in_user(to, from, size) \
6966+ __copy_tofrom_user((to), (from), (size))
6967+
6968+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6969+{
6970+ if ((long)n < 0 || n > INT_MAX)
6971+ return n;
6972+
6973+ if (!__builtin_constant_p(n))
6974+ check_object_size(to, n, false);
6975+
6976+ if (likely(access_ok(VERIFY_READ, from, n)))
6977+ n = __copy_from_user(to, from, n);
6978+ else
6979+ memset(to, 0, n);
6980+ return n;
6981+}
6982+
6983+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6984+{
6985+ if ((long)n < 0 || n > INT_MAX)
6986+ return n;
6987+
6988+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6989+ if (!__builtin_constant_p(n))
6990+ check_object_size(from, n, true);
6991+ n = __copy_to_user(to, from, n);
6992+ }
6993+ return n;
6994+}
6995+
6996+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6997+ unsigned long n);
6998+
6999+#endif /* __powerpc64__ */
7000+
7001 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7002
7003 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7004diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7005index 645170a..6cf0271 100644
7006--- a/arch/powerpc/kernel/exceptions-64e.S
7007+++ b/arch/powerpc/kernel/exceptions-64e.S
7008@@ -757,6 +757,7 @@ storage_fault_common:
7009 std r14,_DAR(r1)
7010 std r15,_DSISR(r1)
7011 addi r3,r1,STACK_FRAME_OVERHEAD
7012+ bl .save_nvgprs
7013 mr r4,r14
7014 mr r5,r15
7015 ld r14,PACA_EXGEN+EX_R14(r13)
7016@@ -765,8 +766,7 @@ storage_fault_common:
7017 cmpdi r3,0
7018 bne- 1f
7019 b .ret_from_except_lite
7020-1: bl .save_nvgprs
7021- mr r5,r3
7022+1: mr r5,r3
7023 addi r3,r1,STACK_FRAME_OVERHEAD
7024 ld r4,_DAR(r1)
7025 bl .bad_page_fault
7026diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7027index 902ca3c..e942155 100644
7028--- a/arch/powerpc/kernel/exceptions-64s.S
7029+++ b/arch/powerpc/kernel/exceptions-64s.S
7030@@ -1357,10 +1357,10 @@ handle_page_fault:
7031 11: ld r4,_DAR(r1)
7032 ld r5,_DSISR(r1)
7033 addi r3,r1,STACK_FRAME_OVERHEAD
7034+ bl .save_nvgprs
7035 bl .do_page_fault
7036 cmpdi r3,0
7037 beq+ 12f
7038- bl .save_nvgprs
7039 mr r5,r3
7040 addi r3,r1,STACK_FRAME_OVERHEAD
7041 lwz r4,_DAR(r1)
7042diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7043index 2e3200c..72095ce 100644
7044--- a/arch/powerpc/kernel/module_32.c
7045+++ b/arch/powerpc/kernel/module_32.c
7046@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7047 me->arch.core_plt_section = i;
7048 }
7049 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7050- printk("Module doesn't contain .plt or .init.plt sections.\n");
7051+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7052 return -ENOEXEC;
7053 }
7054
7055@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7056
7057 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7058 /* Init, or core PLT? */
7059- if (location >= mod->module_core
7060- && location < mod->module_core + mod->core_size)
7061+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7062+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7063 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7064- else
7065+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7066+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7067 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7068+ else {
7069+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7070+ return ~0UL;
7071+ }
7072
7073 /* Find this entry, or if that fails, the next avail. entry */
7074 while (entry->jump[0]) {
7075diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7076index 7baa27b..f6b394a 100644
7077--- a/arch/powerpc/kernel/process.c
7078+++ b/arch/powerpc/kernel/process.c
7079@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7080 * Lookup NIP late so we have the best change of getting the
7081 * above info out without failing
7082 */
7083- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7084- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7085+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7086+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7087 #endif
7088 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7089 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7090@@ -1345,10 +1345,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7091 newsp = stack[0];
7092 ip = stack[STACK_FRAME_LR_SAVE];
7093 if (!firstframe || ip != lr) {
7094- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7095+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7096 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7097 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7098- printk(" (%pS)",
7099+ printk(" (%pA)",
7100 (void *)current->ret_stack[curr_frame].ret);
7101 curr_frame--;
7102 }
7103@@ -1368,7 +1368,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7104 struct pt_regs *regs = (struct pt_regs *)
7105 (sp + STACK_FRAME_OVERHEAD);
7106 lr = regs->link;
7107- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7108+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7109 regs->trap, (void *)regs->nip, (void *)lr);
7110 firstframe = 1;
7111 }
7112@@ -1404,58 +1404,3 @@ void notrace __ppc64_runlatch_off(void)
7113 mtspr(SPRN_CTRLT, ctrl);
7114 }
7115 #endif /* CONFIG_PPC64 */
7116-
7117-unsigned long arch_align_stack(unsigned long sp)
7118-{
7119- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7120- sp -= get_random_int() & ~PAGE_MASK;
7121- return sp & ~0xf;
7122-}
7123-
7124-static inline unsigned long brk_rnd(void)
7125-{
7126- unsigned long rnd = 0;
7127-
7128- /* 8MB for 32bit, 1GB for 64bit */
7129- if (is_32bit_task())
7130- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
7131- else
7132- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
7133-
7134- return rnd << PAGE_SHIFT;
7135-}
7136-
7137-unsigned long arch_randomize_brk(struct mm_struct *mm)
7138-{
7139- unsigned long base = mm->brk;
7140- unsigned long ret;
7141-
7142-#ifdef CONFIG_PPC_STD_MMU_64
7143- /*
7144- * If we are using 1TB segments and we are allowed to randomise
7145- * the heap, we can put it above 1TB so it is backed by a 1TB
7146- * segment. Otherwise the heap will be in the bottom 1TB
7147- * which always uses 256MB segments and this may result in a
7148- * performance penalty.
7149- */
7150- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
7151- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
7152-#endif
7153-
7154- ret = PAGE_ALIGN(base + brk_rnd());
7155-
7156- if (ret < mm->brk)
7157- return mm->brk;
7158-
7159- return ret;
7160-}
7161-
7162-unsigned long randomize_et_dyn(unsigned long base)
7163-{
7164- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7165-
7166- if (ret < base)
7167- return base;
7168-
7169- return ret;
7170-}
7171diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
7172index 64f7bd5..8dd550f 100644
7173--- a/arch/powerpc/kernel/ptrace.c
7174+++ b/arch/powerpc/kernel/ptrace.c
7175@@ -1783,6 +1783,10 @@ long arch_ptrace(struct task_struct *child, long request,
7176 return ret;
7177 }
7178
7179+#ifdef CONFIG_GRKERNSEC_SETXID
7180+extern void gr_delayed_cred_worker(void);
7181+#endif
7182+
7183 /*
7184 * We must return the syscall number to actually look up in the table.
7185 * This can be -1L to skip running any syscall at all.
7186@@ -1795,6 +1799,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
7187
7188 secure_computing_strict(regs->gpr[0]);
7189
7190+#ifdef CONFIG_GRKERNSEC_SETXID
7191+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7192+ gr_delayed_cred_worker();
7193+#endif
7194+
7195 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
7196 tracehook_report_syscall_entry(regs))
7197 /*
7198@@ -1829,6 +1838,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
7199 {
7200 int step;
7201
7202+#ifdef CONFIG_GRKERNSEC_SETXID
7203+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7204+ gr_delayed_cred_worker();
7205+#endif
7206+
7207 audit_syscall_exit(regs);
7208
7209 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7210diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
7211index 0f83122..c0aca6a 100644
7212--- a/arch/powerpc/kernel/signal_32.c
7213+++ b/arch/powerpc/kernel/signal_32.c
7214@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
7215 /* Save user registers on the stack */
7216 frame = &rt_sf->uc.uc_mcontext;
7217 addr = frame;
7218- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
7219+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7220 sigret = 0;
7221 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
7222 } else {
7223diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
7224index 887e99d..310bc11 100644
7225--- a/arch/powerpc/kernel/signal_64.c
7226+++ b/arch/powerpc/kernel/signal_64.c
7227@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
7228 #endif
7229
7230 /* Set up to return from userspace. */
7231- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
7232+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
7233 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
7234 } else {
7235 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
7236diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
7237index e68a845..8b140e6 100644
7238--- a/arch/powerpc/kernel/sysfs.c
7239+++ b/arch/powerpc/kernel/sysfs.c
7240@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
7241 return NOTIFY_OK;
7242 }
7243
7244-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
7245+static struct notifier_block sysfs_cpu_nb = {
7246 .notifier_call = sysfs_cpu_notify,
7247 };
7248
7249diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
7250index 88929b1..bece8f8 100644
7251--- a/arch/powerpc/kernel/traps.c
7252+++ b/arch/powerpc/kernel/traps.c
7253@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
7254 return flags;
7255 }
7256
7257+extern void gr_handle_kernel_exploit(void);
7258+
7259 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7260 int signr)
7261 {
7262@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
7263 panic("Fatal exception in interrupt");
7264 if (panic_on_oops)
7265 panic("Fatal exception");
7266+
7267+ gr_handle_kernel_exploit();
7268+
7269 do_exit(signr);
7270 }
7271
7272diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
7273index d4f463a..8fb7431 100644
7274--- a/arch/powerpc/kernel/vdso.c
7275+++ b/arch/powerpc/kernel/vdso.c
7276@@ -34,6 +34,7 @@
7277 #include <asm/firmware.h>
7278 #include <asm/vdso.h>
7279 #include <asm/vdso_datapage.h>
7280+#include <asm/mman.h>
7281
7282 #include "setup.h"
7283
7284@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7285 vdso_base = VDSO32_MBASE;
7286 #endif
7287
7288- current->mm->context.vdso_base = 0;
7289+ current->mm->context.vdso_base = ~0UL;
7290
7291 /* vDSO has a problem and was disabled, just don't "enable" it for the
7292 * process
7293@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
7294 vdso_base = get_unmapped_area(NULL, vdso_base,
7295 (vdso_pages << PAGE_SHIFT) +
7296 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
7297- 0, 0);
7298+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
7299 if (IS_ERR_VALUE(vdso_base)) {
7300 rc = vdso_base;
7301 goto fail_mmapsem;
7302diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
7303index 5eea6f3..5d10396 100644
7304--- a/arch/powerpc/lib/usercopy_64.c
7305+++ b/arch/powerpc/lib/usercopy_64.c
7306@@ -9,22 +9,6 @@
7307 #include <linux/module.h>
7308 #include <asm/uaccess.h>
7309
7310-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7311-{
7312- if (likely(access_ok(VERIFY_READ, from, n)))
7313- n = __copy_from_user(to, from, n);
7314- else
7315- memset(to, 0, n);
7316- return n;
7317-}
7318-
7319-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7320-{
7321- if (likely(access_ok(VERIFY_WRITE, to, n)))
7322- n = __copy_to_user(to, from, n);
7323- return n;
7324-}
7325-
7326 unsigned long copy_in_user(void __user *to, const void __user *from,
7327 unsigned long n)
7328 {
7329@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
7330 return n;
7331 }
7332
7333-EXPORT_SYMBOL(copy_from_user);
7334-EXPORT_SYMBOL(copy_to_user);
7335 EXPORT_SYMBOL(copy_in_user);
7336
7337diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
7338index 8726779..a33c512 100644
7339--- a/arch/powerpc/mm/fault.c
7340+++ b/arch/powerpc/mm/fault.c
7341@@ -33,6 +33,10 @@
7342 #include <linux/magic.h>
7343 #include <linux/ratelimit.h>
7344 #include <linux/context_tracking.h>
7345+#include <linux/slab.h>
7346+#include <linux/pagemap.h>
7347+#include <linux/compiler.h>
7348+#include <linux/unistd.h>
7349
7350 #include <asm/firmware.h>
7351 #include <asm/page.h>
7352@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7353 }
7354 #endif
7355
7356+#ifdef CONFIG_PAX_PAGEEXEC
7357+/*
7358+ * PaX: decide what to do with offenders (regs->nip = fault address)
7359+ *
7360+ * returns 1 when task should be killed
7361+ */
7362+static int pax_handle_fetch_fault(struct pt_regs *regs)
7363+{
7364+ return 1;
7365+}
7366+
7367+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7368+{
7369+ unsigned long i;
7370+
7371+ printk(KERN_ERR "PAX: bytes at PC: ");
7372+ for (i = 0; i < 5; i++) {
7373+ unsigned int c;
7374+ if (get_user(c, (unsigned int __user *)pc+i))
7375+ printk(KERN_CONT "???????? ");
7376+ else
7377+ printk(KERN_CONT "%08x ", c);
7378+ }
7379+ printk("\n");
7380+}
7381+#endif
7382+
7383 /*
7384 * Check whether the instruction at regs->nip is a store using
7385 * an update addressing form which will update r1.
7386@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7387 * indicate errors in DSISR but can validly be set in SRR1.
7388 */
7389 if (trap == 0x400)
7390- error_code &= 0x48200000;
7391+ error_code &= 0x58200000;
7392 else
7393 is_write = error_code & DSISR_ISSTORE;
7394 #else
7395@@ -371,7 +402,7 @@ good_area:
7396 * "undefined". Of those that can be set, this is the only
7397 * one which seems bad.
7398 */
7399- if (error_code & 0x10000000)
7400+ if (error_code & DSISR_GUARDED)
7401 /* Guarded storage error. */
7402 goto bad_area;
7403 #endif /* CONFIG_8xx */
7404@@ -386,7 +417,7 @@ good_area:
7405 * processors use the same I/D cache coherency mechanism
7406 * as embedded.
7407 */
7408- if (error_code & DSISR_PROTFAULT)
7409+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7410 goto bad_area;
7411 #endif /* CONFIG_PPC_STD_MMU */
7412
7413@@ -471,6 +502,23 @@ bad_area:
7414 bad_area_nosemaphore:
7415 /* User mode accesses cause a SIGSEGV */
7416 if (user_mode(regs)) {
7417+
7418+#ifdef CONFIG_PAX_PAGEEXEC
7419+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7420+#ifdef CONFIG_PPC_STD_MMU
7421+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7422+#else
7423+ if (is_exec && regs->nip == address) {
7424+#endif
7425+ switch (pax_handle_fetch_fault(regs)) {
7426+ }
7427+
7428+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7429+ do_group_exit(SIGKILL);
7430+ }
7431+ }
7432+#endif
7433+
7434 _exception(SIGSEGV, regs, code, address);
7435 goto bail;
7436 }
7437diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7438index 67a42ed..cd463e0 100644
7439--- a/arch/powerpc/mm/mmap_64.c
7440+++ b/arch/powerpc/mm/mmap_64.c
7441@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7442 {
7443 unsigned long rnd = 0;
7444
7445+#ifdef CONFIG_PAX_RANDMMAP
7446+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7447+#endif
7448+
7449 if (current->flags & PF_RANDOMIZE) {
7450 /* 8MB for 32bit, 1GB for 64bit */
7451 if (is_32bit_task())
7452@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7453 */
7454 if (mmap_is_legacy()) {
7455 mm->mmap_base = TASK_UNMAPPED_BASE;
7456+
7457+#ifdef CONFIG_PAX_RANDMMAP
7458+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7459+ mm->mmap_base += mm->delta_mmap;
7460+#endif
7461+
7462 mm->get_unmapped_area = arch_get_unmapped_area;
7463 mm->unmap_area = arch_unmap_area;
7464 } else {
7465 mm->mmap_base = mmap_base();
7466+
7467+#ifdef CONFIG_PAX_RANDMMAP
7468+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7469+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7470+#endif
7471+
7472 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7473 mm->unmap_area = arch_unmap_area_topdown;
7474 }
7475diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7476index e779642..e5bb889 100644
7477--- a/arch/powerpc/mm/mmu_context_nohash.c
7478+++ b/arch/powerpc/mm/mmu_context_nohash.c
7479@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7480 return NOTIFY_OK;
7481 }
7482
7483-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7484+static struct notifier_block mmu_context_cpu_nb = {
7485 .notifier_call = mmu_context_cpu_notify,
7486 };
7487
7488diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7489index cafad40..9cbc0fc 100644
7490--- a/arch/powerpc/mm/numa.c
7491+++ b/arch/powerpc/mm/numa.c
7492@@ -920,7 +920,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7493 return ret;
7494 }
7495
7496-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7497+static struct notifier_block ppc64_numa_nb = {
7498 .notifier_call = cpu_numa_callback,
7499 .priority = 1 /* Must run before sched domains notifier. */
7500 };
7501diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7502index 3e99c14..f00953c 100644
7503--- a/arch/powerpc/mm/slice.c
7504+++ b/arch/powerpc/mm/slice.c
7505@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7506 if ((mm->task_size - len) < addr)
7507 return 0;
7508 vma = find_vma(mm, addr);
7509- return (!vma || (addr + len) <= vma->vm_start);
7510+ return check_heap_stack_gap(vma, addr, len, 0);
7511 }
7512
7513 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7514@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
7515 info.align_offset = 0;
7516
7517 addr = TASK_UNMAPPED_BASE;
7518+
7519+#ifdef CONFIG_PAX_RANDMMAP
7520+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7521+ addr += mm->delta_mmap;
7522+#endif
7523+
7524 while (addr < TASK_SIZE) {
7525 info.low_limit = addr;
7526 if (!slice_scan_available(addr, available, 1, &addr))
7527@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7528 if (fixed && addr > (mm->task_size - len))
7529 return -EINVAL;
7530
7531+#ifdef CONFIG_PAX_RANDMMAP
7532+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7533+ addr = 0;
7534+#endif
7535+
7536 /* If hint, make sure it matches our alignment restrictions */
7537 if (!fixed && addr) {
7538 addr = _ALIGN_UP(addr, 1ul << pshift);
7539diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7540index 9098692..3d54cd1 100644
7541--- a/arch/powerpc/platforms/cell/spufs/file.c
7542+++ b/arch/powerpc/platforms/cell/spufs/file.c
7543@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7544 return VM_FAULT_NOPAGE;
7545 }
7546
7547-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7548+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7549 unsigned long address,
7550- void *buf, int len, int write)
7551+ void *buf, size_t len, int write)
7552 {
7553 struct spu_context *ctx = vma->vm_file->private_data;
7554 unsigned long offset = address - vma->vm_start;
7555diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7556index bdb738a..49c9f95 100644
7557--- a/arch/powerpc/platforms/powermac/smp.c
7558+++ b/arch/powerpc/platforms/powermac/smp.c
7559@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7560 return NOTIFY_OK;
7561 }
7562
7563-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7564+static struct notifier_block smp_core99_cpu_nb = {
7565 .notifier_call = smp_core99_cpu_notify,
7566 };
7567 #endif /* CONFIG_HOTPLUG_CPU */
7568diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7569index c797832..ce575c8 100644
7570--- a/arch/s390/include/asm/atomic.h
7571+++ b/arch/s390/include/asm/atomic.h
7572@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7573 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7574 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7575
7576+#define atomic64_read_unchecked(v) atomic64_read(v)
7577+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7578+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7579+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7580+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7581+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7582+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7583+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7584+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7585+
7586 #define smp_mb__before_atomic_dec() smp_mb()
7587 #define smp_mb__after_atomic_dec() smp_mb()
7588 #define smp_mb__before_atomic_inc() smp_mb()
7589diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7590index 4d7ccac..d03d0ad 100644
7591--- a/arch/s390/include/asm/cache.h
7592+++ b/arch/s390/include/asm/cache.h
7593@@ -9,8 +9,10 @@
7594 #ifndef __ARCH_S390_CACHE_H
7595 #define __ARCH_S390_CACHE_H
7596
7597-#define L1_CACHE_BYTES 256
7598+#include <linux/const.h>
7599+
7600 #define L1_CACHE_SHIFT 8
7601+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7602 #define NET_SKB_PAD 32
7603
7604 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7605diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7606index 78f4f87..598ce39 100644
7607--- a/arch/s390/include/asm/elf.h
7608+++ b/arch/s390/include/asm/elf.h
7609@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
7610 the loader. We need to make sure that it is out of the way of the program
7611 that it will "exec", and that there is sufficient room for the brk. */
7612
7613-extern unsigned long randomize_et_dyn(unsigned long base);
7614-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7615+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7616+
7617+#ifdef CONFIG_PAX_ASLR
7618+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7619+
7620+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7621+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7622+#endif
7623
7624 /* This yields a mask that user programs can use to figure out what
7625 instruction set this CPU supports. */
7626@@ -222,9 +228,6 @@ struct linux_binprm;
7627 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7628 int arch_setup_additional_pages(struct linux_binprm *, int);
7629
7630-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7631-#define arch_randomize_brk arch_randomize_brk
7632-
7633 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7634
7635 #endif
7636diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7637index c4a93d6..4d2a9b4 100644
7638--- a/arch/s390/include/asm/exec.h
7639+++ b/arch/s390/include/asm/exec.h
7640@@ -7,6 +7,6 @@
7641 #ifndef __ASM_EXEC_H
7642 #define __ASM_EXEC_H
7643
7644-extern unsigned long arch_align_stack(unsigned long sp);
7645+#define arch_align_stack(x) ((x) & ~0xfUL)
7646
7647 #endif /* __ASM_EXEC_H */
7648diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h
7649index b75d7d6..6d6d92b 100644
7650--- a/arch/s390/include/asm/tlb.h
7651+++ b/arch/s390/include/asm/tlb.h
7652@@ -32,6 +32,7 @@ struct mmu_gather {
7653 struct mm_struct *mm;
7654 struct mmu_table_batch *batch;
7655 unsigned int fullmm;
7656+ unsigned long start, end;
7657 };
7658
7659 struct mmu_table_batch {
7660@@ -48,10 +49,13 @@ extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
7661
7662 static inline void tlb_gather_mmu(struct mmu_gather *tlb,
7663 struct mm_struct *mm,
7664- unsigned int full_mm_flush)
7665+ unsigned long start,
7666+ unsigned long end)
7667 {
7668 tlb->mm = mm;
7669- tlb->fullmm = full_mm_flush;
7670+ tlb->start = start;
7671+ tlb->end = end;
7672+ tlb->fullmm = !(start | (end+1));
7673 tlb->batch = NULL;
7674 if (tlb->fullmm)
7675 __tlb_flush_mm(mm);
7676diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7677index 9c33ed4..e40cbef 100644
7678--- a/arch/s390/include/asm/uaccess.h
7679+++ b/arch/s390/include/asm/uaccess.h
7680@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7681 copy_to_user(void __user *to, const void *from, unsigned long n)
7682 {
7683 might_fault();
7684+
7685+ if ((long)n < 0)
7686+ return n;
7687+
7688 return __copy_to_user(to, from, n);
7689 }
7690
7691@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7692 static inline unsigned long __must_check
7693 __copy_from_user(void *to, const void __user *from, unsigned long n)
7694 {
7695+ if ((long)n < 0)
7696+ return n;
7697+
7698 if (__builtin_constant_p(n) && (n <= 256))
7699 return uaccess.copy_from_user_small(n, from, to);
7700 else
7701@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7702 static inline unsigned long __must_check
7703 copy_from_user(void *to, const void __user *from, unsigned long n)
7704 {
7705- unsigned int sz = __compiletime_object_size(to);
7706+ size_t sz = __compiletime_object_size(to);
7707
7708 might_fault();
7709- if (unlikely(sz != -1 && sz < n)) {
7710+
7711+ if ((long)n < 0)
7712+ return n;
7713+
7714+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7715 copy_from_user_overflow();
7716 return n;
7717 }
7718diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7719index 7845e15..59c4353 100644
7720--- a/arch/s390/kernel/module.c
7721+++ b/arch/s390/kernel/module.c
7722@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7723
7724 /* Increase core size by size of got & plt and set start
7725 offsets for got and plt. */
7726- me->core_size = ALIGN(me->core_size, 4);
7727- me->arch.got_offset = me->core_size;
7728- me->core_size += me->arch.got_size;
7729- me->arch.plt_offset = me->core_size;
7730- me->core_size += me->arch.plt_size;
7731+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7732+ me->arch.got_offset = me->core_size_rw;
7733+ me->core_size_rw += me->arch.got_size;
7734+ me->arch.plt_offset = me->core_size_rx;
7735+ me->core_size_rx += me->arch.plt_size;
7736 return 0;
7737 }
7738
7739@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7740 if (info->got_initialized == 0) {
7741 Elf_Addr *gotent;
7742
7743- gotent = me->module_core + me->arch.got_offset +
7744+ gotent = me->module_core_rw + me->arch.got_offset +
7745 info->got_offset;
7746 *gotent = val;
7747 info->got_initialized = 1;
7748@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7749 rc = apply_rela_bits(loc, val, 0, 64, 0);
7750 else if (r_type == R_390_GOTENT ||
7751 r_type == R_390_GOTPLTENT) {
7752- val += (Elf_Addr) me->module_core - loc;
7753+ val += (Elf_Addr) me->module_core_rw - loc;
7754 rc = apply_rela_bits(loc, val, 1, 32, 1);
7755 }
7756 break;
7757@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7758 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7759 if (info->plt_initialized == 0) {
7760 unsigned int *ip;
7761- ip = me->module_core + me->arch.plt_offset +
7762+ ip = me->module_core_rx + me->arch.plt_offset +
7763 info->plt_offset;
7764 #ifndef CONFIG_64BIT
7765 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7766@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7767 val - loc + 0xffffUL < 0x1ffffeUL) ||
7768 (r_type == R_390_PLT32DBL &&
7769 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7770- val = (Elf_Addr) me->module_core +
7771+ val = (Elf_Addr) me->module_core_rx +
7772 me->arch.plt_offset +
7773 info->plt_offset;
7774 val += rela->r_addend - loc;
7775@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7776 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7777 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7778 val = val + rela->r_addend -
7779- ((Elf_Addr) me->module_core + me->arch.got_offset);
7780+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7781 if (r_type == R_390_GOTOFF16)
7782 rc = apply_rela_bits(loc, val, 0, 16, 0);
7783 else if (r_type == R_390_GOTOFF32)
7784@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7785 break;
7786 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7787 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7788- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7789+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7790 rela->r_addend - loc;
7791 if (r_type == R_390_GOTPC)
7792 rc = apply_rela_bits(loc, val, 1, 32, 0);
7793diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7794index 2bc3edd..ab9d598 100644
7795--- a/arch/s390/kernel/process.c
7796+++ b/arch/s390/kernel/process.c
7797@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
7798 }
7799 return 0;
7800 }
7801-
7802-unsigned long arch_align_stack(unsigned long sp)
7803-{
7804- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7805- sp -= get_random_int() & ~PAGE_MASK;
7806- return sp & ~0xf;
7807-}
7808-
7809-static inline unsigned long brk_rnd(void)
7810-{
7811- /* 8MB for 32bit, 1GB for 64bit */
7812- if (is_32bit_task())
7813- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7814- else
7815- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7816-}
7817-
7818-unsigned long arch_randomize_brk(struct mm_struct *mm)
7819-{
7820- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7821-
7822- if (ret < mm->brk)
7823- return mm->brk;
7824- return ret;
7825-}
7826-
7827-unsigned long randomize_et_dyn(unsigned long base)
7828-{
7829- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7830-
7831- if (!(current->flags & PF_RANDOMIZE))
7832- return base;
7833- if (ret < base)
7834- return base;
7835- return ret;
7836-}
7837diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7838index 06bafec..2bca531 100644
7839--- a/arch/s390/mm/mmap.c
7840+++ b/arch/s390/mm/mmap.c
7841@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7842 */
7843 if (mmap_is_legacy()) {
7844 mm->mmap_base = TASK_UNMAPPED_BASE;
7845+
7846+#ifdef CONFIG_PAX_RANDMMAP
7847+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7848+ mm->mmap_base += mm->delta_mmap;
7849+#endif
7850+
7851 mm->get_unmapped_area = arch_get_unmapped_area;
7852 mm->unmap_area = arch_unmap_area;
7853 } else {
7854 mm->mmap_base = mmap_base();
7855+
7856+#ifdef CONFIG_PAX_RANDMMAP
7857+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7858+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7859+#endif
7860+
7861 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7862 mm->unmap_area = arch_unmap_area_topdown;
7863 }
7864@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7865 */
7866 if (mmap_is_legacy()) {
7867 mm->mmap_base = TASK_UNMAPPED_BASE;
7868+
7869+#ifdef CONFIG_PAX_RANDMMAP
7870+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7871+ mm->mmap_base += mm->delta_mmap;
7872+#endif
7873+
7874 mm->get_unmapped_area = s390_get_unmapped_area;
7875 mm->unmap_area = arch_unmap_area;
7876 } else {
7877 mm->mmap_base = mmap_base();
7878+
7879+#ifdef CONFIG_PAX_RANDMMAP
7880+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7881+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7882+#endif
7883+
7884 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7885 mm->unmap_area = arch_unmap_area_topdown;
7886 }
7887diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7888index ae3d59f..f65f075 100644
7889--- a/arch/score/include/asm/cache.h
7890+++ b/arch/score/include/asm/cache.h
7891@@ -1,7 +1,9 @@
7892 #ifndef _ASM_SCORE_CACHE_H
7893 #define _ASM_SCORE_CACHE_H
7894
7895+#include <linux/const.h>
7896+
7897 #define L1_CACHE_SHIFT 4
7898-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7899+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7900
7901 #endif /* _ASM_SCORE_CACHE_H */
7902diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7903index f9f3cd5..58ff438 100644
7904--- a/arch/score/include/asm/exec.h
7905+++ b/arch/score/include/asm/exec.h
7906@@ -1,6 +1,6 @@
7907 #ifndef _ASM_SCORE_EXEC_H
7908 #define _ASM_SCORE_EXEC_H
7909
7910-extern unsigned long arch_align_stack(unsigned long sp);
7911+#define arch_align_stack(x) (x)
7912
7913 #endif /* _ASM_SCORE_EXEC_H */
7914diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7915index f4c6d02..e9355c3 100644
7916--- a/arch/score/kernel/process.c
7917+++ b/arch/score/kernel/process.c
7918@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
7919
7920 return task_pt_regs(task)->cp0_epc;
7921 }
7922-
7923-unsigned long arch_align_stack(unsigned long sp)
7924-{
7925- return sp;
7926-}
7927diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7928index ef9e555..331bd29 100644
7929--- a/arch/sh/include/asm/cache.h
7930+++ b/arch/sh/include/asm/cache.h
7931@@ -9,10 +9,11 @@
7932 #define __ASM_SH_CACHE_H
7933 #ifdef __KERNEL__
7934
7935+#include <linux/const.h>
7936 #include <linux/init.h>
7937 #include <cpu/cache.h>
7938
7939-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7940+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7941
7942 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7943
7944diff --git a/arch/sh/include/asm/tlb.h b/arch/sh/include/asm/tlb.h
7945index e61d43d..362192e 100644
7946--- a/arch/sh/include/asm/tlb.h
7947+++ b/arch/sh/include/asm/tlb.h
7948@@ -36,10 +36,12 @@ static inline void init_tlb_gather(struct mmu_gather *tlb)
7949 }
7950
7951 static inline void
7952-tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int full_mm_flush)
7953+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
7954 {
7955 tlb->mm = mm;
7956- tlb->fullmm = full_mm_flush;
7957+ tlb->start = start;
7958+ tlb->end = end;
7959+ tlb->fullmm = !(start | (end+1));
7960
7961 init_tlb_gather(tlb);
7962 }
7963diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7964index 03f2b55..b0270327 100644
7965--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7966+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7967@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7968 return NOTIFY_OK;
7969 }
7970
7971-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7972+static struct notifier_block shx3_cpu_notifier = {
7973 .notifier_call = shx3_cpu_callback,
7974 };
7975
7976diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7977index 6777177..cb5e44f 100644
7978--- a/arch/sh/mm/mmap.c
7979+++ b/arch/sh/mm/mmap.c
7980@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7981 struct mm_struct *mm = current->mm;
7982 struct vm_area_struct *vma;
7983 int do_colour_align;
7984+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7985 struct vm_unmapped_area_info info;
7986
7987 if (flags & MAP_FIXED) {
7988@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7989 if (filp || (flags & MAP_SHARED))
7990 do_colour_align = 1;
7991
7992+#ifdef CONFIG_PAX_RANDMMAP
7993+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7994+#endif
7995+
7996 if (addr) {
7997 if (do_colour_align)
7998 addr = COLOUR_ALIGN(addr, pgoff);
7999@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8000 addr = PAGE_ALIGN(addr);
8001
8002 vma = find_vma(mm, addr);
8003- if (TASK_SIZE - len >= addr &&
8004- (!vma || addr + len <= vma->vm_start))
8005+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8006 return addr;
8007 }
8008
8009 info.flags = 0;
8010 info.length = len;
8011- info.low_limit = TASK_UNMAPPED_BASE;
8012+ info.low_limit = mm->mmap_base;
8013 info.high_limit = TASK_SIZE;
8014 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8015 info.align_offset = pgoff << PAGE_SHIFT;
8016@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8017 struct mm_struct *mm = current->mm;
8018 unsigned long addr = addr0;
8019 int do_colour_align;
8020+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8021 struct vm_unmapped_area_info info;
8022
8023 if (flags & MAP_FIXED) {
8024@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8025 if (filp || (flags & MAP_SHARED))
8026 do_colour_align = 1;
8027
8028+#ifdef CONFIG_PAX_RANDMMAP
8029+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8030+#endif
8031+
8032 /* requesting a specific address */
8033 if (addr) {
8034 if (do_colour_align)
8035@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8036 addr = PAGE_ALIGN(addr);
8037
8038 vma = find_vma(mm, addr);
8039- if (TASK_SIZE - len >= addr &&
8040- (!vma || addr + len <= vma->vm_start))
8041+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8042 return addr;
8043 }
8044
8045@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8046 VM_BUG_ON(addr != -ENOMEM);
8047 info.flags = 0;
8048 info.low_limit = TASK_UNMAPPED_BASE;
8049+
8050+#ifdef CONFIG_PAX_RANDMMAP
8051+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8052+ info.low_limit += mm->delta_mmap;
8053+#endif
8054+
8055 info.high_limit = TASK_SIZE;
8056 addr = vm_unmapped_area(&info);
8057 }
8058diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8059index be56a24..443328f 100644
8060--- a/arch/sparc/include/asm/atomic_64.h
8061+++ b/arch/sparc/include/asm/atomic_64.h
8062@@ -14,18 +14,40 @@
8063 #define ATOMIC64_INIT(i) { (i) }
8064
8065 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8066+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8067+{
8068+ return v->counter;
8069+}
8070 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8071+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8072+{
8073+ return v->counter;
8074+}
8075
8076 #define atomic_set(v, i) (((v)->counter) = i)
8077+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8078+{
8079+ v->counter = i;
8080+}
8081 #define atomic64_set(v, i) (((v)->counter) = i)
8082+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8083+{
8084+ v->counter = i;
8085+}
8086
8087 extern void atomic_add(int, atomic_t *);
8088+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8089 extern void atomic64_add(long, atomic64_t *);
8090+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8091 extern void atomic_sub(int, atomic_t *);
8092+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8093 extern void atomic64_sub(long, atomic64_t *);
8094+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8095
8096 extern int atomic_add_ret(int, atomic_t *);
8097+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8098 extern long atomic64_add_ret(long, atomic64_t *);
8099+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8100 extern int atomic_sub_ret(int, atomic_t *);
8101 extern long atomic64_sub_ret(long, atomic64_t *);
8102
8103@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8104 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8105
8106 #define atomic_inc_return(v) atomic_add_ret(1, v)
8107+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8108+{
8109+ return atomic_add_ret_unchecked(1, v);
8110+}
8111 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8112+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8113+{
8114+ return atomic64_add_ret_unchecked(1, v);
8115+}
8116
8117 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8118 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8119
8120 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8121+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8122+{
8123+ return atomic_add_ret_unchecked(i, v);
8124+}
8125 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8126+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8127+{
8128+ return atomic64_add_ret_unchecked(i, v);
8129+}
8130
8131 /*
8132 * atomic_inc_and_test - increment and test
8133@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8134 * other cases.
8135 */
8136 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8137+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8138+{
8139+ return atomic_inc_return_unchecked(v) == 0;
8140+}
8141 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8142
8143 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8144@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8145 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8146
8147 #define atomic_inc(v) atomic_add(1, v)
8148+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8149+{
8150+ atomic_add_unchecked(1, v);
8151+}
8152 #define atomic64_inc(v) atomic64_add(1, v)
8153+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8154+{
8155+ atomic64_add_unchecked(1, v);
8156+}
8157
8158 #define atomic_dec(v) atomic_sub(1, v)
8159+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8160+{
8161+ atomic_sub_unchecked(1, v);
8162+}
8163 #define atomic64_dec(v) atomic64_sub(1, v)
8164+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8165+{
8166+ atomic64_sub_unchecked(1, v);
8167+}
8168
8169 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8170 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8171
8172 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8173+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8174+{
8175+ return cmpxchg(&v->counter, old, new);
8176+}
8177 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8178+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8179+{
8180+ return xchg(&v->counter, new);
8181+}
8182
8183 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8184 {
8185- int c, old;
8186+ int c, old, new;
8187 c = atomic_read(v);
8188 for (;;) {
8189- if (unlikely(c == (u)))
8190+ if (unlikely(c == u))
8191 break;
8192- old = atomic_cmpxchg((v), c, c + (a));
8193+
8194+ asm volatile("addcc %2, %0, %0\n"
8195+
8196+#ifdef CONFIG_PAX_REFCOUNT
8197+ "tvs %%icc, 6\n"
8198+#endif
8199+
8200+ : "=r" (new)
8201+ : "0" (c), "ir" (a)
8202+ : "cc");
8203+
8204+ old = atomic_cmpxchg(v, c, new);
8205 if (likely(old == c))
8206 break;
8207 c = old;
8208@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8209 #define atomic64_cmpxchg(v, o, n) \
8210 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8211 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8212+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8213+{
8214+ return xchg(&v->counter, new);
8215+}
8216
8217 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8218 {
8219- long c, old;
8220+ long c, old, new;
8221 c = atomic64_read(v);
8222 for (;;) {
8223- if (unlikely(c == (u)))
8224+ if (unlikely(c == u))
8225 break;
8226- old = atomic64_cmpxchg((v), c, c + (a));
8227+
8228+ asm volatile("addcc %2, %0, %0\n"
8229+
8230+#ifdef CONFIG_PAX_REFCOUNT
8231+ "tvs %%xcc, 6\n"
8232+#endif
8233+
8234+ : "=r" (new)
8235+ : "0" (c), "ir" (a)
8236+ : "cc");
8237+
8238+ old = atomic64_cmpxchg(v, c, new);
8239 if (likely(old == c))
8240 break;
8241 c = old;
8242 }
8243- return c != (u);
8244+ return c != u;
8245 }
8246
8247 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8248diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
8249index 5bb6991..5c2132e 100644
8250--- a/arch/sparc/include/asm/cache.h
8251+++ b/arch/sparc/include/asm/cache.h
8252@@ -7,10 +7,12 @@
8253 #ifndef _SPARC_CACHE_H
8254 #define _SPARC_CACHE_H
8255
8256+#include <linux/const.h>
8257+
8258 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
8259
8260 #define L1_CACHE_SHIFT 5
8261-#define L1_CACHE_BYTES 32
8262+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8263
8264 #ifdef CONFIG_SPARC32
8265 #define SMP_CACHE_BYTES_SHIFT 5
8266diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
8267index a24e41f..47677ff 100644
8268--- a/arch/sparc/include/asm/elf_32.h
8269+++ b/arch/sparc/include/asm/elf_32.h
8270@@ -114,6 +114,13 @@ typedef struct {
8271
8272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
8273
8274+#ifdef CONFIG_PAX_ASLR
8275+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8276+
8277+#define PAX_DELTA_MMAP_LEN 16
8278+#define PAX_DELTA_STACK_LEN 16
8279+#endif
8280+
8281 /* This yields a mask that user programs can use to figure out what
8282 instruction set this cpu supports. This can NOT be done in userspace
8283 on Sparc. */
8284diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
8285index 370ca1e..d4f4a98 100644
8286--- a/arch/sparc/include/asm/elf_64.h
8287+++ b/arch/sparc/include/asm/elf_64.h
8288@@ -189,6 +189,13 @@ typedef struct {
8289 #define ELF_ET_DYN_BASE 0x0000010000000000UL
8290 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
8291
8292+#ifdef CONFIG_PAX_ASLR
8293+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
8294+
8295+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
8296+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
8297+#endif
8298+
8299 extern unsigned long sparc64_elf_hwcap;
8300 #define ELF_HWCAP sparc64_elf_hwcap
8301
8302diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
8303index 9b1c36d..209298b 100644
8304--- a/arch/sparc/include/asm/pgalloc_32.h
8305+++ b/arch/sparc/include/asm/pgalloc_32.h
8306@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
8307 }
8308
8309 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
8310+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
8311
8312 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
8313 unsigned long address)
8314diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
8315index bcfe063..b333142 100644
8316--- a/arch/sparc/include/asm/pgalloc_64.h
8317+++ b/arch/sparc/include/asm/pgalloc_64.h
8318@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8319 }
8320
8321 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
8322+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
8323
8324 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
8325 {
8326diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
8327index 6fc1348..390c50a 100644
8328--- a/arch/sparc/include/asm/pgtable_32.h
8329+++ b/arch/sparc/include/asm/pgtable_32.h
8330@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
8331 #define PAGE_SHARED SRMMU_PAGE_SHARED
8332 #define PAGE_COPY SRMMU_PAGE_COPY
8333 #define PAGE_READONLY SRMMU_PAGE_RDONLY
8334+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
8335+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
8336+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
8337 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
8338
8339 /* Top-level page directory - dummy used by init-mm.
8340@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
8341
8342 /* xwr */
8343 #define __P000 PAGE_NONE
8344-#define __P001 PAGE_READONLY
8345-#define __P010 PAGE_COPY
8346-#define __P011 PAGE_COPY
8347+#define __P001 PAGE_READONLY_NOEXEC
8348+#define __P010 PAGE_COPY_NOEXEC
8349+#define __P011 PAGE_COPY_NOEXEC
8350 #define __P100 PAGE_READONLY
8351 #define __P101 PAGE_READONLY
8352 #define __P110 PAGE_COPY
8353 #define __P111 PAGE_COPY
8354
8355 #define __S000 PAGE_NONE
8356-#define __S001 PAGE_READONLY
8357-#define __S010 PAGE_SHARED
8358-#define __S011 PAGE_SHARED
8359+#define __S001 PAGE_READONLY_NOEXEC
8360+#define __S010 PAGE_SHARED_NOEXEC
8361+#define __S011 PAGE_SHARED_NOEXEC
8362 #define __S100 PAGE_READONLY
8363 #define __S101 PAGE_READONLY
8364 #define __S110 PAGE_SHARED
8365diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
8366index 79da178..c2eede8 100644
8367--- a/arch/sparc/include/asm/pgtsrmmu.h
8368+++ b/arch/sparc/include/asm/pgtsrmmu.h
8369@@ -115,6 +115,11 @@
8370 SRMMU_EXEC | SRMMU_REF)
8371 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
8372 SRMMU_EXEC | SRMMU_REF)
8373+
8374+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
8375+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8376+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8377+
8378 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8379 SRMMU_DIRTY | SRMMU_REF)
8380
8381diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8382index 9689176..63c18ea 100644
8383--- a/arch/sparc/include/asm/spinlock_64.h
8384+++ b/arch/sparc/include/asm/spinlock_64.h
8385@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8386
8387 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8388
8389-static void inline arch_read_lock(arch_rwlock_t *lock)
8390+static inline void arch_read_lock(arch_rwlock_t *lock)
8391 {
8392 unsigned long tmp1, tmp2;
8393
8394 __asm__ __volatile__ (
8395 "1: ldsw [%2], %0\n"
8396 " brlz,pn %0, 2f\n"
8397-"4: add %0, 1, %1\n"
8398+"4: addcc %0, 1, %1\n"
8399+
8400+#ifdef CONFIG_PAX_REFCOUNT
8401+" tvs %%icc, 6\n"
8402+#endif
8403+
8404 " cas [%2], %0, %1\n"
8405 " cmp %0, %1\n"
8406 " bne,pn %%icc, 1b\n"
8407@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8408 " .previous"
8409 : "=&r" (tmp1), "=&r" (tmp2)
8410 : "r" (lock)
8411- : "memory");
8412+ : "memory", "cc");
8413 }
8414
8415-static int inline arch_read_trylock(arch_rwlock_t *lock)
8416+static inline int arch_read_trylock(arch_rwlock_t *lock)
8417 {
8418 int tmp1, tmp2;
8419
8420@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8421 "1: ldsw [%2], %0\n"
8422 " brlz,a,pn %0, 2f\n"
8423 " mov 0, %0\n"
8424-" add %0, 1, %1\n"
8425+" addcc %0, 1, %1\n"
8426+
8427+#ifdef CONFIG_PAX_REFCOUNT
8428+" tvs %%icc, 6\n"
8429+#endif
8430+
8431 " cas [%2], %0, %1\n"
8432 " cmp %0, %1\n"
8433 " bne,pn %%icc, 1b\n"
8434@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8435 return tmp1;
8436 }
8437
8438-static void inline arch_read_unlock(arch_rwlock_t *lock)
8439+static inline void arch_read_unlock(arch_rwlock_t *lock)
8440 {
8441 unsigned long tmp1, tmp2;
8442
8443 __asm__ __volatile__(
8444 "1: lduw [%2], %0\n"
8445-" sub %0, 1, %1\n"
8446+" subcc %0, 1, %1\n"
8447+
8448+#ifdef CONFIG_PAX_REFCOUNT
8449+" tvs %%icc, 6\n"
8450+#endif
8451+
8452 " cas [%2], %0, %1\n"
8453 " cmp %0, %1\n"
8454 " bne,pn %%xcc, 1b\n"
8455@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8456 : "memory");
8457 }
8458
8459-static void inline arch_write_lock(arch_rwlock_t *lock)
8460+static inline void arch_write_lock(arch_rwlock_t *lock)
8461 {
8462 unsigned long mask, tmp1, tmp2;
8463
8464@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8465 : "memory");
8466 }
8467
8468-static void inline arch_write_unlock(arch_rwlock_t *lock)
8469+static inline void arch_write_unlock(arch_rwlock_t *lock)
8470 {
8471 __asm__ __volatile__(
8472 " stw %%g0, [%0]"
8473@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8474 : "memory");
8475 }
8476
8477-static int inline arch_write_trylock(arch_rwlock_t *lock)
8478+static inline int arch_write_trylock(arch_rwlock_t *lock)
8479 {
8480 unsigned long mask, tmp1, tmp2, result;
8481
8482diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8483index dd38075..e7cac83 100644
8484--- a/arch/sparc/include/asm/thread_info_32.h
8485+++ b/arch/sparc/include/asm/thread_info_32.h
8486@@ -49,6 +49,8 @@ struct thread_info {
8487 unsigned long w_saved;
8488
8489 struct restart_block restart_block;
8490+
8491+ unsigned long lowest_stack;
8492 };
8493
8494 /*
8495diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8496index d5e5042..9bfee76 100644
8497--- a/arch/sparc/include/asm/thread_info_64.h
8498+++ b/arch/sparc/include/asm/thread_info_64.h
8499@@ -63,6 +63,8 @@ struct thread_info {
8500 struct pt_regs *kern_una_regs;
8501 unsigned int kern_una_insn;
8502
8503+ unsigned long lowest_stack;
8504+
8505 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8506 };
8507
8508@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8509 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8510 /* flag bit 6 is available */
8511 #define TIF_32BIT 7 /* 32-bit binary */
8512-/* flag bit 8 is available */
8513+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8514 #define TIF_SECCOMP 9 /* secure computing */
8515 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8516 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8517+
8518 /* NOTE: Thread flags >= 12 should be ones we have no interest
8519 * in using in assembly, else we can't use the mask as
8520 * an immediate value in instructions such as andcc.
8521@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8522 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8523 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8524 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8525+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8526
8527 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8528 _TIF_DO_NOTIFY_RESUME_MASK | \
8529 _TIF_NEED_RESCHED)
8530 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8531
8532+#define _TIF_WORK_SYSCALL \
8533+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8534+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8535+
8536+
8537 /*
8538 * Thread-synchronous status.
8539 *
8540diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8541index 0167d26..767bb0c 100644
8542--- a/arch/sparc/include/asm/uaccess.h
8543+++ b/arch/sparc/include/asm/uaccess.h
8544@@ -1,5 +1,6 @@
8545 #ifndef ___ASM_SPARC_UACCESS_H
8546 #define ___ASM_SPARC_UACCESS_H
8547+
8548 #if defined(__sparc__) && defined(__arch64__)
8549 #include <asm/uaccess_64.h>
8550 #else
8551diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8552index 53a28dd..50c38c3 100644
8553--- a/arch/sparc/include/asm/uaccess_32.h
8554+++ b/arch/sparc/include/asm/uaccess_32.h
8555@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8556
8557 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8558 {
8559- if (n && __access_ok((unsigned long) to, n))
8560+ if ((long)n < 0)
8561+ return n;
8562+
8563+ if (n && __access_ok((unsigned long) to, n)) {
8564+ if (!__builtin_constant_p(n))
8565+ check_object_size(from, n, true);
8566 return __copy_user(to, (__force void __user *) from, n);
8567- else
8568+ } else
8569 return n;
8570 }
8571
8572 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8573 {
8574+ if ((long)n < 0)
8575+ return n;
8576+
8577+ if (!__builtin_constant_p(n))
8578+ check_object_size(from, n, true);
8579+
8580 return __copy_user(to, (__force void __user *) from, n);
8581 }
8582
8583 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8584 {
8585- if (n && __access_ok((unsigned long) from, n))
8586+ if ((long)n < 0)
8587+ return n;
8588+
8589+ if (n && __access_ok((unsigned long) from, n)) {
8590+ if (!__builtin_constant_p(n))
8591+ check_object_size(to, n, false);
8592 return __copy_user((__force void __user *) to, from, n);
8593- else
8594+ } else
8595 return n;
8596 }
8597
8598 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8599 {
8600+ if ((long)n < 0)
8601+ return n;
8602+
8603 return __copy_user((__force void __user *) to, from, n);
8604 }
8605
8606diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8607index e562d3c..191f176 100644
8608--- a/arch/sparc/include/asm/uaccess_64.h
8609+++ b/arch/sparc/include/asm/uaccess_64.h
8610@@ -10,6 +10,7 @@
8611 #include <linux/compiler.h>
8612 #include <linux/string.h>
8613 #include <linux/thread_info.h>
8614+#include <linux/kernel.h>
8615 #include <asm/asi.h>
8616 #include <asm/spitfire.h>
8617 #include <asm-generic/uaccess-unaligned.h>
8618@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8619 static inline unsigned long __must_check
8620 copy_from_user(void *to, const void __user *from, unsigned long size)
8621 {
8622- unsigned long ret = ___copy_from_user(to, from, size);
8623+ unsigned long ret;
8624
8625+ if ((long)size < 0 || size > INT_MAX)
8626+ return size;
8627+
8628+ if (!__builtin_constant_p(size))
8629+ check_object_size(to, size, false);
8630+
8631+ ret = ___copy_from_user(to, from, size);
8632 if (unlikely(ret))
8633 ret = copy_from_user_fixup(to, from, size);
8634
8635@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8636 static inline unsigned long __must_check
8637 copy_to_user(void __user *to, const void *from, unsigned long size)
8638 {
8639- unsigned long ret = ___copy_to_user(to, from, size);
8640+ unsigned long ret;
8641
8642+ if ((long)size < 0 || size > INT_MAX)
8643+ return size;
8644+
8645+ if (!__builtin_constant_p(size))
8646+ check_object_size(from, size, true);
8647+
8648+ ret = ___copy_to_user(to, from, size);
8649 if (unlikely(ret))
8650 ret = copy_to_user_fixup(to, from, size);
8651 return ret;
8652diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8653index d432fb2..6056af1 100644
8654--- a/arch/sparc/kernel/Makefile
8655+++ b/arch/sparc/kernel/Makefile
8656@@ -3,7 +3,7 @@
8657 #
8658
8659 asflags-y := -ansi
8660-ccflags-y := -Werror
8661+#ccflags-y := -Werror
8662
8663 extra-y := head_$(BITS).o
8664
8665diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
8666index 5ef48da..11d460f 100644
8667--- a/arch/sparc/kernel/ds.c
8668+++ b/arch/sparc/kernel/ds.c
8669@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
8670 char *base, *p;
8671 int msg_len, loops;
8672
8673+ if (strlen(var) + strlen(value) + 2 >
8674+ sizeof(pkt) - sizeof(pkt.header)) {
8675+ printk(KERN_ERR PFX
8676+ "contents length: %zu, which more than max: %lu,"
8677+ "so could not set (%s) variable to (%s).\n",
8678+ strlen(var) + strlen(value) + 2,
8679+ sizeof(pkt) - sizeof(pkt.header), var, value);
8680+ return;
8681+ }
8682+
8683 memset(&pkt, 0, sizeof(pkt));
8684 pkt.header.data.tag.type = DS_DATA;
8685 pkt.header.data.handle = cp->handle;
8686diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8687index fdd819d..5af08c8 100644
8688--- a/arch/sparc/kernel/process_32.c
8689+++ b/arch/sparc/kernel/process_32.c
8690@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
8691
8692 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8693 r->psr, r->pc, r->npc, r->y, print_tainted());
8694- printk("PC: <%pS>\n", (void *) r->pc);
8695+ printk("PC: <%pA>\n", (void *) r->pc);
8696 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8697 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8698 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8699 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8700 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8701 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8702- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8703+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8704
8705 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8706 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8707@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8708 rw = (struct reg_window32 *) fp;
8709 pc = rw->ins[7];
8710 printk("[%08lx : ", pc);
8711- printk("%pS ] ", (void *) pc);
8712+ printk("%pA ] ", (void *) pc);
8713 fp = rw->ins[6];
8714 } while (++count < 16);
8715 printk("\n");
8716diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8717index baebab2..9cd13b1 100644
8718--- a/arch/sparc/kernel/process_64.c
8719+++ b/arch/sparc/kernel/process_64.c
8720@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
8721 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8722 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8723 if (regs->tstate & TSTATE_PRIV)
8724- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8725+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8726 }
8727
8728 void show_regs(struct pt_regs *regs)
8729@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
8730
8731 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8732 regs->tpc, regs->tnpc, regs->y, print_tainted());
8733- printk("TPC: <%pS>\n", (void *) regs->tpc);
8734+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8735 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8736 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8737 regs->u_regs[3]);
8738@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
8739 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8740 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8741 regs->u_regs[15]);
8742- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8743+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8744 show_regwindow(regs);
8745 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8746 }
8747@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
8748 ((tp && tp->task) ? tp->task->pid : -1));
8749
8750 if (gp->tstate & TSTATE_PRIV) {
8751- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8752+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8753 (void *) gp->tpc,
8754 (void *) gp->o7,
8755 (void *) gp->i7,
8756diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8757index 79cc0d1..ec62734 100644
8758--- a/arch/sparc/kernel/prom_common.c
8759+++ b/arch/sparc/kernel/prom_common.c
8760@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8761
8762 unsigned int prom_early_allocated __initdata;
8763
8764-static struct of_pdt_ops prom_sparc_ops __initdata = {
8765+static struct of_pdt_ops prom_sparc_ops __initconst = {
8766 .nextprop = prom_common_nextprop,
8767 .getproplen = prom_getproplen,
8768 .getproperty = prom_getproperty,
8769diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8770index 7ff45e4..a58f271 100644
8771--- a/arch/sparc/kernel/ptrace_64.c
8772+++ b/arch/sparc/kernel/ptrace_64.c
8773@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8774 return ret;
8775 }
8776
8777+#ifdef CONFIG_GRKERNSEC_SETXID
8778+extern void gr_delayed_cred_worker(void);
8779+#endif
8780+
8781 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8782 {
8783 int ret = 0;
8784@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8785 /* do the secure computing check first */
8786 secure_computing_strict(regs->u_regs[UREG_G1]);
8787
8788+#ifdef CONFIG_GRKERNSEC_SETXID
8789+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8790+ gr_delayed_cred_worker();
8791+#endif
8792+
8793 if (test_thread_flag(TIF_SYSCALL_TRACE))
8794 ret = tracehook_report_syscall_entry(regs);
8795
8796@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8797
8798 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8799 {
8800+#ifdef CONFIG_GRKERNSEC_SETXID
8801+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8802+ gr_delayed_cred_worker();
8803+#endif
8804+
8805 audit_syscall_exit(regs);
8806
8807 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8808diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8809index 3a8d184..49498a8 100644
8810--- a/arch/sparc/kernel/sys_sparc_32.c
8811+++ b/arch/sparc/kernel/sys_sparc_32.c
8812@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8813 if (len > TASK_SIZE - PAGE_SIZE)
8814 return -ENOMEM;
8815 if (!addr)
8816- addr = TASK_UNMAPPED_BASE;
8817+ addr = current->mm->mmap_base;
8818
8819 info.flags = 0;
8820 info.length = len;
8821diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8822index 2daaaa6..4fb84dc 100644
8823--- a/arch/sparc/kernel/sys_sparc_64.c
8824+++ b/arch/sparc/kernel/sys_sparc_64.c
8825@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8826 struct vm_area_struct * vma;
8827 unsigned long task_size = TASK_SIZE;
8828 int do_color_align;
8829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8830 struct vm_unmapped_area_info info;
8831
8832 if (flags & MAP_FIXED) {
8833 /* We do not accept a shared mapping if it would violate
8834 * cache aliasing constraints.
8835 */
8836- if ((flags & MAP_SHARED) &&
8837+ if ((filp || (flags & MAP_SHARED)) &&
8838 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8839 return -EINVAL;
8840 return addr;
8841@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8842 if (filp || (flags & MAP_SHARED))
8843 do_color_align = 1;
8844
8845+#ifdef CONFIG_PAX_RANDMMAP
8846+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8847+#endif
8848+
8849 if (addr) {
8850 if (do_color_align)
8851 addr = COLOR_ALIGN(addr, pgoff);
8852@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8853 addr = PAGE_ALIGN(addr);
8854
8855 vma = find_vma(mm, addr);
8856- if (task_size - len >= addr &&
8857- (!vma || addr + len <= vma->vm_start))
8858+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8859 return addr;
8860 }
8861
8862 info.flags = 0;
8863 info.length = len;
8864- info.low_limit = TASK_UNMAPPED_BASE;
8865+ info.low_limit = mm->mmap_base;
8866 info.high_limit = min(task_size, VA_EXCLUDE_START);
8867 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8868 info.align_offset = pgoff << PAGE_SHIFT;
8869+ info.threadstack_offset = offset;
8870 addr = vm_unmapped_area(&info);
8871
8872 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8873 VM_BUG_ON(addr != -ENOMEM);
8874 info.low_limit = VA_EXCLUDE_END;
8875+
8876+#ifdef CONFIG_PAX_RANDMMAP
8877+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8878+ info.low_limit += mm->delta_mmap;
8879+#endif
8880+
8881 info.high_limit = task_size;
8882 addr = vm_unmapped_area(&info);
8883 }
8884@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8885 unsigned long task_size = STACK_TOP32;
8886 unsigned long addr = addr0;
8887 int do_color_align;
8888+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8889 struct vm_unmapped_area_info info;
8890
8891 /* This should only ever run for 32-bit processes. */
8892@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8893 /* We do not accept a shared mapping if it would violate
8894 * cache aliasing constraints.
8895 */
8896- if ((flags & MAP_SHARED) &&
8897+ if ((filp || (flags & MAP_SHARED)) &&
8898 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8899 return -EINVAL;
8900 return addr;
8901@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8902 if (filp || (flags & MAP_SHARED))
8903 do_color_align = 1;
8904
8905+#ifdef CONFIG_PAX_RANDMMAP
8906+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8907+#endif
8908+
8909 /* requesting a specific address */
8910 if (addr) {
8911 if (do_color_align)
8912@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8913 addr = PAGE_ALIGN(addr);
8914
8915 vma = find_vma(mm, addr);
8916- if (task_size - len >= addr &&
8917- (!vma || addr + len <= vma->vm_start))
8918+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8919 return addr;
8920 }
8921
8922@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8923 info.high_limit = mm->mmap_base;
8924 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8925 info.align_offset = pgoff << PAGE_SHIFT;
8926+ info.threadstack_offset = offset;
8927 addr = vm_unmapped_area(&info);
8928
8929 /*
8930@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8931 VM_BUG_ON(addr != -ENOMEM);
8932 info.flags = 0;
8933 info.low_limit = TASK_UNMAPPED_BASE;
8934+
8935+#ifdef CONFIG_PAX_RANDMMAP
8936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8937+ info.low_limit += mm->delta_mmap;
8938+#endif
8939+
8940 info.high_limit = STACK_TOP32;
8941 addr = vm_unmapped_area(&info);
8942 }
8943@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
8944 EXPORT_SYMBOL(get_fb_unmapped_area);
8945
8946 /* Essentially the same as PowerPC. */
8947-static unsigned long mmap_rnd(void)
8948+static unsigned long mmap_rnd(struct mm_struct *mm)
8949 {
8950 unsigned long rnd = 0UL;
8951
8952+#ifdef CONFIG_PAX_RANDMMAP
8953+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8954+#endif
8955+
8956 if (current->flags & PF_RANDOMIZE) {
8957 unsigned long val = get_random_int();
8958 if (test_thread_flag(TIF_32BIT))
8959@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
8960
8961 void arch_pick_mmap_layout(struct mm_struct *mm)
8962 {
8963- unsigned long random_factor = mmap_rnd();
8964+ unsigned long random_factor = mmap_rnd(mm);
8965 unsigned long gap;
8966
8967 /*
8968@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8969 gap == RLIM_INFINITY ||
8970 sysctl_legacy_va_layout) {
8971 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8972+
8973+#ifdef CONFIG_PAX_RANDMMAP
8974+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8975+ mm->mmap_base += mm->delta_mmap;
8976+#endif
8977+
8978 mm->get_unmapped_area = arch_get_unmapped_area;
8979 mm->unmap_area = arch_unmap_area;
8980 } else {
8981@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8982 gap = (task_size / 6 * 5);
8983
8984 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8985+
8986+#ifdef CONFIG_PAX_RANDMMAP
8987+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8988+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8989+#endif
8990+
8991 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8992 mm->unmap_area = arch_unmap_area_topdown;
8993 }
8994diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8995index 22a1098..6255eb9 100644
8996--- a/arch/sparc/kernel/syscalls.S
8997+++ b/arch/sparc/kernel/syscalls.S
8998@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8999 #endif
9000 .align 32
9001 1: ldx [%g6 + TI_FLAGS], %l5
9002- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9003+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9004 be,pt %icc, rtrap
9005 nop
9006 call syscall_trace_leave
9007@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9008
9009 srl %i5, 0, %o5 ! IEU1
9010 srl %i2, 0, %o2 ! IEU0 Group
9011- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9012+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9013 bne,pn %icc, linux_syscall_trace32 ! CTI
9014 mov %i0, %l5 ! IEU1
9015 call %l7 ! CTI Group brk forced
9016@@ -207,7 +207,7 @@ linux_sparc_syscall:
9017
9018 mov %i3, %o3 ! IEU1
9019 mov %i4, %o4 ! IEU0 Group
9020- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9021+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9022 bne,pn %icc, linux_syscall_trace ! CTI Group
9023 mov %i0, %l5 ! IEU0
9024 2: call %l7 ! CTI Group brk forced
9025@@ -223,7 +223,7 @@ ret_sys_call:
9026
9027 cmp %o0, -ERESTART_RESTARTBLOCK
9028 bgeu,pn %xcc, 1f
9029- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9030+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9031 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9032
9033 2:
9034diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
9035index 654e8aa..45f431b 100644
9036--- a/arch/sparc/kernel/sysfs.c
9037+++ b/arch/sparc/kernel/sysfs.c
9038@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
9039 return NOTIFY_OK;
9040 }
9041
9042-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
9043+static struct notifier_block sysfs_cpu_nb = {
9044 .notifier_call = sysfs_cpu_notify,
9045 };
9046
9047diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9048index 6629829..036032d 100644
9049--- a/arch/sparc/kernel/traps_32.c
9050+++ b/arch/sparc/kernel/traps_32.c
9051@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9052 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9053 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9054
9055+extern void gr_handle_kernel_exploit(void);
9056+
9057 void die_if_kernel(char *str, struct pt_regs *regs)
9058 {
9059 static int die_counter;
9060@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9061 count++ < 30 &&
9062 (((unsigned long) rw) >= PAGE_OFFSET) &&
9063 !(((unsigned long) rw) & 0x7)) {
9064- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9065+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9066 (void *) rw->ins[7]);
9067 rw = (struct reg_window32 *)rw->ins[6];
9068 }
9069 }
9070 printk("Instruction DUMP:");
9071 instruction_dump ((unsigned long *) regs->pc);
9072- if(regs->psr & PSR_PS)
9073+ if(regs->psr & PSR_PS) {
9074+ gr_handle_kernel_exploit();
9075 do_exit(SIGKILL);
9076+ }
9077 do_exit(SIGSEGV);
9078 }
9079
9080diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9081index b3f833a..ac74b2d 100644
9082--- a/arch/sparc/kernel/traps_64.c
9083+++ b/arch/sparc/kernel/traps_64.c
9084@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9085 i + 1,
9086 p->trapstack[i].tstate, p->trapstack[i].tpc,
9087 p->trapstack[i].tnpc, p->trapstack[i].tt);
9088- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9089+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9090 }
9091 }
9092
9093@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9094
9095 lvl -= 0x100;
9096 if (regs->tstate & TSTATE_PRIV) {
9097+
9098+#ifdef CONFIG_PAX_REFCOUNT
9099+ if (lvl == 6)
9100+ pax_report_refcount_overflow(regs);
9101+#endif
9102+
9103 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9104 die_if_kernel(buffer, regs);
9105 }
9106@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9107 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9108 {
9109 char buffer[32];
9110-
9111+
9112 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9113 0, lvl, SIGTRAP) == NOTIFY_STOP)
9114 return;
9115
9116+#ifdef CONFIG_PAX_REFCOUNT
9117+ if (lvl == 6)
9118+ pax_report_refcount_overflow(regs);
9119+#endif
9120+
9121 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9122
9123 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9124@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9125 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9126 printk("%s" "ERROR(%d): ",
9127 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9128- printk("TPC<%pS>\n", (void *) regs->tpc);
9129+ printk("TPC<%pA>\n", (void *) regs->tpc);
9130 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9131 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9132 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9133@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9134 smp_processor_id(),
9135 (type & 0x1) ? 'I' : 'D',
9136 regs->tpc);
9137- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9138+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9139 panic("Irrecoverable Cheetah+ parity error.");
9140 }
9141
9142@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9143 smp_processor_id(),
9144 (type & 0x1) ? 'I' : 'D',
9145 regs->tpc);
9146- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9147+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9148 }
9149
9150 struct sun4v_error_entry {
9151@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9152
9153 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9154 regs->tpc, tl);
9155- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9156+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9157 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9158- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9159+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9160 (void *) regs->u_regs[UREG_I7]);
9161 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9162 "pte[%lx] error[%lx]\n",
9163@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9164
9165 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9166 regs->tpc, tl);
9167- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9168+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9169 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9170- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9171+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9172 (void *) regs->u_regs[UREG_I7]);
9173 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9174 "pte[%lx] error[%lx]\n",
9175@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9176 fp = (unsigned long)sf->fp + STACK_BIAS;
9177 }
9178
9179- printk(" [%016lx] %pS\n", pc, (void *) pc);
9180+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9181 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9182 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9183 int index = tsk->curr_ret_stack;
9184 if (tsk->ret_stack && index >= graph) {
9185 pc = tsk->ret_stack[index - graph].ret;
9186- printk(" [%016lx] %pS\n", pc, (void *) pc);
9187+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9188 graph++;
9189 }
9190 }
9191@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9192 return (struct reg_window *) (fp + STACK_BIAS);
9193 }
9194
9195+extern void gr_handle_kernel_exploit(void);
9196+
9197 void die_if_kernel(char *str, struct pt_regs *regs)
9198 {
9199 static int die_counter;
9200@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9201 while (rw &&
9202 count++ < 30 &&
9203 kstack_valid(tp, (unsigned long) rw)) {
9204- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9205+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9206 (void *) rw->ins[7]);
9207
9208 rw = kernel_stack_up(rw);
9209@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9210 }
9211 user_instruction_dump ((unsigned int __user *) regs->tpc);
9212 }
9213- if (regs->tstate & TSTATE_PRIV)
9214+ if (regs->tstate & TSTATE_PRIV) {
9215+ gr_handle_kernel_exploit();
9216 do_exit(SIGKILL);
9217+ }
9218 do_exit(SIGSEGV);
9219 }
9220 EXPORT_SYMBOL(die_if_kernel);
9221diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
9222index 8201c25e..072a2a7 100644
9223--- a/arch/sparc/kernel/unaligned_64.c
9224+++ b/arch/sparc/kernel/unaligned_64.c
9225@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
9226 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
9227
9228 if (__ratelimit(&ratelimit)) {
9229- printk("Kernel unaligned access at TPC[%lx] %pS\n",
9230+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
9231 regs->tpc, (void *) regs->tpc);
9232 }
9233 }
9234diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
9235index dbe119b..089c7c1 100644
9236--- a/arch/sparc/lib/Makefile
9237+++ b/arch/sparc/lib/Makefile
9238@@ -2,7 +2,7 @@
9239 #
9240
9241 asflags-y := -ansi -DST_DIV0=0x02
9242-ccflags-y := -Werror
9243+#ccflags-y := -Werror
9244
9245 lib-$(CONFIG_SPARC32) += ashrdi3.o
9246 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
9247diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
9248index 85c233d..68500e0 100644
9249--- a/arch/sparc/lib/atomic_64.S
9250+++ b/arch/sparc/lib/atomic_64.S
9251@@ -17,7 +17,12 @@
9252 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9253 BACKOFF_SETUP(%o2)
9254 1: lduw [%o1], %g1
9255- add %g1, %o0, %g7
9256+ addcc %g1, %o0, %g7
9257+
9258+#ifdef CONFIG_PAX_REFCOUNT
9259+ tvs %icc, 6
9260+#endif
9261+
9262 cas [%o1], %g1, %g7
9263 cmp %g1, %g7
9264 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9265@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
9266 2: BACKOFF_SPIN(%o2, %o3, 1b)
9267 ENDPROC(atomic_add)
9268
9269+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9270+ BACKOFF_SETUP(%o2)
9271+1: lduw [%o1], %g1
9272+ add %g1, %o0, %g7
9273+ cas [%o1], %g1, %g7
9274+ cmp %g1, %g7
9275+ bne,pn %icc, 2f
9276+ nop
9277+ retl
9278+ nop
9279+2: BACKOFF_SPIN(%o2, %o3, 1b)
9280+ENDPROC(atomic_add_unchecked)
9281+
9282 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9283 BACKOFF_SETUP(%o2)
9284 1: lduw [%o1], %g1
9285- sub %g1, %o0, %g7
9286+ subcc %g1, %o0, %g7
9287+
9288+#ifdef CONFIG_PAX_REFCOUNT
9289+ tvs %icc, 6
9290+#endif
9291+
9292 cas [%o1], %g1, %g7
9293 cmp %g1, %g7
9294 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9295@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9296 2: BACKOFF_SPIN(%o2, %o3, 1b)
9297 ENDPROC(atomic_sub)
9298
9299+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9300+ BACKOFF_SETUP(%o2)
9301+1: lduw [%o1], %g1
9302+ sub %g1, %o0, %g7
9303+ cas [%o1], %g1, %g7
9304+ cmp %g1, %g7
9305+ bne,pn %icc, 2f
9306+ nop
9307+ retl
9308+ nop
9309+2: BACKOFF_SPIN(%o2, %o3, 1b)
9310+ENDPROC(atomic_sub_unchecked)
9311+
9312 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9313 BACKOFF_SETUP(%o2)
9314 1: lduw [%o1], %g1
9315- add %g1, %o0, %g7
9316+ addcc %g1, %o0, %g7
9317+
9318+#ifdef CONFIG_PAX_REFCOUNT
9319+ tvs %icc, 6
9320+#endif
9321+
9322 cas [%o1], %g1, %g7
9323 cmp %g1, %g7
9324 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9325@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9326 2: BACKOFF_SPIN(%o2, %o3, 1b)
9327 ENDPROC(atomic_add_ret)
9328
9329+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9330+ BACKOFF_SETUP(%o2)
9331+1: lduw [%o1], %g1
9332+ addcc %g1, %o0, %g7
9333+ cas [%o1], %g1, %g7
9334+ cmp %g1, %g7
9335+ bne,pn %icc, 2f
9336+ add %g7, %o0, %g7
9337+ sra %g7, 0, %o0
9338+ retl
9339+ nop
9340+2: BACKOFF_SPIN(%o2, %o3, 1b)
9341+ENDPROC(atomic_add_ret_unchecked)
9342+
9343 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9344 BACKOFF_SETUP(%o2)
9345 1: lduw [%o1], %g1
9346- sub %g1, %o0, %g7
9347+ subcc %g1, %o0, %g7
9348+
9349+#ifdef CONFIG_PAX_REFCOUNT
9350+ tvs %icc, 6
9351+#endif
9352+
9353 cas [%o1], %g1, %g7
9354 cmp %g1, %g7
9355 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9356@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
9357 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9358 BACKOFF_SETUP(%o2)
9359 1: ldx [%o1], %g1
9360- add %g1, %o0, %g7
9361+ addcc %g1, %o0, %g7
9362+
9363+#ifdef CONFIG_PAX_REFCOUNT
9364+ tvs %xcc, 6
9365+#endif
9366+
9367 casx [%o1], %g1, %g7
9368 cmp %g1, %g7
9369 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9370@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9371 2: BACKOFF_SPIN(%o2, %o3, 1b)
9372 ENDPROC(atomic64_add)
9373
9374+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9375+ BACKOFF_SETUP(%o2)
9376+1: ldx [%o1], %g1
9377+ addcc %g1, %o0, %g7
9378+ casx [%o1], %g1, %g7
9379+ cmp %g1, %g7
9380+ bne,pn %xcc, 2f
9381+ nop
9382+ retl
9383+ nop
9384+2: BACKOFF_SPIN(%o2, %o3, 1b)
9385+ENDPROC(atomic64_add_unchecked)
9386+
9387 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9388 BACKOFF_SETUP(%o2)
9389 1: ldx [%o1], %g1
9390- sub %g1, %o0, %g7
9391+ subcc %g1, %o0, %g7
9392+
9393+#ifdef CONFIG_PAX_REFCOUNT
9394+ tvs %xcc, 6
9395+#endif
9396+
9397 casx [%o1], %g1, %g7
9398 cmp %g1, %g7
9399 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9400@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9401 2: BACKOFF_SPIN(%o2, %o3, 1b)
9402 ENDPROC(atomic64_sub)
9403
9404+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9405+ BACKOFF_SETUP(%o2)
9406+1: ldx [%o1], %g1
9407+ subcc %g1, %o0, %g7
9408+ casx [%o1], %g1, %g7
9409+ cmp %g1, %g7
9410+ bne,pn %xcc, 2f
9411+ nop
9412+ retl
9413+ nop
9414+2: BACKOFF_SPIN(%o2, %o3, 1b)
9415+ENDPROC(atomic64_sub_unchecked)
9416+
9417 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9418 BACKOFF_SETUP(%o2)
9419 1: ldx [%o1], %g1
9420- add %g1, %o0, %g7
9421+ addcc %g1, %o0, %g7
9422+
9423+#ifdef CONFIG_PAX_REFCOUNT
9424+ tvs %xcc, 6
9425+#endif
9426+
9427 casx [%o1], %g1, %g7
9428 cmp %g1, %g7
9429 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9430@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9431 2: BACKOFF_SPIN(%o2, %o3, 1b)
9432 ENDPROC(atomic64_add_ret)
9433
9434+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9435+ BACKOFF_SETUP(%o2)
9436+1: ldx [%o1], %g1
9437+ addcc %g1, %o0, %g7
9438+ casx [%o1], %g1, %g7
9439+ cmp %g1, %g7
9440+ bne,pn %xcc, 2f
9441+ add %g7, %o0, %g7
9442+ mov %g7, %o0
9443+ retl
9444+ nop
9445+2: BACKOFF_SPIN(%o2, %o3, 1b)
9446+ENDPROC(atomic64_add_ret_unchecked)
9447+
9448 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9449 BACKOFF_SETUP(%o2)
9450 1: ldx [%o1], %g1
9451- sub %g1, %o0, %g7
9452+ subcc %g1, %o0, %g7
9453+
9454+#ifdef CONFIG_PAX_REFCOUNT
9455+ tvs %xcc, 6
9456+#endif
9457+
9458 casx [%o1], %g1, %g7
9459 cmp %g1, %g7
9460 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9461diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9462index 0c4e35e..745d3e4 100644
9463--- a/arch/sparc/lib/ksyms.c
9464+++ b/arch/sparc/lib/ksyms.c
9465@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9466
9467 /* Atomic counter implementation. */
9468 EXPORT_SYMBOL(atomic_add);
9469+EXPORT_SYMBOL(atomic_add_unchecked);
9470 EXPORT_SYMBOL(atomic_add_ret);
9471+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9472 EXPORT_SYMBOL(atomic_sub);
9473+EXPORT_SYMBOL(atomic_sub_unchecked);
9474 EXPORT_SYMBOL(atomic_sub_ret);
9475 EXPORT_SYMBOL(atomic64_add);
9476+EXPORT_SYMBOL(atomic64_add_unchecked);
9477 EXPORT_SYMBOL(atomic64_add_ret);
9478+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9479 EXPORT_SYMBOL(atomic64_sub);
9480+EXPORT_SYMBOL(atomic64_sub_unchecked);
9481 EXPORT_SYMBOL(atomic64_sub_ret);
9482 EXPORT_SYMBOL(atomic64_dec_if_positive);
9483
9484diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9485index 30c3ecc..736f015 100644
9486--- a/arch/sparc/mm/Makefile
9487+++ b/arch/sparc/mm/Makefile
9488@@ -2,7 +2,7 @@
9489 #
9490
9491 asflags-y := -ansi
9492-ccflags-y := -Werror
9493+#ccflags-y := -Werror
9494
9495 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9496 obj-y += fault_$(BITS).o
9497diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9498index e98bfda..ea8d221 100644
9499--- a/arch/sparc/mm/fault_32.c
9500+++ b/arch/sparc/mm/fault_32.c
9501@@ -21,6 +21,9 @@
9502 #include <linux/perf_event.h>
9503 #include <linux/interrupt.h>
9504 #include <linux/kdebug.h>
9505+#include <linux/slab.h>
9506+#include <linux/pagemap.h>
9507+#include <linux/compiler.h>
9508
9509 #include <asm/page.h>
9510 #include <asm/pgtable.h>
9511@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9512 return safe_compute_effective_address(regs, insn);
9513 }
9514
9515+#ifdef CONFIG_PAX_PAGEEXEC
9516+#ifdef CONFIG_PAX_DLRESOLVE
9517+static void pax_emuplt_close(struct vm_area_struct *vma)
9518+{
9519+ vma->vm_mm->call_dl_resolve = 0UL;
9520+}
9521+
9522+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9523+{
9524+ unsigned int *kaddr;
9525+
9526+ vmf->page = alloc_page(GFP_HIGHUSER);
9527+ if (!vmf->page)
9528+ return VM_FAULT_OOM;
9529+
9530+ kaddr = kmap(vmf->page);
9531+ memset(kaddr, 0, PAGE_SIZE);
9532+ kaddr[0] = 0x9DE3BFA8U; /* save */
9533+ flush_dcache_page(vmf->page);
9534+ kunmap(vmf->page);
9535+ return VM_FAULT_MAJOR;
9536+}
9537+
9538+static const struct vm_operations_struct pax_vm_ops = {
9539+ .close = pax_emuplt_close,
9540+ .fault = pax_emuplt_fault
9541+};
9542+
9543+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9544+{
9545+ int ret;
9546+
9547+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9548+ vma->vm_mm = current->mm;
9549+ vma->vm_start = addr;
9550+ vma->vm_end = addr + PAGE_SIZE;
9551+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9552+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9553+ vma->vm_ops = &pax_vm_ops;
9554+
9555+ ret = insert_vm_struct(current->mm, vma);
9556+ if (ret)
9557+ return ret;
9558+
9559+ ++current->mm->total_vm;
9560+ return 0;
9561+}
9562+#endif
9563+
9564+/*
9565+ * PaX: decide what to do with offenders (regs->pc = fault address)
9566+ *
9567+ * returns 1 when task should be killed
9568+ * 2 when patched PLT trampoline was detected
9569+ * 3 when unpatched PLT trampoline was detected
9570+ */
9571+static int pax_handle_fetch_fault(struct pt_regs *regs)
9572+{
9573+
9574+#ifdef CONFIG_PAX_EMUPLT
9575+ int err;
9576+
9577+ do { /* PaX: patched PLT emulation #1 */
9578+ unsigned int sethi1, sethi2, jmpl;
9579+
9580+ err = get_user(sethi1, (unsigned int *)regs->pc);
9581+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9582+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9583+
9584+ if (err)
9585+ break;
9586+
9587+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9588+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9589+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9590+ {
9591+ unsigned int addr;
9592+
9593+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9594+ addr = regs->u_regs[UREG_G1];
9595+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9596+ regs->pc = addr;
9597+ regs->npc = addr+4;
9598+ return 2;
9599+ }
9600+ } while (0);
9601+
9602+ do { /* PaX: patched PLT emulation #2 */
9603+ unsigned int ba;
9604+
9605+ err = get_user(ba, (unsigned int *)regs->pc);
9606+
9607+ if (err)
9608+ break;
9609+
9610+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9611+ unsigned int addr;
9612+
9613+ if ((ba & 0xFFC00000U) == 0x30800000U)
9614+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9615+ else
9616+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9617+ regs->pc = addr;
9618+ regs->npc = addr+4;
9619+ return 2;
9620+ }
9621+ } while (0);
9622+
9623+ do { /* PaX: patched PLT emulation #3 */
9624+ unsigned int sethi, bajmpl, nop;
9625+
9626+ err = get_user(sethi, (unsigned int *)regs->pc);
9627+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9628+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9629+
9630+ if (err)
9631+ break;
9632+
9633+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9634+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9635+ nop == 0x01000000U)
9636+ {
9637+ unsigned int addr;
9638+
9639+ addr = (sethi & 0x003FFFFFU) << 10;
9640+ regs->u_regs[UREG_G1] = addr;
9641+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9642+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9643+ else
9644+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9645+ regs->pc = addr;
9646+ regs->npc = addr+4;
9647+ return 2;
9648+ }
9649+ } while (0);
9650+
9651+ do { /* PaX: unpatched PLT emulation step 1 */
9652+ unsigned int sethi, ba, nop;
9653+
9654+ err = get_user(sethi, (unsigned int *)regs->pc);
9655+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9656+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9657+
9658+ if (err)
9659+ break;
9660+
9661+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9662+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9663+ nop == 0x01000000U)
9664+ {
9665+ unsigned int addr, save, call;
9666+
9667+ if ((ba & 0xFFC00000U) == 0x30800000U)
9668+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9669+ else
9670+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9671+
9672+ err = get_user(save, (unsigned int *)addr);
9673+ err |= get_user(call, (unsigned int *)(addr+4));
9674+ err |= get_user(nop, (unsigned int *)(addr+8));
9675+ if (err)
9676+ break;
9677+
9678+#ifdef CONFIG_PAX_DLRESOLVE
9679+ if (save == 0x9DE3BFA8U &&
9680+ (call & 0xC0000000U) == 0x40000000U &&
9681+ nop == 0x01000000U)
9682+ {
9683+ struct vm_area_struct *vma;
9684+ unsigned long call_dl_resolve;
9685+
9686+ down_read(&current->mm->mmap_sem);
9687+ call_dl_resolve = current->mm->call_dl_resolve;
9688+ up_read(&current->mm->mmap_sem);
9689+ if (likely(call_dl_resolve))
9690+ goto emulate;
9691+
9692+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9693+
9694+ down_write(&current->mm->mmap_sem);
9695+ if (current->mm->call_dl_resolve) {
9696+ call_dl_resolve = current->mm->call_dl_resolve;
9697+ up_write(&current->mm->mmap_sem);
9698+ if (vma)
9699+ kmem_cache_free(vm_area_cachep, vma);
9700+ goto emulate;
9701+ }
9702+
9703+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9704+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9705+ up_write(&current->mm->mmap_sem);
9706+ if (vma)
9707+ kmem_cache_free(vm_area_cachep, vma);
9708+ return 1;
9709+ }
9710+
9711+ if (pax_insert_vma(vma, call_dl_resolve)) {
9712+ up_write(&current->mm->mmap_sem);
9713+ kmem_cache_free(vm_area_cachep, vma);
9714+ return 1;
9715+ }
9716+
9717+ current->mm->call_dl_resolve = call_dl_resolve;
9718+ up_write(&current->mm->mmap_sem);
9719+
9720+emulate:
9721+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9722+ regs->pc = call_dl_resolve;
9723+ regs->npc = addr+4;
9724+ return 3;
9725+ }
9726+#endif
9727+
9728+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9729+ if ((save & 0xFFC00000U) == 0x05000000U &&
9730+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9731+ nop == 0x01000000U)
9732+ {
9733+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9734+ regs->u_regs[UREG_G2] = addr + 4;
9735+ addr = (save & 0x003FFFFFU) << 10;
9736+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9737+ regs->pc = addr;
9738+ regs->npc = addr+4;
9739+ return 3;
9740+ }
9741+ }
9742+ } while (0);
9743+
9744+ do { /* PaX: unpatched PLT emulation step 2 */
9745+ unsigned int save, call, nop;
9746+
9747+ err = get_user(save, (unsigned int *)(regs->pc-4));
9748+ err |= get_user(call, (unsigned int *)regs->pc);
9749+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9750+ if (err)
9751+ break;
9752+
9753+ if (save == 0x9DE3BFA8U &&
9754+ (call & 0xC0000000U) == 0x40000000U &&
9755+ nop == 0x01000000U)
9756+ {
9757+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9758+
9759+ regs->u_regs[UREG_RETPC] = regs->pc;
9760+ regs->pc = dl_resolve;
9761+ regs->npc = dl_resolve+4;
9762+ return 3;
9763+ }
9764+ } while (0);
9765+#endif
9766+
9767+ return 1;
9768+}
9769+
9770+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9771+{
9772+ unsigned long i;
9773+
9774+ printk(KERN_ERR "PAX: bytes at PC: ");
9775+ for (i = 0; i < 8; i++) {
9776+ unsigned int c;
9777+ if (get_user(c, (unsigned int *)pc+i))
9778+ printk(KERN_CONT "???????? ");
9779+ else
9780+ printk(KERN_CONT "%08x ", c);
9781+ }
9782+ printk("\n");
9783+}
9784+#endif
9785+
9786 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9787 int text_fault)
9788 {
9789@@ -230,6 +504,24 @@ good_area:
9790 if (!(vma->vm_flags & VM_WRITE))
9791 goto bad_area;
9792 } else {
9793+
9794+#ifdef CONFIG_PAX_PAGEEXEC
9795+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9796+ up_read(&mm->mmap_sem);
9797+ switch (pax_handle_fetch_fault(regs)) {
9798+
9799+#ifdef CONFIG_PAX_EMUPLT
9800+ case 2:
9801+ case 3:
9802+ return;
9803+#endif
9804+
9805+ }
9806+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9807+ do_group_exit(SIGKILL);
9808+ }
9809+#endif
9810+
9811 /* Allow reads even for write-only mappings */
9812 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9813 goto bad_area;
9814diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9815index 5062ff3..e0b75f3 100644
9816--- a/arch/sparc/mm/fault_64.c
9817+++ b/arch/sparc/mm/fault_64.c
9818@@ -21,6 +21,9 @@
9819 #include <linux/kprobes.h>
9820 #include <linux/kdebug.h>
9821 #include <linux/percpu.h>
9822+#include <linux/slab.h>
9823+#include <linux/pagemap.h>
9824+#include <linux/compiler.h>
9825
9826 #include <asm/page.h>
9827 #include <asm/pgtable.h>
9828@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9829 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9830 regs->tpc);
9831 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9832- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9833+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9834 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9835 dump_stack();
9836 unhandled_fault(regs->tpc, current, regs);
9837@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9838 show_regs(regs);
9839 }
9840
9841+#ifdef CONFIG_PAX_PAGEEXEC
9842+#ifdef CONFIG_PAX_DLRESOLVE
9843+static void pax_emuplt_close(struct vm_area_struct *vma)
9844+{
9845+ vma->vm_mm->call_dl_resolve = 0UL;
9846+}
9847+
9848+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9849+{
9850+ unsigned int *kaddr;
9851+
9852+ vmf->page = alloc_page(GFP_HIGHUSER);
9853+ if (!vmf->page)
9854+ return VM_FAULT_OOM;
9855+
9856+ kaddr = kmap(vmf->page);
9857+ memset(kaddr, 0, PAGE_SIZE);
9858+ kaddr[0] = 0x9DE3BFA8U; /* save */
9859+ flush_dcache_page(vmf->page);
9860+ kunmap(vmf->page);
9861+ return VM_FAULT_MAJOR;
9862+}
9863+
9864+static const struct vm_operations_struct pax_vm_ops = {
9865+ .close = pax_emuplt_close,
9866+ .fault = pax_emuplt_fault
9867+};
9868+
9869+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9870+{
9871+ int ret;
9872+
9873+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9874+ vma->vm_mm = current->mm;
9875+ vma->vm_start = addr;
9876+ vma->vm_end = addr + PAGE_SIZE;
9877+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9878+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9879+ vma->vm_ops = &pax_vm_ops;
9880+
9881+ ret = insert_vm_struct(current->mm, vma);
9882+ if (ret)
9883+ return ret;
9884+
9885+ ++current->mm->total_vm;
9886+ return 0;
9887+}
9888+#endif
9889+
9890+/*
9891+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9892+ *
9893+ * returns 1 when task should be killed
9894+ * 2 when patched PLT trampoline was detected
9895+ * 3 when unpatched PLT trampoline was detected
9896+ */
9897+static int pax_handle_fetch_fault(struct pt_regs *regs)
9898+{
9899+
9900+#ifdef CONFIG_PAX_EMUPLT
9901+ int err;
9902+
9903+ do { /* PaX: patched PLT emulation #1 */
9904+ unsigned int sethi1, sethi2, jmpl;
9905+
9906+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9907+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9908+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9909+
9910+ if (err)
9911+ break;
9912+
9913+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9914+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9915+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9916+ {
9917+ unsigned long addr;
9918+
9919+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9920+ addr = regs->u_regs[UREG_G1];
9921+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9922+
9923+ if (test_thread_flag(TIF_32BIT))
9924+ addr &= 0xFFFFFFFFUL;
9925+
9926+ regs->tpc = addr;
9927+ regs->tnpc = addr+4;
9928+ return 2;
9929+ }
9930+ } while (0);
9931+
9932+ do { /* PaX: patched PLT emulation #2 */
9933+ unsigned int ba;
9934+
9935+ err = get_user(ba, (unsigned int *)regs->tpc);
9936+
9937+ if (err)
9938+ break;
9939+
9940+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9941+ unsigned long addr;
9942+
9943+ if ((ba & 0xFFC00000U) == 0x30800000U)
9944+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9945+ else
9946+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9947+
9948+ if (test_thread_flag(TIF_32BIT))
9949+ addr &= 0xFFFFFFFFUL;
9950+
9951+ regs->tpc = addr;
9952+ regs->tnpc = addr+4;
9953+ return 2;
9954+ }
9955+ } while (0);
9956+
9957+ do { /* PaX: patched PLT emulation #3 */
9958+ unsigned int sethi, bajmpl, nop;
9959+
9960+ err = get_user(sethi, (unsigned int *)regs->tpc);
9961+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9962+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9963+
9964+ if (err)
9965+ break;
9966+
9967+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9968+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9969+ nop == 0x01000000U)
9970+ {
9971+ unsigned long addr;
9972+
9973+ addr = (sethi & 0x003FFFFFU) << 10;
9974+ regs->u_regs[UREG_G1] = addr;
9975+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9976+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9977+ else
9978+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9979+
9980+ if (test_thread_flag(TIF_32BIT))
9981+ addr &= 0xFFFFFFFFUL;
9982+
9983+ regs->tpc = addr;
9984+ regs->tnpc = addr+4;
9985+ return 2;
9986+ }
9987+ } while (0);
9988+
9989+ do { /* PaX: patched PLT emulation #4 */
9990+ unsigned int sethi, mov1, call, mov2;
9991+
9992+ err = get_user(sethi, (unsigned int *)regs->tpc);
9993+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9994+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9995+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9996+
9997+ if (err)
9998+ break;
9999+
10000+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10001+ mov1 == 0x8210000FU &&
10002+ (call & 0xC0000000U) == 0x40000000U &&
10003+ mov2 == 0x9E100001U)
10004+ {
10005+ unsigned long addr;
10006+
10007+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10008+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10009+
10010+ if (test_thread_flag(TIF_32BIT))
10011+ addr &= 0xFFFFFFFFUL;
10012+
10013+ regs->tpc = addr;
10014+ regs->tnpc = addr+4;
10015+ return 2;
10016+ }
10017+ } while (0);
10018+
10019+ do { /* PaX: patched PLT emulation #5 */
10020+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10021+
10022+ err = get_user(sethi, (unsigned int *)regs->tpc);
10023+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10024+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10025+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10026+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10027+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10028+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10029+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10030+
10031+ if (err)
10032+ break;
10033+
10034+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10035+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10036+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10037+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10038+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10039+ sllx == 0x83287020U &&
10040+ jmpl == 0x81C04005U &&
10041+ nop == 0x01000000U)
10042+ {
10043+ unsigned long addr;
10044+
10045+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10046+ regs->u_regs[UREG_G1] <<= 32;
10047+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10048+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10049+ regs->tpc = addr;
10050+ regs->tnpc = addr+4;
10051+ return 2;
10052+ }
10053+ } while (0);
10054+
10055+ do { /* PaX: patched PLT emulation #6 */
10056+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10057+
10058+ err = get_user(sethi, (unsigned int *)regs->tpc);
10059+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10060+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10061+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10062+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10063+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10064+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10065+
10066+ if (err)
10067+ break;
10068+
10069+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10070+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10071+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10072+ sllx == 0x83287020U &&
10073+ (or & 0xFFFFE000U) == 0x8A116000U &&
10074+ jmpl == 0x81C04005U &&
10075+ nop == 0x01000000U)
10076+ {
10077+ unsigned long addr;
10078+
10079+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10080+ regs->u_regs[UREG_G1] <<= 32;
10081+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10082+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10083+ regs->tpc = addr;
10084+ regs->tnpc = addr+4;
10085+ return 2;
10086+ }
10087+ } while (0);
10088+
10089+ do { /* PaX: unpatched PLT emulation step 1 */
10090+ unsigned int sethi, ba, nop;
10091+
10092+ err = get_user(sethi, (unsigned int *)regs->tpc);
10093+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10094+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10095+
10096+ if (err)
10097+ break;
10098+
10099+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10100+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10101+ nop == 0x01000000U)
10102+ {
10103+ unsigned long addr;
10104+ unsigned int save, call;
10105+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10106+
10107+ if ((ba & 0xFFC00000U) == 0x30800000U)
10108+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10109+ else
10110+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10111+
10112+ if (test_thread_flag(TIF_32BIT))
10113+ addr &= 0xFFFFFFFFUL;
10114+
10115+ err = get_user(save, (unsigned int *)addr);
10116+ err |= get_user(call, (unsigned int *)(addr+4));
10117+ err |= get_user(nop, (unsigned int *)(addr+8));
10118+ if (err)
10119+ break;
10120+
10121+#ifdef CONFIG_PAX_DLRESOLVE
10122+ if (save == 0x9DE3BFA8U &&
10123+ (call & 0xC0000000U) == 0x40000000U &&
10124+ nop == 0x01000000U)
10125+ {
10126+ struct vm_area_struct *vma;
10127+ unsigned long call_dl_resolve;
10128+
10129+ down_read(&current->mm->mmap_sem);
10130+ call_dl_resolve = current->mm->call_dl_resolve;
10131+ up_read(&current->mm->mmap_sem);
10132+ if (likely(call_dl_resolve))
10133+ goto emulate;
10134+
10135+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10136+
10137+ down_write(&current->mm->mmap_sem);
10138+ if (current->mm->call_dl_resolve) {
10139+ call_dl_resolve = current->mm->call_dl_resolve;
10140+ up_write(&current->mm->mmap_sem);
10141+ if (vma)
10142+ kmem_cache_free(vm_area_cachep, vma);
10143+ goto emulate;
10144+ }
10145+
10146+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10147+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10148+ up_write(&current->mm->mmap_sem);
10149+ if (vma)
10150+ kmem_cache_free(vm_area_cachep, vma);
10151+ return 1;
10152+ }
10153+
10154+ if (pax_insert_vma(vma, call_dl_resolve)) {
10155+ up_write(&current->mm->mmap_sem);
10156+ kmem_cache_free(vm_area_cachep, vma);
10157+ return 1;
10158+ }
10159+
10160+ current->mm->call_dl_resolve = call_dl_resolve;
10161+ up_write(&current->mm->mmap_sem);
10162+
10163+emulate:
10164+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10165+ regs->tpc = call_dl_resolve;
10166+ regs->tnpc = addr+4;
10167+ return 3;
10168+ }
10169+#endif
10170+
10171+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10172+ if ((save & 0xFFC00000U) == 0x05000000U &&
10173+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10174+ nop == 0x01000000U)
10175+ {
10176+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10177+ regs->u_regs[UREG_G2] = addr + 4;
10178+ addr = (save & 0x003FFFFFU) << 10;
10179+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10180+
10181+ if (test_thread_flag(TIF_32BIT))
10182+ addr &= 0xFFFFFFFFUL;
10183+
10184+ regs->tpc = addr;
10185+ regs->tnpc = addr+4;
10186+ return 3;
10187+ }
10188+
10189+ /* PaX: 64-bit PLT stub */
10190+ err = get_user(sethi1, (unsigned int *)addr);
10191+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10192+ err |= get_user(or1, (unsigned int *)(addr+8));
10193+ err |= get_user(or2, (unsigned int *)(addr+12));
10194+ err |= get_user(sllx, (unsigned int *)(addr+16));
10195+ err |= get_user(add, (unsigned int *)(addr+20));
10196+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10197+ err |= get_user(nop, (unsigned int *)(addr+28));
10198+ if (err)
10199+ break;
10200+
10201+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10202+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10203+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10204+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10205+ sllx == 0x89293020U &&
10206+ add == 0x8A010005U &&
10207+ jmpl == 0x89C14000U &&
10208+ nop == 0x01000000U)
10209+ {
10210+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10211+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10212+ regs->u_regs[UREG_G4] <<= 32;
10213+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10214+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
10215+ regs->u_regs[UREG_G4] = addr + 24;
10216+ addr = regs->u_regs[UREG_G5];
10217+ regs->tpc = addr;
10218+ regs->tnpc = addr+4;
10219+ return 3;
10220+ }
10221+ }
10222+ } while (0);
10223+
10224+#ifdef CONFIG_PAX_DLRESOLVE
10225+ do { /* PaX: unpatched PLT emulation step 2 */
10226+ unsigned int save, call, nop;
10227+
10228+ err = get_user(save, (unsigned int *)(regs->tpc-4));
10229+ err |= get_user(call, (unsigned int *)regs->tpc);
10230+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
10231+ if (err)
10232+ break;
10233+
10234+ if (save == 0x9DE3BFA8U &&
10235+ (call & 0xC0000000U) == 0x40000000U &&
10236+ nop == 0x01000000U)
10237+ {
10238+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10239+
10240+ if (test_thread_flag(TIF_32BIT))
10241+ dl_resolve &= 0xFFFFFFFFUL;
10242+
10243+ regs->u_regs[UREG_RETPC] = regs->tpc;
10244+ regs->tpc = dl_resolve;
10245+ regs->tnpc = dl_resolve+4;
10246+ return 3;
10247+ }
10248+ } while (0);
10249+#endif
10250+
10251+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
10252+ unsigned int sethi, ba, nop;
10253+
10254+ err = get_user(sethi, (unsigned int *)regs->tpc);
10255+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10256+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10257+
10258+ if (err)
10259+ break;
10260+
10261+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10262+ (ba & 0xFFF00000U) == 0x30600000U &&
10263+ nop == 0x01000000U)
10264+ {
10265+ unsigned long addr;
10266+
10267+ addr = (sethi & 0x003FFFFFU) << 10;
10268+ regs->u_regs[UREG_G1] = addr;
10269+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10270+
10271+ if (test_thread_flag(TIF_32BIT))
10272+ addr &= 0xFFFFFFFFUL;
10273+
10274+ regs->tpc = addr;
10275+ regs->tnpc = addr+4;
10276+ return 2;
10277+ }
10278+ } while (0);
10279+
10280+#endif
10281+
10282+ return 1;
10283+}
10284+
10285+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10286+{
10287+ unsigned long i;
10288+
10289+ printk(KERN_ERR "PAX: bytes at PC: ");
10290+ for (i = 0; i < 8; i++) {
10291+ unsigned int c;
10292+ if (get_user(c, (unsigned int *)pc+i))
10293+ printk(KERN_CONT "???????? ");
10294+ else
10295+ printk(KERN_CONT "%08x ", c);
10296+ }
10297+ printk("\n");
10298+}
10299+#endif
10300+
10301 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
10302 {
10303 struct mm_struct *mm = current->mm;
10304@@ -341,6 +804,29 @@ retry:
10305 if (!vma)
10306 goto bad_area;
10307
10308+#ifdef CONFIG_PAX_PAGEEXEC
10309+ /* PaX: detect ITLB misses on non-exec pages */
10310+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
10311+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
10312+ {
10313+ if (address != regs->tpc)
10314+ goto good_area;
10315+
10316+ up_read(&mm->mmap_sem);
10317+ switch (pax_handle_fetch_fault(regs)) {
10318+
10319+#ifdef CONFIG_PAX_EMUPLT
10320+ case 2:
10321+ case 3:
10322+ return;
10323+#endif
10324+
10325+ }
10326+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
10327+ do_group_exit(SIGKILL);
10328+ }
10329+#endif
10330+
10331 /* Pure DTLB misses do not tell us whether the fault causing
10332 * load/store/atomic was a write or not, it only says that there
10333 * was no match. So in such a case we (carefully) read the
10334diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
10335index d2b5944..d878f3c 100644
10336--- a/arch/sparc/mm/hugetlbpage.c
10337+++ b/arch/sparc/mm/hugetlbpage.c
10338@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10339 unsigned long addr,
10340 unsigned long len,
10341 unsigned long pgoff,
10342- unsigned long flags)
10343+ unsigned long flags,
10344+ unsigned long offset)
10345 {
10346 unsigned long task_size = TASK_SIZE;
10347 struct vm_unmapped_area_info info;
10348@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10349
10350 info.flags = 0;
10351 info.length = len;
10352- info.low_limit = TASK_UNMAPPED_BASE;
10353+ info.low_limit = mm->mmap_base;
10354 info.high_limit = min(task_size, VA_EXCLUDE_START);
10355 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10356 info.align_offset = 0;
10357+ info.threadstack_offset = offset;
10358 addr = vm_unmapped_area(&info);
10359
10360 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10361 VM_BUG_ON(addr != -ENOMEM);
10362 info.low_limit = VA_EXCLUDE_END;
10363+
10364+#ifdef CONFIG_PAX_RANDMMAP
10365+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10366+ info.low_limit += mm->delta_mmap;
10367+#endif
10368+
10369 info.high_limit = task_size;
10370 addr = vm_unmapped_area(&info);
10371 }
10372@@ -58,7 +66,8 @@ static unsigned long
10373 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10374 const unsigned long len,
10375 const unsigned long pgoff,
10376- const unsigned long flags)
10377+ const unsigned long flags,
10378+ const unsigned long offset)
10379 {
10380 struct mm_struct *mm = current->mm;
10381 unsigned long addr = addr0;
10382@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10383 info.high_limit = mm->mmap_base;
10384 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10385 info.align_offset = 0;
10386+ info.threadstack_offset = offset;
10387 addr = vm_unmapped_area(&info);
10388
10389 /*
10390@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10391 VM_BUG_ON(addr != -ENOMEM);
10392 info.flags = 0;
10393 info.low_limit = TASK_UNMAPPED_BASE;
10394+
10395+#ifdef CONFIG_PAX_RANDMMAP
10396+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10397+ info.low_limit += mm->delta_mmap;
10398+#endif
10399+
10400 info.high_limit = STACK_TOP32;
10401 addr = vm_unmapped_area(&info);
10402 }
10403@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10404 struct mm_struct *mm = current->mm;
10405 struct vm_area_struct *vma;
10406 unsigned long task_size = TASK_SIZE;
10407+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10408
10409 if (test_thread_flag(TIF_32BIT))
10410 task_size = STACK_TOP32;
10411@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10412 return addr;
10413 }
10414
10415+#ifdef CONFIG_PAX_RANDMMAP
10416+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10417+#endif
10418+
10419 if (addr) {
10420 addr = ALIGN(addr, HPAGE_SIZE);
10421 vma = find_vma(mm, addr);
10422- if (task_size - len >= addr &&
10423- (!vma || addr + len <= vma->vm_start))
10424+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10425 return addr;
10426 }
10427 if (mm->get_unmapped_area == arch_get_unmapped_area)
10428 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
10429- pgoff, flags);
10430+ pgoff, flags, offset);
10431 else
10432 return hugetlb_get_unmapped_area_topdown(file, addr, len,
10433- pgoff, flags);
10434+ pgoff, flags, offset);
10435 }
10436
10437 pte_t *huge_pte_alloc(struct mm_struct *mm,
10438diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10439index f4500c6..889656c 100644
10440--- a/arch/tile/include/asm/atomic_64.h
10441+++ b/arch/tile/include/asm/atomic_64.h
10442@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10443
10444 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10445
10446+#define atomic64_read_unchecked(v) atomic64_read(v)
10447+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10448+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10449+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10450+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10451+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10452+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10453+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10454+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10455+
10456 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10457 #define smp_mb__before_atomic_dec() smp_mb()
10458 #define smp_mb__after_atomic_dec() smp_mb()
10459diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10460index a9a5299..0fce79e 100644
10461--- a/arch/tile/include/asm/cache.h
10462+++ b/arch/tile/include/asm/cache.h
10463@@ -15,11 +15,12 @@
10464 #ifndef _ASM_TILE_CACHE_H
10465 #define _ASM_TILE_CACHE_H
10466
10467+#include <linux/const.h>
10468 #include <arch/chip.h>
10469
10470 /* bytes per L1 data cache line */
10471 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10472-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10474
10475 /* bytes per L2 cache line */
10476 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10477diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10478index 8a082bc..7a6bf87 100644
10479--- a/arch/tile/include/asm/uaccess.h
10480+++ b/arch/tile/include/asm/uaccess.h
10481@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10482 const void __user *from,
10483 unsigned long n)
10484 {
10485- int sz = __compiletime_object_size(to);
10486+ size_t sz = __compiletime_object_size(to);
10487
10488- if (likely(sz == -1 || sz >= n))
10489+ if (likely(sz == (size_t)-1 || sz >= n))
10490 n = _copy_from_user(to, from, n);
10491 else
10492 copy_from_user_overflow();
10493diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10494index 650ccff..45fe2d6 100644
10495--- a/arch/tile/mm/hugetlbpage.c
10496+++ b/arch/tile/mm/hugetlbpage.c
10497@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10498 info.high_limit = TASK_SIZE;
10499 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10500 info.align_offset = 0;
10501+ info.threadstack_offset = 0;
10502 return vm_unmapped_area(&info);
10503 }
10504
10505@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10506 info.high_limit = current->mm->mmap_base;
10507 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10508 info.align_offset = 0;
10509+ info.threadstack_offset = 0;
10510 addr = vm_unmapped_area(&info);
10511
10512 /*
10513diff --git a/arch/um/Makefile b/arch/um/Makefile
10514index 133f7de..1d6f2f1 100644
10515--- a/arch/um/Makefile
10516+++ b/arch/um/Makefile
10517@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10518 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10519 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10520
10521+ifdef CONSTIFY_PLUGIN
10522+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10523+endif
10524+
10525 #This will adjust *FLAGS accordingly to the platform.
10526 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10527
10528diff --git a/arch/um/defconfig b/arch/um/defconfig
10529index 08107a7..ab22afe 100644
10530--- a/arch/um/defconfig
10531+++ b/arch/um/defconfig
10532@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10533 CONFIG_X86_L1_CACHE_SHIFT=5
10534 CONFIG_X86_XADD=y
10535 CONFIG_X86_PPRO_FENCE=y
10536-CONFIG_X86_WP_WORKS_OK=y
10537 CONFIG_X86_INVLPG=y
10538 CONFIG_X86_BSWAP=y
10539 CONFIG_X86_POPAD_OK=y
10540diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10541index 19e1bdd..3665b77 100644
10542--- a/arch/um/include/asm/cache.h
10543+++ b/arch/um/include/asm/cache.h
10544@@ -1,6 +1,7 @@
10545 #ifndef __UM_CACHE_H
10546 #define __UM_CACHE_H
10547
10548+#include <linux/const.h>
10549
10550 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10551 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10552@@ -12,6 +13,6 @@
10553 # define L1_CACHE_SHIFT 5
10554 #endif
10555
10556-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10557+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10558
10559 #endif
10560diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10561index 2e0a6b1..a64d0f5 100644
10562--- a/arch/um/include/asm/kmap_types.h
10563+++ b/arch/um/include/asm/kmap_types.h
10564@@ -8,6 +8,6 @@
10565
10566 /* No more #include "asm/arch/kmap_types.h" ! */
10567
10568-#define KM_TYPE_NR 14
10569+#define KM_TYPE_NR 15
10570
10571 #endif
10572diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10573index 5ff53d9..5850cdf 100644
10574--- a/arch/um/include/asm/page.h
10575+++ b/arch/um/include/asm/page.h
10576@@ -14,6 +14,9 @@
10577 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10578 #define PAGE_MASK (~(PAGE_SIZE-1))
10579
10580+#define ktla_ktva(addr) (addr)
10581+#define ktva_ktla(addr) (addr)
10582+
10583 #ifndef __ASSEMBLY__
10584
10585 struct page;
10586diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10587index 0032f92..cd151e0 100644
10588--- a/arch/um/include/asm/pgtable-3level.h
10589+++ b/arch/um/include/asm/pgtable-3level.h
10590@@ -58,6 +58,7 @@
10591 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10592 #define pud_populate(mm, pud, pmd) \
10593 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10594+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10595
10596 #ifdef CONFIG_64BIT
10597 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10598diff --git a/arch/um/include/asm/tlb.h b/arch/um/include/asm/tlb.h
10599index 4febacd..29b0301 100644
10600--- a/arch/um/include/asm/tlb.h
10601+++ b/arch/um/include/asm/tlb.h
10602@@ -45,10 +45,12 @@ static inline void init_tlb_gather(struct mmu_gather *tlb)
10603 }
10604
10605 static inline void
10606-tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int full_mm_flush)
10607+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
10608 {
10609 tlb->mm = mm;
10610- tlb->fullmm = full_mm_flush;
10611+ tlb->start = start;
10612+ tlb->end = end;
10613+ tlb->fullmm = !(start | (end+1));
10614
10615 init_tlb_gather(tlb);
10616 }
10617diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10618index bbcef52..6a2a483 100644
10619--- a/arch/um/kernel/process.c
10620+++ b/arch/um/kernel/process.c
10621@@ -367,22 +367,6 @@ int singlestepping(void * t)
10622 return 2;
10623 }
10624
10625-/*
10626- * Only x86 and x86_64 have an arch_align_stack().
10627- * All other arches have "#define arch_align_stack(x) (x)"
10628- * in their asm/system.h
10629- * As this is included in UML from asm-um/system-generic.h,
10630- * we can use it to behave as the subarch does.
10631- */
10632-#ifndef arch_align_stack
10633-unsigned long arch_align_stack(unsigned long sp)
10634-{
10635- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10636- sp -= get_random_int() % 8192;
10637- return sp & ~0xf;
10638-}
10639-#endif
10640-
10641 unsigned long get_wchan(struct task_struct *p)
10642 {
10643 unsigned long stack_page, sp, ip;
10644diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10645index ad8f795..2c7eec6 100644
10646--- a/arch/unicore32/include/asm/cache.h
10647+++ b/arch/unicore32/include/asm/cache.h
10648@@ -12,8 +12,10 @@
10649 #ifndef __UNICORE_CACHE_H__
10650 #define __UNICORE_CACHE_H__
10651
10652-#define L1_CACHE_SHIFT (5)
10653-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10654+#include <linux/const.h>
10655+
10656+#define L1_CACHE_SHIFT 5
10657+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10658
10659 /*
10660 * Memory returned by kmalloc() may be used for DMA, so we must make
10661diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10662index fe120da..24177f7 100644
10663--- a/arch/x86/Kconfig
10664+++ b/arch/x86/Kconfig
10665@@ -239,7 +239,7 @@ config X86_HT
10666
10667 config X86_32_LAZY_GS
10668 def_bool y
10669- depends on X86_32 && !CC_STACKPROTECTOR
10670+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10671
10672 config ARCH_HWEIGHT_CFLAGS
10673 string
10674@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
10675
10676 config X86_MSR
10677 tristate "/dev/cpu/*/msr - Model-specific register support"
10678+ depends on !GRKERNSEC_KMEM
10679 ---help---
10680 This device gives privileged processes access to the x86
10681 Model-Specific Registers (MSRs). It is a character device with
10682@@ -1096,7 +1097,7 @@ choice
10683
10684 config NOHIGHMEM
10685 bool "off"
10686- depends on !X86_NUMAQ
10687+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10688 ---help---
10689 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10690 However, the address space of 32-bit x86 processors is only 4
10691@@ -1133,7 +1134,7 @@ config NOHIGHMEM
10692
10693 config HIGHMEM4G
10694 bool "4GB"
10695- depends on !X86_NUMAQ
10696+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10697 ---help---
10698 Select this if you have a 32-bit processor and between 1 and 4
10699 gigabytes of physical RAM.
10700@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
10701 hex
10702 default 0xB0000000 if VMSPLIT_3G_OPT
10703 default 0x80000000 if VMSPLIT_2G
10704- default 0x78000000 if VMSPLIT_2G_OPT
10705+ default 0x70000000 if VMSPLIT_2G_OPT
10706 default 0x40000000 if VMSPLIT_1G
10707 default 0xC0000000
10708 depends on X86_32
10709@@ -1584,6 +1585,7 @@ config SECCOMP
10710
10711 config CC_STACKPROTECTOR
10712 bool "Enable -fstack-protector buffer overflow detection"
10713+ depends on X86_64 || !PAX_MEMORY_UDEREF
10714 ---help---
10715 This option turns on the -fstack-protector GCC feature. This
10716 feature puts, at the beginning of functions, a canary value on
10717@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
10718 config PHYSICAL_ALIGN
10719 hex "Alignment value to which kernel should be aligned" if X86_32
10720 default "0x1000000"
10721+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10722+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10723 range 0x2000 0x1000000
10724 ---help---
10725 This value puts the alignment restrictions on physical address
10726@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
10727 If unsure, say N.
10728
10729 config COMPAT_VDSO
10730- def_bool y
10731+ def_bool n
10732 prompt "Compat VDSO support"
10733 depends on X86_32 || IA32_EMULATION
10734+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10735 ---help---
10736 Map the 32-bit VDSO to the predictable old-style address too.
10737
10738diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10739index c026cca..14657ae 100644
10740--- a/arch/x86/Kconfig.cpu
10741+++ b/arch/x86/Kconfig.cpu
10742@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10743
10744 config X86_F00F_BUG
10745 def_bool y
10746- depends on M586MMX || M586TSC || M586 || M486
10747+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10748
10749 config X86_INVD_BUG
10750 def_bool y
10751@@ -327,7 +327,7 @@ config X86_INVD_BUG
10752
10753 config X86_ALIGNMENT_16
10754 def_bool y
10755- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10756+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10757
10758 config X86_INTEL_USERCOPY
10759 def_bool y
10760@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10761 # generates cmov.
10762 config X86_CMOV
10763 def_bool y
10764- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10765+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10766
10767 config X86_MINIMUM_CPU_FAMILY
10768 int
10769diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10770index c198b7e..63eea60 100644
10771--- a/arch/x86/Kconfig.debug
10772+++ b/arch/x86/Kconfig.debug
10773@@ -84,7 +84,7 @@ config X86_PTDUMP
10774 config DEBUG_RODATA
10775 bool "Write protect kernel read-only data structures"
10776 default y
10777- depends on DEBUG_KERNEL
10778+ depends on DEBUG_KERNEL && BROKEN
10779 ---help---
10780 Mark the kernel read-only data as write-protected in the pagetables,
10781 in order to catch accidental (and incorrect) writes to such const
10782@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10783
10784 config DEBUG_SET_MODULE_RONX
10785 bool "Set loadable kernel module data as NX and text as RO"
10786- depends on MODULES
10787+ depends on MODULES && BROKEN
10788 ---help---
10789 This option helps catch unintended modifications to loadable
10790 kernel module's text and read-only data. It also prevents execution
10791diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10792index 5c47726..8c4fa67 100644
10793--- a/arch/x86/Makefile
10794+++ b/arch/x86/Makefile
10795@@ -54,6 +54,7 @@ else
10796 UTS_MACHINE := x86_64
10797 CHECKFLAGS += -D__x86_64__ -m64
10798
10799+ biarch := $(call cc-option,-m64)
10800 KBUILD_AFLAGS += -m64
10801 KBUILD_CFLAGS += -m64
10802
10803@@ -234,3 +235,12 @@ define archhelp
10804 echo ' FDARGS="..." arguments for the booted kernel'
10805 echo ' FDINITRD=file initrd for the booted kernel'
10806 endef
10807+
10808+define OLD_LD
10809+
10810+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10811+*** Please upgrade your binutils to 2.18 or newer
10812+endef
10813+
10814+archprepare:
10815+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10816diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10817index 379814b..add62ce 100644
10818--- a/arch/x86/boot/Makefile
10819+++ b/arch/x86/boot/Makefile
10820@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10821 $(call cc-option, -fno-stack-protector) \
10822 $(call cc-option, -mpreferred-stack-boundary=2)
10823 KBUILD_CFLAGS += $(call cc-option, -m32)
10824+ifdef CONSTIFY_PLUGIN
10825+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10826+endif
10827 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10828 GCOV_PROFILE := n
10829
10830diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10831index 878e4b9..20537ab 100644
10832--- a/arch/x86/boot/bitops.h
10833+++ b/arch/x86/boot/bitops.h
10834@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10835 u8 v;
10836 const u32 *p = (const u32 *)addr;
10837
10838- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10839+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10840 return v;
10841 }
10842
10843@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10844
10845 static inline void set_bit(int nr, void *addr)
10846 {
10847- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10848+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10849 }
10850
10851 #endif /* BOOT_BITOPS_H */
10852diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10853index 5b75319..331a4ca 100644
10854--- a/arch/x86/boot/boot.h
10855+++ b/arch/x86/boot/boot.h
10856@@ -85,7 +85,7 @@ static inline void io_delay(void)
10857 static inline u16 ds(void)
10858 {
10859 u16 seg;
10860- asm("movw %%ds,%0" : "=rm" (seg));
10861+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10862 return seg;
10863 }
10864
10865@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10866 static inline int memcmp(const void *s1, const void *s2, size_t len)
10867 {
10868 u8 diff;
10869- asm("repe; cmpsb; setnz %0"
10870+ asm volatile("repe; cmpsb; setnz %0"
10871 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10872 return diff;
10873 }
10874diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10875index 5ef205c..342191d 100644
10876--- a/arch/x86/boot/compressed/Makefile
10877+++ b/arch/x86/boot/compressed/Makefile
10878@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10879 KBUILD_CFLAGS += $(cflags-y)
10880 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10881 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10882+ifdef CONSTIFY_PLUGIN
10883+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10884+endif
10885
10886 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10887 GCOV_PROFILE := n
10888diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10889index d606463..b887794 100644
10890--- a/arch/x86/boot/compressed/eboot.c
10891+++ b/arch/x86/boot/compressed/eboot.c
10892@@ -150,7 +150,6 @@ again:
10893 *addr = max_addr;
10894 }
10895
10896-free_pool:
10897 efi_call_phys1(sys_table->boottime->free_pool, map);
10898
10899 fail:
10900@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10901 if (i == map_size / desc_size)
10902 status = EFI_NOT_FOUND;
10903
10904-free_pool:
10905 efi_call_phys1(sys_table->boottime->free_pool, map);
10906 fail:
10907 return status;
10908diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10909index a53440e..c3dbf1e 100644
10910--- a/arch/x86/boot/compressed/efi_stub_32.S
10911+++ b/arch/x86/boot/compressed/efi_stub_32.S
10912@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10913 * parameter 2, ..., param n. To make things easy, we save the return
10914 * address of efi_call_phys in a global variable.
10915 */
10916- popl %ecx
10917- movl %ecx, saved_return_addr(%edx)
10918- /* get the function pointer into ECX*/
10919- popl %ecx
10920- movl %ecx, efi_rt_function_ptr(%edx)
10921+ popl saved_return_addr(%edx)
10922+ popl efi_rt_function_ptr(%edx)
10923
10924 /*
10925 * 3. Call the physical function.
10926 */
10927- call *%ecx
10928+ call *efi_rt_function_ptr(%edx)
10929
10930 /*
10931 * 4. Balance the stack. And because EAX contain the return value,
10932@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10933 1: popl %edx
10934 subl $1b, %edx
10935
10936- movl efi_rt_function_ptr(%edx), %ecx
10937- pushl %ecx
10938+ pushl efi_rt_function_ptr(%edx)
10939
10940 /*
10941 * 10. Push the saved return address onto the stack and return.
10942 */
10943- movl saved_return_addr(%edx), %ecx
10944- pushl %ecx
10945- ret
10946+ jmpl *saved_return_addr(%edx)
10947 ENDPROC(efi_call_phys)
10948 .previous
10949
10950diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10951index 1e3184f..0d11e2e 100644
10952--- a/arch/x86/boot/compressed/head_32.S
10953+++ b/arch/x86/boot/compressed/head_32.S
10954@@ -118,7 +118,7 @@ preferred_addr:
10955 notl %eax
10956 andl %eax, %ebx
10957 #else
10958- movl $LOAD_PHYSICAL_ADDR, %ebx
10959+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10960 #endif
10961
10962 /* Target address to relocate to for decompression */
10963@@ -204,7 +204,7 @@ relocated:
10964 * and where it was actually loaded.
10965 */
10966 movl %ebp, %ebx
10967- subl $LOAD_PHYSICAL_ADDR, %ebx
10968+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10969 jz 2f /* Nothing to be done if loaded at compiled addr. */
10970 /*
10971 * Process relocations.
10972@@ -212,8 +212,7 @@ relocated:
10973
10974 1: subl $4, %edi
10975 movl (%edi), %ecx
10976- testl %ecx, %ecx
10977- jz 2f
10978+ jecxz 2f
10979 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10980 jmp 1b
10981 2:
10982diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10983index 16f24e6..47491a3 100644
10984--- a/arch/x86/boot/compressed/head_64.S
10985+++ b/arch/x86/boot/compressed/head_64.S
10986@@ -97,7 +97,7 @@ ENTRY(startup_32)
10987 notl %eax
10988 andl %eax, %ebx
10989 #else
10990- movl $LOAD_PHYSICAL_ADDR, %ebx
10991+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10992 #endif
10993
10994 /* Target address to relocate to for decompression */
10995@@ -272,7 +272,7 @@ preferred_addr:
10996 notq %rax
10997 andq %rax, %rbp
10998 #else
10999- movq $LOAD_PHYSICAL_ADDR, %rbp
11000+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11001 #endif
11002
11003 /* Target address to relocate to for decompression */
11004@@ -363,8 +363,8 @@ gdt:
11005 .long gdt
11006 .word 0
11007 .quad 0x0000000000000000 /* NULL descriptor */
11008- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11009- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11010+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11011+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11012 .quad 0x0080890000000000 /* TS descriptor */
11013 .quad 0x0000000000000000 /* TS continued */
11014 gdt_end:
11015diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11016index 7cb56c6..d382d84 100644
11017--- a/arch/x86/boot/compressed/misc.c
11018+++ b/arch/x86/boot/compressed/misc.c
11019@@ -303,7 +303,7 @@ static void parse_elf(void *output)
11020 case PT_LOAD:
11021 #ifdef CONFIG_RELOCATABLE
11022 dest = output;
11023- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11024+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11025 #else
11026 dest = (void *)(phdr->p_paddr);
11027 #endif
11028@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11029 error("Destination address too large");
11030 #endif
11031 #ifndef CONFIG_RELOCATABLE
11032- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11033+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11034 error("Wrong destination address");
11035 #endif
11036
11037diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11038index 4d3ff03..e4972ff 100644
11039--- a/arch/x86/boot/cpucheck.c
11040+++ b/arch/x86/boot/cpucheck.c
11041@@ -74,7 +74,7 @@ static int has_fpu(void)
11042 u16 fcw = -1, fsw = -1;
11043 u32 cr0;
11044
11045- asm("movl %%cr0,%0" : "=r" (cr0));
11046+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11047 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11048 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11049 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11050@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11051 {
11052 u32 f0, f1;
11053
11054- asm("pushfl ; "
11055+ asm volatile("pushfl ; "
11056 "pushfl ; "
11057 "popl %0 ; "
11058 "movl %0,%1 ; "
11059@@ -115,7 +115,7 @@ static void get_flags(void)
11060 set_bit(X86_FEATURE_FPU, cpu.flags);
11061
11062 if (has_eflag(X86_EFLAGS_ID)) {
11063- asm("cpuid"
11064+ asm volatile("cpuid"
11065 : "=a" (max_intel_level),
11066 "=b" (cpu_vendor[0]),
11067 "=d" (cpu_vendor[1]),
11068@@ -124,7 +124,7 @@ static void get_flags(void)
11069
11070 if (max_intel_level >= 0x00000001 &&
11071 max_intel_level <= 0x0000ffff) {
11072- asm("cpuid"
11073+ asm volatile("cpuid"
11074 : "=a" (tfms),
11075 "=c" (cpu.flags[4]),
11076 "=d" (cpu.flags[0])
11077@@ -136,7 +136,7 @@ static void get_flags(void)
11078 cpu.model += ((tfms >> 16) & 0xf) << 4;
11079 }
11080
11081- asm("cpuid"
11082+ asm volatile("cpuid"
11083 : "=a" (max_amd_level)
11084 : "a" (0x80000000)
11085 : "ebx", "ecx", "edx");
11086@@ -144,7 +144,7 @@ static void get_flags(void)
11087 if (max_amd_level >= 0x80000001 &&
11088 max_amd_level <= 0x8000ffff) {
11089 u32 eax = 0x80000001;
11090- asm("cpuid"
11091+ asm volatile("cpuid"
11092 : "+a" (eax),
11093 "=c" (cpu.flags[6]),
11094 "=d" (cpu.flags[1])
11095@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11096 u32 ecx = MSR_K7_HWCR;
11097 u32 eax, edx;
11098
11099- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11100+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11101 eax &= ~(1 << 15);
11102- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11103+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11104
11105 get_flags(); /* Make sure it really did something */
11106 err = check_flags();
11107@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11108 u32 ecx = MSR_VIA_FCR;
11109 u32 eax, edx;
11110
11111- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11112+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11113 eax |= (1<<1)|(1<<7);
11114- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11115+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11116
11117 set_bit(X86_FEATURE_CX8, cpu.flags);
11118 err = check_flags();
11119@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11120 u32 eax, edx;
11121 u32 level = 1;
11122
11123- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11124- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11125- asm("cpuid"
11126+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11127+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11128+ asm volatile("cpuid"
11129 : "+a" (level), "=d" (cpu.flags[0])
11130 : : "ecx", "ebx");
11131- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11132+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11133
11134 err = check_flags();
11135 }
11136diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11137index 9ec06a1..2c25e79 100644
11138--- a/arch/x86/boot/header.S
11139+++ b/arch/x86/boot/header.S
11140@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11141 # single linked list of
11142 # struct setup_data
11143
11144-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11145+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
11146
11147 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
11148+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11149+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
11150+#else
11151 #define VO_INIT_SIZE (VO__end - VO__text)
11152+#endif
11153 #if ZO_INIT_SIZE > VO_INIT_SIZE
11154 #define INIT_SIZE ZO_INIT_SIZE
11155 #else
11156diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
11157index db75d07..8e6d0af 100644
11158--- a/arch/x86/boot/memory.c
11159+++ b/arch/x86/boot/memory.c
11160@@ -19,7 +19,7 @@
11161
11162 static int detect_memory_e820(void)
11163 {
11164- int count = 0;
11165+ unsigned int count = 0;
11166 struct biosregs ireg, oreg;
11167 struct e820entry *desc = boot_params.e820_map;
11168 static struct e820entry buf; /* static so it is zeroed */
11169diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
11170index 11e8c6e..fdbb1ed 100644
11171--- a/arch/x86/boot/video-vesa.c
11172+++ b/arch/x86/boot/video-vesa.c
11173@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
11174
11175 boot_params.screen_info.vesapm_seg = oreg.es;
11176 boot_params.screen_info.vesapm_off = oreg.di;
11177+ boot_params.screen_info.vesapm_size = oreg.cx;
11178 }
11179
11180 /*
11181diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
11182index 43eda28..5ab5fdb 100644
11183--- a/arch/x86/boot/video.c
11184+++ b/arch/x86/boot/video.c
11185@@ -96,7 +96,7 @@ static void store_mode_params(void)
11186 static unsigned int get_entry(void)
11187 {
11188 char entry_buf[4];
11189- int i, len = 0;
11190+ unsigned int i, len = 0;
11191 int key;
11192 unsigned int v;
11193
11194diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
11195index 9105655..5e37f27 100644
11196--- a/arch/x86/crypto/aes-x86_64-asm_64.S
11197+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
11198@@ -8,6 +8,8 @@
11199 * including this sentence is retained in full.
11200 */
11201
11202+#include <asm/alternative-asm.h>
11203+
11204 .extern crypto_ft_tab
11205 .extern crypto_it_tab
11206 .extern crypto_fl_tab
11207@@ -70,6 +72,8 @@
11208 je B192; \
11209 leaq 32(r9),r9;
11210
11211+#define ret pax_force_retaddr 0, 1; ret
11212+
11213 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
11214 movq r1,r2; \
11215 movq r3,r4; \
11216diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
11217index 477e9d7..3ab339f 100644
11218--- a/arch/x86/crypto/aesni-intel_asm.S
11219+++ b/arch/x86/crypto/aesni-intel_asm.S
11220@@ -31,6 +31,7 @@
11221
11222 #include <linux/linkage.h>
11223 #include <asm/inst.h>
11224+#include <asm/alternative-asm.h>
11225
11226 #ifdef __x86_64__
11227 .data
11228@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
11229 pop %r14
11230 pop %r13
11231 pop %r12
11232+ pax_force_retaddr 0, 1
11233 ret
11234 ENDPROC(aesni_gcm_dec)
11235
11236@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
11237 pop %r14
11238 pop %r13
11239 pop %r12
11240+ pax_force_retaddr 0, 1
11241 ret
11242 ENDPROC(aesni_gcm_enc)
11243
11244@@ -1722,6 +1725,7 @@ _key_expansion_256a:
11245 pxor %xmm1, %xmm0
11246 movaps %xmm0, (TKEYP)
11247 add $0x10, TKEYP
11248+ pax_force_retaddr_bts
11249 ret
11250 ENDPROC(_key_expansion_128)
11251 ENDPROC(_key_expansion_256a)
11252@@ -1748,6 +1752,7 @@ _key_expansion_192a:
11253 shufps $0b01001110, %xmm2, %xmm1
11254 movaps %xmm1, 0x10(TKEYP)
11255 add $0x20, TKEYP
11256+ pax_force_retaddr_bts
11257 ret
11258 ENDPROC(_key_expansion_192a)
11259
11260@@ -1768,6 +1773,7 @@ _key_expansion_192b:
11261
11262 movaps %xmm0, (TKEYP)
11263 add $0x10, TKEYP
11264+ pax_force_retaddr_bts
11265 ret
11266 ENDPROC(_key_expansion_192b)
11267
11268@@ -1781,6 +1787,7 @@ _key_expansion_256b:
11269 pxor %xmm1, %xmm2
11270 movaps %xmm2, (TKEYP)
11271 add $0x10, TKEYP
11272+ pax_force_retaddr_bts
11273 ret
11274 ENDPROC(_key_expansion_256b)
11275
11276@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
11277 #ifndef __x86_64__
11278 popl KEYP
11279 #endif
11280+ pax_force_retaddr 0, 1
11281 ret
11282 ENDPROC(aesni_set_key)
11283
11284@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
11285 popl KLEN
11286 popl KEYP
11287 #endif
11288+ pax_force_retaddr 0, 1
11289 ret
11290 ENDPROC(aesni_enc)
11291
11292@@ -1974,6 +1983,7 @@ _aesni_enc1:
11293 AESENC KEY STATE
11294 movaps 0x70(TKEYP), KEY
11295 AESENCLAST KEY STATE
11296+ pax_force_retaddr_bts
11297 ret
11298 ENDPROC(_aesni_enc1)
11299
11300@@ -2083,6 +2093,7 @@ _aesni_enc4:
11301 AESENCLAST KEY STATE2
11302 AESENCLAST KEY STATE3
11303 AESENCLAST KEY STATE4
11304+ pax_force_retaddr_bts
11305 ret
11306 ENDPROC(_aesni_enc4)
11307
11308@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
11309 popl KLEN
11310 popl KEYP
11311 #endif
11312+ pax_force_retaddr 0, 1
11313 ret
11314 ENDPROC(aesni_dec)
11315
11316@@ -2164,6 +2176,7 @@ _aesni_dec1:
11317 AESDEC KEY STATE
11318 movaps 0x70(TKEYP), KEY
11319 AESDECLAST KEY STATE
11320+ pax_force_retaddr_bts
11321 ret
11322 ENDPROC(_aesni_dec1)
11323
11324@@ -2273,6 +2286,7 @@ _aesni_dec4:
11325 AESDECLAST KEY STATE2
11326 AESDECLAST KEY STATE3
11327 AESDECLAST KEY STATE4
11328+ pax_force_retaddr_bts
11329 ret
11330 ENDPROC(_aesni_dec4)
11331
11332@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
11333 popl KEYP
11334 popl LEN
11335 #endif
11336+ pax_force_retaddr 0, 1
11337 ret
11338 ENDPROC(aesni_ecb_enc)
11339
11340@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
11341 popl KEYP
11342 popl LEN
11343 #endif
11344+ pax_force_retaddr 0, 1
11345 ret
11346 ENDPROC(aesni_ecb_dec)
11347
11348@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
11349 popl LEN
11350 popl IVP
11351 #endif
11352+ pax_force_retaddr 0, 1
11353 ret
11354 ENDPROC(aesni_cbc_enc)
11355
11356@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
11357 popl LEN
11358 popl IVP
11359 #endif
11360+ pax_force_retaddr 0, 1
11361 ret
11362 ENDPROC(aesni_cbc_dec)
11363
11364@@ -2550,6 +2568,7 @@ _aesni_inc_init:
11365 mov $1, TCTR_LOW
11366 MOVQ_R64_XMM TCTR_LOW INC
11367 MOVQ_R64_XMM CTR TCTR_LOW
11368+ pax_force_retaddr_bts
11369 ret
11370 ENDPROC(_aesni_inc_init)
11371
11372@@ -2579,6 +2598,7 @@ _aesni_inc:
11373 .Linc_low:
11374 movaps CTR, IV
11375 PSHUFB_XMM BSWAP_MASK IV
11376+ pax_force_retaddr_bts
11377 ret
11378 ENDPROC(_aesni_inc)
11379
11380@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
11381 .Lctr_enc_ret:
11382 movups IV, (IVP)
11383 .Lctr_enc_just_ret:
11384+ pax_force_retaddr 0, 1
11385 ret
11386 ENDPROC(aesni_ctr_enc)
11387
11388@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
11389 pxor INC, STATE4
11390 movdqu STATE4, 0x70(OUTP)
11391
11392+ pax_force_retaddr 0, 1
11393 ret
11394 ENDPROC(aesni_xts_crypt8)
11395
11396diff --git a/arch/x86/crypto/blowfish-avx2-asm_64.S b/arch/x86/crypto/blowfish-avx2-asm_64.S
11397index 784452e..46982c7 100644
11398--- a/arch/x86/crypto/blowfish-avx2-asm_64.S
11399+++ b/arch/x86/crypto/blowfish-avx2-asm_64.S
11400@@ -221,6 +221,7 @@ __blowfish_enc_blk32:
11401
11402 write_block(RXl, RXr);
11403
11404+ pax_force_retaddr 0, 1
11405 ret;
11406 ENDPROC(__blowfish_enc_blk32)
11407
11408@@ -250,6 +251,7 @@ __blowfish_dec_blk32:
11409
11410 write_block(RXl, RXr);
11411
11412+ pax_force_retaddr 0, 1
11413 ret;
11414 ENDPROC(__blowfish_dec_blk32)
11415
11416@@ -284,6 +286,7 @@ ENTRY(blowfish_ecb_enc_32way)
11417
11418 vzeroupper;
11419
11420+ pax_force_retaddr 0, 1
11421 ret;
11422 ENDPROC(blowfish_ecb_enc_32way)
11423
11424@@ -318,6 +321,7 @@ ENTRY(blowfish_ecb_dec_32way)
11425
11426 vzeroupper;
11427
11428+ pax_force_retaddr 0, 1
11429 ret;
11430 ENDPROC(blowfish_ecb_dec_32way)
11431
11432@@ -365,6 +369,7 @@ ENTRY(blowfish_cbc_dec_32way)
11433
11434 vzeroupper;
11435
11436+ pax_force_retaddr 0, 1
11437 ret;
11438 ENDPROC(blowfish_cbc_dec_32way)
11439
11440@@ -445,5 +450,6 @@ ENTRY(blowfish_ctr_32way)
11441
11442 vzeroupper;
11443
11444+ pax_force_retaddr 0, 1
11445 ret;
11446 ENDPROC(blowfish_ctr_32way)
11447diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11448index 246c670..4d1ed00 100644
11449--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
11450+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
11451@@ -21,6 +21,7 @@
11452 */
11453
11454 #include <linux/linkage.h>
11455+#include <asm/alternative-asm.h>
11456
11457 .file "blowfish-x86_64-asm.S"
11458 .text
11459@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
11460 jnz .L__enc_xor;
11461
11462 write_block();
11463+ pax_force_retaddr 0, 1
11464 ret;
11465 .L__enc_xor:
11466 xor_block();
11467+ pax_force_retaddr 0, 1
11468 ret;
11469 ENDPROC(__blowfish_enc_blk)
11470
11471@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
11472
11473 movq %r11, %rbp;
11474
11475+ pax_force_retaddr 0, 1
11476 ret;
11477 ENDPROC(blowfish_dec_blk)
11478
11479@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
11480
11481 popq %rbx;
11482 popq %rbp;
11483+ pax_force_retaddr 0, 1
11484 ret;
11485
11486 .L__enc_xor4:
11487@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
11488
11489 popq %rbx;
11490 popq %rbp;
11491+ pax_force_retaddr 0, 1
11492 ret;
11493 ENDPROC(__blowfish_enc_blk_4way)
11494
11495@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
11496 popq %rbx;
11497 popq %rbp;
11498
11499+ pax_force_retaddr 0, 1
11500 ret;
11501 ENDPROC(blowfish_dec_blk_4way)
11502diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
11503index ce71f92..2dd5b1e 100644
11504--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
11505+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
11506@@ -16,6 +16,7 @@
11507 */
11508
11509 #include <linux/linkage.h>
11510+#include <asm/alternative-asm.h>
11511
11512 #define CAMELLIA_TABLE_BYTE_LEN 272
11513
11514@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
11515 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
11516 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
11517 %rcx, (%r9));
11518+ pax_force_retaddr_bts
11519 ret;
11520 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
11521
11522@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
11523 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
11524 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
11525 %rax, (%r9));
11526+ pax_force_retaddr_bts
11527 ret;
11528 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
11529
11530@@ -780,6 +783,7 @@ __camellia_enc_blk16:
11531 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
11532 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
11533
11534+ pax_force_retaddr_bts
11535 ret;
11536
11537 .align 8
11538@@ -865,6 +869,7 @@ __camellia_dec_blk16:
11539 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
11540 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
11541
11542+ pax_force_retaddr_bts
11543 ret;
11544
11545 .align 8
11546@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
11547 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
11548 %xmm8, %rsi);
11549
11550+ pax_force_retaddr 0, 1
11551 ret;
11552 ENDPROC(camellia_ecb_enc_16way)
11553
11554@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
11555 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
11556 %xmm8, %rsi);
11557
11558+ pax_force_retaddr 0, 1
11559 ret;
11560 ENDPROC(camellia_ecb_dec_16way)
11561
11562@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
11563 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
11564 %xmm8, %rsi);
11565
11566+ pax_force_retaddr 0, 1
11567 ret;
11568 ENDPROC(camellia_cbc_dec_16way)
11569
11570@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
11571 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
11572 %xmm8, %rsi);
11573
11574+ pax_force_retaddr 0, 1
11575 ret;
11576 ENDPROC(camellia_ctr_16way)
11577
11578@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
11579 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
11580 %xmm8, %rsi);
11581
11582+ pax_force_retaddr 0, 1
11583 ret;
11584 ENDPROC(camellia_xts_crypt_16way)
11585
11586diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
11587index 91a1878..bcf340a 100644
11588--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
11589+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
11590@@ -11,6 +11,7 @@
11591 */
11592
11593 #include <linux/linkage.h>
11594+#include <asm/alternative-asm.h>
11595
11596 #define CAMELLIA_TABLE_BYTE_LEN 272
11597
11598@@ -212,6 +213,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
11599 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
11600 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
11601 %rcx, (%r9));
11602+ pax_force_retaddr_bts
11603 ret;
11604 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
11605
11606@@ -220,6 +222,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
11607 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
11608 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
11609 %rax, (%r9));
11610+ pax_force_retaddr_bts
11611 ret;
11612 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
11613
11614@@ -802,6 +805,7 @@ __camellia_enc_blk32:
11615 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
11616 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
11617
11618+ pax_force_retaddr_bts
11619 ret;
11620
11621 .align 8
11622@@ -887,6 +891,7 @@ __camellia_dec_blk32:
11623 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
11624 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
11625
11626+ pax_force_retaddr_bts
11627 ret;
11628
11629 .align 8
11630@@ -930,6 +935,7 @@ ENTRY(camellia_ecb_enc_32way)
11631
11632 vzeroupper;
11633
11634+ pax_force_retaddr 0, 1
11635 ret;
11636 ENDPROC(camellia_ecb_enc_32way)
11637
11638@@ -962,6 +968,7 @@ ENTRY(camellia_ecb_dec_32way)
11639
11640 vzeroupper;
11641
11642+ pax_force_retaddr 0, 1
11643 ret;
11644 ENDPROC(camellia_ecb_dec_32way)
11645
11646@@ -1028,6 +1035,7 @@ ENTRY(camellia_cbc_dec_32way)
11647
11648 vzeroupper;
11649
11650+ pax_force_retaddr 0, 1
11651 ret;
11652 ENDPROC(camellia_cbc_dec_32way)
11653
11654@@ -1166,6 +1174,7 @@ ENTRY(camellia_ctr_32way)
11655
11656 vzeroupper;
11657
11658+ pax_force_retaddr 0, 1
11659 ret;
11660 ENDPROC(camellia_ctr_32way)
11661
11662@@ -1331,6 +1340,7 @@ camellia_xts_crypt_32way:
11663
11664 vzeroupper;
11665
11666+ pax_force_retaddr 0, 1
11667 ret;
11668 ENDPROC(camellia_xts_crypt_32way)
11669
11670diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11671index 310319c..ce174a4 100644
11672--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11673+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11674@@ -21,6 +21,7 @@
11675 */
11676
11677 #include <linux/linkage.h>
11678+#include <asm/alternative-asm.h>
11679
11680 .file "camellia-x86_64-asm_64.S"
11681 .text
11682@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11683 enc_outunpack(mov, RT1);
11684
11685 movq RRBP, %rbp;
11686+ pax_force_retaddr 0, 1
11687 ret;
11688
11689 .L__enc_xor:
11690 enc_outunpack(xor, RT1);
11691
11692 movq RRBP, %rbp;
11693+ pax_force_retaddr 0, 1
11694 ret;
11695 ENDPROC(__camellia_enc_blk)
11696
11697@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11698 dec_outunpack();
11699
11700 movq RRBP, %rbp;
11701+ pax_force_retaddr 0, 1
11702 ret;
11703 ENDPROC(camellia_dec_blk)
11704
11705@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11706
11707 movq RRBP, %rbp;
11708 popq %rbx;
11709+ pax_force_retaddr 0, 1
11710 ret;
11711
11712 .L__enc2_xor:
11713@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11714
11715 movq RRBP, %rbp;
11716 popq %rbx;
11717+ pax_force_retaddr 0, 1
11718 ret;
11719 ENDPROC(__camellia_enc_blk_2way)
11720
11721@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11722
11723 movq RRBP, %rbp;
11724 movq RXOR, %rbx;
11725+ pax_force_retaddr 0, 1
11726 ret;
11727 ENDPROC(camellia_dec_blk_2way)
11728diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11729index c35fd5d..c1ee236 100644
11730--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11731+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11732@@ -24,6 +24,7 @@
11733 */
11734
11735 #include <linux/linkage.h>
11736+#include <asm/alternative-asm.h>
11737
11738 .file "cast5-avx-x86_64-asm_64.S"
11739
11740@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11741 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11742 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11743
11744+ pax_force_retaddr 0, 1
11745 ret;
11746 ENDPROC(__cast5_enc_blk16)
11747
11748@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11749 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11750 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11751
11752+ pax_force_retaddr 0, 1
11753 ret;
11754
11755 .L__skip_dec:
11756@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11757 vmovdqu RR4, (6*4*4)(%r11);
11758 vmovdqu RL4, (7*4*4)(%r11);
11759
11760+ pax_force_retaddr
11761 ret;
11762 ENDPROC(cast5_ecb_enc_16way)
11763
11764@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11765 vmovdqu RR4, (6*4*4)(%r11);
11766 vmovdqu RL4, (7*4*4)(%r11);
11767
11768+ pax_force_retaddr
11769 ret;
11770 ENDPROC(cast5_ecb_dec_16way)
11771
11772@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11773
11774 popq %r12;
11775
11776+ pax_force_retaddr
11777 ret;
11778 ENDPROC(cast5_cbc_dec_16way)
11779
11780@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11781
11782 popq %r12;
11783
11784+ pax_force_retaddr
11785 ret;
11786 ENDPROC(cast5_ctr_16way)
11787diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11788index e3531f8..18ded3a 100644
11789--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11790+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11791@@ -24,6 +24,7 @@
11792 */
11793
11794 #include <linux/linkage.h>
11795+#include <asm/alternative-asm.h>
11796 #include "glue_helper-asm-avx.S"
11797
11798 .file "cast6-avx-x86_64-asm_64.S"
11799@@ -295,6 +296,7 @@ __cast6_enc_blk8:
11800 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11801 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11802
11803+ pax_force_retaddr 0, 1
11804 ret;
11805 ENDPROC(__cast6_enc_blk8)
11806
11807@@ -340,6 +342,7 @@ __cast6_dec_blk8:
11808 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11809 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11810
11811+ pax_force_retaddr 0, 1
11812 ret;
11813 ENDPROC(__cast6_dec_blk8)
11814
11815@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
11816
11817 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11818
11819+ pax_force_retaddr
11820 ret;
11821 ENDPROC(cast6_ecb_enc_8way)
11822
11823@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
11824
11825 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11826
11827+ pax_force_retaddr
11828 ret;
11829 ENDPROC(cast6_ecb_dec_8way)
11830
11831@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
11832
11833 popq %r12;
11834
11835+ pax_force_retaddr
11836 ret;
11837 ENDPROC(cast6_cbc_dec_8way)
11838
11839@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
11840
11841 popq %r12;
11842
11843+ pax_force_retaddr
11844 ret;
11845 ENDPROC(cast6_ctr_8way)
11846
11847@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
11848 /* dst <= regs xor IVs(in dst) */
11849 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11850
11851+ pax_force_retaddr
11852 ret;
11853 ENDPROC(cast6_xts_enc_8way)
11854
11855@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
11856 /* dst <= regs xor IVs(in dst) */
11857 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11858
11859+ pax_force_retaddr
11860 ret;
11861 ENDPROC(cast6_xts_dec_8way)
11862diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
11863index dbc4339..3d868c5 100644
11864--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
11865+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
11866@@ -45,6 +45,7 @@
11867
11868 #include <asm/inst.h>
11869 #include <linux/linkage.h>
11870+#include <asm/alternative-asm.h>
11871
11872 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
11873
11874@@ -312,6 +313,7 @@ do_return:
11875 popq %rsi
11876 popq %rdi
11877 popq %rbx
11878+ pax_force_retaddr 0, 1
11879 ret
11880
11881 ################################################################
11882diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
11883index 586f41a..d02851e 100644
11884--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
11885+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
11886@@ -18,6 +18,7 @@
11887
11888 #include <linux/linkage.h>
11889 #include <asm/inst.h>
11890+#include <asm/alternative-asm.h>
11891
11892 .data
11893
11894@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
11895 psrlq $1, T2
11896 pxor T2, T1
11897 pxor T1, DATA
11898+ pax_force_retaddr
11899 ret
11900 ENDPROC(__clmul_gf128mul_ble)
11901
11902@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
11903 call __clmul_gf128mul_ble
11904 PSHUFB_XMM BSWAP DATA
11905 movups DATA, (%rdi)
11906+ pax_force_retaddr
11907 ret
11908 ENDPROC(clmul_ghash_mul)
11909
11910@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
11911 PSHUFB_XMM BSWAP DATA
11912 movups DATA, (%rdi)
11913 .Lupdate_just_ret:
11914+ pax_force_retaddr
11915 ret
11916 ENDPROC(clmul_ghash_update)
11917
11918@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
11919 pand .Lpoly, %xmm1
11920 pxor %xmm1, %xmm0
11921 movups %xmm0, (%rdi)
11922+ pax_force_retaddr
11923 ret
11924 ENDPROC(clmul_ghash_setkey)
11925diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11926index 9279e0b..9270820 100644
11927--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11928+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11929@@ -1,4 +1,5 @@
11930 #include <linux/linkage.h>
11931+#include <asm/alternative-asm.h>
11932
11933 # enter salsa20_encrypt_bytes
11934 ENTRY(salsa20_encrypt_bytes)
11935@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11936 add %r11,%rsp
11937 mov %rdi,%rax
11938 mov %rsi,%rdx
11939+ pax_force_retaddr 0, 1
11940 ret
11941 # bytesatleast65:
11942 ._bytesatleast65:
11943@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11944 add %r11,%rsp
11945 mov %rdi,%rax
11946 mov %rsi,%rdx
11947+ pax_force_retaddr
11948 ret
11949 ENDPROC(salsa20_keysetup)
11950
11951@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11952 add %r11,%rsp
11953 mov %rdi,%rax
11954 mov %rsi,%rdx
11955+ pax_force_retaddr
11956 ret
11957 ENDPROC(salsa20_ivsetup)
11958diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11959index 2f202f4..d9164d6 100644
11960--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11961+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11962@@ -24,6 +24,7 @@
11963 */
11964
11965 #include <linux/linkage.h>
11966+#include <asm/alternative-asm.h>
11967 #include "glue_helper-asm-avx.S"
11968
11969 .file "serpent-avx-x86_64-asm_64.S"
11970@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
11971 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11972 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11973
11974+ pax_force_retaddr
11975 ret;
11976 ENDPROC(__serpent_enc_blk8_avx)
11977
11978@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
11979 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11980 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11981
11982+ pax_force_retaddr
11983 ret;
11984 ENDPROC(__serpent_dec_blk8_avx)
11985
11986@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11987
11988 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11989
11990+ pax_force_retaddr
11991 ret;
11992 ENDPROC(serpent_ecb_enc_8way_avx)
11993
11994@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11995
11996 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11997
11998+ pax_force_retaddr
11999 ret;
12000 ENDPROC(serpent_ecb_dec_8way_avx)
12001
12002@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12003
12004 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12005
12006+ pax_force_retaddr
12007 ret;
12008 ENDPROC(serpent_cbc_dec_8way_avx)
12009
12010@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12011
12012 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12013
12014+ pax_force_retaddr
12015 ret;
12016 ENDPROC(serpent_ctr_8way_avx)
12017
12018@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12019 /* dst <= regs xor IVs(in dst) */
12020 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12021
12022+ pax_force_retaddr
12023 ret;
12024 ENDPROC(serpent_xts_enc_8way_avx)
12025
12026@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12027 /* dst <= regs xor IVs(in dst) */
12028 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12029
12030+ pax_force_retaddr
12031 ret;
12032 ENDPROC(serpent_xts_dec_8way_avx)
12033diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12034index b222085..abd483c 100644
12035--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12036+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12037@@ -15,6 +15,7 @@
12038 */
12039
12040 #include <linux/linkage.h>
12041+#include <asm/alternative-asm.h>
12042 #include "glue_helper-asm-avx2.S"
12043
12044 .file "serpent-avx2-asm_64.S"
12045@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12046 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12047 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12048
12049+ pax_force_retaddr
12050 ret;
12051 ENDPROC(__serpent_enc_blk16)
12052
12053@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12054 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12055 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12056
12057+ pax_force_retaddr
12058 ret;
12059 ENDPROC(__serpent_dec_blk16)
12060
12061@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12062
12063 vzeroupper;
12064
12065+ pax_force_retaddr
12066 ret;
12067 ENDPROC(serpent_ecb_enc_16way)
12068
12069@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12070
12071 vzeroupper;
12072
12073+ pax_force_retaddr
12074 ret;
12075 ENDPROC(serpent_ecb_dec_16way)
12076
12077@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12078
12079 vzeroupper;
12080
12081+ pax_force_retaddr
12082 ret;
12083 ENDPROC(serpent_cbc_dec_16way)
12084
12085@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12086
12087 vzeroupper;
12088
12089+ pax_force_retaddr
12090 ret;
12091 ENDPROC(serpent_ctr_16way)
12092
12093@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12094
12095 vzeroupper;
12096
12097+ pax_force_retaddr
12098 ret;
12099 ENDPROC(serpent_xts_enc_16way)
12100
12101@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12102
12103 vzeroupper;
12104
12105+ pax_force_retaddr
12106 ret;
12107 ENDPROC(serpent_xts_dec_16way)
12108diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12109index acc066c..1559cc4 100644
12110--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12111+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12112@@ -25,6 +25,7 @@
12113 */
12114
12115 #include <linux/linkage.h>
12116+#include <asm/alternative-asm.h>
12117
12118 .file "serpent-sse2-x86_64-asm_64.S"
12119 .text
12120@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12121 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12122 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12123
12124+ pax_force_retaddr
12125 ret;
12126
12127 .L__enc_xor8:
12128 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12129 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12130
12131+ pax_force_retaddr
12132 ret;
12133 ENDPROC(__serpent_enc_blk_8way)
12134
12135@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12136 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12137 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12138
12139+ pax_force_retaddr
12140 ret;
12141 ENDPROC(serpent_dec_blk_8way)
12142diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12143index a410950..3356d42 100644
12144--- a/arch/x86/crypto/sha1_ssse3_asm.S
12145+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12146@@ -29,6 +29,7 @@
12147 */
12148
12149 #include <linux/linkage.h>
12150+#include <asm/alternative-asm.h>
12151
12152 #define CTX %rdi // arg1
12153 #define BUF %rsi // arg2
12154@@ -104,6 +105,7 @@
12155 pop %r12
12156 pop %rbp
12157 pop %rbx
12158+ pax_force_retaddr 0, 1
12159 ret
12160
12161 ENDPROC(\name)
12162diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12163index 642f156..4ab07b9 100644
12164--- a/arch/x86/crypto/sha256-avx-asm.S
12165+++ b/arch/x86/crypto/sha256-avx-asm.S
12166@@ -49,6 +49,7 @@
12167
12168 #ifdef CONFIG_AS_AVX
12169 #include <linux/linkage.h>
12170+#include <asm/alternative-asm.h>
12171
12172 ## assume buffers not aligned
12173 #define VMOVDQ vmovdqu
12174@@ -460,6 +461,7 @@ done_hash:
12175 popq %r13
12176 popq %rbp
12177 popq %rbx
12178+ pax_force_retaddr 0, 1
12179 ret
12180 ENDPROC(sha256_transform_avx)
12181
12182diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
12183index 9e86944..2e7f95a 100644
12184--- a/arch/x86/crypto/sha256-avx2-asm.S
12185+++ b/arch/x86/crypto/sha256-avx2-asm.S
12186@@ -50,6 +50,7 @@
12187
12188 #ifdef CONFIG_AS_AVX2
12189 #include <linux/linkage.h>
12190+#include <asm/alternative-asm.h>
12191
12192 ## assume buffers not aligned
12193 #define VMOVDQ vmovdqu
12194@@ -720,6 +721,7 @@ done_hash:
12195 popq %r12
12196 popq %rbp
12197 popq %rbx
12198+ pax_force_retaddr 0, 1
12199 ret
12200 ENDPROC(sha256_transform_rorx)
12201
12202diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
12203index f833b74..c36ed14 100644
12204--- a/arch/x86/crypto/sha256-ssse3-asm.S
12205+++ b/arch/x86/crypto/sha256-ssse3-asm.S
12206@@ -47,6 +47,7 @@
12207 ########################################################################
12208
12209 #include <linux/linkage.h>
12210+#include <asm/alternative-asm.h>
12211
12212 ## assume buffers not aligned
12213 #define MOVDQ movdqu
12214@@ -471,6 +472,7 @@ done_hash:
12215 popq %rbp
12216 popq %rbx
12217
12218+ pax_force_retaddr 0, 1
12219 ret
12220 ENDPROC(sha256_transform_ssse3)
12221
12222diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
12223index 974dde9..4533d34 100644
12224--- a/arch/x86/crypto/sha512-avx-asm.S
12225+++ b/arch/x86/crypto/sha512-avx-asm.S
12226@@ -49,6 +49,7 @@
12227
12228 #ifdef CONFIG_AS_AVX
12229 #include <linux/linkage.h>
12230+#include <asm/alternative-asm.h>
12231
12232 .text
12233
12234@@ -364,6 +365,7 @@ updateblock:
12235 mov frame_RSPSAVE(%rsp), %rsp
12236
12237 nowork:
12238+ pax_force_retaddr 0, 1
12239 ret
12240 ENDPROC(sha512_transform_avx)
12241
12242diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
12243index 568b961..061ef1d 100644
12244--- a/arch/x86/crypto/sha512-avx2-asm.S
12245+++ b/arch/x86/crypto/sha512-avx2-asm.S
12246@@ -51,6 +51,7 @@
12247
12248 #ifdef CONFIG_AS_AVX2
12249 #include <linux/linkage.h>
12250+#include <asm/alternative-asm.h>
12251
12252 .text
12253
12254@@ -678,6 +679,7 @@ done_hash:
12255
12256 # Restore Stack Pointer
12257 mov frame_RSPSAVE(%rsp), %rsp
12258+ pax_force_retaddr 0, 1
12259 ret
12260 ENDPROC(sha512_transform_rorx)
12261
12262diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
12263index fb56855..e23914f 100644
12264--- a/arch/x86/crypto/sha512-ssse3-asm.S
12265+++ b/arch/x86/crypto/sha512-ssse3-asm.S
12266@@ -48,6 +48,7 @@
12267 ########################################################################
12268
12269 #include <linux/linkage.h>
12270+#include <asm/alternative-asm.h>
12271
12272 .text
12273
12274@@ -363,6 +364,7 @@ updateblock:
12275 mov frame_RSPSAVE(%rsp), %rsp
12276
12277 nowork:
12278+ pax_force_retaddr 0, 1
12279 ret
12280 ENDPROC(sha512_transform_ssse3)
12281
12282diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12283index 0505813..63b1d00 100644
12284--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12285+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
12286@@ -24,6 +24,7 @@
12287 */
12288
12289 #include <linux/linkage.h>
12290+#include <asm/alternative-asm.h>
12291 #include "glue_helper-asm-avx.S"
12292
12293 .file "twofish-avx-x86_64-asm_64.S"
12294@@ -284,6 +285,7 @@ __twofish_enc_blk8:
12295 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
12296 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
12297
12298+ pax_force_retaddr 0, 1
12299 ret;
12300 ENDPROC(__twofish_enc_blk8)
12301
12302@@ -324,6 +326,7 @@ __twofish_dec_blk8:
12303 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
12304 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
12305
12306+ pax_force_retaddr 0, 1
12307 ret;
12308 ENDPROC(__twofish_dec_blk8)
12309
12310@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
12311
12312 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
12313
12314+ pax_force_retaddr 0, 1
12315 ret;
12316 ENDPROC(twofish_ecb_enc_8way)
12317
12318@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
12319
12320 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12321
12322+ pax_force_retaddr 0, 1
12323 ret;
12324 ENDPROC(twofish_ecb_dec_8way)
12325
12326@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
12327
12328 popq %r12;
12329
12330+ pax_force_retaddr 0, 1
12331 ret;
12332 ENDPROC(twofish_cbc_dec_8way)
12333
12334@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
12335
12336 popq %r12;
12337
12338+ pax_force_retaddr 0, 1
12339 ret;
12340 ENDPROC(twofish_ctr_8way)
12341
12342@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
12343 /* dst <= regs xor IVs(in dst) */
12344 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
12345
12346+ pax_force_retaddr 0, 1
12347 ret;
12348 ENDPROC(twofish_xts_enc_8way)
12349
12350@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
12351 /* dst <= regs xor IVs(in dst) */
12352 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12353
12354+ pax_force_retaddr 0, 1
12355 ret;
12356 ENDPROC(twofish_xts_dec_8way)
12357diff --git a/arch/x86/crypto/twofish-avx2-asm_64.S b/arch/x86/crypto/twofish-avx2-asm_64.S
12358index e1a83b9..33006b9 100644
12359--- a/arch/x86/crypto/twofish-avx2-asm_64.S
12360+++ b/arch/x86/crypto/twofish-avx2-asm_64.S
12361@@ -11,6 +11,7 @@
12362 */
12363
12364 #include <linux/linkage.h>
12365+#include <asm/alternative-asm.h>
12366 #include "glue_helper-asm-avx2.S"
12367
12368 .file "twofish-avx2-asm_64.S"
12369@@ -422,6 +423,7 @@ __twofish_enc_blk16:
12370 outunpack_enc16(RA, RB, RC, RD);
12371 write_blocks16(RA, RB, RC, RD);
12372
12373+ pax_force_retaddr_bts
12374 ret;
12375 ENDPROC(__twofish_enc_blk16)
12376
12377@@ -454,6 +456,7 @@ __twofish_dec_blk16:
12378 outunpack_dec16(RA, RB, RC, RD);
12379 write_blocks16(RA, RB, RC, RD);
12380
12381+ pax_force_retaddr_bts
12382 ret;
12383 ENDPROC(__twofish_dec_blk16)
12384
12385@@ -476,6 +479,7 @@ ENTRY(twofish_ecb_enc_16way)
12386 popq %r12;
12387 vzeroupper;
12388
12389+ pax_force_retaddr 0, 1
12390 ret;
12391 ENDPROC(twofish_ecb_enc_16way)
12392
12393@@ -498,6 +502,7 @@ ENTRY(twofish_ecb_dec_16way)
12394 popq %r12;
12395 vzeroupper;
12396
12397+ pax_force_retaddr 0, 1
12398 ret;
12399 ENDPROC(twofish_ecb_dec_16way)
12400
12401@@ -521,6 +526,7 @@ ENTRY(twofish_cbc_dec_16way)
12402 popq %r12;
12403 vzeroupper;
12404
12405+ pax_force_retaddr 0, 1
12406 ret;
12407 ENDPROC(twofish_cbc_dec_16way)
12408
12409@@ -546,6 +552,7 @@ ENTRY(twofish_ctr_16way)
12410 popq %r12;
12411 vzeroupper;
12412
12413+ pax_force_retaddr 0, 1
12414 ret;
12415 ENDPROC(twofish_ctr_16way)
12416
12417@@ -574,6 +581,7 @@ twofish_xts_crypt_16way:
12418 popq %r12;
12419 vzeroupper;
12420
12421+ pax_force_retaddr 0, 1
12422 ret;
12423 ENDPROC(twofish_xts_crypt_16way)
12424
12425diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12426index 1c3b7ce..b365c5e 100644
12427--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12428+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
12429@@ -21,6 +21,7 @@
12430 */
12431
12432 #include <linux/linkage.h>
12433+#include <asm/alternative-asm.h>
12434
12435 .file "twofish-x86_64-asm-3way.S"
12436 .text
12437@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
12438 popq %r13;
12439 popq %r14;
12440 popq %r15;
12441+ pax_force_retaddr 0, 1
12442 ret;
12443
12444 .L__enc_xor3:
12445@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
12446 popq %r13;
12447 popq %r14;
12448 popq %r15;
12449+ pax_force_retaddr 0, 1
12450 ret;
12451 ENDPROC(__twofish_enc_blk_3way)
12452
12453@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
12454 popq %r13;
12455 popq %r14;
12456 popq %r15;
12457+ pax_force_retaddr 0, 1
12458 ret;
12459 ENDPROC(twofish_dec_blk_3way)
12460diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
12461index a039d21..29e7615 100644
12462--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
12463+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
12464@@ -22,6 +22,7 @@
12465
12466 #include <linux/linkage.h>
12467 #include <asm/asm-offsets.h>
12468+#include <asm/alternative-asm.h>
12469
12470 #define a_offset 0
12471 #define b_offset 4
12472@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
12473
12474 popq R1
12475 movq $1,%rax
12476+ pax_force_retaddr 0, 1
12477 ret
12478 ENDPROC(twofish_enc_blk)
12479
12480@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
12481
12482 popq R1
12483 movq $1,%rax
12484+ pax_force_retaddr 0, 1
12485 ret
12486 ENDPROC(twofish_dec_blk)
12487diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
12488index 52ff81c..98af645 100644
12489--- a/arch/x86/ia32/ia32_aout.c
12490+++ b/arch/x86/ia32/ia32_aout.c
12491@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
12492 unsigned long dump_start, dump_size;
12493 struct user32 dump;
12494
12495+ memset(&dump, 0, sizeof(dump));
12496+
12497 fs = get_fs();
12498 set_fs(KERNEL_DS);
12499 has_dumped = 1;
12500diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
12501index cf1a471..5ba2673 100644
12502--- a/arch/x86/ia32/ia32_signal.c
12503+++ b/arch/x86/ia32/ia32_signal.c
12504@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
12505 sp -= frame_size;
12506 /* Align the stack pointer according to the i386 ABI,
12507 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
12508- sp = ((sp + 4) & -16ul) - 4;
12509+ sp = ((sp - 12) & -16ul) - 4;
12510 return (void __user *) sp;
12511 }
12512
12513@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
12514 * These are actually not used anymore, but left because some
12515 * gdb versions depend on them as a marker.
12516 */
12517- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
12518+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
12519 } put_user_catch(err);
12520
12521 if (err)
12522@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
12523 0xb8,
12524 __NR_ia32_rt_sigreturn,
12525 0x80cd,
12526- 0,
12527+ 0
12528 };
12529
12530 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
12531@@ -459,20 +459,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
12532 else
12533 put_user_ex(0, &frame->uc.uc_flags);
12534 put_user_ex(0, &frame->uc.uc_link);
12535- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
12536+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
12537
12538 if (ksig->ka.sa.sa_flags & SA_RESTORER)
12539 restorer = ksig->ka.sa.sa_restorer;
12540+ else if (current->mm->context.vdso)
12541+ /* Return stub is in 32bit vsyscall page */
12542+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
12543 else
12544- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
12545- rt_sigreturn);
12546+ restorer = &frame->retcode;
12547 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
12548
12549 /*
12550 * Not actually used anymore, but left because some gdb
12551 * versions need it.
12552 */
12553- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
12554+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
12555 } put_user_catch(err);
12556
12557 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
12558diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
12559index 474dc1b..9297c58 100644
12560--- a/arch/x86/ia32/ia32entry.S
12561+++ b/arch/x86/ia32/ia32entry.S
12562@@ -15,8 +15,10 @@
12563 #include <asm/irqflags.h>
12564 #include <asm/asm.h>
12565 #include <asm/smap.h>
12566+#include <asm/pgtable.h>
12567 #include <linux/linkage.h>
12568 #include <linux/err.h>
12569+#include <asm/alternative-asm.h>
12570
12571 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
12572 #include <linux/elf-em.h>
12573@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
12574 ENDPROC(native_irq_enable_sysexit)
12575 #endif
12576
12577+ .macro pax_enter_kernel_user
12578+ pax_set_fptr_mask
12579+#ifdef CONFIG_PAX_MEMORY_UDEREF
12580+ call pax_enter_kernel_user
12581+#endif
12582+ .endm
12583+
12584+ .macro pax_exit_kernel_user
12585+#ifdef CONFIG_PAX_MEMORY_UDEREF
12586+ call pax_exit_kernel_user
12587+#endif
12588+#ifdef CONFIG_PAX_RANDKSTACK
12589+ pushq %rax
12590+ pushq %r11
12591+ call pax_randomize_kstack
12592+ popq %r11
12593+ popq %rax
12594+#endif
12595+ .endm
12596+
12597+ .macro pax_erase_kstack
12598+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12599+ call pax_erase_kstack
12600+#endif
12601+ .endm
12602+
12603 /*
12604 * 32bit SYSENTER instruction entry.
12605 *
12606@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
12607 CFI_REGISTER rsp,rbp
12608 SWAPGS_UNSAFE_STACK
12609 movq PER_CPU_VAR(kernel_stack), %rsp
12610- addq $(KERNEL_STACK_OFFSET),%rsp
12611- /*
12612- * No need to follow this irqs on/off section: the syscall
12613- * disabled irqs, here we enable it straight after entry:
12614- */
12615- ENABLE_INTERRUPTS(CLBR_NONE)
12616 movl %ebp,%ebp /* zero extension */
12617 pushq_cfi $__USER32_DS
12618 /*CFI_REL_OFFSET ss,0*/
12619@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
12620 CFI_REL_OFFSET rsp,0
12621 pushfq_cfi
12622 /*CFI_REL_OFFSET rflags,0*/
12623- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
12624- CFI_REGISTER rip,r10
12625+ orl $X86_EFLAGS_IF,(%rsp)
12626+ GET_THREAD_INFO(%r11)
12627+ movl TI_sysenter_return(%r11), %r11d
12628+ CFI_REGISTER rip,r11
12629 pushq_cfi $__USER32_CS
12630 /*CFI_REL_OFFSET cs,0*/
12631 movl %eax, %eax
12632- pushq_cfi %r10
12633+ pushq_cfi %r11
12634 CFI_REL_OFFSET rip,0
12635 pushq_cfi %rax
12636 cld
12637 SAVE_ARGS 0,1,0
12638+ pax_enter_kernel_user
12639+
12640+#ifdef CONFIG_PAX_RANDKSTACK
12641+ pax_erase_kstack
12642+#endif
12643+
12644+ /*
12645+ * No need to follow this irqs on/off section: the syscall
12646+ * disabled irqs, here we enable it straight after entry:
12647+ */
12648+ ENABLE_INTERRUPTS(CLBR_NONE)
12649 /* no need to do an access_ok check here because rbp has been
12650 32bit zero extended */
12651+
12652+#ifdef CONFIG_PAX_MEMORY_UDEREF
12653+ addq pax_user_shadow_base,%rbp
12654+ ASM_PAX_OPEN_USERLAND
12655+#endif
12656+
12657 ASM_STAC
12658 1: movl (%rbp),%ebp
12659 _ASM_EXTABLE(1b,ia32_badarg)
12660 ASM_CLAC
12661- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12662- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12663+
12664+#ifdef CONFIG_PAX_MEMORY_UDEREF
12665+ ASM_PAX_CLOSE_USERLAND
12666+#endif
12667+
12668+ GET_THREAD_INFO(%r11)
12669+ orl $TS_COMPAT,TI_status(%r11)
12670+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12671 CFI_REMEMBER_STATE
12672 jnz sysenter_tracesys
12673 cmpq $(IA32_NR_syscalls-1),%rax
12674@@ -162,12 +209,15 @@ sysenter_do_call:
12675 sysenter_dispatch:
12676 call *ia32_sys_call_table(,%rax,8)
12677 movq %rax,RAX-ARGOFFSET(%rsp)
12678+ GET_THREAD_INFO(%r11)
12679 DISABLE_INTERRUPTS(CLBR_NONE)
12680 TRACE_IRQS_OFF
12681- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12682+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12683 jnz sysexit_audit
12684 sysexit_from_sys_call:
12685- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12686+ pax_exit_kernel_user
12687+ pax_erase_kstack
12688+ andl $~TS_COMPAT,TI_status(%r11)
12689 /* clear IF, that popfq doesn't enable interrupts early */
12690 andl $~0x200,EFLAGS-R11(%rsp)
12691 movl RIP-R11(%rsp),%edx /* User %eip */
12692@@ -193,6 +243,9 @@ sysexit_from_sys_call:
12693 movl %eax,%esi /* 2nd arg: syscall number */
12694 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
12695 call __audit_syscall_entry
12696+
12697+ pax_erase_kstack
12698+
12699 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
12700 cmpq $(IA32_NR_syscalls-1),%rax
12701 ja ia32_badsys
12702@@ -204,7 +257,7 @@ sysexit_from_sys_call:
12703 .endm
12704
12705 .macro auditsys_exit exit
12706- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12707+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12708 jnz ia32_ret_from_sys_call
12709 TRACE_IRQS_ON
12710 ENABLE_INTERRUPTS(CLBR_NONE)
12711@@ -215,11 +268,12 @@ sysexit_from_sys_call:
12712 1: setbe %al /* 1 if error, 0 if not */
12713 movzbl %al,%edi /* zero-extend that into %edi */
12714 call __audit_syscall_exit
12715+ GET_THREAD_INFO(%r11)
12716 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
12717 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
12718 DISABLE_INTERRUPTS(CLBR_NONE)
12719 TRACE_IRQS_OFF
12720- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12721+ testl %edi,TI_flags(%r11)
12722 jz \exit
12723 CLEAR_RREGS -ARGOFFSET
12724 jmp int_with_check
12725@@ -237,7 +291,7 @@ sysexit_audit:
12726
12727 sysenter_tracesys:
12728 #ifdef CONFIG_AUDITSYSCALL
12729- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12730+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12731 jz sysenter_auditsys
12732 #endif
12733 SAVE_REST
12734@@ -249,6 +303,9 @@ sysenter_tracesys:
12735 RESTORE_REST
12736 cmpq $(IA32_NR_syscalls-1),%rax
12737 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
12738+
12739+ pax_erase_kstack
12740+
12741 jmp sysenter_do_call
12742 CFI_ENDPROC
12743 ENDPROC(ia32_sysenter_target)
12744@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
12745 ENTRY(ia32_cstar_target)
12746 CFI_STARTPROC32 simple
12747 CFI_SIGNAL_FRAME
12748- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
12749+ CFI_DEF_CFA rsp,0
12750 CFI_REGISTER rip,rcx
12751 /*CFI_REGISTER rflags,r11*/
12752 SWAPGS_UNSAFE_STACK
12753 movl %esp,%r8d
12754 CFI_REGISTER rsp,r8
12755 movq PER_CPU_VAR(kernel_stack),%rsp
12756+ SAVE_ARGS 8*6,0,0
12757+ pax_enter_kernel_user
12758+
12759+#ifdef CONFIG_PAX_RANDKSTACK
12760+ pax_erase_kstack
12761+#endif
12762+
12763 /*
12764 * No need to follow this irqs on/off section: the syscall
12765 * disabled irqs and here we enable it straight after entry:
12766 */
12767 ENABLE_INTERRUPTS(CLBR_NONE)
12768- SAVE_ARGS 8,0,0
12769 movl %eax,%eax /* zero extension */
12770 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
12771 movq %rcx,RIP-ARGOFFSET(%rsp)
12772@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
12773 /* no need to do an access_ok check here because r8 has been
12774 32bit zero extended */
12775 /* hardware stack frame is complete now */
12776+
12777+#ifdef CONFIG_PAX_MEMORY_UDEREF
12778+ ASM_PAX_OPEN_USERLAND
12779+ movq pax_user_shadow_base,%r8
12780+ addq RSP-ARGOFFSET(%rsp),%r8
12781+#endif
12782+
12783 ASM_STAC
12784 1: movl (%r8),%r9d
12785 _ASM_EXTABLE(1b,ia32_badarg)
12786 ASM_CLAC
12787- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12788- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12789+
12790+#ifdef CONFIG_PAX_MEMORY_UDEREF
12791+ ASM_PAX_CLOSE_USERLAND
12792+#endif
12793+
12794+ GET_THREAD_INFO(%r11)
12795+ orl $TS_COMPAT,TI_status(%r11)
12796+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12797 CFI_REMEMBER_STATE
12798 jnz cstar_tracesys
12799 cmpq $IA32_NR_syscalls-1,%rax
12800@@ -319,12 +395,15 @@ cstar_do_call:
12801 cstar_dispatch:
12802 call *ia32_sys_call_table(,%rax,8)
12803 movq %rax,RAX-ARGOFFSET(%rsp)
12804+ GET_THREAD_INFO(%r11)
12805 DISABLE_INTERRUPTS(CLBR_NONE)
12806 TRACE_IRQS_OFF
12807- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12808+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
12809 jnz sysretl_audit
12810 sysretl_from_sys_call:
12811- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12812+ pax_exit_kernel_user
12813+ pax_erase_kstack
12814+ andl $~TS_COMPAT,TI_status(%r11)
12815 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
12816 movl RIP-ARGOFFSET(%rsp),%ecx
12817 CFI_REGISTER rip,rcx
12818@@ -352,7 +431,7 @@ sysretl_audit:
12819
12820 cstar_tracesys:
12821 #ifdef CONFIG_AUDITSYSCALL
12822- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12823+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
12824 jz cstar_auditsys
12825 #endif
12826 xchgl %r9d,%ebp
12827@@ -366,11 +445,19 @@ cstar_tracesys:
12828 xchgl %ebp,%r9d
12829 cmpq $(IA32_NR_syscalls-1),%rax
12830 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
12831+
12832+ pax_erase_kstack
12833+
12834 jmp cstar_do_call
12835 END(ia32_cstar_target)
12836
12837 ia32_badarg:
12838 ASM_CLAC
12839+
12840+#ifdef CONFIG_PAX_MEMORY_UDEREF
12841+ ASM_PAX_CLOSE_USERLAND
12842+#endif
12843+
12844 movq $-EFAULT,%rax
12845 jmp ia32_sysret
12846 CFI_ENDPROC
12847@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
12848 CFI_REL_OFFSET rip,RIP-RIP
12849 PARAVIRT_ADJUST_EXCEPTION_FRAME
12850 SWAPGS
12851- /*
12852- * No need to follow this irqs on/off section: the syscall
12853- * disabled irqs and here we enable it straight after entry:
12854- */
12855- ENABLE_INTERRUPTS(CLBR_NONE)
12856 movl %eax,%eax
12857 pushq_cfi %rax
12858 cld
12859 /* note the registers are not zero extended to the sf.
12860 this could be a problem. */
12861 SAVE_ARGS 0,1,0
12862- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12863- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
12864+ pax_enter_kernel_user
12865+
12866+#ifdef CONFIG_PAX_RANDKSTACK
12867+ pax_erase_kstack
12868+#endif
12869+
12870+ /*
12871+ * No need to follow this irqs on/off section: the syscall
12872+ * disabled irqs and here we enable it straight after entry:
12873+ */
12874+ ENABLE_INTERRUPTS(CLBR_NONE)
12875+ GET_THREAD_INFO(%r11)
12876+ orl $TS_COMPAT,TI_status(%r11)
12877+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
12878 jnz ia32_tracesys
12879 cmpq $(IA32_NR_syscalls-1),%rax
12880 ja ia32_badsys
12881@@ -442,6 +536,9 @@ ia32_tracesys:
12882 RESTORE_REST
12883 cmpq $(IA32_NR_syscalls-1),%rax
12884 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
12885+
12886+ pax_erase_kstack
12887+
12888 jmp ia32_do_call
12889 END(ia32_syscall)
12890
12891diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
12892index 8e0ceec..af13504 100644
12893--- a/arch/x86/ia32/sys_ia32.c
12894+++ b/arch/x86/ia32/sys_ia32.c
12895@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
12896 */
12897 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
12898 {
12899- typeof(ubuf->st_uid) uid = 0;
12900- typeof(ubuf->st_gid) gid = 0;
12901+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
12902+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
12903 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
12904 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
12905 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
12906diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
12907index 372231c..a5aa1a1 100644
12908--- a/arch/x86/include/asm/alternative-asm.h
12909+++ b/arch/x86/include/asm/alternative-asm.h
12910@@ -18,6 +18,45 @@
12911 .endm
12912 #endif
12913
12914+#ifdef KERNEXEC_PLUGIN
12915+ .macro pax_force_retaddr_bts rip=0
12916+ btsq $63,\rip(%rsp)
12917+ .endm
12918+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12919+ .macro pax_force_retaddr rip=0, reload=0
12920+ btsq $63,\rip(%rsp)
12921+ .endm
12922+ .macro pax_force_fptr ptr
12923+ btsq $63,\ptr
12924+ .endm
12925+ .macro pax_set_fptr_mask
12926+ .endm
12927+#endif
12928+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
12929+ .macro pax_force_retaddr rip=0, reload=0
12930+ .if \reload
12931+ pax_set_fptr_mask
12932+ .endif
12933+ orq %r10,\rip(%rsp)
12934+ .endm
12935+ .macro pax_force_fptr ptr
12936+ orq %r10,\ptr
12937+ .endm
12938+ .macro pax_set_fptr_mask
12939+ movabs $0x8000000000000000,%r10
12940+ .endm
12941+#endif
12942+#else
12943+ .macro pax_force_retaddr rip=0, reload=0
12944+ .endm
12945+ .macro pax_force_fptr ptr
12946+ .endm
12947+ .macro pax_force_retaddr_bts rip=0
12948+ .endm
12949+ .macro pax_set_fptr_mask
12950+ .endm
12951+#endif
12952+
12953 .macro altinstruction_entry orig alt feature orig_len alt_len
12954 .long \orig - .
12955 .long \alt - .
12956diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
12957index 58ed6d9..f1cbe58 100644
12958--- a/arch/x86/include/asm/alternative.h
12959+++ b/arch/x86/include/asm/alternative.h
12960@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12961 ".pushsection .discard,\"aw\",@progbits\n" \
12962 DISCARD_ENTRY(1) \
12963 ".popsection\n" \
12964- ".pushsection .altinstr_replacement, \"ax\"\n" \
12965+ ".pushsection .altinstr_replacement, \"a\"\n" \
12966 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
12967 ".popsection"
12968
12969@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
12970 DISCARD_ENTRY(1) \
12971 DISCARD_ENTRY(2) \
12972 ".popsection\n" \
12973- ".pushsection .altinstr_replacement, \"ax\"\n" \
12974+ ".pushsection .altinstr_replacement, \"a\"\n" \
12975 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
12976 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
12977 ".popsection"
12978diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
12979index 3388034..050f0b9 100644
12980--- a/arch/x86/include/asm/apic.h
12981+++ b/arch/x86/include/asm/apic.h
12982@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
12983
12984 #ifdef CONFIG_X86_LOCAL_APIC
12985
12986-extern unsigned int apic_verbosity;
12987+extern int apic_verbosity;
12988 extern int local_apic_timer_c2_ok;
12989
12990 extern int disable_apic;
12991diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
12992index 20370c6..a2eb9b0 100644
12993--- a/arch/x86/include/asm/apm.h
12994+++ b/arch/x86/include/asm/apm.h
12995@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
12996 __asm__ __volatile__(APM_DO_ZERO_SEGS
12997 "pushl %%edi\n\t"
12998 "pushl %%ebp\n\t"
12999- "lcall *%%cs:apm_bios_entry\n\t"
13000+ "lcall *%%ss:apm_bios_entry\n\t"
13001 "setc %%al\n\t"
13002 "popl %%ebp\n\t"
13003 "popl %%edi\n\t"
13004@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13005 __asm__ __volatile__(APM_DO_ZERO_SEGS
13006 "pushl %%edi\n\t"
13007 "pushl %%ebp\n\t"
13008- "lcall *%%cs:apm_bios_entry\n\t"
13009+ "lcall *%%ss:apm_bios_entry\n\t"
13010 "setc %%bl\n\t"
13011 "popl %%ebp\n\t"
13012 "popl %%edi\n\t"
13013diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13014index 722aa3b..3a0bb27 100644
13015--- a/arch/x86/include/asm/atomic.h
13016+++ b/arch/x86/include/asm/atomic.h
13017@@ -22,7 +22,18 @@
13018 */
13019 static inline int atomic_read(const atomic_t *v)
13020 {
13021- return (*(volatile int *)&(v)->counter);
13022+ return (*(volatile const int *)&(v)->counter);
13023+}
13024+
13025+/**
13026+ * atomic_read_unchecked - read atomic variable
13027+ * @v: pointer of type atomic_unchecked_t
13028+ *
13029+ * Atomically reads the value of @v.
13030+ */
13031+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13032+{
13033+ return (*(volatile const int *)&(v)->counter);
13034 }
13035
13036 /**
13037@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13038 }
13039
13040 /**
13041+ * atomic_set_unchecked - set atomic variable
13042+ * @v: pointer of type atomic_unchecked_t
13043+ * @i: required value
13044+ *
13045+ * Atomically sets the value of @v to @i.
13046+ */
13047+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13048+{
13049+ v->counter = i;
13050+}
13051+
13052+/**
13053 * atomic_add - add integer to atomic variable
13054 * @i: integer value to add
13055 * @v: pointer of type atomic_t
13056@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13057 */
13058 static inline void atomic_add(int i, atomic_t *v)
13059 {
13060- asm volatile(LOCK_PREFIX "addl %1,%0"
13061+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13062+
13063+#ifdef CONFIG_PAX_REFCOUNT
13064+ "jno 0f\n"
13065+ LOCK_PREFIX "subl %1,%0\n"
13066+ "int $4\n0:\n"
13067+ _ASM_EXTABLE(0b, 0b)
13068+#endif
13069+
13070+ : "+m" (v->counter)
13071+ : "ir" (i));
13072+}
13073+
13074+/**
13075+ * atomic_add_unchecked - add integer to atomic variable
13076+ * @i: integer value to add
13077+ * @v: pointer of type atomic_unchecked_t
13078+ *
13079+ * Atomically adds @i to @v.
13080+ */
13081+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13082+{
13083+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13084 : "+m" (v->counter)
13085 : "ir" (i));
13086 }
13087@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13088 */
13089 static inline void atomic_sub(int i, atomic_t *v)
13090 {
13091- asm volatile(LOCK_PREFIX "subl %1,%0"
13092+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13093+
13094+#ifdef CONFIG_PAX_REFCOUNT
13095+ "jno 0f\n"
13096+ LOCK_PREFIX "addl %1,%0\n"
13097+ "int $4\n0:\n"
13098+ _ASM_EXTABLE(0b, 0b)
13099+#endif
13100+
13101+ : "+m" (v->counter)
13102+ : "ir" (i));
13103+}
13104+
13105+/**
13106+ * atomic_sub_unchecked - subtract integer from atomic variable
13107+ * @i: integer value to subtract
13108+ * @v: pointer of type atomic_unchecked_t
13109+ *
13110+ * Atomically subtracts @i from @v.
13111+ */
13112+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13113+{
13114+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13115 : "+m" (v->counter)
13116 : "ir" (i));
13117 }
13118@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13119 {
13120 unsigned char c;
13121
13122- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13123+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13124+
13125+#ifdef CONFIG_PAX_REFCOUNT
13126+ "jno 0f\n"
13127+ LOCK_PREFIX "addl %2,%0\n"
13128+ "int $4\n0:\n"
13129+ _ASM_EXTABLE(0b, 0b)
13130+#endif
13131+
13132+ "sete %1\n"
13133 : "+m" (v->counter), "=qm" (c)
13134 : "ir" (i) : "memory");
13135 return c;
13136@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13137 */
13138 static inline void atomic_inc(atomic_t *v)
13139 {
13140- asm volatile(LOCK_PREFIX "incl %0"
13141+ asm volatile(LOCK_PREFIX "incl %0\n"
13142+
13143+#ifdef CONFIG_PAX_REFCOUNT
13144+ "jno 0f\n"
13145+ LOCK_PREFIX "decl %0\n"
13146+ "int $4\n0:\n"
13147+ _ASM_EXTABLE(0b, 0b)
13148+#endif
13149+
13150+ : "+m" (v->counter));
13151+}
13152+
13153+/**
13154+ * atomic_inc_unchecked - increment atomic variable
13155+ * @v: pointer of type atomic_unchecked_t
13156+ *
13157+ * Atomically increments @v by 1.
13158+ */
13159+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13160+{
13161+ asm volatile(LOCK_PREFIX "incl %0\n"
13162 : "+m" (v->counter));
13163 }
13164
13165@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13166 */
13167 static inline void atomic_dec(atomic_t *v)
13168 {
13169- asm volatile(LOCK_PREFIX "decl %0"
13170+ asm volatile(LOCK_PREFIX "decl %0\n"
13171+
13172+#ifdef CONFIG_PAX_REFCOUNT
13173+ "jno 0f\n"
13174+ LOCK_PREFIX "incl %0\n"
13175+ "int $4\n0:\n"
13176+ _ASM_EXTABLE(0b, 0b)
13177+#endif
13178+
13179+ : "+m" (v->counter));
13180+}
13181+
13182+/**
13183+ * atomic_dec_unchecked - decrement atomic variable
13184+ * @v: pointer of type atomic_unchecked_t
13185+ *
13186+ * Atomically decrements @v by 1.
13187+ */
13188+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13189+{
13190+ asm volatile(LOCK_PREFIX "decl %0\n"
13191 : "+m" (v->counter));
13192 }
13193
13194@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13195 {
13196 unsigned char c;
13197
13198- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13199+ asm volatile(LOCK_PREFIX "decl %0\n"
13200+
13201+#ifdef CONFIG_PAX_REFCOUNT
13202+ "jno 0f\n"
13203+ LOCK_PREFIX "incl %0\n"
13204+ "int $4\n0:\n"
13205+ _ASM_EXTABLE(0b, 0b)
13206+#endif
13207+
13208+ "sete %1\n"
13209 : "+m" (v->counter), "=qm" (c)
13210 : : "memory");
13211 return c != 0;
13212@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13213 {
13214 unsigned char c;
13215
13216- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13217+ asm volatile(LOCK_PREFIX "incl %0\n"
13218+
13219+#ifdef CONFIG_PAX_REFCOUNT
13220+ "jno 0f\n"
13221+ LOCK_PREFIX "decl %0\n"
13222+ "int $4\n0:\n"
13223+ _ASM_EXTABLE(0b, 0b)
13224+#endif
13225+
13226+ "sete %1\n"
13227+ : "+m" (v->counter), "=qm" (c)
13228+ : : "memory");
13229+ return c != 0;
13230+}
13231+
13232+/**
13233+ * atomic_inc_and_test_unchecked - increment and test
13234+ * @v: pointer of type atomic_unchecked_t
13235+ *
13236+ * Atomically increments @v by 1
13237+ * and returns true if the result is zero, or false for all
13238+ * other cases.
13239+ */
13240+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13241+{
13242+ unsigned char c;
13243+
13244+ asm volatile(LOCK_PREFIX "incl %0\n"
13245+ "sete %1\n"
13246 : "+m" (v->counter), "=qm" (c)
13247 : : "memory");
13248 return c != 0;
13249@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13250 {
13251 unsigned char c;
13252
13253- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
13254+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
13255+
13256+#ifdef CONFIG_PAX_REFCOUNT
13257+ "jno 0f\n"
13258+ LOCK_PREFIX "subl %2,%0\n"
13259+ "int $4\n0:\n"
13260+ _ASM_EXTABLE(0b, 0b)
13261+#endif
13262+
13263+ "sets %1\n"
13264 : "+m" (v->counter), "=qm" (c)
13265 : "ir" (i) : "memory");
13266 return c;
13267@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13268 */
13269 static inline int atomic_add_return(int i, atomic_t *v)
13270 {
13271+ return i + xadd_check_overflow(&v->counter, i);
13272+}
13273+
13274+/**
13275+ * atomic_add_return_unchecked - add integer and return
13276+ * @i: integer value to add
13277+ * @v: pointer of type atomic_unchecked_t
13278+ *
13279+ * Atomically adds @i to @v and returns @i + @v
13280+ */
13281+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
13282+{
13283 return i + xadd(&v->counter, i);
13284 }
13285
13286@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
13287 }
13288
13289 #define atomic_inc_return(v) (atomic_add_return(1, v))
13290+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
13291+{
13292+ return atomic_add_return_unchecked(1, v);
13293+}
13294 #define atomic_dec_return(v) (atomic_sub_return(1, v))
13295
13296 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13297@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13298 return cmpxchg(&v->counter, old, new);
13299 }
13300
13301+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
13302+{
13303+ return cmpxchg(&v->counter, old, new);
13304+}
13305+
13306 static inline int atomic_xchg(atomic_t *v, int new)
13307 {
13308 return xchg(&v->counter, new);
13309 }
13310
13311+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
13312+{
13313+ return xchg(&v->counter, new);
13314+}
13315+
13316 /**
13317 * __atomic_add_unless - add unless the number is already a given value
13318 * @v: pointer of type atomic_t
13319@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
13320 */
13321 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
13322 {
13323- int c, old;
13324+ int c, old, new;
13325 c = atomic_read(v);
13326 for (;;) {
13327- if (unlikely(c == (u)))
13328+ if (unlikely(c == u))
13329 break;
13330- old = atomic_cmpxchg((v), c, c + (a));
13331+
13332+ asm volatile("addl %2,%0\n"
13333+
13334+#ifdef CONFIG_PAX_REFCOUNT
13335+ "jno 0f\n"
13336+ "subl %2,%0\n"
13337+ "int $4\n0:\n"
13338+ _ASM_EXTABLE(0b, 0b)
13339+#endif
13340+
13341+ : "=r" (new)
13342+ : "0" (c), "ir" (a));
13343+
13344+ old = atomic_cmpxchg(v, c, new);
13345 if (likely(old == c))
13346 break;
13347 c = old;
13348@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
13349 }
13350
13351 /**
13352+ * atomic_inc_not_zero_hint - increment if not null
13353+ * @v: pointer of type atomic_t
13354+ * @hint: probable value of the atomic before the increment
13355+ *
13356+ * This version of atomic_inc_not_zero() gives a hint of probable
13357+ * value of the atomic. This helps processor to not read the memory
13358+ * before doing the atomic read/modify/write cycle, lowering
13359+ * number of bus transactions on some arches.
13360+ *
13361+ * Returns: 0 if increment was not done, 1 otherwise.
13362+ */
13363+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
13364+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
13365+{
13366+ int val, c = hint, new;
13367+
13368+ /* sanity test, should be removed by compiler if hint is a constant */
13369+ if (!hint)
13370+ return __atomic_add_unless(v, 1, 0);
13371+
13372+ do {
13373+ asm volatile("incl %0\n"
13374+
13375+#ifdef CONFIG_PAX_REFCOUNT
13376+ "jno 0f\n"
13377+ "decl %0\n"
13378+ "int $4\n0:\n"
13379+ _ASM_EXTABLE(0b, 0b)
13380+#endif
13381+
13382+ : "=r" (new)
13383+ : "0" (c));
13384+
13385+ val = atomic_cmpxchg(v, c, new);
13386+ if (val == c)
13387+ return 1;
13388+ c = val;
13389+ } while (c);
13390+
13391+ return 0;
13392+}
13393+
13394+/**
13395 * atomic_inc_short - increment of a short integer
13396 * @v: pointer to type int
13397 *
13398@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
13399 #endif
13400
13401 /* These are x86-specific, used by some header files */
13402-#define atomic_clear_mask(mask, addr) \
13403- asm volatile(LOCK_PREFIX "andl %0,%1" \
13404- : : "r" (~(mask)), "m" (*(addr)) : "memory")
13405+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
13406+{
13407+ asm volatile(LOCK_PREFIX "andl %1,%0"
13408+ : "+m" (v->counter)
13409+ : "r" (~(mask))
13410+ : "memory");
13411+}
13412
13413-#define atomic_set_mask(mask, addr) \
13414- asm volatile(LOCK_PREFIX "orl %0,%1" \
13415- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
13416- : "memory")
13417+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
13418+{
13419+ asm volatile(LOCK_PREFIX "andl %1,%0"
13420+ : "+m" (v->counter)
13421+ : "r" (~(mask))
13422+ : "memory");
13423+}
13424+
13425+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
13426+{
13427+ asm volatile(LOCK_PREFIX "orl %1,%0"
13428+ : "+m" (v->counter)
13429+ : "r" (mask)
13430+ : "memory");
13431+}
13432+
13433+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
13434+{
13435+ asm volatile(LOCK_PREFIX "orl %1,%0"
13436+ : "+m" (v->counter)
13437+ : "r" (mask)
13438+ : "memory");
13439+}
13440
13441 /* Atomic operations are already serializing on x86 */
13442 #define smp_mb__before_atomic_dec() barrier()
13443diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
13444index b154de7..aadebd8 100644
13445--- a/arch/x86/include/asm/atomic64_32.h
13446+++ b/arch/x86/include/asm/atomic64_32.h
13447@@ -12,6 +12,14 @@ typedef struct {
13448 u64 __aligned(8) counter;
13449 } atomic64_t;
13450
13451+#ifdef CONFIG_PAX_REFCOUNT
13452+typedef struct {
13453+ u64 __aligned(8) counter;
13454+} atomic64_unchecked_t;
13455+#else
13456+typedef atomic64_t atomic64_unchecked_t;
13457+#endif
13458+
13459 #define ATOMIC64_INIT(val) { (val) }
13460
13461 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
13462@@ -37,21 +45,31 @@ typedef struct {
13463 ATOMIC64_DECL_ONE(sym##_386)
13464
13465 ATOMIC64_DECL_ONE(add_386);
13466+ATOMIC64_DECL_ONE(add_unchecked_386);
13467 ATOMIC64_DECL_ONE(sub_386);
13468+ATOMIC64_DECL_ONE(sub_unchecked_386);
13469 ATOMIC64_DECL_ONE(inc_386);
13470+ATOMIC64_DECL_ONE(inc_unchecked_386);
13471 ATOMIC64_DECL_ONE(dec_386);
13472+ATOMIC64_DECL_ONE(dec_unchecked_386);
13473 #endif
13474
13475 #define alternative_atomic64(f, out, in...) \
13476 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
13477
13478 ATOMIC64_DECL(read);
13479+ATOMIC64_DECL(read_unchecked);
13480 ATOMIC64_DECL(set);
13481+ATOMIC64_DECL(set_unchecked);
13482 ATOMIC64_DECL(xchg);
13483 ATOMIC64_DECL(add_return);
13484+ATOMIC64_DECL(add_return_unchecked);
13485 ATOMIC64_DECL(sub_return);
13486+ATOMIC64_DECL(sub_return_unchecked);
13487 ATOMIC64_DECL(inc_return);
13488+ATOMIC64_DECL(inc_return_unchecked);
13489 ATOMIC64_DECL(dec_return);
13490+ATOMIC64_DECL(dec_return_unchecked);
13491 ATOMIC64_DECL(dec_if_positive);
13492 ATOMIC64_DECL(inc_not_zero);
13493 ATOMIC64_DECL(add_unless);
13494@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
13495 }
13496
13497 /**
13498+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
13499+ * @p: pointer to type atomic64_unchecked_t
13500+ * @o: expected value
13501+ * @n: new value
13502+ *
13503+ * Atomically sets @v to @n if it was equal to @o and returns
13504+ * the old value.
13505+ */
13506+
13507+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
13508+{
13509+ return cmpxchg64(&v->counter, o, n);
13510+}
13511+
13512+/**
13513 * atomic64_xchg - xchg atomic64 variable
13514 * @v: pointer to type atomic64_t
13515 * @n: value to assign
13516@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
13517 }
13518
13519 /**
13520+ * atomic64_set_unchecked - set atomic64 variable
13521+ * @v: pointer to type atomic64_unchecked_t
13522+ * @n: value to assign
13523+ *
13524+ * Atomically sets the value of @v to @n.
13525+ */
13526+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
13527+{
13528+ unsigned high = (unsigned)(i >> 32);
13529+ unsigned low = (unsigned)i;
13530+ alternative_atomic64(set, /* no output */,
13531+ "S" (v), "b" (low), "c" (high)
13532+ : "eax", "edx", "memory");
13533+}
13534+
13535+/**
13536 * atomic64_read - read atomic64 variable
13537 * @v: pointer to type atomic64_t
13538 *
13539@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
13540 }
13541
13542 /**
13543+ * atomic64_read_unchecked - read atomic64 variable
13544+ * @v: pointer to type atomic64_unchecked_t
13545+ *
13546+ * Atomically reads the value of @v and returns it.
13547+ */
13548+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
13549+{
13550+ long long r;
13551+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
13552+ return r;
13553+ }
13554+
13555+/**
13556 * atomic64_add_return - add and return
13557 * @i: integer value to add
13558 * @v: pointer to type atomic64_t
13559@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
13560 return i;
13561 }
13562
13563+/**
13564+ * atomic64_add_return_unchecked - add and return
13565+ * @i: integer value to add
13566+ * @v: pointer to type atomic64_unchecked_t
13567+ *
13568+ * Atomically adds @i to @v and returns @i + *@v
13569+ */
13570+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
13571+{
13572+ alternative_atomic64(add_return_unchecked,
13573+ ASM_OUTPUT2("+A" (i), "+c" (v)),
13574+ ASM_NO_INPUT_CLOBBER("memory"));
13575+ return i;
13576+}
13577+
13578 /*
13579 * Other variants with different arithmetic operators:
13580 */
13581@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
13582 return a;
13583 }
13584
13585+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13586+{
13587+ long long a;
13588+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
13589+ "S" (v) : "memory", "ecx");
13590+ return a;
13591+}
13592+
13593 static inline long long atomic64_dec_return(atomic64_t *v)
13594 {
13595 long long a;
13596@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
13597 }
13598
13599 /**
13600+ * atomic64_add_unchecked - add integer to atomic64 variable
13601+ * @i: integer value to add
13602+ * @v: pointer to type atomic64_unchecked_t
13603+ *
13604+ * Atomically adds @i to @v.
13605+ */
13606+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
13607+{
13608+ __alternative_atomic64(add_unchecked, add_return_unchecked,
13609+ ASM_OUTPUT2("+A" (i), "+c" (v)),
13610+ ASM_NO_INPUT_CLOBBER("memory"));
13611+ return i;
13612+}
13613+
13614+/**
13615 * atomic64_sub - subtract the atomic64 variable
13616 * @i: integer value to subtract
13617 * @v: pointer to type atomic64_t
13618diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
13619index 0e1cbfc..5623683 100644
13620--- a/arch/x86/include/asm/atomic64_64.h
13621+++ b/arch/x86/include/asm/atomic64_64.h
13622@@ -18,7 +18,19 @@
13623 */
13624 static inline long atomic64_read(const atomic64_t *v)
13625 {
13626- return (*(volatile long *)&(v)->counter);
13627+ return (*(volatile const long *)&(v)->counter);
13628+}
13629+
13630+/**
13631+ * atomic64_read_unchecked - read atomic64 variable
13632+ * @v: pointer of type atomic64_unchecked_t
13633+ *
13634+ * Atomically reads the value of @v.
13635+ * Doesn't imply a read memory barrier.
13636+ */
13637+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
13638+{
13639+ return (*(volatile const long *)&(v)->counter);
13640 }
13641
13642 /**
13643@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
13644 }
13645
13646 /**
13647+ * atomic64_set_unchecked - set atomic64 variable
13648+ * @v: pointer to type atomic64_unchecked_t
13649+ * @i: required value
13650+ *
13651+ * Atomically sets the value of @v to @i.
13652+ */
13653+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
13654+{
13655+ v->counter = i;
13656+}
13657+
13658+/**
13659 * atomic64_add - add integer to atomic64 variable
13660 * @i: integer value to add
13661 * @v: pointer to type atomic64_t
13662@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
13663 */
13664 static inline void atomic64_add(long i, atomic64_t *v)
13665 {
13666+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
13667+
13668+#ifdef CONFIG_PAX_REFCOUNT
13669+ "jno 0f\n"
13670+ LOCK_PREFIX "subq %1,%0\n"
13671+ "int $4\n0:\n"
13672+ _ASM_EXTABLE(0b, 0b)
13673+#endif
13674+
13675+ : "=m" (v->counter)
13676+ : "er" (i), "m" (v->counter));
13677+}
13678+
13679+/**
13680+ * atomic64_add_unchecked - add integer to atomic64 variable
13681+ * @i: integer value to add
13682+ * @v: pointer to type atomic64_unchecked_t
13683+ *
13684+ * Atomically adds @i to @v.
13685+ */
13686+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
13687+{
13688 asm volatile(LOCK_PREFIX "addq %1,%0"
13689 : "=m" (v->counter)
13690 : "er" (i), "m" (v->counter));
13691@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
13692 */
13693 static inline void atomic64_sub(long i, atomic64_t *v)
13694 {
13695- asm volatile(LOCK_PREFIX "subq %1,%0"
13696+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13697+
13698+#ifdef CONFIG_PAX_REFCOUNT
13699+ "jno 0f\n"
13700+ LOCK_PREFIX "addq %1,%0\n"
13701+ "int $4\n0:\n"
13702+ _ASM_EXTABLE(0b, 0b)
13703+#endif
13704+
13705+ : "=m" (v->counter)
13706+ : "er" (i), "m" (v->counter));
13707+}
13708+
13709+/**
13710+ * atomic64_sub_unchecked - subtract the atomic64 variable
13711+ * @i: integer value to subtract
13712+ * @v: pointer to type atomic64_unchecked_t
13713+ *
13714+ * Atomically subtracts @i from @v.
13715+ */
13716+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
13717+{
13718+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
13719 : "=m" (v->counter)
13720 : "er" (i), "m" (v->counter));
13721 }
13722@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13723 {
13724 unsigned char c;
13725
13726- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
13727+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
13728+
13729+#ifdef CONFIG_PAX_REFCOUNT
13730+ "jno 0f\n"
13731+ LOCK_PREFIX "addq %2,%0\n"
13732+ "int $4\n0:\n"
13733+ _ASM_EXTABLE(0b, 0b)
13734+#endif
13735+
13736+ "sete %1\n"
13737 : "=m" (v->counter), "=qm" (c)
13738 : "er" (i), "m" (v->counter) : "memory");
13739 return c;
13740@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
13741 */
13742 static inline void atomic64_inc(atomic64_t *v)
13743 {
13744+ asm volatile(LOCK_PREFIX "incq %0\n"
13745+
13746+#ifdef CONFIG_PAX_REFCOUNT
13747+ "jno 0f\n"
13748+ LOCK_PREFIX "decq %0\n"
13749+ "int $4\n0:\n"
13750+ _ASM_EXTABLE(0b, 0b)
13751+#endif
13752+
13753+ : "=m" (v->counter)
13754+ : "m" (v->counter));
13755+}
13756+
13757+/**
13758+ * atomic64_inc_unchecked - increment atomic64 variable
13759+ * @v: pointer to type atomic64_unchecked_t
13760+ *
13761+ * Atomically increments @v by 1.
13762+ */
13763+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
13764+{
13765 asm volatile(LOCK_PREFIX "incq %0"
13766 : "=m" (v->counter)
13767 : "m" (v->counter));
13768@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
13769 */
13770 static inline void atomic64_dec(atomic64_t *v)
13771 {
13772- asm volatile(LOCK_PREFIX "decq %0"
13773+ asm volatile(LOCK_PREFIX "decq %0\n"
13774+
13775+#ifdef CONFIG_PAX_REFCOUNT
13776+ "jno 0f\n"
13777+ LOCK_PREFIX "incq %0\n"
13778+ "int $4\n0:\n"
13779+ _ASM_EXTABLE(0b, 0b)
13780+#endif
13781+
13782+ : "=m" (v->counter)
13783+ : "m" (v->counter));
13784+}
13785+
13786+/**
13787+ * atomic64_dec_unchecked - decrement atomic64 variable
13788+ * @v: pointer to type atomic64_t
13789+ *
13790+ * Atomically decrements @v by 1.
13791+ */
13792+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
13793+{
13794+ asm volatile(LOCK_PREFIX "decq %0\n"
13795 : "=m" (v->counter)
13796 : "m" (v->counter));
13797 }
13798@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
13799 {
13800 unsigned char c;
13801
13802- asm volatile(LOCK_PREFIX "decq %0; sete %1"
13803+ asm volatile(LOCK_PREFIX "decq %0\n"
13804+
13805+#ifdef CONFIG_PAX_REFCOUNT
13806+ "jno 0f\n"
13807+ LOCK_PREFIX "incq %0\n"
13808+ "int $4\n0:\n"
13809+ _ASM_EXTABLE(0b, 0b)
13810+#endif
13811+
13812+ "sete %1\n"
13813 : "=m" (v->counter), "=qm" (c)
13814 : "m" (v->counter) : "memory");
13815 return c != 0;
13816@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
13817 {
13818 unsigned char c;
13819
13820- asm volatile(LOCK_PREFIX "incq %0; sete %1"
13821+ asm volatile(LOCK_PREFIX "incq %0\n"
13822+
13823+#ifdef CONFIG_PAX_REFCOUNT
13824+ "jno 0f\n"
13825+ LOCK_PREFIX "decq %0\n"
13826+ "int $4\n0:\n"
13827+ _ASM_EXTABLE(0b, 0b)
13828+#endif
13829+
13830+ "sete %1\n"
13831 : "=m" (v->counter), "=qm" (c)
13832 : "m" (v->counter) : "memory");
13833 return c != 0;
13834@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13835 {
13836 unsigned char c;
13837
13838- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
13839+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
13840+
13841+#ifdef CONFIG_PAX_REFCOUNT
13842+ "jno 0f\n"
13843+ LOCK_PREFIX "subq %2,%0\n"
13844+ "int $4\n0:\n"
13845+ _ASM_EXTABLE(0b, 0b)
13846+#endif
13847+
13848+ "sets %1\n"
13849 : "=m" (v->counter), "=qm" (c)
13850 : "er" (i), "m" (v->counter) : "memory");
13851 return c;
13852@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
13853 */
13854 static inline long atomic64_add_return(long i, atomic64_t *v)
13855 {
13856+ return i + xadd_check_overflow(&v->counter, i);
13857+}
13858+
13859+/**
13860+ * atomic64_add_return_unchecked - add and return
13861+ * @i: integer value to add
13862+ * @v: pointer to type atomic64_unchecked_t
13863+ *
13864+ * Atomically adds @i to @v and returns @i + @v
13865+ */
13866+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
13867+{
13868 return i + xadd(&v->counter, i);
13869 }
13870
13871@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
13872 }
13873
13874 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
13875+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
13876+{
13877+ return atomic64_add_return_unchecked(1, v);
13878+}
13879 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
13880
13881 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13882@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
13883 return cmpxchg(&v->counter, old, new);
13884 }
13885
13886+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
13887+{
13888+ return cmpxchg(&v->counter, old, new);
13889+}
13890+
13891 static inline long atomic64_xchg(atomic64_t *v, long new)
13892 {
13893 return xchg(&v->counter, new);
13894@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
13895 */
13896 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
13897 {
13898- long c, old;
13899+ long c, old, new;
13900 c = atomic64_read(v);
13901 for (;;) {
13902- if (unlikely(c == (u)))
13903+ if (unlikely(c == u))
13904 break;
13905- old = atomic64_cmpxchg((v), c, c + (a));
13906+
13907+ asm volatile("add %2,%0\n"
13908+
13909+#ifdef CONFIG_PAX_REFCOUNT
13910+ "jno 0f\n"
13911+ "sub %2,%0\n"
13912+ "int $4\n0:\n"
13913+ _ASM_EXTABLE(0b, 0b)
13914+#endif
13915+
13916+ : "=r" (new)
13917+ : "0" (c), "ir" (a));
13918+
13919+ old = atomic64_cmpxchg(v, c, new);
13920 if (likely(old == c))
13921 break;
13922 c = old;
13923 }
13924- return c != (u);
13925+ return c != u;
13926 }
13927
13928 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13929diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
13930index 6dfd019..28e188d 100644
13931--- a/arch/x86/include/asm/bitops.h
13932+++ b/arch/x86/include/asm/bitops.h
13933@@ -40,7 +40,7 @@
13934 * a mask operation on a byte.
13935 */
13936 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
13937-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
13938+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
13939 #define CONST_MASK(nr) (1 << ((nr) & 7))
13940
13941 /**
13942@@ -486,7 +486,7 @@ static inline int fls(int x)
13943 * at position 64.
13944 */
13945 #ifdef CONFIG_X86_64
13946-static __always_inline int fls64(__u64 x)
13947+static __always_inline long fls64(__u64 x)
13948 {
13949 int bitpos = -1;
13950 /*
13951diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
13952index 4fa687a..60f2d39 100644
13953--- a/arch/x86/include/asm/boot.h
13954+++ b/arch/x86/include/asm/boot.h
13955@@ -6,10 +6,15 @@
13956 #include <uapi/asm/boot.h>
13957
13958 /* Physical address where kernel should be loaded. */
13959-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13960+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
13961 + (CONFIG_PHYSICAL_ALIGN - 1)) \
13962 & ~(CONFIG_PHYSICAL_ALIGN - 1))
13963
13964+#ifndef __ASSEMBLY__
13965+extern unsigned char __LOAD_PHYSICAL_ADDR[];
13966+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
13967+#endif
13968+
13969 /* Minimum kernel alignment, as a power of two */
13970 #ifdef CONFIG_X86_64
13971 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
13972diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
13973index 48f99f1..d78ebf9 100644
13974--- a/arch/x86/include/asm/cache.h
13975+++ b/arch/x86/include/asm/cache.h
13976@@ -5,12 +5,13 @@
13977
13978 /* L1 cache line size */
13979 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13980-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13981+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13982
13983 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
13984+#define __read_only __attribute__((__section__(".data..read_only")))
13985
13986 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
13987-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
13988+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
13989
13990 #ifdef CONFIG_X86_VSMP
13991 #ifdef CONFIG_SMP
13992diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
13993index 9863ee3..4a1f8e1 100644
13994--- a/arch/x86/include/asm/cacheflush.h
13995+++ b/arch/x86/include/asm/cacheflush.h
13996@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
13997 unsigned long pg_flags = pg->flags & _PGMT_MASK;
13998
13999 if (pg_flags == _PGMT_DEFAULT)
14000- return -1;
14001+ return ~0UL;
14002 else if (pg_flags == _PGMT_WC)
14003 return _PAGE_CACHE_WC;
14004 else if (pg_flags == _PGMT_UC_MINUS)
14005diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14006index 46fc474..b02b0f9 100644
14007--- a/arch/x86/include/asm/checksum_32.h
14008+++ b/arch/x86/include/asm/checksum_32.h
14009@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14010 int len, __wsum sum,
14011 int *src_err_ptr, int *dst_err_ptr);
14012
14013+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14014+ int len, __wsum sum,
14015+ int *src_err_ptr, int *dst_err_ptr);
14016+
14017+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14018+ int len, __wsum sum,
14019+ int *src_err_ptr, int *dst_err_ptr);
14020+
14021 /*
14022 * Note: when you get a NULL pointer exception here this means someone
14023 * passed in an incorrect kernel address to one of these functions.
14024@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14025 int *err_ptr)
14026 {
14027 might_sleep();
14028- return csum_partial_copy_generic((__force void *)src, dst,
14029+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
14030 len, sum, err_ptr, NULL);
14031 }
14032
14033@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14034 {
14035 might_sleep();
14036 if (access_ok(VERIFY_WRITE, dst, len))
14037- return csum_partial_copy_generic(src, (__force void *)dst,
14038+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
14039 len, sum, NULL, err_ptr);
14040
14041 if (len)
14042diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14043index d47786a..ce1b05d 100644
14044--- a/arch/x86/include/asm/cmpxchg.h
14045+++ b/arch/x86/include/asm/cmpxchg.h
14046@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14047 __compiletime_error("Bad argument size for cmpxchg");
14048 extern void __xadd_wrong_size(void)
14049 __compiletime_error("Bad argument size for xadd");
14050+extern void __xadd_check_overflow_wrong_size(void)
14051+ __compiletime_error("Bad argument size for xadd_check_overflow");
14052 extern void __add_wrong_size(void)
14053 __compiletime_error("Bad argument size for add");
14054+extern void __add_check_overflow_wrong_size(void)
14055+ __compiletime_error("Bad argument size for add_check_overflow");
14056
14057 /*
14058 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14059@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14060 __ret; \
14061 })
14062
14063+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14064+ ({ \
14065+ __typeof__ (*(ptr)) __ret = (arg); \
14066+ switch (sizeof(*(ptr))) { \
14067+ case __X86_CASE_L: \
14068+ asm volatile (lock #op "l %0, %1\n" \
14069+ "jno 0f\n" \
14070+ "mov %0,%1\n" \
14071+ "int $4\n0:\n" \
14072+ _ASM_EXTABLE(0b, 0b) \
14073+ : "+r" (__ret), "+m" (*(ptr)) \
14074+ : : "memory", "cc"); \
14075+ break; \
14076+ case __X86_CASE_Q: \
14077+ asm volatile (lock #op "q %q0, %1\n" \
14078+ "jno 0f\n" \
14079+ "mov %0,%1\n" \
14080+ "int $4\n0:\n" \
14081+ _ASM_EXTABLE(0b, 0b) \
14082+ : "+r" (__ret), "+m" (*(ptr)) \
14083+ : : "memory", "cc"); \
14084+ break; \
14085+ default: \
14086+ __ ## op ## _check_overflow_wrong_size(); \
14087+ } \
14088+ __ret; \
14089+ })
14090+
14091 /*
14092 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14093 * Since this is generally used to protect other memory information, we
14094@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14095 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14096 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14097
14098+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14099+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14100+
14101 #define __add(ptr, inc, lock) \
14102 ({ \
14103 __typeof__ (*(ptr)) __ret = (inc); \
14104diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14105index 59c6c40..5e0b22c 100644
14106--- a/arch/x86/include/asm/compat.h
14107+++ b/arch/x86/include/asm/compat.h
14108@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14109 typedef u32 compat_uint_t;
14110 typedef u32 compat_ulong_t;
14111 typedef u64 __attribute__((aligned(4))) compat_u64;
14112-typedef u32 compat_uptr_t;
14113+typedef u32 __user compat_uptr_t;
14114
14115 struct compat_timespec {
14116 compat_time_t tv_sec;
14117diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14118index e99ac27..10d834e 100644
14119--- a/arch/x86/include/asm/cpufeature.h
14120+++ b/arch/x86/include/asm/cpufeature.h
14121@@ -203,7 +203,7 @@
14122 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14123 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14124 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14125-
14126+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14127
14128 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14129 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14130@@ -211,7 +211,7 @@
14131 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14132 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14133 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14134-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14135+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14136 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14137 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14138 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14139@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14140 #undef cpu_has_centaur_mcr
14141 #define cpu_has_centaur_mcr 0
14142
14143+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14144 #endif /* CONFIG_X86_64 */
14145
14146 #if __GNUC__ >= 4
14147@@ -394,7 +395,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14148 ".section .discard,\"aw\",@progbits\n"
14149 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14150 ".previous\n"
14151- ".section .altinstr_replacement,\"ax\"\n"
14152+ ".section .altinstr_replacement,\"a\"\n"
14153 "3: movb $1,%0\n"
14154 "4:\n"
14155 ".previous\n"
14156diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14157index 8bf1c06..b6ae785 100644
14158--- a/arch/x86/include/asm/desc.h
14159+++ b/arch/x86/include/asm/desc.h
14160@@ -4,6 +4,7 @@
14161 #include <asm/desc_defs.h>
14162 #include <asm/ldt.h>
14163 #include <asm/mmu.h>
14164+#include <asm/pgtable.h>
14165
14166 #include <linux/smp.h>
14167 #include <linux/percpu.h>
14168@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14169
14170 desc->type = (info->read_exec_only ^ 1) << 1;
14171 desc->type |= info->contents << 2;
14172+ desc->type |= info->seg_not_present ^ 1;
14173
14174 desc->s = 1;
14175 desc->dpl = 0x3;
14176@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14177 }
14178
14179 extern struct desc_ptr idt_descr;
14180-extern gate_desc idt_table[];
14181 extern struct desc_ptr nmi_idt_descr;
14182-extern gate_desc nmi_idt_table[];
14183-
14184-struct gdt_page {
14185- struct desc_struct gdt[GDT_ENTRIES];
14186-} __attribute__((aligned(PAGE_SIZE)));
14187-
14188-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14189+extern gate_desc idt_table[256];
14190+extern gate_desc nmi_idt_table[256];
14191
14192+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14193 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14194 {
14195- return per_cpu(gdt_page, cpu).gdt;
14196+ return cpu_gdt_table[cpu];
14197 }
14198
14199 #ifdef CONFIG_X86_64
14200@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14201 unsigned long base, unsigned dpl, unsigned flags,
14202 unsigned short seg)
14203 {
14204- gate->a = (seg << 16) | (base & 0xffff);
14205- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
14206+ gate->gate.offset_low = base;
14207+ gate->gate.seg = seg;
14208+ gate->gate.reserved = 0;
14209+ gate->gate.type = type;
14210+ gate->gate.s = 0;
14211+ gate->gate.dpl = dpl;
14212+ gate->gate.p = 1;
14213+ gate->gate.offset_high = base >> 16;
14214 }
14215
14216 #endif
14217@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
14218
14219 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
14220 {
14221+ pax_open_kernel();
14222 memcpy(&idt[entry], gate, sizeof(*gate));
14223+ pax_close_kernel();
14224 }
14225
14226 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
14227 {
14228+ pax_open_kernel();
14229 memcpy(&ldt[entry], desc, 8);
14230+ pax_close_kernel();
14231 }
14232
14233 static inline void
14234@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
14235 default: size = sizeof(*gdt); break;
14236 }
14237
14238+ pax_open_kernel();
14239 memcpy(&gdt[entry], desc, size);
14240+ pax_close_kernel();
14241 }
14242
14243 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
14244@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
14245
14246 static inline void native_load_tr_desc(void)
14247 {
14248+ pax_open_kernel();
14249 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
14250+ pax_close_kernel();
14251 }
14252
14253 static inline void native_load_gdt(const struct desc_ptr *dtr)
14254@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
14255 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
14256 unsigned int i;
14257
14258+ pax_open_kernel();
14259 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
14260 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
14261+ pax_close_kernel();
14262 }
14263
14264 #define _LDT_empty(info) \
14265@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
14266 preempt_enable();
14267 }
14268
14269-static inline unsigned long get_desc_base(const struct desc_struct *desc)
14270+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
14271 {
14272 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
14273 }
14274@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
14275 }
14276
14277 #ifdef CONFIG_X86_64
14278-static inline void set_nmi_gate(int gate, void *addr)
14279+static inline void set_nmi_gate(int gate, const void *addr)
14280 {
14281 gate_desc s;
14282
14283@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
14284 }
14285 #endif
14286
14287-static inline void _set_gate(int gate, unsigned type, void *addr,
14288+static inline void _set_gate(int gate, unsigned type, const void *addr,
14289 unsigned dpl, unsigned ist, unsigned seg)
14290 {
14291 gate_desc s;
14292@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
14293 * Pentium F0 0F bugfix can have resulted in the mapped
14294 * IDT being write-protected.
14295 */
14296-static inline void set_intr_gate(unsigned int n, void *addr)
14297+static inline void set_intr_gate(unsigned int n, const void *addr)
14298 {
14299 BUG_ON((unsigned)n > 0xFF);
14300 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
14301@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
14302 /*
14303 * This routine sets up an interrupt gate at directory privilege level 3.
14304 */
14305-static inline void set_system_intr_gate(unsigned int n, void *addr)
14306+static inline void set_system_intr_gate(unsigned int n, const void *addr)
14307 {
14308 BUG_ON((unsigned)n > 0xFF);
14309 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
14310 }
14311
14312-static inline void set_system_trap_gate(unsigned int n, void *addr)
14313+static inline void set_system_trap_gate(unsigned int n, const void *addr)
14314 {
14315 BUG_ON((unsigned)n > 0xFF);
14316 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
14317 }
14318
14319-static inline void set_trap_gate(unsigned int n, void *addr)
14320+static inline void set_trap_gate(unsigned int n, const void *addr)
14321 {
14322 BUG_ON((unsigned)n > 0xFF);
14323 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
14324@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
14325 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
14326 {
14327 BUG_ON((unsigned)n > 0xFF);
14328- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
14329+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
14330 }
14331
14332-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
14333+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
14334 {
14335 BUG_ON((unsigned)n > 0xFF);
14336 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
14337 }
14338
14339-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
14340+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
14341 {
14342 BUG_ON((unsigned)n > 0xFF);
14343 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
14344 }
14345
14346+#ifdef CONFIG_X86_32
14347+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
14348+{
14349+ struct desc_struct d;
14350+
14351+ if (likely(limit))
14352+ limit = (limit - 1UL) >> PAGE_SHIFT;
14353+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
14354+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
14355+}
14356+#endif
14357+
14358 #endif /* _ASM_X86_DESC_H */
14359diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
14360index 278441f..b95a174 100644
14361--- a/arch/x86/include/asm/desc_defs.h
14362+++ b/arch/x86/include/asm/desc_defs.h
14363@@ -31,6 +31,12 @@ struct desc_struct {
14364 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
14365 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
14366 };
14367+ struct {
14368+ u16 offset_low;
14369+ u16 seg;
14370+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
14371+ unsigned offset_high: 16;
14372+ } gate;
14373 };
14374 } __attribute__((packed));
14375
14376diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
14377index ced283a..ffe04cc 100644
14378--- a/arch/x86/include/asm/div64.h
14379+++ b/arch/x86/include/asm/div64.h
14380@@ -39,7 +39,7 @@
14381 __mod; \
14382 })
14383
14384-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
14385+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
14386 {
14387 union {
14388 u64 v64;
14389diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
14390index 9c999c1..3860cb8 100644
14391--- a/arch/x86/include/asm/elf.h
14392+++ b/arch/x86/include/asm/elf.h
14393@@ -243,7 +243,25 @@ extern int force_personality32;
14394 the loader. We need to make sure that it is out of the way of the program
14395 that it will "exec", and that there is sufficient room for the brk. */
14396
14397+#ifdef CONFIG_PAX_SEGMEXEC
14398+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
14399+#else
14400 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
14401+#endif
14402+
14403+#ifdef CONFIG_PAX_ASLR
14404+#ifdef CONFIG_X86_32
14405+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
14406+
14407+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
14408+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
14409+#else
14410+#define PAX_ELF_ET_DYN_BASE 0x400000UL
14411+
14412+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
14413+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
14414+#endif
14415+#endif
14416
14417 /* This yields a mask that user programs can use to figure out what
14418 instruction set this CPU supports. This could be done in user space,
14419@@ -296,16 +314,12 @@ do { \
14420
14421 #define ARCH_DLINFO \
14422 do { \
14423- if (vdso_enabled) \
14424- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
14425- (unsigned long)current->mm->context.vdso); \
14426+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
14427 } while (0)
14428
14429 #define ARCH_DLINFO_X32 \
14430 do { \
14431- if (vdso_enabled) \
14432- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
14433- (unsigned long)current->mm->context.vdso); \
14434+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
14435 } while (0)
14436
14437 #define AT_SYSINFO 32
14438@@ -320,7 +334,7 @@ else \
14439
14440 #endif /* !CONFIG_X86_32 */
14441
14442-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
14443+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
14444
14445 #define VDSO_ENTRY \
14446 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
14447@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
14448 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
14449 #define compat_arch_setup_additional_pages syscall32_setup_pages
14450
14451-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
14452-#define arch_randomize_brk arch_randomize_brk
14453-
14454 /*
14455 * True on X86_32 or when emulating IA32 on X86_64
14456 */
14457diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
14458index 75ce3f4..882e801 100644
14459--- a/arch/x86/include/asm/emergency-restart.h
14460+++ b/arch/x86/include/asm/emergency-restart.h
14461@@ -13,6 +13,6 @@ enum reboot_type {
14462
14463 extern enum reboot_type reboot_type;
14464
14465-extern void machine_emergency_restart(void);
14466+extern void machine_emergency_restart(void) __noreturn;
14467
14468 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
14469diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
14470index e25cc33..7d3ec01 100644
14471--- a/arch/x86/include/asm/fpu-internal.h
14472+++ b/arch/x86/include/asm/fpu-internal.h
14473@@ -126,8 +126,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
14474 #define user_insn(insn, output, input...) \
14475 ({ \
14476 int err; \
14477+ pax_open_userland(); \
14478 asm volatile(ASM_STAC "\n" \
14479- "1:" #insn "\n\t" \
14480+ "1:" \
14481+ __copyuser_seg \
14482+ #insn "\n\t" \
14483 "2: " ASM_CLAC "\n" \
14484 ".section .fixup,\"ax\"\n" \
14485 "3: movl $-1,%[err]\n" \
14486@@ -136,6 +139,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
14487 _ASM_EXTABLE(1b, 3b) \
14488 : [err] "=r" (err), output \
14489 : "0"(0), input); \
14490+ pax_close_userland(); \
14491 err; \
14492 })
14493
14494@@ -300,7 +304,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
14495 "emms\n\t" /* clear stack tags */
14496 "fildl %P[addr]", /* set F?P to defined value */
14497 X86_FEATURE_FXSAVE_LEAK,
14498- [addr] "m" (tsk->thread.fpu.has_fpu));
14499+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
14500
14501 return fpu_restore_checking(&tsk->thread.fpu);
14502 }
14503diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
14504index be27ba1..04a8801 100644
14505--- a/arch/x86/include/asm/futex.h
14506+++ b/arch/x86/include/asm/futex.h
14507@@ -12,6 +12,7 @@
14508 #include <asm/smap.h>
14509
14510 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
14511+ typecheck(u32 __user *, uaddr); \
14512 asm volatile("\t" ASM_STAC "\n" \
14513 "1:\t" insn "\n" \
14514 "2:\t" ASM_CLAC "\n" \
14515@@ -20,15 +21,16 @@
14516 "\tjmp\t2b\n" \
14517 "\t.previous\n" \
14518 _ASM_EXTABLE(1b, 3b) \
14519- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
14520+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
14521 : "i" (-EFAULT), "0" (oparg), "1" (0))
14522
14523 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
14524+ typecheck(u32 __user *, uaddr); \
14525 asm volatile("\t" ASM_STAC "\n" \
14526 "1:\tmovl %2, %0\n" \
14527 "\tmovl\t%0, %3\n" \
14528 "\t" insn "\n" \
14529- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
14530+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
14531 "\tjnz\t1b\n" \
14532 "3:\t" ASM_CLAC "\n" \
14533 "\t.section .fixup,\"ax\"\n" \
14534@@ -38,7 +40,7 @@
14535 _ASM_EXTABLE(1b, 4b) \
14536 _ASM_EXTABLE(2b, 4b) \
14537 : "=&a" (oldval), "=&r" (ret), \
14538- "+m" (*uaddr), "=&r" (tem) \
14539+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
14540 : "r" (oparg), "i" (-EFAULT), "1" (0))
14541
14542 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
14543@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
14544
14545 pagefault_disable();
14546
14547+ pax_open_userland();
14548 switch (op) {
14549 case FUTEX_OP_SET:
14550- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
14551+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
14552 break;
14553 case FUTEX_OP_ADD:
14554- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
14555+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
14556 uaddr, oparg);
14557 break;
14558 case FUTEX_OP_OR:
14559@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
14560 default:
14561 ret = -ENOSYS;
14562 }
14563+ pax_close_userland();
14564
14565 pagefault_enable();
14566
14567@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
14568 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
14569 return -EFAULT;
14570
14571+ pax_open_userland();
14572 asm volatile("\t" ASM_STAC "\n"
14573- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
14574+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
14575 "2:\t" ASM_CLAC "\n"
14576 "\t.section .fixup, \"ax\"\n"
14577 "3:\tmov %3, %0\n"
14578 "\tjmp 2b\n"
14579 "\t.previous\n"
14580 _ASM_EXTABLE(1b, 3b)
14581- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
14582+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
14583 : "i" (-EFAULT), "r" (newval), "1" (oldval)
14584 : "memory"
14585 );
14586+ pax_close_userland();
14587
14588 *uval = oldval;
14589 return ret;
14590diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
14591index 1da97ef..9c2ebff 100644
14592--- a/arch/x86/include/asm/hw_irq.h
14593+++ b/arch/x86/include/asm/hw_irq.h
14594@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
14595 extern void enable_IO_APIC(void);
14596
14597 /* Statistics */
14598-extern atomic_t irq_err_count;
14599-extern atomic_t irq_mis_count;
14600+extern atomic_unchecked_t irq_err_count;
14601+extern atomic_unchecked_t irq_mis_count;
14602
14603 /* EISA */
14604 extern void eisa_set_level_irq(unsigned int irq);
14605diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
14606index a203659..9889f1c 100644
14607--- a/arch/x86/include/asm/i8259.h
14608+++ b/arch/x86/include/asm/i8259.h
14609@@ -62,7 +62,7 @@ struct legacy_pic {
14610 void (*init)(int auto_eoi);
14611 int (*irq_pending)(unsigned int irq);
14612 void (*make_irq)(unsigned int irq);
14613-};
14614+} __do_const;
14615
14616 extern struct legacy_pic *legacy_pic;
14617 extern struct legacy_pic null_legacy_pic;
14618diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
14619index d8e8eef..1765f78 100644
14620--- a/arch/x86/include/asm/io.h
14621+++ b/arch/x86/include/asm/io.h
14622@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
14623 "m" (*(volatile type __force *)addr) barrier); }
14624
14625 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
14626-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
14627-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
14628+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
14629+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
14630
14631 build_mmio_read(__readb, "b", unsigned char, "=q", )
14632-build_mmio_read(__readw, "w", unsigned short, "=r", )
14633-build_mmio_read(__readl, "l", unsigned int, "=r", )
14634+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
14635+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
14636
14637 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
14638 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
14639@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
14640 return ioremap_nocache(offset, size);
14641 }
14642
14643-extern void iounmap(volatile void __iomem *addr);
14644+extern void iounmap(const volatile void __iomem *addr);
14645
14646 extern void set_iounmap_nonlazy(void);
14647
14648@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
14649
14650 #include <linux/vmalloc.h>
14651
14652+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
14653+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
14654+{
14655+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
14656+}
14657+
14658+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
14659+{
14660+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
14661+}
14662+
14663 /*
14664 * Convert a virtual cached pointer to an uncached pointer
14665 */
14666diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
14667index bba3cf8..06bc8da 100644
14668--- a/arch/x86/include/asm/irqflags.h
14669+++ b/arch/x86/include/asm/irqflags.h
14670@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
14671 sti; \
14672 sysexit
14673
14674+#define GET_CR0_INTO_RDI mov %cr0, %rdi
14675+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
14676+#define GET_CR3_INTO_RDI mov %cr3, %rdi
14677+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
14678+
14679 #else
14680 #define INTERRUPT_RETURN iret
14681 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
14682diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
14683index 5a6d287..f815789 100644
14684--- a/arch/x86/include/asm/kprobes.h
14685+++ b/arch/x86/include/asm/kprobes.h
14686@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
14687 #define RELATIVEJUMP_SIZE 5
14688 #define RELATIVECALL_OPCODE 0xe8
14689 #define RELATIVE_ADDR_SIZE 4
14690-#define MAX_STACK_SIZE 64
14691-#define MIN_STACK_SIZE(ADDR) \
14692- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
14693- THREAD_SIZE - (unsigned long)(ADDR))) \
14694- ? (MAX_STACK_SIZE) \
14695- : (((unsigned long)current_thread_info()) + \
14696- THREAD_SIZE - (unsigned long)(ADDR)))
14697+#define MAX_STACK_SIZE 64UL
14698+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
14699
14700 #define flush_insn_slot(p) do { } while (0)
14701
14702diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
14703index 2d89e39..baee879 100644
14704--- a/arch/x86/include/asm/local.h
14705+++ b/arch/x86/include/asm/local.h
14706@@ -10,33 +10,97 @@ typedef struct {
14707 atomic_long_t a;
14708 } local_t;
14709
14710+typedef struct {
14711+ atomic_long_unchecked_t a;
14712+} local_unchecked_t;
14713+
14714 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
14715
14716 #define local_read(l) atomic_long_read(&(l)->a)
14717+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
14718 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
14719+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
14720
14721 static inline void local_inc(local_t *l)
14722 {
14723- asm volatile(_ASM_INC "%0"
14724+ asm volatile(_ASM_INC "%0\n"
14725+
14726+#ifdef CONFIG_PAX_REFCOUNT
14727+ "jno 0f\n"
14728+ _ASM_DEC "%0\n"
14729+ "int $4\n0:\n"
14730+ _ASM_EXTABLE(0b, 0b)
14731+#endif
14732+
14733+ : "+m" (l->a.counter));
14734+}
14735+
14736+static inline void local_inc_unchecked(local_unchecked_t *l)
14737+{
14738+ asm volatile(_ASM_INC "%0\n"
14739 : "+m" (l->a.counter));
14740 }
14741
14742 static inline void local_dec(local_t *l)
14743 {
14744- asm volatile(_ASM_DEC "%0"
14745+ asm volatile(_ASM_DEC "%0\n"
14746+
14747+#ifdef CONFIG_PAX_REFCOUNT
14748+ "jno 0f\n"
14749+ _ASM_INC "%0\n"
14750+ "int $4\n0:\n"
14751+ _ASM_EXTABLE(0b, 0b)
14752+#endif
14753+
14754+ : "+m" (l->a.counter));
14755+}
14756+
14757+static inline void local_dec_unchecked(local_unchecked_t *l)
14758+{
14759+ asm volatile(_ASM_DEC "%0\n"
14760 : "+m" (l->a.counter));
14761 }
14762
14763 static inline void local_add(long i, local_t *l)
14764 {
14765- asm volatile(_ASM_ADD "%1,%0"
14766+ asm volatile(_ASM_ADD "%1,%0\n"
14767+
14768+#ifdef CONFIG_PAX_REFCOUNT
14769+ "jno 0f\n"
14770+ _ASM_SUB "%1,%0\n"
14771+ "int $4\n0:\n"
14772+ _ASM_EXTABLE(0b, 0b)
14773+#endif
14774+
14775+ : "+m" (l->a.counter)
14776+ : "ir" (i));
14777+}
14778+
14779+static inline void local_add_unchecked(long i, local_unchecked_t *l)
14780+{
14781+ asm volatile(_ASM_ADD "%1,%0\n"
14782 : "+m" (l->a.counter)
14783 : "ir" (i));
14784 }
14785
14786 static inline void local_sub(long i, local_t *l)
14787 {
14788- asm volatile(_ASM_SUB "%1,%0"
14789+ asm volatile(_ASM_SUB "%1,%0\n"
14790+
14791+#ifdef CONFIG_PAX_REFCOUNT
14792+ "jno 0f\n"
14793+ _ASM_ADD "%1,%0\n"
14794+ "int $4\n0:\n"
14795+ _ASM_EXTABLE(0b, 0b)
14796+#endif
14797+
14798+ : "+m" (l->a.counter)
14799+ : "ir" (i));
14800+}
14801+
14802+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
14803+{
14804+ asm volatile(_ASM_SUB "%1,%0\n"
14805 : "+m" (l->a.counter)
14806 : "ir" (i));
14807 }
14808@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
14809 {
14810 unsigned char c;
14811
14812- asm volatile(_ASM_SUB "%2,%0; sete %1"
14813+ asm volatile(_ASM_SUB "%2,%0\n"
14814+
14815+#ifdef CONFIG_PAX_REFCOUNT
14816+ "jno 0f\n"
14817+ _ASM_ADD "%2,%0\n"
14818+ "int $4\n0:\n"
14819+ _ASM_EXTABLE(0b, 0b)
14820+#endif
14821+
14822+ "sete %1\n"
14823 : "+m" (l->a.counter), "=qm" (c)
14824 : "ir" (i) : "memory");
14825 return c;
14826@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
14827 {
14828 unsigned char c;
14829
14830- asm volatile(_ASM_DEC "%0; sete %1"
14831+ asm volatile(_ASM_DEC "%0\n"
14832+
14833+#ifdef CONFIG_PAX_REFCOUNT
14834+ "jno 0f\n"
14835+ _ASM_INC "%0\n"
14836+ "int $4\n0:\n"
14837+ _ASM_EXTABLE(0b, 0b)
14838+#endif
14839+
14840+ "sete %1\n"
14841 : "+m" (l->a.counter), "=qm" (c)
14842 : : "memory");
14843 return c != 0;
14844@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
14845 {
14846 unsigned char c;
14847
14848- asm volatile(_ASM_INC "%0; sete %1"
14849+ asm volatile(_ASM_INC "%0\n"
14850+
14851+#ifdef CONFIG_PAX_REFCOUNT
14852+ "jno 0f\n"
14853+ _ASM_DEC "%0\n"
14854+ "int $4\n0:\n"
14855+ _ASM_EXTABLE(0b, 0b)
14856+#endif
14857+
14858+ "sete %1\n"
14859 : "+m" (l->a.counter), "=qm" (c)
14860 : : "memory");
14861 return c != 0;
14862@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
14863 {
14864 unsigned char c;
14865
14866- asm volatile(_ASM_ADD "%2,%0; sets %1"
14867+ asm volatile(_ASM_ADD "%2,%0\n"
14868+
14869+#ifdef CONFIG_PAX_REFCOUNT
14870+ "jno 0f\n"
14871+ _ASM_SUB "%2,%0\n"
14872+ "int $4\n0:\n"
14873+ _ASM_EXTABLE(0b, 0b)
14874+#endif
14875+
14876+ "sets %1\n"
14877 : "+m" (l->a.counter), "=qm" (c)
14878 : "ir" (i) : "memory");
14879 return c;
14880@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
14881 static inline long local_add_return(long i, local_t *l)
14882 {
14883 long __i = i;
14884+ asm volatile(_ASM_XADD "%0, %1\n"
14885+
14886+#ifdef CONFIG_PAX_REFCOUNT
14887+ "jno 0f\n"
14888+ _ASM_MOV "%0,%1\n"
14889+ "int $4\n0:\n"
14890+ _ASM_EXTABLE(0b, 0b)
14891+#endif
14892+
14893+ : "+r" (i), "+m" (l->a.counter)
14894+ : : "memory");
14895+ return i + __i;
14896+}
14897+
14898+/**
14899+ * local_add_return_unchecked - add and return
14900+ * @i: integer value to add
14901+ * @l: pointer to type local_unchecked_t
14902+ *
14903+ * Atomically adds @i to @l and returns @i + @l
14904+ */
14905+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
14906+{
14907+ long __i = i;
14908 asm volatile(_ASM_XADD "%0, %1;"
14909 : "+r" (i), "+m" (l->a.counter)
14910 : : "memory");
14911@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
14912
14913 #define local_cmpxchg(l, o, n) \
14914 (cmpxchg_local(&((l)->a.counter), (o), (n)))
14915+#define local_cmpxchg_unchecked(l, o, n) \
14916+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
14917 /* Always has a lock prefix */
14918 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
14919
14920diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
14921new file mode 100644
14922index 0000000..2bfd3ba
14923--- /dev/null
14924+++ b/arch/x86/include/asm/mman.h
14925@@ -0,0 +1,15 @@
14926+#ifndef _X86_MMAN_H
14927+#define _X86_MMAN_H
14928+
14929+#include <uapi/asm/mman.h>
14930+
14931+#ifdef __KERNEL__
14932+#ifndef __ASSEMBLY__
14933+#ifdef CONFIG_X86_32
14934+#define arch_mmap_check i386_mmap_check
14935+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
14936+#endif
14937+#endif
14938+#endif
14939+
14940+#endif /* X86_MMAN_H */
14941diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
14942index 5f55e69..e20bfb1 100644
14943--- a/arch/x86/include/asm/mmu.h
14944+++ b/arch/x86/include/asm/mmu.h
14945@@ -9,7 +9,7 @@
14946 * we put the segment information here.
14947 */
14948 typedef struct {
14949- void *ldt;
14950+ struct desc_struct *ldt;
14951 int size;
14952
14953 #ifdef CONFIG_X86_64
14954@@ -18,7 +18,19 @@ typedef struct {
14955 #endif
14956
14957 struct mutex lock;
14958- void *vdso;
14959+ unsigned long vdso;
14960+
14961+#ifdef CONFIG_X86_32
14962+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14963+ unsigned long user_cs_base;
14964+ unsigned long user_cs_limit;
14965+
14966+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14967+ cpumask_t cpu_user_cs_mask;
14968+#endif
14969+
14970+#endif
14971+#endif
14972 } mm_context_t;
14973
14974 #ifdef CONFIG_SMP
14975diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
14976index cdbf367..4c73c9e 100644
14977--- a/arch/x86/include/asm/mmu_context.h
14978+++ b/arch/x86/include/asm/mmu_context.h
14979@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
14980
14981 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
14982 {
14983+
14984+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14985+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
14986+ unsigned int i;
14987+ pgd_t *pgd;
14988+
14989+ pax_open_kernel();
14990+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
14991+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
14992+ set_pgd_batched(pgd+i, native_make_pgd(0));
14993+ pax_close_kernel();
14994+ }
14995+#endif
14996+
14997 #ifdef CONFIG_SMP
14998 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
14999 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15000@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15001 struct task_struct *tsk)
15002 {
15003 unsigned cpu = smp_processor_id();
15004+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15005+ int tlbstate = TLBSTATE_OK;
15006+#endif
15007
15008 if (likely(prev != next)) {
15009 #ifdef CONFIG_SMP
15010+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15011+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15012+#endif
15013 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15014 this_cpu_write(cpu_tlbstate.active_mm, next);
15015 #endif
15016 cpumask_set_cpu(cpu, mm_cpumask(next));
15017
15018 /* Re-load page tables */
15019+#ifdef CONFIG_PAX_PER_CPU_PGD
15020+ pax_open_kernel();
15021+
15022+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15023+ if (static_cpu_has(X86_FEATURE_PCID))
15024+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15025+ else
15026+#endif
15027+
15028+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15029+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15030+ pax_close_kernel();
15031+ 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));
15032+
15033+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15034+ if (static_cpu_has(X86_FEATURE_PCID)) {
15035+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15036+ unsigned long descriptor[2];
15037+ descriptor[0] = PCID_USER;
15038+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15039+ } else {
15040+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15041+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15042+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15043+ else
15044+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15045+ }
15046+ } else
15047+#endif
15048+
15049+ load_cr3(get_cpu_pgd(cpu, kernel));
15050+#else
15051 load_cr3(next->pgd);
15052+#endif
15053
15054 /* stop flush ipis for the previous mm */
15055 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15056@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15057 */
15058 if (unlikely(prev->context.ldt != next->context.ldt))
15059 load_LDT_nolock(&next->context);
15060- }
15061+
15062+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15063+ if (!(__supported_pte_mask & _PAGE_NX)) {
15064+ smp_mb__before_clear_bit();
15065+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15066+ smp_mb__after_clear_bit();
15067+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15068+ }
15069+#endif
15070+
15071+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15072+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15073+ prev->context.user_cs_limit != next->context.user_cs_limit))
15074+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15075 #ifdef CONFIG_SMP
15076+ else if (unlikely(tlbstate != TLBSTATE_OK))
15077+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15078+#endif
15079+#endif
15080+
15081+ }
15082 else {
15083+
15084+#ifdef CONFIG_PAX_PER_CPU_PGD
15085+ pax_open_kernel();
15086+
15087+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15088+ if (static_cpu_has(X86_FEATURE_PCID))
15089+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15090+ else
15091+#endif
15092+
15093+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15094+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15095+ pax_close_kernel();
15096+ 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));
15097+
15098+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15099+ if (static_cpu_has(X86_FEATURE_PCID)) {
15100+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15101+ unsigned long descriptor[2];
15102+ descriptor[0] = PCID_USER;
15103+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15104+ } else {
15105+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15106+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15107+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15108+ else
15109+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15110+ }
15111+ } else
15112+#endif
15113+
15114+ load_cr3(get_cpu_pgd(cpu, kernel));
15115+#endif
15116+
15117+#ifdef CONFIG_SMP
15118 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15119 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15120
15121@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15122 * tlb flush IPI delivery. We must reload CR3
15123 * to make sure to use no freed page tables.
15124 */
15125+
15126+#ifndef CONFIG_PAX_PER_CPU_PGD
15127 load_cr3(next->pgd);
15128+#endif
15129+
15130 load_LDT_nolock(&next->context);
15131+
15132+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15133+ if (!(__supported_pte_mask & _PAGE_NX))
15134+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15135+#endif
15136+
15137+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15138+#ifdef CONFIG_PAX_PAGEEXEC
15139+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15140+#endif
15141+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15142+#endif
15143+
15144 }
15145+#endif
15146 }
15147-#endif
15148 }
15149
15150 #define activate_mm(prev, next) \
15151diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15152index e3b7819..b257c64 100644
15153--- a/arch/x86/include/asm/module.h
15154+++ b/arch/x86/include/asm/module.h
15155@@ -5,6 +5,7 @@
15156
15157 #ifdef CONFIG_X86_64
15158 /* X86_64 does not define MODULE_PROC_FAMILY */
15159+#define MODULE_PROC_FAMILY ""
15160 #elif defined CONFIG_M486
15161 #define MODULE_PROC_FAMILY "486 "
15162 #elif defined CONFIG_M586
15163@@ -57,8 +58,20 @@
15164 #error unknown processor family
15165 #endif
15166
15167-#ifdef CONFIG_X86_32
15168-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15169+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15170+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15171+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15172+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15173+#else
15174+#define MODULE_PAX_KERNEXEC ""
15175 #endif
15176
15177+#ifdef CONFIG_PAX_MEMORY_UDEREF
15178+#define MODULE_PAX_UDEREF "UDEREF "
15179+#else
15180+#define MODULE_PAX_UDEREF ""
15181+#endif
15182+
15183+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15184+
15185 #endif /* _ASM_X86_MODULE_H */
15186diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15187index 86f9301..b365cda 100644
15188--- a/arch/x86/include/asm/nmi.h
15189+++ b/arch/x86/include/asm/nmi.h
15190@@ -40,11 +40,11 @@ struct nmiaction {
15191 nmi_handler_t handler;
15192 unsigned long flags;
15193 const char *name;
15194-};
15195+} __do_const;
15196
15197 #define register_nmi_handler(t, fn, fg, n, init...) \
15198 ({ \
15199- static struct nmiaction init fn##_na = { \
15200+ static const struct nmiaction init fn##_na = { \
15201 .handler = (fn), \
15202 .name = (n), \
15203 .flags = (fg), \
15204@@ -52,7 +52,7 @@ struct nmiaction {
15205 __register_nmi_handler((t), &fn##_na); \
15206 })
15207
15208-int __register_nmi_handler(unsigned int, struct nmiaction *);
15209+int __register_nmi_handler(unsigned int, const struct nmiaction *);
15210
15211 void unregister_nmi_handler(unsigned int, const char *);
15212
15213diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
15214index c878924..21f4889 100644
15215--- a/arch/x86/include/asm/page.h
15216+++ b/arch/x86/include/asm/page.h
15217@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
15218 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
15219
15220 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
15221+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
15222
15223 #define __boot_va(x) __va(x)
15224 #define __boot_pa(x) __pa(x)
15225diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
15226index 0f1ddee..e2fc3d1 100644
15227--- a/arch/x86/include/asm/page_64.h
15228+++ b/arch/x86/include/asm/page_64.h
15229@@ -7,9 +7,9 @@
15230
15231 /* duplicated to the one in bootmem.h */
15232 extern unsigned long max_pfn;
15233-extern unsigned long phys_base;
15234+extern const unsigned long phys_base;
15235
15236-static inline unsigned long __phys_addr_nodebug(unsigned long x)
15237+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
15238 {
15239 unsigned long y = x - __START_KERNEL_map;
15240
15241diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
15242index cfdc9ee..3f7b5d6 100644
15243--- a/arch/x86/include/asm/paravirt.h
15244+++ b/arch/x86/include/asm/paravirt.h
15245@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
15246 return (pmd_t) { ret };
15247 }
15248
15249-static inline pmdval_t pmd_val(pmd_t pmd)
15250+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
15251 {
15252 pmdval_t ret;
15253
15254@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
15255 val);
15256 }
15257
15258+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
15259+{
15260+ pgdval_t val = native_pgd_val(pgd);
15261+
15262+ if (sizeof(pgdval_t) > sizeof(long))
15263+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
15264+ val, (u64)val >> 32);
15265+ else
15266+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
15267+ val);
15268+}
15269+
15270 static inline void pgd_clear(pgd_t *pgdp)
15271 {
15272 set_pgd(pgdp, __pgd(0));
15273@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
15274 pv_mmu_ops.set_fixmap(idx, phys, flags);
15275 }
15276
15277+#ifdef CONFIG_PAX_KERNEXEC
15278+static inline unsigned long pax_open_kernel(void)
15279+{
15280+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
15281+}
15282+
15283+static inline unsigned long pax_close_kernel(void)
15284+{
15285+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
15286+}
15287+#else
15288+static inline unsigned long pax_open_kernel(void) { return 0; }
15289+static inline unsigned long pax_close_kernel(void) { return 0; }
15290+#endif
15291+
15292 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
15293
15294 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
15295@@ -926,7 +953,7 @@ extern void default_banner(void);
15296
15297 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
15298 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
15299-#define PARA_INDIRECT(addr) *%cs:addr
15300+#define PARA_INDIRECT(addr) *%ss:addr
15301 #endif
15302
15303 #define INTERRUPT_RETURN \
15304@@ -1001,6 +1028,21 @@ extern void default_banner(void);
15305 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
15306 CLBR_NONE, \
15307 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
15308+
15309+#define GET_CR0_INTO_RDI \
15310+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
15311+ mov %rax,%rdi
15312+
15313+#define SET_RDI_INTO_CR0 \
15314+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15315+
15316+#define GET_CR3_INTO_RDI \
15317+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
15318+ mov %rax,%rdi
15319+
15320+#define SET_RDI_INTO_CR3 \
15321+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
15322+
15323 #endif /* CONFIG_X86_32 */
15324
15325 #endif /* __ASSEMBLY__ */
15326diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
15327index 0db1fca..52310cc 100644
15328--- a/arch/x86/include/asm/paravirt_types.h
15329+++ b/arch/x86/include/asm/paravirt_types.h
15330@@ -84,7 +84,7 @@ struct pv_init_ops {
15331 */
15332 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
15333 unsigned long addr, unsigned len);
15334-};
15335+} __no_const;
15336
15337
15338 struct pv_lazy_ops {
15339@@ -98,7 +98,7 @@ struct pv_time_ops {
15340 unsigned long long (*sched_clock)(void);
15341 unsigned long long (*steal_clock)(int cpu);
15342 unsigned long (*get_tsc_khz)(void);
15343-};
15344+} __no_const;
15345
15346 struct pv_cpu_ops {
15347 /* hooks for various privileged instructions */
15348@@ -192,7 +192,7 @@ struct pv_cpu_ops {
15349
15350 void (*start_context_switch)(struct task_struct *prev);
15351 void (*end_context_switch)(struct task_struct *next);
15352-};
15353+} __no_const;
15354
15355 struct pv_irq_ops {
15356 /*
15357@@ -223,7 +223,7 @@ struct pv_apic_ops {
15358 unsigned long start_eip,
15359 unsigned long start_esp);
15360 #endif
15361-};
15362+} __no_const;
15363
15364 struct pv_mmu_ops {
15365 unsigned long (*read_cr2)(void);
15366@@ -313,6 +313,7 @@ struct pv_mmu_ops {
15367 struct paravirt_callee_save make_pud;
15368
15369 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
15370+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
15371 #endif /* PAGETABLE_LEVELS == 4 */
15372 #endif /* PAGETABLE_LEVELS >= 3 */
15373
15374@@ -324,6 +325,12 @@ struct pv_mmu_ops {
15375 an mfn. We can tell which is which from the index. */
15376 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
15377 phys_addr_t phys, pgprot_t flags);
15378+
15379+#ifdef CONFIG_PAX_KERNEXEC
15380+ unsigned long (*pax_open_kernel)(void);
15381+ unsigned long (*pax_close_kernel)(void);
15382+#endif
15383+
15384 };
15385
15386 struct arch_spinlock;
15387@@ -334,7 +341,7 @@ struct pv_lock_ops {
15388 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
15389 int (*spin_trylock)(struct arch_spinlock *lock);
15390 void (*spin_unlock)(struct arch_spinlock *lock);
15391-};
15392+} __no_const;
15393
15394 /* This contains all the paravirt structures: we get a convenient
15395 * number for each function using the offset which we use to indicate
15396diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
15397index b4389a4..7024269 100644
15398--- a/arch/x86/include/asm/pgalloc.h
15399+++ b/arch/x86/include/asm/pgalloc.h
15400@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
15401 pmd_t *pmd, pte_t *pte)
15402 {
15403 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
15404+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
15405+}
15406+
15407+static inline void pmd_populate_user(struct mm_struct *mm,
15408+ pmd_t *pmd, pte_t *pte)
15409+{
15410+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
15411 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
15412 }
15413
15414@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
15415
15416 #ifdef CONFIG_X86_PAE
15417 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
15418+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
15419+{
15420+ pud_populate(mm, pudp, pmd);
15421+}
15422 #else /* !CONFIG_X86_PAE */
15423 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
15424 {
15425 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
15426 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
15427 }
15428+
15429+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
15430+{
15431+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
15432+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
15433+}
15434 #endif /* CONFIG_X86_PAE */
15435
15436 #if PAGETABLE_LEVELS > 3
15437@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
15438 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
15439 }
15440
15441+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
15442+{
15443+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
15444+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
15445+}
15446+
15447 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
15448 {
15449 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
15450diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
15451index f2b489c..4f7e2e5 100644
15452--- a/arch/x86/include/asm/pgtable-2level.h
15453+++ b/arch/x86/include/asm/pgtable-2level.h
15454@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
15455
15456 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15457 {
15458+ pax_open_kernel();
15459 *pmdp = pmd;
15460+ pax_close_kernel();
15461 }
15462
15463 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15464diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
15465index 4cc9f2b..5fd9226 100644
15466--- a/arch/x86/include/asm/pgtable-3level.h
15467+++ b/arch/x86/include/asm/pgtable-3level.h
15468@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15469
15470 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15471 {
15472+ pax_open_kernel();
15473 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
15474+ pax_close_kernel();
15475 }
15476
15477 static inline void native_set_pud(pud_t *pudp, pud_t pud)
15478 {
15479+ pax_open_kernel();
15480 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
15481+ pax_close_kernel();
15482 }
15483
15484 /*
15485diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
15486index 1e67223..92a9585 100644
15487--- a/arch/x86/include/asm/pgtable.h
15488+++ b/arch/x86/include/asm/pgtable.h
15489@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
15490
15491 #ifndef __PAGETABLE_PUD_FOLDED
15492 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
15493+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
15494 #define pgd_clear(pgd) native_pgd_clear(pgd)
15495 #endif
15496
15497@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
15498
15499 #define arch_end_context_switch(prev) do {} while(0)
15500
15501+#define pax_open_kernel() native_pax_open_kernel()
15502+#define pax_close_kernel() native_pax_close_kernel()
15503 #endif /* CONFIG_PARAVIRT */
15504
15505+#define __HAVE_ARCH_PAX_OPEN_KERNEL
15506+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
15507+
15508+#ifdef CONFIG_PAX_KERNEXEC
15509+static inline unsigned long native_pax_open_kernel(void)
15510+{
15511+ unsigned long cr0;
15512+
15513+ preempt_disable();
15514+ barrier();
15515+ cr0 = read_cr0() ^ X86_CR0_WP;
15516+ BUG_ON(cr0 & X86_CR0_WP);
15517+ write_cr0(cr0);
15518+ return cr0 ^ X86_CR0_WP;
15519+}
15520+
15521+static inline unsigned long native_pax_close_kernel(void)
15522+{
15523+ unsigned long cr0;
15524+
15525+ cr0 = read_cr0() ^ X86_CR0_WP;
15526+ BUG_ON(!(cr0 & X86_CR0_WP));
15527+ write_cr0(cr0);
15528+ barrier();
15529+ preempt_enable_no_resched();
15530+ return cr0 ^ X86_CR0_WP;
15531+}
15532+#else
15533+static inline unsigned long native_pax_open_kernel(void) { return 0; }
15534+static inline unsigned long native_pax_close_kernel(void) { return 0; }
15535+#endif
15536+
15537 /*
15538 * The following only work if pte_present() is true.
15539 * Undefined behaviour if not..
15540 */
15541+static inline int pte_user(pte_t pte)
15542+{
15543+ return pte_val(pte) & _PAGE_USER;
15544+}
15545+
15546 static inline int pte_dirty(pte_t pte)
15547 {
15548 return pte_flags(pte) & _PAGE_DIRTY;
15549@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
15550 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
15551 }
15552
15553+static inline unsigned long pgd_pfn(pgd_t pgd)
15554+{
15555+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
15556+}
15557+
15558 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
15559
15560 static inline int pmd_large(pmd_t pte)
15561@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
15562 return pte_clear_flags(pte, _PAGE_RW);
15563 }
15564
15565+static inline pte_t pte_mkread(pte_t pte)
15566+{
15567+ return __pte(pte_val(pte) | _PAGE_USER);
15568+}
15569+
15570 static inline pte_t pte_mkexec(pte_t pte)
15571 {
15572- return pte_clear_flags(pte, _PAGE_NX);
15573+#ifdef CONFIG_X86_PAE
15574+ if (__supported_pte_mask & _PAGE_NX)
15575+ return pte_clear_flags(pte, _PAGE_NX);
15576+ else
15577+#endif
15578+ return pte_set_flags(pte, _PAGE_USER);
15579+}
15580+
15581+static inline pte_t pte_exprotect(pte_t pte)
15582+{
15583+#ifdef CONFIG_X86_PAE
15584+ if (__supported_pte_mask & _PAGE_NX)
15585+ return pte_set_flags(pte, _PAGE_NX);
15586+ else
15587+#endif
15588+ return pte_clear_flags(pte, _PAGE_USER);
15589 }
15590
15591 static inline pte_t pte_mkdirty(pte_t pte)
15592@@ -394,6 +459,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
15593 #endif
15594
15595 #ifndef __ASSEMBLY__
15596+
15597+#ifdef CONFIG_PAX_PER_CPU_PGD
15598+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
15599+enum cpu_pgd_type {kernel = 0, user = 1};
15600+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
15601+{
15602+ return cpu_pgd[cpu][type];
15603+}
15604+#endif
15605+
15606 #include <linux/mm_types.h>
15607 #include <linux/log2.h>
15608
15609@@ -529,7 +604,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
15610 * Currently stuck as a macro due to indirect forward reference to
15611 * linux/mmzone.h's __section_mem_map_addr() definition:
15612 */
15613-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
15614+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
15615
15616 /* Find an entry in the second-level page table.. */
15617 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
15618@@ -569,7 +644,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
15619 * Currently stuck as a macro due to indirect forward reference to
15620 * linux/mmzone.h's __section_mem_map_addr() definition:
15621 */
15622-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
15623+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
15624
15625 /* to find an entry in a page-table-directory. */
15626 static inline unsigned long pud_index(unsigned long address)
15627@@ -584,7 +659,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
15628
15629 static inline int pgd_bad(pgd_t pgd)
15630 {
15631- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
15632+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
15633 }
15634
15635 static inline int pgd_none(pgd_t pgd)
15636@@ -607,7 +682,12 @@ static inline int pgd_none(pgd_t pgd)
15637 * pgd_offset() returns a (pgd_t *)
15638 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
15639 */
15640-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
15641+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
15642+
15643+#ifdef CONFIG_PAX_PER_CPU_PGD
15644+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
15645+#endif
15646+
15647 /*
15648 * a shortcut which implies the use of the kernel's pgd, instead
15649 * of a process's
15650@@ -618,6 +698,23 @@ static inline int pgd_none(pgd_t pgd)
15651 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
15652 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
15653
15654+#ifdef CONFIG_X86_32
15655+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
15656+#else
15657+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
15658+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
15659+
15660+#ifdef CONFIG_PAX_MEMORY_UDEREF
15661+#ifdef __ASSEMBLY__
15662+#define pax_user_shadow_base pax_user_shadow_base(%rip)
15663+#else
15664+extern unsigned long pax_user_shadow_base;
15665+extern pgdval_t clone_pgd_mask;
15666+#endif
15667+#endif
15668+
15669+#endif
15670+
15671 #ifndef __ASSEMBLY__
15672
15673 extern int direct_gbpages;
15674@@ -784,11 +881,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
15675 * dst and src can be on the same page, but the range must not overlap,
15676 * and must not cross a page boundary.
15677 */
15678-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
15679+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
15680 {
15681- memcpy(dst, src, count * sizeof(pgd_t));
15682+ pax_open_kernel();
15683+ while (count--)
15684+ *dst++ = *src++;
15685+ pax_close_kernel();
15686 }
15687
15688+#ifdef CONFIG_PAX_PER_CPU_PGD
15689+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
15690+#endif
15691+
15692+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15693+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
15694+#else
15695+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
15696+#endif
15697+
15698 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
15699 static inline int page_level_shift(enum pg_level level)
15700 {
15701diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
15702index 9ee3221..b979c6b 100644
15703--- a/arch/x86/include/asm/pgtable_32.h
15704+++ b/arch/x86/include/asm/pgtable_32.h
15705@@ -25,9 +25,6 @@
15706 struct mm_struct;
15707 struct vm_area_struct;
15708
15709-extern pgd_t swapper_pg_dir[1024];
15710-extern pgd_t initial_page_table[1024];
15711-
15712 static inline void pgtable_cache_init(void) { }
15713 static inline void check_pgt_cache(void) { }
15714 void paging_init(void);
15715@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
15716 # include <asm/pgtable-2level.h>
15717 #endif
15718
15719+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
15720+extern pgd_t initial_page_table[PTRS_PER_PGD];
15721+#ifdef CONFIG_X86_PAE
15722+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
15723+#endif
15724+
15725 #if defined(CONFIG_HIGHPTE)
15726 #define pte_offset_map(dir, address) \
15727 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
15728@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
15729 /* Clear a kernel PTE and flush it from the TLB */
15730 #define kpte_clear_flush(ptep, vaddr) \
15731 do { \
15732+ pax_open_kernel(); \
15733 pte_clear(&init_mm, (vaddr), (ptep)); \
15734+ pax_close_kernel(); \
15735 __flush_tlb_one((vaddr)); \
15736 } while (0)
15737
15738 #endif /* !__ASSEMBLY__ */
15739
15740+#define HAVE_ARCH_UNMAPPED_AREA
15741+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
15742+
15743 /*
15744 * kern_addr_valid() is (1) for FLATMEM and (0) for
15745 * SPARSEMEM and DISCONTIGMEM
15746diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
15747index ed5903b..c7fe163 100644
15748--- a/arch/x86/include/asm/pgtable_32_types.h
15749+++ b/arch/x86/include/asm/pgtable_32_types.h
15750@@ -8,7 +8,7 @@
15751 */
15752 #ifdef CONFIG_X86_PAE
15753 # include <asm/pgtable-3level_types.h>
15754-# define PMD_SIZE (1UL << PMD_SHIFT)
15755+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
15756 # define PMD_MASK (~(PMD_SIZE - 1))
15757 #else
15758 # include <asm/pgtable-2level_types.h>
15759@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
15760 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
15761 #endif
15762
15763+#ifdef CONFIG_PAX_KERNEXEC
15764+#ifndef __ASSEMBLY__
15765+extern unsigned char MODULES_EXEC_VADDR[];
15766+extern unsigned char MODULES_EXEC_END[];
15767+#endif
15768+#include <asm/boot.h>
15769+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
15770+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
15771+#else
15772+#define ktla_ktva(addr) (addr)
15773+#define ktva_ktla(addr) (addr)
15774+#endif
15775+
15776 #define MODULES_VADDR VMALLOC_START
15777 #define MODULES_END VMALLOC_END
15778 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
15779diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
15780index e22c1db..23a625a 100644
15781--- a/arch/x86/include/asm/pgtable_64.h
15782+++ b/arch/x86/include/asm/pgtable_64.h
15783@@ -16,10 +16,14 @@
15784
15785 extern pud_t level3_kernel_pgt[512];
15786 extern pud_t level3_ident_pgt[512];
15787+extern pud_t level3_vmalloc_start_pgt[512];
15788+extern pud_t level3_vmalloc_end_pgt[512];
15789+extern pud_t level3_vmemmap_pgt[512];
15790+extern pud_t level2_vmemmap_pgt[512];
15791 extern pmd_t level2_kernel_pgt[512];
15792 extern pmd_t level2_fixmap_pgt[512];
15793-extern pmd_t level2_ident_pgt[512];
15794-extern pgd_t init_level4_pgt[];
15795+extern pmd_t level2_ident_pgt[512*2];
15796+extern pgd_t init_level4_pgt[512];
15797
15798 #define swapper_pg_dir init_level4_pgt
15799
15800@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
15801
15802 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
15803 {
15804+ pax_open_kernel();
15805 *pmdp = pmd;
15806+ pax_close_kernel();
15807 }
15808
15809 static inline void native_pmd_clear(pmd_t *pmd)
15810@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
15811
15812 static inline void native_set_pud(pud_t *pudp, pud_t pud)
15813 {
15814+ pax_open_kernel();
15815 *pudp = pud;
15816+ pax_close_kernel();
15817 }
15818
15819 static inline void native_pud_clear(pud_t *pud)
15820@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
15821
15822 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
15823 {
15824+ pax_open_kernel();
15825+ *pgdp = pgd;
15826+ pax_close_kernel();
15827+}
15828+
15829+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
15830+{
15831 *pgdp = pgd;
15832 }
15833
15834diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
15835index 2d88344..4679fc3 100644
15836--- a/arch/x86/include/asm/pgtable_64_types.h
15837+++ b/arch/x86/include/asm/pgtable_64_types.h
15838@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
15839 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
15840 #define MODULES_END _AC(0xffffffffff000000, UL)
15841 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
15842+#define MODULES_EXEC_VADDR MODULES_VADDR
15843+#define MODULES_EXEC_END MODULES_END
15844+
15845+#define ktla_ktva(addr) (addr)
15846+#define ktva_ktla(addr) (addr)
15847
15848 #define EARLY_DYNAMIC_PAGE_TABLES 64
15849
15850diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
15851index e642300..0ef8f31 100644
15852--- a/arch/x86/include/asm/pgtable_types.h
15853+++ b/arch/x86/include/asm/pgtable_types.h
15854@@ -16,13 +16,12 @@
15855 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
15856 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
15857 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
15858-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
15859+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
15860 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
15861 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
15862 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
15863-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
15864-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
15865-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
15866+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
15867+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
15868 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
15869
15870 /* If _PAGE_BIT_PRESENT is clear, we use these: */
15871@@ -40,7 +39,6 @@
15872 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
15873 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
15874 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
15875-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
15876 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
15877 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
15878 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
15879@@ -57,8 +55,10 @@
15880
15881 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
15882 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
15883-#else
15884+#elif defined(CONFIG_KMEMCHECK)
15885 #define _PAGE_NX (_AT(pteval_t, 0))
15886+#else
15887+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
15888 #endif
15889
15890 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
15891@@ -116,6 +116,9 @@
15892 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
15893 _PAGE_ACCESSED)
15894
15895+#define PAGE_READONLY_NOEXEC PAGE_READONLY
15896+#define PAGE_SHARED_NOEXEC PAGE_SHARED
15897+
15898 #define __PAGE_KERNEL_EXEC \
15899 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
15900 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
15901@@ -126,7 +129,7 @@
15902 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
15903 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
15904 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
15905-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
15906+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
15907 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
15908 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
15909 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
15910@@ -188,8 +191,8 @@
15911 * bits are combined, this will alow user to access the high address mapped
15912 * VDSO in the presence of CONFIG_COMPAT_VDSO
15913 */
15914-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
15915-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
15916+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15917+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
15918 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
15919 #endif
15920
15921@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
15922 {
15923 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
15924 }
15925+#endif
15926
15927+#if PAGETABLE_LEVELS == 3
15928+#include <asm-generic/pgtable-nopud.h>
15929+#endif
15930+
15931+#if PAGETABLE_LEVELS == 2
15932+#include <asm-generic/pgtable-nopmd.h>
15933+#endif
15934+
15935+#ifndef __ASSEMBLY__
15936 #if PAGETABLE_LEVELS > 3
15937 typedef struct { pudval_t pud; } pud_t;
15938
15939@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
15940 return pud.pud;
15941 }
15942 #else
15943-#include <asm-generic/pgtable-nopud.h>
15944-
15945 static inline pudval_t native_pud_val(pud_t pud)
15946 {
15947 return native_pgd_val(pud.pgd);
15948@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
15949 return pmd.pmd;
15950 }
15951 #else
15952-#include <asm-generic/pgtable-nopmd.h>
15953-
15954 static inline pmdval_t native_pmd_val(pmd_t pmd)
15955 {
15956 return native_pgd_val(pmd.pud.pgd);
15957@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
15958
15959 extern pteval_t __supported_pte_mask;
15960 extern void set_nx(void);
15961-extern int nx_enabled;
15962
15963 #define pgprot_writecombine pgprot_writecombine
15964 extern pgprot_t pgprot_writecombine(pgprot_t prot);
15965diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
15966index 22224b3..c5d8d7d 100644
15967--- a/arch/x86/include/asm/processor.h
15968+++ b/arch/x86/include/asm/processor.h
15969@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
15970 : "memory");
15971 }
15972
15973+/* invpcid (%rdx),%rax */
15974+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
15975+
15976+#define INVPCID_SINGLE_ADDRESS 0UL
15977+#define INVPCID_SINGLE_CONTEXT 1UL
15978+#define INVPCID_ALL_GLOBAL 2UL
15979+#define INVPCID_ALL_MONGLOBAL 3UL
15980+
15981+#define PCID_KERNEL 0UL
15982+#define PCID_USER 1UL
15983+#define PCID_NOFLUSH (1UL << 63)
15984+
15985 static inline void load_cr3(pgd_t *pgdir)
15986 {
15987- write_cr3(__pa(pgdir));
15988+ write_cr3(__pa(pgdir) | PCID_KERNEL);
15989 }
15990
15991 #ifdef CONFIG_X86_32
15992@@ -282,7 +294,7 @@ struct tss_struct {
15993
15994 } ____cacheline_aligned;
15995
15996-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
15997+extern struct tss_struct init_tss[NR_CPUS];
15998
15999 /*
16000 * Save the original ist values for checking stack pointers during debugging
16001@@ -452,6 +464,7 @@ struct thread_struct {
16002 unsigned short ds;
16003 unsigned short fsindex;
16004 unsigned short gsindex;
16005+ unsigned short ss;
16006 #endif
16007 #ifdef CONFIG_X86_32
16008 unsigned long ip;
16009@@ -823,11 +836,18 @@ static inline void spin_lock_prefetch(const void *x)
16010 */
16011 #define TASK_SIZE PAGE_OFFSET
16012 #define TASK_SIZE_MAX TASK_SIZE
16013+
16014+#ifdef CONFIG_PAX_SEGMEXEC
16015+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16016+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16017+#else
16018 #define STACK_TOP TASK_SIZE
16019-#define STACK_TOP_MAX STACK_TOP
16020+#endif
16021+
16022+#define STACK_TOP_MAX TASK_SIZE
16023
16024 #define INIT_THREAD { \
16025- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16026+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16027 .vm86_info = NULL, \
16028 .sysenter_cs = __KERNEL_CS, \
16029 .io_bitmap_ptr = NULL, \
16030@@ -841,7 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
16031 */
16032 #define INIT_TSS { \
16033 .x86_tss = { \
16034- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16035+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16036 .ss0 = __KERNEL_DS, \
16037 .ss1 = __KERNEL_CS, \
16038 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16039@@ -852,11 +872,7 @@ static inline void spin_lock_prefetch(const void *x)
16040 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16041
16042 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16043-#define KSTK_TOP(info) \
16044-({ \
16045- unsigned long *__ptr = (unsigned long *)(info); \
16046- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16047-})
16048+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16049
16050 /*
16051 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16052@@ -871,7 +887,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16053 #define task_pt_regs(task) \
16054 ({ \
16055 struct pt_regs *__regs__; \
16056- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16057+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16058 __regs__ - 1; \
16059 })
16060
16061@@ -881,13 +897,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16062 /*
16063 * User space process size. 47bits minus one guard page.
16064 */
16065-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16066+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16067
16068 /* This decides where the kernel will search for a free chunk of vm
16069 * space during mmap's.
16070 */
16071 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16072- 0xc0000000 : 0xFFFFe000)
16073+ 0xc0000000 : 0xFFFFf000)
16074
16075 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16076 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16077@@ -898,11 +914,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16078 #define STACK_TOP_MAX TASK_SIZE_MAX
16079
16080 #define INIT_THREAD { \
16081- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16082+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16083 }
16084
16085 #define INIT_TSS { \
16086- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16087+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16088 }
16089
16090 /*
16091@@ -930,6 +946,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16092 */
16093 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16094
16095+#ifdef CONFIG_PAX_SEGMEXEC
16096+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16097+#endif
16098+
16099 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16100
16101 /* Get/set a process' ability to use the timestamp counter instruction */
16102@@ -942,7 +962,8 @@ extern int set_tsc_mode(unsigned int val);
16103 extern u16 amd_get_nb_id(int cpu);
16104
16105 struct aperfmperf {
16106- u64 aperf, mperf;
16107+ u64 aperf __intentional_overflow(0);
16108+ u64 mperf __intentional_overflow(0);
16109 };
16110
16111 static inline void get_aperfmperf(struct aperfmperf *am)
16112@@ -970,7 +991,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16113 return ratio;
16114 }
16115
16116-extern unsigned long arch_align_stack(unsigned long sp);
16117+#define arch_align_stack(x) ((x) & ~0xfUL)
16118 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16119
16120 void default_idle(void);
16121@@ -980,6 +1001,6 @@ bool xen_set_default_idle(void);
16122 #define xen_set_default_idle 0
16123 #endif
16124
16125-void stop_this_cpu(void *dummy);
16126+void stop_this_cpu(void *dummy) __noreturn;
16127
16128 #endif /* _ASM_X86_PROCESSOR_H */
16129diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16130index 942a086..6c26446 100644
16131--- a/arch/x86/include/asm/ptrace.h
16132+++ b/arch/x86/include/asm/ptrace.h
16133@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16134 }
16135
16136 /*
16137- * user_mode_vm(regs) determines whether a register set came from user mode.
16138+ * user_mode(regs) determines whether a register set came from user mode.
16139 * This is true if V8086 mode was enabled OR if the register set was from
16140 * protected mode with RPL-3 CS value. This tricky test checks that with
16141 * one comparison. Many places in the kernel can bypass this full check
16142- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16143+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16144+ * be used.
16145 */
16146-static inline int user_mode(struct pt_regs *regs)
16147+static inline int user_mode_novm(struct pt_regs *regs)
16148 {
16149 #ifdef CONFIG_X86_32
16150 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16151 #else
16152- return !!(regs->cs & 3);
16153+ return !!(regs->cs & SEGMENT_RPL_MASK);
16154 #endif
16155 }
16156
16157-static inline int user_mode_vm(struct pt_regs *regs)
16158+static inline int user_mode(struct pt_regs *regs)
16159 {
16160 #ifdef CONFIG_X86_32
16161 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
16162 USER_RPL;
16163 #else
16164- return user_mode(regs);
16165+ return user_mode_novm(regs);
16166 #endif
16167 }
16168
16169@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
16170 #ifdef CONFIG_X86_64
16171 static inline bool user_64bit_mode(struct pt_regs *regs)
16172 {
16173+ unsigned long cs = regs->cs & 0xffff;
16174 #ifndef CONFIG_PARAVIRT
16175 /*
16176 * On non-paravirt systems, this is the only long mode CPL 3
16177 * selector. We do not allow long mode selectors in the LDT.
16178 */
16179- return regs->cs == __USER_CS;
16180+ return cs == __USER_CS;
16181 #else
16182 /* Headers are too twisted for this to go in paravirt.h. */
16183- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
16184+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
16185 #endif
16186 }
16187
16188@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
16189 * Traps from the kernel do not save sp and ss.
16190 * Use the helper function to retrieve sp.
16191 */
16192- if (offset == offsetof(struct pt_regs, sp) &&
16193- regs->cs == __KERNEL_CS)
16194- return kernel_stack_pointer(regs);
16195+ if (offset == offsetof(struct pt_regs, sp)) {
16196+ unsigned long cs = regs->cs & 0xffff;
16197+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
16198+ return kernel_stack_pointer(regs);
16199+ }
16200 #endif
16201 return *(unsigned long *)((unsigned long)regs + offset);
16202 }
16203diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
16204index 9c6b890..5305f53 100644
16205--- a/arch/x86/include/asm/realmode.h
16206+++ b/arch/x86/include/asm/realmode.h
16207@@ -22,16 +22,14 @@ struct real_mode_header {
16208 #endif
16209 /* APM/BIOS reboot */
16210 u32 machine_real_restart_asm;
16211-#ifdef CONFIG_X86_64
16212 u32 machine_real_restart_seg;
16213-#endif
16214 };
16215
16216 /* This must match data at trampoline_32/64.S */
16217 struct trampoline_header {
16218 #ifdef CONFIG_X86_32
16219 u32 start;
16220- u16 gdt_pad;
16221+ u16 boot_cs;
16222 u16 gdt_limit;
16223 u32 gdt_base;
16224 #else
16225diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
16226index a82c4f1..ac45053 100644
16227--- a/arch/x86/include/asm/reboot.h
16228+++ b/arch/x86/include/asm/reboot.h
16229@@ -6,13 +6,13 @@
16230 struct pt_regs;
16231
16232 struct machine_ops {
16233- void (*restart)(char *cmd);
16234- void (*halt)(void);
16235- void (*power_off)(void);
16236+ void (* __noreturn restart)(char *cmd);
16237+ void (* __noreturn halt)(void);
16238+ void (* __noreturn power_off)(void);
16239 void (*shutdown)(void);
16240 void (*crash_shutdown)(struct pt_regs *);
16241- void (*emergency_restart)(void);
16242-};
16243+ void (* __noreturn emergency_restart)(void);
16244+} __no_const;
16245
16246 extern struct machine_ops machine_ops;
16247
16248diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
16249index cad82c9..2e5c5c1 100644
16250--- a/arch/x86/include/asm/rwsem.h
16251+++ b/arch/x86/include/asm/rwsem.h
16252@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
16253 {
16254 asm volatile("# beginning down_read\n\t"
16255 LOCK_PREFIX _ASM_INC "(%1)\n\t"
16256+
16257+#ifdef CONFIG_PAX_REFCOUNT
16258+ "jno 0f\n"
16259+ LOCK_PREFIX _ASM_DEC "(%1)\n"
16260+ "int $4\n0:\n"
16261+ _ASM_EXTABLE(0b, 0b)
16262+#endif
16263+
16264 /* adds 0x00000001 */
16265 " jns 1f\n"
16266 " call call_rwsem_down_read_failed\n"
16267@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
16268 "1:\n\t"
16269 " mov %1,%2\n\t"
16270 " add %3,%2\n\t"
16271+
16272+#ifdef CONFIG_PAX_REFCOUNT
16273+ "jno 0f\n"
16274+ "sub %3,%2\n"
16275+ "int $4\n0:\n"
16276+ _ASM_EXTABLE(0b, 0b)
16277+#endif
16278+
16279 " jle 2f\n\t"
16280 LOCK_PREFIX " cmpxchg %2,%0\n\t"
16281 " jnz 1b\n\t"
16282@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
16283 long tmp;
16284 asm volatile("# beginning down_write\n\t"
16285 LOCK_PREFIX " xadd %1,(%2)\n\t"
16286+
16287+#ifdef CONFIG_PAX_REFCOUNT
16288+ "jno 0f\n"
16289+ "mov %1,(%2)\n"
16290+ "int $4\n0:\n"
16291+ _ASM_EXTABLE(0b, 0b)
16292+#endif
16293+
16294 /* adds 0xffff0001, returns the old value */
16295 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
16296 /* was the active mask 0 before? */
16297@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
16298 long tmp;
16299 asm volatile("# beginning __up_read\n\t"
16300 LOCK_PREFIX " xadd %1,(%2)\n\t"
16301+
16302+#ifdef CONFIG_PAX_REFCOUNT
16303+ "jno 0f\n"
16304+ "mov %1,(%2)\n"
16305+ "int $4\n0:\n"
16306+ _ASM_EXTABLE(0b, 0b)
16307+#endif
16308+
16309 /* subtracts 1, returns the old value */
16310 " jns 1f\n\t"
16311 " call call_rwsem_wake\n" /* expects old value in %edx */
16312@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
16313 long tmp;
16314 asm volatile("# beginning __up_write\n\t"
16315 LOCK_PREFIX " xadd %1,(%2)\n\t"
16316+
16317+#ifdef CONFIG_PAX_REFCOUNT
16318+ "jno 0f\n"
16319+ "mov %1,(%2)\n"
16320+ "int $4\n0:\n"
16321+ _ASM_EXTABLE(0b, 0b)
16322+#endif
16323+
16324 /* subtracts 0xffff0001, returns the old value */
16325 " jns 1f\n\t"
16326 " call call_rwsem_wake\n" /* expects old value in %edx */
16327@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
16328 {
16329 asm volatile("# beginning __downgrade_write\n\t"
16330 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
16331+
16332+#ifdef CONFIG_PAX_REFCOUNT
16333+ "jno 0f\n"
16334+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
16335+ "int $4\n0:\n"
16336+ _ASM_EXTABLE(0b, 0b)
16337+#endif
16338+
16339 /*
16340 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
16341 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
16342@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
16343 */
16344 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
16345 {
16346- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
16347+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
16348+
16349+#ifdef CONFIG_PAX_REFCOUNT
16350+ "jno 0f\n"
16351+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
16352+ "int $4\n0:\n"
16353+ _ASM_EXTABLE(0b, 0b)
16354+#endif
16355+
16356 : "+m" (sem->count)
16357 : "er" (delta));
16358 }
16359@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
16360 */
16361 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
16362 {
16363- return delta + xadd(&sem->count, delta);
16364+ return delta + xadd_check_overflow(&sem->count, delta);
16365 }
16366
16367 #endif /* __KERNEL__ */
16368diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
16369index c48a950..bc40804 100644
16370--- a/arch/x86/include/asm/segment.h
16371+++ b/arch/x86/include/asm/segment.h
16372@@ -64,10 +64,15 @@
16373 * 26 - ESPFIX small SS
16374 * 27 - per-cpu [ offset to per-cpu data area ]
16375 * 28 - stack_canary-20 [ for stack protector ]
16376- * 29 - unused
16377- * 30 - unused
16378+ * 29 - PCI BIOS CS
16379+ * 30 - PCI BIOS DS
16380 * 31 - TSS for double fault handler
16381 */
16382+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
16383+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
16384+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
16385+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
16386+
16387 #define GDT_ENTRY_TLS_MIN 6
16388 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
16389
16390@@ -79,6 +84,8 @@
16391
16392 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
16393
16394+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
16395+
16396 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
16397
16398 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
16399@@ -104,6 +111,12 @@
16400 #define __KERNEL_STACK_CANARY 0
16401 #endif
16402
16403+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
16404+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
16405+
16406+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
16407+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
16408+
16409 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
16410
16411 /*
16412@@ -141,7 +154,7 @@
16413 */
16414
16415 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
16416-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
16417+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
16418
16419
16420 #else
16421@@ -165,6 +178,8 @@
16422 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
16423 #define __USER32_DS __USER_DS
16424
16425+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
16426+
16427 #define GDT_ENTRY_TSS 8 /* needs two entries */
16428 #define GDT_ENTRY_LDT 10 /* needs two entries */
16429 #define GDT_ENTRY_TLS_MIN 12
16430@@ -173,6 +188,8 @@
16431 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
16432 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
16433
16434+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
16435+
16436 /* TLS indexes for 64bit - hardcoded in arch_prctl */
16437 #define FS_TLS 0
16438 #define GS_TLS 1
16439@@ -180,12 +197,14 @@
16440 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
16441 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
16442
16443-#define GDT_ENTRIES 16
16444+#define GDT_ENTRIES 17
16445
16446 #endif
16447
16448 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
16449+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
16450 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
16451+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
16452 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
16453 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
16454 #ifndef CONFIG_PARAVIRT
16455@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
16456 {
16457 unsigned long __limit;
16458 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
16459- return __limit + 1;
16460+ return __limit;
16461 }
16462
16463 #endif /* !__ASSEMBLY__ */
16464diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
16465index 8d3120f..352b440 100644
16466--- a/arch/x86/include/asm/smap.h
16467+++ b/arch/x86/include/asm/smap.h
16468@@ -25,11 +25,40 @@
16469
16470 #include <asm/alternative-asm.h>
16471
16472+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16473+#define ASM_PAX_OPEN_USERLAND \
16474+ 661: jmp 663f; \
16475+ .pushsection .altinstr_replacement, "a" ; \
16476+ 662: pushq %rax; nop; \
16477+ .popsection ; \
16478+ .pushsection .altinstructions, "a" ; \
16479+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
16480+ .popsection ; \
16481+ call __pax_open_userland; \
16482+ popq %rax; \
16483+ 663:
16484+
16485+#define ASM_PAX_CLOSE_USERLAND \
16486+ 661: jmp 663f; \
16487+ .pushsection .altinstr_replacement, "a" ; \
16488+ 662: pushq %rax; nop; \
16489+ .popsection; \
16490+ .pushsection .altinstructions, "a" ; \
16491+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
16492+ .popsection; \
16493+ call __pax_close_userland; \
16494+ popq %rax; \
16495+ 663:
16496+#else
16497+#define ASM_PAX_OPEN_USERLAND
16498+#define ASM_PAX_CLOSE_USERLAND
16499+#endif
16500+
16501 #ifdef CONFIG_X86_SMAP
16502
16503 #define ASM_CLAC \
16504 661: ASM_NOP3 ; \
16505- .pushsection .altinstr_replacement, "ax" ; \
16506+ .pushsection .altinstr_replacement, "a" ; \
16507 662: __ASM_CLAC ; \
16508 .popsection ; \
16509 .pushsection .altinstructions, "a" ; \
16510@@ -38,7 +67,7 @@
16511
16512 #define ASM_STAC \
16513 661: ASM_NOP3 ; \
16514- .pushsection .altinstr_replacement, "ax" ; \
16515+ .pushsection .altinstr_replacement, "a" ; \
16516 662: __ASM_STAC ; \
16517 .popsection ; \
16518 .pushsection .altinstructions, "a" ; \
16519@@ -56,6 +85,37 @@
16520
16521 #include <asm/alternative.h>
16522
16523+#define __HAVE_ARCH_PAX_OPEN_USERLAND
16524+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
16525+
16526+extern void __pax_open_userland(void);
16527+static __always_inline unsigned long pax_open_userland(void)
16528+{
16529+
16530+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16531+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
16532+ :
16533+ : [open] "i" (__pax_open_userland)
16534+ : "memory", "rax");
16535+#endif
16536+
16537+ return 0;
16538+}
16539+
16540+extern void __pax_close_userland(void);
16541+static __always_inline unsigned long pax_close_userland(void)
16542+{
16543+
16544+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16545+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
16546+ :
16547+ : [close] "i" (__pax_close_userland)
16548+ : "memory", "rax");
16549+#endif
16550+
16551+ return 0;
16552+}
16553+
16554 #ifdef CONFIG_X86_SMAP
16555
16556 static __always_inline void clac(void)
16557diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
16558index b073aae..39f9bdd 100644
16559--- a/arch/x86/include/asm/smp.h
16560+++ b/arch/x86/include/asm/smp.h
16561@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
16562 /* cpus sharing the last level cache: */
16563 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
16564 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
16565-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
16566+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
16567
16568 static inline struct cpumask *cpu_sibling_mask(int cpu)
16569 {
16570@@ -79,7 +79,7 @@ struct smp_ops {
16571
16572 void (*send_call_func_ipi)(const struct cpumask *mask);
16573 void (*send_call_func_single_ipi)(int cpu);
16574-};
16575+} __no_const;
16576
16577 /* Globals due to paravirt */
16578 extern void set_cpu_sibling_map(int cpu);
16579@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
16580 extern int safe_smp_processor_id(void);
16581
16582 #elif defined(CONFIG_X86_64_SMP)
16583-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
16584-
16585-#define stack_smp_processor_id() \
16586-({ \
16587- struct thread_info *ti; \
16588- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
16589- ti->cpu; \
16590-})
16591+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
16592+#define stack_smp_processor_id() raw_smp_processor_id()
16593 #define safe_smp_processor_id() smp_processor_id()
16594
16595 #endif
16596diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
16597index 33692ea..350a534 100644
16598--- a/arch/x86/include/asm/spinlock.h
16599+++ b/arch/x86/include/asm/spinlock.h
16600@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
16601 static inline void arch_read_lock(arch_rwlock_t *rw)
16602 {
16603 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
16604+
16605+#ifdef CONFIG_PAX_REFCOUNT
16606+ "jno 0f\n"
16607+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
16608+ "int $4\n0:\n"
16609+ _ASM_EXTABLE(0b, 0b)
16610+#endif
16611+
16612 "jns 1f\n"
16613 "call __read_lock_failed\n\t"
16614 "1:\n"
16615@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
16616 static inline void arch_write_lock(arch_rwlock_t *rw)
16617 {
16618 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
16619+
16620+#ifdef CONFIG_PAX_REFCOUNT
16621+ "jno 0f\n"
16622+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
16623+ "int $4\n0:\n"
16624+ _ASM_EXTABLE(0b, 0b)
16625+#endif
16626+
16627 "jz 1f\n"
16628 "call __write_lock_failed\n\t"
16629 "1:\n"
16630@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
16631
16632 static inline void arch_read_unlock(arch_rwlock_t *rw)
16633 {
16634- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
16635+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
16636+
16637+#ifdef CONFIG_PAX_REFCOUNT
16638+ "jno 0f\n"
16639+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
16640+ "int $4\n0:\n"
16641+ _ASM_EXTABLE(0b, 0b)
16642+#endif
16643+
16644 :"+m" (rw->lock) : : "memory");
16645 }
16646
16647 static inline void arch_write_unlock(arch_rwlock_t *rw)
16648 {
16649- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
16650+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
16651+
16652+#ifdef CONFIG_PAX_REFCOUNT
16653+ "jno 0f\n"
16654+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
16655+ "int $4\n0:\n"
16656+ _ASM_EXTABLE(0b, 0b)
16657+#endif
16658+
16659 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
16660 }
16661
16662diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
16663index 6a99859..03cb807 100644
16664--- a/arch/x86/include/asm/stackprotector.h
16665+++ b/arch/x86/include/asm/stackprotector.h
16666@@ -47,7 +47,7 @@
16667 * head_32 for boot CPU and setup_per_cpu_areas() for others.
16668 */
16669 #define GDT_STACK_CANARY_INIT \
16670- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
16671+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
16672
16673 /*
16674 * Initialize the stackprotector canary value.
16675@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
16676
16677 static inline void load_stack_canary_segment(void)
16678 {
16679-#ifdef CONFIG_X86_32
16680+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16681 asm volatile ("mov %0, %%gs" : : "r" (0));
16682 #endif
16683 }
16684diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
16685index 70bbe39..4ae2bd4 100644
16686--- a/arch/x86/include/asm/stacktrace.h
16687+++ b/arch/x86/include/asm/stacktrace.h
16688@@ -11,28 +11,20 @@
16689
16690 extern int kstack_depth_to_print;
16691
16692-struct thread_info;
16693+struct task_struct;
16694 struct stacktrace_ops;
16695
16696-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
16697- unsigned long *stack,
16698- unsigned long bp,
16699- const struct stacktrace_ops *ops,
16700- void *data,
16701- unsigned long *end,
16702- int *graph);
16703+typedef unsigned long walk_stack_t(struct task_struct *task,
16704+ void *stack_start,
16705+ unsigned long *stack,
16706+ unsigned long bp,
16707+ const struct stacktrace_ops *ops,
16708+ void *data,
16709+ unsigned long *end,
16710+ int *graph);
16711
16712-extern unsigned long
16713-print_context_stack(struct thread_info *tinfo,
16714- unsigned long *stack, unsigned long bp,
16715- const struct stacktrace_ops *ops, void *data,
16716- unsigned long *end, int *graph);
16717-
16718-extern unsigned long
16719-print_context_stack_bp(struct thread_info *tinfo,
16720- unsigned long *stack, unsigned long bp,
16721- const struct stacktrace_ops *ops, void *data,
16722- unsigned long *end, int *graph);
16723+extern walk_stack_t print_context_stack;
16724+extern walk_stack_t print_context_stack_bp;
16725
16726 /* Generic stack tracer with callbacks */
16727
16728@@ -40,7 +32,7 @@ struct stacktrace_ops {
16729 void (*address)(void *data, unsigned long address, int reliable);
16730 /* On negative return stop dumping */
16731 int (*stack)(void *data, char *name);
16732- walk_stack_t walk_stack;
16733+ walk_stack_t *walk_stack;
16734 };
16735
16736 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
16737diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
16738index 4ec45b3..a4f0a8a 100644
16739--- a/arch/x86/include/asm/switch_to.h
16740+++ b/arch/x86/include/asm/switch_to.h
16741@@ -108,7 +108,7 @@ do { \
16742 "call __switch_to\n\t" \
16743 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
16744 __switch_canary \
16745- "movq %P[thread_info](%%rsi),%%r8\n\t" \
16746+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
16747 "movq %%rax,%%rdi\n\t" \
16748 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
16749 "jnz ret_from_fork\n\t" \
16750@@ -119,7 +119,7 @@ do { \
16751 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
16752 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
16753 [_tif_fork] "i" (_TIF_FORK), \
16754- [thread_info] "i" (offsetof(struct task_struct, stack)), \
16755+ [thread_info] "m" (current_tinfo), \
16756 [current_task] "m" (current_task) \
16757 __switch_canary_iparam \
16758 : "memory", "cc" __EXTRA_CLOBBER)
16759diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
16760index a1df6e8..e002940 100644
16761--- a/arch/x86/include/asm/thread_info.h
16762+++ b/arch/x86/include/asm/thread_info.h
16763@@ -10,6 +10,7 @@
16764 #include <linux/compiler.h>
16765 #include <asm/page.h>
16766 #include <asm/types.h>
16767+#include <asm/percpu.h>
16768
16769 /*
16770 * low level task data that entry.S needs immediate access to
16771@@ -23,7 +24,6 @@ struct exec_domain;
16772 #include <linux/atomic.h>
16773
16774 struct thread_info {
16775- struct task_struct *task; /* main task structure */
16776 struct exec_domain *exec_domain; /* execution domain */
16777 __u32 flags; /* low level flags */
16778 __u32 status; /* thread synchronous flags */
16779@@ -33,19 +33,13 @@ struct thread_info {
16780 mm_segment_t addr_limit;
16781 struct restart_block restart_block;
16782 void __user *sysenter_return;
16783-#ifdef CONFIG_X86_32
16784- unsigned long previous_esp; /* ESP of the previous stack in
16785- case of nested (IRQ) stacks
16786- */
16787- __u8 supervisor_stack[0];
16788-#endif
16789+ unsigned long lowest_stack;
16790 unsigned int sig_on_uaccess_error:1;
16791 unsigned int uaccess_err:1; /* uaccess failed */
16792 };
16793
16794-#define INIT_THREAD_INFO(tsk) \
16795+#define INIT_THREAD_INFO \
16796 { \
16797- .task = &tsk, \
16798 .exec_domain = &default_exec_domain, \
16799 .flags = 0, \
16800 .cpu = 0, \
16801@@ -56,7 +50,7 @@ struct thread_info {
16802 }, \
16803 }
16804
16805-#define init_thread_info (init_thread_union.thread_info)
16806+#define init_thread_info (init_thread_union.stack)
16807 #define init_stack (init_thread_union.stack)
16808
16809 #else /* !__ASSEMBLY__ */
16810@@ -97,6 +91,7 @@ struct thread_info {
16811 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
16812 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
16813 #define TIF_X32 30 /* 32-bit native x86-64 binary */
16814+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
16815
16816 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
16817 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
16818@@ -121,17 +116,18 @@ struct thread_info {
16819 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
16820 #define _TIF_ADDR32 (1 << TIF_ADDR32)
16821 #define _TIF_X32 (1 << TIF_X32)
16822+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
16823
16824 /* work to do in syscall_trace_enter() */
16825 #define _TIF_WORK_SYSCALL_ENTRY \
16826 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
16827 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
16828- _TIF_NOHZ)
16829+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
16830
16831 /* work to do in syscall_trace_leave() */
16832 #define _TIF_WORK_SYSCALL_EXIT \
16833 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
16834- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
16835+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
16836
16837 /* work to do on interrupt/exception return */
16838 #define _TIF_WORK_MASK \
16839@@ -142,7 +138,7 @@ struct thread_info {
16840 /* work to do on any return to user space */
16841 #define _TIF_ALLWORK_MASK \
16842 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
16843- _TIF_NOHZ)
16844+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
16845
16846 /* Only used for 64 bit */
16847 #define _TIF_DO_NOTIFY_MASK \
16848@@ -158,45 +154,40 @@ struct thread_info {
16849
16850 #define PREEMPT_ACTIVE 0x10000000
16851
16852-#ifdef CONFIG_X86_32
16853-
16854-#define STACK_WARN (THREAD_SIZE/8)
16855-/*
16856- * macros/functions for gaining access to the thread information structure
16857- *
16858- * preempt_count needs to be 1 initially, until the scheduler is functional.
16859- */
16860-#ifndef __ASSEMBLY__
16861-
16862-
16863-/* how to get the current stack pointer from C */
16864-register unsigned long current_stack_pointer asm("esp") __used;
16865-
16866-/* how to get the thread information struct from C */
16867-static inline struct thread_info *current_thread_info(void)
16868-{
16869- return (struct thread_info *)
16870- (current_stack_pointer & ~(THREAD_SIZE - 1));
16871-}
16872-
16873-#else /* !__ASSEMBLY__ */
16874-
16875+#ifdef __ASSEMBLY__
16876 /* how to get the thread information struct from ASM */
16877 #define GET_THREAD_INFO(reg) \
16878- movl $-THREAD_SIZE, reg; \
16879- andl %esp, reg
16880+ mov PER_CPU_VAR(current_tinfo), reg
16881
16882 /* use this one if reg already contains %esp */
16883-#define GET_THREAD_INFO_WITH_ESP(reg) \
16884- andl $-THREAD_SIZE, reg
16885+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
16886+#else
16887+/* how to get the thread information struct from C */
16888+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
16889+
16890+static __always_inline struct thread_info *current_thread_info(void)
16891+{
16892+ return this_cpu_read_stable(current_tinfo);
16893+}
16894+#endif
16895+
16896+#ifdef CONFIG_X86_32
16897+
16898+#define STACK_WARN (THREAD_SIZE/8)
16899+/*
16900+ * macros/functions for gaining access to the thread information structure
16901+ *
16902+ * preempt_count needs to be 1 initially, until the scheduler is functional.
16903+ */
16904+#ifndef __ASSEMBLY__
16905+
16906+/* how to get the current stack pointer from C */
16907+register unsigned long current_stack_pointer asm("esp") __used;
16908
16909 #endif
16910
16911 #else /* X86_32 */
16912
16913-#include <asm/percpu.h>
16914-#define KERNEL_STACK_OFFSET (5*8)
16915-
16916 /*
16917 * macros/functions for gaining access to the thread information structure
16918 * preempt_count needs to be 1 initially, until the scheduler is functional.
16919@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
16920 #ifndef __ASSEMBLY__
16921 DECLARE_PER_CPU(unsigned long, kernel_stack);
16922
16923-static inline struct thread_info *current_thread_info(void)
16924-{
16925- struct thread_info *ti;
16926- ti = (void *)(this_cpu_read_stable(kernel_stack) +
16927- KERNEL_STACK_OFFSET - THREAD_SIZE);
16928- return ti;
16929-}
16930-
16931-#else /* !__ASSEMBLY__ */
16932-
16933-/* how to get the thread information struct from ASM */
16934-#define GET_THREAD_INFO(reg) \
16935- movq PER_CPU_VAR(kernel_stack),reg ; \
16936- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
16937-
16938-/*
16939- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
16940- * a certain register (to be used in assembler memory operands).
16941- */
16942-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
16943-
16944+/* how to get the current stack pointer from C */
16945+register unsigned long current_stack_pointer asm("rsp") __used;
16946 #endif
16947
16948 #endif /* !X86_32 */
16949@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
16950 extern void arch_task_cache_init(void);
16951 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
16952 extern void arch_release_task_struct(struct task_struct *tsk);
16953+
16954+#define __HAVE_THREAD_FUNCTIONS
16955+#define task_thread_info(task) (&(task)->tinfo)
16956+#define task_stack_page(task) ((task)->stack)
16957+#define setup_thread_stack(p, org) do {} while (0)
16958+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
16959+
16960 #endif
16961 #endif /* _ASM_X86_THREAD_INFO_H */
16962diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
16963index 50a7fc0..7c437a7 100644
16964--- a/arch/x86/include/asm/tlbflush.h
16965+++ b/arch/x86/include/asm/tlbflush.h
16966@@ -17,18 +17,40 @@
16967
16968 static inline void __native_flush_tlb(void)
16969 {
16970+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16971+ unsigned long descriptor[2];
16972+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
16973+ return;
16974+ }
16975+
16976+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16977+ if (static_cpu_has(X86_FEATURE_PCID)) {
16978+ unsigned int cpu = raw_get_cpu();
16979+
16980+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16981+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16982+ raw_put_cpu_no_resched();
16983+ return;
16984+ }
16985+#endif
16986+
16987 native_write_cr3(native_read_cr3());
16988 }
16989
16990 static inline void __native_flush_tlb_global_irq_disabled(void)
16991 {
16992- unsigned long cr4;
16993+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16994+ unsigned long descriptor[2];
16995+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
16996+ } else {
16997+ unsigned long cr4;
16998
16999- cr4 = native_read_cr4();
17000- /* clear PGE */
17001- native_write_cr4(cr4 & ~X86_CR4_PGE);
17002- /* write old PGE again and flush TLBs */
17003- native_write_cr4(cr4);
17004+ cr4 = native_read_cr4();
17005+ /* clear PGE */
17006+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17007+ /* write old PGE again and flush TLBs */
17008+ native_write_cr4(cr4);
17009+ }
17010 }
17011
17012 static inline void __native_flush_tlb_global(void)
17013@@ -49,6 +71,42 @@ static inline void __native_flush_tlb_global(void)
17014
17015 static inline void __native_flush_tlb_single(unsigned long addr)
17016 {
17017+
17018+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17019+ unsigned long descriptor[2];
17020+
17021+ descriptor[0] = PCID_KERNEL;
17022+ descriptor[1] = addr;
17023+
17024+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17025+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17026+ if (addr < TASK_SIZE_MAX)
17027+ descriptor[1] += pax_user_shadow_base;
17028+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17029+ }
17030+
17031+ descriptor[0] = PCID_USER;
17032+ descriptor[1] = addr;
17033+#endif
17034+
17035+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17036+ return;
17037+ }
17038+
17039+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17040+ if (static_cpu_has(X86_FEATURE_PCID)) {
17041+ unsigned int cpu = raw_get_cpu();
17042+
17043+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17044+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17045+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17046+ raw_put_cpu_no_resched();
17047+
17048+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17049+ addr += pax_user_shadow_base;
17050+ }
17051+#endif
17052+
17053 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17054 }
17055
17056diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17057index 5ee2687..74590b9 100644
17058--- a/arch/x86/include/asm/uaccess.h
17059+++ b/arch/x86/include/asm/uaccess.h
17060@@ -7,6 +7,7 @@
17061 #include <linux/compiler.h>
17062 #include <linux/thread_info.h>
17063 #include <linux/string.h>
17064+#include <linux/sched.h>
17065 #include <asm/asm.h>
17066 #include <asm/page.h>
17067 #include <asm/smap.h>
17068@@ -29,7 +30,12 @@
17069
17070 #define get_ds() (KERNEL_DS)
17071 #define get_fs() (current_thread_info()->addr_limit)
17072+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17073+void __set_fs(mm_segment_t x);
17074+void set_fs(mm_segment_t x);
17075+#else
17076 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17077+#endif
17078
17079 #define segment_eq(a, b) ((a).seg == (b).seg)
17080
17081@@ -77,8 +83,33 @@
17082 * checks that the pointer is in the user space range - after calling
17083 * this function, memory access functions may still return -EFAULT.
17084 */
17085-#define access_ok(type, addr, size) \
17086- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17087+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17088+#define access_ok(type, addr, size) \
17089+({ \
17090+ long __size = size; \
17091+ unsigned long __addr = (unsigned long)addr; \
17092+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17093+ unsigned long __end_ao = __addr + __size - 1; \
17094+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17095+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17096+ while(__addr_ao <= __end_ao) { \
17097+ char __c_ao; \
17098+ __addr_ao += PAGE_SIZE; \
17099+ if (__size > PAGE_SIZE) \
17100+ cond_resched(); \
17101+ if (__get_user(__c_ao, (char __user *)__addr)) \
17102+ break; \
17103+ if (type != VERIFY_WRITE) { \
17104+ __addr = __addr_ao; \
17105+ continue; \
17106+ } \
17107+ if (__put_user(__c_ao, (char __user *)__addr)) \
17108+ break; \
17109+ __addr = __addr_ao; \
17110+ } \
17111+ } \
17112+ __ret_ao; \
17113+})
17114
17115 /*
17116 * The exception table consists of pairs of addresses relative to the
17117@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17118 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17119 __chk_user_ptr(ptr); \
17120 might_fault(); \
17121+ pax_open_userland(); \
17122 asm volatile("call __get_user_%P3" \
17123 : "=a" (__ret_gu), "=r" (__val_gu) \
17124 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17125 (x) = (__typeof__(*(ptr))) __val_gu; \
17126+ pax_close_userland(); \
17127 __ret_gu; \
17128 })
17129
17130@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17131 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17132 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17133
17134-
17135+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17136+#define __copyuser_seg "gs;"
17137+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17138+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17139+#else
17140+#define __copyuser_seg
17141+#define __COPYUSER_SET_ES
17142+#define __COPYUSER_RESTORE_ES
17143+#endif
17144
17145 #ifdef CONFIG_X86_32
17146 #define __put_user_asm_u64(x, addr, err, errret) \
17147 asm volatile(ASM_STAC "\n" \
17148- "1: movl %%eax,0(%2)\n" \
17149- "2: movl %%edx,4(%2)\n" \
17150+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17151+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17152 "3: " ASM_CLAC "\n" \
17153 ".section .fixup,\"ax\"\n" \
17154 "4: movl %3,%0\n" \
17155@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17156
17157 #define __put_user_asm_ex_u64(x, addr) \
17158 asm volatile(ASM_STAC "\n" \
17159- "1: movl %%eax,0(%1)\n" \
17160- "2: movl %%edx,4(%1)\n" \
17161+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
17162+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
17163 "3: " ASM_CLAC "\n" \
17164 _ASM_EXTABLE_EX(1b, 2b) \
17165 _ASM_EXTABLE_EX(2b, 3b) \
17166@@ -246,7 +287,8 @@ extern void __put_user_8(void);
17167 __typeof__(*(ptr)) __pu_val; \
17168 __chk_user_ptr(ptr); \
17169 might_fault(); \
17170- __pu_val = x; \
17171+ __pu_val = (x); \
17172+ pax_open_userland(); \
17173 switch (sizeof(*(ptr))) { \
17174 case 1: \
17175 __put_user_x(1, __pu_val, ptr, __ret_pu); \
17176@@ -264,6 +306,7 @@ extern void __put_user_8(void);
17177 __put_user_x(X, __pu_val, ptr, __ret_pu); \
17178 break; \
17179 } \
17180+ pax_close_userland(); \
17181 __ret_pu; \
17182 })
17183
17184@@ -344,8 +387,10 @@ do { \
17185 } while (0)
17186
17187 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
17188+do { \
17189+ pax_open_userland(); \
17190 asm volatile(ASM_STAC "\n" \
17191- "1: mov"itype" %2,%"rtype"1\n" \
17192+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
17193 "2: " ASM_CLAC "\n" \
17194 ".section .fixup,\"ax\"\n" \
17195 "3: mov %3,%0\n" \
17196@@ -353,8 +398,10 @@ do { \
17197 " jmp 2b\n" \
17198 ".previous\n" \
17199 _ASM_EXTABLE(1b, 3b) \
17200- : "=r" (err), ltype(x) \
17201- : "m" (__m(addr)), "i" (errret), "0" (err))
17202+ : "=r" (err), ltype (x) \
17203+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
17204+ pax_close_userland(); \
17205+} while (0)
17206
17207 #define __get_user_size_ex(x, ptr, size) \
17208 do { \
17209@@ -378,7 +425,7 @@ do { \
17210 } while (0)
17211
17212 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
17213- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
17214+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
17215 "2:\n" \
17216 _ASM_EXTABLE_EX(1b, 2b) \
17217 : ltype(x) : "m" (__m(addr)))
17218@@ -395,13 +442,24 @@ do { \
17219 int __gu_err; \
17220 unsigned long __gu_val; \
17221 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
17222- (x) = (__force __typeof__(*(ptr)))__gu_val; \
17223+ (x) = (__typeof__(*(ptr)))__gu_val; \
17224 __gu_err; \
17225 })
17226
17227 /* FIXME: this hack is definitely wrong -AK */
17228 struct __large_struct { unsigned long buf[100]; };
17229-#define __m(x) (*(struct __large_struct __user *)(x))
17230+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17231+#define ____m(x) \
17232+({ \
17233+ unsigned long ____x = (unsigned long)(x); \
17234+ if (____x < pax_user_shadow_base) \
17235+ ____x += pax_user_shadow_base; \
17236+ (typeof(x))____x; \
17237+})
17238+#else
17239+#define ____m(x) (x)
17240+#endif
17241+#define __m(x) (*(struct __large_struct __user *)____m(x))
17242
17243 /*
17244 * Tell gcc we read from memory instead of writing: this is because
17245@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
17246 * aliasing issues.
17247 */
17248 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
17249+do { \
17250+ pax_open_userland(); \
17251 asm volatile(ASM_STAC "\n" \
17252- "1: mov"itype" %"rtype"1,%2\n" \
17253+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
17254 "2: " ASM_CLAC "\n" \
17255 ".section .fixup,\"ax\"\n" \
17256 "3: mov %3,%0\n" \
17257@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
17258 ".previous\n" \
17259 _ASM_EXTABLE(1b, 3b) \
17260 : "=r"(err) \
17261- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
17262+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
17263+ pax_close_userland(); \
17264+} while (0)
17265
17266 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
17267- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
17268+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
17269 "2:\n" \
17270 _ASM_EXTABLE_EX(1b, 2b) \
17271 : : ltype(x), "m" (__m(addr)))
17272@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
17273 */
17274 #define uaccess_try do { \
17275 current_thread_info()->uaccess_err = 0; \
17276+ pax_open_userland(); \
17277 stac(); \
17278 barrier();
17279
17280 #define uaccess_catch(err) \
17281 clac(); \
17282+ pax_close_userland(); \
17283 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
17284 } while (0)
17285
17286@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
17287 * On error, the variable @x is set to zero.
17288 */
17289
17290+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17291+#define __get_user(x, ptr) get_user((x), (ptr))
17292+#else
17293 #define __get_user(x, ptr) \
17294 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
17295+#endif
17296
17297 /**
17298 * __put_user: - Write a simple value into user space, with less checking.
17299@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
17300 * Returns zero on success, or -EFAULT on error.
17301 */
17302
17303+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17304+#define __put_user(x, ptr) put_user((x), (ptr))
17305+#else
17306 #define __put_user(x, ptr) \
17307 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
17308+#endif
17309
17310 #define __get_user_unaligned __get_user
17311 #define __put_user_unaligned __put_user
17312@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
17313 #define get_user_ex(x, ptr) do { \
17314 unsigned long __gue_val; \
17315 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
17316- (x) = (__force __typeof__(*(ptr)))__gue_val; \
17317+ (x) = (__typeof__(*(ptr)))__gue_val; \
17318 } while (0)
17319
17320 #define put_user_try uaccess_try
17321@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
17322 extern __must_check long strlen_user(const char __user *str);
17323 extern __must_check long strnlen_user(const char __user *str, long n);
17324
17325-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
17326-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
17327+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
17328+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
17329
17330 /*
17331 * movsl can be slow when source and dest are not both 8-byte aligned
17332diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
17333index 7f760a9..04b1c65 100644
17334--- a/arch/x86/include/asm/uaccess_32.h
17335+++ b/arch/x86/include/asm/uaccess_32.h
17336@@ -11,15 +11,15 @@
17337 #include <asm/page.h>
17338
17339 unsigned long __must_check __copy_to_user_ll
17340- (void __user *to, const void *from, unsigned long n);
17341+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
17342 unsigned long __must_check __copy_from_user_ll
17343- (void *to, const void __user *from, unsigned long n);
17344+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
17345 unsigned long __must_check __copy_from_user_ll_nozero
17346- (void *to, const void __user *from, unsigned long n);
17347+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
17348 unsigned long __must_check __copy_from_user_ll_nocache
17349- (void *to, const void __user *from, unsigned long n);
17350+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
17351 unsigned long __must_check __copy_from_user_ll_nocache_nozero
17352- (void *to, const void __user *from, unsigned long n);
17353+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
17354
17355 /**
17356 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
17357@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
17358 static __always_inline unsigned long __must_check
17359 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
17360 {
17361+ if ((long)n < 0)
17362+ return n;
17363+
17364+ check_object_size(from, n, true);
17365+
17366 if (__builtin_constant_p(n)) {
17367 unsigned long ret;
17368
17369@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
17370 __copy_to_user(void __user *to, const void *from, unsigned long n)
17371 {
17372 might_fault();
17373+
17374 return __copy_to_user_inatomic(to, from, n);
17375 }
17376
17377 static __always_inline unsigned long
17378 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
17379 {
17380+ if ((long)n < 0)
17381+ return n;
17382+
17383 /* Avoid zeroing the tail if the copy fails..
17384 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
17385 * but as the zeroing behaviour is only significant when n is not
17386@@ -137,6 +146,12 @@ static __always_inline unsigned long
17387 __copy_from_user(void *to, const void __user *from, unsigned long n)
17388 {
17389 might_fault();
17390+
17391+ if ((long)n < 0)
17392+ return n;
17393+
17394+ check_object_size(to, n, false);
17395+
17396 if (__builtin_constant_p(n)) {
17397 unsigned long ret;
17398
17399@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
17400 const void __user *from, unsigned long n)
17401 {
17402 might_fault();
17403+
17404+ if ((long)n < 0)
17405+ return n;
17406+
17407 if (__builtin_constant_p(n)) {
17408 unsigned long ret;
17409
17410@@ -181,15 +200,19 @@ static __always_inline unsigned long
17411 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
17412 unsigned long n)
17413 {
17414- return __copy_from_user_ll_nocache_nozero(to, from, n);
17415+ if ((long)n < 0)
17416+ return n;
17417+
17418+ return __copy_from_user_ll_nocache_nozero(to, from, n);
17419 }
17420
17421-unsigned long __must_check copy_to_user(void __user *to,
17422- const void *from, unsigned long n);
17423-unsigned long __must_check _copy_from_user(void *to,
17424- const void __user *from,
17425- unsigned long n);
17426-
17427+extern void copy_to_user_overflow(void)
17428+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
17429+ __compiletime_error("copy_to_user() buffer size is not provably correct")
17430+#else
17431+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
17432+#endif
17433+;
17434
17435 extern void copy_from_user_overflow(void)
17436 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
17437@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
17438 #endif
17439 ;
17440
17441-static inline unsigned long __must_check copy_from_user(void *to,
17442- const void __user *from,
17443- unsigned long n)
17444+/**
17445+ * copy_to_user: - Copy a block of data into user space.
17446+ * @to: Destination address, in user space.
17447+ * @from: Source address, in kernel space.
17448+ * @n: Number of bytes to copy.
17449+ *
17450+ * Context: User context only. This function may sleep.
17451+ *
17452+ * Copy data from kernel space to user space.
17453+ *
17454+ * Returns number of bytes that could not be copied.
17455+ * On success, this will be zero.
17456+ */
17457+static inline unsigned long __must_check
17458+copy_to_user(void __user *to, const void *from, unsigned long n)
17459 {
17460- int sz = __compiletime_object_size(to);
17461+ size_t sz = __compiletime_object_size(from);
17462
17463- if (likely(sz == -1 || sz >= n))
17464- n = _copy_from_user(to, from, n);
17465- else
17466+ if (unlikely(sz != (size_t)-1 && sz < n))
17467+ copy_to_user_overflow();
17468+ else if (access_ok(VERIFY_WRITE, to, n))
17469+ n = __copy_to_user(to, from, n);
17470+ return n;
17471+}
17472+
17473+/**
17474+ * copy_from_user: - Copy a block of data from user space.
17475+ * @to: Destination address, in kernel space.
17476+ * @from: Source address, in user space.
17477+ * @n: Number of bytes to copy.
17478+ *
17479+ * Context: User context only. This function may sleep.
17480+ *
17481+ * Copy data from user space to kernel space.
17482+ *
17483+ * Returns number of bytes that could not be copied.
17484+ * On success, this will be zero.
17485+ *
17486+ * If some data could not be copied, this function will pad the copied
17487+ * data to the requested size using zero bytes.
17488+ */
17489+static inline unsigned long __must_check
17490+copy_from_user(void *to, const void __user *from, unsigned long n)
17491+{
17492+ size_t sz = __compiletime_object_size(to);
17493+
17494+ check_object_size(to, n, false);
17495+
17496+ if (unlikely(sz != (size_t)-1 && sz < n))
17497 copy_from_user_overflow();
17498-
17499+ else if (access_ok(VERIFY_READ, from, n))
17500+ n = __copy_from_user(to, from, n);
17501+ else if ((long)n > 0)
17502+ memset(to, 0, n);
17503 return n;
17504 }
17505
17506diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
17507index 142810c..1f2a0a7 100644
17508--- a/arch/x86/include/asm/uaccess_64.h
17509+++ b/arch/x86/include/asm/uaccess_64.h
17510@@ -10,6 +10,9 @@
17511 #include <asm/alternative.h>
17512 #include <asm/cpufeature.h>
17513 #include <asm/page.h>
17514+#include <asm/pgtable.h>
17515+
17516+#define set_fs(x) (current_thread_info()->addr_limit = (x))
17517
17518 /*
17519 * Copy To/From Userspace
17520@@ -17,13 +20,13 @@
17521
17522 /* Handles exceptions in both to and from, but doesn't do access_ok */
17523 __must_check unsigned long
17524-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
17525+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
17526 __must_check unsigned long
17527-copy_user_generic_string(void *to, const void *from, unsigned len);
17528+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
17529 __must_check unsigned long
17530-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
17531+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
17532
17533-static __always_inline __must_check unsigned long
17534+static __always_inline __must_check __size_overflow(3) unsigned long
17535 copy_user_generic(void *to, const void *from, unsigned len)
17536 {
17537 unsigned ret;
17538@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
17539 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
17540 "=d" (len)),
17541 "1" (to), "2" (from), "3" (len)
17542- : "memory", "rcx", "r8", "r9", "r10", "r11");
17543+ : "memory", "rcx", "r8", "r9", "r11");
17544 return ret;
17545 }
17546
17547+static __always_inline __must_check unsigned long
17548+__copy_to_user(void __user *to, const void *from, unsigned long len);
17549+static __always_inline __must_check unsigned long
17550+__copy_from_user(void *to, const void __user *from, unsigned long len);
17551 __must_check unsigned long
17552-_copy_to_user(void __user *to, const void *from, unsigned len);
17553-__must_check unsigned long
17554-_copy_from_user(void *to, const void __user *from, unsigned len);
17555-__must_check unsigned long
17556-copy_in_user(void __user *to, const void __user *from, unsigned len);
17557+copy_in_user(void __user *to, const void __user *from, unsigned long len);
17558+
17559+extern void copy_to_user_overflow(void)
17560+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
17561+ __compiletime_error("copy_to_user() buffer size is not provably correct")
17562+#else
17563+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
17564+#endif
17565+;
17566+
17567+extern void copy_from_user_overflow(void)
17568+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
17569+ __compiletime_error("copy_from_user() buffer size is not provably correct")
17570+#else
17571+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
17572+#endif
17573+;
17574
17575 static inline unsigned long __must_check copy_from_user(void *to,
17576 const void __user *from,
17577 unsigned long n)
17578 {
17579- int sz = __compiletime_object_size(to);
17580-
17581 might_fault();
17582- if (likely(sz == -1 || sz >= n))
17583- n = _copy_from_user(to, from, n);
17584-#ifdef CONFIG_DEBUG_VM
17585- else
17586- WARN(1, "Buffer overflow detected!\n");
17587-#endif
17588+
17589+ check_object_size(to, n, false);
17590+
17591+ if (access_ok(VERIFY_READ, from, n))
17592+ n = __copy_from_user(to, from, n);
17593+ else if (n < INT_MAX)
17594+ memset(to, 0, n);
17595 return n;
17596 }
17597
17598 static __always_inline __must_check
17599-int copy_to_user(void __user *dst, const void *src, unsigned size)
17600+int copy_to_user(void __user *dst, const void *src, unsigned long size)
17601 {
17602 might_fault();
17603
17604- return _copy_to_user(dst, src, size);
17605+ if (access_ok(VERIFY_WRITE, dst, size))
17606+ size = __copy_to_user(dst, src, size);
17607+ return size;
17608 }
17609
17610 static __always_inline __must_check
17611-int __copy_from_user(void *dst, const void __user *src, unsigned size)
17612+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
17613 {
17614- int ret = 0;
17615+ size_t sz = __compiletime_object_size(dst);
17616+ unsigned ret = 0;
17617
17618 might_fault();
17619+
17620+ if (size > INT_MAX)
17621+ return size;
17622+
17623+ check_object_size(dst, size, false);
17624+
17625+#ifdef CONFIG_PAX_MEMORY_UDEREF
17626+ if (!__access_ok(VERIFY_READ, src, size))
17627+ return size;
17628+#endif
17629+
17630+ if (unlikely(sz != (size_t)-1 && sz < size)) {
17631+ copy_from_user_overflow();
17632+ return size;
17633+ }
17634+
17635 if (!__builtin_constant_p(size))
17636- return copy_user_generic(dst, (__force void *)src, size);
17637+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
17638 switch (size) {
17639- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
17640+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
17641 ret, "b", "b", "=q", 1);
17642 return ret;
17643- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
17644+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
17645 ret, "w", "w", "=r", 2);
17646 return ret;
17647- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
17648+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
17649 ret, "l", "k", "=r", 4);
17650 return ret;
17651- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
17652+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17653 ret, "q", "", "=r", 8);
17654 return ret;
17655 case 10:
17656- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
17657+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17658 ret, "q", "", "=r", 10);
17659 if (unlikely(ret))
17660 return ret;
17661 __get_user_asm(*(u16 *)(8 + (char *)dst),
17662- (u16 __user *)(8 + (char __user *)src),
17663+ (const u16 __user *)(8 + (const char __user *)src),
17664 ret, "w", "w", "=r", 2);
17665 return ret;
17666 case 16:
17667- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
17668+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
17669 ret, "q", "", "=r", 16);
17670 if (unlikely(ret))
17671 return ret;
17672 __get_user_asm(*(u64 *)(8 + (char *)dst),
17673- (u64 __user *)(8 + (char __user *)src),
17674+ (const u64 __user *)(8 + (const char __user *)src),
17675 ret, "q", "", "=r", 8);
17676 return ret;
17677 default:
17678- return copy_user_generic(dst, (__force void *)src, size);
17679+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
17680 }
17681 }
17682
17683 static __always_inline __must_check
17684-int __copy_to_user(void __user *dst, const void *src, unsigned size)
17685+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
17686 {
17687- int ret = 0;
17688+ size_t sz = __compiletime_object_size(src);
17689+ unsigned ret = 0;
17690
17691 might_fault();
17692+
17693+ if (size > INT_MAX)
17694+ return size;
17695+
17696+ check_object_size(src, size, true);
17697+
17698+#ifdef CONFIG_PAX_MEMORY_UDEREF
17699+ if (!__access_ok(VERIFY_WRITE, dst, size))
17700+ return size;
17701+#endif
17702+
17703+ if (unlikely(sz != (size_t)-1 && sz < size)) {
17704+ copy_to_user_overflow();
17705+ return size;
17706+ }
17707+
17708 if (!__builtin_constant_p(size))
17709- return copy_user_generic((__force void *)dst, src, size);
17710+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17711 switch (size) {
17712- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
17713+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
17714 ret, "b", "b", "iq", 1);
17715 return ret;
17716- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
17717+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
17718 ret, "w", "w", "ir", 2);
17719 return ret;
17720- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
17721+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
17722 ret, "l", "k", "ir", 4);
17723 return ret;
17724- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
17725+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17726 ret, "q", "", "er", 8);
17727 return ret;
17728 case 10:
17729- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
17730+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17731 ret, "q", "", "er", 10);
17732 if (unlikely(ret))
17733 return ret;
17734 asm("":::"memory");
17735- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
17736+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
17737 ret, "w", "w", "ir", 2);
17738 return ret;
17739 case 16:
17740- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
17741+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
17742 ret, "q", "", "er", 16);
17743 if (unlikely(ret))
17744 return ret;
17745 asm("":::"memory");
17746- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
17747+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
17748 ret, "q", "", "er", 8);
17749 return ret;
17750 default:
17751- return copy_user_generic((__force void *)dst, src, size);
17752+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17753 }
17754 }
17755
17756 static __always_inline __must_check
17757-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17758+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
17759 {
17760- int ret = 0;
17761+ unsigned ret = 0;
17762
17763 might_fault();
17764+
17765+ if (size > INT_MAX)
17766+ return size;
17767+
17768+#ifdef CONFIG_PAX_MEMORY_UDEREF
17769+ if (!__access_ok(VERIFY_READ, src, size))
17770+ return size;
17771+ if (!__access_ok(VERIFY_WRITE, dst, size))
17772+ return size;
17773+#endif
17774+
17775 if (!__builtin_constant_p(size))
17776- return copy_user_generic((__force void *)dst,
17777- (__force void *)src, size);
17778+ return copy_user_generic((__force_kernel void *)____m(dst),
17779+ (__force_kernel const void *)____m(src), size);
17780 switch (size) {
17781 case 1: {
17782 u8 tmp;
17783- __get_user_asm(tmp, (u8 __user *)src,
17784+ __get_user_asm(tmp, (const u8 __user *)src,
17785 ret, "b", "b", "=q", 1);
17786 if (likely(!ret))
17787 __put_user_asm(tmp, (u8 __user *)dst,
17788@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17789 }
17790 case 2: {
17791 u16 tmp;
17792- __get_user_asm(tmp, (u16 __user *)src,
17793+ __get_user_asm(tmp, (const u16 __user *)src,
17794 ret, "w", "w", "=r", 2);
17795 if (likely(!ret))
17796 __put_user_asm(tmp, (u16 __user *)dst,
17797@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17798
17799 case 4: {
17800 u32 tmp;
17801- __get_user_asm(tmp, (u32 __user *)src,
17802+ __get_user_asm(tmp, (const u32 __user *)src,
17803 ret, "l", "k", "=r", 4);
17804 if (likely(!ret))
17805 __put_user_asm(tmp, (u32 __user *)dst,
17806@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17807 }
17808 case 8: {
17809 u64 tmp;
17810- __get_user_asm(tmp, (u64 __user *)src,
17811+ __get_user_asm(tmp, (const u64 __user *)src,
17812 ret, "q", "", "=r", 8);
17813 if (likely(!ret))
17814 __put_user_asm(tmp, (u64 __user *)dst,
17815@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
17816 return ret;
17817 }
17818 default:
17819- return copy_user_generic((__force void *)dst,
17820- (__force void *)src, size);
17821+ return copy_user_generic((__force_kernel void *)____m(dst),
17822+ (__force_kernel const void *)____m(src), size);
17823 }
17824 }
17825
17826 static __must_check __always_inline int
17827-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
17828+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
17829 {
17830- return copy_user_generic(dst, (__force const void *)src, size);
17831+ if (size > INT_MAX)
17832+ return size;
17833+
17834+#ifdef CONFIG_PAX_MEMORY_UDEREF
17835+ if (!__access_ok(VERIFY_READ, src, size))
17836+ return size;
17837+#endif
17838+
17839+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
17840 }
17841
17842-static __must_check __always_inline int
17843-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
17844+static __must_check __always_inline unsigned long
17845+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
17846 {
17847- return copy_user_generic((__force void *)dst, src, size);
17848+ if (size > INT_MAX)
17849+ return size;
17850+
17851+#ifdef CONFIG_PAX_MEMORY_UDEREF
17852+ if (!__access_ok(VERIFY_WRITE, dst, size))
17853+ return size;
17854+#endif
17855+
17856+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
17857 }
17858
17859-extern long __copy_user_nocache(void *dst, const void __user *src,
17860- unsigned size, int zerorest);
17861+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
17862+ unsigned long size, int zerorest) __size_overflow(3);
17863
17864-static inline int
17865-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
17866+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
17867 {
17868 might_sleep();
17869+
17870+ if (size > INT_MAX)
17871+ return size;
17872+
17873+#ifdef CONFIG_PAX_MEMORY_UDEREF
17874+ if (!__access_ok(VERIFY_READ, src, size))
17875+ return size;
17876+#endif
17877+
17878 return __copy_user_nocache(dst, src, size, 1);
17879 }
17880
17881-static inline int
17882-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
17883- unsigned size)
17884+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
17885+ unsigned long size)
17886 {
17887+ if (size > INT_MAX)
17888+ return size;
17889+
17890+#ifdef CONFIG_PAX_MEMORY_UDEREF
17891+ if (!__access_ok(VERIFY_READ, src, size))
17892+ return size;
17893+#endif
17894+
17895 return __copy_user_nocache(dst, src, size, 0);
17896 }
17897
17898-unsigned long
17899-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
17900+extern unsigned long
17901+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
17902
17903 #endif /* _ASM_X86_UACCESS_64_H */
17904diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
17905index 5b238981..77fdd78 100644
17906--- a/arch/x86/include/asm/word-at-a-time.h
17907+++ b/arch/x86/include/asm/word-at-a-time.h
17908@@ -11,7 +11,7 @@
17909 * and shift, for example.
17910 */
17911 struct word_at_a_time {
17912- const unsigned long one_bits, high_bits;
17913+ unsigned long one_bits, high_bits;
17914 };
17915
17916 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
17917diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
17918index d8d9922..bf6cecb 100644
17919--- a/arch/x86/include/asm/x86_init.h
17920+++ b/arch/x86/include/asm/x86_init.h
17921@@ -129,7 +129,7 @@ struct x86_init_ops {
17922 struct x86_init_timers timers;
17923 struct x86_init_iommu iommu;
17924 struct x86_init_pci pci;
17925-};
17926+} __no_const;
17927
17928 /**
17929 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
17930@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
17931 void (*setup_percpu_clockev)(void);
17932 void (*early_percpu_clock_init)(void);
17933 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
17934-};
17935+} __no_const;
17936
17937 /**
17938 * struct x86_platform_ops - platform specific runtime functions
17939@@ -166,7 +166,7 @@ struct x86_platform_ops {
17940 void (*save_sched_clock_state)(void);
17941 void (*restore_sched_clock_state)(void);
17942 void (*apic_post_init)(void);
17943-};
17944+} __no_const;
17945
17946 struct pci_dev;
17947 struct msi_msg;
17948@@ -180,7 +180,7 @@ struct x86_msi_ops {
17949 void (*teardown_msi_irqs)(struct pci_dev *dev);
17950 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
17951 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
17952-};
17953+} __no_const;
17954
17955 struct IO_APIC_route_entry;
17956 struct io_apic_irq_attr;
17957@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
17958 unsigned int destination, int vector,
17959 struct io_apic_irq_attr *attr);
17960 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
17961-};
17962+} __no_const;
17963
17964 extern struct x86_init_ops x86_init;
17965 extern struct x86_cpuinit_ops x86_cpuinit;
17966diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
17967index 0415cda..3b22adc 100644
17968--- a/arch/x86/include/asm/xsave.h
17969+++ b/arch/x86/include/asm/xsave.h
17970@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
17971 if (unlikely(err))
17972 return -EFAULT;
17973
17974+ pax_open_userland();
17975 __asm__ __volatile__(ASM_STAC "\n"
17976- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
17977+ "1:"
17978+ __copyuser_seg
17979+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
17980 "2: " ASM_CLAC "\n"
17981 ".section .fixup,\"ax\"\n"
17982 "3: movl $-1,%[err]\n"
17983@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
17984 : [err] "=r" (err)
17985 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
17986 : "memory");
17987+ pax_close_userland();
17988 return err;
17989 }
17990
17991 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
17992 {
17993 int err;
17994- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
17995+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
17996 u32 lmask = mask;
17997 u32 hmask = mask >> 32;
17998
17999+ pax_open_userland();
18000 __asm__ __volatile__(ASM_STAC "\n"
18001- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18002+ "1:"
18003+ __copyuser_seg
18004+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18005 "2: " ASM_CLAC "\n"
18006 ".section .fixup,\"ax\"\n"
18007 "3: movl $-1,%[err]\n"
18008@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18009 : [err] "=r" (err)
18010 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18011 : "memory"); /* memory required? */
18012+ pax_close_userland();
18013 return err;
18014 }
18015
18016diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18017index bbae024..e1528f9 100644
18018--- a/arch/x86/include/uapi/asm/e820.h
18019+++ b/arch/x86/include/uapi/asm/e820.h
18020@@ -63,7 +63,7 @@ struct e820map {
18021 #define ISA_START_ADDRESS 0xa0000
18022 #define ISA_END_ADDRESS 0x100000
18023
18024-#define BIOS_BEGIN 0x000a0000
18025+#define BIOS_BEGIN 0x000c0000
18026 #define BIOS_END 0x00100000
18027
18028 #define BIOS_ROM_BASE 0xffe00000
18029diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18030index 7bd3bd3..5dac791 100644
18031--- a/arch/x86/kernel/Makefile
18032+++ b/arch/x86/kernel/Makefile
18033@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18034 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18035 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18036 obj-y += probe_roms.o
18037-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18038+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18039 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18040 obj-y += syscall_$(BITS).o
18041 obj-$(CONFIG_X86_64) += vsyscall_64.o
18042diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18043index 230c8ea..f915130 100644
18044--- a/arch/x86/kernel/acpi/boot.c
18045+++ b/arch/x86/kernel/acpi/boot.c
18046@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18047 * If your system is blacklisted here, but you find that acpi=force
18048 * works for you, please contact linux-acpi@vger.kernel.org
18049 */
18050-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18051+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18052 /*
18053 * Boxes that need ACPI disabled
18054 */
18055@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18056 };
18057
18058 /* second table for DMI checks that should run after early-quirks */
18059-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18060+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18061 /*
18062 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18063 * which includes some code which overrides all temperature
18064diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18065index ec94e11..7fbbec0 100644
18066--- a/arch/x86/kernel/acpi/sleep.c
18067+++ b/arch/x86/kernel/acpi/sleep.c
18068@@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
18069 #else /* CONFIG_64BIT */
18070 #ifdef CONFIG_SMP
18071 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18072+
18073+ pax_open_kernel();
18074 early_gdt_descr.address =
18075 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18076+ pax_close_kernel();
18077+
18078 initial_gs = per_cpu_offset(smp_processor_id());
18079 #endif
18080 initial_code = (unsigned long)wakeup_long64;
18081diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18082index d1daa66..59fecba 100644
18083--- a/arch/x86/kernel/acpi/wakeup_32.S
18084+++ b/arch/x86/kernel/acpi/wakeup_32.S
18085@@ -29,13 +29,11 @@ wakeup_pmode_return:
18086 # and restore the stack ... but you need gdt for this to work
18087 movl saved_context_esp, %esp
18088
18089- movl %cs:saved_magic, %eax
18090- cmpl $0x12345678, %eax
18091+ cmpl $0x12345678, saved_magic
18092 jne bogus_magic
18093
18094 # jump to place where we left off
18095- movl saved_eip, %eax
18096- jmp *%eax
18097+ jmp *(saved_eip)
18098
18099 bogus_magic:
18100 jmp bogus_magic
18101diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18102index c15cf9a..0e63558 100644
18103--- a/arch/x86/kernel/alternative.c
18104+++ b/arch/x86/kernel/alternative.c
18105@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18106 */
18107 for (a = start; a < end; a++) {
18108 instr = (u8 *)&a->instr_offset + a->instr_offset;
18109+
18110+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18111+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18112+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18113+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18114+#endif
18115+
18116 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18117 BUG_ON(a->replacementlen > a->instrlen);
18118 BUG_ON(a->instrlen > sizeof(insnbuf));
18119@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18120 for (poff = start; poff < end; poff++) {
18121 u8 *ptr = (u8 *)poff + *poff;
18122
18123+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18124+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18125+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18126+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18127+#endif
18128+
18129 if (!*poff || ptr < text || ptr >= text_end)
18130 continue;
18131 /* turn DS segment override prefix into lock prefix */
18132- if (*ptr == 0x3e)
18133+ if (*ktla_ktva(ptr) == 0x3e)
18134 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18135 }
18136 mutex_unlock(&text_mutex);
18137@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18138 for (poff = start; poff < end; poff++) {
18139 u8 *ptr = (u8 *)poff + *poff;
18140
18141+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18142+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18143+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18144+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18145+#endif
18146+
18147 if (!*poff || ptr < text || ptr >= text_end)
18148 continue;
18149 /* turn lock prefix into DS segment override prefix */
18150- if (*ptr == 0xf0)
18151+ if (*ktla_ktva(ptr) == 0xf0)
18152 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18153 }
18154 mutex_unlock(&text_mutex);
18155@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18156
18157 BUG_ON(p->len > MAX_PATCH_LEN);
18158 /* prep the buffer with the original instructions */
18159- memcpy(insnbuf, p->instr, p->len);
18160+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
18161 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
18162 (unsigned long)p->instr, p->len);
18163
18164@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
18165 if (!uniproc_patched || num_possible_cpus() == 1)
18166 free_init_pages("SMP alternatives",
18167 (unsigned long)__smp_locks,
18168- (unsigned long)__smp_locks_end);
18169+ PAGE_ALIGN((unsigned long)__smp_locks_end));
18170 #endif
18171
18172 apply_paravirt(__parainstructions, __parainstructions_end);
18173@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
18174 * instructions. And on the local CPU you need to be protected again NMI or MCE
18175 * handlers seeing an inconsistent instruction while you patch.
18176 */
18177-void *__init_or_module text_poke_early(void *addr, const void *opcode,
18178+void *__kprobes text_poke_early(void *addr, const void *opcode,
18179 size_t len)
18180 {
18181 unsigned long flags;
18182 local_irq_save(flags);
18183- memcpy(addr, opcode, len);
18184+
18185+ pax_open_kernel();
18186+ memcpy(ktla_ktva(addr), opcode, len);
18187 sync_core();
18188+ pax_close_kernel();
18189+
18190 local_irq_restore(flags);
18191 /* Could also do a CLFLUSH here to speed up CPU recovery; but
18192 that causes hangs on some VIA CPUs. */
18193@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
18194 */
18195 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
18196 {
18197- unsigned long flags;
18198- char *vaddr;
18199+ unsigned char *vaddr = ktla_ktva(addr);
18200 struct page *pages[2];
18201- int i;
18202+ size_t i;
18203
18204 if (!core_kernel_text((unsigned long)addr)) {
18205- pages[0] = vmalloc_to_page(addr);
18206- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
18207+ pages[0] = vmalloc_to_page(vaddr);
18208+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
18209 } else {
18210- pages[0] = virt_to_page(addr);
18211+ pages[0] = virt_to_page(vaddr);
18212 WARN_ON(!PageReserved(pages[0]));
18213- pages[1] = virt_to_page(addr + PAGE_SIZE);
18214+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
18215 }
18216 BUG_ON(!pages[0]);
18217- local_irq_save(flags);
18218- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
18219- if (pages[1])
18220- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
18221- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
18222- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
18223- clear_fixmap(FIX_TEXT_POKE0);
18224- if (pages[1])
18225- clear_fixmap(FIX_TEXT_POKE1);
18226- local_flush_tlb();
18227- sync_core();
18228- /* Could also do a CLFLUSH here to speed up CPU recovery; but
18229- that causes hangs on some VIA CPUs. */
18230+ text_poke_early(addr, opcode, len);
18231 for (i = 0; i < len; i++)
18232- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
18233- local_irq_restore(flags);
18234+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
18235 return addr;
18236 }
18237
18238diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
18239index 904611b..004dde6 100644
18240--- a/arch/x86/kernel/apic/apic.c
18241+++ b/arch/x86/kernel/apic/apic.c
18242@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
18243 /*
18244 * Debug level, exported for io_apic.c
18245 */
18246-unsigned int apic_verbosity;
18247+int apic_verbosity;
18248
18249 int pic_mode;
18250
18251@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
18252 apic_write(APIC_ESR, 0);
18253 v1 = apic_read(APIC_ESR);
18254 ack_APIC_irq();
18255- atomic_inc(&irq_err_count);
18256+ atomic_inc_unchecked(&irq_err_count);
18257
18258 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
18259 smp_processor_id(), v0 , v1);
18260diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
18261index 00c77cf..2dc6a2d 100644
18262--- a/arch/x86/kernel/apic/apic_flat_64.c
18263+++ b/arch/x86/kernel/apic/apic_flat_64.c
18264@@ -157,7 +157,7 @@ static int flat_probe(void)
18265 return 1;
18266 }
18267
18268-static struct apic apic_flat = {
18269+static struct apic apic_flat __read_only = {
18270 .name = "flat",
18271 .probe = flat_probe,
18272 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
18273@@ -271,7 +271,7 @@ static int physflat_probe(void)
18274 return 0;
18275 }
18276
18277-static struct apic apic_physflat = {
18278+static struct apic apic_physflat __read_only = {
18279
18280 .name = "physical flat",
18281 .probe = physflat_probe,
18282diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
18283index e145f28..2752888 100644
18284--- a/arch/x86/kernel/apic/apic_noop.c
18285+++ b/arch/x86/kernel/apic/apic_noop.c
18286@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
18287 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
18288 }
18289
18290-struct apic apic_noop = {
18291+struct apic apic_noop __read_only = {
18292 .name = "noop",
18293 .probe = noop_probe,
18294 .acpi_madt_oem_check = NULL,
18295diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
18296index d50e364..543bee3 100644
18297--- a/arch/x86/kernel/apic/bigsmp_32.c
18298+++ b/arch/x86/kernel/apic/bigsmp_32.c
18299@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
18300 return dmi_bigsmp;
18301 }
18302
18303-static struct apic apic_bigsmp = {
18304+static struct apic apic_bigsmp __read_only = {
18305
18306 .name = "bigsmp",
18307 .probe = probe_bigsmp,
18308diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
18309index 0874799..a7a7892 100644
18310--- a/arch/x86/kernel/apic/es7000_32.c
18311+++ b/arch/x86/kernel/apic/es7000_32.c
18312@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
18313 return ret && es7000_apic_is_cluster();
18314 }
18315
18316-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
18317-static struct apic __refdata apic_es7000_cluster = {
18318+static struct apic apic_es7000_cluster __read_only = {
18319
18320 .name = "es7000",
18321 .probe = probe_es7000,
18322@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
18323 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
18324 };
18325
18326-static struct apic __refdata apic_es7000 = {
18327+static struct apic apic_es7000 __read_only = {
18328
18329 .name = "es7000",
18330 .probe = probe_es7000,
18331diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
18332index 9ed796c..e930fe4 100644
18333--- a/arch/x86/kernel/apic/io_apic.c
18334+++ b/arch/x86/kernel/apic/io_apic.c
18335@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
18336 }
18337 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
18338
18339-void lock_vector_lock(void)
18340+void lock_vector_lock(void) __acquires(vector_lock)
18341 {
18342 /* Used to the online set of cpus does not change
18343 * during assign_irq_vector.
18344@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
18345 raw_spin_lock(&vector_lock);
18346 }
18347
18348-void unlock_vector_lock(void)
18349+void unlock_vector_lock(void) __releases(vector_lock)
18350 {
18351 raw_spin_unlock(&vector_lock);
18352 }
18353@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
18354 ack_APIC_irq();
18355 }
18356
18357-atomic_t irq_mis_count;
18358+atomic_unchecked_t irq_mis_count;
18359
18360 #ifdef CONFIG_GENERIC_PENDING_IRQ
18361 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
18362@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
18363 * at the cpu.
18364 */
18365 if (!(v & (1 << (i & 0x1f)))) {
18366- atomic_inc(&irq_mis_count);
18367+ atomic_inc_unchecked(&irq_mis_count);
18368
18369 eoi_ioapic_irq(irq, cfg);
18370 }
18371diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
18372index d661ee9..791fd33 100644
18373--- a/arch/x86/kernel/apic/numaq_32.c
18374+++ b/arch/x86/kernel/apic/numaq_32.c
18375@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
18376 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
18377 }
18378
18379-/* Use __refdata to keep false positive warning calm. */
18380-static struct apic __refdata apic_numaq = {
18381+static struct apic apic_numaq __read_only = {
18382
18383 .name = "NUMAQ",
18384 .probe = probe_numaq,
18385diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
18386index eb35ef9..f184a21 100644
18387--- a/arch/x86/kernel/apic/probe_32.c
18388+++ b/arch/x86/kernel/apic/probe_32.c
18389@@ -72,7 +72,7 @@ static int probe_default(void)
18390 return 1;
18391 }
18392
18393-static struct apic apic_default = {
18394+static struct apic apic_default __read_only = {
18395
18396 .name = "default",
18397 .probe = probe_default,
18398diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
18399index 77c95c0..434f8a4 100644
18400--- a/arch/x86/kernel/apic/summit_32.c
18401+++ b/arch/x86/kernel/apic/summit_32.c
18402@@ -486,7 +486,7 @@ void setup_summit(void)
18403 }
18404 #endif
18405
18406-static struct apic apic_summit = {
18407+static struct apic apic_summit __read_only = {
18408
18409 .name = "summit",
18410 .probe = probe_summit,
18411diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
18412index c88baa4..757aee1 100644
18413--- a/arch/x86/kernel/apic/x2apic_cluster.c
18414+++ b/arch/x86/kernel/apic/x2apic_cluster.c
18415@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
18416 return notifier_from_errno(err);
18417 }
18418
18419-static struct notifier_block __refdata x2apic_cpu_notifier = {
18420+static struct notifier_block x2apic_cpu_notifier = {
18421 .notifier_call = update_clusterinfo,
18422 };
18423
18424@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
18425 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
18426 }
18427
18428-static struct apic apic_x2apic_cluster = {
18429+static struct apic apic_x2apic_cluster __read_only = {
18430
18431 .name = "cluster x2apic",
18432 .probe = x2apic_cluster_probe,
18433diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
18434index 562a76d..a003c0f 100644
18435--- a/arch/x86/kernel/apic/x2apic_phys.c
18436+++ b/arch/x86/kernel/apic/x2apic_phys.c
18437@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
18438 return apic == &apic_x2apic_phys;
18439 }
18440
18441-static struct apic apic_x2apic_phys = {
18442+static struct apic apic_x2apic_phys __read_only = {
18443
18444 .name = "physical x2apic",
18445 .probe = x2apic_phys_probe,
18446diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
18447index 794f6eb..67e1db2 100644
18448--- a/arch/x86/kernel/apic/x2apic_uv_x.c
18449+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
18450@@ -342,7 +342,7 @@ static int uv_probe(void)
18451 return apic == &apic_x2apic_uv_x;
18452 }
18453
18454-static struct apic __refdata apic_x2apic_uv_x = {
18455+static struct apic apic_x2apic_uv_x __read_only = {
18456
18457 .name = "UV large system",
18458 .probe = uv_probe,
18459diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
18460index 53a4e27..038760a 100644
18461--- a/arch/x86/kernel/apm_32.c
18462+++ b/arch/x86/kernel/apm_32.c
18463@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
18464 * This is for buggy BIOS's that refer to (real mode) segment 0x40
18465 * even though they are called in protected mode.
18466 */
18467-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
18468+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
18469 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
18470
18471 static const char driver_version[] = "1.16ac"; /* no spaces */
18472@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
18473 BUG_ON(cpu != 0);
18474 gdt = get_cpu_gdt_table(cpu);
18475 save_desc_40 = gdt[0x40 / 8];
18476+
18477+ pax_open_kernel();
18478 gdt[0x40 / 8] = bad_bios_desc;
18479+ pax_close_kernel();
18480
18481 apm_irq_save(flags);
18482 APM_DO_SAVE_SEGS;
18483@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
18484 &call->esi);
18485 APM_DO_RESTORE_SEGS;
18486 apm_irq_restore(flags);
18487+
18488+ pax_open_kernel();
18489 gdt[0x40 / 8] = save_desc_40;
18490+ pax_close_kernel();
18491+
18492 put_cpu();
18493
18494 return call->eax & 0xff;
18495@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
18496 BUG_ON(cpu != 0);
18497 gdt = get_cpu_gdt_table(cpu);
18498 save_desc_40 = gdt[0x40 / 8];
18499+
18500+ pax_open_kernel();
18501 gdt[0x40 / 8] = bad_bios_desc;
18502+ pax_close_kernel();
18503
18504 apm_irq_save(flags);
18505 APM_DO_SAVE_SEGS;
18506@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
18507 &call->eax);
18508 APM_DO_RESTORE_SEGS;
18509 apm_irq_restore(flags);
18510+
18511+ pax_open_kernel();
18512 gdt[0x40 / 8] = save_desc_40;
18513+ pax_close_kernel();
18514+
18515 put_cpu();
18516 return error;
18517 }
18518@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
18519 * code to that CPU.
18520 */
18521 gdt = get_cpu_gdt_table(0);
18522+
18523+ pax_open_kernel();
18524 set_desc_base(&gdt[APM_CS >> 3],
18525 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
18526 set_desc_base(&gdt[APM_CS_16 >> 3],
18527 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
18528 set_desc_base(&gdt[APM_DS >> 3],
18529 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
18530+ pax_close_kernel();
18531
18532 proc_create("apm", 0, NULL, &apm_file_ops);
18533
18534diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
18535index 2861082..6d4718e 100644
18536--- a/arch/x86/kernel/asm-offsets.c
18537+++ b/arch/x86/kernel/asm-offsets.c
18538@@ -33,6 +33,8 @@ void common(void) {
18539 OFFSET(TI_status, thread_info, status);
18540 OFFSET(TI_addr_limit, thread_info, addr_limit);
18541 OFFSET(TI_preempt_count, thread_info, preempt_count);
18542+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
18543+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
18544
18545 BLANK();
18546 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
18547@@ -53,8 +55,26 @@ void common(void) {
18548 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
18549 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
18550 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
18551+
18552+#ifdef CONFIG_PAX_KERNEXEC
18553+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
18554 #endif
18555
18556+#ifdef CONFIG_PAX_MEMORY_UDEREF
18557+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
18558+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
18559+#ifdef CONFIG_X86_64
18560+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
18561+#endif
18562+#endif
18563+
18564+#endif
18565+
18566+ BLANK();
18567+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
18568+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
18569+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
18570+
18571 #ifdef CONFIG_XEN
18572 BLANK();
18573 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
18574diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
18575index e7c798b..2b2019b 100644
18576--- a/arch/x86/kernel/asm-offsets_64.c
18577+++ b/arch/x86/kernel/asm-offsets_64.c
18578@@ -77,6 +77,7 @@ int main(void)
18579 BLANK();
18580 #undef ENTRY
18581
18582+ DEFINE(TSS_size, sizeof(struct tss_struct));
18583 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
18584 BLANK();
18585
18586diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
18587index b0684e4..22ccfd7 100644
18588--- a/arch/x86/kernel/cpu/Makefile
18589+++ b/arch/x86/kernel/cpu/Makefile
18590@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
18591 CFLAGS_REMOVE_perf_event.o = -pg
18592 endif
18593
18594-# Make sure load_percpu_segment has no stackprotector
18595-nostackp := $(call cc-option, -fno-stack-protector)
18596-CFLAGS_common.o := $(nostackp)
18597-
18598 obj-y := intel_cacheinfo.o scattered.o topology.o
18599 obj-y += proc.o capflags.o powerflags.o common.o
18600 obj-y += rdrand.o
18601diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
18602index 5013a48..0782c53 100644
18603--- a/arch/x86/kernel/cpu/amd.c
18604+++ b/arch/x86/kernel/cpu/amd.c
18605@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
18606 unsigned int size)
18607 {
18608 /* AMD errata T13 (order #21922) */
18609- if ((c->x86 == 6)) {
18610+ if (c->x86 == 6) {
18611 /* Duron Rev A0 */
18612 if (c->x86_model == 3 && c->x86_mask == 0)
18613 size = 64;
18614diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
18615index 22018f7..2ae0e75 100644
18616--- a/arch/x86/kernel/cpu/common.c
18617+++ b/arch/x86/kernel/cpu/common.c
18618@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
18619
18620 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
18621
18622-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
18623-#ifdef CONFIG_X86_64
18624- /*
18625- * We need valid kernel segments for data and code in long mode too
18626- * IRET will check the segment types kkeil 2000/10/28
18627- * Also sysret mandates a special GDT layout
18628- *
18629- * TLS descriptors are currently at a different place compared to i386.
18630- * Hopefully nobody expects them at a fixed place (Wine?)
18631- */
18632- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
18633- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
18634- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
18635- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
18636- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
18637- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
18638-#else
18639- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
18640- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18641- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
18642- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
18643- /*
18644- * Segments used for calling PnP BIOS have byte granularity.
18645- * They code segments and data segments have fixed 64k limits,
18646- * the transfer segment sizes are set at run time.
18647- */
18648- /* 32-bit code */
18649- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
18650- /* 16-bit code */
18651- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
18652- /* 16-bit data */
18653- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
18654- /* 16-bit data */
18655- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
18656- /* 16-bit data */
18657- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
18658- /*
18659- * The APM segments have byte granularity and their bases
18660- * are set at run time. All have 64k limits.
18661- */
18662- /* 32-bit code */
18663- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
18664- /* 16-bit code */
18665- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
18666- /* data */
18667- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
18668-
18669- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18670- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
18671- GDT_STACK_CANARY_INIT
18672-#endif
18673-} };
18674-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
18675-
18676 static int __init x86_xsave_setup(char *s)
18677 {
18678 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
18679@@ -288,6 +234,53 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
18680 set_in_cr4(X86_CR4_SMAP);
18681 }
18682
18683+#ifdef CONFIG_X86_64
18684+static __init int setup_disable_pcid(char *arg)
18685+{
18686+ setup_clear_cpu_cap(X86_FEATURE_PCID);
18687+
18688+#ifdef CONFIG_PAX_MEMORY_UDEREF
18689+ if (clone_pgd_mask != ~(pgdval_t)0UL)
18690+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
18691+#endif
18692+
18693+ return 1;
18694+}
18695+__setup("nopcid", setup_disable_pcid);
18696+
18697+static void setup_pcid(struct cpuinfo_x86 *c)
18698+{
18699+ if (!cpu_has(c, X86_FEATURE_PCID)) {
18700+
18701+#ifdef CONFIG_PAX_MEMORY_UDEREF
18702+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
18703+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
18704+ printk("PAX: slow and weak UDEREF enabled\n");
18705+ } else
18706+ printk("PAX: UDEREF disabled\n");
18707+#endif
18708+
18709+ return;
18710+ }
18711+
18712+ printk("PAX: PCID detected\n");
18713+ set_in_cr4(X86_CR4_PCIDE);
18714+
18715+#ifdef CONFIG_PAX_MEMORY_UDEREF
18716+ clone_pgd_mask = ~(pgdval_t)0UL;
18717+ if (pax_user_shadow_base)
18718+ printk("PAX: weak UDEREF enabled\n");
18719+ else {
18720+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
18721+ printk("PAX: strong UDEREF enabled\n");
18722+ }
18723+#endif
18724+
18725+ if (cpu_has(c, X86_FEATURE_INVPCID))
18726+ printk("PAX: INVPCID detected\n");
18727+}
18728+#endif
18729+
18730 /*
18731 * Some CPU features depend on higher CPUID levels, which may not always
18732 * be available due to CPUID level capping or broken virtualization
18733@@ -386,7 +379,7 @@ void switch_to_new_gdt(int cpu)
18734 {
18735 struct desc_ptr gdt_descr;
18736
18737- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
18738+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
18739 gdt_descr.size = GDT_SIZE - 1;
18740 load_gdt(&gdt_descr);
18741 /* Reload the per-cpu base */
18742@@ -874,6 +867,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
18743 setup_smep(c);
18744 setup_smap(c);
18745
18746+#ifdef CONFIG_X86_64
18747+ setup_pcid(c);
18748+#endif
18749+
18750 /*
18751 * The vendor-specific functions might have changed features.
18752 * Now we do "generic changes."
18753@@ -882,6 +879,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
18754 /* Filter out anything that depends on CPUID levels we don't have */
18755 filter_cpuid_features(c, true);
18756
18757+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18758+ setup_clear_cpu_cap(X86_FEATURE_SEP);
18759+#endif
18760+
18761 /* If the model name is still unset, do table lookup. */
18762 if (!c->x86_model_id[0]) {
18763 const char *p;
18764@@ -1069,10 +1070,12 @@ static __init int setup_disablecpuid(char *arg)
18765 }
18766 __setup("clearcpuid=", setup_disablecpuid);
18767
18768+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
18769+EXPORT_PER_CPU_SYMBOL(current_tinfo);
18770+
18771 #ifdef CONFIG_X86_64
18772 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
18773-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
18774- (unsigned long) nmi_idt_table };
18775+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
18776
18777 DEFINE_PER_CPU_FIRST(union irq_stack_union,
18778 irq_stack_union) __aligned(PAGE_SIZE);
18779@@ -1086,7 +1089,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
18780 EXPORT_PER_CPU_SYMBOL(current_task);
18781
18782 DEFINE_PER_CPU(unsigned long, kernel_stack) =
18783- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
18784+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
18785 EXPORT_PER_CPU_SYMBOL(kernel_stack);
18786
18787 DEFINE_PER_CPU(char *, irq_stack_ptr) =
18788@@ -1231,7 +1234,7 @@ void __cpuinit cpu_init(void)
18789 load_ucode_ap();
18790
18791 cpu = stack_smp_processor_id();
18792- t = &per_cpu(init_tss, cpu);
18793+ t = init_tss + cpu;
18794 oist = &per_cpu(orig_ist, cpu);
18795
18796 #ifdef CONFIG_NUMA
18797@@ -1257,7 +1260,7 @@ void __cpuinit cpu_init(void)
18798 switch_to_new_gdt(cpu);
18799 loadsegment(fs, 0);
18800
18801- load_idt((const struct desc_ptr *)&idt_descr);
18802+ load_idt(&idt_descr);
18803
18804 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
18805 syscall_init();
18806@@ -1266,7 +1269,6 @@ void __cpuinit cpu_init(void)
18807 wrmsrl(MSR_KERNEL_GS_BASE, 0);
18808 barrier();
18809
18810- x86_configure_nx();
18811 enable_x2apic();
18812
18813 /*
18814@@ -1318,7 +1320,7 @@ void __cpuinit cpu_init(void)
18815 {
18816 int cpu = smp_processor_id();
18817 struct task_struct *curr = current;
18818- struct tss_struct *t = &per_cpu(init_tss, cpu);
18819+ struct tss_struct *t = init_tss + cpu;
18820 struct thread_struct *thread = &curr->thread;
18821
18822 show_ucode_info_early();
18823diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
18824index 7c6f7d5..8cac382 100644
18825--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
18826+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
18827@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
18828 };
18829
18830 #ifdef CONFIG_AMD_NB
18831+static struct attribute *default_attrs_amd_nb[] = {
18832+ &type.attr,
18833+ &level.attr,
18834+ &coherency_line_size.attr,
18835+ &physical_line_partition.attr,
18836+ &ways_of_associativity.attr,
18837+ &number_of_sets.attr,
18838+ &size.attr,
18839+ &shared_cpu_map.attr,
18840+ &shared_cpu_list.attr,
18841+ NULL,
18842+ NULL,
18843+ NULL,
18844+ NULL
18845+};
18846+
18847 static struct attribute ** __cpuinit amd_l3_attrs(void)
18848 {
18849 static struct attribute **attrs;
18850@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
18851
18852 n = ARRAY_SIZE(default_attrs);
18853
18854- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
18855- n += 2;
18856-
18857- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
18858- n += 1;
18859-
18860- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
18861- if (attrs == NULL)
18862- return attrs = default_attrs;
18863-
18864- for (n = 0; default_attrs[n]; n++)
18865- attrs[n] = default_attrs[n];
18866+ attrs = default_attrs_amd_nb;
18867
18868 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
18869 attrs[n++] = &cache_disable_0.attr;
18870@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
18871 .default_attrs = default_attrs,
18872 };
18873
18874+#ifdef CONFIG_AMD_NB
18875+static struct kobj_type ktype_cache_amd_nb = {
18876+ .sysfs_ops = &sysfs_ops,
18877+ .default_attrs = default_attrs_amd_nb,
18878+};
18879+#endif
18880+
18881 static struct kobj_type ktype_percpu_entry = {
18882 .sysfs_ops = &sysfs_ops,
18883 };
18884@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
18885 return retval;
18886 }
18887
18888+#ifdef CONFIG_AMD_NB
18889+ amd_l3_attrs();
18890+#endif
18891+
18892 for (i = 0; i < num_cache_leaves; i++) {
18893+ struct kobj_type *ktype;
18894+
18895 this_object = INDEX_KOBJECT_PTR(cpu, i);
18896 this_object->cpu = cpu;
18897 this_object->index = i;
18898
18899 this_leaf = CPUID4_INFO_IDX(cpu, i);
18900
18901- ktype_cache.default_attrs = default_attrs;
18902+ ktype = &ktype_cache;
18903 #ifdef CONFIG_AMD_NB
18904 if (this_leaf->base.nb)
18905- ktype_cache.default_attrs = amd_l3_attrs();
18906+ ktype = &ktype_cache_amd_nb;
18907 #endif
18908 retval = kobject_init_and_add(&(this_object->kobj),
18909- &ktype_cache,
18910+ ktype,
18911 per_cpu(ici_cache_kobject, cpu),
18912 "index%1lu", i);
18913 if (unlikely(retval)) {
18914@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
18915 return NOTIFY_OK;
18916 }
18917
18918-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
18919+static struct notifier_block cacheinfo_cpu_notifier = {
18920 .notifier_call = cacheinfo_cpu_callback,
18921 };
18922
18923diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
18924index 9239504..b2471ce 100644
18925--- a/arch/x86/kernel/cpu/mcheck/mce.c
18926+++ b/arch/x86/kernel/cpu/mcheck/mce.c
18927@@ -45,6 +45,7 @@
18928 #include <asm/processor.h>
18929 #include <asm/mce.h>
18930 #include <asm/msr.h>
18931+#include <asm/local.h>
18932
18933 #include "mce-internal.h"
18934
18935@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
18936 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
18937 m->cs, m->ip);
18938
18939- if (m->cs == __KERNEL_CS)
18940+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
18941 print_symbol("{%s}", m->ip);
18942 pr_cont("\n");
18943 }
18944@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
18945
18946 #define PANIC_TIMEOUT 5 /* 5 seconds */
18947
18948-static atomic_t mce_paniced;
18949+static atomic_unchecked_t mce_paniced;
18950
18951 static int fake_panic;
18952-static atomic_t mce_fake_paniced;
18953+static atomic_unchecked_t mce_fake_paniced;
18954
18955 /* Panic in progress. Enable interrupts and wait for final IPI */
18956 static void wait_for_panic(void)
18957@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
18958 /*
18959 * Make sure only one CPU runs in machine check panic
18960 */
18961- if (atomic_inc_return(&mce_paniced) > 1)
18962+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
18963 wait_for_panic();
18964 barrier();
18965
18966@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
18967 console_verbose();
18968 } else {
18969 /* Don't log too much for fake panic */
18970- if (atomic_inc_return(&mce_fake_paniced) > 1)
18971+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
18972 return;
18973 }
18974 /* First print corrected ones that are still unlogged */
18975@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
18976 if (!fake_panic) {
18977 if (panic_timeout == 0)
18978 panic_timeout = mca_cfg.panic_timeout;
18979- panic(msg);
18980+ panic("%s", msg);
18981 } else
18982 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
18983 }
18984@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
18985 * might have been modified by someone else.
18986 */
18987 rmb();
18988- if (atomic_read(&mce_paniced))
18989+ if (atomic_read_unchecked(&mce_paniced))
18990 wait_for_panic();
18991 if (!mca_cfg.monarch_timeout)
18992 goto out;
18993@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
18994 }
18995
18996 /* Call the installed machine check handler for this CPU setup. */
18997-void (*machine_check_vector)(struct pt_regs *, long error_code) =
18998+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
18999 unexpected_machine_check;
19000
19001 /*
19002@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
19003 return;
19004 }
19005
19006+ pax_open_kernel();
19007 machine_check_vector = do_machine_check;
19008+ pax_close_kernel();
19009
19010 __mcheck_cpu_init_generic();
19011 __mcheck_cpu_init_vendor(c);
19012@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
19013 */
19014
19015 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19016-static int mce_chrdev_open_count; /* #times opened */
19017+static local_t mce_chrdev_open_count; /* #times opened */
19018 static int mce_chrdev_open_exclu; /* already open exclusive? */
19019
19020 static int mce_chrdev_open(struct inode *inode, struct file *file)
19021@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19022 spin_lock(&mce_chrdev_state_lock);
19023
19024 if (mce_chrdev_open_exclu ||
19025- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19026+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19027 spin_unlock(&mce_chrdev_state_lock);
19028
19029 return -EBUSY;
19030@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19031
19032 if (file->f_flags & O_EXCL)
19033 mce_chrdev_open_exclu = 1;
19034- mce_chrdev_open_count++;
19035+ local_inc(&mce_chrdev_open_count);
19036
19037 spin_unlock(&mce_chrdev_state_lock);
19038
19039@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19040 {
19041 spin_lock(&mce_chrdev_state_lock);
19042
19043- mce_chrdev_open_count--;
19044+ local_dec(&mce_chrdev_open_count);
19045 mce_chrdev_open_exclu = 0;
19046
19047 spin_unlock(&mce_chrdev_state_lock);
19048@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
19049 return NOTIFY_OK;
19050 }
19051
19052-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
19053+static struct notifier_block mce_cpu_notifier = {
19054 .notifier_call = mce_cpu_callback,
19055 };
19056
19057@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
19058
19059 for (i = 0; i < mca_cfg.banks; i++) {
19060 struct mce_bank *b = &mce_banks[i];
19061- struct device_attribute *a = &b->attr;
19062+ device_attribute_no_const *a = &b->attr;
19063
19064 sysfs_attr_init(&a->attr);
19065 a->attr.name = b->attrname;
19066@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
19067 static void mce_reset(void)
19068 {
19069 cpu_missing = 0;
19070- atomic_set(&mce_fake_paniced, 0);
19071+ atomic_set_unchecked(&mce_fake_paniced, 0);
19072 atomic_set(&mce_executing, 0);
19073 atomic_set(&mce_callin, 0);
19074 atomic_set(&global_nwo, 0);
19075diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19076index 1c044b1..37a2a43 100644
19077--- a/arch/x86/kernel/cpu/mcheck/p5.c
19078+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19079@@ -11,6 +11,7 @@
19080 #include <asm/processor.h>
19081 #include <asm/mce.h>
19082 #include <asm/msr.h>
19083+#include <asm/pgtable.h>
19084
19085 /* By default disabled */
19086 int mce_p5_enabled __read_mostly;
19087@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19088 if (!cpu_has(c, X86_FEATURE_MCE))
19089 return;
19090
19091+ pax_open_kernel();
19092 machine_check_vector = pentium_machine_check;
19093+ pax_close_kernel();
19094 /* Make sure the vector pointer is visible before we enable MCEs: */
19095 wmb();
19096
19097diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
19098index 47a1870..8c019a7 100644
19099--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
19100+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
19101@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
19102 return notifier_from_errno(err);
19103 }
19104
19105-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
19106+static struct notifier_block thermal_throttle_cpu_notifier =
19107 {
19108 .notifier_call = thermal_throttle_cpu_callback,
19109 };
19110diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19111index e9a701a..35317d6 100644
19112--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19113+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19114@@ -10,6 +10,7 @@
19115 #include <asm/processor.h>
19116 #include <asm/mce.h>
19117 #include <asm/msr.h>
19118+#include <asm/pgtable.h>
19119
19120 /* Machine check handler for WinChip C6: */
19121 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19122@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19123 {
19124 u32 lo, hi;
19125
19126+ pax_open_kernel();
19127 machine_check_vector = winchip_machine_check;
19128+ pax_close_kernel();
19129 /* Make sure the vector pointer is visible before we enable MCEs: */
19130 wmb();
19131
19132diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19133index ca22b73..9987afe 100644
19134--- a/arch/x86/kernel/cpu/mtrr/main.c
19135+++ b/arch/x86/kernel/cpu/mtrr/main.c
19136@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19137 u64 size_or_mask, size_and_mask;
19138 static bool mtrr_aps_delayed_init;
19139
19140-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19141+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19142
19143 const struct mtrr_ops *mtrr_if;
19144
19145diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19146index df5e41f..816c719 100644
19147--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19148+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19149@@ -25,7 +25,7 @@ struct mtrr_ops {
19150 int (*validate_add_page)(unsigned long base, unsigned long size,
19151 unsigned int type);
19152 int (*have_wrcomb)(void);
19153-};
19154+} __do_const;
19155
19156 extern int generic_get_free_region(unsigned long base, unsigned long size,
19157 int replace_reg);
19158diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19159index 1025f3c..824f677 100644
19160--- a/arch/x86/kernel/cpu/perf_event.c
19161+++ b/arch/x86/kernel/cpu/perf_event.c
19162@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
19163 pr_info("no hardware sampling interrupt available.\n");
19164 }
19165
19166-static struct attribute_group x86_pmu_format_group = {
19167+static attribute_group_no_const x86_pmu_format_group = {
19168 .name = "format",
19169 .attrs = NULL,
19170 };
19171@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
19172 NULL,
19173 };
19174
19175-static struct attribute_group x86_pmu_events_group = {
19176+static attribute_group_no_const x86_pmu_events_group = {
19177 .name = "events",
19178 .attrs = events_attr,
19179 };
19180@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
19181 if (idx > GDT_ENTRIES)
19182 return 0;
19183
19184- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19185+ desc = get_cpu_gdt_table(smp_processor_id());
19186 }
19187
19188 return get_desc_base(desc + idx);
19189@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19190 break;
19191
19192 perf_callchain_store(entry, frame.return_address);
19193- fp = frame.next_frame;
19194+ fp = (const void __force_user *)frame.next_frame;
19195 }
19196 }
19197
19198diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
19199index a9e2207..d70c83a 100644
19200--- a/arch/x86/kernel/cpu/perf_event_intel.c
19201+++ b/arch/x86/kernel/cpu/perf_event_intel.c
19202@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
19203 * v2 and above have a perf capabilities MSR
19204 */
19205 if (version > 1) {
19206- u64 capabilities;
19207+ u64 capabilities = x86_pmu.intel_cap.capabilities;
19208
19209- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
19210- x86_pmu.intel_cap.capabilities = capabilities;
19211+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
19212+ x86_pmu.intel_cap.capabilities = capabilities;
19213 }
19214
19215 intel_ds_init();
19216diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19217index 52441a2..f94fae8 100644
19218--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19219+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19220@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
19221 static int __init uncore_type_init(struct intel_uncore_type *type)
19222 {
19223 struct intel_uncore_pmu *pmus;
19224- struct attribute_group *attr_group;
19225+ attribute_group_no_const *attr_group;
19226 struct attribute **attrs;
19227 int i, j;
19228
19229@@ -3518,7 +3518,7 @@ static int
19230 return NOTIFY_OK;
19231 }
19232
19233-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
19234+static struct notifier_block uncore_cpu_nb = {
19235 .notifier_call = uncore_cpu_notifier,
19236 /*
19237 * to migrate uncore events, our notifier should be executed
19238diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19239index f952891..4722ad4 100644
19240--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19241+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19242@@ -488,7 +488,7 @@ struct intel_uncore_box {
19243 struct uncore_event_desc {
19244 struct kobj_attribute attr;
19245 const char *config;
19246-};
19247+} __do_const;
19248
19249 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
19250 { \
19251diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
19252index 1e4dbcf..b9a34c2 100644
19253--- a/arch/x86/kernel/cpuid.c
19254+++ b/arch/x86/kernel/cpuid.c
19255@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
19256 return notifier_from_errno(err);
19257 }
19258
19259-static struct notifier_block __refdata cpuid_class_cpu_notifier =
19260+static struct notifier_block cpuid_class_cpu_notifier =
19261 {
19262 .notifier_call = cpuid_class_cpu_callback,
19263 };
19264diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
19265index 74467fe..18793d5 100644
19266--- a/arch/x86/kernel/crash.c
19267+++ b/arch/x86/kernel/crash.c
19268@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
19269 {
19270 #ifdef CONFIG_X86_32
19271 struct pt_regs fixed_regs;
19272-#endif
19273
19274-#ifdef CONFIG_X86_32
19275- if (!user_mode_vm(regs)) {
19276+ if (!user_mode(regs)) {
19277 crash_fixup_ss_esp(&fixed_regs, regs);
19278 regs = &fixed_regs;
19279 }
19280diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
19281index afa64ad..dce67dd 100644
19282--- a/arch/x86/kernel/crash_dump_64.c
19283+++ b/arch/x86/kernel/crash_dump_64.c
19284@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
19285 return -ENOMEM;
19286
19287 if (userbuf) {
19288- if (copy_to_user(buf, vaddr + offset, csize)) {
19289+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
19290 iounmap(vaddr);
19291 return -EFAULT;
19292 }
19293diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
19294index 155a13f..1672b9b 100644
19295--- a/arch/x86/kernel/doublefault_32.c
19296+++ b/arch/x86/kernel/doublefault_32.c
19297@@ -11,7 +11,7 @@
19298
19299 #define DOUBLEFAULT_STACKSIZE (1024)
19300 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
19301-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
19302+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
19303
19304 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
19305
19306@@ -21,7 +21,7 @@ static void doublefault_fn(void)
19307 unsigned long gdt, tss;
19308
19309 native_store_gdt(&gdt_desc);
19310- gdt = gdt_desc.address;
19311+ gdt = (unsigned long)gdt_desc.address;
19312
19313 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
19314
19315@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
19316 /* 0x2 bit is always set */
19317 .flags = X86_EFLAGS_SF | 0x2,
19318 .sp = STACK_START,
19319- .es = __USER_DS,
19320+ .es = __KERNEL_DS,
19321 .cs = __KERNEL_CS,
19322 .ss = __KERNEL_DS,
19323- .ds = __USER_DS,
19324+ .ds = __KERNEL_DS,
19325 .fs = __KERNEL_PERCPU,
19326
19327 .__cr3 = __pa_nodebug(swapper_pg_dir),
19328diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
19329index deb6421..76bbc12 100644
19330--- a/arch/x86/kernel/dumpstack.c
19331+++ b/arch/x86/kernel/dumpstack.c
19332@@ -2,6 +2,9 @@
19333 * Copyright (C) 1991, 1992 Linus Torvalds
19334 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
19335 */
19336+#ifdef CONFIG_GRKERNSEC_HIDESYM
19337+#define __INCLUDED_BY_HIDESYM 1
19338+#endif
19339 #include <linux/kallsyms.h>
19340 #include <linux/kprobes.h>
19341 #include <linux/uaccess.h>
19342@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
19343 static void
19344 print_ftrace_graph_addr(unsigned long addr, void *data,
19345 const struct stacktrace_ops *ops,
19346- struct thread_info *tinfo, int *graph)
19347+ struct task_struct *task, int *graph)
19348 {
19349- struct task_struct *task;
19350 unsigned long ret_addr;
19351 int index;
19352
19353 if (addr != (unsigned long)return_to_handler)
19354 return;
19355
19356- task = tinfo->task;
19357 index = task->curr_ret_stack;
19358
19359 if (!task->ret_stack || index < *graph)
19360@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
19361 static inline void
19362 print_ftrace_graph_addr(unsigned long addr, void *data,
19363 const struct stacktrace_ops *ops,
19364- struct thread_info *tinfo, int *graph)
19365+ struct task_struct *task, int *graph)
19366 { }
19367 #endif
19368
19369@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
19370 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
19371 */
19372
19373-static inline int valid_stack_ptr(struct thread_info *tinfo,
19374- void *p, unsigned int size, void *end)
19375+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
19376 {
19377- void *t = tinfo;
19378 if (end) {
19379 if (p < end && p >= (end-THREAD_SIZE))
19380 return 1;
19381@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
19382 }
19383
19384 unsigned long
19385-print_context_stack(struct thread_info *tinfo,
19386+print_context_stack(struct task_struct *task, void *stack_start,
19387 unsigned long *stack, unsigned long bp,
19388 const struct stacktrace_ops *ops, void *data,
19389 unsigned long *end, int *graph)
19390 {
19391 struct stack_frame *frame = (struct stack_frame *)bp;
19392
19393- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
19394+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
19395 unsigned long addr;
19396
19397 addr = *stack;
19398@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
19399 } else {
19400 ops->address(data, addr, 0);
19401 }
19402- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
19403+ print_ftrace_graph_addr(addr, data, ops, task, graph);
19404 }
19405 stack++;
19406 }
19407@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
19408 EXPORT_SYMBOL_GPL(print_context_stack);
19409
19410 unsigned long
19411-print_context_stack_bp(struct thread_info *tinfo,
19412+print_context_stack_bp(struct task_struct *task, void *stack_start,
19413 unsigned long *stack, unsigned long bp,
19414 const struct stacktrace_ops *ops, void *data,
19415 unsigned long *end, int *graph)
19416@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
19417 struct stack_frame *frame = (struct stack_frame *)bp;
19418 unsigned long *ret_addr = &frame->return_address;
19419
19420- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
19421+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
19422 unsigned long addr = *ret_addr;
19423
19424 if (!__kernel_text_address(addr))
19425@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
19426 ops->address(data, addr, 1);
19427 frame = frame->next_frame;
19428 ret_addr = &frame->return_address;
19429- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
19430+ print_ftrace_graph_addr(addr, data, ops, task, graph);
19431 }
19432
19433 return (unsigned long)frame;
19434@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
19435 static void print_trace_address(void *data, unsigned long addr, int reliable)
19436 {
19437 touch_nmi_watchdog();
19438- printk(data);
19439+ printk("%s", (char *)data);
19440 printk_address(addr, reliable);
19441 }
19442
19443@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
19444 }
19445 EXPORT_SYMBOL_GPL(oops_begin);
19446
19447+extern void gr_handle_kernel_exploit(void);
19448+
19449 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
19450 {
19451 if (regs && kexec_should_crash(current))
19452@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
19453 panic("Fatal exception in interrupt");
19454 if (panic_on_oops)
19455 panic("Fatal exception");
19456- do_exit(signr);
19457+
19458+ gr_handle_kernel_exploit();
19459+
19460+ do_group_exit(signr);
19461 }
19462
19463 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
19464@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
19465 print_modules();
19466 show_regs(regs);
19467 #ifdef CONFIG_X86_32
19468- if (user_mode_vm(regs)) {
19469+ if (user_mode(regs)) {
19470 sp = regs->sp;
19471 ss = regs->ss & 0xffff;
19472 } else {
19473@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
19474 unsigned long flags = oops_begin();
19475 int sig = SIGSEGV;
19476
19477- if (!user_mode_vm(regs))
19478+ if (!user_mode(regs))
19479 report_bug(regs->ip, regs);
19480
19481 if (__die(str, regs, err))
19482diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
19483index f2a1770..540657f 100644
19484--- a/arch/x86/kernel/dumpstack_32.c
19485+++ b/arch/x86/kernel/dumpstack_32.c
19486@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19487 bp = stack_frame(task, regs);
19488
19489 for (;;) {
19490- struct thread_info *context;
19491+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
19492
19493- context = (struct thread_info *)
19494- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
19495- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
19496+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
19497
19498- stack = (unsigned long *)context->previous_esp;
19499- if (!stack)
19500+ if (stack_start == task_stack_page(task))
19501 break;
19502+ stack = *(unsigned long **)stack_start;
19503 if (ops->stack(data, "IRQ") < 0)
19504 break;
19505 touch_nmi_watchdog();
19506@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
19507 int i;
19508
19509 show_regs_print_info(KERN_EMERG);
19510- __show_regs(regs, !user_mode_vm(regs));
19511+ __show_regs(regs, !user_mode(regs));
19512
19513 /*
19514 * When in-kernel, we also print out the stack and code at the
19515 * time of the fault..
19516 */
19517- if (!user_mode_vm(regs)) {
19518+ if (!user_mode(regs)) {
19519 unsigned int code_prologue = code_bytes * 43 / 64;
19520 unsigned int code_len = code_bytes;
19521 unsigned char c;
19522 u8 *ip;
19523+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
19524
19525 pr_emerg("Stack:\n");
19526 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
19527
19528 pr_emerg("Code:");
19529
19530- ip = (u8 *)regs->ip - code_prologue;
19531+ ip = (u8 *)regs->ip - code_prologue + cs_base;
19532 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
19533 /* try starting at IP */
19534- ip = (u8 *)regs->ip;
19535+ ip = (u8 *)regs->ip + cs_base;
19536 code_len = code_len - code_prologue + 1;
19537 }
19538 for (i = 0; i < code_len; i++, ip++) {
19539@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
19540 pr_cont(" Bad EIP value.");
19541 break;
19542 }
19543- if (ip == (u8 *)regs->ip)
19544+ if (ip == (u8 *)regs->ip + cs_base)
19545 pr_cont(" <%02x>", c);
19546 else
19547 pr_cont(" %02x", c);
19548@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
19549 {
19550 unsigned short ud2;
19551
19552+ ip = ktla_ktva(ip);
19553 if (ip < PAGE_OFFSET)
19554 return 0;
19555 if (probe_kernel_address((unsigned short *)ip, ud2))
19556@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
19557
19558 return ud2 == 0x0b0f;
19559 }
19560+
19561+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19562+void pax_check_alloca(unsigned long size)
19563+{
19564+ unsigned long sp = (unsigned long)&sp, stack_left;
19565+
19566+ /* all kernel stacks are of the same size */
19567+ stack_left = sp & (THREAD_SIZE - 1);
19568+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
19569+}
19570+EXPORT_SYMBOL(pax_check_alloca);
19571+#endif
19572diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
19573index addb207..99635fa 100644
19574--- a/arch/x86/kernel/dumpstack_64.c
19575+++ b/arch/x86/kernel/dumpstack_64.c
19576@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19577 unsigned long *irq_stack_end =
19578 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
19579 unsigned used = 0;
19580- struct thread_info *tinfo;
19581 int graph = 0;
19582 unsigned long dummy;
19583+ void *stack_start;
19584
19585 if (!task)
19586 task = current;
19587@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19588 * current stack address. If the stacks consist of nested
19589 * exceptions
19590 */
19591- tinfo = task_thread_info(task);
19592 for (;;) {
19593 char *id;
19594 unsigned long *estack_end;
19595+
19596 estack_end = in_exception_stack(cpu, (unsigned long)stack,
19597 &used, &id);
19598
19599@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19600 if (ops->stack(data, id) < 0)
19601 break;
19602
19603- bp = ops->walk_stack(tinfo, stack, bp, ops,
19604+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
19605 data, estack_end, &graph);
19606 ops->stack(data, "<EOE>");
19607 /*
19608@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19609 * second-to-last pointer (index -2 to end) in the
19610 * exception stack:
19611 */
19612+ if ((u16)estack_end[-1] != __KERNEL_DS)
19613+ goto out;
19614 stack = (unsigned long *) estack_end[-2];
19615 continue;
19616 }
19617@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19618 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
19619 if (ops->stack(data, "IRQ") < 0)
19620 break;
19621- bp = ops->walk_stack(tinfo, stack, bp,
19622+ bp = ops->walk_stack(task, irq_stack, stack, bp,
19623 ops, data, irq_stack_end, &graph);
19624 /*
19625 * We link to the next stack (which would be
19626@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
19627 /*
19628 * This handles the process stack:
19629 */
19630- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
19631+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
19632+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
19633+out:
19634 put_cpu();
19635 }
19636 EXPORT_SYMBOL(dump_trace);
19637@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
19638
19639 return ud2 == 0x0b0f;
19640 }
19641+
19642+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19643+void pax_check_alloca(unsigned long size)
19644+{
19645+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
19646+ unsigned cpu, used;
19647+ char *id;
19648+
19649+ /* check the process stack first */
19650+ stack_start = (unsigned long)task_stack_page(current);
19651+ stack_end = stack_start + THREAD_SIZE;
19652+ if (likely(stack_start <= sp && sp < stack_end)) {
19653+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
19654+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
19655+ return;
19656+ }
19657+
19658+ cpu = get_cpu();
19659+
19660+ /* check the irq stacks */
19661+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
19662+ stack_start = stack_end - IRQ_STACK_SIZE;
19663+ if (stack_start <= sp && sp < stack_end) {
19664+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
19665+ put_cpu();
19666+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
19667+ return;
19668+ }
19669+
19670+ /* check the exception stacks */
19671+ used = 0;
19672+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
19673+ stack_start = stack_end - EXCEPTION_STKSZ;
19674+ if (stack_end && stack_start <= sp && sp < stack_end) {
19675+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
19676+ put_cpu();
19677+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
19678+ return;
19679+ }
19680+
19681+ put_cpu();
19682+
19683+ /* unknown stack */
19684+ BUG();
19685+}
19686+EXPORT_SYMBOL(pax_check_alloca);
19687+#endif
19688diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
19689index d32abea..74daf4f 100644
19690--- a/arch/x86/kernel/e820.c
19691+++ b/arch/x86/kernel/e820.c
19692@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
19693
19694 static void early_panic(char *msg)
19695 {
19696- early_printk(msg);
19697- panic(msg);
19698+ early_printk("%s", msg);
19699+ panic("%s", msg);
19700 }
19701
19702 static int userdef __initdata;
19703diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
19704index d15f575..d692043 100644
19705--- a/arch/x86/kernel/early_printk.c
19706+++ b/arch/x86/kernel/early_printk.c
19707@@ -7,6 +7,7 @@
19708 #include <linux/pci_regs.h>
19709 #include <linux/pci_ids.h>
19710 #include <linux/errno.h>
19711+#include <linux/sched.h>
19712 #include <asm/io.h>
19713 #include <asm/processor.h>
19714 #include <asm/fcntl.h>
19715diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
19716index 8f3e2de..6b71e39 100644
19717--- a/arch/x86/kernel/entry_32.S
19718+++ b/arch/x86/kernel/entry_32.S
19719@@ -177,13 +177,153 @@
19720 /*CFI_REL_OFFSET gs, PT_GS*/
19721 .endm
19722 .macro SET_KERNEL_GS reg
19723+
19724+#ifdef CONFIG_CC_STACKPROTECTOR
19725 movl $(__KERNEL_STACK_CANARY), \reg
19726+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19727+ movl $(__USER_DS), \reg
19728+#else
19729+ xorl \reg, \reg
19730+#endif
19731+
19732 movl \reg, %gs
19733 .endm
19734
19735 #endif /* CONFIG_X86_32_LAZY_GS */
19736
19737-.macro SAVE_ALL
19738+.macro pax_enter_kernel
19739+#ifdef CONFIG_PAX_KERNEXEC
19740+ call pax_enter_kernel
19741+#endif
19742+.endm
19743+
19744+.macro pax_exit_kernel
19745+#ifdef CONFIG_PAX_KERNEXEC
19746+ call pax_exit_kernel
19747+#endif
19748+.endm
19749+
19750+#ifdef CONFIG_PAX_KERNEXEC
19751+ENTRY(pax_enter_kernel)
19752+#ifdef CONFIG_PARAVIRT
19753+ pushl %eax
19754+ pushl %ecx
19755+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
19756+ mov %eax, %esi
19757+#else
19758+ mov %cr0, %esi
19759+#endif
19760+ bts $16, %esi
19761+ jnc 1f
19762+ mov %cs, %esi
19763+ cmp $__KERNEL_CS, %esi
19764+ jz 3f
19765+ ljmp $__KERNEL_CS, $3f
19766+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
19767+2:
19768+#ifdef CONFIG_PARAVIRT
19769+ mov %esi, %eax
19770+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
19771+#else
19772+ mov %esi, %cr0
19773+#endif
19774+3:
19775+#ifdef CONFIG_PARAVIRT
19776+ popl %ecx
19777+ popl %eax
19778+#endif
19779+ ret
19780+ENDPROC(pax_enter_kernel)
19781+
19782+ENTRY(pax_exit_kernel)
19783+#ifdef CONFIG_PARAVIRT
19784+ pushl %eax
19785+ pushl %ecx
19786+#endif
19787+ mov %cs, %esi
19788+ cmp $__KERNEXEC_KERNEL_CS, %esi
19789+ jnz 2f
19790+#ifdef CONFIG_PARAVIRT
19791+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
19792+ mov %eax, %esi
19793+#else
19794+ mov %cr0, %esi
19795+#endif
19796+ btr $16, %esi
19797+ ljmp $__KERNEL_CS, $1f
19798+1:
19799+#ifdef CONFIG_PARAVIRT
19800+ mov %esi, %eax
19801+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
19802+#else
19803+ mov %esi, %cr0
19804+#endif
19805+2:
19806+#ifdef CONFIG_PARAVIRT
19807+ popl %ecx
19808+ popl %eax
19809+#endif
19810+ ret
19811+ENDPROC(pax_exit_kernel)
19812+#endif
19813+
19814+ .macro pax_erase_kstack
19815+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19816+ call pax_erase_kstack
19817+#endif
19818+ .endm
19819+
19820+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19821+/*
19822+ * ebp: thread_info
19823+ */
19824+ENTRY(pax_erase_kstack)
19825+ pushl %edi
19826+ pushl %ecx
19827+ pushl %eax
19828+
19829+ mov TI_lowest_stack(%ebp), %edi
19830+ mov $-0xBEEF, %eax
19831+ std
19832+
19833+1: mov %edi, %ecx
19834+ and $THREAD_SIZE_asm - 1, %ecx
19835+ shr $2, %ecx
19836+ repne scasl
19837+ jecxz 2f
19838+
19839+ cmp $2*16, %ecx
19840+ jc 2f
19841+
19842+ mov $2*16, %ecx
19843+ repe scasl
19844+ jecxz 2f
19845+ jne 1b
19846+
19847+2: cld
19848+ mov %esp, %ecx
19849+ sub %edi, %ecx
19850+
19851+ cmp $THREAD_SIZE_asm, %ecx
19852+ jb 3f
19853+ ud2
19854+3:
19855+
19856+ shr $2, %ecx
19857+ rep stosl
19858+
19859+ mov TI_task_thread_sp0(%ebp), %edi
19860+ sub $128, %edi
19861+ mov %edi, TI_lowest_stack(%ebp)
19862+
19863+ popl %eax
19864+ popl %ecx
19865+ popl %edi
19866+ ret
19867+ENDPROC(pax_erase_kstack)
19868+#endif
19869+
19870+.macro __SAVE_ALL _DS
19871 cld
19872 PUSH_GS
19873 pushl_cfi %fs
19874@@ -206,7 +346,7 @@
19875 CFI_REL_OFFSET ecx, 0
19876 pushl_cfi %ebx
19877 CFI_REL_OFFSET ebx, 0
19878- movl $(__USER_DS), %edx
19879+ movl $\_DS, %edx
19880 movl %edx, %ds
19881 movl %edx, %es
19882 movl $(__KERNEL_PERCPU), %edx
19883@@ -214,6 +354,15 @@
19884 SET_KERNEL_GS %edx
19885 .endm
19886
19887+.macro SAVE_ALL
19888+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
19889+ __SAVE_ALL __KERNEL_DS
19890+ pax_enter_kernel
19891+#else
19892+ __SAVE_ALL __USER_DS
19893+#endif
19894+.endm
19895+
19896 .macro RESTORE_INT_REGS
19897 popl_cfi %ebx
19898 CFI_RESTORE ebx
19899@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
19900 popfl_cfi
19901 jmp syscall_exit
19902 CFI_ENDPROC
19903-END(ret_from_fork)
19904+ENDPROC(ret_from_fork)
19905
19906 ENTRY(ret_from_kernel_thread)
19907 CFI_STARTPROC
19908@@ -344,7 +493,15 @@ ret_from_intr:
19909 andl $SEGMENT_RPL_MASK, %eax
19910 #endif
19911 cmpl $USER_RPL, %eax
19912+
19913+#ifdef CONFIG_PAX_KERNEXEC
19914+ jae resume_userspace
19915+
19916+ pax_exit_kernel
19917+ jmp resume_kernel
19918+#else
19919 jb resume_kernel # not returning to v8086 or userspace
19920+#endif
19921
19922 ENTRY(resume_userspace)
19923 LOCKDEP_SYS_EXIT
19924@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
19925 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
19926 # int/exception return?
19927 jne work_pending
19928- jmp restore_all
19929-END(ret_from_exception)
19930+ jmp restore_all_pax
19931+ENDPROC(ret_from_exception)
19932
19933 #ifdef CONFIG_PREEMPT
19934 ENTRY(resume_kernel)
19935@@ -372,7 +529,7 @@ need_resched:
19936 jz restore_all
19937 call preempt_schedule_irq
19938 jmp need_resched
19939-END(resume_kernel)
19940+ENDPROC(resume_kernel)
19941 #endif
19942 CFI_ENDPROC
19943 /*
19944@@ -406,30 +563,45 @@ sysenter_past_esp:
19945 /*CFI_REL_OFFSET cs, 0*/
19946 /*
19947 * Push current_thread_info()->sysenter_return to the stack.
19948- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
19949- * pushed above; +8 corresponds to copy_thread's esp0 setting.
19950 */
19951- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
19952+ pushl_cfi $0
19953 CFI_REL_OFFSET eip, 0
19954
19955 pushl_cfi %eax
19956 SAVE_ALL
19957+ GET_THREAD_INFO(%ebp)
19958+ movl TI_sysenter_return(%ebp),%ebp
19959+ movl %ebp,PT_EIP(%esp)
19960 ENABLE_INTERRUPTS(CLBR_NONE)
19961
19962 /*
19963 * Load the potential sixth argument from user stack.
19964 * Careful about security.
19965 */
19966+ movl PT_OLDESP(%esp),%ebp
19967+
19968+#ifdef CONFIG_PAX_MEMORY_UDEREF
19969+ mov PT_OLDSS(%esp),%ds
19970+1: movl %ds:(%ebp),%ebp
19971+ push %ss
19972+ pop %ds
19973+#else
19974 cmpl $__PAGE_OFFSET-3,%ebp
19975 jae syscall_fault
19976 ASM_STAC
19977 1: movl (%ebp),%ebp
19978 ASM_CLAC
19979+#endif
19980+
19981 movl %ebp,PT_EBP(%esp)
19982 _ASM_EXTABLE(1b,syscall_fault)
19983
19984 GET_THREAD_INFO(%ebp)
19985
19986+#ifdef CONFIG_PAX_RANDKSTACK
19987+ pax_erase_kstack
19988+#endif
19989+
19990 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
19991 jnz sysenter_audit
19992 sysenter_do_call:
19993@@ -444,12 +616,24 @@ sysenter_do_call:
19994 testl $_TIF_ALLWORK_MASK, %ecx
19995 jne sysexit_audit
19996 sysenter_exit:
19997+
19998+#ifdef CONFIG_PAX_RANDKSTACK
19999+ pushl_cfi %eax
20000+ movl %esp, %eax
20001+ call pax_randomize_kstack
20002+ popl_cfi %eax
20003+#endif
20004+
20005+ pax_erase_kstack
20006+
20007 /* if something modifies registers it must also disable sysexit */
20008 movl PT_EIP(%esp), %edx
20009 movl PT_OLDESP(%esp), %ecx
20010 xorl %ebp,%ebp
20011 TRACE_IRQS_ON
20012 1: mov PT_FS(%esp), %fs
20013+2: mov PT_DS(%esp), %ds
20014+3: mov PT_ES(%esp), %es
20015 PTGS_TO_GS
20016 ENABLE_INTERRUPTS_SYSEXIT
20017
20018@@ -466,6 +650,9 @@ sysenter_audit:
20019 movl %eax,%edx /* 2nd arg: syscall number */
20020 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20021 call __audit_syscall_entry
20022+
20023+ pax_erase_kstack
20024+
20025 pushl_cfi %ebx
20026 movl PT_EAX(%esp),%eax /* reload syscall number */
20027 jmp sysenter_do_call
20028@@ -491,10 +678,16 @@ sysexit_audit:
20029
20030 CFI_ENDPROC
20031 .pushsection .fixup,"ax"
20032-2: movl $0,PT_FS(%esp)
20033+4: movl $0,PT_FS(%esp)
20034+ jmp 1b
20035+5: movl $0,PT_DS(%esp)
20036+ jmp 1b
20037+6: movl $0,PT_ES(%esp)
20038 jmp 1b
20039 .popsection
20040- _ASM_EXTABLE(1b,2b)
20041+ _ASM_EXTABLE(1b,4b)
20042+ _ASM_EXTABLE(2b,5b)
20043+ _ASM_EXTABLE(3b,6b)
20044 PTGS_TO_GS_EX
20045 ENDPROC(ia32_sysenter_target)
20046
20047@@ -509,6 +702,11 @@ ENTRY(system_call)
20048 pushl_cfi %eax # save orig_eax
20049 SAVE_ALL
20050 GET_THREAD_INFO(%ebp)
20051+
20052+#ifdef CONFIG_PAX_RANDKSTACK
20053+ pax_erase_kstack
20054+#endif
20055+
20056 # system call tracing in operation / emulation
20057 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20058 jnz syscall_trace_entry
20059@@ -527,6 +725,15 @@ syscall_exit:
20060 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20061 jne syscall_exit_work
20062
20063+restore_all_pax:
20064+
20065+#ifdef CONFIG_PAX_RANDKSTACK
20066+ movl %esp, %eax
20067+ call pax_randomize_kstack
20068+#endif
20069+
20070+ pax_erase_kstack
20071+
20072 restore_all:
20073 TRACE_IRQS_IRET
20074 restore_all_notrace:
20075@@ -583,14 +790,34 @@ ldt_ss:
20076 * compensating for the offset by changing to the ESPFIX segment with
20077 * a base address that matches for the difference.
20078 */
20079-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20080+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20081 mov %esp, %edx /* load kernel esp */
20082 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20083 mov %dx, %ax /* eax: new kernel esp */
20084 sub %eax, %edx /* offset (low word is 0) */
20085+#ifdef CONFIG_SMP
20086+ movl PER_CPU_VAR(cpu_number), %ebx
20087+ shll $PAGE_SHIFT_asm, %ebx
20088+ addl $cpu_gdt_table, %ebx
20089+#else
20090+ movl $cpu_gdt_table, %ebx
20091+#endif
20092 shr $16, %edx
20093- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20094- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20095+
20096+#ifdef CONFIG_PAX_KERNEXEC
20097+ mov %cr0, %esi
20098+ btr $16, %esi
20099+ mov %esi, %cr0
20100+#endif
20101+
20102+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20103+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20104+
20105+#ifdef CONFIG_PAX_KERNEXEC
20106+ bts $16, %esi
20107+ mov %esi, %cr0
20108+#endif
20109+
20110 pushl_cfi $__ESPFIX_SS
20111 pushl_cfi %eax /* new kernel esp */
20112 /* Disable interrupts, but do not irqtrace this section: we
20113@@ -619,20 +846,18 @@ work_resched:
20114 movl TI_flags(%ebp), %ecx
20115 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20116 # than syscall tracing?
20117- jz restore_all
20118+ jz restore_all_pax
20119 testb $_TIF_NEED_RESCHED, %cl
20120 jnz work_resched
20121
20122 work_notifysig: # deal with pending signals and
20123 # notify-resume requests
20124+ movl %esp, %eax
20125 #ifdef CONFIG_VM86
20126 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20127- movl %esp, %eax
20128 jne work_notifysig_v86 # returning to kernel-space or
20129 # vm86-space
20130 1:
20131-#else
20132- movl %esp, %eax
20133 #endif
20134 TRACE_IRQS_ON
20135 ENABLE_INTERRUPTS(CLBR_NONE)
20136@@ -653,7 +878,7 @@ work_notifysig_v86:
20137 movl %eax, %esp
20138 jmp 1b
20139 #endif
20140-END(work_pending)
20141+ENDPROC(work_pending)
20142
20143 # perform syscall exit tracing
20144 ALIGN
20145@@ -661,11 +886,14 @@ syscall_trace_entry:
20146 movl $-ENOSYS,PT_EAX(%esp)
20147 movl %esp, %eax
20148 call syscall_trace_enter
20149+
20150+ pax_erase_kstack
20151+
20152 /* What it returned is what we'll actually use. */
20153 cmpl $(NR_syscalls), %eax
20154 jnae syscall_call
20155 jmp syscall_exit
20156-END(syscall_trace_entry)
20157+ENDPROC(syscall_trace_entry)
20158
20159 # perform syscall exit tracing
20160 ALIGN
20161@@ -678,21 +906,25 @@ syscall_exit_work:
20162 movl %esp, %eax
20163 call syscall_trace_leave
20164 jmp resume_userspace
20165-END(syscall_exit_work)
20166+ENDPROC(syscall_exit_work)
20167 CFI_ENDPROC
20168
20169 RING0_INT_FRAME # can't unwind into user space anyway
20170 syscall_fault:
20171+#ifdef CONFIG_PAX_MEMORY_UDEREF
20172+ push %ss
20173+ pop %ds
20174+#endif
20175 ASM_CLAC
20176 GET_THREAD_INFO(%ebp)
20177 movl $-EFAULT,PT_EAX(%esp)
20178 jmp resume_userspace
20179-END(syscall_fault)
20180+ENDPROC(syscall_fault)
20181
20182 syscall_badsys:
20183 movl $-ENOSYS,PT_EAX(%esp)
20184 jmp resume_userspace
20185-END(syscall_badsys)
20186+ENDPROC(syscall_badsys)
20187 CFI_ENDPROC
20188 /*
20189 * End of kprobes section
20190@@ -708,8 +940,15 @@ END(syscall_badsys)
20191 * normal stack and adjusts ESP with the matching offset.
20192 */
20193 /* fixup the stack */
20194- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20195- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
20196+#ifdef CONFIG_SMP
20197+ movl PER_CPU_VAR(cpu_number), %ebx
20198+ shll $PAGE_SHIFT_asm, %ebx
20199+ addl $cpu_gdt_table, %ebx
20200+#else
20201+ movl $cpu_gdt_table, %ebx
20202+#endif
20203+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
20204+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
20205 shl $16, %eax
20206 addl %esp, %eax /* the adjusted stack pointer */
20207 pushl_cfi $__KERNEL_DS
20208@@ -762,7 +1001,7 @@ vector=vector+1
20209 .endr
20210 2: jmp common_interrupt
20211 .endr
20212-END(irq_entries_start)
20213+ENDPROC(irq_entries_start)
20214
20215 .previous
20216 END(interrupt)
20217@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
20218 pushl_cfi $do_coprocessor_error
20219 jmp error_code
20220 CFI_ENDPROC
20221-END(coprocessor_error)
20222+ENDPROC(coprocessor_error)
20223
20224 ENTRY(simd_coprocessor_error)
20225 RING0_INT_FRAME
20226@@ -826,7 +1065,7 @@ ENTRY(simd_coprocessor_error)
20227 .section .altinstructions,"a"
20228 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
20229 .previous
20230-.section .altinstr_replacement,"ax"
20231+.section .altinstr_replacement,"a"
20232 663: pushl $do_simd_coprocessor_error
20233 664:
20234 .previous
20235@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
20236 #endif
20237 jmp error_code
20238 CFI_ENDPROC
20239-END(simd_coprocessor_error)
20240+ENDPROC(simd_coprocessor_error)
20241
20242 ENTRY(device_not_available)
20243 RING0_INT_FRAME
20244@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
20245 pushl_cfi $do_device_not_available
20246 jmp error_code
20247 CFI_ENDPROC
20248-END(device_not_available)
20249+ENDPROC(device_not_available)
20250
20251 #ifdef CONFIG_PARAVIRT
20252 ENTRY(native_iret)
20253 iret
20254 _ASM_EXTABLE(native_iret, iret_exc)
20255-END(native_iret)
20256+ENDPROC(native_iret)
20257
20258 ENTRY(native_irq_enable_sysexit)
20259 sti
20260 sysexit
20261-END(native_irq_enable_sysexit)
20262+ENDPROC(native_irq_enable_sysexit)
20263 #endif
20264
20265 ENTRY(overflow)
20266@@ -865,7 +1104,7 @@ ENTRY(overflow)
20267 pushl_cfi $do_overflow
20268 jmp error_code
20269 CFI_ENDPROC
20270-END(overflow)
20271+ENDPROC(overflow)
20272
20273 ENTRY(bounds)
20274 RING0_INT_FRAME
20275@@ -874,7 +1113,7 @@ ENTRY(bounds)
20276 pushl_cfi $do_bounds
20277 jmp error_code
20278 CFI_ENDPROC
20279-END(bounds)
20280+ENDPROC(bounds)
20281
20282 ENTRY(invalid_op)
20283 RING0_INT_FRAME
20284@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
20285 pushl_cfi $do_invalid_op
20286 jmp error_code
20287 CFI_ENDPROC
20288-END(invalid_op)
20289+ENDPROC(invalid_op)
20290
20291 ENTRY(coprocessor_segment_overrun)
20292 RING0_INT_FRAME
20293@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
20294 pushl_cfi $do_coprocessor_segment_overrun
20295 jmp error_code
20296 CFI_ENDPROC
20297-END(coprocessor_segment_overrun)
20298+ENDPROC(coprocessor_segment_overrun)
20299
20300 ENTRY(invalid_TSS)
20301 RING0_EC_FRAME
20302@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
20303 pushl_cfi $do_invalid_TSS
20304 jmp error_code
20305 CFI_ENDPROC
20306-END(invalid_TSS)
20307+ENDPROC(invalid_TSS)
20308
20309 ENTRY(segment_not_present)
20310 RING0_EC_FRAME
20311@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
20312 pushl_cfi $do_segment_not_present
20313 jmp error_code
20314 CFI_ENDPROC
20315-END(segment_not_present)
20316+ENDPROC(segment_not_present)
20317
20318 ENTRY(stack_segment)
20319 RING0_EC_FRAME
20320@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
20321 pushl_cfi $do_stack_segment
20322 jmp error_code
20323 CFI_ENDPROC
20324-END(stack_segment)
20325+ENDPROC(stack_segment)
20326
20327 ENTRY(alignment_check)
20328 RING0_EC_FRAME
20329@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
20330 pushl_cfi $do_alignment_check
20331 jmp error_code
20332 CFI_ENDPROC
20333-END(alignment_check)
20334+ENDPROC(alignment_check)
20335
20336 ENTRY(divide_error)
20337 RING0_INT_FRAME
20338@@ -933,7 +1172,7 @@ ENTRY(divide_error)
20339 pushl_cfi $do_divide_error
20340 jmp error_code
20341 CFI_ENDPROC
20342-END(divide_error)
20343+ENDPROC(divide_error)
20344
20345 #ifdef CONFIG_X86_MCE
20346 ENTRY(machine_check)
20347@@ -943,7 +1182,7 @@ ENTRY(machine_check)
20348 pushl_cfi machine_check_vector
20349 jmp error_code
20350 CFI_ENDPROC
20351-END(machine_check)
20352+ENDPROC(machine_check)
20353 #endif
20354
20355 ENTRY(spurious_interrupt_bug)
20356@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
20357 pushl_cfi $do_spurious_interrupt_bug
20358 jmp error_code
20359 CFI_ENDPROC
20360-END(spurious_interrupt_bug)
20361+ENDPROC(spurious_interrupt_bug)
20362 /*
20363 * End of kprobes section
20364 */
20365@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
20366
20367 ENTRY(mcount)
20368 ret
20369-END(mcount)
20370+ENDPROC(mcount)
20371
20372 ENTRY(ftrace_caller)
20373 cmpl $0, function_trace_stop
20374@@ -1096,7 +1335,7 @@ ftrace_graph_call:
20375 .globl ftrace_stub
20376 ftrace_stub:
20377 ret
20378-END(ftrace_caller)
20379+ENDPROC(ftrace_caller)
20380
20381 ENTRY(ftrace_regs_caller)
20382 pushf /* push flags before compare (in cs location) */
20383@@ -1197,7 +1436,7 @@ trace:
20384 popl %ecx
20385 popl %eax
20386 jmp ftrace_stub
20387-END(mcount)
20388+ENDPROC(mcount)
20389 #endif /* CONFIG_DYNAMIC_FTRACE */
20390 #endif /* CONFIG_FUNCTION_TRACER */
20391
20392@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
20393 popl %ecx
20394 popl %eax
20395 ret
20396-END(ftrace_graph_caller)
20397+ENDPROC(ftrace_graph_caller)
20398
20399 .globl return_to_handler
20400 return_to_handler:
20401@@ -1271,15 +1510,18 @@ error_code:
20402 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
20403 REG_TO_PTGS %ecx
20404 SET_KERNEL_GS %ecx
20405- movl $(__USER_DS), %ecx
20406+ movl $(__KERNEL_DS), %ecx
20407 movl %ecx, %ds
20408 movl %ecx, %es
20409+
20410+ pax_enter_kernel
20411+
20412 TRACE_IRQS_OFF
20413 movl %esp,%eax # pt_regs pointer
20414 call *%edi
20415 jmp ret_from_exception
20416 CFI_ENDPROC
20417-END(page_fault)
20418+ENDPROC(page_fault)
20419
20420 /*
20421 * Debug traps and NMI can happen at the one SYSENTER instruction
20422@@ -1322,7 +1564,7 @@ debug_stack_correct:
20423 call do_debug
20424 jmp ret_from_exception
20425 CFI_ENDPROC
20426-END(debug)
20427+ENDPROC(debug)
20428
20429 /*
20430 * NMI is doubly nasty. It can happen _while_ we're handling
20431@@ -1360,6 +1602,9 @@ nmi_stack_correct:
20432 xorl %edx,%edx # zero error code
20433 movl %esp,%eax # pt_regs pointer
20434 call do_nmi
20435+
20436+ pax_exit_kernel
20437+
20438 jmp restore_all_notrace
20439 CFI_ENDPROC
20440
20441@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
20442 FIXUP_ESPFIX_STACK # %eax == %esp
20443 xorl %edx,%edx # zero error code
20444 call do_nmi
20445+
20446+ pax_exit_kernel
20447+
20448 RESTORE_REGS
20449 lss 12+4(%esp), %esp # back to espfix stack
20450 CFI_ADJUST_CFA_OFFSET -24
20451 jmp irq_return
20452 CFI_ENDPROC
20453-END(nmi)
20454+ENDPROC(nmi)
20455
20456 ENTRY(int3)
20457 RING0_INT_FRAME
20458@@ -1414,14 +1662,14 @@ ENTRY(int3)
20459 call do_int3
20460 jmp ret_from_exception
20461 CFI_ENDPROC
20462-END(int3)
20463+ENDPROC(int3)
20464
20465 ENTRY(general_protection)
20466 RING0_EC_FRAME
20467 pushl_cfi $do_general_protection
20468 jmp error_code
20469 CFI_ENDPROC
20470-END(general_protection)
20471+ENDPROC(general_protection)
20472
20473 #ifdef CONFIG_KVM_GUEST
20474 ENTRY(async_page_fault)
20475@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
20476 pushl_cfi $do_async_page_fault
20477 jmp error_code
20478 CFI_ENDPROC
20479-END(async_page_fault)
20480+ENDPROC(async_page_fault)
20481 #endif
20482
20483 /*
20484diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
20485index 7272089..ee191c7 100644
20486--- a/arch/x86/kernel/entry_64.S
20487+++ b/arch/x86/kernel/entry_64.S
20488@@ -59,6 +59,8 @@
20489 #include <asm/context_tracking.h>
20490 #include <asm/smap.h>
20491 #include <linux/err.h>
20492+#include <asm/pgtable.h>
20493+#include <asm/alternative-asm.h>
20494
20495 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
20496 #include <linux/elf-em.h>
20497@@ -80,8 +82,9 @@
20498 #ifdef CONFIG_DYNAMIC_FTRACE
20499
20500 ENTRY(function_hook)
20501+ pax_force_retaddr
20502 retq
20503-END(function_hook)
20504+ENDPROC(function_hook)
20505
20506 /* skip is set if stack has been adjusted */
20507 .macro ftrace_caller_setup skip=0
20508@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
20509 #endif
20510
20511 GLOBAL(ftrace_stub)
20512+ pax_force_retaddr
20513 retq
20514-END(ftrace_caller)
20515+ENDPROC(ftrace_caller)
20516
20517 ENTRY(ftrace_regs_caller)
20518 /* Save the current flags before compare (in SS location)*/
20519@@ -191,7 +195,7 @@ ftrace_restore_flags:
20520 popfq
20521 jmp ftrace_stub
20522
20523-END(ftrace_regs_caller)
20524+ENDPROC(ftrace_regs_caller)
20525
20526
20527 #else /* ! CONFIG_DYNAMIC_FTRACE */
20528@@ -212,6 +216,7 @@ ENTRY(function_hook)
20529 #endif
20530
20531 GLOBAL(ftrace_stub)
20532+ pax_force_retaddr
20533 retq
20534
20535 trace:
20536@@ -225,12 +230,13 @@ trace:
20537 #endif
20538 subq $MCOUNT_INSN_SIZE, %rdi
20539
20540+ pax_force_fptr ftrace_trace_function
20541 call *ftrace_trace_function
20542
20543 MCOUNT_RESTORE_FRAME
20544
20545 jmp ftrace_stub
20546-END(function_hook)
20547+ENDPROC(function_hook)
20548 #endif /* CONFIG_DYNAMIC_FTRACE */
20549 #endif /* CONFIG_FUNCTION_TRACER */
20550
20551@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
20552
20553 MCOUNT_RESTORE_FRAME
20554
20555+ pax_force_retaddr
20556 retq
20557-END(ftrace_graph_caller)
20558+ENDPROC(ftrace_graph_caller)
20559
20560 GLOBAL(return_to_handler)
20561 subq $24, %rsp
20562@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
20563 movq 8(%rsp), %rdx
20564 movq (%rsp), %rax
20565 addq $24, %rsp
20566+ pax_force_fptr %rdi
20567 jmp *%rdi
20568+ENDPROC(return_to_handler)
20569 #endif
20570
20571
20572@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
20573 ENDPROC(native_usergs_sysret64)
20574 #endif /* CONFIG_PARAVIRT */
20575
20576+ .macro ljmpq sel, off
20577+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
20578+ .byte 0x48; ljmp *1234f(%rip)
20579+ .pushsection .rodata
20580+ .align 16
20581+ 1234: .quad \off; .word \sel
20582+ .popsection
20583+#else
20584+ pushq $\sel
20585+ pushq $\off
20586+ lretq
20587+#endif
20588+ .endm
20589+
20590+ .macro pax_enter_kernel
20591+ pax_set_fptr_mask
20592+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20593+ call pax_enter_kernel
20594+#endif
20595+ .endm
20596+
20597+ .macro pax_exit_kernel
20598+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20599+ call pax_exit_kernel
20600+#endif
20601+
20602+ .endm
20603+
20604+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20605+ENTRY(pax_enter_kernel)
20606+ pushq %rdi
20607+
20608+#ifdef CONFIG_PARAVIRT
20609+ PV_SAVE_REGS(CLBR_RDI)
20610+#endif
20611+
20612+#ifdef CONFIG_PAX_KERNEXEC
20613+ GET_CR0_INTO_RDI
20614+ bts $16,%rdi
20615+ jnc 3f
20616+ mov %cs,%edi
20617+ cmp $__KERNEL_CS,%edi
20618+ jnz 2f
20619+1:
20620+#endif
20621+
20622+#ifdef CONFIG_PAX_MEMORY_UDEREF
20623+ 661: jmp 111f
20624+ .pushsection .altinstr_replacement, "a"
20625+ 662: ASM_NOP2
20626+ .popsection
20627+ .pushsection .altinstructions, "a"
20628+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
20629+ .popsection
20630+ GET_CR3_INTO_RDI
20631+ cmp $0,%dil
20632+ jnz 112f
20633+ mov $__KERNEL_DS,%edi
20634+ mov %edi,%ss
20635+ jmp 111f
20636+112: cmp $1,%dil
20637+ jz 113f
20638+ ud2
20639+113: sub $4097,%rdi
20640+ bts $63,%rdi
20641+ SET_RDI_INTO_CR3
20642+ mov $__UDEREF_KERNEL_DS,%edi
20643+ mov %edi,%ss
20644+111:
20645+#endif
20646+
20647+#ifdef CONFIG_PARAVIRT
20648+ PV_RESTORE_REGS(CLBR_RDI)
20649+#endif
20650+
20651+ popq %rdi
20652+ pax_force_retaddr
20653+ retq
20654+
20655+#ifdef CONFIG_PAX_KERNEXEC
20656+2: ljmpq __KERNEL_CS,1b
20657+3: ljmpq __KERNEXEC_KERNEL_CS,4f
20658+4: SET_RDI_INTO_CR0
20659+ jmp 1b
20660+#endif
20661+ENDPROC(pax_enter_kernel)
20662+
20663+ENTRY(pax_exit_kernel)
20664+ pushq %rdi
20665+
20666+#ifdef CONFIG_PARAVIRT
20667+ PV_SAVE_REGS(CLBR_RDI)
20668+#endif
20669+
20670+#ifdef CONFIG_PAX_KERNEXEC
20671+ mov %cs,%rdi
20672+ cmp $__KERNEXEC_KERNEL_CS,%edi
20673+ jz 2f
20674+ GET_CR0_INTO_RDI
20675+ bts $16,%rdi
20676+ jnc 4f
20677+1:
20678+#endif
20679+
20680+#ifdef CONFIG_PAX_MEMORY_UDEREF
20681+ 661: jmp 111f
20682+ .pushsection .altinstr_replacement, "a"
20683+ 662: ASM_NOP2
20684+ .popsection
20685+ .pushsection .altinstructions, "a"
20686+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
20687+ .popsection
20688+ mov %ss,%edi
20689+ cmp $__UDEREF_KERNEL_DS,%edi
20690+ jnz 111f
20691+ GET_CR3_INTO_RDI
20692+ cmp $0,%dil
20693+ jz 112f
20694+ ud2
20695+112: add $4097,%rdi
20696+ bts $63,%rdi
20697+ SET_RDI_INTO_CR3
20698+ mov $__KERNEL_DS,%edi
20699+ mov %edi,%ss
20700+111:
20701+#endif
20702+
20703+#ifdef CONFIG_PARAVIRT
20704+ PV_RESTORE_REGS(CLBR_RDI);
20705+#endif
20706+
20707+ popq %rdi
20708+ pax_force_retaddr
20709+ retq
20710+
20711+#ifdef CONFIG_PAX_KERNEXEC
20712+2: GET_CR0_INTO_RDI
20713+ btr $16,%rdi
20714+ jnc 4f
20715+ ljmpq __KERNEL_CS,3f
20716+3: SET_RDI_INTO_CR0
20717+ jmp 1b
20718+4: ud2
20719+ jmp 4b
20720+#endif
20721+ENDPROC(pax_exit_kernel)
20722+#endif
20723+
20724+ .macro pax_enter_kernel_user
20725+ pax_set_fptr_mask
20726+#ifdef CONFIG_PAX_MEMORY_UDEREF
20727+ call pax_enter_kernel_user
20728+#endif
20729+ .endm
20730+
20731+ .macro pax_exit_kernel_user
20732+#ifdef CONFIG_PAX_MEMORY_UDEREF
20733+ call pax_exit_kernel_user
20734+#endif
20735+#ifdef CONFIG_PAX_RANDKSTACK
20736+ pushq %rax
20737+ pushq %r11
20738+ call pax_randomize_kstack
20739+ popq %r11
20740+ popq %rax
20741+#endif
20742+ .endm
20743+
20744+#ifdef CONFIG_PAX_MEMORY_UDEREF
20745+ENTRY(pax_enter_kernel_user)
20746+ pushq %rdi
20747+ pushq %rbx
20748+
20749+#ifdef CONFIG_PARAVIRT
20750+ PV_SAVE_REGS(CLBR_RDI)
20751+#endif
20752+
20753+ 661: jmp 111f
20754+ .pushsection .altinstr_replacement, "a"
20755+ 662: ASM_NOP2
20756+ .popsection
20757+ .pushsection .altinstructions, "a"
20758+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
20759+ .popsection
20760+ GET_CR3_INTO_RDI
20761+ cmp $1,%dil
20762+ jnz 4f
20763+ sub $4097,%rdi
20764+ bts $63,%rdi
20765+ SET_RDI_INTO_CR3
20766+ jmp 3f
20767+111:
20768+
20769+ GET_CR3_INTO_RDI
20770+ mov %rdi,%rbx
20771+ add $__START_KERNEL_map,%rbx
20772+ sub phys_base(%rip),%rbx
20773+
20774+#ifdef CONFIG_PARAVIRT
20775+ cmpl $0, pv_info+PARAVIRT_enabled
20776+ jz 1f
20777+ pushq %rdi
20778+ i = 0
20779+ .rept USER_PGD_PTRS
20780+ mov i*8(%rbx),%rsi
20781+ mov $0,%sil
20782+ lea i*8(%rbx),%rdi
20783+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
20784+ i = i + 1
20785+ .endr
20786+ popq %rdi
20787+ jmp 2f
20788+1:
20789+#endif
20790+
20791+ i = 0
20792+ .rept USER_PGD_PTRS
20793+ movb $0,i*8(%rbx)
20794+ i = i + 1
20795+ .endr
20796+
20797+2: SET_RDI_INTO_CR3
20798+
20799+#ifdef CONFIG_PAX_KERNEXEC
20800+ GET_CR0_INTO_RDI
20801+ bts $16,%rdi
20802+ SET_RDI_INTO_CR0
20803+#endif
20804+
20805+3:
20806+
20807+#ifdef CONFIG_PARAVIRT
20808+ PV_RESTORE_REGS(CLBR_RDI)
20809+#endif
20810+
20811+ popq %rbx
20812+ popq %rdi
20813+ pax_force_retaddr
20814+ retq
20815+4: ud2
20816+ENDPROC(pax_enter_kernel_user)
20817+
20818+ENTRY(pax_exit_kernel_user)
20819+ pushq %rdi
20820+ pushq %rbx
20821+
20822+#ifdef CONFIG_PARAVIRT
20823+ PV_SAVE_REGS(CLBR_RDI)
20824+#endif
20825+
20826+ GET_CR3_INTO_RDI
20827+ 661: jmp 1f
20828+ .pushsection .altinstr_replacement, "a"
20829+ 662: ASM_NOP2
20830+ .popsection
20831+ .pushsection .altinstructions, "a"
20832+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
20833+ .popsection
20834+ cmp $0,%dil
20835+ jnz 3f
20836+ add $4097,%rdi
20837+ bts $63,%rdi
20838+ SET_RDI_INTO_CR3
20839+ jmp 2f
20840+1:
20841+ mov %rdi,%rbx
20842+ add $__START_KERNEL_map,%rbx
20843+ sub phys_base(%rip),%rbx
20844+
20845+#ifdef CONFIG_PARAVIRT
20846+ cmpl $0, pv_info+PARAVIRT_enabled
20847+ jz 1f
20848+ pushq %rdi
20849+ i = 0
20850+ .rept USER_PGD_PTRS
20851+ mov i*8(%rbx),%rsi
20852+ mov $0x67,%sil
20853+ lea i*8(%rbx),%rdi
20854+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
20855+ i = i + 1
20856+ .endr
20857+ popq %rdi
20858+ jmp 2f
20859+1:
20860+#endif
20861+
20862+#ifdef CONFIG_PAX_KERNEXEC
20863+ GET_CR0_INTO_RDI
20864+ btr $16,%rdi
20865+ jnc 3f
20866+ SET_RDI_INTO_CR0
20867+#endif
20868+
20869+ i = 0
20870+ .rept USER_PGD_PTRS
20871+ movb $0x67,i*8(%rbx)
20872+ i = i + 1
20873+ .endr
20874+2:
20875+
20876+#ifdef CONFIG_PARAVIRT
20877+ PV_RESTORE_REGS(CLBR_RDI)
20878+#endif
20879+
20880+ popq %rbx
20881+ popq %rdi
20882+ pax_force_retaddr
20883+ retq
20884+3: ud2
20885+ENDPROC(pax_exit_kernel_user)
20886+#endif
20887+
20888+ .macro pax_enter_kernel_nmi
20889+ pax_set_fptr_mask
20890+
20891+#ifdef CONFIG_PAX_KERNEXEC
20892+ GET_CR0_INTO_RDI
20893+ bts $16,%rdi
20894+ jc 110f
20895+ SET_RDI_INTO_CR0
20896+ or $2,%ebx
20897+110:
20898+#endif
20899+
20900+#ifdef CONFIG_PAX_MEMORY_UDEREF
20901+ 661: jmp 111f
20902+ .pushsection .altinstr_replacement, "a"
20903+ 662: ASM_NOP2
20904+ .popsection
20905+ .pushsection .altinstructions, "a"
20906+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
20907+ .popsection
20908+ GET_CR3_INTO_RDI
20909+ cmp $0,%dil
20910+ jz 111f
20911+ sub $4097,%rdi
20912+ or $4,%ebx
20913+ bts $63,%rdi
20914+ SET_RDI_INTO_CR3
20915+ mov $__UDEREF_KERNEL_DS,%edi
20916+ mov %edi,%ss
20917+111:
20918+#endif
20919+ .endm
20920+
20921+ .macro pax_exit_kernel_nmi
20922+#ifdef CONFIG_PAX_KERNEXEC
20923+ btr $1,%ebx
20924+ jnc 110f
20925+ GET_CR0_INTO_RDI
20926+ btr $16,%rdi
20927+ SET_RDI_INTO_CR0
20928+110:
20929+#endif
20930+
20931+#ifdef CONFIG_PAX_MEMORY_UDEREF
20932+ btr $2,%ebx
20933+ jnc 111f
20934+ GET_CR3_INTO_RDI
20935+ add $4097,%rdi
20936+ bts $63,%rdi
20937+ SET_RDI_INTO_CR3
20938+ mov $__KERNEL_DS,%edi
20939+ mov %edi,%ss
20940+111:
20941+#endif
20942+ .endm
20943+
20944+ .macro pax_erase_kstack
20945+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20946+ call pax_erase_kstack
20947+#endif
20948+ .endm
20949+
20950+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20951+ENTRY(pax_erase_kstack)
20952+ pushq %rdi
20953+ pushq %rcx
20954+ pushq %rax
20955+ pushq %r11
20956+
20957+ GET_THREAD_INFO(%r11)
20958+ mov TI_lowest_stack(%r11), %rdi
20959+ mov $-0xBEEF, %rax
20960+ std
20961+
20962+1: mov %edi, %ecx
20963+ and $THREAD_SIZE_asm - 1, %ecx
20964+ shr $3, %ecx
20965+ repne scasq
20966+ jecxz 2f
20967+
20968+ cmp $2*8, %ecx
20969+ jc 2f
20970+
20971+ mov $2*8, %ecx
20972+ repe scasq
20973+ jecxz 2f
20974+ jne 1b
20975+
20976+2: cld
20977+ mov %esp, %ecx
20978+ sub %edi, %ecx
20979+
20980+ cmp $THREAD_SIZE_asm, %rcx
20981+ jb 3f
20982+ ud2
20983+3:
20984+
20985+ shr $3, %ecx
20986+ rep stosq
20987+
20988+ mov TI_task_thread_sp0(%r11), %rdi
20989+ sub $256, %rdi
20990+ mov %rdi, TI_lowest_stack(%r11)
20991+
20992+ popq %r11
20993+ popq %rax
20994+ popq %rcx
20995+ popq %rdi
20996+ pax_force_retaddr
20997+ ret
20998+ENDPROC(pax_erase_kstack)
20999+#endif
21000
21001 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21002 #ifdef CONFIG_TRACE_IRQFLAGS
21003@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21004 .endm
21005
21006 .macro UNFAKE_STACK_FRAME
21007- addq $8*6, %rsp
21008- CFI_ADJUST_CFA_OFFSET -(6*8)
21009+ addq $8*6 + ARG_SKIP, %rsp
21010+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21011 .endm
21012
21013 /*
21014@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21015 movq %rsp, %rsi
21016
21017 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21018- testl $3, CS-RBP(%rsi)
21019+ testb $3, CS-RBP(%rsi)
21020 je 1f
21021 SWAPGS
21022 /*
21023@@ -498,9 +931,10 @@ ENTRY(save_rest)
21024 movq_cfi r15, R15+16
21025 movq %r11, 8(%rsp) /* return address */
21026 FIXUP_TOP_OF_STACK %r11, 16
21027+ pax_force_retaddr
21028 ret
21029 CFI_ENDPROC
21030-END(save_rest)
21031+ENDPROC(save_rest)
21032
21033 /* save complete stack frame */
21034 .pushsection .kprobes.text, "ax"
21035@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21036 js 1f /* negative -> in kernel */
21037 SWAPGS
21038 xorl %ebx,%ebx
21039-1: ret
21040+1: pax_force_retaddr_bts
21041+ ret
21042 CFI_ENDPROC
21043-END(save_paranoid)
21044+ENDPROC(save_paranoid)
21045 .popsection
21046
21047 /*
21048@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21049
21050 RESTORE_REST
21051
21052- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21053+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21054 jz 1f
21055
21056 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21057@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21058 RESTORE_REST
21059 jmp int_ret_from_sys_call
21060 CFI_ENDPROC
21061-END(ret_from_fork)
21062+ENDPROC(ret_from_fork)
21063
21064 /*
21065 * System call entry. Up to 6 arguments in registers are supported.
21066@@ -608,7 +1043,7 @@ END(ret_from_fork)
21067 ENTRY(system_call)
21068 CFI_STARTPROC simple
21069 CFI_SIGNAL_FRAME
21070- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21071+ CFI_DEF_CFA rsp,0
21072 CFI_REGISTER rip,rcx
21073 /*CFI_REGISTER rflags,r11*/
21074 SWAPGS_UNSAFE_STACK
21075@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21076
21077 movq %rsp,PER_CPU_VAR(old_rsp)
21078 movq PER_CPU_VAR(kernel_stack),%rsp
21079+ SAVE_ARGS 8*6,0
21080+ pax_enter_kernel_user
21081+
21082+#ifdef CONFIG_PAX_RANDKSTACK
21083+ pax_erase_kstack
21084+#endif
21085+
21086 /*
21087 * No need to follow this irqs off/on section - it's straight
21088 * and short:
21089 */
21090 ENABLE_INTERRUPTS(CLBR_NONE)
21091- SAVE_ARGS 8,0
21092 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21093 movq %rcx,RIP-ARGOFFSET(%rsp)
21094 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21095- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21096+ GET_THREAD_INFO(%rcx)
21097+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21098 jnz tracesys
21099 system_call_fastpath:
21100 #if __SYSCALL_MASK == ~0
21101@@ -640,7 +1082,7 @@ system_call_fastpath:
21102 cmpl $__NR_syscall_max,%eax
21103 #endif
21104 ja badsys
21105- movq %r10,%rcx
21106+ movq R10-ARGOFFSET(%rsp),%rcx
21107 call *sys_call_table(,%rax,8) # XXX: rip relative
21108 movq %rax,RAX-ARGOFFSET(%rsp)
21109 /*
21110@@ -654,10 +1096,13 @@ sysret_check:
21111 LOCKDEP_SYS_EXIT
21112 DISABLE_INTERRUPTS(CLBR_NONE)
21113 TRACE_IRQS_OFF
21114- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21115+ GET_THREAD_INFO(%rcx)
21116+ movl TI_flags(%rcx),%edx
21117 andl %edi,%edx
21118 jnz sysret_careful
21119 CFI_REMEMBER_STATE
21120+ pax_exit_kernel_user
21121+ pax_erase_kstack
21122 /*
21123 * sysretq will re-enable interrupts:
21124 */
21125@@ -709,14 +1154,18 @@ badsys:
21126 * jump back to the normal fast path.
21127 */
21128 auditsys:
21129- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21130+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21131 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21132 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21133 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21134 movq %rax,%rsi /* 2nd arg: syscall number */
21135 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21136 call __audit_syscall_entry
21137+
21138+ pax_erase_kstack
21139+
21140 LOAD_ARGS 0 /* reload call-clobbered registers */
21141+ pax_set_fptr_mask
21142 jmp system_call_fastpath
21143
21144 /*
21145@@ -737,7 +1186,7 @@ sysret_audit:
21146 /* Do syscall tracing */
21147 tracesys:
21148 #ifdef CONFIG_AUDITSYSCALL
21149- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21150+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21151 jz auditsys
21152 #endif
21153 SAVE_REST
21154@@ -745,12 +1194,16 @@ tracesys:
21155 FIXUP_TOP_OF_STACK %rdi
21156 movq %rsp,%rdi
21157 call syscall_trace_enter
21158+
21159+ pax_erase_kstack
21160+
21161 /*
21162 * Reload arg registers from stack in case ptrace changed them.
21163 * We don't reload %rax because syscall_trace_enter() returned
21164 * the value it wants us to use in the table lookup.
21165 */
21166 LOAD_ARGS ARGOFFSET, 1
21167+ pax_set_fptr_mask
21168 RESTORE_REST
21169 #if __SYSCALL_MASK == ~0
21170 cmpq $__NR_syscall_max,%rax
21171@@ -759,7 +1212,7 @@ tracesys:
21172 cmpl $__NR_syscall_max,%eax
21173 #endif
21174 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21175- movq %r10,%rcx /* fixup for C */
21176+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21177 call *sys_call_table(,%rax,8)
21178 movq %rax,RAX-ARGOFFSET(%rsp)
21179 /* Use IRET because user could have changed frame */
21180@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21181 andl %edi,%edx
21182 jnz int_careful
21183 andl $~TS_COMPAT,TI_status(%rcx)
21184- jmp retint_swapgs
21185+ pax_exit_kernel_user
21186+ pax_erase_kstack
21187+ jmp retint_swapgs_pax
21188
21189 /* Either reschedule or signal or syscall exit tracking needed. */
21190 /* First do a reschedule test. */
21191@@ -826,7 +1281,7 @@ int_restore_rest:
21192 TRACE_IRQS_OFF
21193 jmp int_with_check
21194 CFI_ENDPROC
21195-END(system_call)
21196+ENDPROC(system_call)
21197
21198 .macro FORK_LIKE func
21199 ENTRY(stub_\func)
21200@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
21201 DEFAULT_FRAME 0 8 /* offset 8: return address */
21202 call sys_\func
21203 RESTORE_TOP_OF_STACK %r11, 8
21204+ pax_force_retaddr
21205 ret $REST_SKIP /* pop extended registers */
21206 CFI_ENDPROC
21207-END(stub_\func)
21208+ENDPROC(stub_\func)
21209 .endm
21210
21211 .macro FIXED_FRAME label,func
21212@@ -851,9 +1307,10 @@ ENTRY(\label)
21213 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
21214 call \func
21215 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
21216+ pax_force_retaddr
21217 ret
21218 CFI_ENDPROC
21219-END(\label)
21220+ENDPROC(\label)
21221 .endm
21222
21223 FORK_LIKE clone
21224@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
21225 movq_cfi_restore R12+8, r12
21226 movq_cfi_restore RBP+8, rbp
21227 movq_cfi_restore RBX+8, rbx
21228+ pax_force_retaddr
21229 ret $REST_SKIP /* pop extended registers */
21230 CFI_ENDPROC
21231-END(ptregscall_common)
21232+ENDPROC(ptregscall_common)
21233
21234 ENTRY(stub_execve)
21235 CFI_STARTPROC
21236@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
21237 RESTORE_REST
21238 jmp int_ret_from_sys_call
21239 CFI_ENDPROC
21240-END(stub_execve)
21241+ENDPROC(stub_execve)
21242
21243 /*
21244 * sigreturn is special because it needs to restore all registers on return.
21245@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
21246 RESTORE_REST
21247 jmp int_ret_from_sys_call
21248 CFI_ENDPROC
21249-END(stub_rt_sigreturn)
21250+ENDPROC(stub_rt_sigreturn)
21251
21252 #ifdef CONFIG_X86_X32_ABI
21253 ENTRY(stub_x32_rt_sigreturn)
21254@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
21255 RESTORE_REST
21256 jmp int_ret_from_sys_call
21257 CFI_ENDPROC
21258-END(stub_x32_rt_sigreturn)
21259+ENDPROC(stub_x32_rt_sigreturn)
21260
21261 ENTRY(stub_x32_execve)
21262 CFI_STARTPROC
21263@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
21264 RESTORE_REST
21265 jmp int_ret_from_sys_call
21266 CFI_ENDPROC
21267-END(stub_x32_execve)
21268+ENDPROC(stub_x32_execve)
21269
21270 #endif
21271
21272@@ -967,7 +1425,7 @@ vector=vector+1
21273 2: jmp common_interrupt
21274 .endr
21275 CFI_ENDPROC
21276-END(irq_entries_start)
21277+ENDPROC(irq_entries_start)
21278
21279 .previous
21280 END(interrupt)
21281@@ -987,6 +1445,16 @@ END(interrupt)
21282 subq $ORIG_RAX-RBP, %rsp
21283 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
21284 SAVE_ARGS_IRQ
21285+#ifdef CONFIG_PAX_MEMORY_UDEREF
21286+ testb $3, CS(%rdi)
21287+ jnz 1f
21288+ pax_enter_kernel
21289+ jmp 2f
21290+1: pax_enter_kernel_user
21291+2:
21292+#else
21293+ pax_enter_kernel
21294+#endif
21295 call \func
21296 .endm
21297
21298@@ -1019,7 +1487,7 @@ ret_from_intr:
21299
21300 exit_intr:
21301 GET_THREAD_INFO(%rcx)
21302- testl $3,CS-ARGOFFSET(%rsp)
21303+ testb $3,CS-ARGOFFSET(%rsp)
21304 je retint_kernel
21305
21306 /* Interrupt came from user space */
21307@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
21308 * The iretq could re-enable interrupts:
21309 */
21310 DISABLE_INTERRUPTS(CLBR_ANY)
21311+ pax_exit_kernel_user
21312+retint_swapgs_pax:
21313 TRACE_IRQS_IRETQ
21314 SWAPGS
21315 jmp restore_args
21316
21317 retint_restore_args: /* return to kernel space */
21318 DISABLE_INTERRUPTS(CLBR_ANY)
21319+ pax_exit_kernel
21320+ pax_force_retaddr (RIP-ARGOFFSET)
21321 /*
21322 * The iretq could re-enable interrupts:
21323 */
21324@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
21325 #endif
21326
21327 CFI_ENDPROC
21328-END(common_interrupt)
21329+ENDPROC(common_interrupt)
21330 /*
21331 * End of kprobes section
21332 */
21333@@ -1147,7 +1619,7 @@ ENTRY(\sym)
21334 interrupt \do_sym
21335 jmp ret_from_intr
21336 CFI_ENDPROC
21337-END(\sym)
21338+ENDPROC(\sym)
21339 .endm
21340
21341 #ifdef CONFIG_SMP
21342@@ -1208,12 +1680,22 @@ ENTRY(\sym)
21343 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
21344 call error_entry
21345 DEFAULT_FRAME 0
21346+#ifdef CONFIG_PAX_MEMORY_UDEREF
21347+ testb $3, CS(%rsp)
21348+ jnz 1f
21349+ pax_enter_kernel
21350+ jmp 2f
21351+1: pax_enter_kernel_user
21352+2:
21353+#else
21354+ pax_enter_kernel
21355+#endif
21356 movq %rsp,%rdi /* pt_regs pointer */
21357 xorl %esi,%esi /* no error code */
21358 call \do_sym
21359 jmp error_exit /* %ebx: no swapgs flag */
21360 CFI_ENDPROC
21361-END(\sym)
21362+ENDPROC(\sym)
21363 .endm
21364
21365 .macro paranoidzeroentry sym do_sym
21366@@ -1226,15 +1708,25 @@ ENTRY(\sym)
21367 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
21368 call save_paranoid
21369 TRACE_IRQS_OFF
21370+#ifdef CONFIG_PAX_MEMORY_UDEREF
21371+ testb $3, CS(%rsp)
21372+ jnz 1f
21373+ pax_enter_kernel
21374+ jmp 2f
21375+1: pax_enter_kernel_user
21376+2:
21377+#else
21378+ pax_enter_kernel
21379+#endif
21380 movq %rsp,%rdi /* pt_regs pointer */
21381 xorl %esi,%esi /* no error code */
21382 call \do_sym
21383 jmp paranoid_exit /* %ebx: no swapgs flag */
21384 CFI_ENDPROC
21385-END(\sym)
21386+ENDPROC(\sym)
21387 .endm
21388
21389-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
21390+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
21391 .macro paranoidzeroentry_ist sym do_sym ist
21392 ENTRY(\sym)
21393 INTR_FRAME
21394@@ -1245,14 +1737,30 @@ ENTRY(\sym)
21395 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
21396 call save_paranoid
21397 TRACE_IRQS_OFF_DEBUG
21398+#ifdef CONFIG_PAX_MEMORY_UDEREF
21399+ testb $3, CS(%rsp)
21400+ jnz 1f
21401+ pax_enter_kernel
21402+ jmp 2f
21403+1: pax_enter_kernel_user
21404+2:
21405+#else
21406+ pax_enter_kernel
21407+#endif
21408 movq %rsp,%rdi /* pt_regs pointer */
21409 xorl %esi,%esi /* no error code */
21410+#ifdef CONFIG_SMP
21411+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
21412+ lea init_tss(%r12), %r12
21413+#else
21414+ lea init_tss(%rip), %r12
21415+#endif
21416 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
21417 call \do_sym
21418 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
21419 jmp paranoid_exit /* %ebx: no swapgs flag */
21420 CFI_ENDPROC
21421-END(\sym)
21422+ENDPROC(\sym)
21423 .endm
21424
21425 .macro errorentry sym do_sym
21426@@ -1264,13 +1772,23 @@ ENTRY(\sym)
21427 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
21428 call error_entry
21429 DEFAULT_FRAME 0
21430+#ifdef CONFIG_PAX_MEMORY_UDEREF
21431+ testb $3, CS(%rsp)
21432+ jnz 1f
21433+ pax_enter_kernel
21434+ jmp 2f
21435+1: pax_enter_kernel_user
21436+2:
21437+#else
21438+ pax_enter_kernel
21439+#endif
21440 movq %rsp,%rdi /* pt_regs pointer */
21441 movq ORIG_RAX(%rsp),%rsi /* get error code */
21442 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
21443 call \do_sym
21444 jmp error_exit /* %ebx: no swapgs flag */
21445 CFI_ENDPROC
21446-END(\sym)
21447+ENDPROC(\sym)
21448 .endm
21449
21450 /* error code is on the stack already */
21451@@ -1284,13 +1802,23 @@ ENTRY(\sym)
21452 call save_paranoid
21453 DEFAULT_FRAME 0
21454 TRACE_IRQS_OFF
21455+#ifdef CONFIG_PAX_MEMORY_UDEREF
21456+ testb $3, CS(%rsp)
21457+ jnz 1f
21458+ pax_enter_kernel
21459+ jmp 2f
21460+1: pax_enter_kernel_user
21461+2:
21462+#else
21463+ pax_enter_kernel
21464+#endif
21465 movq %rsp,%rdi /* pt_regs pointer */
21466 movq ORIG_RAX(%rsp),%rsi /* get error code */
21467 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
21468 call \do_sym
21469 jmp paranoid_exit /* %ebx: no swapgs flag */
21470 CFI_ENDPROC
21471-END(\sym)
21472+ENDPROC(\sym)
21473 .endm
21474
21475 zeroentry divide_error do_divide_error
21476@@ -1320,9 +1848,10 @@ gs_change:
21477 2: mfence /* workaround */
21478 SWAPGS
21479 popfq_cfi
21480+ pax_force_retaddr
21481 ret
21482 CFI_ENDPROC
21483-END(native_load_gs_index)
21484+ENDPROC(native_load_gs_index)
21485
21486 _ASM_EXTABLE(gs_change,bad_gs)
21487 .section .fixup,"ax"
21488@@ -1350,9 +1879,10 @@ ENTRY(call_softirq)
21489 CFI_DEF_CFA_REGISTER rsp
21490 CFI_ADJUST_CFA_OFFSET -8
21491 decl PER_CPU_VAR(irq_count)
21492+ pax_force_retaddr
21493 ret
21494 CFI_ENDPROC
21495-END(call_softirq)
21496+ENDPROC(call_softirq)
21497
21498 #ifdef CONFIG_XEN
21499 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
21500@@ -1390,7 +1920,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
21501 decl PER_CPU_VAR(irq_count)
21502 jmp error_exit
21503 CFI_ENDPROC
21504-END(xen_do_hypervisor_callback)
21505+ENDPROC(xen_do_hypervisor_callback)
21506
21507 /*
21508 * Hypervisor uses this for application faults while it executes.
21509@@ -1449,7 +1979,7 @@ ENTRY(xen_failsafe_callback)
21510 SAVE_ALL
21511 jmp error_exit
21512 CFI_ENDPROC
21513-END(xen_failsafe_callback)
21514+ENDPROC(xen_failsafe_callback)
21515
21516 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
21517 xen_hvm_callback_vector xen_evtchn_do_upcall
21518@@ -1501,18 +2031,33 @@ ENTRY(paranoid_exit)
21519 DEFAULT_FRAME
21520 DISABLE_INTERRUPTS(CLBR_NONE)
21521 TRACE_IRQS_OFF_DEBUG
21522- testl %ebx,%ebx /* swapgs needed? */
21523+ testl $1,%ebx /* swapgs needed? */
21524 jnz paranoid_restore
21525- testl $3,CS(%rsp)
21526+ testb $3,CS(%rsp)
21527 jnz paranoid_userspace
21528+#ifdef CONFIG_PAX_MEMORY_UDEREF
21529+ pax_exit_kernel
21530+ TRACE_IRQS_IRETQ 0
21531+ SWAPGS_UNSAFE_STACK
21532+ RESTORE_ALL 8
21533+ pax_force_retaddr_bts
21534+ jmp irq_return
21535+#endif
21536 paranoid_swapgs:
21537+#ifdef CONFIG_PAX_MEMORY_UDEREF
21538+ pax_exit_kernel_user
21539+#else
21540+ pax_exit_kernel
21541+#endif
21542 TRACE_IRQS_IRETQ 0
21543 SWAPGS_UNSAFE_STACK
21544 RESTORE_ALL 8
21545 jmp irq_return
21546 paranoid_restore:
21547+ pax_exit_kernel
21548 TRACE_IRQS_IRETQ_DEBUG 0
21549 RESTORE_ALL 8
21550+ pax_force_retaddr_bts
21551 jmp irq_return
21552 paranoid_userspace:
21553 GET_THREAD_INFO(%rcx)
21554@@ -1541,7 +2086,7 @@ paranoid_schedule:
21555 TRACE_IRQS_OFF
21556 jmp paranoid_userspace
21557 CFI_ENDPROC
21558-END(paranoid_exit)
21559+ENDPROC(paranoid_exit)
21560
21561 /*
21562 * Exception entry point. This expects an error code/orig_rax on the stack.
21563@@ -1568,12 +2113,13 @@ ENTRY(error_entry)
21564 movq_cfi r14, R14+8
21565 movq_cfi r15, R15+8
21566 xorl %ebx,%ebx
21567- testl $3,CS+8(%rsp)
21568+ testb $3,CS+8(%rsp)
21569 je error_kernelspace
21570 error_swapgs:
21571 SWAPGS
21572 error_sti:
21573 TRACE_IRQS_OFF
21574+ pax_force_retaddr_bts
21575 ret
21576
21577 /*
21578@@ -1600,7 +2146,7 @@ bstep_iret:
21579 movq %rcx,RIP+8(%rsp)
21580 jmp error_swapgs
21581 CFI_ENDPROC
21582-END(error_entry)
21583+ENDPROC(error_entry)
21584
21585
21586 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
21587@@ -1611,7 +2157,7 @@ ENTRY(error_exit)
21588 DISABLE_INTERRUPTS(CLBR_NONE)
21589 TRACE_IRQS_OFF
21590 GET_THREAD_INFO(%rcx)
21591- testl %eax,%eax
21592+ testl $1,%eax
21593 jne retint_kernel
21594 LOCKDEP_SYS_EXIT_IRQ
21595 movl TI_flags(%rcx),%edx
21596@@ -1620,7 +2166,7 @@ ENTRY(error_exit)
21597 jnz retint_careful
21598 jmp retint_swapgs
21599 CFI_ENDPROC
21600-END(error_exit)
21601+ENDPROC(error_exit)
21602
21603 /*
21604 * Test if a given stack is an NMI stack or not.
21605@@ -1678,9 +2224,11 @@ ENTRY(nmi)
21606 * If %cs was not the kernel segment, then the NMI triggered in user
21607 * space, which means it is definitely not nested.
21608 */
21609+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
21610+ je 1f
21611 cmpl $__KERNEL_CS, 16(%rsp)
21612 jne first_nmi
21613-
21614+1:
21615 /*
21616 * Check the special variable on the stack to see if NMIs are
21617 * executing.
21618@@ -1714,8 +2262,7 @@ nested_nmi:
21619
21620 1:
21621 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
21622- leaq -1*8(%rsp), %rdx
21623- movq %rdx, %rsp
21624+ subq $8, %rsp
21625 CFI_ADJUST_CFA_OFFSET 1*8
21626 leaq -10*8(%rsp), %rdx
21627 pushq_cfi $__KERNEL_DS
21628@@ -1733,6 +2280,7 @@ nested_nmi_out:
21629 CFI_RESTORE rdx
21630
21631 /* No need to check faults here */
21632+# pax_force_retaddr_bts
21633 INTERRUPT_RETURN
21634
21635 CFI_RESTORE_STATE
21636@@ -1849,6 +2397,8 @@ end_repeat_nmi:
21637 */
21638 movq %cr2, %r12
21639
21640+ pax_enter_kernel_nmi
21641+
21642 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
21643 movq %rsp,%rdi
21644 movq $-1,%rsi
21645@@ -1861,26 +2411,31 @@ end_repeat_nmi:
21646 movq %r12, %cr2
21647 1:
21648
21649- testl %ebx,%ebx /* swapgs needed? */
21650+ testl $1,%ebx /* swapgs needed? */
21651 jnz nmi_restore
21652 nmi_swapgs:
21653 SWAPGS_UNSAFE_STACK
21654 nmi_restore:
21655+ pax_exit_kernel_nmi
21656 /* Pop the extra iret frame at once */
21657 RESTORE_ALL 6*8
21658+ testb $3, 8(%rsp)
21659+ jnz 1f
21660+ pax_force_retaddr_bts
21661+1:
21662
21663 /* Clear the NMI executing stack variable */
21664 movq $0, 5*8(%rsp)
21665 jmp irq_return
21666 CFI_ENDPROC
21667-END(nmi)
21668+ENDPROC(nmi)
21669
21670 ENTRY(ignore_sysret)
21671 CFI_STARTPROC
21672 mov $-ENOSYS,%eax
21673 sysret
21674 CFI_ENDPROC
21675-END(ignore_sysret)
21676+ENDPROC(ignore_sysret)
21677
21678 /*
21679 * End of kprobes section
21680diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
21681index 42a392a..fbbd930 100644
21682--- a/arch/x86/kernel/ftrace.c
21683+++ b/arch/x86/kernel/ftrace.c
21684@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
21685 {
21686 unsigned char replaced[MCOUNT_INSN_SIZE];
21687
21688+ ip = ktla_ktva(ip);
21689+
21690 /*
21691 * Note: Due to modules and __init, code can
21692 * disappear and change, we need to protect against faulting
21693@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
21694 unsigned char old[MCOUNT_INSN_SIZE], *new;
21695 int ret;
21696
21697- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
21698+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
21699 new = ftrace_call_replace(ip, (unsigned long)func);
21700
21701 /* See comment above by declaration of modifying_ftrace_code */
21702@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
21703 /* Also update the regs callback function */
21704 if (!ret) {
21705 ip = (unsigned long)(&ftrace_regs_call);
21706- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
21707+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
21708 new = ftrace_call_replace(ip, (unsigned long)func);
21709 ret = ftrace_modify_code(ip, old, new);
21710 }
21711@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
21712 * kernel identity mapping to modify code.
21713 */
21714 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
21715- ip = (unsigned long)__va(__pa_symbol(ip));
21716+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
21717
21718 return probe_kernel_write((void *)ip, val, size);
21719 }
21720@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
21721 unsigned char replaced[MCOUNT_INSN_SIZE];
21722 unsigned char brk = BREAKPOINT_INSTRUCTION;
21723
21724- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
21725+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
21726 return -EFAULT;
21727
21728 /* Make sure it is what we expect it to be */
21729@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
21730 return ret;
21731
21732 fail_update:
21733- probe_kernel_write((void *)ip, &old_code[0], 1);
21734+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
21735 goto out;
21736 }
21737
21738@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
21739 {
21740 unsigned char code[MCOUNT_INSN_SIZE];
21741
21742+ ip = ktla_ktva(ip);
21743+
21744 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
21745 return -EFAULT;
21746
21747diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
21748index 55b6761..a6456fc 100644
21749--- a/arch/x86/kernel/head64.c
21750+++ b/arch/x86/kernel/head64.c
21751@@ -67,12 +67,12 @@ again:
21752 pgd = *pgd_p;
21753
21754 /*
21755- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
21756- * critical -- __PAGE_OFFSET would point us back into the dynamic
21757+ * The use of __early_va rather than __va here is critical:
21758+ * __va would point us back into the dynamic
21759 * range and we might end up looping forever...
21760 */
21761 if (pgd)
21762- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
21763+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
21764 else {
21765 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
21766 reset_early_page_tables();
21767@@ -82,13 +82,13 @@ again:
21768 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
21769 for (i = 0; i < PTRS_PER_PUD; i++)
21770 pud_p[i] = 0;
21771- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
21772+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
21773 }
21774 pud_p += pud_index(address);
21775 pud = *pud_p;
21776
21777 if (pud)
21778- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
21779+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
21780 else {
21781 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
21782 reset_early_page_tables();
21783@@ -98,7 +98,7 @@ again:
21784 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
21785 for (i = 0; i < PTRS_PER_PMD; i++)
21786 pmd_p[i] = 0;
21787- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
21788+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
21789 }
21790 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
21791 pmd_p[pmd_index(address)] = pmd;
21792@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
21793 if (console_loglevel == 10)
21794 early_printk("Kernel alive\n");
21795
21796- clear_page(init_level4_pgt);
21797 /* set init_level4_pgt kernel high mapping*/
21798 init_level4_pgt[511] = early_level4_pgt[511];
21799
21800diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
21801index 73afd11..0ef46f2 100644
21802--- a/arch/x86/kernel/head_32.S
21803+++ b/arch/x86/kernel/head_32.S
21804@@ -26,6 +26,12 @@
21805 /* Physical address */
21806 #define pa(X) ((X) - __PAGE_OFFSET)
21807
21808+#ifdef CONFIG_PAX_KERNEXEC
21809+#define ta(X) (X)
21810+#else
21811+#define ta(X) ((X) - __PAGE_OFFSET)
21812+#endif
21813+
21814 /*
21815 * References to members of the new_cpu_data structure.
21816 */
21817@@ -55,11 +61,7 @@
21818 * and small than max_low_pfn, otherwise will waste some page table entries
21819 */
21820
21821-#if PTRS_PER_PMD > 1
21822-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
21823-#else
21824-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
21825-#endif
21826+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
21827
21828 /* Number of possible pages in the lowmem region */
21829 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
21830@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
21831 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
21832
21833 /*
21834+ * Real beginning of normal "text" segment
21835+ */
21836+ENTRY(stext)
21837+ENTRY(_stext)
21838+
21839+/*
21840 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
21841 * %esi points to the real-mode code as a 32-bit pointer.
21842 * CS and DS must be 4 GB flat segments, but we don't depend on
21843@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
21844 * can.
21845 */
21846 __HEAD
21847+
21848+#ifdef CONFIG_PAX_KERNEXEC
21849+ jmp startup_32
21850+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
21851+.fill PAGE_SIZE-5,1,0xcc
21852+#endif
21853+
21854 ENTRY(startup_32)
21855 movl pa(stack_start),%ecx
21856
21857@@ -106,6 +121,59 @@ ENTRY(startup_32)
21858 2:
21859 leal -__PAGE_OFFSET(%ecx),%esp
21860
21861+#ifdef CONFIG_SMP
21862+ movl $pa(cpu_gdt_table),%edi
21863+ movl $__per_cpu_load,%eax
21864+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
21865+ rorl $16,%eax
21866+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
21867+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
21868+ movl $__per_cpu_end - 1,%eax
21869+ subl $__per_cpu_start,%eax
21870+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
21871+#endif
21872+
21873+#ifdef CONFIG_PAX_MEMORY_UDEREF
21874+ movl $NR_CPUS,%ecx
21875+ movl $pa(cpu_gdt_table),%edi
21876+1:
21877+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
21878+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
21879+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
21880+ addl $PAGE_SIZE_asm,%edi
21881+ loop 1b
21882+#endif
21883+
21884+#ifdef CONFIG_PAX_KERNEXEC
21885+ movl $pa(boot_gdt),%edi
21886+ movl $__LOAD_PHYSICAL_ADDR,%eax
21887+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
21888+ rorl $16,%eax
21889+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
21890+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
21891+ rorl $16,%eax
21892+
21893+ ljmp $(__BOOT_CS),$1f
21894+1:
21895+
21896+ movl $NR_CPUS,%ecx
21897+ movl $pa(cpu_gdt_table),%edi
21898+ addl $__PAGE_OFFSET,%eax
21899+1:
21900+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
21901+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
21902+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
21903+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
21904+ rorl $16,%eax
21905+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
21906+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
21907+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
21908+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
21909+ rorl $16,%eax
21910+ addl $PAGE_SIZE_asm,%edi
21911+ loop 1b
21912+#endif
21913+
21914 /*
21915 * Clear BSS first so that there are no surprises...
21916 */
21917@@ -201,8 +269,11 @@ ENTRY(startup_32)
21918 movl %eax, pa(max_pfn_mapped)
21919
21920 /* Do early initialization of the fixmap area */
21921- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
21922- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
21923+#ifdef CONFIG_COMPAT_VDSO
21924+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
21925+#else
21926+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
21927+#endif
21928 #else /* Not PAE */
21929
21930 page_pde_offset = (__PAGE_OFFSET >> 20);
21931@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
21932 movl %eax, pa(max_pfn_mapped)
21933
21934 /* Do early initialization of the fixmap area */
21935- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
21936- movl %eax,pa(initial_page_table+0xffc)
21937+#ifdef CONFIG_COMPAT_VDSO
21938+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
21939+#else
21940+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
21941+#endif
21942 #endif
21943
21944 #ifdef CONFIG_PARAVIRT
21945@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
21946 cmpl $num_subarch_entries, %eax
21947 jae bad_subarch
21948
21949- movl pa(subarch_entries)(,%eax,4), %eax
21950- subl $__PAGE_OFFSET, %eax
21951- jmp *%eax
21952+ jmp *pa(subarch_entries)(,%eax,4)
21953
21954 bad_subarch:
21955 WEAK(lguest_entry)
21956@@ -261,10 +333,10 @@ WEAK(xen_entry)
21957 __INITDATA
21958
21959 subarch_entries:
21960- .long default_entry /* normal x86/PC */
21961- .long lguest_entry /* lguest hypervisor */
21962- .long xen_entry /* Xen hypervisor */
21963- .long default_entry /* Moorestown MID */
21964+ .long ta(default_entry) /* normal x86/PC */
21965+ .long ta(lguest_entry) /* lguest hypervisor */
21966+ .long ta(xen_entry) /* Xen hypervisor */
21967+ .long ta(default_entry) /* Moorestown MID */
21968 num_subarch_entries = (. - subarch_entries) / 4
21969 .previous
21970 #else
21971@@ -355,6 +427,7 @@ default_entry:
21972 movl pa(mmu_cr4_features),%eax
21973 movl %eax,%cr4
21974
21975+#ifdef CONFIG_X86_PAE
21976 testb $X86_CR4_PAE, %al # check if PAE is enabled
21977 jz enable_paging
21978
21979@@ -383,6 +456,9 @@ default_entry:
21980 /* Make changes effective */
21981 wrmsr
21982
21983+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
21984+#endif
21985+
21986 enable_paging:
21987
21988 /*
21989@@ -451,14 +527,20 @@ is486:
21990 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
21991 movl %eax,%ss # after changing gdt.
21992
21993- movl $(__USER_DS),%eax # DS/ES contains default USER segment
21994+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
21995 movl %eax,%ds
21996 movl %eax,%es
21997
21998 movl $(__KERNEL_PERCPU), %eax
21999 movl %eax,%fs # set this cpu's percpu
22000
22001+#ifdef CONFIG_CC_STACKPROTECTOR
22002 movl $(__KERNEL_STACK_CANARY),%eax
22003+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22004+ movl $(__USER_DS),%eax
22005+#else
22006+ xorl %eax,%eax
22007+#endif
22008 movl %eax,%gs
22009
22010 xorl %eax,%eax # Clear LDT
22011@@ -534,8 +616,11 @@ setup_once:
22012 * relocation. Manually set base address in stack canary
22013 * segment descriptor.
22014 */
22015- movl $gdt_page,%eax
22016+ movl $cpu_gdt_table,%eax
22017 movl $stack_canary,%ecx
22018+#ifdef CONFIG_SMP
22019+ addl $__per_cpu_load,%ecx
22020+#endif
22021 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22022 shrl $16, %ecx
22023 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22024@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
22025 /* This is global to keep gas from relaxing the jumps */
22026 ENTRY(early_idt_handler)
22027 cld
22028- cmpl $2,%ss:early_recursion_flag
22029+ cmpl $1,%ss:early_recursion_flag
22030 je hlt_loop
22031 incl %ss:early_recursion_flag
22032
22033@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
22034 pushl (20+6*4)(%esp) /* trapno */
22035 pushl $fault_msg
22036 call printk
22037-#endif
22038 call dump_stack
22039+#endif
22040 hlt_loop:
22041 hlt
22042 jmp hlt_loop
22043@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
22044 /* This is the default interrupt "handler" :-) */
22045 ALIGN
22046 ignore_int:
22047- cld
22048 #ifdef CONFIG_PRINTK
22049+ cmpl $2,%ss:early_recursion_flag
22050+ je hlt_loop
22051+ incl %ss:early_recursion_flag
22052+ cld
22053 pushl %eax
22054 pushl %ecx
22055 pushl %edx
22056@@ -634,9 +722,6 @@ ignore_int:
22057 movl $(__KERNEL_DS),%eax
22058 movl %eax,%ds
22059 movl %eax,%es
22060- cmpl $2,early_recursion_flag
22061- je hlt_loop
22062- incl early_recursion_flag
22063 pushl 16(%esp)
22064 pushl 24(%esp)
22065 pushl 32(%esp)
22066@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
22067 /*
22068 * BSS section
22069 */
22070-__PAGE_ALIGNED_BSS
22071- .align PAGE_SIZE
22072 #ifdef CONFIG_X86_PAE
22073+.section .initial_pg_pmd,"a",@progbits
22074 initial_pg_pmd:
22075 .fill 1024*KPMDS,4,0
22076 #else
22077+.section .initial_page_table,"a",@progbits
22078 ENTRY(initial_page_table)
22079 .fill 1024,4,0
22080 #endif
22081+.section .initial_pg_fixmap,"a",@progbits
22082 initial_pg_fixmap:
22083 .fill 1024,4,0
22084+.section .empty_zero_page,"a",@progbits
22085 ENTRY(empty_zero_page)
22086 .fill 4096,1,0
22087+.section .swapper_pg_dir,"a",@progbits
22088 ENTRY(swapper_pg_dir)
22089+#ifdef CONFIG_X86_PAE
22090+ .fill 4,8,0
22091+#else
22092 .fill 1024,4,0
22093+#endif
22094+
22095+/*
22096+ * The IDT has to be page-aligned to simplify the Pentium
22097+ * F0 0F bug workaround.. We have a special link segment
22098+ * for this.
22099+ */
22100+.section .idt,"a",@progbits
22101+ENTRY(idt_table)
22102+ .fill 256,8,0
22103
22104 /*
22105 * This starts the data section.
22106 */
22107 #ifdef CONFIG_X86_PAE
22108-__PAGE_ALIGNED_DATA
22109- /* Page-aligned for the benefit of paravirt? */
22110- .align PAGE_SIZE
22111+.section .initial_page_table,"a",@progbits
22112 ENTRY(initial_page_table)
22113 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22114 # if KPMDS == 3
22115@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
22116 # error "Kernel PMDs should be 1, 2 or 3"
22117 # endif
22118 .align PAGE_SIZE /* needs to be page-sized too */
22119+
22120+#ifdef CONFIG_PAX_PER_CPU_PGD
22121+ENTRY(cpu_pgd)
22122+ .rept 2*NR_CPUS
22123+ .fill 4,8,0
22124+ .endr
22125+#endif
22126+
22127 #endif
22128
22129 .data
22130 .balign 4
22131 ENTRY(stack_start)
22132- .long init_thread_union+THREAD_SIZE
22133+ .long init_thread_union+THREAD_SIZE-8
22134
22135 __INITRODATA
22136 int_msg:
22137@@ -744,7 +851,7 @@ fault_msg:
22138 * segment size, and 32-bit linear address value:
22139 */
22140
22141- .data
22142+.section .rodata,"a",@progbits
22143 .globl boot_gdt_descr
22144 .globl idt_descr
22145
22146@@ -753,7 +860,7 @@ fault_msg:
22147 .word 0 # 32 bit align gdt_desc.address
22148 boot_gdt_descr:
22149 .word __BOOT_DS+7
22150- .long boot_gdt - __PAGE_OFFSET
22151+ .long pa(boot_gdt)
22152
22153 .word 0 # 32-bit align idt_desc.address
22154 idt_descr:
22155@@ -764,7 +871,7 @@ idt_descr:
22156 .word 0 # 32 bit align gdt_desc.address
22157 ENTRY(early_gdt_descr)
22158 .word GDT_ENTRIES*8-1
22159- .long gdt_page /* Overwritten for secondary CPUs */
22160+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22161
22162 /*
22163 * The boot_gdt must mirror the equivalent in setup.S and is
22164@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
22165 .align L1_CACHE_BYTES
22166 ENTRY(boot_gdt)
22167 .fill GDT_ENTRY_BOOT_CS,8,0
22168- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22169- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22170+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22171+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22172+
22173+ .align PAGE_SIZE_asm
22174+ENTRY(cpu_gdt_table)
22175+ .rept NR_CPUS
22176+ .quad 0x0000000000000000 /* NULL descriptor */
22177+ .quad 0x0000000000000000 /* 0x0b reserved */
22178+ .quad 0x0000000000000000 /* 0x13 reserved */
22179+ .quad 0x0000000000000000 /* 0x1b reserved */
22180+
22181+#ifdef CONFIG_PAX_KERNEXEC
22182+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22183+#else
22184+ .quad 0x0000000000000000 /* 0x20 unused */
22185+#endif
22186+
22187+ .quad 0x0000000000000000 /* 0x28 unused */
22188+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22189+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22190+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22191+ .quad 0x0000000000000000 /* 0x4b reserved */
22192+ .quad 0x0000000000000000 /* 0x53 reserved */
22193+ .quad 0x0000000000000000 /* 0x5b reserved */
22194+
22195+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22196+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22197+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22198+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22199+
22200+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22201+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22202+
22203+ /*
22204+ * Segments used for calling PnP BIOS have byte granularity.
22205+ * The code segments and data segments have fixed 64k limits,
22206+ * the transfer segment sizes are set at run time.
22207+ */
22208+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
22209+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
22210+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
22211+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
22212+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
22213+
22214+ /*
22215+ * The APM segments have byte granularity and their bases
22216+ * are set at run time. All have 64k limits.
22217+ */
22218+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
22219+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
22220+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
22221+
22222+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
22223+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
22224+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
22225+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
22226+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
22227+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
22228+
22229+ /* Be sure this is zeroed to avoid false validations in Xen */
22230+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
22231+ .endr
22232diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
22233index a836860..1b5c665 100644
22234--- a/arch/x86/kernel/head_64.S
22235+++ b/arch/x86/kernel/head_64.S
22236@@ -20,6 +20,8 @@
22237 #include <asm/processor-flags.h>
22238 #include <asm/percpu.h>
22239 #include <asm/nops.h>
22240+#include <asm/cpufeature.h>
22241+#include <asm/alternative-asm.h>
22242
22243 #ifdef CONFIG_PARAVIRT
22244 #include <asm/asm-offsets.h>
22245@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
22246 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
22247 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
22248 L3_START_KERNEL = pud_index(__START_KERNEL_map)
22249+L4_VMALLOC_START = pgd_index(VMALLOC_START)
22250+L3_VMALLOC_START = pud_index(VMALLOC_START)
22251+L4_VMALLOC_END = pgd_index(VMALLOC_END)
22252+L3_VMALLOC_END = pud_index(VMALLOC_END)
22253+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
22254+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
22255
22256 .text
22257 __HEAD
22258@@ -89,11 +97,23 @@ startup_64:
22259 * Fixup the physical addresses in the page table
22260 */
22261 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
22262+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
22263+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
22264+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
22265+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
22266+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
22267
22268- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
22269- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
22270+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
22271+#ifndef CONFIG_XEN
22272+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
22273+#endif
22274
22275- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
22276+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
22277+
22278+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
22279+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
22280+
22281+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
22282
22283 /*
22284 * Set up the identity mapping for the switchover. These
22285@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
22286 movq $(init_level4_pgt - __START_KERNEL_map), %rax
22287 1:
22288
22289- /* Enable PAE mode and PGE */
22290- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
22291+ /* Enable PAE mode and PSE/PGE */
22292+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
22293 movq %rcx, %cr4
22294
22295 /* Setup early boot stage 4 level pagetables. */
22296@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
22297 movl $MSR_EFER, %ecx
22298 rdmsr
22299 btsl $_EFER_SCE, %eax /* Enable System Call */
22300- btl $20,%edi /* No Execute supported? */
22301+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
22302 jnc 1f
22303 btsl $_EFER_NX, %eax
22304 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
22305+ leaq init_level4_pgt(%rip), %rdi
22306+#ifndef CONFIG_EFI
22307+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
22308+#endif
22309+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
22310+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
22311+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
22312+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
22313 1: wrmsr /* Make changes effective */
22314
22315 /* Setup cr0 */
22316@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
22317 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
22318 * address given in m16:64.
22319 */
22320+ pax_set_fptr_mask
22321 movq initial_code(%rip),%rax
22322 pushq $0 # fake return address to stop unwinder
22323 pushq $__KERNEL_CS # set correct cs
22324@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
22325 call dump_stack
22326 #ifdef CONFIG_KALLSYMS
22327 leaq early_idt_ripmsg(%rip),%rdi
22328- movq 40(%rsp),%rsi # %rip again
22329+ movq 88(%rsp),%rsi # %rip again
22330 call __print_symbol
22331 #endif
22332 #endif /* EARLY_PRINTK */
22333@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
22334 early_recursion_flag:
22335 .long 0
22336
22337+ .section .rodata,"a",@progbits
22338 #ifdef CONFIG_EARLY_PRINTK
22339 early_idt_msg:
22340 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
22341@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
22342 NEXT_PAGE(early_dynamic_pgts)
22343 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
22344
22345- .data
22346+ .section .rodata,"a",@progbits
22347
22348-#ifndef CONFIG_XEN
22349 NEXT_PAGE(init_level4_pgt)
22350- .fill 512,8,0
22351-#else
22352-NEXT_PAGE(init_level4_pgt)
22353- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
22354 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
22355 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
22356+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
22357+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
22358+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
22359+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
22360+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
22361+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
22362 .org init_level4_pgt + L4_START_KERNEL*8, 0
22363 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
22364 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
22365
22366+#ifdef CONFIG_PAX_PER_CPU_PGD
22367+NEXT_PAGE(cpu_pgd)
22368+ .rept 2*NR_CPUS
22369+ .fill 512,8,0
22370+ .endr
22371+#endif
22372+
22373 NEXT_PAGE(level3_ident_pgt)
22374 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
22375+#ifdef CONFIG_XEN
22376 .fill 511, 8, 0
22377+#else
22378+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
22379+ .fill 510,8,0
22380+#endif
22381+
22382+NEXT_PAGE(level3_vmalloc_start_pgt)
22383+ .fill 512,8,0
22384+
22385+NEXT_PAGE(level3_vmalloc_end_pgt)
22386+ .fill 512,8,0
22387+
22388+NEXT_PAGE(level3_vmemmap_pgt)
22389+ .fill L3_VMEMMAP_START,8,0
22390+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
22391+
22392 NEXT_PAGE(level2_ident_pgt)
22393- /* Since I easily can, map the first 1G.
22394+ /* Since I easily can, map the first 2G.
22395 * Don't set NX because code runs from these pages.
22396 */
22397- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
22398-#endif
22399+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
22400
22401 NEXT_PAGE(level3_kernel_pgt)
22402 .fill L3_START_KERNEL,8,0
22403@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
22404 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
22405 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
22406
22407+NEXT_PAGE(level2_vmemmap_pgt)
22408+ .fill 512,8,0
22409+
22410 NEXT_PAGE(level2_kernel_pgt)
22411 /*
22412 * 512 MB kernel mapping. We spend a full page on this pagetable
22413@@ -488,39 +544,70 @@ NEXT_PAGE(level2_kernel_pgt)
22414 KERNEL_IMAGE_SIZE/PMD_SIZE)
22415
22416 NEXT_PAGE(level2_fixmap_pgt)
22417- .fill 506,8,0
22418- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
22419- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
22420- .fill 5,8,0
22421+ .fill 507,8,0
22422+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
22423+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
22424+ .fill 4,8,0
22425
22426-NEXT_PAGE(level1_fixmap_pgt)
22427+NEXT_PAGE(level1_vsyscall_pgt)
22428 .fill 512,8,0
22429
22430 #undef PMDS
22431
22432- .data
22433+ .align PAGE_SIZE
22434+ENTRY(cpu_gdt_table)
22435+ .rept NR_CPUS
22436+ .quad 0x0000000000000000 /* NULL descriptor */
22437+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
22438+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
22439+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
22440+ .quad 0x00cffb000000ffff /* __USER32_CS */
22441+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
22442+ .quad 0x00affb000000ffff /* __USER_CS */
22443+
22444+#ifdef CONFIG_PAX_KERNEXEC
22445+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
22446+#else
22447+ .quad 0x0 /* unused */
22448+#endif
22449+
22450+ .quad 0,0 /* TSS */
22451+ .quad 0,0 /* LDT */
22452+ .quad 0,0,0 /* three TLS descriptors */
22453+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
22454+ /* asm/segment.h:GDT_ENTRIES must match this */
22455+
22456+#ifdef CONFIG_PAX_MEMORY_UDEREF
22457+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
22458+#else
22459+ .quad 0x0 /* unused */
22460+#endif
22461+
22462+ /* zero the remaining page */
22463+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
22464+ .endr
22465+
22466 .align 16
22467 .globl early_gdt_descr
22468 early_gdt_descr:
22469 .word GDT_ENTRIES*8-1
22470 early_gdt_descr_base:
22471- .quad INIT_PER_CPU_VAR(gdt_page)
22472+ .quad cpu_gdt_table
22473
22474 ENTRY(phys_base)
22475 /* This must match the first entry in level2_kernel_pgt */
22476 .quad 0x0000000000000000
22477
22478 #include "../../x86/xen/xen-head.S"
22479-
22480- .section .bss, "aw", @nobits
22481+
22482+ .section .rodata,"a",@progbits
22483+NEXT_PAGE(empty_zero_page)
22484+ .skip PAGE_SIZE
22485+
22486 .align PAGE_SIZE
22487 ENTRY(idt_table)
22488- .skip IDT_ENTRIES * 16
22489+ .fill 512,8,0
22490
22491 .align L1_CACHE_BYTES
22492 ENTRY(nmi_idt_table)
22493- .skip IDT_ENTRIES * 16
22494-
22495- __PAGE_ALIGNED_BSS
22496-NEXT_PAGE(empty_zero_page)
22497- .skip PAGE_SIZE
22498+ .fill 512,8,0
22499diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
22500index 0fa6912..37fce70 100644
22501--- a/arch/x86/kernel/i386_ksyms_32.c
22502+++ b/arch/x86/kernel/i386_ksyms_32.c
22503@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
22504 EXPORT_SYMBOL(cmpxchg8b_emu);
22505 #endif
22506
22507+EXPORT_SYMBOL_GPL(cpu_gdt_table);
22508+
22509 /* Networking helper routines. */
22510 EXPORT_SYMBOL(csum_partial_copy_generic);
22511+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
22512+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
22513
22514 EXPORT_SYMBOL(__get_user_1);
22515 EXPORT_SYMBOL(__get_user_2);
22516@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
22517
22518 EXPORT_SYMBOL(csum_partial);
22519 EXPORT_SYMBOL(empty_zero_page);
22520+
22521+#ifdef CONFIG_PAX_KERNEXEC
22522+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
22523+#endif
22524diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
22525index f7ea30d..6318acc 100644
22526--- a/arch/x86/kernel/i387.c
22527+++ b/arch/x86/kernel/i387.c
22528@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
22529 static inline bool interrupted_user_mode(void)
22530 {
22531 struct pt_regs *regs = get_irq_regs();
22532- return regs && user_mode_vm(regs);
22533+ return regs && user_mode(regs);
22534 }
22535
22536 /*
22537diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
22538index 9a5c460..84868423 100644
22539--- a/arch/x86/kernel/i8259.c
22540+++ b/arch/x86/kernel/i8259.c
22541@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
22542 static void make_8259A_irq(unsigned int irq)
22543 {
22544 disable_irq_nosync(irq);
22545- io_apic_irqs &= ~(1<<irq);
22546+ io_apic_irqs &= ~(1UL<<irq);
22547 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
22548 i8259A_chip.name);
22549 enable_irq(irq);
22550@@ -209,7 +209,7 @@ spurious_8259A_irq:
22551 "spurious 8259A interrupt: IRQ%d.\n", irq);
22552 spurious_irq_mask |= irqmask;
22553 }
22554- atomic_inc(&irq_err_count);
22555+ atomic_inc_unchecked(&irq_err_count);
22556 /*
22557 * Theoretically we do not have to handle this IRQ,
22558 * but in Linux this does not cause problems and is
22559@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
22560 /* (slave's support for AEOI in flat mode is to be investigated) */
22561 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
22562
22563+ pax_open_kernel();
22564 if (auto_eoi)
22565 /*
22566 * In AEOI mode we just have to mask the interrupt
22567 * when acking.
22568 */
22569- i8259A_chip.irq_mask_ack = disable_8259A_irq;
22570+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
22571 else
22572- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
22573+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
22574+ pax_close_kernel();
22575
22576 udelay(100); /* wait for 8259A to initialize */
22577
22578diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
22579index a979b5b..1d6db75 100644
22580--- a/arch/x86/kernel/io_delay.c
22581+++ b/arch/x86/kernel/io_delay.c
22582@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
22583 * Quirk table for systems that misbehave (lock up, etc.) if port
22584 * 0x80 is used:
22585 */
22586-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
22587+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
22588 {
22589 .callback = dmi_io_delay_0xed_port,
22590 .ident = "Compaq Presario V6000",
22591diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
22592index 4ddaf66..6292f4e 100644
22593--- a/arch/x86/kernel/ioport.c
22594+++ b/arch/x86/kernel/ioport.c
22595@@ -6,6 +6,7 @@
22596 #include <linux/sched.h>
22597 #include <linux/kernel.h>
22598 #include <linux/capability.h>
22599+#include <linux/security.h>
22600 #include <linux/errno.h>
22601 #include <linux/types.h>
22602 #include <linux/ioport.h>
22603@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
22604
22605 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
22606 return -EINVAL;
22607+#ifdef CONFIG_GRKERNSEC_IO
22608+ if (turn_on && grsec_disable_privio) {
22609+ gr_handle_ioperm();
22610+ return -EPERM;
22611+ }
22612+#endif
22613 if (turn_on && !capable(CAP_SYS_RAWIO))
22614 return -EPERM;
22615
22616@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
22617 * because the ->io_bitmap_max value must match the bitmap
22618 * contents:
22619 */
22620- tss = &per_cpu(init_tss, get_cpu());
22621+ tss = init_tss + get_cpu();
22622
22623 if (turn_on)
22624 bitmap_clear(t->io_bitmap_ptr, from, num);
22625@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
22626 return -EINVAL;
22627 /* Trying to gain more privileges? */
22628 if (level > old) {
22629+#ifdef CONFIG_GRKERNSEC_IO
22630+ if (grsec_disable_privio) {
22631+ gr_handle_iopl();
22632+ return -EPERM;
22633+ }
22634+#endif
22635 if (!capable(CAP_SYS_RAWIO))
22636 return -EPERM;
22637 }
22638diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
22639index ac0631d..ff7cb62 100644
22640--- a/arch/x86/kernel/irq.c
22641+++ b/arch/x86/kernel/irq.c
22642@@ -18,7 +18,7 @@
22643 #include <asm/mce.h>
22644 #include <asm/hw_irq.h>
22645
22646-atomic_t irq_err_count;
22647+atomic_unchecked_t irq_err_count;
22648
22649 /* Function pointer for generic interrupt vector handling */
22650 void (*x86_platform_ipi_callback)(void) = NULL;
22651@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
22652 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
22653 seq_printf(p, " Machine check polls\n");
22654 #endif
22655- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
22656+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
22657 #if defined(CONFIG_X86_IO_APIC)
22658- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
22659+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
22660 #endif
22661 return 0;
22662 }
22663@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
22664
22665 u64 arch_irq_stat(void)
22666 {
22667- u64 sum = atomic_read(&irq_err_count);
22668+ u64 sum = atomic_read_unchecked(&irq_err_count);
22669 return sum;
22670 }
22671
22672diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
22673index 344faf8..355f60d 100644
22674--- a/arch/x86/kernel/irq_32.c
22675+++ b/arch/x86/kernel/irq_32.c
22676@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
22677 __asm__ __volatile__("andl %%esp,%0" :
22678 "=r" (sp) : "0" (THREAD_SIZE - 1));
22679
22680- return sp < (sizeof(struct thread_info) + STACK_WARN);
22681+ return sp < STACK_WARN;
22682 }
22683
22684 static void print_stack_overflow(void)
22685@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
22686 * per-CPU IRQ handling contexts (thread information and stack)
22687 */
22688 union irq_ctx {
22689- struct thread_info tinfo;
22690- u32 stack[THREAD_SIZE/sizeof(u32)];
22691+ unsigned long previous_esp;
22692+ u32 stack[THREAD_SIZE/sizeof(u32)];
22693 } __attribute__((aligned(THREAD_SIZE)));
22694
22695 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
22696@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
22697 static inline int
22698 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
22699 {
22700- union irq_ctx *curctx, *irqctx;
22701+ union irq_ctx *irqctx;
22702 u32 *isp, arg1, arg2;
22703
22704- curctx = (union irq_ctx *) current_thread_info();
22705 irqctx = __this_cpu_read(hardirq_ctx);
22706
22707 /*
22708@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
22709 * handler) we can't do that and just have to keep using the
22710 * current stack (which is the irq stack already after all)
22711 */
22712- if (unlikely(curctx == irqctx))
22713+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
22714 return 0;
22715
22716 /* build the stack frame on the IRQ stack */
22717- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
22718- irqctx->tinfo.task = curctx->tinfo.task;
22719- irqctx->tinfo.previous_esp = current_stack_pointer;
22720+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
22721+ irqctx->previous_esp = current_stack_pointer;
22722
22723- /* Copy the preempt_count so that the [soft]irq checks work. */
22724- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
22725+#ifdef CONFIG_PAX_MEMORY_UDEREF
22726+ __set_fs(MAKE_MM_SEG(0));
22727+#endif
22728
22729 if (unlikely(overflow))
22730 call_on_stack(print_stack_overflow, isp);
22731@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
22732 : "0" (irq), "1" (desc), "2" (isp),
22733 "D" (desc->handle_irq)
22734 : "memory", "cc", "ecx");
22735+
22736+#ifdef CONFIG_PAX_MEMORY_UDEREF
22737+ __set_fs(current_thread_info()->addr_limit);
22738+#endif
22739+
22740 return 1;
22741 }
22742
22743@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
22744 */
22745 void __cpuinit irq_ctx_init(int cpu)
22746 {
22747- union irq_ctx *irqctx;
22748-
22749 if (per_cpu(hardirq_ctx, cpu))
22750 return;
22751
22752- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
22753- THREADINFO_GFP,
22754- THREAD_SIZE_ORDER));
22755- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
22756- irqctx->tinfo.cpu = cpu;
22757- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
22758- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
22759-
22760- per_cpu(hardirq_ctx, cpu) = irqctx;
22761-
22762- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
22763- THREADINFO_GFP,
22764- THREAD_SIZE_ORDER));
22765- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
22766- irqctx->tinfo.cpu = cpu;
22767- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
22768-
22769- per_cpu(softirq_ctx, cpu) = irqctx;
22770+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
22771+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
22772+
22773+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
22774+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
22775
22776 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
22777 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
22778@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
22779 asmlinkage void do_softirq(void)
22780 {
22781 unsigned long flags;
22782- struct thread_info *curctx;
22783 union irq_ctx *irqctx;
22784 u32 *isp;
22785
22786@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
22787 local_irq_save(flags);
22788
22789 if (local_softirq_pending()) {
22790- curctx = current_thread_info();
22791 irqctx = __this_cpu_read(softirq_ctx);
22792- irqctx->tinfo.task = curctx->task;
22793- irqctx->tinfo.previous_esp = current_stack_pointer;
22794+ irqctx->previous_esp = current_stack_pointer;
22795
22796 /* build the stack frame on the softirq stack */
22797- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
22798+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
22799+
22800+#ifdef CONFIG_PAX_MEMORY_UDEREF
22801+ __set_fs(MAKE_MM_SEG(0));
22802+#endif
22803
22804 call_on_stack(__do_softirq, isp);
22805+
22806+#ifdef CONFIG_PAX_MEMORY_UDEREF
22807+ __set_fs(current_thread_info()->addr_limit);
22808+#endif
22809+
22810 /*
22811 * Shouldn't happen, we returned above if in_interrupt():
22812 */
22813@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
22814 if (unlikely(!desc))
22815 return false;
22816
22817- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
22818+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
22819 if (unlikely(overflow))
22820 print_stack_overflow();
22821 desc->handle_irq(irq, desc);
22822diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
22823index d04d3ec..ea4b374 100644
22824--- a/arch/x86/kernel/irq_64.c
22825+++ b/arch/x86/kernel/irq_64.c
22826@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
22827 u64 estack_top, estack_bottom;
22828 u64 curbase = (u64)task_stack_page(current);
22829
22830- if (user_mode_vm(regs))
22831+ if (user_mode(regs))
22832 return;
22833
22834 if (regs->sp >= curbase + sizeof(struct thread_info) +
22835diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
22836index dc1404b..bbc43e7 100644
22837--- a/arch/x86/kernel/kdebugfs.c
22838+++ b/arch/x86/kernel/kdebugfs.c
22839@@ -27,7 +27,7 @@ struct setup_data_node {
22840 u32 len;
22841 };
22842
22843-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
22844+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
22845 size_t count, loff_t *ppos)
22846 {
22847 struct setup_data_node *node = file->private_data;
22848diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
22849index 836f832..a8bda67 100644
22850--- a/arch/x86/kernel/kgdb.c
22851+++ b/arch/x86/kernel/kgdb.c
22852@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
22853 #ifdef CONFIG_X86_32
22854 switch (regno) {
22855 case GDB_SS:
22856- if (!user_mode_vm(regs))
22857+ if (!user_mode(regs))
22858 *(unsigned long *)mem = __KERNEL_DS;
22859 break;
22860 case GDB_SP:
22861- if (!user_mode_vm(regs))
22862+ if (!user_mode(regs))
22863 *(unsigned long *)mem = kernel_stack_pointer(regs);
22864 break;
22865 case GDB_GS:
22866@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
22867 bp->attr.bp_addr = breakinfo[breakno].addr;
22868 bp->attr.bp_len = breakinfo[breakno].len;
22869 bp->attr.bp_type = breakinfo[breakno].type;
22870- info->address = breakinfo[breakno].addr;
22871+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
22872+ info->address = ktla_ktva(breakinfo[breakno].addr);
22873+ else
22874+ info->address = breakinfo[breakno].addr;
22875 info->len = breakinfo[breakno].len;
22876 info->type = breakinfo[breakno].type;
22877 val = arch_install_hw_breakpoint(bp);
22878@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
22879 case 'k':
22880 /* clear the trace bit */
22881 linux_regs->flags &= ~X86_EFLAGS_TF;
22882- atomic_set(&kgdb_cpu_doing_single_step, -1);
22883+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
22884
22885 /* set the trace bit if we're stepping */
22886 if (remcomInBuffer[0] == 's') {
22887 linux_regs->flags |= X86_EFLAGS_TF;
22888- atomic_set(&kgdb_cpu_doing_single_step,
22889+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
22890 raw_smp_processor_id());
22891 }
22892
22893@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
22894
22895 switch (cmd) {
22896 case DIE_DEBUG:
22897- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
22898+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
22899 if (user_mode(regs))
22900 return single_step_cont(regs, args);
22901 break;
22902@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
22903 #endif /* CONFIG_DEBUG_RODATA */
22904
22905 bpt->type = BP_BREAKPOINT;
22906- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
22907+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
22908 BREAK_INSTR_SIZE);
22909 if (err)
22910 return err;
22911- err = probe_kernel_write((char *)bpt->bpt_addr,
22912+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
22913 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
22914 #ifdef CONFIG_DEBUG_RODATA
22915 if (!err)
22916@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
22917 return -EBUSY;
22918 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
22919 BREAK_INSTR_SIZE);
22920- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
22921+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
22922 if (err)
22923 return err;
22924 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
22925@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
22926 if (mutex_is_locked(&text_mutex))
22927 goto knl_write;
22928 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
22929- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
22930+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
22931 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
22932 goto knl_write;
22933 return err;
22934 knl_write:
22935 #endif /* CONFIG_DEBUG_RODATA */
22936- return probe_kernel_write((char *)bpt->bpt_addr,
22937+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
22938 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
22939 }
22940
22941diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
22942index 211bce4..6e2580a 100644
22943--- a/arch/x86/kernel/kprobes/core.c
22944+++ b/arch/x86/kernel/kprobes/core.c
22945@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
22946 s32 raddr;
22947 } __packed *insn;
22948
22949- insn = (struct __arch_relative_insn *)from;
22950+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
22951+
22952+ pax_open_kernel();
22953 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
22954 insn->op = op;
22955+ pax_close_kernel();
22956 }
22957
22958 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
22959@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
22960 kprobe_opcode_t opcode;
22961 kprobe_opcode_t *orig_opcodes = opcodes;
22962
22963- if (search_exception_tables((unsigned long)opcodes))
22964+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
22965 return 0; /* Page fault may occur on this address. */
22966
22967 retry:
22968@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
22969 * for the first byte, we can recover the original instruction
22970 * from it and kp->opcode.
22971 */
22972- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
22973+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
22974 buf[0] = kp->opcode;
22975- return (unsigned long)buf;
22976+ return ktva_ktla((unsigned long)buf);
22977 }
22978
22979 /*
22980@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
22981 /* Another subsystem puts a breakpoint, failed to recover */
22982 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
22983 return 0;
22984+ pax_open_kernel();
22985 memcpy(dest, insn.kaddr, insn.length);
22986+ pax_close_kernel();
22987
22988 #ifdef CONFIG_X86_64
22989 if (insn_rip_relative(&insn)) {
22990@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
22991 return 0;
22992 }
22993 disp = (u8 *) dest + insn_offset_displacement(&insn);
22994+ pax_open_kernel();
22995 *(s32 *) disp = (s32) newdisp;
22996+ pax_close_kernel();
22997 }
22998 #endif
22999 return insn.length;
23000@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23001 * nor set current_kprobe, because it doesn't use single
23002 * stepping.
23003 */
23004- regs->ip = (unsigned long)p->ainsn.insn;
23005+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23006 preempt_enable_no_resched();
23007 return;
23008 }
23009@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23010 regs->flags &= ~X86_EFLAGS_IF;
23011 /* single step inline if the instruction is an int3 */
23012 if (p->opcode == BREAKPOINT_INSTRUCTION)
23013- regs->ip = (unsigned long)p->addr;
23014+ regs->ip = ktla_ktva((unsigned long)p->addr);
23015 else
23016- regs->ip = (unsigned long)p->ainsn.insn;
23017+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23018 }
23019
23020 /*
23021@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23022 setup_singlestep(p, regs, kcb, 0);
23023 return 1;
23024 }
23025- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23026+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23027 /*
23028 * The breakpoint instruction was removed right
23029 * after we hit it. Another cpu has removed
23030@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23031 " movq %rax, 152(%rsp)\n"
23032 RESTORE_REGS_STRING
23033 " popfq\n"
23034+#ifdef KERNEXEC_PLUGIN
23035+ " btsq $63,(%rsp)\n"
23036+#endif
23037 #else
23038 " pushf\n"
23039 SAVE_REGS_STRING
23040@@ -779,7 +789,7 @@ static void __kprobes
23041 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23042 {
23043 unsigned long *tos = stack_addr(regs);
23044- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23045+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23046 unsigned long orig_ip = (unsigned long)p->addr;
23047 kprobe_opcode_t *insn = p->ainsn.insn;
23048
23049@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23050 struct die_args *args = data;
23051 int ret = NOTIFY_DONE;
23052
23053- if (args->regs && user_mode_vm(args->regs))
23054+ if (args->regs && user_mode(args->regs))
23055 return ret;
23056
23057 switch (val) {
23058diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23059index 76dc6f0..66bdfc3 100644
23060--- a/arch/x86/kernel/kprobes/opt.c
23061+++ b/arch/x86/kernel/kprobes/opt.c
23062@@ -79,6 +79,7 @@ found:
23063 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23064 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23065 {
23066+ pax_open_kernel();
23067 #ifdef CONFIG_X86_64
23068 *addr++ = 0x48;
23069 *addr++ = 0xbf;
23070@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23071 *addr++ = 0xb8;
23072 #endif
23073 *(unsigned long *)addr = val;
23074+ pax_close_kernel();
23075 }
23076
23077 static void __used __kprobes kprobes_optinsn_template_holder(void)
23078@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23079 * Verify if the address gap is in 2GB range, because this uses
23080 * a relative jump.
23081 */
23082- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23083+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23084 if (abs(rel) > 0x7fffffff)
23085 return -ERANGE;
23086
23087@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23088 op->optinsn.size = ret;
23089
23090 /* Copy arch-dep-instance from template */
23091- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23092+ pax_open_kernel();
23093+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23094+ pax_close_kernel();
23095
23096 /* Set probe information */
23097 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23098
23099 /* Set probe function call */
23100- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23101+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23102
23103 /* Set returning jmp instruction at the tail of out-of-line buffer */
23104- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23105+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23106 (u8 *)op->kp.addr + op->optinsn.size);
23107
23108 flush_icache_range((unsigned long) buf,
23109@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23110 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23111
23112 /* Backup instructions which will be replaced by jump address */
23113- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23114+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23115 RELATIVE_ADDR_SIZE);
23116
23117 insn_buf[0] = RELATIVEJUMP_OPCODE;
23118@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23119 /* This kprobe is really able to run optimized path. */
23120 op = container_of(p, struct optimized_kprobe, kp);
23121 /* Detour through copied instructions */
23122- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23123+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23124 if (!reenter)
23125 reset_current_kprobe();
23126 preempt_enable_no_resched();
23127diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
23128index cd6d9a5..16245a4 100644
23129--- a/arch/x86/kernel/kvm.c
23130+++ b/arch/x86/kernel/kvm.c
23131@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
23132 return NOTIFY_OK;
23133 }
23134
23135-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
23136+static struct notifier_block kvm_cpu_notifier = {
23137 .notifier_call = kvm_cpu_notify,
23138 };
23139 #endif
23140diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23141index ebc9873..1b9724b 100644
23142--- a/arch/x86/kernel/ldt.c
23143+++ b/arch/x86/kernel/ldt.c
23144@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23145 if (reload) {
23146 #ifdef CONFIG_SMP
23147 preempt_disable();
23148- load_LDT(pc);
23149+ load_LDT_nolock(pc);
23150 if (!cpumask_equal(mm_cpumask(current->mm),
23151 cpumask_of(smp_processor_id())))
23152 smp_call_function(flush_ldt, current->mm, 1);
23153 preempt_enable();
23154 #else
23155- load_LDT(pc);
23156+ load_LDT_nolock(pc);
23157 #endif
23158 }
23159 if (oldsize) {
23160@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23161 return err;
23162
23163 for (i = 0; i < old->size; i++)
23164- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23165+ write_ldt_entry(new->ldt, i, old->ldt + i);
23166 return 0;
23167 }
23168
23169@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23170 retval = copy_ldt(&mm->context, &old_mm->context);
23171 mutex_unlock(&old_mm->context.lock);
23172 }
23173+
23174+ if (tsk == current) {
23175+ mm->context.vdso = 0;
23176+
23177+#ifdef CONFIG_X86_32
23178+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23179+ mm->context.user_cs_base = 0UL;
23180+ mm->context.user_cs_limit = ~0UL;
23181+
23182+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23183+ cpus_clear(mm->context.cpu_user_cs_mask);
23184+#endif
23185+
23186+#endif
23187+#endif
23188+
23189+ }
23190+
23191 return retval;
23192 }
23193
23194@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23195 }
23196 }
23197
23198+#ifdef CONFIG_PAX_SEGMEXEC
23199+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23200+ error = -EINVAL;
23201+ goto out_unlock;
23202+ }
23203+#endif
23204+
23205 fill_ldt(&ldt, &ldt_info);
23206 if (oldmode)
23207 ldt.avl = 0;
23208diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23209index 5b19e4d..6476a76 100644
23210--- a/arch/x86/kernel/machine_kexec_32.c
23211+++ b/arch/x86/kernel/machine_kexec_32.c
23212@@ -26,7 +26,7 @@
23213 #include <asm/cacheflush.h>
23214 #include <asm/debugreg.h>
23215
23216-static void set_idt(void *newidt, __u16 limit)
23217+static void set_idt(struct desc_struct *newidt, __u16 limit)
23218 {
23219 struct desc_ptr curidt;
23220
23221@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23222 }
23223
23224
23225-static void set_gdt(void *newgdt, __u16 limit)
23226+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23227 {
23228 struct desc_ptr curgdt;
23229
23230@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
23231 }
23232
23233 control_page = page_address(image->control_code_page);
23234- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
23235+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
23236
23237 relocate_kernel_ptr = control_page;
23238 page_list[PA_CONTROL_PAGE] = __pa(control_page);
23239diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
23240index 22db92b..d546bec 100644
23241--- a/arch/x86/kernel/microcode_core.c
23242+++ b/arch/x86/kernel/microcode_core.c
23243@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
23244 return NOTIFY_OK;
23245 }
23246
23247-static struct notifier_block __refdata mc_cpu_notifier = {
23248+static struct notifier_block mc_cpu_notifier = {
23249 .notifier_call = mc_cpu_callback,
23250 };
23251
23252diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
23253index 5fb2ceb..3ae90bb 100644
23254--- a/arch/x86/kernel/microcode_intel.c
23255+++ b/arch/x86/kernel/microcode_intel.c
23256@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
23257
23258 static int get_ucode_user(void *to, const void *from, size_t n)
23259 {
23260- return copy_from_user(to, from, n);
23261+ return copy_from_user(to, (const void __force_user *)from, n);
23262 }
23263
23264 static enum ucode_state
23265 request_microcode_user(int cpu, const void __user *buf, size_t size)
23266 {
23267- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
23268+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
23269 }
23270
23271 static void microcode_fini_cpu(int cpu)
23272diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
23273index 216a4d7..228255a 100644
23274--- a/arch/x86/kernel/module.c
23275+++ b/arch/x86/kernel/module.c
23276@@ -43,15 +43,60 @@ do { \
23277 } while (0)
23278 #endif
23279
23280-void *module_alloc(unsigned long size)
23281+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
23282 {
23283- if (PAGE_ALIGN(size) > MODULES_LEN)
23284+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
23285 return NULL;
23286 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
23287- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
23288+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
23289 -1, __builtin_return_address(0));
23290 }
23291
23292+void *module_alloc(unsigned long size)
23293+{
23294+
23295+#ifdef CONFIG_PAX_KERNEXEC
23296+ return __module_alloc(size, PAGE_KERNEL);
23297+#else
23298+ return __module_alloc(size, PAGE_KERNEL_EXEC);
23299+#endif
23300+
23301+}
23302+
23303+#ifdef CONFIG_PAX_KERNEXEC
23304+#ifdef CONFIG_X86_32
23305+void *module_alloc_exec(unsigned long size)
23306+{
23307+ struct vm_struct *area;
23308+
23309+ if (size == 0)
23310+ return NULL;
23311+
23312+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
23313+ return area ? area->addr : NULL;
23314+}
23315+EXPORT_SYMBOL(module_alloc_exec);
23316+
23317+void module_free_exec(struct module *mod, void *module_region)
23318+{
23319+ vunmap(module_region);
23320+}
23321+EXPORT_SYMBOL(module_free_exec);
23322+#else
23323+void module_free_exec(struct module *mod, void *module_region)
23324+{
23325+ module_free(mod, module_region);
23326+}
23327+EXPORT_SYMBOL(module_free_exec);
23328+
23329+void *module_alloc_exec(unsigned long size)
23330+{
23331+ return __module_alloc(size, PAGE_KERNEL_RX);
23332+}
23333+EXPORT_SYMBOL(module_alloc_exec);
23334+#endif
23335+#endif
23336+
23337 #ifdef CONFIG_X86_32
23338 int apply_relocate(Elf32_Shdr *sechdrs,
23339 const char *strtab,
23340@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
23341 unsigned int i;
23342 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
23343 Elf32_Sym *sym;
23344- uint32_t *location;
23345+ uint32_t *plocation, location;
23346
23347 DEBUGP("Applying relocate section %u to %u\n",
23348 relsec, sechdrs[relsec].sh_info);
23349 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
23350 /* This is where to make the change */
23351- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
23352- + rel[i].r_offset;
23353+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
23354+ location = (uint32_t)plocation;
23355+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
23356+ plocation = ktla_ktva((void *)plocation);
23357 /* This is the symbol it is referring to. Note that all
23358 undefined symbols have been resolved. */
23359 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
23360@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
23361 switch (ELF32_R_TYPE(rel[i].r_info)) {
23362 case R_386_32:
23363 /* We add the value into the location given */
23364- *location += sym->st_value;
23365+ pax_open_kernel();
23366+ *plocation += sym->st_value;
23367+ pax_close_kernel();
23368 break;
23369 case R_386_PC32:
23370 /* Add the value, subtract its position */
23371- *location += sym->st_value - (uint32_t)location;
23372+ pax_open_kernel();
23373+ *plocation += sym->st_value - location;
23374+ pax_close_kernel();
23375 break;
23376 default:
23377 pr_err("%s: Unknown relocation: %u\n",
23378@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
23379 case R_X86_64_NONE:
23380 break;
23381 case R_X86_64_64:
23382+ pax_open_kernel();
23383 *(u64 *)loc = val;
23384+ pax_close_kernel();
23385 break;
23386 case R_X86_64_32:
23387+ pax_open_kernel();
23388 *(u32 *)loc = val;
23389+ pax_close_kernel();
23390 if (val != *(u32 *)loc)
23391 goto overflow;
23392 break;
23393 case R_X86_64_32S:
23394+ pax_open_kernel();
23395 *(s32 *)loc = val;
23396+ pax_close_kernel();
23397 if ((s64)val != *(s32 *)loc)
23398 goto overflow;
23399 break;
23400 case R_X86_64_PC32:
23401 val -= (u64)loc;
23402+ pax_open_kernel();
23403 *(u32 *)loc = val;
23404+ pax_close_kernel();
23405+
23406 #if 0
23407 if ((s64)val != *(s32 *)loc)
23408 goto overflow;
23409diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
23410index ce13049..e2e9c3c 100644
23411--- a/arch/x86/kernel/msr.c
23412+++ b/arch/x86/kernel/msr.c
23413@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
23414 return notifier_from_errno(err);
23415 }
23416
23417-static struct notifier_block __refdata msr_class_cpu_notifier = {
23418+static struct notifier_block msr_class_cpu_notifier = {
23419 .notifier_call = msr_class_cpu_callback,
23420 };
23421
23422diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
23423index 6030805..2d33f21 100644
23424--- a/arch/x86/kernel/nmi.c
23425+++ b/arch/x86/kernel/nmi.c
23426@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
23427 return handled;
23428 }
23429
23430-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
23431+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
23432 {
23433 struct nmi_desc *desc = nmi_to_desc(type);
23434 unsigned long flags;
23435@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
23436 * event confuses some handlers (kdump uses this flag)
23437 */
23438 if (action->flags & NMI_FLAG_FIRST)
23439- list_add_rcu(&action->list, &desc->head);
23440+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
23441 else
23442- list_add_tail_rcu(&action->list, &desc->head);
23443+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
23444
23445 spin_unlock_irqrestore(&desc->lock, flags);
23446 return 0;
23447@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
23448 if (!strcmp(n->name, name)) {
23449 WARN(in_nmi(),
23450 "Trying to free NMI (%s) from NMI context!\n", n->name);
23451- list_del_rcu(&n->list);
23452+ pax_list_del_rcu((struct list_head *)&n->list);
23453 break;
23454 }
23455 }
23456@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
23457 dotraplinkage notrace __kprobes void
23458 do_nmi(struct pt_regs *regs, long error_code)
23459 {
23460+
23461+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23462+ if (!user_mode(regs)) {
23463+ unsigned long cs = regs->cs & 0xFFFF;
23464+ unsigned long ip = ktva_ktla(regs->ip);
23465+
23466+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
23467+ regs->ip = ip;
23468+ }
23469+#endif
23470+
23471 nmi_nesting_preprocess(regs);
23472
23473 nmi_enter();
23474diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
23475index 6d9582e..f746287 100644
23476--- a/arch/x86/kernel/nmi_selftest.c
23477+++ b/arch/x86/kernel/nmi_selftest.c
23478@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
23479 {
23480 /* trap all the unknown NMIs we may generate */
23481 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
23482- __initdata);
23483+ __initconst);
23484 }
23485
23486 static void __init cleanup_nmi_testsuite(void)
23487@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
23488 unsigned long timeout;
23489
23490 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
23491- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
23492+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
23493 nmi_fail = FAILURE;
23494 return;
23495 }
23496diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
23497index 676b8c7..870ba04 100644
23498--- a/arch/x86/kernel/paravirt-spinlocks.c
23499+++ b/arch/x86/kernel/paravirt-spinlocks.c
23500@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
23501 arch_spin_lock(lock);
23502 }
23503
23504-struct pv_lock_ops pv_lock_ops = {
23505+struct pv_lock_ops pv_lock_ops __read_only = {
23506 #ifdef CONFIG_SMP
23507 .spin_is_locked = __ticket_spin_is_locked,
23508 .spin_is_contended = __ticket_spin_is_contended,
23509diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
23510index cd6de64..27c6af0 100644
23511--- a/arch/x86/kernel/paravirt.c
23512+++ b/arch/x86/kernel/paravirt.c
23513@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
23514 {
23515 return x;
23516 }
23517+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23518+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
23519+#endif
23520
23521 void __init default_banner(void)
23522 {
23523@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
23524 if (opfunc == NULL)
23525 /* If there's no function, patch it with a ud2a (BUG) */
23526 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
23527- else if (opfunc == _paravirt_nop)
23528+ else if (opfunc == (void *)_paravirt_nop)
23529 /* If the operation is a nop, then nop the callsite */
23530 ret = paravirt_patch_nop();
23531
23532 /* identity functions just return their single argument */
23533- else if (opfunc == _paravirt_ident_32)
23534+ else if (opfunc == (void *)_paravirt_ident_32)
23535 ret = paravirt_patch_ident_32(insnbuf, len);
23536- else if (opfunc == _paravirt_ident_64)
23537+ else if (opfunc == (void *)_paravirt_ident_64)
23538 ret = paravirt_patch_ident_64(insnbuf, len);
23539+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23540+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
23541+ ret = paravirt_patch_ident_64(insnbuf, len);
23542+#endif
23543
23544 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
23545 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
23546@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
23547 if (insn_len > len || start == NULL)
23548 insn_len = len;
23549 else
23550- memcpy(insnbuf, start, insn_len);
23551+ memcpy(insnbuf, ktla_ktva(start), insn_len);
23552
23553 return insn_len;
23554 }
23555@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
23556 return this_cpu_read(paravirt_lazy_mode);
23557 }
23558
23559-struct pv_info pv_info = {
23560+struct pv_info pv_info __read_only = {
23561 .name = "bare hardware",
23562 .paravirt_enabled = 0,
23563 .kernel_rpl = 0,
23564@@ -315,16 +322,16 @@ struct pv_info pv_info = {
23565 #endif
23566 };
23567
23568-struct pv_init_ops pv_init_ops = {
23569+struct pv_init_ops pv_init_ops __read_only = {
23570 .patch = native_patch,
23571 };
23572
23573-struct pv_time_ops pv_time_ops = {
23574+struct pv_time_ops pv_time_ops __read_only = {
23575 .sched_clock = native_sched_clock,
23576 .steal_clock = native_steal_clock,
23577 };
23578
23579-struct pv_irq_ops pv_irq_ops = {
23580+struct pv_irq_ops pv_irq_ops __read_only = {
23581 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
23582 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
23583 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
23584@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
23585 #endif
23586 };
23587
23588-struct pv_cpu_ops pv_cpu_ops = {
23589+struct pv_cpu_ops pv_cpu_ops __read_only = {
23590 .cpuid = native_cpuid,
23591 .get_debugreg = native_get_debugreg,
23592 .set_debugreg = native_set_debugreg,
23593@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
23594 .end_context_switch = paravirt_nop,
23595 };
23596
23597-struct pv_apic_ops pv_apic_ops = {
23598+struct pv_apic_ops pv_apic_ops __read_only= {
23599 #ifdef CONFIG_X86_LOCAL_APIC
23600 .startup_ipi_hook = paravirt_nop,
23601 #endif
23602 };
23603
23604-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
23605+#ifdef CONFIG_X86_32
23606+#ifdef CONFIG_X86_PAE
23607+/* 64-bit pagetable entries */
23608+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
23609+#else
23610 /* 32-bit pagetable entries */
23611 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
23612+#endif
23613 #else
23614 /* 64-bit pagetable entries */
23615 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
23616 #endif
23617
23618-struct pv_mmu_ops pv_mmu_ops = {
23619+struct pv_mmu_ops pv_mmu_ops __read_only = {
23620
23621 .read_cr2 = native_read_cr2,
23622 .write_cr2 = native_write_cr2,
23623@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
23624 .make_pud = PTE_IDENT,
23625
23626 .set_pgd = native_set_pgd,
23627+ .set_pgd_batched = native_set_pgd_batched,
23628 #endif
23629 #endif /* PAGETABLE_LEVELS >= 3 */
23630
23631@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
23632 },
23633
23634 .set_fixmap = native_set_fixmap,
23635+
23636+#ifdef CONFIG_PAX_KERNEXEC
23637+ .pax_open_kernel = native_pax_open_kernel,
23638+ .pax_close_kernel = native_pax_close_kernel,
23639+#endif
23640+
23641 };
23642
23643 EXPORT_SYMBOL_GPL(pv_time_ops);
23644diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
23645index 299d493..2ccb0ee 100644
23646--- a/arch/x86/kernel/pci-calgary_64.c
23647+++ b/arch/x86/kernel/pci-calgary_64.c
23648@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
23649 tce_space = be64_to_cpu(readq(target));
23650 tce_space = tce_space & TAR_SW_BITS;
23651
23652- tce_space = tce_space & (~specified_table_size);
23653+ tce_space = tce_space & (~(unsigned long)specified_table_size);
23654 info->tce_space = (u64 *)__va(tce_space);
23655 }
23656 }
23657diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
23658index 35ccf75..7a15747 100644
23659--- a/arch/x86/kernel/pci-iommu_table.c
23660+++ b/arch/x86/kernel/pci-iommu_table.c
23661@@ -2,7 +2,7 @@
23662 #include <asm/iommu_table.h>
23663 #include <linux/string.h>
23664 #include <linux/kallsyms.h>
23665-
23666+#include <linux/sched.h>
23667
23668 #define DEBUG 1
23669
23670diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
23671index 6c483ba..d10ce2f 100644
23672--- a/arch/x86/kernel/pci-swiotlb.c
23673+++ b/arch/x86/kernel/pci-swiotlb.c
23674@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
23675 void *vaddr, dma_addr_t dma_addr,
23676 struct dma_attrs *attrs)
23677 {
23678- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
23679+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
23680 }
23681
23682 static struct dma_map_ops swiotlb_dma_ops = {
23683diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
23684index 81a5f5e..20f8b58 100644
23685--- a/arch/x86/kernel/process.c
23686+++ b/arch/x86/kernel/process.c
23687@@ -36,7 +36,8 @@
23688 * section. Since TSS's are completely CPU-local, we want them
23689 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
23690 */
23691-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
23692+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
23693+EXPORT_SYMBOL(init_tss);
23694
23695 #ifdef CONFIG_X86_64
23696 static DEFINE_PER_CPU(unsigned char, is_idle);
23697@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
23698 task_xstate_cachep =
23699 kmem_cache_create("task_xstate", xstate_size,
23700 __alignof__(union thread_xstate),
23701- SLAB_PANIC | SLAB_NOTRACK, NULL);
23702+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
23703 }
23704
23705 /*
23706@@ -105,7 +106,7 @@ void exit_thread(void)
23707 unsigned long *bp = t->io_bitmap_ptr;
23708
23709 if (bp) {
23710- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
23711+ struct tss_struct *tss = init_tss + get_cpu();
23712
23713 t->io_bitmap_ptr = NULL;
23714 clear_thread_flag(TIF_IO_BITMAP);
23715@@ -125,6 +126,9 @@ void flush_thread(void)
23716 {
23717 struct task_struct *tsk = current;
23718
23719+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
23720+ loadsegment(gs, 0);
23721+#endif
23722 flush_ptrace_hw_breakpoint(tsk);
23723 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
23724 drop_init_fpu(tsk);
23725@@ -271,7 +275,7 @@ static void __exit_idle(void)
23726 void exit_idle(void)
23727 {
23728 /* idle loop has pid 0 */
23729- if (current->pid)
23730+ if (task_pid_nr(current))
23731 return;
23732 __exit_idle();
23733 }
23734@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
23735 return ret;
23736 }
23737 #endif
23738-void stop_this_cpu(void *dummy)
23739+__noreturn void stop_this_cpu(void *dummy)
23740 {
23741 local_irq_disable();
23742 /*
23743@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
23744 }
23745 early_param("idle", idle_setup);
23746
23747-unsigned long arch_align_stack(unsigned long sp)
23748+#ifdef CONFIG_PAX_RANDKSTACK
23749+void pax_randomize_kstack(struct pt_regs *regs)
23750 {
23751- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
23752- sp -= get_random_int() % 8192;
23753- return sp & ~0xf;
23754-}
23755+ struct thread_struct *thread = &current->thread;
23756+ unsigned long time;
23757
23758-unsigned long arch_randomize_brk(struct mm_struct *mm)
23759-{
23760- unsigned long range_end = mm->brk + 0x02000000;
23761- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
23762-}
23763+ if (!randomize_va_space)
23764+ return;
23765+
23766+ if (v8086_mode(regs))
23767+ return;
23768
23769+ rdtscl(time);
23770+
23771+ /* P4 seems to return a 0 LSB, ignore it */
23772+#ifdef CONFIG_MPENTIUM4
23773+ time &= 0x3EUL;
23774+ time <<= 2;
23775+#elif defined(CONFIG_X86_64)
23776+ time &= 0xFUL;
23777+ time <<= 4;
23778+#else
23779+ time &= 0x1FUL;
23780+ time <<= 3;
23781+#endif
23782+
23783+ thread->sp0 ^= time;
23784+ load_sp0(init_tss + smp_processor_id(), thread);
23785+
23786+#ifdef CONFIG_X86_64
23787+ this_cpu_write(kernel_stack, thread->sp0);
23788+#endif
23789+}
23790+#endif
23791diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
23792index 7305f7d..22f73d6 100644
23793--- a/arch/x86/kernel/process_32.c
23794+++ b/arch/x86/kernel/process_32.c
23795@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
23796 unsigned long thread_saved_pc(struct task_struct *tsk)
23797 {
23798 return ((unsigned long *)tsk->thread.sp)[3];
23799+//XXX return tsk->thread.eip;
23800 }
23801
23802 void __show_regs(struct pt_regs *regs, int all)
23803@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
23804 unsigned long sp;
23805 unsigned short ss, gs;
23806
23807- if (user_mode_vm(regs)) {
23808+ if (user_mode(regs)) {
23809 sp = regs->sp;
23810 ss = regs->ss & 0xffff;
23811- gs = get_user_gs(regs);
23812 } else {
23813 sp = kernel_stack_pointer(regs);
23814 savesegment(ss, ss);
23815- savesegment(gs, gs);
23816 }
23817+ gs = get_user_gs(regs);
23818
23819 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
23820 (u16)regs->cs, regs->ip, regs->flags,
23821- smp_processor_id());
23822+ raw_smp_processor_id());
23823 print_symbol("EIP is at %s\n", regs->ip);
23824
23825 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
23826@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
23827 int copy_thread(unsigned long clone_flags, unsigned long sp,
23828 unsigned long arg, struct task_struct *p)
23829 {
23830- struct pt_regs *childregs = task_pt_regs(p);
23831+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
23832 struct task_struct *tsk;
23833 int err;
23834
23835 p->thread.sp = (unsigned long) childregs;
23836 p->thread.sp0 = (unsigned long) (childregs+1);
23837+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
23838
23839 if (unlikely(p->flags & PF_KTHREAD)) {
23840 /* kernel thread */
23841 memset(childregs, 0, sizeof(struct pt_regs));
23842 p->thread.ip = (unsigned long) ret_from_kernel_thread;
23843- task_user_gs(p) = __KERNEL_STACK_CANARY;
23844- childregs->ds = __USER_DS;
23845- childregs->es = __USER_DS;
23846+ savesegment(gs, childregs->gs);
23847+ childregs->ds = __KERNEL_DS;
23848+ childregs->es = __KERNEL_DS;
23849 childregs->fs = __KERNEL_PERCPU;
23850 childregs->bx = sp; /* function */
23851 childregs->bp = arg;
23852@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23853 struct thread_struct *prev = &prev_p->thread,
23854 *next = &next_p->thread;
23855 int cpu = smp_processor_id();
23856- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23857+ struct tss_struct *tss = init_tss + cpu;
23858 fpu_switch_t fpu;
23859
23860 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
23861@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23862 */
23863 lazy_save_gs(prev->gs);
23864
23865+#ifdef CONFIG_PAX_MEMORY_UDEREF
23866+ __set_fs(task_thread_info(next_p)->addr_limit);
23867+#endif
23868+
23869 /*
23870 * Load the per-thread Thread-Local Storage descriptor.
23871 */
23872@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23873 */
23874 arch_end_context_switch(next_p);
23875
23876+ this_cpu_write(current_task, next_p);
23877+ this_cpu_write(current_tinfo, &next_p->tinfo);
23878+
23879 /*
23880 * Restore %gs if needed (which is common)
23881 */
23882@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23883
23884 switch_fpu_finish(next_p, fpu);
23885
23886- this_cpu_write(current_task, next_p);
23887-
23888 return prev_p;
23889 }
23890
23891@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
23892 } while (count++ < 16);
23893 return 0;
23894 }
23895-
23896diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
23897index 355ae06..560fbbe 100644
23898--- a/arch/x86/kernel/process_64.c
23899+++ b/arch/x86/kernel/process_64.c
23900@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
23901 struct pt_regs *childregs;
23902 struct task_struct *me = current;
23903
23904- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
23905+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
23906 childregs = task_pt_regs(p);
23907 p->thread.sp = (unsigned long) childregs;
23908 p->thread.usersp = me->thread.usersp;
23909+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
23910 set_tsk_thread_flag(p, TIF_FORK);
23911 p->fpu_counter = 0;
23912 p->thread.io_bitmap_ptr = NULL;
23913@@ -165,6 +166,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
23914 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
23915 savesegment(es, p->thread.es);
23916 savesegment(ds, p->thread.ds);
23917+ savesegment(ss, p->thread.ss);
23918+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
23919 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
23920
23921 if (unlikely(p->flags & PF_KTHREAD)) {
23922@@ -273,7 +276,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23923 struct thread_struct *prev = &prev_p->thread;
23924 struct thread_struct *next = &next_p->thread;
23925 int cpu = smp_processor_id();
23926- struct tss_struct *tss = &per_cpu(init_tss, cpu);
23927+ struct tss_struct *tss = init_tss + cpu;
23928 unsigned fsindex, gsindex;
23929 fpu_switch_t fpu;
23930
23931@@ -296,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23932 if (unlikely(next->ds | prev->ds))
23933 loadsegment(ds, next->ds);
23934
23935+ savesegment(ss, prev->ss);
23936+ if (unlikely(next->ss != prev->ss))
23937+ loadsegment(ss, next->ss);
23938
23939 /* We must save %fs and %gs before load_TLS() because
23940 * %fs and %gs may be cleared by load_TLS().
23941@@ -355,10 +361,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
23942 prev->usersp = this_cpu_read(old_rsp);
23943 this_cpu_write(old_rsp, next->usersp);
23944 this_cpu_write(current_task, next_p);
23945+ this_cpu_write(current_tinfo, &next_p->tinfo);
23946
23947- this_cpu_write(kernel_stack,
23948- (unsigned long)task_stack_page(next_p) +
23949- THREAD_SIZE - KERNEL_STACK_OFFSET);
23950+ this_cpu_write(kernel_stack, next->sp0);
23951
23952 /*
23953 * Now maybe reload the debug registers and handle I/O bitmaps
23954@@ -427,12 +432,11 @@ unsigned long get_wchan(struct task_struct *p)
23955 if (!p || p == current || p->state == TASK_RUNNING)
23956 return 0;
23957 stack = (unsigned long)task_stack_page(p);
23958- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
23959+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
23960 return 0;
23961 fp = *(u64 *)(p->thread.sp);
23962 do {
23963- if (fp < (unsigned long)stack ||
23964- fp >= (unsigned long)stack+THREAD_SIZE)
23965+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
23966 return 0;
23967 ip = *(u64 *)(fp+8);
23968 if (!in_sched_functions(ip))
23969diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
23970index 29a8120..a50b5ee 100644
23971--- a/arch/x86/kernel/ptrace.c
23972+++ b/arch/x86/kernel/ptrace.c
23973@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
23974 {
23975 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
23976 unsigned long sp = (unsigned long)&regs->sp;
23977- struct thread_info *tinfo;
23978
23979- if (context == (sp & ~(THREAD_SIZE - 1)))
23980+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
23981 return sp;
23982
23983- tinfo = (struct thread_info *)context;
23984- if (tinfo->previous_esp)
23985- return tinfo->previous_esp;
23986+ sp = *(unsigned long *)context;
23987+ if (sp)
23988+ return sp;
23989
23990 return (unsigned long)regs;
23991 }
23992@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
23993 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
23994 {
23995 int i;
23996- int dr7 = 0;
23997+ unsigned long dr7 = 0;
23998 struct arch_hw_breakpoint *info;
23999
24000 for (i = 0; i < HBP_NUM; i++) {
24001@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
24002 unsigned long addr, unsigned long data)
24003 {
24004 int ret;
24005- unsigned long __user *datap = (unsigned long __user *)data;
24006+ unsigned long __user *datap = (__force unsigned long __user *)data;
24007
24008 switch (request) {
24009 /* read the word at location addr in the USER area. */
24010@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
24011 if ((int) addr < 0)
24012 return -EIO;
24013 ret = do_get_thread_area(child, addr,
24014- (struct user_desc __user *)data);
24015+ (__force struct user_desc __user *) data);
24016 break;
24017
24018 case PTRACE_SET_THREAD_AREA:
24019 if ((int) addr < 0)
24020 return -EIO;
24021 ret = do_set_thread_area(child, addr,
24022- (struct user_desc __user *)data, 0);
24023+ (__force struct user_desc __user *) data, 0);
24024 break;
24025 #endif
24026
24027@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24028
24029 #ifdef CONFIG_X86_64
24030
24031-static struct user_regset x86_64_regsets[] __read_mostly = {
24032+static user_regset_no_const x86_64_regsets[] __read_only = {
24033 [REGSET_GENERAL] = {
24034 .core_note_type = NT_PRSTATUS,
24035 .n = sizeof(struct user_regs_struct) / sizeof(long),
24036@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
24037 #endif /* CONFIG_X86_64 */
24038
24039 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24040-static struct user_regset x86_32_regsets[] __read_mostly = {
24041+static user_regset_no_const x86_32_regsets[] __read_only = {
24042 [REGSET_GENERAL] = {
24043 .core_note_type = NT_PRSTATUS,
24044 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24045@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
24046 */
24047 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24048
24049-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24050+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24051 {
24052 #ifdef CONFIG_X86_64
24053 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24054@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24055 memset(info, 0, sizeof(*info));
24056 info->si_signo = SIGTRAP;
24057 info->si_code = si_code;
24058- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24059+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24060 }
24061
24062 void user_single_step_siginfo(struct task_struct *tsk,
24063@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24064 # define IS_IA32 0
24065 #endif
24066
24067+#ifdef CONFIG_GRKERNSEC_SETXID
24068+extern void gr_delayed_cred_worker(void);
24069+#endif
24070+
24071 /*
24072 * We must return the syscall number to actually look up in the table.
24073 * This can be -1L to skip running any syscall at all.
24074@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24075
24076 user_exit();
24077
24078+#ifdef CONFIG_GRKERNSEC_SETXID
24079+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24080+ gr_delayed_cred_worker();
24081+#endif
24082+
24083 /*
24084 * If we stepped into a sysenter/syscall insn, it trapped in
24085 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24086@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24087 */
24088 user_exit();
24089
24090+#ifdef CONFIG_GRKERNSEC_SETXID
24091+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24092+ gr_delayed_cred_worker();
24093+#endif
24094+
24095 audit_syscall_exit(regs);
24096
24097 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24098diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24099index 2cb9470..ff1fd80 100644
24100--- a/arch/x86/kernel/pvclock.c
24101+++ b/arch/x86/kernel/pvclock.c
24102@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24103 return pv_tsc_khz;
24104 }
24105
24106-static atomic64_t last_value = ATOMIC64_INIT(0);
24107+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24108
24109 void pvclock_resume(void)
24110 {
24111- atomic64_set(&last_value, 0);
24112+ atomic64_set_unchecked(&last_value, 0);
24113 }
24114
24115 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24116@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24117 * updating at the same time, and one of them could be slightly behind,
24118 * making the assumption that last_value always go forward fail to hold.
24119 */
24120- last = atomic64_read(&last_value);
24121+ last = atomic64_read_unchecked(&last_value);
24122 do {
24123 if (ret < last)
24124 return last;
24125- last = atomic64_cmpxchg(&last_value, last, ret);
24126+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24127 } while (unlikely(last != ret));
24128
24129 return ret;
24130diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24131index 76fa1e9..abf09ea 100644
24132--- a/arch/x86/kernel/reboot.c
24133+++ b/arch/x86/kernel/reboot.c
24134@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
24135 EXPORT_SYMBOL(pm_power_off);
24136
24137 static const struct desc_ptr no_idt = {};
24138-static int reboot_mode;
24139+static unsigned short reboot_mode;
24140 enum reboot_type reboot_type = BOOT_ACPI;
24141 int reboot_force;
24142
24143@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24144
24145 void __noreturn machine_real_restart(unsigned int type)
24146 {
24147+
24148+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24149+ struct desc_struct *gdt;
24150+#endif
24151+
24152 local_irq_disable();
24153
24154 /*
24155@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
24156
24157 /* Jump to the identity-mapped low memory code */
24158 #ifdef CONFIG_X86_32
24159- asm volatile("jmpl *%0" : :
24160+
24161+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24162+ gdt = get_cpu_gdt_table(smp_processor_id());
24163+ pax_open_kernel();
24164+#ifdef CONFIG_PAX_MEMORY_UDEREF
24165+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24166+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24167+ loadsegment(ds, __KERNEL_DS);
24168+ loadsegment(es, __KERNEL_DS);
24169+ loadsegment(ss, __KERNEL_DS);
24170+#endif
24171+#ifdef CONFIG_PAX_KERNEXEC
24172+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24173+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24174+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24175+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24176+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24177+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24178+#endif
24179+ pax_close_kernel();
24180+#endif
24181+
24182+ asm volatile("ljmpl *%0" : :
24183 "rm" (real_mode_header->machine_real_restart_asm),
24184 "a" (type));
24185 #else
24186@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24187 * try to force a triple fault and then cycle between hitting the keyboard
24188 * controller and doing that
24189 */
24190-static void native_machine_emergency_restart(void)
24191+static void __noreturn native_machine_emergency_restart(void)
24192 {
24193 int i;
24194 int attempt = 0;
24195@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
24196 #endif
24197 }
24198
24199-static void __machine_emergency_restart(int emergency)
24200+static void __noreturn __machine_emergency_restart(int emergency)
24201 {
24202 reboot_emergency = emergency;
24203 machine_ops.emergency_restart();
24204 }
24205
24206-static void native_machine_restart(char *__unused)
24207+static void __noreturn native_machine_restart(char *__unused)
24208 {
24209 pr_notice("machine restart\n");
24210
24211@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
24212 __machine_emergency_restart(0);
24213 }
24214
24215-static void native_machine_halt(void)
24216+static void __noreturn native_machine_halt(void)
24217 {
24218 /* Stop other cpus and apics */
24219 machine_shutdown();
24220@@ -679,7 +706,7 @@ static void native_machine_halt(void)
24221 stop_this_cpu(NULL);
24222 }
24223
24224-static void native_machine_power_off(void)
24225+static void __noreturn native_machine_power_off(void)
24226 {
24227 if (pm_power_off) {
24228 if (!reboot_force)
24229@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
24230 }
24231 /* A fallback in case there is no PM info available */
24232 tboot_shutdown(TB_SHUTDOWN_HALT);
24233+ unreachable();
24234 }
24235
24236-struct machine_ops machine_ops = {
24237+struct machine_ops machine_ops __read_only = {
24238 .power_off = native_machine_power_off,
24239 .shutdown = native_machine_shutdown,
24240 .emergency_restart = native_machine_emergency_restart,
24241diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
24242index c8e41e9..64049ef 100644
24243--- a/arch/x86/kernel/reboot_fixups_32.c
24244+++ b/arch/x86/kernel/reboot_fixups_32.c
24245@@ -57,7 +57,7 @@ struct device_fixup {
24246 unsigned int vendor;
24247 unsigned int device;
24248 void (*reboot_fixup)(struct pci_dev *);
24249-};
24250+} __do_const;
24251
24252 /*
24253 * PCI ids solely used for fixups_table go here
24254diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
24255index f2bb9c9..bed145d7 100644
24256--- a/arch/x86/kernel/relocate_kernel_64.S
24257+++ b/arch/x86/kernel/relocate_kernel_64.S
24258@@ -11,6 +11,7 @@
24259 #include <asm/kexec.h>
24260 #include <asm/processor-flags.h>
24261 #include <asm/pgtable_types.h>
24262+#include <asm/alternative-asm.h>
24263
24264 /*
24265 * Must be relocatable PIC code callable as a C function
24266@@ -167,6 +168,7 @@ identity_mapped:
24267 xorq %r14, %r14
24268 xorq %r15, %r15
24269
24270+ pax_force_retaddr 0, 1
24271 ret
24272
24273 1:
24274diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
24275index 56f7fcf..3b88ad1 100644
24276--- a/arch/x86/kernel/setup.c
24277+++ b/arch/x86/kernel/setup.c
24278@@ -110,6 +110,7 @@
24279 #include <asm/mce.h>
24280 #include <asm/alternative.h>
24281 #include <asm/prom.h>
24282+#include <asm/boot.h>
24283
24284 /*
24285 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
24286@@ -205,10 +206,12 @@ EXPORT_SYMBOL(boot_cpu_data);
24287 #endif
24288
24289
24290-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
24291-unsigned long mmu_cr4_features;
24292+#ifdef CONFIG_X86_64
24293+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
24294+#elif defined(CONFIG_X86_PAE)
24295+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
24296 #else
24297-unsigned long mmu_cr4_features = X86_CR4_PAE;
24298+unsigned long mmu_cr4_features __read_only;
24299 #endif
24300
24301 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
24302@@ -444,7 +447,7 @@ static void __init parse_setup_data(void)
24303
24304 switch (data->type) {
24305 case SETUP_E820_EXT:
24306- parse_e820_ext(data);
24307+ parse_e820_ext((struct setup_data __force_kernel *)data);
24308 break;
24309 case SETUP_DTB:
24310 add_dtb(pa_data);
24311@@ -771,7 +774,7 @@ static void __init trim_bios_range(void)
24312 * area (640->1Mb) as ram even though it is not.
24313 * take them out.
24314 */
24315- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
24316+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
24317
24318 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
24319 }
24320@@ -779,7 +782,7 @@ static void __init trim_bios_range(void)
24321 /* called before trim_bios_range() to spare extra sanitize */
24322 static void __init e820_add_kernel_range(void)
24323 {
24324- u64 start = __pa_symbol(_text);
24325+ u64 start = __pa_symbol(ktla_ktva(_text));
24326 u64 size = __pa_symbol(_end) - start;
24327
24328 /*
24329@@ -841,8 +844,12 @@ static void __init trim_low_memory_range(void)
24330
24331 void __init setup_arch(char **cmdline_p)
24332 {
24333+#ifdef CONFIG_X86_32
24334+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
24335+#else
24336 memblock_reserve(__pa_symbol(_text),
24337 (unsigned long)__bss_stop - (unsigned long)_text);
24338+#endif
24339
24340 early_reserve_initrd();
24341
24342@@ -934,14 +941,14 @@ void __init setup_arch(char **cmdline_p)
24343
24344 if (!boot_params.hdr.root_flags)
24345 root_mountflags &= ~MS_RDONLY;
24346- init_mm.start_code = (unsigned long) _text;
24347- init_mm.end_code = (unsigned long) _etext;
24348+ init_mm.start_code = ktla_ktva((unsigned long) _text);
24349+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
24350 init_mm.end_data = (unsigned long) _edata;
24351 init_mm.brk = _brk_end;
24352
24353- code_resource.start = __pa_symbol(_text);
24354- code_resource.end = __pa_symbol(_etext)-1;
24355- data_resource.start = __pa_symbol(_etext);
24356+ code_resource.start = __pa_symbol(ktla_ktva(_text));
24357+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
24358+ data_resource.start = __pa_symbol(_sdata);
24359 data_resource.end = __pa_symbol(_edata)-1;
24360 bss_resource.start = __pa_symbol(__bss_start);
24361 bss_resource.end = __pa_symbol(__bss_stop)-1;
24362diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
24363index 5cdff03..80fa283 100644
24364--- a/arch/x86/kernel/setup_percpu.c
24365+++ b/arch/x86/kernel/setup_percpu.c
24366@@ -21,19 +21,17 @@
24367 #include <asm/cpu.h>
24368 #include <asm/stackprotector.h>
24369
24370-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
24371+#ifdef CONFIG_SMP
24372+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
24373 EXPORT_PER_CPU_SYMBOL(cpu_number);
24374+#endif
24375
24376-#ifdef CONFIG_X86_64
24377 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
24378-#else
24379-#define BOOT_PERCPU_OFFSET 0
24380-#endif
24381
24382 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
24383 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
24384
24385-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
24386+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
24387 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
24388 };
24389 EXPORT_SYMBOL(__per_cpu_offset);
24390@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
24391 {
24392 #ifdef CONFIG_NEED_MULTIPLE_NODES
24393 pg_data_t *last = NULL;
24394- unsigned int cpu;
24395+ int cpu;
24396
24397 for_each_possible_cpu(cpu) {
24398 int node = early_cpu_to_node(cpu);
24399@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
24400 {
24401 #ifdef CONFIG_X86_32
24402 struct desc_struct gdt;
24403+ unsigned long base = per_cpu_offset(cpu);
24404
24405- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
24406- 0x2 | DESCTYPE_S, 0x8);
24407- gdt.s = 1;
24408+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
24409+ 0x83 | DESCTYPE_S, 0xC);
24410 write_gdt_entry(get_cpu_gdt_table(cpu),
24411 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
24412 #endif
24413@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
24414 /* alrighty, percpu areas up and running */
24415 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
24416 for_each_possible_cpu(cpu) {
24417+#ifdef CONFIG_CC_STACKPROTECTOR
24418+#ifdef CONFIG_X86_32
24419+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
24420+#endif
24421+#endif
24422 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
24423 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
24424 per_cpu(cpu_number, cpu) = cpu;
24425@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
24426 */
24427 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
24428 #endif
24429+#ifdef CONFIG_CC_STACKPROTECTOR
24430+#ifdef CONFIG_X86_32
24431+ if (!cpu)
24432+ per_cpu(stack_canary.canary, cpu) = canary;
24433+#endif
24434+#endif
24435 /*
24436 * Up to this point, the boot CPU has been using .init.data
24437 * area. Reload any changed state for the boot CPU.
24438diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
24439index 6956299..18126ec4 100644
24440--- a/arch/x86/kernel/signal.c
24441+++ b/arch/x86/kernel/signal.c
24442@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
24443 * Align the stack pointer according to the i386 ABI,
24444 * i.e. so that on function entry ((sp + 4) & 15) == 0.
24445 */
24446- sp = ((sp + 4) & -16ul) - 4;
24447+ sp = ((sp - 12) & -16ul) - 4;
24448 #else /* !CONFIG_X86_32 */
24449 sp = round_down(sp, 16) - 8;
24450 #endif
24451@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
24452 }
24453
24454 if (current->mm->context.vdso)
24455- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
24456+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
24457 else
24458- restorer = &frame->retcode;
24459+ restorer = (void __user *)&frame->retcode;
24460 if (ksig->ka.sa.sa_flags & SA_RESTORER)
24461 restorer = ksig->ka.sa.sa_restorer;
24462
24463@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
24464 * reasons and because gdb uses it as a signature to notice
24465 * signal handler stack frames.
24466 */
24467- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
24468+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
24469
24470 if (err)
24471 return -EFAULT;
24472@@ -364,10 +364,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
24473 else
24474 put_user_ex(0, &frame->uc.uc_flags);
24475 put_user_ex(0, &frame->uc.uc_link);
24476- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
24477+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
24478
24479 /* Set up to return from userspace. */
24480- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
24481+ if (current->mm->context.vdso)
24482+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
24483+ else
24484+ restorer = (void __user *)&frame->retcode;
24485 if (ksig->ka.sa.sa_flags & SA_RESTORER)
24486 restorer = ksig->ka.sa.sa_restorer;
24487 put_user_ex(restorer, &frame->pretcode);
24488@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
24489 * reasons and because gdb uses it as a signature to notice
24490 * signal handler stack frames.
24491 */
24492- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
24493+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
24494 } put_user_catch(err);
24495
24496 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
24497@@ -429,7 +432,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
24498 else
24499 put_user_ex(0, &frame->uc.uc_flags);
24500 put_user_ex(0, &frame->uc.uc_link);
24501- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
24502+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
24503
24504 /* Set up to return from userspace. If provided, use a stub
24505 already in userspace. */
24506@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
24507 {
24508 int usig = signr_convert(ksig->sig);
24509 sigset_t *set = sigmask_to_save();
24510- compat_sigset_t *cset = (compat_sigset_t *) set;
24511+ sigset_t sigcopy;
24512+ compat_sigset_t *cset;
24513+
24514+ sigcopy = *set;
24515+
24516+ cset = (compat_sigset_t *) &sigcopy;
24517
24518 /* Set up the stack frame */
24519 if (is_ia32_frame()) {
24520@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
24521 } else if (is_x32_frame()) {
24522 return x32_setup_rt_frame(ksig, cset, regs);
24523 } else {
24524- return __setup_rt_frame(ksig->sig, ksig, set, regs);
24525+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
24526 }
24527 }
24528
24529diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
24530index 48d2b7d..90d328a 100644
24531--- a/arch/x86/kernel/smp.c
24532+++ b/arch/x86/kernel/smp.c
24533@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
24534
24535 __setup("nonmi_ipi", nonmi_ipi_setup);
24536
24537-struct smp_ops smp_ops = {
24538+struct smp_ops smp_ops __read_only = {
24539 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
24540 .smp_prepare_cpus = native_smp_prepare_cpus,
24541 .smp_cpus_done = native_smp_cpus_done,
24542diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
24543index bfd348e..f0c1bf2 100644
24544--- a/arch/x86/kernel/smpboot.c
24545+++ b/arch/x86/kernel/smpboot.c
24546@@ -251,14 +251,18 @@ notrace static void __cpuinit start_secondary(void *unused)
24547
24548 enable_start_cpu0 = 0;
24549
24550-#ifdef CONFIG_X86_32
24551- /* switch away from the initial page table */
24552- load_cr3(swapper_pg_dir);
24553- __flush_tlb_all();
24554-#endif
24555-
24556 /* otherwise gcc will move up smp_processor_id before the cpu_init */
24557 barrier();
24558+
24559+ /* switch away from the initial page table */
24560+#ifdef CONFIG_PAX_PER_CPU_PGD
24561+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
24562+ __flush_tlb_all();
24563+#elif defined(CONFIG_X86_32)
24564+ load_cr3(swapper_pg_dir);
24565+ __flush_tlb_all();
24566+#endif
24567+
24568 /*
24569 * Check TSC synchronization with the BP:
24570 */
24571@@ -748,6 +752,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
24572 idle->thread.sp = (unsigned long) (((struct pt_regs *)
24573 (THREAD_SIZE + task_stack_page(idle))) - 1);
24574 per_cpu(current_task, cpu) = idle;
24575+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
24576
24577 #ifdef CONFIG_X86_32
24578 /* Stack for startup_32 can be just as for start_secondary onwards */
24579@@ -755,11 +760,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
24580 #else
24581 clear_tsk_thread_flag(idle, TIF_FORK);
24582 initial_gs = per_cpu_offset(cpu);
24583- per_cpu(kernel_stack, cpu) =
24584- (unsigned long)task_stack_page(idle) -
24585- KERNEL_STACK_OFFSET + THREAD_SIZE;
24586+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24587 #endif
24588+
24589+ pax_open_kernel();
24590 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
24591+ pax_close_kernel();
24592+
24593 initial_code = (unsigned long)start_secondary;
24594 stack_start = idle->thread.sp;
24595
24596@@ -908,6 +915,18 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
24597 /* the FPU context is blank, nobody can own it */
24598 __cpu_disable_lazy_restore(cpu);
24599
24600+#ifdef CONFIG_PAX_PER_CPU_PGD
24601+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
24602+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24603+ KERNEL_PGD_PTRS);
24604+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
24605+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24606+ KERNEL_PGD_PTRS);
24607+#endif
24608+
24609+ /* the FPU context is blank, nobody can own it */
24610+ __cpu_disable_lazy_restore(cpu);
24611+
24612 err = do_boot_cpu(apicid, cpu, tidle);
24613 if (err) {
24614 pr_debug("do_boot_cpu failed %d\n", err);
24615diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
24616index 9b4d51d..5d28b58 100644
24617--- a/arch/x86/kernel/step.c
24618+++ b/arch/x86/kernel/step.c
24619@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
24620 struct desc_struct *desc;
24621 unsigned long base;
24622
24623- seg &= ~7UL;
24624+ seg >>= 3;
24625
24626 mutex_lock(&child->mm->context.lock);
24627- if (unlikely((seg >> 3) >= child->mm->context.size))
24628+ if (unlikely(seg >= child->mm->context.size))
24629 addr = -1L; /* bogus selector, access would fault */
24630 else {
24631 desc = child->mm->context.ldt + seg;
24632@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
24633 addr += base;
24634 }
24635 mutex_unlock(&child->mm->context.lock);
24636- }
24637+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
24638+ addr = ktla_ktva(addr);
24639
24640 return addr;
24641 }
24642@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
24643 unsigned char opcode[15];
24644 unsigned long addr = convert_ip_to_linear(child, regs);
24645
24646+ if (addr == -EINVAL)
24647+ return 0;
24648+
24649 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
24650 for (i = 0; i < copied; i++) {
24651 switch (opcode[i]) {
24652diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
24653new file mode 100644
24654index 0000000..5877189
24655--- /dev/null
24656+++ b/arch/x86/kernel/sys_i386_32.c
24657@@ -0,0 +1,189 @@
24658+/*
24659+ * This file contains various random system calls that
24660+ * have a non-standard calling sequence on the Linux/i386
24661+ * platform.
24662+ */
24663+
24664+#include <linux/errno.h>
24665+#include <linux/sched.h>
24666+#include <linux/mm.h>
24667+#include <linux/fs.h>
24668+#include <linux/smp.h>
24669+#include <linux/sem.h>
24670+#include <linux/msg.h>
24671+#include <linux/shm.h>
24672+#include <linux/stat.h>
24673+#include <linux/syscalls.h>
24674+#include <linux/mman.h>
24675+#include <linux/file.h>
24676+#include <linux/utsname.h>
24677+#include <linux/ipc.h>
24678+#include <linux/elf.h>
24679+
24680+#include <linux/uaccess.h>
24681+#include <linux/unistd.h>
24682+
24683+#include <asm/syscalls.h>
24684+
24685+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
24686+{
24687+ unsigned long pax_task_size = TASK_SIZE;
24688+
24689+#ifdef CONFIG_PAX_SEGMEXEC
24690+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
24691+ pax_task_size = SEGMEXEC_TASK_SIZE;
24692+#endif
24693+
24694+ if (flags & MAP_FIXED)
24695+ if (len > pax_task_size || addr > pax_task_size - len)
24696+ return -EINVAL;
24697+
24698+ return 0;
24699+}
24700+
24701+/*
24702+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
24703+ */
24704+static unsigned long get_align_mask(void)
24705+{
24706+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
24707+ return 0;
24708+
24709+ if (!(current->flags & PF_RANDOMIZE))
24710+ return 0;
24711+
24712+ return va_align.mask;
24713+}
24714+
24715+unsigned long
24716+arch_get_unmapped_area(struct file *filp, unsigned long addr,
24717+ unsigned long len, unsigned long pgoff, unsigned long flags)
24718+{
24719+ struct mm_struct *mm = current->mm;
24720+ struct vm_area_struct *vma;
24721+ unsigned long pax_task_size = TASK_SIZE;
24722+ struct vm_unmapped_area_info info;
24723+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
24724+
24725+#ifdef CONFIG_PAX_SEGMEXEC
24726+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24727+ pax_task_size = SEGMEXEC_TASK_SIZE;
24728+#endif
24729+
24730+ pax_task_size -= PAGE_SIZE;
24731+
24732+ if (len > pax_task_size)
24733+ return -ENOMEM;
24734+
24735+ if (flags & MAP_FIXED)
24736+ return addr;
24737+
24738+#ifdef CONFIG_PAX_RANDMMAP
24739+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24740+#endif
24741+
24742+ if (addr) {
24743+ addr = PAGE_ALIGN(addr);
24744+ if (pax_task_size - len >= addr) {
24745+ vma = find_vma(mm, addr);
24746+ if (check_heap_stack_gap(vma, addr, len, offset))
24747+ return addr;
24748+ }
24749+ }
24750+
24751+ info.flags = 0;
24752+ info.length = len;
24753+ info.align_mask = filp ? get_align_mask() : 0;
24754+ info.align_offset = pgoff << PAGE_SHIFT;
24755+ info.threadstack_offset = offset;
24756+
24757+#ifdef CONFIG_PAX_PAGEEXEC
24758+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
24759+ info.low_limit = 0x00110000UL;
24760+ info.high_limit = mm->start_code;
24761+
24762+#ifdef CONFIG_PAX_RANDMMAP
24763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24764+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
24765+#endif
24766+
24767+ if (info.low_limit < info.high_limit) {
24768+ addr = vm_unmapped_area(&info);
24769+ if (!IS_ERR_VALUE(addr))
24770+ return addr;
24771+ }
24772+ } else
24773+#endif
24774+
24775+ info.low_limit = mm->mmap_base;
24776+ info.high_limit = pax_task_size;
24777+
24778+ return vm_unmapped_area(&info);
24779+}
24780+
24781+unsigned long
24782+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
24783+ const unsigned long len, const unsigned long pgoff,
24784+ const unsigned long flags)
24785+{
24786+ struct vm_area_struct *vma;
24787+ struct mm_struct *mm = current->mm;
24788+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
24789+ struct vm_unmapped_area_info info;
24790+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
24791+
24792+#ifdef CONFIG_PAX_SEGMEXEC
24793+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24794+ pax_task_size = SEGMEXEC_TASK_SIZE;
24795+#endif
24796+
24797+ pax_task_size -= PAGE_SIZE;
24798+
24799+ /* requested length too big for entire address space */
24800+ if (len > pax_task_size)
24801+ return -ENOMEM;
24802+
24803+ if (flags & MAP_FIXED)
24804+ return addr;
24805+
24806+#ifdef CONFIG_PAX_PAGEEXEC
24807+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
24808+ goto bottomup;
24809+#endif
24810+
24811+#ifdef CONFIG_PAX_RANDMMAP
24812+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24813+#endif
24814+
24815+ /* requesting a specific address */
24816+ if (addr) {
24817+ addr = PAGE_ALIGN(addr);
24818+ if (pax_task_size - len >= addr) {
24819+ vma = find_vma(mm, addr);
24820+ if (check_heap_stack_gap(vma, addr, len, offset))
24821+ return addr;
24822+ }
24823+ }
24824+
24825+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
24826+ info.length = len;
24827+ info.low_limit = PAGE_SIZE;
24828+ info.high_limit = mm->mmap_base;
24829+ info.align_mask = filp ? get_align_mask() : 0;
24830+ info.align_offset = pgoff << PAGE_SHIFT;
24831+ info.threadstack_offset = offset;
24832+
24833+ addr = vm_unmapped_area(&info);
24834+ if (!(addr & ~PAGE_MASK))
24835+ return addr;
24836+ VM_BUG_ON(addr != -ENOMEM);
24837+
24838+bottomup:
24839+ /*
24840+ * A failed mmap() very likely causes application failure,
24841+ * so fall back to the bottom-up function here. This scenario
24842+ * can happen with large stack limits and large mmap()
24843+ * allocations.
24844+ */
24845+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
24846+}
24847diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
24848index dbded5a..ace2781 100644
24849--- a/arch/x86/kernel/sys_x86_64.c
24850+++ b/arch/x86/kernel/sys_x86_64.c
24851@@ -81,8 +81,8 @@ out:
24852 return error;
24853 }
24854
24855-static void find_start_end(unsigned long flags, unsigned long *begin,
24856- unsigned long *end)
24857+static void find_start_end(struct mm_struct *mm, unsigned long flags,
24858+ unsigned long *begin, unsigned long *end)
24859 {
24860 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
24861 unsigned long new_begin;
24862@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
24863 *begin = new_begin;
24864 }
24865 } else {
24866- *begin = TASK_UNMAPPED_BASE;
24867+ *begin = mm->mmap_base;
24868 *end = TASK_SIZE;
24869 }
24870 }
24871@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
24872 struct vm_area_struct *vma;
24873 struct vm_unmapped_area_info info;
24874 unsigned long begin, end;
24875+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
24876
24877 if (flags & MAP_FIXED)
24878 return addr;
24879
24880- find_start_end(flags, &begin, &end);
24881+ find_start_end(mm, flags, &begin, &end);
24882
24883 if (len > end)
24884 return -ENOMEM;
24885
24886+#ifdef CONFIG_PAX_RANDMMAP
24887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24888+#endif
24889+
24890 if (addr) {
24891 addr = PAGE_ALIGN(addr);
24892 vma = find_vma(mm, addr);
24893- if (end - len >= addr &&
24894- (!vma || addr + len <= vma->vm_start))
24895+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
24896 return addr;
24897 }
24898
24899@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
24900 info.high_limit = end;
24901 info.align_mask = filp ? get_align_mask() : 0;
24902 info.align_offset = pgoff << PAGE_SHIFT;
24903+ info.threadstack_offset = offset;
24904 return vm_unmapped_area(&info);
24905 }
24906
24907@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
24908 struct mm_struct *mm = current->mm;
24909 unsigned long addr = addr0;
24910 struct vm_unmapped_area_info info;
24911+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
24912
24913 /* requested length too big for entire address space */
24914 if (len > TASK_SIZE)
24915@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
24916 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
24917 goto bottomup;
24918
24919+#ifdef CONFIG_PAX_RANDMMAP
24920+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24921+#endif
24922+
24923 /* requesting a specific address */
24924 if (addr) {
24925 addr = PAGE_ALIGN(addr);
24926 vma = find_vma(mm, addr);
24927- if (TASK_SIZE - len >= addr &&
24928- (!vma || addr + len <= vma->vm_start))
24929+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
24930 return addr;
24931 }
24932
24933@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
24934 info.high_limit = mm->mmap_base;
24935 info.align_mask = filp ? get_align_mask() : 0;
24936 info.align_offset = pgoff << PAGE_SHIFT;
24937+ info.threadstack_offset = offset;
24938 addr = vm_unmapped_area(&info);
24939 if (!(addr & ~PAGE_MASK))
24940 return addr;
24941diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
24942index f84fe00..f41d9f1 100644
24943--- a/arch/x86/kernel/tboot.c
24944+++ b/arch/x86/kernel/tboot.c
24945@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
24946
24947 void tboot_shutdown(u32 shutdown_type)
24948 {
24949- void (*shutdown)(void);
24950+ void (* __noreturn shutdown)(void);
24951
24952 if (!tboot_enabled())
24953 return;
24954@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
24955
24956 switch_to_tboot_pt();
24957
24958- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
24959+ shutdown = (void *)tboot->shutdown_entry;
24960 shutdown();
24961
24962 /* should not reach here */
24963@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
24964 return 0;
24965 }
24966
24967-static atomic_t ap_wfs_count;
24968+static atomic_unchecked_t ap_wfs_count;
24969
24970 static int tboot_wait_for_aps(int num_aps)
24971 {
24972@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
24973 {
24974 switch (action) {
24975 case CPU_DYING:
24976- atomic_inc(&ap_wfs_count);
24977+ atomic_inc_unchecked(&ap_wfs_count);
24978 if (num_online_cpus() == 1)
24979- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
24980+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
24981 return NOTIFY_BAD;
24982 break;
24983 }
24984 return NOTIFY_OK;
24985 }
24986
24987-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
24988+static struct notifier_block tboot_cpu_notifier =
24989 {
24990 .notifier_call = tboot_cpu_callback,
24991 };
24992@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
24993
24994 tboot_create_trampoline();
24995
24996- atomic_set(&ap_wfs_count, 0);
24997+ atomic_set_unchecked(&ap_wfs_count, 0);
24998 register_hotcpu_notifier(&tboot_cpu_notifier);
24999
25000 acpi_os_set_prepare_sleep(&tboot_sleep);
25001diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25002index 24d3c91..d06b473 100644
25003--- a/arch/x86/kernel/time.c
25004+++ b/arch/x86/kernel/time.c
25005@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25006 {
25007 unsigned long pc = instruction_pointer(regs);
25008
25009- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25010+ if (!user_mode(regs) && in_lock_functions(pc)) {
25011 #ifdef CONFIG_FRAME_POINTER
25012- return *(unsigned long *)(regs->bp + sizeof(long));
25013+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25014 #else
25015 unsigned long *sp =
25016 (unsigned long *)kernel_stack_pointer(regs);
25017@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25018 * or above a saved flags. Eflags has bits 22-31 zero,
25019 * kernel addresses don't.
25020 */
25021+
25022+#ifdef CONFIG_PAX_KERNEXEC
25023+ return ktla_ktva(sp[0]);
25024+#else
25025 if (sp[0] >> 22)
25026 return sp[0];
25027 if (sp[1] >> 22)
25028 return sp[1];
25029 #endif
25030+
25031+#endif
25032 }
25033 return pc;
25034 }
25035diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25036index f7fec09..9991981 100644
25037--- a/arch/x86/kernel/tls.c
25038+++ b/arch/x86/kernel/tls.c
25039@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25040 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25041 return -EINVAL;
25042
25043+#ifdef CONFIG_PAX_SEGMEXEC
25044+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25045+ return -EINVAL;
25046+#endif
25047+
25048 set_tls_desc(p, idx, &info, 1);
25049
25050 return 0;
25051@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25052
25053 if (kbuf)
25054 info = kbuf;
25055- else if (__copy_from_user(infobuf, ubuf, count))
25056+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25057 return -EFAULT;
25058 else
25059 info = infobuf;
25060diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25061index 772e2a8..bad5bf6 100644
25062--- a/arch/x86/kernel/traps.c
25063+++ b/arch/x86/kernel/traps.c
25064@@ -68,12 +68,6 @@
25065 #include <asm/setup.h>
25066
25067 asmlinkage int system_call(void);
25068-
25069-/*
25070- * The IDT has to be page-aligned to simplify the Pentium
25071- * F0 0F bug workaround.
25072- */
25073-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
25074 #endif
25075
25076 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25077@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25078 }
25079
25080 static int __kprobes
25081-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25082+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25083 struct pt_regs *regs, long error_code)
25084 {
25085 #ifdef CONFIG_X86_32
25086- if (regs->flags & X86_VM_MASK) {
25087+ if (v8086_mode(regs)) {
25088 /*
25089 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25090 * On nmi (interrupt 2), do_trap should not be called.
25091@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25092 return -1;
25093 }
25094 #endif
25095- if (!user_mode(regs)) {
25096+ if (!user_mode_novm(regs)) {
25097 if (!fixup_exception(regs)) {
25098 tsk->thread.error_code = error_code;
25099 tsk->thread.trap_nr = trapnr;
25100+
25101+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25102+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25103+ str = "PAX: suspicious stack segment fault";
25104+#endif
25105+
25106 die(str, regs, error_code);
25107 }
25108+
25109+#ifdef CONFIG_PAX_REFCOUNT
25110+ if (trapnr == 4)
25111+ pax_report_refcount_overflow(regs);
25112+#endif
25113+
25114 return 0;
25115 }
25116
25117@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25118 }
25119
25120 static void __kprobes
25121-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25122+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25123 long error_code, siginfo_t *info)
25124 {
25125 struct task_struct *tsk = current;
25126@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25127 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25128 printk_ratelimit()) {
25129 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25130- tsk->comm, tsk->pid, str,
25131+ tsk->comm, task_pid_nr(tsk), str,
25132 regs->ip, regs->sp, error_code);
25133 print_vma_addr(" in ", regs->ip);
25134 pr_cont("\n");
25135@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25136 conditional_sti(regs);
25137
25138 #ifdef CONFIG_X86_32
25139- if (regs->flags & X86_VM_MASK) {
25140+ if (v8086_mode(regs)) {
25141 local_irq_enable();
25142 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25143 goto exit;
25144@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25145 #endif
25146
25147 tsk = current;
25148- if (!user_mode(regs)) {
25149+ if (!user_mode_novm(regs)) {
25150 if (fixup_exception(regs))
25151 goto exit;
25152
25153 tsk->thread.error_code = error_code;
25154 tsk->thread.trap_nr = X86_TRAP_GP;
25155 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25156- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25157+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25158+
25159+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25160+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25161+ die("PAX: suspicious general protection fault", regs, error_code);
25162+ else
25163+#endif
25164+
25165 die("general protection fault", regs, error_code);
25166+ }
25167 goto exit;
25168 }
25169
25170+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25171+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25172+ struct mm_struct *mm = tsk->mm;
25173+ unsigned long limit;
25174+
25175+ down_write(&mm->mmap_sem);
25176+ limit = mm->context.user_cs_limit;
25177+ if (limit < TASK_SIZE) {
25178+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25179+ up_write(&mm->mmap_sem);
25180+ return;
25181+ }
25182+ up_write(&mm->mmap_sem);
25183+ }
25184+#endif
25185+
25186 tsk->thread.error_code = error_code;
25187 tsk->thread.trap_nr = X86_TRAP_GP;
25188
25189@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25190 /* It's safe to allow irq's after DR6 has been saved */
25191 preempt_conditional_sti(regs);
25192
25193- if (regs->flags & X86_VM_MASK) {
25194+ if (v8086_mode(regs)) {
25195 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
25196 X86_TRAP_DB);
25197 preempt_conditional_cli(regs);
25198@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25199 * We already checked v86 mode above, so we can check for kernel mode
25200 * by just checking the CPL of CS.
25201 */
25202- if ((dr6 & DR_STEP) && !user_mode(regs)) {
25203+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
25204 tsk->thread.debugreg6 &= ~DR_STEP;
25205 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
25206 regs->flags &= ~X86_EFLAGS_TF;
25207@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
25208 return;
25209 conditional_sti(regs);
25210
25211- if (!user_mode_vm(regs))
25212+ if (!user_mode(regs))
25213 {
25214 if (!fixup_exception(regs)) {
25215 task->thread.error_code = error_code;
25216diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
25217index 2ed8459..7cf329f 100644
25218--- a/arch/x86/kernel/uprobes.c
25219+++ b/arch/x86/kernel/uprobes.c
25220@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
25221 int ret = NOTIFY_DONE;
25222
25223 /* We are only interested in userspace traps */
25224- if (regs && !user_mode_vm(regs))
25225+ if (regs && !user_mode(regs))
25226 return NOTIFY_DONE;
25227
25228 switch (val) {
25229@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
25230
25231 if (ncopied != rasize) {
25232 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
25233- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
25234+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
25235
25236 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
25237 }
25238diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
25239index b9242ba..50c5edd 100644
25240--- a/arch/x86/kernel/verify_cpu.S
25241+++ b/arch/x86/kernel/verify_cpu.S
25242@@ -20,6 +20,7 @@
25243 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
25244 * arch/x86/kernel/trampoline_64.S: secondary processor verification
25245 * arch/x86/kernel/head_32.S: processor startup
25246+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
25247 *
25248 * verify_cpu, returns the status of longmode and SSE in register %eax.
25249 * 0: Success 1: Failure
25250diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
25251index e8edcf5..27f9344 100644
25252--- a/arch/x86/kernel/vm86_32.c
25253+++ b/arch/x86/kernel/vm86_32.c
25254@@ -44,6 +44,7 @@
25255 #include <linux/ptrace.h>
25256 #include <linux/audit.h>
25257 #include <linux/stddef.h>
25258+#include <linux/grsecurity.h>
25259
25260 #include <asm/uaccess.h>
25261 #include <asm/io.h>
25262@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
25263 do_exit(SIGSEGV);
25264 }
25265
25266- tss = &per_cpu(init_tss, get_cpu());
25267+ tss = init_tss + get_cpu();
25268 current->thread.sp0 = current->thread.saved_sp0;
25269 current->thread.sysenter_cs = __KERNEL_CS;
25270 load_sp0(tss, &current->thread);
25271@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
25272
25273 if (tsk->thread.saved_sp0)
25274 return -EPERM;
25275+
25276+#ifdef CONFIG_GRKERNSEC_VM86
25277+ if (!capable(CAP_SYS_RAWIO)) {
25278+ gr_handle_vm86();
25279+ return -EPERM;
25280+ }
25281+#endif
25282+
25283 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
25284 offsetof(struct kernel_vm86_struct, vm86plus) -
25285 sizeof(info.regs));
25286@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
25287 int tmp;
25288 struct vm86plus_struct __user *v86;
25289
25290+#ifdef CONFIG_GRKERNSEC_VM86
25291+ if (!capable(CAP_SYS_RAWIO)) {
25292+ gr_handle_vm86();
25293+ return -EPERM;
25294+ }
25295+#endif
25296+
25297 tsk = current;
25298 switch (cmd) {
25299 case VM86_REQUEST_IRQ:
25300@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
25301 tsk->thread.saved_fs = info->regs32->fs;
25302 tsk->thread.saved_gs = get_user_gs(info->regs32);
25303
25304- tss = &per_cpu(init_tss, get_cpu());
25305+ tss = init_tss + get_cpu();
25306 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
25307 if (cpu_has_sep)
25308 tsk->thread.sysenter_cs = 0;
25309@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
25310 goto cannot_handle;
25311 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
25312 goto cannot_handle;
25313- intr_ptr = (unsigned long __user *) (i << 2);
25314+ intr_ptr = (__force unsigned long __user *) (i << 2);
25315 if (get_user(segoffs, intr_ptr))
25316 goto cannot_handle;
25317 if ((segoffs >> 16) == BIOSSEG)
25318diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
25319index 10c4f30..57377c2 100644
25320--- a/arch/x86/kernel/vmlinux.lds.S
25321+++ b/arch/x86/kernel/vmlinux.lds.S
25322@@ -26,6 +26,13 @@
25323 #include <asm/page_types.h>
25324 #include <asm/cache.h>
25325 #include <asm/boot.h>
25326+#include <asm/segment.h>
25327+
25328+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25329+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
25330+#else
25331+#define __KERNEL_TEXT_OFFSET 0
25332+#endif
25333
25334 #undef i386 /* in case the preprocessor is a 32bit one */
25335
25336@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
25337
25338 PHDRS {
25339 text PT_LOAD FLAGS(5); /* R_E */
25340+#ifdef CONFIG_X86_32
25341+ module PT_LOAD FLAGS(5); /* R_E */
25342+#endif
25343+#ifdef CONFIG_XEN
25344+ rodata PT_LOAD FLAGS(5); /* R_E */
25345+#else
25346+ rodata PT_LOAD FLAGS(4); /* R__ */
25347+#endif
25348 data PT_LOAD FLAGS(6); /* RW_ */
25349-#ifdef CONFIG_X86_64
25350+ init.begin PT_LOAD FLAGS(6); /* RW_ */
25351 #ifdef CONFIG_SMP
25352 percpu PT_LOAD FLAGS(6); /* RW_ */
25353 #endif
25354+ text.init PT_LOAD FLAGS(5); /* R_E */
25355+ text.exit PT_LOAD FLAGS(5); /* R_E */
25356 init PT_LOAD FLAGS(7); /* RWE */
25357-#endif
25358 note PT_NOTE FLAGS(0); /* ___ */
25359 }
25360
25361 SECTIONS
25362 {
25363 #ifdef CONFIG_X86_32
25364- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
25365- phys_startup_32 = startup_32 - LOAD_OFFSET;
25366+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
25367 #else
25368- . = __START_KERNEL;
25369- phys_startup_64 = startup_64 - LOAD_OFFSET;
25370+ . = __START_KERNEL;
25371 #endif
25372
25373 /* Text and read-only data */
25374- .text : AT(ADDR(.text) - LOAD_OFFSET) {
25375- _text = .;
25376+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
25377 /* bootstrapping code */
25378+#ifdef CONFIG_X86_32
25379+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
25380+#else
25381+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
25382+#endif
25383+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
25384+ _text = .;
25385 HEAD_TEXT
25386 . = ALIGN(8);
25387 _stext = .;
25388@@ -104,13 +124,48 @@ SECTIONS
25389 IRQENTRY_TEXT
25390 *(.fixup)
25391 *(.gnu.warning)
25392- /* End of text section */
25393- _etext = .;
25394 } :text = 0x9090
25395
25396- NOTES :text :note
25397+ . += __KERNEL_TEXT_OFFSET;
25398
25399- EXCEPTION_TABLE(16) :text = 0x9090
25400+#ifdef CONFIG_X86_32
25401+ . = ALIGN(PAGE_SIZE);
25402+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
25403+
25404+#ifdef CONFIG_PAX_KERNEXEC
25405+ MODULES_EXEC_VADDR = .;
25406+ BYTE(0)
25407+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
25408+ . = ALIGN(HPAGE_SIZE) - 1;
25409+ MODULES_EXEC_END = .;
25410+#endif
25411+
25412+ } :module
25413+#endif
25414+
25415+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
25416+ /* End of text section */
25417+ BYTE(0)
25418+ _etext = . - __KERNEL_TEXT_OFFSET;
25419+ }
25420+
25421+#ifdef CONFIG_X86_32
25422+ . = ALIGN(PAGE_SIZE);
25423+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
25424+ *(.idt)
25425+ . = ALIGN(PAGE_SIZE);
25426+ *(.empty_zero_page)
25427+ *(.initial_pg_fixmap)
25428+ *(.initial_pg_pmd)
25429+ *(.initial_page_table)
25430+ *(.swapper_pg_dir)
25431+ } :rodata
25432+#endif
25433+
25434+ . = ALIGN(PAGE_SIZE);
25435+ NOTES :rodata :note
25436+
25437+ EXCEPTION_TABLE(16) :rodata
25438
25439 #if defined(CONFIG_DEBUG_RODATA)
25440 /* .text should occupy whole number of pages */
25441@@ -122,16 +177,20 @@ SECTIONS
25442
25443 /* Data */
25444 .data : AT(ADDR(.data) - LOAD_OFFSET) {
25445+
25446+#ifdef CONFIG_PAX_KERNEXEC
25447+ . = ALIGN(HPAGE_SIZE);
25448+#else
25449+ . = ALIGN(PAGE_SIZE);
25450+#endif
25451+
25452 /* Start of data section */
25453 _sdata = .;
25454
25455 /* init_task */
25456 INIT_TASK_DATA(THREAD_SIZE)
25457
25458-#ifdef CONFIG_X86_32
25459- /* 32 bit has nosave before _edata */
25460 NOSAVE_DATA
25461-#endif
25462
25463 PAGE_ALIGNED_DATA(PAGE_SIZE)
25464
25465@@ -172,12 +231,19 @@ SECTIONS
25466 #endif /* CONFIG_X86_64 */
25467
25468 /* Init code and data - will be freed after init */
25469- . = ALIGN(PAGE_SIZE);
25470 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
25471+ BYTE(0)
25472+
25473+#ifdef CONFIG_PAX_KERNEXEC
25474+ . = ALIGN(HPAGE_SIZE);
25475+#else
25476+ . = ALIGN(PAGE_SIZE);
25477+#endif
25478+
25479 __init_begin = .; /* paired with __init_end */
25480- }
25481+ } :init.begin
25482
25483-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
25484+#ifdef CONFIG_SMP
25485 /*
25486 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
25487 * output PHDR, so the next output section - .init.text - should
25488@@ -186,12 +252,27 @@ SECTIONS
25489 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
25490 #endif
25491
25492- INIT_TEXT_SECTION(PAGE_SIZE)
25493-#ifdef CONFIG_X86_64
25494- :init
25495-#endif
25496+ . = ALIGN(PAGE_SIZE);
25497+ init_begin = .;
25498+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
25499+ VMLINUX_SYMBOL(_sinittext) = .;
25500+ INIT_TEXT
25501+ VMLINUX_SYMBOL(_einittext) = .;
25502+ . = ALIGN(PAGE_SIZE);
25503+ } :text.init
25504
25505- INIT_DATA_SECTION(16)
25506+ /*
25507+ * .exit.text is discard at runtime, not link time, to deal with
25508+ * references from .altinstructions and .eh_frame
25509+ */
25510+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
25511+ EXIT_TEXT
25512+ . = ALIGN(16);
25513+ } :text.exit
25514+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
25515+
25516+ . = ALIGN(PAGE_SIZE);
25517+ INIT_DATA_SECTION(16) :init
25518
25519 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
25520 __x86_cpu_dev_start = .;
25521@@ -253,19 +334,12 @@ SECTIONS
25522 }
25523
25524 . = ALIGN(8);
25525- /*
25526- * .exit.text is discard at runtime, not link time, to deal with
25527- * references from .altinstructions and .eh_frame
25528- */
25529- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
25530- EXIT_TEXT
25531- }
25532
25533 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
25534 EXIT_DATA
25535 }
25536
25537-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
25538+#ifndef CONFIG_SMP
25539 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
25540 #endif
25541
25542@@ -284,16 +358,10 @@ SECTIONS
25543 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
25544 __smp_locks = .;
25545 *(.smp_locks)
25546- . = ALIGN(PAGE_SIZE);
25547 __smp_locks_end = .;
25548+ . = ALIGN(PAGE_SIZE);
25549 }
25550
25551-#ifdef CONFIG_X86_64
25552- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
25553- NOSAVE_DATA
25554- }
25555-#endif
25556-
25557 /* BSS */
25558 . = ALIGN(PAGE_SIZE);
25559 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
25560@@ -309,6 +377,7 @@ SECTIONS
25561 __brk_base = .;
25562 . += 64 * 1024; /* 64k alignment slop space */
25563 *(.brk_reservation) /* areas brk users have reserved */
25564+ . = ALIGN(HPAGE_SIZE);
25565 __brk_limit = .;
25566 }
25567
25568@@ -335,13 +404,12 @@ SECTIONS
25569 * for the boot processor.
25570 */
25571 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
25572-INIT_PER_CPU(gdt_page);
25573 INIT_PER_CPU(irq_stack_union);
25574
25575 /*
25576 * Build-time check on the image size:
25577 */
25578-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
25579+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
25580 "kernel image bigger than KERNEL_IMAGE_SIZE");
25581
25582 #ifdef CONFIG_SMP
25583diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
25584index 9a907a6..f83f921 100644
25585--- a/arch/x86/kernel/vsyscall_64.c
25586+++ b/arch/x86/kernel/vsyscall_64.c
25587@@ -56,15 +56,13 @@
25588 DEFINE_VVAR(int, vgetcpu_mode);
25589 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
25590
25591-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
25592+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
25593
25594 static int __init vsyscall_setup(char *str)
25595 {
25596 if (str) {
25597 if (!strcmp("emulate", str))
25598 vsyscall_mode = EMULATE;
25599- else if (!strcmp("native", str))
25600- vsyscall_mode = NATIVE;
25601 else if (!strcmp("none", str))
25602 vsyscall_mode = NONE;
25603 else
25604@@ -323,8 +321,7 @@ do_ret:
25605 return true;
25606
25607 sigsegv:
25608- force_sig(SIGSEGV, current);
25609- return true;
25610+ do_group_exit(SIGKILL);
25611 }
25612
25613 /*
25614@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
25615 extern char __vvar_page;
25616 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
25617
25618- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
25619- vsyscall_mode == NATIVE
25620- ? PAGE_KERNEL_VSYSCALL
25621- : PAGE_KERNEL_VVAR);
25622+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
25623 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
25624 (unsigned long)VSYSCALL_START);
25625
25626diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
25627index b014d94..6d6ca7b 100644
25628--- a/arch/x86/kernel/x8664_ksyms_64.c
25629+++ b/arch/x86/kernel/x8664_ksyms_64.c
25630@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
25631 EXPORT_SYMBOL(copy_user_generic_unrolled);
25632 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
25633 EXPORT_SYMBOL(__copy_user_nocache);
25634-EXPORT_SYMBOL(_copy_from_user);
25635-EXPORT_SYMBOL(_copy_to_user);
25636
25637 EXPORT_SYMBOL(copy_page);
25638 EXPORT_SYMBOL(clear_page);
25639diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
25640index 45a14db..075bb9b 100644
25641--- a/arch/x86/kernel/x86_init.c
25642+++ b/arch/x86/kernel/x86_init.c
25643@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
25644 },
25645 };
25646
25647-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
25648+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
25649 .early_percpu_clock_init = x86_init_noop,
25650 .setup_percpu_clockev = setup_secondary_APIC_clock,
25651 };
25652@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
25653 static void default_nmi_init(void) { };
25654 static int default_i8042_detect(void) { return 1; };
25655
25656-struct x86_platform_ops x86_platform = {
25657+struct x86_platform_ops x86_platform __read_only = {
25658 .calibrate_tsc = native_calibrate_tsc,
25659 .get_wallclock = mach_get_cmos_time,
25660 .set_wallclock = mach_set_rtc_mmss,
25661@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
25662 };
25663
25664 EXPORT_SYMBOL_GPL(x86_platform);
25665-struct x86_msi_ops x86_msi = {
25666+struct x86_msi_ops x86_msi __read_only = {
25667 .setup_msi_irqs = native_setup_msi_irqs,
25668 .compose_msi_msg = native_compose_msi_msg,
25669 .teardown_msi_irq = native_teardown_msi_irq,
25670@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
25671 .setup_hpet_msi = default_setup_hpet_msi,
25672 };
25673
25674-struct x86_io_apic_ops x86_io_apic_ops = {
25675+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
25676 .init = native_io_apic_init_mappings,
25677 .read = native_io_apic_read,
25678 .write = native_io_apic_write,
25679diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
25680index ada87a3..afea76d 100644
25681--- a/arch/x86/kernel/xsave.c
25682+++ b/arch/x86/kernel/xsave.c
25683@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
25684 {
25685 int err;
25686
25687+ buf = (struct xsave_struct __user *)____m(buf);
25688 if (use_xsave())
25689 err = xsave_user(buf);
25690 else if (use_fxsr())
25691@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
25692 */
25693 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
25694 {
25695+ buf = (void __user *)____m(buf);
25696 if (use_xsave()) {
25697 if ((unsigned long)buf % 64 || fx_only) {
25698 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
25699diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
25700index a20ecb5..d0e2194 100644
25701--- a/arch/x86/kvm/cpuid.c
25702+++ b/arch/x86/kvm/cpuid.c
25703@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
25704 struct kvm_cpuid2 *cpuid,
25705 struct kvm_cpuid_entry2 __user *entries)
25706 {
25707- int r;
25708+ int r, i;
25709
25710 r = -E2BIG;
25711 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
25712 goto out;
25713 r = -EFAULT;
25714- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
25715- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
25716+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
25717 goto out;
25718+ for (i = 0; i < cpuid->nent; ++i) {
25719+ struct kvm_cpuid_entry2 cpuid_entry;
25720+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
25721+ goto out;
25722+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
25723+ }
25724 vcpu->arch.cpuid_nent = cpuid->nent;
25725 kvm_apic_set_version(vcpu);
25726 kvm_x86_ops->cpuid_update(vcpu);
25727@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
25728 struct kvm_cpuid2 *cpuid,
25729 struct kvm_cpuid_entry2 __user *entries)
25730 {
25731- int r;
25732+ int r, i;
25733
25734 r = -E2BIG;
25735 if (cpuid->nent < vcpu->arch.cpuid_nent)
25736 goto out;
25737 r = -EFAULT;
25738- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
25739- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
25740+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
25741 goto out;
25742+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
25743+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
25744+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
25745+ goto out;
25746+ }
25747 return 0;
25748
25749 out:
25750diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
25751index 5953dce..f11a7d2 100644
25752--- a/arch/x86/kvm/emulate.c
25753+++ b/arch/x86/kvm/emulate.c
25754@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
25755
25756 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
25757 do { \
25758+ unsigned long _tmp; \
25759 __asm__ __volatile__ ( \
25760 _PRE_EFLAGS("0", "4", "2") \
25761 _op _suffix " %"_x"3,%1; " \
25762@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
25763 /* Raw emulation: instruction has two explicit operands. */
25764 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
25765 do { \
25766- unsigned long _tmp; \
25767- \
25768 switch ((ctxt)->dst.bytes) { \
25769 case 2: \
25770 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
25771@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
25772
25773 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
25774 do { \
25775- unsigned long _tmp; \
25776 switch ((ctxt)->dst.bytes) { \
25777 case 1: \
25778 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
25779diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
25780index 0eee2c8..94a32c3 100644
25781--- a/arch/x86/kvm/lapic.c
25782+++ b/arch/x86/kvm/lapic.c
25783@@ -55,7 +55,7 @@
25784 #define APIC_BUS_CYCLE_NS 1
25785
25786 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
25787-#define apic_debug(fmt, arg...)
25788+#define apic_debug(fmt, arg...) do {} while (0)
25789
25790 #define APIC_LVT_NUM 6
25791 /* 14 is the version for Xeon and Pentium 8.4.8*/
25792diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
25793index da20860..d19fdf5 100644
25794--- a/arch/x86/kvm/paging_tmpl.h
25795+++ b/arch/x86/kvm/paging_tmpl.h
25796@@ -208,7 +208,7 @@ retry_walk:
25797 if (unlikely(kvm_is_error_hva(host_addr)))
25798 goto error;
25799
25800- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
25801+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
25802 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
25803 goto error;
25804 walker->ptep_user[walker->level - 1] = ptep_user;
25805diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
25806index a14a6ea..dc86cf0 100644
25807--- a/arch/x86/kvm/svm.c
25808+++ b/arch/x86/kvm/svm.c
25809@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
25810 int cpu = raw_smp_processor_id();
25811
25812 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
25813+
25814+ pax_open_kernel();
25815 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
25816+ pax_close_kernel();
25817+
25818 load_TR_desc();
25819 }
25820
25821@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
25822 #endif
25823 #endif
25824
25825+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25826+ __set_fs(current_thread_info()->addr_limit);
25827+#endif
25828+
25829 reload_tss(vcpu);
25830
25831 local_irq_disable();
25832diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
25833index 5402c94..c3bdeee 100644
25834--- a/arch/x86/kvm/vmx.c
25835+++ b/arch/x86/kvm/vmx.c
25836@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
25837 #endif
25838 }
25839
25840-static void vmcs_clear_bits(unsigned long field, u32 mask)
25841+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
25842 {
25843 vmcs_writel(field, vmcs_readl(field) & ~mask);
25844 }
25845
25846-static void vmcs_set_bits(unsigned long field, u32 mask)
25847+static void vmcs_set_bits(unsigned long field, unsigned long mask)
25848 {
25849 vmcs_writel(field, vmcs_readl(field) | mask);
25850 }
25851@@ -1517,7 +1517,11 @@ static void reload_tss(void)
25852 struct desc_struct *descs;
25853
25854 descs = (void *)gdt->address;
25855+
25856+ pax_open_kernel();
25857 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
25858+ pax_close_kernel();
25859+
25860 load_TR_desc();
25861 }
25862
25863@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
25864 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
25865 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
25866
25867+#ifdef CONFIG_PAX_PER_CPU_PGD
25868+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
25869+#endif
25870+
25871 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
25872 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
25873 vmx->loaded_vmcs->cpu = cpu;
25874@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
25875 if (!cpu_has_vmx_flexpriority())
25876 flexpriority_enabled = 0;
25877
25878- if (!cpu_has_vmx_tpr_shadow())
25879- kvm_x86_ops->update_cr8_intercept = NULL;
25880+ if (!cpu_has_vmx_tpr_shadow()) {
25881+ pax_open_kernel();
25882+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
25883+ pax_close_kernel();
25884+ }
25885
25886 if (enable_ept && !cpu_has_vmx_ept_2m_page())
25887 kvm_disable_largepages();
25888@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
25889 if (!cpu_has_vmx_apicv())
25890 enable_apicv = 0;
25891
25892+ pax_open_kernel();
25893 if (enable_apicv)
25894- kvm_x86_ops->update_cr8_intercept = NULL;
25895+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
25896 else {
25897- kvm_x86_ops->hwapic_irr_update = NULL;
25898- kvm_x86_ops->deliver_posted_interrupt = NULL;
25899- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
25900+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
25901+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
25902+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
25903 }
25904+ pax_close_kernel();
25905
25906 if (nested)
25907 nested_vmx_setup_ctls_msrs();
25908@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
25909
25910 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
25911 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
25912+
25913+#ifndef CONFIG_PAX_PER_CPU_PGD
25914 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
25915+#endif
25916
25917 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
25918 #ifdef CONFIG_X86_64
25919@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
25920 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
25921 vmx->host_idt_base = dt.address;
25922
25923- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
25924+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
25925
25926 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
25927 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
25928@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
25929 "jmp 2f \n\t"
25930 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
25931 "2: "
25932+
25933+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25934+ "ljmp %[cs],$3f\n\t"
25935+ "3: "
25936+#endif
25937+
25938 /* Save guest registers, load host registers, keep flags */
25939 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
25940 "pop %0 \n\t"
25941@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
25942 #endif
25943 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
25944 [wordsize]"i"(sizeof(ulong))
25945+
25946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25947+ ,[cs]"i"(__KERNEL_CS)
25948+#endif
25949+
25950 : "cc", "memory"
25951 #ifdef CONFIG_X86_64
25952 , "rax", "rbx", "rdi", "rsi"
25953@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
25954 if (debugctlmsr)
25955 update_debugctlmsr(debugctlmsr);
25956
25957-#ifndef CONFIG_X86_64
25958+#ifdef CONFIG_X86_32
25959 /*
25960 * The sysexit path does not restore ds/es, so we must set them to
25961 * a reasonable value ourselves.
25962@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
25963 * may be executed in interrupt context, which saves and restore segments
25964 * around it, nullifying its effect.
25965 */
25966- loadsegment(ds, __USER_DS);
25967- loadsegment(es, __USER_DS);
25968+ loadsegment(ds, __KERNEL_DS);
25969+ loadsegment(es, __KERNEL_DS);
25970+ loadsegment(ss, __KERNEL_DS);
25971+
25972+#ifdef CONFIG_PAX_KERNEXEC
25973+ loadsegment(fs, __KERNEL_PERCPU);
25974+#endif
25975+
25976+#ifdef CONFIG_PAX_MEMORY_UDEREF
25977+ __set_fs(current_thread_info()->addr_limit);
25978+#endif
25979+
25980 #endif
25981
25982 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
25983diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
25984index e8ba99c..ee9d7d9 100644
25985--- a/arch/x86/kvm/x86.c
25986+++ b/arch/x86/kvm/x86.c
25987@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
25988 {
25989 struct kvm *kvm = vcpu->kvm;
25990 int lm = is_long_mode(vcpu);
25991- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
25992- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
25993+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
25994+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
25995 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
25996 : kvm->arch.xen_hvm_config.blob_size_32;
25997 u32 page_num = data & ~PAGE_MASK;
25998@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
25999 if (n < msr_list.nmsrs)
26000 goto out;
26001 r = -EFAULT;
26002+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26003+ goto out;
26004 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26005 num_msrs_to_save * sizeof(u32)))
26006 goto out;
26007@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26008 };
26009 #endif
26010
26011-int kvm_arch_init(void *opaque)
26012+int kvm_arch_init(const void *opaque)
26013 {
26014 int r;
26015 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26016diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26017index 7114c63..a1018fc 100644
26018--- a/arch/x86/lguest/boot.c
26019+++ b/arch/x86/lguest/boot.c
26020@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26021 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26022 * Launcher to reboot us.
26023 */
26024-static void lguest_restart(char *reason)
26025+static __noreturn void lguest_restart(char *reason)
26026 {
26027 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26028+ BUG();
26029 }
26030
26031 /*G:050
26032diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26033index 00933d5..3a64af9 100644
26034--- a/arch/x86/lib/atomic64_386_32.S
26035+++ b/arch/x86/lib/atomic64_386_32.S
26036@@ -48,6 +48,10 @@ BEGIN(read)
26037 movl (v), %eax
26038 movl 4(v), %edx
26039 RET_ENDP
26040+BEGIN(read_unchecked)
26041+ movl (v), %eax
26042+ movl 4(v), %edx
26043+RET_ENDP
26044 #undef v
26045
26046 #define v %esi
26047@@ -55,6 +59,10 @@ BEGIN(set)
26048 movl %ebx, (v)
26049 movl %ecx, 4(v)
26050 RET_ENDP
26051+BEGIN(set_unchecked)
26052+ movl %ebx, (v)
26053+ movl %ecx, 4(v)
26054+RET_ENDP
26055 #undef v
26056
26057 #define v %esi
26058@@ -70,6 +78,20 @@ RET_ENDP
26059 BEGIN(add)
26060 addl %eax, (v)
26061 adcl %edx, 4(v)
26062+
26063+#ifdef CONFIG_PAX_REFCOUNT
26064+ jno 0f
26065+ subl %eax, (v)
26066+ sbbl %edx, 4(v)
26067+ int $4
26068+0:
26069+ _ASM_EXTABLE(0b, 0b)
26070+#endif
26071+
26072+RET_ENDP
26073+BEGIN(add_unchecked)
26074+ addl %eax, (v)
26075+ adcl %edx, 4(v)
26076 RET_ENDP
26077 #undef v
26078
26079@@ -77,6 +99,24 @@ RET_ENDP
26080 BEGIN(add_return)
26081 addl (v), %eax
26082 adcl 4(v), %edx
26083+
26084+#ifdef CONFIG_PAX_REFCOUNT
26085+ into
26086+1234:
26087+ _ASM_EXTABLE(1234b, 2f)
26088+#endif
26089+
26090+ movl %eax, (v)
26091+ movl %edx, 4(v)
26092+
26093+#ifdef CONFIG_PAX_REFCOUNT
26094+2:
26095+#endif
26096+
26097+RET_ENDP
26098+BEGIN(add_return_unchecked)
26099+ addl (v), %eax
26100+ adcl 4(v), %edx
26101 movl %eax, (v)
26102 movl %edx, 4(v)
26103 RET_ENDP
26104@@ -86,6 +126,20 @@ RET_ENDP
26105 BEGIN(sub)
26106 subl %eax, (v)
26107 sbbl %edx, 4(v)
26108+
26109+#ifdef CONFIG_PAX_REFCOUNT
26110+ jno 0f
26111+ addl %eax, (v)
26112+ adcl %edx, 4(v)
26113+ int $4
26114+0:
26115+ _ASM_EXTABLE(0b, 0b)
26116+#endif
26117+
26118+RET_ENDP
26119+BEGIN(sub_unchecked)
26120+ subl %eax, (v)
26121+ sbbl %edx, 4(v)
26122 RET_ENDP
26123 #undef v
26124
26125@@ -96,6 +150,27 @@ BEGIN(sub_return)
26126 sbbl $0, %edx
26127 addl (v), %eax
26128 adcl 4(v), %edx
26129+
26130+#ifdef CONFIG_PAX_REFCOUNT
26131+ into
26132+1234:
26133+ _ASM_EXTABLE(1234b, 2f)
26134+#endif
26135+
26136+ movl %eax, (v)
26137+ movl %edx, 4(v)
26138+
26139+#ifdef CONFIG_PAX_REFCOUNT
26140+2:
26141+#endif
26142+
26143+RET_ENDP
26144+BEGIN(sub_return_unchecked)
26145+ negl %edx
26146+ negl %eax
26147+ sbbl $0, %edx
26148+ addl (v), %eax
26149+ adcl 4(v), %edx
26150 movl %eax, (v)
26151 movl %edx, 4(v)
26152 RET_ENDP
26153@@ -105,6 +180,20 @@ RET_ENDP
26154 BEGIN(inc)
26155 addl $1, (v)
26156 adcl $0, 4(v)
26157+
26158+#ifdef CONFIG_PAX_REFCOUNT
26159+ jno 0f
26160+ subl $1, (v)
26161+ sbbl $0, 4(v)
26162+ int $4
26163+0:
26164+ _ASM_EXTABLE(0b, 0b)
26165+#endif
26166+
26167+RET_ENDP
26168+BEGIN(inc_unchecked)
26169+ addl $1, (v)
26170+ adcl $0, 4(v)
26171 RET_ENDP
26172 #undef v
26173
26174@@ -114,6 +203,26 @@ BEGIN(inc_return)
26175 movl 4(v), %edx
26176 addl $1, %eax
26177 adcl $0, %edx
26178+
26179+#ifdef CONFIG_PAX_REFCOUNT
26180+ into
26181+1234:
26182+ _ASM_EXTABLE(1234b, 2f)
26183+#endif
26184+
26185+ movl %eax, (v)
26186+ movl %edx, 4(v)
26187+
26188+#ifdef CONFIG_PAX_REFCOUNT
26189+2:
26190+#endif
26191+
26192+RET_ENDP
26193+BEGIN(inc_return_unchecked)
26194+ movl (v), %eax
26195+ movl 4(v), %edx
26196+ addl $1, %eax
26197+ adcl $0, %edx
26198 movl %eax, (v)
26199 movl %edx, 4(v)
26200 RET_ENDP
26201@@ -123,6 +232,20 @@ RET_ENDP
26202 BEGIN(dec)
26203 subl $1, (v)
26204 sbbl $0, 4(v)
26205+
26206+#ifdef CONFIG_PAX_REFCOUNT
26207+ jno 0f
26208+ addl $1, (v)
26209+ adcl $0, 4(v)
26210+ int $4
26211+0:
26212+ _ASM_EXTABLE(0b, 0b)
26213+#endif
26214+
26215+RET_ENDP
26216+BEGIN(dec_unchecked)
26217+ subl $1, (v)
26218+ sbbl $0, 4(v)
26219 RET_ENDP
26220 #undef v
26221
26222@@ -132,6 +255,26 @@ BEGIN(dec_return)
26223 movl 4(v), %edx
26224 subl $1, %eax
26225 sbbl $0, %edx
26226+
26227+#ifdef CONFIG_PAX_REFCOUNT
26228+ into
26229+1234:
26230+ _ASM_EXTABLE(1234b, 2f)
26231+#endif
26232+
26233+ movl %eax, (v)
26234+ movl %edx, 4(v)
26235+
26236+#ifdef CONFIG_PAX_REFCOUNT
26237+2:
26238+#endif
26239+
26240+RET_ENDP
26241+BEGIN(dec_return_unchecked)
26242+ movl (v), %eax
26243+ movl 4(v), %edx
26244+ subl $1, %eax
26245+ sbbl $0, %edx
26246 movl %eax, (v)
26247 movl %edx, 4(v)
26248 RET_ENDP
26249@@ -143,6 +286,13 @@ BEGIN(add_unless)
26250 adcl %edx, %edi
26251 addl (v), %eax
26252 adcl 4(v), %edx
26253+
26254+#ifdef CONFIG_PAX_REFCOUNT
26255+ into
26256+1234:
26257+ _ASM_EXTABLE(1234b, 2f)
26258+#endif
26259+
26260 cmpl %eax, %ecx
26261 je 3f
26262 1:
26263@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
26264 1:
26265 addl $1, %eax
26266 adcl $0, %edx
26267+
26268+#ifdef CONFIG_PAX_REFCOUNT
26269+ into
26270+1234:
26271+ _ASM_EXTABLE(1234b, 2f)
26272+#endif
26273+
26274 movl %eax, (v)
26275 movl %edx, 4(v)
26276 movl $1, %eax
26277@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
26278 movl 4(v), %edx
26279 subl $1, %eax
26280 sbbl $0, %edx
26281+
26282+#ifdef CONFIG_PAX_REFCOUNT
26283+ into
26284+1234:
26285+ _ASM_EXTABLE(1234b, 1f)
26286+#endif
26287+
26288 js 1f
26289 movl %eax, (v)
26290 movl %edx, 4(v)
26291diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
26292index f5cc9eb..51fa319 100644
26293--- a/arch/x86/lib/atomic64_cx8_32.S
26294+++ b/arch/x86/lib/atomic64_cx8_32.S
26295@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
26296 CFI_STARTPROC
26297
26298 read64 %ecx
26299+ pax_force_retaddr
26300 ret
26301 CFI_ENDPROC
26302 ENDPROC(atomic64_read_cx8)
26303
26304+ENTRY(atomic64_read_unchecked_cx8)
26305+ CFI_STARTPROC
26306+
26307+ read64 %ecx
26308+ pax_force_retaddr
26309+ ret
26310+ CFI_ENDPROC
26311+ENDPROC(atomic64_read_unchecked_cx8)
26312+
26313 ENTRY(atomic64_set_cx8)
26314 CFI_STARTPROC
26315
26316@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
26317 cmpxchg8b (%esi)
26318 jne 1b
26319
26320+ pax_force_retaddr
26321 ret
26322 CFI_ENDPROC
26323 ENDPROC(atomic64_set_cx8)
26324
26325+ENTRY(atomic64_set_unchecked_cx8)
26326+ CFI_STARTPROC
26327+
26328+1:
26329+/* we don't need LOCK_PREFIX since aligned 64-bit writes
26330+ * are atomic on 586 and newer */
26331+ cmpxchg8b (%esi)
26332+ jne 1b
26333+
26334+ pax_force_retaddr
26335+ ret
26336+ CFI_ENDPROC
26337+ENDPROC(atomic64_set_unchecked_cx8)
26338+
26339 ENTRY(atomic64_xchg_cx8)
26340 CFI_STARTPROC
26341
26342@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
26343 cmpxchg8b (%esi)
26344 jne 1b
26345
26346+ pax_force_retaddr
26347 ret
26348 CFI_ENDPROC
26349 ENDPROC(atomic64_xchg_cx8)
26350
26351-.macro addsub_return func ins insc
26352-ENTRY(atomic64_\func\()_return_cx8)
26353+.macro addsub_return func ins insc unchecked=""
26354+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
26355 CFI_STARTPROC
26356 SAVE ebp
26357 SAVE ebx
26358@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
26359 movl %edx, %ecx
26360 \ins\()l %esi, %ebx
26361 \insc\()l %edi, %ecx
26362+
26363+.ifb \unchecked
26364+#ifdef CONFIG_PAX_REFCOUNT
26365+ into
26366+2:
26367+ _ASM_EXTABLE(2b, 3f)
26368+#endif
26369+.endif
26370+
26371 LOCK_PREFIX
26372 cmpxchg8b (%ebp)
26373 jne 1b
26374-
26375-10:
26376 movl %ebx, %eax
26377 movl %ecx, %edx
26378+
26379+.ifb \unchecked
26380+#ifdef CONFIG_PAX_REFCOUNT
26381+3:
26382+#endif
26383+.endif
26384+
26385 RESTORE edi
26386 RESTORE esi
26387 RESTORE ebx
26388 RESTORE ebp
26389+ pax_force_retaddr
26390 ret
26391 CFI_ENDPROC
26392-ENDPROC(atomic64_\func\()_return_cx8)
26393+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
26394 .endm
26395
26396 addsub_return add add adc
26397 addsub_return sub sub sbb
26398+addsub_return add add adc _unchecked
26399+addsub_return sub sub sbb _unchecked
26400
26401-.macro incdec_return func ins insc
26402-ENTRY(atomic64_\func\()_return_cx8)
26403+.macro incdec_return func ins insc unchecked=""
26404+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
26405 CFI_STARTPROC
26406 SAVE ebx
26407
26408@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
26409 movl %edx, %ecx
26410 \ins\()l $1, %ebx
26411 \insc\()l $0, %ecx
26412+
26413+.ifb \unchecked
26414+#ifdef CONFIG_PAX_REFCOUNT
26415+ into
26416+2:
26417+ _ASM_EXTABLE(2b, 3f)
26418+#endif
26419+.endif
26420+
26421 LOCK_PREFIX
26422 cmpxchg8b (%esi)
26423 jne 1b
26424
26425-10:
26426 movl %ebx, %eax
26427 movl %ecx, %edx
26428+
26429+.ifb \unchecked
26430+#ifdef CONFIG_PAX_REFCOUNT
26431+3:
26432+#endif
26433+.endif
26434+
26435 RESTORE ebx
26436+ pax_force_retaddr
26437 ret
26438 CFI_ENDPROC
26439-ENDPROC(atomic64_\func\()_return_cx8)
26440+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
26441 .endm
26442
26443 incdec_return inc add adc
26444 incdec_return dec sub sbb
26445+incdec_return inc add adc _unchecked
26446+incdec_return dec sub sbb _unchecked
26447
26448 ENTRY(atomic64_dec_if_positive_cx8)
26449 CFI_STARTPROC
26450@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
26451 movl %edx, %ecx
26452 subl $1, %ebx
26453 sbb $0, %ecx
26454+
26455+#ifdef CONFIG_PAX_REFCOUNT
26456+ into
26457+1234:
26458+ _ASM_EXTABLE(1234b, 2f)
26459+#endif
26460+
26461 js 2f
26462 LOCK_PREFIX
26463 cmpxchg8b (%esi)
26464@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
26465 movl %ebx, %eax
26466 movl %ecx, %edx
26467 RESTORE ebx
26468+ pax_force_retaddr
26469 ret
26470 CFI_ENDPROC
26471 ENDPROC(atomic64_dec_if_positive_cx8)
26472@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
26473 movl %edx, %ecx
26474 addl %ebp, %ebx
26475 adcl %edi, %ecx
26476+
26477+#ifdef CONFIG_PAX_REFCOUNT
26478+ into
26479+1234:
26480+ _ASM_EXTABLE(1234b, 3f)
26481+#endif
26482+
26483 LOCK_PREFIX
26484 cmpxchg8b (%esi)
26485 jne 1b
26486@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
26487 CFI_ADJUST_CFA_OFFSET -8
26488 RESTORE ebx
26489 RESTORE ebp
26490+ pax_force_retaddr
26491 ret
26492 4:
26493 cmpl %edx, 4(%esp)
26494@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
26495 xorl %ecx, %ecx
26496 addl $1, %ebx
26497 adcl %edx, %ecx
26498+
26499+#ifdef CONFIG_PAX_REFCOUNT
26500+ into
26501+1234:
26502+ _ASM_EXTABLE(1234b, 3f)
26503+#endif
26504+
26505 LOCK_PREFIX
26506 cmpxchg8b (%esi)
26507 jne 1b
26508@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
26509 movl $1, %eax
26510 3:
26511 RESTORE ebx
26512+ pax_force_retaddr
26513 ret
26514 CFI_ENDPROC
26515 ENDPROC(atomic64_inc_not_zero_cx8)
26516diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
26517index e78b8ee..7e173a8 100644
26518--- a/arch/x86/lib/checksum_32.S
26519+++ b/arch/x86/lib/checksum_32.S
26520@@ -29,7 +29,8 @@
26521 #include <asm/dwarf2.h>
26522 #include <asm/errno.h>
26523 #include <asm/asm.h>
26524-
26525+#include <asm/segment.h>
26526+
26527 /*
26528 * computes a partial checksum, e.g. for TCP/UDP fragments
26529 */
26530@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
26531
26532 #define ARGBASE 16
26533 #define FP 12
26534-
26535-ENTRY(csum_partial_copy_generic)
26536+
26537+ENTRY(csum_partial_copy_generic_to_user)
26538 CFI_STARTPROC
26539+
26540+#ifdef CONFIG_PAX_MEMORY_UDEREF
26541+ pushl_cfi %gs
26542+ popl_cfi %es
26543+ jmp csum_partial_copy_generic
26544+#endif
26545+
26546+ENTRY(csum_partial_copy_generic_from_user)
26547+
26548+#ifdef CONFIG_PAX_MEMORY_UDEREF
26549+ pushl_cfi %gs
26550+ popl_cfi %ds
26551+#endif
26552+
26553+ENTRY(csum_partial_copy_generic)
26554 subl $4,%esp
26555 CFI_ADJUST_CFA_OFFSET 4
26556 pushl_cfi %edi
26557@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
26558 jmp 4f
26559 SRC(1: movw (%esi), %bx )
26560 addl $2, %esi
26561-DST( movw %bx, (%edi) )
26562+DST( movw %bx, %es:(%edi) )
26563 addl $2, %edi
26564 addw %bx, %ax
26565 adcl $0, %eax
26566@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
26567 SRC(1: movl (%esi), %ebx )
26568 SRC( movl 4(%esi), %edx )
26569 adcl %ebx, %eax
26570-DST( movl %ebx, (%edi) )
26571+DST( movl %ebx, %es:(%edi) )
26572 adcl %edx, %eax
26573-DST( movl %edx, 4(%edi) )
26574+DST( movl %edx, %es:4(%edi) )
26575
26576 SRC( movl 8(%esi), %ebx )
26577 SRC( movl 12(%esi), %edx )
26578 adcl %ebx, %eax
26579-DST( movl %ebx, 8(%edi) )
26580+DST( movl %ebx, %es:8(%edi) )
26581 adcl %edx, %eax
26582-DST( movl %edx, 12(%edi) )
26583+DST( movl %edx, %es:12(%edi) )
26584
26585 SRC( movl 16(%esi), %ebx )
26586 SRC( movl 20(%esi), %edx )
26587 adcl %ebx, %eax
26588-DST( movl %ebx, 16(%edi) )
26589+DST( movl %ebx, %es:16(%edi) )
26590 adcl %edx, %eax
26591-DST( movl %edx, 20(%edi) )
26592+DST( movl %edx, %es:20(%edi) )
26593
26594 SRC( movl 24(%esi), %ebx )
26595 SRC( movl 28(%esi), %edx )
26596 adcl %ebx, %eax
26597-DST( movl %ebx, 24(%edi) )
26598+DST( movl %ebx, %es:24(%edi) )
26599 adcl %edx, %eax
26600-DST( movl %edx, 28(%edi) )
26601+DST( movl %edx, %es:28(%edi) )
26602
26603 lea 32(%esi), %esi
26604 lea 32(%edi), %edi
26605@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
26606 shrl $2, %edx # This clears CF
26607 SRC(3: movl (%esi), %ebx )
26608 adcl %ebx, %eax
26609-DST( movl %ebx, (%edi) )
26610+DST( movl %ebx, %es:(%edi) )
26611 lea 4(%esi), %esi
26612 lea 4(%edi), %edi
26613 dec %edx
26614@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
26615 jb 5f
26616 SRC( movw (%esi), %cx )
26617 leal 2(%esi), %esi
26618-DST( movw %cx, (%edi) )
26619+DST( movw %cx, %es:(%edi) )
26620 leal 2(%edi), %edi
26621 je 6f
26622 shll $16,%ecx
26623 SRC(5: movb (%esi), %cl )
26624-DST( movb %cl, (%edi) )
26625+DST( movb %cl, %es:(%edi) )
26626 6: addl %ecx, %eax
26627 adcl $0, %eax
26628 7:
26629@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
26630
26631 6001:
26632 movl ARGBASE+20(%esp), %ebx # src_err_ptr
26633- movl $-EFAULT, (%ebx)
26634+ movl $-EFAULT, %ss:(%ebx)
26635
26636 # zero the complete destination - computing the rest
26637 # is too much work
26638@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
26639
26640 6002:
26641 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
26642- movl $-EFAULT,(%ebx)
26643+ movl $-EFAULT,%ss:(%ebx)
26644 jmp 5000b
26645
26646 .previous
26647
26648+ pushl_cfi %ss
26649+ popl_cfi %ds
26650+ pushl_cfi %ss
26651+ popl_cfi %es
26652 popl_cfi %ebx
26653 CFI_RESTORE ebx
26654 popl_cfi %esi
26655@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
26656 popl_cfi %ecx # equivalent to addl $4,%esp
26657 ret
26658 CFI_ENDPROC
26659-ENDPROC(csum_partial_copy_generic)
26660+ENDPROC(csum_partial_copy_generic_to_user)
26661
26662 #else
26663
26664 /* Version for PentiumII/PPro */
26665
26666 #define ROUND1(x) \
26667+ nop; nop; nop; \
26668 SRC(movl x(%esi), %ebx ) ; \
26669 addl %ebx, %eax ; \
26670- DST(movl %ebx, x(%edi) ) ;
26671+ DST(movl %ebx, %es:x(%edi)) ;
26672
26673 #define ROUND(x) \
26674+ nop; nop; nop; \
26675 SRC(movl x(%esi), %ebx ) ; \
26676 adcl %ebx, %eax ; \
26677- DST(movl %ebx, x(%edi) ) ;
26678+ DST(movl %ebx, %es:x(%edi)) ;
26679
26680 #define ARGBASE 12
26681-
26682-ENTRY(csum_partial_copy_generic)
26683+
26684+ENTRY(csum_partial_copy_generic_to_user)
26685 CFI_STARTPROC
26686+
26687+#ifdef CONFIG_PAX_MEMORY_UDEREF
26688+ pushl_cfi %gs
26689+ popl_cfi %es
26690+ jmp csum_partial_copy_generic
26691+#endif
26692+
26693+ENTRY(csum_partial_copy_generic_from_user)
26694+
26695+#ifdef CONFIG_PAX_MEMORY_UDEREF
26696+ pushl_cfi %gs
26697+ popl_cfi %ds
26698+#endif
26699+
26700+ENTRY(csum_partial_copy_generic)
26701 pushl_cfi %ebx
26702 CFI_REL_OFFSET ebx, 0
26703 pushl_cfi %edi
26704@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
26705 subl %ebx, %edi
26706 lea -1(%esi),%edx
26707 andl $-32,%edx
26708- lea 3f(%ebx,%ebx), %ebx
26709+ lea 3f(%ebx,%ebx,2), %ebx
26710 testl %esi, %esi
26711 jmp *%ebx
26712 1: addl $64,%esi
26713@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
26714 jb 5f
26715 SRC( movw (%esi), %dx )
26716 leal 2(%esi), %esi
26717-DST( movw %dx, (%edi) )
26718+DST( movw %dx, %es:(%edi) )
26719 leal 2(%edi), %edi
26720 je 6f
26721 shll $16,%edx
26722 5:
26723 SRC( movb (%esi), %dl )
26724-DST( movb %dl, (%edi) )
26725+DST( movb %dl, %es:(%edi) )
26726 6: addl %edx, %eax
26727 adcl $0, %eax
26728 7:
26729 .section .fixup, "ax"
26730 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
26731- movl $-EFAULT, (%ebx)
26732+ movl $-EFAULT, %ss:(%ebx)
26733 # zero the complete destination (computing the rest is too much work)
26734 movl ARGBASE+8(%esp),%edi # dst
26735 movl ARGBASE+12(%esp),%ecx # len
26736@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
26737 rep; stosb
26738 jmp 7b
26739 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
26740- movl $-EFAULT, (%ebx)
26741+ movl $-EFAULT, %ss:(%ebx)
26742 jmp 7b
26743 .previous
26744
26745+#ifdef CONFIG_PAX_MEMORY_UDEREF
26746+ pushl_cfi %ss
26747+ popl_cfi %ds
26748+ pushl_cfi %ss
26749+ popl_cfi %es
26750+#endif
26751+
26752 popl_cfi %esi
26753 CFI_RESTORE esi
26754 popl_cfi %edi
26755@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
26756 CFI_RESTORE ebx
26757 ret
26758 CFI_ENDPROC
26759-ENDPROC(csum_partial_copy_generic)
26760+ENDPROC(csum_partial_copy_generic_to_user)
26761
26762 #undef ROUND
26763 #undef ROUND1
26764diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
26765index f2145cf..cea889d 100644
26766--- a/arch/x86/lib/clear_page_64.S
26767+++ b/arch/x86/lib/clear_page_64.S
26768@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
26769 movl $4096/8,%ecx
26770 xorl %eax,%eax
26771 rep stosq
26772+ pax_force_retaddr
26773 ret
26774 CFI_ENDPROC
26775 ENDPROC(clear_page_c)
26776@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
26777 movl $4096,%ecx
26778 xorl %eax,%eax
26779 rep stosb
26780+ pax_force_retaddr
26781 ret
26782 CFI_ENDPROC
26783 ENDPROC(clear_page_c_e)
26784@@ -43,6 +45,7 @@ ENTRY(clear_page)
26785 leaq 64(%rdi),%rdi
26786 jnz .Lloop
26787 nop
26788+ pax_force_retaddr
26789 ret
26790 CFI_ENDPROC
26791 .Lclear_page_end:
26792@@ -58,7 +61,7 @@ ENDPROC(clear_page)
26793
26794 #include <asm/cpufeature.h>
26795
26796- .section .altinstr_replacement,"ax"
26797+ .section .altinstr_replacement,"a"
26798 1: .byte 0xeb /* jmp <disp8> */
26799 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
26800 2: .byte 0xeb /* jmp <disp8> */
26801diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
26802index 1e572c5..2a162cd 100644
26803--- a/arch/x86/lib/cmpxchg16b_emu.S
26804+++ b/arch/x86/lib/cmpxchg16b_emu.S
26805@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
26806
26807 popf
26808 mov $1, %al
26809+ pax_force_retaddr
26810 ret
26811
26812 not_same:
26813 popf
26814 xor %al,%al
26815+ pax_force_retaddr
26816 ret
26817
26818 CFI_ENDPROC
26819diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
26820index 176cca6..1166c50 100644
26821--- a/arch/x86/lib/copy_page_64.S
26822+++ b/arch/x86/lib/copy_page_64.S
26823@@ -9,6 +9,7 @@ copy_page_rep:
26824 CFI_STARTPROC
26825 movl $4096/8, %ecx
26826 rep movsq
26827+ pax_force_retaddr
26828 ret
26829 CFI_ENDPROC
26830 ENDPROC(copy_page_rep)
26831@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
26832
26833 ENTRY(copy_page)
26834 CFI_STARTPROC
26835- subq $2*8, %rsp
26836- CFI_ADJUST_CFA_OFFSET 2*8
26837+ subq $3*8, %rsp
26838+ CFI_ADJUST_CFA_OFFSET 3*8
26839 movq %rbx, (%rsp)
26840 CFI_REL_OFFSET rbx, 0
26841 movq %r12, 1*8(%rsp)
26842 CFI_REL_OFFSET r12, 1*8
26843+ movq %r13, 2*8(%rsp)
26844+ CFI_REL_OFFSET r13, 2*8
26845
26846 movl $(4096/64)-5, %ecx
26847 .p2align 4
26848@@ -36,7 +39,7 @@ ENTRY(copy_page)
26849 movq 0x8*2(%rsi), %rdx
26850 movq 0x8*3(%rsi), %r8
26851 movq 0x8*4(%rsi), %r9
26852- movq 0x8*5(%rsi), %r10
26853+ movq 0x8*5(%rsi), %r13
26854 movq 0x8*6(%rsi), %r11
26855 movq 0x8*7(%rsi), %r12
26856
26857@@ -47,7 +50,7 @@ ENTRY(copy_page)
26858 movq %rdx, 0x8*2(%rdi)
26859 movq %r8, 0x8*3(%rdi)
26860 movq %r9, 0x8*4(%rdi)
26861- movq %r10, 0x8*5(%rdi)
26862+ movq %r13, 0x8*5(%rdi)
26863 movq %r11, 0x8*6(%rdi)
26864 movq %r12, 0x8*7(%rdi)
26865
26866@@ -66,7 +69,7 @@ ENTRY(copy_page)
26867 movq 0x8*2(%rsi), %rdx
26868 movq 0x8*3(%rsi), %r8
26869 movq 0x8*4(%rsi), %r9
26870- movq 0x8*5(%rsi), %r10
26871+ movq 0x8*5(%rsi), %r13
26872 movq 0x8*6(%rsi), %r11
26873 movq 0x8*7(%rsi), %r12
26874
26875@@ -75,7 +78,7 @@ ENTRY(copy_page)
26876 movq %rdx, 0x8*2(%rdi)
26877 movq %r8, 0x8*3(%rdi)
26878 movq %r9, 0x8*4(%rdi)
26879- movq %r10, 0x8*5(%rdi)
26880+ movq %r13, 0x8*5(%rdi)
26881 movq %r11, 0x8*6(%rdi)
26882 movq %r12, 0x8*7(%rdi)
26883
26884@@ -87,8 +90,11 @@ ENTRY(copy_page)
26885 CFI_RESTORE rbx
26886 movq 1*8(%rsp), %r12
26887 CFI_RESTORE r12
26888- addq $2*8, %rsp
26889- CFI_ADJUST_CFA_OFFSET -2*8
26890+ movq 2*8(%rsp), %r13
26891+ CFI_RESTORE r13
26892+ addq $3*8, %rsp
26893+ CFI_ADJUST_CFA_OFFSET -3*8
26894+ pax_force_retaddr
26895 ret
26896 .Lcopy_page_end:
26897 CFI_ENDPROC
26898@@ -99,7 +105,7 @@ ENDPROC(copy_page)
26899
26900 #include <asm/cpufeature.h>
26901
26902- .section .altinstr_replacement,"ax"
26903+ .section .altinstr_replacement,"a"
26904 1: .byte 0xeb /* jmp <disp8> */
26905 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
26906 2:
26907diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
26908index a30ca15..6b3f4e1 100644
26909--- a/arch/x86/lib/copy_user_64.S
26910+++ b/arch/x86/lib/copy_user_64.S
26911@@ -18,31 +18,7 @@
26912 #include <asm/alternative-asm.h>
26913 #include <asm/asm.h>
26914 #include <asm/smap.h>
26915-
26916-/*
26917- * By placing feature2 after feature1 in altinstructions section, we logically
26918- * implement:
26919- * If CPU has feature2, jmp to alt2 is used
26920- * else if CPU has feature1, jmp to alt1 is used
26921- * else jmp to orig is used.
26922- */
26923- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
26924-0:
26925- .byte 0xe9 /* 32bit jump */
26926- .long \orig-1f /* by default jump to orig */
26927-1:
26928- .section .altinstr_replacement,"ax"
26929-2: .byte 0xe9 /* near jump with 32bit immediate */
26930- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
26931-3: .byte 0xe9 /* near jump with 32bit immediate */
26932- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
26933- .previous
26934-
26935- .section .altinstructions,"a"
26936- altinstruction_entry 0b,2b,\feature1,5,5
26937- altinstruction_entry 0b,3b,\feature2,5,5
26938- .previous
26939- .endm
26940+#include <asm/pgtable.h>
26941
26942 .macro ALIGN_DESTINATION
26943 #ifdef FIX_ALIGNMENT
26944@@ -70,52 +46,6 @@
26945 #endif
26946 .endm
26947
26948-/* Standard copy_to_user with segment limit checking */
26949-ENTRY(_copy_to_user)
26950- CFI_STARTPROC
26951- GET_THREAD_INFO(%rax)
26952- movq %rdi,%rcx
26953- addq %rdx,%rcx
26954- jc bad_to_user
26955- cmpq TI_addr_limit(%rax),%rcx
26956- ja bad_to_user
26957- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
26958- copy_user_generic_unrolled,copy_user_generic_string, \
26959- copy_user_enhanced_fast_string
26960- CFI_ENDPROC
26961-ENDPROC(_copy_to_user)
26962-
26963-/* Standard copy_from_user with segment limit checking */
26964-ENTRY(_copy_from_user)
26965- CFI_STARTPROC
26966- GET_THREAD_INFO(%rax)
26967- movq %rsi,%rcx
26968- addq %rdx,%rcx
26969- jc bad_from_user
26970- cmpq TI_addr_limit(%rax),%rcx
26971- ja bad_from_user
26972- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
26973- copy_user_generic_unrolled,copy_user_generic_string, \
26974- copy_user_enhanced_fast_string
26975- CFI_ENDPROC
26976-ENDPROC(_copy_from_user)
26977-
26978- .section .fixup,"ax"
26979- /* must zero dest */
26980-ENTRY(bad_from_user)
26981-bad_from_user:
26982- CFI_STARTPROC
26983- movl %edx,%ecx
26984- xorl %eax,%eax
26985- rep
26986- stosb
26987-bad_to_user:
26988- movl %edx,%eax
26989- ret
26990- CFI_ENDPROC
26991-ENDPROC(bad_from_user)
26992- .previous
26993-
26994 /*
26995 * copy_user_generic_unrolled - memory copy with exception handling.
26996 * This version is for CPUs like P4 that don't have efficient micro
26997@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
26998 */
26999 ENTRY(copy_user_generic_unrolled)
27000 CFI_STARTPROC
27001+ ASM_PAX_OPEN_USERLAND
27002 ASM_STAC
27003 cmpl $8,%edx
27004 jb 20f /* less then 8 bytes, go to byte copy loop */
27005@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27006 jz 17f
27007 1: movq (%rsi),%r8
27008 2: movq 1*8(%rsi),%r9
27009-3: movq 2*8(%rsi),%r10
27010+3: movq 2*8(%rsi),%rax
27011 4: movq 3*8(%rsi),%r11
27012 5: movq %r8,(%rdi)
27013 6: movq %r9,1*8(%rdi)
27014-7: movq %r10,2*8(%rdi)
27015+7: movq %rax,2*8(%rdi)
27016 8: movq %r11,3*8(%rdi)
27017 9: movq 4*8(%rsi),%r8
27018 10: movq 5*8(%rsi),%r9
27019-11: movq 6*8(%rsi),%r10
27020+11: movq 6*8(%rsi),%rax
27021 12: movq 7*8(%rsi),%r11
27022 13: movq %r8,4*8(%rdi)
27023 14: movq %r9,5*8(%rdi)
27024-15: movq %r10,6*8(%rdi)
27025+15: movq %rax,6*8(%rdi)
27026 16: movq %r11,7*8(%rdi)
27027 leaq 64(%rsi),%rsi
27028 leaq 64(%rdi),%rdi
27029@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27030 jnz 21b
27031 23: xor %eax,%eax
27032 ASM_CLAC
27033+ ASM_PAX_CLOSE_USERLAND
27034+ pax_force_retaddr
27035 ret
27036
27037 .section .fixup,"ax"
27038@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27039 */
27040 ENTRY(copy_user_generic_string)
27041 CFI_STARTPROC
27042+ ASM_PAX_OPEN_USERLAND
27043 ASM_STAC
27044 andl %edx,%edx
27045 jz 4f
27046@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27047 movsb
27048 4: xorl %eax,%eax
27049 ASM_CLAC
27050+ ASM_PAX_CLOSE_USERLAND
27051+ pax_force_retaddr
27052 ret
27053
27054 .section .fixup,"ax"
27055@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27056 */
27057 ENTRY(copy_user_enhanced_fast_string)
27058 CFI_STARTPROC
27059+ ASM_PAX_OPEN_USERLAND
27060 ASM_STAC
27061 andl %edx,%edx
27062 jz 2f
27063@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27064 movsb
27065 2: xorl %eax,%eax
27066 ASM_CLAC
27067+ ASM_PAX_CLOSE_USERLAND
27068+ pax_force_retaddr
27069 ret
27070
27071 .section .fixup,"ax"
27072diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27073index 6a4f43c..55d26f2 100644
27074--- a/arch/x86/lib/copy_user_nocache_64.S
27075+++ b/arch/x86/lib/copy_user_nocache_64.S
27076@@ -8,6 +8,7 @@
27077
27078 #include <linux/linkage.h>
27079 #include <asm/dwarf2.h>
27080+#include <asm/alternative-asm.h>
27081
27082 #define FIX_ALIGNMENT 1
27083
27084@@ -16,6 +17,7 @@
27085 #include <asm/thread_info.h>
27086 #include <asm/asm.h>
27087 #include <asm/smap.h>
27088+#include <asm/pgtable.h>
27089
27090 .macro ALIGN_DESTINATION
27091 #ifdef FIX_ALIGNMENT
27092@@ -49,6 +51,16 @@
27093 */
27094 ENTRY(__copy_user_nocache)
27095 CFI_STARTPROC
27096+
27097+#ifdef CONFIG_PAX_MEMORY_UDEREF
27098+ mov pax_user_shadow_base,%rcx
27099+ cmp %rcx,%rsi
27100+ jae 1f
27101+ add %rcx,%rsi
27102+1:
27103+#endif
27104+
27105+ ASM_PAX_OPEN_USERLAND
27106 ASM_STAC
27107 cmpl $8,%edx
27108 jb 20f /* less then 8 bytes, go to byte copy loop */
27109@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27110 jz 17f
27111 1: movq (%rsi),%r8
27112 2: movq 1*8(%rsi),%r9
27113-3: movq 2*8(%rsi),%r10
27114+3: movq 2*8(%rsi),%rax
27115 4: movq 3*8(%rsi),%r11
27116 5: movnti %r8,(%rdi)
27117 6: movnti %r9,1*8(%rdi)
27118-7: movnti %r10,2*8(%rdi)
27119+7: movnti %rax,2*8(%rdi)
27120 8: movnti %r11,3*8(%rdi)
27121 9: movq 4*8(%rsi),%r8
27122 10: movq 5*8(%rsi),%r9
27123-11: movq 6*8(%rsi),%r10
27124+11: movq 6*8(%rsi),%rax
27125 12: movq 7*8(%rsi),%r11
27126 13: movnti %r8,4*8(%rdi)
27127 14: movnti %r9,5*8(%rdi)
27128-15: movnti %r10,6*8(%rdi)
27129+15: movnti %rax,6*8(%rdi)
27130 16: movnti %r11,7*8(%rdi)
27131 leaq 64(%rsi),%rsi
27132 leaq 64(%rdi),%rdi
27133@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27134 jnz 21b
27135 23: xorl %eax,%eax
27136 ASM_CLAC
27137+ ASM_PAX_CLOSE_USERLAND
27138 sfence
27139+ pax_force_retaddr
27140 ret
27141
27142 .section .fixup,"ax"
27143diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27144index 2419d5f..953ee51 100644
27145--- a/arch/x86/lib/csum-copy_64.S
27146+++ b/arch/x86/lib/csum-copy_64.S
27147@@ -9,6 +9,7 @@
27148 #include <asm/dwarf2.h>
27149 #include <asm/errno.h>
27150 #include <asm/asm.h>
27151+#include <asm/alternative-asm.h>
27152
27153 /*
27154 * Checksum copy with exception handling.
27155@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27156 CFI_RESTORE rbp
27157 addq $7*8, %rsp
27158 CFI_ADJUST_CFA_OFFSET -7*8
27159+ pax_force_retaddr 0, 1
27160 ret
27161 CFI_RESTORE_STATE
27162
27163diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27164index 25b7ae8..c40113e 100644
27165--- a/arch/x86/lib/csum-wrappers_64.c
27166+++ b/arch/x86/lib/csum-wrappers_64.c
27167@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27168 len -= 2;
27169 }
27170 }
27171- isum = csum_partial_copy_generic((__force const void *)src,
27172+ pax_open_userland();
27173+ stac();
27174+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27175 dst, len, isum, errp, NULL);
27176+ clac();
27177+ pax_close_userland();
27178 if (unlikely(*errp))
27179 goto out_err;
27180
27181@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27182 }
27183
27184 *errp = 0;
27185- return csum_partial_copy_generic(src, (void __force *)dst,
27186+ pax_open_userland();
27187+ stac();
27188+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27189 len, isum, NULL, errp);
27190+ clac();
27191+ pax_close_userland();
27192+ return isum;
27193 }
27194 EXPORT_SYMBOL(csum_partial_copy_to_user);
27195
27196diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27197index a451235..1daa956 100644
27198--- a/arch/x86/lib/getuser.S
27199+++ b/arch/x86/lib/getuser.S
27200@@ -33,17 +33,40 @@
27201 #include <asm/thread_info.h>
27202 #include <asm/asm.h>
27203 #include <asm/smap.h>
27204+#include <asm/segment.h>
27205+#include <asm/pgtable.h>
27206+#include <asm/alternative-asm.h>
27207+
27208+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27209+#define __copyuser_seg gs;
27210+#else
27211+#define __copyuser_seg
27212+#endif
27213
27214 .text
27215 ENTRY(__get_user_1)
27216 CFI_STARTPROC
27217+
27218+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27219 GET_THREAD_INFO(%_ASM_DX)
27220 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27221 jae bad_get_user
27222 ASM_STAC
27223-1: movzbl (%_ASM_AX),%edx
27224+
27225+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27226+ mov pax_user_shadow_base,%_ASM_DX
27227+ cmp %_ASM_DX,%_ASM_AX
27228+ jae 1234f
27229+ add %_ASM_DX,%_ASM_AX
27230+1234:
27231+#endif
27232+
27233+#endif
27234+
27235+1: __copyuser_seg movzbl (%_ASM_AX),%edx
27236 xor %eax,%eax
27237 ASM_CLAC
27238+ pax_force_retaddr
27239 ret
27240 CFI_ENDPROC
27241 ENDPROC(__get_user_1)
27242@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
27243 ENTRY(__get_user_2)
27244 CFI_STARTPROC
27245 add $1,%_ASM_AX
27246+
27247+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27248 jc bad_get_user
27249 GET_THREAD_INFO(%_ASM_DX)
27250 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27251 jae bad_get_user
27252 ASM_STAC
27253-2: movzwl -1(%_ASM_AX),%edx
27254+
27255+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27256+ mov pax_user_shadow_base,%_ASM_DX
27257+ cmp %_ASM_DX,%_ASM_AX
27258+ jae 1234f
27259+ add %_ASM_DX,%_ASM_AX
27260+1234:
27261+#endif
27262+
27263+#endif
27264+
27265+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
27266 xor %eax,%eax
27267 ASM_CLAC
27268+ pax_force_retaddr
27269 ret
27270 CFI_ENDPROC
27271 ENDPROC(__get_user_2)
27272@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
27273 ENTRY(__get_user_4)
27274 CFI_STARTPROC
27275 add $3,%_ASM_AX
27276+
27277+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27278 jc bad_get_user
27279 GET_THREAD_INFO(%_ASM_DX)
27280 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27281 jae bad_get_user
27282 ASM_STAC
27283-3: movl -3(%_ASM_AX),%edx
27284+
27285+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27286+ mov pax_user_shadow_base,%_ASM_DX
27287+ cmp %_ASM_DX,%_ASM_AX
27288+ jae 1234f
27289+ add %_ASM_DX,%_ASM_AX
27290+1234:
27291+#endif
27292+
27293+#endif
27294+
27295+3: __copyuser_seg movl -3(%_ASM_AX),%edx
27296 xor %eax,%eax
27297 ASM_CLAC
27298+ pax_force_retaddr
27299 ret
27300 CFI_ENDPROC
27301 ENDPROC(__get_user_4)
27302@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
27303 GET_THREAD_INFO(%_ASM_DX)
27304 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27305 jae bad_get_user
27306+
27307+#ifdef CONFIG_PAX_MEMORY_UDEREF
27308+ mov pax_user_shadow_base,%_ASM_DX
27309+ cmp %_ASM_DX,%_ASM_AX
27310+ jae 1234f
27311+ add %_ASM_DX,%_ASM_AX
27312+1234:
27313+#endif
27314+
27315 ASM_STAC
27316 4: movq -7(%_ASM_AX),%rdx
27317 xor %eax,%eax
27318 ASM_CLAC
27319+ pax_force_retaddr
27320 ret
27321 #else
27322 add $7,%_ASM_AX
27323@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
27324 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27325 jae bad_get_user_8
27326 ASM_STAC
27327-4: movl -7(%_ASM_AX),%edx
27328-5: movl -3(%_ASM_AX),%ecx
27329+4: __copyuser_seg movl -7(%_ASM_AX),%edx
27330+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
27331 xor %eax,%eax
27332 ASM_CLAC
27333+ pax_force_retaddr
27334 ret
27335 #endif
27336 CFI_ENDPROC
27337@@ -113,6 +175,7 @@ bad_get_user:
27338 xor %edx,%edx
27339 mov $(-EFAULT),%_ASM_AX
27340 ASM_CLAC
27341+ pax_force_retaddr
27342 ret
27343 CFI_ENDPROC
27344 END(bad_get_user)
27345@@ -124,6 +187,7 @@ bad_get_user_8:
27346 xor %ecx,%ecx
27347 mov $(-EFAULT),%_ASM_AX
27348 ASM_CLAC
27349+ pax_force_retaddr
27350 ret
27351 CFI_ENDPROC
27352 END(bad_get_user_8)
27353diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
27354index 54fcffe..7be149e 100644
27355--- a/arch/x86/lib/insn.c
27356+++ b/arch/x86/lib/insn.c
27357@@ -20,8 +20,10 @@
27358
27359 #ifdef __KERNEL__
27360 #include <linux/string.h>
27361+#include <asm/pgtable_types.h>
27362 #else
27363 #include <string.h>
27364+#define ktla_ktva(addr) addr
27365 #endif
27366 #include <asm/inat.h>
27367 #include <asm/insn.h>
27368@@ -53,8 +55,8 @@
27369 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
27370 {
27371 memset(insn, 0, sizeof(*insn));
27372- insn->kaddr = kaddr;
27373- insn->next_byte = kaddr;
27374+ insn->kaddr = ktla_ktva(kaddr);
27375+ insn->next_byte = ktla_ktva(kaddr);
27376 insn->x86_64 = x86_64 ? 1 : 0;
27377 insn->opnd_bytes = 4;
27378 if (x86_64)
27379diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
27380index 05a95e7..326f2fa 100644
27381--- a/arch/x86/lib/iomap_copy_64.S
27382+++ b/arch/x86/lib/iomap_copy_64.S
27383@@ -17,6 +17,7 @@
27384
27385 #include <linux/linkage.h>
27386 #include <asm/dwarf2.h>
27387+#include <asm/alternative-asm.h>
27388
27389 /*
27390 * override generic version in lib/iomap_copy.c
27391@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
27392 CFI_STARTPROC
27393 movl %edx,%ecx
27394 rep movsd
27395+ pax_force_retaddr
27396 ret
27397 CFI_ENDPROC
27398 ENDPROC(__iowrite32_copy)
27399diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
27400index 56313a3..9b59269 100644
27401--- a/arch/x86/lib/memcpy_64.S
27402+++ b/arch/x86/lib/memcpy_64.S
27403@@ -24,7 +24,7 @@
27404 * This gets patched over the unrolled variant (below) via the
27405 * alternative instructions framework:
27406 */
27407- .section .altinstr_replacement, "ax", @progbits
27408+ .section .altinstr_replacement, "a", @progbits
27409 .Lmemcpy_c:
27410 movq %rdi, %rax
27411 movq %rdx, %rcx
27412@@ -33,6 +33,7 @@
27413 rep movsq
27414 movl %edx, %ecx
27415 rep movsb
27416+ pax_force_retaddr
27417 ret
27418 .Lmemcpy_e:
27419 .previous
27420@@ -44,11 +45,12 @@
27421 * This gets patched over the unrolled variant (below) via the
27422 * alternative instructions framework:
27423 */
27424- .section .altinstr_replacement, "ax", @progbits
27425+ .section .altinstr_replacement, "a", @progbits
27426 .Lmemcpy_c_e:
27427 movq %rdi, %rax
27428 movq %rdx, %rcx
27429 rep movsb
27430+ pax_force_retaddr
27431 ret
27432 .Lmemcpy_e_e:
27433 .previous
27434@@ -76,13 +78,13 @@ ENTRY(memcpy)
27435 */
27436 movq 0*8(%rsi), %r8
27437 movq 1*8(%rsi), %r9
27438- movq 2*8(%rsi), %r10
27439+ movq 2*8(%rsi), %rcx
27440 movq 3*8(%rsi), %r11
27441 leaq 4*8(%rsi), %rsi
27442
27443 movq %r8, 0*8(%rdi)
27444 movq %r9, 1*8(%rdi)
27445- movq %r10, 2*8(%rdi)
27446+ movq %rcx, 2*8(%rdi)
27447 movq %r11, 3*8(%rdi)
27448 leaq 4*8(%rdi), %rdi
27449 jae .Lcopy_forward_loop
27450@@ -105,12 +107,12 @@ ENTRY(memcpy)
27451 subq $0x20, %rdx
27452 movq -1*8(%rsi), %r8
27453 movq -2*8(%rsi), %r9
27454- movq -3*8(%rsi), %r10
27455+ movq -3*8(%rsi), %rcx
27456 movq -4*8(%rsi), %r11
27457 leaq -4*8(%rsi), %rsi
27458 movq %r8, -1*8(%rdi)
27459 movq %r9, -2*8(%rdi)
27460- movq %r10, -3*8(%rdi)
27461+ movq %rcx, -3*8(%rdi)
27462 movq %r11, -4*8(%rdi)
27463 leaq -4*8(%rdi), %rdi
27464 jae .Lcopy_backward_loop
27465@@ -130,12 +132,13 @@ ENTRY(memcpy)
27466 */
27467 movq 0*8(%rsi), %r8
27468 movq 1*8(%rsi), %r9
27469- movq -2*8(%rsi, %rdx), %r10
27470+ movq -2*8(%rsi, %rdx), %rcx
27471 movq -1*8(%rsi, %rdx), %r11
27472 movq %r8, 0*8(%rdi)
27473 movq %r9, 1*8(%rdi)
27474- movq %r10, -2*8(%rdi, %rdx)
27475+ movq %rcx, -2*8(%rdi, %rdx)
27476 movq %r11, -1*8(%rdi, %rdx)
27477+ pax_force_retaddr
27478 retq
27479 .p2align 4
27480 .Lless_16bytes:
27481@@ -148,6 +151,7 @@ ENTRY(memcpy)
27482 movq -1*8(%rsi, %rdx), %r9
27483 movq %r8, 0*8(%rdi)
27484 movq %r9, -1*8(%rdi, %rdx)
27485+ pax_force_retaddr
27486 retq
27487 .p2align 4
27488 .Lless_8bytes:
27489@@ -161,6 +165,7 @@ ENTRY(memcpy)
27490 movl -4(%rsi, %rdx), %r8d
27491 movl %ecx, (%rdi)
27492 movl %r8d, -4(%rdi, %rdx)
27493+ pax_force_retaddr
27494 retq
27495 .p2align 4
27496 .Lless_3bytes:
27497@@ -179,6 +184,7 @@ ENTRY(memcpy)
27498 movb %cl, (%rdi)
27499
27500 .Lend:
27501+ pax_force_retaddr
27502 retq
27503 CFI_ENDPROC
27504 ENDPROC(memcpy)
27505diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
27506index 65268a6..5aa7815 100644
27507--- a/arch/x86/lib/memmove_64.S
27508+++ b/arch/x86/lib/memmove_64.S
27509@@ -61,13 +61,13 @@ ENTRY(memmove)
27510 5:
27511 sub $0x20, %rdx
27512 movq 0*8(%rsi), %r11
27513- movq 1*8(%rsi), %r10
27514+ movq 1*8(%rsi), %rcx
27515 movq 2*8(%rsi), %r9
27516 movq 3*8(%rsi), %r8
27517 leaq 4*8(%rsi), %rsi
27518
27519 movq %r11, 0*8(%rdi)
27520- movq %r10, 1*8(%rdi)
27521+ movq %rcx, 1*8(%rdi)
27522 movq %r9, 2*8(%rdi)
27523 movq %r8, 3*8(%rdi)
27524 leaq 4*8(%rdi), %rdi
27525@@ -81,10 +81,10 @@ ENTRY(memmove)
27526 4:
27527 movq %rdx, %rcx
27528 movq -8(%rsi, %rdx), %r11
27529- lea -8(%rdi, %rdx), %r10
27530+ lea -8(%rdi, %rdx), %r9
27531 shrq $3, %rcx
27532 rep movsq
27533- movq %r11, (%r10)
27534+ movq %r11, (%r9)
27535 jmp 13f
27536 .Lmemmove_end_forward:
27537
27538@@ -95,14 +95,14 @@ ENTRY(memmove)
27539 7:
27540 movq %rdx, %rcx
27541 movq (%rsi), %r11
27542- movq %rdi, %r10
27543+ movq %rdi, %r9
27544 leaq -8(%rsi, %rdx), %rsi
27545 leaq -8(%rdi, %rdx), %rdi
27546 shrq $3, %rcx
27547 std
27548 rep movsq
27549 cld
27550- movq %r11, (%r10)
27551+ movq %r11, (%r9)
27552 jmp 13f
27553
27554 /*
27555@@ -127,13 +127,13 @@ ENTRY(memmove)
27556 8:
27557 subq $0x20, %rdx
27558 movq -1*8(%rsi), %r11
27559- movq -2*8(%rsi), %r10
27560+ movq -2*8(%rsi), %rcx
27561 movq -3*8(%rsi), %r9
27562 movq -4*8(%rsi), %r8
27563 leaq -4*8(%rsi), %rsi
27564
27565 movq %r11, -1*8(%rdi)
27566- movq %r10, -2*8(%rdi)
27567+ movq %rcx, -2*8(%rdi)
27568 movq %r9, -3*8(%rdi)
27569 movq %r8, -4*8(%rdi)
27570 leaq -4*8(%rdi), %rdi
27571@@ -151,11 +151,11 @@ ENTRY(memmove)
27572 * Move data from 16 bytes to 31 bytes.
27573 */
27574 movq 0*8(%rsi), %r11
27575- movq 1*8(%rsi), %r10
27576+ movq 1*8(%rsi), %rcx
27577 movq -2*8(%rsi, %rdx), %r9
27578 movq -1*8(%rsi, %rdx), %r8
27579 movq %r11, 0*8(%rdi)
27580- movq %r10, 1*8(%rdi)
27581+ movq %rcx, 1*8(%rdi)
27582 movq %r9, -2*8(%rdi, %rdx)
27583 movq %r8, -1*8(%rdi, %rdx)
27584 jmp 13f
27585@@ -167,9 +167,9 @@ ENTRY(memmove)
27586 * Move data from 8 bytes to 15 bytes.
27587 */
27588 movq 0*8(%rsi), %r11
27589- movq -1*8(%rsi, %rdx), %r10
27590+ movq -1*8(%rsi, %rdx), %r9
27591 movq %r11, 0*8(%rdi)
27592- movq %r10, -1*8(%rdi, %rdx)
27593+ movq %r9, -1*8(%rdi, %rdx)
27594 jmp 13f
27595 10:
27596 cmpq $4, %rdx
27597@@ -178,9 +178,9 @@ ENTRY(memmove)
27598 * Move data from 4 bytes to 7 bytes.
27599 */
27600 movl (%rsi), %r11d
27601- movl -4(%rsi, %rdx), %r10d
27602+ movl -4(%rsi, %rdx), %r9d
27603 movl %r11d, (%rdi)
27604- movl %r10d, -4(%rdi, %rdx)
27605+ movl %r9d, -4(%rdi, %rdx)
27606 jmp 13f
27607 11:
27608 cmp $2, %rdx
27609@@ -189,9 +189,9 @@ ENTRY(memmove)
27610 * Move data from 2 bytes to 3 bytes.
27611 */
27612 movw (%rsi), %r11w
27613- movw -2(%rsi, %rdx), %r10w
27614+ movw -2(%rsi, %rdx), %r9w
27615 movw %r11w, (%rdi)
27616- movw %r10w, -2(%rdi, %rdx)
27617+ movw %r9w, -2(%rdi, %rdx)
27618 jmp 13f
27619 12:
27620 cmp $1, %rdx
27621@@ -202,14 +202,16 @@ ENTRY(memmove)
27622 movb (%rsi), %r11b
27623 movb %r11b, (%rdi)
27624 13:
27625+ pax_force_retaddr
27626 retq
27627 CFI_ENDPROC
27628
27629- .section .altinstr_replacement,"ax"
27630+ .section .altinstr_replacement,"a"
27631 .Lmemmove_begin_forward_efs:
27632 /* Forward moving data. */
27633 movq %rdx, %rcx
27634 rep movsb
27635+ pax_force_retaddr
27636 retq
27637 .Lmemmove_end_forward_efs:
27638 .previous
27639diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
27640index 2dcb380..50a78bc 100644
27641--- a/arch/x86/lib/memset_64.S
27642+++ b/arch/x86/lib/memset_64.S
27643@@ -16,7 +16,7 @@
27644 *
27645 * rax original destination
27646 */
27647- .section .altinstr_replacement, "ax", @progbits
27648+ .section .altinstr_replacement, "a", @progbits
27649 .Lmemset_c:
27650 movq %rdi,%r9
27651 movq %rdx,%rcx
27652@@ -30,6 +30,7 @@
27653 movl %edx,%ecx
27654 rep stosb
27655 movq %r9,%rax
27656+ pax_force_retaddr
27657 ret
27658 .Lmemset_e:
27659 .previous
27660@@ -45,13 +46,14 @@
27661 *
27662 * rax original destination
27663 */
27664- .section .altinstr_replacement, "ax", @progbits
27665+ .section .altinstr_replacement, "a", @progbits
27666 .Lmemset_c_e:
27667 movq %rdi,%r9
27668 movb %sil,%al
27669 movq %rdx,%rcx
27670 rep stosb
27671 movq %r9,%rax
27672+ pax_force_retaddr
27673 ret
27674 .Lmemset_e_e:
27675 .previous
27676@@ -59,7 +61,7 @@
27677 ENTRY(memset)
27678 ENTRY(__memset)
27679 CFI_STARTPROC
27680- movq %rdi,%r10
27681+ movq %rdi,%r11
27682
27683 /* expand byte value */
27684 movzbl %sil,%ecx
27685@@ -117,7 +119,8 @@ ENTRY(__memset)
27686 jnz .Lloop_1
27687
27688 .Lende:
27689- movq %r10,%rax
27690+ movq %r11,%rax
27691+ pax_force_retaddr
27692 ret
27693
27694 CFI_RESTORE_STATE
27695diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
27696index c9f2d9b..e7fd2c0 100644
27697--- a/arch/x86/lib/mmx_32.c
27698+++ b/arch/x86/lib/mmx_32.c
27699@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
27700 {
27701 void *p;
27702 int i;
27703+ unsigned long cr0;
27704
27705 if (unlikely(in_interrupt()))
27706 return __memcpy(to, from, len);
27707@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
27708 kernel_fpu_begin();
27709
27710 __asm__ __volatile__ (
27711- "1: prefetch (%0)\n" /* This set is 28 bytes */
27712- " prefetch 64(%0)\n"
27713- " prefetch 128(%0)\n"
27714- " prefetch 192(%0)\n"
27715- " prefetch 256(%0)\n"
27716+ "1: prefetch (%1)\n" /* This set is 28 bytes */
27717+ " prefetch 64(%1)\n"
27718+ " prefetch 128(%1)\n"
27719+ " prefetch 192(%1)\n"
27720+ " prefetch 256(%1)\n"
27721 "2: \n"
27722 ".section .fixup, \"ax\"\n"
27723- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27724+ "3: \n"
27725+
27726+#ifdef CONFIG_PAX_KERNEXEC
27727+ " movl %%cr0, %0\n"
27728+ " movl %0, %%eax\n"
27729+ " andl $0xFFFEFFFF, %%eax\n"
27730+ " movl %%eax, %%cr0\n"
27731+#endif
27732+
27733+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27734+
27735+#ifdef CONFIG_PAX_KERNEXEC
27736+ " movl %0, %%cr0\n"
27737+#endif
27738+
27739 " jmp 2b\n"
27740 ".previous\n"
27741 _ASM_EXTABLE(1b, 3b)
27742- : : "r" (from));
27743+ : "=&r" (cr0) : "r" (from) : "ax");
27744
27745 for ( ; i > 5; i--) {
27746 __asm__ __volatile__ (
27747- "1: prefetch 320(%0)\n"
27748- "2: movq (%0), %%mm0\n"
27749- " movq 8(%0), %%mm1\n"
27750- " movq 16(%0), %%mm2\n"
27751- " movq 24(%0), %%mm3\n"
27752- " movq %%mm0, (%1)\n"
27753- " movq %%mm1, 8(%1)\n"
27754- " movq %%mm2, 16(%1)\n"
27755- " movq %%mm3, 24(%1)\n"
27756- " movq 32(%0), %%mm0\n"
27757- " movq 40(%0), %%mm1\n"
27758- " movq 48(%0), %%mm2\n"
27759- " movq 56(%0), %%mm3\n"
27760- " movq %%mm0, 32(%1)\n"
27761- " movq %%mm1, 40(%1)\n"
27762- " movq %%mm2, 48(%1)\n"
27763- " movq %%mm3, 56(%1)\n"
27764+ "1: prefetch 320(%1)\n"
27765+ "2: movq (%1), %%mm0\n"
27766+ " movq 8(%1), %%mm1\n"
27767+ " movq 16(%1), %%mm2\n"
27768+ " movq 24(%1), %%mm3\n"
27769+ " movq %%mm0, (%2)\n"
27770+ " movq %%mm1, 8(%2)\n"
27771+ " movq %%mm2, 16(%2)\n"
27772+ " movq %%mm3, 24(%2)\n"
27773+ " movq 32(%1), %%mm0\n"
27774+ " movq 40(%1), %%mm1\n"
27775+ " movq 48(%1), %%mm2\n"
27776+ " movq 56(%1), %%mm3\n"
27777+ " movq %%mm0, 32(%2)\n"
27778+ " movq %%mm1, 40(%2)\n"
27779+ " movq %%mm2, 48(%2)\n"
27780+ " movq %%mm3, 56(%2)\n"
27781 ".section .fixup, \"ax\"\n"
27782- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
27783+ "3:\n"
27784+
27785+#ifdef CONFIG_PAX_KERNEXEC
27786+ " movl %%cr0, %0\n"
27787+ " movl %0, %%eax\n"
27788+ " andl $0xFFFEFFFF, %%eax\n"
27789+ " movl %%eax, %%cr0\n"
27790+#endif
27791+
27792+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
27793+
27794+#ifdef CONFIG_PAX_KERNEXEC
27795+ " movl %0, %%cr0\n"
27796+#endif
27797+
27798 " jmp 2b\n"
27799 ".previous\n"
27800 _ASM_EXTABLE(1b, 3b)
27801- : : "r" (from), "r" (to) : "memory");
27802+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
27803
27804 from += 64;
27805 to += 64;
27806@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
27807 static void fast_copy_page(void *to, void *from)
27808 {
27809 int i;
27810+ unsigned long cr0;
27811
27812 kernel_fpu_begin();
27813
27814@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
27815 * but that is for later. -AV
27816 */
27817 __asm__ __volatile__(
27818- "1: prefetch (%0)\n"
27819- " prefetch 64(%0)\n"
27820- " prefetch 128(%0)\n"
27821- " prefetch 192(%0)\n"
27822- " prefetch 256(%0)\n"
27823+ "1: prefetch (%1)\n"
27824+ " prefetch 64(%1)\n"
27825+ " prefetch 128(%1)\n"
27826+ " prefetch 192(%1)\n"
27827+ " prefetch 256(%1)\n"
27828 "2: \n"
27829 ".section .fixup, \"ax\"\n"
27830- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27831+ "3: \n"
27832+
27833+#ifdef CONFIG_PAX_KERNEXEC
27834+ " movl %%cr0, %0\n"
27835+ " movl %0, %%eax\n"
27836+ " andl $0xFFFEFFFF, %%eax\n"
27837+ " movl %%eax, %%cr0\n"
27838+#endif
27839+
27840+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27841+
27842+#ifdef CONFIG_PAX_KERNEXEC
27843+ " movl %0, %%cr0\n"
27844+#endif
27845+
27846 " jmp 2b\n"
27847 ".previous\n"
27848- _ASM_EXTABLE(1b, 3b) : : "r" (from));
27849+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
27850
27851 for (i = 0; i < (4096-320)/64; i++) {
27852 __asm__ __volatile__ (
27853- "1: prefetch 320(%0)\n"
27854- "2: movq (%0), %%mm0\n"
27855- " movntq %%mm0, (%1)\n"
27856- " movq 8(%0), %%mm1\n"
27857- " movntq %%mm1, 8(%1)\n"
27858- " movq 16(%0), %%mm2\n"
27859- " movntq %%mm2, 16(%1)\n"
27860- " movq 24(%0), %%mm3\n"
27861- " movntq %%mm3, 24(%1)\n"
27862- " movq 32(%0), %%mm4\n"
27863- " movntq %%mm4, 32(%1)\n"
27864- " movq 40(%0), %%mm5\n"
27865- " movntq %%mm5, 40(%1)\n"
27866- " movq 48(%0), %%mm6\n"
27867- " movntq %%mm6, 48(%1)\n"
27868- " movq 56(%0), %%mm7\n"
27869- " movntq %%mm7, 56(%1)\n"
27870+ "1: prefetch 320(%1)\n"
27871+ "2: movq (%1), %%mm0\n"
27872+ " movntq %%mm0, (%2)\n"
27873+ " movq 8(%1), %%mm1\n"
27874+ " movntq %%mm1, 8(%2)\n"
27875+ " movq 16(%1), %%mm2\n"
27876+ " movntq %%mm2, 16(%2)\n"
27877+ " movq 24(%1), %%mm3\n"
27878+ " movntq %%mm3, 24(%2)\n"
27879+ " movq 32(%1), %%mm4\n"
27880+ " movntq %%mm4, 32(%2)\n"
27881+ " movq 40(%1), %%mm5\n"
27882+ " movntq %%mm5, 40(%2)\n"
27883+ " movq 48(%1), %%mm6\n"
27884+ " movntq %%mm6, 48(%2)\n"
27885+ " movq 56(%1), %%mm7\n"
27886+ " movntq %%mm7, 56(%2)\n"
27887 ".section .fixup, \"ax\"\n"
27888- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
27889+ "3:\n"
27890+
27891+#ifdef CONFIG_PAX_KERNEXEC
27892+ " movl %%cr0, %0\n"
27893+ " movl %0, %%eax\n"
27894+ " andl $0xFFFEFFFF, %%eax\n"
27895+ " movl %%eax, %%cr0\n"
27896+#endif
27897+
27898+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
27899+
27900+#ifdef CONFIG_PAX_KERNEXEC
27901+ " movl %0, %%cr0\n"
27902+#endif
27903+
27904 " jmp 2b\n"
27905 ".previous\n"
27906- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
27907+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
27908
27909 from += 64;
27910 to += 64;
27911@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
27912 static void fast_copy_page(void *to, void *from)
27913 {
27914 int i;
27915+ unsigned long cr0;
27916
27917 kernel_fpu_begin();
27918
27919 __asm__ __volatile__ (
27920- "1: prefetch (%0)\n"
27921- " prefetch 64(%0)\n"
27922- " prefetch 128(%0)\n"
27923- " prefetch 192(%0)\n"
27924- " prefetch 256(%0)\n"
27925+ "1: prefetch (%1)\n"
27926+ " prefetch 64(%1)\n"
27927+ " prefetch 128(%1)\n"
27928+ " prefetch 192(%1)\n"
27929+ " prefetch 256(%1)\n"
27930 "2: \n"
27931 ".section .fixup, \"ax\"\n"
27932- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27933+ "3: \n"
27934+
27935+#ifdef CONFIG_PAX_KERNEXEC
27936+ " movl %%cr0, %0\n"
27937+ " movl %0, %%eax\n"
27938+ " andl $0xFFFEFFFF, %%eax\n"
27939+ " movl %%eax, %%cr0\n"
27940+#endif
27941+
27942+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
27943+
27944+#ifdef CONFIG_PAX_KERNEXEC
27945+ " movl %0, %%cr0\n"
27946+#endif
27947+
27948 " jmp 2b\n"
27949 ".previous\n"
27950- _ASM_EXTABLE(1b, 3b) : : "r" (from));
27951+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
27952
27953 for (i = 0; i < 4096/64; i++) {
27954 __asm__ __volatile__ (
27955- "1: prefetch 320(%0)\n"
27956- "2: movq (%0), %%mm0\n"
27957- " movq 8(%0), %%mm1\n"
27958- " movq 16(%0), %%mm2\n"
27959- " movq 24(%0), %%mm3\n"
27960- " movq %%mm0, (%1)\n"
27961- " movq %%mm1, 8(%1)\n"
27962- " movq %%mm2, 16(%1)\n"
27963- " movq %%mm3, 24(%1)\n"
27964- " movq 32(%0), %%mm0\n"
27965- " movq 40(%0), %%mm1\n"
27966- " movq 48(%0), %%mm2\n"
27967- " movq 56(%0), %%mm3\n"
27968- " movq %%mm0, 32(%1)\n"
27969- " movq %%mm1, 40(%1)\n"
27970- " movq %%mm2, 48(%1)\n"
27971- " movq %%mm3, 56(%1)\n"
27972+ "1: prefetch 320(%1)\n"
27973+ "2: movq (%1), %%mm0\n"
27974+ " movq 8(%1), %%mm1\n"
27975+ " movq 16(%1), %%mm2\n"
27976+ " movq 24(%1), %%mm3\n"
27977+ " movq %%mm0, (%2)\n"
27978+ " movq %%mm1, 8(%2)\n"
27979+ " movq %%mm2, 16(%2)\n"
27980+ " movq %%mm3, 24(%2)\n"
27981+ " movq 32(%1), %%mm0\n"
27982+ " movq 40(%1), %%mm1\n"
27983+ " movq 48(%1), %%mm2\n"
27984+ " movq 56(%1), %%mm3\n"
27985+ " movq %%mm0, 32(%2)\n"
27986+ " movq %%mm1, 40(%2)\n"
27987+ " movq %%mm2, 48(%2)\n"
27988+ " movq %%mm3, 56(%2)\n"
27989 ".section .fixup, \"ax\"\n"
27990- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
27991+ "3:\n"
27992+
27993+#ifdef CONFIG_PAX_KERNEXEC
27994+ " movl %%cr0, %0\n"
27995+ " movl %0, %%eax\n"
27996+ " andl $0xFFFEFFFF, %%eax\n"
27997+ " movl %%eax, %%cr0\n"
27998+#endif
27999+
28000+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28001+
28002+#ifdef CONFIG_PAX_KERNEXEC
28003+ " movl %0, %%cr0\n"
28004+#endif
28005+
28006 " jmp 2b\n"
28007 ".previous\n"
28008 _ASM_EXTABLE(1b, 3b)
28009- : : "r" (from), "r" (to) : "memory");
28010+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28011
28012 from += 64;
28013 to += 64;
28014diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28015index f6d13ee..aca5f0b 100644
28016--- a/arch/x86/lib/msr-reg.S
28017+++ b/arch/x86/lib/msr-reg.S
28018@@ -3,6 +3,7 @@
28019 #include <asm/dwarf2.h>
28020 #include <asm/asm.h>
28021 #include <asm/msr.h>
28022+#include <asm/alternative-asm.h>
28023
28024 #ifdef CONFIG_X86_64
28025 /*
28026@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28027 CFI_STARTPROC
28028 pushq_cfi %rbx
28029 pushq_cfi %rbp
28030- movq %rdi, %r10 /* Save pointer */
28031+ movq %rdi, %r9 /* Save pointer */
28032 xorl %r11d, %r11d /* Return value */
28033 movl (%rdi), %eax
28034 movl 4(%rdi), %ecx
28035@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28036 movl 28(%rdi), %edi
28037 CFI_REMEMBER_STATE
28038 1: \op
28039-2: movl %eax, (%r10)
28040+2: movl %eax, (%r9)
28041 movl %r11d, %eax /* Return value */
28042- movl %ecx, 4(%r10)
28043- movl %edx, 8(%r10)
28044- movl %ebx, 12(%r10)
28045- movl %ebp, 20(%r10)
28046- movl %esi, 24(%r10)
28047- movl %edi, 28(%r10)
28048+ movl %ecx, 4(%r9)
28049+ movl %edx, 8(%r9)
28050+ movl %ebx, 12(%r9)
28051+ movl %ebp, 20(%r9)
28052+ movl %esi, 24(%r9)
28053+ movl %edi, 28(%r9)
28054 popq_cfi %rbp
28055 popq_cfi %rbx
28056+ pax_force_retaddr
28057 ret
28058 3:
28059 CFI_RESTORE_STATE
28060diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28061index fc6ba17..d4d989d 100644
28062--- a/arch/x86/lib/putuser.S
28063+++ b/arch/x86/lib/putuser.S
28064@@ -16,7 +16,9 @@
28065 #include <asm/errno.h>
28066 #include <asm/asm.h>
28067 #include <asm/smap.h>
28068-
28069+#include <asm/segment.h>
28070+#include <asm/pgtable.h>
28071+#include <asm/alternative-asm.h>
28072
28073 /*
28074 * __put_user_X
28075@@ -30,57 +32,125 @@
28076 * as they get called from within inline assembly.
28077 */
28078
28079-#define ENTER CFI_STARTPROC ; \
28080- GET_THREAD_INFO(%_ASM_BX)
28081-#define EXIT ASM_CLAC ; \
28082- ret ; \
28083+#define ENTER CFI_STARTPROC
28084+#define EXIT ASM_CLAC ; \
28085+ pax_force_retaddr ; \
28086+ ret ; \
28087 CFI_ENDPROC
28088
28089+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28090+#define _DEST %_ASM_CX,%_ASM_BX
28091+#else
28092+#define _DEST %_ASM_CX
28093+#endif
28094+
28095+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28096+#define __copyuser_seg gs;
28097+#else
28098+#define __copyuser_seg
28099+#endif
28100+
28101 .text
28102 ENTRY(__put_user_1)
28103 ENTER
28104+
28105+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28106+ GET_THREAD_INFO(%_ASM_BX)
28107 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28108 jae bad_put_user
28109 ASM_STAC
28110-1: movb %al,(%_ASM_CX)
28111+
28112+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28113+ mov pax_user_shadow_base,%_ASM_BX
28114+ cmp %_ASM_BX,%_ASM_CX
28115+ jb 1234f
28116+ xor %ebx,%ebx
28117+1234:
28118+#endif
28119+
28120+#endif
28121+
28122+1: __copyuser_seg movb %al,(_DEST)
28123 xor %eax,%eax
28124 EXIT
28125 ENDPROC(__put_user_1)
28126
28127 ENTRY(__put_user_2)
28128 ENTER
28129+
28130+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28131+ GET_THREAD_INFO(%_ASM_BX)
28132 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28133 sub $1,%_ASM_BX
28134 cmp %_ASM_BX,%_ASM_CX
28135 jae bad_put_user
28136 ASM_STAC
28137-2: movw %ax,(%_ASM_CX)
28138+
28139+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28140+ mov pax_user_shadow_base,%_ASM_BX
28141+ cmp %_ASM_BX,%_ASM_CX
28142+ jb 1234f
28143+ xor %ebx,%ebx
28144+1234:
28145+#endif
28146+
28147+#endif
28148+
28149+2: __copyuser_seg movw %ax,(_DEST)
28150 xor %eax,%eax
28151 EXIT
28152 ENDPROC(__put_user_2)
28153
28154 ENTRY(__put_user_4)
28155 ENTER
28156+
28157+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28158+ GET_THREAD_INFO(%_ASM_BX)
28159 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28160 sub $3,%_ASM_BX
28161 cmp %_ASM_BX,%_ASM_CX
28162 jae bad_put_user
28163 ASM_STAC
28164-3: movl %eax,(%_ASM_CX)
28165+
28166+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28167+ mov pax_user_shadow_base,%_ASM_BX
28168+ cmp %_ASM_BX,%_ASM_CX
28169+ jb 1234f
28170+ xor %ebx,%ebx
28171+1234:
28172+#endif
28173+
28174+#endif
28175+
28176+3: __copyuser_seg movl %eax,(_DEST)
28177 xor %eax,%eax
28178 EXIT
28179 ENDPROC(__put_user_4)
28180
28181 ENTRY(__put_user_8)
28182 ENTER
28183+
28184+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28185+ GET_THREAD_INFO(%_ASM_BX)
28186 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28187 sub $7,%_ASM_BX
28188 cmp %_ASM_BX,%_ASM_CX
28189 jae bad_put_user
28190 ASM_STAC
28191-4: mov %_ASM_AX,(%_ASM_CX)
28192+
28193+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28194+ mov pax_user_shadow_base,%_ASM_BX
28195+ cmp %_ASM_BX,%_ASM_CX
28196+ jb 1234f
28197+ xor %ebx,%ebx
28198+1234:
28199+#endif
28200+
28201+#endif
28202+
28203+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28204 #ifdef CONFIG_X86_32
28205-5: movl %edx,4(%_ASM_CX)
28206+5: __copyuser_seg movl %edx,4(_DEST)
28207 #endif
28208 xor %eax,%eax
28209 EXIT
28210diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28211index 1cad221..de671ee 100644
28212--- a/arch/x86/lib/rwlock.S
28213+++ b/arch/x86/lib/rwlock.S
28214@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
28215 FRAME
28216 0: LOCK_PREFIX
28217 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28218+
28219+#ifdef CONFIG_PAX_REFCOUNT
28220+ jno 1234f
28221+ LOCK_PREFIX
28222+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28223+ int $4
28224+1234:
28225+ _ASM_EXTABLE(1234b, 1234b)
28226+#endif
28227+
28228 1: rep; nop
28229 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
28230 jne 1b
28231 LOCK_PREFIX
28232 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28233+
28234+#ifdef CONFIG_PAX_REFCOUNT
28235+ jno 1234f
28236+ LOCK_PREFIX
28237+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28238+ int $4
28239+1234:
28240+ _ASM_EXTABLE(1234b, 1234b)
28241+#endif
28242+
28243 jnz 0b
28244 ENDFRAME
28245+ pax_force_retaddr
28246 ret
28247 CFI_ENDPROC
28248 END(__write_lock_failed)
28249@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
28250 FRAME
28251 0: LOCK_PREFIX
28252 READ_LOCK_SIZE(inc) (%__lock_ptr)
28253+
28254+#ifdef CONFIG_PAX_REFCOUNT
28255+ jno 1234f
28256+ LOCK_PREFIX
28257+ READ_LOCK_SIZE(dec) (%__lock_ptr)
28258+ int $4
28259+1234:
28260+ _ASM_EXTABLE(1234b, 1234b)
28261+#endif
28262+
28263 1: rep; nop
28264 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
28265 js 1b
28266 LOCK_PREFIX
28267 READ_LOCK_SIZE(dec) (%__lock_ptr)
28268+
28269+#ifdef CONFIG_PAX_REFCOUNT
28270+ jno 1234f
28271+ LOCK_PREFIX
28272+ READ_LOCK_SIZE(inc) (%__lock_ptr)
28273+ int $4
28274+1234:
28275+ _ASM_EXTABLE(1234b, 1234b)
28276+#endif
28277+
28278 js 0b
28279 ENDFRAME
28280+ pax_force_retaddr
28281 ret
28282 CFI_ENDPROC
28283 END(__read_lock_failed)
28284diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
28285index 5dff5f0..cadebf4 100644
28286--- a/arch/x86/lib/rwsem.S
28287+++ b/arch/x86/lib/rwsem.S
28288@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
28289 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
28290 CFI_RESTORE __ASM_REG(dx)
28291 restore_common_regs
28292+ pax_force_retaddr
28293 ret
28294 CFI_ENDPROC
28295 ENDPROC(call_rwsem_down_read_failed)
28296@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
28297 movq %rax,%rdi
28298 call rwsem_down_write_failed
28299 restore_common_regs
28300+ pax_force_retaddr
28301 ret
28302 CFI_ENDPROC
28303 ENDPROC(call_rwsem_down_write_failed)
28304@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
28305 movq %rax,%rdi
28306 call rwsem_wake
28307 restore_common_regs
28308-1: ret
28309+1: pax_force_retaddr
28310+ ret
28311 CFI_ENDPROC
28312 ENDPROC(call_rwsem_wake)
28313
28314@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
28315 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
28316 CFI_RESTORE __ASM_REG(dx)
28317 restore_common_regs
28318+ pax_force_retaddr
28319 ret
28320 CFI_ENDPROC
28321 ENDPROC(call_rwsem_downgrade_wake)
28322diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
28323index a63efd6..ccecad8 100644
28324--- a/arch/x86/lib/thunk_64.S
28325+++ b/arch/x86/lib/thunk_64.S
28326@@ -8,6 +8,7 @@
28327 #include <linux/linkage.h>
28328 #include <asm/dwarf2.h>
28329 #include <asm/calling.h>
28330+#include <asm/alternative-asm.h>
28331
28332 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
28333 .macro THUNK name, func, put_ret_addr_in_rdi=0
28334@@ -41,5 +42,6 @@
28335 SAVE_ARGS
28336 restore:
28337 RESTORE_ARGS
28338+ pax_force_retaddr
28339 ret
28340 CFI_ENDPROC
28341diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
28342index 3eb18ac..6890bc3 100644
28343--- a/arch/x86/lib/usercopy_32.c
28344+++ b/arch/x86/lib/usercopy_32.c
28345@@ -42,11 +42,13 @@ do { \
28346 int __d0; \
28347 might_fault(); \
28348 __asm__ __volatile__( \
28349+ __COPYUSER_SET_ES \
28350 ASM_STAC "\n" \
28351 "0: rep; stosl\n" \
28352 " movl %2,%0\n" \
28353 "1: rep; stosb\n" \
28354 "2: " ASM_CLAC "\n" \
28355+ __COPYUSER_RESTORE_ES \
28356 ".section .fixup,\"ax\"\n" \
28357 "3: lea 0(%2,%0,4),%0\n" \
28358 " jmp 2b\n" \
28359@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
28360
28361 #ifdef CONFIG_X86_INTEL_USERCOPY
28362 static unsigned long
28363-__copy_user_intel(void __user *to, const void *from, unsigned long size)
28364+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
28365 {
28366 int d0, d1;
28367 __asm__ __volatile__(
28368@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
28369 " .align 2,0x90\n"
28370 "3: movl 0(%4), %%eax\n"
28371 "4: movl 4(%4), %%edx\n"
28372- "5: movl %%eax, 0(%3)\n"
28373- "6: movl %%edx, 4(%3)\n"
28374+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
28375+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
28376 "7: movl 8(%4), %%eax\n"
28377 "8: movl 12(%4),%%edx\n"
28378- "9: movl %%eax, 8(%3)\n"
28379- "10: movl %%edx, 12(%3)\n"
28380+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
28381+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
28382 "11: movl 16(%4), %%eax\n"
28383 "12: movl 20(%4), %%edx\n"
28384- "13: movl %%eax, 16(%3)\n"
28385- "14: movl %%edx, 20(%3)\n"
28386+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
28387+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
28388 "15: movl 24(%4), %%eax\n"
28389 "16: movl 28(%4), %%edx\n"
28390- "17: movl %%eax, 24(%3)\n"
28391- "18: movl %%edx, 28(%3)\n"
28392+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
28393+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
28394 "19: movl 32(%4), %%eax\n"
28395 "20: movl 36(%4), %%edx\n"
28396- "21: movl %%eax, 32(%3)\n"
28397- "22: movl %%edx, 36(%3)\n"
28398+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
28399+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
28400 "23: movl 40(%4), %%eax\n"
28401 "24: movl 44(%4), %%edx\n"
28402- "25: movl %%eax, 40(%3)\n"
28403- "26: movl %%edx, 44(%3)\n"
28404+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
28405+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
28406 "27: movl 48(%4), %%eax\n"
28407 "28: movl 52(%4), %%edx\n"
28408- "29: movl %%eax, 48(%3)\n"
28409- "30: movl %%edx, 52(%3)\n"
28410+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
28411+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
28412 "31: movl 56(%4), %%eax\n"
28413 "32: movl 60(%4), %%edx\n"
28414- "33: movl %%eax, 56(%3)\n"
28415- "34: movl %%edx, 60(%3)\n"
28416+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
28417+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
28418 " addl $-64, %0\n"
28419 " addl $64, %4\n"
28420 " addl $64, %3\n"
28421@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
28422 " shrl $2, %0\n"
28423 " andl $3, %%eax\n"
28424 " cld\n"
28425+ __COPYUSER_SET_ES
28426 "99: rep; movsl\n"
28427 "36: movl %%eax, %0\n"
28428 "37: rep; movsb\n"
28429 "100:\n"
28430+ __COPYUSER_RESTORE_ES
28431 ".section .fixup,\"ax\"\n"
28432 "101: lea 0(%%eax,%0,4),%0\n"
28433 " jmp 100b\n"
28434@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
28435 }
28436
28437 static unsigned long
28438+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
28439+{
28440+ int d0, d1;
28441+ __asm__ __volatile__(
28442+ " .align 2,0x90\n"
28443+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
28444+ " cmpl $67, %0\n"
28445+ " jbe 3f\n"
28446+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
28447+ " .align 2,0x90\n"
28448+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
28449+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
28450+ "5: movl %%eax, 0(%3)\n"
28451+ "6: movl %%edx, 4(%3)\n"
28452+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
28453+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
28454+ "9: movl %%eax, 8(%3)\n"
28455+ "10: movl %%edx, 12(%3)\n"
28456+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
28457+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
28458+ "13: movl %%eax, 16(%3)\n"
28459+ "14: movl %%edx, 20(%3)\n"
28460+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
28461+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
28462+ "17: movl %%eax, 24(%3)\n"
28463+ "18: movl %%edx, 28(%3)\n"
28464+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
28465+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
28466+ "21: movl %%eax, 32(%3)\n"
28467+ "22: movl %%edx, 36(%3)\n"
28468+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
28469+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
28470+ "25: movl %%eax, 40(%3)\n"
28471+ "26: movl %%edx, 44(%3)\n"
28472+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
28473+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
28474+ "29: movl %%eax, 48(%3)\n"
28475+ "30: movl %%edx, 52(%3)\n"
28476+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
28477+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
28478+ "33: movl %%eax, 56(%3)\n"
28479+ "34: movl %%edx, 60(%3)\n"
28480+ " addl $-64, %0\n"
28481+ " addl $64, %4\n"
28482+ " addl $64, %3\n"
28483+ " cmpl $63, %0\n"
28484+ " ja 1b\n"
28485+ "35: movl %0, %%eax\n"
28486+ " shrl $2, %0\n"
28487+ " andl $3, %%eax\n"
28488+ " cld\n"
28489+ "99: rep; "__copyuser_seg" movsl\n"
28490+ "36: movl %%eax, %0\n"
28491+ "37: rep; "__copyuser_seg" movsb\n"
28492+ "100:\n"
28493+ ".section .fixup,\"ax\"\n"
28494+ "101: lea 0(%%eax,%0,4),%0\n"
28495+ " jmp 100b\n"
28496+ ".previous\n"
28497+ _ASM_EXTABLE(1b,100b)
28498+ _ASM_EXTABLE(2b,100b)
28499+ _ASM_EXTABLE(3b,100b)
28500+ _ASM_EXTABLE(4b,100b)
28501+ _ASM_EXTABLE(5b,100b)
28502+ _ASM_EXTABLE(6b,100b)
28503+ _ASM_EXTABLE(7b,100b)
28504+ _ASM_EXTABLE(8b,100b)
28505+ _ASM_EXTABLE(9b,100b)
28506+ _ASM_EXTABLE(10b,100b)
28507+ _ASM_EXTABLE(11b,100b)
28508+ _ASM_EXTABLE(12b,100b)
28509+ _ASM_EXTABLE(13b,100b)
28510+ _ASM_EXTABLE(14b,100b)
28511+ _ASM_EXTABLE(15b,100b)
28512+ _ASM_EXTABLE(16b,100b)
28513+ _ASM_EXTABLE(17b,100b)
28514+ _ASM_EXTABLE(18b,100b)
28515+ _ASM_EXTABLE(19b,100b)
28516+ _ASM_EXTABLE(20b,100b)
28517+ _ASM_EXTABLE(21b,100b)
28518+ _ASM_EXTABLE(22b,100b)
28519+ _ASM_EXTABLE(23b,100b)
28520+ _ASM_EXTABLE(24b,100b)
28521+ _ASM_EXTABLE(25b,100b)
28522+ _ASM_EXTABLE(26b,100b)
28523+ _ASM_EXTABLE(27b,100b)
28524+ _ASM_EXTABLE(28b,100b)
28525+ _ASM_EXTABLE(29b,100b)
28526+ _ASM_EXTABLE(30b,100b)
28527+ _ASM_EXTABLE(31b,100b)
28528+ _ASM_EXTABLE(32b,100b)
28529+ _ASM_EXTABLE(33b,100b)
28530+ _ASM_EXTABLE(34b,100b)
28531+ _ASM_EXTABLE(35b,100b)
28532+ _ASM_EXTABLE(36b,100b)
28533+ _ASM_EXTABLE(37b,100b)
28534+ _ASM_EXTABLE(99b,101b)
28535+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
28536+ : "1"(to), "2"(from), "0"(size)
28537+ : "eax", "edx", "memory");
28538+ return size;
28539+}
28540+
28541+static unsigned long __size_overflow(3)
28542 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
28543 {
28544 int d0, d1;
28545 __asm__ __volatile__(
28546 " .align 2,0x90\n"
28547- "0: movl 32(%4), %%eax\n"
28548+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
28549 " cmpl $67, %0\n"
28550 " jbe 2f\n"
28551- "1: movl 64(%4), %%eax\n"
28552+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
28553 " .align 2,0x90\n"
28554- "2: movl 0(%4), %%eax\n"
28555- "21: movl 4(%4), %%edx\n"
28556+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
28557+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
28558 " movl %%eax, 0(%3)\n"
28559 " movl %%edx, 4(%3)\n"
28560- "3: movl 8(%4), %%eax\n"
28561- "31: movl 12(%4),%%edx\n"
28562+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
28563+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
28564 " movl %%eax, 8(%3)\n"
28565 " movl %%edx, 12(%3)\n"
28566- "4: movl 16(%4), %%eax\n"
28567- "41: movl 20(%4), %%edx\n"
28568+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
28569+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
28570 " movl %%eax, 16(%3)\n"
28571 " movl %%edx, 20(%3)\n"
28572- "10: movl 24(%4), %%eax\n"
28573- "51: movl 28(%4), %%edx\n"
28574+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
28575+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
28576 " movl %%eax, 24(%3)\n"
28577 " movl %%edx, 28(%3)\n"
28578- "11: movl 32(%4), %%eax\n"
28579- "61: movl 36(%4), %%edx\n"
28580+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
28581+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
28582 " movl %%eax, 32(%3)\n"
28583 " movl %%edx, 36(%3)\n"
28584- "12: movl 40(%4), %%eax\n"
28585- "71: movl 44(%4), %%edx\n"
28586+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
28587+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
28588 " movl %%eax, 40(%3)\n"
28589 " movl %%edx, 44(%3)\n"
28590- "13: movl 48(%4), %%eax\n"
28591- "81: movl 52(%4), %%edx\n"
28592+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
28593+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
28594 " movl %%eax, 48(%3)\n"
28595 " movl %%edx, 52(%3)\n"
28596- "14: movl 56(%4), %%eax\n"
28597- "91: movl 60(%4), %%edx\n"
28598+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
28599+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
28600 " movl %%eax, 56(%3)\n"
28601 " movl %%edx, 60(%3)\n"
28602 " addl $-64, %0\n"
28603@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
28604 " shrl $2, %0\n"
28605 " andl $3, %%eax\n"
28606 " cld\n"
28607- "6: rep; movsl\n"
28608+ "6: rep; "__copyuser_seg" movsl\n"
28609 " movl %%eax,%0\n"
28610- "7: rep; movsb\n"
28611+ "7: rep; "__copyuser_seg" movsb\n"
28612 "8:\n"
28613 ".section .fixup,\"ax\"\n"
28614 "9: lea 0(%%eax,%0,4),%0\n"
28615@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
28616 * hyoshiok@miraclelinux.com
28617 */
28618
28619-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
28620+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
28621 const void __user *from, unsigned long size)
28622 {
28623 int d0, d1;
28624
28625 __asm__ __volatile__(
28626 " .align 2,0x90\n"
28627- "0: movl 32(%4), %%eax\n"
28628+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
28629 " cmpl $67, %0\n"
28630 " jbe 2f\n"
28631- "1: movl 64(%4), %%eax\n"
28632+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
28633 " .align 2,0x90\n"
28634- "2: movl 0(%4), %%eax\n"
28635- "21: movl 4(%4), %%edx\n"
28636+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
28637+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
28638 " movnti %%eax, 0(%3)\n"
28639 " movnti %%edx, 4(%3)\n"
28640- "3: movl 8(%4), %%eax\n"
28641- "31: movl 12(%4),%%edx\n"
28642+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
28643+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
28644 " movnti %%eax, 8(%3)\n"
28645 " movnti %%edx, 12(%3)\n"
28646- "4: movl 16(%4), %%eax\n"
28647- "41: movl 20(%4), %%edx\n"
28648+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
28649+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
28650 " movnti %%eax, 16(%3)\n"
28651 " movnti %%edx, 20(%3)\n"
28652- "10: movl 24(%4), %%eax\n"
28653- "51: movl 28(%4), %%edx\n"
28654+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
28655+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
28656 " movnti %%eax, 24(%3)\n"
28657 " movnti %%edx, 28(%3)\n"
28658- "11: movl 32(%4), %%eax\n"
28659- "61: movl 36(%4), %%edx\n"
28660+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
28661+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
28662 " movnti %%eax, 32(%3)\n"
28663 " movnti %%edx, 36(%3)\n"
28664- "12: movl 40(%4), %%eax\n"
28665- "71: movl 44(%4), %%edx\n"
28666+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
28667+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
28668 " movnti %%eax, 40(%3)\n"
28669 " movnti %%edx, 44(%3)\n"
28670- "13: movl 48(%4), %%eax\n"
28671- "81: movl 52(%4), %%edx\n"
28672+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
28673+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
28674 " movnti %%eax, 48(%3)\n"
28675 " movnti %%edx, 52(%3)\n"
28676- "14: movl 56(%4), %%eax\n"
28677- "91: movl 60(%4), %%edx\n"
28678+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
28679+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
28680 " movnti %%eax, 56(%3)\n"
28681 " movnti %%edx, 60(%3)\n"
28682 " addl $-64, %0\n"
28683@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
28684 " shrl $2, %0\n"
28685 " andl $3, %%eax\n"
28686 " cld\n"
28687- "6: rep; movsl\n"
28688+ "6: rep; "__copyuser_seg" movsl\n"
28689 " movl %%eax,%0\n"
28690- "7: rep; movsb\n"
28691+ "7: rep; "__copyuser_seg" movsb\n"
28692 "8:\n"
28693 ".section .fixup,\"ax\"\n"
28694 "9: lea 0(%%eax,%0,4),%0\n"
28695@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
28696 return size;
28697 }
28698
28699-static unsigned long __copy_user_intel_nocache(void *to,
28700+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
28701 const void __user *from, unsigned long size)
28702 {
28703 int d0, d1;
28704
28705 __asm__ __volatile__(
28706 " .align 2,0x90\n"
28707- "0: movl 32(%4), %%eax\n"
28708+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
28709 " cmpl $67, %0\n"
28710 " jbe 2f\n"
28711- "1: movl 64(%4), %%eax\n"
28712+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
28713 " .align 2,0x90\n"
28714- "2: movl 0(%4), %%eax\n"
28715- "21: movl 4(%4), %%edx\n"
28716+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
28717+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
28718 " movnti %%eax, 0(%3)\n"
28719 " movnti %%edx, 4(%3)\n"
28720- "3: movl 8(%4), %%eax\n"
28721- "31: movl 12(%4),%%edx\n"
28722+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
28723+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
28724 " movnti %%eax, 8(%3)\n"
28725 " movnti %%edx, 12(%3)\n"
28726- "4: movl 16(%4), %%eax\n"
28727- "41: movl 20(%4), %%edx\n"
28728+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
28729+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
28730 " movnti %%eax, 16(%3)\n"
28731 " movnti %%edx, 20(%3)\n"
28732- "10: movl 24(%4), %%eax\n"
28733- "51: movl 28(%4), %%edx\n"
28734+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
28735+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
28736 " movnti %%eax, 24(%3)\n"
28737 " movnti %%edx, 28(%3)\n"
28738- "11: movl 32(%4), %%eax\n"
28739- "61: movl 36(%4), %%edx\n"
28740+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
28741+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
28742 " movnti %%eax, 32(%3)\n"
28743 " movnti %%edx, 36(%3)\n"
28744- "12: movl 40(%4), %%eax\n"
28745- "71: movl 44(%4), %%edx\n"
28746+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
28747+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
28748 " movnti %%eax, 40(%3)\n"
28749 " movnti %%edx, 44(%3)\n"
28750- "13: movl 48(%4), %%eax\n"
28751- "81: movl 52(%4), %%edx\n"
28752+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
28753+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
28754 " movnti %%eax, 48(%3)\n"
28755 " movnti %%edx, 52(%3)\n"
28756- "14: movl 56(%4), %%eax\n"
28757- "91: movl 60(%4), %%edx\n"
28758+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
28759+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
28760 " movnti %%eax, 56(%3)\n"
28761 " movnti %%edx, 60(%3)\n"
28762 " addl $-64, %0\n"
28763@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
28764 " shrl $2, %0\n"
28765 " andl $3, %%eax\n"
28766 " cld\n"
28767- "6: rep; movsl\n"
28768+ "6: rep; "__copyuser_seg" movsl\n"
28769 " movl %%eax,%0\n"
28770- "7: rep; movsb\n"
28771+ "7: rep; "__copyuser_seg" movsb\n"
28772 "8:\n"
28773 ".section .fixup,\"ax\"\n"
28774 "9: lea 0(%%eax,%0,4),%0\n"
28775@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
28776 */
28777 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
28778 unsigned long size);
28779-unsigned long __copy_user_intel(void __user *to, const void *from,
28780+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
28781+ unsigned long size);
28782+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
28783 unsigned long size);
28784 unsigned long __copy_user_zeroing_intel_nocache(void *to,
28785 const void __user *from, unsigned long size);
28786 #endif /* CONFIG_X86_INTEL_USERCOPY */
28787
28788 /* Generic arbitrary sized copy. */
28789-#define __copy_user(to, from, size) \
28790+#define __copy_user(to, from, size, prefix, set, restore) \
28791 do { \
28792 int __d0, __d1, __d2; \
28793 __asm__ __volatile__( \
28794+ set \
28795 " cmp $7,%0\n" \
28796 " jbe 1f\n" \
28797 " movl %1,%0\n" \
28798 " negl %0\n" \
28799 " andl $7,%0\n" \
28800 " subl %0,%3\n" \
28801- "4: rep; movsb\n" \
28802+ "4: rep; "prefix"movsb\n" \
28803 " movl %3,%0\n" \
28804 " shrl $2,%0\n" \
28805 " andl $3,%3\n" \
28806 " .align 2,0x90\n" \
28807- "0: rep; movsl\n" \
28808+ "0: rep; "prefix"movsl\n" \
28809 " movl %3,%0\n" \
28810- "1: rep; movsb\n" \
28811+ "1: rep; "prefix"movsb\n" \
28812 "2:\n" \
28813+ restore \
28814 ".section .fixup,\"ax\"\n" \
28815 "5: addl %3,%0\n" \
28816 " jmp 2b\n" \
28817@@ -538,14 +650,14 @@ do { \
28818 " negl %0\n" \
28819 " andl $7,%0\n" \
28820 " subl %0,%3\n" \
28821- "4: rep; movsb\n" \
28822+ "4: rep; "__copyuser_seg"movsb\n" \
28823 " movl %3,%0\n" \
28824 " shrl $2,%0\n" \
28825 " andl $3,%3\n" \
28826 " .align 2,0x90\n" \
28827- "0: rep; movsl\n" \
28828+ "0: rep; "__copyuser_seg"movsl\n" \
28829 " movl %3,%0\n" \
28830- "1: rep; movsb\n" \
28831+ "1: rep; "__copyuser_seg"movsb\n" \
28832 "2:\n" \
28833 ".section .fixup,\"ax\"\n" \
28834 "5: addl %3,%0\n" \
28835@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
28836 {
28837 stac();
28838 if (movsl_is_ok(to, from, n))
28839- __copy_user(to, from, n);
28840+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
28841 else
28842- n = __copy_user_intel(to, from, n);
28843+ n = __generic_copy_to_user_intel(to, from, n);
28844 clac();
28845 return n;
28846 }
28847@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
28848 {
28849 stac();
28850 if (movsl_is_ok(to, from, n))
28851- __copy_user(to, from, n);
28852+ __copy_user(to, from, n, __copyuser_seg, "", "");
28853 else
28854- n = __copy_user_intel((void __user *)to,
28855- (const void *)from, n);
28856+ n = __generic_copy_from_user_intel(to, from, n);
28857 clac();
28858 return n;
28859 }
28860@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
28861 if (n > 64 && cpu_has_xmm2)
28862 n = __copy_user_intel_nocache(to, from, n);
28863 else
28864- __copy_user(to, from, n);
28865+ __copy_user(to, from, n, __copyuser_seg, "", "");
28866 #else
28867- __copy_user(to, from, n);
28868+ __copy_user(to, from, n, __copyuser_seg, "", "");
28869 #endif
28870 clac();
28871 return n;
28872 }
28873 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
28874
28875-/**
28876- * copy_to_user: - Copy a block of data into user space.
28877- * @to: Destination address, in user space.
28878- * @from: Source address, in kernel space.
28879- * @n: Number of bytes to copy.
28880- *
28881- * Context: User context only. This function may sleep.
28882- *
28883- * Copy data from kernel space to user space.
28884- *
28885- * Returns number of bytes that could not be copied.
28886- * On success, this will be zero.
28887- */
28888-unsigned long
28889-copy_to_user(void __user *to, const void *from, unsigned long n)
28890+#ifdef CONFIG_PAX_MEMORY_UDEREF
28891+void __set_fs(mm_segment_t x)
28892 {
28893- if (access_ok(VERIFY_WRITE, to, n))
28894- n = __copy_to_user(to, from, n);
28895- return n;
28896+ switch (x.seg) {
28897+ case 0:
28898+ loadsegment(gs, 0);
28899+ break;
28900+ case TASK_SIZE_MAX:
28901+ loadsegment(gs, __USER_DS);
28902+ break;
28903+ case -1UL:
28904+ loadsegment(gs, __KERNEL_DS);
28905+ break;
28906+ default:
28907+ BUG();
28908+ }
28909 }
28910-EXPORT_SYMBOL(copy_to_user);
28911+EXPORT_SYMBOL(__set_fs);
28912
28913-/**
28914- * copy_from_user: - Copy a block of data from user space.
28915- * @to: Destination address, in kernel space.
28916- * @from: Source address, in user space.
28917- * @n: Number of bytes to copy.
28918- *
28919- * Context: User context only. This function may sleep.
28920- *
28921- * Copy data from user space to kernel space.
28922- *
28923- * Returns number of bytes that could not be copied.
28924- * On success, this will be zero.
28925- *
28926- * If some data could not be copied, this function will pad the copied
28927- * data to the requested size using zero bytes.
28928- */
28929-unsigned long
28930-_copy_from_user(void *to, const void __user *from, unsigned long n)
28931+void set_fs(mm_segment_t x)
28932 {
28933- if (access_ok(VERIFY_READ, from, n))
28934- n = __copy_from_user(to, from, n);
28935- else
28936- memset(to, 0, n);
28937- return n;
28938+ current_thread_info()->addr_limit = x;
28939+ __set_fs(x);
28940 }
28941-EXPORT_SYMBOL(_copy_from_user);
28942+EXPORT_SYMBOL(set_fs);
28943+#endif
28944diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
28945index 906fea3..0194a18 100644
28946--- a/arch/x86/lib/usercopy_64.c
28947+++ b/arch/x86/lib/usercopy_64.c
28948@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
28949 might_fault();
28950 /* no memory constraint because it doesn't change any memory gcc knows
28951 about */
28952+ pax_open_userland();
28953 stac();
28954 asm volatile(
28955 " testq %[size8],%[size8]\n"
28956@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
28957 _ASM_EXTABLE(0b,3b)
28958 _ASM_EXTABLE(1b,2b)
28959 : [size8] "=&c"(size), [dst] "=&D" (__d0)
28960- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
28961+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
28962 [zero] "r" (0UL), [eight] "r" (8UL));
28963 clac();
28964+ pax_close_userland();
28965 return size;
28966 }
28967 EXPORT_SYMBOL(__clear_user);
28968@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
28969 }
28970 EXPORT_SYMBOL(clear_user);
28971
28972-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
28973+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
28974 {
28975- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
28976- return copy_user_generic((__force void *)to, (__force void *)from, len);
28977- }
28978- return len;
28979+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
28980+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
28981+ return len;
28982 }
28983 EXPORT_SYMBOL(copy_in_user);
28984
28985@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
28986 * it is not necessary to optimize tail handling.
28987 */
28988 unsigned long
28989-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
28990+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
28991 {
28992 char c;
28993 unsigned zero_len;
28994
28995+ clac();
28996+ pax_close_userland();
28997 for (; len; --len, to++) {
28998 if (__get_user_nocheck(c, from++, sizeof(char)))
28999 break;
29000@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29001 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29002 if (__put_user_nocheck(c, to++, sizeof(char)))
29003 break;
29004- clac();
29005 return len;
29006 }
29007diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29008index 23d8e5f..9ccc13a 100644
29009--- a/arch/x86/mm/Makefile
29010+++ b/arch/x86/mm/Makefile
29011@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29012 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29013
29014 obj-$(CONFIG_MEMTEST) += memtest.o
29015+
29016+quote:="
29017+obj-$(CONFIG_X86_64) += uderef_64.o
29018+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29019diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29020index 903ec1e..c4166b2 100644
29021--- a/arch/x86/mm/extable.c
29022+++ b/arch/x86/mm/extable.c
29023@@ -6,12 +6,24 @@
29024 static inline unsigned long
29025 ex_insn_addr(const struct exception_table_entry *x)
29026 {
29027- return (unsigned long)&x->insn + x->insn;
29028+ unsigned long reloc = 0;
29029+
29030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29031+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29032+#endif
29033+
29034+ return (unsigned long)&x->insn + x->insn + reloc;
29035 }
29036 static inline unsigned long
29037 ex_fixup_addr(const struct exception_table_entry *x)
29038 {
29039- return (unsigned long)&x->fixup + x->fixup;
29040+ unsigned long reloc = 0;
29041+
29042+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29043+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29044+#endif
29045+
29046+ return (unsigned long)&x->fixup + x->fixup + reloc;
29047 }
29048
29049 int fixup_exception(struct pt_regs *regs)
29050@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29051 unsigned long new_ip;
29052
29053 #ifdef CONFIG_PNPBIOS
29054- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29055+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29056 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29057 extern u32 pnp_bios_is_utter_crap;
29058 pnp_bios_is_utter_crap = 1;
29059@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29060 i += 4;
29061 p->fixup -= i;
29062 i += 4;
29063+
29064+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29065+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29066+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29067+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29068+#endif
29069+
29070 }
29071 }
29072
29073diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29074index 654be4a..a4a3da1 100644
29075--- a/arch/x86/mm/fault.c
29076+++ b/arch/x86/mm/fault.c
29077@@ -14,11 +14,18 @@
29078 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29079 #include <linux/prefetch.h> /* prefetchw */
29080 #include <linux/context_tracking.h> /* exception_enter(), ... */
29081+#include <linux/unistd.h>
29082+#include <linux/compiler.h>
29083
29084 #include <asm/traps.h> /* dotraplinkage, ... */
29085 #include <asm/pgalloc.h> /* pgd_*(), ... */
29086 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29087 #include <asm/fixmap.h> /* VSYSCALL_START */
29088+#include <asm/tlbflush.h>
29089+
29090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29091+#include <asm/stacktrace.h>
29092+#endif
29093
29094 /*
29095 * Page fault error code bits:
29096@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29097 int ret = 0;
29098
29099 /* kprobe_running() needs smp_processor_id() */
29100- if (kprobes_built_in() && !user_mode_vm(regs)) {
29101+ if (kprobes_built_in() && !user_mode(regs)) {
29102 preempt_disable();
29103 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29104 ret = 1;
29105@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29106 return !instr_lo || (instr_lo>>1) == 1;
29107 case 0x00:
29108 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29109- if (probe_kernel_address(instr, opcode))
29110+ if (user_mode(regs)) {
29111+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29112+ return 0;
29113+ } else if (probe_kernel_address(instr, opcode))
29114 return 0;
29115
29116 *prefetch = (instr_lo == 0xF) &&
29117@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29118 while (instr < max_instr) {
29119 unsigned char opcode;
29120
29121- if (probe_kernel_address(instr, opcode))
29122+ if (user_mode(regs)) {
29123+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29124+ break;
29125+ } else if (probe_kernel_address(instr, opcode))
29126 break;
29127
29128 instr++;
29129@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29130 force_sig_info(si_signo, &info, tsk);
29131 }
29132
29133+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29134+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29135+#endif
29136+
29137+#ifdef CONFIG_PAX_EMUTRAMP
29138+static int pax_handle_fetch_fault(struct pt_regs *regs);
29139+#endif
29140+
29141+#ifdef CONFIG_PAX_PAGEEXEC
29142+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29143+{
29144+ pgd_t *pgd;
29145+ pud_t *pud;
29146+ pmd_t *pmd;
29147+
29148+ pgd = pgd_offset(mm, address);
29149+ if (!pgd_present(*pgd))
29150+ return NULL;
29151+ pud = pud_offset(pgd, address);
29152+ if (!pud_present(*pud))
29153+ return NULL;
29154+ pmd = pmd_offset(pud, address);
29155+ if (!pmd_present(*pmd))
29156+ return NULL;
29157+ return pmd;
29158+}
29159+#endif
29160+
29161 DEFINE_SPINLOCK(pgd_lock);
29162 LIST_HEAD(pgd_list);
29163
29164@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29165 for (address = VMALLOC_START & PMD_MASK;
29166 address >= TASK_SIZE && address < FIXADDR_TOP;
29167 address += PMD_SIZE) {
29168+
29169+#ifdef CONFIG_PAX_PER_CPU_PGD
29170+ unsigned long cpu;
29171+#else
29172 struct page *page;
29173+#endif
29174
29175 spin_lock(&pgd_lock);
29176+
29177+#ifdef CONFIG_PAX_PER_CPU_PGD
29178+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29179+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29180+ pmd_t *ret;
29181+
29182+ ret = vmalloc_sync_one(pgd, address);
29183+ if (!ret)
29184+ break;
29185+ pgd = get_cpu_pgd(cpu, kernel);
29186+#else
29187 list_for_each_entry(page, &pgd_list, lru) {
29188+ pgd_t *pgd;
29189 spinlock_t *pgt_lock;
29190 pmd_t *ret;
29191
29192@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29193 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29194
29195 spin_lock(pgt_lock);
29196- ret = vmalloc_sync_one(page_address(page), address);
29197+ pgd = page_address(page);
29198+#endif
29199+
29200+ ret = vmalloc_sync_one(pgd, address);
29201+
29202+#ifndef CONFIG_PAX_PER_CPU_PGD
29203 spin_unlock(pgt_lock);
29204+#endif
29205
29206 if (!ret)
29207 break;
29208@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29209 * an interrupt in the middle of a task switch..
29210 */
29211 pgd_paddr = read_cr3();
29212+
29213+#ifdef CONFIG_PAX_PER_CPU_PGD
29214+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29215+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29216+#endif
29217+
29218 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
29219 if (!pmd_k)
29220 return -1;
29221@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29222 * happen within a race in page table update. In the later
29223 * case just flush:
29224 */
29225- pgd = pgd_offset(current->active_mm, address);
29226+
29227 pgd_ref = pgd_offset_k(address);
29228 if (pgd_none(*pgd_ref))
29229 return -1;
29230
29231+#ifdef CONFIG_PAX_PER_CPU_PGD
29232+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
29233+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
29234+ if (pgd_none(*pgd)) {
29235+ set_pgd(pgd, *pgd_ref);
29236+ arch_flush_lazy_mmu_mode();
29237+ } else {
29238+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
29239+ }
29240+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
29241+#else
29242+ pgd = pgd_offset(current->active_mm, address);
29243+#endif
29244+
29245 if (pgd_none(*pgd)) {
29246 set_pgd(pgd, *pgd_ref);
29247 arch_flush_lazy_mmu_mode();
29248@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
29249 static int is_errata100(struct pt_regs *regs, unsigned long address)
29250 {
29251 #ifdef CONFIG_X86_64
29252- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
29253+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
29254 return 1;
29255 #endif
29256 return 0;
29257@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
29258 }
29259
29260 static const char nx_warning[] = KERN_CRIT
29261-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
29262+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
29263
29264 static void
29265 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29266@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29267 if (!oops_may_print())
29268 return;
29269
29270- if (error_code & PF_INSTR) {
29271+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
29272 unsigned int level;
29273
29274 pte_t *pte = lookup_address(address, &level);
29275
29276 if (pte && pte_present(*pte) && !pte_exec(*pte))
29277- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
29278+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
29279 }
29280
29281+#ifdef CONFIG_PAX_KERNEXEC
29282+ if (init_mm.start_code <= address && address < init_mm.end_code) {
29283+ if (current->signal->curr_ip)
29284+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
29285+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
29286+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
29287+ else
29288+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
29289+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
29290+ }
29291+#endif
29292+
29293 printk(KERN_ALERT "BUG: unable to handle kernel ");
29294 if (address < PAGE_SIZE)
29295 printk(KERN_CONT "NULL pointer dereference");
29296@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
29297 return;
29298 }
29299 #endif
29300+
29301+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29302+ if (pax_is_fetch_fault(regs, error_code, address)) {
29303+
29304+#ifdef CONFIG_PAX_EMUTRAMP
29305+ switch (pax_handle_fetch_fault(regs)) {
29306+ case 2:
29307+ return;
29308+ }
29309+#endif
29310+
29311+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
29312+ do_group_exit(SIGKILL);
29313+ }
29314+#endif
29315+
29316 /* Kernel addresses are always protection faults: */
29317 if (address >= TASK_SIZE)
29318 error_code |= PF_PROT;
29319@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
29320 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
29321 printk(KERN_ERR
29322 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
29323- tsk->comm, tsk->pid, address);
29324+ tsk->comm, task_pid_nr(tsk), address);
29325 code = BUS_MCEERR_AR;
29326 }
29327 #endif
29328@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
29329 return 1;
29330 }
29331
29332+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
29333+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
29334+{
29335+ pte_t *pte;
29336+ pmd_t *pmd;
29337+ spinlock_t *ptl;
29338+ unsigned char pte_mask;
29339+
29340+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
29341+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
29342+ return 0;
29343+
29344+ /* PaX: it's our fault, let's handle it if we can */
29345+
29346+ /* PaX: take a look at read faults before acquiring any locks */
29347+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
29348+ /* instruction fetch attempt from a protected page in user mode */
29349+ up_read(&mm->mmap_sem);
29350+
29351+#ifdef CONFIG_PAX_EMUTRAMP
29352+ switch (pax_handle_fetch_fault(regs)) {
29353+ case 2:
29354+ return 1;
29355+ }
29356+#endif
29357+
29358+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
29359+ do_group_exit(SIGKILL);
29360+ }
29361+
29362+ pmd = pax_get_pmd(mm, address);
29363+ if (unlikely(!pmd))
29364+ return 0;
29365+
29366+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
29367+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
29368+ pte_unmap_unlock(pte, ptl);
29369+ return 0;
29370+ }
29371+
29372+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
29373+ /* write attempt to a protected page in user mode */
29374+ pte_unmap_unlock(pte, ptl);
29375+ return 0;
29376+ }
29377+
29378+#ifdef CONFIG_SMP
29379+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
29380+#else
29381+ if (likely(address > get_limit(regs->cs)))
29382+#endif
29383+ {
29384+ set_pte(pte, pte_mkread(*pte));
29385+ __flush_tlb_one(address);
29386+ pte_unmap_unlock(pte, ptl);
29387+ up_read(&mm->mmap_sem);
29388+ return 1;
29389+ }
29390+
29391+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
29392+
29393+ /*
29394+ * PaX: fill DTLB with user rights and retry
29395+ */
29396+ __asm__ __volatile__ (
29397+ "orb %2,(%1)\n"
29398+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
29399+/*
29400+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
29401+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
29402+ * page fault when examined during a TLB load attempt. this is true not only
29403+ * for PTEs holding a non-present entry but also present entries that will
29404+ * raise a page fault (such as those set up by PaX, or the copy-on-write
29405+ * mechanism). in effect it means that we do *not* need to flush the TLBs
29406+ * for our target pages since their PTEs are simply not in the TLBs at all.
29407+
29408+ * the best thing in omitting it is that we gain around 15-20% speed in the
29409+ * fast path of the page fault handler and can get rid of tracing since we
29410+ * can no longer flush unintended entries.
29411+ */
29412+ "invlpg (%0)\n"
29413+#endif
29414+ __copyuser_seg"testb $0,(%0)\n"
29415+ "xorb %3,(%1)\n"
29416+ :
29417+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
29418+ : "memory", "cc");
29419+ pte_unmap_unlock(pte, ptl);
29420+ up_read(&mm->mmap_sem);
29421+ return 1;
29422+}
29423+#endif
29424+
29425 /*
29426 * Handle a spurious fault caused by a stale TLB entry.
29427 *
29428@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
29429 static inline int
29430 access_error(unsigned long error_code, struct vm_area_struct *vma)
29431 {
29432+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
29433+ return 1;
29434+
29435 if (error_code & PF_WRITE) {
29436 /* write, present and write, not present: */
29437 if (unlikely(!(vma->vm_flags & VM_WRITE)))
29438@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
29439 if (error_code & PF_USER)
29440 return false;
29441
29442- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
29443+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
29444 return false;
29445
29446 return true;
29447@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
29448 {
29449 struct vm_area_struct *vma;
29450 struct task_struct *tsk;
29451- unsigned long address;
29452 struct mm_struct *mm;
29453 int fault;
29454 int write = error_code & PF_WRITE;
29455 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
29456 (write ? FAULT_FLAG_WRITE : 0);
29457
29458- tsk = current;
29459- mm = tsk->mm;
29460-
29461 /* Get the faulting address: */
29462- address = read_cr2();
29463+ unsigned long address = read_cr2();
29464+
29465+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29466+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
29467+ if (!search_exception_tables(regs->ip)) {
29468+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
29469+ bad_area_nosemaphore(regs, error_code, address);
29470+ return;
29471+ }
29472+ if (address < pax_user_shadow_base) {
29473+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
29474+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
29475+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
29476+ } else
29477+ address -= pax_user_shadow_base;
29478+ }
29479+#endif
29480+
29481+ tsk = current;
29482+ mm = tsk->mm;
29483
29484 /*
29485 * Detect and handle instructions that would cause a page fault for
29486@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
29487 * User-mode registers count as a user access even for any
29488 * potential system fault or CPU buglet:
29489 */
29490- if (user_mode_vm(regs)) {
29491+ if (user_mode(regs)) {
29492 local_irq_enable();
29493 error_code |= PF_USER;
29494 } else {
29495@@ -1142,6 +1365,11 @@ retry:
29496 might_sleep();
29497 }
29498
29499+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
29500+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
29501+ return;
29502+#endif
29503+
29504 vma = find_vma(mm, address);
29505 if (unlikely(!vma)) {
29506 bad_area(regs, error_code, address);
29507@@ -1153,18 +1381,24 @@ retry:
29508 bad_area(regs, error_code, address);
29509 return;
29510 }
29511- if (error_code & PF_USER) {
29512- /*
29513- * Accessing the stack below %sp is always a bug.
29514- * The large cushion allows instructions like enter
29515- * and pusha to work. ("enter $65535, $31" pushes
29516- * 32 pointers and then decrements %sp by 65535.)
29517- */
29518- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
29519- bad_area(regs, error_code, address);
29520- return;
29521- }
29522+ /*
29523+ * Accessing the stack below %sp is always a bug.
29524+ * The large cushion allows instructions like enter
29525+ * and pusha to work. ("enter $65535, $31" pushes
29526+ * 32 pointers and then decrements %sp by 65535.)
29527+ */
29528+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
29529+ bad_area(regs, error_code, address);
29530+ return;
29531 }
29532+
29533+#ifdef CONFIG_PAX_SEGMEXEC
29534+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
29535+ bad_area(regs, error_code, address);
29536+ return;
29537+ }
29538+#endif
29539+
29540 if (unlikely(expand_stack(vma, address))) {
29541 bad_area(regs, error_code, address);
29542 return;
29543@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
29544 __do_page_fault(regs, error_code);
29545 exception_exit(prev_state);
29546 }
29547+
29548+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29549+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
29550+{
29551+ struct mm_struct *mm = current->mm;
29552+ unsigned long ip = regs->ip;
29553+
29554+ if (v8086_mode(regs))
29555+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
29556+
29557+#ifdef CONFIG_PAX_PAGEEXEC
29558+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
29559+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
29560+ return true;
29561+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
29562+ return true;
29563+ return false;
29564+ }
29565+#endif
29566+
29567+#ifdef CONFIG_PAX_SEGMEXEC
29568+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
29569+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
29570+ return true;
29571+ return false;
29572+ }
29573+#endif
29574+
29575+ return false;
29576+}
29577+#endif
29578+
29579+#ifdef CONFIG_PAX_EMUTRAMP
29580+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
29581+{
29582+ int err;
29583+
29584+ do { /* PaX: libffi trampoline emulation */
29585+ unsigned char mov, jmp;
29586+ unsigned int addr1, addr2;
29587+
29588+#ifdef CONFIG_X86_64
29589+ if ((regs->ip + 9) >> 32)
29590+ break;
29591+#endif
29592+
29593+ err = get_user(mov, (unsigned char __user *)regs->ip);
29594+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
29595+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
29596+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
29597+
29598+ if (err)
29599+ break;
29600+
29601+ if (mov == 0xB8 && jmp == 0xE9) {
29602+ regs->ax = addr1;
29603+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
29604+ return 2;
29605+ }
29606+ } while (0);
29607+
29608+ do { /* PaX: gcc trampoline emulation #1 */
29609+ unsigned char mov1, mov2;
29610+ unsigned short jmp;
29611+ unsigned int addr1, addr2;
29612+
29613+#ifdef CONFIG_X86_64
29614+ if ((regs->ip + 11) >> 32)
29615+ break;
29616+#endif
29617+
29618+ err = get_user(mov1, (unsigned char __user *)regs->ip);
29619+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
29620+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
29621+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
29622+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
29623+
29624+ if (err)
29625+ break;
29626+
29627+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
29628+ regs->cx = addr1;
29629+ regs->ax = addr2;
29630+ regs->ip = addr2;
29631+ return 2;
29632+ }
29633+ } while (0);
29634+
29635+ do { /* PaX: gcc trampoline emulation #2 */
29636+ unsigned char mov, jmp;
29637+ unsigned int addr1, addr2;
29638+
29639+#ifdef CONFIG_X86_64
29640+ if ((regs->ip + 9) >> 32)
29641+ break;
29642+#endif
29643+
29644+ err = get_user(mov, (unsigned char __user *)regs->ip);
29645+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
29646+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
29647+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
29648+
29649+ if (err)
29650+ break;
29651+
29652+ if (mov == 0xB9 && jmp == 0xE9) {
29653+ regs->cx = addr1;
29654+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
29655+ return 2;
29656+ }
29657+ } while (0);
29658+
29659+ return 1; /* PaX in action */
29660+}
29661+
29662+#ifdef CONFIG_X86_64
29663+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
29664+{
29665+ int err;
29666+
29667+ do { /* PaX: libffi trampoline emulation */
29668+ unsigned short mov1, mov2, jmp1;
29669+ unsigned char stcclc, jmp2;
29670+ unsigned long addr1, addr2;
29671+
29672+ err = get_user(mov1, (unsigned short __user *)regs->ip);
29673+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
29674+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
29675+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
29676+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
29677+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
29678+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
29679+
29680+ if (err)
29681+ break;
29682+
29683+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
29684+ regs->r11 = addr1;
29685+ regs->r10 = addr2;
29686+ if (stcclc == 0xF8)
29687+ regs->flags &= ~X86_EFLAGS_CF;
29688+ else
29689+ regs->flags |= X86_EFLAGS_CF;
29690+ regs->ip = addr1;
29691+ return 2;
29692+ }
29693+ } while (0);
29694+
29695+ do { /* PaX: gcc trampoline emulation #1 */
29696+ unsigned short mov1, mov2, jmp1;
29697+ unsigned char jmp2;
29698+ unsigned int addr1;
29699+ unsigned long addr2;
29700+
29701+ err = get_user(mov1, (unsigned short __user *)regs->ip);
29702+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
29703+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
29704+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
29705+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
29706+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
29707+
29708+ if (err)
29709+ break;
29710+
29711+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
29712+ regs->r11 = addr1;
29713+ regs->r10 = addr2;
29714+ regs->ip = addr1;
29715+ return 2;
29716+ }
29717+ } while (0);
29718+
29719+ do { /* PaX: gcc trampoline emulation #2 */
29720+ unsigned short mov1, mov2, jmp1;
29721+ unsigned char jmp2;
29722+ unsigned long addr1, addr2;
29723+
29724+ err = get_user(mov1, (unsigned short __user *)regs->ip);
29725+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
29726+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
29727+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
29728+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
29729+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
29730+
29731+ if (err)
29732+ break;
29733+
29734+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
29735+ regs->r11 = addr1;
29736+ regs->r10 = addr2;
29737+ regs->ip = addr1;
29738+ return 2;
29739+ }
29740+ } while (0);
29741+
29742+ return 1; /* PaX in action */
29743+}
29744+#endif
29745+
29746+/*
29747+ * PaX: decide what to do with offenders (regs->ip = fault address)
29748+ *
29749+ * returns 1 when task should be killed
29750+ * 2 when gcc trampoline was detected
29751+ */
29752+static int pax_handle_fetch_fault(struct pt_regs *regs)
29753+{
29754+ if (v8086_mode(regs))
29755+ return 1;
29756+
29757+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
29758+ return 1;
29759+
29760+#ifdef CONFIG_X86_32
29761+ return pax_handle_fetch_fault_32(regs);
29762+#else
29763+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
29764+ return pax_handle_fetch_fault_32(regs);
29765+ else
29766+ return pax_handle_fetch_fault_64(regs);
29767+#endif
29768+}
29769+#endif
29770+
29771+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29772+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
29773+{
29774+ long i;
29775+
29776+ printk(KERN_ERR "PAX: bytes at PC: ");
29777+ for (i = 0; i < 20; i++) {
29778+ unsigned char c;
29779+ if (get_user(c, (unsigned char __force_user *)pc+i))
29780+ printk(KERN_CONT "?? ");
29781+ else
29782+ printk(KERN_CONT "%02x ", c);
29783+ }
29784+ printk("\n");
29785+
29786+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
29787+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
29788+ unsigned long c;
29789+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
29790+#ifdef CONFIG_X86_32
29791+ printk(KERN_CONT "???????? ");
29792+#else
29793+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
29794+ printk(KERN_CONT "???????? ???????? ");
29795+ else
29796+ printk(KERN_CONT "???????????????? ");
29797+#endif
29798+ } else {
29799+#ifdef CONFIG_X86_64
29800+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
29801+ printk(KERN_CONT "%08x ", (unsigned int)c);
29802+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
29803+ } else
29804+#endif
29805+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
29806+ }
29807+ }
29808+ printk("\n");
29809+}
29810+#endif
29811+
29812+/**
29813+ * probe_kernel_write(): safely attempt to write to a location
29814+ * @dst: address to write to
29815+ * @src: pointer to the data that shall be written
29816+ * @size: size of the data chunk
29817+ *
29818+ * Safely write to address @dst from the buffer at @src. If a kernel fault
29819+ * happens, handle that and return -EFAULT.
29820+ */
29821+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
29822+{
29823+ long ret;
29824+ mm_segment_t old_fs = get_fs();
29825+
29826+ set_fs(KERNEL_DS);
29827+ pagefault_disable();
29828+ pax_open_kernel();
29829+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
29830+ pax_close_kernel();
29831+ pagefault_enable();
29832+ set_fs(old_fs);
29833+
29834+ return ret ? -EFAULT : 0;
29835+}
29836diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
29837index dd74e46..7d26398 100644
29838--- a/arch/x86/mm/gup.c
29839+++ b/arch/x86/mm/gup.c
29840@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
29841 addr = start;
29842 len = (unsigned long) nr_pages << PAGE_SHIFT;
29843 end = start + len;
29844- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
29845+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
29846 (void __user *)start, len)))
29847 return 0;
29848
29849diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
29850index 252b8f5..4dcfdc1 100644
29851--- a/arch/x86/mm/highmem_32.c
29852+++ b/arch/x86/mm/highmem_32.c
29853@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
29854 idx = type + KM_TYPE_NR*smp_processor_id();
29855 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
29856 BUG_ON(!pte_none(*(kmap_pte-idx)));
29857+
29858+ pax_open_kernel();
29859 set_pte(kmap_pte-idx, mk_pte(page, prot));
29860+ pax_close_kernel();
29861+
29862 arch_flush_lazy_mmu_mode();
29863
29864 return (void *)vaddr;
29865diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
29866index ae1aa71..d9bea75 100644
29867--- a/arch/x86/mm/hugetlbpage.c
29868+++ b/arch/x86/mm/hugetlbpage.c
29869@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
29870 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
29871 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
29872 unsigned long addr, unsigned long len,
29873- unsigned long pgoff, unsigned long flags)
29874+ unsigned long pgoff, unsigned long flags, unsigned long offset)
29875 {
29876 struct hstate *h = hstate_file(file);
29877 struct vm_unmapped_area_info info;
29878-
29879+
29880 info.flags = 0;
29881 info.length = len;
29882 info.low_limit = TASK_UNMAPPED_BASE;
29883+
29884+#ifdef CONFIG_PAX_RANDMMAP
29885+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
29886+ info.low_limit += current->mm->delta_mmap;
29887+#endif
29888+
29889 info.high_limit = TASK_SIZE;
29890 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
29891 info.align_offset = 0;
29892+ info.threadstack_offset = offset;
29893 return vm_unmapped_area(&info);
29894 }
29895
29896 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
29897 unsigned long addr0, unsigned long len,
29898- unsigned long pgoff, unsigned long flags)
29899+ unsigned long pgoff, unsigned long flags, unsigned long offset)
29900 {
29901 struct hstate *h = hstate_file(file);
29902 struct vm_unmapped_area_info info;
29903@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
29904 info.high_limit = current->mm->mmap_base;
29905 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
29906 info.align_offset = 0;
29907+ info.threadstack_offset = offset;
29908 addr = vm_unmapped_area(&info);
29909
29910 /*
29911@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
29912 VM_BUG_ON(addr != -ENOMEM);
29913 info.flags = 0;
29914 info.low_limit = TASK_UNMAPPED_BASE;
29915+
29916+#ifdef CONFIG_PAX_RANDMMAP
29917+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
29918+ info.low_limit += current->mm->delta_mmap;
29919+#endif
29920+
29921 info.high_limit = TASK_SIZE;
29922 addr = vm_unmapped_area(&info);
29923 }
29924@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
29925 struct hstate *h = hstate_file(file);
29926 struct mm_struct *mm = current->mm;
29927 struct vm_area_struct *vma;
29928+ unsigned long pax_task_size = TASK_SIZE;
29929+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
29930
29931 if (len & ~huge_page_mask(h))
29932 return -EINVAL;
29933- if (len > TASK_SIZE)
29934+
29935+#ifdef CONFIG_PAX_SEGMEXEC
29936+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
29937+ pax_task_size = SEGMEXEC_TASK_SIZE;
29938+#endif
29939+
29940+ pax_task_size -= PAGE_SIZE;
29941+
29942+ if (len > pax_task_size)
29943 return -ENOMEM;
29944
29945 if (flags & MAP_FIXED) {
29946@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
29947 return addr;
29948 }
29949
29950+#ifdef CONFIG_PAX_RANDMMAP
29951+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29952+#endif
29953+
29954 if (addr) {
29955 addr = ALIGN(addr, huge_page_size(h));
29956 vma = find_vma(mm, addr);
29957- if (TASK_SIZE - len >= addr &&
29958- (!vma || addr + len <= vma->vm_start))
29959+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
29960 return addr;
29961 }
29962 if (mm->get_unmapped_area == arch_get_unmapped_area)
29963 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
29964- pgoff, flags);
29965+ pgoff, flags, offset);
29966 else
29967 return hugetlb_get_unmapped_area_topdown(file, addr, len,
29968- pgoff, flags);
29969+ pgoff, flags, offset);
29970 }
29971
29972 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
29973diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
29974index 1f34e92..c97b98f 100644
29975--- a/arch/x86/mm/init.c
29976+++ b/arch/x86/mm/init.c
29977@@ -4,6 +4,7 @@
29978 #include <linux/swap.h>
29979 #include <linux/memblock.h>
29980 #include <linux/bootmem.h> /* for max_low_pfn */
29981+#include <linux/tboot.h>
29982
29983 #include <asm/cacheflush.h>
29984 #include <asm/e820.h>
29985@@ -17,6 +18,8 @@
29986 #include <asm/proto.h>
29987 #include <asm/dma.h> /* for MAX_DMA_PFN */
29988 #include <asm/microcode.h>
29989+#include <asm/desc.h>
29990+#include <asm/bios_ebda.h>
29991
29992 #include "mm_internal.h"
29993
29994@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
29995 early_ioremap_page_table_range_init();
29996 #endif
29997
29998+#ifdef CONFIG_PAX_PER_CPU_PGD
29999+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30000+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30001+ KERNEL_PGD_PTRS);
30002+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30003+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30004+ KERNEL_PGD_PTRS);
30005+ load_cr3(get_cpu_pgd(0, kernel));
30006+#else
30007 load_cr3(swapper_pg_dir);
30008+#endif
30009+
30010 __flush_tlb_all();
30011
30012 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30013@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30014 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30015 * mmio resources as well as potential bios/acpi data regions.
30016 */
30017+
30018+#ifdef CONFIG_GRKERNSEC_KMEM
30019+static unsigned int ebda_start __read_only;
30020+static unsigned int ebda_end __read_only;
30021+#endif
30022+
30023 int devmem_is_allowed(unsigned long pagenr)
30024 {
30025- if (pagenr < 256)
30026+#ifdef CONFIG_GRKERNSEC_KMEM
30027+ /* allow BDA */
30028+ if (!pagenr)
30029 return 1;
30030+ /* allow EBDA */
30031+ if (pagenr >= ebda_start && pagenr < ebda_end)
30032+ return 1;
30033+ /* if tboot is in use, allow access to its hardcoded serial log range */
30034+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30035+ return 1;
30036+#else
30037+ if (!pagenr)
30038+ return 1;
30039+#ifdef CONFIG_VM86
30040+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30041+ return 1;
30042+#endif
30043+#endif
30044+
30045+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30046+ return 1;
30047+#ifdef CONFIG_GRKERNSEC_KMEM
30048+ /* throw out everything else below 1MB */
30049+ if (pagenr <= 256)
30050+ return 0;
30051+#endif
30052 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30053 return 0;
30054 if (!page_is_ram(pagenr))
30055@@ -538,8 +582,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30056 #endif
30057 }
30058
30059+#ifdef CONFIG_GRKERNSEC_KMEM
30060+static inline void gr_init_ebda(void)
30061+{
30062+ unsigned int ebda_addr;
30063+ unsigned int ebda_size = 0;
30064+
30065+ ebda_addr = get_bios_ebda();
30066+ if (ebda_addr) {
30067+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30068+ ebda_size <<= 10;
30069+ }
30070+ if (ebda_addr && ebda_size) {
30071+ ebda_start = ebda_addr >> PAGE_SHIFT;
30072+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30073+ } else {
30074+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30075+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30076+ }
30077+}
30078+#else
30079+static inline void gr_init_ebda(void) { }
30080+#endif
30081+
30082 void free_initmem(void)
30083 {
30084+#ifdef CONFIG_PAX_KERNEXEC
30085+#ifdef CONFIG_X86_32
30086+ /* PaX: limit KERNEL_CS to actual size */
30087+ unsigned long addr, limit;
30088+ struct desc_struct d;
30089+ int cpu;
30090+#else
30091+ pgd_t *pgd;
30092+ pud_t *pud;
30093+ pmd_t *pmd;
30094+ unsigned long addr, end;
30095+#endif
30096+#endif
30097+
30098+ gr_init_ebda();
30099+
30100+#ifdef CONFIG_PAX_KERNEXEC
30101+#ifdef CONFIG_X86_32
30102+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30103+ limit = (limit - 1UL) >> PAGE_SHIFT;
30104+
30105+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30106+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30107+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30108+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30109+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30110+ }
30111+
30112+ /* PaX: make KERNEL_CS read-only */
30113+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30114+ if (!paravirt_enabled())
30115+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30116+/*
30117+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30118+ pgd = pgd_offset_k(addr);
30119+ pud = pud_offset(pgd, addr);
30120+ pmd = pmd_offset(pud, addr);
30121+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30122+ }
30123+*/
30124+#ifdef CONFIG_X86_PAE
30125+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30126+/*
30127+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30128+ pgd = pgd_offset_k(addr);
30129+ pud = pud_offset(pgd, addr);
30130+ pmd = pmd_offset(pud, addr);
30131+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30132+ }
30133+*/
30134+#endif
30135+
30136+#ifdef CONFIG_MODULES
30137+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30138+#endif
30139+
30140+#else
30141+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30142+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30143+ pgd = pgd_offset_k(addr);
30144+ pud = pud_offset(pgd, addr);
30145+ pmd = pmd_offset(pud, addr);
30146+ if (!pmd_present(*pmd))
30147+ continue;
30148+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30149+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30150+ else
30151+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30152+ }
30153+
30154+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30155+ end = addr + KERNEL_IMAGE_SIZE;
30156+ for (; addr < end; addr += PMD_SIZE) {
30157+ pgd = pgd_offset_k(addr);
30158+ pud = pud_offset(pgd, addr);
30159+ pmd = pmd_offset(pud, addr);
30160+ if (!pmd_present(*pmd))
30161+ continue;
30162+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30163+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30164+ }
30165+#endif
30166+
30167+ flush_tlb_all();
30168+#endif
30169+
30170 free_init_pages("unused kernel memory",
30171 (unsigned long)(&__init_begin),
30172 (unsigned long)(&__init_end));
30173diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30174index 3ac7e31..89611b7 100644
30175--- a/arch/x86/mm/init_32.c
30176+++ b/arch/x86/mm/init_32.c
30177@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30178 bool __read_mostly __vmalloc_start_set = false;
30179
30180 /*
30181- * Creates a middle page table and puts a pointer to it in the
30182- * given global directory entry. This only returns the gd entry
30183- * in non-PAE compilation mode, since the middle layer is folded.
30184- */
30185-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30186-{
30187- pud_t *pud;
30188- pmd_t *pmd_table;
30189-
30190-#ifdef CONFIG_X86_PAE
30191- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30192- pmd_table = (pmd_t *)alloc_low_page();
30193- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30194- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30195- pud = pud_offset(pgd, 0);
30196- BUG_ON(pmd_table != pmd_offset(pud, 0));
30197-
30198- return pmd_table;
30199- }
30200-#endif
30201- pud = pud_offset(pgd, 0);
30202- pmd_table = pmd_offset(pud, 0);
30203-
30204- return pmd_table;
30205-}
30206-
30207-/*
30208 * Create a page table and place a pointer to it in a middle page
30209 * directory entry:
30210 */
30211@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30212 pte_t *page_table = (pte_t *)alloc_low_page();
30213
30214 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30215+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30216+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30217+#else
30218 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30219+#endif
30220 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
30221 }
30222
30223 return pte_offset_kernel(pmd, 0);
30224 }
30225
30226+static pmd_t * __init one_md_table_init(pgd_t *pgd)
30227+{
30228+ pud_t *pud;
30229+ pmd_t *pmd_table;
30230+
30231+ pud = pud_offset(pgd, 0);
30232+ pmd_table = pmd_offset(pud, 0);
30233+
30234+ return pmd_table;
30235+}
30236+
30237 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
30238 {
30239 int pgd_idx = pgd_index(vaddr);
30240@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30241 int pgd_idx, pmd_idx;
30242 unsigned long vaddr;
30243 pgd_t *pgd;
30244+ pud_t *pud;
30245 pmd_t *pmd;
30246 pte_t *pte = NULL;
30247 unsigned long count = page_table_range_init_count(start, end);
30248@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30249 pgd = pgd_base + pgd_idx;
30250
30251 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
30252- pmd = one_md_table_init(pgd);
30253- pmd = pmd + pmd_index(vaddr);
30254+ pud = pud_offset(pgd, vaddr);
30255+ pmd = pmd_offset(pud, vaddr);
30256+
30257+#ifdef CONFIG_X86_PAE
30258+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
30259+#endif
30260+
30261 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
30262 pmd++, pmd_idx++) {
30263 pte = page_table_kmap_check(one_page_table_init(pmd),
30264@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30265 }
30266 }
30267
30268-static inline int is_kernel_text(unsigned long addr)
30269+static inline int is_kernel_text(unsigned long start, unsigned long end)
30270 {
30271- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
30272- return 1;
30273- return 0;
30274+ if ((start > ktla_ktva((unsigned long)_etext) ||
30275+ end <= ktla_ktva((unsigned long)_stext)) &&
30276+ (start > ktla_ktva((unsigned long)_einittext) ||
30277+ end <= ktla_ktva((unsigned long)_sinittext)) &&
30278+
30279+#ifdef CONFIG_ACPI_SLEEP
30280+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
30281+#endif
30282+
30283+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
30284+ return 0;
30285+ return 1;
30286 }
30287
30288 /*
30289@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
30290 unsigned long last_map_addr = end;
30291 unsigned long start_pfn, end_pfn;
30292 pgd_t *pgd_base = swapper_pg_dir;
30293- int pgd_idx, pmd_idx, pte_ofs;
30294+ unsigned int pgd_idx, pmd_idx, pte_ofs;
30295 unsigned long pfn;
30296 pgd_t *pgd;
30297+ pud_t *pud;
30298 pmd_t *pmd;
30299 pte_t *pte;
30300 unsigned pages_2m, pages_4k;
30301@@ -291,8 +295,13 @@ repeat:
30302 pfn = start_pfn;
30303 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
30304 pgd = pgd_base + pgd_idx;
30305- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
30306- pmd = one_md_table_init(pgd);
30307+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
30308+ pud = pud_offset(pgd, 0);
30309+ pmd = pmd_offset(pud, 0);
30310+
30311+#ifdef CONFIG_X86_PAE
30312+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
30313+#endif
30314
30315 if (pfn >= end_pfn)
30316 continue;
30317@@ -304,14 +313,13 @@ repeat:
30318 #endif
30319 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
30320 pmd++, pmd_idx++) {
30321- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
30322+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
30323
30324 /*
30325 * Map with big pages if possible, otherwise
30326 * create normal page tables:
30327 */
30328 if (use_pse) {
30329- unsigned int addr2;
30330 pgprot_t prot = PAGE_KERNEL_LARGE;
30331 /*
30332 * first pass will use the same initial
30333@@ -322,11 +330,7 @@ repeat:
30334 _PAGE_PSE);
30335
30336 pfn &= PMD_MASK >> PAGE_SHIFT;
30337- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
30338- PAGE_OFFSET + PAGE_SIZE-1;
30339-
30340- if (is_kernel_text(addr) ||
30341- is_kernel_text(addr2))
30342+ if (is_kernel_text(address, address + PMD_SIZE))
30343 prot = PAGE_KERNEL_LARGE_EXEC;
30344
30345 pages_2m++;
30346@@ -343,7 +347,7 @@ repeat:
30347 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
30348 pte += pte_ofs;
30349 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
30350- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
30351+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
30352 pgprot_t prot = PAGE_KERNEL;
30353 /*
30354 * first pass will use the same initial
30355@@ -351,7 +355,7 @@ repeat:
30356 */
30357 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
30358
30359- if (is_kernel_text(addr))
30360+ if (is_kernel_text(address, address + PAGE_SIZE))
30361 prot = PAGE_KERNEL_EXEC;
30362
30363 pages_4k++;
30364@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
30365
30366 pud = pud_offset(pgd, va);
30367 pmd = pmd_offset(pud, va);
30368- if (!pmd_present(*pmd))
30369+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
30370 break;
30371
30372 /* should not be large page here */
30373@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
30374
30375 static void __init pagetable_init(void)
30376 {
30377- pgd_t *pgd_base = swapper_pg_dir;
30378-
30379- permanent_kmaps_init(pgd_base);
30380+ permanent_kmaps_init(swapper_pg_dir);
30381 }
30382
30383-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
30384+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
30385 EXPORT_SYMBOL_GPL(__supported_pte_mask);
30386
30387 /* user-defined highmem size */
30388@@ -772,7 +774,7 @@ void __init mem_init(void)
30389 after_bootmem = 1;
30390
30391 codesize = (unsigned long) &_etext - (unsigned long) &_text;
30392- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
30393+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
30394 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
30395
30396 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
30397@@ -813,10 +815,10 @@ void __init mem_init(void)
30398 ((unsigned long)&__init_end -
30399 (unsigned long)&__init_begin) >> 10,
30400
30401- (unsigned long)&_etext, (unsigned long)&_edata,
30402- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
30403+ (unsigned long)&_sdata, (unsigned long)&_edata,
30404+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
30405
30406- (unsigned long)&_text, (unsigned long)&_etext,
30407+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
30408 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
30409
30410 /*
30411@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
30412 if (!kernel_set_to_readonly)
30413 return;
30414
30415+ start = ktla_ktva(start);
30416 pr_debug("Set kernel text: %lx - %lx for read write\n",
30417 start, start+size);
30418
30419@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
30420 if (!kernel_set_to_readonly)
30421 return;
30422
30423+ start = ktla_ktva(start);
30424 pr_debug("Set kernel text: %lx - %lx for read only\n",
30425 start, start+size);
30426
30427@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
30428 unsigned long start = PFN_ALIGN(_text);
30429 unsigned long size = PFN_ALIGN(_etext) - start;
30430
30431+ start = ktla_ktva(start);
30432 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
30433 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
30434 size >> 10);
30435diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
30436index bb00c46..bf91a67 100644
30437--- a/arch/x86/mm/init_64.c
30438+++ b/arch/x86/mm/init_64.c
30439@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
30440 * around without checking the pgd every time.
30441 */
30442
30443-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
30444+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
30445 EXPORT_SYMBOL_GPL(__supported_pte_mask);
30446
30447 int force_personality32;
30448@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
30449
30450 for (address = start; address <= end; address += PGDIR_SIZE) {
30451 const pgd_t *pgd_ref = pgd_offset_k(address);
30452+
30453+#ifdef CONFIG_PAX_PER_CPU_PGD
30454+ unsigned long cpu;
30455+#else
30456 struct page *page;
30457+#endif
30458
30459 if (pgd_none(*pgd_ref))
30460 continue;
30461
30462 spin_lock(&pgd_lock);
30463+
30464+#ifdef CONFIG_PAX_PER_CPU_PGD
30465+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30466+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
30467+
30468+ if (pgd_none(*pgd))
30469+ set_pgd(pgd, *pgd_ref);
30470+ else
30471+ BUG_ON(pgd_page_vaddr(*pgd)
30472+ != pgd_page_vaddr(*pgd_ref));
30473+ pgd = pgd_offset_cpu(cpu, kernel, address);
30474+#else
30475 list_for_each_entry(page, &pgd_list, lru) {
30476 pgd_t *pgd;
30477 spinlock_t *pgt_lock;
30478@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
30479 /* the pgt_lock only for Xen */
30480 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30481 spin_lock(pgt_lock);
30482+#endif
30483
30484 if (pgd_none(*pgd))
30485 set_pgd(pgd, *pgd_ref);
30486@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
30487 BUG_ON(pgd_page_vaddr(*pgd)
30488 != pgd_page_vaddr(*pgd_ref));
30489
30490+#ifndef CONFIG_PAX_PER_CPU_PGD
30491 spin_unlock(pgt_lock);
30492+#endif
30493+
30494 }
30495 spin_unlock(&pgd_lock);
30496 }
30497@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
30498 {
30499 if (pgd_none(*pgd)) {
30500 pud_t *pud = (pud_t *)spp_getpage();
30501- pgd_populate(&init_mm, pgd, pud);
30502+ pgd_populate_kernel(&init_mm, pgd, pud);
30503 if (pud != pud_offset(pgd, 0))
30504 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
30505 pud, pud_offset(pgd, 0));
30506@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
30507 {
30508 if (pud_none(*pud)) {
30509 pmd_t *pmd = (pmd_t *) spp_getpage();
30510- pud_populate(&init_mm, pud, pmd);
30511+ pud_populate_kernel(&init_mm, pud, pmd);
30512 if (pmd != pmd_offset(pud, 0))
30513 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
30514 pmd, pmd_offset(pud, 0));
30515@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
30516 pmd = fill_pmd(pud, vaddr);
30517 pte = fill_pte(pmd, vaddr);
30518
30519+ pax_open_kernel();
30520 set_pte(pte, new_pte);
30521+ pax_close_kernel();
30522
30523 /*
30524 * It's enough to flush this one mapping.
30525@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
30526 pgd = pgd_offset_k((unsigned long)__va(phys));
30527 if (pgd_none(*pgd)) {
30528 pud = (pud_t *) spp_getpage();
30529- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
30530- _PAGE_USER));
30531+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
30532 }
30533 pud = pud_offset(pgd, (unsigned long)__va(phys));
30534 if (pud_none(*pud)) {
30535 pmd = (pmd_t *) spp_getpage();
30536- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
30537- _PAGE_USER));
30538+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
30539 }
30540 pmd = pmd_offset(pud, phys);
30541 BUG_ON(!pmd_none(*pmd));
30542@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
30543 prot);
30544
30545 spin_lock(&init_mm.page_table_lock);
30546- pud_populate(&init_mm, pud, pmd);
30547+ pud_populate_kernel(&init_mm, pud, pmd);
30548 spin_unlock(&init_mm.page_table_lock);
30549 }
30550 __flush_tlb_all();
30551@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
30552 page_size_mask);
30553
30554 spin_lock(&init_mm.page_table_lock);
30555- pgd_populate(&init_mm, pgd, pud);
30556+ pgd_populate_kernel(&init_mm, pgd, pud);
30557 spin_unlock(&init_mm.page_table_lock);
30558 pgd_changed = true;
30559 }
30560@@ -1221,8 +1242,8 @@ int kern_addr_valid(unsigned long addr)
30561 static struct vm_area_struct gate_vma = {
30562 .vm_start = VSYSCALL_START,
30563 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
30564- .vm_page_prot = PAGE_READONLY_EXEC,
30565- .vm_flags = VM_READ | VM_EXEC
30566+ .vm_page_prot = PAGE_READONLY,
30567+ .vm_flags = VM_READ
30568 };
30569
30570 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30571@@ -1256,7 +1277,7 @@ int in_gate_area_no_mm(unsigned long addr)
30572
30573 const char *arch_vma_name(struct vm_area_struct *vma)
30574 {
30575- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30576+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30577 return "[vdso]";
30578 if (vma == &gate_vma)
30579 return "[vsyscall]";
30580diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
30581index 7b179b4..6bd17777 100644
30582--- a/arch/x86/mm/iomap_32.c
30583+++ b/arch/x86/mm/iomap_32.c
30584@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
30585 type = kmap_atomic_idx_push();
30586 idx = type + KM_TYPE_NR * smp_processor_id();
30587 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30588+
30589+ pax_open_kernel();
30590 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
30591+ pax_close_kernel();
30592+
30593 arch_flush_lazy_mmu_mode();
30594
30595 return (void *)vaddr;
30596diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
30597index 9a1e658..da003f3 100644
30598--- a/arch/x86/mm/ioremap.c
30599+++ b/arch/x86/mm/ioremap.c
30600@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
30601 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
30602 int is_ram = page_is_ram(pfn);
30603
30604- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
30605+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
30606 return NULL;
30607 WARN_ON_ONCE(is_ram);
30608 }
30609@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
30610 *
30611 * Caller must ensure there is only one unmapping for the same pointer.
30612 */
30613-void iounmap(volatile void __iomem *addr)
30614+void iounmap(const volatile void __iomem *addr)
30615 {
30616 struct vm_struct *p, *o;
30617
30618@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
30619
30620 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
30621 if (page_is_ram(start >> PAGE_SHIFT))
30622+#ifdef CONFIG_HIGHMEM
30623+ if ((start >> PAGE_SHIFT) < max_low_pfn)
30624+#endif
30625 return __va(phys);
30626
30627 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
30628@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
30629 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
30630 {
30631 if (page_is_ram(phys >> PAGE_SHIFT))
30632+#ifdef CONFIG_HIGHMEM
30633+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
30634+#endif
30635 return;
30636
30637 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
30638@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
30639 early_param("early_ioremap_debug", early_ioremap_debug_setup);
30640
30641 static __initdata int after_paging_init;
30642-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
30643+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
30644
30645 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
30646 {
30647@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
30648 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
30649
30650 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
30651- memset(bm_pte, 0, sizeof(bm_pte));
30652- pmd_populate_kernel(&init_mm, pmd, bm_pte);
30653+ pmd_populate_user(&init_mm, pmd, bm_pte);
30654
30655 /*
30656 * The boot-ioremap range spans multiple pmds, for which
30657diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
30658index d87dd6d..bf3fa66 100644
30659--- a/arch/x86/mm/kmemcheck/kmemcheck.c
30660+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
30661@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
30662 * memory (e.g. tracked pages)? For now, we need this to avoid
30663 * invoking kmemcheck for PnP BIOS calls.
30664 */
30665- if (regs->flags & X86_VM_MASK)
30666+ if (v8086_mode(regs))
30667 return false;
30668- if (regs->cs != __KERNEL_CS)
30669+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
30670 return false;
30671
30672 pte = kmemcheck_pte_lookup(address);
30673diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
30674index 845df68..1d8d29f 100644
30675--- a/arch/x86/mm/mmap.c
30676+++ b/arch/x86/mm/mmap.c
30677@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
30678 * Leave an at least ~128 MB hole with possible stack randomization.
30679 */
30680 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
30681-#define MAX_GAP (TASK_SIZE/6*5)
30682+#define MAX_GAP (pax_task_size/6*5)
30683
30684 static int mmap_is_legacy(void)
30685 {
30686@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
30687 return rnd << PAGE_SHIFT;
30688 }
30689
30690-static unsigned long mmap_base(void)
30691+static unsigned long mmap_base(struct mm_struct *mm)
30692 {
30693 unsigned long gap = rlimit(RLIMIT_STACK);
30694+ unsigned long pax_task_size = TASK_SIZE;
30695+
30696+#ifdef CONFIG_PAX_SEGMEXEC
30697+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30698+ pax_task_size = SEGMEXEC_TASK_SIZE;
30699+#endif
30700
30701 if (gap < MIN_GAP)
30702 gap = MIN_GAP;
30703 else if (gap > MAX_GAP)
30704 gap = MAX_GAP;
30705
30706- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
30707+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
30708 }
30709
30710 /*
30711 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
30712 * does, but not when emulating X86_32
30713 */
30714-static unsigned long mmap_legacy_base(void)
30715+static unsigned long mmap_legacy_base(struct mm_struct *mm)
30716 {
30717- if (mmap_is_ia32())
30718+ if (mmap_is_ia32()) {
30719+
30720+#ifdef CONFIG_PAX_SEGMEXEC
30721+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30722+ return SEGMEXEC_TASK_UNMAPPED_BASE;
30723+ else
30724+#endif
30725+
30726 return TASK_UNMAPPED_BASE;
30727- else
30728+ } else
30729 return TASK_UNMAPPED_BASE + mmap_rnd();
30730 }
30731
30732@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
30733 void arch_pick_mmap_layout(struct mm_struct *mm)
30734 {
30735 if (mmap_is_legacy()) {
30736- mm->mmap_base = mmap_legacy_base();
30737+ mm->mmap_base = mmap_legacy_base(mm);
30738+
30739+#ifdef CONFIG_PAX_RANDMMAP
30740+ if (mm->pax_flags & MF_PAX_RANDMMAP)
30741+ mm->mmap_base += mm->delta_mmap;
30742+#endif
30743+
30744 mm->get_unmapped_area = arch_get_unmapped_area;
30745 mm->unmap_area = arch_unmap_area;
30746 } else {
30747- mm->mmap_base = mmap_base();
30748+ mm->mmap_base = mmap_base(mm);
30749+
30750+#ifdef CONFIG_PAX_RANDMMAP
30751+ if (mm->pax_flags & MF_PAX_RANDMMAP)
30752+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
30753+#endif
30754+
30755 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
30756 mm->unmap_area = arch_unmap_area_topdown;
30757 }
30758diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
30759index dc0b727..f612039 100644
30760--- a/arch/x86/mm/mmio-mod.c
30761+++ b/arch/x86/mm/mmio-mod.c
30762@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
30763 break;
30764 default:
30765 {
30766- unsigned char *ip = (unsigned char *)instptr;
30767+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
30768 my_trace->opcode = MMIO_UNKNOWN_OP;
30769 my_trace->width = 0;
30770 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
30771@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
30772 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
30773 void __iomem *addr)
30774 {
30775- static atomic_t next_id;
30776+ static atomic_unchecked_t next_id;
30777 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
30778 /* These are page-unaligned. */
30779 struct mmiotrace_map map = {
30780@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
30781 .private = trace
30782 },
30783 .phys = offset,
30784- .id = atomic_inc_return(&next_id)
30785+ .id = atomic_inc_return_unchecked(&next_id)
30786 };
30787 map.map_id = trace->id;
30788
30789@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
30790 ioremap_trace_core(offset, size, addr);
30791 }
30792
30793-static void iounmap_trace_core(volatile void __iomem *addr)
30794+static void iounmap_trace_core(const volatile void __iomem *addr)
30795 {
30796 struct mmiotrace_map map = {
30797 .phys = 0,
30798@@ -328,7 +328,7 @@ not_enabled:
30799 }
30800 }
30801
30802-void mmiotrace_iounmap(volatile void __iomem *addr)
30803+void mmiotrace_iounmap(const volatile void __iomem *addr)
30804 {
30805 might_sleep();
30806 if (is_enabled()) /* recheck and proper locking in *_core() */
30807diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
30808index a71c4e2..301ae44 100644
30809--- a/arch/x86/mm/numa.c
30810+++ b/arch/x86/mm/numa.c
30811@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
30812 return true;
30813 }
30814
30815-static int __init numa_register_memblks(struct numa_meminfo *mi)
30816+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
30817 {
30818 unsigned long uninitialized_var(pfn_align);
30819 int i, nid;
30820diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
30821index d0b1773..4c3327c 100644
30822--- a/arch/x86/mm/pageattr-test.c
30823+++ b/arch/x86/mm/pageattr-test.c
30824@@ -36,7 +36,7 @@ enum {
30825
30826 static int pte_testbit(pte_t pte)
30827 {
30828- return pte_flags(pte) & _PAGE_UNUSED1;
30829+ return pte_flags(pte) & _PAGE_CPA_TEST;
30830 }
30831
30832 struct split_state {
30833diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
30834index bb32480..75f2f5e 100644
30835--- a/arch/x86/mm/pageattr.c
30836+++ b/arch/x86/mm/pageattr.c
30837@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
30838 */
30839 #ifdef CONFIG_PCI_BIOS
30840 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
30841- pgprot_val(forbidden) |= _PAGE_NX;
30842+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
30843 #endif
30844
30845 /*
30846@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
30847 * Does not cover __inittext since that is gone later on. On
30848 * 64bit we do not enforce !NX on the low mapping
30849 */
30850- if (within(address, (unsigned long)_text, (unsigned long)_etext))
30851- pgprot_val(forbidden) |= _PAGE_NX;
30852+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
30853+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
30854
30855+#ifdef CONFIG_DEBUG_RODATA
30856 /*
30857 * The .rodata section needs to be read-only. Using the pfn
30858 * catches all aliases.
30859@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
30860 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
30861 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
30862 pgprot_val(forbidden) |= _PAGE_RW;
30863+#endif
30864
30865 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
30866 /*
30867@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
30868 }
30869 #endif
30870
30871+#ifdef CONFIG_PAX_KERNEXEC
30872+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
30873+ pgprot_val(forbidden) |= _PAGE_RW;
30874+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
30875+ }
30876+#endif
30877+
30878 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
30879
30880 return prot;
30881@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
30882 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
30883 {
30884 /* change init_mm */
30885+ pax_open_kernel();
30886 set_pte_atomic(kpte, pte);
30887+
30888 #ifdef CONFIG_X86_32
30889 if (!SHARED_KERNEL_PMD) {
30890+
30891+#ifdef CONFIG_PAX_PER_CPU_PGD
30892+ unsigned long cpu;
30893+#else
30894 struct page *page;
30895+#endif
30896
30897+#ifdef CONFIG_PAX_PER_CPU_PGD
30898+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30899+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
30900+#else
30901 list_for_each_entry(page, &pgd_list, lru) {
30902- pgd_t *pgd;
30903+ pgd_t *pgd = (pgd_t *)page_address(page);
30904+#endif
30905+
30906 pud_t *pud;
30907 pmd_t *pmd;
30908
30909- pgd = (pgd_t *)page_address(page) + pgd_index(address);
30910+ pgd += pgd_index(address);
30911 pud = pud_offset(pgd, address);
30912 pmd = pmd_offset(pud, address);
30913 set_pte_atomic((pte_t *)pmd, pte);
30914 }
30915 }
30916 #endif
30917+ pax_close_kernel();
30918 }
30919
30920 static int
30921diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
30922index 6574388..87e9bef 100644
30923--- a/arch/x86/mm/pat.c
30924+++ b/arch/x86/mm/pat.c
30925@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
30926
30927 if (!entry) {
30928 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
30929- current->comm, current->pid, start, end - 1);
30930+ current->comm, task_pid_nr(current), start, end - 1);
30931 return -EINVAL;
30932 }
30933
30934@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30935
30936 while (cursor < to) {
30937 if (!devmem_is_allowed(pfn)) {
30938- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
30939- current->comm, from, to - 1);
30940+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
30941+ current->comm, from, to - 1, cursor);
30942 return 0;
30943 }
30944 cursor += PAGE_SIZE;
30945@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
30946 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
30947 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
30948 "for [mem %#010Lx-%#010Lx]\n",
30949- current->comm, current->pid,
30950+ current->comm, task_pid_nr(current),
30951 cattr_name(flags),
30952 base, (unsigned long long)(base + size-1));
30953 return -EINVAL;
30954@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
30955 flags = lookup_memtype(paddr);
30956 if (want_flags != flags) {
30957 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
30958- current->comm, current->pid,
30959+ current->comm, task_pid_nr(current),
30960 cattr_name(want_flags),
30961 (unsigned long long)paddr,
30962 (unsigned long long)(paddr + size - 1),
30963@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
30964 free_memtype(paddr, paddr + size);
30965 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
30966 " for [mem %#010Lx-%#010Lx], got %s\n",
30967- current->comm, current->pid,
30968+ current->comm, task_pid_nr(current),
30969 cattr_name(want_flags),
30970 (unsigned long long)paddr,
30971 (unsigned long long)(paddr + size - 1),
30972diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
30973index 415f6c4..d319983 100644
30974--- a/arch/x86/mm/pat_rbtree.c
30975+++ b/arch/x86/mm/pat_rbtree.c
30976@@ -160,7 +160,7 @@ success:
30977
30978 failure:
30979 printk(KERN_INFO "%s:%d conflicting memory types "
30980- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
30981+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
30982 end, cattr_name(found_type), cattr_name(match->type));
30983 return -EBUSY;
30984 }
30985diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
30986index 9f0614d..92ae64a 100644
30987--- a/arch/x86/mm/pf_in.c
30988+++ b/arch/x86/mm/pf_in.c
30989@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
30990 int i;
30991 enum reason_type rv = OTHERS;
30992
30993- p = (unsigned char *)ins_addr;
30994+ p = (unsigned char *)ktla_ktva(ins_addr);
30995 p += skip_prefix(p, &prf);
30996 p += get_opcode(p, &opcode);
30997
30998@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
30999 struct prefix_bits prf;
31000 int i;
31001
31002- p = (unsigned char *)ins_addr;
31003+ p = (unsigned char *)ktla_ktva(ins_addr);
31004 p += skip_prefix(p, &prf);
31005 p += get_opcode(p, &opcode);
31006
31007@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31008 struct prefix_bits prf;
31009 int i;
31010
31011- p = (unsigned char *)ins_addr;
31012+ p = (unsigned char *)ktla_ktva(ins_addr);
31013 p += skip_prefix(p, &prf);
31014 p += get_opcode(p, &opcode);
31015
31016@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31017 struct prefix_bits prf;
31018 int i;
31019
31020- p = (unsigned char *)ins_addr;
31021+ p = (unsigned char *)ktla_ktva(ins_addr);
31022 p += skip_prefix(p, &prf);
31023 p += get_opcode(p, &opcode);
31024 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31025@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31026 struct prefix_bits prf;
31027 int i;
31028
31029- p = (unsigned char *)ins_addr;
31030+ p = (unsigned char *)ktla_ktva(ins_addr);
31031 p += skip_prefix(p, &prf);
31032 p += get_opcode(p, &opcode);
31033 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31034diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31035index 17fda6a..f7d54a0 100644
31036--- a/arch/x86/mm/pgtable.c
31037+++ b/arch/x86/mm/pgtable.c
31038@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31039 list_del(&page->lru);
31040 }
31041
31042-#define UNSHARED_PTRS_PER_PGD \
31043- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31044+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31045+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31046
31047+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31048+{
31049+ unsigned int count = USER_PGD_PTRS;
31050
31051+ if (!pax_user_shadow_base)
31052+ return;
31053+
31054+ while (count--)
31055+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31056+}
31057+#endif
31058+
31059+#ifdef CONFIG_PAX_PER_CPU_PGD
31060+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31061+{
31062+ unsigned int count = USER_PGD_PTRS;
31063+
31064+ while (count--) {
31065+ pgd_t pgd;
31066+
31067+#ifdef CONFIG_X86_64
31068+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31069+#else
31070+ pgd = *src++;
31071+#endif
31072+
31073+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31074+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31075+#endif
31076+
31077+ *dst++ = pgd;
31078+ }
31079+
31080+}
31081+#endif
31082+
31083+#ifdef CONFIG_X86_64
31084+#define pxd_t pud_t
31085+#define pyd_t pgd_t
31086+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31087+#define pxd_free(mm, pud) pud_free((mm), (pud))
31088+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31089+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31090+#define PYD_SIZE PGDIR_SIZE
31091+#else
31092+#define pxd_t pmd_t
31093+#define pyd_t pud_t
31094+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31095+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31096+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31097+#define pyd_offset(mm, address) pud_offset((mm), (address))
31098+#define PYD_SIZE PUD_SIZE
31099+#endif
31100+
31101+#ifdef CONFIG_PAX_PER_CPU_PGD
31102+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31103+static inline void pgd_dtor(pgd_t *pgd) {}
31104+#else
31105 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31106 {
31107 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31108@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31109 pgd_list_del(pgd);
31110 spin_unlock(&pgd_lock);
31111 }
31112+#endif
31113
31114 /*
31115 * List of all pgd's needed for non-PAE so it can invalidate entries
31116@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31117 * -- nyc
31118 */
31119
31120-#ifdef CONFIG_X86_PAE
31121+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31122 /*
31123 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31124 * updating the top-level pagetable entries to guarantee the
31125@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31126 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31127 * and initialize the kernel pmds here.
31128 */
31129-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31130+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31131
31132 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31133 {
31134@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31135 */
31136 flush_tlb_mm(mm);
31137 }
31138+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31139+#define PREALLOCATED_PXDS USER_PGD_PTRS
31140 #else /* !CONFIG_X86_PAE */
31141
31142 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31143-#define PREALLOCATED_PMDS 0
31144+#define PREALLOCATED_PXDS 0
31145
31146 #endif /* CONFIG_X86_PAE */
31147
31148-static void free_pmds(pmd_t *pmds[])
31149+static void free_pxds(pxd_t *pxds[])
31150 {
31151 int i;
31152
31153- for(i = 0; i < PREALLOCATED_PMDS; i++)
31154- if (pmds[i])
31155- free_page((unsigned long)pmds[i]);
31156+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31157+ if (pxds[i])
31158+ free_page((unsigned long)pxds[i]);
31159 }
31160
31161-static int preallocate_pmds(pmd_t *pmds[])
31162+static int preallocate_pxds(pxd_t *pxds[])
31163 {
31164 int i;
31165 bool failed = false;
31166
31167- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31168- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31169- if (pmd == NULL)
31170+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31171+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31172+ if (pxd == NULL)
31173 failed = true;
31174- pmds[i] = pmd;
31175+ pxds[i] = pxd;
31176 }
31177
31178 if (failed) {
31179- free_pmds(pmds);
31180+ free_pxds(pxds);
31181 return -ENOMEM;
31182 }
31183
31184@@ -219,51 +279,55 @@ static int preallocate_pmds(pmd_t *pmds[])
31185 * preallocate which never got a corresponding vma will need to be
31186 * freed manually.
31187 */
31188-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31189+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31190 {
31191 int i;
31192
31193- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31194+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31195 pgd_t pgd = pgdp[i];
31196
31197 if (pgd_val(pgd) != 0) {
31198- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31199+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31200
31201- pgdp[i] = native_make_pgd(0);
31202+ set_pgd(pgdp + i, native_make_pgd(0));
31203
31204- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31205- pmd_free(mm, pmd);
31206+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31207+ pxd_free(mm, pxd);
31208 }
31209 }
31210 }
31211
31212-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31213+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31214 {
31215- pud_t *pud;
31216+ pyd_t *pyd;
31217 unsigned long addr;
31218 int i;
31219
31220- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31221+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31222 return;
31223
31224- pud = pud_offset(pgd, 0);
31225+#ifdef CONFIG_X86_64
31226+ pyd = pyd_offset(mm, 0L);
31227+#else
31228+ pyd = pyd_offset(pgd, 0L);
31229+#endif
31230
31231- for (addr = i = 0; i < PREALLOCATED_PMDS;
31232- i++, pud++, addr += PUD_SIZE) {
31233- pmd_t *pmd = pmds[i];
31234+ for (addr = i = 0; i < PREALLOCATED_PXDS;
31235+ i++, pyd++, addr += PYD_SIZE) {
31236+ pxd_t *pxd = pxds[i];
31237
31238 if (i >= KERNEL_PGD_BOUNDARY)
31239- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31240- sizeof(pmd_t) * PTRS_PER_PMD);
31241+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31242+ sizeof(pxd_t) * PTRS_PER_PMD);
31243
31244- pud_populate(mm, pud, pmd);
31245+ pyd_populate(mm, pyd, pxd);
31246 }
31247 }
31248
31249 pgd_t *pgd_alloc(struct mm_struct *mm)
31250 {
31251 pgd_t *pgd;
31252- pmd_t *pmds[PREALLOCATED_PMDS];
31253+ pxd_t *pxds[PREALLOCATED_PXDS];
31254
31255 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
31256
31257@@ -272,11 +336,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31258
31259 mm->pgd = pgd;
31260
31261- if (preallocate_pmds(pmds) != 0)
31262+ if (preallocate_pxds(pxds) != 0)
31263 goto out_free_pgd;
31264
31265 if (paravirt_pgd_alloc(mm) != 0)
31266- goto out_free_pmds;
31267+ goto out_free_pxds;
31268
31269 /*
31270 * Make sure that pre-populating the pmds is atomic with
31271@@ -286,14 +350,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31272 spin_lock(&pgd_lock);
31273
31274 pgd_ctor(mm, pgd);
31275- pgd_prepopulate_pmd(mm, pgd, pmds);
31276+ pgd_prepopulate_pxd(mm, pgd, pxds);
31277
31278 spin_unlock(&pgd_lock);
31279
31280 return pgd;
31281
31282-out_free_pmds:
31283- free_pmds(pmds);
31284+out_free_pxds:
31285+ free_pxds(pxds);
31286 out_free_pgd:
31287 free_page((unsigned long)pgd);
31288 out:
31289@@ -302,7 +366,7 @@ out:
31290
31291 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
31292 {
31293- pgd_mop_up_pmds(mm, pgd);
31294+ pgd_mop_up_pxds(mm, pgd);
31295 pgd_dtor(pgd);
31296 paravirt_pgd_free(mm, pgd);
31297 free_page((unsigned long)pgd);
31298diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
31299index a69bcb8..19068ab 100644
31300--- a/arch/x86/mm/pgtable_32.c
31301+++ b/arch/x86/mm/pgtable_32.c
31302@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
31303 return;
31304 }
31305 pte = pte_offset_kernel(pmd, vaddr);
31306+
31307+ pax_open_kernel();
31308 if (pte_val(pteval))
31309 set_pte_at(&init_mm, vaddr, pte, pteval);
31310 else
31311 pte_clear(&init_mm, vaddr, pte);
31312+ pax_close_kernel();
31313
31314 /*
31315 * It's enough to flush this one mapping.
31316diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
31317index e666cbb..61788c45 100644
31318--- a/arch/x86/mm/physaddr.c
31319+++ b/arch/x86/mm/physaddr.c
31320@@ -10,7 +10,7 @@
31321 #ifdef CONFIG_X86_64
31322
31323 #ifdef CONFIG_DEBUG_VIRTUAL
31324-unsigned long __phys_addr(unsigned long x)
31325+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
31326 {
31327 unsigned long y = x - __START_KERNEL_map;
31328
31329@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
31330 #else
31331
31332 #ifdef CONFIG_DEBUG_VIRTUAL
31333-unsigned long __phys_addr(unsigned long x)
31334+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
31335 {
31336 unsigned long phys_addr = x - PAGE_OFFSET;
31337 /* VMALLOC_* aren't constants */
31338diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
31339index 410531d..0f16030 100644
31340--- a/arch/x86/mm/setup_nx.c
31341+++ b/arch/x86/mm/setup_nx.c
31342@@ -5,8 +5,10 @@
31343 #include <asm/pgtable.h>
31344 #include <asm/proto.h>
31345
31346+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31347 static int disable_nx __cpuinitdata;
31348
31349+#ifndef CONFIG_PAX_PAGEEXEC
31350 /*
31351 * noexec = on|off
31352 *
31353@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
31354 return 0;
31355 }
31356 early_param("noexec", noexec_setup);
31357+#endif
31358+
31359+#endif
31360
31361 void __cpuinit x86_configure_nx(void)
31362 {
31363+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31364 if (cpu_has_nx && !disable_nx)
31365 __supported_pte_mask |= _PAGE_NX;
31366 else
31367+#endif
31368 __supported_pte_mask &= ~_PAGE_NX;
31369 }
31370
31371diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
31372index 282375f..e03a98f 100644
31373--- a/arch/x86/mm/tlb.c
31374+++ b/arch/x86/mm/tlb.c
31375@@ -48,7 +48,11 @@ void leave_mm(int cpu)
31376 BUG();
31377 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
31378 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
31379+
31380+#ifndef CONFIG_PAX_PER_CPU_PGD
31381 load_cr3(swapper_pg_dir);
31382+#endif
31383+
31384 }
31385 }
31386 EXPORT_SYMBOL_GPL(leave_mm);
31387diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
31388new file mode 100644
31389index 0000000..dace51c
31390--- /dev/null
31391+++ b/arch/x86/mm/uderef_64.c
31392@@ -0,0 +1,37 @@
31393+#include <linux/mm.h>
31394+#include <asm/pgtable.h>
31395+#include <asm/uaccess.h>
31396+
31397+#ifdef CONFIG_PAX_MEMORY_UDEREF
31398+/* PaX: due to the special call convention these functions must
31399+ * - remain leaf functions under all configurations,
31400+ * - never be called directly, only dereferenced from the wrappers.
31401+ */
31402+void __pax_open_userland(void)
31403+{
31404+ unsigned int cpu;
31405+
31406+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
31407+ return;
31408+
31409+ cpu = raw_get_cpu();
31410+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
31411+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
31412+ raw_put_cpu_no_resched();
31413+}
31414+EXPORT_SYMBOL(__pax_open_userland);
31415+
31416+void __pax_close_userland(void)
31417+{
31418+ unsigned int cpu;
31419+
31420+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
31421+ return;
31422+
31423+ cpu = raw_get_cpu();
31424+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
31425+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
31426+ raw_put_cpu_no_resched();
31427+}
31428+EXPORT_SYMBOL(__pax_close_userland);
31429+#endif
31430diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
31431index 877b9a1..a8ecf42 100644
31432--- a/arch/x86/net/bpf_jit.S
31433+++ b/arch/x86/net/bpf_jit.S
31434@@ -9,6 +9,7 @@
31435 */
31436 #include <linux/linkage.h>
31437 #include <asm/dwarf2.h>
31438+#include <asm/alternative-asm.h>
31439
31440 /*
31441 * Calling convention :
31442@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
31443 jle bpf_slow_path_word
31444 mov (SKBDATA,%rsi),%eax
31445 bswap %eax /* ntohl() */
31446+ pax_force_retaddr
31447 ret
31448
31449 sk_load_half:
31450@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
31451 jle bpf_slow_path_half
31452 movzwl (SKBDATA,%rsi),%eax
31453 rol $8,%ax # ntohs()
31454+ pax_force_retaddr
31455 ret
31456
31457 sk_load_byte:
31458@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
31459 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
31460 jle bpf_slow_path_byte
31461 movzbl (SKBDATA,%rsi),%eax
31462+ pax_force_retaddr
31463 ret
31464
31465 /**
31466@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
31467 movzbl (SKBDATA,%rsi),%ebx
31468 and $15,%bl
31469 shl $2,%bl
31470+ pax_force_retaddr
31471 ret
31472
31473 /* rsi contains offset and can be scratched */
31474@@ -109,6 +114,7 @@ bpf_slow_path_word:
31475 js bpf_error
31476 mov -12(%rbp),%eax
31477 bswap %eax
31478+ pax_force_retaddr
31479 ret
31480
31481 bpf_slow_path_half:
31482@@ -117,12 +123,14 @@ bpf_slow_path_half:
31483 mov -12(%rbp),%ax
31484 rol $8,%ax
31485 movzwl %ax,%eax
31486+ pax_force_retaddr
31487 ret
31488
31489 bpf_slow_path_byte:
31490 bpf_slow_path_common(1)
31491 js bpf_error
31492 movzbl -12(%rbp),%eax
31493+ pax_force_retaddr
31494 ret
31495
31496 bpf_slow_path_byte_msh:
31497@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
31498 and $15,%al
31499 shl $2,%al
31500 xchg %eax,%ebx
31501+ pax_force_retaddr
31502 ret
31503
31504 #define sk_negative_common(SIZE) \
31505@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
31506 sk_negative_common(4)
31507 mov (%rax), %eax
31508 bswap %eax
31509+ pax_force_retaddr
31510 ret
31511
31512 bpf_slow_path_half_neg:
31513@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
31514 mov (%rax),%ax
31515 rol $8,%ax
31516 movzwl %ax,%eax
31517+ pax_force_retaddr
31518 ret
31519
31520 bpf_slow_path_byte_neg:
31521@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
31522 .globl sk_load_byte_negative_offset
31523 sk_negative_common(1)
31524 movzbl (%rax), %eax
31525+ pax_force_retaddr
31526 ret
31527
31528 bpf_slow_path_byte_msh_neg:
31529@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
31530 and $15,%al
31531 shl $2,%al
31532 xchg %eax,%ebx
31533+ pax_force_retaddr
31534 ret
31535
31536 bpf_error:
31537@@ -197,4 +210,5 @@ bpf_error:
31538 xor %eax,%eax
31539 mov -8(%rbp),%rbx
31540 leaveq
31541+ pax_force_retaddr
31542 ret
31543diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
31544index f66b540..3e88dfb 100644
31545--- a/arch/x86/net/bpf_jit_comp.c
31546+++ b/arch/x86/net/bpf_jit_comp.c
31547@@ -12,6 +12,7 @@
31548 #include <linux/netdevice.h>
31549 #include <linux/filter.h>
31550 #include <linux/if_vlan.h>
31551+#include <linux/random.h>
31552
31553 /*
31554 * Conventions :
31555@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
31556 return ptr + len;
31557 }
31558
31559+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31560+#define MAX_INSTR_CODE_SIZE 96
31561+#else
31562+#define MAX_INSTR_CODE_SIZE 64
31563+#endif
31564+
31565 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
31566
31567 #define EMIT1(b1) EMIT(b1, 1)
31568 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
31569 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
31570 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
31571+
31572+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31573+/* original constant will appear in ecx */
31574+#define DILUTE_CONST_SEQUENCE(_off, _key) \
31575+do { \
31576+ /* mov ecx, randkey */ \
31577+ EMIT1(0xb9); \
31578+ EMIT(_key, 4); \
31579+ /* xor ecx, randkey ^ off */ \
31580+ EMIT2(0x81, 0xf1); \
31581+ EMIT((_key) ^ (_off), 4); \
31582+} while (0)
31583+
31584+#define EMIT1_off32(b1, _off) \
31585+do { \
31586+ switch (b1) { \
31587+ case 0x05: /* add eax, imm32 */ \
31588+ case 0x2d: /* sub eax, imm32 */ \
31589+ case 0x25: /* and eax, imm32 */ \
31590+ case 0x0d: /* or eax, imm32 */ \
31591+ case 0xb8: /* mov eax, imm32 */ \
31592+ case 0x35: /* xor eax, imm32 */ \
31593+ case 0x3d: /* cmp eax, imm32 */ \
31594+ case 0xa9: /* test eax, imm32 */ \
31595+ DILUTE_CONST_SEQUENCE(_off, randkey); \
31596+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
31597+ break; \
31598+ case 0xbb: /* mov ebx, imm32 */ \
31599+ DILUTE_CONST_SEQUENCE(_off, randkey); \
31600+ /* mov ebx, ecx */ \
31601+ EMIT2(0x89, 0xcb); \
31602+ break; \
31603+ case 0xbe: /* mov esi, imm32 */ \
31604+ DILUTE_CONST_SEQUENCE(_off, randkey); \
31605+ /* mov esi, ecx */ \
31606+ EMIT2(0x89, 0xce); \
31607+ break; \
31608+ case 0xe8: /* call rel imm32, always to known funcs */ \
31609+ EMIT1(b1); \
31610+ EMIT(_off, 4); \
31611+ break; \
31612+ case 0xe9: /* jmp rel imm32 */ \
31613+ EMIT1(b1); \
31614+ EMIT(_off, 4); \
31615+ /* prevent fall-through, we're not called if off = 0 */ \
31616+ EMIT(0xcccccccc, 4); \
31617+ EMIT(0xcccccccc, 4); \
31618+ break; \
31619+ default: \
31620+ BUILD_BUG(); \
31621+ } \
31622+} while (0)
31623+
31624+#define EMIT2_off32(b1, b2, _off) \
31625+do { \
31626+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
31627+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
31628+ EMIT(randkey, 4); \
31629+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
31630+ EMIT((_off) - randkey, 4); \
31631+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
31632+ DILUTE_CONST_SEQUENCE(_off, randkey); \
31633+ /* imul eax, ecx */ \
31634+ EMIT3(0x0f, 0xaf, 0xc1); \
31635+ } else { \
31636+ BUILD_BUG(); \
31637+ } \
31638+} while (0)
31639+#else
31640 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
31641+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
31642+#endif
31643
31644 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
31645 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
31646@@ -90,6 +168,24 @@ do { \
31647 #define X86_JBE 0x76
31648 #define X86_JA 0x77
31649
31650+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31651+#define APPEND_FLOW_VERIFY() \
31652+do { \
31653+ /* mov ecx, randkey */ \
31654+ EMIT1(0xb9); \
31655+ EMIT(randkey, 4); \
31656+ /* cmp ecx, randkey */ \
31657+ EMIT2(0x81, 0xf9); \
31658+ EMIT(randkey, 4); \
31659+ /* jz after 8 int 3s */ \
31660+ EMIT2(0x74, 0x08); \
31661+ EMIT(0xcccccccc, 4); \
31662+ EMIT(0xcccccccc, 4); \
31663+} while (0)
31664+#else
31665+#define APPEND_FLOW_VERIFY() do { } while (0)
31666+#endif
31667+
31668 #define EMIT_COND_JMP(op, offset) \
31669 do { \
31670 if (is_near(offset)) \
31671@@ -97,6 +193,7 @@ do { \
31672 else { \
31673 EMIT2(0x0f, op + 0x10); \
31674 EMIT(offset, 4); /* jxx .+off32 */ \
31675+ APPEND_FLOW_VERIFY(); \
31676 } \
31677 } while (0)
31678
31679@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
31680 set_fs(old_fs);
31681 }
31682
31683+struct bpf_jit_work {
31684+ struct work_struct work;
31685+ void *image;
31686+};
31687+
31688 #define CHOOSE_LOAD_FUNC(K, func) \
31689 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
31690
31691@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
31692
31693 void bpf_jit_compile(struct sk_filter *fp)
31694 {
31695- u8 temp[64];
31696+ u8 temp[MAX_INSTR_CODE_SIZE];
31697 u8 *prog;
31698 unsigned int proglen, oldproglen = 0;
31699 int ilen, i;
31700@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
31701 unsigned int *addrs;
31702 const struct sock_filter *filter = fp->insns;
31703 int flen = fp->len;
31704+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31705+ unsigned int randkey;
31706+#endif
31707
31708 if (!bpf_jit_enable)
31709 return;
31710@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
31711 if (addrs == NULL)
31712 return;
31713
31714+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
31715+ if (!fp->work)
31716+ goto out;
31717+
31718+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31719+ randkey = get_random_int();
31720+#endif
31721+
31722 /* Before first pass, make a rough estimation of addrs[]
31723- * each bpf instruction is translated to less than 64 bytes
31724+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
31725 */
31726 for (proglen = 0, i = 0; i < flen; i++) {
31727- proglen += 64;
31728+ proglen += MAX_INSTR_CODE_SIZE;
31729 addrs[i] = proglen;
31730 }
31731 cleanup_addr = proglen; /* epilogue address */
31732@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
31733 case BPF_S_ALU_MUL_K: /* A *= K */
31734 if (is_imm8(K))
31735 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
31736- else {
31737- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
31738- EMIT(K, 4);
31739- }
31740+ else
31741+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
31742 break;
31743 case BPF_S_ALU_DIV_X: /* A /= X; */
31744 seen |= SEEN_XREG;
31745@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
31746 break;
31747 case BPF_S_ALU_MOD_K: /* A %= K; */
31748 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
31749+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31750+ DILUTE_CONST_SEQUENCE(K, randkey);
31751+#else
31752 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
31753+#endif
31754 EMIT2(0xf7, 0xf1); /* div %ecx */
31755 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
31756 break;
31757 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
31758+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
31759+ DILUTE_CONST_SEQUENCE(K, randkey);
31760+ // imul rax, rcx
31761+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
31762+#else
31763 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
31764 EMIT(K, 4);
31765+#endif
31766 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
31767 break;
31768 case BPF_S_ALU_AND_X:
31769@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
31770 if (is_imm8(K)) {
31771 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
31772 } else {
31773- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
31774- EMIT(K, 4);
31775+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
31776 }
31777 } else {
31778 EMIT2(0x89,0xde); /* mov %ebx,%esi */
31779@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
31780 break;
31781 default:
31782 /* hmm, too complex filter, give up with jit compiler */
31783- goto out;
31784+ goto error;
31785 }
31786 ilen = prog - temp;
31787 if (image) {
31788 if (unlikely(proglen + ilen > oldproglen)) {
31789 pr_err("bpb_jit_compile fatal error\n");
31790- kfree(addrs);
31791- module_free(NULL, image);
31792- return;
31793+ module_free_exec(NULL, image);
31794+ goto error;
31795 }
31796+ pax_open_kernel();
31797 memcpy(image + proglen, temp, ilen);
31798+ pax_close_kernel();
31799 }
31800 proglen += ilen;
31801 addrs[i] = proglen;
31802@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
31803 break;
31804 }
31805 if (proglen == oldproglen) {
31806- image = module_alloc(max_t(unsigned int,
31807- proglen,
31808- sizeof(struct work_struct)));
31809+ image = module_alloc_exec(proglen);
31810 if (!image)
31811- goto out;
31812+ goto error;
31813 }
31814 oldproglen = proglen;
31815 }
31816@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
31817 if (image) {
31818 bpf_flush_icache(image, image + proglen);
31819 fp->bpf_func = (void *)image;
31820- }
31821+ } else
31822+error:
31823+ kfree(fp->work);
31824+
31825 out:
31826 kfree(addrs);
31827 return;
31828@@ -740,18 +862,20 @@ out:
31829
31830 static void jit_free_defer(struct work_struct *arg)
31831 {
31832- module_free(NULL, arg);
31833+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
31834+ kfree(arg);
31835 }
31836
31837 /* run from softirq, we must use a work_struct to call
31838- * module_free() from process context
31839+ * module_free_exec() from process context
31840 */
31841 void bpf_jit_free(struct sk_filter *fp)
31842 {
31843 if (fp->bpf_func != sk_run_filter) {
31844- struct work_struct *work = (struct work_struct *)fp->bpf_func;
31845+ struct work_struct *work = &fp->work->work;
31846
31847 INIT_WORK(work, jit_free_defer);
31848+ fp->work->image = fp->bpf_func;
31849 schedule_work(work);
31850 }
31851 }
31852diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
31853index d6aa6e8..266395a 100644
31854--- a/arch/x86/oprofile/backtrace.c
31855+++ b/arch/x86/oprofile/backtrace.c
31856@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
31857 struct stack_frame_ia32 *fp;
31858 unsigned long bytes;
31859
31860- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
31861+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
31862 if (bytes != sizeof(bufhead))
31863 return NULL;
31864
31865- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
31866+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
31867
31868 oprofile_add_trace(bufhead[0].return_address);
31869
31870@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
31871 struct stack_frame bufhead[2];
31872 unsigned long bytes;
31873
31874- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
31875+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
31876 if (bytes != sizeof(bufhead))
31877 return NULL;
31878
31879@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
31880 {
31881 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
31882
31883- if (!user_mode_vm(regs)) {
31884+ if (!user_mode(regs)) {
31885 unsigned long stack = kernel_stack_pointer(regs);
31886 if (depth)
31887 dump_trace(NULL, regs, (unsigned long *)stack, 0,
31888diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
31889index 48768df..ba9143c 100644
31890--- a/arch/x86/oprofile/nmi_int.c
31891+++ b/arch/x86/oprofile/nmi_int.c
31892@@ -23,6 +23,7 @@
31893 #include <asm/nmi.h>
31894 #include <asm/msr.h>
31895 #include <asm/apic.h>
31896+#include <asm/pgtable.h>
31897
31898 #include "op_counter.h"
31899 #include "op_x86_model.h"
31900@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
31901 if (ret)
31902 return ret;
31903
31904- if (!model->num_virt_counters)
31905- model->num_virt_counters = model->num_counters;
31906+ if (!model->num_virt_counters) {
31907+ pax_open_kernel();
31908+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
31909+ pax_close_kernel();
31910+ }
31911
31912 mux_init(ops);
31913
31914diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
31915index b2b9443..be58856 100644
31916--- a/arch/x86/oprofile/op_model_amd.c
31917+++ b/arch/x86/oprofile/op_model_amd.c
31918@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
31919 num_counters = AMD64_NUM_COUNTERS;
31920 }
31921
31922- op_amd_spec.num_counters = num_counters;
31923- op_amd_spec.num_controls = num_counters;
31924- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
31925+ pax_open_kernel();
31926+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
31927+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
31928+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
31929+ pax_close_kernel();
31930
31931 return 0;
31932 }
31933diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
31934index d90528e..0127e2b 100644
31935--- a/arch/x86/oprofile/op_model_ppro.c
31936+++ b/arch/x86/oprofile/op_model_ppro.c
31937@@ -19,6 +19,7 @@
31938 #include <asm/msr.h>
31939 #include <asm/apic.h>
31940 #include <asm/nmi.h>
31941+#include <asm/pgtable.h>
31942
31943 #include "op_x86_model.h"
31944 #include "op_counter.h"
31945@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
31946
31947 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
31948
31949- op_arch_perfmon_spec.num_counters = num_counters;
31950- op_arch_perfmon_spec.num_controls = num_counters;
31951+ pax_open_kernel();
31952+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
31953+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
31954+ pax_close_kernel();
31955 }
31956
31957 static int arch_perfmon_init(struct oprofile_operations *ignore)
31958diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
31959index 71e8a67..6a313bb 100644
31960--- a/arch/x86/oprofile/op_x86_model.h
31961+++ b/arch/x86/oprofile/op_x86_model.h
31962@@ -52,7 +52,7 @@ struct op_x86_model_spec {
31963 void (*switch_ctrl)(struct op_x86_model_spec const *model,
31964 struct op_msrs const * const msrs);
31965 #endif
31966-};
31967+} __do_const;
31968
31969 struct op_counter_config;
31970
31971diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
31972index e9e6ed5..e47ae67 100644
31973--- a/arch/x86/pci/amd_bus.c
31974+++ b/arch/x86/pci/amd_bus.c
31975@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
31976 return NOTIFY_OK;
31977 }
31978
31979-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
31980+static struct notifier_block amd_cpu_notifier = {
31981 .notifier_call = amd_cpu_notify,
31982 };
31983
31984diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
31985index 372e9b8..e775a6c 100644
31986--- a/arch/x86/pci/irq.c
31987+++ b/arch/x86/pci/irq.c
31988@@ -50,7 +50,7 @@ struct irq_router {
31989 struct irq_router_handler {
31990 u16 vendor;
31991 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
31992-};
31993+} __do_const;
31994
31995 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
31996 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
31997@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
31998 return 0;
31999 }
32000
32001-static __initdata struct irq_router_handler pirq_routers[] = {
32002+static __initconst const struct irq_router_handler pirq_routers[] = {
32003 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32004 { PCI_VENDOR_ID_AL, ali_router_probe },
32005 { PCI_VENDOR_ID_ITE, ite_router_probe },
32006@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32007 static void __init pirq_find_router(struct irq_router *r)
32008 {
32009 struct irq_routing_table *rt = pirq_table;
32010- struct irq_router_handler *h;
32011+ const struct irq_router_handler *h;
32012
32013 #ifdef CONFIG_PCI_BIOS
32014 if (!rt->signature) {
32015@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32016 return 0;
32017 }
32018
32019-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32020+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32021 {
32022 .callback = fix_broken_hp_bios_irq9,
32023 .ident = "HP Pavilion N5400 Series Laptop",
32024diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32025index 6eb18c4..20d83de 100644
32026--- a/arch/x86/pci/mrst.c
32027+++ b/arch/x86/pci/mrst.c
32028@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32029 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32030 pci_mmcfg_late_init();
32031 pcibios_enable_irq = mrst_pci_irq_enable;
32032- pci_root_ops = pci_mrst_ops;
32033+ pax_open_kernel();
32034+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32035+ pax_close_kernel();
32036 pci_soc_mode = 1;
32037 /* Continue with standard init */
32038 return 1;
32039diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32040index c77b24a..c979855 100644
32041--- a/arch/x86/pci/pcbios.c
32042+++ b/arch/x86/pci/pcbios.c
32043@@ -79,7 +79,7 @@ union bios32 {
32044 static struct {
32045 unsigned long address;
32046 unsigned short segment;
32047-} bios32_indirect = { 0, __KERNEL_CS };
32048+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32049
32050 /*
32051 * Returns the entry point for the given service, NULL on error
32052@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32053 unsigned long length; /* %ecx */
32054 unsigned long entry; /* %edx */
32055 unsigned long flags;
32056+ struct desc_struct d, *gdt;
32057
32058 local_irq_save(flags);
32059- __asm__("lcall *(%%edi); cld"
32060+
32061+ gdt = get_cpu_gdt_table(smp_processor_id());
32062+
32063+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32064+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32065+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32066+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32067+
32068+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32069 : "=a" (return_code),
32070 "=b" (address),
32071 "=c" (length),
32072 "=d" (entry)
32073 : "0" (service),
32074 "1" (0),
32075- "D" (&bios32_indirect));
32076+ "D" (&bios32_indirect),
32077+ "r"(__PCIBIOS_DS)
32078+ : "memory");
32079+
32080+ pax_open_kernel();
32081+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32082+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32083+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32084+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32085+ pax_close_kernel();
32086+
32087 local_irq_restore(flags);
32088
32089 switch (return_code) {
32090- case 0:
32091- return address + entry;
32092- case 0x80: /* Not present */
32093- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32094- return 0;
32095- default: /* Shouldn't happen */
32096- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32097- service, return_code);
32098+ case 0: {
32099+ int cpu;
32100+ unsigned char flags;
32101+
32102+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32103+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32104+ printk(KERN_WARNING "bios32_service: not valid\n");
32105 return 0;
32106+ }
32107+ address = address + PAGE_OFFSET;
32108+ length += 16UL; /* some BIOSs underreport this... */
32109+ flags = 4;
32110+ if (length >= 64*1024*1024) {
32111+ length >>= PAGE_SHIFT;
32112+ flags |= 8;
32113+ }
32114+
32115+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32116+ gdt = get_cpu_gdt_table(cpu);
32117+ pack_descriptor(&d, address, length, 0x9b, flags);
32118+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32119+ pack_descriptor(&d, address, length, 0x93, flags);
32120+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32121+ }
32122+ return entry;
32123+ }
32124+ case 0x80: /* Not present */
32125+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32126+ return 0;
32127+ default: /* Shouldn't happen */
32128+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32129+ service, return_code);
32130+ return 0;
32131 }
32132 }
32133
32134 static struct {
32135 unsigned long address;
32136 unsigned short segment;
32137-} pci_indirect = { 0, __KERNEL_CS };
32138+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32139
32140-static int pci_bios_present;
32141+static int pci_bios_present __read_only;
32142
32143 static int check_pcibios(void)
32144 {
32145@@ -131,11 +174,13 @@ static int check_pcibios(void)
32146 unsigned long flags, pcibios_entry;
32147
32148 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32149- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32150+ pci_indirect.address = pcibios_entry;
32151
32152 local_irq_save(flags);
32153- __asm__(
32154- "lcall *(%%edi); cld\n\t"
32155+ __asm__("movw %w6, %%ds\n\t"
32156+ "lcall *%%ss:(%%edi); cld\n\t"
32157+ "push %%ss\n\t"
32158+ "pop %%ds\n\t"
32159 "jc 1f\n\t"
32160 "xor %%ah, %%ah\n"
32161 "1:"
32162@@ -144,7 +189,8 @@ static int check_pcibios(void)
32163 "=b" (ebx),
32164 "=c" (ecx)
32165 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32166- "D" (&pci_indirect)
32167+ "D" (&pci_indirect),
32168+ "r" (__PCIBIOS_DS)
32169 : "memory");
32170 local_irq_restore(flags);
32171
32172@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32173
32174 switch (len) {
32175 case 1:
32176- __asm__("lcall *(%%esi); cld\n\t"
32177+ __asm__("movw %w6, %%ds\n\t"
32178+ "lcall *%%ss:(%%esi); cld\n\t"
32179+ "push %%ss\n\t"
32180+ "pop %%ds\n\t"
32181 "jc 1f\n\t"
32182 "xor %%ah, %%ah\n"
32183 "1:"
32184@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32185 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32186 "b" (bx),
32187 "D" ((long)reg),
32188- "S" (&pci_indirect));
32189+ "S" (&pci_indirect),
32190+ "r" (__PCIBIOS_DS));
32191 /*
32192 * Zero-extend the result beyond 8 bits, do not trust the
32193 * BIOS having done it:
32194@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32195 *value &= 0xff;
32196 break;
32197 case 2:
32198- __asm__("lcall *(%%esi); cld\n\t"
32199+ __asm__("movw %w6, %%ds\n\t"
32200+ "lcall *%%ss:(%%esi); cld\n\t"
32201+ "push %%ss\n\t"
32202+ "pop %%ds\n\t"
32203 "jc 1f\n\t"
32204 "xor %%ah, %%ah\n"
32205 "1:"
32206@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32207 : "1" (PCIBIOS_READ_CONFIG_WORD),
32208 "b" (bx),
32209 "D" ((long)reg),
32210- "S" (&pci_indirect));
32211+ "S" (&pci_indirect),
32212+ "r" (__PCIBIOS_DS));
32213 /*
32214 * Zero-extend the result beyond 16 bits, do not trust the
32215 * BIOS having done it:
32216@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32217 *value &= 0xffff;
32218 break;
32219 case 4:
32220- __asm__("lcall *(%%esi); cld\n\t"
32221+ __asm__("movw %w6, %%ds\n\t"
32222+ "lcall *%%ss:(%%esi); cld\n\t"
32223+ "push %%ss\n\t"
32224+ "pop %%ds\n\t"
32225 "jc 1f\n\t"
32226 "xor %%ah, %%ah\n"
32227 "1:"
32228@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32229 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32230 "b" (bx),
32231 "D" ((long)reg),
32232- "S" (&pci_indirect));
32233+ "S" (&pci_indirect),
32234+ "r" (__PCIBIOS_DS));
32235 break;
32236 }
32237
32238@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32239
32240 switch (len) {
32241 case 1:
32242- __asm__("lcall *(%%esi); cld\n\t"
32243+ __asm__("movw %w6, %%ds\n\t"
32244+ "lcall *%%ss:(%%esi); cld\n\t"
32245+ "push %%ss\n\t"
32246+ "pop %%ds\n\t"
32247 "jc 1f\n\t"
32248 "xor %%ah, %%ah\n"
32249 "1:"
32250@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32251 "c" (value),
32252 "b" (bx),
32253 "D" ((long)reg),
32254- "S" (&pci_indirect));
32255+ "S" (&pci_indirect),
32256+ "r" (__PCIBIOS_DS));
32257 break;
32258 case 2:
32259- __asm__("lcall *(%%esi); cld\n\t"
32260+ __asm__("movw %w6, %%ds\n\t"
32261+ "lcall *%%ss:(%%esi); cld\n\t"
32262+ "push %%ss\n\t"
32263+ "pop %%ds\n\t"
32264 "jc 1f\n\t"
32265 "xor %%ah, %%ah\n"
32266 "1:"
32267@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32268 "c" (value),
32269 "b" (bx),
32270 "D" ((long)reg),
32271- "S" (&pci_indirect));
32272+ "S" (&pci_indirect),
32273+ "r" (__PCIBIOS_DS));
32274 break;
32275 case 4:
32276- __asm__("lcall *(%%esi); cld\n\t"
32277+ __asm__("movw %w6, %%ds\n\t"
32278+ "lcall *%%ss:(%%esi); cld\n\t"
32279+ "push %%ss\n\t"
32280+ "pop %%ds\n\t"
32281 "jc 1f\n\t"
32282 "xor %%ah, %%ah\n"
32283 "1:"
32284@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32285 "c" (value),
32286 "b" (bx),
32287 "D" ((long)reg),
32288- "S" (&pci_indirect));
32289+ "S" (&pci_indirect),
32290+ "r" (__PCIBIOS_DS));
32291 break;
32292 }
32293
32294@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32295
32296 DBG("PCI: Fetching IRQ routing table... ");
32297 __asm__("push %%es\n\t"
32298+ "movw %w8, %%ds\n\t"
32299 "push %%ds\n\t"
32300 "pop %%es\n\t"
32301- "lcall *(%%esi); cld\n\t"
32302+ "lcall *%%ss:(%%esi); cld\n\t"
32303 "pop %%es\n\t"
32304+ "push %%ss\n\t"
32305+ "pop %%ds\n"
32306 "jc 1f\n\t"
32307 "xor %%ah, %%ah\n"
32308 "1:"
32309@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32310 "1" (0),
32311 "D" ((long) &opt),
32312 "S" (&pci_indirect),
32313- "m" (opt)
32314+ "m" (opt),
32315+ "r" (__PCIBIOS_DS)
32316 : "memory");
32317 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
32318 if (ret & 0xff00)
32319@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
32320 {
32321 int ret;
32322
32323- __asm__("lcall *(%%esi); cld\n\t"
32324+ __asm__("movw %w5, %%ds\n\t"
32325+ "lcall *%%ss:(%%esi); cld\n\t"
32326+ "push %%ss\n\t"
32327+ "pop %%ds\n"
32328 "jc 1f\n\t"
32329 "xor %%ah, %%ah\n"
32330 "1:"
32331@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
32332 : "0" (PCIBIOS_SET_PCI_HW_INT),
32333 "b" ((dev->bus->number << 8) | dev->devfn),
32334 "c" ((irq << 8) | (pin + 10)),
32335- "S" (&pci_indirect));
32336+ "S" (&pci_indirect),
32337+ "r" (__PCIBIOS_DS));
32338 return !(ret & 0xff00);
32339 }
32340 EXPORT_SYMBOL(pcibios_set_irq_routing);
32341diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
32342index 40e4469..d915bf9 100644
32343--- a/arch/x86/platform/efi/efi_32.c
32344+++ b/arch/x86/platform/efi/efi_32.c
32345@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
32346 {
32347 struct desc_ptr gdt_descr;
32348
32349+#ifdef CONFIG_PAX_KERNEXEC
32350+ struct desc_struct d;
32351+#endif
32352+
32353 local_irq_save(efi_rt_eflags);
32354
32355 load_cr3(initial_page_table);
32356 __flush_tlb_all();
32357
32358+#ifdef CONFIG_PAX_KERNEXEC
32359+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
32360+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
32361+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
32362+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
32363+#endif
32364+
32365 gdt_descr.address = __pa(get_cpu_gdt_table(0));
32366 gdt_descr.size = GDT_SIZE - 1;
32367 load_gdt(&gdt_descr);
32368@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
32369 {
32370 struct desc_ptr gdt_descr;
32371
32372+#ifdef CONFIG_PAX_KERNEXEC
32373+ struct desc_struct d;
32374+
32375+ memset(&d, 0, sizeof d);
32376+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
32377+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
32378+#endif
32379+
32380 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
32381 gdt_descr.size = GDT_SIZE - 1;
32382 load_gdt(&gdt_descr);
32383
32384+#ifdef CONFIG_PAX_PER_CPU_PGD
32385+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
32386+#else
32387 load_cr3(swapper_pg_dir);
32388+#endif
32389+
32390 __flush_tlb_all();
32391
32392 local_irq_restore(efi_rt_eflags);
32393diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
32394index 39a0e7f1..872396e 100644
32395--- a/arch/x86/platform/efi/efi_64.c
32396+++ b/arch/x86/platform/efi/efi_64.c
32397@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
32398 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
32399 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
32400 }
32401+
32402+#ifdef CONFIG_PAX_PER_CPU_PGD
32403+ load_cr3(swapper_pg_dir);
32404+#endif
32405+
32406 __flush_tlb_all();
32407 }
32408
32409@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
32410 for (pgd = 0; pgd < n_pgds; pgd++)
32411 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
32412 kfree(save_pgd);
32413+
32414+#ifdef CONFIG_PAX_PER_CPU_PGD
32415+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
32416+#endif
32417+
32418 __flush_tlb_all();
32419 local_irq_restore(efi_flags);
32420 early_code_mapping_set_exec(0);
32421diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
32422index fbe66e6..eae5e38 100644
32423--- a/arch/x86/platform/efi/efi_stub_32.S
32424+++ b/arch/x86/platform/efi/efi_stub_32.S
32425@@ -6,7 +6,9 @@
32426 */
32427
32428 #include <linux/linkage.h>
32429+#include <linux/init.h>
32430 #include <asm/page_types.h>
32431+#include <asm/segment.h>
32432
32433 /*
32434 * efi_call_phys(void *, ...) is a function with variable parameters.
32435@@ -20,7 +22,7 @@
32436 * service functions will comply with gcc calling convention, too.
32437 */
32438
32439-.text
32440+__INIT
32441 ENTRY(efi_call_phys)
32442 /*
32443 * 0. The function can only be called in Linux kernel. So CS has been
32444@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
32445 * The mapping of lower virtual memory has been created in prelog and
32446 * epilog.
32447 */
32448- movl $1f, %edx
32449- subl $__PAGE_OFFSET, %edx
32450- jmp *%edx
32451+#ifdef CONFIG_PAX_KERNEXEC
32452+ movl $(__KERNEXEC_EFI_DS), %edx
32453+ mov %edx, %ds
32454+ mov %edx, %es
32455+ mov %edx, %ss
32456+ addl $2f,(1f)
32457+ ljmp *(1f)
32458+
32459+__INITDATA
32460+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
32461+.previous
32462+
32463+2:
32464+ subl $2b,(1b)
32465+#else
32466+ jmp 1f-__PAGE_OFFSET
32467 1:
32468+#endif
32469
32470 /*
32471 * 2. Now on the top of stack is the return
32472@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
32473 * parameter 2, ..., param n. To make things easy, we save the return
32474 * address of efi_call_phys in a global variable.
32475 */
32476- popl %edx
32477- movl %edx, saved_return_addr
32478- /* get the function pointer into ECX*/
32479- popl %ecx
32480- movl %ecx, efi_rt_function_ptr
32481- movl $2f, %edx
32482- subl $__PAGE_OFFSET, %edx
32483- pushl %edx
32484+ popl (saved_return_addr)
32485+ popl (efi_rt_function_ptr)
32486
32487 /*
32488 * 3. Clear PG bit in %CR0.
32489@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
32490 /*
32491 * 5. Call the physical function.
32492 */
32493- jmp *%ecx
32494+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
32495
32496-2:
32497 /*
32498 * 6. After EFI runtime service returns, control will return to
32499 * following instruction. We'd better readjust stack pointer first.
32500@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
32501 movl %cr0, %edx
32502 orl $0x80000000, %edx
32503 movl %edx, %cr0
32504- jmp 1f
32505-1:
32506+
32507 /*
32508 * 8. Now restore the virtual mode from flat mode by
32509 * adding EIP with PAGE_OFFSET.
32510 */
32511- movl $1f, %edx
32512- jmp *%edx
32513+#ifdef CONFIG_PAX_KERNEXEC
32514+ movl $(__KERNEL_DS), %edx
32515+ mov %edx, %ds
32516+ mov %edx, %es
32517+ mov %edx, %ss
32518+ ljmp $(__KERNEL_CS),$1f
32519+#else
32520+ jmp 1f+__PAGE_OFFSET
32521+#endif
32522 1:
32523
32524 /*
32525 * 9. Balance the stack. And because EAX contain the return value,
32526 * we'd better not clobber it.
32527 */
32528- leal efi_rt_function_ptr, %edx
32529- movl (%edx), %ecx
32530- pushl %ecx
32531+ pushl (efi_rt_function_ptr)
32532
32533 /*
32534- * 10. Push the saved return address onto the stack and return.
32535+ * 10. Return to the saved return address.
32536 */
32537- leal saved_return_addr, %edx
32538- movl (%edx), %ecx
32539- pushl %ecx
32540- ret
32541+ jmpl *(saved_return_addr)
32542 ENDPROC(efi_call_phys)
32543 .previous
32544
32545-.data
32546+__INITDATA
32547 saved_return_addr:
32548 .long 0
32549 efi_rt_function_ptr:
32550diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
32551index 4c07cca..2c8427d 100644
32552--- a/arch/x86/platform/efi/efi_stub_64.S
32553+++ b/arch/x86/platform/efi/efi_stub_64.S
32554@@ -7,6 +7,7 @@
32555 */
32556
32557 #include <linux/linkage.h>
32558+#include <asm/alternative-asm.h>
32559
32560 #define SAVE_XMM \
32561 mov %rsp, %rax; \
32562@@ -40,6 +41,7 @@ ENTRY(efi_call0)
32563 call *%rdi
32564 addq $32, %rsp
32565 RESTORE_XMM
32566+ pax_force_retaddr 0, 1
32567 ret
32568 ENDPROC(efi_call0)
32569
32570@@ -50,6 +52,7 @@ ENTRY(efi_call1)
32571 call *%rdi
32572 addq $32, %rsp
32573 RESTORE_XMM
32574+ pax_force_retaddr 0, 1
32575 ret
32576 ENDPROC(efi_call1)
32577
32578@@ -60,6 +63,7 @@ ENTRY(efi_call2)
32579 call *%rdi
32580 addq $32, %rsp
32581 RESTORE_XMM
32582+ pax_force_retaddr 0, 1
32583 ret
32584 ENDPROC(efi_call2)
32585
32586@@ -71,6 +75,7 @@ ENTRY(efi_call3)
32587 call *%rdi
32588 addq $32, %rsp
32589 RESTORE_XMM
32590+ pax_force_retaddr 0, 1
32591 ret
32592 ENDPROC(efi_call3)
32593
32594@@ -83,6 +88,7 @@ ENTRY(efi_call4)
32595 call *%rdi
32596 addq $32, %rsp
32597 RESTORE_XMM
32598+ pax_force_retaddr 0, 1
32599 ret
32600 ENDPROC(efi_call4)
32601
32602@@ -96,6 +102,7 @@ ENTRY(efi_call5)
32603 call *%rdi
32604 addq $48, %rsp
32605 RESTORE_XMM
32606+ pax_force_retaddr 0, 1
32607 ret
32608 ENDPROC(efi_call5)
32609
32610@@ -112,5 +119,6 @@ ENTRY(efi_call6)
32611 call *%rdi
32612 addq $48, %rsp
32613 RESTORE_XMM
32614+ pax_force_retaddr 0, 1
32615 ret
32616 ENDPROC(efi_call6)
32617diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
32618index a0a0a43..a48e233 100644
32619--- a/arch/x86/platform/mrst/mrst.c
32620+++ b/arch/x86/platform/mrst/mrst.c
32621@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
32622 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
32623 int sfi_mrtc_num;
32624
32625-static void mrst_power_off(void)
32626+static __noreturn void mrst_power_off(void)
32627 {
32628+ BUG();
32629 }
32630
32631-static void mrst_reboot(void)
32632+static __noreturn void mrst_reboot(void)
32633 {
32634 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
32635+ BUG();
32636 }
32637
32638 /* parse all the mtimer info to a static mtimer array */
32639diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
32640index d6ee929..3637cb5 100644
32641--- a/arch/x86/platform/olpc/olpc_dt.c
32642+++ b/arch/x86/platform/olpc/olpc_dt.c
32643@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
32644 return res;
32645 }
32646
32647-static struct of_pdt_ops prom_olpc_ops __initdata = {
32648+static struct of_pdt_ops prom_olpc_ops __initconst = {
32649 .nextprop = olpc_dt_nextprop,
32650 .getproplen = olpc_dt_getproplen,
32651 .getproperty = olpc_dt_getproperty,
32652diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
32653index 1cf5b30..fd45732 100644
32654--- a/arch/x86/power/cpu.c
32655+++ b/arch/x86/power/cpu.c
32656@@ -137,11 +137,8 @@ static void do_fpu_end(void)
32657 static void fix_processor_context(void)
32658 {
32659 int cpu = smp_processor_id();
32660- struct tss_struct *t = &per_cpu(init_tss, cpu);
32661-#ifdef CONFIG_X86_64
32662- struct desc_struct *desc = get_cpu_gdt_table(cpu);
32663- tss_desc tss;
32664-#endif
32665+ struct tss_struct *t = init_tss + cpu;
32666+
32667 set_tss_desc(cpu, t); /*
32668 * This just modifies memory; should not be
32669 * necessary. But... This is necessary, because
32670@@ -150,10 +147,6 @@ static void fix_processor_context(void)
32671 */
32672
32673 #ifdef CONFIG_X86_64
32674- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
32675- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
32676- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
32677-
32678 syscall_init(); /* This sets MSR_*STAR and related */
32679 #endif
32680 load_TR_desc(); /* This does ltr */
32681diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
32682index a44f457..9140171 100644
32683--- a/arch/x86/realmode/init.c
32684+++ b/arch/x86/realmode/init.c
32685@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
32686 __va(real_mode_header->trampoline_header);
32687
32688 #ifdef CONFIG_X86_32
32689- trampoline_header->start = __pa_symbol(startup_32_smp);
32690+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
32691+
32692+#ifdef CONFIG_PAX_KERNEXEC
32693+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
32694+#endif
32695+
32696+ trampoline_header->boot_cs = __BOOT_CS;
32697 trampoline_header->gdt_limit = __BOOT_DS + 7;
32698 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
32699 #else
32700@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
32701 *trampoline_cr4_features = read_cr4();
32702
32703 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
32704- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
32705+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
32706 trampoline_pgd[511] = init_level4_pgt[511].pgd;
32707 #endif
32708 }
32709diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
32710index 8869287..d577672 100644
32711--- a/arch/x86/realmode/rm/Makefile
32712+++ b/arch/x86/realmode/rm/Makefile
32713@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
32714 $(call cc-option, -fno-unit-at-a-time)) \
32715 $(call cc-option, -fno-stack-protector) \
32716 $(call cc-option, -mpreferred-stack-boundary=2)
32717+ifdef CONSTIFY_PLUGIN
32718+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
32719+endif
32720 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
32721 GCOV_PROFILE := n
32722diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
32723index a28221d..93c40f1 100644
32724--- a/arch/x86/realmode/rm/header.S
32725+++ b/arch/x86/realmode/rm/header.S
32726@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
32727 #endif
32728 /* APM/BIOS reboot */
32729 .long pa_machine_real_restart_asm
32730-#ifdef CONFIG_X86_64
32731+#ifdef CONFIG_X86_32
32732+ .long __KERNEL_CS
32733+#else
32734 .long __KERNEL32_CS
32735 #endif
32736 END(real_mode_header)
32737diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
32738index c1b2791..f9e31c7 100644
32739--- a/arch/x86/realmode/rm/trampoline_32.S
32740+++ b/arch/x86/realmode/rm/trampoline_32.S
32741@@ -25,6 +25,12 @@
32742 #include <asm/page_types.h>
32743 #include "realmode.h"
32744
32745+#ifdef CONFIG_PAX_KERNEXEC
32746+#define ta(X) (X)
32747+#else
32748+#define ta(X) (pa_ ## X)
32749+#endif
32750+
32751 .text
32752 .code16
32753
32754@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
32755
32756 cli # We should be safe anyway
32757
32758- movl tr_start, %eax # where we need to go
32759-
32760 movl $0xA5A5A5A5, trampoline_status
32761 # write marker for master knows we're running
32762
32763@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
32764 movw $1, %dx # protected mode (PE) bit
32765 lmsw %dx # into protected mode
32766
32767- ljmpl $__BOOT_CS, $pa_startup_32
32768+ ljmpl *(trampoline_header)
32769
32770 .section ".text32","ax"
32771 .code32
32772@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
32773 .balign 8
32774 GLOBAL(trampoline_header)
32775 tr_start: .space 4
32776- tr_gdt_pad: .space 2
32777+ tr_boot_cs: .space 2
32778 tr_gdt: .space 6
32779 END(trampoline_header)
32780
32781diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
32782index bb360dc..d0fd8f8 100644
32783--- a/arch/x86/realmode/rm/trampoline_64.S
32784+++ b/arch/x86/realmode/rm/trampoline_64.S
32785@@ -94,6 +94,7 @@ ENTRY(startup_32)
32786 movl %edx, %gs
32787
32788 movl pa_tr_cr4, %eax
32789+ andl $~X86_CR4_PCIDE, %eax
32790 movl %eax, %cr4 # Enable PAE mode
32791
32792 # Setup trampoline 4 level pagetables
32793@@ -107,7 +108,7 @@ ENTRY(startup_32)
32794 wrmsr
32795
32796 # Enable paging and in turn activate Long Mode
32797- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
32798+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
32799 movl %eax, %cr0
32800
32801 /*
32802diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
32803index e812034..c747134 100644
32804--- a/arch/x86/tools/Makefile
32805+++ b/arch/x86/tools/Makefile
32806@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
32807
32808 $(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
32809
32810-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
32811+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
32812 hostprogs-y += relocs
32813 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
32814 relocs: $(obj)/relocs
32815diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
32816index f7bab68..b6d9886 100644
32817--- a/arch/x86/tools/relocs.c
32818+++ b/arch/x86/tools/relocs.c
32819@@ -1,5 +1,7 @@
32820 /* This is included from relocs_32/64.c */
32821
32822+#include "../../../include/generated/autoconf.h"
32823+
32824 #define ElfW(type) _ElfW(ELF_BITS, type)
32825 #define _ElfW(bits, type) __ElfW(bits, type)
32826 #define __ElfW(bits, type) Elf##bits##_##type
32827@@ -11,6 +13,7 @@
32828 #define Elf_Sym ElfW(Sym)
32829
32830 static Elf_Ehdr ehdr;
32831+static Elf_Phdr *phdr;
32832
32833 struct relocs {
32834 uint32_t *offset;
32835@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
32836 }
32837 }
32838
32839+static void read_phdrs(FILE *fp)
32840+{
32841+ unsigned int i;
32842+
32843+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
32844+ if (!phdr) {
32845+ die("Unable to allocate %d program headers\n",
32846+ ehdr.e_phnum);
32847+ }
32848+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
32849+ die("Seek to %d failed: %s\n",
32850+ ehdr.e_phoff, strerror(errno));
32851+ }
32852+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
32853+ die("Cannot read ELF program headers: %s\n",
32854+ strerror(errno));
32855+ }
32856+ for(i = 0; i < ehdr.e_phnum; i++) {
32857+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
32858+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
32859+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
32860+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
32861+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
32862+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
32863+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
32864+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
32865+ }
32866+
32867+}
32868+
32869 static void read_shdrs(FILE *fp)
32870 {
32871- int i;
32872+ unsigned int i;
32873 Elf_Shdr shdr;
32874
32875 secs = calloc(ehdr.e_shnum, sizeof(struct section));
32876@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
32877
32878 static void read_strtabs(FILE *fp)
32879 {
32880- int i;
32881+ unsigned int i;
32882 for (i = 0; i < ehdr.e_shnum; i++) {
32883 struct section *sec = &secs[i];
32884 if (sec->shdr.sh_type != SHT_STRTAB) {
32885@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
32886
32887 static void read_symtabs(FILE *fp)
32888 {
32889- int i,j;
32890+ unsigned int i,j;
32891 for (i = 0; i < ehdr.e_shnum; i++) {
32892 struct section *sec = &secs[i];
32893 if (sec->shdr.sh_type != SHT_SYMTAB) {
32894@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
32895 }
32896
32897
32898-static void read_relocs(FILE *fp)
32899+static void read_relocs(FILE *fp, int use_real_mode)
32900 {
32901- int i,j;
32902+ unsigned int i,j;
32903+ uint32_t base;
32904+
32905 for (i = 0; i < ehdr.e_shnum; i++) {
32906 struct section *sec = &secs[i];
32907 if (sec->shdr.sh_type != SHT_REL_TYPE) {
32908@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
32909 die("Cannot read symbol table: %s\n",
32910 strerror(errno));
32911 }
32912+ base = 0;
32913+
32914+#ifdef CONFIG_X86_32
32915+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
32916+ if (phdr[j].p_type != PT_LOAD )
32917+ continue;
32918+ 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)
32919+ continue;
32920+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
32921+ break;
32922+ }
32923+#endif
32924+
32925 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
32926 Elf_Rel *rel = &sec->reltab[j];
32927- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
32928+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
32929 rel->r_info = elf_xword_to_cpu(rel->r_info);
32930 #if (SHT_REL_TYPE == SHT_RELA)
32931 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
32932@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
32933
32934 static void print_absolute_symbols(void)
32935 {
32936- int i;
32937+ unsigned int i;
32938 const char *format;
32939
32940 if (ELF_BITS == 64)
32941@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
32942 for (i = 0; i < ehdr.e_shnum; i++) {
32943 struct section *sec = &secs[i];
32944 char *sym_strtab;
32945- int j;
32946+ unsigned int j;
32947
32948 if (sec->shdr.sh_type != SHT_SYMTAB) {
32949 continue;
32950@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
32951
32952 static void print_absolute_relocs(void)
32953 {
32954- int i, printed = 0;
32955+ unsigned int i, printed = 0;
32956 const char *format;
32957
32958 if (ELF_BITS == 64)
32959@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
32960 struct section *sec_applies, *sec_symtab;
32961 char *sym_strtab;
32962 Elf_Sym *sh_symtab;
32963- int j;
32964+ unsigned int j;
32965 if (sec->shdr.sh_type != SHT_REL_TYPE) {
32966 continue;
32967 }
32968@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
32969 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
32970 Elf_Sym *sym, const char *symname))
32971 {
32972- int i;
32973+ unsigned int i;
32974 /* Walk through the relocations */
32975 for (i = 0; i < ehdr.e_shnum; i++) {
32976 char *sym_strtab;
32977 Elf_Sym *sh_symtab;
32978 struct section *sec_applies, *sec_symtab;
32979- int j;
32980+ unsigned int j;
32981 struct section *sec = &secs[i];
32982
32983 if (sec->shdr.sh_type != SHT_REL_TYPE) {
32984@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
32985 {
32986 unsigned r_type = ELF32_R_TYPE(rel->r_info);
32987 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
32988+ char *sym_strtab = sec->link->link->strtab;
32989+
32990+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
32991+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
32992+ return 0;
32993+
32994+#ifdef CONFIG_PAX_KERNEXEC
32995+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
32996+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
32997+ return 0;
32998+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
32999+ return 0;
33000+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33001+ return 0;
33002+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33003+ return 0;
33004+#endif
33005
33006 switch (r_type) {
33007 case R_386_NONE:
33008@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33009
33010 static void emit_relocs(int as_text, int use_real_mode)
33011 {
33012- int i;
33013+ unsigned int i;
33014 int (*write_reloc)(uint32_t, FILE *) = write32;
33015 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33016 const char *symname);
33017@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33018 {
33019 regex_init(use_real_mode);
33020 read_ehdr(fp);
33021+ read_phdrs(fp);
33022 read_shdrs(fp);
33023 read_strtabs(fp);
33024 read_symtabs(fp);
33025- read_relocs(fp);
33026+ read_relocs(fp, use_real_mode);
33027 if (ELF_BITS == 64)
33028 percpu_init();
33029 if (show_absolute_syms) {
33030diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33031index 80ffa5b..a33bd15 100644
33032--- a/arch/x86/um/tls_32.c
33033+++ b/arch/x86/um/tls_32.c
33034@@ -260,7 +260,7 @@ out:
33035 if (unlikely(task == current &&
33036 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33037 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33038- "without flushed TLS.", current->pid);
33039+ "without flushed TLS.", task_pid_nr(current));
33040 }
33041
33042 return 0;
33043diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33044index fd14be1..e3c79c0 100644
33045--- a/arch/x86/vdso/Makefile
33046+++ b/arch/x86/vdso/Makefile
33047@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33048 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33049 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33050
33051-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33052+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33053 GCOV_PROFILE := n
33054
33055 #
33056diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33057index 0faad64..39ef157 100644
33058--- a/arch/x86/vdso/vdso32-setup.c
33059+++ b/arch/x86/vdso/vdso32-setup.c
33060@@ -25,6 +25,7 @@
33061 #include <asm/tlbflush.h>
33062 #include <asm/vdso.h>
33063 #include <asm/proto.h>
33064+#include <asm/mman.h>
33065
33066 enum {
33067 VDSO_DISABLED = 0,
33068@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33069 void enable_sep_cpu(void)
33070 {
33071 int cpu = get_cpu();
33072- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33073+ struct tss_struct *tss = init_tss + cpu;
33074
33075 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33076 put_cpu();
33077@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33078 gate_vma.vm_start = FIXADDR_USER_START;
33079 gate_vma.vm_end = FIXADDR_USER_END;
33080 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33081- gate_vma.vm_page_prot = __P101;
33082+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33083
33084 return 0;
33085 }
33086@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33087 if (compat)
33088 addr = VDSO_HIGH_BASE;
33089 else {
33090- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33091+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33092 if (IS_ERR_VALUE(addr)) {
33093 ret = addr;
33094 goto up_fail;
33095 }
33096 }
33097
33098- current->mm->context.vdso = (void *)addr;
33099+ current->mm->context.vdso = addr;
33100
33101 if (compat_uses_vma || !compat) {
33102 /*
33103@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33104 }
33105
33106 current_thread_info()->sysenter_return =
33107- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33108+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33109
33110 up_fail:
33111 if (ret)
33112- current->mm->context.vdso = NULL;
33113+ current->mm->context.vdso = 0;
33114
33115 up_write(&mm->mmap_sem);
33116
33117@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33118
33119 const char *arch_vma_name(struct vm_area_struct *vma)
33120 {
33121- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33122+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33123 return "[vdso]";
33124+
33125+#ifdef CONFIG_PAX_SEGMEXEC
33126+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33127+ return "[vdso]";
33128+#endif
33129+
33130 return NULL;
33131 }
33132
33133@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33134 * Check to see if the corresponding task was created in compat vdso
33135 * mode.
33136 */
33137- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33138+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33139 return &gate_vma;
33140 return NULL;
33141 }
33142diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33143index 431e875..cbb23f3 100644
33144--- a/arch/x86/vdso/vma.c
33145+++ b/arch/x86/vdso/vma.c
33146@@ -16,8 +16,6 @@
33147 #include <asm/vdso.h>
33148 #include <asm/page.h>
33149
33150-unsigned int __read_mostly vdso_enabled = 1;
33151-
33152 extern char vdso_start[], vdso_end[];
33153 extern unsigned short vdso_sync_cpuid;
33154
33155@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33156 * unaligned here as a result of stack start randomization.
33157 */
33158 addr = PAGE_ALIGN(addr);
33159- addr = align_vdso_addr(addr);
33160
33161 return addr;
33162 }
33163@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33164 unsigned size)
33165 {
33166 struct mm_struct *mm = current->mm;
33167- unsigned long addr;
33168+ unsigned long addr = 0;
33169 int ret;
33170
33171- if (!vdso_enabled)
33172- return 0;
33173-
33174 down_write(&mm->mmap_sem);
33175+
33176+#ifdef CONFIG_PAX_RANDMMAP
33177+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33178+#endif
33179+
33180 addr = vdso_addr(mm->start_stack, size);
33181+ addr = align_vdso_addr(addr);
33182 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33183 if (IS_ERR_VALUE(addr)) {
33184 ret = addr;
33185 goto up_fail;
33186 }
33187
33188- current->mm->context.vdso = (void *)addr;
33189+ mm->context.vdso = addr;
33190
33191 ret = install_special_mapping(mm, addr, size,
33192 VM_READ|VM_EXEC|
33193 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33194 pages);
33195- if (ret) {
33196- current->mm->context.vdso = NULL;
33197- goto up_fail;
33198- }
33199+ if (ret)
33200+ mm->context.vdso = 0;
33201
33202 up_fail:
33203 up_write(&mm->mmap_sem);
33204@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33205 vdsox32_size);
33206 }
33207 #endif
33208-
33209-static __init int vdso_setup(char *s)
33210-{
33211- vdso_enabled = simple_strtoul(s, NULL, 0);
33212- return 0;
33213-}
33214-__setup("vdso=", vdso_setup);
33215diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33216index a492be2..08678da 100644
33217--- a/arch/x86/xen/enlighten.c
33218+++ b/arch/x86/xen/enlighten.c
33219@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33220
33221 struct shared_info xen_dummy_shared_info;
33222
33223-void *xen_initial_gdt;
33224-
33225 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33226 __read_mostly int xen_have_vector_callback;
33227 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33228@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33229 {
33230 unsigned long va = dtr->address;
33231 unsigned int size = dtr->size + 1;
33232- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33233- unsigned long frames[pages];
33234+ unsigned long frames[65536 / PAGE_SIZE];
33235 int f;
33236
33237 /*
33238@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33239 {
33240 unsigned long va = dtr->address;
33241 unsigned int size = dtr->size + 1;
33242- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33243- unsigned long frames[pages];
33244+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33245 int f;
33246
33247 /*
33248@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33249 * 8-byte entries, or 16 4k pages..
33250 */
33251
33252- BUG_ON(size > 65536);
33253+ BUG_ON(size > GDT_SIZE);
33254 BUG_ON(va & ~PAGE_MASK);
33255
33256 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33257@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33258 return 0;
33259 }
33260
33261-static void set_xen_basic_apic_ops(void)
33262+static void __init set_xen_basic_apic_ops(void)
33263 {
33264 apic->read = xen_apic_read;
33265 apic->write = xen_apic_write;
33266@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
33267 #endif
33268 };
33269
33270-static void xen_reboot(int reason)
33271+static __noreturn void xen_reboot(int reason)
33272 {
33273 struct sched_shutdown r = { .reason = reason };
33274
33275- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
33276- BUG();
33277+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
33278+ BUG();
33279 }
33280
33281-static void xen_restart(char *msg)
33282+static __noreturn void xen_restart(char *msg)
33283 {
33284 xen_reboot(SHUTDOWN_reboot);
33285 }
33286
33287-static void xen_emergency_restart(void)
33288+static __noreturn void xen_emergency_restart(void)
33289 {
33290 xen_reboot(SHUTDOWN_reboot);
33291 }
33292
33293-static void xen_machine_halt(void)
33294+static __noreturn void xen_machine_halt(void)
33295 {
33296 xen_reboot(SHUTDOWN_poweroff);
33297 }
33298
33299-static void xen_machine_power_off(void)
33300+static __noreturn void xen_machine_power_off(void)
33301 {
33302 if (pm_power_off)
33303 pm_power_off();
33304@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
33305 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
33306
33307 /* Work out if we support NX */
33308- x86_configure_nx();
33309+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33310+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
33311+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
33312+ unsigned l, h;
33313+
33314+ __supported_pte_mask |= _PAGE_NX;
33315+ rdmsr(MSR_EFER, l, h);
33316+ l |= EFER_NX;
33317+ wrmsr(MSR_EFER, l, h);
33318+ }
33319+#endif
33320
33321 xen_setup_features();
33322
33323@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
33324
33325 machine_ops = xen_machine_ops;
33326
33327- /*
33328- * The only reliable way to retain the initial address of the
33329- * percpu gdt_page is to remember it here, so we can go and
33330- * mark it RW later, when the initial percpu area is freed.
33331- */
33332- xen_initial_gdt = &per_cpu(gdt_page, 0);
33333-
33334 xen_smp_init();
33335
33336 #ifdef CONFIG_ACPI_NUMA
33337@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
33338 return NOTIFY_OK;
33339 }
33340
33341-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
33342+static struct notifier_block xen_hvm_cpu_notifier = {
33343 .notifier_call = xen_hvm_cpu_notify,
33344 };
33345
33346diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
33347index fdc3ba2..3daee39 100644
33348--- a/arch/x86/xen/mmu.c
33349+++ b/arch/x86/xen/mmu.c
33350@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
33351 /* L3_k[510] -> level2_kernel_pgt
33352 * L3_i[511] -> level2_fixmap_pgt */
33353 convert_pfn_mfn(level3_kernel_pgt);
33354+ convert_pfn_mfn(level3_vmalloc_start_pgt);
33355+ convert_pfn_mfn(level3_vmalloc_end_pgt);
33356+ convert_pfn_mfn(level3_vmemmap_pgt);
33357
33358 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
33359 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
33360@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
33361 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
33362 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
33363 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
33364+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
33365+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
33366+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
33367 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
33368 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
33369+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
33370 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
33371 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
33372
33373@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
33374 pv_mmu_ops.set_pud = xen_set_pud;
33375 #if PAGETABLE_LEVELS == 4
33376 pv_mmu_ops.set_pgd = xen_set_pgd;
33377+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
33378 #endif
33379
33380 /* This will work as long as patching hasn't happened yet
33381@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
33382 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
33383 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
33384 .set_pgd = xen_set_pgd_hyper,
33385+ .set_pgd_batched = xen_set_pgd_hyper,
33386
33387 .alloc_pud = xen_alloc_pmd_init,
33388 .release_pud = xen_release_pmd_init,
33389diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
33390index d99cae8..18401e1 100644
33391--- a/arch/x86/xen/smp.c
33392+++ b/arch/x86/xen/smp.c
33393@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
33394 {
33395 BUG_ON(smp_processor_id() != 0);
33396 native_smp_prepare_boot_cpu();
33397-
33398- /* We've switched to the "real" per-cpu gdt, so make sure the
33399- old memory can be recycled */
33400- make_lowmem_page_readwrite(xen_initial_gdt);
33401-
33402 xen_filter_cpu_maps();
33403 xen_setup_vcpu_info_placement();
33404 }
33405@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
33406 ctxt->user_regs.ss = __KERNEL_DS;
33407 #ifdef CONFIG_X86_32
33408 ctxt->user_regs.fs = __KERNEL_PERCPU;
33409- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
33410+ savesegment(gs, ctxt->user_regs.gs);
33411 #else
33412 ctxt->gs_base_kernel = per_cpu_offset(cpu);
33413 #endif
33414@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
33415
33416 {
33417 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
33418- ctxt->user_regs.ds = __USER_DS;
33419- ctxt->user_regs.es = __USER_DS;
33420+ ctxt->user_regs.ds = __KERNEL_DS;
33421+ ctxt->user_regs.es = __KERNEL_DS;
33422
33423 xen_copy_trap_info(ctxt->trap_ctxt);
33424
33425@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
33426 int rc;
33427
33428 per_cpu(current_task, cpu) = idle;
33429+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
33430 #ifdef CONFIG_X86_32
33431 irq_ctx_init(cpu);
33432 #else
33433 clear_tsk_thread_flag(idle, TIF_FORK);
33434- per_cpu(kernel_stack, cpu) =
33435- (unsigned long)task_stack_page(idle) -
33436- KERNEL_STACK_OFFSET + THREAD_SIZE;
33437+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
33438 #endif
33439 xen_setup_runstate_info(cpu);
33440 xen_setup_timer(cpu);
33441@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
33442
33443 void __init xen_smp_init(void)
33444 {
33445- smp_ops = xen_smp_ops;
33446+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
33447 xen_fill_possible_map();
33448 xen_init_spinlocks();
33449 }
33450diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
33451index 33ca6e4..0ded929 100644
33452--- a/arch/x86/xen/xen-asm_32.S
33453+++ b/arch/x86/xen/xen-asm_32.S
33454@@ -84,14 +84,14 @@ ENTRY(xen_iret)
33455 ESP_OFFSET=4 # bytes pushed onto stack
33456
33457 /*
33458- * Store vcpu_info pointer for easy access. Do it this way to
33459- * avoid having to reload %fs
33460+ * Store vcpu_info pointer for easy access.
33461 */
33462 #ifdef CONFIG_SMP
33463- GET_THREAD_INFO(%eax)
33464- movl %ss:TI_cpu(%eax), %eax
33465- movl %ss:__per_cpu_offset(,%eax,4), %eax
33466- mov %ss:xen_vcpu(%eax), %eax
33467+ push %fs
33468+ mov $(__KERNEL_PERCPU), %eax
33469+ mov %eax, %fs
33470+ mov PER_CPU_VAR(xen_vcpu), %eax
33471+ pop %fs
33472 #else
33473 movl %ss:xen_vcpu, %eax
33474 #endif
33475diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
33476index 7faed58..ba4427c 100644
33477--- a/arch/x86/xen/xen-head.S
33478+++ b/arch/x86/xen/xen-head.S
33479@@ -19,6 +19,17 @@ ENTRY(startup_xen)
33480 #ifdef CONFIG_X86_32
33481 mov %esi,xen_start_info
33482 mov $init_thread_union+THREAD_SIZE,%esp
33483+#ifdef CONFIG_SMP
33484+ movl $cpu_gdt_table,%edi
33485+ movl $__per_cpu_load,%eax
33486+ movw %ax,__KERNEL_PERCPU + 2(%edi)
33487+ rorl $16,%eax
33488+ movb %al,__KERNEL_PERCPU + 4(%edi)
33489+ movb %ah,__KERNEL_PERCPU + 7(%edi)
33490+ movl $__per_cpu_end - 1,%eax
33491+ subl $__per_cpu_start,%eax
33492+ movw %ax,__KERNEL_PERCPU + 0(%edi)
33493+#endif
33494 #else
33495 mov %rsi,xen_start_info
33496 mov $init_thread_union+THREAD_SIZE,%rsp
33497diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
33498index a95b417..b6dbd0b 100644
33499--- a/arch/x86/xen/xen-ops.h
33500+++ b/arch/x86/xen/xen-ops.h
33501@@ -10,8 +10,6 @@
33502 extern const char xen_hypervisor_callback[];
33503 extern const char xen_failsafe_callback[];
33504
33505-extern void *xen_initial_gdt;
33506-
33507 struct trap_info;
33508 void xen_copy_trap_info(struct trap_info *traps);
33509
33510diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
33511index 525bd3d..ef888b1 100644
33512--- a/arch/xtensa/variants/dc232b/include/variant/core.h
33513+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
33514@@ -119,9 +119,9 @@
33515 ----------------------------------------------------------------------*/
33516
33517 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
33518-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
33519 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
33520 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
33521+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
33522
33523 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
33524 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
33525diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
33526index 2f33760..835e50a 100644
33527--- a/arch/xtensa/variants/fsf/include/variant/core.h
33528+++ b/arch/xtensa/variants/fsf/include/variant/core.h
33529@@ -11,6 +11,7 @@
33530 #ifndef _XTENSA_CORE_H
33531 #define _XTENSA_CORE_H
33532
33533+#include <linux/const.h>
33534
33535 /****************************************************************************
33536 Parameters Useful for Any Code, USER or PRIVILEGED
33537@@ -112,9 +113,9 @@
33538 ----------------------------------------------------------------------*/
33539
33540 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
33541-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
33542 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
33543 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
33544+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
33545
33546 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
33547 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
33548diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
33549index af00795..2bb8105 100644
33550--- a/arch/xtensa/variants/s6000/include/variant/core.h
33551+++ b/arch/xtensa/variants/s6000/include/variant/core.h
33552@@ -11,6 +11,7 @@
33553 #ifndef _XTENSA_CORE_CONFIGURATION_H
33554 #define _XTENSA_CORE_CONFIGURATION_H
33555
33556+#include <linux/const.h>
33557
33558 /****************************************************************************
33559 Parameters Useful for Any Code, USER or PRIVILEGED
33560@@ -118,9 +119,9 @@
33561 ----------------------------------------------------------------------*/
33562
33563 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
33564-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
33565 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
33566 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
33567+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
33568
33569 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
33570 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
33571diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
33572index 58916af..eb9dbcf6 100644
33573--- a/block/blk-iopoll.c
33574+++ b/block/blk-iopoll.c
33575@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
33576 }
33577 EXPORT_SYMBOL(blk_iopoll_complete);
33578
33579-static void blk_iopoll_softirq(struct softirq_action *h)
33580+static void blk_iopoll_softirq(void)
33581 {
33582 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
33583 int rearm = 0, budget = blk_iopoll_budget;
33584@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
33585 return NOTIFY_OK;
33586 }
33587
33588-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
33589+static struct notifier_block blk_iopoll_cpu_notifier = {
33590 .notifier_call = blk_iopoll_cpu_notify,
33591 };
33592
33593diff --git a/block/blk-map.c b/block/blk-map.c
33594index 623e1cd..ca1e109 100644
33595--- a/block/blk-map.c
33596+++ b/block/blk-map.c
33597@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
33598 if (!len || !kbuf)
33599 return -EINVAL;
33600
33601- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
33602+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
33603 if (do_copy)
33604 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
33605 else
33606diff --git a/block/blk-softirq.c b/block/blk-softirq.c
33607index 467c8de..f3628c5 100644
33608--- a/block/blk-softirq.c
33609+++ b/block/blk-softirq.c
33610@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
33611 * Softirq action handler - move entries to local list and loop over them
33612 * while passing them to the queue registered handler.
33613 */
33614-static void blk_done_softirq(struct softirq_action *h)
33615+static void blk_done_softirq(void)
33616 {
33617 struct list_head *cpu_list, local_list;
33618
33619@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
33620 return NOTIFY_OK;
33621 }
33622
33623-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
33624+static struct notifier_block blk_cpu_notifier = {
33625 .notifier_call = blk_cpu_notify,
33626 };
33627
33628diff --git a/block/bsg.c b/block/bsg.c
33629index 420a5a9..23834aa 100644
33630--- a/block/bsg.c
33631+++ b/block/bsg.c
33632@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
33633 struct sg_io_v4 *hdr, struct bsg_device *bd,
33634 fmode_t has_write_perm)
33635 {
33636+ unsigned char tmpcmd[sizeof(rq->__cmd)];
33637+ unsigned char *cmdptr;
33638+
33639 if (hdr->request_len > BLK_MAX_CDB) {
33640 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
33641 if (!rq->cmd)
33642 return -ENOMEM;
33643- }
33644+ cmdptr = rq->cmd;
33645+ } else
33646+ cmdptr = tmpcmd;
33647
33648- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
33649+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
33650 hdr->request_len))
33651 return -EFAULT;
33652
33653+ if (cmdptr != rq->cmd)
33654+ memcpy(rq->cmd, cmdptr, hdr->request_len);
33655+
33656 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
33657 if (blk_verify_command(rq->cmd, has_write_perm))
33658 return -EPERM;
33659diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
33660index 7c668c8..db3521c 100644
33661--- a/block/compat_ioctl.c
33662+++ b/block/compat_ioctl.c
33663@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
33664 err |= __get_user(f->spec1, &uf->spec1);
33665 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
33666 err |= __get_user(name, &uf->name);
33667- f->name = compat_ptr(name);
33668+ f->name = (void __force_kernel *)compat_ptr(name);
33669 if (err) {
33670 err = -EFAULT;
33671 goto out;
33672diff --git a/block/genhd.c b/block/genhd.c
33673index cdeb527..10aa34db 100644
33674--- a/block/genhd.c
33675+++ b/block/genhd.c
33676@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
33677
33678 /*
33679 * Register device numbers dev..(dev+range-1)
33680- * range must be nonzero
33681+ * Noop if @range is zero.
33682 * The hash chain is sorted on range, so that subranges can override.
33683 */
33684 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
33685 struct kobject *(*probe)(dev_t, int *, void *),
33686 int (*lock)(dev_t, void *), void *data)
33687 {
33688- kobj_map(bdev_map, devt, range, module, probe, lock, data);
33689+ if (range)
33690+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
33691 }
33692
33693 EXPORT_SYMBOL(blk_register_region);
33694
33695+/* undo blk_register_region(), noop if @range is zero */
33696 void blk_unregister_region(dev_t devt, unsigned long range)
33697 {
33698- kobj_unmap(bdev_map, devt, range);
33699+ if (range)
33700+ kobj_unmap(bdev_map, devt, range);
33701 }
33702
33703 EXPORT_SYMBOL(blk_unregister_region);
33704diff --git a/block/partitions/efi.c b/block/partitions/efi.c
33705index c85fc89..51e690b 100644
33706--- a/block/partitions/efi.c
33707+++ b/block/partitions/efi.c
33708@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
33709 if (!gpt)
33710 return NULL;
33711
33712+ if (!le32_to_cpu(gpt->num_partition_entries))
33713+ return NULL;
33714+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
33715+ if (!pte)
33716+ return NULL;
33717+
33718 count = le32_to_cpu(gpt->num_partition_entries) *
33719 le32_to_cpu(gpt->sizeof_partition_entry);
33720- if (!count)
33721- return NULL;
33722- pte = kmalloc(count, GFP_KERNEL);
33723- if (!pte)
33724- return NULL;
33725-
33726 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
33727 (u8 *) pte,
33728 count) < count) {
33729diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
33730index a5ffcc9..3cedc9c 100644
33731--- a/block/scsi_ioctl.c
33732+++ b/block/scsi_ioctl.c
33733@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
33734 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
33735 struct sg_io_hdr *hdr, fmode_t mode)
33736 {
33737- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
33738+ unsigned char tmpcmd[sizeof(rq->__cmd)];
33739+ unsigned char *cmdptr;
33740+
33741+ if (rq->cmd != rq->__cmd)
33742+ cmdptr = rq->cmd;
33743+ else
33744+ cmdptr = tmpcmd;
33745+
33746+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
33747 return -EFAULT;
33748+
33749+ if (cmdptr != rq->cmd)
33750+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
33751+
33752 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
33753 return -EPERM;
33754
33755@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
33756 int err;
33757 unsigned int in_len, out_len, bytes, opcode, cmdlen;
33758 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
33759+ unsigned char tmpcmd[sizeof(rq->__cmd)];
33760+ unsigned char *cmdptr;
33761
33762 if (!sic)
33763 return -EINVAL;
33764@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
33765 */
33766 err = -EFAULT;
33767 rq->cmd_len = cmdlen;
33768- if (copy_from_user(rq->cmd, sic->data, cmdlen))
33769+
33770+ if (rq->cmd != rq->__cmd)
33771+ cmdptr = rq->cmd;
33772+ else
33773+ cmdptr = tmpcmd;
33774+
33775+ if (copy_from_user(cmdptr, sic->data, cmdlen))
33776 goto error;
33777
33778+ if (rq->cmd != cmdptr)
33779+ memcpy(rq->cmd, cmdptr, cmdlen);
33780+
33781 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
33782 goto error;
33783
33784diff --git a/crypto/cryptd.c b/crypto/cryptd.c
33785index 7bdd61b..afec999 100644
33786--- a/crypto/cryptd.c
33787+++ b/crypto/cryptd.c
33788@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
33789
33790 struct cryptd_blkcipher_request_ctx {
33791 crypto_completion_t complete;
33792-};
33793+} __no_const;
33794
33795 struct cryptd_hash_ctx {
33796 struct crypto_shash *child;
33797@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
33798
33799 struct cryptd_aead_request_ctx {
33800 crypto_completion_t complete;
33801-};
33802+} __no_const;
33803
33804 static void cryptd_queue_worker(struct work_struct *work);
33805
33806diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
33807index b2c99dc..476c9fb 100644
33808--- a/crypto/pcrypt.c
33809+++ b/crypto/pcrypt.c
33810@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
33811 int ret;
33812
33813 pinst->kobj.kset = pcrypt_kset;
33814- ret = kobject_add(&pinst->kobj, NULL, name);
33815+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
33816 if (!ret)
33817 kobject_uevent(&pinst->kobj, KOBJ_ADD);
33818
33819@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
33820
33821 get_online_cpus();
33822
33823- pcrypt->wq = alloc_workqueue(name,
33824- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
33825+ pcrypt->wq = alloc_workqueue("%s",
33826+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
33827 if (!pcrypt->wq)
33828 goto err;
33829
33830diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
33831index f220d64..d359ad6 100644
33832--- a/drivers/acpi/apei/apei-internal.h
33833+++ b/drivers/acpi/apei/apei-internal.h
33834@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
33835 struct apei_exec_ins_type {
33836 u32 flags;
33837 apei_exec_ins_func_t run;
33838-};
33839+} __do_const;
33840
33841 struct apei_exec_context {
33842 u32 ip;
33843diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
33844index 33dc6a0..4b24b47 100644
33845--- a/drivers/acpi/apei/cper.c
33846+++ b/drivers/acpi/apei/cper.c
33847@@ -39,12 +39,12 @@
33848 */
33849 u64 cper_next_record_id(void)
33850 {
33851- static atomic64_t seq;
33852+ static atomic64_unchecked_t seq;
33853
33854- if (!atomic64_read(&seq))
33855- atomic64_set(&seq, ((u64)get_seconds()) << 32);
33856+ if (!atomic64_read_unchecked(&seq))
33857+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
33858
33859- return atomic64_inc_return(&seq);
33860+ return atomic64_inc_return_unchecked(&seq);
33861 }
33862 EXPORT_SYMBOL_GPL(cper_next_record_id);
33863
33864diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
33865index be60399..778b33e8 100644
33866--- a/drivers/acpi/bgrt.c
33867+++ b/drivers/acpi/bgrt.c
33868@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
33869 return -ENODEV;
33870
33871 sysfs_bin_attr_init(&image_attr);
33872- image_attr.private = bgrt_image;
33873- image_attr.size = bgrt_image_size;
33874+ pax_open_kernel();
33875+ *(void **)&image_attr.private = bgrt_image;
33876+ *(size_t *)&image_attr.size = bgrt_image_size;
33877+ pax_close_kernel();
33878
33879 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
33880 if (!bgrt_kobj)
33881diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
33882index cb96296..b81293b 100644
33883--- a/drivers/acpi/blacklist.c
33884+++ b/drivers/acpi/blacklist.c
33885@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
33886 u32 is_critical_error;
33887 };
33888
33889-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
33890+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
33891
33892 /*
33893 * POLICY: If *anything* doesn't work, put it on the blacklist.
33894@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
33895 return 0;
33896 }
33897
33898-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
33899+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
33900 {
33901 .callback = dmi_disable_osi_vista,
33902 .ident = "Fujitsu Siemens",
33903diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
33904index 7586544..636a2f0 100644
33905--- a/drivers/acpi/ec_sys.c
33906+++ b/drivers/acpi/ec_sys.c
33907@@ -12,6 +12,7 @@
33908 #include <linux/acpi.h>
33909 #include <linux/debugfs.h>
33910 #include <linux/module.h>
33911+#include <linux/uaccess.h>
33912 #include "internal.h"
33913
33914 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
33915@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
33916 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
33917 */
33918 unsigned int size = EC_SPACE_SIZE;
33919- u8 *data = (u8 *) buf;
33920+ u8 data;
33921 loff_t init_off = *off;
33922 int err = 0;
33923
33924@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
33925 size = count;
33926
33927 while (size) {
33928- err = ec_read(*off, &data[*off - init_off]);
33929+ err = ec_read(*off, &data);
33930 if (err)
33931 return err;
33932+ if (put_user(data, &buf[*off - init_off]))
33933+ return -EFAULT;
33934 *off += 1;
33935 size--;
33936 }
33937@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
33938
33939 unsigned int size = count;
33940 loff_t init_off = *off;
33941- u8 *data = (u8 *) buf;
33942 int err = 0;
33943
33944 if (*off >= EC_SPACE_SIZE)
33945@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
33946 }
33947
33948 while (size) {
33949- u8 byte_write = data[*off - init_off];
33950+ u8 byte_write;
33951+ if (get_user(byte_write, &buf[*off - init_off]))
33952+ return -EFAULT;
33953 err = ec_write(*off, byte_write);
33954 if (err)
33955 return err;
33956diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
33957index eb133c7..f571552 100644
33958--- a/drivers/acpi/processor_idle.c
33959+++ b/drivers/acpi/processor_idle.c
33960@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
33961 {
33962 int i, count = CPUIDLE_DRIVER_STATE_START;
33963 struct acpi_processor_cx *cx;
33964- struct cpuidle_state *state;
33965+ cpuidle_state_no_const *state;
33966 struct cpuidle_driver *drv = &acpi_idle_driver;
33967
33968 if (!pr->flags.power_setup_done)
33969diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
33970index fcae5fa..e9f71ea 100644
33971--- a/drivers/acpi/sysfs.c
33972+++ b/drivers/acpi/sysfs.c
33973@@ -423,11 +423,11 @@ static u32 num_counters;
33974 static struct attribute **all_attrs;
33975 static u32 acpi_gpe_count;
33976
33977-static struct attribute_group interrupt_stats_attr_group = {
33978+static attribute_group_no_const interrupt_stats_attr_group = {
33979 .name = "interrupts",
33980 };
33981
33982-static struct kobj_attribute *counter_attrs;
33983+static kobj_attribute_no_const *counter_attrs;
33984
33985 static void delete_gpe_attr_array(void)
33986 {
33987diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
33988index 7b9bdd8..37638ca 100644
33989--- a/drivers/ata/libahci.c
33990+++ b/drivers/ata/libahci.c
33991@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
33992 }
33993 EXPORT_SYMBOL_GPL(ahci_kick_engine);
33994
33995-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
33996+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
33997 struct ata_taskfile *tf, int is_cmd, u16 flags,
33998 unsigned long timeout_msec)
33999 {
34000diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34001index adf002a..39bb8f9 100644
34002--- a/drivers/ata/libata-core.c
34003+++ b/drivers/ata/libata-core.c
34004@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34005 struct ata_port *ap;
34006 unsigned int tag;
34007
34008- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34009+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34010 ap = qc->ap;
34011
34012 qc->flags = 0;
34013@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34014 struct ata_port *ap;
34015 struct ata_link *link;
34016
34017- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34018+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34019 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34020 ap = qc->ap;
34021 link = qc->dev->link;
34022@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34023 return;
34024
34025 spin_lock(&lock);
34026+ pax_open_kernel();
34027
34028 for (cur = ops->inherits; cur; cur = cur->inherits) {
34029 void **inherit = (void **)cur;
34030@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34031 if (IS_ERR(*pp))
34032 *pp = NULL;
34033
34034- ops->inherits = NULL;
34035+ *(struct ata_port_operations **)&ops->inherits = NULL;
34036
34037+ pax_close_kernel();
34038 spin_unlock(&lock);
34039 }
34040
34041diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34042index 7638121..357a965 100644
34043--- a/drivers/ata/pata_arasan_cf.c
34044+++ b/drivers/ata/pata_arasan_cf.c
34045@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34046 /* Handle platform specific quirks */
34047 if (quirk) {
34048 if (quirk & CF_BROKEN_PIO) {
34049- ap->ops->set_piomode = NULL;
34050+ pax_open_kernel();
34051+ *(void **)&ap->ops->set_piomode = NULL;
34052+ pax_close_kernel();
34053 ap->pio_mask = 0;
34054 }
34055 if (quirk & CF_BROKEN_MWDMA)
34056diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34057index f9b983a..887b9d8 100644
34058--- a/drivers/atm/adummy.c
34059+++ b/drivers/atm/adummy.c
34060@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34061 vcc->pop(vcc, skb);
34062 else
34063 dev_kfree_skb_any(skb);
34064- atomic_inc(&vcc->stats->tx);
34065+ atomic_inc_unchecked(&vcc->stats->tx);
34066
34067 return 0;
34068 }
34069diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34070index 77a7480d..05cde58 100644
34071--- a/drivers/atm/ambassador.c
34072+++ b/drivers/atm/ambassador.c
34073@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34074 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34075
34076 // VC layer stats
34077- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34078+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34079
34080 // free the descriptor
34081 kfree (tx_descr);
34082@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34083 dump_skb ("<<<", vc, skb);
34084
34085 // VC layer stats
34086- atomic_inc(&atm_vcc->stats->rx);
34087+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34088 __net_timestamp(skb);
34089 // end of our responsibility
34090 atm_vcc->push (atm_vcc, skb);
34091@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34092 } else {
34093 PRINTK (KERN_INFO, "dropped over-size frame");
34094 // should we count this?
34095- atomic_inc(&atm_vcc->stats->rx_drop);
34096+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34097 }
34098
34099 } else {
34100@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34101 }
34102
34103 if (check_area (skb->data, skb->len)) {
34104- atomic_inc(&atm_vcc->stats->tx_err);
34105+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34106 return -ENOMEM; // ?
34107 }
34108
34109diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34110index 0e3f8f9..765a7a5 100644
34111--- a/drivers/atm/atmtcp.c
34112+++ b/drivers/atm/atmtcp.c
34113@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34114 if (vcc->pop) vcc->pop(vcc,skb);
34115 else dev_kfree_skb(skb);
34116 if (dev_data) return 0;
34117- atomic_inc(&vcc->stats->tx_err);
34118+ atomic_inc_unchecked(&vcc->stats->tx_err);
34119 return -ENOLINK;
34120 }
34121 size = skb->len+sizeof(struct atmtcp_hdr);
34122@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34123 if (!new_skb) {
34124 if (vcc->pop) vcc->pop(vcc,skb);
34125 else dev_kfree_skb(skb);
34126- atomic_inc(&vcc->stats->tx_err);
34127+ atomic_inc_unchecked(&vcc->stats->tx_err);
34128 return -ENOBUFS;
34129 }
34130 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34131@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34132 if (vcc->pop) vcc->pop(vcc,skb);
34133 else dev_kfree_skb(skb);
34134 out_vcc->push(out_vcc,new_skb);
34135- atomic_inc(&vcc->stats->tx);
34136- atomic_inc(&out_vcc->stats->rx);
34137+ atomic_inc_unchecked(&vcc->stats->tx);
34138+ atomic_inc_unchecked(&out_vcc->stats->rx);
34139 return 0;
34140 }
34141
34142@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34143 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34144 read_unlock(&vcc_sklist_lock);
34145 if (!out_vcc) {
34146- atomic_inc(&vcc->stats->tx_err);
34147+ atomic_inc_unchecked(&vcc->stats->tx_err);
34148 goto done;
34149 }
34150 skb_pull(skb,sizeof(struct atmtcp_hdr));
34151@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34152 __net_timestamp(new_skb);
34153 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34154 out_vcc->push(out_vcc,new_skb);
34155- atomic_inc(&vcc->stats->tx);
34156- atomic_inc(&out_vcc->stats->rx);
34157+ atomic_inc_unchecked(&vcc->stats->tx);
34158+ atomic_inc_unchecked(&out_vcc->stats->rx);
34159 done:
34160 if (vcc->pop) vcc->pop(vcc,skb);
34161 else dev_kfree_skb(skb);
34162diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34163index b1955ba..b179940 100644
34164--- a/drivers/atm/eni.c
34165+++ b/drivers/atm/eni.c
34166@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34167 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34168 vcc->dev->number);
34169 length = 0;
34170- atomic_inc(&vcc->stats->rx_err);
34171+ atomic_inc_unchecked(&vcc->stats->rx_err);
34172 }
34173 else {
34174 length = ATM_CELL_SIZE-1; /* no HEC */
34175@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34176 size);
34177 }
34178 eff = length = 0;
34179- atomic_inc(&vcc->stats->rx_err);
34180+ atomic_inc_unchecked(&vcc->stats->rx_err);
34181 }
34182 else {
34183 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34184@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34185 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34186 vcc->dev->number,vcc->vci,length,size << 2,descr);
34187 length = eff = 0;
34188- atomic_inc(&vcc->stats->rx_err);
34189+ atomic_inc_unchecked(&vcc->stats->rx_err);
34190 }
34191 }
34192 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34193@@ -767,7 +767,7 @@ rx_dequeued++;
34194 vcc->push(vcc,skb);
34195 pushed++;
34196 }
34197- atomic_inc(&vcc->stats->rx);
34198+ atomic_inc_unchecked(&vcc->stats->rx);
34199 }
34200 wake_up(&eni_dev->rx_wait);
34201 }
34202@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34203 PCI_DMA_TODEVICE);
34204 if (vcc->pop) vcc->pop(vcc,skb);
34205 else dev_kfree_skb_irq(skb);
34206- atomic_inc(&vcc->stats->tx);
34207+ atomic_inc_unchecked(&vcc->stats->tx);
34208 wake_up(&eni_dev->tx_wait);
34209 dma_complete++;
34210 }
34211diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34212index b41c948..a002b17 100644
34213--- a/drivers/atm/firestream.c
34214+++ b/drivers/atm/firestream.c
34215@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34216 }
34217 }
34218
34219- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34220+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34221
34222 fs_dprintk (FS_DEBUG_TXMEM, "i");
34223 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34224@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34225 #endif
34226 skb_put (skb, qe->p1 & 0xffff);
34227 ATM_SKB(skb)->vcc = atm_vcc;
34228- atomic_inc(&atm_vcc->stats->rx);
34229+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34230 __net_timestamp(skb);
34231 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34232 atm_vcc->push (atm_vcc, skb);
34233@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34234 kfree (pe);
34235 }
34236 if (atm_vcc)
34237- atomic_inc(&atm_vcc->stats->rx_drop);
34238+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34239 break;
34240 case 0x1f: /* Reassembly abort: no buffers. */
34241 /* Silently increment error counter. */
34242 if (atm_vcc)
34243- atomic_inc(&atm_vcc->stats->rx_drop);
34244+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34245 break;
34246 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34247 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34248diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34249index 204814e..cede831 100644
34250--- a/drivers/atm/fore200e.c
34251+++ b/drivers/atm/fore200e.c
34252@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34253 #endif
34254 /* check error condition */
34255 if (*entry->status & STATUS_ERROR)
34256- atomic_inc(&vcc->stats->tx_err);
34257+ atomic_inc_unchecked(&vcc->stats->tx_err);
34258 else
34259- atomic_inc(&vcc->stats->tx);
34260+ atomic_inc_unchecked(&vcc->stats->tx);
34261 }
34262 }
34263
34264@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34265 if (skb == NULL) {
34266 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
34267
34268- atomic_inc(&vcc->stats->rx_drop);
34269+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34270 return -ENOMEM;
34271 }
34272
34273@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34274
34275 dev_kfree_skb_any(skb);
34276
34277- atomic_inc(&vcc->stats->rx_drop);
34278+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34279 return -ENOMEM;
34280 }
34281
34282 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34283
34284 vcc->push(vcc, skb);
34285- atomic_inc(&vcc->stats->rx);
34286+ atomic_inc_unchecked(&vcc->stats->rx);
34287
34288 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34289
34290@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
34291 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
34292 fore200e->atm_dev->number,
34293 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
34294- atomic_inc(&vcc->stats->rx_err);
34295+ atomic_inc_unchecked(&vcc->stats->rx_err);
34296 }
34297 }
34298
34299@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
34300 goto retry_here;
34301 }
34302
34303- atomic_inc(&vcc->stats->tx_err);
34304+ atomic_inc_unchecked(&vcc->stats->tx_err);
34305
34306 fore200e->tx_sat++;
34307 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
34308diff --git a/drivers/atm/he.c b/drivers/atm/he.c
34309index 507362a..a845e57 100644
34310--- a/drivers/atm/he.c
34311+++ b/drivers/atm/he.c
34312@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
34313
34314 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
34315 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
34316- atomic_inc(&vcc->stats->rx_drop);
34317+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34318 goto return_host_buffers;
34319 }
34320
34321@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
34322 RBRQ_LEN_ERR(he_dev->rbrq_head)
34323 ? "LEN_ERR" : "",
34324 vcc->vpi, vcc->vci);
34325- atomic_inc(&vcc->stats->rx_err);
34326+ atomic_inc_unchecked(&vcc->stats->rx_err);
34327 goto return_host_buffers;
34328 }
34329
34330@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
34331 vcc->push(vcc, skb);
34332 spin_lock(&he_dev->global_lock);
34333
34334- atomic_inc(&vcc->stats->rx);
34335+ atomic_inc_unchecked(&vcc->stats->rx);
34336
34337 return_host_buffers:
34338 ++pdus_assembled;
34339@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
34340 tpd->vcc->pop(tpd->vcc, tpd->skb);
34341 else
34342 dev_kfree_skb_any(tpd->skb);
34343- atomic_inc(&tpd->vcc->stats->tx_err);
34344+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
34345 }
34346 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
34347 return;
34348@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
34349 vcc->pop(vcc, skb);
34350 else
34351 dev_kfree_skb_any(skb);
34352- atomic_inc(&vcc->stats->tx_err);
34353+ atomic_inc_unchecked(&vcc->stats->tx_err);
34354 return -EINVAL;
34355 }
34356
34357@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
34358 vcc->pop(vcc, skb);
34359 else
34360 dev_kfree_skb_any(skb);
34361- atomic_inc(&vcc->stats->tx_err);
34362+ atomic_inc_unchecked(&vcc->stats->tx_err);
34363 return -EINVAL;
34364 }
34365 #endif
34366@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
34367 vcc->pop(vcc, skb);
34368 else
34369 dev_kfree_skb_any(skb);
34370- atomic_inc(&vcc->stats->tx_err);
34371+ atomic_inc_unchecked(&vcc->stats->tx_err);
34372 spin_unlock_irqrestore(&he_dev->global_lock, flags);
34373 return -ENOMEM;
34374 }
34375@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
34376 vcc->pop(vcc, skb);
34377 else
34378 dev_kfree_skb_any(skb);
34379- atomic_inc(&vcc->stats->tx_err);
34380+ atomic_inc_unchecked(&vcc->stats->tx_err);
34381 spin_unlock_irqrestore(&he_dev->global_lock, flags);
34382 return -ENOMEM;
34383 }
34384@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
34385 __enqueue_tpd(he_dev, tpd, cid);
34386 spin_unlock_irqrestore(&he_dev->global_lock, flags);
34387
34388- atomic_inc(&vcc->stats->tx);
34389+ atomic_inc_unchecked(&vcc->stats->tx);
34390
34391 return 0;
34392 }
34393diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
34394index 1dc0519..1aadaf7 100644
34395--- a/drivers/atm/horizon.c
34396+++ b/drivers/atm/horizon.c
34397@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
34398 {
34399 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
34400 // VC layer stats
34401- atomic_inc(&vcc->stats->rx);
34402+ atomic_inc_unchecked(&vcc->stats->rx);
34403 __net_timestamp(skb);
34404 // end of our responsibility
34405 vcc->push (vcc, skb);
34406@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
34407 dev->tx_iovec = NULL;
34408
34409 // VC layer stats
34410- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34411+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34412
34413 // free the skb
34414 hrz_kfree_skb (skb);
34415diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
34416index 272f009..a18ba55 100644
34417--- a/drivers/atm/idt77252.c
34418+++ b/drivers/atm/idt77252.c
34419@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
34420 else
34421 dev_kfree_skb(skb);
34422
34423- atomic_inc(&vcc->stats->tx);
34424+ atomic_inc_unchecked(&vcc->stats->tx);
34425 }
34426
34427 atomic_dec(&scq->used);
34428@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34429 if ((sb = dev_alloc_skb(64)) == NULL) {
34430 printk("%s: Can't allocate buffers for aal0.\n",
34431 card->name);
34432- atomic_add(i, &vcc->stats->rx_drop);
34433+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
34434 break;
34435 }
34436 if (!atm_charge(vcc, sb->truesize)) {
34437 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
34438 card->name);
34439- atomic_add(i - 1, &vcc->stats->rx_drop);
34440+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
34441 dev_kfree_skb(sb);
34442 break;
34443 }
34444@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34445 ATM_SKB(sb)->vcc = vcc;
34446 __net_timestamp(sb);
34447 vcc->push(vcc, sb);
34448- atomic_inc(&vcc->stats->rx);
34449+ atomic_inc_unchecked(&vcc->stats->rx);
34450
34451 cell += ATM_CELL_PAYLOAD;
34452 }
34453@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34454 "(CDC: %08x)\n",
34455 card->name, len, rpp->len, readl(SAR_REG_CDC));
34456 recycle_rx_pool_skb(card, rpp);
34457- atomic_inc(&vcc->stats->rx_err);
34458+ atomic_inc_unchecked(&vcc->stats->rx_err);
34459 return;
34460 }
34461 if (stat & SAR_RSQE_CRC) {
34462 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
34463 recycle_rx_pool_skb(card, rpp);
34464- atomic_inc(&vcc->stats->rx_err);
34465+ atomic_inc_unchecked(&vcc->stats->rx_err);
34466 return;
34467 }
34468 if (skb_queue_len(&rpp->queue) > 1) {
34469@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34470 RXPRINTK("%s: Can't alloc RX skb.\n",
34471 card->name);
34472 recycle_rx_pool_skb(card, rpp);
34473- atomic_inc(&vcc->stats->rx_err);
34474+ atomic_inc_unchecked(&vcc->stats->rx_err);
34475 return;
34476 }
34477 if (!atm_charge(vcc, skb->truesize)) {
34478@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34479 __net_timestamp(skb);
34480
34481 vcc->push(vcc, skb);
34482- atomic_inc(&vcc->stats->rx);
34483+ atomic_inc_unchecked(&vcc->stats->rx);
34484
34485 return;
34486 }
34487@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
34488 __net_timestamp(skb);
34489
34490 vcc->push(vcc, skb);
34491- atomic_inc(&vcc->stats->rx);
34492+ atomic_inc_unchecked(&vcc->stats->rx);
34493
34494 if (skb->truesize > SAR_FB_SIZE_3)
34495 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
34496@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
34497 if (vcc->qos.aal != ATM_AAL0) {
34498 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
34499 card->name, vpi, vci);
34500- atomic_inc(&vcc->stats->rx_drop);
34501+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34502 goto drop;
34503 }
34504
34505 if ((sb = dev_alloc_skb(64)) == NULL) {
34506 printk("%s: Can't allocate buffers for AAL0.\n",
34507 card->name);
34508- atomic_inc(&vcc->stats->rx_err);
34509+ atomic_inc_unchecked(&vcc->stats->rx_err);
34510 goto drop;
34511 }
34512
34513@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
34514 ATM_SKB(sb)->vcc = vcc;
34515 __net_timestamp(sb);
34516 vcc->push(vcc, sb);
34517- atomic_inc(&vcc->stats->rx);
34518+ atomic_inc_unchecked(&vcc->stats->rx);
34519
34520 drop:
34521 skb_pull(queue, 64);
34522@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
34523
34524 if (vc == NULL) {
34525 printk("%s: NULL connection in send().\n", card->name);
34526- atomic_inc(&vcc->stats->tx_err);
34527+ atomic_inc_unchecked(&vcc->stats->tx_err);
34528 dev_kfree_skb(skb);
34529 return -EINVAL;
34530 }
34531 if (!test_bit(VCF_TX, &vc->flags)) {
34532 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
34533- atomic_inc(&vcc->stats->tx_err);
34534+ atomic_inc_unchecked(&vcc->stats->tx_err);
34535 dev_kfree_skb(skb);
34536 return -EINVAL;
34537 }
34538@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
34539 break;
34540 default:
34541 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
34542- atomic_inc(&vcc->stats->tx_err);
34543+ atomic_inc_unchecked(&vcc->stats->tx_err);
34544 dev_kfree_skb(skb);
34545 return -EINVAL;
34546 }
34547
34548 if (skb_shinfo(skb)->nr_frags != 0) {
34549 printk("%s: No scatter-gather yet.\n", card->name);
34550- atomic_inc(&vcc->stats->tx_err);
34551+ atomic_inc_unchecked(&vcc->stats->tx_err);
34552 dev_kfree_skb(skb);
34553 return -EINVAL;
34554 }
34555@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
34556
34557 err = queue_skb(card, vc, skb, oam);
34558 if (err) {
34559- atomic_inc(&vcc->stats->tx_err);
34560+ atomic_inc_unchecked(&vcc->stats->tx_err);
34561 dev_kfree_skb(skb);
34562 return err;
34563 }
34564@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
34565 skb = dev_alloc_skb(64);
34566 if (!skb) {
34567 printk("%s: Out of memory in send_oam().\n", card->name);
34568- atomic_inc(&vcc->stats->tx_err);
34569+ atomic_inc_unchecked(&vcc->stats->tx_err);
34570 return -ENOMEM;
34571 }
34572 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
34573diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
34574index 4217f29..88f547a 100644
34575--- a/drivers/atm/iphase.c
34576+++ b/drivers/atm/iphase.c
34577@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
34578 status = (u_short) (buf_desc_ptr->desc_mode);
34579 if (status & (RX_CER | RX_PTE | RX_OFL))
34580 {
34581- atomic_inc(&vcc->stats->rx_err);
34582+ atomic_inc_unchecked(&vcc->stats->rx_err);
34583 IF_ERR(printk("IA: bad packet, dropping it");)
34584 if (status & RX_CER) {
34585 IF_ERR(printk(" cause: packet CRC error\n");)
34586@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
34587 len = dma_addr - buf_addr;
34588 if (len > iadev->rx_buf_sz) {
34589 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
34590- atomic_inc(&vcc->stats->rx_err);
34591+ atomic_inc_unchecked(&vcc->stats->rx_err);
34592 goto out_free_desc;
34593 }
34594
34595@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
34596 ia_vcc = INPH_IA_VCC(vcc);
34597 if (ia_vcc == NULL)
34598 {
34599- atomic_inc(&vcc->stats->rx_err);
34600+ atomic_inc_unchecked(&vcc->stats->rx_err);
34601 atm_return(vcc, skb->truesize);
34602 dev_kfree_skb_any(skb);
34603 goto INCR_DLE;
34604@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
34605 if ((length > iadev->rx_buf_sz) || (length >
34606 (skb->len - sizeof(struct cpcs_trailer))))
34607 {
34608- atomic_inc(&vcc->stats->rx_err);
34609+ atomic_inc_unchecked(&vcc->stats->rx_err);
34610 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
34611 length, skb->len);)
34612 atm_return(vcc, skb->truesize);
34613@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
34614
34615 IF_RX(printk("rx_dle_intr: skb push");)
34616 vcc->push(vcc,skb);
34617- atomic_inc(&vcc->stats->rx);
34618+ atomic_inc_unchecked(&vcc->stats->rx);
34619 iadev->rx_pkt_cnt++;
34620 }
34621 INCR_DLE:
34622@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
34623 {
34624 struct k_sonet_stats *stats;
34625 stats = &PRIV(_ia_dev[board])->sonet_stats;
34626- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
34627- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
34628- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
34629- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
34630- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
34631- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
34632- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
34633- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
34634- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
34635+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
34636+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
34637+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
34638+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
34639+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
34640+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
34641+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
34642+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
34643+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
34644 }
34645 ia_cmds.status = 0;
34646 break;
34647@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
34648 if ((desc == 0) || (desc > iadev->num_tx_desc))
34649 {
34650 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
34651- atomic_inc(&vcc->stats->tx);
34652+ atomic_inc_unchecked(&vcc->stats->tx);
34653 if (vcc->pop)
34654 vcc->pop(vcc, skb);
34655 else
34656@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
34657 ATM_DESC(skb) = vcc->vci;
34658 skb_queue_tail(&iadev->tx_dma_q, skb);
34659
34660- atomic_inc(&vcc->stats->tx);
34661+ atomic_inc_unchecked(&vcc->stats->tx);
34662 iadev->tx_pkt_cnt++;
34663 /* Increment transaction counter */
34664 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
34665
34666 #if 0
34667 /* add flow control logic */
34668- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
34669+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
34670 if (iavcc->vc_desc_cnt > 10) {
34671 vcc->tx_quota = vcc->tx_quota * 3 / 4;
34672 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
34673diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
34674index fa7d701..1e404c7 100644
34675--- a/drivers/atm/lanai.c
34676+++ b/drivers/atm/lanai.c
34677@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
34678 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
34679 lanai_endtx(lanai, lvcc);
34680 lanai_free_skb(lvcc->tx.atmvcc, skb);
34681- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
34682+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
34683 }
34684
34685 /* Try to fill the buffer - don't call unless there is backlog */
34686@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
34687 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
34688 __net_timestamp(skb);
34689 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
34690- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
34691+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
34692 out:
34693 lvcc->rx.buf.ptr = end;
34694 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
34695@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
34696 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
34697 "vcc %d\n", lanai->number, (unsigned int) s, vci);
34698 lanai->stats.service_rxnotaal5++;
34699- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
34700+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
34701 return 0;
34702 }
34703 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
34704@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
34705 int bytes;
34706 read_unlock(&vcc_sklist_lock);
34707 DPRINTK("got trashed rx pdu on vci %d\n", vci);
34708- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
34709+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
34710 lvcc->stats.x.aal5.service_trash++;
34711 bytes = (SERVICE_GET_END(s) * 16) -
34712 (((unsigned long) lvcc->rx.buf.ptr) -
34713@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
34714 }
34715 if (s & SERVICE_STREAM) {
34716 read_unlock(&vcc_sklist_lock);
34717- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
34718+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
34719 lvcc->stats.x.aal5.service_stream++;
34720 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
34721 "PDU on VCI %d!\n", lanai->number, vci);
34722@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
34723 return 0;
34724 }
34725 DPRINTK("got rx crc error on vci %d\n", vci);
34726- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
34727+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
34728 lvcc->stats.x.aal5.service_rxcrc++;
34729 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
34730 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
34731diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
34732index 6587dc2..149833d 100644
34733--- a/drivers/atm/nicstar.c
34734+++ b/drivers/atm/nicstar.c
34735@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
34736 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
34737 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
34738 card->index);
34739- atomic_inc(&vcc->stats->tx_err);
34740+ atomic_inc_unchecked(&vcc->stats->tx_err);
34741 dev_kfree_skb_any(skb);
34742 return -EINVAL;
34743 }
34744@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
34745 if (!vc->tx) {
34746 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
34747 card->index);
34748- atomic_inc(&vcc->stats->tx_err);
34749+ atomic_inc_unchecked(&vcc->stats->tx_err);
34750 dev_kfree_skb_any(skb);
34751 return -EINVAL;
34752 }
34753@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
34754 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
34755 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
34756 card->index);
34757- atomic_inc(&vcc->stats->tx_err);
34758+ atomic_inc_unchecked(&vcc->stats->tx_err);
34759 dev_kfree_skb_any(skb);
34760 return -EINVAL;
34761 }
34762
34763 if (skb_shinfo(skb)->nr_frags != 0) {
34764 printk("nicstar%d: No scatter-gather yet.\n", card->index);
34765- atomic_inc(&vcc->stats->tx_err);
34766+ atomic_inc_unchecked(&vcc->stats->tx_err);
34767 dev_kfree_skb_any(skb);
34768 return -EINVAL;
34769 }
34770@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
34771 }
34772
34773 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
34774- atomic_inc(&vcc->stats->tx_err);
34775+ atomic_inc_unchecked(&vcc->stats->tx_err);
34776 dev_kfree_skb_any(skb);
34777 return -EIO;
34778 }
34779- atomic_inc(&vcc->stats->tx);
34780+ atomic_inc_unchecked(&vcc->stats->tx);
34781
34782 return 0;
34783 }
34784@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34785 printk
34786 ("nicstar%d: Can't allocate buffers for aal0.\n",
34787 card->index);
34788- atomic_add(i, &vcc->stats->rx_drop);
34789+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
34790 break;
34791 }
34792 if (!atm_charge(vcc, sb->truesize)) {
34793 RXPRINTK
34794 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
34795 card->index);
34796- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
34797+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
34798 dev_kfree_skb_any(sb);
34799 break;
34800 }
34801@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34802 ATM_SKB(sb)->vcc = vcc;
34803 __net_timestamp(sb);
34804 vcc->push(vcc, sb);
34805- atomic_inc(&vcc->stats->rx);
34806+ atomic_inc_unchecked(&vcc->stats->rx);
34807 cell += ATM_CELL_PAYLOAD;
34808 }
34809
34810@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34811 if (iovb == NULL) {
34812 printk("nicstar%d: Out of iovec buffers.\n",
34813 card->index);
34814- atomic_inc(&vcc->stats->rx_drop);
34815+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34816 recycle_rx_buf(card, skb);
34817 return;
34818 }
34819@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34820 small or large buffer itself. */
34821 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
34822 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
34823- atomic_inc(&vcc->stats->rx_err);
34824+ atomic_inc_unchecked(&vcc->stats->rx_err);
34825 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
34826 NS_MAX_IOVECS);
34827 NS_PRV_IOVCNT(iovb) = 0;
34828@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34829 ("nicstar%d: Expected a small buffer, and this is not one.\n",
34830 card->index);
34831 which_list(card, skb);
34832- atomic_inc(&vcc->stats->rx_err);
34833+ atomic_inc_unchecked(&vcc->stats->rx_err);
34834 recycle_rx_buf(card, skb);
34835 vc->rx_iov = NULL;
34836 recycle_iov_buf(card, iovb);
34837@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34838 ("nicstar%d: Expected a large buffer, and this is not one.\n",
34839 card->index);
34840 which_list(card, skb);
34841- atomic_inc(&vcc->stats->rx_err);
34842+ atomic_inc_unchecked(&vcc->stats->rx_err);
34843 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
34844 NS_PRV_IOVCNT(iovb));
34845 vc->rx_iov = NULL;
34846@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34847 printk(" - PDU size mismatch.\n");
34848 else
34849 printk(".\n");
34850- atomic_inc(&vcc->stats->rx_err);
34851+ atomic_inc_unchecked(&vcc->stats->rx_err);
34852 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
34853 NS_PRV_IOVCNT(iovb));
34854 vc->rx_iov = NULL;
34855@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34856 /* skb points to a small buffer */
34857 if (!atm_charge(vcc, skb->truesize)) {
34858 push_rxbufs(card, skb);
34859- atomic_inc(&vcc->stats->rx_drop);
34860+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34861 } else {
34862 skb_put(skb, len);
34863 dequeue_sm_buf(card, skb);
34864@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34865 ATM_SKB(skb)->vcc = vcc;
34866 __net_timestamp(skb);
34867 vcc->push(vcc, skb);
34868- atomic_inc(&vcc->stats->rx);
34869+ atomic_inc_unchecked(&vcc->stats->rx);
34870 }
34871 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
34872 struct sk_buff *sb;
34873@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34874 if (len <= NS_SMBUFSIZE) {
34875 if (!atm_charge(vcc, sb->truesize)) {
34876 push_rxbufs(card, sb);
34877- atomic_inc(&vcc->stats->rx_drop);
34878+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34879 } else {
34880 skb_put(sb, len);
34881 dequeue_sm_buf(card, sb);
34882@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34883 ATM_SKB(sb)->vcc = vcc;
34884 __net_timestamp(sb);
34885 vcc->push(vcc, sb);
34886- atomic_inc(&vcc->stats->rx);
34887+ atomic_inc_unchecked(&vcc->stats->rx);
34888 }
34889
34890 push_rxbufs(card, skb);
34891@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34892
34893 if (!atm_charge(vcc, skb->truesize)) {
34894 push_rxbufs(card, skb);
34895- atomic_inc(&vcc->stats->rx_drop);
34896+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34897 } else {
34898 dequeue_lg_buf(card, skb);
34899 #ifdef NS_USE_DESTRUCTORS
34900@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34901 ATM_SKB(skb)->vcc = vcc;
34902 __net_timestamp(skb);
34903 vcc->push(vcc, skb);
34904- atomic_inc(&vcc->stats->rx);
34905+ atomic_inc_unchecked(&vcc->stats->rx);
34906 }
34907
34908 push_rxbufs(card, sb);
34909@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34910 printk
34911 ("nicstar%d: Out of huge buffers.\n",
34912 card->index);
34913- atomic_inc(&vcc->stats->rx_drop);
34914+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34915 recycle_iovec_rx_bufs(card,
34916 (struct iovec *)
34917 iovb->data,
34918@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34919 card->hbpool.count++;
34920 } else
34921 dev_kfree_skb_any(hb);
34922- atomic_inc(&vcc->stats->rx_drop);
34923+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34924 } else {
34925 /* Copy the small buffer to the huge buffer */
34926 sb = (struct sk_buff *)iov->iov_base;
34927@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
34928 #endif /* NS_USE_DESTRUCTORS */
34929 __net_timestamp(hb);
34930 vcc->push(vcc, hb);
34931- atomic_inc(&vcc->stats->rx);
34932+ atomic_inc_unchecked(&vcc->stats->rx);
34933 }
34934 }
34935
34936diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
34937index 32784d1..4a8434a 100644
34938--- a/drivers/atm/solos-pci.c
34939+++ b/drivers/atm/solos-pci.c
34940@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
34941 }
34942 atm_charge(vcc, skb->truesize);
34943 vcc->push(vcc, skb);
34944- atomic_inc(&vcc->stats->rx);
34945+ atomic_inc_unchecked(&vcc->stats->rx);
34946 break;
34947
34948 case PKT_STATUS:
34949@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
34950 vcc = SKB_CB(oldskb)->vcc;
34951
34952 if (vcc) {
34953- atomic_inc(&vcc->stats->tx);
34954+ atomic_inc_unchecked(&vcc->stats->tx);
34955 solos_pop(vcc, oldskb);
34956 } else {
34957 dev_kfree_skb_irq(oldskb);
34958diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
34959index 0215934..ce9f5b1 100644
34960--- a/drivers/atm/suni.c
34961+++ b/drivers/atm/suni.c
34962@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
34963
34964
34965 #define ADD_LIMITED(s,v) \
34966- atomic_add((v),&stats->s); \
34967- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
34968+ atomic_add_unchecked((v),&stats->s); \
34969+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
34970
34971
34972 static void suni_hz(unsigned long from_timer)
34973diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
34974index 5120a96..e2572bd 100644
34975--- a/drivers/atm/uPD98402.c
34976+++ b/drivers/atm/uPD98402.c
34977@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
34978 struct sonet_stats tmp;
34979 int error = 0;
34980
34981- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
34982+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
34983 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
34984 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
34985 if (zero && !error) {
34986@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
34987
34988
34989 #define ADD_LIMITED(s,v) \
34990- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
34991- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
34992- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
34993+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
34994+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
34995+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
34996
34997
34998 static void stat_event(struct atm_dev *dev)
34999@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35000 if (reason & uPD98402_INT_PFM) stat_event(dev);
35001 if (reason & uPD98402_INT_PCO) {
35002 (void) GET(PCOCR); /* clear interrupt cause */
35003- atomic_add(GET(HECCT),
35004+ atomic_add_unchecked(GET(HECCT),
35005 &PRIV(dev)->sonet_stats.uncorr_hcs);
35006 }
35007 if ((reason & uPD98402_INT_RFO) &&
35008@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35009 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35010 uPD98402_INT_LOS),PIMR); /* enable them */
35011 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35012- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35013- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35014- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35015+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35016+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35017+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35018 return 0;
35019 }
35020
35021diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35022index 969c3c2..9b72956 100644
35023--- a/drivers/atm/zatm.c
35024+++ b/drivers/atm/zatm.c
35025@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35026 }
35027 if (!size) {
35028 dev_kfree_skb_irq(skb);
35029- if (vcc) atomic_inc(&vcc->stats->rx_err);
35030+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35031 continue;
35032 }
35033 if (!atm_charge(vcc,skb->truesize)) {
35034@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35035 skb->len = size;
35036 ATM_SKB(skb)->vcc = vcc;
35037 vcc->push(vcc,skb);
35038- atomic_inc(&vcc->stats->rx);
35039+ atomic_inc_unchecked(&vcc->stats->rx);
35040 }
35041 zout(pos & 0xffff,MTA(mbx));
35042 #if 0 /* probably a stupid idea */
35043@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35044 skb_queue_head(&zatm_vcc->backlog,skb);
35045 break;
35046 }
35047- atomic_inc(&vcc->stats->tx);
35048+ atomic_inc_unchecked(&vcc->stats->tx);
35049 wake_up(&zatm_vcc->tx_wait);
35050 }
35051
35052diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
35053index d78b204..ecc1929 100644
35054--- a/drivers/base/attribute_container.c
35055+++ b/drivers/base/attribute_container.c
35056@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
35057 ic->classdev.parent = get_device(dev);
35058 ic->classdev.class = cont->class;
35059 cont->class->dev_release = attribute_container_release;
35060- dev_set_name(&ic->classdev, dev_name(dev));
35061+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
35062 if (fn)
35063 fn(cont, dev, &ic->classdev);
35064 else
35065diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35066index d414331..b4dd4ba 100644
35067--- a/drivers/base/bus.c
35068+++ b/drivers/base/bus.c
35069@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35070 return -EINVAL;
35071
35072 mutex_lock(&subsys->p->mutex);
35073- list_add_tail(&sif->node, &subsys->p->interfaces);
35074+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35075 if (sif->add_dev) {
35076 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35077 while ((dev = subsys_dev_iter_next(&iter)))
35078@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35079 subsys = sif->subsys;
35080
35081 mutex_lock(&subsys->p->mutex);
35082- list_del_init(&sif->node);
35083+ pax_list_del_init((struct list_head *)&sif->node);
35084 if (sif->remove_dev) {
35085 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35086 while ((dev = subsys_dev_iter_next(&iter)))
35087diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35088index 7413d06..79155fa 100644
35089--- a/drivers/base/devtmpfs.c
35090+++ b/drivers/base/devtmpfs.c
35091@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35092 if (!thread)
35093 return 0;
35094
35095- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35096+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35097 if (err)
35098 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35099 else
35100@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35101 *err = sys_unshare(CLONE_NEWNS);
35102 if (*err)
35103 goto out;
35104- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35105+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35106 if (*err)
35107 goto out;
35108- sys_chdir("/.."); /* will traverse into overmounted root */
35109- sys_chroot(".");
35110+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35111+ sys_chroot((char __force_user *)".");
35112 complete(&setup_done);
35113 while (1) {
35114 spin_lock(&req_lock);
35115diff --git a/drivers/base/node.c b/drivers/base/node.c
35116index 7616a77c..8f57f51 100644
35117--- a/drivers/base/node.c
35118+++ b/drivers/base/node.c
35119@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35120 struct node_attr {
35121 struct device_attribute attr;
35122 enum node_states state;
35123-};
35124+} __do_const;
35125
35126 static ssize_t show_node_state(struct device *dev,
35127 struct device_attribute *attr, char *buf)
35128diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35129index 7072404..76dcebd 100644
35130--- a/drivers/base/power/domain.c
35131+++ b/drivers/base/power/domain.c
35132@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35133 {
35134 struct cpuidle_driver *cpuidle_drv;
35135 struct gpd_cpu_data *cpu_data;
35136- struct cpuidle_state *idle_state;
35137+ cpuidle_state_no_const *idle_state;
35138 int ret = 0;
35139
35140 if (IS_ERR_OR_NULL(genpd) || state < 0)
35141@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35142 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35143 {
35144 struct gpd_cpu_data *cpu_data;
35145- struct cpuidle_state *idle_state;
35146+ cpuidle_state_no_const *idle_state;
35147 int ret = 0;
35148
35149 if (IS_ERR_OR_NULL(genpd))
35150diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35151index a53ebd2..8f73eeb 100644
35152--- a/drivers/base/power/sysfs.c
35153+++ b/drivers/base/power/sysfs.c
35154@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35155 return -EIO;
35156 }
35157 }
35158- return sprintf(buf, p);
35159+ return sprintf(buf, "%s", p);
35160 }
35161
35162 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35163diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35164index 79715e7..df06b3b 100644
35165--- a/drivers/base/power/wakeup.c
35166+++ b/drivers/base/power/wakeup.c
35167@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35168 * They need to be modified together atomically, so it's better to use one
35169 * atomic variable to hold them both.
35170 */
35171-static atomic_t combined_event_count = ATOMIC_INIT(0);
35172+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35173
35174 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35175 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35176
35177 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35178 {
35179- unsigned int comb = atomic_read(&combined_event_count);
35180+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35181
35182 *cnt = (comb >> IN_PROGRESS_BITS);
35183 *inpr = comb & MAX_IN_PROGRESS;
35184@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35185 ws->start_prevent_time = ws->last_time;
35186
35187 /* Increment the counter of events in progress. */
35188- cec = atomic_inc_return(&combined_event_count);
35189+ cec = atomic_inc_return_unchecked(&combined_event_count);
35190
35191 trace_wakeup_source_activate(ws->name, cec);
35192 }
35193@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35194 * Increment the counter of registered wakeup events and decrement the
35195 * couter of wakeup events in progress simultaneously.
35196 */
35197- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35198+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35199 trace_wakeup_source_deactivate(ws->name, cec);
35200
35201 split_counters(&cnt, &inpr);
35202diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35203index e8d11b6..7b1b36f 100644
35204--- a/drivers/base/syscore.c
35205+++ b/drivers/base/syscore.c
35206@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35207 void register_syscore_ops(struct syscore_ops *ops)
35208 {
35209 mutex_lock(&syscore_ops_lock);
35210- list_add_tail(&ops->node, &syscore_ops_list);
35211+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35212 mutex_unlock(&syscore_ops_lock);
35213 }
35214 EXPORT_SYMBOL_GPL(register_syscore_ops);
35215@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35216 void unregister_syscore_ops(struct syscore_ops *ops)
35217 {
35218 mutex_lock(&syscore_ops_lock);
35219- list_del(&ops->node);
35220+ pax_list_del((struct list_head *)&ops->node);
35221 mutex_unlock(&syscore_ops_lock);
35222 }
35223 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35224diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35225index 62b6c2c..4a11354 100644
35226--- a/drivers/block/cciss.c
35227+++ b/drivers/block/cciss.c
35228@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35229 int err;
35230 u32 cp;
35231
35232+ memset(&arg64, 0, sizeof(arg64));
35233+
35234 err = 0;
35235 err |=
35236 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35237@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35238 while (!list_empty(&h->reqQ)) {
35239 c = list_entry(h->reqQ.next, CommandList_struct, list);
35240 /* can't do anything if fifo is full */
35241- if ((h->access.fifo_full(h))) {
35242+ if ((h->access->fifo_full(h))) {
35243 dev_warn(&h->pdev->dev, "fifo full\n");
35244 break;
35245 }
35246@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
35247 h->Qdepth--;
35248
35249 /* Tell the controller execute command */
35250- h->access.submit_command(h, c);
35251+ h->access->submit_command(h, c);
35252
35253 /* Put job onto the completed Q */
35254 addQ(&h->cmpQ, c);
35255@@ -3446,17 +3448,17 @@ startio:
35256
35257 static inline unsigned long get_next_completion(ctlr_info_t *h)
35258 {
35259- return h->access.command_completed(h);
35260+ return h->access->command_completed(h);
35261 }
35262
35263 static inline int interrupt_pending(ctlr_info_t *h)
35264 {
35265- return h->access.intr_pending(h);
35266+ return h->access->intr_pending(h);
35267 }
35268
35269 static inline long interrupt_not_for_us(ctlr_info_t *h)
35270 {
35271- return ((h->access.intr_pending(h) == 0) ||
35272+ return ((h->access->intr_pending(h) == 0) ||
35273 (h->interrupts_enabled == 0));
35274 }
35275
35276@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
35277 u32 a;
35278
35279 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35280- return h->access.command_completed(h);
35281+ return h->access->command_completed(h);
35282
35283 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35284 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35285@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
35286 trans_support & CFGTBL_Trans_use_short_tags);
35287
35288 /* Change the access methods to the performant access methods */
35289- h->access = SA5_performant_access;
35290+ h->access = &SA5_performant_access;
35291 h->transMethod = CFGTBL_Trans_Performant;
35292
35293 return;
35294@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
35295 if (prod_index < 0)
35296 return -ENODEV;
35297 h->product_name = products[prod_index].product_name;
35298- h->access = *(products[prod_index].access);
35299+ h->access = products[prod_index].access;
35300
35301 if (cciss_board_disabled(h)) {
35302 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35303@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
35304 }
35305
35306 /* make sure the board interrupts are off */
35307- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35308+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35309 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
35310 if (rc)
35311 goto clean2;
35312@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
35313 * fake ones to scoop up any residual completions.
35314 */
35315 spin_lock_irqsave(&h->lock, flags);
35316- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35317+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35318 spin_unlock_irqrestore(&h->lock, flags);
35319 free_irq(h->intr[h->intr_mode], h);
35320 rc = cciss_request_irq(h, cciss_msix_discard_completions,
35321@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
35322 dev_info(&h->pdev->dev, "Board READY.\n");
35323 dev_info(&h->pdev->dev,
35324 "Waiting for stale completions to drain.\n");
35325- h->access.set_intr_mask(h, CCISS_INTR_ON);
35326+ h->access->set_intr_mask(h, CCISS_INTR_ON);
35327 msleep(10000);
35328- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35329+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35330
35331 rc = controller_reset_failed(h->cfgtable);
35332 if (rc)
35333@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
35334 cciss_scsi_setup(h);
35335
35336 /* Turn the interrupts on so we can service requests */
35337- h->access.set_intr_mask(h, CCISS_INTR_ON);
35338+ h->access->set_intr_mask(h, CCISS_INTR_ON);
35339
35340 /* Get the firmware version */
35341 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
35342@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
35343 kfree(flush_buf);
35344 if (return_code != IO_OK)
35345 dev_warn(&h->pdev->dev, "Error flushing cache\n");
35346- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35347+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35348 free_irq(h->intr[h->intr_mode], h);
35349 }
35350
35351diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
35352index 7fda30e..eb5dfe0 100644
35353--- a/drivers/block/cciss.h
35354+++ b/drivers/block/cciss.h
35355@@ -101,7 +101,7 @@ struct ctlr_info
35356 /* information about each logical volume */
35357 drive_info_struct *drv[CISS_MAX_LUN];
35358
35359- struct access_method access;
35360+ struct access_method *access;
35361
35362 /* queue and queue Info */
35363 struct list_head reqQ;
35364diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
35365index 639d26b..fd6ad1f 100644
35366--- a/drivers/block/cpqarray.c
35367+++ b/drivers/block/cpqarray.c
35368@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
35369 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
35370 goto Enomem4;
35371 }
35372- hba[i]->access.set_intr_mask(hba[i], 0);
35373+ hba[i]->access->set_intr_mask(hba[i], 0);
35374 if (request_irq(hba[i]->intr, do_ida_intr,
35375 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
35376 {
35377@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
35378 add_timer(&hba[i]->timer);
35379
35380 /* Enable IRQ now that spinlock and rate limit timer are set up */
35381- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
35382+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
35383
35384 for(j=0; j<NWD; j++) {
35385 struct gendisk *disk = ida_gendisk[i][j];
35386@@ -694,7 +694,7 @@ DBGINFO(
35387 for(i=0; i<NR_PRODUCTS; i++) {
35388 if (board_id == products[i].board_id) {
35389 c->product_name = products[i].product_name;
35390- c->access = *(products[i].access);
35391+ c->access = products[i].access;
35392 break;
35393 }
35394 }
35395@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
35396 hba[ctlr]->intr = intr;
35397 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
35398 hba[ctlr]->product_name = products[j].product_name;
35399- hba[ctlr]->access = *(products[j].access);
35400+ hba[ctlr]->access = products[j].access;
35401 hba[ctlr]->ctlr = ctlr;
35402 hba[ctlr]->board_id = board_id;
35403 hba[ctlr]->pci_dev = NULL; /* not PCI */
35404@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
35405
35406 while((c = h->reqQ) != NULL) {
35407 /* Can't do anything if we're busy */
35408- if (h->access.fifo_full(h) == 0)
35409+ if (h->access->fifo_full(h) == 0)
35410 return;
35411
35412 /* Get the first entry from the request Q */
35413@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
35414 h->Qdepth--;
35415
35416 /* Tell the controller to do our bidding */
35417- h->access.submit_command(h, c);
35418+ h->access->submit_command(h, c);
35419
35420 /* Get onto the completion Q */
35421 addQ(&h->cmpQ, c);
35422@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
35423 unsigned long flags;
35424 __u32 a,a1;
35425
35426- istat = h->access.intr_pending(h);
35427+ istat = h->access->intr_pending(h);
35428 /* Is this interrupt for us? */
35429 if (istat == 0)
35430 return IRQ_NONE;
35431@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
35432 */
35433 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
35434 if (istat & FIFO_NOT_EMPTY) {
35435- while((a = h->access.command_completed(h))) {
35436+ while((a = h->access->command_completed(h))) {
35437 a1 = a; a &= ~3;
35438 if ((c = h->cmpQ) == NULL)
35439 {
35440@@ -1193,6 +1193,7 @@ out_passthru:
35441 ida_pci_info_struct pciinfo;
35442
35443 if (!arg) return -EINVAL;
35444+ memset(&pciinfo, 0, sizeof(pciinfo));
35445 pciinfo.bus = host->pci_dev->bus->number;
35446 pciinfo.dev_fn = host->pci_dev->devfn;
35447 pciinfo.board_id = host->board_id;
35448@@ -1447,11 +1448,11 @@ static int sendcmd(
35449 /*
35450 * Disable interrupt
35451 */
35452- info_p->access.set_intr_mask(info_p, 0);
35453+ info_p->access->set_intr_mask(info_p, 0);
35454 /* Make sure there is room in the command FIFO */
35455 /* Actually it should be completely empty at this time. */
35456 for (i = 200000; i > 0; i--) {
35457- temp = info_p->access.fifo_full(info_p);
35458+ temp = info_p->access->fifo_full(info_p);
35459 if (temp != 0) {
35460 break;
35461 }
35462@@ -1464,7 +1465,7 @@ DBG(
35463 /*
35464 * Send the cmd
35465 */
35466- info_p->access.submit_command(info_p, c);
35467+ info_p->access->submit_command(info_p, c);
35468 complete = pollcomplete(ctlr);
35469
35470 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
35471@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
35472 * we check the new geometry. Then turn interrupts back on when
35473 * we're done.
35474 */
35475- host->access.set_intr_mask(host, 0);
35476+ host->access->set_intr_mask(host, 0);
35477 getgeometry(ctlr);
35478- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
35479+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
35480
35481 for(i=0; i<NWD; i++) {
35482 struct gendisk *disk = ida_gendisk[ctlr][i];
35483@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
35484 /* Wait (up to 2 seconds) for a command to complete */
35485
35486 for (i = 200000; i > 0; i--) {
35487- done = hba[ctlr]->access.command_completed(hba[ctlr]);
35488+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
35489 if (done == 0) {
35490 udelay(10); /* a short fixed delay */
35491 } else
35492diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
35493index be73e9d..7fbf140 100644
35494--- a/drivers/block/cpqarray.h
35495+++ b/drivers/block/cpqarray.h
35496@@ -99,7 +99,7 @@ struct ctlr_info {
35497 drv_info_t drv[NWD];
35498 struct proc_dir_entry *proc;
35499
35500- struct access_method access;
35501+ struct access_method *access;
35502
35503 cmdlist_t *reqQ;
35504 cmdlist_t *cmpQ;
35505diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
35506index f943aac..99bfd19 100644
35507--- a/drivers/block/drbd/drbd_int.h
35508+++ b/drivers/block/drbd/drbd_int.h
35509@@ -582,7 +582,7 @@ struct drbd_epoch {
35510 struct drbd_tconn *tconn;
35511 struct list_head list;
35512 unsigned int barrier_nr;
35513- atomic_t epoch_size; /* increased on every request added. */
35514+ atomic_unchecked_t epoch_size; /* increased on every request added. */
35515 atomic_t active; /* increased on every req. added, and dec on every finished. */
35516 unsigned long flags;
35517 };
35518@@ -1021,7 +1021,7 @@ struct drbd_conf {
35519 unsigned int al_tr_number;
35520 int al_tr_cycle;
35521 wait_queue_head_t seq_wait;
35522- atomic_t packet_seq;
35523+ atomic_unchecked_t packet_seq;
35524 unsigned int peer_seq;
35525 spinlock_t peer_seq_lock;
35526 unsigned int minor;
35527@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
35528 char __user *uoptval;
35529 int err;
35530
35531- uoptval = (char __user __force *)optval;
35532+ uoptval = (char __force_user *)optval;
35533
35534 set_fs(KERNEL_DS);
35535 if (level == SOL_SOCKET)
35536diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
35537index a5dca6a..bb27967 100644
35538--- a/drivers/block/drbd/drbd_main.c
35539+++ b/drivers/block/drbd/drbd_main.c
35540@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
35541 p->sector = sector;
35542 p->block_id = block_id;
35543 p->blksize = blksize;
35544- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
35545+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
35546 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
35547 }
35548
35549@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
35550 return -EIO;
35551 p->sector = cpu_to_be64(req->i.sector);
35552 p->block_id = (unsigned long)req;
35553- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
35554+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
35555 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
35556 if (mdev->state.conn >= C_SYNC_SOURCE &&
35557 mdev->state.conn <= C_PAUSED_SYNC_T)
35558@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
35559 {
35560 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
35561
35562- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
35563- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
35564+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
35565+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
35566 kfree(tconn->current_epoch);
35567
35568 idr_destroy(&tconn->volumes);
35569diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
35570index 4222aff..1f79506 100644
35571--- a/drivers/block/drbd/drbd_receiver.c
35572+++ b/drivers/block/drbd/drbd_receiver.c
35573@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
35574 {
35575 int err;
35576
35577- atomic_set(&mdev->packet_seq, 0);
35578+ atomic_set_unchecked(&mdev->packet_seq, 0);
35579 mdev->peer_seq = 0;
35580
35581 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
35582@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
35583 do {
35584 next_epoch = NULL;
35585
35586- epoch_size = atomic_read(&epoch->epoch_size);
35587+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
35588
35589 switch (ev & ~EV_CLEANUP) {
35590 case EV_PUT:
35591@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
35592 rv = FE_DESTROYED;
35593 } else {
35594 epoch->flags = 0;
35595- atomic_set(&epoch->epoch_size, 0);
35596+ atomic_set_unchecked(&epoch->epoch_size, 0);
35597 /* atomic_set(&epoch->active, 0); is already zero */
35598 if (rv == FE_STILL_LIVE)
35599 rv = FE_RECYCLED;
35600@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
35601 conn_wait_active_ee_empty(tconn);
35602 drbd_flush(tconn);
35603
35604- if (atomic_read(&tconn->current_epoch->epoch_size)) {
35605+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
35606 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
35607 if (epoch)
35608 break;
35609@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
35610 }
35611
35612 epoch->flags = 0;
35613- atomic_set(&epoch->epoch_size, 0);
35614+ atomic_set_unchecked(&epoch->epoch_size, 0);
35615 atomic_set(&epoch->active, 0);
35616
35617 spin_lock(&tconn->epoch_lock);
35618- if (atomic_read(&tconn->current_epoch->epoch_size)) {
35619+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
35620 list_add(&epoch->list, &tconn->current_epoch->list);
35621 tconn->current_epoch = epoch;
35622 tconn->epochs++;
35623@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
35624
35625 err = wait_for_and_update_peer_seq(mdev, peer_seq);
35626 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
35627- atomic_inc(&tconn->current_epoch->epoch_size);
35628+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
35629 err2 = drbd_drain_block(mdev, pi->size);
35630 if (!err)
35631 err = err2;
35632@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
35633
35634 spin_lock(&tconn->epoch_lock);
35635 peer_req->epoch = tconn->current_epoch;
35636- atomic_inc(&peer_req->epoch->epoch_size);
35637+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
35638 atomic_inc(&peer_req->epoch->active);
35639 spin_unlock(&tconn->epoch_lock);
35640
35641@@ -4347,7 +4347,7 @@ struct data_cmd {
35642 int expect_payload;
35643 size_t pkt_size;
35644 int (*fn)(struct drbd_tconn *, struct packet_info *);
35645-};
35646+} __do_const;
35647
35648 static struct data_cmd drbd_cmd_handler[] = {
35649 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
35650@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
35651 if (!list_empty(&tconn->current_epoch->list))
35652 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
35653 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
35654- atomic_set(&tconn->current_epoch->epoch_size, 0);
35655+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
35656 tconn->send.seen_any_write_yet = false;
35657
35658 conn_info(tconn, "Connection closed\n");
35659@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
35660 struct asender_cmd {
35661 size_t pkt_size;
35662 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
35663-};
35664+} __do_const;
35665
35666 static struct asender_cmd asender_tbl[] = {
35667 [P_PING] = { 0, got_Ping },
35668diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35669index d92d50f..a7e9d97 100644
35670--- a/drivers/block/loop.c
35671+++ b/drivers/block/loop.c
35672@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
35673
35674 file_start_write(file);
35675 set_fs(get_ds());
35676- bw = file->f_op->write(file, buf, len, &pos);
35677+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
35678 set_fs(old_fs);
35679 file_end_write(file);
35680 if (likely(bw == len))
35681diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
35682index f5d0ea1..c62380a 100644
35683--- a/drivers/block/pktcdvd.c
35684+++ b/drivers/block/pktcdvd.c
35685@@ -84,7 +84,7 @@
35686 #define MAX_SPEED 0xffff
35687
35688 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
35689- ~(sector_t)((pd)->settings.size - 1))
35690+ ~(sector_t)((pd)->settings.size - 1UL))
35691
35692 static DEFINE_MUTEX(pktcdvd_mutex);
35693 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
35694diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
35695index 8a3aff7..d7538c2 100644
35696--- a/drivers/cdrom/cdrom.c
35697+++ b/drivers/cdrom/cdrom.c
35698@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
35699 ENSURE(reset, CDC_RESET);
35700 ENSURE(generic_packet, CDC_GENERIC_PACKET);
35701 cdi->mc_flags = 0;
35702- cdo->n_minors = 0;
35703 cdi->options = CDO_USE_FFLAGS;
35704
35705 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
35706@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
35707 else
35708 cdi->cdda_method = CDDA_OLD;
35709
35710- if (!cdo->generic_packet)
35711- cdo->generic_packet = cdrom_dummy_generic_packet;
35712+ if (!cdo->generic_packet) {
35713+ pax_open_kernel();
35714+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
35715+ pax_close_kernel();
35716+ }
35717
35718 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
35719 mutex_lock(&cdrom_mutex);
35720@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
35721 if (cdi->exit)
35722 cdi->exit(cdi);
35723
35724- cdi->ops->n_minors--;
35725 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
35726 }
35727
35728@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
35729 */
35730 nr = nframes;
35731 do {
35732- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
35733+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
35734 if (cgc.buffer)
35735 break;
35736
35737@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
35738 struct cdrom_device_info *cdi;
35739 int ret;
35740
35741- ret = scnprintf(info + *pos, max_size - *pos, header);
35742+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
35743 if (!ret)
35744 return 1;
35745
35746diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
35747index 4afcb65..a68a32d 100644
35748--- a/drivers/cdrom/gdrom.c
35749+++ b/drivers/cdrom/gdrom.c
35750@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
35751 .audio_ioctl = gdrom_audio_ioctl,
35752 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
35753 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
35754- .n_minors = 1,
35755 };
35756
35757 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
35758diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
35759index 3bb6fa3..34013fb 100644
35760--- a/drivers/char/Kconfig
35761+++ b/drivers/char/Kconfig
35762@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
35763
35764 config DEVKMEM
35765 bool "/dev/kmem virtual device support"
35766- default y
35767+ default n
35768+ depends on !GRKERNSEC_KMEM
35769 help
35770 Say Y here if you want to support the /dev/kmem device. The
35771 /dev/kmem device is rarely used, but can be used for certain
35772@@ -582,6 +583,7 @@ config DEVPORT
35773 bool
35774 depends on !M68K
35775 depends on ISA || PCI
35776+ depends on !GRKERNSEC_KMEM
35777 default y
35778
35779 source "drivers/s390/char/Kconfig"
35780diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
35781index a48e05b..6bac831 100644
35782--- a/drivers/char/agp/compat_ioctl.c
35783+++ b/drivers/char/agp/compat_ioctl.c
35784@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
35785 return -ENOMEM;
35786 }
35787
35788- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
35789+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
35790 sizeof(*usegment) * ureserve.seg_count)) {
35791 kfree(usegment);
35792 kfree(ksegment);
35793diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
35794index 2e04433..771f2cc 100644
35795--- a/drivers/char/agp/frontend.c
35796+++ b/drivers/char/agp/frontend.c
35797@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
35798 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
35799 return -EFAULT;
35800
35801- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
35802+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
35803 return -EFAULT;
35804
35805 client = agp_find_client_by_pid(reserve.pid);
35806@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
35807 if (segment == NULL)
35808 return -ENOMEM;
35809
35810- if (copy_from_user(segment, (void __user *) reserve.seg_list,
35811+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
35812 sizeof(struct agp_segment) * reserve.seg_count)) {
35813 kfree(segment);
35814 return -EFAULT;
35815diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
35816index 4f94375..413694e 100644
35817--- a/drivers/char/genrtc.c
35818+++ b/drivers/char/genrtc.c
35819@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
35820 switch (cmd) {
35821
35822 case RTC_PLL_GET:
35823+ memset(&pll, 0, sizeof(pll));
35824 if (get_rtc_pll(&pll))
35825 return -EINVAL;
35826 else
35827diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
35828index d784650..e8bfd69 100644
35829--- a/drivers/char/hpet.c
35830+++ b/drivers/char/hpet.c
35831@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
35832 }
35833
35834 static int
35835-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
35836+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
35837 struct hpet_info *info)
35838 {
35839 struct hpet_timer __iomem *timer;
35840diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
35841index 86fe45c..c0ea948 100644
35842--- a/drivers/char/hw_random/intel-rng.c
35843+++ b/drivers/char/hw_random/intel-rng.c
35844@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
35845
35846 if (no_fwh_detect)
35847 return -ENODEV;
35848- printk(warning);
35849+ printk("%s", warning);
35850 return -EBUSY;
35851 }
35852
35853diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
35854index 4445fa1..7c6de37 100644
35855--- a/drivers/char/ipmi/ipmi_msghandler.c
35856+++ b/drivers/char/ipmi/ipmi_msghandler.c
35857@@ -420,7 +420,7 @@ struct ipmi_smi {
35858 struct proc_dir_entry *proc_dir;
35859 char proc_dir_name[10];
35860
35861- atomic_t stats[IPMI_NUM_STATS];
35862+ atomic_unchecked_t stats[IPMI_NUM_STATS];
35863
35864 /*
35865 * run_to_completion duplicate of smb_info, smi_info
35866@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
35867
35868
35869 #define ipmi_inc_stat(intf, stat) \
35870- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
35871+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
35872 #define ipmi_get_stat(intf, stat) \
35873- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
35874+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
35875
35876 static int is_lan_addr(struct ipmi_addr *addr)
35877 {
35878@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
35879 INIT_LIST_HEAD(&intf->cmd_rcvrs);
35880 init_waitqueue_head(&intf->waitq);
35881 for (i = 0; i < IPMI_NUM_STATS; i++)
35882- atomic_set(&intf->stats[i], 0);
35883+ atomic_set_unchecked(&intf->stats[i], 0);
35884
35885 intf->proc_dir = NULL;
35886
35887diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
35888index af4b23f..79806fc 100644
35889--- a/drivers/char/ipmi/ipmi_si_intf.c
35890+++ b/drivers/char/ipmi/ipmi_si_intf.c
35891@@ -275,7 +275,7 @@ struct smi_info {
35892 unsigned char slave_addr;
35893
35894 /* Counters and things for the proc filesystem. */
35895- atomic_t stats[SI_NUM_STATS];
35896+ atomic_unchecked_t stats[SI_NUM_STATS];
35897
35898 struct task_struct *thread;
35899
35900@@ -284,9 +284,9 @@ struct smi_info {
35901 };
35902
35903 #define smi_inc_stat(smi, stat) \
35904- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
35905+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
35906 #define smi_get_stat(smi, stat) \
35907- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
35908+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
35909
35910 #define SI_MAX_PARMS 4
35911
35912@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
35913 atomic_set(&new_smi->req_events, 0);
35914 new_smi->run_to_completion = 0;
35915 for (i = 0; i < SI_NUM_STATS; i++)
35916- atomic_set(&new_smi->stats[i], 0);
35917+ atomic_set_unchecked(&new_smi->stats[i], 0);
35918
35919 new_smi->interrupt_disabled = 1;
35920 atomic_set(&new_smi->stop_operation, 0);
35921diff --git a/drivers/char/mem.c b/drivers/char/mem.c
35922index 1ccbe94..6ad651a 100644
35923--- a/drivers/char/mem.c
35924+++ b/drivers/char/mem.c
35925@@ -18,6 +18,7 @@
35926 #include <linux/raw.h>
35927 #include <linux/tty.h>
35928 #include <linux/capability.h>
35929+#include <linux/security.h>
35930 #include <linux/ptrace.h>
35931 #include <linux/device.h>
35932 #include <linux/highmem.h>
35933@@ -38,6 +39,10 @@
35934
35935 #define DEVPORT_MINOR 4
35936
35937+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
35938+extern const struct file_operations grsec_fops;
35939+#endif
35940+
35941 static inline unsigned long size_inside_page(unsigned long start,
35942 unsigned long size)
35943 {
35944@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
35945
35946 while (cursor < to) {
35947 if (!devmem_is_allowed(pfn)) {
35948+#ifdef CONFIG_GRKERNSEC_KMEM
35949+ gr_handle_mem_readwrite(from, to);
35950+#else
35951 printk(KERN_INFO
35952 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
35953 current->comm, from, to);
35954+#endif
35955 return 0;
35956 }
35957 cursor += PAGE_SIZE;
35958@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
35959 }
35960 return 1;
35961 }
35962+#elif defined(CONFIG_GRKERNSEC_KMEM)
35963+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
35964+{
35965+ return 0;
35966+}
35967 #else
35968 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
35969 {
35970@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
35971
35972 while (count > 0) {
35973 unsigned long remaining;
35974+ char *temp;
35975
35976 sz = size_inside_page(p, count);
35977
35978@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
35979 if (!ptr)
35980 return -EFAULT;
35981
35982- remaining = copy_to_user(buf, ptr, sz);
35983+#ifdef CONFIG_PAX_USERCOPY
35984+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
35985+ if (!temp) {
35986+ unxlate_dev_mem_ptr(p, ptr);
35987+ return -ENOMEM;
35988+ }
35989+ memcpy(temp, ptr, sz);
35990+#else
35991+ temp = ptr;
35992+#endif
35993+
35994+ remaining = copy_to_user(buf, temp, sz);
35995+
35996+#ifdef CONFIG_PAX_USERCOPY
35997+ kfree(temp);
35998+#endif
35999+
36000 unxlate_dev_mem_ptr(p, ptr);
36001 if (remaining)
36002 return -EFAULT;
36003@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
36004 else
36005 csize = count;
36006
36007- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
36008+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
36009 if (rc < 0)
36010 return rc;
36011 buf += csize;
36012@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36013 size_t count, loff_t *ppos)
36014 {
36015 unsigned long p = *ppos;
36016- ssize_t low_count, read, sz;
36017+ ssize_t low_count, read, sz, err = 0;
36018 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36019- int err = 0;
36020
36021 read = 0;
36022 if (p < (unsigned long) high_memory) {
36023@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36024 }
36025 #endif
36026 while (low_count > 0) {
36027+ char *temp;
36028+
36029 sz = size_inside_page(p, low_count);
36030
36031 /*
36032@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36033 */
36034 kbuf = xlate_dev_kmem_ptr((char *)p);
36035
36036- if (copy_to_user(buf, kbuf, sz))
36037+#ifdef CONFIG_PAX_USERCOPY
36038+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36039+ if (!temp)
36040+ return -ENOMEM;
36041+ memcpy(temp, kbuf, sz);
36042+#else
36043+ temp = kbuf;
36044+#endif
36045+
36046+ err = copy_to_user(buf, temp, sz);
36047+
36048+#ifdef CONFIG_PAX_USERCOPY
36049+ kfree(temp);
36050+#endif
36051+
36052+ if (err)
36053 return -EFAULT;
36054 buf += sz;
36055 p += sz;
36056@@ -869,6 +916,9 @@ static const struct memdev {
36057 #ifdef CONFIG_CRASH_DUMP
36058 [12] = { "oldmem", 0, &oldmem_fops, NULL },
36059 #endif
36060+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36061+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36062+#endif
36063 };
36064
36065 static int memory_open(struct inode *inode, struct file *filp)
36066@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
36067 continue;
36068
36069 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36070- NULL, devlist[minor].name);
36071+ NULL, "%s", devlist[minor].name);
36072 }
36073
36074 return tty_init();
36075diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
36076index c689697..04e6d6a2 100644
36077--- a/drivers/char/mwave/tp3780i.c
36078+++ b/drivers/char/mwave/tp3780i.c
36079@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
36080 PRINTK_2(TRACE_TP3780I,
36081 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
36082
36083+ memset(pAbilities, 0, sizeof(*pAbilities));
36084 /* fill out standard constant fields */
36085 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
36086 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
36087diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36088index 9df78e2..01ba9ae 100644
36089--- a/drivers/char/nvram.c
36090+++ b/drivers/char/nvram.c
36091@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36092
36093 spin_unlock_irq(&rtc_lock);
36094
36095- if (copy_to_user(buf, contents, tmp - contents))
36096+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36097 return -EFAULT;
36098
36099 *ppos = i;
36100diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36101index 5c5cc00..ac9edb7 100644
36102--- a/drivers/char/pcmcia/synclink_cs.c
36103+++ b/drivers/char/pcmcia/synclink_cs.c
36104@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36105
36106 if (debug_level >= DEBUG_LEVEL_INFO)
36107 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36108- __FILE__, __LINE__, info->device_name, port->count);
36109+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36110
36111- WARN_ON(!port->count);
36112+ WARN_ON(!atomic_read(&port->count));
36113
36114 if (tty_port_close_start(port, tty, filp) == 0)
36115 goto cleanup;
36116@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36117 cleanup:
36118 if (debug_level >= DEBUG_LEVEL_INFO)
36119 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36120- tty->driver->name, port->count);
36121+ tty->driver->name, atomic_read(&port->count));
36122 }
36123
36124 /* Wait until the transmitter is empty.
36125@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36126
36127 if (debug_level >= DEBUG_LEVEL_INFO)
36128 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36129- __FILE__, __LINE__, tty->driver->name, port->count);
36130+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36131
36132 /* If port is closing, signal caller to try again */
36133 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36134@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36135 goto cleanup;
36136 }
36137 spin_lock(&port->lock);
36138- port->count++;
36139+ atomic_inc(&port->count);
36140 spin_unlock(&port->lock);
36141 spin_unlock_irqrestore(&info->netlock, flags);
36142
36143- if (port->count == 1) {
36144+ if (atomic_read(&port->count) == 1) {
36145 /* 1st open on this device, init hardware */
36146 retval = startup(info, tty);
36147 if (retval < 0)
36148@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36149 unsigned short new_crctype;
36150
36151 /* return error if TTY interface open */
36152- if (info->port.count)
36153+ if (atomic_read(&info->port.count))
36154 return -EBUSY;
36155
36156 switch (encoding)
36157@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36158
36159 /* arbitrate between network and tty opens */
36160 spin_lock_irqsave(&info->netlock, flags);
36161- if (info->port.count != 0 || info->netcount != 0) {
36162+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36163 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36164 spin_unlock_irqrestore(&info->netlock, flags);
36165 return -EBUSY;
36166@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36167 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36168
36169 /* return error if TTY interface open */
36170- if (info->port.count)
36171+ if (atomic_read(&info->port.count))
36172 return -EBUSY;
36173
36174 if (cmd != SIOCWANDEV)
36175diff --git a/drivers/char/random.c b/drivers/char/random.c
36176index 35487e8..dac8bd1 100644
36177--- a/drivers/char/random.c
36178+++ b/drivers/char/random.c
36179@@ -272,8 +272,13 @@
36180 /*
36181 * Configuration information
36182 */
36183+#ifdef CONFIG_GRKERNSEC_RANDNET
36184+#define INPUT_POOL_WORDS 512
36185+#define OUTPUT_POOL_WORDS 128
36186+#else
36187 #define INPUT_POOL_WORDS 128
36188 #define OUTPUT_POOL_WORDS 32
36189+#endif
36190 #define SEC_XFER_SIZE 512
36191 #define EXTRACT_SIZE 10
36192
36193@@ -313,10 +318,17 @@ static struct poolinfo {
36194 int poolwords;
36195 int tap1, tap2, tap3, tap4, tap5;
36196 } poolinfo_table[] = {
36197+#ifdef CONFIG_GRKERNSEC_RANDNET
36198+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36199+ { 512, 411, 308, 208, 104, 1 },
36200+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36201+ { 128, 103, 76, 51, 25, 1 },
36202+#else
36203 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36204 { 128, 103, 76, 51, 25, 1 },
36205 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36206 { 32, 26, 20, 14, 7, 1 },
36207+#endif
36208 #if 0
36209 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36210 { 2048, 1638, 1231, 819, 411, 1 },
36211@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36212 input_rotate += i ? 7 : 14;
36213 }
36214
36215- ACCESS_ONCE(r->input_rotate) = input_rotate;
36216- ACCESS_ONCE(r->add_ptr) = i;
36217+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36218+ ACCESS_ONCE_RW(r->add_ptr) = i;
36219 smp_wmb();
36220
36221 if (out)
36222@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36223
36224 extract_buf(r, tmp);
36225 i = min_t(int, nbytes, EXTRACT_SIZE);
36226- if (copy_to_user(buf, tmp, i)) {
36227+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36228 ret = -EFAULT;
36229 break;
36230 }
36231@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36232 #include <linux/sysctl.h>
36233
36234 static int min_read_thresh = 8, min_write_thresh;
36235-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36236+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36237 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36238 static char sysctl_bootid[16];
36239
36240@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36241 static int proc_do_uuid(ctl_table *table, int write,
36242 void __user *buffer, size_t *lenp, loff_t *ppos)
36243 {
36244- ctl_table fake_table;
36245+ ctl_table_no_const fake_table;
36246 unsigned char buf[64], tmp_uuid[16], *uuid;
36247
36248 uuid = table->data;
36249diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36250index bf2349db..5456d53 100644
36251--- a/drivers/char/sonypi.c
36252+++ b/drivers/char/sonypi.c
36253@@ -54,6 +54,7 @@
36254
36255 #include <asm/uaccess.h>
36256 #include <asm/io.h>
36257+#include <asm/local.h>
36258
36259 #include <linux/sonypi.h>
36260
36261@@ -490,7 +491,7 @@ static struct sonypi_device {
36262 spinlock_t fifo_lock;
36263 wait_queue_head_t fifo_proc_list;
36264 struct fasync_struct *fifo_async;
36265- int open_count;
36266+ local_t open_count;
36267 int model;
36268 struct input_dev *input_jog_dev;
36269 struct input_dev *input_key_dev;
36270@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
36271 static int sonypi_misc_release(struct inode *inode, struct file *file)
36272 {
36273 mutex_lock(&sonypi_device.lock);
36274- sonypi_device.open_count--;
36275+ local_dec(&sonypi_device.open_count);
36276 mutex_unlock(&sonypi_device.lock);
36277 return 0;
36278 }
36279@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
36280 {
36281 mutex_lock(&sonypi_device.lock);
36282 /* Flush input queue on first open */
36283- if (!sonypi_device.open_count)
36284+ if (!local_read(&sonypi_device.open_count))
36285 kfifo_reset(&sonypi_device.fifo);
36286- sonypi_device.open_count++;
36287+ local_inc(&sonypi_device.open_count);
36288 mutex_unlock(&sonypi_device.lock);
36289
36290 return 0;
36291diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
36292index 64420b3..5c40b56 100644
36293--- a/drivers/char/tpm/tpm_acpi.c
36294+++ b/drivers/char/tpm/tpm_acpi.c
36295@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
36296 virt = acpi_os_map_memory(start, len);
36297 if (!virt) {
36298 kfree(log->bios_event_log);
36299+ log->bios_event_log = NULL;
36300 printk("%s: ERROR - Unable to map memory\n", __func__);
36301 return -EIO;
36302 }
36303
36304- memcpy_fromio(log->bios_event_log, virt, len);
36305+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
36306
36307 acpi_os_unmap_memory(virt, len);
36308 return 0;
36309diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
36310index 84ddc55..1d32f1e 100644
36311--- a/drivers/char/tpm/tpm_eventlog.c
36312+++ b/drivers/char/tpm/tpm_eventlog.c
36313@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
36314 event = addr;
36315
36316 if ((event->event_type == 0 && event->event_size == 0) ||
36317- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
36318+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
36319 return NULL;
36320
36321 return addr;
36322@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
36323 return NULL;
36324
36325 if ((event->event_type == 0 && event->event_size == 0) ||
36326- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
36327+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
36328 return NULL;
36329
36330 (*pos)++;
36331@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
36332 int i;
36333
36334 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
36335- seq_putc(m, data[i]);
36336+ if (!seq_putc(m, data[i]))
36337+ return -EFAULT;
36338
36339 return 0;
36340 }
36341diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
36342index fc45567..fa2a590 100644
36343--- a/drivers/char/virtio_console.c
36344+++ b/drivers/char/virtio_console.c
36345@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
36346 if (to_user) {
36347 ssize_t ret;
36348
36349- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
36350+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
36351 if (ret)
36352 return -EFAULT;
36353 } else {
36354@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
36355 if (!port_has_data(port) && !port->host_connected)
36356 return 0;
36357
36358- return fill_readbuf(port, ubuf, count, true);
36359+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
36360 }
36361
36362 static int wait_port_writable(struct port *port, bool nonblock)
36363diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
36364index a33f46f..a720eed 100644
36365--- a/drivers/clk/clk-composite.c
36366+++ b/drivers/clk/clk-composite.c
36367@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
36368 struct clk *clk;
36369 struct clk_init_data init;
36370 struct clk_composite *composite;
36371- struct clk_ops *clk_composite_ops;
36372+ clk_ops_no_const *clk_composite_ops;
36373
36374 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
36375 if (!composite) {
36376diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
36377index bd11315..7f87098 100644
36378--- a/drivers/clk/socfpga/clk.c
36379+++ b/drivers/clk/socfpga/clk.c
36380@@ -22,6 +22,7 @@
36381 #include <linux/clk-provider.h>
36382 #include <linux/io.h>
36383 #include <linux/of.h>
36384+#include <asm/pgtable.h>
36385
36386 /* Clock Manager offsets */
36387 #define CLKMGR_CTRL 0x0
36388@@ -135,8 +136,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
36389 if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") ||
36390 strcmp(clk_name, "sdram_pll")) {
36391 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
36392- clk_pll_ops.enable = clk_gate_ops.enable;
36393- clk_pll_ops.disable = clk_gate_ops.disable;
36394+ pax_open_kernel();
36395+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
36396+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
36397+ pax_close_kernel();
36398 }
36399
36400 clk = clk_register(NULL, &socfpga_clk->hw.hw);
36401diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
36402index a2b2541..bc1e7ff 100644
36403--- a/drivers/clocksource/arm_arch_timer.c
36404+++ b/drivers/clocksource/arm_arch_timer.c
36405@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
36406 return NOTIFY_OK;
36407 }
36408
36409-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
36410+static struct notifier_block arch_timer_cpu_nb = {
36411 .notifier_call = arch_timer_cpu_notify,
36412 };
36413
36414diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
36415index 350f493..489479e 100644
36416--- a/drivers/clocksource/bcm_kona_timer.c
36417+++ b/drivers/clocksource/bcm_kona_timer.c
36418@@ -199,7 +199,7 @@ static struct irqaction kona_timer_irq = {
36419 .handler = kona_timer_interrupt,
36420 };
36421
36422-static void __init kona_timer_init(void)
36423+static void __init kona_timer_init(struct device_node *np)
36424 {
36425 kona_timers_init();
36426 kona_timer_clockevents_init();
36427diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
36428index ade7513..069445f 100644
36429--- a/drivers/clocksource/metag_generic.c
36430+++ b/drivers/clocksource/metag_generic.c
36431@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
36432 return NOTIFY_OK;
36433 }
36434
36435-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
36436+static struct notifier_block arch_timer_cpu_nb = {
36437 .notifier_call = arch_timer_cpu_notify,
36438 };
36439
36440diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
36441index edc089e..bc7c0bc 100644
36442--- a/drivers/cpufreq/acpi-cpufreq.c
36443+++ b/drivers/cpufreq/acpi-cpufreq.c
36444@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
36445 return sprintf(buf, "%u\n", boost_enabled);
36446 }
36447
36448-static struct global_attr global_boost = __ATTR(boost, 0644,
36449+static global_attr_no_const global_boost = __ATTR(boost, 0644,
36450 show_global_boost,
36451 store_global_boost);
36452
36453@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
36454 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
36455 per_cpu(acfreq_data, cpu) = data;
36456
36457- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
36458- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
36459+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
36460+ pax_open_kernel();
36461+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
36462+ pax_close_kernel();
36463+ }
36464
36465 result = acpi_processor_register_performance(data->acpi_data, cpu);
36466 if (result)
36467@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
36468 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
36469 break;
36470 case ACPI_ADR_SPACE_FIXED_HARDWARE:
36471- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
36472+ pax_open_kernel();
36473+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
36474+ pax_close_kernel();
36475 policy->cur = get_cur_freq_on_cpu(cpu);
36476 break;
36477 default:
36478@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
36479 acpi_processor_notify_smm(THIS_MODULE);
36480
36481 /* Check for APERF/MPERF support in hardware */
36482- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
36483- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
36484+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
36485+ pax_open_kernel();
36486+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
36487+ pax_close_kernel();
36488+ }
36489
36490 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
36491 for (i = 0; i < perf->state_count; i++)
36492diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
36493index 6485547..477033e 100644
36494--- a/drivers/cpufreq/cpufreq.c
36495+++ b/drivers/cpufreq/cpufreq.c
36496@@ -1854,7 +1854,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
36497 return NOTIFY_OK;
36498 }
36499
36500-static struct notifier_block __refdata cpufreq_cpu_notifier = {
36501+static struct notifier_block cpufreq_cpu_notifier = {
36502 .notifier_call = cpufreq_cpu_callback,
36503 };
36504
36505@@ -1886,8 +1886,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
36506
36507 pr_debug("trying to register driver %s\n", driver_data->name);
36508
36509- if (driver_data->setpolicy)
36510- driver_data->flags |= CPUFREQ_CONST_LOOPS;
36511+ if (driver_data->setpolicy) {
36512+ pax_open_kernel();
36513+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
36514+ pax_close_kernel();
36515+ }
36516
36517 write_lock_irqsave(&cpufreq_driver_lock, flags);
36518 if (cpufreq_driver) {
36519diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
36520index a86ff72..aad2b03 100644
36521--- a/drivers/cpufreq/cpufreq_governor.c
36522+++ b/drivers/cpufreq/cpufreq_governor.c
36523@@ -235,7 +235,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
36524 struct dbs_data *dbs_data;
36525 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
36526 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
36527- struct od_ops *od_ops = NULL;
36528+ const struct od_ops *od_ops = NULL;
36529 struct od_dbs_tuners *od_tuners = NULL;
36530 struct cs_dbs_tuners *cs_tuners = NULL;
36531 struct cpu_dbs_common_info *cpu_cdbs;
36532@@ -298,7 +298,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
36533
36534 if ((cdata->governor == GOV_CONSERVATIVE) &&
36535 (!policy->governor->initialized)) {
36536- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
36537+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
36538
36539 cpufreq_register_notifier(cs_ops->notifier_block,
36540 CPUFREQ_TRANSITION_NOTIFIER);
36541@@ -315,7 +315,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
36542
36543 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
36544 (policy->governor->initialized == 1)) {
36545- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
36546+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
36547
36548 cpufreq_unregister_notifier(cs_ops->notifier_block,
36549 CPUFREQ_TRANSITION_NOTIFIER);
36550diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
36551index 0d9e6be..461fd3b 100644
36552--- a/drivers/cpufreq/cpufreq_governor.h
36553+++ b/drivers/cpufreq/cpufreq_governor.h
36554@@ -204,7 +204,7 @@ struct common_dbs_data {
36555 void (*exit)(struct dbs_data *dbs_data);
36556
36557 /* Governor specific ops, see below */
36558- void *gov_ops;
36559+ const void *gov_ops;
36560 };
36561
36562 /* Governer Per policy data */
36563diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
36564index c087347..dad6268 100644
36565--- a/drivers/cpufreq/cpufreq_ondemand.c
36566+++ b/drivers/cpufreq/cpufreq_ondemand.c
36567@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
36568 (struct cpufreq_policy *, unsigned int, unsigned int),
36569 unsigned int powersave_bias)
36570 {
36571- od_ops.powersave_bias_target = f;
36572+ pax_open_kernel();
36573+ *(void **)&od_ops.powersave_bias_target = f;
36574+ pax_close_kernel();
36575 od_set_powersave_bias(powersave_bias);
36576 }
36577 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
36578
36579 void od_unregister_powersave_bias_handler(void)
36580 {
36581- od_ops.powersave_bias_target = generic_powersave_bias_target;
36582+ pax_open_kernel();
36583+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
36584+ pax_close_kernel();
36585 od_set_powersave_bias(0);
36586 }
36587 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
36588diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
36589index bfd6273..e39dd63 100644
36590--- a/drivers/cpufreq/cpufreq_stats.c
36591+++ b/drivers/cpufreq/cpufreq_stats.c
36592@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
36593 }
36594
36595 /* priority=1 so this will get called before cpufreq_remove_dev */
36596-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
36597+static struct notifier_block cpufreq_stat_cpu_notifier = {
36598 .notifier_call = cpufreq_stat_cpu_callback,
36599 .priority = 1,
36600 };
36601diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
36602index 421ef37..e708530c 100644
36603--- a/drivers/cpufreq/p4-clockmod.c
36604+++ b/drivers/cpufreq/p4-clockmod.c
36605@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
36606 case 0x0F: /* Core Duo */
36607 case 0x16: /* Celeron Core */
36608 case 0x1C: /* Atom */
36609- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36610+ pax_open_kernel();
36611+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36612+ pax_close_kernel();
36613 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
36614 case 0x0D: /* Pentium M (Dothan) */
36615- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36616+ pax_open_kernel();
36617+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36618+ pax_close_kernel();
36619 /* fall through */
36620 case 0x09: /* Pentium M (Banias) */
36621 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
36622@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
36623
36624 /* on P-4s, the TSC runs with constant frequency independent whether
36625 * throttling is active or not. */
36626- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36627+ pax_open_kernel();
36628+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
36629+ pax_close_kernel();
36630
36631 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
36632 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
36633diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
36634index c71ee14..7c2e183 100644
36635--- a/drivers/cpufreq/sparc-us3-cpufreq.c
36636+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
36637@@ -18,14 +18,12 @@
36638 #include <asm/head.h>
36639 #include <asm/timer.h>
36640
36641-static struct cpufreq_driver *cpufreq_us3_driver;
36642-
36643 struct us3_freq_percpu_info {
36644 struct cpufreq_frequency_table table[4];
36645 };
36646
36647 /* Indexed by cpu number. */
36648-static struct us3_freq_percpu_info *us3_freq_table;
36649+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
36650
36651 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
36652 * in the Safari config register.
36653@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
36654
36655 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
36656 {
36657- if (cpufreq_us3_driver)
36658- us3_set_cpu_divider_index(policy, 0);
36659+ us3_set_cpu_divider_index(policy->cpu, 0);
36660
36661 return 0;
36662 }
36663
36664+static int __init us3_freq_init(void);
36665+static void __exit us3_freq_exit(void);
36666+
36667+static struct cpufreq_driver cpufreq_us3_driver = {
36668+ .init = us3_freq_cpu_init,
36669+ .verify = us3_freq_verify,
36670+ .target = us3_freq_target,
36671+ .get = us3_freq_get,
36672+ .exit = us3_freq_cpu_exit,
36673+ .owner = THIS_MODULE,
36674+ .name = "UltraSPARC-III",
36675+
36676+};
36677+
36678 static int __init us3_freq_init(void)
36679 {
36680 unsigned long manuf, impl, ver;
36681@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
36682 (impl == CHEETAH_IMPL ||
36683 impl == CHEETAH_PLUS_IMPL ||
36684 impl == JAGUAR_IMPL ||
36685- impl == PANTHER_IMPL)) {
36686- struct cpufreq_driver *driver;
36687-
36688- ret = -ENOMEM;
36689- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
36690- if (!driver)
36691- goto err_out;
36692-
36693- us3_freq_table = kzalloc(
36694- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
36695- GFP_KERNEL);
36696- if (!us3_freq_table)
36697- goto err_out;
36698-
36699- driver->init = us3_freq_cpu_init;
36700- driver->verify = us3_freq_verify;
36701- driver->target = us3_freq_target;
36702- driver->get = us3_freq_get;
36703- driver->exit = us3_freq_cpu_exit;
36704- driver->owner = THIS_MODULE,
36705- strcpy(driver->name, "UltraSPARC-III");
36706-
36707- cpufreq_us3_driver = driver;
36708- ret = cpufreq_register_driver(driver);
36709- if (ret)
36710- goto err_out;
36711-
36712- return 0;
36713-
36714-err_out:
36715- if (driver) {
36716- kfree(driver);
36717- cpufreq_us3_driver = NULL;
36718- }
36719- kfree(us3_freq_table);
36720- us3_freq_table = NULL;
36721- return ret;
36722- }
36723+ impl == PANTHER_IMPL))
36724+ return cpufreq_register_driver(&cpufreq_us3_driver);
36725
36726 return -ENODEV;
36727 }
36728
36729 static void __exit us3_freq_exit(void)
36730 {
36731- if (cpufreq_us3_driver) {
36732- cpufreq_unregister_driver(cpufreq_us3_driver);
36733- kfree(cpufreq_us3_driver);
36734- cpufreq_us3_driver = NULL;
36735- kfree(us3_freq_table);
36736- us3_freq_table = NULL;
36737- }
36738+ cpufreq_unregister_driver(&cpufreq_us3_driver);
36739 }
36740
36741 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
36742diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
36743index 618e6f4..e89d915 100644
36744--- a/drivers/cpufreq/speedstep-centrino.c
36745+++ b/drivers/cpufreq/speedstep-centrino.c
36746@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
36747 !cpu_has(cpu, X86_FEATURE_EST))
36748 return -ENODEV;
36749
36750- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
36751- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
36752+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
36753+ pax_open_kernel();
36754+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
36755+ pax_close_kernel();
36756+ }
36757
36758 if (policy->cpu != 0)
36759 return -ENODEV;
36760diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
36761index c3a93fe..e808f24 100644
36762--- a/drivers/cpuidle/cpuidle.c
36763+++ b/drivers/cpuidle/cpuidle.c
36764@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
36765
36766 static void poll_idle_init(struct cpuidle_driver *drv)
36767 {
36768- struct cpuidle_state *state = &drv->states[0];
36769+ cpuidle_state_no_const *state = &drv->states[0];
36770
36771 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
36772 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
36773diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
36774index ea2f8e7..70ac501 100644
36775--- a/drivers/cpuidle/governor.c
36776+++ b/drivers/cpuidle/governor.c
36777@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
36778 mutex_lock(&cpuidle_lock);
36779 if (__cpuidle_find_governor(gov->name) == NULL) {
36780 ret = 0;
36781- list_add_tail(&gov->governor_list, &cpuidle_governors);
36782+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
36783 if (!cpuidle_curr_governor ||
36784 cpuidle_curr_governor->rating < gov->rating)
36785 cpuidle_switch_governor(gov);
36786@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
36787 new_gov = cpuidle_replace_governor(gov->rating);
36788 cpuidle_switch_governor(new_gov);
36789 }
36790- list_del(&gov->governor_list);
36791+ pax_list_del((struct list_head *)&gov->governor_list);
36792 mutex_unlock(&cpuidle_lock);
36793 }
36794
36795diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
36796index 428754a..8bdf9cc 100644
36797--- a/drivers/cpuidle/sysfs.c
36798+++ b/drivers/cpuidle/sysfs.c
36799@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
36800 NULL
36801 };
36802
36803-static struct attribute_group cpuidle_attr_group = {
36804+static attribute_group_no_const cpuidle_attr_group = {
36805 .attrs = cpuidle_default_attrs,
36806 .name = "cpuidle",
36807 };
36808diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
36809index 3b36797..db0b0c0 100644
36810--- a/drivers/devfreq/devfreq.c
36811+++ b/drivers/devfreq/devfreq.c
36812@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
36813 GFP_KERNEL);
36814 devfreq->last_stat_updated = jiffies;
36815
36816- dev_set_name(&devfreq->dev, dev_name(dev));
36817+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
36818 err = device_register(&devfreq->dev);
36819 if (err) {
36820 put_device(&devfreq->dev);
36821@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
36822 goto err_out;
36823 }
36824
36825- list_add(&governor->node, &devfreq_governor_list);
36826+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
36827
36828 list_for_each_entry(devfreq, &devfreq_list, node) {
36829 int ret = 0;
36830@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
36831 }
36832 }
36833
36834- list_del(&governor->node);
36835+ pax_list_del((struct list_head *)&governor->node);
36836 err_out:
36837 mutex_unlock(&devfreq_list_lock);
36838
36839diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
36840index b70709b..1d8d02a 100644
36841--- a/drivers/dma/sh/shdma.c
36842+++ b/drivers/dma/sh/shdma.c
36843@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
36844 return ret;
36845 }
36846
36847-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
36848+static struct notifier_block sh_dmae_nmi_notifier = {
36849 .notifier_call = sh_dmae_nmi_handler,
36850
36851 /* Run before NMI debug handler and KGDB */
36852diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
36853index c4d700a..0b57abd 100644
36854--- a/drivers/edac/edac_mc_sysfs.c
36855+++ b/drivers/edac/edac_mc_sysfs.c
36856@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
36857 struct dev_ch_attribute {
36858 struct device_attribute attr;
36859 int channel;
36860-};
36861+} __do_const;
36862
36863 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
36864 struct dev_ch_attribute dev_attr_legacy_##_name = \
36865@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
36866 }
36867
36868 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
36869+ pax_open_kernel();
36870 if (mci->get_sdram_scrub_rate) {
36871- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
36872- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
36873+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
36874+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
36875 }
36876 if (mci->set_sdram_scrub_rate) {
36877- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
36878- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
36879+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
36880+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
36881 }
36882+ pax_close_kernel();
36883 err = device_create_file(&mci->dev,
36884 &dev_attr_sdram_scrub_rate);
36885 if (err) {
36886diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
36887index e8658e4..22746d6 100644
36888--- a/drivers/edac/edac_pci_sysfs.c
36889+++ b/drivers/edac/edac_pci_sysfs.c
36890@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
36891 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
36892 static int edac_pci_poll_msec = 1000; /* one second workq period */
36893
36894-static atomic_t pci_parity_count = ATOMIC_INIT(0);
36895-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
36896+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
36897+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
36898
36899 static struct kobject *edac_pci_top_main_kobj;
36900 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
36901@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
36902 void *value;
36903 ssize_t(*show) (void *, char *);
36904 ssize_t(*store) (void *, const char *, size_t);
36905-};
36906+} __do_const;
36907
36908 /* Set of show/store abstract level functions for PCI Parity object */
36909 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
36910@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36911 edac_printk(KERN_CRIT, EDAC_PCI,
36912 "Signaled System Error on %s\n",
36913 pci_name(dev));
36914- atomic_inc(&pci_nonparity_count);
36915+ atomic_inc_unchecked(&pci_nonparity_count);
36916 }
36917
36918 if (status & (PCI_STATUS_PARITY)) {
36919@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36920 "Master Data Parity Error on %s\n",
36921 pci_name(dev));
36922
36923- atomic_inc(&pci_parity_count);
36924+ atomic_inc_unchecked(&pci_parity_count);
36925 }
36926
36927 if (status & (PCI_STATUS_DETECTED_PARITY)) {
36928@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36929 "Detected Parity Error on %s\n",
36930 pci_name(dev));
36931
36932- atomic_inc(&pci_parity_count);
36933+ atomic_inc_unchecked(&pci_parity_count);
36934 }
36935 }
36936
36937@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36938 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
36939 "Signaled System Error on %s\n",
36940 pci_name(dev));
36941- atomic_inc(&pci_nonparity_count);
36942+ atomic_inc_unchecked(&pci_nonparity_count);
36943 }
36944
36945 if (status & (PCI_STATUS_PARITY)) {
36946@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36947 "Master Data Parity Error on "
36948 "%s\n", pci_name(dev));
36949
36950- atomic_inc(&pci_parity_count);
36951+ atomic_inc_unchecked(&pci_parity_count);
36952 }
36953
36954 if (status & (PCI_STATUS_DETECTED_PARITY)) {
36955@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
36956 "Detected Parity Error on %s\n",
36957 pci_name(dev));
36958
36959- atomic_inc(&pci_parity_count);
36960+ atomic_inc_unchecked(&pci_parity_count);
36961 }
36962 }
36963 }
36964@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
36965 if (!check_pci_errors)
36966 return;
36967
36968- before_count = atomic_read(&pci_parity_count);
36969+ before_count = atomic_read_unchecked(&pci_parity_count);
36970
36971 /* scan all PCI devices looking for a Parity Error on devices and
36972 * bridges.
36973@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
36974 /* Only if operator has selected panic on PCI Error */
36975 if (edac_pci_get_panic_on_pe()) {
36976 /* If the count is different 'after' from 'before' */
36977- if (before_count != atomic_read(&pci_parity_count))
36978+ if (before_count != atomic_read_unchecked(&pci_parity_count))
36979 panic("EDAC: PCI Parity Error");
36980 }
36981 }
36982diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
36983index 51b7e3a..aa8a3e8 100644
36984--- a/drivers/edac/mce_amd.h
36985+++ b/drivers/edac/mce_amd.h
36986@@ -77,7 +77,7 @@ struct amd_decoder_ops {
36987 bool (*mc0_mce)(u16, u8);
36988 bool (*mc1_mce)(u16, u8);
36989 bool (*mc2_mce)(u16, u8);
36990-};
36991+} __no_const;
36992
36993 void amd_report_gart_errors(bool);
36994 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
36995diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
36996index 57ea7f4..789e3c3 100644
36997--- a/drivers/firewire/core-card.c
36998+++ b/drivers/firewire/core-card.c
36999@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37000
37001 void fw_core_remove_card(struct fw_card *card)
37002 {
37003- struct fw_card_driver dummy_driver = dummy_driver_template;
37004+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37005
37006 card->driver->update_phy_reg(card, 4,
37007 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37008diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37009index 664a6ff..af13580 100644
37010--- a/drivers/firewire/core-device.c
37011+++ b/drivers/firewire/core-device.c
37012@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37013 struct config_rom_attribute {
37014 struct device_attribute attr;
37015 u32 key;
37016-};
37017+} __do_const;
37018
37019 static ssize_t show_immediate(struct device *dev,
37020 struct device_attribute *dattr, char *buf)
37021diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37022index 28a94c7..58da63a 100644
37023--- a/drivers/firewire/core-transaction.c
37024+++ b/drivers/firewire/core-transaction.c
37025@@ -38,6 +38,7 @@
37026 #include <linux/timer.h>
37027 #include <linux/types.h>
37028 #include <linux/workqueue.h>
37029+#include <linux/sched.h>
37030
37031 #include <asm/byteorder.h>
37032
37033diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37034index 515a42c..5ecf3ba 100644
37035--- a/drivers/firewire/core.h
37036+++ b/drivers/firewire/core.h
37037@@ -111,6 +111,7 @@ struct fw_card_driver {
37038
37039 int (*stop_iso)(struct fw_iso_context *ctx);
37040 };
37041+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37042
37043 void fw_card_initialize(struct fw_card *card,
37044 const struct fw_card_driver *driver, struct device *device);
37045diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37046index 94a58a0..f5eba42 100644
37047--- a/drivers/firmware/dmi-id.c
37048+++ b/drivers/firmware/dmi-id.c
37049@@ -16,7 +16,7 @@
37050 struct dmi_device_attribute{
37051 struct device_attribute dev_attr;
37052 int field;
37053-};
37054+} __do_const;
37055 #define to_dmi_dev_attr(_dev_attr) \
37056 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37057
37058diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37059index b95159b..841ae55 100644
37060--- a/drivers/firmware/dmi_scan.c
37061+++ b/drivers/firmware/dmi_scan.c
37062@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
37063 }
37064 }
37065 else {
37066- /*
37067- * no iounmap() for that ioremap(); it would be a no-op, but
37068- * it's so early in setup that sucker gets confused into doing
37069- * what it shouldn't if we actually call it.
37070- */
37071 p = dmi_ioremap(0xF0000, 0x10000);
37072 if (p == NULL)
37073 goto error;
37074@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37075 if (buf == NULL)
37076 return -1;
37077
37078- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37079+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37080
37081 iounmap(buf);
37082 return 0;
37083diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37084index 5145fa3..0d3babd 100644
37085--- a/drivers/firmware/efi/efi.c
37086+++ b/drivers/firmware/efi/efi.c
37087@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37088 };
37089
37090 static struct efivars generic_efivars;
37091-static struct efivar_operations generic_ops;
37092+static efivar_operations_no_const generic_ops __read_only;
37093
37094 static int generic_ops_register(void)
37095 {
37096- generic_ops.get_variable = efi.get_variable;
37097- generic_ops.set_variable = efi.set_variable;
37098- generic_ops.get_next_variable = efi.get_next_variable;
37099- generic_ops.query_variable_store = efi_query_variable_store;
37100+ pax_open_kernel();
37101+ *(void **)&generic_ops.get_variable = efi.get_variable;
37102+ *(void **)&generic_ops.set_variable = efi.set_variable;
37103+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37104+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37105+ pax_close_kernel();
37106
37107 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37108 }
37109diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37110index 8bd1bb6..c48b0c6 100644
37111--- a/drivers/firmware/efi/efivars.c
37112+++ b/drivers/firmware/efi/efivars.c
37113@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37114 static int
37115 create_efivars_bin_attributes(void)
37116 {
37117- struct bin_attribute *attr;
37118+ bin_attribute_no_const *attr;
37119 int error;
37120
37121 /* new_var */
37122diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37123index 2a90ba6..07f3733 100644
37124--- a/drivers/firmware/google/memconsole.c
37125+++ b/drivers/firmware/google/memconsole.c
37126@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37127 if (!found_memconsole())
37128 return -ENODEV;
37129
37130- memconsole_bin_attr.size = memconsole_length;
37131+ pax_open_kernel();
37132+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37133+ pax_close_kernel();
37134
37135 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37136
37137diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37138index e16d932..f0206ef 100644
37139--- a/drivers/gpio/gpio-ich.c
37140+++ b/drivers/gpio/gpio-ich.c
37141@@ -69,7 +69,7 @@ struct ichx_desc {
37142 /* Some chipsets have quirks, let these use their own request/get */
37143 int (*request)(struct gpio_chip *chip, unsigned offset);
37144 int (*get)(struct gpio_chip *chip, unsigned offset);
37145-};
37146+} __do_const;
37147
37148 static struct {
37149 spinlock_t lock;
37150diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37151index 9902732..64b62dd 100644
37152--- a/drivers/gpio/gpio-vr41xx.c
37153+++ b/drivers/gpio/gpio-vr41xx.c
37154@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37155 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37156 maskl, pendl, maskh, pendh);
37157
37158- atomic_inc(&irq_err_count);
37159+ atomic_inc_unchecked(&irq_err_count);
37160
37161 return -EINVAL;
37162 }
37163diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37164index ed1334e..ee0dd42 100644
37165--- a/drivers/gpu/drm/drm_crtc_helper.c
37166+++ b/drivers/gpu/drm/drm_crtc_helper.c
37167@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37168 struct drm_crtc *tmp;
37169 int crtc_mask = 1;
37170
37171- WARN(!crtc, "checking null crtc?\n");
37172+ BUG_ON(!crtc);
37173
37174 dev = crtc->dev;
37175
37176diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37177index 9cc247f..36aa285 100644
37178--- a/drivers/gpu/drm/drm_drv.c
37179+++ b/drivers/gpu/drm/drm_drv.c
37180@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
37181 /**
37182 * Copy and IOCTL return string to user space
37183 */
37184-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37185+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37186 {
37187 int len;
37188
37189@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
37190 struct drm_file *file_priv = filp->private_data;
37191 struct drm_device *dev;
37192 const struct drm_ioctl_desc *ioctl = NULL;
37193- drm_ioctl_t *func;
37194+ drm_ioctl_no_const_t func;
37195 unsigned int nr = DRM_IOCTL_NR(cmd);
37196 int retcode = -EINVAL;
37197 char stack_kdata[128];
37198@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
37199 return -ENODEV;
37200
37201 atomic_inc(&dev->ioctl_count);
37202- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37203+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37204 ++file_priv->ioctl_count;
37205
37206 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37207diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37208index 429e07d..e681a2c 100644
37209--- a/drivers/gpu/drm/drm_fops.c
37210+++ b/drivers/gpu/drm/drm_fops.c
37211@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
37212 }
37213
37214 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37215- atomic_set(&dev->counts[i], 0);
37216+ atomic_set_unchecked(&dev->counts[i], 0);
37217
37218 dev->sigdata.lock = NULL;
37219
37220@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
37221 if (drm_device_is_unplugged(dev))
37222 return -ENODEV;
37223
37224- if (!dev->open_count++)
37225+ if (local_inc_return(&dev->open_count) == 1)
37226 need_setup = 1;
37227 mutex_lock(&dev->struct_mutex);
37228 old_imapping = inode->i_mapping;
37229@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
37230 retcode = drm_open_helper(inode, filp, dev);
37231 if (retcode)
37232 goto err_undo;
37233- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
37234+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
37235 if (need_setup) {
37236 retcode = drm_setup(dev);
37237 if (retcode)
37238@@ -166,7 +166,7 @@ err_undo:
37239 iput(container_of(dev->dev_mapping, struct inode, i_data));
37240 dev->dev_mapping = old_mapping;
37241 mutex_unlock(&dev->struct_mutex);
37242- dev->open_count--;
37243+ local_dec(&dev->open_count);
37244 return retcode;
37245 }
37246 EXPORT_SYMBOL(drm_open);
37247@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
37248
37249 mutex_lock(&drm_global_mutex);
37250
37251- DRM_DEBUG("open_count = %d\n", dev->open_count);
37252+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
37253
37254 if (dev->driver->preclose)
37255 dev->driver->preclose(dev, file_priv);
37256@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
37257 * Begin inline drm_release
37258 */
37259
37260- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
37261+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
37262 task_pid_nr(current),
37263 (long)old_encode_dev(file_priv->minor->device),
37264- dev->open_count);
37265+ local_read(&dev->open_count));
37266
37267 /* Release any auth tokens that might point to this file_priv,
37268 (do that under the drm_global_mutex) */
37269@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
37270 * End inline drm_release
37271 */
37272
37273- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
37274- if (!--dev->open_count) {
37275+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
37276+ if (local_dec_and_test(&dev->open_count)) {
37277 if (atomic_read(&dev->ioctl_count)) {
37278 DRM_ERROR("Device busy: %d\n",
37279 atomic_read(&dev->ioctl_count));
37280diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
37281index f731116..629842c 100644
37282--- a/drivers/gpu/drm/drm_global.c
37283+++ b/drivers/gpu/drm/drm_global.c
37284@@ -36,7 +36,7 @@
37285 struct drm_global_item {
37286 struct mutex mutex;
37287 void *object;
37288- int refcount;
37289+ atomic_t refcount;
37290 };
37291
37292 static struct drm_global_item glob[DRM_GLOBAL_NUM];
37293@@ -49,7 +49,7 @@ void drm_global_init(void)
37294 struct drm_global_item *item = &glob[i];
37295 mutex_init(&item->mutex);
37296 item->object = NULL;
37297- item->refcount = 0;
37298+ atomic_set(&item->refcount, 0);
37299 }
37300 }
37301
37302@@ -59,7 +59,7 @@ void drm_global_release(void)
37303 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
37304 struct drm_global_item *item = &glob[i];
37305 BUG_ON(item->object != NULL);
37306- BUG_ON(item->refcount != 0);
37307+ BUG_ON(atomic_read(&item->refcount) != 0);
37308 }
37309 }
37310
37311@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
37312 void *object;
37313
37314 mutex_lock(&item->mutex);
37315- if (item->refcount == 0) {
37316+ if (atomic_read(&item->refcount) == 0) {
37317 item->object = kzalloc(ref->size, GFP_KERNEL);
37318 if (unlikely(item->object == NULL)) {
37319 ret = -ENOMEM;
37320@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
37321 goto out_err;
37322
37323 }
37324- ++item->refcount;
37325+ atomic_inc(&item->refcount);
37326 ref->object = item->object;
37327 object = item->object;
37328 mutex_unlock(&item->mutex);
37329@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
37330 struct drm_global_item *item = &glob[ref->global_type];
37331
37332 mutex_lock(&item->mutex);
37333- BUG_ON(item->refcount == 0);
37334+ BUG_ON(atomic_read(&item->refcount) == 0);
37335 BUG_ON(ref->object != item->object);
37336- if (--item->refcount == 0) {
37337+ if (atomic_dec_and_test(&item->refcount)) {
37338 ref->release(ref);
37339 item->object = NULL;
37340 }
37341diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
37342index d4b20ce..77a8d41 100644
37343--- a/drivers/gpu/drm/drm_info.c
37344+++ b/drivers/gpu/drm/drm_info.c
37345@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
37346 struct drm_local_map *map;
37347 struct drm_map_list *r_list;
37348
37349- /* Hardcoded from _DRM_FRAME_BUFFER,
37350- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
37351- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
37352- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
37353+ static const char * const types[] = {
37354+ [_DRM_FRAME_BUFFER] = "FB",
37355+ [_DRM_REGISTERS] = "REG",
37356+ [_DRM_SHM] = "SHM",
37357+ [_DRM_AGP] = "AGP",
37358+ [_DRM_SCATTER_GATHER] = "SG",
37359+ [_DRM_CONSISTENT] = "PCI",
37360+ [_DRM_GEM] = "GEM" };
37361 const char *type;
37362 int i;
37363
37364@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
37365 map = r_list->map;
37366 if (!map)
37367 continue;
37368- if (map->type < 0 || map->type > 5)
37369+ if (map->type >= ARRAY_SIZE(types))
37370 type = "??";
37371 else
37372 type = types[map->type];
37373@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
37374 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
37375 vma->vm_flags & VM_LOCKED ? 'l' : '-',
37376 vma->vm_flags & VM_IO ? 'i' : '-',
37377+#ifdef CONFIG_GRKERNSEC_HIDESYM
37378+ 0);
37379+#else
37380 vma->vm_pgoff);
37381+#endif
37382
37383 #if defined(__i386__)
37384 pgprot = pgprot_val(vma->vm_page_prot);
37385diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
37386index 2f4c434..dd12cd2 100644
37387--- a/drivers/gpu/drm/drm_ioc32.c
37388+++ b/drivers/gpu/drm/drm_ioc32.c
37389@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
37390 request = compat_alloc_user_space(nbytes);
37391 if (!access_ok(VERIFY_WRITE, request, nbytes))
37392 return -EFAULT;
37393- list = (struct drm_buf_desc *) (request + 1);
37394+ list = (struct drm_buf_desc __user *) (request + 1);
37395
37396 if (__put_user(count, &request->count)
37397 || __put_user(list, &request->list))
37398@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
37399 request = compat_alloc_user_space(nbytes);
37400 if (!access_ok(VERIFY_WRITE, request, nbytes))
37401 return -EFAULT;
37402- list = (struct drm_buf_pub *) (request + 1);
37403+ list = (struct drm_buf_pub __user *) (request + 1);
37404
37405 if (__put_user(count, &request->count)
37406 || __put_user(list, &request->list))
37407@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
37408 return 0;
37409 }
37410
37411-drm_ioctl_compat_t *drm_compat_ioctls[] = {
37412+drm_ioctl_compat_t drm_compat_ioctls[] = {
37413 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
37414 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
37415 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
37416@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
37417 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
37418 {
37419 unsigned int nr = DRM_IOCTL_NR(cmd);
37420- drm_ioctl_compat_t *fn;
37421 int ret;
37422
37423 /* Assume that ioctls without an explicit compat routine will just
37424@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
37425 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
37426 return drm_ioctl(filp, cmd, arg);
37427
37428- fn = drm_compat_ioctls[nr];
37429-
37430- if (fn != NULL)
37431- ret = (*fn) (filp, cmd, arg);
37432+ if (drm_compat_ioctls[nr] != NULL)
37433+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
37434 else
37435 ret = drm_ioctl(filp, cmd, arg);
37436
37437diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
37438index e77bd8b..1571b85 100644
37439--- a/drivers/gpu/drm/drm_ioctl.c
37440+++ b/drivers/gpu/drm/drm_ioctl.c
37441@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
37442 stats->data[i].value =
37443 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
37444 else
37445- stats->data[i].value = atomic_read(&dev->counts[i]);
37446+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
37447 stats->data[i].type = dev->types[i];
37448 }
37449
37450diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
37451index d752c96..fe08455 100644
37452--- a/drivers/gpu/drm/drm_lock.c
37453+++ b/drivers/gpu/drm/drm_lock.c
37454@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
37455 if (drm_lock_take(&master->lock, lock->context)) {
37456 master->lock.file_priv = file_priv;
37457 master->lock.lock_time = jiffies;
37458- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
37459+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
37460 break; /* Got lock */
37461 }
37462
37463@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
37464 return -EINVAL;
37465 }
37466
37467- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
37468+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
37469
37470 if (drm_lock_free(&master->lock, lock->context)) {
37471 /* FIXME: Should really bail out here. */
37472diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
37473index 16f3ec5..b28f9ca 100644
37474--- a/drivers/gpu/drm/drm_stub.c
37475+++ b/drivers/gpu/drm/drm_stub.c
37476@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
37477
37478 drm_device_set_unplugged(dev);
37479
37480- if (dev->open_count == 0) {
37481+ if (local_read(&dev->open_count) == 0) {
37482 drm_put_dev(dev);
37483 }
37484 mutex_unlock(&drm_global_mutex);
37485diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
37486index 0229665..f61329c 100644
37487--- a/drivers/gpu/drm/drm_sysfs.c
37488+++ b/drivers/gpu/drm/drm_sysfs.c
37489@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
37490 int drm_sysfs_device_add(struct drm_minor *minor)
37491 {
37492 int err;
37493- char *minor_str;
37494+ const char *minor_str;
37495
37496 minor->kdev.parent = minor->dev->dev;
37497
37498diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
37499index 004ecdf..db1f6e0 100644
37500--- a/drivers/gpu/drm/i810/i810_dma.c
37501+++ b/drivers/gpu/drm/i810/i810_dma.c
37502@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
37503 dma->buflist[vertex->idx],
37504 vertex->discard, vertex->used);
37505
37506- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
37507- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
37508+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
37509+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
37510 sarea_priv->last_enqueue = dev_priv->counter - 1;
37511 sarea_priv->last_dispatch = (int)hw_status[5];
37512
37513@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
37514 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
37515 mc->last_render);
37516
37517- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
37518- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
37519+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
37520+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
37521 sarea_priv->last_enqueue = dev_priv->counter - 1;
37522 sarea_priv->last_dispatch = (int)hw_status[5];
37523
37524diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
37525index 6e0acad..93c8289 100644
37526--- a/drivers/gpu/drm/i810/i810_drv.h
37527+++ b/drivers/gpu/drm/i810/i810_drv.h
37528@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
37529 int page_flipping;
37530
37531 wait_queue_head_t irq_queue;
37532- atomic_t irq_received;
37533- atomic_t irq_emitted;
37534+ atomic_unchecked_t irq_received;
37535+ atomic_unchecked_t irq_emitted;
37536
37537 int front_offset;
37538 } drm_i810_private_t;
37539diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
37540index e913d32..4d9b351 100644
37541--- a/drivers/gpu/drm/i915/i915_debugfs.c
37542+++ b/drivers/gpu/drm/i915/i915_debugfs.c
37543@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
37544 I915_READ(GTIMR));
37545 }
37546 seq_printf(m, "Interrupts received: %d\n",
37547- atomic_read(&dev_priv->irq_received));
37548+ atomic_read_unchecked(&dev_priv->irq_received));
37549 for_each_ring(ring, dev_priv, i) {
37550 if (IS_GEN6(dev) || IS_GEN7(dev)) {
37551 seq_printf(m,
37552diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
37553index 17d9b0b..860e6d9 100644
37554--- a/drivers/gpu/drm/i915/i915_dma.c
37555+++ b/drivers/gpu/drm/i915/i915_dma.c
37556@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
37557 bool can_switch;
37558
37559 spin_lock(&dev->count_lock);
37560- can_switch = (dev->open_count == 0);
37561+ can_switch = (local_read(&dev->open_count) == 0);
37562 spin_unlock(&dev->count_lock);
37563 return can_switch;
37564 }
37565diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
37566index 47d8b68..52f5d8d 100644
37567--- a/drivers/gpu/drm/i915/i915_drv.h
37568+++ b/drivers/gpu/drm/i915/i915_drv.h
37569@@ -916,7 +916,7 @@ typedef struct drm_i915_private {
37570 drm_dma_handle_t *status_page_dmah;
37571 struct resource mch_res;
37572
37573- atomic_t irq_received;
37574+ atomic_unchecked_t irq_received;
37575
37576 /* protects the irq masks */
37577 spinlock_t irq_lock;
37578@@ -1813,7 +1813,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
37579 struct drm_i915_private *dev_priv, unsigned port);
37580 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
37581 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
37582-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
37583+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
37584 {
37585 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
37586 }
37587diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
37588index 117ce38..eefd237 100644
37589--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
37590+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
37591@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
37592
37593 static int
37594 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
37595- int count)
37596+ unsigned int count)
37597 {
37598- int i;
37599+ unsigned int i;
37600 int relocs_total = 0;
37601 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
37602
37603diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
37604index 3c59584..500f2e9 100644
37605--- a/drivers/gpu/drm/i915/i915_ioc32.c
37606+++ b/drivers/gpu/drm/i915/i915_ioc32.c
37607@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
37608 (unsigned long)request);
37609 }
37610
37611-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
37612+static drm_ioctl_compat_t i915_compat_ioctls[] = {
37613 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
37614 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
37615 [DRM_I915_GETPARAM] = compat_i915_getparam,
37616@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
37617 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
37618 {
37619 unsigned int nr = DRM_IOCTL_NR(cmd);
37620- drm_ioctl_compat_t *fn = NULL;
37621 int ret;
37622
37623 if (nr < DRM_COMMAND_BASE)
37624 return drm_compat_ioctl(filp, cmd, arg);
37625
37626- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
37627- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
37628-
37629- if (fn != NULL)
37630+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
37631+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
37632 ret = (*fn) (filp, cmd, arg);
37633- else
37634+ } else
37635 ret = drm_ioctl(filp, cmd, arg);
37636
37637 return ret;
37638diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
37639index e5e32869..1678f36 100644
37640--- a/drivers/gpu/drm/i915/i915_irq.c
37641+++ b/drivers/gpu/drm/i915/i915_irq.c
37642@@ -670,7 +670,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
37643 int pipe;
37644 u32 pipe_stats[I915_MAX_PIPES];
37645
37646- atomic_inc(&dev_priv->irq_received);
37647+ atomic_inc_unchecked(&dev_priv->irq_received);
37648
37649 while (true) {
37650 iir = I915_READ(VLV_IIR);
37651@@ -835,7 +835,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
37652 irqreturn_t ret = IRQ_NONE;
37653 int i;
37654
37655- atomic_inc(&dev_priv->irq_received);
37656+ atomic_inc_unchecked(&dev_priv->irq_received);
37657
37658 /* disable master interrupt before clearing iir */
37659 de_ier = I915_READ(DEIER);
37660@@ -925,7 +925,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
37661 int ret = IRQ_NONE;
37662 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
37663
37664- atomic_inc(&dev_priv->irq_received);
37665+ atomic_inc_unchecked(&dev_priv->irq_received);
37666
37667 /* disable master interrupt before clearing iir */
37668 de_ier = I915_READ(DEIER);
37669@@ -2089,7 +2089,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
37670 {
37671 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
37672
37673- atomic_set(&dev_priv->irq_received, 0);
37674+ atomic_set_unchecked(&dev_priv->irq_received, 0);
37675
37676 I915_WRITE(HWSTAM, 0xeffe);
37677
37678@@ -2124,7 +2124,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
37679 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
37680 int pipe;
37681
37682- atomic_set(&dev_priv->irq_received, 0);
37683+ atomic_set_unchecked(&dev_priv->irq_received, 0);
37684
37685 /* VLV magic */
37686 I915_WRITE(VLV_IMR, 0);
37687@@ -2411,7 +2411,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
37688 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
37689 int pipe;
37690
37691- atomic_set(&dev_priv->irq_received, 0);
37692+ atomic_set_unchecked(&dev_priv->irq_received, 0);
37693
37694 for_each_pipe(pipe)
37695 I915_WRITE(PIPESTAT(pipe), 0);
37696@@ -2490,7 +2490,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
37697 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
37698 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
37699
37700- atomic_inc(&dev_priv->irq_received);
37701+ atomic_inc_unchecked(&dev_priv->irq_received);
37702
37703 iir = I915_READ16(IIR);
37704 if (iir == 0)
37705@@ -2565,7 +2565,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
37706 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
37707 int pipe;
37708
37709- atomic_set(&dev_priv->irq_received, 0);
37710+ atomic_set_unchecked(&dev_priv->irq_received, 0);
37711
37712 if (I915_HAS_HOTPLUG(dev)) {
37713 I915_WRITE(PORT_HOTPLUG_EN, 0);
37714@@ -2664,7 +2664,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
37715 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
37716 int pipe, ret = IRQ_NONE;
37717
37718- atomic_inc(&dev_priv->irq_received);
37719+ atomic_inc_unchecked(&dev_priv->irq_received);
37720
37721 iir = I915_READ(IIR);
37722 do {
37723@@ -2791,7 +2791,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
37724 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
37725 int pipe;
37726
37727- atomic_set(&dev_priv->irq_received, 0);
37728+ atomic_set_unchecked(&dev_priv->irq_received, 0);
37729
37730 I915_WRITE(PORT_HOTPLUG_EN, 0);
37731 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
37732@@ -2898,7 +2898,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
37733 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
37734 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
37735
37736- atomic_inc(&dev_priv->irq_received);
37737+ atomic_inc_unchecked(&dev_priv->irq_received);
37738
37739 iir = I915_READ(IIR);
37740
37741diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
37742index eea5982..eeef407 100644
37743--- a/drivers/gpu/drm/i915/intel_display.c
37744+++ b/drivers/gpu/drm/i915/intel_display.c
37745@@ -8935,13 +8935,13 @@ struct intel_quirk {
37746 int subsystem_vendor;
37747 int subsystem_device;
37748 void (*hook)(struct drm_device *dev);
37749-};
37750+} __do_const;
37751
37752 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
37753 struct intel_dmi_quirk {
37754 void (*hook)(struct drm_device *dev);
37755 const struct dmi_system_id (*dmi_id_list)[];
37756-};
37757+} __do_const;
37758
37759 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
37760 {
37761@@ -8949,18 +8949,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
37762 return 1;
37763 }
37764
37765-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
37766+static const struct dmi_system_id intel_dmi_quirks_table[] = {
37767 {
37768- .dmi_id_list = &(const struct dmi_system_id[]) {
37769- {
37770- .callback = intel_dmi_reverse_brightness,
37771- .ident = "NCR Corporation",
37772- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
37773- DMI_MATCH(DMI_PRODUCT_NAME, ""),
37774- },
37775- },
37776- { } /* terminating entry */
37777+ .callback = intel_dmi_reverse_brightness,
37778+ .ident = "NCR Corporation",
37779+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
37780+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
37781 },
37782+ },
37783+ { } /* terminating entry */
37784+};
37785+
37786+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
37787+ {
37788+ .dmi_id_list = &intel_dmi_quirks_table,
37789 .hook = quirk_invert_brightness,
37790 },
37791 };
37792diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
37793index 54558a0..2d97005 100644
37794--- a/drivers/gpu/drm/mga/mga_drv.h
37795+++ b/drivers/gpu/drm/mga/mga_drv.h
37796@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
37797 u32 clear_cmd;
37798 u32 maccess;
37799
37800- atomic_t vbl_received; /**< Number of vblanks received. */
37801+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
37802 wait_queue_head_t fence_queue;
37803- atomic_t last_fence_retired;
37804+ atomic_unchecked_t last_fence_retired;
37805 u32 next_fence_to_post;
37806
37807 unsigned int fb_cpp;
37808diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
37809index 709e90d..89a1c0d 100644
37810--- a/drivers/gpu/drm/mga/mga_ioc32.c
37811+++ b/drivers/gpu/drm/mga/mga_ioc32.c
37812@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
37813 return 0;
37814 }
37815
37816-drm_ioctl_compat_t *mga_compat_ioctls[] = {
37817+drm_ioctl_compat_t mga_compat_ioctls[] = {
37818 [DRM_MGA_INIT] = compat_mga_init,
37819 [DRM_MGA_GETPARAM] = compat_mga_getparam,
37820 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
37821@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
37822 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
37823 {
37824 unsigned int nr = DRM_IOCTL_NR(cmd);
37825- drm_ioctl_compat_t *fn = NULL;
37826 int ret;
37827
37828 if (nr < DRM_COMMAND_BASE)
37829 return drm_compat_ioctl(filp, cmd, arg);
37830
37831- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
37832- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
37833-
37834- if (fn != NULL)
37835+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
37836+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
37837 ret = (*fn) (filp, cmd, arg);
37838- else
37839+ } else
37840 ret = drm_ioctl(filp, cmd, arg);
37841
37842 return ret;
37843diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
37844index 598c281..60d590e 100644
37845--- a/drivers/gpu/drm/mga/mga_irq.c
37846+++ b/drivers/gpu/drm/mga/mga_irq.c
37847@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
37848 if (crtc != 0)
37849 return 0;
37850
37851- return atomic_read(&dev_priv->vbl_received);
37852+ return atomic_read_unchecked(&dev_priv->vbl_received);
37853 }
37854
37855
37856@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
37857 /* VBLANK interrupt */
37858 if (status & MGA_VLINEPEN) {
37859 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
37860- atomic_inc(&dev_priv->vbl_received);
37861+ atomic_inc_unchecked(&dev_priv->vbl_received);
37862 drm_handle_vblank(dev, 0);
37863 handled = 1;
37864 }
37865@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
37866 if ((prim_start & ~0x03) != (prim_end & ~0x03))
37867 MGA_WRITE(MGA_PRIMEND, prim_end);
37868
37869- atomic_inc(&dev_priv->last_fence_retired);
37870+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
37871 DRM_WAKEUP(&dev_priv->fence_queue);
37872 handled = 1;
37873 }
37874@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
37875 * using fences.
37876 */
37877 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
37878- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
37879+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
37880 - *sequence) <= (1 << 23)));
37881
37882 *sequence = cur_fence;
37883diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
37884index 6aa2137..fe8dc55 100644
37885--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
37886+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
37887@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
37888 struct bit_table {
37889 const char id;
37890 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
37891-};
37892+} __no_const;
37893
37894 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
37895
37896diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
37897index f2b30f8..d0f9a95 100644
37898--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
37899+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
37900@@ -92,7 +92,7 @@ struct nouveau_drm {
37901 struct drm_global_reference mem_global_ref;
37902 struct ttm_bo_global_ref bo_global_ref;
37903 struct ttm_bo_device bdev;
37904- atomic_t validate_sequence;
37905+ atomic_unchecked_t validate_sequence;
37906 int (*move)(struct nouveau_channel *,
37907 struct ttm_buffer_object *,
37908 struct ttm_mem_reg *, struct ttm_mem_reg *);
37909diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
37910index b4b4d0c..b7edc15 100644
37911--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
37912+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
37913@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
37914 int ret, i;
37915 struct nouveau_bo *res_bo = NULL;
37916
37917- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
37918+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
37919 retry:
37920 if (++trycnt > 100000) {
37921 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
37922@@ -359,7 +359,7 @@ retry:
37923 if (ret) {
37924 validate_fini(op, NULL);
37925 if (unlikely(ret == -EAGAIN)) {
37926- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
37927+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
37928 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
37929 sequence);
37930 if (!ret)
37931diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
37932index 08214bc..9208577 100644
37933--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
37934+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
37935@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
37936 unsigned long arg)
37937 {
37938 unsigned int nr = DRM_IOCTL_NR(cmd);
37939- drm_ioctl_compat_t *fn = NULL;
37940+ drm_ioctl_compat_t fn = NULL;
37941 int ret;
37942
37943 if (nr < DRM_COMMAND_BASE)
37944diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
37945index 25d3495..d81aaf6 100644
37946--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
37947+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
37948@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
37949 bool can_switch;
37950
37951 spin_lock(&dev->count_lock);
37952- can_switch = (dev->open_count == 0);
37953+ can_switch = (local_read(&dev->open_count) == 0);
37954 spin_unlock(&dev->count_lock);
37955 return can_switch;
37956 }
37957diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
37958index 489cb8c..0b8d0d3 100644
37959--- a/drivers/gpu/drm/qxl/qxl_ttm.c
37960+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
37961@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
37962 }
37963 }
37964
37965-static struct vm_operations_struct qxl_ttm_vm_ops;
37966+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
37967 static const struct vm_operations_struct *ttm_vm_ops;
37968
37969 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
37970@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
37971 return r;
37972 if (unlikely(ttm_vm_ops == NULL)) {
37973 ttm_vm_ops = vma->vm_ops;
37974+ pax_open_kernel();
37975 qxl_ttm_vm_ops = *ttm_vm_ops;
37976 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
37977+ pax_close_kernel();
37978 }
37979 vma->vm_ops = &qxl_ttm_vm_ops;
37980 return 0;
37981@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
37982 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
37983 {
37984 #if defined(CONFIG_DEBUG_FS)
37985- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
37986- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
37987- unsigned i;
37988+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
37989+ {
37990+ .name = "qxl_mem_mm",
37991+ .show = &qxl_mm_dump_table,
37992+ },
37993+ {
37994+ .name = "qxl_surf_mm",
37995+ .show = &qxl_mm_dump_table,
37996+ }
37997+ };
37998
37999- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38000- if (i == 0)
38001- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38002- else
38003- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38004- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38005- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38006- qxl_mem_types_list[i].driver_features = 0;
38007- if (i == 0)
38008- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38009- else
38010- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38011+ pax_open_kernel();
38012+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38013+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38014+ pax_close_kernel();
38015
38016- }
38017- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38018+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38019 #else
38020 return 0;
38021 #endif
38022diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38023index d4660cf..70dbe65 100644
38024--- a/drivers/gpu/drm/r128/r128_cce.c
38025+++ b/drivers/gpu/drm/r128/r128_cce.c
38026@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38027
38028 /* GH: Simple idle check.
38029 */
38030- atomic_set(&dev_priv->idle_count, 0);
38031+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38032
38033 /* We don't support anything other than bus-mastering ring mode,
38034 * but the ring can be in either AGP or PCI space for the ring
38035diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38036index 930c71b..499aded 100644
38037--- a/drivers/gpu/drm/r128/r128_drv.h
38038+++ b/drivers/gpu/drm/r128/r128_drv.h
38039@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38040 int is_pci;
38041 unsigned long cce_buffers_offset;
38042
38043- atomic_t idle_count;
38044+ atomic_unchecked_t idle_count;
38045
38046 int page_flipping;
38047 int current_page;
38048 u32 crtc_offset;
38049 u32 crtc_offset_cntl;
38050
38051- atomic_t vbl_received;
38052+ atomic_unchecked_t vbl_received;
38053
38054 u32 color_fmt;
38055 unsigned int front_offset;
38056diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38057index a954c54..9cc595c 100644
38058--- a/drivers/gpu/drm/r128/r128_ioc32.c
38059+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38060@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38061 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38062 }
38063
38064-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38065+drm_ioctl_compat_t r128_compat_ioctls[] = {
38066 [DRM_R128_INIT] = compat_r128_init,
38067 [DRM_R128_DEPTH] = compat_r128_depth,
38068 [DRM_R128_STIPPLE] = compat_r128_stipple,
38069@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38070 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38071 {
38072 unsigned int nr = DRM_IOCTL_NR(cmd);
38073- drm_ioctl_compat_t *fn = NULL;
38074 int ret;
38075
38076 if (nr < DRM_COMMAND_BASE)
38077 return drm_compat_ioctl(filp, cmd, arg);
38078
38079- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38080- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38081-
38082- if (fn != NULL)
38083+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38084+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38085 ret = (*fn) (filp, cmd, arg);
38086- else
38087+ } else
38088 ret = drm_ioctl(filp, cmd, arg);
38089
38090 return ret;
38091diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38092index 2ea4f09..d391371 100644
38093--- a/drivers/gpu/drm/r128/r128_irq.c
38094+++ b/drivers/gpu/drm/r128/r128_irq.c
38095@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38096 if (crtc != 0)
38097 return 0;
38098
38099- return atomic_read(&dev_priv->vbl_received);
38100+ return atomic_read_unchecked(&dev_priv->vbl_received);
38101 }
38102
38103 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38104@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38105 /* VBLANK interrupt */
38106 if (status & R128_CRTC_VBLANK_INT) {
38107 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38108- atomic_inc(&dev_priv->vbl_received);
38109+ atomic_inc_unchecked(&dev_priv->vbl_received);
38110 drm_handle_vblank(dev, 0);
38111 return IRQ_HANDLED;
38112 }
38113diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38114index 19bb7e6..de7e2a2 100644
38115--- a/drivers/gpu/drm/r128/r128_state.c
38116+++ b/drivers/gpu/drm/r128/r128_state.c
38117@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38118
38119 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38120 {
38121- if (atomic_read(&dev_priv->idle_count) == 0)
38122+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38123 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38124 else
38125- atomic_set(&dev_priv->idle_count, 0);
38126+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38127 }
38128
38129 #endif
38130diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38131index 5a82b6b..9e69c73 100644
38132--- a/drivers/gpu/drm/radeon/mkregtable.c
38133+++ b/drivers/gpu/drm/radeon/mkregtable.c
38134@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
38135 regex_t mask_rex;
38136 regmatch_t match[4];
38137 char buf[1024];
38138- size_t end;
38139+ long end;
38140 int len;
38141 int done = 0;
38142 int r;
38143 unsigned o;
38144 struct offset *offset;
38145 char last_reg_s[10];
38146- int last_reg;
38147+ unsigned long last_reg;
38148
38149 if (regcomp
38150 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38151diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38152index b0dc0b6..a9bfe9c 100644
38153--- a/drivers/gpu/drm/radeon/radeon_device.c
38154+++ b/drivers/gpu/drm/radeon/radeon_device.c
38155@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38156 bool can_switch;
38157
38158 spin_lock(&dev->count_lock);
38159- can_switch = (dev->open_count == 0);
38160+ can_switch = (local_read(&dev->open_count) == 0);
38161 spin_unlock(&dev->count_lock);
38162 return can_switch;
38163 }
38164diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38165index b369d42..8dd04eb 100644
38166--- a/drivers/gpu/drm/radeon/radeon_drv.h
38167+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38168@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38169
38170 /* SW interrupt */
38171 wait_queue_head_t swi_queue;
38172- atomic_t swi_emitted;
38173+ atomic_unchecked_t swi_emitted;
38174 int vblank_crtc;
38175 uint32_t irq_enable_reg;
38176 uint32_t r500_disp_irq_reg;
38177diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38178index c180df8..5fd8186 100644
38179--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38180+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38181@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38182 request = compat_alloc_user_space(sizeof(*request));
38183 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38184 || __put_user(req32.param, &request->param)
38185- || __put_user((void __user *)(unsigned long)req32.value,
38186+ || __put_user((unsigned long)req32.value,
38187 &request->value))
38188 return -EFAULT;
38189
38190@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38191 #define compat_radeon_cp_setparam NULL
38192 #endif /* X86_64 || IA64 */
38193
38194-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38195+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38196 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38197 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38198 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38199@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38200 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38201 {
38202 unsigned int nr = DRM_IOCTL_NR(cmd);
38203- drm_ioctl_compat_t *fn = NULL;
38204 int ret;
38205
38206 if (nr < DRM_COMMAND_BASE)
38207 return drm_compat_ioctl(filp, cmd, arg);
38208
38209- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38210- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38211-
38212- if (fn != NULL)
38213+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38214+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38215 ret = (*fn) (filp, cmd, arg);
38216- else
38217+ } else
38218 ret = drm_ioctl(filp, cmd, arg);
38219
38220 return ret;
38221diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38222index 8d68e97..9dcfed8 100644
38223--- a/drivers/gpu/drm/radeon/radeon_irq.c
38224+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38225@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38226 unsigned int ret;
38227 RING_LOCALS;
38228
38229- atomic_inc(&dev_priv->swi_emitted);
38230- ret = atomic_read(&dev_priv->swi_emitted);
38231+ atomic_inc_unchecked(&dev_priv->swi_emitted);
38232+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
38233
38234 BEGIN_RING(4);
38235 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
38236@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
38237 drm_radeon_private_t *dev_priv =
38238 (drm_radeon_private_t *) dev->dev_private;
38239
38240- atomic_set(&dev_priv->swi_emitted, 0);
38241+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
38242 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
38243
38244 dev->max_vblank_count = 0x001fffff;
38245diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
38246index 4d20910..6726b6d 100644
38247--- a/drivers/gpu/drm/radeon/radeon_state.c
38248+++ b/drivers/gpu/drm/radeon/radeon_state.c
38249@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
38250 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
38251 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
38252
38253- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38254+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38255 sarea_priv->nbox * sizeof(depth_boxes[0])))
38256 return -EFAULT;
38257
38258@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
38259 {
38260 drm_radeon_private_t *dev_priv = dev->dev_private;
38261 drm_radeon_getparam_t *param = data;
38262- int value;
38263+ int value = 0;
38264
38265 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
38266
38267diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
38268index 6c0ce89..57a2529 100644
38269--- a/drivers/gpu/drm/radeon/radeon_ttm.c
38270+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
38271@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
38272 man->size = size >> PAGE_SHIFT;
38273 }
38274
38275-static struct vm_operations_struct radeon_ttm_vm_ops;
38276+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
38277 static const struct vm_operations_struct *ttm_vm_ops = NULL;
38278
38279 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38280@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
38281 }
38282 if (unlikely(ttm_vm_ops == NULL)) {
38283 ttm_vm_ops = vma->vm_ops;
38284+ pax_open_kernel();
38285 radeon_ttm_vm_ops = *ttm_vm_ops;
38286 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
38287+ pax_close_kernel();
38288 }
38289 vma->vm_ops = &radeon_ttm_vm_ops;
38290 return 0;
38291@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
38292 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
38293 {
38294 #if defined(CONFIG_DEBUG_FS)
38295- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
38296- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
38297+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
38298+ {
38299+ .name = "radeon_vram_mm",
38300+ .show = &radeon_mm_dump_table,
38301+ },
38302+ {
38303+ .name = "radeon_gtt_mm",
38304+ .show = &radeon_mm_dump_table,
38305+ },
38306+ {
38307+ .name = "ttm_page_pool",
38308+ .show = &ttm_page_alloc_debugfs,
38309+ },
38310+ {
38311+ .name = "ttm_dma_page_pool",
38312+ .show = &ttm_dma_page_alloc_debugfs,
38313+ },
38314+ };
38315 unsigned i;
38316
38317- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
38318- if (i == 0)
38319- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
38320- else
38321- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
38322- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
38323- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
38324- radeon_mem_types_list[i].driver_features = 0;
38325- if (i == 0)
38326- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
38327- else
38328- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
38329-
38330- }
38331- /* Add ttm page pool to debugfs */
38332- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
38333- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
38334- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
38335- radeon_mem_types_list[i].driver_features = 0;
38336- radeon_mem_types_list[i++].data = NULL;
38337+ pax_open_kernel();
38338+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
38339+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
38340+ pax_close_kernel();
38341 #ifdef CONFIG_SWIOTLB
38342- if (swiotlb_nr_tbl()) {
38343- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
38344- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
38345- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
38346- radeon_mem_types_list[i].driver_features = 0;
38347- radeon_mem_types_list[i++].data = NULL;
38348- }
38349+ if (swiotlb_nr_tbl())
38350+ i++;
38351 #endif
38352 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
38353
38354diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
38355index 55880d5..9e95342 100644
38356--- a/drivers/gpu/drm/radeon/rs690.c
38357+++ b/drivers/gpu/drm/radeon/rs690.c
38358@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
38359 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
38360 rdev->pm.sideport_bandwidth.full)
38361 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
38362- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
38363+ read_delay_latency.full = dfixed_const(800 * 1000);
38364 read_delay_latency.full = dfixed_div(read_delay_latency,
38365 rdev->pm.igp_sideport_mclk);
38366+ a.full = dfixed_const(370);
38367+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
38368 } else {
38369 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
38370 rdev->pm.k8_bandwidth.full)
38371diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
38372index dbc2def..0a9f710 100644
38373--- a/drivers/gpu/drm/ttm/ttm_memory.c
38374+++ b/drivers/gpu/drm/ttm/ttm_memory.c
38375@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
38376 zone->glob = glob;
38377 glob->zone_kernel = zone;
38378 ret = kobject_init_and_add(
38379- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
38380+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
38381 if (unlikely(ret != 0)) {
38382 kobject_put(&zone->kobj);
38383 return ret;
38384@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
38385 zone->glob = glob;
38386 glob->zone_dma32 = zone;
38387 ret = kobject_init_and_add(
38388- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
38389+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
38390 if (unlikely(ret != 0)) {
38391 kobject_put(&zone->kobj);
38392 return ret;
38393diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
38394index bd2a3b4..122d9ad 100644
38395--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
38396+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
38397@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
38398 static int ttm_pool_mm_shrink(struct shrinker *shrink,
38399 struct shrink_control *sc)
38400 {
38401- static atomic_t start_pool = ATOMIC_INIT(0);
38402+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
38403 unsigned i;
38404- unsigned pool_offset = atomic_add_return(1, &start_pool);
38405+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
38406 struct ttm_page_pool *pool;
38407 int shrink_pages = sc->nr_to_scan;
38408
38409diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
38410index dc0c065..58a0782 100644
38411--- a/drivers/gpu/drm/udl/udl_fb.c
38412+++ b/drivers/gpu/drm/udl/udl_fb.c
38413@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
38414 fb_deferred_io_cleanup(info);
38415 kfree(info->fbdefio);
38416 info->fbdefio = NULL;
38417- info->fbops->fb_mmap = udl_fb_mmap;
38418 }
38419
38420 pr_warn("released /dev/fb%d user=%d count=%d\n",
38421diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
38422index 893a650..6190d3b 100644
38423--- a/drivers/gpu/drm/via/via_drv.h
38424+++ b/drivers/gpu/drm/via/via_drv.h
38425@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
38426 typedef uint32_t maskarray_t[5];
38427
38428 typedef struct drm_via_irq {
38429- atomic_t irq_received;
38430+ atomic_unchecked_t irq_received;
38431 uint32_t pending_mask;
38432 uint32_t enable_mask;
38433 wait_queue_head_t irq_queue;
38434@@ -75,7 +75,7 @@ typedef struct drm_via_private {
38435 struct timeval last_vblank;
38436 int last_vblank_valid;
38437 unsigned usec_per_vblank;
38438- atomic_t vbl_received;
38439+ atomic_unchecked_t vbl_received;
38440 drm_via_state_t hc_state;
38441 char pci_buf[VIA_PCI_BUF_SIZE];
38442 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
38443diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
38444index ac98964..5dbf512 100644
38445--- a/drivers/gpu/drm/via/via_irq.c
38446+++ b/drivers/gpu/drm/via/via_irq.c
38447@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
38448 if (crtc != 0)
38449 return 0;
38450
38451- return atomic_read(&dev_priv->vbl_received);
38452+ return atomic_read_unchecked(&dev_priv->vbl_received);
38453 }
38454
38455 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
38456@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
38457
38458 status = VIA_READ(VIA_REG_INTERRUPT);
38459 if (status & VIA_IRQ_VBLANK_PENDING) {
38460- atomic_inc(&dev_priv->vbl_received);
38461- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
38462+ atomic_inc_unchecked(&dev_priv->vbl_received);
38463+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
38464 do_gettimeofday(&cur_vblank);
38465 if (dev_priv->last_vblank_valid) {
38466 dev_priv->usec_per_vblank =
38467@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
38468 dev_priv->last_vblank = cur_vblank;
38469 dev_priv->last_vblank_valid = 1;
38470 }
38471- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
38472+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
38473 DRM_DEBUG("US per vblank is: %u\n",
38474 dev_priv->usec_per_vblank);
38475 }
38476@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
38477
38478 for (i = 0; i < dev_priv->num_irqs; ++i) {
38479 if (status & cur_irq->pending_mask) {
38480- atomic_inc(&cur_irq->irq_received);
38481+ atomic_inc_unchecked(&cur_irq->irq_received);
38482 DRM_WAKEUP(&cur_irq->irq_queue);
38483 handled = 1;
38484 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
38485@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
38486 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
38487 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
38488 masks[irq][4]));
38489- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
38490+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
38491 } else {
38492 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
38493 (((cur_irq_sequence =
38494- atomic_read(&cur_irq->irq_received)) -
38495+ atomic_read_unchecked(&cur_irq->irq_received)) -
38496 *sequence) <= (1 << 23)));
38497 }
38498 *sequence = cur_irq_sequence;
38499@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
38500 }
38501
38502 for (i = 0; i < dev_priv->num_irqs; ++i) {
38503- atomic_set(&cur_irq->irq_received, 0);
38504+ atomic_set_unchecked(&cur_irq->irq_received, 0);
38505 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
38506 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
38507 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
38508@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
38509 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
38510 case VIA_IRQ_RELATIVE:
38511 irqwait->request.sequence +=
38512- atomic_read(&cur_irq->irq_received);
38513+ atomic_read_unchecked(&cur_irq->irq_received);
38514 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
38515 case VIA_IRQ_ABSOLUTE:
38516 break;
38517diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
38518index 13aeda7..4a952d1 100644
38519--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
38520+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
38521@@ -290,7 +290,7 @@ struct vmw_private {
38522 * Fencing and IRQs.
38523 */
38524
38525- atomic_t marker_seq;
38526+ atomic_unchecked_t marker_seq;
38527 wait_queue_head_t fence_queue;
38528 wait_queue_head_t fifo_queue;
38529 int fence_queue_waiters; /* Protected by hw_mutex */
38530diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
38531index 3eb1486..0a47ee9 100644
38532--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
38533+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
38534@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
38535 (unsigned int) min,
38536 (unsigned int) fifo->capabilities);
38537
38538- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
38539+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
38540 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
38541 vmw_marker_queue_init(&fifo->marker_queue);
38542 return vmw_fifo_send_fence(dev_priv, &dummy);
38543@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
38544 if (reserveable)
38545 iowrite32(bytes, fifo_mem +
38546 SVGA_FIFO_RESERVED);
38547- return fifo_mem + (next_cmd >> 2);
38548+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
38549 } else {
38550 need_bounce = true;
38551 }
38552@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
38553
38554 fm = vmw_fifo_reserve(dev_priv, bytes);
38555 if (unlikely(fm == NULL)) {
38556- *seqno = atomic_read(&dev_priv->marker_seq);
38557+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
38558 ret = -ENOMEM;
38559 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
38560 false, 3*HZ);
38561@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
38562 }
38563
38564 do {
38565- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
38566+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
38567 } while (*seqno == 0);
38568
38569 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
38570diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
38571index c509d40..3b640c3 100644
38572--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
38573+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
38574@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
38575 int ret;
38576
38577 num_clips = arg->num_clips;
38578- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
38579+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
38580
38581 if (unlikely(num_clips == 0))
38582 return 0;
38583@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
38584 int ret;
38585
38586 num_clips = arg->num_clips;
38587- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
38588+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
38589
38590 if (unlikely(num_clips == 0))
38591 return 0;
38592diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
38593index 4640adb..e1384ed 100644
38594--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
38595+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
38596@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
38597 * emitted. Then the fence is stale and signaled.
38598 */
38599
38600- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
38601+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
38602 > VMW_FENCE_WRAP);
38603
38604 return ret;
38605@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
38606
38607 if (fifo_idle)
38608 down_read(&fifo_state->rwsem);
38609- signal_seq = atomic_read(&dev_priv->marker_seq);
38610+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
38611 ret = 0;
38612
38613 for (;;) {
38614diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
38615index 8a8725c2..afed796 100644
38616--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
38617+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
38618@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
38619 while (!vmw_lag_lt(queue, us)) {
38620 spin_lock(&queue->lock);
38621 if (list_empty(&queue->head))
38622- seqno = atomic_read(&dev_priv->marker_seq);
38623+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
38624 else {
38625 marker = list_first_entry(&queue->head,
38626 struct vmw_marker, head);
38627diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
38628index 8c04943..4370ed9 100644
38629--- a/drivers/gpu/host1x/drm/dc.c
38630+++ b/drivers/gpu/host1x/drm/dc.c
38631@@ -999,7 +999,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
38632 }
38633
38634 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
38635- dc->debugfs_files[i].data = dc;
38636+ *(void **)&dc->debugfs_files[i].data = dc;
38637
38638 err = drm_debugfs_create_files(dc->debugfs_files,
38639 ARRAY_SIZE(debugfs_files),
38640diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
38641index 402f486..f862d7e 100644
38642--- a/drivers/hid/hid-core.c
38643+++ b/drivers/hid/hid-core.c
38644@@ -2275,7 +2275,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
38645
38646 int hid_add_device(struct hid_device *hdev)
38647 {
38648- static atomic_t id = ATOMIC_INIT(0);
38649+ static atomic_unchecked_t id = ATOMIC_INIT(0);
38650 int ret;
38651
38652 if (WARN_ON(hdev->status & HID_STAT_ADDED))
38653@@ -2309,7 +2309,7 @@ int hid_add_device(struct hid_device *hdev)
38654 /* XXX hack, any other cleaner solution after the driver core
38655 * is converted to allow more than 20 bytes as the device name? */
38656 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
38657- hdev->vendor, hdev->product, atomic_inc_return(&id));
38658+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
38659
38660 hid_debug_register(hdev, dev_name(&hdev->dev));
38661 ret = device_add(&hdev->dev);
38662diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
38663index 90124ff..3761764 100644
38664--- a/drivers/hid/hid-wiimote-debug.c
38665+++ b/drivers/hid/hid-wiimote-debug.c
38666@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
38667 else if (size == 0)
38668 return -EIO;
38669
38670- if (copy_to_user(u, buf, size))
38671+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
38672 return -EFAULT;
38673
38674 *off += size;
38675diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
38676index 0b122f8..b1d8160 100644
38677--- a/drivers/hv/channel.c
38678+++ b/drivers/hv/channel.c
38679@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
38680 int ret = 0;
38681 int t;
38682
38683- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
38684- atomic_inc(&vmbus_connection.next_gpadl_handle);
38685+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
38686+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
38687
38688 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
38689 if (ret)
38690diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
38691index ae49237..380d4c9 100644
38692--- a/drivers/hv/hv.c
38693+++ b/drivers/hv/hv.c
38694@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
38695 u64 output_address = (output) ? virt_to_phys(output) : 0;
38696 u32 output_address_hi = output_address >> 32;
38697 u32 output_address_lo = output_address & 0xFFFFFFFF;
38698- void *hypercall_page = hv_context.hypercall_page;
38699+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
38700
38701 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
38702 "=a"(hv_status_lo) : "d" (control_hi),
38703diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
38704index 12f2f9e..679603c 100644
38705--- a/drivers/hv/hyperv_vmbus.h
38706+++ b/drivers/hv/hyperv_vmbus.h
38707@@ -591,7 +591,7 @@ enum vmbus_connect_state {
38708 struct vmbus_connection {
38709 enum vmbus_connect_state conn_state;
38710
38711- atomic_t next_gpadl_handle;
38712+ atomic_unchecked_t next_gpadl_handle;
38713
38714 /*
38715 * Represents channel interrupts. Each bit position represents a
38716diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
38717index 4004e54..c2de226 100644
38718--- a/drivers/hv/vmbus_drv.c
38719+++ b/drivers/hv/vmbus_drv.c
38720@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
38721 {
38722 int ret = 0;
38723
38724- static atomic_t device_num = ATOMIC_INIT(0);
38725+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
38726
38727 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
38728- atomic_inc_return(&device_num));
38729+ atomic_inc_return_unchecked(&device_num));
38730
38731 child_device_obj->device.bus = &hv_bus;
38732 child_device_obj->device.parent = &hv_acpi_dev->dev;
38733diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
38734index 6351aba..dc4aaf4 100644
38735--- a/drivers/hwmon/acpi_power_meter.c
38736+++ b/drivers/hwmon/acpi_power_meter.c
38737@@ -117,7 +117,7 @@ struct sensor_template {
38738 struct device_attribute *devattr,
38739 const char *buf, size_t count);
38740 int index;
38741-};
38742+} __do_const;
38743
38744 /* Averaging interval */
38745 static int update_avg_interval(struct acpi_power_meter_resource *resource)
38746@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
38747 struct sensor_template *attrs)
38748 {
38749 struct device *dev = &resource->acpi_dev->dev;
38750- struct sensor_device_attribute *sensors =
38751+ sensor_device_attribute_no_const *sensors =
38752 &resource->sensors[resource->num_sensors];
38753 int res = 0;
38754
38755diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
38756index 62c2e32..8f2859a 100644
38757--- a/drivers/hwmon/applesmc.c
38758+++ b/drivers/hwmon/applesmc.c
38759@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
38760 {
38761 struct applesmc_node_group *grp;
38762 struct applesmc_dev_attr *node;
38763- struct attribute *attr;
38764+ attribute_no_const *attr;
38765 int ret, i;
38766
38767 for (grp = groups; grp->format; grp++) {
38768diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
38769index b25c643..a13460d 100644
38770--- a/drivers/hwmon/asus_atk0110.c
38771+++ b/drivers/hwmon/asus_atk0110.c
38772@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
38773 struct atk_sensor_data {
38774 struct list_head list;
38775 struct atk_data *data;
38776- struct device_attribute label_attr;
38777- struct device_attribute input_attr;
38778- struct device_attribute limit1_attr;
38779- struct device_attribute limit2_attr;
38780+ device_attribute_no_const label_attr;
38781+ device_attribute_no_const input_attr;
38782+ device_attribute_no_const limit1_attr;
38783+ device_attribute_no_const limit2_attr;
38784 char label_attr_name[ATTR_NAME_SIZE];
38785 char input_attr_name[ATTR_NAME_SIZE];
38786 char limit1_attr_name[ATTR_NAME_SIZE];
38787@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
38788 static struct device_attribute atk_name_attr =
38789 __ATTR(name, 0444, atk_name_show, NULL);
38790
38791-static void atk_init_attribute(struct device_attribute *attr, char *name,
38792+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
38793 sysfs_show_func show)
38794 {
38795 sysfs_attr_init(&attr->attr);
38796diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
38797index 658ce3a..0d0c2f3 100644
38798--- a/drivers/hwmon/coretemp.c
38799+++ b/drivers/hwmon/coretemp.c
38800@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
38801 return NOTIFY_OK;
38802 }
38803
38804-static struct notifier_block coretemp_cpu_notifier __refdata = {
38805+static struct notifier_block coretemp_cpu_notifier = {
38806 .notifier_call = coretemp_cpu_callback,
38807 };
38808
38809diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
38810index 1429f6e..ee03d59 100644
38811--- a/drivers/hwmon/ibmaem.c
38812+++ b/drivers/hwmon/ibmaem.c
38813@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
38814 struct aem_rw_sensor_template *rw)
38815 {
38816 struct device *dev = &data->pdev->dev;
38817- struct sensor_device_attribute *sensors = data->sensors;
38818+ sensor_device_attribute_no_const *sensors = data->sensors;
38819 int err;
38820
38821 /* Set up read-only sensors */
38822diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
38823index 52b77af..aed1ddf 100644
38824--- a/drivers/hwmon/iio_hwmon.c
38825+++ b/drivers/hwmon/iio_hwmon.c
38826@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
38827 {
38828 struct device *dev = &pdev->dev;
38829 struct iio_hwmon_state *st;
38830- struct sensor_device_attribute *a;
38831+ sensor_device_attribute_no_const *a;
38832 int ret, i;
38833 int in_i = 1, temp_i = 1, curr_i = 1;
38834 enum iio_chan_type type;
38835diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
38836index 9add6092..ee7ba3f 100644
38837--- a/drivers/hwmon/pmbus/pmbus_core.c
38838+++ b/drivers/hwmon/pmbus/pmbus_core.c
38839@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
38840 return 0;
38841 }
38842
38843-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
38844+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
38845 const char *name,
38846 umode_t mode,
38847 ssize_t (*show)(struct device *dev,
38848@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
38849 dev_attr->store = store;
38850 }
38851
38852-static void pmbus_attr_init(struct sensor_device_attribute *a,
38853+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
38854 const char *name,
38855 umode_t mode,
38856 ssize_t (*show)(struct device *dev,
38857@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
38858 u16 reg, u8 mask)
38859 {
38860 struct pmbus_boolean *boolean;
38861- struct sensor_device_attribute *a;
38862+ sensor_device_attribute_no_const *a;
38863
38864 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
38865 if (!boolean)
38866@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
38867 bool update, bool readonly)
38868 {
38869 struct pmbus_sensor *sensor;
38870- struct device_attribute *a;
38871+ device_attribute_no_const *a;
38872
38873 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
38874 if (!sensor)
38875@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
38876 const char *lstring, int index)
38877 {
38878 struct pmbus_label *label;
38879- struct device_attribute *a;
38880+ device_attribute_no_const *a;
38881
38882 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
38883 if (!label)
38884diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
38885index 2507f90..1645765 100644
38886--- a/drivers/hwmon/sht15.c
38887+++ b/drivers/hwmon/sht15.c
38888@@ -169,7 +169,7 @@ struct sht15_data {
38889 int supply_uv;
38890 bool supply_uv_valid;
38891 struct work_struct update_supply_work;
38892- atomic_t interrupt_handled;
38893+ atomic_unchecked_t interrupt_handled;
38894 };
38895
38896 /**
38897@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
38898 ret = gpio_direction_input(data->pdata->gpio_data);
38899 if (ret)
38900 return ret;
38901- atomic_set(&data->interrupt_handled, 0);
38902+ atomic_set_unchecked(&data->interrupt_handled, 0);
38903
38904 enable_irq(gpio_to_irq(data->pdata->gpio_data));
38905 if (gpio_get_value(data->pdata->gpio_data) == 0) {
38906 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
38907 /* Only relevant if the interrupt hasn't occurred. */
38908- if (!atomic_read(&data->interrupt_handled))
38909+ if (!atomic_read_unchecked(&data->interrupt_handled))
38910 schedule_work(&data->read_work);
38911 }
38912 ret = wait_event_timeout(data->wait_queue,
38913@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
38914
38915 /* First disable the interrupt */
38916 disable_irq_nosync(irq);
38917- atomic_inc(&data->interrupt_handled);
38918+ atomic_inc_unchecked(&data->interrupt_handled);
38919 /* Then schedule a reading work struct */
38920 if (data->state != SHT15_READING_NOTHING)
38921 schedule_work(&data->read_work);
38922@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
38923 * If not, then start the interrupt again - care here as could
38924 * have gone low in meantime so verify it hasn't!
38925 */
38926- atomic_set(&data->interrupt_handled, 0);
38927+ atomic_set_unchecked(&data->interrupt_handled, 0);
38928 enable_irq(gpio_to_irq(data->pdata->gpio_data));
38929 /* If still not occurred or another handler was scheduled */
38930 if (gpio_get_value(data->pdata->gpio_data)
38931- || atomic_read(&data->interrupt_handled))
38932+ || atomic_read_unchecked(&data->interrupt_handled))
38933 return;
38934 }
38935
38936diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
38937index 76f157b..9c0db1b 100644
38938--- a/drivers/hwmon/via-cputemp.c
38939+++ b/drivers/hwmon/via-cputemp.c
38940@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
38941 return NOTIFY_OK;
38942 }
38943
38944-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
38945+static struct notifier_block via_cputemp_cpu_notifier = {
38946 .notifier_call = via_cputemp_cpu_callback,
38947 };
38948
38949diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
38950index 07f01ac..d79ad3d 100644
38951--- a/drivers/i2c/busses/i2c-amd756-s4882.c
38952+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
38953@@ -43,7 +43,7 @@
38954 extern struct i2c_adapter amd756_smbus;
38955
38956 static struct i2c_adapter *s4882_adapter;
38957-static struct i2c_algorithm *s4882_algo;
38958+static i2c_algorithm_no_const *s4882_algo;
38959
38960 /* Wrapper access functions for multiplexed SMBus */
38961 static DEFINE_MUTEX(amd756_lock);
38962diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
38963index 2ca268d..c6acbdf 100644
38964--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
38965+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
38966@@ -41,7 +41,7 @@
38967 extern struct i2c_adapter *nforce2_smbus;
38968
38969 static struct i2c_adapter *s4985_adapter;
38970-static struct i2c_algorithm *s4985_algo;
38971+static i2c_algorithm_no_const *s4985_algo;
38972
38973 /* Wrapper access functions for multiplexed SMBus */
38974 static DEFINE_MUTEX(nforce2_lock);
38975diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
38976index c3ccdea..5b3dc1a 100644
38977--- a/drivers/i2c/i2c-dev.c
38978+++ b/drivers/i2c/i2c-dev.c
38979@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
38980 break;
38981 }
38982
38983- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
38984+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
38985 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
38986 if (IS_ERR(rdwr_pa[i].buf)) {
38987 res = PTR_ERR(rdwr_pa[i].buf);
38988diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
38989index 2ff6204..218c16e 100644
38990--- a/drivers/ide/ide-cd.c
38991+++ b/drivers/ide/ide-cd.c
38992@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
38993 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
38994 if ((unsigned long)buf & alignment
38995 || blk_rq_bytes(rq) & q->dma_pad_mask
38996- || object_is_on_stack(buf))
38997+ || object_starts_on_stack(buf))
38998 drive->dma = 0;
38999 }
39000 }
39001diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
39002index e145931..08bfc59 100644
39003--- a/drivers/iio/industrialio-core.c
39004+++ b/drivers/iio/industrialio-core.c
39005@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
39006 }
39007
39008 static
39009-int __iio_device_attr_init(struct device_attribute *dev_attr,
39010+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
39011 const char *postfix,
39012 struct iio_chan_spec const *chan,
39013 ssize_t (*readfunc)(struct device *dev,
39014diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
39015index 784b97c..c9ceadf 100644
39016--- a/drivers/infiniband/core/cm.c
39017+++ b/drivers/infiniband/core/cm.c
39018@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
39019
39020 struct cm_counter_group {
39021 struct kobject obj;
39022- atomic_long_t counter[CM_ATTR_COUNT];
39023+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
39024 };
39025
39026 struct cm_counter_attribute {
39027@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
39028 struct ib_mad_send_buf *msg = NULL;
39029 int ret;
39030
39031- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39032+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39033 counter[CM_REQ_COUNTER]);
39034
39035 /* Quick state check to discard duplicate REQs. */
39036@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
39037 if (!cm_id_priv)
39038 return;
39039
39040- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39041+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39042 counter[CM_REP_COUNTER]);
39043 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
39044 if (ret)
39045@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
39046 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
39047 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
39048 spin_unlock_irq(&cm_id_priv->lock);
39049- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39050+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39051 counter[CM_RTU_COUNTER]);
39052 goto out;
39053 }
39054@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
39055 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
39056 dreq_msg->local_comm_id);
39057 if (!cm_id_priv) {
39058- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39059+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39060 counter[CM_DREQ_COUNTER]);
39061 cm_issue_drep(work->port, work->mad_recv_wc);
39062 return -EINVAL;
39063@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
39064 case IB_CM_MRA_REP_RCVD:
39065 break;
39066 case IB_CM_TIMEWAIT:
39067- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39068+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39069 counter[CM_DREQ_COUNTER]);
39070 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39071 goto unlock;
39072@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
39073 cm_free_msg(msg);
39074 goto deref;
39075 case IB_CM_DREQ_RCVD:
39076- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39077+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39078 counter[CM_DREQ_COUNTER]);
39079 goto unlock;
39080 default:
39081@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
39082 ib_modify_mad(cm_id_priv->av.port->mad_agent,
39083 cm_id_priv->msg, timeout)) {
39084 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
39085- atomic_long_inc(&work->port->
39086+ atomic_long_inc_unchecked(&work->port->
39087 counter_group[CM_RECV_DUPLICATES].
39088 counter[CM_MRA_COUNTER]);
39089 goto out;
39090@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
39091 break;
39092 case IB_CM_MRA_REQ_RCVD:
39093 case IB_CM_MRA_REP_RCVD:
39094- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39095+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39096 counter[CM_MRA_COUNTER]);
39097 /* fall through */
39098 default:
39099@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
39100 case IB_CM_LAP_IDLE:
39101 break;
39102 case IB_CM_MRA_LAP_SENT:
39103- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39104+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39105 counter[CM_LAP_COUNTER]);
39106 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39107 goto unlock;
39108@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
39109 cm_free_msg(msg);
39110 goto deref;
39111 case IB_CM_LAP_RCVD:
39112- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39113+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39114 counter[CM_LAP_COUNTER]);
39115 goto unlock;
39116 default:
39117@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
39118 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
39119 if (cur_cm_id_priv) {
39120 spin_unlock_irq(&cm.lock);
39121- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39122+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39123 counter[CM_SIDR_REQ_COUNTER]);
39124 goto out; /* Duplicate message. */
39125 }
39126@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
39127 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
39128 msg->retries = 1;
39129
39130- atomic_long_add(1 + msg->retries,
39131+ atomic_long_add_unchecked(1 + msg->retries,
39132 &port->counter_group[CM_XMIT].counter[attr_index]);
39133 if (msg->retries)
39134- atomic_long_add(msg->retries,
39135+ atomic_long_add_unchecked(msg->retries,
39136 &port->counter_group[CM_XMIT_RETRIES].
39137 counter[attr_index]);
39138
39139@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
39140 }
39141
39142 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
39143- atomic_long_inc(&port->counter_group[CM_RECV].
39144+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
39145 counter[attr_id - CM_ATTR_ID_OFFSET]);
39146
39147 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
39148@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
39149 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
39150
39151 return sprintf(buf, "%ld\n",
39152- atomic_long_read(&group->counter[cm_attr->index]));
39153+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
39154 }
39155
39156 static const struct sysfs_ops cm_counter_ops = {
39157diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
39158index 9f5ad7c..588cd84 100644
39159--- a/drivers/infiniband/core/fmr_pool.c
39160+++ b/drivers/infiniband/core/fmr_pool.c
39161@@ -98,8 +98,8 @@ struct ib_fmr_pool {
39162
39163 struct task_struct *thread;
39164
39165- atomic_t req_ser;
39166- atomic_t flush_ser;
39167+ atomic_unchecked_t req_ser;
39168+ atomic_unchecked_t flush_ser;
39169
39170 wait_queue_head_t force_wait;
39171 };
39172@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
39173 struct ib_fmr_pool *pool = pool_ptr;
39174
39175 do {
39176- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
39177+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
39178 ib_fmr_batch_release(pool);
39179
39180- atomic_inc(&pool->flush_ser);
39181+ atomic_inc_unchecked(&pool->flush_ser);
39182 wake_up_interruptible(&pool->force_wait);
39183
39184 if (pool->flush_function)
39185@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
39186 }
39187
39188 set_current_state(TASK_INTERRUPTIBLE);
39189- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
39190+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
39191 !kthread_should_stop())
39192 schedule();
39193 __set_current_state(TASK_RUNNING);
39194@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
39195 pool->dirty_watermark = params->dirty_watermark;
39196 pool->dirty_len = 0;
39197 spin_lock_init(&pool->pool_lock);
39198- atomic_set(&pool->req_ser, 0);
39199- atomic_set(&pool->flush_ser, 0);
39200+ atomic_set_unchecked(&pool->req_ser, 0);
39201+ atomic_set_unchecked(&pool->flush_ser, 0);
39202 init_waitqueue_head(&pool->force_wait);
39203
39204 pool->thread = kthread_run(ib_fmr_cleanup_thread,
39205@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
39206 }
39207 spin_unlock_irq(&pool->pool_lock);
39208
39209- serial = atomic_inc_return(&pool->req_ser);
39210+ serial = atomic_inc_return_unchecked(&pool->req_ser);
39211 wake_up_process(pool->thread);
39212
39213 if (wait_event_interruptible(pool->force_wait,
39214- atomic_read(&pool->flush_ser) - serial >= 0))
39215+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
39216 return -EINTR;
39217
39218 return 0;
39219@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
39220 } else {
39221 list_add_tail(&fmr->list, &pool->dirty_list);
39222 if (++pool->dirty_len >= pool->dirty_watermark) {
39223- atomic_inc(&pool->req_ser);
39224+ atomic_inc_unchecked(&pool->req_ser);
39225 wake_up_process(pool->thread);
39226 }
39227 }
39228diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
39229index 4cb8eb2..146bf60 100644
39230--- a/drivers/infiniband/hw/cxgb4/mem.c
39231+++ b/drivers/infiniband/hw/cxgb4/mem.c
39232@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
39233 int err;
39234 struct fw_ri_tpte tpt;
39235 u32 stag_idx;
39236- static atomic_t key;
39237+ static atomic_unchecked_t key;
39238
39239 if (c4iw_fatal_error(rdev))
39240 return -EIO;
39241@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
39242 if (rdev->stats.stag.cur > rdev->stats.stag.max)
39243 rdev->stats.stag.max = rdev->stats.stag.cur;
39244 mutex_unlock(&rdev->stats.lock);
39245- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
39246+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
39247 }
39248 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
39249 __func__, stag_state, type, pdid, stag_idx);
39250diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
39251index 79b3dbc..96e5fcc 100644
39252--- a/drivers/infiniband/hw/ipath/ipath_rc.c
39253+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
39254@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
39255 struct ib_atomic_eth *ateth;
39256 struct ipath_ack_entry *e;
39257 u64 vaddr;
39258- atomic64_t *maddr;
39259+ atomic64_unchecked_t *maddr;
39260 u64 sdata;
39261 u32 rkey;
39262 u8 next;
39263@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
39264 IB_ACCESS_REMOTE_ATOMIC)))
39265 goto nack_acc_unlck;
39266 /* Perform atomic OP and save result. */
39267- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
39268+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
39269 sdata = be64_to_cpu(ateth->swap_data);
39270 e = &qp->s_ack_queue[qp->r_head_ack_queue];
39271 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
39272- (u64) atomic64_add_return(sdata, maddr) - sdata :
39273+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
39274 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
39275 be64_to_cpu(ateth->compare_data),
39276 sdata);
39277diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
39278index 1f95bba..9530f87 100644
39279--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
39280+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
39281@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
39282 unsigned long flags;
39283 struct ib_wc wc;
39284 u64 sdata;
39285- atomic64_t *maddr;
39286+ atomic64_unchecked_t *maddr;
39287 enum ib_wc_status send_status;
39288
39289 /*
39290@@ -382,11 +382,11 @@ again:
39291 IB_ACCESS_REMOTE_ATOMIC)))
39292 goto acc_err;
39293 /* Perform atomic OP and save result. */
39294- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
39295+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
39296 sdata = wqe->wr.wr.atomic.compare_add;
39297 *(u64 *) sqp->s_sge.sge.vaddr =
39298 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
39299- (u64) atomic64_add_return(sdata, maddr) - sdata :
39300+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
39301 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
39302 sdata, wqe->wr.wr.atomic.swap);
39303 goto send_comp;
39304diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
39305index 9d3e5c1..d9afe4a 100644
39306--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
39307+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
39308@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
39309 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
39310 }
39311
39312-int mthca_QUERY_FW(struct mthca_dev *dev)
39313+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
39314 {
39315 struct mthca_mailbox *mailbox;
39316 u32 *outbox;
39317diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
39318index ed9a989..e0c5871 100644
39319--- a/drivers/infiniband/hw/mthca/mthca_mr.c
39320+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
39321@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
39322 return key;
39323 }
39324
39325-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
39326+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
39327 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
39328 {
39329 struct mthca_mailbox *mailbox;
39330diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
39331index 4291410..d2ab1fb 100644
39332--- a/drivers/infiniband/hw/nes/nes.c
39333+++ b/drivers/infiniband/hw/nes/nes.c
39334@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
39335 LIST_HEAD(nes_adapter_list);
39336 static LIST_HEAD(nes_dev_list);
39337
39338-atomic_t qps_destroyed;
39339+atomic_unchecked_t qps_destroyed;
39340
39341 static unsigned int ee_flsh_adapter;
39342 static unsigned int sysfs_nonidx_addr;
39343@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
39344 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
39345 struct nes_adapter *nesadapter = nesdev->nesadapter;
39346
39347- atomic_inc(&qps_destroyed);
39348+ atomic_inc_unchecked(&qps_destroyed);
39349
39350 /* Free the control structures */
39351
39352diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
39353index 33cc589..3bd6538 100644
39354--- a/drivers/infiniband/hw/nes/nes.h
39355+++ b/drivers/infiniband/hw/nes/nes.h
39356@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
39357 extern unsigned int wqm_quanta;
39358 extern struct list_head nes_adapter_list;
39359
39360-extern atomic_t cm_connects;
39361-extern atomic_t cm_accepts;
39362-extern atomic_t cm_disconnects;
39363-extern atomic_t cm_closes;
39364-extern atomic_t cm_connecteds;
39365-extern atomic_t cm_connect_reqs;
39366-extern atomic_t cm_rejects;
39367-extern atomic_t mod_qp_timouts;
39368-extern atomic_t qps_created;
39369-extern atomic_t qps_destroyed;
39370-extern atomic_t sw_qps_destroyed;
39371+extern atomic_unchecked_t cm_connects;
39372+extern atomic_unchecked_t cm_accepts;
39373+extern atomic_unchecked_t cm_disconnects;
39374+extern atomic_unchecked_t cm_closes;
39375+extern atomic_unchecked_t cm_connecteds;
39376+extern atomic_unchecked_t cm_connect_reqs;
39377+extern atomic_unchecked_t cm_rejects;
39378+extern atomic_unchecked_t mod_qp_timouts;
39379+extern atomic_unchecked_t qps_created;
39380+extern atomic_unchecked_t qps_destroyed;
39381+extern atomic_unchecked_t sw_qps_destroyed;
39382 extern u32 mh_detected;
39383 extern u32 mh_pauses_sent;
39384 extern u32 cm_packets_sent;
39385@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
39386 extern u32 cm_packets_received;
39387 extern u32 cm_packets_dropped;
39388 extern u32 cm_packets_retrans;
39389-extern atomic_t cm_listens_created;
39390-extern atomic_t cm_listens_destroyed;
39391+extern atomic_unchecked_t cm_listens_created;
39392+extern atomic_unchecked_t cm_listens_destroyed;
39393 extern u32 cm_backlog_drops;
39394-extern atomic_t cm_loopbacks;
39395-extern atomic_t cm_nodes_created;
39396-extern atomic_t cm_nodes_destroyed;
39397-extern atomic_t cm_accel_dropped_pkts;
39398-extern atomic_t cm_resets_recvd;
39399-extern atomic_t pau_qps_created;
39400-extern atomic_t pau_qps_destroyed;
39401+extern atomic_unchecked_t cm_loopbacks;
39402+extern atomic_unchecked_t cm_nodes_created;
39403+extern atomic_unchecked_t cm_nodes_destroyed;
39404+extern atomic_unchecked_t cm_accel_dropped_pkts;
39405+extern atomic_unchecked_t cm_resets_recvd;
39406+extern atomic_unchecked_t pau_qps_created;
39407+extern atomic_unchecked_t pau_qps_destroyed;
39408
39409 extern u32 int_mod_timer_init;
39410 extern u32 int_mod_cq_depth_256;
39411diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
39412index 24b9f1a..00fd004 100644
39413--- a/drivers/infiniband/hw/nes/nes_cm.c
39414+++ b/drivers/infiniband/hw/nes/nes_cm.c
39415@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
39416 u32 cm_packets_retrans;
39417 u32 cm_packets_created;
39418 u32 cm_packets_received;
39419-atomic_t cm_listens_created;
39420-atomic_t cm_listens_destroyed;
39421+atomic_unchecked_t cm_listens_created;
39422+atomic_unchecked_t cm_listens_destroyed;
39423 u32 cm_backlog_drops;
39424-atomic_t cm_loopbacks;
39425-atomic_t cm_nodes_created;
39426-atomic_t cm_nodes_destroyed;
39427-atomic_t cm_accel_dropped_pkts;
39428-atomic_t cm_resets_recvd;
39429+atomic_unchecked_t cm_loopbacks;
39430+atomic_unchecked_t cm_nodes_created;
39431+atomic_unchecked_t cm_nodes_destroyed;
39432+atomic_unchecked_t cm_accel_dropped_pkts;
39433+atomic_unchecked_t cm_resets_recvd;
39434
39435 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
39436 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
39437@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
39438
39439 static struct nes_cm_core *g_cm_core;
39440
39441-atomic_t cm_connects;
39442-atomic_t cm_accepts;
39443-atomic_t cm_disconnects;
39444-atomic_t cm_closes;
39445-atomic_t cm_connecteds;
39446-atomic_t cm_connect_reqs;
39447-atomic_t cm_rejects;
39448+atomic_unchecked_t cm_connects;
39449+atomic_unchecked_t cm_accepts;
39450+atomic_unchecked_t cm_disconnects;
39451+atomic_unchecked_t cm_closes;
39452+atomic_unchecked_t cm_connecteds;
39453+atomic_unchecked_t cm_connect_reqs;
39454+atomic_unchecked_t cm_rejects;
39455
39456 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
39457 {
39458@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
39459 kfree(listener);
39460 listener = NULL;
39461 ret = 0;
39462- atomic_inc(&cm_listens_destroyed);
39463+ atomic_inc_unchecked(&cm_listens_destroyed);
39464 } else {
39465 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
39466 }
39467@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
39468 cm_node->rem_mac);
39469
39470 add_hte_node(cm_core, cm_node);
39471- atomic_inc(&cm_nodes_created);
39472+ atomic_inc_unchecked(&cm_nodes_created);
39473
39474 return cm_node;
39475 }
39476@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
39477 }
39478
39479 atomic_dec(&cm_core->node_cnt);
39480- atomic_inc(&cm_nodes_destroyed);
39481+ atomic_inc_unchecked(&cm_nodes_destroyed);
39482 nesqp = cm_node->nesqp;
39483 if (nesqp) {
39484 nesqp->cm_node = NULL;
39485@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
39486
39487 static void drop_packet(struct sk_buff *skb)
39488 {
39489- atomic_inc(&cm_accel_dropped_pkts);
39490+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
39491 dev_kfree_skb_any(skb);
39492 }
39493
39494@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
39495 {
39496
39497 int reset = 0; /* whether to send reset in case of err.. */
39498- atomic_inc(&cm_resets_recvd);
39499+ atomic_inc_unchecked(&cm_resets_recvd);
39500 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
39501 " refcnt=%d\n", cm_node, cm_node->state,
39502 atomic_read(&cm_node->ref_count));
39503@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
39504 rem_ref_cm_node(cm_node->cm_core, cm_node);
39505 return NULL;
39506 }
39507- atomic_inc(&cm_loopbacks);
39508+ atomic_inc_unchecked(&cm_loopbacks);
39509 loopbackremotenode->loopbackpartner = cm_node;
39510 loopbackremotenode->tcp_cntxt.rcv_wscale =
39511 NES_CM_DEFAULT_RCV_WND_SCALE;
39512@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
39513 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
39514 else {
39515 rem_ref_cm_node(cm_core, cm_node);
39516- atomic_inc(&cm_accel_dropped_pkts);
39517+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
39518 dev_kfree_skb_any(skb);
39519 }
39520 break;
39521@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
39522
39523 if ((cm_id) && (cm_id->event_handler)) {
39524 if (issue_disconn) {
39525- atomic_inc(&cm_disconnects);
39526+ atomic_inc_unchecked(&cm_disconnects);
39527 cm_event.event = IW_CM_EVENT_DISCONNECT;
39528 cm_event.status = disconn_status;
39529 cm_event.local_addr = cm_id->local_addr;
39530@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
39531 }
39532
39533 if (issue_close) {
39534- atomic_inc(&cm_closes);
39535+ atomic_inc_unchecked(&cm_closes);
39536 nes_disconnect(nesqp, 1);
39537
39538 cm_id->provider_data = nesqp;
39539@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
39540
39541 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
39542 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
39543- atomic_inc(&cm_accepts);
39544+ atomic_inc_unchecked(&cm_accepts);
39545
39546 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
39547 netdev_refcnt_read(nesvnic->netdev));
39548@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
39549 struct nes_cm_core *cm_core;
39550 u8 *start_buff;
39551
39552- atomic_inc(&cm_rejects);
39553+ atomic_inc_unchecked(&cm_rejects);
39554 cm_node = (struct nes_cm_node *)cm_id->provider_data;
39555 loopback = cm_node->loopbackpartner;
39556 cm_core = cm_node->cm_core;
39557@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
39558 ntohl(cm_id->local_addr.sin_addr.s_addr),
39559 ntohs(cm_id->local_addr.sin_port));
39560
39561- atomic_inc(&cm_connects);
39562+ atomic_inc_unchecked(&cm_connects);
39563 nesqp->active_conn = 1;
39564
39565 /* cache the cm_id in the qp */
39566@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
39567 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
39568 return err;
39569 }
39570- atomic_inc(&cm_listens_created);
39571+ atomic_inc_unchecked(&cm_listens_created);
39572 }
39573
39574 cm_id->add_ref(cm_id);
39575@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
39576
39577 if (nesqp->destroyed)
39578 return;
39579- atomic_inc(&cm_connecteds);
39580+ atomic_inc_unchecked(&cm_connecteds);
39581 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
39582 " local port 0x%04X. jiffies = %lu.\n",
39583 nesqp->hwqp.qp_id,
39584@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
39585
39586 cm_id->add_ref(cm_id);
39587 ret = cm_id->event_handler(cm_id, &cm_event);
39588- atomic_inc(&cm_closes);
39589+ atomic_inc_unchecked(&cm_closes);
39590 cm_event.event = IW_CM_EVENT_CLOSE;
39591 cm_event.status = 0;
39592 cm_event.provider_data = cm_id->provider_data;
39593@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
39594 return;
39595 cm_id = cm_node->cm_id;
39596
39597- atomic_inc(&cm_connect_reqs);
39598+ atomic_inc_unchecked(&cm_connect_reqs);
39599 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
39600 cm_node, cm_id, jiffies);
39601
39602@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
39603 return;
39604 cm_id = cm_node->cm_id;
39605
39606- atomic_inc(&cm_connect_reqs);
39607+ atomic_inc_unchecked(&cm_connect_reqs);
39608 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
39609 cm_node, cm_id, jiffies);
39610
39611diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
39612index 4166452..fc952c3 100644
39613--- a/drivers/infiniband/hw/nes/nes_mgt.c
39614+++ b/drivers/infiniband/hw/nes/nes_mgt.c
39615@@ -40,8 +40,8 @@
39616 #include "nes.h"
39617 #include "nes_mgt.h"
39618
39619-atomic_t pau_qps_created;
39620-atomic_t pau_qps_destroyed;
39621+atomic_unchecked_t pau_qps_created;
39622+atomic_unchecked_t pau_qps_destroyed;
39623
39624 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
39625 {
39626@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
39627 {
39628 struct sk_buff *skb;
39629 unsigned long flags;
39630- atomic_inc(&pau_qps_destroyed);
39631+ atomic_inc_unchecked(&pau_qps_destroyed);
39632
39633 /* Free packets that have not yet been forwarded */
39634 /* Lock is acquired by skb_dequeue when removing the skb */
39635@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
39636 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
39637 skb_queue_head_init(&nesqp->pau_list);
39638 spin_lock_init(&nesqp->pau_lock);
39639- atomic_inc(&pau_qps_created);
39640+ atomic_inc_unchecked(&pau_qps_created);
39641 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
39642 }
39643
39644diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
39645index 49eb511..a774366 100644
39646--- a/drivers/infiniband/hw/nes/nes_nic.c
39647+++ b/drivers/infiniband/hw/nes/nes_nic.c
39648@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
39649 target_stat_values[++index] = mh_detected;
39650 target_stat_values[++index] = mh_pauses_sent;
39651 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
39652- target_stat_values[++index] = atomic_read(&cm_connects);
39653- target_stat_values[++index] = atomic_read(&cm_accepts);
39654- target_stat_values[++index] = atomic_read(&cm_disconnects);
39655- target_stat_values[++index] = atomic_read(&cm_connecteds);
39656- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
39657- target_stat_values[++index] = atomic_read(&cm_rejects);
39658- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
39659- target_stat_values[++index] = atomic_read(&qps_created);
39660- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
39661- target_stat_values[++index] = atomic_read(&qps_destroyed);
39662- target_stat_values[++index] = atomic_read(&cm_closes);
39663+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
39664+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
39665+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
39666+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
39667+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
39668+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
39669+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
39670+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
39671+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
39672+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
39673+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
39674 target_stat_values[++index] = cm_packets_sent;
39675 target_stat_values[++index] = cm_packets_bounced;
39676 target_stat_values[++index] = cm_packets_created;
39677 target_stat_values[++index] = cm_packets_received;
39678 target_stat_values[++index] = cm_packets_dropped;
39679 target_stat_values[++index] = cm_packets_retrans;
39680- target_stat_values[++index] = atomic_read(&cm_listens_created);
39681- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
39682+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
39683+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
39684 target_stat_values[++index] = cm_backlog_drops;
39685- target_stat_values[++index] = atomic_read(&cm_loopbacks);
39686- target_stat_values[++index] = atomic_read(&cm_nodes_created);
39687- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
39688- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
39689- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
39690+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
39691+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
39692+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
39693+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
39694+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
39695 target_stat_values[++index] = nesadapter->free_4kpbl;
39696 target_stat_values[++index] = nesadapter->free_256pbl;
39697 target_stat_values[++index] = int_mod_timer_init;
39698 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
39699 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
39700 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
39701- target_stat_values[++index] = atomic_read(&pau_qps_created);
39702- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
39703+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
39704+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
39705 }
39706
39707 /**
39708diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
39709index 8f67fe2..8960859 100644
39710--- a/drivers/infiniband/hw/nes/nes_verbs.c
39711+++ b/drivers/infiniband/hw/nes/nes_verbs.c
39712@@ -46,9 +46,9 @@
39713
39714 #include <rdma/ib_umem.h>
39715
39716-atomic_t mod_qp_timouts;
39717-atomic_t qps_created;
39718-atomic_t sw_qps_destroyed;
39719+atomic_unchecked_t mod_qp_timouts;
39720+atomic_unchecked_t qps_created;
39721+atomic_unchecked_t sw_qps_destroyed;
39722
39723 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
39724
39725@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
39726 if (init_attr->create_flags)
39727 return ERR_PTR(-EINVAL);
39728
39729- atomic_inc(&qps_created);
39730+ atomic_inc_unchecked(&qps_created);
39731 switch (init_attr->qp_type) {
39732 case IB_QPT_RC:
39733 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
39734@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
39735 struct iw_cm_event cm_event;
39736 int ret = 0;
39737
39738- atomic_inc(&sw_qps_destroyed);
39739+ atomic_inc_unchecked(&sw_qps_destroyed);
39740 nesqp->destroyed = 1;
39741
39742 /* Blow away the connection if it exists. */
39743diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
39744index 4d11575..3e890e5 100644
39745--- a/drivers/infiniband/hw/qib/qib.h
39746+++ b/drivers/infiniband/hw/qib/qib.h
39747@@ -51,6 +51,7 @@
39748 #include <linux/completion.h>
39749 #include <linux/kref.h>
39750 #include <linux/sched.h>
39751+#include <linux/slab.h>
39752
39753 #include "qib_common.h"
39754 #include "qib_verbs.h"
39755diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
39756index da739d9..da1c7f4 100644
39757--- a/drivers/input/gameport/gameport.c
39758+++ b/drivers/input/gameport/gameport.c
39759@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
39760 */
39761 static void gameport_init_port(struct gameport *gameport)
39762 {
39763- static atomic_t gameport_no = ATOMIC_INIT(0);
39764+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
39765
39766 __module_get(THIS_MODULE);
39767
39768 mutex_init(&gameport->drv_mutex);
39769 device_initialize(&gameport->dev);
39770 dev_set_name(&gameport->dev, "gameport%lu",
39771- (unsigned long)atomic_inc_return(&gameport_no) - 1);
39772+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
39773 gameport->dev.bus = &gameport_bus;
39774 gameport->dev.release = gameport_release_port;
39775 if (gameport->parent)
39776diff --git a/drivers/input/input.c b/drivers/input/input.c
39777index c044699..174d71a 100644
39778--- a/drivers/input/input.c
39779+++ b/drivers/input/input.c
39780@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
39781 */
39782 int input_register_device(struct input_dev *dev)
39783 {
39784- static atomic_t input_no = ATOMIC_INIT(0);
39785+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
39786 struct input_devres *devres = NULL;
39787 struct input_handler *handler;
39788 unsigned int packet_size;
39789@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
39790 dev->setkeycode = input_default_setkeycode;
39791
39792 dev_set_name(&dev->dev, "input%ld",
39793- (unsigned long) atomic_inc_return(&input_no) - 1);
39794+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
39795
39796 error = device_add(&dev->dev);
39797 if (error)
39798diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
39799index 04c69af..5f92d00 100644
39800--- a/drivers/input/joystick/sidewinder.c
39801+++ b/drivers/input/joystick/sidewinder.c
39802@@ -30,6 +30,7 @@
39803 #include <linux/kernel.h>
39804 #include <linux/module.h>
39805 #include <linux/slab.h>
39806+#include <linux/sched.h>
39807 #include <linux/init.h>
39808 #include <linux/input.h>
39809 #include <linux/gameport.h>
39810diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
39811index fa061d4..4a6957c 100644
39812--- a/drivers/input/joystick/xpad.c
39813+++ b/drivers/input/joystick/xpad.c
39814@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
39815
39816 static int xpad_led_probe(struct usb_xpad *xpad)
39817 {
39818- static atomic_t led_seq = ATOMIC_INIT(0);
39819+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
39820 long led_no;
39821 struct xpad_led *led;
39822 struct led_classdev *led_cdev;
39823@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
39824 if (!led)
39825 return -ENOMEM;
39826
39827- led_no = (long)atomic_inc_return(&led_seq) - 1;
39828+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
39829
39830 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
39831 led->xpad = xpad;
39832diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
39833index 2f0b39d..7370f13 100644
39834--- a/drivers/input/mouse/psmouse.h
39835+++ b/drivers/input/mouse/psmouse.h
39836@@ -116,7 +116,7 @@ struct psmouse_attribute {
39837 ssize_t (*set)(struct psmouse *psmouse, void *data,
39838 const char *buf, size_t count);
39839 bool protect;
39840-};
39841+} __do_const;
39842 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
39843
39844 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
39845diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
39846index 4c842c3..590b0bf 100644
39847--- a/drivers/input/mousedev.c
39848+++ b/drivers/input/mousedev.c
39849@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
39850
39851 spin_unlock_irq(&client->packet_lock);
39852
39853- if (copy_to_user(buffer, data, count))
39854+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
39855 return -EFAULT;
39856
39857 return count;
39858diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
39859index 25fc597..558bf3b3 100644
39860--- a/drivers/input/serio/serio.c
39861+++ b/drivers/input/serio/serio.c
39862@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
39863 */
39864 static void serio_init_port(struct serio *serio)
39865 {
39866- static atomic_t serio_no = ATOMIC_INIT(0);
39867+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
39868
39869 __module_get(THIS_MODULE);
39870
39871@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
39872 mutex_init(&serio->drv_mutex);
39873 device_initialize(&serio->dev);
39874 dev_set_name(&serio->dev, "serio%ld",
39875- (long)atomic_inc_return(&serio_no) - 1);
39876+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
39877 serio->dev.bus = &serio_bus;
39878 serio->dev.release = serio_release_port;
39879 serio->dev.groups = serio_device_attr_groups;
39880diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
39881index d8f98b1..f62a640 100644
39882--- a/drivers/iommu/iommu.c
39883+++ b/drivers/iommu/iommu.c
39884@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
39885 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
39886 {
39887 bus_register_notifier(bus, &iommu_bus_nb);
39888- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
39889+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
39890 }
39891
39892 /**
39893diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
39894index dcfea4e..f4226b2 100644
39895--- a/drivers/iommu/irq_remapping.c
39896+++ b/drivers/iommu/irq_remapping.c
39897@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
39898 void panic_if_irq_remap(const char *msg)
39899 {
39900 if (irq_remapping_enabled)
39901- panic(msg);
39902+ panic("%s", msg);
39903 }
39904
39905 static void ir_ack_apic_edge(struct irq_data *data)
39906@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
39907
39908 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
39909 {
39910- chip->irq_print_chip = ir_print_prefix;
39911- chip->irq_ack = ir_ack_apic_edge;
39912- chip->irq_eoi = ir_ack_apic_level;
39913- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
39914+ pax_open_kernel();
39915+ *(void **)&chip->irq_print_chip = ir_print_prefix;
39916+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
39917+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
39918+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
39919+ pax_close_kernel();
39920 }
39921
39922 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
39923diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
39924index 19ceaa6..3625818 100644
39925--- a/drivers/irqchip/irq-gic.c
39926+++ b/drivers/irqchip/irq-gic.c
39927@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
39928 * Supported arch specific GIC irq extension.
39929 * Default make them NULL.
39930 */
39931-struct irq_chip gic_arch_extn = {
39932+irq_chip_no_const gic_arch_extn = {
39933 .irq_eoi = NULL,
39934 .irq_mask = NULL,
39935 .irq_unmask = NULL,
39936@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
39937 chained_irq_exit(chip, desc);
39938 }
39939
39940-static struct irq_chip gic_chip = {
39941+static irq_chip_no_const gic_chip __read_only = {
39942 .name = "GIC",
39943 .irq_mask = gic_mask_irq,
39944 .irq_unmask = gic_unmask_irq,
39945diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
39946index ac6f72b..81150f2 100644
39947--- a/drivers/isdn/capi/capi.c
39948+++ b/drivers/isdn/capi/capi.c
39949@@ -81,8 +81,8 @@ struct capiminor {
39950
39951 struct capi20_appl *ap;
39952 u32 ncci;
39953- atomic_t datahandle;
39954- atomic_t msgid;
39955+ atomic_unchecked_t datahandle;
39956+ atomic_unchecked_t msgid;
39957
39958 struct tty_port port;
39959 int ttyinstop;
39960@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
39961 capimsg_setu16(s, 2, mp->ap->applid);
39962 capimsg_setu8 (s, 4, CAPI_DATA_B3);
39963 capimsg_setu8 (s, 5, CAPI_RESP);
39964- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
39965+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
39966 capimsg_setu32(s, 8, mp->ncci);
39967 capimsg_setu16(s, 12, datahandle);
39968 }
39969@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
39970 mp->outbytes -= len;
39971 spin_unlock_bh(&mp->outlock);
39972
39973- datahandle = atomic_inc_return(&mp->datahandle);
39974+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
39975 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
39976 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
39977 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
39978 capimsg_setu16(skb->data, 2, mp->ap->applid);
39979 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
39980 capimsg_setu8 (skb->data, 5, CAPI_REQ);
39981- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
39982+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
39983 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
39984 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
39985 capimsg_setu16(skb->data, 16, len); /* Data length */
39986diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
39987index 600c79b..3752bab 100644
39988--- a/drivers/isdn/gigaset/interface.c
39989+++ b/drivers/isdn/gigaset/interface.c
39990@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
39991 }
39992 tty->driver_data = cs;
39993
39994- ++cs->port.count;
39995+ atomic_inc(&cs->port.count);
39996
39997- if (cs->port.count == 1) {
39998+ if (atomic_read(&cs->port.count) == 1) {
39999 tty_port_tty_set(&cs->port, tty);
40000 cs->port.low_latency = 1;
40001 }
40002@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
40003
40004 if (!cs->connected)
40005 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
40006- else if (!cs->port.count)
40007+ else if (!atomic_read(&cs->port.count))
40008 dev_warn(cs->dev, "%s: device not opened\n", __func__);
40009- else if (!--cs->port.count)
40010+ else if (!atomic_dec_return(&cs->port.count))
40011 tty_port_tty_set(&cs->port, NULL);
40012
40013 mutex_unlock(&cs->mutex);
40014diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
40015index 4d9b195..455075c 100644
40016--- a/drivers/isdn/hardware/avm/b1.c
40017+++ b/drivers/isdn/hardware/avm/b1.c
40018@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
40019 }
40020 if (left) {
40021 if (t4file->user) {
40022- if (copy_from_user(buf, dp, left))
40023+ if (left > sizeof buf || copy_from_user(buf, dp, left))
40024 return -EFAULT;
40025 } else {
40026 memcpy(buf, dp, left);
40027@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
40028 }
40029 if (left) {
40030 if (config->user) {
40031- if (copy_from_user(buf, dp, left))
40032+ if (left > sizeof buf || copy_from_user(buf, dp, left))
40033 return -EFAULT;
40034 } else {
40035 memcpy(buf, dp, left);
40036diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
40037index 3c5f249..5fac4d0 100644
40038--- a/drivers/isdn/i4l/isdn_tty.c
40039+++ b/drivers/isdn/i4l/isdn_tty.c
40040@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
40041
40042 #ifdef ISDN_DEBUG_MODEM_OPEN
40043 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
40044- port->count);
40045+ atomic_read(&port->count));
40046 #endif
40047- port->count++;
40048+ atomic_inc(&port->count);
40049 port->tty = tty;
40050 /*
40051 * Start up serial port
40052@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
40053 #endif
40054 return;
40055 }
40056- if ((tty->count == 1) && (port->count != 1)) {
40057+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
40058 /*
40059 * Uh, oh. tty->count is 1, which means that the tty
40060 * structure will be freed. Info->count should always
40061@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
40062 * serial port won't be shutdown.
40063 */
40064 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
40065- "info->count is %d\n", port->count);
40066- port->count = 1;
40067+ "info->count is %d\n", atomic_read(&port->count));
40068+ atomic_set(&port->count, 1);
40069 }
40070- if (--port->count < 0) {
40071+ if (atomic_dec_return(&port->count) < 0) {
40072 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
40073- info->line, port->count);
40074- port->count = 0;
40075+ info->line, atomic_read(&port->count));
40076+ atomic_set(&port->count, 0);
40077 }
40078- if (port->count) {
40079+ if (atomic_read(&port->count)) {
40080 #ifdef ISDN_DEBUG_MODEM_OPEN
40081 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
40082 #endif
40083@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
40084 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
40085 return;
40086 isdn_tty_shutdown(info);
40087- port->count = 0;
40088+ atomic_set(&port->count, 0);
40089 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40090 port->tty = NULL;
40091 wake_up_interruptible(&port->open_wait);
40092@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
40093 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
40094 modem_info *info = &dev->mdm.info[i];
40095
40096- if (info->port.count == 0)
40097+ if (atomic_read(&info->port.count) == 0)
40098 continue;
40099 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
40100 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
40101diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
40102index e74df7c..03a03ba 100644
40103--- a/drivers/isdn/icn/icn.c
40104+++ b/drivers/isdn/icn/icn.c
40105@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
40106 if (count > len)
40107 count = len;
40108 if (user) {
40109- if (copy_from_user(msg, buf, count))
40110+ if (count > sizeof msg || copy_from_user(msg, buf, count))
40111 return -EFAULT;
40112 } else
40113 memcpy(msg, buf, count);
40114diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
40115index 6a8405d..0bd1c7e 100644
40116--- a/drivers/leds/leds-clevo-mail.c
40117+++ b/drivers/leds/leds-clevo-mail.c
40118@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
40119 * detected as working, but in reality it is not) as low as
40120 * possible.
40121 */
40122-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
40123+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
40124 {
40125 .callback = clevo_mail_led_dmi_callback,
40126 .ident = "Clevo D410J",
40127diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
40128index 64e204e..c6bf189 100644
40129--- a/drivers/leds/leds-ss4200.c
40130+++ b/drivers/leds/leds-ss4200.c
40131@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
40132 * detected as working, but in reality it is not) as low as
40133 * possible.
40134 */
40135-static struct dmi_system_id __initdata nas_led_whitelist[] = {
40136+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
40137 {
40138 .callback = ss4200_led_dmi_callback,
40139 .ident = "Intel SS4200-E",
40140diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
40141index 0bf1e4e..b4bf44e 100644
40142--- a/drivers/lguest/core.c
40143+++ b/drivers/lguest/core.c
40144@@ -97,9 +97,17 @@ static __init int map_switcher(void)
40145 * The end address needs +1 because __get_vm_area allocates an
40146 * extra guard page, so we need space for that.
40147 */
40148+
40149+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
40150+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
40151+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
40152+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
40153+#else
40154 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
40155 VM_ALLOC, switcher_addr, switcher_addr
40156 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
40157+#endif
40158+
40159 if (!switcher_vma) {
40160 err = -ENOMEM;
40161 printk("lguest: could not map switcher pages high\n");
40162@@ -124,7 +132,7 @@ static __init int map_switcher(void)
40163 * Now the Switcher is mapped at the right address, we can't fail!
40164 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
40165 */
40166- memcpy(switcher_vma->addr, start_switcher_text,
40167+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
40168 end_switcher_text - start_switcher_text);
40169
40170 printk(KERN_INFO "lguest: mapped switcher at %p\n",
40171diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
40172index 5b9ac32..2ef4f26 100644
40173--- a/drivers/lguest/page_tables.c
40174+++ b/drivers/lguest/page_tables.c
40175@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
40176 /*:*/
40177
40178 #ifdef CONFIG_X86_PAE
40179-static void release_pmd(pmd_t *spmd)
40180+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
40181 {
40182 /* If the entry's not present, there's nothing to release. */
40183 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
40184diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
40185index f0a3347..f6608b2 100644
40186--- a/drivers/lguest/x86/core.c
40187+++ b/drivers/lguest/x86/core.c
40188@@ -59,7 +59,7 @@ static struct {
40189 /* Offset from where switcher.S was compiled to where we've copied it */
40190 static unsigned long switcher_offset(void)
40191 {
40192- return switcher_addr - (unsigned long)start_switcher_text;
40193+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
40194 }
40195
40196 /* This cpu's struct lguest_pages (after the Switcher text page) */
40197@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
40198 * These copies are pretty cheap, so we do them unconditionally: */
40199 /* Save the current Host top-level page directory.
40200 */
40201+
40202+#ifdef CONFIG_PAX_PER_CPU_PGD
40203+ pages->state.host_cr3 = read_cr3();
40204+#else
40205 pages->state.host_cr3 = __pa(current->mm->pgd);
40206+#endif
40207+
40208 /*
40209 * Set up the Guest's page tables to see this CPU's pages (and no
40210 * other CPU's pages).
40211@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
40212 * compiled-in switcher code and the high-mapped copy we just made.
40213 */
40214 for (i = 0; i < IDT_ENTRIES; i++)
40215- default_idt_entries[i] += switcher_offset();
40216+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
40217
40218 /*
40219 * Set up the Switcher's per-cpu areas.
40220@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
40221 * it will be undisturbed when we switch. To change %cs and jump we
40222 * need this structure to feed to Intel's "lcall" instruction.
40223 */
40224- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
40225+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
40226 lguest_entry.segment = LGUEST_CS;
40227
40228 /*
40229diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
40230index 40634b0..4f5855e 100644
40231--- a/drivers/lguest/x86/switcher_32.S
40232+++ b/drivers/lguest/x86/switcher_32.S
40233@@ -87,6 +87,7 @@
40234 #include <asm/page.h>
40235 #include <asm/segment.h>
40236 #include <asm/lguest.h>
40237+#include <asm/processor-flags.h>
40238
40239 // We mark the start of the code to copy
40240 // It's placed in .text tho it's never run here
40241@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
40242 // Changes type when we load it: damn Intel!
40243 // For after we switch over our page tables
40244 // That entry will be read-only: we'd crash.
40245+
40246+#ifdef CONFIG_PAX_KERNEXEC
40247+ mov %cr0, %edx
40248+ xor $X86_CR0_WP, %edx
40249+ mov %edx, %cr0
40250+#endif
40251+
40252 movl $(GDT_ENTRY_TSS*8), %edx
40253 ltr %dx
40254
40255@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
40256 // Let's clear it again for our return.
40257 // The GDT descriptor of the Host
40258 // Points to the table after two "size" bytes
40259- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
40260+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
40261 // Clear "used" from type field (byte 5, bit 2)
40262- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
40263+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
40264+
40265+#ifdef CONFIG_PAX_KERNEXEC
40266+ mov %cr0, %eax
40267+ xor $X86_CR0_WP, %eax
40268+ mov %eax, %cr0
40269+#endif
40270
40271 // Once our page table's switched, the Guest is live!
40272 // The Host fades as we run this final step.
40273@@ -295,13 +309,12 @@ deliver_to_host:
40274 // I consulted gcc, and it gave
40275 // These instructions, which I gladly credit:
40276 leal (%edx,%ebx,8), %eax
40277- movzwl (%eax),%edx
40278- movl 4(%eax), %eax
40279- xorw %ax, %ax
40280- orl %eax, %edx
40281+ movl 4(%eax), %edx
40282+ movw (%eax), %dx
40283 // Now the address of the handler's in %edx
40284 // We call it now: its "iret" drops us home.
40285- jmp *%edx
40286+ ljmp $__KERNEL_CS, $1f
40287+1: jmp *%edx
40288
40289 // Every interrupt can come to us here
40290 // But we must truly tell each apart.
40291diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
40292index 0003992..854bbce 100644
40293--- a/drivers/md/bcache/closure.h
40294+++ b/drivers/md/bcache/closure.h
40295@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
40296 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
40297 struct workqueue_struct *wq)
40298 {
40299- BUG_ON(object_is_on_stack(cl));
40300+ BUG_ON(object_starts_on_stack(cl));
40301 closure_set_ip(cl);
40302 cl->fn = fn;
40303 cl->wq = wq;
40304diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
40305index 5a2c754..0fa55db 100644
40306--- a/drivers/md/bitmap.c
40307+++ b/drivers/md/bitmap.c
40308@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
40309 chunk_kb ? "KB" : "B");
40310 if (bitmap->storage.file) {
40311 seq_printf(seq, ", file: ");
40312- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
40313+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
40314 }
40315
40316 seq_printf(seq, "\n");
40317diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
40318index 81a79b7..87a0f73 100644
40319--- a/drivers/md/dm-ioctl.c
40320+++ b/drivers/md/dm-ioctl.c
40321@@ -1697,7 +1697,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
40322 cmd == DM_LIST_VERSIONS_CMD)
40323 return 0;
40324
40325- if ((cmd == DM_DEV_CREATE_CMD)) {
40326+ if (cmd == DM_DEV_CREATE_CMD) {
40327 if (!*param->name) {
40328 DMWARN("name not supplied when creating device");
40329 return -EINVAL;
40330diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
40331index 699b5be..eac0a15 100644
40332--- a/drivers/md/dm-raid1.c
40333+++ b/drivers/md/dm-raid1.c
40334@@ -40,7 +40,7 @@ enum dm_raid1_error {
40335
40336 struct mirror {
40337 struct mirror_set *ms;
40338- atomic_t error_count;
40339+ atomic_unchecked_t error_count;
40340 unsigned long error_type;
40341 struct dm_dev *dev;
40342 sector_t offset;
40343@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
40344 struct mirror *m;
40345
40346 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
40347- if (!atomic_read(&m->error_count))
40348+ if (!atomic_read_unchecked(&m->error_count))
40349 return m;
40350
40351 return NULL;
40352@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
40353 * simple way to tell if a device has encountered
40354 * errors.
40355 */
40356- atomic_inc(&m->error_count);
40357+ atomic_inc_unchecked(&m->error_count);
40358
40359 if (test_and_set_bit(error_type, &m->error_type))
40360 return;
40361@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
40362 struct mirror *m = get_default_mirror(ms);
40363
40364 do {
40365- if (likely(!atomic_read(&m->error_count)))
40366+ if (likely(!atomic_read_unchecked(&m->error_count)))
40367 return m;
40368
40369 if (m-- == ms->mirror)
40370@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
40371 {
40372 struct mirror *default_mirror = get_default_mirror(m->ms);
40373
40374- return !atomic_read(&default_mirror->error_count);
40375+ return !atomic_read_unchecked(&default_mirror->error_count);
40376 }
40377
40378 static int mirror_available(struct mirror_set *ms, struct bio *bio)
40379@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
40380 */
40381 if (likely(region_in_sync(ms, region, 1)))
40382 m = choose_mirror(ms, bio->bi_sector);
40383- else if (m && atomic_read(&m->error_count))
40384+ else if (m && atomic_read_unchecked(&m->error_count))
40385 m = NULL;
40386
40387 if (likely(m))
40388@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
40389 }
40390
40391 ms->mirror[mirror].ms = ms;
40392- atomic_set(&(ms->mirror[mirror].error_count), 0);
40393+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
40394 ms->mirror[mirror].error_type = 0;
40395 ms->mirror[mirror].offset = offset;
40396
40397@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
40398 */
40399 static char device_status_char(struct mirror *m)
40400 {
40401- if (!atomic_read(&(m->error_count)))
40402+ if (!atomic_read_unchecked(&(m->error_count)))
40403 return 'A';
40404
40405 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
40406diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
40407index d907ca6..cfb8384 100644
40408--- a/drivers/md/dm-stripe.c
40409+++ b/drivers/md/dm-stripe.c
40410@@ -20,7 +20,7 @@ struct stripe {
40411 struct dm_dev *dev;
40412 sector_t physical_start;
40413
40414- atomic_t error_count;
40415+ atomic_unchecked_t error_count;
40416 };
40417
40418 struct stripe_c {
40419@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
40420 kfree(sc);
40421 return r;
40422 }
40423- atomic_set(&(sc->stripe[i].error_count), 0);
40424+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
40425 }
40426
40427 ti->private = sc;
40428@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
40429 DMEMIT("%d ", sc->stripes);
40430 for (i = 0; i < sc->stripes; i++) {
40431 DMEMIT("%s ", sc->stripe[i].dev->name);
40432- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
40433+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
40434 'D' : 'A';
40435 }
40436 buffer[i] = '\0';
40437@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
40438 */
40439 for (i = 0; i < sc->stripes; i++)
40440 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
40441- atomic_inc(&(sc->stripe[i].error_count));
40442- if (atomic_read(&(sc->stripe[i].error_count)) <
40443+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
40444+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
40445 DM_IO_ERROR_THRESHOLD)
40446 schedule_work(&sc->trigger_event);
40447 }
40448diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
40449index 1ff252a..ee384c1 100644
40450--- a/drivers/md/dm-table.c
40451+++ b/drivers/md/dm-table.c
40452@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
40453 if (!dev_size)
40454 return 0;
40455
40456- if ((start >= dev_size) || (start + len > dev_size)) {
40457+ if ((start >= dev_size) || (len > dev_size - start)) {
40458 DMWARN("%s: %s too small for target: "
40459 "start=%llu, len=%llu, dev_size=%llu",
40460 dm_device_name(ti->table->md), bdevname(bdev, b),
40461diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
40462index 60bce43..9b997d0 100644
40463--- a/drivers/md/dm-thin-metadata.c
40464+++ b/drivers/md/dm-thin-metadata.c
40465@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
40466 {
40467 pmd->info.tm = pmd->tm;
40468 pmd->info.levels = 2;
40469- pmd->info.value_type.context = pmd->data_sm;
40470+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
40471 pmd->info.value_type.size = sizeof(__le64);
40472 pmd->info.value_type.inc = data_block_inc;
40473 pmd->info.value_type.dec = data_block_dec;
40474@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
40475
40476 pmd->bl_info.tm = pmd->tm;
40477 pmd->bl_info.levels = 1;
40478- pmd->bl_info.value_type.context = pmd->data_sm;
40479+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
40480 pmd->bl_info.value_type.size = sizeof(__le64);
40481 pmd->bl_info.value_type.inc = data_block_inc;
40482 pmd->bl_info.value_type.dec = data_block_dec;
40483diff --git a/drivers/md/dm.c b/drivers/md/dm.c
40484index 33f2010..23fb84c 100644
40485--- a/drivers/md/dm.c
40486+++ b/drivers/md/dm.c
40487@@ -169,9 +169,9 @@ struct mapped_device {
40488 /*
40489 * Event handling.
40490 */
40491- atomic_t event_nr;
40492+ atomic_unchecked_t event_nr;
40493 wait_queue_head_t eventq;
40494- atomic_t uevent_seq;
40495+ atomic_unchecked_t uevent_seq;
40496 struct list_head uevent_list;
40497 spinlock_t uevent_lock; /* Protect access to uevent_list */
40498
40499@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
40500 rwlock_init(&md->map_lock);
40501 atomic_set(&md->holders, 1);
40502 atomic_set(&md->open_count, 0);
40503- atomic_set(&md->event_nr, 0);
40504- atomic_set(&md->uevent_seq, 0);
40505+ atomic_set_unchecked(&md->event_nr, 0);
40506+ atomic_set_unchecked(&md->uevent_seq, 0);
40507 INIT_LIST_HEAD(&md->uevent_list);
40508 spin_lock_init(&md->uevent_lock);
40509
40510@@ -2033,7 +2033,7 @@ static void event_callback(void *context)
40511
40512 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
40513
40514- atomic_inc(&md->event_nr);
40515+ atomic_inc_unchecked(&md->event_nr);
40516 wake_up(&md->eventq);
40517 }
40518
40519@@ -2690,18 +2690,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
40520
40521 uint32_t dm_next_uevent_seq(struct mapped_device *md)
40522 {
40523- return atomic_add_return(1, &md->uevent_seq);
40524+ return atomic_add_return_unchecked(1, &md->uevent_seq);
40525 }
40526
40527 uint32_t dm_get_event_nr(struct mapped_device *md)
40528 {
40529- return atomic_read(&md->event_nr);
40530+ return atomic_read_unchecked(&md->event_nr);
40531 }
40532
40533 int dm_wait_event(struct mapped_device *md, int event_nr)
40534 {
40535 return wait_event_interruptible(md->eventq,
40536- (event_nr != atomic_read(&md->event_nr)));
40537+ (event_nr != atomic_read_unchecked(&md->event_nr)));
40538 }
40539
40540 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
40541diff --git a/drivers/md/md.c b/drivers/md/md.c
40542index 51f0345..c77810e 100644
40543--- a/drivers/md/md.c
40544+++ b/drivers/md/md.c
40545@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
40546 * start build, activate spare
40547 */
40548 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
40549-static atomic_t md_event_count;
40550+static atomic_unchecked_t md_event_count;
40551 void md_new_event(struct mddev *mddev)
40552 {
40553- atomic_inc(&md_event_count);
40554+ atomic_inc_unchecked(&md_event_count);
40555 wake_up(&md_event_waiters);
40556 }
40557 EXPORT_SYMBOL_GPL(md_new_event);
40558@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
40559 */
40560 static void md_new_event_inintr(struct mddev *mddev)
40561 {
40562- atomic_inc(&md_event_count);
40563+ atomic_inc_unchecked(&md_event_count);
40564 wake_up(&md_event_waiters);
40565 }
40566
40567@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
40568 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
40569 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
40570 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
40571- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
40572+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
40573
40574 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
40575 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
40576@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
40577 else
40578 sb->resync_offset = cpu_to_le64(0);
40579
40580- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
40581+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
40582
40583 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
40584 sb->size = cpu_to_le64(mddev->dev_sectors);
40585@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
40586 static ssize_t
40587 errors_show(struct md_rdev *rdev, char *page)
40588 {
40589- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
40590+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
40591 }
40592
40593 static ssize_t
40594@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
40595 char *e;
40596 unsigned long n = simple_strtoul(buf, &e, 10);
40597 if (*buf && (*e == 0 || *e == '\n')) {
40598- atomic_set(&rdev->corrected_errors, n);
40599+ atomic_set_unchecked(&rdev->corrected_errors, n);
40600 return len;
40601 }
40602 return -EINVAL;
40603@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
40604 rdev->sb_loaded = 0;
40605 rdev->bb_page = NULL;
40606 atomic_set(&rdev->nr_pending, 0);
40607- atomic_set(&rdev->read_errors, 0);
40608- atomic_set(&rdev->corrected_errors, 0);
40609+ atomic_set_unchecked(&rdev->read_errors, 0);
40610+ atomic_set_unchecked(&rdev->corrected_errors, 0);
40611
40612 INIT_LIST_HEAD(&rdev->same_set);
40613 init_waitqueue_head(&rdev->blocked_wait);
40614@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
40615
40616 spin_unlock(&pers_lock);
40617 seq_printf(seq, "\n");
40618- seq->poll_event = atomic_read(&md_event_count);
40619+ seq->poll_event = atomic_read_unchecked(&md_event_count);
40620 return 0;
40621 }
40622 if (v == (void*)2) {
40623@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
40624 return error;
40625
40626 seq = file->private_data;
40627- seq->poll_event = atomic_read(&md_event_count);
40628+ seq->poll_event = atomic_read_unchecked(&md_event_count);
40629 return error;
40630 }
40631
40632@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
40633 /* always allow read */
40634 mask = POLLIN | POLLRDNORM;
40635
40636- if (seq->poll_event != atomic_read(&md_event_count))
40637+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
40638 mask |= POLLERR | POLLPRI;
40639 return mask;
40640 }
40641@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
40642 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
40643 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
40644 (int)part_stat_read(&disk->part0, sectors[1]) -
40645- atomic_read(&disk->sync_io);
40646+ atomic_read_unchecked(&disk->sync_io);
40647 /* sync IO will cause sync_io to increase before the disk_stats
40648 * as sync_io is counted when a request starts, and
40649 * disk_stats is counted when it completes.
40650diff --git a/drivers/md/md.h b/drivers/md/md.h
40651index 653f992b6..6af6c40 100644
40652--- a/drivers/md/md.h
40653+++ b/drivers/md/md.h
40654@@ -94,13 +94,13 @@ struct md_rdev {
40655 * only maintained for arrays that
40656 * support hot removal
40657 */
40658- atomic_t read_errors; /* number of consecutive read errors that
40659+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
40660 * we have tried to ignore.
40661 */
40662 struct timespec last_read_error; /* monotonic time since our
40663 * last read error
40664 */
40665- atomic_t corrected_errors; /* number of corrected read errors,
40666+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
40667 * for reporting to userspace and storing
40668 * in superblock.
40669 */
40670@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
40671
40672 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
40673 {
40674- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
40675+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
40676 }
40677
40678 struct md_personality
40679diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
40680index 3e6d115..ffecdeb 100644
40681--- a/drivers/md/persistent-data/dm-space-map.h
40682+++ b/drivers/md/persistent-data/dm-space-map.h
40683@@ -71,6 +71,7 @@ struct dm_space_map {
40684 dm_sm_threshold_fn fn,
40685 void *context);
40686 };
40687+typedef struct dm_space_map __no_const dm_space_map_no_const;
40688
40689 /*----------------------------------------------------------------*/
40690
40691diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
40692index 6f48244..7d29145 100644
40693--- a/drivers/md/raid1.c
40694+++ b/drivers/md/raid1.c
40695@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
40696 if (r1_sync_page_io(rdev, sect, s,
40697 bio->bi_io_vec[idx].bv_page,
40698 READ) != 0)
40699- atomic_add(s, &rdev->corrected_errors);
40700+ atomic_add_unchecked(s, &rdev->corrected_errors);
40701 }
40702 sectors -= s;
40703 sect += s;
40704@@ -2049,7 +2049,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
40705 test_bit(In_sync, &rdev->flags)) {
40706 if (r1_sync_page_io(rdev, sect, s,
40707 conf->tmppage, READ)) {
40708- atomic_add(s, &rdev->corrected_errors);
40709+ atomic_add_unchecked(s, &rdev->corrected_errors);
40710 printk(KERN_INFO
40711 "md/raid1:%s: read error corrected "
40712 "(%d sectors at %llu on %s)\n",
40713diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
40714index 081bb33..3c4b287 100644
40715--- a/drivers/md/raid10.c
40716+++ b/drivers/md/raid10.c
40717@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
40718 /* The write handler will notice the lack of
40719 * R10BIO_Uptodate and record any errors etc
40720 */
40721- atomic_add(r10_bio->sectors,
40722+ atomic_add_unchecked(r10_bio->sectors,
40723 &conf->mirrors[d].rdev->corrected_errors);
40724
40725 /* for reconstruct, we always reschedule after a read.
40726@@ -2298,7 +2298,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
40727 {
40728 struct timespec cur_time_mon;
40729 unsigned long hours_since_last;
40730- unsigned int read_errors = atomic_read(&rdev->read_errors);
40731+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
40732
40733 ktime_get_ts(&cur_time_mon);
40734
40735@@ -2320,9 +2320,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
40736 * overflowing the shift of read_errors by hours_since_last.
40737 */
40738 if (hours_since_last >= 8 * sizeof(read_errors))
40739- atomic_set(&rdev->read_errors, 0);
40740+ atomic_set_unchecked(&rdev->read_errors, 0);
40741 else
40742- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
40743+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
40744 }
40745
40746 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
40747@@ -2376,8 +2376,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
40748 return;
40749
40750 check_decay_read_errors(mddev, rdev);
40751- atomic_inc(&rdev->read_errors);
40752- if (atomic_read(&rdev->read_errors) > max_read_errors) {
40753+ atomic_inc_unchecked(&rdev->read_errors);
40754+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
40755 char b[BDEVNAME_SIZE];
40756 bdevname(rdev->bdev, b);
40757
40758@@ -2385,7 +2385,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
40759 "md/raid10:%s: %s: Raid device exceeded "
40760 "read_error threshold [cur %d:max %d]\n",
40761 mdname(mddev), b,
40762- atomic_read(&rdev->read_errors), max_read_errors);
40763+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
40764 printk(KERN_NOTICE
40765 "md/raid10:%s: %s: Failing raid device\n",
40766 mdname(mddev), b);
40767@@ -2540,7 +2540,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
40768 sect +
40769 choose_data_offset(r10_bio, rdev)),
40770 bdevname(rdev->bdev, b));
40771- atomic_add(s, &rdev->corrected_errors);
40772+ atomic_add_unchecked(s, &rdev->corrected_errors);
40773 }
40774
40775 rdev_dec_pending(rdev, mddev);
40776diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
40777index a35b846..e295c6d 100644
40778--- a/drivers/md/raid5.c
40779+++ b/drivers/md/raid5.c
40780@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
40781 mdname(conf->mddev), STRIPE_SECTORS,
40782 (unsigned long long)s,
40783 bdevname(rdev->bdev, b));
40784- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
40785+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
40786 clear_bit(R5_ReadError, &sh->dev[i].flags);
40787 clear_bit(R5_ReWrite, &sh->dev[i].flags);
40788 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
40789 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
40790
40791- if (atomic_read(&rdev->read_errors))
40792- atomic_set(&rdev->read_errors, 0);
40793+ if (atomic_read_unchecked(&rdev->read_errors))
40794+ atomic_set_unchecked(&rdev->read_errors, 0);
40795 } else {
40796 const char *bdn = bdevname(rdev->bdev, b);
40797 int retry = 0;
40798 int set_bad = 0;
40799
40800 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
40801- atomic_inc(&rdev->read_errors);
40802+ atomic_inc_unchecked(&rdev->read_errors);
40803 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
40804 printk_ratelimited(
40805 KERN_WARNING
40806@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
40807 mdname(conf->mddev),
40808 (unsigned long long)s,
40809 bdn);
40810- } else if (atomic_read(&rdev->read_errors)
40811+ } else if (atomic_read_unchecked(&rdev->read_errors)
40812 > conf->max_nr_stripes)
40813 printk(KERN_WARNING
40814 "md/raid:%s: Too many read errors, failing device %s.\n",
40815diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
40816index 401ef64..836e563 100644
40817--- a/drivers/media/dvb-core/dvbdev.c
40818+++ b/drivers/media/dvb-core/dvbdev.c
40819@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
40820 const struct dvb_device *template, void *priv, int type)
40821 {
40822 struct dvb_device *dvbdev;
40823- struct file_operations *dvbdevfops;
40824+ file_operations_no_const *dvbdevfops;
40825 struct device *clsdev;
40826 int minor;
40827 int id;
40828diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
40829index 9b6c3bb..baeb5c7 100644
40830--- a/drivers/media/dvb-frontends/dib3000.h
40831+++ b/drivers/media/dvb-frontends/dib3000.h
40832@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
40833 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
40834 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
40835 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
40836-};
40837+} __no_const;
40838
40839 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
40840 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
40841diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
40842index c7a9be1..683f6f8 100644
40843--- a/drivers/media/pci/cx88/cx88-video.c
40844+++ b/drivers/media/pci/cx88/cx88-video.c
40845@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
40846
40847 /* ------------------------------------------------------------------ */
40848
40849-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40850-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40851-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40852+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40853+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40854+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
40855
40856 module_param_array(video_nr, int, NULL, 0444);
40857 module_param_array(vbi_nr, int, NULL, 0444);
40858diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
40859index d338b19..aae4f9e 100644
40860--- a/drivers/media/platform/omap/omap_vout.c
40861+++ b/drivers/media/platform/omap/omap_vout.c
40862@@ -63,7 +63,6 @@ enum omap_vout_channels {
40863 OMAP_VIDEO2,
40864 };
40865
40866-static struct videobuf_queue_ops video_vbq_ops;
40867 /* Variables configurable through module params*/
40868 static u32 video1_numbuffers = 3;
40869 static u32 video2_numbuffers = 3;
40870@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
40871 {
40872 struct videobuf_queue *q;
40873 struct omap_vout_device *vout = NULL;
40874+ static struct videobuf_queue_ops video_vbq_ops = {
40875+ .buf_setup = omap_vout_buffer_setup,
40876+ .buf_prepare = omap_vout_buffer_prepare,
40877+ .buf_release = omap_vout_buffer_release,
40878+ .buf_queue = omap_vout_buffer_queue,
40879+ };
40880
40881 vout = video_drvdata(file);
40882 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
40883@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
40884 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
40885
40886 q = &vout->vbq;
40887- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
40888- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
40889- video_vbq_ops.buf_release = omap_vout_buffer_release;
40890- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
40891 spin_lock_init(&vout->vbq_lock);
40892
40893 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
40894diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
40895index 04e6490..2df65bf 100644
40896--- a/drivers/media/platform/s5p-tv/mixer.h
40897+++ b/drivers/media/platform/s5p-tv/mixer.h
40898@@ -156,7 +156,7 @@ struct mxr_layer {
40899 /** layer index (unique identifier) */
40900 int idx;
40901 /** callbacks for layer methods */
40902- struct mxr_layer_ops ops;
40903+ struct mxr_layer_ops *ops;
40904 /** format array */
40905 const struct mxr_format **fmt_array;
40906 /** size of format array */
40907diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
40908index b93a21f..2535195 100644
40909--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
40910+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
40911@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
40912 {
40913 struct mxr_layer *layer;
40914 int ret;
40915- struct mxr_layer_ops ops = {
40916+ static struct mxr_layer_ops ops = {
40917 .release = mxr_graph_layer_release,
40918 .buffer_set = mxr_graph_buffer_set,
40919 .stream_set = mxr_graph_stream_set,
40920diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
40921index b713403..53cb5ad 100644
40922--- a/drivers/media/platform/s5p-tv/mixer_reg.c
40923+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
40924@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
40925 layer->update_buf = next;
40926 }
40927
40928- layer->ops.buffer_set(layer, layer->update_buf);
40929+ layer->ops->buffer_set(layer, layer->update_buf);
40930
40931 if (done && done != layer->shadow_buf)
40932 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
40933diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
40934index ef0efdf..8c78eb6 100644
40935--- a/drivers/media/platform/s5p-tv/mixer_video.c
40936+++ b/drivers/media/platform/s5p-tv/mixer_video.c
40937@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
40938 layer->geo.src.height = layer->geo.src.full_height;
40939
40940 mxr_geometry_dump(mdev, &layer->geo);
40941- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
40942+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
40943 mxr_geometry_dump(mdev, &layer->geo);
40944 }
40945
40946@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
40947 layer->geo.dst.full_width = mbus_fmt.width;
40948 layer->geo.dst.full_height = mbus_fmt.height;
40949 layer->geo.dst.field = mbus_fmt.field;
40950- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
40951+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
40952
40953 mxr_geometry_dump(mdev, &layer->geo);
40954 }
40955@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
40956 /* set source size to highest accepted value */
40957 geo->src.full_width = max(geo->dst.full_width, pix->width);
40958 geo->src.full_height = max(geo->dst.full_height, pix->height);
40959- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
40960+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
40961 mxr_geometry_dump(mdev, &layer->geo);
40962 /* set cropping to total visible screen */
40963 geo->src.width = pix->width;
40964@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
40965 geo->src.x_offset = 0;
40966 geo->src.y_offset = 0;
40967 /* assure consistency of geometry */
40968- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
40969+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
40970 mxr_geometry_dump(mdev, &layer->geo);
40971 /* set full size to lowest possible value */
40972 geo->src.full_width = 0;
40973 geo->src.full_height = 0;
40974- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
40975+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
40976 mxr_geometry_dump(mdev, &layer->geo);
40977
40978 /* returning results */
40979@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
40980 target->width = s->r.width;
40981 target->height = s->r.height;
40982
40983- layer->ops.fix_geometry(layer, stage, s->flags);
40984+ layer->ops->fix_geometry(layer, stage, s->flags);
40985
40986 /* retrieve update selection rectangle */
40987 res.left = target->x_offset;
40988@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
40989 mxr_output_get(mdev);
40990
40991 mxr_layer_update_output(layer);
40992- layer->ops.format_set(layer);
40993+ layer->ops->format_set(layer);
40994 /* enabling layer in hardware */
40995 spin_lock_irqsave(&layer->enq_slock, flags);
40996 layer->state = MXR_LAYER_STREAMING;
40997 spin_unlock_irqrestore(&layer->enq_slock, flags);
40998
40999- layer->ops.stream_set(layer, MXR_ENABLE);
41000+ layer->ops->stream_set(layer, MXR_ENABLE);
41001 mxr_streamer_get(mdev);
41002
41003 return 0;
41004@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
41005 spin_unlock_irqrestore(&layer->enq_slock, flags);
41006
41007 /* disabling layer in hardware */
41008- layer->ops.stream_set(layer, MXR_DISABLE);
41009+ layer->ops->stream_set(layer, MXR_DISABLE);
41010 /* remove one streamer */
41011 mxr_streamer_put(mdev);
41012 /* allow changes in output configuration */
41013@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
41014
41015 void mxr_layer_release(struct mxr_layer *layer)
41016 {
41017- if (layer->ops.release)
41018- layer->ops.release(layer);
41019+ if (layer->ops->release)
41020+ layer->ops->release(layer);
41021 }
41022
41023 void mxr_base_layer_release(struct mxr_layer *layer)
41024@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
41025
41026 layer->mdev = mdev;
41027 layer->idx = idx;
41028- layer->ops = *ops;
41029+ layer->ops = ops;
41030
41031 spin_lock_init(&layer->enq_slock);
41032 INIT_LIST_HEAD(&layer->enq_list);
41033diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
41034index 3d13a63..da31bf1 100644
41035--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
41036+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
41037@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
41038 {
41039 struct mxr_layer *layer;
41040 int ret;
41041- struct mxr_layer_ops ops = {
41042+ static struct mxr_layer_ops ops = {
41043 .release = mxr_vp_layer_release,
41044 .buffer_set = mxr_vp_buffer_set,
41045 .stream_set = mxr_vp_stream_set,
41046diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
41047index 545c04c..a14bded 100644
41048--- a/drivers/media/radio/radio-cadet.c
41049+++ b/drivers/media/radio/radio-cadet.c
41050@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
41051 unsigned char readbuf[RDS_BUFFER];
41052 int i = 0;
41053
41054+ if (count > RDS_BUFFER)
41055+ return -EFAULT;
41056 mutex_lock(&dev->lock);
41057 if (dev->rdsstat == 0)
41058 cadet_start_rds(dev);
41059@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
41060 while (i < count && dev->rdsin != dev->rdsout)
41061 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
41062
41063- if (i && copy_to_user(data, readbuf, i))
41064+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
41065 i = -EFAULT;
41066 unlock:
41067 mutex_unlock(&dev->lock);
41068diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
41069index 3940bb0..fb3952a 100644
41070--- a/drivers/media/usb/dvb-usb/cxusb.c
41071+++ b/drivers/media/usb/dvb-usb/cxusb.c
41072@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
41073
41074 struct dib0700_adapter_state {
41075 int (*set_param_save) (struct dvb_frontend *);
41076-};
41077+} __no_const;
41078
41079 static int dib7070_set_param_override(struct dvb_frontend *fe)
41080 {
41081diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
41082index 6e237b6..dc25556 100644
41083--- a/drivers/media/usb/dvb-usb/dw2102.c
41084+++ b/drivers/media/usb/dvb-usb/dw2102.c
41085@@ -118,7 +118,7 @@ struct su3000_state {
41086
41087 struct s6x0_state {
41088 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
41089-};
41090+} __no_const;
41091
41092 /* debug */
41093 static int dvb_usb_dw2102_debug;
41094diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
41095index f129551..ecf6514 100644
41096--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
41097+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
41098@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
41099 __u32 reserved;
41100 };
41101
41102-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
41103+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
41104 enum v4l2_memory memory)
41105 {
41106 void __user *up_pln;
41107@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
41108 return 0;
41109 }
41110
41111-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
41112+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
41113 enum v4l2_memory memory)
41114 {
41115 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
41116@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
41117 put_user(kp->start_block, &up->start_block) ||
41118 put_user(kp->blocks, &up->blocks) ||
41119 put_user(tmp, &up->edid) ||
41120- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
41121+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
41122 return -EFAULT;
41123 return 0;
41124 }
41125diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
41126index 7658586..1079260 100644
41127--- a/drivers/media/v4l2-core/v4l2-ioctl.c
41128+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
41129@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
41130 struct file *file, void *fh, void *p);
41131 } u;
41132 void (*debug)(const void *arg, bool write_only);
41133-};
41134+} __do_const;
41135+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
41136
41137 /* This control needs a priority check */
41138 #define INFO_FL_PRIO (1 << 0)
41139@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
41140 struct video_device *vfd = video_devdata(file);
41141 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
41142 bool write_only = false;
41143- struct v4l2_ioctl_info default_info;
41144+ v4l2_ioctl_info_no_const default_info;
41145 const struct v4l2_ioctl_info *info;
41146 void *fh = file->private_data;
41147 struct v4l2_fh *vfh = NULL;
41148@@ -2251,7 +2252,7 @@ done:
41149 }
41150
41151 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
41152- void * __user *user_ptr, void ***kernel_ptr)
41153+ void __user **user_ptr, void ***kernel_ptr)
41154 {
41155 int ret = 0;
41156
41157@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
41158 ret = -EINVAL;
41159 break;
41160 }
41161- *user_ptr = (void __user *)buf->m.planes;
41162+ *user_ptr = (void __force_user *)buf->m.planes;
41163 *kernel_ptr = (void *)&buf->m.planes;
41164 *array_size = sizeof(struct v4l2_plane) * buf->length;
41165 ret = 1;
41166@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
41167 ret = -EINVAL;
41168 break;
41169 }
41170- *user_ptr = (void __user *)ctrls->controls;
41171+ *user_ptr = (void __force_user *)ctrls->controls;
41172 *kernel_ptr = (void *)&ctrls->controls;
41173 *array_size = sizeof(struct v4l2_ext_control)
41174 * ctrls->count;
41175diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
41176index 767ff4d..c69d259 100644
41177--- a/drivers/message/fusion/mptbase.c
41178+++ b/drivers/message/fusion/mptbase.c
41179@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
41180 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
41181 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
41182
41183+#ifdef CONFIG_GRKERNSEC_HIDESYM
41184+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
41185+#else
41186 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
41187 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
41188+#endif
41189+
41190 /*
41191 * Rounding UP to nearest 4-kB boundary here...
41192 */
41193@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
41194 ioc->facts.GlobalCredits);
41195
41196 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
41197+#ifdef CONFIG_GRKERNSEC_HIDESYM
41198+ NULL, NULL);
41199+#else
41200 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
41201+#endif
41202 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
41203 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
41204 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
41205diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
41206index dd239bd..689c4f7 100644
41207--- a/drivers/message/fusion/mptsas.c
41208+++ b/drivers/message/fusion/mptsas.c
41209@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
41210 return 0;
41211 }
41212
41213+static inline void
41214+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
41215+{
41216+ if (phy_info->port_details) {
41217+ phy_info->port_details->rphy = rphy;
41218+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
41219+ ioc->name, rphy));
41220+ }
41221+
41222+ if (rphy) {
41223+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
41224+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
41225+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
41226+ ioc->name, rphy, rphy->dev.release));
41227+ }
41228+}
41229+
41230 /* no mutex */
41231 static void
41232 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
41233@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
41234 return NULL;
41235 }
41236
41237-static inline void
41238-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
41239-{
41240- if (phy_info->port_details) {
41241- phy_info->port_details->rphy = rphy;
41242- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
41243- ioc->name, rphy));
41244- }
41245-
41246- if (rphy) {
41247- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
41248- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
41249- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
41250- ioc->name, rphy, rphy->dev.release));
41251- }
41252-}
41253-
41254 static inline struct sas_port *
41255 mptsas_get_port(struct mptsas_phyinfo *phy_info)
41256 {
41257diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
41258index 727819c..ad74694 100644
41259--- a/drivers/message/fusion/mptscsih.c
41260+++ b/drivers/message/fusion/mptscsih.c
41261@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
41262
41263 h = shost_priv(SChost);
41264
41265- if (h) {
41266- if (h->info_kbuf == NULL)
41267- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
41268- return h->info_kbuf;
41269- h->info_kbuf[0] = '\0';
41270+ if (!h)
41271+ return NULL;
41272
41273- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
41274- h->info_kbuf[size-1] = '\0';
41275- }
41276+ if (h->info_kbuf == NULL)
41277+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
41278+ return h->info_kbuf;
41279+ h->info_kbuf[0] = '\0';
41280+
41281+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
41282+ h->info_kbuf[size-1] = '\0';
41283
41284 return h->info_kbuf;
41285 }
41286diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
41287index b7d87cd..9890039 100644
41288--- a/drivers/message/i2o/i2o_proc.c
41289+++ b/drivers/message/i2o/i2o_proc.c
41290@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
41291 "Array Controller Device"
41292 };
41293
41294-static char *chtostr(char *tmp, u8 *chars, int n)
41295-{
41296- tmp[0] = 0;
41297- return strncat(tmp, (char *)chars, n);
41298-}
41299-
41300 static int i2o_report_query_status(struct seq_file *seq, int block_status,
41301 char *group)
41302 {
41303@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
41304 } *result;
41305
41306 i2o_exec_execute_ddm_table ddm_table;
41307- char tmp[28 + 1];
41308
41309 result = kmalloc(sizeof(*result), GFP_KERNEL);
41310 if (!result)
41311@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
41312
41313 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
41314 seq_printf(seq, "%-#8x", ddm_table.module_id);
41315- seq_printf(seq, "%-29s",
41316- chtostr(tmp, ddm_table.module_name_version, 28));
41317+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
41318 seq_printf(seq, "%9d ", ddm_table.data_size);
41319 seq_printf(seq, "%8d", ddm_table.code_size);
41320
41321@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
41322
41323 i2o_driver_result_table *result;
41324 i2o_driver_store_table *dst;
41325- char tmp[28 + 1];
41326
41327 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
41328 if (result == NULL)
41329@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
41330
41331 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
41332 seq_printf(seq, "%-#8x", dst->module_id);
41333- seq_printf(seq, "%-29s",
41334- chtostr(tmp, dst->module_name_version, 28));
41335- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
41336+ seq_printf(seq, "%-.28s", dst->module_name_version);
41337+ seq_printf(seq, "%-.8s", dst->date);
41338 seq_printf(seq, "%8d ", dst->module_size);
41339 seq_printf(seq, "%8d ", dst->mpb_size);
41340 seq_printf(seq, "0x%04x", dst->module_flags);
41341@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
41342 // == (allow) 512d bytes (max)
41343 static u16 *work16 = (u16 *) work32;
41344 int token;
41345- char tmp[16 + 1];
41346
41347 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
41348
41349@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
41350 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
41351 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
41352 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
41353- seq_printf(seq, "Vendor info : %s\n",
41354- chtostr(tmp, (u8 *) (work32 + 2), 16));
41355- seq_printf(seq, "Product info : %s\n",
41356- chtostr(tmp, (u8 *) (work32 + 6), 16));
41357- seq_printf(seq, "Description : %s\n",
41358- chtostr(tmp, (u8 *) (work32 + 10), 16));
41359- seq_printf(seq, "Product rev. : %s\n",
41360- chtostr(tmp, (u8 *) (work32 + 14), 8));
41361+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
41362+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
41363+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
41364+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
41365
41366 seq_printf(seq, "Serial number : ");
41367 print_serial_number(seq, (u8 *) (work32 + 16),
41368@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
41369 u8 pad[256]; // allow up to 256 byte (max) serial number
41370 } result;
41371
41372- char tmp[24 + 1];
41373-
41374 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
41375
41376 if (token < 0) {
41377@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
41378 }
41379
41380 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
41381- seq_printf(seq, "Module name : %s\n",
41382- chtostr(tmp, result.module_name, 24));
41383- seq_printf(seq, "Module revision : %s\n",
41384- chtostr(tmp, result.module_rev, 8));
41385+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
41386+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
41387
41388 seq_printf(seq, "Serial number : ");
41389 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
41390@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
41391 u8 instance_number[4];
41392 } result;
41393
41394- char tmp[64 + 1];
41395-
41396 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
41397
41398 if (token < 0) {
41399@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
41400 return 0;
41401 }
41402
41403- seq_printf(seq, "Device name : %s\n",
41404- chtostr(tmp, result.device_name, 64));
41405- seq_printf(seq, "Service name : %s\n",
41406- chtostr(tmp, result.service_name, 64));
41407- seq_printf(seq, "Physical name : %s\n",
41408- chtostr(tmp, result.physical_location, 64));
41409- seq_printf(seq, "Instance number : %s\n",
41410- chtostr(tmp, result.instance_number, 4));
41411+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
41412+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
41413+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
41414+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
41415
41416 return 0;
41417 }
41418diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
41419index a8c08f3..155fe3d 100644
41420--- a/drivers/message/i2o/iop.c
41421+++ b/drivers/message/i2o/iop.c
41422@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
41423
41424 spin_lock_irqsave(&c->context_list_lock, flags);
41425
41426- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
41427- atomic_inc(&c->context_list_counter);
41428+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
41429+ atomic_inc_unchecked(&c->context_list_counter);
41430
41431- entry->context = atomic_read(&c->context_list_counter);
41432+ entry->context = atomic_read_unchecked(&c->context_list_counter);
41433
41434 list_add(&entry->list, &c->context_list);
41435
41436@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
41437
41438 #if BITS_PER_LONG == 64
41439 spin_lock_init(&c->context_list_lock);
41440- atomic_set(&c->context_list_counter, 0);
41441+ atomic_set_unchecked(&c->context_list_counter, 0);
41442 INIT_LIST_HEAD(&c->context_list);
41443 #endif
41444
41445diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
41446index 45ece11..8efa218 100644
41447--- a/drivers/mfd/janz-cmodio.c
41448+++ b/drivers/mfd/janz-cmodio.c
41449@@ -13,6 +13,7 @@
41450
41451 #include <linux/kernel.h>
41452 #include <linux/module.h>
41453+#include <linux/slab.h>
41454 #include <linux/init.h>
41455 #include <linux/pci.h>
41456 #include <linux/interrupt.h>
41457diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
41458index a5f9888..1c0ed56 100644
41459--- a/drivers/mfd/twl4030-irq.c
41460+++ b/drivers/mfd/twl4030-irq.c
41461@@ -35,6 +35,7 @@
41462 #include <linux/of.h>
41463 #include <linux/irqdomain.h>
41464 #include <linux/i2c/twl.h>
41465+#include <asm/pgtable.h>
41466
41467 #include "twl-core.h"
41468
41469@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
41470 * Install an irq handler for each of the SIH modules;
41471 * clone dummy irq_chip since PIH can't *do* anything
41472 */
41473- twl4030_irq_chip = dummy_irq_chip;
41474- twl4030_irq_chip.name = "twl4030";
41475+ pax_open_kernel();
41476+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
41477+ *(const char **)&twl4030_irq_chip.name = "twl4030";
41478
41479- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
41480+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
41481+ pax_close_kernel();
41482
41483 for (i = irq_base; i < irq_end; i++) {
41484 irq_set_chip_and_handler(i, &twl4030_irq_chip,
41485diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
41486index 277a8db..0e0b754 100644
41487--- a/drivers/mfd/twl6030-irq.c
41488+++ b/drivers/mfd/twl6030-irq.c
41489@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
41490 * install an irq handler for each of the modules;
41491 * clone dummy irq_chip since PIH can't *do* anything
41492 */
41493- twl6030_irq_chip = dummy_irq_chip;
41494- twl6030_irq_chip.name = "twl6030";
41495- twl6030_irq_chip.irq_set_type = NULL;
41496- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
41497+ pax_open_kernel();
41498+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
41499+ *(const char **)&twl6030_irq_chip.name = "twl6030";
41500+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
41501+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
41502+ pax_close_kernel();
41503
41504 for (i = irq_base; i < irq_end; i++) {
41505 irq_set_chip_and_handler(i, &twl6030_irq_chip,
41506diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
41507index f32550a..e3e52a2 100644
41508--- a/drivers/misc/c2port/core.c
41509+++ b/drivers/misc/c2port/core.c
41510@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
41511 mutex_init(&c2dev->mutex);
41512
41513 /* Create binary file */
41514- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
41515+ pax_open_kernel();
41516+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
41517+ pax_close_kernel();
41518 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
41519 if (unlikely(ret))
41520 goto error_device_create_bin_file;
41521diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
41522index 36f5d52..32311c3 100644
41523--- a/drivers/misc/kgdbts.c
41524+++ b/drivers/misc/kgdbts.c
41525@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
41526 char before[BREAK_INSTR_SIZE];
41527 char after[BREAK_INSTR_SIZE];
41528
41529- probe_kernel_read(before, (char *)kgdbts_break_test,
41530+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
41531 BREAK_INSTR_SIZE);
41532 init_simple_test();
41533 ts.tst = plant_and_detach_test;
41534@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
41535 /* Activate test with initial breakpoint */
41536 if (!is_early)
41537 kgdb_breakpoint();
41538- probe_kernel_read(after, (char *)kgdbts_break_test,
41539+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
41540 BREAK_INSTR_SIZE);
41541 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
41542 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
41543diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
41544index 4cd4a3d..b48cbc7 100644
41545--- a/drivers/misc/lis3lv02d/lis3lv02d.c
41546+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
41547@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
41548 * the lid is closed. This leads to interrupts as soon as a little move
41549 * is done.
41550 */
41551- atomic_inc(&lis3->count);
41552+ atomic_inc_unchecked(&lis3->count);
41553
41554 wake_up_interruptible(&lis3->misc_wait);
41555 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
41556@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
41557 if (lis3->pm_dev)
41558 pm_runtime_get_sync(lis3->pm_dev);
41559
41560- atomic_set(&lis3->count, 0);
41561+ atomic_set_unchecked(&lis3->count, 0);
41562 return 0;
41563 }
41564
41565@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
41566 add_wait_queue(&lis3->misc_wait, &wait);
41567 while (true) {
41568 set_current_state(TASK_INTERRUPTIBLE);
41569- data = atomic_xchg(&lis3->count, 0);
41570+ data = atomic_xchg_unchecked(&lis3->count, 0);
41571 if (data)
41572 break;
41573
41574@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
41575 struct lis3lv02d, miscdev);
41576
41577 poll_wait(file, &lis3->misc_wait, wait);
41578- if (atomic_read(&lis3->count))
41579+ if (atomic_read_unchecked(&lis3->count))
41580 return POLLIN | POLLRDNORM;
41581 return 0;
41582 }
41583diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
41584index c439c82..1f20f57 100644
41585--- a/drivers/misc/lis3lv02d/lis3lv02d.h
41586+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
41587@@ -297,7 +297,7 @@ struct lis3lv02d {
41588 struct input_polled_dev *idev; /* input device */
41589 struct platform_device *pdev; /* platform device */
41590 struct regulator_bulk_data regulators[2];
41591- atomic_t count; /* interrupt count after last read */
41592+ atomic_unchecked_t count; /* interrupt count after last read */
41593 union axis_conversion ac; /* hw -> logical axis */
41594 int mapped_btns[3];
41595
41596diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
41597index 2f30bad..c4c13d0 100644
41598--- a/drivers/misc/sgi-gru/gruhandles.c
41599+++ b/drivers/misc/sgi-gru/gruhandles.c
41600@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
41601 unsigned long nsec;
41602
41603 nsec = CLKS2NSEC(clks);
41604- atomic_long_inc(&mcs_op_statistics[op].count);
41605- atomic_long_add(nsec, &mcs_op_statistics[op].total);
41606+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
41607+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
41608 if (mcs_op_statistics[op].max < nsec)
41609 mcs_op_statistics[op].max = nsec;
41610 }
41611diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
41612index 797d796..ae8f01e 100644
41613--- a/drivers/misc/sgi-gru/gruprocfs.c
41614+++ b/drivers/misc/sgi-gru/gruprocfs.c
41615@@ -32,9 +32,9 @@
41616
41617 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
41618
41619-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
41620+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
41621 {
41622- unsigned long val = atomic_long_read(v);
41623+ unsigned long val = atomic_long_read_unchecked(v);
41624
41625 seq_printf(s, "%16lu %s\n", val, id);
41626 }
41627@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
41628
41629 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
41630 for (op = 0; op < mcsop_last; op++) {
41631- count = atomic_long_read(&mcs_op_statistics[op].count);
41632- total = atomic_long_read(&mcs_op_statistics[op].total);
41633+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
41634+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
41635 max = mcs_op_statistics[op].max;
41636 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
41637 count ? total / count : 0, max);
41638diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
41639index 5c3ce24..4915ccb 100644
41640--- a/drivers/misc/sgi-gru/grutables.h
41641+++ b/drivers/misc/sgi-gru/grutables.h
41642@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
41643 * GRU statistics.
41644 */
41645 struct gru_stats_s {
41646- atomic_long_t vdata_alloc;
41647- atomic_long_t vdata_free;
41648- atomic_long_t gts_alloc;
41649- atomic_long_t gts_free;
41650- atomic_long_t gms_alloc;
41651- atomic_long_t gms_free;
41652- atomic_long_t gts_double_allocate;
41653- atomic_long_t assign_context;
41654- atomic_long_t assign_context_failed;
41655- atomic_long_t free_context;
41656- atomic_long_t load_user_context;
41657- atomic_long_t load_kernel_context;
41658- atomic_long_t lock_kernel_context;
41659- atomic_long_t unlock_kernel_context;
41660- atomic_long_t steal_user_context;
41661- atomic_long_t steal_kernel_context;
41662- atomic_long_t steal_context_failed;
41663- atomic_long_t nopfn;
41664- atomic_long_t asid_new;
41665- atomic_long_t asid_next;
41666- atomic_long_t asid_wrap;
41667- atomic_long_t asid_reuse;
41668- atomic_long_t intr;
41669- atomic_long_t intr_cbr;
41670- atomic_long_t intr_tfh;
41671- atomic_long_t intr_spurious;
41672- atomic_long_t intr_mm_lock_failed;
41673- atomic_long_t call_os;
41674- atomic_long_t call_os_wait_queue;
41675- atomic_long_t user_flush_tlb;
41676- atomic_long_t user_unload_context;
41677- atomic_long_t user_exception;
41678- atomic_long_t set_context_option;
41679- atomic_long_t check_context_retarget_intr;
41680- atomic_long_t check_context_unload;
41681- atomic_long_t tlb_dropin;
41682- atomic_long_t tlb_preload_page;
41683- atomic_long_t tlb_dropin_fail_no_asid;
41684- atomic_long_t tlb_dropin_fail_upm;
41685- atomic_long_t tlb_dropin_fail_invalid;
41686- atomic_long_t tlb_dropin_fail_range_active;
41687- atomic_long_t tlb_dropin_fail_idle;
41688- atomic_long_t tlb_dropin_fail_fmm;
41689- atomic_long_t tlb_dropin_fail_no_exception;
41690- atomic_long_t tfh_stale_on_fault;
41691- atomic_long_t mmu_invalidate_range;
41692- atomic_long_t mmu_invalidate_page;
41693- atomic_long_t flush_tlb;
41694- atomic_long_t flush_tlb_gru;
41695- atomic_long_t flush_tlb_gru_tgh;
41696- atomic_long_t flush_tlb_gru_zero_asid;
41697+ atomic_long_unchecked_t vdata_alloc;
41698+ atomic_long_unchecked_t vdata_free;
41699+ atomic_long_unchecked_t gts_alloc;
41700+ atomic_long_unchecked_t gts_free;
41701+ atomic_long_unchecked_t gms_alloc;
41702+ atomic_long_unchecked_t gms_free;
41703+ atomic_long_unchecked_t gts_double_allocate;
41704+ atomic_long_unchecked_t assign_context;
41705+ atomic_long_unchecked_t assign_context_failed;
41706+ atomic_long_unchecked_t free_context;
41707+ atomic_long_unchecked_t load_user_context;
41708+ atomic_long_unchecked_t load_kernel_context;
41709+ atomic_long_unchecked_t lock_kernel_context;
41710+ atomic_long_unchecked_t unlock_kernel_context;
41711+ atomic_long_unchecked_t steal_user_context;
41712+ atomic_long_unchecked_t steal_kernel_context;
41713+ atomic_long_unchecked_t steal_context_failed;
41714+ atomic_long_unchecked_t nopfn;
41715+ atomic_long_unchecked_t asid_new;
41716+ atomic_long_unchecked_t asid_next;
41717+ atomic_long_unchecked_t asid_wrap;
41718+ atomic_long_unchecked_t asid_reuse;
41719+ atomic_long_unchecked_t intr;
41720+ atomic_long_unchecked_t intr_cbr;
41721+ atomic_long_unchecked_t intr_tfh;
41722+ atomic_long_unchecked_t intr_spurious;
41723+ atomic_long_unchecked_t intr_mm_lock_failed;
41724+ atomic_long_unchecked_t call_os;
41725+ atomic_long_unchecked_t call_os_wait_queue;
41726+ atomic_long_unchecked_t user_flush_tlb;
41727+ atomic_long_unchecked_t user_unload_context;
41728+ atomic_long_unchecked_t user_exception;
41729+ atomic_long_unchecked_t set_context_option;
41730+ atomic_long_unchecked_t check_context_retarget_intr;
41731+ atomic_long_unchecked_t check_context_unload;
41732+ atomic_long_unchecked_t tlb_dropin;
41733+ atomic_long_unchecked_t tlb_preload_page;
41734+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
41735+ atomic_long_unchecked_t tlb_dropin_fail_upm;
41736+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
41737+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
41738+ atomic_long_unchecked_t tlb_dropin_fail_idle;
41739+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
41740+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
41741+ atomic_long_unchecked_t tfh_stale_on_fault;
41742+ atomic_long_unchecked_t mmu_invalidate_range;
41743+ atomic_long_unchecked_t mmu_invalidate_page;
41744+ atomic_long_unchecked_t flush_tlb;
41745+ atomic_long_unchecked_t flush_tlb_gru;
41746+ atomic_long_unchecked_t flush_tlb_gru_tgh;
41747+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
41748
41749- atomic_long_t copy_gpa;
41750- atomic_long_t read_gpa;
41751+ atomic_long_unchecked_t copy_gpa;
41752+ atomic_long_unchecked_t read_gpa;
41753
41754- atomic_long_t mesq_receive;
41755- atomic_long_t mesq_receive_none;
41756- atomic_long_t mesq_send;
41757- atomic_long_t mesq_send_failed;
41758- atomic_long_t mesq_noop;
41759- atomic_long_t mesq_send_unexpected_error;
41760- atomic_long_t mesq_send_lb_overflow;
41761- atomic_long_t mesq_send_qlimit_reached;
41762- atomic_long_t mesq_send_amo_nacked;
41763- atomic_long_t mesq_send_put_nacked;
41764- atomic_long_t mesq_page_overflow;
41765- atomic_long_t mesq_qf_locked;
41766- atomic_long_t mesq_qf_noop_not_full;
41767- atomic_long_t mesq_qf_switch_head_failed;
41768- atomic_long_t mesq_qf_unexpected_error;
41769- atomic_long_t mesq_noop_unexpected_error;
41770- atomic_long_t mesq_noop_lb_overflow;
41771- atomic_long_t mesq_noop_qlimit_reached;
41772- atomic_long_t mesq_noop_amo_nacked;
41773- atomic_long_t mesq_noop_put_nacked;
41774- atomic_long_t mesq_noop_page_overflow;
41775+ atomic_long_unchecked_t mesq_receive;
41776+ atomic_long_unchecked_t mesq_receive_none;
41777+ atomic_long_unchecked_t mesq_send;
41778+ atomic_long_unchecked_t mesq_send_failed;
41779+ atomic_long_unchecked_t mesq_noop;
41780+ atomic_long_unchecked_t mesq_send_unexpected_error;
41781+ atomic_long_unchecked_t mesq_send_lb_overflow;
41782+ atomic_long_unchecked_t mesq_send_qlimit_reached;
41783+ atomic_long_unchecked_t mesq_send_amo_nacked;
41784+ atomic_long_unchecked_t mesq_send_put_nacked;
41785+ atomic_long_unchecked_t mesq_page_overflow;
41786+ atomic_long_unchecked_t mesq_qf_locked;
41787+ atomic_long_unchecked_t mesq_qf_noop_not_full;
41788+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
41789+ atomic_long_unchecked_t mesq_qf_unexpected_error;
41790+ atomic_long_unchecked_t mesq_noop_unexpected_error;
41791+ atomic_long_unchecked_t mesq_noop_lb_overflow;
41792+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
41793+ atomic_long_unchecked_t mesq_noop_amo_nacked;
41794+ atomic_long_unchecked_t mesq_noop_put_nacked;
41795+ atomic_long_unchecked_t mesq_noop_page_overflow;
41796
41797 };
41798
41799@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
41800 tghop_invalidate, mcsop_last};
41801
41802 struct mcs_op_statistic {
41803- atomic_long_t count;
41804- atomic_long_t total;
41805+ atomic_long_unchecked_t count;
41806+ atomic_long_unchecked_t total;
41807 unsigned long max;
41808 };
41809
41810@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
41811
41812 #define STAT(id) do { \
41813 if (gru_options & OPT_STATS) \
41814- atomic_long_inc(&gru_stats.id); \
41815+ atomic_long_inc_unchecked(&gru_stats.id); \
41816 } while (0)
41817
41818 #ifdef CONFIG_SGI_GRU_DEBUG
41819diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
41820index c862cd4..0d176fe 100644
41821--- a/drivers/misc/sgi-xp/xp.h
41822+++ b/drivers/misc/sgi-xp/xp.h
41823@@ -288,7 +288,7 @@ struct xpc_interface {
41824 xpc_notify_func, void *);
41825 void (*received) (short, int, void *);
41826 enum xp_retval (*partid_to_nasids) (short, void *);
41827-};
41828+} __no_const;
41829
41830 extern struct xpc_interface xpc_interface;
41831
41832diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
41833index b94d5f7..7f494c5 100644
41834--- a/drivers/misc/sgi-xp/xpc.h
41835+++ b/drivers/misc/sgi-xp/xpc.h
41836@@ -835,6 +835,7 @@ struct xpc_arch_operations {
41837 void (*received_payload) (struct xpc_channel *, void *);
41838 void (*notify_senders_of_disconnect) (struct xpc_channel *);
41839 };
41840+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
41841
41842 /* struct xpc_partition act_state values (for XPC HB) */
41843
41844@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
41845 /* found in xpc_main.c */
41846 extern struct device *xpc_part;
41847 extern struct device *xpc_chan;
41848-extern struct xpc_arch_operations xpc_arch_ops;
41849+extern xpc_arch_operations_no_const xpc_arch_ops;
41850 extern int xpc_disengage_timelimit;
41851 extern int xpc_disengage_timedout;
41852 extern int xpc_activate_IRQ_rcvd;
41853diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
41854index d971817..33bdca5 100644
41855--- a/drivers/misc/sgi-xp/xpc_main.c
41856+++ b/drivers/misc/sgi-xp/xpc_main.c
41857@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
41858 .notifier_call = xpc_system_die,
41859 };
41860
41861-struct xpc_arch_operations xpc_arch_ops;
41862+xpc_arch_operations_no_const xpc_arch_ops;
41863
41864 /*
41865 * Timer function to enforce the timelimit on the partition disengage.
41866@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
41867
41868 if (((die_args->trapnr == X86_TRAP_MF) ||
41869 (die_args->trapnr == X86_TRAP_XF)) &&
41870- !user_mode_vm(die_args->regs))
41871+ !user_mode(die_args->regs))
41872 xpc_die_deactivate();
41873
41874 break;
41875diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
41876index 49f04bc..65660c2 100644
41877--- a/drivers/mmc/core/mmc_ops.c
41878+++ b/drivers/mmc/core/mmc_ops.c
41879@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
41880 void *data_buf;
41881 int is_on_stack;
41882
41883- is_on_stack = object_is_on_stack(buf);
41884+ is_on_stack = object_starts_on_stack(buf);
41885 if (is_on_stack) {
41886 /*
41887 * dma onto stack is unsafe/nonportable, but callers to this
41888diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
41889index 0b74189..818358f 100644
41890--- a/drivers/mmc/host/dw_mmc.h
41891+++ b/drivers/mmc/host/dw_mmc.h
41892@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
41893 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
41894 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
41895 int (*parse_dt)(struct dw_mci *host);
41896-};
41897+} __do_const;
41898 #endif /* _DW_MMC_H_ */
41899diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
41900index c6f6246..60760a8 100644
41901--- a/drivers/mmc/host/sdhci-s3c.c
41902+++ b/drivers/mmc/host/sdhci-s3c.c
41903@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
41904 * we can use overriding functions instead of default.
41905 */
41906 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
41907- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
41908- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
41909- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
41910+ pax_open_kernel();
41911+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
41912+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
41913+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
41914+ pax_close_kernel();
41915 }
41916
41917 /* It supports additional host capabilities if needed */
41918diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
41919index 0c8bb6b..6f35deb 100644
41920--- a/drivers/mtd/nand/denali.c
41921+++ b/drivers/mtd/nand/denali.c
41922@@ -24,6 +24,7 @@
41923 #include <linux/slab.h>
41924 #include <linux/mtd/mtd.h>
41925 #include <linux/module.h>
41926+#include <linux/slab.h>
41927
41928 #include "denali.h"
41929
41930diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
41931index 51b9d6a..52af9a7 100644
41932--- a/drivers/mtd/nftlmount.c
41933+++ b/drivers/mtd/nftlmount.c
41934@@ -24,6 +24,7 @@
41935 #include <asm/errno.h>
41936 #include <linux/delay.h>
41937 #include <linux/slab.h>
41938+#include <linux/sched.h>
41939 #include <linux/mtd/mtd.h>
41940 #include <linux/mtd/nand.h>
41941 #include <linux/mtd/nftl.h>
41942diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
41943index f9d5615..99dd95f 100644
41944--- a/drivers/mtd/sm_ftl.c
41945+++ b/drivers/mtd/sm_ftl.c
41946@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
41947 #define SM_CIS_VENDOR_OFFSET 0x59
41948 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
41949 {
41950- struct attribute_group *attr_group;
41951+ attribute_group_no_const *attr_group;
41952 struct attribute **attributes;
41953 struct sm_sysfs_attribute *vendor_attribute;
41954
41955diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
41956index f975696..4597e21 100644
41957--- a/drivers/net/bonding/bond_main.c
41958+++ b/drivers/net/bonding/bond_main.c
41959@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
41960 return tx_queues;
41961 }
41962
41963-static struct rtnl_link_ops bond_link_ops __read_mostly = {
41964+static struct rtnl_link_ops bond_link_ops = {
41965 .kind = "bond",
41966 .priv_size = sizeof(struct bonding),
41967 .setup = bond_setup,
41968@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
41969
41970 bond_destroy_debugfs();
41971
41972- rtnl_link_unregister(&bond_link_ops);
41973 unregister_pernet_subsys(&bond_net_ops);
41974+ rtnl_link_unregister(&bond_link_ops);
41975
41976 #ifdef CONFIG_NET_POLL_CONTROLLER
41977 /*
41978diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
41979index 25723d8..925ab8e 100644
41980--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
41981+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
41982@@ -649,7 +649,7 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
41983 if ((mc->ptr + rec_len) > mc->end)
41984 goto decode_failed;
41985
41986- memcpy(cf->data, mc->ptr, rec_len);
41987+ memcpy(cf->data, mc->ptr, cf->can_dlc);
41988 mc->ptr += rec_len;
41989 }
41990
41991diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
41992index e1d2643..7f4133b 100644
41993--- a/drivers/net/ethernet/8390/ax88796.c
41994+++ b/drivers/net/ethernet/8390/ax88796.c
41995@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
41996 if (ax->plat->reg_offsets)
41997 ei_local->reg_offset = ax->plat->reg_offsets;
41998 else {
41999+ resource_size_t _mem_size = mem_size;
42000+ do_div(_mem_size, 0x18);
42001 ei_local->reg_offset = ax->reg_offsets;
42002 for (ret = 0; ret < 0x18; ret++)
42003- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
42004+ ax->reg_offsets[ret] = _mem_size * ret;
42005 }
42006
42007 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
42008diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
42009index 151675d..0139a9d 100644
42010--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
42011+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
42012@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
42013 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
42014 {
42015 /* RX_MODE controlling object */
42016- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
42017+ bnx2x_init_rx_mode_obj(bp);
42018
42019 /* multicast configuration controlling object */
42020 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
42021diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
42022index ce1a916..10b52b0 100644
42023--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
42024+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
42025@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
42026 struct bnx2x *bp = netdev_priv(dev);
42027
42028 /* Use the ethtool_dump "flag" field as the dump preset index */
42029+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
42030+ return -EINVAL;
42031+
42032 bp->dump_preset_idx = val->flag;
42033 return 0;
42034 }
42035@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
42036 struct bnx2x *bp = netdev_priv(dev);
42037 struct dump_header dump_hdr = {0};
42038
42039- memset(p, 0, dump->len);
42040-
42041 /* Disable parity attentions as long as following dump may
42042 * cause false alarms by reading never written registers. We
42043 * will re-enable parity attentions right after the dump.
42044diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
42045index b4c9dea..2a9927f 100644
42046--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
42047+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
42048@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
42049 bp->min_msix_vec_cnt = 2;
42050 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
42051
42052+ bp->dump_preset_idx = 1;
42053+
42054 return rc;
42055 }
42056
42057diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
42058index 32a9609..0b1c53a 100644
42059--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
42060+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
42061@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
42062 return rc;
42063 }
42064
42065-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
42066- struct bnx2x_rx_mode_obj *o)
42067+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
42068 {
42069 if (CHIP_IS_E1x(bp)) {
42070- o->wait_comp = bnx2x_empty_rx_mode_wait;
42071- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
42072+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
42073+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
42074 } else {
42075- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
42076- o->config_rx_mode = bnx2x_set_rx_mode_e2;
42077+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
42078+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
42079 }
42080 }
42081
42082diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
42083index 43c00bc..dd1d03d 100644
42084--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
42085+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
42086@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
42087
42088 /********************* RX MODE ****************/
42089
42090-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
42091- struct bnx2x_rx_mode_obj *o);
42092+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
42093
42094 /**
42095 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
42096diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
42097index ff6e30e..87e8452 100644
42098--- a/drivers/net/ethernet/broadcom/tg3.h
42099+++ b/drivers/net/ethernet/broadcom/tg3.h
42100@@ -147,6 +147,7 @@
42101 #define CHIPREV_ID_5750_A0 0x4000
42102 #define CHIPREV_ID_5750_A1 0x4001
42103 #define CHIPREV_ID_5750_A3 0x4003
42104+#define CHIPREV_ID_5750_C1 0x4201
42105 #define CHIPREV_ID_5750_C2 0x4202
42106 #define CHIPREV_ID_5752_A0_HW 0x5000
42107 #define CHIPREV_ID_5752_A0 0x6000
42108diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
42109index 71497e8..b650951 100644
42110--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
42111+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
42112@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
42113 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
42114 t3_read_reg(adapter, A_PCIE_PEX_ERR));
42115
42116+ rtnl_lock();
42117 t3_resume_ports(adapter);
42118+ rtnl_unlock();
42119 }
42120
42121 static const struct pci_error_handlers t3_err_handler = {
42122diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
42123index 8cffcdf..aadf043 100644
42124--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
42125+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
42126@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
42127 */
42128 struct l2t_skb_cb {
42129 arp_failure_handler_func arp_failure_handler;
42130-};
42131+} __no_const;
42132
42133 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
42134
42135diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
42136index 4c83003..2a2a5b9 100644
42137--- a/drivers/net/ethernet/dec/tulip/de4x5.c
42138+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
42139@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
42140 for (i=0; i<ETH_ALEN; i++) {
42141 tmp.addr[i] = dev->dev_addr[i];
42142 }
42143- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
42144+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
42145 break;
42146
42147 case DE4X5_SET_HWADDR: /* Set the hardware address */
42148@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
42149 spin_lock_irqsave(&lp->lock, flags);
42150 memcpy(&statbuf, &lp->pktStats, ioc->len);
42151 spin_unlock_irqrestore(&lp->lock, flags);
42152- if (copy_to_user(ioc->data, &statbuf, ioc->len))
42153+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
42154 return -EFAULT;
42155 break;
42156 }
42157diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
42158index 6e43426..1bd8365 100644
42159--- a/drivers/net/ethernet/emulex/benet/be_main.c
42160+++ b/drivers/net/ethernet/emulex/benet/be_main.c
42161@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
42162
42163 if (wrapped)
42164 newacc += 65536;
42165- ACCESS_ONCE(*acc) = newacc;
42166+ ACCESS_ONCE_RW(*acc) = newacc;
42167 }
42168
42169 void populate_erx_stats(struct be_adapter *adapter,
42170diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
42171index 21b85fb..b49e5fc 100644
42172--- a/drivers/net/ethernet/faraday/ftgmac100.c
42173+++ b/drivers/net/ethernet/faraday/ftgmac100.c
42174@@ -31,6 +31,8 @@
42175 #include <linux/netdevice.h>
42176 #include <linux/phy.h>
42177 #include <linux/platform_device.h>
42178+#include <linux/interrupt.h>
42179+#include <linux/irqreturn.h>
42180 #include <net/ip.h>
42181
42182 #include "ftgmac100.h"
42183diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
42184index a6eda8d..935d273 100644
42185--- a/drivers/net/ethernet/faraday/ftmac100.c
42186+++ b/drivers/net/ethernet/faraday/ftmac100.c
42187@@ -31,6 +31,8 @@
42188 #include <linux/module.h>
42189 #include <linux/netdevice.h>
42190 #include <linux/platform_device.h>
42191+#include <linux/interrupt.h>
42192+#include <linux/irqreturn.h>
42193
42194 #include "ftmac100.h"
42195
42196diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
42197index 331987d..3be1135 100644
42198--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
42199+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
42200@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
42201 }
42202
42203 /* update the base incval used to calculate frequency adjustment */
42204- ACCESS_ONCE(adapter->base_incval) = incval;
42205+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
42206 smp_mb();
42207
42208 /* need lock to prevent incorrect read while modifying cyclecounter */
42209diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
42210index fbe5363..266b4e3 100644
42211--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
42212+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
42213@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
42214 struct __vxge_hw_fifo *fifo;
42215 struct vxge_hw_fifo_config *config;
42216 u32 txdl_size, txdl_per_memblock;
42217- struct vxge_hw_mempool_cbs fifo_mp_callback;
42218+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
42219+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
42220+ };
42221+
42222 struct __vxge_hw_virtualpath *vpath;
42223
42224 if ((vp == NULL) || (attr == NULL)) {
42225@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
42226 goto exit;
42227 }
42228
42229- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
42230-
42231 fifo->mempool =
42232 __vxge_hw_mempool_create(vpath->hldev,
42233 fifo->config->memblock_size,
42234diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
42235index 5e7fb1d..f8d1810 100644
42236--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
42237+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
42238@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
42239 op_mode = QLC_83XX_DEFAULT_OPMODE;
42240
42241 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
42242- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
42243+ pax_open_kernel();
42244+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
42245+ pax_close_kernel();
42246 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
42247 } else {
42248 return -EIO;
42249diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
42250index b0c3de9..fc5857e 100644
42251--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
42252+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
42253@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
42254 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
42255 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
42256 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
42257- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
42258+ pax_open_kernel();
42259+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
42260+ pax_close_kernel();
42261 } else if (priv_level == QLCNIC_PRIV_FUNC) {
42262 ahw->op_mode = QLCNIC_PRIV_FUNC;
42263 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
42264- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
42265+ pax_open_kernel();
42266+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
42267+ pax_close_kernel();
42268 } else if (priv_level == QLCNIC_MGMT_FUNC) {
42269 ahw->op_mode = QLCNIC_MGMT_FUNC;
42270 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
42271- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
42272+ pax_open_kernel();
42273+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
42274+ pax_close_kernel();
42275 } else {
42276 return -EIO;
42277 }
42278diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
42279index 6acf82b..14b097e 100644
42280--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
42281+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
42282@@ -206,10 +206,10 @@ int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter *adapter)
42283 if (err) {
42284 dev_info(&adapter->pdev->dev,
42285 "Failed to set driver version in firmware\n");
42286- return -EIO;
42287+ err = -EIO;
42288 }
42289-
42290- return 0;
42291+ qlcnic_free_mbx_args(&cmd);
42292+ return err;
42293 }
42294
42295 int
42296diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
42297index d3f8797..82a03d3 100644
42298--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
42299+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
42300@@ -262,7 +262,7 @@ void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
42301
42302 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
42303 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
42304- memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
42305+ memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
42306
42307 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
42308 vlan_req->vlan_id = cpu_to_le16(vlan_id);
42309diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
42310index 887aebe..9095ff9 100644
42311--- a/drivers/net/ethernet/realtek/8139cp.c
42312+++ b/drivers/net/ethernet/realtek/8139cp.c
42313@@ -524,6 +524,7 @@ rx_status_loop:
42314 PCI_DMA_FROMDEVICE);
42315 if (dma_mapping_error(&cp->pdev->dev, new_mapping)) {
42316 dev->stats.rx_dropped++;
42317+ kfree_skb(new_skb);
42318 goto rx_next;
42319 }
42320
42321diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
42322index 393f961..d343034 100644
42323--- a/drivers/net/ethernet/realtek/r8169.c
42324+++ b/drivers/net/ethernet/realtek/r8169.c
42325@@ -753,22 +753,22 @@ struct rtl8169_private {
42326 struct mdio_ops {
42327 void (*write)(struct rtl8169_private *, int, int);
42328 int (*read)(struct rtl8169_private *, int);
42329- } mdio_ops;
42330+ } __no_const mdio_ops;
42331
42332 struct pll_power_ops {
42333 void (*down)(struct rtl8169_private *);
42334 void (*up)(struct rtl8169_private *);
42335- } pll_power_ops;
42336+ } __no_const pll_power_ops;
42337
42338 struct jumbo_ops {
42339 void (*enable)(struct rtl8169_private *);
42340 void (*disable)(struct rtl8169_private *);
42341- } jumbo_ops;
42342+ } __no_const jumbo_ops;
42343
42344 struct csi_ops {
42345 void (*write)(struct rtl8169_private *, int, int);
42346 u32 (*read)(struct rtl8169_private *, int);
42347- } csi_ops;
42348+ } __no_const csi_ops;
42349
42350 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
42351 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
42352diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
42353index 9a95abf..36df7f9 100644
42354--- a/drivers/net/ethernet/sfc/ptp.c
42355+++ b/drivers/net/ethernet/sfc/ptp.c
42356@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
42357 (u32)((u64)ptp->start.dma_addr >> 32));
42358
42359 /* Clear flag that signals MC ready */
42360- ACCESS_ONCE(*start) = 0;
42361+ ACCESS_ONCE_RW(*start) = 0;
42362 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
42363 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
42364
42365diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
42366index 50617c5..b13724c 100644
42367--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
42368+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
42369@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
42370
42371 writel(value, ioaddr + MMC_CNTRL);
42372
42373- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
42374- MMC_CNTRL, value);
42375+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
42376+// MMC_CNTRL, value);
42377 }
42378
42379 /* To mask all all interrupts.*/
42380diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
42381index e6fe0d8..2b7d752 100644
42382--- a/drivers/net/hyperv/hyperv_net.h
42383+++ b/drivers/net/hyperv/hyperv_net.h
42384@@ -101,7 +101,7 @@ struct rndis_device {
42385
42386 enum rndis_device_state state;
42387 bool link_state;
42388- atomic_t new_req_id;
42389+ atomic_unchecked_t new_req_id;
42390
42391 spinlock_t request_lock;
42392 struct list_head req_list;
42393diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
42394index 0775f0a..d4fb316 100644
42395--- a/drivers/net/hyperv/rndis_filter.c
42396+++ b/drivers/net/hyperv/rndis_filter.c
42397@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
42398 * template
42399 */
42400 set = &rndis_msg->msg.set_req;
42401- set->req_id = atomic_inc_return(&dev->new_req_id);
42402+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
42403
42404 /* Add to the request list */
42405 spin_lock_irqsave(&dev->request_lock, flags);
42406@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
42407
42408 /* Setup the rndis set */
42409 halt = &request->request_msg.msg.halt_req;
42410- halt->req_id = atomic_inc_return(&dev->new_req_id);
42411+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
42412
42413 /* Ignore return since this msg is optional. */
42414 rndis_filter_send_request(dev, request);
42415diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
42416index bf0d55e..82bcfbd1 100644
42417--- a/drivers/net/ieee802154/fakehard.c
42418+++ b/drivers/net/ieee802154/fakehard.c
42419@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
42420 phy->transmit_power = 0xbf;
42421
42422 dev->netdev_ops = &fake_ops;
42423- dev->ml_priv = &fake_mlme;
42424+ dev->ml_priv = (void *)&fake_mlme;
42425
42426 priv = netdev_priv(dev);
42427 priv->phy = phy;
42428diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
42429index 6e91931..2b0ebe7 100644
42430--- a/drivers/net/macvlan.c
42431+++ b/drivers/net/macvlan.c
42432@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
42433 int macvlan_link_register(struct rtnl_link_ops *ops)
42434 {
42435 /* common fields */
42436- ops->priv_size = sizeof(struct macvlan_dev);
42437- ops->validate = macvlan_validate;
42438- ops->maxtype = IFLA_MACVLAN_MAX;
42439- ops->policy = macvlan_policy;
42440- ops->changelink = macvlan_changelink;
42441- ops->get_size = macvlan_get_size;
42442- ops->fill_info = macvlan_fill_info;
42443+ pax_open_kernel();
42444+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
42445+ *(void **)&ops->validate = macvlan_validate;
42446+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
42447+ *(const void **)&ops->policy = macvlan_policy;
42448+ *(void **)&ops->changelink = macvlan_changelink;
42449+ *(void **)&ops->get_size = macvlan_get_size;
42450+ *(void **)&ops->fill_info = macvlan_fill_info;
42451+ pax_close_kernel();
42452
42453 return rtnl_link_register(ops);
42454 };
42455@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
42456 return NOTIFY_DONE;
42457 }
42458
42459-static struct notifier_block macvlan_notifier_block __read_mostly = {
42460+static struct notifier_block macvlan_notifier_block = {
42461 .notifier_call = macvlan_device_event,
42462 };
42463
42464diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
42465index 523d6b2..5e16aa1 100644
42466--- a/drivers/net/macvtap.c
42467+++ b/drivers/net/macvtap.c
42468@@ -1110,7 +1110,7 @@ static int macvtap_device_event(struct notifier_block *unused,
42469 return NOTIFY_DONE;
42470 }
42471
42472-static struct notifier_block macvtap_notifier_block __read_mostly = {
42473+static struct notifier_block macvtap_notifier_block = {
42474 .notifier_call = macvtap_device_event,
42475 };
42476
42477diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
42478index daec9b0..6428fcb 100644
42479--- a/drivers/net/phy/mdio-bitbang.c
42480+++ b/drivers/net/phy/mdio-bitbang.c
42481@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
42482 struct mdiobb_ctrl *ctrl = bus->priv;
42483
42484 module_put(ctrl->ops->owner);
42485+ mdiobus_unregister(bus);
42486 mdiobus_free(bus);
42487 }
42488 EXPORT_SYMBOL(free_mdio_bitbang);
42489diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
42490index 72ff14b..11d442d 100644
42491--- a/drivers/net/ppp/ppp_generic.c
42492+++ b/drivers/net/ppp/ppp_generic.c
42493@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42494 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
42495 struct ppp_stats stats;
42496 struct ppp_comp_stats cstats;
42497- char *vers;
42498
42499 switch (cmd) {
42500 case SIOCGPPPSTATS:
42501@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42502 break;
42503
42504 case SIOCGPPPVER:
42505- vers = PPP_VERSION;
42506- if (copy_to_user(addr, vers, strlen(vers) + 1))
42507+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
42508 break;
42509 err = 0;
42510 break;
42511diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
42512index 1252d9c..80e660b 100644
42513--- a/drivers/net/slip/slhc.c
42514+++ b/drivers/net/slip/slhc.c
42515@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
42516 register struct tcphdr *thp;
42517 register struct iphdr *ip;
42518 register struct cstate *cs;
42519- int len, hdrlen;
42520+ long len, hdrlen;
42521 unsigned char *cp = icp;
42522
42523 /* We've got a compressed packet; read the change byte */
42524diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
42525index b305105..8ead6df 100644
42526--- a/drivers/net/team/team.c
42527+++ b/drivers/net/team/team.c
42528@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
42529 return NOTIFY_DONE;
42530 }
42531
42532-static struct notifier_block team_notifier_block __read_mostly = {
42533+static struct notifier_block team_notifier_block = {
42534 .notifier_call = team_device_event,
42535 };
42536
42537diff --git a/drivers/net/tun.c b/drivers/net/tun.c
42538index 2491eb2..1a453eb 100644
42539--- a/drivers/net/tun.c
42540+++ b/drivers/net/tun.c
42541@@ -1076,8 +1076,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
42542 u32 rxhash;
42543
42544 if (!(tun->flags & TUN_NO_PI)) {
42545- if ((len -= sizeof(pi)) > total_len)
42546+ if (len < sizeof(pi))
42547 return -EINVAL;
42548+ len -= sizeof(pi);
42549
42550 if (memcpy_fromiovecend((void *)&pi, iv, 0, sizeof(pi)))
42551 return -EFAULT;
42552@@ -1085,8 +1086,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
42553 }
42554
42555 if (tun->flags & TUN_VNET_HDR) {
42556- if ((len -= tun->vnet_hdr_sz) > total_len)
42557+ if (len < tun->vnet_hdr_sz)
42558 return -EINVAL;
42559+ len -= tun->vnet_hdr_sz;
42560
42561 if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
42562 return -EFAULT;
42563@@ -1869,7 +1871,7 @@ unlock:
42564 }
42565
42566 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
42567- unsigned long arg, int ifreq_len)
42568+ unsigned long arg, size_t ifreq_len)
42569 {
42570 struct tun_file *tfile = file->private_data;
42571 struct tun_struct *tun;
42572@@ -1881,6 +1883,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
42573 int vnet_hdr_sz;
42574 int ret;
42575
42576+ if (ifreq_len > sizeof ifr)
42577+ return -EFAULT;
42578+
42579 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
42580 if (copy_from_user(&ifr, argp, ifreq_len))
42581 return -EFAULT;
42582diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
42583index cba1d46..f703766 100644
42584--- a/drivers/net/usb/hso.c
42585+++ b/drivers/net/usb/hso.c
42586@@ -71,7 +71,7 @@
42587 #include <asm/byteorder.h>
42588 #include <linux/serial_core.h>
42589 #include <linux/serial.h>
42590-
42591+#include <asm/local.h>
42592
42593 #define MOD_AUTHOR "Option Wireless"
42594 #define MOD_DESCRIPTION "USB High Speed Option driver"
42595@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
42596 struct urb *urb;
42597
42598 urb = serial->rx_urb[0];
42599- if (serial->port.count > 0) {
42600+ if (atomic_read(&serial->port.count) > 0) {
42601 count = put_rxbuf_data(urb, serial);
42602 if (count == -1)
42603 return;
42604@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
42605 DUMP1(urb->transfer_buffer, urb->actual_length);
42606
42607 /* Anyone listening? */
42608- if (serial->port.count == 0)
42609+ if (atomic_read(&serial->port.count) == 0)
42610 return;
42611
42612 if (status == 0) {
42613@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
42614 tty_port_tty_set(&serial->port, tty);
42615
42616 /* check for port already opened, if not set the termios */
42617- serial->port.count++;
42618- if (serial->port.count == 1) {
42619+ if (atomic_inc_return(&serial->port.count) == 1) {
42620 serial->rx_state = RX_IDLE;
42621 /* Force default termio settings */
42622 _hso_serial_set_termios(tty, NULL);
42623@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
42624 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
42625 if (result) {
42626 hso_stop_serial_device(serial->parent);
42627- serial->port.count--;
42628+ atomic_dec(&serial->port.count);
42629 kref_put(&serial->parent->ref, hso_serial_ref_free);
42630 }
42631 } else {
42632@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
42633
42634 /* reset the rts and dtr */
42635 /* do the actual close */
42636- serial->port.count--;
42637+ atomic_dec(&serial->port.count);
42638
42639- if (serial->port.count <= 0) {
42640- serial->port.count = 0;
42641+ if (atomic_read(&serial->port.count) <= 0) {
42642+ atomic_set(&serial->port.count, 0);
42643 tty_port_tty_set(&serial->port, NULL);
42644 if (!usb_gone)
42645 hso_stop_serial_device(serial->parent);
42646@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
42647
42648 /* the actual setup */
42649 spin_lock_irqsave(&serial->serial_lock, flags);
42650- if (serial->port.count)
42651+ if (atomic_read(&serial->port.count))
42652 _hso_serial_set_termios(tty, old);
42653 else
42654 tty->termios = *old;
42655@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
42656 D1("Pending read interrupt on port %d\n", i);
42657 spin_lock(&serial->serial_lock);
42658 if (serial->rx_state == RX_IDLE &&
42659- serial->port.count > 0) {
42660+ atomic_read(&serial->port.count) > 0) {
42661 /* Setup and send a ctrl req read on
42662 * port i */
42663 if (!serial->rx_urb_filled[0]) {
42664@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
42665 /* Start all serial ports */
42666 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
42667 if (serial_table[i] && (serial_table[i]->interface == iface)) {
42668- if (dev2ser(serial_table[i])->port.count) {
42669+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
42670 result =
42671 hso_start_serial_device(serial_table[i], GFP_NOIO);
42672 hso_kick_transmit(dev2ser(serial_table[i]));
42673diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
42674index 57325f3..36b181f 100644
42675--- a/drivers/net/vxlan.c
42676+++ b/drivers/net/vxlan.c
42677@@ -1579,7 +1579,7 @@ nla_put_failure:
42678 return -EMSGSIZE;
42679 }
42680
42681-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
42682+static struct rtnl_link_ops vxlan_link_ops = {
42683 .kind = "vxlan",
42684 .maxtype = IFLA_VXLAN_MAX,
42685 .policy = vxlan_policy,
42686diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
42687index 34c8a33..3261fdc 100644
42688--- a/drivers/net/wireless/at76c50x-usb.c
42689+++ b/drivers/net/wireless/at76c50x-usb.c
42690@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
42691 }
42692
42693 /* Convert timeout from the DFU status to jiffies */
42694-static inline unsigned long at76_get_timeout(struct dfu_status *s)
42695+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
42696 {
42697 return msecs_to_jiffies((s->poll_timeout[2] << 16)
42698 | (s->poll_timeout[1] << 8)
42699diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
42700index 8d78253..bebbb68 100644
42701--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
42702+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
42703@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42704 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
42705 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
42706
42707- ACCESS_ONCE(ads->ds_link) = i->link;
42708- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
42709+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
42710+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
42711
42712 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
42713 ctl6 = SM(i->keytype, AR_EncrType);
42714@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42715
42716 if ((i->is_first || i->is_last) &&
42717 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
42718- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
42719+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
42720 | set11nTries(i->rates, 1)
42721 | set11nTries(i->rates, 2)
42722 | set11nTries(i->rates, 3)
42723 | (i->dur_update ? AR_DurUpdateEna : 0)
42724 | SM(0, AR_BurstDur);
42725
42726- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
42727+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
42728 | set11nRate(i->rates, 1)
42729 | set11nRate(i->rates, 2)
42730 | set11nRate(i->rates, 3);
42731 } else {
42732- ACCESS_ONCE(ads->ds_ctl2) = 0;
42733- ACCESS_ONCE(ads->ds_ctl3) = 0;
42734+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
42735+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
42736 }
42737
42738 if (!i->is_first) {
42739- ACCESS_ONCE(ads->ds_ctl0) = 0;
42740- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
42741- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
42742+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
42743+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
42744+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
42745 return;
42746 }
42747
42748@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42749 break;
42750 }
42751
42752- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
42753+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
42754 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
42755 | SM(i->txpower, AR_XmitPower)
42756 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
42757@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42758 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
42759 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
42760
42761- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
42762- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
42763+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
42764+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
42765
42766 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
42767 return;
42768
42769- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
42770+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
42771 | set11nPktDurRTSCTS(i->rates, 1);
42772
42773- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
42774+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
42775 | set11nPktDurRTSCTS(i->rates, 3);
42776
42777- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
42778+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
42779 | set11nRateFlags(i->rates, 1)
42780 | set11nRateFlags(i->rates, 2)
42781 | set11nRateFlags(i->rates, 3)
42782diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
42783index 301bf72..3f5654f 100644
42784--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
42785+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
42786@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42787 (i->qcu << AR_TxQcuNum_S) | desc_len;
42788
42789 checksum += val;
42790- ACCESS_ONCE(ads->info) = val;
42791+ ACCESS_ONCE_RW(ads->info) = val;
42792
42793 checksum += i->link;
42794- ACCESS_ONCE(ads->link) = i->link;
42795+ ACCESS_ONCE_RW(ads->link) = i->link;
42796
42797 checksum += i->buf_addr[0];
42798- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
42799+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
42800 checksum += i->buf_addr[1];
42801- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
42802+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
42803 checksum += i->buf_addr[2];
42804- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
42805+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
42806 checksum += i->buf_addr[3];
42807- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
42808+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
42809
42810 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
42811- ACCESS_ONCE(ads->ctl3) = val;
42812+ ACCESS_ONCE_RW(ads->ctl3) = val;
42813 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
42814- ACCESS_ONCE(ads->ctl5) = val;
42815+ ACCESS_ONCE_RW(ads->ctl5) = val;
42816 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
42817- ACCESS_ONCE(ads->ctl7) = val;
42818+ ACCESS_ONCE_RW(ads->ctl7) = val;
42819 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
42820- ACCESS_ONCE(ads->ctl9) = val;
42821+ ACCESS_ONCE_RW(ads->ctl9) = val;
42822
42823 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
42824- ACCESS_ONCE(ads->ctl10) = checksum;
42825+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
42826
42827 if (i->is_first || i->is_last) {
42828- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
42829+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
42830 | set11nTries(i->rates, 1)
42831 | set11nTries(i->rates, 2)
42832 | set11nTries(i->rates, 3)
42833 | (i->dur_update ? AR_DurUpdateEna : 0)
42834 | SM(0, AR_BurstDur);
42835
42836- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
42837+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
42838 | set11nRate(i->rates, 1)
42839 | set11nRate(i->rates, 2)
42840 | set11nRate(i->rates, 3);
42841 } else {
42842- ACCESS_ONCE(ads->ctl13) = 0;
42843- ACCESS_ONCE(ads->ctl14) = 0;
42844+ ACCESS_ONCE_RW(ads->ctl13) = 0;
42845+ ACCESS_ONCE_RW(ads->ctl14) = 0;
42846 }
42847
42848 ads->ctl20 = 0;
42849@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42850
42851 ctl17 = SM(i->keytype, AR_EncrType);
42852 if (!i->is_first) {
42853- ACCESS_ONCE(ads->ctl11) = 0;
42854- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
42855- ACCESS_ONCE(ads->ctl15) = 0;
42856- ACCESS_ONCE(ads->ctl16) = 0;
42857- ACCESS_ONCE(ads->ctl17) = ctl17;
42858- ACCESS_ONCE(ads->ctl18) = 0;
42859- ACCESS_ONCE(ads->ctl19) = 0;
42860+ ACCESS_ONCE_RW(ads->ctl11) = 0;
42861+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
42862+ ACCESS_ONCE_RW(ads->ctl15) = 0;
42863+ ACCESS_ONCE_RW(ads->ctl16) = 0;
42864+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
42865+ ACCESS_ONCE_RW(ads->ctl18) = 0;
42866+ ACCESS_ONCE_RW(ads->ctl19) = 0;
42867 return;
42868 }
42869
42870- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
42871+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
42872 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
42873 | SM(i->txpower, AR_XmitPower)
42874 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
42875@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
42876 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
42877 ctl12 |= SM(val, AR_PAPRDChainMask);
42878
42879- ACCESS_ONCE(ads->ctl12) = ctl12;
42880- ACCESS_ONCE(ads->ctl17) = ctl17;
42881+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
42882+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
42883
42884- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
42885+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
42886 | set11nPktDurRTSCTS(i->rates, 1);
42887
42888- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
42889+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
42890 | set11nPktDurRTSCTS(i->rates, 3);
42891
42892- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
42893+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
42894 | set11nRateFlags(i->rates, 1)
42895 | set11nRateFlags(i->rates, 2)
42896 | set11nRateFlags(i->rates, 3)
42897 | SM(i->rtscts_rate, AR_RTSCTSRate);
42898
42899- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
42900+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
42901 }
42902
42903 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
42904diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
42905index ae30343..a117806 100644
42906--- a/drivers/net/wireless/ath/ath9k/hw.h
42907+++ b/drivers/net/wireless/ath/ath9k/hw.h
42908@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
42909
42910 /* ANI */
42911 void (*ani_cache_ini_regs)(struct ath_hw *ah);
42912-};
42913+} __no_const;
42914
42915 /**
42916 * struct ath_spec_scan - parameters for Atheros spectral scan
42917@@ -721,7 +721,7 @@ struct ath_hw_ops {
42918 struct ath_spec_scan *param);
42919 void (*spectral_scan_trigger)(struct ath_hw *ah);
42920 void (*spectral_scan_wait)(struct ath_hw *ah);
42921-};
42922+} __no_const;
42923
42924 struct ath_nf_limits {
42925 s16 max;
42926diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
42927index b37a582..680835d 100644
42928--- a/drivers/net/wireless/iwlegacy/3945-mac.c
42929+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
42930@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
42931 */
42932 if (il3945_mod_params.disable_hw_scan) {
42933 D_INFO("Disabling hw_scan\n");
42934- il3945_mac_ops.hw_scan = NULL;
42935+ pax_open_kernel();
42936+ *(void **)&il3945_mac_ops.hw_scan = NULL;
42937+ pax_close_kernel();
42938 }
42939
42940 D_INFO("*** LOAD DRIVER ***\n");
42941diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
42942index d532948..e0d8bb1 100644
42943--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
42944+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
42945@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
42946 {
42947 struct iwl_priv *priv = file->private_data;
42948 char buf[64];
42949- int buf_size;
42950+ size_t buf_size;
42951 u32 offset, len;
42952
42953 memset(buf, 0, sizeof(buf));
42954@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
42955 struct iwl_priv *priv = file->private_data;
42956
42957 char buf[8];
42958- int buf_size;
42959+ size_t buf_size;
42960 u32 reset_flag;
42961
42962 memset(buf, 0, sizeof(buf));
42963@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
42964 {
42965 struct iwl_priv *priv = file->private_data;
42966 char buf[8];
42967- int buf_size;
42968+ size_t buf_size;
42969 int ht40;
42970
42971 memset(buf, 0, sizeof(buf));
42972@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
42973 {
42974 struct iwl_priv *priv = file->private_data;
42975 char buf[8];
42976- int buf_size;
42977+ size_t buf_size;
42978 int value;
42979
42980 memset(buf, 0, sizeof(buf));
42981@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
42982 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
42983 DEBUGFS_READ_FILE_OPS(current_sleep_command);
42984
42985-static const char *fmt_value = " %-30s %10u\n";
42986-static const char *fmt_hex = " %-30s 0x%02X\n";
42987-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
42988-static const char *fmt_header =
42989+static const char fmt_value[] = " %-30s %10u\n";
42990+static const char fmt_hex[] = " %-30s 0x%02X\n";
42991+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
42992+static const char fmt_header[] =
42993 "%-32s current cumulative delta max\n";
42994
42995 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
42996@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
42997 {
42998 struct iwl_priv *priv = file->private_data;
42999 char buf[8];
43000- int buf_size;
43001+ size_t buf_size;
43002 int clear;
43003
43004 memset(buf, 0, sizeof(buf));
43005@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
43006 {
43007 struct iwl_priv *priv = file->private_data;
43008 char buf[8];
43009- int buf_size;
43010+ size_t buf_size;
43011 int trace;
43012
43013 memset(buf, 0, sizeof(buf));
43014@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
43015 {
43016 struct iwl_priv *priv = file->private_data;
43017 char buf[8];
43018- int buf_size;
43019+ size_t buf_size;
43020 int missed;
43021
43022 memset(buf, 0, sizeof(buf));
43023@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
43024
43025 struct iwl_priv *priv = file->private_data;
43026 char buf[8];
43027- int buf_size;
43028+ size_t buf_size;
43029 int plcp;
43030
43031 memset(buf, 0, sizeof(buf));
43032@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
43033
43034 struct iwl_priv *priv = file->private_data;
43035 char buf[8];
43036- int buf_size;
43037+ size_t buf_size;
43038 int flush;
43039
43040 memset(buf, 0, sizeof(buf));
43041@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
43042
43043 struct iwl_priv *priv = file->private_data;
43044 char buf[8];
43045- int buf_size;
43046+ size_t buf_size;
43047 int rts;
43048
43049 if (!priv->cfg->ht_params)
43050@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
43051 {
43052 struct iwl_priv *priv = file->private_data;
43053 char buf[8];
43054- int buf_size;
43055+ size_t buf_size;
43056
43057 memset(buf, 0, sizeof(buf));
43058 buf_size = min(count, sizeof(buf) - 1);
43059@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
43060 struct iwl_priv *priv = file->private_data;
43061 u32 event_log_flag;
43062 char buf[8];
43063- int buf_size;
43064+ size_t buf_size;
43065
43066 /* check that the interface is up */
43067 if (!iwl_is_ready(priv))
43068@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
43069 struct iwl_priv *priv = file->private_data;
43070 char buf[8];
43071 u32 calib_disabled;
43072- int buf_size;
43073+ size_t buf_size;
43074
43075 memset(buf, 0, sizeof(buf));
43076 buf_size = min(count, sizeof(buf) - 1);
43077diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
43078index 50ba0a4..29424e7 100644
43079--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
43080+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
43081@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
43082 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
43083
43084 char buf[8];
43085- int buf_size;
43086+ size_t buf_size;
43087 u32 reset_flag;
43088
43089 memset(buf, 0, sizeof(buf));
43090@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
43091 {
43092 struct iwl_trans *trans = file->private_data;
43093 char buf[8];
43094- int buf_size;
43095+ size_t buf_size;
43096 int csr;
43097
43098 memset(buf, 0, sizeof(buf));
43099diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
43100index cb34c78..9fec0dc 100644
43101--- a/drivers/net/wireless/mac80211_hwsim.c
43102+++ b/drivers/net/wireless/mac80211_hwsim.c
43103@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
43104
43105 if (channels > 1) {
43106 hwsim_if_comb.num_different_channels = channels;
43107- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
43108- mac80211_hwsim_ops.cancel_hw_scan =
43109- mac80211_hwsim_cancel_hw_scan;
43110- mac80211_hwsim_ops.sw_scan_start = NULL;
43111- mac80211_hwsim_ops.sw_scan_complete = NULL;
43112- mac80211_hwsim_ops.remain_on_channel =
43113- mac80211_hwsim_roc;
43114- mac80211_hwsim_ops.cancel_remain_on_channel =
43115- mac80211_hwsim_croc;
43116- mac80211_hwsim_ops.add_chanctx =
43117- mac80211_hwsim_add_chanctx;
43118- mac80211_hwsim_ops.remove_chanctx =
43119- mac80211_hwsim_remove_chanctx;
43120- mac80211_hwsim_ops.change_chanctx =
43121- mac80211_hwsim_change_chanctx;
43122- mac80211_hwsim_ops.assign_vif_chanctx =
43123- mac80211_hwsim_assign_vif_chanctx;
43124- mac80211_hwsim_ops.unassign_vif_chanctx =
43125- mac80211_hwsim_unassign_vif_chanctx;
43126+ pax_open_kernel();
43127+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
43128+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
43129+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
43130+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
43131+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
43132+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
43133+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
43134+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
43135+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
43136+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
43137+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
43138+ pax_close_kernel();
43139 }
43140
43141 spin_lock_init(&hwsim_radio_lock);
43142diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
43143index 8169a85..7fa3b47 100644
43144--- a/drivers/net/wireless/rndis_wlan.c
43145+++ b/drivers/net/wireless/rndis_wlan.c
43146@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
43147
43148 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
43149
43150- if (rts_threshold < 0 || rts_threshold > 2347)
43151+ if (rts_threshold > 2347)
43152 rts_threshold = 2347;
43153
43154 tmp = cpu_to_le32(rts_threshold);
43155diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
43156index 7510723..5ba37f5 100644
43157--- a/drivers/net/wireless/rt2x00/rt2x00.h
43158+++ b/drivers/net/wireless/rt2x00/rt2x00.h
43159@@ -386,7 +386,7 @@ struct rt2x00_intf {
43160 * for hardware which doesn't support hardware
43161 * sequence counting.
43162 */
43163- atomic_t seqno;
43164+ atomic_unchecked_t seqno;
43165 };
43166
43167 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
43168diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
43169index d955741..8730748 100644
43170--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
43171+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
43172@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
43173 * sequence counter given by mac80211.
43174 */
43175 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
43176- seqno = atomic_add_return(0x10, &intf->seqno);
43177+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
43178 else
43179- seqno = atomic_read(&intf->seqno);
43180+ seqno = atomic_read_unchecked(&intf->seqno);
43181
43182 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
43183 hdr->seq_ctrl |= cpu_to_le16(seqno);
43184diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
43185index e2b3d9c..67a5184 100644
43186--- a/drivers/net/wireless/ti/wl1251/sdio.c
43187+++ b/drivers/net/wireless/ti/wl1251/sdio.c
43188@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
43189
43190 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
43191
43192- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
43193- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
43194+ pax_open_kernel();
43195+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
43196+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
43197+ pax_close_kernel();
43198
43199 wl1251_info("using dedicated interrupt line");
43200 } else {
43201- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
43202- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
43203+ pax_open_kernel();
43204+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
43205+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
43206+ pax_close_kernel();
43207
43208 wl1251_info("using SDIO interrupt");
43209 }
43210diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
43211index 1c627da..69f7d17 100644
43212--- a/drivers/net/wireless/ti/wl12xx/main.c
43213+++ b/drivers/net/wireless/ti/wl12xx/main.c
43214@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
43215 sizeof(wl->conf.mem));
43216
43217 /* read data preparation is only needed by wl127x */
43218- wl->ops->prepare_read = wl127x_prepare_read;
43219+ pax_open_kernel();
43220+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
43221+ pax_close_kernel();
43222
43223 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
43224 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
43225@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
43226 sizeof(wl->conf.mem));
43227
43228 /* read data preparation is only needed by wl127x */
43229- wl->ops->prepare_read = wl127x_prepare_read;
43230+ pax_open_kernel();
43231+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
43232+ pax_close_kernel();
43233
43234 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
43235 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
43236diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
43237index 9fa692d..b31fee0 100644
43238--- a/drivers/net/wireless/ti/wl18xx/main.c
43239+++ b/drivers/net/wireless/ti/wl18xx/main.c
43240@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
43241 }
43242
43243 if (!checksum_param) {
43244- wl18xx_ops.set_rx_csum = NULL;
43245- wl18xx_ops.init_vif = NULL;
43246+ pax_open_kernel();
43247+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
43248+ *(void **)&wl18xx_ops.init_vif = NULL;
43249+ pax_close_kernel();
43250 }
43251
43252 /* Enable 11a Band only if we have 5G antennas */
43253diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
43254index 7ef0b4a..ff65c28 100644
43255--- a/drivers/net/wireless/zd1211rw/zd_usb.c
43256+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
43257@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
43258 {
43259 struct zd_usb *usb = urb->context;
43260 struct zd_usb_interrupt *intr = &usb->intr;
43261- int len;
43262+ unsigned int len;
43263 u16 int_num;
43264
43265 ZD_ASSERT(in_interrupt());
43266diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
43267index d93b2b6..ae50401 100644
43268--- a/drivers/oprofile/buffer_sync.c
43269+++ b/drivers/oprofile/buffer_sync.c
43270@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
43271 if (cookie == NO_COOKIE)
43272 offset = pc;
43273 if (cookie == INVALID_COOKIE) {
43274- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
43275+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
43276 offset = pc;
43277 }
43278 if (cookie != last_cookie) {
43279@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
43280 /* add userspace sample */
43281
43282 if (!mm) {
43283- atomic_inc(&oprofile_stats.sample_lost_no_mm);
43284+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
43285 return 0;
43286 }
43287
43288 cookie = lookup_dcookie(mm, s->eip, &offset);
43289
43290 if (cookie == INVALID_COOKIE) {
43291- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
43292+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
43293 return 0;
43294 }
43295
43296@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
43297 /* ignore backtraces if failed to add a sample */
43298 if (state == sb_bt_start) {
43299 state = sb_bt_ignore;
43300- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
43301+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
43302 }
43303 }
43304 release_mm(mm);
43305diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
43306index c0cc4e7..44d4e54 100644
43307--- a/drivers/oprofile/event_buffer.c
43308+++ b/drivers/oprofile/event_buffer.c
43309@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
43310 }
43311
43312 if (buffer_pos == buffer_size) {
43313- atomic_inc(&oprofile_stats.event_lost_overflow);
43314+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
43315 return;
43316 }
43317
43318diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
43319index ed2c3ec..deda85a 100644
43320--- a/drivers/oprofile/oprof.c
43321+++ b/drivers/oprofile/oprof.c
43322@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
43323 if (oprofile_ops.switch_events())
43324 return;
43325
43326- atomic_inc(&oprofile_stats.multiplex_counter);
43327+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
43328 start_switch_worker();
43329 }
43330
43331diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
43332index 84a208d..d61b0a1 100644
43333--- a/drivers/oprofile/oprofile_files.c
43334+++ b/drivers/oprofile/oprofile_files.c
43335@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
43336
43337 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
43338
43339-static ssize_t timeout_read(struct file *file, char __user *buf,
43340+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
43341 size_t count, loff_t *offset)
43342 {
43343 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
43344diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
43345index 917d28e..d62d981 100644
43346--- a/drivers/oprofile/oprofile_stats.c
43347+++ b/drivers/oprofile/oprofile_stats.c
43348@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
43349 cpu_buf->sample_invalid_eip = 0;
43350 }
43351
43352- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
43353- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
43354- atomic_set(&oprofile_stats.event_lost_overflow, 0);
43355- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
43356- atomic_set(&oprofile_stats.multiplex_counter, 0);
43357+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
43358+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
43359+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
43360+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
43361+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
43362 }
43363
43364
43365diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
43366index 38b6fc0..b5cbfce 100644
43367--- a/drivers/oprofile/oprofile_stats.h
43368+++ b/drivers/oprofile/oprofile_stats.h
43369@@ -13,11 +13,11 @@
43370 #include <linux/atomic.h>
43371
43372 struct oprofile_stat_struct {
43373- atomic_t sample_lost_no_mm;
43374- atomic_t sample_lost_no_mapping;
43375- atomic_t bt_lost_no_mapping;
43376- atomic_t event_lost_overflow;
43377- atomic_t multiplex_counter;
43378+ atomic_unchecked_t sample_lost_no_mm;
43379+ atomic_unchecked_t sample_lost_no_mapping;
43380+ atomic_unchecked_t bt_lost_no_mapping;
43381+ atomic_unchecked_t event_lost_overflow;
43382+ atomic_unchecked_t multiplex_counter;
43383 };
43384
43385 extern struct oprofile_stat_struct oprofile_stats;
43386diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
43387index 7c12d9c..558bf3bb 100644
43388--- a/drivers/oprofile/oprofilefs.c
43389+++ b/drivers/oprofile/oprofilefs.c
43390@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
43391
43392
43393 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
43394- char const *name, atomic_t *val)
43395+ char const *name, atomic_unchecked_t *val)
43396 {
43397 return __oprofilefs_create_file(sb, root, name,
43398 &atomic_ro_fops, 0444, val);
43399diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
43400index 93404f7..4a313d8 100644
43401--- a/drivers/oprofile/timer_int.c
43402+++ b/drivers/oprofile/timer_int.c
43403@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
43404 return NOTIFY_OK;
43405 }
43406
43407-static struct notifier_block __refdata oprofile_cpu_notifier = {
43408+static struct notifier_block oprofile_cpu_notifier = {
43409 .notifier_call = oprofile_cpu_notify,
43410 };
43411
43412diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
43413index 92ed045..62d39bd7 100644
43414--- a/drivers/parport/procfs.c
43415+++ b/drivers/parport/procfs.c
43416@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
43417
43418 *ppos += len;
43419
43420- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
43421+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
43422 }
43423
43424 #ifdef CONFIG_PARPORT_1284
43425@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
43426
43427 *ppos += len;
43428
43429- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
43430+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
43431 }
43432 #endif /* IEEE1284.3 support. */
43433
43434diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
43435index c35e8ad..fc33beb 100644
43436--- a/drivers/pci/hotplug/acpiphp_ibm.c
43437+++ b/drivers/pci/hotplug/acpiphp_ibm.c
43438@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
43439 goto init_cleanup;
43440 }
43441
43442- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
43443+ pax_open_kernel();
43444+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
43445+ pax_close_kernel();
43446 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
43447
43448 return retval;
43449diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
43450index a6a71c4..c91097b 100644
43451--- a/drivers/pci/hotplug/cpcihp_generic.c
43452+++ b/drivers/pci/hotplug/cpcihp_generic.c
43453@@ -73,7 +73,6 @@ static u16 port;
43454 static unsigned int enum_bit;
43455 static u8 enum_mask;
43456
43457-static struct cpci_hp_controller_ops generic_hpc_ops;
43458 static struct cpci_hp_controller generic_hpc;
43459
43460 static int __init validate_parameters(void)
43461@@ -139,6 +138,10 @@ static int query_enum(void)
43462 return ((value & enum_mask) == enum_mask);
43463 }
43464
43465+static struct cpci_hp_controller_ops generic_hpc_ops = {
43466+ .query_enum = query_enum,
43467+};
43468+
43469 static int __init cpcihp_generic_init(void)
43470 {
43471 int status;
43472@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
43473 pci_dev_put(dev);
43474
43475 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
43476- generic_hpc_ops.query_enum = query_enum;
43477 generic_hpc.ops = &generic_hpc_ops;
43478
43479 status = cpci_hp_register_controller(&generic_hpc);
43480diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
43481index 449b4bb..257e2e8 100644
43482--- a/drivers/pci/hotplug/cpcihp_zt5550.c
43483+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
43484@@ -59,7 +59,6 @@
43485 /* local variables */
43486 static bool debug;
43487 static bool poll;
43488-static struct cpci_hp_controller_ops zt5550_hpc_ops;
43489 static struct cpci_hp_controller zt5550_hpc;
43490
43491 /* Primary cPCI bus bridge device */
43492@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
43493 return 0;
43494 }
43495
43496+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
43497+ .query_enum = zt5550_hc_query_enum,
43498+};
43499+
43500 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
43501 {
43502 int status;
43503@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
43504 dbg("returned from zt5550_hc_config");
43505
43506 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
43507- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
43508 zt5550_hpc.ops = &zt5550_hpc_ops;
43509 if(!poll) {
43510 zt5550_hpc.irq = hc_dev->irq;
43511 zt5550_hpc.irq_flags = IRQF_SHARED;
43512 zt5550_hpc.dev_id = hc_dev;
43513
43514- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
43515- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
43516- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
43517+ pax_open_kernel();
43518+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
43519+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
43520+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
43521+ pax_open_kernel();
43522 } else {
43523 info("using ENUM# polling mode");
43524 }
43525diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
43526index 76ba8a1..20ca857 100644
43527--- a/drivers/pci/hotplug/cpqphp_nvram.c
43528+++ b/drivers/pci/hotplug/cpqphp_nvram.c
43529@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
43530
43531 void compaq_nvram_init (void __iomem *rom_start)
43532 {
43533+
43534+#ifndef CONFIG_PAX_KERNEXEC
43535 if (rom_start) {
43536 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
43537 }
43538+#endif
43539+
43540 dbg("int15 entry = %p\n", compaq_int15_entry_point);
43541
43542 /* initialize our int15 lock */
43543diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
43544index ec20f74..c1d961e 100644
43545--- a/drivers/pci/hotplug/pci_hotplug_core.c
43546+++ b/drivers/pci/hotplug/pci_hotplug_core.c
43547@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
43548 return -EINVAL;
43549 }
43550
43551- slot->ops->owner = owner;
43552- slot->ops->mod_name = mod_name;
43553+ pax_open_kernel();
43554+ *(struct module **)&slot->ops->owner = owner;
43555+ *(const char **)&slot->ops->mod_name = mod_name;
43556+ pax_close_kernel();
43557
43558 mutex_lock(&pci_hp_mutex);
43559 /*
43560diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
43561index 7d72c5e..edce02c 100644
43562--- a/drivers/pci/hotplug/pciehp_core.c
43563+++ b/drivers/pci/hotplug/pciehp_core.c
43564@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
43565 struct slot *slot = ctrl->slot;
43566 struct hotplug_slot *hotplug = NULL;
43567 struct hotplug_slot_info *info = NULL;
43568- struct hotplug_slot_ops *ops = NULL;
43569+ hotplug_slot_ops_no_const *ops = NULL;
43570 char name[SLOT_NAME_SIZE];
43571 int retval = -ENOMEM;
43572
43573diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
43574index 5b4a9d9..cd5ac1f 100644
43575--- a/drivers/pci/pci-sysfs.c
43576+++ b/drivers/pci/pci-sysfs.c
43577@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
43578 {
43579 /* allocate attribute structure, piggyback attribute name */
43580 int name_len = write_combine ? 13 : 10;
43581- struct bin_attribute *res_attr;
43582+ bin_attribute_no_const *res_attr;
43583 int retval;
43584
43585 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
43586@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
43587 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
43588 {
43589 int retval;
43590- struct bin_attribute *attr;
43591+ bin_attribute_no_const *attr;
43592
43593 /* If the device has VPD, try to expose it in sysfs. */
43594 if (dev->vpd) {
43595@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
43596 {
43597 int retval;
43598 int rom_size = 0;
43599- struct bin_attribute *attr;
43600+ bin_attribute_no_const *attr;
43601
43602 if (!sysfs_initialized)
43603 return -EACCES;
43604diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
43605index d1182c4..2a138ec 100644
43606--- a/drivers/pci/pci.h
43607+++ b/drivers/pci/pci.h
43608@@ -92,7 +92,7 @@ struct pci_vpd_ops {
43609 struct pci_vpd {
43610 unsigned int len;
43611 const struct pci_vpd_ops *ops;
43612- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
43613+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
43614 };
43615
43616 int pci_vpd_pci22_init(struct pci_dev *dev);
43617diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
43618index d320df6..ca9a8f6 100644
43619--- a/drivers/pci/pcie/aspm.c
43620+++ b/drivers/pci/pcie/aspm.c
43621@@ -27,9 +27,9 @@
43622 #define MODULE_PARAM_PREFIX "pcie_aspm."
43623
43624 /* Note: those are not register definitions */
43625-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
43626-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
43627-#define ASPM_STATE_L1 (4) /* L1 state */
43628+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
43629+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
43630+#define ASPM_STATE_L1 (4U) /* L1 state */
43631 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
43632 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
43633
43634diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
43635index ea37072..10e58e56 100644
43636--- a/drivers/pci/probe.c
43637+++ b/drivers/pci/probe.c
43638@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
43639 struct pci_bus_region region;
43640 bool bar_too_big = false, bar_disabled = false;
43641
43642- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
43643+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
43644
43645 /* No printks while decoding is disabled! */
43646 if (!dev->mmio_always_on) {
43647diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
43648index 0812608..b04018c4 100644
43649--- a/drivers/pci/proc.c
43650+++ b/drivers/pci/proc.c
43651@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
43652 static int __init pci_proc_init(void)
43653 {
43654 struct pci_dev *dev = NULL;
43655+
43656+#ifdef CONFIG_GRKERNSEC_PROC_ADD
43657+#ifdef CONFIG_GRKERNSEC_PROC_USER
43658+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
43659+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
43660+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
43661+#endif
43662+#else
43663 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
43664+#endif
43665 proc_create("devices", 0, proc_bus_pci_dir,
43666 &proc_bus_pci_dev_operations);
43667 proc_initialized = 1;
43668diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
43669index 3e5b4497..dcdfb70 100644
43670--- a/drivers/platform/x86/chromeos_laptop.c
43671+++ b/drivers/platform/x86/chromeos_laptop.c
43672@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
43673 return 0;
43674 }
43675
43676-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
43677+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
43678 {
43679 .ident = "Samsung Series 5 550 - Touchpad",
43680 .matches = {
43681diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
43682index 6b22938..bc9700e 100644
43683--- a/drivers/platform/x86/msi-laptop.c
43684+++ b/drivers/platform/x86/msi-laptop.c
43685@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
43686
43687 if (!quirks->ec_read_only) {
43688 /* allow userland write sysfs file */
43689- dev_attr_bluetooth.store = store_bluetooth;
43690- dev_attr_wlan.store = store_wlan;
43691- dev_attr_threeg.store = store_threeg;
43692- dev_attr_bluetooth.attr.mode |= S_IWUSR;
43693- dev_attr_wlan.attr.mode |= S_IWUSR;
43694- dev_attr_threeg.attr.mode |= S_IWUSR;
43695+ pax_open_kernel();
43696+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
43697+ *(void **)&dev_attr_wlan.store = store_wlan;
43698+ *(void **)&dev_attr_threeg.store = store_threeg;
43699+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
43700+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
43701+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
43702+ pax_close_kernel();
43703 }
43704
43705 /* disable hardware control by fn key */
43706diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
43707index 2ac045f..39c443d 100644
43708--- a/drivers/platform/x86/sony-laptop.c
43709+++ b/drivers/platform/x86/sony-laptop.c
43710@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
43711 }
43712
43713 /* High speed charging function */
43714-static struct device_attribute *hsc_handle;
43715+static device_attribute_no_const *hsc_handle;
43716
43717 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
43718 struct device_attribute *attr,
43719diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
43720index 54d31c0..3f896d3 100644
43721--- a/drivers/platform/x86/thinkpad_acpi.c
43722+++ b/drivers/platform/x86/thinkpad_acpi.c
43723@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
43724 return 0;
43725 }
43726
43727-void static hotkey_mask_warn_incomplete_mask(void)
43728+static void hotkey_mask_warn_incomplete_mask(void)
43729 {
43730 /* log only what the user can fix... */
43731 const u32 wantedmask = hotkey_driver_mask &
43732@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
43733 }
43734 }
43735
43736-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43737- struct tp_nvram_state *newn,
43738- const u32 event_mask)
43739-{
43740-
43741 #define TPACPI_COMPARE_KEY(__scancode, __member) \
43742 do { \
43743 if ((event_mask & (1 << __scancode)) && \
43744@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43745 tpacpi_hotkey_send_key(__scancode); \
43746 } while (0)
43747
43748- void issue_volchange(const unsigned int oldvol,
43749- const unsigned int newvol)
43750- {
43751- unsigned int i = oldvol;
43752+static void issue_volchange(const unsigned int oldvol,
43753+ const unsigned int newvol,
43754+ const u32 event_mask)
43755+{
43756+ unsigned int i = oldvol;
43757
43758- while (i > newvol) {
43759- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
43760- i--;
43761- }
43762- while (i < newvol) {
43763- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
43764- i++;
43765- }
43766+ while (i > newvol) {
43767+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
43768+ i--;
43769 }
43770+ while (i < newvol) {
43771+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
43772+ i++;
43773+ }
43774+}
43775
43776- void issue_brightnesschange(const unsigned int oldbrt,
43777- const unsigned int newbrt)
43778- {
43779- unsigned int i = oldbrt;
43780+static void issue_brightnesschange(const unsigned int oldbrt,
43781+ const unsigned int newbrt,
43782+ const u32 event_mask)
43783+{
43784+ unsigned int i = oldbrt;
43785
43786- while (i > newbrt) {
43787- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
43788- i--;
43789- }
43790- while (i < newbrt) {
43791- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
43792- i++;
43793- }
43794+ while (i > newbrt) {
43795+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
43796+ i--;
43797+ }
43798+ while (i < newbrt) {
43799+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
43800+ i++;
43801 }
43802+}
43803
43804+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43805+ struct tp_nvram_state *newn,
43806+ const u32 event_mask)
43807+{
43808 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
43809 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
43810 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
43811@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43812 oldn->volume_level != newn->volume_level) {
43813 /* recently muted, or repeated mute keypress, or
43814 * multiple presses ending in mute */
43815- issue_volchange(oldn->volume_level, newn->volume_level);
43816+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
43817 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
43818 }
43819 } else {
43820@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43821 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
43822 }
43823 if (oldn->volume_level != newn->volume_level) {
43824- issue_volchange(oldn->volume_level, newn->volume_level);
43825+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
43826 } else if (oldn->volume_toggle != newn->volume_toggle) {
43827 /* repeated vol up/down keypress at end of scale ? */
43828 if (newn->volume_level == 0)
43829@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43830 /* handle brightness */
43831 if (oldn->brightness_level != newn->brightness_level) {
43832 issue_brightnesschange(oldn->brightness_level,
43833- newn->brightness_level);
43834+ newn->brightness_level,
43835+ event_mask);
43836 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
43837 /* repeated key presses that didn't change state */
43838 if (newn->brightness_level == 0)
43839@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
43840 && !tp_features.bright_unkfw)
43841 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
43842 }
43843+}
43844
43845 #undef TPACPI_COMPARE_KEY
43846 #undef TPACPI_MAY_SEND_KEY
43847-}
43848
43849 /*
43850 * Polling driver
43851diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
43852index 769d265..a3a05ca 100644
43853--- a/drivers/pnp/pnpbios/bioscalls.c
43854+++ b/drivers/pnp/pnpbios/bioscalls.c
43855@@ -58,7 +58,7 @@ do { \
43856 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
43857 } while(0)
43858
43859-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
43860+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
43861 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
43862
43863 /*
43864@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
43865
43866 cpu = get_cpu();
43867 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
43868+
43869+ pax_open_kernel();
43870 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
43871+ pax_close_kernel();
43872
43873 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
43874 spin_lock_irqsave(&pnp_bios_lock, flags);
43875@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
43876 :"memory");
43877 spin_unlock_irqrestore(&pnp_bios_lock, flags);
43878
43879+ pax_open_kernel();
43880 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
43881+ pax_close_kernel();
43882+
43883 put_cpu();
43884
43885 /* If we get here and this is set then the PnP BIOS faulted on us. */
43886@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
43887 return status;
43888 }
43889
43890-void pnpbios_calls_init(union pnp_bios_install_struct *header)
43891+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
43892 {
43893 int i;
43894
43895@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
43896 pnp_bios_callpoint.offset = header->fields.pm16offset;
43897 pnp_bios_callpoint.segment = PNP_CS16;
43898
43899+ pax_open_kernel();
43900+
43901 for_each_possible_cpu(i) {
43902 struct desc_struct *gdt = get_cpu_gdt_table(i);
43903 if (!gdt)
43904@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
43905 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
43906 (unsigned long)__va(header->fields.pm16dseg));
43907 }
43908+
43909+ pax_close_kernel();
43910 }
43911diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
43912index 3e6db1c..1fbbdae 100644
43913--- a/drivers/pnp/resource.c
43914+++ b/drivers/pnp/resource.c
43915@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
43916 return 1;
43917
43918 /* check if the resource is valid */
43919- if (*irq < 0 || *irq > 15)
43920+ if (*irq > 15)
43921 return 0;
43922
43923 /* check if the resource is reserved */
43924@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
43925 return 1;
43926
43927 /* check if the resource is valid */
43928- if (*dma < 0 || *dma == 4 || *dma > 7)
43929+ if (*dma == 4 || *dma > 7)
43930 return 0;
43931
43932 /* check if the resource is reserved */
43933diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
43934index 0c52e2a..3421ab7 100644
43935--- a/drivers/power/pda_power.c
43936+++ b/drivers/power/pda_power.c
43937@@ -37,7 +37,11 @@ static int polling;
43938
43939 #if IS_ENABLED(CONFIG_USB_PHY)
43940 static struct usb_phy *transceiver;
43941-static struct notifier_block otg_nb;
43942+static int otg_handle_notification(struct notifier_block *nb,
43943+ unsigned long event, void *unused);
43944+static struct notifier_block otg_nb = {
43945+ .notifier_call = otg_handle_notification
43946+};
43947 #endif
43948
43949 static struct regulator *ac_draw;
43950@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
43951
43952 #if IS_ENABLED(CONFIG_USB_PHY)
43953 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
43954- otg_nb.notifier_call = otg_handle_notification;
43955 ret = usb_register_notifier(transceiver, &otg_nb);
43956 if (ret) {
43957 dev_err(dev, "failure to register otg notifier\n");
43958diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
43959index cc439fd..8fa30df 100644
43960--- a/drivers/power/power_supply.h
43961+++ b/drivers/power/power_supply.h
43962@@ -16,12 +16,12 @@ struct power_supply;
43963
43964 #ifdef CONFIG_SYSFS
43965
43966-extern void power_supply_init_attrs(struct device_type *dev_type);
43967+extern void power_supply_init_attrs(void);
43968 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
43969
43970 #else
43971
43972-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
43973+static inline void power_supply_init_attrs(void) {}
43974 #define power_supply_uevent NULL
43975
43976 #endif /* CONFIG_SYSFS */
43977diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
43978index 1c517c3..ffa2f17 100644
43979--- a/drivers/power/power_supply_core.c
43980+++ b/drivers/power/power_supply_core.c
43981@@ -24,7 +24,10 @@
43982 struct class *power_supply_class;
43983 EXPORT_SYMBOL_GPL(power_supply_class);
43984
43985-static struct device_type power_supply_dev_type;
43986+extern const struct attribute_group *power_supply_attr_groups[];
43987+static struct device_type power_supply_dev_type = {
43988+ .groups = power_supply_attr_groups,
43989+};
43990
43991 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
43992 struct power_supply *supply)
43993@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
43994 return PTR_ERR(power_supply_class);
43995
43996 power_supply_class->dev_uevent = power_supply_uevent;
43997- power_supply_init_attrs(&power_supply_dev_type);
43998+ power_supply_init_attrs();
43999
44000 return 0;
44001 }
44002diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
44003index 29178f7..c65f324 100644
44004--- a/drivers/power/power_supply_sysfs.c
44005+++ b/drivers/power/power_supply_sysfs.c
44006@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
44007 .is_visible = power_supply_attr_is_visible,
44008 };
44009
44010-static const struct attribute_group *power_supply_attr_groups[] = {
44011+const struct attribute_group *power_supply_attr_groups[] = {
44012 &power_supply_attr_group,
44013 NULL,
44014 };
44015
44016-void power_supply_init_attrs(struct device_type *dev_type)
44017+void power_supply_init_attrs(void)
44018 {
44019 int i;
44020
44021- dev_type->groups = power_supply_attr_groups;
44022-
44023 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
44024 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
44025 }
44026diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
44027index d428ef9..fdc0357 100644
44028--- a/drivers/regulator/max8660.c
44029+++ b/drivers/regulator/max8660.c
44030@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
44031 max8660->shadow_regs[MAX8660_OVER1] = 5;
44032 } else {
44033 /* Otherwise devices can be toggled via software */
44034- max8660_dcdc_ops.enable = max8660_dcdc_enable;
44035- max8660_dcdc_ops.disable = max8660_dcdc_disable;
44036+ pax_open_kernel();
44037+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
44038+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
44039+ pax_close_kernel();
44040 }
44041
44042 /*
44043diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
44044index adb1414..c13e0ce 100644
44045--- a/drivers/regulator/max8973-regulator.c
44046+++ b/drivers/regulator/max8973-regulator.c
44047@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
44048 if (!pdata->enable_ext_control) {
44049 max->desc.enable_reg = MAX8973_VOUT;
44050 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
44051- max8973_dcdc_ops.enable = regulator_enable_regmap;
44052- max8973_dcdc_ops.disable = regulator_disable_regmap;
44053- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
44054+ pax_open_kernel();
44055+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
44056+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
44057+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
44058+ pax_close_kernel();
44059 }
44060
44061 max->enable_external_control = pdata->enable_ext_control;
44062diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
44063index b716283..3cc4349 100644
44064--- a/drivers/regulator/mc13892-regulator.c
44065+++ b/drivers/regulator/mc13892-regulator.c
44066@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
44067 }
44068 mc13xxx_unlock(mc13892);
44069
44070- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
44071+ pax_open_kernel();
44072+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
44073 = mc13892_vcam_set_mode;
44074- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
44075+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
44076 = mc13892_vcam_get_mode;
44077+ pax_close_kernel();
44078
44079 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
44080 ARRAY_SIZE(mc13892_regulators));
44081diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
44082index f1cb706..4c7832a 100644
44083--- a/drivers/rtc/rtc-cmos.c
44084+++ b/drivers/rtc/rtc-cmos.c
44085@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
44086 hpet_rtc_timer_init();
44087
44088 /* export at least the first block of NVRAM */
44089- nvram.size = address_space - NVRAM_OFFSET;
44090+ pax_open_kernel();
44091+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
44092+ pax_close_kernel();
44093 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
44094 if (retval < 0) {
44095 dev_dbg(dev, "can't create nvram file? %d\n", retval);
44096diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
44097index d049393..bb20be0 100644
44098--- a/drivers/rtc/rtc-dev.c
44099+++ b/drivers/rtc/rtc-dev.c
44100@@ -16,6 +16,7 @@
44101 #include <linux/module.h>
44102 #include <linux/rtc.h>
44103 #include <linux/sched.h>
44104+#include <linux/grsecurity.h>
44105 #include "rtc-core.h"
44106
44107 static dev_t rtc_devt;
44108@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
44109 if (copy_from_user(&tm, uarg, sizeof(tm)))
44110 return -EFAULT;
44111
44112+ gr_log_timechange();
44113+
44114 return rtc_set_time(rtc, &tm);
44115
44116 case RTC_PIE_ON:
44117diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
44118index b53992a..776df84 100644
44119--- a/drivers/rtc/rtc-ds1307.c
44120+++ b/drivers/rtc/rtc-ds1307.c
44121@@ -107,7 +107,7 @@ struct ds1307 {
44122 u8 offset; /* register's offset */
44123 u8 regs[11];
44124 u16 nvram_offset;
44125- struct bin_attribute *nvram;
44126+ bin_attribute_no_const *nvram;
44127 enum ds_type type;
44128 unsigned long flags;
44129 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
44130diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
44131index 130f29a..6179d03 100644
44132--- a/drivers/rtc/rtc-m48t59.c
44133+++ b/drivers/rtc/rtc-m48t59.c
44134@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
44135 goto out;
44136 }
44137
44138- m48t59_nvram_attr.size = pdata->offset;
44139+ pax_open_kernel();
44140+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
44141+ pax_close_kernel();
44142
44143 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
44144 if (ret) {
44145diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
44146index e693af6..2e525b6 100644
44147--- a/drivers/scsi/bfa/bfa_fcpim.h
44148+++ b/drivers/scsi/bfa/bfa_fcpim.h
44149@@ -36,7 +36,7 @@ struct bfa_iotag_s {
44150
44151 struct bfa_itn_s {
44152 bfa_isr_func_t isr;
44153-};
44154+} __no_const;
44155
44156 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
44157 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
44158diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
44159index 23a90e7..9cf04ee 100644
44160--- a/drivers/scsi/bfa/bfa_ioc.h
44161+++ b/drivers/scsi/bfa/bfa_ioc.h
44162@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
44163 bfa_ioc_disable_cbfn_t disable_cbfn;
44164 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
44165 bfa_ioc_reset_cbfn_t reset_cbfn;
44166-};
44167+} __no_const;
44168
44169 /*
44170 * IOC event notification mechanism.
44171@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
44172 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
44173 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
44174 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
44175-};
44176+} __no_const;
44177
44178 /*
44179 * Queue element to wait for room in request queue. FIFO order is
44180diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
44181index df0c3c7..b00e1d0 100644
44182--- a/drivers/scsi/hosts.c
44183+++ b/drivers/scsi/hosts.c
44184@@ -42,7 +42,7 @@
44185 #include "scsi_logging.h"
44186
44187
44188-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
44189+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
44190
44191
44192 static void scsi_host_cls_release(struct device *dev)
44193@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
44194 * subtract one because we increment first then return, but we need to
44195 * know what the next host number was before increment
44196 */
44197- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
44198+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
44199 shost->dma_channel = 0xff;
44200
44201 /* These three are default values which can be overridden */
44202diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
44203index 7f4f790..b75b92a 100644
44204--- a/drivers/scsi/hpsa.c
44205+++ b/drivers/scsi/hpsa.c
44206@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
44207 unsigned long flags;
44208
44209 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
44210- return h->access.command_completed(h, q);
44211+ return h->access->command_completed(h, q);
44212
44213 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
44214 a = rq->head[rq->current_entry];
44215@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
44216 while (!list_empty(&h->reqQ)) {
44217 c = list_entry(h->reqQ.next, struct CommandList, list);
44218 /* can't do anything if fifo is full */
44219- if ((h->access.fifo_full(h))) {
44220+ if ((h->access->fifo_full(h))) {
44221 dev_warn(&h->pdev->dev, "fifo full\n");
44222 break;
44223 }
44224@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
44225
44226 /* Tell the controller execute command */
44227 spin_unlock_irqrestore(&h->lock, flags);
44228- h->access.submit_command(h, c);
44229+ h->access->submit_command(h, c);
44230 spin_lock_irqsave(&h->lock, flags);
44231 }
44232 spin_unlock_irqrestore(&h->lock, flags);
44233@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
44234
44235 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
44236 {
44237- return h->access.command_completed(h, q);
44238+ return h->access->command_completed(h, q);
44239 }
44240
44241 static inline bool interrupt_pending(struct ctlr_info *h)
44242 {
44243- return h->access.intr_pending(h);
44244+ return h->access->intr_pending(h);
44245 }
44246
44247 static inline long interrupt_not_for_us(struct ctlr_info *h)
44248 {
44249- return (h->access.intr_pending(h) == 0) ||
44250+ return (h->access->intr_pending(h) == 0) ||
44251 (h->interrupts_enabled == 0);
44252 }
44253
44254@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
44255 if (prod_index < 0)
44256 return -ENODEV;
44257 h->product_name = products[prod_index].product_name;
44258- h->access = *(products[prod_index].access);
44259+ h->access = products[prod_index].access;
44260
44261 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
44262 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
44263@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
44264
44265 assert_spin_locked(&lockup_detector_lock);
44266 remove_ctlr_from_lockup_detector_list(h);
44267- h->access.set_intr_mask(h, HPSA_INTR_OFF);
44268+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
44269 spin_lock_irqsave(&h->lock, flags);
44270 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
44271 spin_unlock_irqrestore(&h->lock, flags);
44272@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
44273 }
44274
44275 /* make sure the board interrupts are off */
44276- h->access.set_intr_mask(h, HPSA_INTR_OFF);
44277+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
44278
44279 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
44280 goto clean2;
44281@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
44282 * fake ones to scoop up any residual completions.
44283 */
44284 spin_lock_irqsave(&h->lock, flags);
44285- h->access.set_intr_mask(h, HPSA_INTR_OFF);
44286+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
44287 spin_unlock_irqrestore(&h->lock, flags);
44288 free_irqs(h);
44289 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
44290@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
44291 dev_info(&h->pdev->dev, "Board READY.\n");
44292 dev_info(&h->pdev->dev,
44293 "Waiting for stale completions to drain.\n");
44294- h->access.set_intr_mask(h, HPSA_INTR_ON);
44295+ h->access->set_intr_mask(h, HPSA_INTR_ON);
44296 msleep(10000);
44297- h->access.set_intr_mask(h, HPSA_INTR_OFF);
44298+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
44299
44300 rc = controller_reset_failed(h->cfgtable);
44301 if (rc)
44302@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
44303 }
44304
44305 /* Turn the interrupts on so we can service requests */
44306- h->access.set_intr_mask(h, HPSA_INTR_ON);
44307+ h->access->set_intr_mask(h, HPSA_INTR_ON);
44308
44309 hpsa_hba_inquiry(h);
44310 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
44311@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
44312 * To write all data in the battery backed cache to disks
44313 */
44314 hpsa_flush_cache(h);
44315- h->access.set_intr_mask(h, HPSA_INTR_OFF);
44316+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
44317 hpsa_free_irqs_and_disable_msix(h);
44318 }
44319
44320@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
44321 return;
44322 }
44323 /* Change the access methods to the performant access methods */
44324- h->access = SA5_performant_access;
44325+ h->access = &SA5_performant_access;
44326 h->transMethod = CFGTBL_Trans_Performant;
44327 }
44328
44329diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
44330index 9816479..c5d4e97 100644
44331--- a/drivers/scsi/hpsa.h
44332+++ b/drivers/scsi/hpsa.h
44333@@ -79,7 +79,7 @@ struct ctlr_info {
44334 unsigned int msix_vector;
44335 unsigned int msi_vector;
44336 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
44337- struct access_method access;
44338+ struct access_method *access;
44339
44340 /* queue and queue Info */
44341 struct list_head reqQ;
44342diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
44343index 8b928c6..9c76300 100644
44344--- a/drivers/scsi/libfc/fc_exch.c
44345+++ b/drivers/scsi/libfc/fc_exch.c
44346@@ -100,12 +100,12 @@ struct fc_exch_mgr {
44347 u16 pool_max_index;
44348
44349 struct {
44350- atomic_t no_free_exch;
44351- atomic_t no_free_exch_xid;
44352- atomic_t xid_not_found;
44353- atomic_t xid_busy;
44354- atomic_t seq_not_found;
44355- atomic_t non_bls_resp;
44356+ atomic_unchecked_t no_free_exch;
44357+ atomic_unchecked_t no_free_exch_xid;
44358+ atomic_unchecked_t xid_not_found;
44359+ atomic_unchecked_t xid_busy;
44360+ atomic_unchecked_t seq_not_found;
44361+ atomic_unchecked_t non_bls_resp;
44362 } stats;
44363 };
44364
44365@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
44366 /* allocate memory for exchange */
44367 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
44368 if (!ep) {
44369- atomic_inc(&mp->stats.no_free_exch);
44370+ atomic_inc_unchecked(&mp->stats.no_free_exch);
44371 goto out;
44372 }
44373 memset(ep, 0, sizeof(*ep));
44374@@ -797,7 +797,7 @@ out:
44375 return ep;
44376 err:
44377 spin_unlock_bh(&pool->lock);
44378- atomic_inc(&mp->stats.no_free_exch_xid);
44379+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
44380 mempool_free(ep, mp->ep_pool);
44381 return NULL;
44382 }
44383@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
44384 xid = ntohs(fh->fh_ox_id); /* we originated exch */
44385 ep = fc_exch_find(mp, xid);
44386 if (!ep) {
44387- atomic_inc(&mp->stats.xid_not_found);
44388+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44389 reject = FC_RJT_OX_ID;
44390 goto out;
44391 }
44392@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
44393 ep = fc_exch_find(mp, xid);
44394 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
44395 if (ep) {
44396- atomic_inc(&mp->stats.xid_busy);
44397+ atomic_inc_unchecked(&mp->stats.xid_busy);
44398 reject = FC_RJT_RX_ID;
44399 goto rel;
44400 }
44401@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
44402 }
44403 xid = ep->xid; /* get our XID */
44404 } else if (!ep) {
44405- atomic_inc(&mp->stats.xid_not_found);
44406+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44407 reject = FC_RJT_RX_ID; /* XID not found */
44408 goto out;
44409 }
44410@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
44411 } else {
44412 sp = &ep->seq;
44413 if (sp->id != fh->fh_seq_id) {
44414- atomic_inc(&mp->stats.seq_not_found);
44415+ atomic_inc_unchecked(&mp->stats.seq_not_found);
44416 if (f_ctl & FC_FC_END_SEQ) {
44417 /*
44418 * Update sequence_id based on incoming last
44419@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
44420
44421 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
44422 if (!ep) {
44423- atomic_inc(&mp->stats.xid_not_found);
44424+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44425 goto out;
44426 }
44427 if (ep->esb_stat & ESB_ST_COMPLETE) {
44428- atomic_inc(&mp->stats.xid_not_found);
44429+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44430 goto rel;
44431 }
44432 if (ep->rxid == FC_XID_UNKNOWN)
44433 ep->rxid = ntohs(fh->fh_rx_id);
44434 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
44435- atomic_inc(&mp->stats.xid_not_found);
44436+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44437 goto rel;
44438 }
44439 if (ep->did != ntoh24(fh->fh_s_id) &&
44440 ep->did != FC_FID_FLOGI) {
44441- atomic_inc(&mp->stats.xid_not_found);
44442+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44443 goto rel;
44444 }
44445 sof = fr_sof(fp);
44446@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
44447 sp->ssb_stat |= SSB_ST_RESP;
44448 sp->id = fh->fh_seq_id;
44449 } else if (sp->id != fh->fh_seq_id) {
44450- atomic_inc(&mp->stats.seq_not_found);
44451+ atomic_inc_unchecked(&mp->stats.seq_not_found);
44452 goto rel;
44453 }
44454
44455@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
44456 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
44457
44458 if (!sp)
44459- atomic_inc(&mp->stats.xid_not_found);
44460+ atomic_inc_unchecked(&mp->stats.xid_not_found);
44461 else
44462- atomic_inc(&mp->stats.non_bls_resp);
44463+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
44464
44465 fc_frame_free(fp);
44466 }
44467@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
44468
44469 list_for_each_entry(ema, &lport->ema_list, ema_list) {
44470 mp = ema->mp;
44471- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
44472+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
44473 st->fc_no_free_exch_xid +=
44474- atomic_read(&mp->stats.no_free_exch_xid);
44475- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
44476- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
44477- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
44478- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
44479+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
44480+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
44481+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
44482+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
44483+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
44484 }
44485 }
44486 EXPORT_SYMBOL(fc_exch_update_stats);
44487diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
44488index 161c98e..6d563b3 100644
44489--- a/drivers/scsi/libsas/sas_ata.c
44490+++ b/drivers/scsi/libsas/sas_ata.c
44491@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
44492 .postreset = ata_std_postreset,
44493 .error_handler = ata_std_error_handler,
44494 .post_internal_cmd = sas_ata_post_internal,
44495- .qc_defer = ata_std_qc_defer,
44496+ .qc_defer = ata_std_qc_defer,
44497 .qc_prep = ata_noop_qc_prep,
44498 .qc_issue = sas_ata_qc_issue,
44499 .qc_fill_rtf = sas_ata_qc_fill_rtf,
44500diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
44501index bcc56ca..6f4174a 100644
44502--- a/drivers/scsi/lpfc/lpfc.h
44503+++ b/drivers/scsi/lpfc/lpfc.h
44504@@ -431,7 +431,7 @@ struct lpfc_vport {
44505 struct dentry *debug_nodelist;
44506 struct dentry *vport_debugfs_root;
44507 struct lpfc_debugfs_trc *disc_trc;
44508- atomic_t disc_trc_cnt;
44509+ atomic_unchecked_t disc_trc_cnt;
44510 #endif
44511 uint8_t stat_data_enabled;
44512 uint8_t stat_data_blocked;
44513@@ -865,8 +865,8 @@ struct lpfc_hba {
44514 struct timer_list fabric_block_timer;
44515 unsigned long bit_flags;
44516 #define FABRIC_COMANDS_BLOCKED 0
44517- atomic_t num_rsrc_err;
44518- atomic_t num_cmd_success;
44519+ atomic_unchecked_t num_rsrc_err;
44520+ atomic_unchecked_t num_cmd_success;
44521 unsigned long last_rsrc_error_time;
44522 unsigned long last_ramp_down_time;
44523 unsigned long last_ramp_up_time;
44524@@ -902,7 +902,7 @@ struct lpfc_hba {
44525
44526 struct dentry *debug_slow_ring_trc;
44527 struct lpfc_debugfs_trc *slow_ring_trc;
44528- atomic_t slow_ring_trc_cnt;
44529+ atomic_unchecked_t slow_ring_trc_cnt;
44530 /* iDiag debugfs sub-directory */
44531 struct dentry *idiag_root;
44532 struct dentry *idiag_pci_cfg;
44533diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
44534index f525ecb..32549a4 100644
44535--- a/drivers/scsi/lpfc/lpfc_debugfs.c
44536+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
44537@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
44538
44539 #include <linux/debugfs.h>
44540
44541-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
44542+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
44543 static unsigned long lpfc_debugfs_start_time = 0L;
44544
44545 /* iDiag */
44546@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
44547 lpfc_debugfs_enable = 0;
44548
44549 len = 0;
44550- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
44551+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
44552 (lpfc_debugfs_max_disc_trc - 1);
44553 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
44554 dtp = vport->disc_trc + i;
44555@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
44556 lpfc_debugfs_enable = 0;
44557
44558 len = 0;
44559- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
44560+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
44561 (lpfc_debugfs_max_slow_ring_trc - 1);
44562 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
44563 dtp = phba->slow_ring_trc + i;
44564@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
44565 !vport || !vport->disc_trc)
44566 return;
44567
44568- index = atomic_inc_return(&vport->disc_trc_cnt) &
44569+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
44570 (lpfc_debugfs_max_disc_trc - 1);
44571 dtp = vport->disc_trc + index;
44572 dtp->fmt = fmt;
44573 dtp->data1 = data1;
44574 dtp->data2 = data2;
44575 dtp->data3 = data3;
44576- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
44577+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
44578 dtp->jif = jiffies;
44579 #endif
44580 return;
44581@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
44582 !phba || !phba->slow_ring_trc)
44583 return;
44584
44585- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
44586+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
44587 (lpfc_debugfs_max_slow_ring_trc - 1);
44588 dtp = phba->slow_ring_trc + index;
44589 dtp->fmt = fmt;
44590 dtp->data1 = data1;
44591 dtp->data2 = data2;
44592 dtp->data3 = data3;
44593- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
44594+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
44595 dtp->jif = jiffies;
44596 #endif
44597 return;
44598@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
44599 "slow_ring buffer\n");
44600 goto debug_failed;
44601 }
44602- atomic_set(&phba->slow_ring_trc_cnt, 0);
44603+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
44604 memset(phba->slow_ring_trc, 0,
44605 (sizeof(struct lpfc_debugfs_trc) *
44606 lpfc_debugfs_max_slow_ring_trc));
44607@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
44608 "buffer\n");
44609 goto debug_failed;
44610 }
44611- atomic_set(&vport->disc_trc_cnt, 0);
44612+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
44613
44614 snprintf(name, sizeof(name), "discovery_trace");
44615 vport->debug_disc_trc =
44616diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
44617index cb465b2..2e7b25f 100644
44618--- a/drivers/scsi/lpfc/lpfc_init.c
44619+++ b/drivers/scsi/lpfc/lpfc_init.c
44620@@ -10950,8 +10950,10 @@ lpfc_init(void)
44621 "misc_register returned with status %d", error);
44622
44623 if (lpfc_enable_npiv) {
44624- lpfc_transport_functions.vport_create = lpfc_vport_create;
44625- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
44626+ pax_open_kernel();
44627+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
44628+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
44629+ pax_close_kernel();
44630 }
44631 lpfc_transport_template =
44632 fc_attach_transport(&lpfc_transport_functions);
44633diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
44634index 8523b278e..ce1d812 100644
44635--- a/drivers/scsi/lpfc/lpfc_scsi.c
44636+++ b/drivers/scsi/lpfc/lpfc_scsi.c
44637@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
44638 uint32_t evt_posted;
44639
44640 spin_lock_irqsave(&phba->hbalock, flags);
44641- atomic_inc(&phba->num_rsrc_err);
44642+ atomic_inc_unchecked(&phba->num_rsrc_err);
44643 phba->last_rsrc_error_time = jiffies;
44644
44645 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
44646@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
44647 unsigned long flags;
44648 struct lpfc_hba *phba = vport->phba;
44649 uint32_t evt_posted;
44650- atomic_inc(&phba->num_cmd_success);
44651+ atomic_inc_unchecked(&phba->num_cmd_success);
44652
44653 if (vport->cfg_lun_queue_depth <= queue_depth)
44654 return;
44655@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
44656 unsigned long num_rsrc_err, num_cmd_success;
44657 int i;
44658
44659- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
44660- num_cmd_success = atomic_read(&phba->num_cmd_success);
44661+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
44662+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
44663
44664 /*
44665 * The error and success command counters are global per
44666@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
44667 }
44668 }
44669 lpfc_destroy_vport_work_array(phba, vports);
44670- atomic_set(&phba->num_rsrc_err, 0);
44671- atomic_set(&phba->num_cmd_success, 0);
44672+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
44673+ atomic_set_unchecked(&phba->num_cmd_success, 0);
44674 }
44675
44676 /**
44677@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
44678 }
44679 }
44680 lpfc_destroy_vport_work_array(phba, vports);
44681- atomic_set(&phba->num_rsrc_err, 0);
44682- atomic_set(&phba->num_cmd_success, 0);
44683+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
44684+ atomic_set_unchecked(&phba->num_cmd_success, 0);
44685 }
44686
44687 /**
44688diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
44689index 8e1b737..50ff510 100644
44690--- a/drivers/scsi/pmcraid.c
44691+++ b/drivers/scsi/pmcraid.c
44692@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
44693 res->scsi_dev = scsi_dev;
44694 scsi_dev->hostdata = res;
44695 res->change_detected = 0;
44696- atomic_set(&res->read_failures, 0);
44697- atomic_set(&res->write_failures, 0);
44698+ atomic_set_unchecked(&res->read_failures, 0);
44699+ atomic_set_unchecked(&res->write_failures, 0);
44700 rc = 0;
44701 }
44702 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
44703@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
44704
44705 /* If this was a SCSI read/write command keep count of errors */
44706 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
44707- atomic_inc(&res->read_failures);
44708+ atomic_inc_unchecked(&res->read_failures);
44709 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
44710- atomic_inc(&res->write_failures);
44711+ atomic_inc_unchecked(&res->write_failures);
44712
44713 if (!RES_IS_GSCSI(res->cfg_entry) &&
44714 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
44715@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
44716 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
44717 * hrrq_id assigned here in queuecommand
44718 */
44719- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
44720+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
44721 pinstance->num_hrrq;
44722 cmd->cmd_done = pmcraid_io_done;
44723
44724@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
44725 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
44726 * hrrq_id assigned here in queuecommand
44727 */
44728- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
44729+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
44730 pinstance->num_hrrq;
44731
44732 if (request_size) {
44733@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
44734
44735 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
44736 /* add resources only after host is added into system */
44737- if (!atomic_read(&pinstance->expose_resources))
44738+ if (!atomic_read_unchecked(&pinstance->expose_resources))
44739 return;
44740
44741 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
44742@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
44743 init_waitqueue_head(&pinstance->reset_wait_q);
44744
44745 atomic_set(&pinstance->outstanding_cmds, 0);
44746- atomic_set(&pinstance->last_message_id, 0);
44747- atomic_set(&pinstance->expose_resources, 0);
44748+ atomic_set_unchecked(&pinstance->last_message_id, 0);
44749+ atomic_set_unchecked(&pinstance->expose_resources, 0);
44750
44751 INIT_LIST_HEAD(&pinstance->free_res_q);
44752 INIT_LIST_HEAD(&pinstance->used_res_q);
44753@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
44754 /* Schedule worker thread to handle CCN and take care of adding and
44755 * removing devices to OS
44756 */
44757- atomic_set(&pinstance->expose_resources, 1);
44758+ atomic_set_unchecked(&pinstance->expose_resources, 1);
44759 schedule_work(&pinstance->worker_q);
44760 return rc;
44761
44762diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
44763index e1d150f..6c6df44 100644
44764--- a/drivers/scsi/pmcraid.h
44765+++ b/drivers/scsi/pmcraid.h
44766@@ -748,7 +748,7 @@ struct pmcraid_instance {
44767 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
44768
44769 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
44770- atomic_t last_message_id;
44771+ atomic_unchecked_t last_message_id;
44772
44773 /* configuration table */
44774 struct pmcraid_config_table *cfg_table;
44775@@ -777,7 +777,7 @@ struct pmcraid_instance {
44776 atomic_t outstanding_cmds;
44777
44778 /* should add/delete resources to mid-layer now ?*/
44779- atomic_t expose_resources;
44780+ atomic_unchecked_t expose_resources;
44781
44782
44783
44784@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
44785 struct pmcraid_config_table_entry_ext cfg_entry_ext;
44786 };
44787 struct scsi_device *scsi_dev; /* Link scsi_device structure */
44788- atomic_t read_failures; /* count of failed READ commands */
44789- atomic_t write_failures; /* count of failed WRITE commands */
44790+ atomic_unchecked_t read_failures; /* count of failed READ commands */
44791+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
44792
44793 /* To indicate add/delete/modify during CCN */
44794 u8 change_detected;
44795diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
44796index bf60c63..74d4dce 100644
44797--- a/drivers/scsi/qla2xxx/qla_attr.c
44798+++ b/drivers/scsi/qla2xxx/qla_attr.c
44799@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
44800 return 0;
44801 }
44802
44803-struct fc_function_template qla2xxx_transport_functions = {
44804+fc_function_template_no_const qla2xxx_transport_functions = {
44805
44806 .show_host_node_name = 1,
44807 .show_host_port_name = 1,
44808@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
44809 .bsg_timeout = qla24xx_bsg_timeout,
44810 };
44811
44812-struct fc_function_template qla2xxx_transport_vport_functions = {
44813+fc_function_template_no_const qla2xxx_transport_vport_functions = {
44814
44815 .show_host_node_name = 1,
44816 .show_host_port_name = 1,
44817diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
44818index 026bfde..90c4018 100644
44819--- a/drivers/scsi/qla2xxx/qla_gbl.h
44820+++ b/drivers/scsi/qla2xxx/qla_gbl.h
44821@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
44822 struct device_attribute;
44823 extern struct device_attribute *qla2x00_host_attrs[];
44824 struct fc_function_template;
44825-extern struct fc_function_template qla2xxx_transport_functions;
44826-extern struct fc_function_template qla2xxx_transport_vport_functions;
44827+extern fc_function_template_no_const qla2xxx_transport_functions;
44828+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
44829 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
44830 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
44831 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
44832diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
44833index ad72c1d..afc9a98 100644
44834--- a/drivers/scsi/qla2xxx/qla_os.c
44835+++ b/drivers/scsi/qla2xxx/qla_os.c
44836@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
44837 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
44838 /* Ok, a 64bit DMA mask is applicable. */
44839 ha->flags.enable_64bit_addressing = 1;
44840- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
44841- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
44842+ pax_open_kernel();
44843+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
44844+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
44845+ pax_close_kernel();
44846 return;
44847 }
44848 }
44849diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
44850index ddf16a8..80f4dd0 100644
44851--- a/drivers/scsi/qla4xxx/ql4_def.h
44852+++ b/drivers/scsi/qla4xxx/ql4_def.h
44853@@ -291,7 +291,7 @@ struct ddb_entry {
44854 * (4000 only) */
44855 atomic_t relogin_timer; /* Max Time to wait for
44856 * relogin to complete */
44857- atomic_t relogin_retry_count; /* Num of times relogin has been
44858+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
44859 * retried */
44860 uint32_t default_time2wait; /* Default Min time between
44861 * relogins (+aens) */
44862diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
44863index 4d231c1..2892c37 100644
44864--- a/drivers/scsi/qla4xxx/ql4_os.c
44865+++ b/drivers/scsi/qla4xxx/ql4_os.c
44866@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
44867 */
44868 if (!iscsi_is_session_online(cls_sess)) {
44869 /* Reset retry relogin timer */
44870- atomic_inc(&ddb_entry->relogin_retry_count);
44871+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
44872 DEBUG2(ql4_printk(KERN_INFO, ha,
44873 "%s: index[%d] relogin timed out-retrying"
44874 " relogin (%d), retry (%d)\n", __func__,
44875 ddb_entry->fw_ddb_index,
44876- atomic_read(&ddb_entry->relogin_retry_count),
44877+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
44878 ddb_entry->default_time2wait + 4));
44879 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
44880 atomic_set(&ddb_entry->retry_relogin_timer,
44881@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
44882
44883 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
44884 atomic_set(&ddb_entry->relogin_timer, 0);
44885- atomic_set(&ddb_entry->relogin_retry_count, 0);
44886+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
44887 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
44888 ddb_entry->default_relogin_timeout =
44889 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
44890diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
44891index eaa808e..95f8841 100644
44892--- a/drivers/scsi/scsi.c
44893+++ b/drivers/scsi/scsi.c
44894@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
44895 unsigned long timeout;
44896 int rtn = 0;
44897
44898- atomic_inc(&cmd->device->iorequest_cnt);
44899+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
44900
44901 /* check if the device is still usable */
44902 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
44903diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
44904index 86d5220..f22c51a 100644
44905--- a/drivers/scsi/scsi_lib.c
44906+++ b/drivers/scsi/scsi_lib.c
44907@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
44908 shost = sdev->host;
44909 scsi_init_cmd_errh(cmd);
44910 cmd->result = DID_NO_CONNECT << 16;
44911- atomic_inc(&cmd->device->iorequest_cnt);
44912+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
44913
44914 /*
44915 * SCSI request completion path will do scsi_device_unbusy(),
44916@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
44917
44918 INIT_LIST_HEAD(&cmd->eh_entry);
44919
44920- atomic_inc(&cmd->device->iodone_cnt);
44921+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
44922 if (cmd->result)
44923- atomic_inc(&cmd->device->ioerr_cnt);
44924+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
44925
44926 disposition = scsi_decide_disposition(cmd);
44927 if (disposition != SUCCESS &&
44928diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
44929index 931a7d9..0c2a754 100644
44930--- a/drivers/scsi/scsi_sysfs.c
44931+++ b/drivers/scsi/scsi_sysfs.c
44932@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
44933 char *buf) \
44934 { \
44935 struct scsi_device *sdev = to_scsi_device(dev); \
44936- unsigned long long count = atomic_read(&sdev->field); \
44937+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
44938 return snprintf(buf, 20, "0x%llx\n", count); \
44939 } \
44940 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
44941diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
44942index 84a1fdf..693b0d6 100644
44943--- a/drivers/scsi/scsi_tgt_lib.c
44944+++ b/drivers/scsi/scsi_tgt_lib.c
44945@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
44946 int err;
44947
44948 dprintk("%lx %u\n", uaddr, len);
44949- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
44950+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
44951 if (err) {
44952 /*
44953 * TODO: need to fixup sg_tablesize, max_segment_size,
44954diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
44955index e106c27..11a380e 100644
44956--- a/drivers/scsi/scsi_transport_fc.c
44957+++ b/drivers/scsi/scsi_transport_fc.c
44958@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
44959 * Netlink Infrastructure
44960 */
44961
44962-static atomic_t fc_event_seq;
44963+static atomic_unchecked_t fc_event_seq;
44964
44965 /**
44966 * fc_get_event_number - Obtain the next sequential FC event number
44967@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
44968 u32
44969 fc_get_event_number(void)
44970 {
44971- return atomic_add_return(1, &fc_event_seq);
44972+ return atomic_add_return_unchecked(1, &fc_event_seq);
44973 }
44974 EXPORT_SYMBOL(fc_get_event_number);
44975
44976@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
44977 {
44978 int error;
44979
44980- atomic_set(&fc_event_seq, 0);
44981+ atomic_set_unchecked(&fc_event_seq, 0);
44982
44983 error = transport_class_register(&fc_host_class);
44984 if (error)
44985@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
44986 char *cp;
44987
44988 *val = simple_strtoul(buf, &cp, 0);
44989- if ((*cp && (*cp != '\n')) || (*val < 0))
44990+ if (*cp && (*cp != '\n'))
44991 return -EINVAL;
44992 /*
44993 * Check for overflow; dev_loss_tmo is u32
44994diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
44995index 133926b..903000d 100644
44996--- a/drivers/scsi/scsi_transport_iscsi.c
44997+++ b/drivers/scsi/scsi_transport_iscsi.c
44998@@ -80,7 +80,7 @@ struct iscsi_internal {
44999 struct transport_container session_cont;
45000 };
45001
45002-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
45003+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
45004 static struct workqueue_struct *iscsi_eh_timer_workq;
45005
45006 static DEFINE_IDA(iscsi_sess_ida);
45007@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
45008 int err;
45009
45010 ihost = shost->shost_data;
45011- session->sid = atomic_add_return(1, &iscsi_session_nr);
45012+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
45013
45014 if (target_id == ISCSI_MAX_TARGET) {
45015 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
45016@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
45017 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
45018 ISCSI_TRANSPORT_VERSION);
45019
45020- atomic_set(&iscsi_session_nr, 0);
45021+ atomic_set_unchecked(&iscsi_session_nr, 0);
45022
45023 err = class_register(&iscsi_transport_class);
45024 if (err)
45025diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
45026index f379c7f..e8fc69c 100644
45027--- a/drivers/scsi/scsi_transport_srp.c
45028+++ b/drivers/scsi/scsi_transport_srp.c
45029@@ -33,7 +33,7 @@
45030 #include "scsi_transport_srp_internal.h"
45031
45032 struct srp_host_attrs {
45033- atomic_t next_port_id;
45034+ atomic_unchecked_t next_port_id;
45035 };
45036 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
45037
45038@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
45039 struct Scsi_Host *shost = dev_to_shost(dev);
45040 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
45041
45042- atomic_set(&srp_host->next_port_id, 0);
45043+ atomic_set_unchecked(&srp_host->next_port_id, 0);
45044 return 0;
45045 }
45046
45047@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
45048 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
45049 rport->roles = ids->roles;
45050
45051- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
45052+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
45053 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
45054
45055 transport_setup_device(&rport->dev);
45056diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
45057index 610417e..1544fa9 100644
45058--- a/drivers/scsi/sd.c
45059+++ b/drivers/scsi/sd.c
45060@@ -2928,7 +2928,7 @@ static int sd_probe(struct device *dev)
45061 sdkp->disk = gd;
45062 sdkp->index = index;
45063 atomic_set(&sdkp->openers, 0);
45064- atomic_set(&sdkp->device->ioerr_cnt, 0);
45065+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
45066
45067 if (!sdp->request_queue->rq_timeout) {
45068 if (sdp->type != TYPE_MOD)
45069diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
45070index df5e961..df6b97f 100644
45071--- a/drivers/scsi/sg.c
45072+++ b/drivers/scsi/sg.c
45073@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
45074 sdp->disk->disk_name,
45075 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
45076 NULL,
45077- (char *)arg);
45078+ (char __user *)arg);
45079 case BLKTRACESTART:
45080 return blk_trace_startstop(sdp->device->request_queue, 1);
45081 case BLKTRACESTOP:
45082diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
45083index 32b7bb1..2f1c4bd 100644
45084--- a/drivers/spi/spi.c
45085+++ b/drivers/spi/spi.c
45086@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
45087 EXPORT_SYMBOL_GPL(spi_bus_unlock);
45088
45089 /* portable code must never pass more than 32 bytes */
45090-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
45091+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
45092
45093 static u8 *buf;
45094
45095diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
45096index 3675020..e80d92c 100644
45097--- a/drivers/staging/media/solo6x10/solo6x10-core.c
45098+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
45099@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
45100
45101 static int solo_sysfs_init(struct solo_dev *solo_dev)
45102 {
45103- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45104+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45105 struct device *dev = &solo_dev->dev;
45106 const char *driver;
45107 int i;
45108diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
45109index 34afc16..ffe44dd 100644
45110--- a/drivers/staging/octeon/ethernet-rx.c
45111+++ b/drivers/staging/octeon/ethernet-rx.c
45112@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
45113 /* Increment RX stats for virtual ports */
45114 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
45115 #ifdef CONFIG_64BIT
45116- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
45117- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
45118+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
45119+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
45120 #else
45121- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
45122- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
45123+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
45124+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
45125 #endif
45126 }
45127 netif_receive_skb(skb);
45128@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
45129 dev->name);
45130 */
45131 #ifdef CONFIG_64BIT
45132- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
45133+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
45134 #else
45135- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
45136+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
45137 #endif
45138 dev_kfree_skb_irq(skb);
45139 }
45140diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
45141index c3a90e7..023619a 100644
45142--- a/drivers/staging/octeon/ethernet.c
45143+++ b/drivers/staging/octeon/ethernet.c
45144@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
45145 * since the RX tasklet also increments it.
45146 */
45147 #ifdef CONFIG_64BIT
45148- atomic64_add(rx_status.dropped_packets,
45149- (atomic64_t *)&priv->stats.rx_dropped);
45150+ atomic64_add_unchecked(rx_status.dropped_packets,
45151+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
45152 #else
45153- atomic_add(rx_status.dropped_packets,
45154- (atomic_t *)&priv->stats.rx_dropped);
45155+ atomic_add_unchecked(rx_status.dropped_packets,
45156+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
45157 #endif
45158 }
45159
45160diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
45161index dc23395..cf7e9b1 100644
45162--- a/drivers/staging/rtl8712/rtl871x_io.h
45163+++ b/drivers/staging/rtl8712/rtl871x_io.h
45164@@ -108,7 +108,7 @@ struct _io_ops {
45165 u8 *pmem);
45166 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
45167 u8 *pmem);
45168-};
45169+} __no_const;
45170
45171 struct io_req {
45172 struct list_head list;
45173diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
45174index 1f5088b..0e59820 100644
45175--- a/drivers/staging/sbe-2t3e3/netdev.c
45176+++ b/drivers/staging/sbe-2t3e3/netdev.c
45177@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45178 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
45179
45180 if (rlen)
45181- if (copy_to_user(data, &resp, rlen))
45182+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
45183 return -EFAULT;
45184
45185 return 0;
45186diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
45187index a863a98..d272795 100644
45188--- a/drivers/staging/usbip/vhci.h
45189+++ b/drivers/staging/usbip/vhci.h
45190@@ -83,7 +83,7 @@ struct vhci_hcd {
45191 unsigned resuming:1;
45192 unsigned long re_timeout;
45193
45194- atomic_t seqnum;
45195+ atomic_unchecked_t seqnum;
45196
45197 /*
45198 * NOTE:
45199diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
45200index d7974cb..d78076b 100644
45201--- a/drivers/staging/usbip/vhci_hcd.c
45202+++ b/drivers/staging/usbip/vhci_hcd.c
45203@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
45204
45205 spin_lock(&vdev->priv_lock);
45206
45207- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
45208+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
45209 if (priv->seqnum == 0xffff)
45210 dev_info(&urb->dev->dev, "seqnum max\n");
45211
45212@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
45213 return -ENOMEM;
45214 }
45215
45216- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
45217+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
45218 if (unlink->seqnum == 0xffff)
45219 pr_info("seqnum max\n");
45220
45221@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
45222 vdev->rhport = rhport;
45223 }
45224
45225- atomic_set(&vhci->seqnum, 0);
45226+ atomic_set_unchecked(&vhci->seqnum, 0);
45227 spin_lock_init(&vhci->lock);
45228
45229 hcd->power_budget = 0; /* no limit */
45230diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
45231index d07fcb5..358e1e1 100644
45232--- a/drivers/staging/usbip/vhci_rx.c
45233+++ b/drivers/staging/usbip/vhci_rx.c
45234@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
45235 if (!urb) {
45236 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
45237 pr_info("max seqnum %d\n",
45238- atomic_read(&the_controller->seqnum));
45239+ atomic_read_unchecked(&the_controller->seqnum));
45240 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
45241 return;
45242 }
45243diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
45244index 8417c2f..ef5ebd6 100644
45245--- a/drivers/staging/vt6655/hostap.c
45246+++ b/drivers/staging/vt6655/hostap.c
45247@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
45248 *
45249 */
45250
45251+static net_device_ops_no_const apdev_netdev_ops;
45252+
45253 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
45254 {
45255 PSDevice apdev_priv;
45256 struct net_device *dev = pDevice->dev;
45257 int ret;
45258- const struct net_device_ops apdev_netdev_ops = {
45259- .ndo_start_xmit = pDevice->tx_80211,
45260- };
45261
45262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
45263
45264@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
45265 *apdev_priv = *pDevice;
45266 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
45267
45268+ /* only half broken now */
45269+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
45270 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
45271
45272 pDevice->apdev->type = ARPHRD_IEEE80211;
45273diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
45274index c699a30..b90a5fd 100644
45275--- a/drivers/staging/vt6656/hostap.c
45276+++ b/drivers/staging/vt6656/hostap.c
45277@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
45278 *
45279 */
45280
45281+static net_device_ops_no_const apdev_netdev_ops;
45282+
45283 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
45284 {
45285 struct vnt_private *apdev_priv;
45286 struct net_device *dev = pDevice->dev;
45287 int ret;
45288- const struct net_device_ops apdev_netdev_ops = {
45289- .ndo_start_xmit = pDevice->tx_80211,
45290- };
45291
45292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
45293
45294@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
45295 *apdev_priv = *pDevice;
45296 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
45297
45298+ /* only half broken now */
45299+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
45300 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
45301
45302 pDevice->apdev->type = ARPHRD_IEEE80211;
45303diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
45304index d7e51e4..d07eaab 100644
45305--- a/drivers/staging/zcache/tmem.c
45306+++ b/drivers/staging/zcache/tmem.c
45307@@ -51,7 +51,7 @@
45308 * A tmem host implementation must use this function to register callbacks
45309 * for memory allocation.
45310 */
45311-static struct tmem_hostops tmem_hostops;
45312+static tmem_hostops_no_const tmem_hostops;
45313
45314 static void tmem_objnode_tree_init(void);
45315
45316@@ -65,7 +65,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
45317 * A tmem host implementation must use this function to register
45318 * callbacks for a page-accessible memory (PAM) implementation.
45319 */
45320-static struct tmem_pamops tmem_pamops;
45321+static tmem_pamops_no_const tmem_pamops;
45322
45323 void tmem_register_pamops(struct tmem_pamops *m)
45324 {
45325diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
45326index d128ce2..a43980c 100644
45327--- a/drivers/staging/zcache/tmem.h
45328+++ b/drivers/staging/zcache/tmem.h
45329@@ -226,6 +226,7 @@ struct tmem_pamops {
45330 int (*replace_in_obj)(void *, struct tmem_obj *);
45331 #endif
45332 };
45333+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
45334 extern void tmem_register_pamops(struct tmem_pamops *m);
45335
45336 /* memory allocation methods provided by the host implementation */
45337@@ -235,6 +236,7 @@ struct tmem_hostops {
45338 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
45339 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
45340 };
45341+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
45342 extern void tmem_register_hostops(struct tmem_hostops *m);
45343
45344 /* core tmem accessor functions */
45345diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
45346index 4630481..c26782a 100644
45347--- a/drivers/target/target_core_device.c
45348+++ b/drivers/target/target_core_device.c
45349@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
45350 spin_lock_init(&dev->se_port_lock);
45351 spin_lock_init(&dev->se_tmr_lock);
45352 spin_lock_init(&dev->qf_cmd_lock);
45353- atomic_set(&dev->dev_ordered_id, 0);
45354+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
45355 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
45356 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
45357 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
45358diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
45359index 21e3158..43c6004 100644
45360--- a/drivers/target/target_core_transport.c
45361+++ b/drivers/target/target_core_transport.c
45362@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
45363 * Used to determine when ORDERED commands should go from
45364 * Dormant to Active status.
45365 */
45366- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
45367+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
45368 smp_mb__after_atomic_inc();
45369 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
45370 cmd->se_ordered_id, cmd->sam_task_attr,
45371diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
45372index 33f83fe..d80f8e1 100644
45373--- a/drivers/tty/cyclades.c
45374+++ b/drivers/tty/cyclades.c
45375@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
45376 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
45377 info->port.count);
45378 #endif
45379- info->port.count++;
45380+ atomic_inc(&info->port.count);
45381 #ifdef CY_DEBUG_COUNT
45382 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
45383- current->pid, info->port.count);
45384+ current->pid, atomic_read(&info->port.count));
45385 #endif
45386
45387 /*
45388@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
45389 for (j = 0; j < cy_card[i].nports; j++) {
45390 info = &cy_card[i].ports[j];
45391
45392- if (info->port.count) {
45393+ if (atomic_read(&info->port.count)) {
45394 /* XXX is the ldisc num worth this? */
45395 struct tty_struct *tty;
45396 struct tty_ldisc *ld;
45397diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
45398index eb255e8..f637a57 100644
45399--- a/drivers/tty/hvc/hvc_console.c
45400+++ b/drivers/tty/hvc/hvc_console.c
45401@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
45402
45403 spin_lock_irqsave(&hp->port.lock, flags);
45404 /* Check and then increment for fast path open. */
45405- if (hp->port.count++ > 0) {
45406+ if (atomic_inc_return(&hp->port.count) > 1) {
45407 spin_unlock_irqrestore(&hp->port.lock, flags);
45408 hvc_kick();
45409 return 0;
45410@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
45411
45412 spin_lock_irqsave(&hp->port.lock, flags);
45413
45414- if (--hp->port.count == 0) {
45415+ if (atomic_dec_return(&hp->port.count) == 0) {
45416 spin_unlock_irqrestore(&hp->port.lock, flags);
45417 /* We are done with the tty pointer now. */
45418 tty_port_tty_set(&hp->port, NULL);
45419@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
45420 */
45421 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
45422 } else {
45423- if (hp->port.count < 0)
45424+ if (atomic_read(&hp->port.count) < 0)
45425 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
45426- hp->vtermno, hp->port.count);
45427+ hp->vtermno, atomic_read(&hp->port.count));
45428 spin_unlock_irqrestore(&hp->port.lock, flags);
45429 }
45430 }
45431@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
45432 * open->hangup case this can be called after the final close so prevent
45433 * that from happening for now.
45434 */
45435- if (hp->port.count <= 0) {
45436+ if (atomic_read(&hp->port.count) <= 0) {
45437 spin_unlock_irqrestore(&hp->port.lock, flags);
45438 return;
45439 }
45440
45441- hp->port.count = 0;
45442+ atomic_set(&hp->port.count, 0);
45443 spin_unlock_irqrestore(&hp->port.lock, flags);
45444 tty_port_tty_set(&hp->port, NULL);
45445
45446@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
45447 return -EPIPE;
45448
45449 /* FIXME what's this (unprotected) check for? */
45450- if (hp->port.count <= 0)
45451+ if (atomic_read(&hp->port.count) <= 0)
45452 return -EIO;
45453
45454 spin_lock_irqsave(&hp->lock, flags);
45455diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
45456index 81e939e..95ead10 100644
45457--- a/drivers/tty/hvc/hvcs.c
45458+++ b/drivers/tty/hvc/hvcs.c
45459@@ -83,6 +83,7 @@
45460 #include <asm/hvcserver.h>
45461 #include <asm/uaccess.h>
45462 #include <asm/vio.h>
45463+#include <asm/local.h>
45464
45465 /*
45466 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
45467@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
45468
45469 spin_lock_irqsave(&hvcsd->lock, flags);
45470
45471- if (hvcsd->port.count > 0) {
45472+ if (atomic_read(&hvcsd->port.count) > 0) {
45473 spin_unlock_irqrestore(&hvcsd->lock, flags);
45474 printk(KERN_INFO "HVCS: vterm state unchanged. "
45475 "The hvcs device node is still in use.\n");
45476@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
45477 }
45478 }
45479
45480- hvcsd->port.count = 0;
45481+ atomic_set(&hvcsd->port.count, 0);
45482 hvcsd->port.tty = tty;
45483 tty->driver_data = hvcsd;
45484
45485@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
45486 unsigned long flags;
45487
45488 spin_lock_irqsave(&hvcsd->lock, flags);
45489- hvcsd->port.count++;
45490+ atomic_inc(&hvcsd->port.count);
45491 hvcsd->todo_mask |= HVCS_SCHED_READ;
45492 spin_unlock_irqrestore(&hvcsd->lock, flags);
45493
45494@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
45495 hvcsd = tty->driver_data;
45496
45497 spin_lock_irqsave(&hvcsd->lock, flags);
45498- if (--hvcsd->port.count == 0) {
45499+ if (atomic_dec_and_test(&hvcsd->port.count)) {
45500
45501 vio_disable_interrupts(hvcsd->vdev);
45502
45503@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
45504
45505 free_irq(irq, hvcsd);
45506 return;
45507- } else if (hvcsd->port.count < 0) {
45508+ } else if (atomic_read(&hvcsd->port.count) < 0) {
45509 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
45510 " is missmanaged.\n",
45511- hvcsd->vdev->unit_address, hvcsd->port.count);
45512+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
45513 }
45514
45515 spin_unlock_irqrestore(&hvcsd->lock, flags);
45516@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
45517
45518 spin_lock_irqsave(&hvcsd->lock, flags);
45519 /* Preserve this so that we know how many kref refs to put */
45520- temp_open_count = hvcsd->port.count;
45521+ temp_open_count = atomic_read(&hvcsd->port.count);
45522
45523 /*
45524 * Don't kref put inside the spinlock because the destruction
45525@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
45526 tty->driver_data = NULL;
45527 hvcsd->port.tty = NULL;
45528
45529- hvcsd->port.count = 0;
45530+ atomic_set(&hvcsd->port.count, 0);
45531
45532 /* This will drop any buffered data on the floor which is OK in a hangup
45533 * scenario. */
45534@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
45535 * the middle of a write operation? This is a crummy place to do this
45536 * but we want to keep it all in the spinlock.
45537 */
45538- if (hvcsd->port.count <= 0) {
45539+ if (atomic_read(&hvcsd->port.count) <= 0) {
45540 spin_unlock_irqrestore(&hvcsd->lock, flags);
45541 return -ENODEV;
45542 }
45543@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
45544 {
45545 struct hvcs_struct *hvcsd = tty->driver_data;
45546
45547- if (!hvcsd || hvcsd->port.count <= 0)
45548+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
45549 return 0;
45550
45551 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
45552diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
45553index 8fd72ff..34a0bed 100644
45554--- a/drivers/tty/ipwireless/tty.c
45555+++ b/drivers/tty/ipwireless/tty.c
45556@@ -29,6 +29,7 @@
45557 #include <linux/tty_driver.h>
45558 #include <linux/tty_flip.h>
45559 #include <linux/uaccess.h>
45560+#include <asm/local.h>
45561
45562 #include "tty.h"
45563 #include "network.h"
45564@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
45565 mutex_unlock(&tty->ipw_tty_mutex);
45566 return -ENODEV;
45567 }
45568- if (tty->port.count == 0)
45569+ if (atomic_read(&tty->port.count) == 0)
45570 tty->tx_bytes_queued = 0;
45571
45572- tty->port.count++;
45573+ atomic_inc(&tty->port.count);
45574
45575 tty->port.tty = linux_tty;
45576 linux_tty->driver_data = tty;
45577@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
45578
45579 static void do_ipw_close(struct ipw_tty *tty)
45580 {
45581- tty->port.count--;
45582-
45583- if (tty->port.count == 0) {
45584+ if (atomic_dec_return(&tty->port.count) == 0) {
45585 struct tty_struct *linux_tty = tty->port.tty;
45586
45587 if (linux_tty != NULL) {
45588@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
45589 return;
45590
45591 mutex_lock(&tty->ipw_tty_mutex);
45592- if (tty->port.count == 0) {
45593+ if (atomic_read(&tty->port.count) == 0) {
45594 mutex_unlock(&tty->ipw_tty_mutex);
45595 return;
45596 }
45597@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
45598
45599 mutex_lock(&tty->ipw_tty_mutex);
45600
45601- if (!tty->port.count) {
45602+ if (!atomic_read(&tty->port.count)) {
45603 mutex_unlock(&tty->ipw_tty_mutex);
45604 return;
45605 }
45606@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
45607 return -ENODEV;
45608
45609 mutex_lock(&tty->ipw_tty_mutex);
45610- if (!tty->port.count) {
45611+ if (!atomic_read(&tty->port.count)) {
45612 mutex_unlock(&tty->ipw_tty_mutex);
45613 return -EINVAL;
45614 }
45615@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
45616 if (!tty)
45617 return -ENODEV;
45618
45619- if (!tty->port.count)
45620+ if (!atomic_read(&tty->port.count))
45621 return -EINVAL;
45622
45623 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
45624@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
45625 if (!tty)
45626 return 0;
45627
45628- if (!tty->port.count)
45629+ if (!atomic_read(&tty->port.count))
45630 return 0;
45631
45632 return tty->tx_bytes_queued;
45633@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
45634 if (!tty)
45635 return -ENODEV;
45636
45637- if (!tty->port.count)
45638+ if (!atomic_read(&tty->port.count))
45639 return -EINVAL;
45640
45641 return get_control_lines(tty);
45642@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
45643 if (!tty)
45644 return -ENODEV;
45645
45646- if (!tty->port.count)
45647+ if (!atomic_read(&tty->port.count))
45648 return -EINVAL;
45649
45650 return set_control_lines(tty, set, clear);
45651@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
45652 if (!tty)
45653 return -ENODEV;
45654
45655- if (!tty->port.count)
45656+ if (!atomic_read(&tty->port.count))
45657 return -EINVAL;
45658
45659 /* FIXME: Exactly how is the tty object locked here .. */
45660@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
45661 * are gone */
45662 mutex_lock(&ttyj->ipw_tty_mutex);
45663 }
45664- while (ttyj->port.count)
45665+ while (atomic_read(&ttyj->port.count))
45666 do_ipw_close(ttyj);
45667 ipwireless_disassociate_network_ttys(network,
45668 ttyj->channel_idx);
45669diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
45670index 1deaca4..c8582d4 100644
45671--- a/drivers/tty/moxa.c
45672+++ b/drivers/tty/moxa.c
45673@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
45674 }
45675
45676 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
45677- ch->port.count++;
45678+ atomic_inc(&ch->port.count);
45679 tty->driver_data = ch;
45680 tty_port_tty_set(&ch->port, tty);
45681 mutex_lock(&ch->port.mutex);
45682diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
45683index 6422390..49003ac8 100644
45684--- a/drivers/tty/n_gsm.c
45685+++ b/drivers/tty/n_gsm.c
45686@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
45687 spin_lock_init(&dlci->lock);
45688 mutex_init(&dlci->mutex);
45689 dlci->fifo = &dlci->_fifo;
45690- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
45691+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
45692 kfree(dlci);
45693 return NULL;
45694 }
45695@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
45696 struct gsm_dlci *dlci = tty->driver_data;
45697 struct tty_port *port = &dlci->port;
45698
45699- port->count++;
45700+ atomic_inc(&port->count);
45701 dlci_get(dlci);
45702 dlci_get(dlci->gsm->dlci[0]);
45703 mux_get(dlci->gsm);
45704diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
45705index 6c7fe90..9241dab 100644
45706--- a/drivers/tty/n_tty.c
45707+++ b/drivers/tty/n_tty.c
45708@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
45709 {
45710 *ops = tty_ldisc_N_TTY;
45711 ops->owner = NULL;
45712- ops->refcount = ops->flags = 0;
45713+ atomic_set(&ops->refcount, 0);
45714+ ops->flags = 0;
45715 }
45716 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
45717diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
45718index abfd990..5ab5da9 100644
45719--- a/drivers/tty/pty.c
45720+++ b/drivers/tty/pty.c
45721@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
45722 panic("Couldn't register Unix98 pts driver");
45723
45724 /* Now create the /dev/ptmx special device */
45725+ pax_open_kernel();
45726 tty_default_fops(&ptmx_fops);
45727- ptmx_fops.open = ptmx_open;
45728+ *(void **)&ptmx_fops.open = ptmx_open;
45729+ pax_close_kernel();
45730
45731 cdev_init(&ptmx_cdev, &ptmx_fops);
45732 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
45733diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
45734index 354564e..fe50d9a 100644
45735--- a/drivers/tty/rocket.c
45736+++ b/drivers/tty/rocket.c
45737@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
45738 tty->driver_data = info;
45739 tty_port_tty_set(port, tty);
45740
45741- if (port->count++ == 0) {
45742+ if (atomic_inc_return(&port->count) == 1) {
45743 atomic_inc(&rp_num_ports_open);
45744
45745 #ifdef ROCKET_DEBUG_OPEN
45746@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
45747 #endif
45748 }
45749 #ifdef ROCKET_DEBUG_OPEN
45750- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
45751+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
45752 #endif
45753
45754 /*
45755@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
45756 spin_unlock_irqrestore(&info->port.lock, flags);
45757 return;
45758 }
45759- if (info->port.count)
45760+ if (atomic_read(&info->port.count))
45761 atomic_dec(&rp_num_ports_open);
45762 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
45763 spin_unlock_irqrestore(&info->port.lock, flags);
45764diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
45765index 1002054..dd644a8 100644
45766--- a/drivers/tty/serial/kgdboc.c
45767+++ b/drivers/tty/serial/kgdboc.c
45768@@ -24,8 +24,9 @@
45769 #define MAX_CONFIG_LEN 40
45770
45771 static struct kgdb_io kgdboc_io_ops;
45772+static struct kgdb_io kgdboc_io_ops_console;
45773
45774-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
45775+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
45776 static int configured = -1;
45777
45778 static char config[MAX_CONFIG_LEN];
45779@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
45780 kgdboc_unregister_kbd();
45781 if (configured == 1)
45782 kgdb_unregister_io_module(&kgdboc_io_ops);
45783+ else if (configured == 2)
45784+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
45785 }
45786
45787 static int configure_kgdboc(void)
45788@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
45789 int err;
45790 char *cptr = config;
45791 struct console *cons;
45792+ int is_console = 0;
45793
45794 err = kgdboc_option_setup(config);
45795 if (err || !strlen(config) || isspace(config[0]))
45796 goto noconfig;
45797
45798 err = -ENODEV;
45799- kgdboc_io_ops.is_console = 0;
45800 kgdb_tty_driver = NULL;
45801
45802 kgdboc_use_kms = 0;
45803@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
45804 int idx;
45805 if (cons->device && cons->device(cons, &idx) == p &&
45806 idx == tty_line) {
45807- kgdboc_io_ops.is_console = 1;
45808+ is_console = 1;
45809 break;
45810 }
45811 cons = cons->next;
45812@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
45813 kgdb_tty_line = tty_line;
45814
45815 do_register:
45816- err = kgdb_register_io_module(&kgdboc_io_ops);
45817+ if (is_console) {
45818+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
45819+ configured = 2;
45820+ } else {
45821+ err = kgdb_register_io_module(&kgdboc_io_ops);
45822+ configured = 1;
45823+ }
45824 if (err)
45825 goto noconfig;
45826
45827@@ -205,8 +214,6 @@ do_register:
45828 if (err)
45829 goto nmi_con_failed;
45830
45831- configured = 1;
45832-
45833 return 0;
45834
45835 nmi_con_failed:
45836@@ -223,7 +230,7 @@ noconfig:
45837 static int __init init_kgdboc(void)
45838 {
45839 /* Already configured? */
45840- if (configured == 1)
45841+ if (configured >= 1)
45842 return 0;
45843
45844 return configure_kgdboc();
45845@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
45846 if (config[len - 1] == '\n')
45847 config[len - 1] = '\0';
45848
45849- if (configured == 1)
45850+ if (configured >= 1)
45851 cleanup_kgdboc();
45852
45853 /* Go and configure with the new params. */
45854@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
45855 .post_exception = kgdboc_post_exp_handler,
45856 };
45857
45858+static struct kgdb_io kgdboc_io_ops_console = {
45859+ .name = "kgdboc",
45860+ .read_char = kgdboc_get_char,
45861+ .write_char = kgdboc_put_char,
45862+ .pre_exception = kgdboc_pre_exp_handler,
45863+ .post_exception = kgdboc_post_exp_handler,
45864+ .is_console = 1
45865+};
45866+
45867 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
45868 /* This is only available if kgdboc is a built in for early debugging */
45869 static int __init kgdboc_early_init(char *opt)
45870diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
45871index 0c8a9fa..234a95f 100644
45872--- a/drivers/tty/serial/samsung.c
45873+++ b/drivers/tty/serial/samsung.c
45874@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
45875 }
45876 }
45877
45878+static int s3c64xx_serial_startup(struct uart_port *port);
45879 static int s3c24xx_serial_startup(struct uart_port *port)
45880 {
45881 struct s3c24xx_uart_port *ourport = to_ourport(port);
45882 int ret;
45883
45884+ /* Startup sequence is different for s3c64xx and higher SoC's */
45885+ if (s3c24xx_serial_has_interrupt_mask(port))
45886+ return s3c64xx_serial_startup(port);
45887+
45888 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
45889 port->mapbase, port->membase);
45890
45891@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
45892 /* setup info for port */
45893 port->dev = &platdev->dev;
45894
45895- /* Startup sequence is different for s3c64xx and higher SoC's */
45896- if (s3c24xx_serial_has_interrupt_mask(port))
45897- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
45898-
45899 port->uartclk = 1;
45900
45901 if (cfg->uart_flags & UPF_CONS_FLOW) {
45902diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
45903index f87dbfd..42ad4b1 100644
45904--- a/drivers/tty/serial/serial_core.c
45905+++ b/drivers/tty/serial/serial_core.c
45906@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
45907 uart_flush_buffer(tty);
45908 uart_shutdown(tty, state);
45909 spin_lock_irqsave(&port->lock, flags);
45910- port->count = 0;
45911+ atomic_set(&port->count, 0);
45912 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
45913 spin_unlock_irqrestore(&port->lock, flags);
45914 tty_port_tty_set(port, NULL);
45915@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
45916 goto end;
45917 }
45918
45919- port->count++;
45920+ atomic_inc(&port->count);
45921 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
45922 retval = -ENXIO;
45923 goto err_dec_count;
45924@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
45925 /*
45926 * Make sure the device is in D0 state.
45927 */
45928- if (port->count == 1)
45929+ if (atomic_read(&port->count) == 1)
45930 uart_change_pm(state, UART_PM_STATE_ON);
45931
45932 /*
45933@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
45934 end:
45935 return retval;
45936 err_dec_count:
45937- port->count--;
45938+ atomic_inc(&port->count);
45939 mutex_unlock(&port->mutex);
45940 goto end;
45941 }
45942diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
45943index 8eaf1ab..85c030d 100644
45944--- a/drivers/tty/synclink.c
45945+++ b/drivers/tty/synclink.c
45946@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
45947
45948 if (debug_level >= DEBUG_LEVEL_INFO)
45949 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
45950- __FILE__,__LINE__, info->device_name, info->port.count);
45951+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
45952
45953 if (tty_port_close_start(&info->port, tty, filp) == 0)
45954 goto cleanup;
45955@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
45956 cleanup:
45957 if (debug_level >= DEBUG_LEVEL_INFO)
45958 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
45959- tty->driver->name, info->port.count);
45960+ tty->driver->name, atomic_read(&info->port.count));
45961
45962 } /* end of mgsl_close() */
45963
45964@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
45965
45966 mgsl_flush_buffer(tty);
45967 shutdown(info);
45968-
45969- info->port.count = 0;
45970+
45971+ atomic_set(&info->port.count, 0);
45972 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
45973 info->port.tty = NULL;
45974
45975@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
45976
45977 if (debug_level >= DEBUG_LEVEL_INFO)
45978 printk("%s(%d):block_til_ready before block on %s count=%d\n",
45979- __FILE__,__LINE__, tty->driver->name, port->count );
45980+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
45981
45982 spin_lock_irqsave(&info->irq_spinlock, flags);
45983 if (!tty_hung_up_p(filp)) {
45984 extra_count = true;
45985- port->count--;
45986+ atomic_dec(&port->count);
45987 }
45988 spin_unlock_irqrestore(&info->irq_spinlock, flags);
45989 port->blocked_open++;
45990@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
45991
45992 if (debug_level >= DEBUG_LEVEL_INFO)
45993 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
45994- __FILE__,__LINE__, tty->driver->name, port->count );
45995+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
45996
45997 tty_unlock(tty);
45998 schedule();
45999@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
46000
46001 /* FIXME: Racy on hangup during close wait */
46002 if (extra_count)
46003- port->count++;
46004+ atomic_inc(&port->count);
46005 port->blocked_open--;
46006
46007 if (debug_level >= DEBUG_LEVEL_INFO)
46008 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
46009- __FILE__,__LINE__, tty->driver->name, port->count );
46010+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
46011
46012 if (!retval)
46013 port->flags |= ASYNC_NORMAL_ACTIVE;
46014@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
46015
46016 if (debug_level >= DEBUG_LEVEL_INFO)
46017 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
46018- __FILE__,__LINE__,tty->driver->name, info->port.count);
46019+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
46020
46021 /* If port is closing, signal caller to try again */
46022 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
46023@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
46024 spin_unlock_irqrestore(&info->netlock, flags);
46025 goto cleanup;
46026 }
46027- info->port.count++;
46028+ atomic_inc(&info->port.count);
46029 spin_unlock_irqrestore(&info->netlock, flags);
46030
46031- if (info->port.count == 1) {
46032+ if (atomic_read(&info->port.count) == 1) {
46033 /* 1st open on this device, init hardware */
46034 retval = startup(info);
46035 if (retval < 0)
46036@@ -3446,8 +3446,8 @@ cleanup:
46037 if (retval) {
46038 if (tty->count == 1)
46039 info->port.tty = NULL; /* tty layer will release tty struct */
46040- if(info->port.count)
46041- info->port.count--;
46042+ if (atomic_read(&info->port.count))
46043+ atomic_dec(&info->port.count);
46044 }
46045
46046 return retval;
46047@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
46048 unsigned short new_crctype;
46049
46050 /* return error if TTY interface open */
46051- if (info->port.count)
46052+ if (atomic_read(&info->port.count))
46053 return -EBUSY;
46054
46055 switch (encoding)
46056@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
46057
46058 /* arbitrate between network and tty opens */
46059 spin_lock_irqsave(&info->netlock, flags);
46060- if (info->port.count != 0 || info->netcount != 0) {
46061+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
46062 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
46063 spin_unlock_irqrestore(&info->netlock, flags);
46064 return -EBUSY;
46065@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46066 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
46067
46068 /* return error if TTY interface open */
46069- if (info->port.count)
46070+ if (atomic_read(&info->port.count))
46071 return -EBUSY;
46072
46073 if (cmd != SIOCWANDEV)
46074diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
46075index 1abf946..1ee34fc 100644
46076--- a/drivers/tty/synclink_gt.c
46077+++ b/drivers/tty/synclink_gt.c
46078@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
46079 tty->driver_data = info;
46080 info->port.tty = tty;
46081
46082- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
46083+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
46084
46085 /* If port is closing, signal caller to try again */
46086 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
46087@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
46088 mutex_unlock(&info->port.mutex);
46089 goto cleanup;
46090 }
46091- info->port.count++;
46092+ atomic_inc(&info->port.count);
46093 spin_unlock_irqrestore(&info->netlock, flags);
46094
46095- if (info->port.count == 1) {
46096+ if (atomic_read(&info->port.count) == 1) {
46097 /* 1st open on this device, init hardware */
46098 retval = startup(info);
46099 if (retval < 0) {
46100@@ -715,8 +715,8 @@ cleanup:
46101 if (retval) {
46102 if (tty->count == 1)
46103 info->port.tty = NULL; /* tty layer will release tty struct */
46104- if(info->port.count)
46105- info->port.count--;
46106+ if(atomic_read(&info->port.count))
46107+ atomic_dec(&info->port.count);
46108 }
46109
46110 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
46111@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
46112
46113 if (sanity_check(info, tty->name, "close"))
46114 return;
46115- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
46116+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
46117
46118 if (tty_port_close_start(&info->port, tty, filp) == 0)
46119 goto cleanup;
46120@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
46121 tty_port_close_end(&info->port, tty);
46122 info->port.tty = NULL;
46123 cleanup:
46124- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
46125+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
46126 }
46127
46128 static void hangup(struct tty_struct *tty)
46129@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
46130 shutdown(info);
46131
46132 spin_lock_irqsave(&info->port.lock, flags);
46133- info->port.count = 0;
46134+ atomic_set(&info->port.count, 0);
46135 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
46136 info->port.tty = NULL;
46137 spin_unlock_irqrestore(&info->port.lock, flags);
46138@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
46139 unsigned short new_crctype;
46140
46141 /* return error if TTY interface open */
46142- if (info->port.count)
46143+ if (atomic_read(&info->port.count))
46144 return -EBUSY;
46145
46146 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
46147@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
46148
46149 /* arbitrate between network and tty opens */
46150 spin_lock_irqsave(&info->netlock, flags);
46151- if (info->port.count != 0 || info->netcount != 0) {
46152+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
46153 DBGINFO(("%s hdlc_open busy\n", dev->name));
46154 spin_unlock_irqrestore(&info->netlock, flags);
46155 return -EBUSY;
46156@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46157 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
46158
46159 /* return error if TTY interface open */
46160- if (info->port.count)
46161+ if (atomic_read(&info->port.count))
46162 return -EBUSY;
46163
46164 if (cmd != SIOCWANDEV)
46165@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
46166 if (port == NULL)
46167 continue;
46168 spin_lock(&port->lock);
46169- if ((port->port.count || port->netcount) &&
46170+ if ((atomic_read(&port->port.count) || port->netcount) &&
46171 port->pending_bh && !port->bh_running &&
46172 !port->bh_requested) {
46173 DBGISR(("%s bh queued\n", port->device_name));
46174@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
46175 spin_lock_irqsave(&info->lock, flags);
46176 if (!tty_hung_up_p(filp)) {
46177 extra_count = true;
46178- port->count--;
46179+ atomic_dec(&port->count);
46180 }
46181 spin_unlock_irqrestore(&info->lock, flags);
46182 port->blocked_open++;
46183@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
46184 remove_wait_queue(&port->open_wait, &wait);
46185
46186 if (extra_count)
46187- port->count++;
46188+ atomic_inc(&port->count);
46189 port->blocked_open--;
46190
46191 if (!retval)
46192diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
46193index ff17138..e38b41e 100644
46194--- a/drivers/tty/synclinkmp.c
46195+++ b/drivers/tty/synclinkmp.c
46196@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
46197
46198 if (debug_level >= DEBUG_LEVEL_INFO)
46199 printk("%s(%d):%s open(), old ref count = %d\n",
46200- __FILE__,__LINE__,tty->driver->name, info->port.count);
46201+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
46202
46203 /* If port is closing, signal caller to try again */
46204 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
46205@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
46206 spin_unlock_irqrestore(&info->netlock, flags);
46207 goto cleanup;
46208 }
46209- info->port.count++;
46210+ atomic_inc(&info->port.count);
46211 spin_unlock_irqrestore(&info->netlock, flags);
46212
46213- if (info->port.count == 1) {
46214+ if (atomic_read(&info->port.count) == 1) {
46215 /* 1st open on this device, init hardware */
46216 retval = startup(info);
46217 if (retval < 0)
46218@@ -796,8 +796,8 @@ cleanup:
46219 if (retval) {
46220 if (tty->count == 1)
46221 info->port.tty = NULL; /* tty layer will release tty struct */
46222- if(info->port.count)
46223- info->port.count--;
46224+ if(atomic_read(&info->port.count))
46225+ atomic_dec(&info->port.count);
46226 }
46227
46228 return retval;
46229@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
46230
46231 if (debug_level >= DEBUG_LEVEL_INFO)
46232 printk("%s(%d):%s close() entry, count=%d\n",
46233- __FILE__,__LINE__, info->device_name, info->port.count);
46234+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
46235
46236 if (tty_port_close_start(&info->port, tty, filp) == 0)
46237 goto cleanup;
46238@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
46239 cleanup:
46240 if (debug_level >= DEBUG_LEVEL_INFO)
46241 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
46242- tty->driver->name, info->port.count);
46243+ tty->driver->name, atomic_read(&info->port.count));
46244 }
46245
46246 /* Called by tty_hangup() when a hangup is signaled.
46247@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
46248 shutdown(info);
46249
46250 spin_lock_irqsave(&info->port.lock, flags);
46251- info->port.count = 0;
46252+ atomic_set(&info->port.count, 0);
46253 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
46254 info->port.tty = NULL;
46255 spin_unlock_irqrestore(&info->port.lock, flags);
46256@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
46257 unsigned short new_crctype;
46258
46259 /* return error if TTY interface open */
46260- if (info->port.count)
46261+ if (atomic_read(&info->port.count))
46262 return -EBUSY;
46263
46264 switch (encoding)
46265@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
46266
46267 /* arbitrate between network and tty opens */
46268 spin_lock_irqsave(&info->netlock, flags);
46269- if (info->port.count != 0 || info->netcount != 0) {
46270+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
46271 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
46272 spin_unlock_irqrestore(&info->netlock, flags);
46273 return -EBUSY;
46274@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46275 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
46276
46277 /* return error if TTY interface open */
46278- if (info->port.count)
46279+ if (atomic_read(&info->port.count))
46280 return -EBUSY;
46281
46282 if (cmd != SIOCWANDEV)
46283@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
46284 * do not request bottom half processing if the
46285 * device is not open in a normal mode.
46286 */
46287- if ( port && (port->port.count || port->netcount) &&
46288+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
46289 port->pending_bh && !port->bh_running &&
46290 !port->bh_requested ) {
46291 if ( debug_level >= DEBUG_LEVEL_ISR )
46292@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
46293
46294 if (debug_level >= DEBUG_LEVEL_INFO)
46295 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
46296- __FILE__,__LINE__, tty->driver->name, port->count );
46297+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
46298
46299 spin_lock_irqsave(&info->lock, flags);
46300 if (!tty_hung_up_p(filp)) {
46301 extra_count = true;
46302- port->count--;
46303+ atomic_dec(&port->count);
46304 }
46305 spin_unlock_irqrestore(&info->lock, flags);
46306 port->blocked_open++;
46307@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
46308
46309 if (debug_level >= DEBUG_LEVEL_INFO)
46310 printk("%s(%d):%s block_til_ready() count=%d\n",
46311- __FILE__,__LINE__, tty->driver->name, port->count );
46312+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
46313
46314 tty_unlock(tty);
46315 schedule();
46316@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
46317 remove_wait_queue(&port->open_wait, &wait);
46318
46319 if (extra_count)
46320- port->count++;
46321+ atomic_inc(&port->count);
46322 port->blocked_open--;
46323
46324 if (debug_level >= DEBUG_LEVEL_INFO)
46325 printk("%s(%d):%s block_til_ready() after, count=%d\n",
46326- __FILE__,__LINE__, tty->driver->name, port->count );
46327+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
46328
46329 if (!retval)
46330 port->flags |= ASYNC_NORMAL_ACTIVE;
46331diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
46332index b51c154..17d55d1 100644
46333--- a/drivers/tty/sysrq.c
46334+++ b/drivers/tty/sysrq.c
46335@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
46336 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
46337 size_t count, loff_t *ppos)
46338 {
46339- if (count) {
46340+ if (count && capable(CAP_SYS_ADMIN)) {
46341 char c;
46342
46343 if (get_user(c, buf))
46344diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
46345index 4476682..d77e748 100644
46346--- a/drivers/tty/tty_io.c
46347+++ b/drivers/tty/tty_io.c
46348@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
46349
46350 void tty_default_fops(struct file_operations *fops)
46351 {
46352- *fops = tty_fops;
46353+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
46354 }
46355
46356 /*
46357diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
46358index 1afe192..73d2c20 100644
46359--- a/drivers/tty/tty_ldisc.c
46360+++ b/drivers/tty/tty_ldisc.c
46361@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
46362 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
46363 tty_ldiscs[disc] = new_ldisc;
46364 new_ldisc->num = disc;
46365- new_ldisc->refcount = 0;
46366+ atomic_set(&new_ldisc->refcount, 0);
46367 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
46368
46369 return ret;
46370@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
46371 return -EINVAL;
46372
46373 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
46374- if (tty_ldiscs[disc]->refcount)
46375+ if (atomic_read(&tty_ldiscs[disc]->refcount))
46376 ret = -EBUSY;
46377 else
46378 tty_ldiscs[disc] = NULL;
46379@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
46380 if (ldops) {
46381 ret = ERR_PTR(-EAGAIN);
46382 if (try_module_get(ldops->owner)) {
46383- ldops->refcount++;
46384+ atomic_inc(&ldops->refcount);
46385 ret = ldops;
46386 }
46387 }
46388@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
46389 unsigned long flags;
46390
46391 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
46392- ldops->refcount--;
46393+ atomic_dec(&ldops->refcount);
46394 module_put(ldops->owner);
46395 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
46396 }
46397@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
46398 /* unreleased reader reference(s) will cause this WARN */
46399 WARN_ON(!atomic_dec_and_test(&ld->users));
46400
46401- ld->ops->refcount--;
46402+ atomic_dec(&ld->ops->refcount);
46403 module_put(ld->ops->owner);
46404 kfree(ld);
46405 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
46406diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
46407index f597e88..b7f68ed 100644
46408--- a/drivers/tty/tty_port.c
46409+++ b/drivers/tty/tty_port.c
46410@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
46411 unsigned long flags;
46412
46413 spin_lock_irqsave(&port->lock, flags);
46414- port->count = 0;
46415+ atomic_set(&port->count, 0);
46416 port->flags &= ~ASYNC_NORMAL_ACTIVE;
46417 tty = port->tty;
46418 if (tty)
46419@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
46420 /* The port lock protects the port counts */
46421 spin_lock_irqsave(&port->lock, flags);
46422 if (!tty_hung_up_p(filp))
46423- port->count--;
46424+ atomic_dec(&port->count);
46425 port->blocked_open++;
46426 spin_unlock_irqrestore(&port->lock, flags);
46427
46428@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
46429 we must not mess that up further */
46430 spin_lock_irqsave(&port->lock, flags);
46431 if (!tty_hung_up_p(filp))
46432- port->count++;
46433+ atomic_inc(&port->count);
46434 port->blocked_open--;
46435 if (retval == 0)
46436 port->flags |= ASYNC_NORMAL_ACTIVE;
46437@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
46438 return 0;
46439 }
46440
46441- if (tty->count == 1 && port->count != 1) {
46442+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
46443 printk(KERN_WARNING
46444 "tty_port_close_start: tty->count = 1 port count = %d.\n",
46445- port->count);
46446- port->count = 1;
46447+ atomic_read(&port->count));
46448+ atomic_set(&port->count, 1);
46449 }
46450- if (--port->count < 0) {
46451+ if (atomic_dec_return(&port->count) < 0) {
46452 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
46453- port->count);
46454- port->count = 0;
46455+ atomic_read(&port->count));
46456+ atomic_set(&port->count, 0);
46457 }
46458
46459- if (port->count) {
46460+ if (atomic_read(&port->count)) {
46461 spin_unlock_irqrestore(&port->lock, flags);
46462 if (port->ops->drop)
46463 port->ops->drop(port);
46464@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
46465 {
46466 spin_lock_irq(&port->lock);
46467 if (!tty_hung_up_p(filp))
46468- ++port->count;
46469+ atomic_inc(&port->count);
46470 spin_unlock_irq(&port->lock);
46471 tty_port_tty_set(port, tty);
46472
46473diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
46474index a9af1b9a..1e08e7f 100644
46475--- a/drivers/tty/vt/keyboard.c
46476+++ b/drivers/tty/vt/keyboard.c
46477@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
46478 kbd->kbdmode == VC_OFF) &&
46479 value != KVAL(K_SAK))
46480 return; /* SAK is allowed even in raw mode */
46481+
46482+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46483+ {
46484+ void *func = fn_handler[value];
46485+ if (func == fn_show_state || func == fn_show_ptregs ||
46486+ func == fn_show_mem)
46487+ return;
46488+ }
46489+#endif
46490+
46491 fn_handler[value](vc);
46492 }
46493
46494@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
46495 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
46496 return -EFAULT;
46497
46498- if (!capable(CAP_SYS_TTY_CONFIG))
46499- perm = 0;
46500-
46501 switch (cmd) {
46502 case KDGKBENT:
46503 /* Ensure another thread doesn't free it under us */
46504@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
46505 spin_unlock_irqrestore(&kbd_event_lock, flags);
46506 return put_user(val, &user_kbe->kb_value);
46507 case KDSKBENT:
46508+ if (!capable(CAP_SYS_TTY_CONFIG))
46509+ perm = 0;
46510+
46511 if (!perm)
46512 return -EPERM;
46513 if (!i && v == K_NOSUCHMAP) {
46514@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
46515 int i, j, k;
46516 int ret;
46517
46518- if (!capable(CAP_SYS_TTY_CONFIG))
46519- perm = 0;
46520-
46521 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
46522 if (!kbs) {
46523 ret = -ENOMEM;
46524@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
46525 kfree(kbs);
46526 return ((p && *p) ? -EOVERFLOW : 0);
46527 case KDSKBSENT:
46528+ if (!capable(CAP_SYS_TTY_CONFIG))
46529+ perm = 0;
46530+
46531 if (!perm) {
46532 ret = -EPERM;
46533 goto reterr;
46534diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
46535index b645c47..a55c182 100644
46536--- a/drivers/uio/uio.c
46537+++ b/drivers/uio/uio.c
46538@@ -25,6 +25,7 @@
46539 #include <linux/kobject.h>
46540 #include <linux/cdev.h>
46541 #include <linux/uio_driver.h>
46542+#include <asm/local.h>
46543
46544 #define UIO_MAX_DEVICES (1U << MINORBITS)
46545
46546@@ -32,10 +33,10 @@ struct uio_device {
46547 struct module *owner;
46548 struct device *dev;
46549 int minor;
46550- atomic_t event;
46551+ atomic_unchecked_t event;
46552 struct fasync_struct *async_queue;
46553 wait_queue_head_t wait;
46554- int vma_count;
46555+ local_t vma_count;
46556 struct uio_info *info;
46557 struct kobject *map_dir;
46558 struct kobject *portio_dir;
46559@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
46560 struct device_attribute *attr, char *buf)
46561 {
46562 struct uio_device *idev = dev_get_drvdata(dev);
46563- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
46564+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
46565 }
46566
46567 static struct device_attribute uio_class_attributes[] = {
46568@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
46569 {
46570 struct uio_device *idev = info->uio_dev;
46571
46572- atomic_inc(&idev->event);
46573+ atomic_inc_unchecked(&idev->event);
46574 wake_up_interruptible(&idev->wait);
46575 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
46576 }
46577@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
46578 }
46579
46580 listener->dev = idev;
46581- listener->event_count = atomic_read(&idev->event);
46582+ listener->event_count = atomic_read_unchecked(&idev->event);
46583 filep->private_data = listener;
46584
46585 if (idev->info->open) {
46586@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
46587 return -EIO;
46588
46589 poll_wait(filep, &idev->wait, wait);
46590- if (listener->event_count != atomic_read(&idev->event))
46591+ if (listener->event_count != atomic_read_unchecked(&idev->event))
46592 return POLLIN | POLLRDNORM;
46593 return 0;
46594 }
46595@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
46596 do {
46597 set_current_state(TASK_INTERRUPTIBLE);
46598
46599- event_count = atomic_read(&idev->event);
46600+ event_count = atomic_read_unchecked(&idev->event);
46601 if (event_count != listener->event_count) {
46602 if (copy_to_user(buf, &event_count, count))
46603 retval = -EFAULT;
46604@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
46605 static void uio_vma_open(struct vm_area_struct *vma)
46606 {
46607 struct uio_device *idev = vma->vm_private_data;
46608- idev->vma_count++;
46609+ local_inc(&idev->vma_count);
46610 }
46611
46612 static void uio_vma_close(struct vm_area_struct *vma)
46613 {
46614 struct uio_device *idev = vma->vm_private_data;
46615- idev->vma_count--;
46616+ local_dec(&idev->vma_count);
46617 }
46618
46619 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
46620@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
46621 idev->owner = owner;
46622 idev->info = info;
46623 init_waitqueue_head(&idev->wait);
46624- atomic_set(&idev->event, 0);
46625+ atomic_set_unchecked(&idev->event, 0);
46626
46627 ret = uio_get_minor(idev);
46628 if (ret)
46629diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
46630index 8a7eb77..c00402f 100644
46631--- a/drivers/usb/atm/cxacru.c
46632+++ b/drivers/usb/atm/cxacru.c
46633@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
46634 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
46635 if (ret < 2)
46636 return -EINVAL;
46637- if (index < 0 || index > 0x7f)
46638+ if (index > 0x7f)
46639 return -EINVAL;
46640 pos += tmp;
46641
46642diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
46643index d3527dd..26effa2 100644
46644--- a/drivers/usb/atm/usbatm.c
46645+++ b/drivers/usb/atm/usbatm.c
46646@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
46647 if (printk_ratelimit())
46648 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
46649 __func__, vpi, vci);
46650- atomic_inc(&vcc->stats->rx_err);
46651+ atomic_inc_unchecked(&vcc->stats->rx_err);
46652 return;
46653 }
46654
46655@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
46656 if (length > ATM_MAX_AAL5_PDU) {
46657 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
46658 __func__, length, vcc);
46659- atomic_inc(&vcc->stats->rx_err);
46660+ atomic_inc_unchecked(&vcc->stats->rx_err);
46661 goto out;
46662 }
46663
46664@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
46665 if (sarb->len < pdu_length) {
46666 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
46667 __func__, pdu_length, sarb->len, vcc);
46668- atomic_inc(&vcc->stats->rx_err);
46669+ atomic_inc_unchecked(&vcc->stats->rx_err);
46670 goto out;
46671 }
46672
46673 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
46674 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
46675 __func__, vcc);
46676- atomic_inc(&vcc->stats->rx_err);
46677+ atomic_inc_unchecked(&vcc->stats->rx_err);
46678 goto out;
46679 }
46680
46681@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
46682 if (printk_ratelimit())
46683 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
46684 __func__, length);
46685- atomic_inc(&vcc->stats->rx_drop);
46686+ atomic_inc_unchecked(&vcc->stats->rx_drop);
46687 goto out;
46688 }
46689
46690@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
46691
46692 vcc->push(vcc, skb);
46693
46694- atomic_inc(&vcc->stats->rx);
46695+ atomic_inc_unchecked(&vcc->stats->rx);
46696 out:
46697 skb_trim(sarb, 0);
46698 }
46699@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
46700 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
46701
46702 usbatm_pop(vcc, skb);
46703- atomic_inc(&vcc->stats->tx);
46704+ atomic_inc_unchecked(&vcc->stats->tx);
46705
46706 skb = skb_dequeue(&instance->sndqueue);
46707 }
46708@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
46709 if (!left--)
46710 return sprintf(page,
46711 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
46712- atomic_read(&atm_dev->stats.aal5.tx),
46713- atomic_read(&atm_dev->stats.aal5.tx_err),
46714- atomic_read(&atm_dev->stats.aal5.rx),
46715- atomic_read(&atm_dev->stats.aal5.rx_err),
46716- atomic_read(&atm_dev->stats.aal5.rx_drop));
46717+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
46718+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
46719+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
46720+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
46721+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
46722
46723 if (!left--) {
46724 if (instance->disconnected)
46725diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
46726index 2a3bbdf..91d72cf 100644
46727--- a/drivers/usb/core/devices.c
46728+++ b/drivers/usb/core/devices.c
46729@@ -126,7 +126,7 @@ static const char format_endpt[] =
46730 * time it gets called.
46731 */
46732 static struct device_connect_event {
46733- atomic_t count;
46734+ atomic_unchecked_t count;
46735 wait_queue_head_t wait;
46736 } device_event = {
46737 .count = ATOMIC_INIT(1),
46738@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
46739
46740 void usbfs_conn_disc_event(void)
46741 {
46742- atomic_add(2, &device_event.count);
46743+ atomic_add_unchecked(2, &device_event.count);
46744 wake_up(&device_event.wait);
46745 }
46746
46747@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
46748
46749 poll_wait(file, &device_event.wait, wait);
46750
46751- event_count = atomic_read(&device_event.count);
46752+ event_count = atomic_read_unchecked(&device_event.count);
46753 if (file->f_version != event_count) {
46754 file->f_version = event_count;
46755 return POLLIN | POLLRDNORM;
46756diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
46757index d53547d..6a22d02 100644
46758--- a/drivers/usb/core/hcd.c
46759+++ b/drivers/usb/core/hcd.c
46760@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
46761 */
46762 usb_get_urb(urb);
46763 atomic_inc(&urb->use_count);
46764- atomic_inc(&urb->dev->urbnum);
46765+ atomic_inc_unchecked(&urb->dev->urbnum);
46766 usbmon_urb_submit(&hcd->self, urb);
46767
46768 /* NOTE requirements on root-hub callers (usbfs and the hub
46769@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
46770 urb->hcpriv = NULL;
46771 INIT_LIST_HEAD(&urb->urb_list);
46772 atomic_dec(&urb->use_count);
46773- atomic_dec(&urb->dev->urbnum);
46774+ atomic_dec_unchecked(&urb->dev->urbnum);
46775 if (atomic_read(&urb->reject))
46776 wake_up(&usb_kill_urb_queue);
46777 usb_put_urb(urb);
46778diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
46779index 444d30e..f15c850 100644
46780--- a/drivers/usb/core/message.c
46781+++ b/drivers/usb/core/message.c
46782@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
46783 * method can wait for it to complete. Since you don't have a handle on the
46784 * URB used, you can't cancel the request.
46785 */
46786-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
46787+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
46788 __u8 requesttype, __u16 value, __u16 index, void *data,
46789 __u16 size, int timeout)
46790 {
46791diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
46792index aa38db4..0a08682 100644
46793--- a/drivers/usb/core/sysfs.c
46794+++ b/drivers/usb/core/sysfs.c
46795@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
46796 struct usb_device *udev;
46797
46798 udev = to_usb_device(dev);
46799- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
46800+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
46801 }
46802 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
46803
46804diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
46805index b10da72..43aa0b2 100644
46806--- a/drivers/usb/core/usb.c
46807+++ b/drivers/usb/core/usb.c
46808@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
46809 set_dev_node(&dev->dev, dev_to_node(bus->controller));
46810 dev->state = USB_STATE_ATTACHED;
46811 dev->lpm_disable_count = 1;
46812- atomic_set(&dev->urbnum, 0);
46813+ atomic_set_unchecked(&dev->urbnum, 0);
46814
46815 INIT_LIST_HEAD(&dev->ep0.urb_list);
46816 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
46817diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
46818index 5e29dde..eca992f 100644
46819--- a/drivers/usb/early/ehci-dbgp.c
46820+++ b/drivers/usb/early/ehci-dbgp.c
46821@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
46822
46823 #ifdef CONFIG_KGDB
46824 static struct kgdb_io kgdbdbgp_io_ops;
46825-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
46826+static struct kgdb_io kgdbdbgp_io_ops_console;
46827+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
46828 #else
46829 #define dbgp_kgdb_mode (0)
46830 #endif
46831@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
46832 .write_char = kgdbdbgp_write_char,
46833 };
46834
46835+static struct kgdb_io kgdbdbgp_io_ops_console = {
46836+ .name = "kgdbdbgp",
46837+ .read_char = kgdbdbgp_read_char,
46838+ .write_char = kgdbdbgp_write_char,
46839+ .is_console = 1
46840+};
46841+
46842 static int kgdbdbgp_wait_time;
46843
46844 static int __init kgdbdbgp_parse_config(char *str)
46845@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
46846 ptr++;
46847 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
46848 }
46849- kgdb_register_io_module(&kgdbdbgp_io_ops);
46850- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
46851+ if (early_dbgp_console.index != -1)
46852+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
46853+ else
46854+ kgdb_register_io_module(&kgdbdbgp_io_ops);
46855
46856 return 0;
46857 }
46858diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
46859index b369292..9f3ba40 100644
46860--- a/drivers/usb/gadget/u_serial.c
46861+++ b/drivers/usb/gadget/u_serial.c
46862@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
46863 spin_lock_irq(&port->port_lock);
46864
46865 /* already open? Great. */
46866- if (port->port.count) {
46867+ if (atomic_read(&port->port.count)) {
46868 status = 0;
46869- port->port.count++;
46870+ atomic_inc(&port->port.count);
46871
46872 /* currently opening/closing? wait ... */
46873 } else if (port->openclose) {
46874@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
46875 tty->driver_data = port;
46876 port->port.tty = tty;
46877
46878- port->port.count = 1;
46879+ atomic_set(&port->port.count, 1);
46880 port->openclose = false;
46881
46882 /* if connected, start the I/O stream */
46883@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
46884
46885 spin_lock_irq(&port->port_lock);
46886
46887- if (port->port.count != 1) {
46888- if (port->port.count == 0)
46889+ if (atomic_read(&port->port.count) != 1) {
46890+ if (atomic_read(&port->port.count) == 0)
46891 WARN_ON(1);
46892 else
46893- --port->port.count;
46894+ atomic_dec(&port->port.count);
46895 goto exit;
46896 }
46897
46898@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
46899 * and sleep if necessary
46900 */
46901 port->openclose = true;
46902- port->port.count = 0;
46903+ atomic_set(&port->port.count, 0);
46904
46905 gser = port->port_usb;
46906 if (gser && gser->disconnect)
46907@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
46908 int cond;
46909
46910 spin_lock_irq(&port->port_lock);
46911- cond = (port->port.count == 0) && !port->openclose;
46912+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
46913 spin_unlock_irq(&port->port_lock);
46914 return cond;
46915 }
46916@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
46917 /* if it's already open, start I/O ... and notify the serial
46918 * protocol about open/close status (connect/disconnect).
46919 */
46920- if (port->port.count) {
46921+ if (atomic_read(&port->port.count)) {
46922 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
46923 gs_start_io(port);
46924 if (gser->connect)
46925@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
46926
46927 port->port_usb = NULL;
46928 gser->ioport = NULL;
46929- if (port->port.count > 0 || port->openclose) {
46930+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
46931 wake_up_interruptible(&port->drain_wait);
46932 if (port->port.tty)
46933 tty_hangup(port->port.tty);
46934@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
46935
46936 /* finally, free any unused/unusable I/O buffers */
46937 spin_lock_irqsave(&port->port_lock, flags);
46938- if (port->port.count == 0 && !port->openclose)
46939+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
46940 gs_buf_free(&port->port_write_buf);
46941 gs_free_requests(gser->out, &port->read_pool, NULL);
46942 gs_free_requests(gser->out, &port->read_queue, NULL);
46943diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
46944index 5f3bcd3..bfca43f 100644
46945--- a/drivers/usb/serial/console.c
46946+++ b/drivers/usb/serial/console.c
46947@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
46948
46949 info->port = port;
46950
46951- ++port->port.count;
46952+ atomic_inc(&port->port.count);
46953 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
46954 if (serial->type->set_termios) {
46955 /*
46956@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
46957 }
46958 /* Now that any required fake tty operations are completed restore
46959 * the tty port count */
46960- --port->port.count;
46961+ atomic_dec(&port->port.count);
46962 /* The console is special in terms of closing the device so
46963 * indicate this port is now acting as a system console. */
46964 port->port.console = 1;
46965@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
46966 free_tty:
46967 kfree(tty);
46968 reset_open_count:
46969- port->port.count = 0;
46970+ atomic_set(&port->port.count, 0);
46971 usb_autopm_put_interface(serial->interface);
46972 error_get_interface:
46973 usb_serial_put(serial);
46974diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
46975index 75f70f0..d467e1a 100644
46976--- a/drivers/usb/storage/usb.h
46977+++ b/drivers/usb/storage/usb.h
46978@@ -63,7 +63,7 @@ struct us_unusual_dev {
46979 __u8 useProtocol;
46980 __u8 useTransport;
46981 int (*initFunction)(struct us_data *);
46982-};
46983+} __do_const;
46984
46985
46986 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
46987diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
46988index d6bea3e..60b250e 100644
46989--- a/drivers/usb/wusbcore/wa-hc.h
46990+++ b/drivers/usb/wusbcore/wa-hc.h
46991@@ -192,7 +192,7 @@ struct wahc {
46992 struct list_head xfer_delayed_list;
46993 spinlock_t xfer_list_lock;
46994 struct work_struct xfer_work;
46995- atomic_t xfer_id_count;
46996+ atomic_unchecked_t xfer_id_count;
46997 };
46998
46999
47000@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
47001 INIT_LIST_HEAD(&wa->xfer_delayed_list);
47002 spin_lock_init(&wa->xfer_list_lock);
47003 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
47004- atomic_set(&wa->xfer_id_count, 1);
47005+ atomic_set_unchecked(&wa->xfer_id_count, 1);
47006 }
47007
47008 /**
47009diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
47010index 6ef94bc..1b41265 100644
47011--- a/drivers/usb/wusbcore/wa-xfer.c
47012+++ b/drivers/usb/wusbcore/wa-xfer.c
47013@@ -296,7 +296,7 @@ out:
47014 */
47015 static void wa_xfer_id_init(struct wa_xfer *xfer)
47016 {
47017- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
47018+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
47019 }
47020
47021 /*
47022diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
47023index 5174eba..86e764a 100644
47024--- a/drivers/vhost/vringh.c
47025+++ b/drivers/vhost/vringh.c
47026@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
47027
47028 static inline int putu16_kern(u16 *p, u16 val)
47029 {
47030- ACCESS_ONCE(*p) = val;
47031+ ACCESS_ONCE_RW(*p) = val;
47032 return 0;
47033 }
47034
47035diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
47036index 8c55011..eed4ae1a 100644
47037--- a/drivers/video/aty/aty128fb.c
47038+++ b/drivers/video/aty/aty128fb.c
47039@@ -149,7 +149,7 @@ enum {
47040 };
47041
47042 /* Must match above enum */
47043-static char * const r128_family[] = {
47044+static const char * const r128_family[] = {
47045 "AGP",
47046 "PCI",
47047 "PRO AGP",
47048diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
47049index 4f27fdc..d3537e6 100644
47050--- a/drivers/video/aty/atyfb_base.c
47051+++ b/drivers/video/aty/atyfb_base.c
47052@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
47053 par->accel_flags = var->accel_flags; /* hack */
47054
47055 if (var->accel_flags) {
47056- info->fbops->fb_sync = atyfb_sync;
47057+ pax_open_kernel();
47058+ *(void **)&info->fbops->fb_sync = atyfb_sync;
47059+ pax_close_kernel();
47060 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47061 } else {
47062- info->fbops->fb_sync = NULL;
47063+ pax_open_kernel();
47064+ *(void **)&info->fbops->fb_sync = NULL;
47065+ pax_close_kernel();
47066 info->flags |= FBINFO_HWACCEL_DISABLED;
47067 }
47068
47069diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
47070index 95ec042..e6affdd 100644
47071--- a/drivers/video/aty/mach64_cursor.c
47072+++ b/drivers/video/aty/mach64_cursor.c
47073@@ -7,6 +7,7 @@
47074 #include <linux/string.h>
47075
47076 #include <asm/io.h>
47077+#include <asm/pgtable.h>
47078
47079 #ifdef __sparc__
47080 #include <asm/fbio.h>
47081@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
47082 info->sprite.buf_align = 16; /* and 64 lines tall. */
47083 info->sprite.flags = FB_PIXMAP_IO;
47084
47085- info->fbops->fb_cursor = atyfb_cursor;
47086+ pax_open_kernel();
47087+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
47088+ pax_close_kernel();
47089
47090 return 0;
47091 }
47092diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
47093index c74e7aa..e3c2790 100644
47094--- a/drivers/video/backlight/backlight.c
47095+++ b/drivers/video/backlight/backlight.c
47096@@ -304,7 +304,7 @@ struct backlight_device *backlight_device_register(const char *name,
47097 new_bd->dev.class = backlight_class;
47098 new_bd->dev.parent = parent;
47099 new_bd->dev.release = bl_device_release;
47100- dev_set_name(&new_bd->dev, name);
47101+ dev_set_name(&new_bd->dev, "%s", name);
47102 dev_set_drvdata(&new_bd->dev, devdata);
47103
47104 /* Set default properties */
47105diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
47106index bca6ccc..252107e 100644
47107--- a/drivers/video/backlight/kb3886_bl.c
47108+++ b/drivers/video/backlight/kb3886_bl.c
47109@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
47110 static unsigned long kb3886bl_flags;
47111 #define KB3886BL_SUSPENDED 0x01
47112
47113-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
47114+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
47115 {
47116 .ident = "Sahara Touch-iT",
47117 .matches = {
47118diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
47119index 34fb6bd..3649fd9 100644
47120--- a/drivers/video/backlight/lcd.c
47121+++ b/drivers/video/backlight/lcd.c
47122@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
47123 new_ld->dev.class = lcd_class;
47124 new_ld->dev.parent = parent;
47125 new_ld->dev.release = lcd_device_release;
47126- dev_set_name(&new_ld->dev, name);
47127+ dev_set_name(&new_ld->dev, "%s", name);
47128 dev_set_drvdata(&new_ld->dev, devdata);
47129
47130 rc = device_register(&new_ld->dev);
47131diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
47132index 900aa4e..6d49418 100644
47133--- a/drivers/video/fb_defio.c
47134+++ b/drivers/video/fb_defio.c
47135@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
47136
47137 BUG_ON(!fbdefio);
47138 mutex_init(&fbdefio->lock);
47139- info->fbops->fb_mmap = fb_deferred_io_mmap;
47140+ pax_open_kernel();
47141+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
47142+ pax_close_kernel();
47143 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
47144 INIT_LIST_HEAD(&fbdefio->pagelist);
47145 if (fbdefio->delay == 0) /* set a default of 1 s */
47146@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
47147 page->mapping = NULL;
47148 }
47149
47150- info->fbops->fb_mmap = NULL;
47151+ *(void **)&info->fbops->fb_mmap = NULL;
47152 mutex_destroy(&fbdefio->lock);
47153 }
47154 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
47155diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
47156index 5c3960d..15cf8fc 100644
47157--- a/drivers/video/fbcmap.c
47158+++ b/drivers/video/fbcmap.c
47159@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
47160 rc = -ENODEV;
47161 goto out;
47162 }
47163- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
47164- !info->fbops->fb_setcmap)) {
47165+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
47166 rc = -EINVAL;
47167 goto out1;
47168 }
47169diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
47170index 098bfc6..796841d 100644
47171--- a/drivers/video/fbmem.c
47172+++ b/drivers/video/fbmem.c
47173@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
47174 image->dx += image->width + 8;
47175 }
47176 } else if (rotate == FB_ROTATE_UD) {
47177- for (x = 0; x < num && image->dx >= 0; x++) {
47178+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
47179 info->fbops->fb_imageblit(info, image);
47180 image->dx -= image->width + 8;
47181 }
47182@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
47183 image->dy += image->height + 8;
47184 }
47185 } else if (rotate == FB_ROTATE_CCW) {
47186- for (x = 0; x < num && image->dy >= 0; x++) {
47187+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
47188 info->fbops->fb_imageblit(info, image);
47189 image->dy -= image->height + 8;
47190 }
47191@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
47192 return -EFAULT;
47193 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
47194 return -EINVAL;
47195- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
47196+ if (con2fb.framebuffer >= FB_MAX)
47197 return -EINVAL;
47198 if (!registered_fb[con2fb.framebuffer])
47199 request_module("fb%d", con2fb.framebuffer);
47200diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
47201index 7672d2e..b56437f 100644
47202--- a/drivers/video/i810/i810_accel.c
47203+++ b/drivers/video/i810/i810_accel.c
47204@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
47205 }
47206 }
47207 printk("ringbuffer lockup!!!\n");
47208+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
47209 i810_report_error(mmio);
47210 par->dev_flags |= LOCKUP;
47211 info->pixmap.scan_align = 1;
47212diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
47213index 3c14e43..eafa544 100644
47214--- a/drivers/video/logo/logo_linux_clut224.ppm
47215+++ b/drivers/video/logo/logo_linux_clut224.ppm
47216@@ -1,1604 +1,1123 @@
47217 P3
47218-# Standard 224-color Linux logo
47219 80 80
47220 255
47221- 0 0 0 0 0 0 0 0 0 0 0 0
47222- 0 0 0 0 0 0 0 0 0 0 0 0
47223- 0 0 0 0 0 0 0 0 0 0 0 0
47224- 0 0 0 0 0 0 0 0 0 0 0 0
47225- 0 0 0 0 0 0 0 0 0 0 0 0
47226- 0 0 0 0 0 0 0 0 0 0 0 0
47227- 0 0 0 0 0 0 0 0 0 0 0 0
47228- 0 0 0 0 0 0 0 0 0 0 0 0
47229- 0 0 0 0 0 0 0 0 0 0 0 0
47230- 6 6 6 6 6 6 10 10 10 10 10 10
47231- 10 10 10 6 6 6 6 6 6 6 6 6
47232- 0 0 0 0 0 0 0 0 0 0 0 0
47233- 0 0 0 0 0 0 0 0 0 0 0 0
47234- 0 0 0 0 0 0 0 0 0 0 0 0
47235- 0 0 0 0 0 0 0 0 0 0 0 0
47236- 0 0 0 0 0 0 0 0 0 0 0 0
47237- 0 0 0 0 0 0 0 0 0 0 0 0
47238- 0 0 0 0 0 0 0 0 0 0 0 0
47239- 0 0 0 0 0 0 0 0 0 0 0 0
47240- 0 0 0 0 0 0 0 0 0 0 0 0
47241- 0 0 0 0 0 0 0 0 0 0 0 0
47242- 0 0 0 0 0 0 0 0 0 0 0 0
47243- 0 0 0 0 0 0 0 0 0 0 0 0
47244- 0 0 0 0 0 0 0 0 0 0 0 0
47245- 0 0 0 0 0 0 0 0 0 0 0 0
47246- 0 0 0 0 0 0 0 0 0 0 0 0
47247- 0 0 0 0 0 0 0 0 0 0 0 0
47248- 0 0 0 0 0 0 0 0 0 0 0 0
47249- 0 0 0 6 6 6 10 10 10 14 14 14
47250- 22 22 22 26 26 26 30 30 30 34 34 34
47251- 30 30 30 30 30 30 26 26 26 18 18 18
47252- 14 14 14 10 10 10 6 6 6 0 0 0
47253- 0 0 0 0 0 0 0 0 0 0 0 0
47254- 0 0 0 0 0 0 0 0 0 0 0 0
47255- 0 0 0 0 0 0 0 0 0 0 0 0
47256- 0 0 0 0 0 0 0 0 0 0 0 0
47257- 0 0 0 0 0 0 0 0 0 0 0 0
47258- 0 0 0 0 0 0 0 0 0 0 0 0
47259- 0 0 0 0 0 0 0 0 0 0 0 0
47260- 0 0 0 0 0 0 0 0 0 0 0 0
47261- 0 0 0 0 0 0 0 0 0 0 0 0
47262- 0 0 0 0 0 1 0 0 1 0 0 0
47263- 0 0 0 0 0 0 0 0 0 0 0 0
47264- 0 0 0 0 0 0 0 0 0 0 0 0
47265- 0 0 0 0 0 0 0 0 0 0 0 0
47266- 0 0 0 0 0 0 0 0 0 0 0 0
47267- 0 0 0 0 0 0 0 0 0 0 0 0
47268- 0 0 0 0 0 0 0 0 0 0 0 0
47269- 6 6 6 14 14 14 26 26 26 42 42 42
47270- 54 54 54 66 66 66 78 78 78 78 78 78
47271- 78 78 78 74 74 74 66 66 66 54 54 54
47272- 42 42 42 26 26 26 18 18 18 10 10 10
47273- 6 6 6 0 0 0 0 0 0 0 0 0
47274- 0 0 0 0 0 0 0 0 0 0 0 0
47275- 0 0 0 0 0 0 0 0 0 0 0 0
47276- 0 0 0 0 0 0 0 0 0 0 0 0
47277- 0 0 0 0 0 0 0 0 0 0 0 0
47278- 0 0 0 0 0 0 0 0 0 0 0 0
47279- 0 0 0 0 0 0 0 0 0 0 0 0
47280- 0 0 0 0 0 0 0 0 0 0 0 0
47281- 0 0 0 0 0 0 0 0 0 0 0 0
47282- 0 0 1 0 0 0 0 0 0 0 0 0
47283- 0 0 0 0 0 0 0 0 0 0 0 0
47284- 0 0 0 0 0 0 0 0 0 0 0 0
47285- 0 0 0 0 0 0 0 0 0 0 0 0
47286- 0 0 0 0 0 0 0 0 0 0 0 0
47287- 0 0 0 0 0 0 0 0 0 0 0 0
47288- 0 0 0 0 0 0 0 0 0 10 10 10
47289- 22 22 22 42 42 42 66 66 66 86 86 86
47290- 66 66 66 38 38 38 38 38 38 22 22 22
47291- 26 26 26 34 34 34 54 54 54 66 66 66
47292- 86 86 86 70 70 70 46 46 46 26 26 26
47293- 14 14 14 6 6 6 0 0 0 0 0 0
47294- 0 0 0 0 0 0 0 0 0 0 0 0
47295- 0 0 0 0 0 0 0 0 0 0 0 0
47296- 0 0 0 0 0 0 0 0 0 0 0 0
47297- 0 0 0 0 0 0 0 0 0 0 0 0
47298- 0 0 0 0 0 0 0 0 0 0 0 0
47299- 0 0 0 0 0 0 0 0 0 0 0 0
47300- 0 0 0 0 0 0 0 0 0 0 0 0
47301- 0 0 0 0 0 0 0 0 0 0 0 0
47302- 0 0 1 0 0 1 0 0 1 0 0 0
47303- 0 0 0 0 0 0 0 0 0 0 0 0
47304- 0 0 0 0 0 0 0 0 0 0 0 0
47305- 0 0 0 0 0 0 0 0 0 0 0 0
47306- 0 0 0 0 0 0 0 0 0 0 0 0
47307- 0 0 0 0 0 0 0 0 0 0 0 0
47308- 0 0 0 0 0 0 10 10 10 26 26 26
47309- 50 50 50 82 82 82 58 58 58 6 6 6
47310- 2 2 6 2 2 6 2 2 6 2 2 6
47311- 2 2 6 2 2 6 2 2 6 2 2 6
47312- 6 6 6 54 54 54 86 86 86 66 66 66
47313- 38 38 38 18 18 18 6 6 6 0 0 0
47314- 0 0 0 0 0 0 0 0 0 0 0 0
47315- 0 0 0 0 0 0 0 0 0 0 0 0
47316- 0 0 0 0 0 0 0 0 0 0 0 0
47317- 0 0 0 0 0 0 0 0 0 0 0 0
47318- 0 0 0 0 0 0 0 0 0 0 0 0
47319- 0 0 0 0 0 0 0 0 0 0 0 0
47320- 0 0 0 0 0 0 0 0 0 0 0 0
47321- 0 0 0 0 0 0 0 0 0 0 0 0
47322- 0 0 0 0 0 0 0 0 0 0 0 0
47323- 0 0 0 0 0 0 0 0 0 0 0 0
47324- 0 0 0 0 0 0 0 0 0 0 0 0
47325- 0 0 0 0 0 0 0 0 0 0 0 0
47326- 0 0 0 0 0 0 0 0 0 0 0 0
47327- 0 0 0 0 0 0 0 0 0 0 0 0
47328- 0 0 0 6 6 6 22 22 22 50 50 50
47329- 78 78 78 34 34 34 2 2 6 2 2 6
47330- 2 2 6 2 2 6 2 2 6 2 2 6
47331- 2 2 6 2 2 6 2 2 6 2 2 6
47332- 2 2 6 2 2 6 6 6 6 70 70 70
47333- 78 78 78 46 46 46 22 22 22 6 6 6
47334- 0 0 0 0 0 0 0 0 0 0 0 0
47335- 0 0 0 0 0 0 0 0 0 0 0 0
47336- 0 0 0 0 0 0 0 0 0 0 0 0
47337- 0 0 0 0 0 0 0 0 0 0 0 0
47338- 0 0 0 0 0 0 0 0 0 0 0 0
47339- 0 0 0 0 0 0 0 0 0 0 0 0
47340- 0 0 0 0 0 0 0 0 0 0 0 0
47341- 0 0 0 0 0 0 0 0 0 0 0 0
47342- 0 0 1 0 0 1 0 0 1 0 0 0
47343- 0 0 0 0 0 0 0 0 0 0 0 0
47344- 0 0 0 0 0 0 0 0 0 0 0 0
47345- 0 0 0 0 0 0 0 0 0 0 0 0
47346- 0 0 0 0 0 0 0 0 0 0 0 0
47347- 0 0 0 0 0 0 0 0 0 0 0 0
47348- 6 6 6 18 18 18 42 42 42 82 82 82
47349- 26 26 26 2 2 6 2 2 6 2 2 6
47350- 2 2 6 2 2 6 2 2 6 2 2 6
47351- 2 2 6 2 2 6 2 2 6 14 14 14
47352- 46 46 46 34 34 34 6 6 6 2 2 6
47353- 42 42 42 78 78 78 42 42 42 18 18 18
47354- 6 6 6 0 0 0 0 0 0 0 0 0
47355- 0 0 0 0 0 0 0 0 0 0 0 0
47356- 0 0 0 0 0 0 0 0 0 0 0 0
47357- 0 0 0 0 0 0 0 0 0 0 0 0
47358- 0 0 0 0 0 0 0 0 0 0 0 0
47359- 0 0 0 0 0 0 0 0 0 0 0 0
47360- 0 0 0 0 0 0 0 0 0 0 0 0
47361- 0 0 0 0 0 0 0 0 0 0 0 0
47362- 0 0 1 0 0 0 0 0 1 0 0 0
47363- 0 0 0 0 0 0 0 0 0 0 0 0
47364- 0 0 0 0 0 0 0 0 0 0 0 0
47365- 0 0 0 0 0 0 0 0 0 0 0 0
47366- 0 0 0 0 0 0 0 0 0 0 0 0
47367- 0 0 0 0 0 0 0 0 0 0 0 0
47368- 10 10 10 30 30 30 66 66 66 58 58 58
47369- 2 2 6 2 2 6 2 2 6 2 2 6
47370- 2 2 6 2 2 6 2 2 6 2 2 6
47371- 2 2 6 2 2 6 2 2 6 26 26 26
47372- 86 86 86 101 101 101 46 46 46 10 10 10
47373- 2 2 6 58 58 58 70 70 70 34 34 34
47374- 10 10 10 0 0 0 0 0 0 0 0 0
47375- 0 0 0 0 0 0 0 0 0 0 0 0
47376- 0 0 0 0 0 0 0 0 0 0 0 0
47377- 0 0 0 0 0 0 0 0 0 0 0 0
47378- 0 0 0 0 0 0 0 0 0 0 0 0
47379- 0 0 0 0 0 0 0 0 0 0 0 0
47380- 0 0 0 0 0 0 0 0 0 0 0 0
47381- 0 0 0 0 0 0 0 0 0 0 0 0
47382- 0 0 1 0 0 1 0 0 1 0 0 0
47383- 0 0 0 0 0 0 0 0 0 0 0 0
47384- 0 0 0 0 0 0 0 0 0 0 0 0
47385- 0 0 0 0 0 0 0 0 0 0 0 0
47386- 0 0 0 0 0 0 0 0 0 0 0 0
47387- 0 0 0 0 0 0 0 0 0 0 0 0
47388- 14 14 14 42 42 42 86 86 86 10 10 10
47389- 2 2 6 2 2 6 2 2 6 2 2 6
47390- 2 2 6 2 2 6 2 2 6 2 2 6
47391- 2 2 6 2 2 6 2 2 6 30 30 30
47392- 94 94 94 94 94 94 58 58 58 26 26 26
47393- 2 2 6 6 6 6 78 78 78 54 54 54
47394- 22 22 22 6 6 6 0 0 0 0 0 0
47395- 0 0 0 0 0 0 0 0 0 0 0 0
47396- 0 0 0 0 0 0 0 0 0 0 0 0
47397- 0 0 0 0 0 0 0 0 0 0 0 0
47398- 0 0 0 0 0 0 0 0 0 0 0 0
47399- 0 0 0 0 0 0 0 0 0 0 0 0
47400- 0 0 0 0 0 0 0 0 0 0 0 0
47401- 0 0 0 0 0 0 0 0 0 0 0 0
47402- 0 0 0 0 0 0 0 0 0 0 0 0
47403- 0 0 0 0 0 0 0 0 0 0 0 0
47404- 0 0 0 0 0 0 0 0 0 0 0 0
47405- 0 0 0 0 0 0 0 0 0 0 0 0
47406- 0 0 0 0 0 0 0 0 0 0 0 0
47407- 0 0 0 0 0 0 0 0 0 6 6 6
47408- 22 22 22 62 62 62 62 62 62 2 2 6
47409- 2 2 6 2 2 6 2 2 6 2 2 6
47410- 2 2 6 2 2 6 2 2 6 2 2 6
47411- 2 2 6 2 2 6 2 2 6 26 26 26
47412- 54 54 54 38 38 38 18 18 18 10 10 10
47413- 2 2 6 2 2 6 34 34 34 82 82 82
47414- 38 38 38 14 14 14 0 0 0 0 0 0
47415- 0 0 0 0 0 0 0 0 0 0 0 0
47416- 0 0 0 0 0 0 0 0 0 0 0 0
47417- 0 0 0 0 0 0 0 0 0 0 0 0
47418- 0 0 0 0 0 0 0 0 0 0 0 0
47419- 0 0 0 0 0 0 0 0 0 0 0 0
47420- 0 0 0 0 0 0 0 0 0 0 0 0
47421- 0 0 0 0 0 0 0 0 0 0 0 0
47422- 0 0 0 0 0 1 0 0 1 0 0 0
47423- 0 0 0 0 0 0 0 0 0 0 0 0
47424- 0 0 0 0 0 0 0 0 0 0 0 0
47425- 0 0 0 0 0 0 0 0 0 0 0 0
47426- 0 0 0 0 0 0 0 0 0 0 0 0
47427- 0 0 0 0 0 0 0 0 0 6 6 6
47428- 30 30 30 78 78 78 30 30 30 2 2 6
47429- 2 2 6 2 2 6 2 2 6 2 2 6
47430- 2 2 6 2 2 6 2 2 6 2 2 6
47431- 2 2 6 2 2 6 2 2 6 10 10 10
47432- 10 10 10 2 2 6 2 2 6 2 2 6
47433- 2 2 6 2 2 6 2 2 6 78 78 78
47434- 50 50 50 18 18 18 6 6 6 0 0 0
47435- 0 0 0 0 0 0 0 0 0 0 0 0
47436- 0 0 0 0 0 0 0 0 0 0 0 0
47437- 0 0 0 0 0 0 0 0 0 0 0 0
47438- 0 0 0 0 0 0 0 0 0 0 0 0
47439- 0 0 0 0 0 0 0 0 0 0 0 0
47440- 0 0 0 0 0 0 0 0 0 0 0 0
47441- 0 0 0 0 0 0 0 0 0 0 0 0
47442- 0 0 1 0 0 0 0 0 0 0 0 0
47443- 0 0 0 0 0 0 0 0 0 0 0 0
47444- 0 0 0 0 0 0 0 0 0 0 0 0
47445- 0 0 0 0 0 0 0 0 0 0 0 0
47446- 0 0 0 0 0 0 0 0 0 0 0 0
47447- 0 0 0 0 0 0 0 0 0 10 10 10
47448- 38 38 38 86 86 86 14 14 14 2 2 6
47449- 2 2 6 2 2 6 2 2 6 2 2 6
47450- 2 2 6 2 2 6 2 2 6 2 2 6
47451- 2 2 6 2 2 6 2 2 6 2 2 6
47452- 2 2 6 2 2 6 2 2 6 2 2 6
47453- 2 2 6 2 2 6 2 2 6 54 54 54
47454- 66 66 66 26 26 26 6 6 6 0 0 0
47455- 0 0 0 0 0 0 0 0 0 0 0 0
47456- 0 0 0 0 0 0 0 0 0 0 0 0
47457- 0 0 0 0 0 0 0 0 0 0 0 0
47458- 0 0 0 0 0 0 0 0 0 0 0 0
47459- 0 0 0 0 0 0 0 0 0 0 0 0
47460- 0 0 0 0 0 0 0 0 0 0 0 0
47461- 0 0 0 0 0 0 0 0 0 0 0 0
47462- 0 0 0 0 0 1 0 0 1 0 0 0
47463- 0 0 0 0 0 0 0 0 0 0 0 0
47464- 0 0 0 0 0 0 0 0 0 0 0 0
47465- 0 0 0 0 0 0 0 0 0 0 0 0
47466- 0 0 0 0 0 0 0 0 0 0 0 0
47467- 0 0 0 0 0 0 0 0 0 14 14 14
47468- 42 42 42 82 82 82 2 2 6 2 2 6
47469- 2 2 6 6 6 6 10 10 10 2 2 6
47470- 2 2 6 2 2 6 2 2 6 2 2 6
47471- 2 2 6 2 2 6 2 2 6 6 6 6
47472- 14 14 14 10 10 10 2 2 6 2 2 6
47473- 2 2 6 2 2 6 2 2 6 18 18 18
47474- 82 82 82 34 34 34 10 10 10 0 0 0
47475- 0 0 0 0 0 0 0 0 0 0 0 0
47476- 0 0 0 0 0 0 0 0 0 0 0 0
47477- 0 0 0 0 0 0 0 0 0 0 0 0
47478- 0 0 0 0 0 0 0 0 0 0 0 0
47479- 0 0 0 0 0 0 0 0 0 0 0 0
47480- 0 0 0 0 0 0 0 0 0 0 0 0
47481- 0 0 0 0 0 0 0 0 0 0 0 0
47482- 0 0 1 0 0 0 0 0 0 0 0 0
47483- 0 0 0 0 0 0 0 0 0 0 0 0
47484- 0 0 0 0 0 0 0 0 0 0 0 0
47485- 0 0 0 0 0 0 0 0 0 0 0 0
47486- 0 0 0 0 0 0 0 0 0 0 0 0
47487- 0 0 0 0 0 0 0 0 0 14 14 14
47488- 46 46 46 86 86 86 2 2 6 2 2 6
47489- 6 6 6 6 6 6 22 22 22 34 34 34
47490- 6 6 6 2 2 6 2 2 6 2 2 6
47491- 2 2 6 2 2 6 18 18 18 34 34 34
47492- 10 10 10 50 50 50 22 22 22 2 2 6
47493- 2 2 6 2 2 6 2 2 6 10 10 10
47494- 86 86 86 42 42 42 14 14 14 0 0 0
47495- 0 0 0 0 0 0 0 0 0 0 0 0
47496- 0 0 0 0 0 0 0 0 0 0 0 0
47497- 0 0 0 0 0 0 0 0 0 0 0 0
47498- 0 0 0 0 0 0 0 0 0 0 0 0
47499- 0 0 0 0 0 0 0 0 0 0 0 0
47500- 0 0 0 0 0 0 0 0 0 0 0 0
47501- 0 0 0 0 0 0 0 0 0 0 0 0
47502- 0 0 1 0 0 1 0 0 1 0 0 0
47503- 0 0 0 0 0 0 0 0 0 0 0 0
47504- 0 0 0 0 0 0 0 0 0 0 0 0
47505- 0 0 0 0 0 0 0 0 0 0 0 0
47506- 0 0 0 0 0 0 0 0 0 0 0 0
47507- 0 0 0 0 0 0 0 0 0 14 14 14
47508- 46 46 46 86 86 86 2 2 6 2 2 6
47509- 38 38 38 116 116 116 94 94 94 22 22 22
47510- 22 22 22 2 2 6 2 2 6 2 2 6
47511- 14 14 14 86 86 86 138 138 138 162 162 162
47512-154 154 154 38 38 38 26 26 26 6 6 6
47513- 2 2 6 2 2 6 2 2 6 2 2 6
47514- 86 86 86 46 46 46 14 14 14 0 0 0
47515- 0 0 0 0 0 0 0 0 0 0 0 0
47516- 0 0 0 0 0 0 0 0 0 0 0 0
47517- 0 0 0 0 0 0 0 0 0 0 0 0
47518- 0 0 0 0 0 0 0 0 0 0 0 0
47519- 0 0 0 0 0 0 0 0 0 0 0 0
47520- 0 0 0 0 0 0 0 0 0 0 0 0
47521- 0 0 0 0 0 0 0 0 0 0 0 0
47522- 0 0 0 0 0 0 0 0 0 0 0 0
47523- 0 0 0 0 0 0 0 0 0 0 0 0
47524- 0 0 0 0 0 0 0 0 0 0 0 0
47525- 0 0 0 0 0 0 0 0 0 0 0 0
47526- 0 0 0 0 0 0 0 0 0 0 0 0
47527- 0 0 0 0 0 0 0 0 0 14 14 14
47528- 46 46 46 86 86 86 2 2 6 14 14 14
47529-134 134 134 198 198 198 195 195 195 116 116 116
47530- 10 10 10 2 2 6 2 2 6 6 6 6
47531-101 98 89 187 187 187 210 210 210 218 218 218
47532-214 214 214 134 134 134 14 14 14 6 6 6
47533- 2 2 6 2 2 6 2 2 6 2 2 6
47534- 86 86 86 50 50 50 18 18 18 6 6 6
47535- 0 0 0 0 0 0 0 0 0 0 0 0
47536- 0 0 0 0 0 0 0 0 0 0 0 0
47537- 0 0 0 0 0 0 0 0 0 0 0 0
47538- 0 0 0 0 0 0 0 0 0 0 0 0
47539- 0 0 0 0 0 0 0 0 0 0 0 0
47540- 0 0 0 0 0 0 0 0 0 0 0 0
47541- 0 0 0 0 0 0 0 0 1 0 0 0
47542- 0 0 1 0 0 1 0 0 1 0 0 0
47543- 0 0 0 0 0 0 0 0 0 0 0 0
47544- 0 0 0 0 0 0 0 0 0 0 0 0
47545- 0 0 0 0 0 0 0 0 0 0 0 0
47546- 0 0 0 0 0 0 0 0 0 0 0 0
47547- 0 0 0 0 0 0 0 0 0 14 14 14
47548- 46 46 46 86 86 86 2 2 6 54 54 54
47549-218 218 218 195 195 195 226 226 226 246 246 246
47550- 58 58 58 2 2 6 2 2 6 30 30 30
47551-210 210 210 253 253 253 174 174 174 123 123 123
47552-221 221 221 234 234 234 74 74 74 2 2 6
47553- 2 2 6 2 2 6 2 2 6 2 2 6
47554- 70 70 70 58 58 58 22 22 22 6 6 6
47555- 0 0 0 0 0 0 0 0 0 0 0 0
47556- 0 0 0 0 0 0 0 0 0 0 0 0
47557- 0 0 0 0 0 0 0 0 0 0 0 0
47558- 0 0 0 0 0 0 0 0 0 0 0 0
47559- 0 0 0 0 0 0 0 0 0 0 0 0
47560- 0 0 0 0 0 0 0 0 0 0 0 0
47561- 0 0 0 0 0 0 0 0 0 0 0 0
47562- 0 0 0 0 0 0 0 0 0 0 0 0
47563- 0 0 0 0 0 0 0 0 0 0 0 0
47564- 0 0 0 0 0 0 0 0 0 0 0 0
47565- 0 0 0 0 0 0 0 0 0 0 0 0
47566- 0 0 0 0 0 0 0 0 0 0 0 0
47567- 0 0 0 0 0 0 0 0 0 14 14 14
47568- 46 46 46 82 82 82 2 2 6 106 106 106
47569-170 170 170 26 26 26 86 86 86 226 226 226
47570-123 123 123 10 10 10 14 14 14 46 46 46
47571-231 231 231 190 190 190 6 6 6 70 70 70
47572- 90 90 90 238 238 238 158 158 158 2 2 6
47573- 2 2 6 2 2 6 2 2 6 2 2 6
47574- 70 70 70 58 58 58 22 22 22 6 6 6
47575- 0 0 0 0 0 0 0 0 0 0 0 0
47576- 0 0 0 0 0 0 0 0 0 0 0 0
47577- 0 0 0 0 0 0 0 0 0 0 0 0
47578- 0 0 0 0 0 0 0 0 0 0 0 0
47579- 0 0 0 0 0 0 0 0 0 0 0 0
47580- 0 0 0 0 0 0 0 0 0 0 0 0
47581- 0 0 0 0 0 0 0 0 1 0 0 0
47582- 0 0 1 0 0 1 0 0 1 0 0 0
47583- 0 0 0 0 0 0 0 0 0 0 0 0
47584- 0 0 0 0 0 0 0 0 0 0 0 0
47585- 0 0 0 0 0 0 0 0 0 0 0 0
47586- 0 0 0 0 0 0 0 0 0 0 0 0
47587- 0 0 0 0 0 0 0 0 0 14 14 14
47588- 42 42 42 86 86 86 6 6 6 116 116 116
47589-106 106 106 6 6 6 70 70 70 149 149 149
47590-128 128 128 18 18 18 38 38 38 54 54 54
47591-221 221 221 106 106 106 2 2 6 14 14 14
47592- 46 46 46 190 190 190 198 198 198 2 2 6
47593- 2 2 6 2 2 6 2 2 6 2 2 6
47594- 74 74 74 62 62 62 22 22 22 6 6 6
47595- 0 0 0 0 0 0 0 0 0 0 0 0
47596- 0 0 0 0 0 0 0 0 0 0 0 0
47597- 0 0 0 0 0 0 0 0 0 0 0 0
47598- 0 0 0 0 0 0 0 0 0 0 0 0
47599- 0 0 0 0 0 0 0 0 0 0 0 0
47600- 0 0 0 0 0 0 0 0 0 0 0 0
47601- 0 0 0 0 0 0 0 0 1 0 0 0
47602- 0 0 1 0 0 0 0 0 1 0 0 0
47603- 0 0 0 0 0 0 0 0 0 0 0 0
47604- 0 0 0 0 0 0 0 0 0 0 0 0
47605- 0 0 0 0 0 0 0 0 0 0 0 0
47606- 0 0 0 0 0 0 0 0 0 0 0 0
47607- 0 0 0 0 0 0 0 0 0 14 14 14
47608- 42 42 42 94 94 94 14 14 14 101 101 101
47609-128 128 128 2 2 6 18 18 18 116 116 116
47610-118 98 46 121 92 8 121 92 8 98 78 10
47611-162 162 162 106 106 106 2 2 6 2 2 6
47612- 2 2 6 195 195 195 195 195 195 6 6 6
47613- 2 2 6 2 2 6 2 2 6 2 2 6
47614- 74 74 74 62 62 62 22 22 22 6 6 6
47615- 0 0 0 0 0 0 0 0 0 0 0 0
47616- 0 0 0 0 0 0 0 0 0 0 0 0
47617- 0 0 0 0 0 0 0 0 0 0 0 0
47618- 0 0 0 0 0 0 0 0 0 0 0 0
47619- 0 0 0 0 0 0 0 0 0 0 0 0
47620- 0 0 0 0 0 0 0 0 0 0 0 0
47621- 0 0 0 0 0 0 0 0 1 0 0 1
47622- 0 0 1 0 0 0 0 0 1 0 0 0
47623- 0 0 0 0 0 0 0 0 0 0 0 0
47624- 0 0 0 0 0 0 0 0 0 0 0 0
47625- 0 0 0 0 0 0 0 0 0 0 0 0
47626- 0 0 0 0 0 0 0 0 0 0 0 0
47627- 0 0 0 0 0 0 0 0 0 10 10 10
47628- 38 38 38 90 90 90 14 14 14 58 58 58
47629-210 210 210 26 26 26 54 38 6 154 114 10
47630-226 170 11 236 186 11 225 175 15 184 144 12
47631-215 174 15 175 146 61 37 26 9 2 2 6
47632- 70 70 70 246 246 246 138 138 138 2 2 6
47633- 2 2 6 2 2 6 2 2 6 2 2 6
47634- 70 70 70 66 66 66 26 26 26 6 6 6
47635- 0 0 0 0 0 0 0 0 0 0 0 0
47636- 0 0 0 0 0 0 0 0 0 0 0 0
47637- 0 0 0 0 0 0 0 0 0 0 0 0
47638- 0 0 0 0 0 0 0 0 0 0 0 0
47639- 0 0 0 0 0 0 0 0 0 0 0 0
47640- 0 0 0 0 0 0 0 0 0 0 0 0
47641- 0 0 0 0 0 0 0 0 0 0 0 0
47642- 0 0 0 0 0 0 0 0 0 0 0 0
47643- 0 0 0 0 0 0 0 0 0 0 0 0
47644- 0 0 0 0 0 0 0 0 0 0 0 0
47645- 0 0 0 0 0 0 0 0 0 0 0 0
47646- 0 0 0 0 0 0 0 0 0 0 0 0
47647- 0 0 0 0 0 0 0 0 0 10 10 10
47648- 38 38 38 86 86 86 14 14 14 10 10 10
47649-195 195 195 188 164 115 192 133 9 225 175 15
47650-239 182 13 234 190 10 232 195 16 232 200 30
47651-245 207 45 241 208 19 232 195 16 184 144 12
47652-218 194 134 211 206 186 42 42 42 2 2 6
47653- 2 2 6 2 2 6 2 2 6 2 2 6
47654- 50 50 50 74 74 74 30 30 30 6 6 6
47655- 0 0 0 0 0 0 0 0 0 0 0 0
47656- 0 0 0 0 0 0 0 0 0 0 0 0
47657- 0 0 0 0 0 0 0 0 0 0 0 0
47658- 0 0 0 0 0 0 0 0 0 0 0 0
47659- 0 0 0 0 0 0 0 0 0 0 0 0
47660- 0 0 0 0 0 0 0 0 0 0 0 0
47661- 0 0 0 0 0 0 0 0 0 0 0 0
47662- 0 0 0 0 0 0 0 0 0 0 0 0
47663- 0 0 0 0 0 0 0 0 0 0 0 0
47664- 0 0 0 0 0 0 0 0 0 0 0 0
47665- 0 0 0 0 0 0 0 0 0 0 0 0
47666- 0 0 0 0 0 0 0 0 0 0 0 0
47667- 0 0 0 0 0 0 0 0 0 10 10 10
47668- 34 34 34 86 86 86 14 14 14 2 2 6
47669-121 87 25 192 133 9 219 162 10 239 182 13
47670-236 186 11 232 195 16 241 208 19 244 214 54
47671-246 218 60 246 218 38 246 215 20 241 208 19
47672-241 208 19 226 184 13 121 87 25 2 2 6
47673- 2 2 6 2 2 6 2 2 6 2 2 6
47674- 50 50 50 82 82 82 34 34 34 10 10 10
47675- 0 0 0 0 0 0 0 0 0 0 0 0
47676- 0 0 0 0 0 0 0 0 0 0 0 0
47677- 0 0 0 0 0 0 0 0 0 0 0 0
47678- 0 0 0 0 0 0 0 0 0 0 0 0
47679- 0 0 0 0 0 0 0 0 0 0 0 0
47680- 0 0 0 0 0 0 0 0 0 0 0 0
47681- 0 0 0 0 0 0 0 0 0 0 0 0
47682- 0 0 0 0 0 0 0 0 0 0 0 0
47683- 0 0 0 0 0 0 0 0 0 0 0 0
47684- 0 0 0 0 0 0 0 0 0 0 0 0
47685- 0 0 0 0 0 0 0 0 0 0 0 0
47686- 0 0 0 0 0 0 0 0 0 0 0 0
47687- 0 0 0 0 0 0 0 0 0 10 10 10
47688- 34 34 34 82 82 82 30 30 30 61 42 6
47689-180 123 7 206 145 10 230 174 11 239 182 13
47690-234 190 10 238 202 15 241 208 19 246 218 74
47691-246 218 38 246 215 20 246 215 20 246 215 20
47692-226 184 13 215 174 15 184 144 12 6 6 6
47693- 2 2 6 2 2 6 2 2 6 2 2 6
47694- 26 26 26 94 94 94 42 42 42 14 14 14
47695- 0 0 0 0 0 0 0 0 0 0 0 0
47696- 0 0 0 0 0 0 0 0 0 0 0 0
47697- 0 0 0 0 0 0 0 0 0 0 0 0
47698- 0 0 0 0 0 0 0 0 0 0 0 0
47699- 0 0 0 0 0 0 0 0 0 0 0 0
47700- 0 0 0 0 0 0 0 0 0 0 0 0
47701- 0 0 0 0 0 0 0 0 0 0 0 0
47702- 0 0 0 0 0 0 0 0 0 0 0 0
47703- 0 0 0 0 0 0 0 0 0 0 0 0
47704- 0 0 0 0 0 0 0 0 0 0 0 0
47705- 0 0 0 0 0 0 0 0 0 0 0 0
47706- 0 0 0 0 0 0 0 0 0 0 0 0
47707- 0 0 0 0 0 0 0 0 0 10 10 10
47708- 30 30 30 78 78 78 50 50 50 104 69 6
47709-192 133 9 216 158 10 236 178 12 236 186 11
47710-232 195 16 241 208 19 244 214 54 245 215 43
47711-246 215 20 246 215 20 241 208 19 198 155 10
47712-200 144 11 216 158 10 156 118 10 2 2 6
47713- 2 2 6 2 2 6 2 2 6 2 2 6
47714- 6 6 6 90 90 90 54 54 54 18 18 18
47715- 6 6 6 0 0 0 0 0 0 0 0 0
47716- 0 0 0 0 0 0 0 0 0 0 0 0
47717- 0 0 0 0 0 0 0 0 0 0 0 0
47718- 0 0 0 0 0 0 0 0 0 0 0 0
47719- 0 0 0 0 0 0 0 0 0 0 0 0
47720- 0 0 0 0 0 0 0 0 0 0 0 0
47721- 0 0 0 0 0 0 0 0 0 0 0 0
47722- 0 0 0 0 0 0 0 0 0 0 0 0
47723- 0 0 0 0 0 0 0 0 0 0 0 0
47724- 0 0 0 0 0 0 0 0 0 0 0 0
47725- 0 0 0 0 0 0 0 0 0 0 0 0
47726- 0 0 0 0 0 0 0 0 0 0 0 0
47727- 0 0 0 0 0 0 0 0 0 10 10 10
47728- 30 30 30 78 78 78 46 46 46 22 22 22
47729-137 92 6 210 162 10 239 182 13 238 190 10
47730-238 202 15 241 208 19 246 215 20 246 215 20
47731-241 208 19 203 166 17 185 133 11 210 150 10
47732-216 158 10 210 150 10 102 78 10 2 2 6
47733- 6 6 6 54 54 54 14 14 14 2 2 6
47734- 2 2 6 62 62 62 74 74 74 30 30 30
47735- 10 10 10 0 0 0 0 0 0 0 0 0
47736- 0 0 0 0 0 0 0 0 0 0 0 0
47737- 0 0 0 0 0 0 0 0 0 0 0 0
47738- 0 0 0 0 0 0 0 0 0 0 0 0
47739- 0 0 0 0 0 0 0 0 0 0 0 0
47740- 0 0 0 0 0 0 0 0 0 0 0 0
47741- 0 0 0 0 0 0 0 0 0 0 0 0
47742- 0 0 0 0 0 0 0 0 0 0 0 0
47743- 0 0 0 0 0 0 0 0 0 0 0 0
47744- 0 0 0 0 0 0 0 0 0 0 0 0
47745- 0 0 0 0 0 0 0 0 0 0 0 0
47746- 0 0 0 0 0 0 0 0 0 0 0 0
47747- 0 0 0 0 0 0 0 0 0 10 10 10
47748- 34 34 34 78 78 78 50 50 50 6 6 6
47749- 94 70 30 139 102 15 190 146 13 226 184 13
47750-232 200 30 232 195 16 215 174 15 190 146 13
47751-168 122 10 192 133 9 210 150 10 213 154 11
47752-202 150 34 182 157 106 101 98 89 2 2 6
47753- 2 2 6 78 78 78 116 116 116 58 58 58
47754- 2 2 6 22 22 22 90 90 90 46 46 46
47755- 18 18 18 6 6 6 0 0 0 0 0 0
47756- 0 0 0 0 0 0 0 0 0 0 0 0
47757- 0 0 0 0 0 0 0 0 0 0 0 0
47758- 0 0 0 0 0 0 0 0 0 0 0 0
47759- 0 0 0 0 0 0 0 0 0 0 0 0
47760- 0 0 0 0 0 0 0 0 0 0 0 0
47761- 0 0 0 0 0 0 0 0 0 0 0 0
47762- 0 0 0 0 0 0 0 0 0 0 0 0
47763- 0 0 0 0 0 0 0 0 0 0 0 0
47764- 0 0 0 0 0 0 0 0 0 0 0 0
47765- 0 0 0 0 0 0 0 0 0 0 0 0
47766- 0 0 0 0 0 0 0 0 0 0 0 0
47767- 0 0 0 0 0 0 0 0 0 10 10 10
47768- 38 38 38 86 86 86 50 50 50 6 6 6
47769-128 128 128 174 154 114 156 107 11 168 122 10
47770-198 155 10 184 144 12 197 138 11 200 144 11
47771-206 145 10 206 145 10 197 138 11 188 164 115
47772-195 195 195 198 198 198 174 174 174 14 14 14
47773- 2 2 6 22 22 22 116 116 116 116 116 116
47774- 22 22 22 2 2 6 74 74 74 70 70 70
47775- 30 30 30 10 10 10 0 0 0 0 0 0
47776- 0 0 0 0 0 0 0 0 0 0 0 0
47777- 0 0 0 0 0 0 0 0 0 0 0 0
47778- 0 0 0 0 0 0 0 0 0 0 0 0
47779- 0 0 0 0 0 0 0 0 0 0 0 0
47780- 0 0 0 0 0 0 0 0 0 0 0 0
47781- 0 0 0 0 0 0 0 0 0 0 0 0
47782- 0 0 0 0 0 0 0 0 0 0 0 0
47783- 0 0 0 0 0 0 0 0 0 0 0 0
47784- 0 0 0 0 0 0 0 0 0 0 0 0
47785- 0 0 0 0 0 0 0 0 0 0 0 0
47786- 0 0 0 0 0 0 0 0 0 0 0 0
47787- 0 0 0 0 0 0 6 6 6 18 18 18
47788- 50 50 50 101 101 101 26 26 26 10 10 10
47789-138 138 138 190 190 190 174 154 114 156 107 11
47790-197 138 11 200 144 11 197 138 11 192 133 9
47791-180 123 7 190 142 34 190 178 144 187 187 187
47792-202 202 202 221 221 221 214 214 214 66 66 66
47793- 2 2 6 2 2 6 50 50 50 62 62 62
47794- 6 6 6 2 2 6 10 10 10 90 90 90
47795- 50 50 50 18 18 18 6 6 6 0 0 0
47796- 0 0 0 0 0 0 0 0 0 0 0 0
47797- 0 0 0 0 0 0 0 0 0 0 0 0
47798- 0 0 0 0 0 0 0 0 0 0 0 0
47799- 0 0 0 0 0 0 0 0 0 0 0 0
47800- 0 0 0 0 0 0 0 0 0 0 0 0
47801- 0 0 0 0 0 0 0 0 0 0 0 0
47802- 0 0 0 0 0 0 0 0 0 0 0 0
47803- 0 0 0 0 0 0 0 0 0 0 0 0
47804- 0 0 0 0 0 0 0 0 0 0 0 0
47805- 0 0 0 0 0 0 0 0 0 0 0 0
47806- 0 0 0 0 0 0 0 0 0 0 0 0
47807- 0 0 0 0 0 0 10 10 10 34 34 34
47808- 74 74 74 74 74 74 2 2 6 6 6 6
47809-144 144 144 198 198 198 190 190 190 178 166 146
47810-154 121 60 156 107 11 156 107 11 168 124 44
47811-174 154 114 187 187 187 190 190 190 210 210 210
47812-246 246 246 253 253 253 253 253 253 182 182 182
47813- 6 6 6 2 2 6 2 2 6 2 2 6
47814- 2 2 6 2 2 6 2 2 6 62 62 62
47815- 74 74 74 34 34 34 14 14 14 0 0 0
47816- 0 0 0 0 0 0 0 0 0 0 0 0
47817- 0 0 0 0 0 0 0 0 0 0 0 0
47818- 0 0 0 0 0 0 0 0 0 0 0 0
47819- 0 0 0 0 0 0 0 0 0 0 0 0
47820- 0 0 0 0 0 0 0 0 0 0 0 0
47821- 0 0 0 0 0 0 0 0 0 0 0 0
47822- 0 0 0 0 0 0 0 0 0 0 0 0
47823- 0 0 0 0 0 0 0 0 0 0 0 0
47824- 0 0 0 0 0 0 0 0 0 0 0 0
47825- 0 0 0 0 0 0 0 0 0 0 0 0
47826- 0 0 0 0 0 0 0 0 0 0 0 0
47827- 0 0 0 10 10 10 22 22 22 54 54 54
47828- 94 94 94 18 18 18 2 2 6 46 46 46
47829-234 234 234 221 221 221 190 190 190 190 190 190
47830-190 190 190 187 187 187 187 187 187 190 190 190
47831-190 190 190 195 195 195 214 214 214 242 242 242
47832-253 253 253 253 253 253 253 253 253 253 253 253
47833- 82 82 82 2 2 6 2 2 6 2 2 6
47834- 2 2 6 2 2 6 2 2 6 14 14 14
47835- 86 86 86 54 54 54 22 22 22 6 6 6
47836- 0 0 0 0 0 0 0 0 0 0 0 0
47837- 0 0 0 0 0 0 0 0 0 0 0 0
47838- 0 0 0 0 0 0 0 0 0 0 0 0
47839- 0 0 0 0 0 0 0 0 0 0 0 0
47840- 0 0 0 0 0 0 0 0 0 0 0 0
47841- 0 0 0 0 0 0 0 0 0 0 0 0
47842- 0 0 0 0 0 0 0 0 0 0 0 0
47843- 0 0 0 0 0 0 0 0 0 0 0 0
47844- 0 0 0 0 0 0 0 0 0 0 0 0
47845- 0 0 0 0 0 0 0 0 0 0 0 0
47846- 0 0 0 0 0 0 0 0 0 0 0 0
47847- 6 6 6 18 18 18 46 46 46 90 90 90
47848- 46 46 46 18 18 18 6 6 6 182 182 182
47849-253 253 253 246 246 246 206 206 206 190 190 190
47850-190 190 190 190 190 190 190 190 190 190 190 190
47851-206 206 206 231 231 231 250 250 250 253 253 253
47852-253 253 253 253 253 253 253 253 253 253 253 253
47853-202 202 202 14 14 14 2 2 6 2 2 6
47854- 2 2 6 2 2 6 2 2 6 2 2 6
47855- 42 42 42 86 86 86 42 42 42 18 18 18
47856- 6 6 6 0 0 0 0 0 0 0 0 0
47857- 0 0 0 0 0 0 0 0 0 0 0 0
47858- 0 0 0 0 0 0 0 0 0 0 0 0
47859- 0 0 0 0 0 0 0 0 0 0 0 0
47860- 0 0 0 0 0 0 0 0 0 0 0 0
47861- 0 0 0 0 0 0 0 0 0 0 0 0
47862- 0 0 0 0 0 0 0 0 0 0 0 0
47863- 0 0 0 0 0 0 0 0 0 0 0 0
47864- 0 0 0 0 0 0 0 0 0 0 0 0
47865- 0 0 0 0 0 0 0 0 0 0 0 0
47866- 0 0 0 0 0 0 0 0 0 6 6 6
47867- 14 14 14 38 38 38 74 74 74 66 66 66
47868- 2 2 6 6 6 6 90 90 90 250 250 250
47869-253 253 253 253 253 253 238 238 238 198 198 198
47870-190 190 190 190 190 190 195 195 195 221 221 221
47871-246 246 246 253 253 253 253 253 253 253 253 253
47872-253 253 253 253 253 253 253 253 253 253 253 253
47873-253 253 253 82 82 82 2 2 6 2 2 6
47874- 2 2 6 2 2 6 2 2 6 2 2 6
47875- 2 2 6 78 78 78 70 70 70 34 34 34
47876- 14 14 14 6 6 6 0 0 0 0 0 0
47877- 0 0 0 0 0 0 0 0 0 0 0 0
47878- 0 0 0 0 0 0 0 0 0 0 0 0
47879- 0 0 0 0 0 0 0 0 0 0 0 0
47880- 0 0 0 0 0 0 0 0 0 0 0 0
47881- 0 0 0 0 0 0 0 0 0 0 0 0
47882- 0 0 0 0 0 0 0 0 0 0 0 0
47883- 0 0 0 0 0 0 0 0 0 0 0 0
47884- 0 0 0 0 0 0 0 0 0 0 0 0
47885- 0 0 0 0 0 0 0 0 0 0 0 0
47886- 0 0 0 0 0 0 0 0 0 14 14 14
47887- 34 34 34 66 66 66 78 78 78 6 6 6
47888- 2 2 6 18 18 18 218 218 218 253 253 253
47889-253 253 253 253 253 253 253 253 253 246 246 246
47890-226 226 226 231 231 231 246 246 246 253 253 253
47891-253 253 253 253 253 253 253 253 253 253 253 253
47892-253 253 253 253 253 253 253 253 253 253 253 253
47893-253 253 253 178 178 178 2 2 6 2 2 6
47894- 2 2 6 2 2 6 2 2 6 2 2 6
47895- 2 2 6 18 18 18 90 90 90 62 62 62
47896- 30 30 30 10 10 10 0 0 0 0 0 0
47897- 0 0 0 0 0 0 0 0 0 0 0 0
47898- 0 0 0 0 0 0 0 0 0 0 0 0
47899- 0 0 0 0 0 0 0 0 0 0 0 0
47900- 0 0 0 0 0 0 0 0 0 0 0 0
47901- 0 0 0 0 0 0 0 0 0 0 0 0
47902- 0 0 0 0 0 0 0 0 0 0 0 0
47903- 0 0 0 0 0 0 0 0 0 0 0 0
47904- 0 0 0 0 0 0 0 0 0 0 0 0
47905- 0 0 0 0 0 0 0 0 0 0 0 0
47906- 0 0 0 0 0 0 10 10 10 26 26 26
47907- 58 58 58 90 90 90 18 18 18 2 2 6
47908- 2 2 6 110 110 110 253 253 253 253 253 253
47909-253 253 253 253 253 253 253 253 253 253 253 253
47910-250 250 250 253 253 253 253 253 253 253 253 253
47911-253 253 253 253 253 253 253 253 253 253 253 253
47912-253 253 253 253 253 253 253 253 253 253 253 253
47913-253 253 253 231 231 231 18 18 18 2 2 6
47914- 2 2 6 2 2 6 2 2 6 2 2 6
47915- 2 2 6 2 2 6 18 18 18 94 94 94
47916- 54 54 54 26 26 26 10 10 10 0 0 0
47917- 0 0 0 0 0 0 0 0 0 0 0 0
47918- 0 0 0 0 0 0 0 0 0 0 0 0
47919- 0 0 0 0 0 0 0 0 0 0 0 0
47920- 0 0 0 0 0 0 0 0 0 0 0 0
47921- 0 0 0 0 0 0 0 0 0 0 0 0
47922- 0 0 0 0 0 0 0 0 0 0 0 0
47923- 0 0 0 0 0 0 0 0 0 0 0 0
47924- 0 0 0 0 0 0 0 0 0 0 0 0
47925- 0 0 0 0 0 0 0 0 0 0 0 0
47926- 0 0 0 6 6 6 22 22 22 50 50 50
47927- 90 90 90 26 26 26 2 2 6 2 2 6
47928- 14 14 14 195 195 195 250 250 250 253 253 253
47929-253 253 253 253 253 253 253 253 253 253 253 253
47930-253 253 253 253 253 253 253 253 253 253 253 253
47931-253 253 253 253 253 253 253 253 253 253 253 253
47932-253 253 253 253 253 253 253 253 253 253 253 253
47933-250 250 250 242 242 242 54 54 54 2 2 6
47934- 2 2 6 2 2 6 2 2 6 2 2 6
47935- 2 2 6 2 2 6 2 2 6 38 38 38
47936- 86 86 86 50 50 50 22 22 22 6 6 6
47937- 0 0 0 0 0 0 0 0 0 0 0 0
47938- 0 0 0 0 0 0 0 0 0 0 0 0
47939- 0 0 0 0 0 0 0 0 0 0 0 0
47940- 0 0 0 0 0 0 0 0 0 0 0 0
47941- 0 0 0 0 0 0 0 0 0 0 0 0
47942- 0 0 0 0 0 0 0 0 0 0 0 0
47943- 0 0 0 0 0 0 0 0 0 0 0 0
47944- 0 0 0 0 0 0 0 0 0 0 0 0
47945- 0 0 0 0 0 0 0 0 0 0 0 0
47946- 6 6 6 14 14 14 38 38 38 82 82 82
47947- 34 34 34 2 2 6 2 2 6 2 2 6
47948- 42 42 42 195 195 195 246 246 246 253 253 253
47949-253 253 253 253 253 253 253 253 253 250 250 250
47950-242 242 242 242 242 242 250 250 250 253 253 253
47951-253 253 253 253 253 253 253 253 253 253 253 253
47952-253 253 253 250 250 250 246 246 246 238 238 238
47953-226 226 226 231 231 231 101 101 101 6 6 6
47954- 2 2 6 2 2 6 2 2 6 2 2 6
47955- 2 2 6 2 2 6 2 2 6 2 2 6
47956- 38 38 38 82 82 82 42 42 42 14 14 14
47957- 6 6 6 0 0 0 0 0 0 0 0 0
47958- 0 0 0 0 0 0 0 0 0 0 0 0
47959- 0 0 0 0 0 0 0 0 0 0 0 0
47960- 0 0 0 0 0 0 0 0 0 0 0 0
47961- 0 0 0 0 0 0 0 0 0 0 0 0
47962- 0 0 0 0 0 0 0 0 0 0 0 0
47963- 0 0 0 0 0 0 0 0 0 0 0 0
47964- 0 0 0 0 0 0 0 0 0 0 0 0
47965- 0 0 0 0 0 0 0 0 0 0 0 0
47966- 10 10 10 26 26 26 62 62 62 66 66 66
47967- 2 2 6 2 2 6 2 2 6 6 6 6
47968- 70 70 70 170 170 170 206 206 206 234 234 234
47969-246 246 246 250 250 250 250 250 250 238 238 238
47970-226 226 226 231 231 231 238 238 238 250 250 250
47971-250 250 250 250 250 250 246 246 246 231 231 231
47972-214 214 214 206 206 206 202 202 202 202 202 202
47973-198 198 198 202 202 202 182 182 182 18 18 18
47974- 2 2 6 2 2 6 2 2 6 2 2 6
47975- 2 2 6 2 2 6 2 2 6 2 2 6
47976- 2 2 6 62 62 62 66 66 66 30 30 30
47977- 10 10 10 0 0 0 0 0 0 0 0 0
47978- 0 0 0 0 0 0 0 0 0 0 0 0
47979- 0 0 0 0 0 0 0 0 0 0 0 0
47980- 0 0 0 0 0 0 0 0 0 0 0 0
47981- 0 0 0 0 0 0 0 0 0 0 0 0
47982- 0 0 0 0 0 0 0 0 0 0 0 0
47983- 0 0 0 0 0 0 0 0 0 0 0 0
47984- 0 0 0 0 0 0 0 0 0 0 0 0
47985- 0 0 0 0 0 0 0 0 0 0 0 0
47986- 14 14 14 42 42 42 82 82 82 18 18 18
47987- 2 2 6 2 2 6 2 2 6 10 10 10
47988- 94 94 94 182 182 182 218 218 218 242 242 242
47989-250 250 250 253 253 253 253 253 253 250 250 250
47990-234 234 234 253 253 253 253 253 253 253 253 253
47991-253 253 253 253 253 253 253 253 253 246 246 246
47992-238 238 238 226 226 226 210 210 210 202 202 202
47993-195 195 195 195 195 195 210 210 210 158 158 158
47994- 6 6 6 14 14 14 50 50 50 14 14 14
47995- 2 2 6 2 2 6 2 2 6 2 2 6
47996- 2 2 6 6 6 6 86 86 86 46 46 46
47997- 18 18 18 6 6 6 0 0 0 0 0 0
47998- 0 0 0 0 0 0 0 0 0 0 0 0
47999- 0 0 0 0 0 0 0 0 0 0 0 0
48000- 0 0 0 0 0 0 0 0 0 0 0 0
48001- 0 0 0 0 0 0 0 0 0 0 0 0
48002- 0 0 0 0 0 0 0 0 0 0 0 0
48003- 0 0 0 0 0 0 0 0 0 0 0 0
48004- 0 0 0 0 0 0 0 0 0 0 0 0
48005- 0 0 0 0 0 0 0 0 0 6 6 6
48006- 22 22 22 54 54 54 70 70 70 2 2 6
48007- 2 2 6 10 10 10 2 2 6 22 22 22
48008-166 166 166 231 231 231 250 250 250 253 253 253
48009-253 253 253 253 253 253 253 253 253 250 250 250
48010-242 242 242 253 253 253 253 253 253 253 253 253
48011-253 253 253 253 253 253 253 253 253 253 253 253
48012-253 253 253 253 253 253 253 253 253 246 246 246
48013-231 231 231 206 206 206 198 198 198 226 226 226
48014- 94 94 94 2 2 6 6 6 6 38 38 38
48015- 30 30 30 2 2 6 2 2 6 2 2 6
48016- 2 2 6 2 2 6 62 62 62 66 66 66
48017- 26 26 26 10 10 10 0 0 0 0 0 0
48018- 0 0 0 0 0 0 0 0 0 0 0 0
48019- 0 0 0 0 0 0 0 0 0 0 0 0
48020- 0 0 0 0 0 0 0 0 0 0 0 0
48021- 0 0 0 0 0 0 0 0 0 0 0 0
48022- 0 0 0 0 0 0 0 0 0 0 0 0
48023- 0 0 0 0 0 0 0 0 0 0 0 0
48024- 0 0 0 0 0 0 0 0 0 0 0 0
48025- 0 0 0 0 0 0 0 0 0 10 10 10
48026- 30 30 30 74 74 74 50 50 50 2 2 6
48027- 26 26 26 26 26 26 2 2 6 106 106 106
48028-238 238 238 253 253 253 253 253 253 253 253 253
48029-253 253 253 253 253 253 253 253 253 253 253 253
48030-253 253 253 253 253 253 253 253 253 253 253 253
48031-253 253 253 253 253 253 253 253 253 253 253 253
48032-253 253 253 253 253 253 253 253 253 253 253 253
48033-253 253 253 246 246 246 218 218 218 202 202 202
48034-210 210 210 14 14 14 2 2 6 2 2 6
48035- 30 30 30 22 22 22 2 2 6 2 2 6
48036- 2 2 6 2 2 6 18 18 18 86 86 86
48037- 42 42 42 14 14 14 0 0 0 0 0 0
48038- 0 0 0 0 0 0 0 0 0 0 0 0
48039- 0 0 0 0 0 0 0 0 0 0 0 0
48040- 0 0 0 0 0 0 0 0 0 0 0 0
48041- 0 0 0 0 0 0 0 0 0 0 0 0
48042- 0 0 0 0 0 0 0 0 0 0 0 0
48043- 0 0 0 0 0 0 0 0 0 0 0 0
48044- 0 0 0 0 0 0 0 0 0 0 0 0
48045- 0 0 0 0 0 0 0 0 0 14 14 14
48046- 42 42 42 90 90 90 22 22 22 2 2 6
48047- 42 42 42 2 2 6 18 18 18 218 218 218
48048-253 253 253 253 253 253 253 253 253 253 253 253
48049-253 253 253 253 253 253 253 253 253 253 253 253
48050-253 253 253 253 253 253 253 253 253 253 253 253
48051-253 253 253 253 253 253 253 253 253 253 253 253
48052-253 253 253 253 253 253 253 253 253 253 253 253
48053-253 253 253 253 253 253 250 250 250 221 221 221
48054-218 218 218 101 101 101 2 2 6 14 14 14
48055- 18 18 18 38 38 38 10 10 10 2 2 6
48056- 2 2 6 2 2 6 2 2 6 78 78 78
48057- 58 58 58 22 22 22 6 6 6 0 0 0
48058- 0 0 0 0 0 0 0 0 0 0 0 0
48059- 0 0 0 0 0 0 0 0 0 0 0 0
48060- 0 0 0 0 0 0 0 0 0 0 0 0
48061- 0 0 0 0 0 0 0 0 0 0 0 0
48062- 0 0 0 0 0 0 0 0 0 0 0 0
48063- 0 0 0 0 0 0 0 0 0 0 0 0
48064- 0 0 0 0 0 0 0 0 0 0 0 0
48065- 0 0 0 0 0 0 6 6 6 18 18 18
48066- 54 54 54 82 82 82 2 2 6 26 26 26
48067- 22 22 22 2 2 6 123 123 123 253 253 253
48068-253 253 253 253 253 253 253 253 253 253 253 253
48069-253 253 253 253 253 253 253 253 253 253 253 253
48070-253 253 253 253 253 253 253 253 253 253 253 253
48071-253 253 253 253 253 253 253 253 253 253 253 253
48072-253 253 253 253 253 253 253 253 253 253 253 253
48073-253 253 253 253 253 253 253 253 253 250 250 250
48074-238 238 238 198 198 198 6 6 6 38 38 38
48075- 58 58 58 26 26 26 38 38 38 2 2 6
48076- 2 2 6 2 2 6 2 2 6 46 46 46
48077- 78 78 78 30 30 30 10 10 10 0 0 0
48078- 0 0 0 0 0 0 0 0 0 0 0 0
48079- 0 0 0 0 0 0 0 0 0 0 0 0
48080- 0 0 0 0 0 0 0 0 0 0 0 0
48081- 0 0 0 0 0 0 0 0 0 0 0 0
48082- 0 0 0 0 0 0 0 0 0 0 0 0
48083- 0 0 0 0 0 0 0 0 0 0 0 0
48084- 0 0 0 0 0 0 0 0 0 0 0 0
48085- 0 0 0 0 0 0 10 10 10 30 30 30
48086- 74 74 74 58 58 58 2 2 6 42 42 42
48087- 2 2 6 22 22 22 231 231 231 253 253 253
48088-253 253 253 253 253 253 253 253 253 253 253 253
48089-253 253 253 253 253 253 253 253 253 250 250 250
48090-253 253 253 253 253 253 253 253 253 253 253 253
48091-253 253 253 253 253 253 253 253 253 253 253 253
48092-253 253 253 253 253 253 253 253 253 253 253 253
48093-253 253 253 253 253 253 253 253 253 253 253 253
48094-253 253 253 246 246 246 46 46 46 38 38 38
48095- 42 42 42 14 14 14 38 38 38 14 14 14
48096- 2 2 6 2 2 6 2 2 6 6 6 6
48097- 86 86 86 46 46 46 14 14 14 0 0 0
48098- 0 0 0 0 0 0 0 0 0 0 0 0
48099- 0 0 0 0 0 0 0 0 0 0 0 0
48100- 0 0 0 0 0 0 0 0 0 0 0 0
48101- 0 0 0 0 0 0 0 0 0 0 0 0
48102- 0 0 0 0 0 0 0 0 0 0 0 0
48103- 0 0 0 0 0 0 0 0 0 0 0 0
48104- 0 0 0 0 0 0 0 0 0 0 0 0
48105- 0 0 0 6 6 6 14 14 14 42 42 42
48106- 90 90 90 18 18 18 18 18 18 26 26 26
48107- 2 2 6 116 116 116 253 253 253 253 253 253
48108-253 253 253 253 253 253 253 253 253 253 253 253
48109-253 253 253 253 253 253 250 250 250 238 238 238
48110-253 253 253 253 253 253 253 253 253 253 253 253
48111-253 253 253 253 253 253 253 253 253 253 253 253
48112-253 253 253 253 253 253 253 253 253 253 253 253
48113-253 253 253 253 253 253 253 253 253 253 253 253
48114-253 253 253 253 253 253 94 94 94 6 6 6
48115- 2 2 6 2 2 6 10 10 10 34 34 34
48116- 2 2 6 2 2 6 2 2 6 2 2 6
48117- 74 74 74 58 58 58 22 22 22 6 6 6
48118- 0 0 0 0 0 0 0 0 0 0 0 0
48119- 0 0 0 0 0 0 0 0 0 0 0 0
48120- 0 0 0 0 0 0 0 0 0 0 0 0
48121- 0 0 0 0 0 0 0 0 0 0 0 0
48122- 0 0 0 0 0 0 0 0 0 0 0 0
48123- 0 0 0 0 0 0 0 0 0 0 0 0
48124- 0 0 0 0 0 0 0 0 0 0 0 0
48125- 0 0 0 10 10 10 26 26 26 66 66 66
48126- 82 82 82 2 2 6 38 38 38 6 6 6
48127- 14 14 14 210 210 210 253 253 253 253 253 253
48128-253 253 253 253 253 253 253 253 253 253 253 253
48129-253 253 253 253 253 253 246 246 246 242 242 242
48130-253 253 253 253 253 253 253 253 253 253 253 253
48131-253 253 253 253 253 253 253 253 253 253 253 253
48132-253 253 253 253 253 253 253 253 253 253 253 253
48133-253 253 253 253 253 253 253 253 253 253 253 253
48134-253 253 253 253 253 253 144 144 144 2 2 6
48135- 2 2 6 2 2 6 2 2 6 46 46 46
48136- 2 2 6 2 2 6 2 2 6 2 2 6
48137- 42 42 42 74 74 74 30 30 30 10 10 10
48138- 0 0 0 0 0 0 0 0 0 0 0 0
48139- 0 0 0 0 0 0 0 0 0 0 0 0
48140- 0 0 0 0 0 0 0 0 0 0 0 0
48141- 0 0 0 0 0 0 0 0 0 0 0 0
48142- 0 0 0 0 0 0 0 0 0 0 0 0
48143- 0 0 0 0 0 0 0 0 0 0 0 0
48144- 0 0 0 0 0 0 0 0 0 0 0 0
48145- 6 6 6 14 14 14 42 42 42 90 90 90
48146- 26 26 26 6 6 6 42 42 42 2 2 6
48147- 74 74 74 250 250 250 253 253 253 253 253 253
48148-253 253 253 253 253 253 253 253 253 253 253 253
48149-253 253 253 253 253 253 242 242 242 242 242 242
48150-253 253 253 253 253 253 253 253 253 253 253 253
48151-253 253 253 253 253 253 253 253 253 253 253 253
48152-253 253 253 253 253 253 253 253 253 253 253 253
48153-253 253 253 253 253 253 253 253 253 253 253 253
48154-253 253 253 253 253 253 182 182 182 2 2 6
48155- 2 2 6 2 2 6 2 2 6 46 46 46
48156- 2 2 6 2 2 6 2 2 6 2 2 6
48157- 10 10 10 86 86 86 38 38 38 10 10 10
48158- 0 0 0 0 0 0 0 0 0 0 0 0
48159- 0 0 0 0 0 0 0 0 0 0 0 0
48160- 0 0 0 0 0 0 0 0 0 0 0 0
48161- 0 0 0 0 0 0 0 0 0 0 0 0
48162- 0 0 0 0 0 0 0 0 0 0 0 0
48163- 0 0 0 0 0 0 0 0 0 0 0 0
48164- 0 0 0 0 0 0 0 0 0 0 0 0
48165- 10 10 10 26 26 26 66 66 66 82 82 82
48166- 2 2 6 22 22 22 18 18 18 2 2 6
48167-149 149 149 253 253 253 253 253 253 253 253 253
48168-253 253 253 253 253 253 253 253 253 253 253 253
48169-253 253 253 253 253 253 234 234 234 242 242 242
48170-253 253 253 253 253 253 253 253 253 253 253 253
48171-253 253 253 253 253 253 253 253 253 253 253 253
48172-253 253 253 253 253 253 253 253 253 253 253 253
48173-253 253 253 253 253 253 253 253 253 253 253 253
48174-253 253 253 253 253 253 206 206 206 2 2 6
48175- 2 2 6 2 2 6 2 2 6 38 38 38
48176- 2 2 6 2 2 6 2 2 6 2 2 6
48177- 6 6 6 86 86 86 46 46 46 14 14 14
48178- 0 0 0 0 0 0 0 0 0 0 0 0
48179- 0 0 0 0 0 0 0 0 0 0 0 0
48180- 0 0 0 0 0 0 0 0 0 0 0 0
48181- 0 0 0 0 0 0 0 0 0 0 0 0
48182- 0 0 0 0 0 0 0 0 0 0 0 0
48183- 0 0 0 0 0 0 0 0 0 0 0 0
48184- 0 0 0 0 0 0 0 0 0 6 6 6
48185- 18 18 18 46 46 46 86 86 86 18 18 18
48186- 2 2 6 34 34 34 10 10 10 6 6 6
48187-210 210 210 253 253 253 253 253 253 253 253 253
48188-253 253 253 253 253 253 253 253 253 253 253 253
48189-253 253 253 253 253 253 234 234 234 242 242 242
48190-253 253 253 253 253 253 253 253 253 253 253 253
48191-253 253 253 253 253 253 253 253 253 253 253 253
48192-253 253 253 253 253 253 253 253 253 253 253 253
48193-253 253 253 253 253 253 253 253 253 253 253 253
48194-253 253 253 253 253 253 221 221 221 6 6 6
48195- 2 2 6 2 2 6 6 6 6 30 30 30
48196- 2 2 6 2 2 6 2 2 6 2 2 6
48197- 2 2 6 82 82 82 54 54 54 18 18 18
48198- 6 6 6 0 0 0 0 0 0 0 0 0
48199- 0 0 0 0 0 0 0 0 0 0 0 0
48200- 0 0 0 0 0 0 0 0 0 0 0 0
48201- 0 0 0 0 0 0 0 0 0 0 0 0
48202- 0 0 0 0 0 0 0 0 0 0 0 0
48203- 0 0 0 0 0 0 0 0 0 0 0 0
48204- 0 0 0 0 0 0 0 0 0 10 10 10
48205- 26 26 26 66 66 66 62 62 62 2 2 6
48206- 2 2 6 38 38 38 10 10 10 26 26 26
48207-238 238 238 253 253 253 253 253 253 253 253 253
48208-253 253 253 253 253 253 253 253 253 253 253 253
48209-253 253 253 253 253 253 231 231 231 238 238 238
48210-253 253 253 253 253 253 253 253 253 253 253 253
48211-253 253 253 253 253 253 253 253 253 253 253 253
48212-253 253 253 253 253 253 253 253 253 253 253 253
48213-253 253 253 253 253 253 253 253 253 253 253 253
48214-253 253 253 253 253 253 231 231 231 6 6 6
48215- 2 2 6 2 2 6 10 10 10 30 30 30
48216- 2 2 6 2 2 6 2 2 6 2 2 6
48217- 2 2 6 66 66 66 58 58 58 22 22 22
48218- 6 6 6 0 0 0 0 0 0 0 0 0
48219- 0 0 0 0 0 0 0 0 0 0 0 0
48220- 0 0 0 0 0 0 0 0 0 0 0 0
48221- 0 0 0 0 0 0 0 0 0 0 0 0
48222- 0 0 0 0 0 0 0 0 0 0 0 0
48223- 0 0 0 0 0 0 0 0 0 0 0 0
48224- 0 0 0 0 0 0 0 0 0 10 10 10
48225- 38 38 38 78 78 78 6 6 6 2 2 6
48226- 2 2 6 46 46 46 14 14 14 42 42 42
48227-246 246 246 253 253 253 253 253 253 253 253 253
48228-253 253 253 253 253 253 253 253 253 253 253 253
48229-253 253 253 253 253 253 231 231 231 242 242 242
48230-253 253 253 253 253 253 253 253 253 253 253 253
48231-253 253 253 253 253 253 253 253 253 253 253 253
48232-253 253 253 253 253 253 253 253 253 253 253 253
48233-253 253 253 253 253 253 253 253 253 253 253 253
48234-253 253 253 253 253 253 234 234 234 10 10 10
48235- 2 2 6 2 2 6 22 22 22 14 14 14
48236- 2 2 6 2 2 6 2 2 6 2 2 6
48237- 2 2 6 66 66 66 62 62 62 22 22 22
48238- 6 6 6 0 0 0 0 0 0 0 0 0
48239- 0 0 0 0 0 0 0 0 0 0 0 0
48240- 0 0 0 0 0 0 0 0 0 0 0 0
48241- 0 0 0 0 0 0 0 0 0 0 0 0
48242- 0 0 0 0 0 0 0 0 0 0 0 0
48243- 0 0 0 0 0 0 0 0 0 0 0 0
48244- 0 0 0 0 0 0 6 6 6 18 18 18
48245- 50 50 50 74 74 74 2 2 6 2 2 6
48246- 14 14 14 70 70 70 34 34 34 62 62 62
48247-250 250 250 253 253 253 253 253 253 253 253 253
48248-253 253 253 253 253 253 253 253 253 253 253 253
48249-253 253 253 253 253 253 231 231 231 246 246 246
48250-253 253 253 253 253 253 253 253 253 253 253 253
48251-253 253 253 253 253 253 253 253 253 253 253 253
48252-253 253 253 253 253 253 253 253 253 253 253 253
48253-253 253 253 253 253 253 253 253 253 253 253 253
48254-253 253 253 253 253 253 234 234 234 14 14 14
48255- 2 2 6 2 2 6 30 30 30 2 2 6
48256- 2 2 6 2 2 6 2 2 6 2 2 6
48257- 2 2 6 66 66 66 62 62 62 22 22 22
48258- 6 6 6 0 0 0 0 0 0 0 0 0
48259- 0 0 0 0 0 0 0 0 0 0 0 0
48260- 0 0 0 0 0 0 0 0 0 0 0 0
48261- 0 0 0 0 0 0 0 0 0 0 0 0
48262- 0 0 0 0 0 0 0 0 0 0 0 0
48263- 0 0 0 0 0 0 0 0 0 0 0 0
48264- 0 0 0 0 0 0 6 6 6 18 18 18
48265- 54 54 54 62 62 62 2 2 6 2 2 6
48266- 2 2 6 30 30 30 46 46 46 70 70 70
48267-250 250 250 253 253 253 253 253 253 253 253 253
48268-253 253 253 253 253 253 253 253 253 253 253 253
48269-253 253 253 253 253 253 231 231 231 246 246 246
48270-253 253 253 253 253 253 253 253 253 253 253 253
48271-253 253 253 253 253 253 253 253 253 253 253 253
48272-253 253 253 253 253 253 253 253 253 253 253 253
48273-253 253 253 253 253 253 253 253 253 253 253 253
48274-253 253 253 253 253 253 226 226 226 10 10 10
48275- 2 2 6 6 6 6 30 30 30 2 2 6
48276- 2 2 6 2 2 6 2 2 6 2 2 6
48277- 2 2 6 66 66 66 58 58 58 22 22 22
48278- 6 6 6 0 0 0 0 0 0 0 0 0
48279- 0 0 0 0 0 0 0 0 0 0 0 0
48280- 0 0 0 0 0 0 0 0 0 0 0 0
48281- 0 0 0 0 0 0 0 0 0 0 0 0
48282- 0 0 0 0 0 0 0 0 0 0 0 0
48283- 0 0 0 0 0 0 0 0 0 0 0 0
48284- 0 0 0 0 0 0 6 6 6 22 22 22
48285- 58 58 58 62 62 62 2 2 6 2 2 6
48286- 2 2 6 2 2 6 30 30 30 78 78 78
48287-250 250 250 253 253 253 253 253 253 253 253 253
48288-253 253 253 253 253 253 253 253 253 253 253 253
48289-253 253 253 253 253 253 231 231 231 246 246 246
48290-253 253 253 253 253 253 253 253 253 253 253 253
48291-253 253 253 253 253 253 253 253 253 253 253 253
48292-253 253 253 253 253 253 253 253 253 253 253 253
48293-253 253 253 253 253 253 253 253 253 253 253 253
48294-253 253 253 253 253 253 206 206 206 2 2 6
48295- 22 22 22 34 34 34 18 14 6 22 22 22
48296- 26 26 26 18 18 18 6 6 6 2 2 6
48297- 2 2 6 82 82 82 54 54 54 18 18 18
48298- 6 6 6 0 0 0 0 0 0 0 0 0
48299- 0 0 0 0 0 0 0 0 0 0 0 0
48300- 0 0 0 0 0 0 0 0 0 0 0 0
48301- 0 0 0 0 0 0 0 0 0 0 0 0
48302- 0 0 0 0 0 0 0 0 0 0 0 0
48303- 0 0 0 0 0 0 0 0 0 0 0 0
48304- 0 0 0 0 0 0 6 6 6 26 26 26
48305- 62 62 62 106 106 106 74 54 14 185 133 11
48306-210 162 10 121 92 8 6 6 6 62 62 62
48307-238 238 238 253 253 253 253 253 253 253 253 253
48308-253 253 253 253 253 253 253 253 253 253 253 253
48309-253 253 253 253 253 253 231 231 231 246 246 246
48310-253 253 253 253 253 253 253 253 253 253 253 253
48311-253 253 253 253 253 253 253 253 253 253 253 253
48312-253 253 253 253 253 253 253 253 253 253 253 253
48313-253 253 253 253 253 253 253 253 253 253 253 253
48314-253 253 253 253 253 253 158 158 158 18 18 18
48315- 14 14 14 2 2 6 2 2 6 2 2 6
48316- 6 6 6 18 18 18 66 66 66 38 38 38
48317- 6 6 6 94 94 94 50 50 50 18 18 18
48318- 6 6 6 0 0 0 0 0 0 0 0 0
48319- 0 0 0 0 0 0 0 0 0 0 0 0
48320- 0 0 0 0 0 0 0 0 0 0 0 0
48321- 0 0 0 0 0 0 0 0 0 0 0 0
48322- 0 0 0 0 0 0 0 0 0 0 0 0
48323- 0 0 0 0 0 0 0 0 0 6 6 6
48324- 10 10 10 10 10 10 18 18 18 38 38 38
48325- 78 78 78 142 134 106 216 158 10 242 186 14
48326-246 190 14 246 190 14 156 118 10 10 10 10
48327- 90 90 90 238 238 238 253 253 253 253 253 253
48328-253 253 253 253 253 253 253 253 253 253 253 253
48329-253 253 253 253 253 253 231 231 231 250 250 250
48330-253 253 253 253 253 253 253 253 253 253 253 253
48331-253 253 253 253 253 253 253 253 253 253 253 253
48332-253 253 253 253 253 253 253 253 253 253 253 253
48333-253 253 253 253 253 253 253 253 253 246 230 190
48334-238 204 91 238 204 91 181 142 44 37 26 9
48335- 2 2 6 2 2 6 2 2 6 2 2 6
48336- 2 2 6 2 2 6 38 38 38 46 46 46
48337- 26 26 26 106 106 106 54 54 54 18 18 18
48338- 6 6 6 0 0 0 0 0 0 0 0 0
48339- 0 0 0 0 0 0 0 0 0 0 0 0
48340- 0 0 0 0 0 0 0 0 0 0 0 0
48341- 0 0 0 0 0 0 0 0 0 0 0 0
48342- 0 0 0 0 0 0 0 0 0 0 0 0
48343- 0 0 0 6 6 6 14 14 14 22 22 22
48344- 30 30 30 38 38 38 50 50 50 70 70 70
48345-106 106 106 190 142 34 226 170 11 242 186 14
48346-246 190 14 246 190 14 246 190 14 154 114 10
48347- 6 6 6 74 74 74 226 226 226 253 253 253
48348-253 253 253 253 253 253 253 253 253 253 253 253
48349-253 253 253 253 253 253 231 231 231 250 250 250
48350-253 253 253 253 253 253 253 253 253 253 253 253
48351-253 253 253 253 253 253 253 253 253 253 253 253
48352-253 253 253 253 253 253 253 253 253 253 253 253
48353-253 253 253 253 253 253 253 253 253 228 184 62
48354-241 196 14 241 208 19 232 195 16 38 30 10
48355- 2 2 6 2 2 6 2 2 6 2 2 6
48356- 2 2 6 6 6 6 30 30 30 26 26 26
48357-203 166 17 154 142 90 66 66 66 26 26 26
48358- 6 6 6 0 0 0 0 0 0 0 0 0
48359- 0 0 0 0 0 0 0 0 0 0 0 0
48360- 0 0 0 0 0 0 0 0 0 0 0 0
48361- 0 0 0 0 0 0 0 0 0 0 0 0
48362- 0 0 0 0 0 0 0 0 0 0 0 0
48363- 6 6 6 18 18 18 38 38 38 58 58 58
48364- 78 78 78 86 86 86 101 101 101 123 123 123
48365-175 146 61 210 150 10 234 174 13 246 186 14
48366-246 190 14 246 190 14 246 190 14 238 190 10
48367-102 78 10 2 2 6 46 46 46 198 198 198
48368-253 253 253 253 253 253 253 253 253 253 253 253
48369-253 253 253 253 253 253 234 234 234 242 242 242
48370-253 253 253 253 253 253 253 253 253 253 253 253
48371-253 253 253 253 253 253 253 253 253 253 253 253
48372-253 253 253 253 253 253 253 253 253 253 253 253
48373-253 253 253 253 253 253 253 253 253 224 178 62
48374-242 186 14 241 196 14 210 166 10 22 18 6
48375- 2 2 6 2 2 6 2 2 6 2 2 6
48376- 2 2 6 2 2 6 6 6 6 121 92 8
48377-238 202 15 232 195 16 82 82 82 34 34 34
48378- 10 10 10 0 0 0 0 0 0 0 0 0
48379- 0 0 0 0 0 0 0 0 0 0 0 0
48380- 0 0 0 0 0 0 0 0 0 0 0 0
48381- 0 0 0 0 0 0 0 0 0 0 0 0
48382- 0 0 0 0 0 0 0 0 0 0 0 0
48383- 14 14 14 38 38 38 70 70 70 154 122 46
48384-190 142 34 200 144 11 197 138 11 197 138 11
48385-213 154 11 226 170 11 242 186 14 246 190 14
48386-246 190 14 246 190 14 246 190 14 246 190 14
48387-225 175 15 46 32 6 2 2 6 22 22 22
48388-158 158 158 250 250 250 253 253 253 253 253 253
48389-253 253 253 253 253 253 253 253 253 253 253 253
48390-253 253 253 253 253 253 253 253 253 253 253 253
48391-253 253 253 253 253 253 253 253 253 253 253 253
48392-253 253 253 253 253 253 253 253 253 253 253 253
48393-253 253 253 250 250 250 242 242 242 224 178 62
48394-239 182 13 236 186 11 213 154 11 46 32 6
48395- 2 2 6 2 2 6 2 2 6 2 2 6
48396- 2 2 6 2 2 6 61 42 6 225 175 15
48397-238 190 10 236 186 11 112 100 78 42 42 42
48398- 14 14 14 0 0 0 0 0 0 0 0 0
48399- 0 0 0 0 0 0 0 0 0 0 0 0
48400- 0 0 0 0 0 0 0 0 0 0 0 0
48401- 0 0 0 0 0 0 0 0 0 0 0 0
48402- 0 0 0 0 0 0 0 0 0 6 6 6
48403- 22 22 22 54 54 54 154 122 46 213 154 11
48404-226 170 11 230 174 11 226 170 11 226 170 11
48405-236 178 12 242 186 14 246 190 14 246 190 14
48406-246 190 14 246 190 14 246 190 14 246 190 14
48407-241 196 14 184 144 12 10 10 10 2 2 6
48408- 6 6 6 116 116 116 242 242 242 253 253 253
48409-253 253 253 253 253 253 253 253 253 253 253 253
48410-253 253 253 253 253 253 253 253 253 253 253 253
48411-253 253 253 253 253 253 253 253 253 253 253 253
48412-253 253 253 253 253 253 253 253 253 253 253 253
48413-253 253 253 231 231 231 198 198 198 214 170 54
48414-236 178 12 236 178 12 210 150 10 137 92 6
48415- 18 14 6 2 2 6 2 2 6 2 2 6
48416- 6 6 6 70 47 6 200 144 11 236 178 12
48417-239 182 13 239 182 13 124 112 88 58 58 58
48418- 22 22 22 6 6 6 0 0 0 0 0 0
48419- 0 0 0 0 0 0 0 0 0 0 0 0
48420- 0 0 0 0 0 0 0 0 0 0 0 0
48421- 0 0 0 0 0 0 0 0 0 0 0 0
48422- 0 0 0 0 0 0 0 0 0 10 10 10
48423- 30 30 30 70 70 70 180 133 36 226 170 11
48424-239 182 13 242 186 14 242 186 14 246 186 14
48425-246 190 14 246 190 14 246 190 14 246 190 14
48426-246 190 14 246 190 14 246 190 14 246 190 14
48427-246 190 14 232 195 16 98 70 6 2 2 6
48428- 2 2 6 2 2 6 66 66 66 221 221 221
48429-253 253 253 253 253 253 253 253 253 253 253 253
48430-253 253 253 253 253 253 253 253 253 253 253 253
48431-253 253 253 253 253 253 253 253 253 253 253 253
48432-253 253 253 253 253 253 253 253 253 253 253 253
48433-253 253 253 206 206 206 198 198 198 214 166 58
48434-230 174 11 230 174 11 216 158 10 192 133 9
48435-163 110 8 116 81 8 102 78 10 116 81 8
48436-167 114 7 197 138 11 226 170 11 239 182 13
48437-242 186 14 242 186 14 162 146 94 78 78 78
48438- 34 34 34 14 14 14 6 6 6 0 0 0
48439- 0 0 0 0 0 0 0 0 0 0 0 0
48440- 0 0 0 0 0 0 0 0 0 0 0 0
48441- 0 0 0 0 0 0 0 0 0 0 0 0
48442- 0 0 0 0 0 0 0 0 0 6 6 6
48443- 30 30 30 78 78 78 190 142 34 226 170 11
48444-239 182 13 246 190 14 246 190 14 246 190 14
48445-246 190 14 246 190 14 246 190 14 246 190 14
48446-246 190 14 246 190 14 246 190 14 246 190 14
48447-246 190 14 241 196 14 203 166 17 22 18 6
48448- 2 2 6 2 2 6 2 2 6 38 38 38
48449-218 218 218 253 253 253 253 253 253 253 253 253
48450-253 253 253 253 253 253 253 253 253 253 253 253
48451-253 253 253 253 253 253 253 253 253 253 253 253
48452-253 253 253 253 253 253 253 253 253 253 253 253
48453-250 250 250 206 206 206 198 198 198 202 162 69
48454-226 170 11 236 178 12 224 166 10 210 150 10
48455-200 144 11 197 138 11 192 133 9 197 138 11
48456-210 150 10 226 170 11 242 186 14 246 190 14
48457-246 190 14 246 186 14 225 175 15 124 112 88
48458- 62 62 62 30 30 30 14 14 14 6 6 6
48459- 0 0 0 0 0 0 0 0 0 0 0 0
48460- 0 0 0 0 0 0 0 0 0 0 0 0
48461- 0 0 0 0 0 0 0 0 0 0 0 0
48462- 0 0 0 0 0 0 0 0 0 10 10 10
48463- 30 30 30 78 78 78 174 135 50 224 166 10
48464-239 182 13 246 190 14 246 190 14 246 190 14
48465-246 190 14 246 190 14 246 190 14 246 190 14
48466-246 190 14 246 190 14 246 190 14 246 190 14
48467-246 190 14 246 190 14 241 196 14 139 102 15
48468- 2 2 6 2 2 6 2 2 6 2 2 6
48469- 78 78 78 250 250 250 253 253 253 253 253 253
48470-253 253 253 253 253 253 253 253 253 253 253 253
48471-253 253 253 253 253 253 253 253 253 253 253 253
48472-253 253 253 253 253 253 253 253 253 253 253 253
48473-250 250 250 214 214 214 198 198 198 190 150 46
48474-219 162 10 236 178 12 234 174 13 224 166 10
48475-216 158 10 213 154 11 213 154 11 216 158 10
48476-226 170 11 239 182 13 246 190 14 246 190 14
48477-246 190 14 246 190 14 242 186 14 206 162 42
48478-101 101 101 58 58 58 30 30 30 14 14 14
48479- 6 6 6 0 0 0 0 0 0 0 0 0
48480- 0 0 0 0 0 0 0 0 0 0 0 0
48481- 0 0 0 0 0 0 0 0 0 0 0 0
48482- 0 0 0 0 0 0 0 0 0 10 10 10
48483- 30 30 30 74 74 74 174 135 50 216 158 10
48484-236 178 12 246 190 14 246 190 14 246 190 14
48485-246 190 14 246 190 14 246 190 14 246 190 14
48486-246 190 14 246 190 14 246 190 14 246 190 14
48487-246 190 14 246 190 14 241 196 14 226 184 13
48488- 61 42 6 2 2 6 2 2 6 2 2 6
48489- 22 22 22 238 238 238 253 253 253 253 253 253
48490-253 253 253 253 253 253 253 253 253 253 253 253
48491-253 253 253 253 253 253 253 253 253 253 253 253
48492-253 253 253 253 253 253 253 253 253 253 253 253
48493-253 253 253 226 226 226 187 187 187 180 133 36
48494-216 158 10 236 178 12 239 182 13 236 178 12
48495-230 174 11 226 170 11 226 170 11 230 174 11
48496-236 178 12 242 186 14 246 190 14 246 190 14
48497-246 190 14 246 190 14 246 186 14 239 182 13
48498-206 162 42 106 106 106 66 66 66 34 34 34
48499- 14 14 14 6 6 6 0 0 0 0 0 0
48500- 0 0 0 0 0 0 0 0 0 0 0 0
48501- 0 0 0 0 0 0 0 0 0 0 0 0
48502- 0 0 0 0 0 0 0 0 0 6 6 6
48503- 26 26 26 70 70 70 163 133 67 213 154 11
48504-236 178 12 246 190 14 246 190 14 246 190 14
48505-246 190 14 246 190 14 246 190 14 246 190 14
48506-246 190 14 246 190 14 246 190 14 246 190 14
48507-246 190 14 246 190 14 246 190 14 241 196 14
48508-190 146 13 18 14 6 2 2 6 2 2 6
48509- 46 46 46 246 246 246 253 253 253 253 253 253
48510-253 253 253 253 253 253 253 253 253 253 253 253
48511-253 253 253 253 253 253 253 253 253 253 253 253
48512-253 253 253 253 253 253 253 253 253 253 253 253
48513-253 253 253 221 221 221 86 86 86 156 107 11
48514-216 158 10 236 178 12 242 186 14 246 186 14
48515-242 186 14 239 182 13 239 182 13 242 186 14
48516-242 186 14 246 186 14 246 190 14 246 190 14
48517-246 190 14 246 190 14 246 190 14 246 190 14
48518-242 186 14 225 175 15 142 122 72 66 66 66
48519- 30 30 30 10 10 10 0 0 0 0 0 0
48520- 0 0 0 0 0 0 0 0 0 0 0 0
48521- 0 0 0 0 0 0 0 0 0 0 0 0
48522- 0 0 0 0 0 0 0 0 0 6 6 6
48523- 26 26 26 70 70 70 163 133 67 210 150 10
48524-236 178 12 246 190 14 246 190 14 246 190 14
48525-246 190 14 246 190 14 246 190 14 246 190 14
48526-246 190 14 246 190 14 246 190 14 246 190 14
48527-246 190 14 246 190 14 246 190 14 246 190 14
48528-232 195 16 121 92 8 34 34 34 106 106 106
48529-221 221 221 253 253 253 253 253 253 253 253 253
48530-253 253 253 253 253 253 253 253 253 253 253 253
48531-253 253 253 253 253 253 253 253 253 253 253 253
48532-253 253 253 253 253 253 253 253 253 253 253 253
48533-242 242 242 82 82 82 18 14 6 163 110 8
48534-216 158 10 236 178 12 242 186 14 246 190 14
48535-246 190 14 246 190 14 246 190 14 246 190 14
48536-246 190 14 246 190 14 246 190 14 246 190 14
48537-246 190 14 246 190 14 246 190 14 246 190 14
48538-246 190 14 246 190 14 242 186 14 163 133 67
48539- 46 46 46 18 18 18 6 6 6 0 0 0
48540- 0 0 0 0 0 0 0 0 0 0 0 0
48541- 0 0 0 0 0 0 0 0 0 0 0 0
48542- 0 0 0 0 0 0 0 0 0 10 10 10
48543- 30 30 30 78 78 78 163 133 67 210 150 10
48544-236 178 12 246 186 14 246 190 14 246 190 14
48545-246 190 14 246 190 14 246 190 14 246 190 14
48546-246 190 14 246 190 14 246 190 14 246 190 14
48547-246 190 14 246 190 14 246 190 14 246 190 14
48548-241 196 14 215 174 15 190 178 144 253 253 253
48549-253 253 253 253 253 253 253 253 253 253 253 253
48550-253 253 253 253 253 253 253 253 253 253 253 253
48551-253 253 253 253 253 253 253 253 253 253 253 253
48552-253 253 253 253 253 253 253 253 253 218 218 218
48553- 58 58 58 2 2 6 22 18 6 167 114 7
48554-216 158 10 236 178 12 246 186 14 246 190 14
48555-246 190 14 246 190 14 246 190 14 246 190 14
48556-246 190 14 246 190 14 246 190 14 246 190 14
48557-246 190 14 246 190 14 246 190 14 246 190 14
48558-246 190 14 246 186 14 242 186 14 190 150 46
48559- 54 54 54 22 22 22 6 6 6 0 0 0
48560- 0 0 0 0 0 0 0 0 0 0 0 0
48561- 0 0 0 0 0 0 0 0 0 0 0 0
48562- 0 0 0 0 0 0 0 0 0 14 14 14
48563- 38 38 38 86 86 86 180 133 36 213 154 11
48564-236 178 12 246 186 14 246 190 14 246 190 14
48565-246 190 14 246 190 14 246 190 14 246 190 14
48566-246 190 14 246 190 14 246 190 14 246 190 14
48567-246 190 14 246 190 14 246 190 14 246 190 14
48568-246 190 14 232 195 16 190 146 13 214 214 214
48569-253 253 253 253 253 253 253 253 253 253 253 253
48570-253 253 253 253 253 253 253 253 253 253 253 253
48571-253 253 253 253 253 253 253 253 253 253 253 253
48572-253 253 253 250 250 250 170 170 170 26 26 26
48573- 2 2 6 2 2 6 37 26 9 163 110 8
48574-219 162 10 239 182 13 246 186 14 246 190 14
48575-246 190 14 246 190 14 246 190 14 246 190 14
48576-246 190 14 246 190 14 246 190 14 246 190 14
48577-246 190 14 246 190 14 246 190 14 246 190 14
48578-246 186 14 236 178 12 224 166 10 142 122 72
48579- 46 46 46 18 18 18 6 6 6 0 0 0
48580- 0 0 0 0 0 0 0 0 0 0 0 0
48581- 0 0 0 0 0 0 0 0 0 0 0 0
48582- 0 0 0 0 0 0 6 6 6 18 18 18
48583- 50 50 50 109 106 95 192 133 9 224 166 10
48584-242 186 14 246 190 14 246 190 14 246 190 14
48585-246 190 14 246 190 14 246 190 14 246 190 14
48586-246 190 14 246 190 14 246 190 14 246 190 14
48587-246 190 14 246 190 14 246 190 14 246 190 14
48588-242 186 14 226 184 13 210 162 10 142 110 46
48589-226 226 226 253 253 253 253 253 253 253 253 253
48590-253 253 253 253 253 253 253 253 253 253 253 253
48591-253 253 253 253 253 253 253 253 253 253 253 253
48592-198 198 198 66 66 66 2 2 6 2 2 6
48593- 2 2 6 2 2 6 50 34 6 156 107 11
48594-219 162 10 239 182 13 246 186 14 246 190 14
48595-246 190 14 246 190 14 246 190 14 246 190 14
48596-246 190 14 246 190 14 246 190 14 246 190 14
48597-246 190 14 246 190 14 246 190 14 242 186 14
48598-234 174 13 213 154 11 154 122 46 66 66 66
48599- 30 30 30 10 10 10 0 0 0 0 0 0
48600- 0 0 0 0 0 0 0 0 0 0 0 0
48601- 0 0 0 0 0 0 0 0 0 0 0 0
48602- 0 0 0 0 0 0 6 6 6 22 22 22
48603- 58 58 58 154 121 60 206 145 10 234 174 13
48604-242 186 14 246 186 14 246 190 14 246 190 14
48605-246 190 14 246 190 14 246 190 14 246 190 14
48606-246 190 14 246 190 14 246 190 14 246 190 14
48607-246 190 14 246 190 14 246 190 14 246 190 14
48608-246 186 14 236 178 12 210 162 10 163 110 8
48609- 61 42 6 138 138 138 218 218 218 250 250 250
48610-253 253 253 253 253 253 253 253 253 250 250 250
48611-242 242 242 210 210 210 144 144 144 66 66 66
48612- 6 6 6 2 2 6 2 2 6 2 2 6
48613- 2 2 6 2 2 6 61 42 6 163 110 8
48614-216 158 10 236 178 12 246 190 14 246 190 14
48615-246 190 14 246 190 14 246 190 14 246 190 14
48616-246 190 14 246 190 14 246 190 14 246 190 14
48617-246 190 14 239 182 13 230 174 11 216 158 10
48618-190 142 34 124 112 88 70 70 70 38 38 38
48619- 18 18 18 6 6 6 0 0 0 0 0 0
48620- 0 0 0 0 0 0 0 0 0 0 0 0
48621- 0 0 0 0 0 0 0 0 0 0 0 0
48622- 0 0 0 0 0 0 6 6 6 22 22 22
48623- 62 62 62 168 124 44 206 145 10 224 166 10
48624-236 178 12 239 182 13 242 186 14 242 186 14
48625-246 186 14 246 190 14 246 190 14 246 190 14
48626-246 190 14 246 190 14 246 190 14 246 190 14
48627-246 190 14 246 190 14 246 190 14 246 190 14
48628-246 190 14 236 178 12 216 158 10 175 118 6
48629- 80 54 7 2 2 6 6 6 6 30 30 30
48630- 54 54 54 62 62 62 50 50 50 38 38 38
48631- 14 14 14 2 2 6 2 2 6 2 2 6
48632- 2 2 6 2 2 6 2 2 6 2 2 6
48633- 2 2 6 6 6 6 80 54 7 167 114 7
48634-213 154 11 236 178 12 246 190 14 246 190 14
48635-246 190 14 246 190 14 246 190 14 246 190 14
48636-246 190 14 242 186 14 239 182 13 239 182 13
48637-230 174 11 210 150 10 174 135 50 124 112 88
48638- 82 82 82 54 54 54 34 34 34 18 18 18
48639- 6 6 6 0 0 0 0 0 0 0 0 0
48640- 0 0 0 0 0 0 0 0 0 0 0 0
48641- 0 0 0 0 0 0 0 0 0 0 0 0
48642- 0 0 0 0 0 0 6 6 6 18 18 18
48643- 50 50 50 158 118 36 192 133 9 200 144 11
48644-216 158 10 219 162 10 224 166 10 226 170 11
48645-230 174 11 236 178 12 239 182 13 239 182 13
48646-242 186 14 246 186 14 246 190 14 246 190 14
48647-246 190 14 246 190 14 246 190 14 246 190 14
48648-246 186 14 230 174 11 210 150 10 163 110 8
48649-104 69 6 10 10 10 2 2 6 2 2 6
48650- 2 2 6 2 2 6 2 2 6 2 2 6
48651- 2 2 6 2 2 6 2 2 6 2 2 6
48652- 2 2 6 2 2 6 2 2 6 2 2 6
48653- 2 2 6 6 6 6 91 60 6 167 114 7
48654-206 145 10 230 174 11 242 186 14 246 190 14
48655-246 190 14 246 190 14 246 186 14 242 186 14
48656-239 182 13 230 174 11 224 166 10 213 154 11
48657-180 133 36 124 112 88 86 86 86 58 58 58
48658- 38 38 38 22 22 22 10 10 10 6 6 6
48659- 0 0 0 0 0 0 0 0 0 0 0 0
48660- 0 0 0 0 0 0 0 0 0 0 0 0
48661- 0 0 0 0 0 0 0 0 0 0 0 0
48662- 0 0 0 0 0 0 0 0 0 14 14 14
48663- 34 34 34 70 70 70 138 110 50 158 118 36
48664-167 114 7 180 123 7 192 133 9 197 138 11
48665-200 144 11 206 145 10 213 154 11 219 162 10
48666-224 166 10 230 174 11 239 182 13 242 186 14
48667-246 186 14 246 186 14 246 186 14 246 186 14
48668-239 182 13 216 158 10 185 133 11 152 99 6
48669-104 69 6 18 14 6 2 2 6 2 2 6
48670- 2 2 6 2 2 6 2 2 6 2 2 6
48671- 2 2 6 2 2 6 2 2 6 2 2 6
48672- 2 2 6 2 2 6 2 2 6 2 2 6
48673- 2 2 6 6 6 6 80 54 7 152 99 6
48674-192 133 9 219 162 10 236 178 12 239 182 13
48675-246 186 14 242 186 14 239 182 13 236 178 12
48676-224 166 10 206 145 10 192 133 9 154 121 60
48677- 94 94 94 62 62 62 42 42 42 22 22 22
48678- 14 14 14 6 6 6 0 0 0 0 0 0
48679- 0 0 0 0 0 0 0 0 0 0 0 0
48680- 0 0 0 0 0 0 0 0 0 0 0 0
48681- 0 0 0 0 0 0 0 0 0 0 0 0
48682- 0 0 0 0 0 0 0 0 0 6 6 6
48683- 18 18 18 34 34 34 58 58 58 78 78 78
48684-101 98 89 124 112 88 142 110 46 156 107 11
48685-163 110 8 167 114 7 175 118 6 180 123 7
48686-185 133 11 197 138 11 210 150 10 219 162 10
48687-226 170 11 236 178 12 236 178 12 234 174 13
48688-219 162 10 197 138 11 163 110 8 130 83 6
48689- 91 60 6 10 10 10 2 2 6 2 2 6
48690- 18 18 18 38 38 38 38 38 38 38 38 38
48691- 38 38 38 38 38 38 38 38 38 38 38 38
48692- 38 38 38 38 38 38 26 26 26 2 2 6
48693- 2 2 6 6 6 6 70 47 6 137 92 6
48694-175 118 6 200 144 11 219 162 10 230 174 11
48695-234 174 13 230 174 11 219 162 10 210 150 10
48696-192 133 9 163 110 8 124 112 88 82 82 82
48697- 50 50 50 30 30 30 14 14 14 6 6 6
48698- 0 0 0 0 0 0 0 0 0 0 0 0
48699- 0 0 0 0 0 0 0 0 0 0 0 0
48700- 0 0 0 0 0 0 0 0 0 0 0 0
48701- 0 0 0 0 0 0 0 0 0 0 0 0
48702- 0 0 0 0 0 0 0 0 0 0 0 0
48703- 6 6 6 14 14 14 22 22 22 34 34 34
48704- 42 42 42 58 58 58 74 74 74 86 86 86
48705-101 98 89 122 102 70 130 98 46 121 87 25
48706-137 92 6 152 99 6 163 110 8 180 123 7
48707-185 133 11 197 138 11 206 145 10 200 144 11
48708-180 123 7 156 107 11 130 83 6 104 69 6
48709- 50 34 6 54 54 54 110 110 110 101 98 89
48710- 86 86 86 82 82 82 78 78 78 78 78 78
48711- 78 78 78 78 78 78 78 78 78 78 78 78
48712- 78 78 78 82 82 82 86 86 86 94 94 94
48713-106 106 106 101 101 101 86 66 34 124 80 6
48714-156 107 11 180 123 7 192 133 9 200 144 11
48715-206 145 10 200 144 11 192 133 9 175 118 6
48716-139 102 15 109 106 95 70 70 70 42 42 42
48717- 22 22 22 10 10 10 0 0 0 0 0 0
48718- 0 0 0 0 0 0 0 0 0 0 0 0
48719- 0 0 0 0 0 0 0 0 0 0 0 0
48720- 0 0 0 0 0 0 0 0 0 0 0 0
48721- 0 0 0 0 0 0 0 0 0 0 0 0
48722- 0 0 0 0 0 0 0 0 0 0 0 0
48723- 0 0 0 0 0 0 6 6 6 10 10 10
48724- 14 14 14 22 22 22 30 30 30 38 38 38
48725- 50 50 50 62 62 62 74 74 74 90 90 90
48726-101 98 89 112 100 78 121 87 25 124 80 6
48727-137 92 6 152 99 6 152 99 6 152 99 6
48728-138 86 6 124 80 6 98 70 6 86 66 30
48729-101 98 89 82 82 82 58 58 58 46 46 46
48730- 38 38 38 34 34 34 34 34 34 34 34 34
48731- 34 34 34 34 34 34 34 34 34 34 34 34
48732- 34 34 34 34 34 34 38 38 38 42 42 42
48733- 54 54 54 82 82 82 94 86 76 91 60 6
48734-134 86 6 156 107 11 167 114 7 175 118 6
48735-175 118 6 167 114 7 152 99 6 121 87 25
48736-101 98 89 62 62 62 34 34 34 18 18 18
48737- 6 6 6 0 0 0 0 0 0 0 0 0
48738- 0 0 0 0 0 0 0 0 0 0 0 0
48739- 0 0 0 0 0 0 0 0 0 0 0 0
48740- 0 0 0 0 0 0 0 0 0 0 0 0
48741- 0 0 0 0 0 0 0 0 0 0 0 0
48742- 0 0 0 0 0 0 0 0 0 0 0 0
48743- 0 0 0 0 0 0 0 0 0 0 0 0
48744- 0 0 0 6 6 6 6 6 6 10 10 10
48745- 18 18 18 22 22 22 30 30 30 42 42 42
48746- 50 50 50 66 66 66 86 86 86 101 98 89
48747-106 86 58 98 70 6 104 69 6 104 69 6
48748-104 69 6 91 60 6 82 62 34 90 90 90
48749- 62 62 62 38 38 38 22 22 22 14 14 14
48750- 10 10 10 10 10 10 10 10 10 10 10 10
48751- 10 10 10 10 10 10 6 6 6 10 10 10
48752- 10 10 10 10 10 10 10 10 10 14 14 14
48753- 22 22 22 42 42 42 70 70 70 89 81 66
48754- 80 54 7 104 69 6 124 80 6 137 92 6
48755-134 86 6 116 81 8 100 82 52 86 86 86
48756- 58 58 58 30 30 30 14 14 14 6 6 6
48757- 0 0 0 0 0 0 0 0 0 0 0 0
48758- 0 0 0 0 0 0 0 0 0 0 0 0
48759- 0 0 0 0 0 0 0 0 0 0 0 0
48760- 0 0 0 0 0 0 0 0 0 0 0 0
48761- 0 0 0 0 0 0 0 0 0 0 0 0
48762- 0 0 0 0 0 0 0 0 0 0 0 0
48763- 0 0 0 0 0 0 0 0 0 0 0 0
48764- 0 0 0 0 0 0 0 0 0 0 0 0
48765- 0 0 0 6 6 6 10 10 10 14 14 14
48766- 18 18 18 26 26 26 38 38 38 54 54 54
48767- 70 70 70 86 86 86 94 86 76 89 81 66
48768- 89 81 66 86 86 86 74 74 74 50 50 50
48769- 30 30 30 14 14 14 6 6 6 0 0 0
48770- 0 0 0 0 0 0 0 0 0 0 0 0
48771- 0 0 0 0 0 0 0 0 0 0 0 0
48772- 0 0 0 0 0 0 0 0 0 0 0 0
48773- 6 6 6 18 18 18 34 34 34 58 58 58
48774- 82 82 82 89 81 66 89 81 66 89 81 66
48775- 94 86 66 94 86 76 74 74 74 50 50 50
48776- 26 26 26 14 14 14 6 6 6 0 0 0
48777- 0 0 0 0 0 0 0 0 0 0 0 0
48778- 0 0 0 0 0 0 0 0 0 0 0 0
48779- 0 0 0 0 0 0 0 0 0 0 0 0
48780- 0 0 0 0 0 0 0 0 0 0 0 0
48781- 0 0 0 0 0 0 0 0 0 0 0 0
48782- 0 0 0 0 0 0 0 0 0 0 0 0
48783- 0 0 0 0 0 0 0 0 0 0 0 0
48784- 0 0 0 0 0 0 0 0 0 0 0 0
48785- 0 0 0 0 0 0 0 0 0 0 0 0
48786- 6 6 6 6 6 6 14 14 14 18 18 18
48787- 30 30 30 38 38 38 46 46 46 54 54 54
48788- 50 50 50 42 42 42 30 30 30 18 18 18
48789- 10 10 10 0 0 0 0 0 0 0 0 0
48790- 0 0 0 0 0 0 0 0 0 0 0 0
48791- 0 0 0 0 0 0 0 0 0 0 0 0
48792- 0 0 0 0 0 0 0 0 0 0 0 0
48793- 0 0 0 6 6 6 14 14 14 26 26 26
48794- 38 38 38 50 50 50 58 58 58 58 58 58
48795- 54 54 54 42 42 42 30 30 30 18 18 18
48796- 10 10 10 0 0 0 0 0 0 0 0 0
48797- 0 0 0 0 0 0 0 0 0 0 0 0
48798- 0 0 0 0 0 0 0 0 0 0 0 0
48799- 0 0 0 0 0 0 0 0 0 0 0 0
48800- 0 0 0 0 0 0 0 0 0 0 0 0
48801- 0 0 0 0 0 0 0 0 0 0 0 0
48802- 0 0 0 0 0 0 0 0 0 0 0 0
48803- 0 0 0 0 0 0 0 0 0 0 0 0
48804- 0 0 0 0 0 0 0 0 0 0 0 0
48805- 0 0 0 0 0 0 0 0 0 0 0 0
48806- 0 0 0 0 0 0 0 0 0 6 6 6
48807- 6 6 6 10 10 10 14 14 14 18 18 18
48808- 18 18 18 14 14 14 10 10 10 6 6 6
48809- 0 0 0 0 0 0 0 0 0 0 0 0
48810- 0 0 0 0 0 0 0 0 0 0 0 0
48811- 0 0 0 0 0 0 0 0 0 0 0 0
48812- 0 0 0 0 0 0 0 0 0 0 0 0
48813- 0 0 0 0 0 0 0 0 0 6 6 6
48814- 14 14 14 18 18 18 22 22 22 22 22 22
48815- 18 18 18 14 14 14 10 10 10 6 6 6
48816- 0 0 0 0 0 0 0 0 0 0 0 0
48817- 0 0 0 0 0 0 0 0 0 0 0 0
48818- 0 0 0 0 0 0 0 0 0 0 0 0
48819- 0 0 0 0 0 0 0 0 0 0 0 0
48820- 0 0 0 0 0 0 0 0 0 0 0 0
48821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48834+4 4 4 4 4 4
48835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48848+4 4 4 4 4 4
48849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48862+4 4 4 4 4 4
48863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48876+4 4 4 4 4 4
48877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48890+4 4 4 4 4 4
48891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48904+4 4 4 4 4 4
48905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48909+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
48910+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
48911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48914+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
48915+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
48916+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
48917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48918+4 4 4 4 4 4
48919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48923+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
48924+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
48925+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48928+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
48929+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
48930+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
48931+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48932+4 4 4 4 4 4
48933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48937+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
48938+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
48939+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
48940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48942+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
48943+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
48944+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
48945+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
48946+4 4 4 4 4 4
48947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48950+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
48951+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
48952+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
48953+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
48954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48955+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
48956+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
48957+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
48958+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
48959+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
48960+4 4 4 4 4 4
48961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48964+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
48965+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
48966+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
48967+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
48968+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
48969+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
48970+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
48971+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
48972+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
48973+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
48974+4 4 4 4 4 4
48975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
48978+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
48979+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
48980+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
48981+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
48982+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
48983+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
48984+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
48985+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
48986+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
48987+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
48988+4 4 4 4 4 4
48989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
48991+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
48992+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
48993+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
48994+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
48995+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
48996+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
48997+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
48998+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
48999+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
49000+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
49001+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
49002+4 4 4 4 4 4
49003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49005+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
49006+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
49007+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
49008+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
49009+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
49010+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
49011+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
49012+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
49013+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
49014+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
49015+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
49016+4 4 4 4 4 4
49017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49019+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
49020+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
49021+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
49022+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
49023+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
49024+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
49025+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
49026+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
49027+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
49028+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
49029+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
49030+4 4 4 4 4 4
49031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49033+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
49034+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
49035+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
49036+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
49037+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
49038+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
49039+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
49040+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
49041+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
49042+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
49043+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
49044+4 4 4 4 4 4
49045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49046+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
49047+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
49048+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
49049+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
49050+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
49051+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
49052+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
49053+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
49054+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
49055+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
49056+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
49057+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
49058+4 4 4 4 4 4
49059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49060+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
49061+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
49062+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
49063+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
49064+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
49065+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
49066+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
49067+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
49068+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
49069+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
49070+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
49071+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
49072+0 0 0 4 4 4
49073+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
49074+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
49075+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
49076+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
49077+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
49078+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
49079+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
49080+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
49081+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
49082+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
49083+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
49084+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
49085+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
49086+2 0 0 0 0 0
49087+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
49088+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
49089+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
49090+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
49091+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
49092+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
49093+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
49094+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
49095+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
49096+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
49097+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
49098+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
49099+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
49100+37 38 37 0 0 0
49101+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
49102+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
49103+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
49104+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
49105+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
49106+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
49107+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
49108+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
49109+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
49110+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
49111+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
49112+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
49113+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
49114+85 115 134 4 0 0
49115+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
49116+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
49117+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
49118+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
49119+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
49120+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
49121+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
49122+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
49123+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
49124+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
49125+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
49126+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
49127+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
49128+60 73 81 4 0 0
49129+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
49130+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
49131+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
49132+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
49133+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
49134+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
49135+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
49136+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
49137+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
49138+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
49139+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
49140+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
49141+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
49142+16 19 21 4 0 0
49143+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
49144+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
49145+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
49146+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
49147+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
49148+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
49149+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
49150+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
49151+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
49152+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
49153+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
49154+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
49155+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
49156+4 0 0 4 3 3
49157+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
49158+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
49159+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
49160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
49161+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
49162+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
49163+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
49164+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
49165+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
49166+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
49167+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
49168+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
49169+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
49170+3 2 2 4 4 4
49171+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
49172+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
49173+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
49174+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
49175+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
49176+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
49177+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49178+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
49179+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
49180+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
49181+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
49182+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
49183+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
49184+4 4 4 4 4 4
49185+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
49186+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
49187+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
49188+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
49189+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
49190+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
49191+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
49192+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
49193+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
49194+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
49195+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
49196+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
49197+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
49198+4 4 4 4 4 4
49199+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
49200+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
49201+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
49202+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
49203+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
49204+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
49205+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
49206+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
49207+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
49208+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
49209+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
49210+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
49211+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
49212+5 5 5 5 5 5
49213+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
49214+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
49215+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
49216+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
49217+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
49218+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
49219+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
49220+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
49221+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
49222+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
49223+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
49224+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
49225+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
49226+5 5 5 4 4 4
49227+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
49228+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
49229+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
49230+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
49231+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
49232+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
49233+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
49234+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
49235+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
49236+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
49237+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
49238+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
49239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49240+4 4 4 4 4 4
49241+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
49242+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
49243+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
49244+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
49245+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
49246+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
49247+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
49248+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
49249+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
49250+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
49251+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
49252+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
49253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49254+4 4 4 4 4 4
49255+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
49256+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
49257+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
49258+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
49259+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
49260+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
49261+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
49262+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
49263+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
49264+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
49265+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
49266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49268+4 4 4 4 4 4
49269+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
49270+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
49271+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
49272+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
49273+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
49274+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
49275+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
49276+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
49277+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
49278+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
49279+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
49280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49282+4 4 4 4 4 4
49283+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
49284+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
49285+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
49286+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
49287+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
49288+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
49289+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
49290+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
49291+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
49292+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
49293+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49296+4 4 4 4 4 4
49297+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
49298+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
49299+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
49300+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
49301+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
49302+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
49303+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
49304+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
49305+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
49306+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
49307+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
49308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49310+4 4 4 4 4 4
49311+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
49312+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
49313+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
49314+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
49315+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
49316+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
49317+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
49318+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
49319+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
49320+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
49321+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
49322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49324+4 4 4 4 4 4
49325+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
49326+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
49327+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
49328+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
49329+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
49330+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
49331+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
49332+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
49333+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
49334+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
49335+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49338+4 4 4 4 4 4
49339+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
49340+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
49341+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
49342+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
49343+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49344+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
49345+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
49346+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
49347+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
49348+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
49349+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49352+4 4 4 4 4 4
49353+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
49354+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
49355+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
49356+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
49357+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49358+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
49359+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
49360+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
49361+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
49362+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
49363+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49366+4 4 4 4 4 4
49367+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
49368+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
49369+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
49370+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
49371+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49372+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
49373+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
49374+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
49375+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
49376+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49377+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49380+4 4 4 4 4 4
49381+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
49382+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
49383+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
49384+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
49385+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
49386+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
49387+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
49388+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
49389+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
49390+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49391+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49394+4 4 4 4 4 4
49395+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
49396+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
49397+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
49398+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
49399+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49400+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
49401+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
49402+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
49403+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
49404+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49405+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49408+4 4 4 4 4 4
49409+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
49410+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
49411+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
49412+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
49413+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
49414+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
49415+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
49416+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
49417+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
49418+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49419+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49422+4 4 4 4 4 4
49423+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
49424+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
49425+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
49426+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
49427+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
49428+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
49429+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
49430+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
49431+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
49432+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49433+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49436+4 4 4 4 4 4
49437+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
49438+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
49439+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
49440+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
49441+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
49442+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
49443+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
49444+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
49445+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
49446+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49447+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49450+4 4 4 4 4 4
49451+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
49452+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
49453+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
49454+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
49455+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
49456+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
49457+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
49458+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
49459+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
49460+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49461+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49464+4 4 4 4 4 4
49465+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
49466+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
49467+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
49468+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
49469+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
49470+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
49471+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
49472+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
49473+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
49474+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49475+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49478+4 4 4 4 4 4
49479+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
49480+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
49481+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
49482+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
49483+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
49484+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
49485+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
49486+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
49487+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
49488+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49489+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49492+4 4 4 4 4 4
49493+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
49494+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
49495+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
49496+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
49497+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
49498+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
49499+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49500+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
49501+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
49502+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49503+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49506+4 4 4 4 4 4
49507+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
49508+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
49509+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
49510+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
49511+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
49512+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
49513+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
49514+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
49515+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
49516+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49517+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49520+4 4 4 4 4 4
49521+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
49522+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
49523+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
49524+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
49525+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
49526+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
49527+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
49528+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
49529+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
49530+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49531+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49534+4 4 4 4 4 4
49535+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
49536+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
49537+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
49538+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
49539+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
49540+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
49541+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
49542+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
49543+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
49544+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49545+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49548+4 4 4 4 4 4
49549+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
49550+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
49551+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
49552+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
49553+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
49554+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
49555+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
49556+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
49557+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
49558+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49559+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49562+4 4 4 4 4 4
49563+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
49564+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
49565+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
49566+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
49567+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
49568+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
49569+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
49570+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
49571+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
49572+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
49573+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49576+4 4 4 4 4 4
49577+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
49578+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
49579+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
49580+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
49581+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
49582+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
49583+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
49584+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
49585+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
49586+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
49587+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49590+4 4 4 4 4 4
49591+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
49592+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
49593+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
49594+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
49595+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
49596+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
49597+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
49598+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
49599+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
49600+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
49601+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49604+4 4 4 4 4 4
49605+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
49606+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
49607+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
49608+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
49609+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
49610+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
49611+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49612+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
49613+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
49614+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
49615+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
49616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49618+4 4 4 4 4 4
49619+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
49620+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
49621+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
49622+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
49623+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
49624+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
49625+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
49626+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
49627+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
49628+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
49629+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49632+4 4 4 4 4 4
49633+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
49634+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
49635+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
49636+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
49637+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
49638+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
49639+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
49640+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
49641+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
49642+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
49643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49646+4 4 4 4 4 4
49647+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
49648+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
49649+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
49650+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
49651+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
49652+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
49653+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
49654+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
49655+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
49656+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
49657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49660+4 4 4 4 4 4
49661+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
49662+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
49663+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
49664+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
49665+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
49666+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
49667+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
49668+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
49669+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
49670+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
49671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49674+4 4 4 4 4 4
49675+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
49676+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
49677+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
49678+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
49679+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
49680+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
49681+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
49682+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
49683+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
49684+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
49685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49688+4 4 4 4 4 4
49689+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
49690+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
49691+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
49692+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
49693+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
49694+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
49695+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
49696+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
49697+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
49698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49702+4 4 4 4 4 4
49703+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
49704+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
49705+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
49706+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
49707+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
49708+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
49709+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
49710+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
49711+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
49712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49716+4 4 4 4 4 4
49717+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
49718+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
49719+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
49720+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
49721+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
49722+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
49723+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
49724+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
49725+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49730+4 4 4 4 4 4
49731+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
49732+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
49733+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
49734+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
49735+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
49736+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
49737+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
49738+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
49739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49744+4 4 4 4 4 4
49745+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
49746+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
49747+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
49748+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
49749+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
49750+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
49751+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
49752+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
49753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49758+4 4 4 4 4 4
49759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
49760+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
49761+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
49762+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
49763+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
49764+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
49765+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
49766+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
49767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49772+4 4 4 4 4 4
49773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49774+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
49775+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
49776+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
49777+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
49778+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
49779+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
49780+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
49781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49786+4 4 4 4 4 4
49787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49788+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
49789+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
49790+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
49791+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
49792+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
49793+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
49794+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
49795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49800+4 4 4 4 4 4
49801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49803+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
49804+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
49805+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
49806+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
49807+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
49808+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
49809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49814+4 4 4 4 4 4
49815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
49818+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
49819+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
49820+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
49821+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
49822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49828+4 4 4 4 4 4
49829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49832+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
49833+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
49834+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
49835+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
49836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49842+4 4 4 4 4 4
49843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49846+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
49847+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
49848+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
49849+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
49850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49856+4 4 4 4 4 4
49857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49860+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
49861+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
49862+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
49863+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
49864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49870+4 4 4 4 4 4
49871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
49875+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
49876+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
49877+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
49878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49884+4 4 4 4 4 4
49885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49889+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
49890+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
49891+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
49892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49898+4 4 4 4 4 4
49899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49903+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
49904+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
49905+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49912+4 4 4 4 4 4
49913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49917+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
49918+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
49919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49926+4 4 4 4 4 4
49927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49931+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
49932+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
49933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
49940+4 4 4 4 4 4
49941diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
49942index fe92eed..106e085 100644
49943--- a/drivers/video/mb862xx/mb862xxfb_accel.c
49944+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
49945@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
49946 struct mb862xxfb_par *par = info->par;
49947
49948 if (info->var.bits_per_pixel == 32) {
49949- info->fbops->fb_fillrect = cfb_fillrect;
49950- info->fbops->fb_copyarea = cfb_copyarea;
49951- info->fbops->fb_imageblit = cfb_imageblit;
49952+ pax_open_kernel();
49953+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
49954+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
49955+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
49956+ pax_close_kernel();
49957 } else {
49958 outreg(disp, GC_L0EM, 3);
49959- info->fbops->fb_fillrect = mb86290fb_fillrect;
49960- info->fbops->fb_copyarea = mb86290fb_copyarea;
49961- info->fbops->fb_imageblit = mb86290fb_imageblit;
49962+ pax_open_kernel();
49963+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
49964+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
49965+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
49966+ pax_close_kernel();
49967 }
49968 outreg(draw, GDC_REG_DRAW_BASE, 0);
49969 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
49970diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
49971index ff22871..b129bed 100644
49972--- a/drivers/video/nvidia/nvidia.c
49973+++ b/drivers/video/nvidia/nvidia.c
49974@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
49975 info->fix.line_length = (info->var.xres_virtual *
49976 info->var.bits_per_pixel) >> 3;
49977 if (info->var.accel_flags) {
49978- info->fbops->fb_imageblit = nvidiafb_imageblit;
49979- info->fbops->fb_fillrect = nvidiafb_fillrect;
49980- info->fbops->fb_copyarea = nvidiafb_copyarea;
49981- info->fbops->fb_sync = nvidiafb_sync;
49982+ pax_open_kernel();
49983+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
49984+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
49985+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
49986+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
49987+ pax_close_kernel();
49988 info->pixmap.scan_align = 4;
49989 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49990 info->flags |= FBINFO_READS_FAST;
49991 NVResetGraphics(info);
49992 } else {
49993- info->fbops->fb_imageblit = cfb_imageblit;
49994- info->fbops->fb_fillrect = cfb_fillrect;
49995- info->fbops->fb_copyarea = cfb_copyarea;
49996- info->fbops->fb_sync = NULL;
49997+ pax_open_kernel();
49998+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
49999+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
50000+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
50001+ *(void **)&info->fbops->fb_sync = NULL;
50002+ pax_close_kernel();
50003 info->pixmap.scan_align = 1;
50004 info->flags |= FBINFO_HWACCEL_DISABLED;
50005 info->flags &= ~FBINFO_READS_FAST;
50006@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
50007 info->pixmap.size = 8 * 1024;
50008 info->pixmap.flags = FB_PIXMAP_SYSTEM;
50009
50010- if (!hwcur)
50011- info->fbops->fb_cursor = NULL;
50012+ if (!hwcur) {
50013+ pax_open_kernel();
50014+ *(void **)&info->fbops->fb_cursor = NULL;
50015+ pax_close_kernel();
50016+ }
50017
50018 info->var.accel_flags = (!noaccel);
50019
50020diff --git a/drivers/video/output.c b/drivers/video/output.c
50021index 0d6f2cd..6285b97 100644
50022--- a/drivers/video/output.c
50023+++ b/drivers/video/output.c
50024@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
50025 new_dev->props = op;
50026 new_dev->dev.class = &video_output_class;
50027 new_dev->dev.parent = dev;
50028- dev_set_name(&new_dev->dev, name);
50029+ dev_set_name(&new_dev->dev, "%s", name);
50030 dev_set_drvdata(&new_dev->dev, devdata);
50031 ret_code = device_register(&new_dev->dev);
50032 if (ret_code) {
50033diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
50034index 05c2dc3..ea1f391 100644
50035--- a/drivers/video/s1d13xxxfb.c
50036+++ b/drivers/video/s1d13xxxfb.c
50037@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
50038
50039 switch(prod_id) {
50040 case S1D13506_PROD_ID: /* activate acceleration */
50041- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
50042- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
50043+ pax_open_kernel();
50044+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
50045+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
50046+ pax_close_kernel();
50047 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
50048 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
50049 break;
50050diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
50051index b2b33fc..f9f4658 100644
50052--- a/drivers/video/smscufx.c
50053+++ b/drivers/video/smscufx.c
50054@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
50055 fb_deferred_io_cleanup(info);
50056 kfree(info->fbdefio);
50057 info->fbdefio = NULL;
50058- info->fbops->fb_mmap = ufx_ops_mmap;
50059+ pax_open_kernel();
50060+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
50061+ pax_close_kernel();
50062 }
50063
50064 pr_debug("released /dev/fb%d user=%d count=%d",
50065diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
50066index ec03e72..f578436 100644
50067--- a/drivers/video/udlfb.c
50068+++ b/drivers/video/udlfb.c
50069@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
50070 dlfb_urb_completion(urb);
50071
50072 error:
50073- atomic_add(bytes_sent, &dev->bytes_sent);
50074- atomic_add(bytes_identical, &dev->bytes_identical);
50075- atomic_add(width*height*2, &dev->bytes_rendered);
50076+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
50077+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
50078+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
50079 end_cycles = get_cycles();
50080- atomic_add(((unsigned int) ((end_cycles - start_cycles)
50081+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
50082 >> 10)), /* Kcycles */
50083 &dev->cpu_kcycles_used);
50084
50085@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
50086 dlfb_urb_completion(urb);
50087
50088 error:
50089- atomic_add(bytes_sent, &dev->bytes_sent);
50090- atomic_add(bytes_identical, &dev->bytes_identical);
50091- atomic_add(bytes_rendered, &dev->bytes_rendered);
50092+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
50093+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
50094+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
50095 end_cycles = get_cycles();
50096- atomic_add(((unsigned int) ((end_cycles - start_cycles)
50097+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
50098 >> 10)), /* Kcycles */
50099 &dev->cpu_kcycles_used);
50100 }
50101@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
50102 fb_deferred_io_cleanup(info);
50103 kfree(info->fbdefio);
50104 info->fbdefio = NULL;
50105- info->fbops->fb_mmap = dlfb_ops_mmap;
50106+ pax_open_kernel();
50107+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
50108+ pax_close_kernel();
50109 }
50110
50111 pr_warn("released /dev/fb%d user=%d count=%d\n",
50112@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
50113 struct fb_info *fb_info = dev_get_drvdata(fbdev);
50114 struct dlfb_data *dev = fb_info->par;
50115 return snprintf(buf, PAGE_SIZE, "%u\n",
50116- atomic_read(&dev->bytes_rendered));
50117+ atomic_read_unchecked(&dev->bytes_rendered));
50118 }
50119
50120 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
50121@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
50122 struct fb_info *fb_info = dev_get_drvdata(fbdev);
50123 struct dlfb_data *dev = fb_info->par;
50124 return snprintf(buf, PAGE_SIZE, "%u\n",
50125- atomic_read(&dev->bytes_identical));
50126+ atomic_read_unchecked(&dev->bytes_identical));
50127 }
50128
50129 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
50130@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
50131 struct fb_info *fb_info = dev_get_drvdata(fbdev);
50132 struct dlfb_data *dev = fb_info->par;
50133 return snprintf(buf, PAGE_SIZE, "%u\n",
50134- atomic_read(&dev->bytes_sent));
50135+ atomic_read_unchecked(&dev->bytes_sent));
50136 }
50137
50138 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
50139@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
50140 struct fb_info *fb_info = dev_get_drvdata(fbdev);
50141 struct dlfb_data *dev = fb_info->par;
50142 return snprintf(buf, PAGE_SIZE, "%u\n",
50143- atomic_read(&dev->cpu_kcycles_used));
50144+ atomic_read_unchecked(&dev->cpu_kcycles_used));
50145 }
50146
50147 static ssize_t edid_show(
50148@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
50149 struct fb_info *fb_info = dev_get_drvdata(fbdev);
50150 struct dlfb_data *dev = fb_info->par;
50151
50152- atomic_set(&dev->bytes_rendered, 0);
50153- atomic_set(&dev->bytes_identical, 0);
50154- atomic_set(&dev->bytes_sent, 0);
50155- atomic_set(&dev->cpu_kcycles_used, 0);
50156+ atomic_set_unchecked(&dev->bytes_rendered, 0);
50157+ atomic_set_unchecked(&dev->bytes_identical, 0);
50158+ atomic_set_unchecked(&dev->bytes_sent, 0);
50159+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
50160
50161 return count;
50162 }
50163diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
50164index e328a61..1b08ecb 100644
50165--- a/drivers/video/uvesafb.c
50166+++ b/drivers/video/uvesafb.c
50167@@ -19,6 +19,7 @@
50168 #include <linux/io.h>
50169 #include <linux/mutex.h>
50170 #include <linux/slab.h>
50171+#include <linux/moduleloader.h>
50172 #include <video/edid.h>
50173 #include <video/uvesafb.h>
50174 #ifdef CONFIG_X86
50175@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
50176 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
50177 par->pmi_setpal = par->ypan = 0;
50178 } else {
50179+
50180+#ifdef CONFIG_PAX_KERNEXEC
50181+#ifdef CONFIG_MODULES
50182+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
50183+#endif
50184+ if (!par->pmi_code) {
50185+ par->pmi_setpal = par->ypan = 0;
50186+ return 0;
50187+ }
50188+#endif
50189+
50190 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
50191 + task->t.regs.edi);
50192+
50193+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50194+ pax_open_kernel();
50195+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
50196+ pax_close_kernel();
50197+
50198+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
50199+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
50200+#else
50201 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
50202 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
50203+#endif
50204+
50205 printk(KERN_INFO "uvesafb: protected mode interface info at "
50206 "%04x:%04x\n",
50207 (u16)task->t.regs.es, (u16)task->t.regs.edi);
50208@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
50209 par->ypan = ypan;
50210
50211 if (par->pmi_setpal || par->ypan) {
50212+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
50213 if (__supported_pte_mask & _PAGE_NX) {
50214 par->pmi_setpal = par->ypan = 0;
50215 printk(KERN_WARNING "uvesafb: NX protection is actively."
50216 "We have better not to use the PMI.\n");
50217- } else {
50218+ } else
50219+#endif
50220 uvesafb_vbe_getpmi(task, par);
50221- }
50222 }
50223 #else
50224 /* The protected mode interface is not available on non-x86. */
50225@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
50226 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
50227
50228 /* Disable blanking if the user requested so. */
50229- if (!blank)
50230- info->fbops->fb_blank = NULL;
50231+ if (!blank) {
50232+ pax_open_kernel();
50233+ *(void **)&info->fbops->fb_blank = NULL;
50234+ pax_close_kernel();
50235+ }
50236
50237 /*
50238 * Find out how much IO memory is required for the mode with
50239@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
50240 info->flags = FBINFO_FLAG_DEFAULT |
50241 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
50242
50243- if (!par->ypan)
50244- info->fbops->fb_pan_display = NULL;
50245+ if (!par->ypan) {
50246+ pax_open_kernel();
50247+ *(void **)&info->fbops->fb_pan_display = NULL;
50248+ pax_close_kernel();
50249+ }
50250 }
50251
50252 static void uvesafb_init_mtrr(struct fb_info *info)
50253@@ -1836,6 +1866,11 @@ out:
50254 if (par->vbe_modes)
50255 kfree(par->vbe_modes);
50256
50257+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50258+ if (par->pmi_code)
50259+ module_free_exec(NULL, par->pmi_code);
50260+#endif
50261+
50262 framebuffer_release(info);
50263 return err;
50264 }
50265@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
50266 kfree(par->vbe_state_orig);
50267 if (par->vbe_state_saved)
50268 kfree(par->vbe_state_saved);
50269+
50270+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50271+ if (par->pmi_code)
50272+ module_free_exec(NULL, par->pmi_code);
50273+#endif
50274+
50275 }
50276
50277 framebuffer_release(info);
50278diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
50279index 501b340..d80aa17 100644
50280--- a/drivers/video/vesafb.c
50281+++ b/drivers/video/vesafb.c
50282@@ -9,6 +9,7 @@
50283 */
50284
50285 #include <linux/module.h>
50286+#include <linux/moduleloader.h>
50287 #include <linux/kernel.h>
50288 #include <linux/errno.h>
50289 #include <linux/string.h>
50290@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
50291 static int vram_total __initdata; /* Set total amount of memory */
50292 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
50293 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
50294-static void (*pmi_start)(void) __read_mostly;
50295-static void (*pmi_pal) (void) __read_mostly;
50296+static void (*pmi_start)(void) __read_only;
50297+static void (*pmi_pal) (void) __read_only;
50298 static int depth __read_mostly;
50299 static int vga_compat __read_mostly;
50300 /* --------------------------------------------------------------------- */
50301@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
50302 unsigned int size_vmode;
50303 unsigned int size_remap;
50304 unsigned int size_total;
50305+ void *pmi_code = NULL;
50306
50307 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
50308 return -ENODEV;
50309@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
50310 size_remap = size_total;
50311 vesafb_fix.smem_len = size_remap;
50312
50313-#ifndef __i386__
50314- screen_info.vesapm_seg = 0;
50315-#endif
50316-
50317 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
50318 printk(KERN_WARNING
50319 "vesafb: cannot reserve video memory at 0x%lx\n",
50320@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
50321 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
50322 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
50323
50324+#ifdef __i386__
50325+
50326+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50327+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
50328+ if (!pmi_code)
50329+#elif !defined(CONFIG_PAX_KERNEXEC)
50330+ if (0)
50331+#endif
50332+
50333+#endif
50334+ screen_info.vesapm_seg = 0;
50335+
50336 if (screen_info.vesapm_seg) {
50337- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
50338- screen_info.vesapm_seg,screen_info.vesapm_off);
50339+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
50340+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
50341 }
50342
50343 if (screen_info.vesapm_seg < 0xc000)
50344@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
50345
50346 if (ypan || pmi_setpal) {
50347 unsigned short *pmi_base;
50348+
50349 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
50350- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
50351- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
50352+
50353+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50354+ pax_open_kernel();
50355+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
50356+#else
50357+ pmi_code = pmi_base;
50358+#endif
50359+
50360+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
50361+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
50362+
50363+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50364+ pmi_start = ktva_ktla(pmi_start);
50365+ pmi_pal = ktva_ktla(pmi_pal);
50366+ pax_close_kernel();
50367+#endif
50368+
50369 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
50370 if (pmi_base[3]) {
50371 printk(KERN_INFO "vesafb: pmi: ports = ");
50372@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
50373 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
50374 (ypan ? FBINFO_HWACCEL_YPAN : 0);
50375
50376- if (!ypan)
50377- info->fbops->fb_pan_display = NULL;
50378+ if (!ypan) {
50379+ pax_open_kernel();
50380+ *(void **)&info->fbops->fb_pan_display = NULL;
50381+ pax_close_kernel();
50382+ }
50383
50384 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
50385 err = -ENOMEM;
50386@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
50387 info->node, info->fix.id);
50388 return 0;
50389 err:
50390+
50391+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
50392+ module_free_exec(NULL, pmi_code);
50393+#endif
50394+
50395 if (info->screen_base)
50396 iounmap(info->screen_base);
50397 framebuffer_release(info);
50398diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
50399index 88714ae..16c2e11 100644
50400--- a/drivers/video/via/via_clock.h
50401+++ b/drivers/video/via/via_clock.h
50402@@ -56,7 +56,7 @@ struct via_clock {
50403
50404 void (*set_engine_pll_state)(u8 state);
50405 void (*set_engine_pll)(struct via_pll_config config);
50406-};
50407+} __no_const;
50408
50409
50410 static inline u32 get_pll_internal_frequency(u32 ref_freq,
50411diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
50412index fef20db..d28b1ab 100644
50413--- a/drivers/xen/xenfs/xenstored.c
50414+++ b/drivers/xen/xenfs/xenstored.c
50415@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
50416 static int xsd_kva_open(struct inode *inode, struct file *file)
50417 {
50418 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
50419+#ifdef CONFIG_GRKERNSEC_HIDESYM
50420+ NULL);
50421+#else
50422 xen_store_interface);
50423+#endif
50424+
50425 if (!file->private_data)
50426 return -ENOMEM;
50427 return 0;
50428diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
50429index 055562c..fdfb10d 100644
50430--- a/fs/9p/vfs_addr.c
50431+++ b/fs/9p/vfs_addr.c
50432@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
50433
50434 retval = v9fs_file_write_internal(inode,
50435 v9inode->writeback_fid,
50436- (__force const char __user *)buffer,
50437+ (const char __force_user *)buffer,
50438 len, &offset, 0);
50439 if (retval > 0)
50440 retval = 0;
50441diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
50442index d86edc8..40ff2fb 100644
50443--- a/fs/9p/vfs_inode.c
50444+++ b/fs/9p/vfs_inode.c
50445@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50446 void
50447 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50448 {
50449- char *s = nd_get_link(nd);
50450+ const char *s = nd_get_link(nd);
50451
50452 p9_debug(P9_DEBUG_VFS, " %s %s\n",
50453 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
50454diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
50455index 370b24c..ff0be7b 100644
50456--- a/fs/Kconfig.binfmt
50457+++ b/fs/Kconfig.binfmt
50458@@ -103,7 +103,7 @@ config HAVE_AOUT
50459
50460 config BINFMT_AOUT
50461 tristate "Kernel support for a.out and ECOFF binaries"
50462- depends on HAVE_AOUT
50463+ depends on HAVE_AOUT && BROKEN
50464 ---help---
50465 A.out (Assembler.OUTput) is a set of formats for libraries and
50466 executables used in the earliest versions of UNIX. Linux used
50467diff --git a/fs/aio.c b/fs/aio.c
50468index 2bbcacf..8614116 100644
50469--- a/fs/aio.c
50470+++ b/fs/aio.c
50471@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
50472 size += sizeof(struct io_event) * nr_events;
50473 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
50474
50475- if (nr_pages < 0)
50476+ if (nr_pages <= 0)
50477 return -EINVAL;
50478
50479 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
50480@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
50481 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
50482 {
50483 ssize_t ret;
50484+ struct iovec iovstack;
50485
50486 kiocb->ki_nr_segs = kiocb->ki_nbytes;
50487
50488@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
50489 if (compat)
50490 ret = compat_rw_copy_check_uvector(rw,
50491 (struct compat_iovec __user *)kiocb->ki_buf,
50492- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
50493+ kiocb->ki_nr_segs, 1, &iovstack,
50494 &kiocb->ki_iovec);
50495 else
50496 #endif
50497 ret = rw_copy_check_uvector(rw,
50498 (struct iovec __user *)kiocb->ki_buf,
50499- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
50500+ kiocb->ki_nr_segs, 1, &iovstack,
50501 &kiocb->ki_iovec);
50502 if (ret < 0)
50503 return ret;
50504
50505+ if (kiocb->ki_iovec == &iovstack) {
50506+ kiocb->ki_inline_vec = iovstack;
50507+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
50508+ }
50509+
50510 /* ki_nbytes now reflect bytes instead of segs */
50511 kiocb->ki_nbytes = ret;
50512 return 0;
50513diff --git a/fs/attr.c b/fs/attr.c
50514index 1449adb..a2038c2 100644
50515--- a/fs/attr.c
50516+++ b/fs/attr.c
50517@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
50518 unsigned long limit;
50519
50520 limit = rlimit(RLIMIT_FSIZE);
50521+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
50522 if (limit != RLIM_INFINITY && offset > limit)
50523 goto out_sig;
50524 if (offset > inode->i_sb->s_maxbytes)
50525diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
50526index 3db70da..7aeec5b 100644
50527--- a/fs/autofs4/waitq.c
50528+++ b/fs/autofs4/waitq.c
50529@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
50530 {
50531 unsigned long sigpipe, flags;
50532 mm_segment_t fs;
50533- const char *data = (const char *)addr;
50534+ const char __user *data = (const char __force_user *)addr;
50535 ssize_t wr = 0;
50536
50537 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
50538@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
50539 return 1;
50540 }
50541
50542+#ifdef CONFIG_GRKERNSEC_HIDESYM
50543+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
50544+#endif
50545+
50546 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
50547 enum autofs_notify notify)
50548 {
50549@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
50550
50551 /* If this is a direct mount request create a dummy name */
50552 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
50553+#ifdef CONFIG_GRKERNSEC_HIDESYM
50554+ /* this name does get written to userland via autofs4_write() */
50555+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
50556+#else
50557 qstr.len = sprintf(name, "%p", dentry);
50558+#endif
50559 else {
50560 qstr.len = autofs4_getpath(sbi, dentry, &name);
50561 if (!qstr.len) {
50562diff --git a/fs/befs/endian.h b/fs/befs/endian.h
50563index 2722387..c8dd2a7 100644
50564--- a/fs/befs/endian.h
50565+++ b/fs/befs/endian.h
50566@@ -11,7 +11,7 @@
50567
50568 #include <asm/byteorder.h>
50569
50570-static inline u64
50571+static inline u64 __intentional_overflow(-1)
50572 fs64_to_cpu(const struct super_block *sb, fs64 n)
50573 {
50574 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
50575@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
50576 return (__force fs64)cpu_to_be64(n);
50577 }
50578
50579-static inline u32
50580+static inline u32 __intentional_overflow(-1)
50581 fs32_to_cpu(const struct super_block *sb, fs32 n)
50582 {
50583 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
50584diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
50585index f95dddc..b1e2c1c 100644
50586--- a/fs/befs/linuxvfs.c
50587+++ b/fs/befs/linuxvfs.c
50588@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50589 {
50590 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
50591 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
50592- char *link = nd_get_link(nd);
50593+ const char *link = nd_get_link(nd);
50594 if (!IS_ERR(link))
50595 kfree(link);
50596 }
50597diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
50598index bce8769..7fc7544 100644
50599--- a/fs/binfmt_aout.c
50600+++ b/fs/binfmt_aout.c
50601@@ -16,6 +16,7 @@
50602 #include <linux/string.h>
50603 #include <linux/fs.h>
50604 #include <linux/file.h>
50605+#include <linux/security.h>
50606 #include <linux/stat.h>
50607 #include <linux/fcntl.h>
50608 #include <linux/ptrace.h>
50609@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
50610 #endif
50611 # define START_STACK(u) ((void __user *)u.start_stack)
50612
50613+ memset(&dump, 0, sizeof(dump));
50614+
50615 fs = get_fs();
50616 set_fs(KERNEL_DS);
50617 has_dumped = 1;
50618@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
50619
50620 /* If the size of the dump file exceeds the rlimit, then see what would happen
50621 if we wrote the stack, but not the data area. */
50622+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
50623 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
50624 dump.u_dsize = 0;
50625
50626 /* Make sure we have enough room to write the stack and data areas. */
50627+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
50628 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
50629 dump.u_ssize = 0;
50630
50631@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
50632 rlim = rlimit(RLIMIT_DATA);
50633 if (rlim >= RLIM_INFINITY)
50634 rlim = ~0;
50635+
50636+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
50637 if (ex.a_data + ex.a_bss > rlim)
50638 return -ENOMEM;
50639
50640@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
50641
50642 install_exec_creds(bprm);
50643
50644+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50645+ current->mm->pax_flags = 0UL;
50646+#endif
50647+
50648+#ifdef CONFIG_PAX_PAGEEXEC
50649+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
50650+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
50651+
50652+#ifdef CONFIG_PAX_EMUTRAMP
50653+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
50654+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
50655+#endif
50656+
50657+#ifdef CONFIG_PAX_MPROTECT
50658+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
50659+ current->mm->pax_flags |= MF_PAX_MPROTECT;
50660+#endif
50661+
50662+ }
50663+#endif
50664+
50665 if (N_MAGIC(ex) == OMAGIC) {
50666 unsigned long text_addr, map_size;
50667 loff_t pos;
50668@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
50669 }
50670
50671 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
50672- PROT_READ | PROT_WRITE | PROT_EXEC,
50673+ PROT_READ | PROT_WRITE,
50674 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
50675 fd_offset + ex.a_text);
50676 if (error != N_DATADDR(ex)) {
50677diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
50678index f8a0b0e..6f036ed 100644
50679--- a/fs/binfmt_elf.c
50680+++ b/fs/binfmt_elf.c
50681@@ -34,6 +34,7 @@
50682 #include <linux/utsname.h>
50683 #include <linux/coredump.h>
50684 #include <linux/sched.h>
50685+#include <linux/xattr.h>
50686 #include <asm/uaccess.h>
50687 #include <asm/param.h>
50688 #include <asm/page.h>
50689@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
50690 #define elf_core_dump NULL
50691 #endif
50692
50693+#ifdef CONFIG_PAX_MPROTECT
50694+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
50695+#endif
50696+
50697+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
50698+static void elf_handle_mmap(struct file *file);
50699+#endif
50700+
50701 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
50702 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
50703 #else
50704@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
50705 .load_binary = load_elf_binary,
50706 .load_shlib = load_elf_library,
50707 .core_dump = elf_core_dump,
50708+
50709+#ifdef CONFIG_PAX_MPROTECT
50710+ .handle_mprotect= elf_handle_mprotect,
50711+#endif
50712+
50713+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
50714+ .handle_mmap = elf_handle_mmap,
50715+#endif
50716+
50717 .min_coredump = ELF_EXEC_PAGESIZE,
50718 };
50719
50720@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
50721
50722 static int set_brk(unsigned long start, unsigned long end)
50723 {
50724+ unsigned long e = end;
50725+
50726 start = ELF_PAGEALIGN(start);
50727 end = ELF_PAGEALIGN(end);
50728 if (end > start) {
50729@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
50730 if (BAD_ADDR(addr))
50731 return addr;
50732 }
50733- current->mm->start_brk = current->mm->brk = end;
50734+ current->mm->start_brk = current->mm->brk = e;
50735 return 0;
50736 }
50737
50738@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
50739 elf_addr_t __user *u_rand_bytes;
50740 const char *k_platform = ELF_PLATFORM;
50741 const char *k_base_platform = ELF_BASE_PLATFORM;
50742- unsigned char k_rand_bytes[16];
50743+ u32 k_rand_bytes[4];
50744 int items;
50745 elf_addr_t *elf_info;
50746 int ei_index = 0;
50747 const struct cred *cred = current_cred();
50748 struct vm_area_struct *vma;
50749+ unsigned long saved_auxv[AT_VECTOR_SIZE];
50750
50751 /*
50752 * In some cases (e.g. Hyper-Threading), we want to avoid L1
50753@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
50754 * Generate 16 random bytes for userspace PRNG seeding.
50755 */
50756 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
50757- u_rand_bytes = (elf_addr_t __user *)
50758- STACK_ALLOC(p, sizeof(k_rand_bytes));
50759+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
50760+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
50761+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
50762+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
50763+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
50764+ u_rand_bytes = (elf_addr_t __user *) p;
50765 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
50766 return -EFAULT;
50767
50768@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
50769 return -EFAULT;
50770 current->mm->env_end = p;
50771
50772+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
50773+
50774 /* Put the elf_info on the stack in the right place. */
50775 sp = (elf_addr_t __user *)envp + 1;
50776- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
50777+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
50778 return -EFAULT;
50779 return 0;
50780 }
50781@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
50782 an ELF header */
50783
50784 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
50785- struct file *interpreter, unsigned long *interp_map_addr,
50786- unsigned long no_base)
50787+ struct file *interpreter, unsigned long no_base)
50788 {
50789 struct elf_phdr *elf_phdata;
50790 struct elf_phdr *eppnt;
50791- unsigned long load_addr = 0;
50792+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
50793 int load_addr_set = 0;
50794 unsigned long last_bss = 0, elf_bss = 0;
50795- unsigned long error = ~0UL;
50796+ unsigned long error = -EINVAL;
50797 unsigned long total_size;
50798 int retval, i, size;
50799
50800@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
50801 goto out_close;
50802 }
50803
50804+#ifdef CONFIG_PAX_SEGMEXEC
50805+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
50806+ pax_task_size = SEGMEXEC_TASK_SIZE;
50807+#endif
50808+
50809 eppnt = elf_phdata;
50810 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
50811 if (eppnt->p_type == PT_LOAD) {
50812@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
50813 map_addr = elf_map(interpreter, load_addr + vaddr,
50814 eppnt, elf_prot, elf_type, total_size);
50815 total_size = 0;
50816- if (!*interp_map_addr)
50817- *interp_map_addr = map_addr;
50818 error = map_addr;
50819 if (BAD_ADDR(map_addr))
50820 goto out_close;
50821@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
50822 k = load_addr + eppnt->p_vaddr;
50823 if (BAD_ADDR(k) ||
50824 eppnt->p_filesz > eppnt->p_memsz ||
50825- eppnt->p_memsz > TASK_SIZE ||
50826- TASK_SIZE - eppnt->p_memsz < k) {
50827+ eppnt->p_memsz > pax_task_size ||
50828+ pax_task_size - eppnt->p_memsz < k) {
50829 error = -ENOMEM;
50830 goto out_close;
50831 }
50832@@ -538,6 +567,315 @@ out:
50833 return error;
50834 }
50835
50836+#ifdef CONFIG_PAX_PT_PAX_FLAGS
50837+#ifdef CONFIG_PAX_SOFTMODE
50838+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
50839+{
50840+ unsigned long pax_flags = 0UL;
50841+
50842+#ifdef CONFIG_PAX_PAGEEXEC
50843+ if (elf_phdata->p_flags & PF_PAGEEXEC)
50844+ pax_flags |= MF_PAX_PAGEEXEC;
50845+#endif
50846+
50847+#ifdef CONFIG_PAX_SEGMEXEC
50848+ if (elf_phdata->p_flags & PF_SEGMEXEC)
50849+ pax_flags |= MF_PAX_SEGMEXEC;
50850+#endif
50851+
50852+#ifdef CONFIG_PAX_EMUTRAMP
50853+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
50854+ pax_flags |= MF_PAX_EMUTRAMP;
50855+#endif
50856+
50857+#ifdef CONFIG_PAX_MPROTECT
50858+ if (elf_phdata->p_flags & PF_MPROTECT)
50859+ pax_flags |= MF_PAX_MPROTECT;
50860+#endif
50861+
50862+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
50863+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
50864+ pax_flags |= MF_PAX_RANDMMAP;
50865+#endif
50866+
50867+ return pax_flags;
50868+}
50869+#endif
50870+
50871+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
50872+{
50873+ unsigned long pax_flags = 0UL;
50874+
50875+#ifdef CONFIG_PAX_PAGEEXEC
50876+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
50877+ pax_flags |= MF_PAX_PAGEEXEC;
50878+#endif
50879+
50880+#ifdef CONFIG_PAX_SEGMEXEC
50881+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
50882+ pax_flags |= MF_PAX_SEGMEXEC;
50883+#endif
50884+
50885+#ifdef CONFIG_PAX_EMUTRAMP
50886+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
50887+ pax_flags |= MF_PAX_EMUTRAMP;
50888+#endif
50889+
50890+#ifdef CONFIG_PAX_MPROTECT
50891+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
50892+ pax_flags |= MF_PAX_MPROTECT;
50893+#endif
50894+
50895+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
50896+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
50897+ pax_flags |= MF_PAX_RANDMMAP;
50898+#endif
50899+
50900+ return pax_flags;
50901+}
50902+#endif
50903+
50904+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
50905+#ifdef CONFIG_PAX_SOFTMODE
50906+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
50907+{
50908+ unsigned long pax_flags = 0UL;
50909+
50910+#ifdef CONFIG_PAX_PAGEEXEC
50911+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
50912+ pax_flags |= MF_PAX_PAGEEXEC;
50913+#endif
50914+
50915+#ifdef CONFIG_PAX_SEGMEXEC
50916+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
50917+ pax_flags |= MF_PAX_SEGMEXEC;
50918+#endif
50919+
50920+#ifdef CONFIG_PAX_EMUTRAMP
50921+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
50922+ pax_flags |= MF_PAX_EMUTRAMP;
50923+#endif
50924+
50925+#ifdef CONFIG_PAX_MPROTECT
50926+ if (pax_flags_softmode & MF_PAX_MPROTECT)
50927+ pax_flags |= MF_PAX_MPROTECT;
50928+#endif
50929+
50930+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
50931+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
50932+ pax_flags |= MF_PAX_RANDMMAP;
50933+#endif
50934+
50935+ return pax_flags;
50936+}
50937+#endif
50938+
50939+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
50940+{
50941+ unsigned long pax_flags = 0UL;
50942+
50943+#ifdef CONFIG_PAX_PAGEEXEC
50944+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
50945+ pax_flags |= MF_PAX_PAGEEXEC;
50946+#endif
50947+
50948+#ifdef CONFIG_PAX_SEGMEXEC
50949+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
50950+ pax_flags |= MF_PAX_SEGMEXEC;
50951+#endif
50952+
50953+#ifdef CONFIG_PAX_EMUTRAMP
50954+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
50955+ pax_flags |= MF_PAX_EMUTRAMP;
50956+#endif
50957+
50958+#ifdef CONFIG_PAX_MPROTECT
50959+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
50960+ pax_flags |= MF_PAX_MPROTECT;
50961+#endif
50962+
50963+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
50964+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
50965+ pax_flags |= MF_PAX_RANDMMAP;
50966+#endif
50967+
50968+ return pax_flags;
50969+}
50970+#endif
50971+
50972+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50973+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
50974+{
50975+ unsigned long pax_flags = 0UL;
50976+
50977+#ifdef CONFIG_PAX_EI_PAX
50978+
50979+#ifdef CONFIG_PAX_PAGEEXEC
50980+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
50981+ pax_flags |= MF_PAX_PAGEEXEC;
50982+#endif
50983+
50984+#ifdef CONFIG_PAX_SEGMEXEC
50985+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
50986+ pax_flags |= MF_PAX_SEGMEXEC;
50987+#endif
50988+
50989+#ifdef CONFIG_PAX_EMUTRAMP
50990+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
50991+ pax_flags |= MF_PAX_EMUTRAMP;
50992+#endif
50993+
50994+#ifdef CONFIG_PAX_MPROTECT
50995+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
50996+ pax_flags |= MF_PAX_MPROTECT;
50997+#endif
50998+
50999+#ifdef CONFIG_PAX_ASLR
51000+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
51001+ pax_flags |= MF_PAX_RANDMMAP;
51002+#endif
51003+
51004+#else
51005+
51006+#ifdef CONFIG_PAX_PAGEEXEC
51007+ pax_flags |= MF_PAX_PAGEEXEC;
51008+#endif
51009+
51010+#ifdef CONFIG_PAX_SEGMEXEC
51011+ pax_flags |= MF_PAX_SEGMEXEC;
51012+#endif
51013+
51014+#ifdef CONFIG_PAX_MPROTECT
51015+ pax_flags |= MF_PAX_MPROTECT;
51016+#endif
51017+
51018+#ifdef CONFIG_PAX_RANDMMAP
51019+ if (randomize_va_space)
51020+ pax_flags |= MF_PAX_RANDMMAP;
51021+#endif
51022+
51023+#endif
51024+
51025+ return pax_flags;
51026+}
51027+
51028+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
51029+{
51030+
51031+#ifdef CONFIG_PAX_PT_PAX_FLAGS
51032+ unsigned long i;
51033+
51034+ for (i = 0UL; i < elf_ex->e_phnum; i++)
51035+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
51036+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
51037+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
51038+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
51039+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
51040+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
51041+ return ~0UL;
51042+
51043+#ifdef CONFIG_PAX_SOFTMODE
51044+ if (pax_softmode)
51045+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
51046+ else
51047+#endif
51048+
51049+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
51050+ break;
51051+ }
51052+#endif
51053+
51054+ return ~0UL;
51055+}
51056+
51057+static unsigned long pax_parse_xattr_pax(struct file * const file)
51058+{
51059+
51060+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
51061+ ssize_t xattr_size, i;
51062+ unsigned char xattr_value[sizeof("pemrs") - 1];
51063+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
51064+
51065+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
51066+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
51067+ return ~0UL;
51068+
51069+ for (i = 0; i < xattr_size; i++)
51070+ switch (xattr_value[i]) {
51071+ default:
51072+ return ~0UL;
51073+
51074+#define parse_flag(option1, option2, flag) \
51075+ case option1: \
51076+ if (pax_flags_hardmode & MF_PAX_##flag) \
51077+ return ~0UL; \
51078+ pax_flags_hardmode |= MF_PAX_##flag; \
51079+ break; \
51080+ case option2: \
51081+ if (pax_flags_softmode & MF_PAX_##flag) \
51082+ return ~0UL; \
51083+ pax_flags_softmode |= MF_PAX_##flag; \
51084+ break;
51085+
51086+ parse_flag('p', 'P', PAGEEXEC);
51087+ parse_flag('e', 'E', EMUTRAMP);
51088+ parse_flag('m', 'M', MPROTECT);
51089+ parse_flag('r', 'R', RANDMMAP);
51090+ parse_flag('s', 'S', SEGMEXEC);
51091+
51092+#undef parse_flag
51093+ }
51094+
51095+ if (pax_flags_hardmode & pax_flags_softmode)
51096+ return ~0UL;
51097+
51098+#ifdef CONFIG_PAX_SOFTMODE
51099+ if (pax_softmode)
51100+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
51101+ else
51102+#endif
51103+
51104+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
51105+#else
51106+ return ~0UL;
51107+#endif
51108+
51109+}
51110+
51111+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
51112+{
51113+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
51114+
51115+ pax_flags = pax_parse_ei_pax(elf_ex);
51116+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
51117+ xattr_pax_flags = pax_parse_xattr_pax(file);
51118+
51119+ if (pt_pax_flags == ~0UL)
51120+ pt_pax_flags = xattr_pax_flags;
51121+ else if (xattr_pax_flags == ~0UL)
51122+ xattr_pax_flags = pt_pax_flags;
51123+ if (pt_pax_flags != xattr_pax_flags)
51124+ return -EINVAL;
51125+ if (pt_pax_flags != ~0UL)
51126+ pax_flags = pt_pax_flags;
51127+
51128+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
51129+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51130+ if ((__supported_pte_mask & _PAGE_NX))
51131+ pax_flags &= ~MF_PAX_SEGMEXEC;
51132+ else
51133+ pax_flags &= ~MF_PAX_PAGEEXEC;
51134+ }
51135+#endif
51136+
51137+ if (0 > pax_check_flags(&pax_flags))
51138+ return -EINVAL;
51139+
51140+ current->mm->pax_flags = pax_flags;
51141+ return 0;
51142+}
51143+#endif
51144+
51145 /*
51146 * These are the functions used to load ELF style executables and shared
51147 * libraries. There is no binary dependent code anywhere else.
51148@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
51149 {
51150 unsigned int random_variable = 0;
51151
51152+#ifdef CONFIG_PAX_RANDUSTACK
51153+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
51154+ return stack_top - current->mm->delta_stack;
51155+#endif
51156+
51157 if ((current->flags & PF_RANDOMIZE) &&
51158 !(current->personality & ADDR_NO_RANDOMIZE)) {
51159 random_variable = get_random_int() & STACK_RND_MASK;
51160@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
51161 unsigned long load_addr = 0, load_bias = 0;
51162 int load_addr_set = 0;
51163 char * elf_interpreter = NULL;
51164- unsigned long error;
51165+ unsigned long error = 0;
51166 struct elf_phdr *elf_ppnt, *elf_phdata;
51167 unsigned long elf_bss, elf_brk;
51168 int retval, i;
51169@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
51170 unsigned long start_code, end_code, start_data, end_data;
51171 unsigned long reloc_func_desc __maybe_unused = 0;
51172 int executable_stack = EXSTACK_DEFAULT;
51173- unsigned long def_flags = 0;
51174 struct pt_regs *regs = current_pt_regs();
51175 struct {
51176 struct elfhdr elf_ex;
51177 struct elfhdr interp_elf_ex;
51178 } *loc;
51179+ unsigned long pax_task_size = TASK_SIZE;
51180
51181 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
51182 if (!loc) {
51183@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
51184 goto out_free_dentry;
51185
51186 /* OK, This is the point of no return */
51187- current->mm->def_flags = def_flags;
51188+
51189+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51190+ current->mm->pax_flags = 0UL;
51191+#endif
51192+
51193+#ifdef CONFIG_PAX_DLRESOLVE
51194+ current->mm->call_dl_resolve = 0UL;
51195+#endif
51196+
51197+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
51198+ current->mm->call_syscall = 0UL;
51199+#endif
51200+
51201+#ifdef CONFIG_PAX_ASLR
51202+ current->mm->delta_mmap = 0UL;
51203+ current->mm->delta_stack = 0UL;
51204+#endif
51205+
51206+ current->mm->def_flags = 0;
51207+
51208+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51209+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
51210+ send_sig(SIGKILL, current, 0);
51211+ goto out_free_dentry;
51212+ }
51213+#endif
51214+
51215+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
51216+ pax_set_initial_flags(bprm);
51217+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
51218+ if (pax_set_initial_flags_func)
51219+ (pax_set_initial_flags_func)(bprm);
51220+#endif
51221+
51222+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51223+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
51224+ current->mm->context.user_cs_limit = PAGE_SIZE;
51225+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
51226+ }
51227+#endif
51228+
51229+#ifdef CONFIG_PAX_SEGMEXEC
51230+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
51231+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
51232+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
51233+ pax_task_size = SEGMEXEC_TASK_SIZE;
51234+ current->mm->def_flags |= VM_NOHUGEPAGE;
51235+ }
51236+#endif
51237+
51238+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
51239+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51240+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
51241+ put_cpu();
51242+ }
51243+#endif
51244
51245 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
51246 may depend on the personality. */
51247 SET_PERSONALITY(loc->elf_ex);
51248+
51249+#ifdef CONFIG_PAX_ASLR
51250+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
51251+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
51252+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
51253+ }
51254+#endif
51255+
51256+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51257+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51258+ executable_stack = EXSTACK_DISABLE_X;
51259+ current->personality &= ~READ_IMPLIES_EXEC;
51260+ } else
51261+#endif
51262+
51263 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
51264 current->personality |= READ_IMPLIES_EXEC;
51265
51266@@ -819,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
51267 #else
51268 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
51269 #endif
51270+
51271+#ifdef CONFIG_PAX_RANDMMAP
51272+ /* PaX: randomize base address at the default exe base if requested */
51273+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
51274+#ifdef CONFIG_SPARC64
51275+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
51276+#else
51277+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
51278+#endif
51279+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
51280+ elf_flags |= MAP_FIXED;
51281+ }
51282+#endif
51283+
51284 }
51285
51286 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
51287@@ -851,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
51288 * allowed task size. Note that p_filesz must always be
51289 * <= p_memsz so it is only necessary to check p_memsz.
51290 */
51291- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
51292- elf_ppnt->p_memsz > TASK_SIZE ||
51293- TASK_SIZE - elf_ppnt->p_memsz < k) {
51294+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
51295+ elf_ppnt->p_memsz > pax_task_size ||
51296+ pax_task_size - elf_ppnt->p_memsz < k) {
51297 /* set_brk can never work. Avoid overflows. */
51298 send_sig(SIGKILL, current, 0);
51299 retval = -EINVAL;
51300@@ -892,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
51301 goto out_free_dentry;
51302 }
51303 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
51304- send_sig(SIGSEGV, current, 0);
51305- retval = -EFAULT; /* Nobody gets to see this, but.. */
51306- goto out_free_dentry;
51307+ /*
51308+ * This bss-zeroing can fail if the ELF
51309+ * file specifies odd protections. So
51310+ * we don't check the return value
51311+ */
51312 }
51313
51314+#ifdef CONFIG_PAX_RANDMMAP
51315+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
51316+ unsigned long start, size, flags;
51317+ vm_flags_t vm_flags;
51318+
51319+ start = ELF_PAGEALIGN(elf_brk);
51320+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
51321+ flags = MAP_FIXED | MAP_PRIVATE;
51322+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
51323+
51324+ down_write(&current->mm->mmap_sem);
51325+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
51326+ retval = -ENOMEM;
51327+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
51328+// if (current->personality & ADDR_NO_RANDOMIZE)
51329+// vm_flags |= VM_READ | VM_MAYREAD;
51330+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
51331+ retval = IS_ERR_VALUE(start) ? start : 0;
51332+ }
51333+ up_write(&current->mm->mmap_sem);
51334+ if (retval == 0)
51335+ retval = set_brk(start + size, start + size + PAGE_SIZE);
51336+ if (retval < 0) {
51337+ send_sig(SIGKILL, current, 0);
51338+ goto out_free_dentry;
51339+ }
51340+ }
51341+#endif
51342+
51343 if (elf_interpreter) {
51344- unsigned long interp_map_addr = 0;
51345-
51346 elf_entry = load_elf_interp(&loc->interp_elf_ex,
51347 interpreter,
51348- &interp_map_addr,
51349 load_bias);
51350 if (!IS_ERR((void *)elf_entry)) {
51351 /*
51352@@ -1124,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
51353 * Decide what to dump of a segment, part, all or none.
51354 */
51355 static unsigned long vma_dump_size(struct vm_area_struct *vma,
51356- unsigned long mm_flags)
51357+ unsigned long mm_flags, long signr)
51358 {
51359 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
51360
51361@@ -1162,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
51362 if (vma->vm_file == NULL)
51363 return 0;
51364
51365- if (FILTER(MAPPED_PRIVATE))
51366+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
51367 goto whole;
51368
51369 /*
51370@@ -1387,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
51371 {
51372 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
51373 int i = 0;
51374- do
51375+ do {
51376 i += 2;
51377- while (auxv[i - 2] != AT_NULL);
51378+ } while (auxv[i - 2] != AT_NULL);
51379 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
51380 }
51381
51382@@ -1398,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
51383 {
51384 mm_segment_t old_fs = get_fs();
51385 set_fs(KERNEL_DS);
51386- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
51387+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
51388 set_fs(old_fs);
51389 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
51390 }
51391@@ -2019,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
51392 }
51393
51394 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
51395- unsigned long mm_flags)
51396+ struct coredump_params *cprm)
51397 {
51398 struct vm_area_struct *vma;
51399 size_t size = 0;
51400
51401 for (vma = first_vma(current, gate_vma); vma != NULL;
51402 vma = next_vma(vma, gate_vma))
51403- size += vma_dump_size(vma, mm_flags);
51404+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
51405 return size;
51406 }
51407
51408@@ -2119,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51409
51410 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
51411
51412- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
51413+ offset += elf_core_vma_data_size(gate_vma, cprm);
51414 offset += elf_core_extra_data_size();
51415 e_shoff = offset;
51416
51417@@ -2133,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
51418 offset = dataoff;
51419
51420 size += sizeof(*elf);
51421+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
51422 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
51423 goto end_coredump;
51424
51425 size += sizeof(*phdr4note);
51426+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
51427 if (size > cprm->limit
51428 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
51429 goto end_coredump;
51430@@ -2150,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51431 phdr.p_offset = offset;
51432 phdr.p_vaddr = vma->vm_start;
51433 phdr.p_paddr = 0;
51434- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
51435+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
51436 phdr.p_memsz = vma->vm_end - vma->vm_start;
51437 offset += phdr.p_filesz;
51438 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
51439@@ -2161,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51440 phdr.p_align = ELF_EXEC_PAGESIZE;
51441
51442 size += sizeof(phdr);
51443+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
51444 if (size > cprm->limit
51445 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
51446 goto end_coredump;
51447@@ -2185,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51448 unsigned long addr;
51449 unsigned long end;
51450
51451- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
51452+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
51453
51454 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
51455 struct page *page;
51456@@ -2194,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51457 page = get_dump_page(addr);
51458 if (page) {
51459 void *kaddr = kmap(page);
51460+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
51461 stop = ((size += PAGE_SIZE) > cprm->limit) ||
51462 !dump_write(cprm->file, kaddr,
51463 PAGE_SIZE);
51464@@ -2211,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
51465
51466 if (e_phnum == PN_XNUM) {
51467 size += sizeof(*shdr4extnum);
51468+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
51469 if (size > cprm->limit
51470 || !dump_write(cprm->file, shdr4extnum,
51471 sizeof(*shdr4extnum)))
51472@@ -2231,6 +2691,167 @@ out:
51473
51474 #endif /* CONFIG_ELF_CORE */
51475
51476+#ifdef CONFIG_PAX_MPROTECT
51477+/* PaX: non-PIC ELF libraries need relocations on their executable segments
51478+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
51479+ * we'll remove VM_MAYWRITE for good on RELRO segments.
51480+ *
51481+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
51482+ * basis because we want to allow the common case and not the special ones.
51483+ */
51484+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
51485+{
51486+ struct elfhdr elf_h;
51487+ struct elf_phdr elf_p;
51488+ unsigned long i;
51489+ unsigned long oldflags;
51490+ bool is_textrel_rw, is_textrel_rx, is_relro;
51491+
51492+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
51493+ return;
51494+
51495+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
51496+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
51497+
51498+#ifdef CONFIG_PAX_ELFRELOCS
51499+ /* possible TEXTREL */
51500+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
51501+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
51502+#else
51503+ is_textrel_rw = false;
51504+ is_textrel_rx = false;
51505+#endif
51506+
51507+ /* possible RELRO */
51508+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
51509+
51510+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
51511+ return;
51512+
51513+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
51514+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
51515+
51516+#ifdef CONFIG_PAX_ETEXECRELOCS
51517+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
51518+#else
51519+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
51520+#endif
51521+
51522+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
51523+ !elf_check_arch(&elf_h) ||
51524+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
51525+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
51526+ return;
51527+
51528+ for (i = 0UL; i < elf_h.e_phnum; i++) {
51529+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
51530+ return;
51531+ switch (elf_p.p_type) {
51532+ case PT_DYNAMIC:
51533+ if (!is_textrel_rw && !is_textrel_rx)
51534+ continue;
51535+ i = 0UL;
51536+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
51537+ elf_dyn dyn;
51538+
51539+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
51540+ break;
51541+ if (dyn.d_tag == DT_NULL)
51542+ break;
51543+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
51544+ gr_log_textrel(vma);
51545+ if (is_textrel_rw)
51546+ vma->vm_flags |= VM_MAYWRITE;
51547+ else
51548+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
51549+ vma->vm_flags &= ~VM_MAYWRITE;
51550+ break;
51551+ }
51552+ i++;
51553+ }
51554+ is_textrel_rw = false;
51555+ is_textrel_rx = false;
51556+ continue;
51557+
51558+ case PT_GNU_RELRO:
51559+ if (!is_relro)
51560+ continue;
51561+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
51562+ vma->vm_flags &= ~VM_MAYWRITE;
51563+ is_relro = false;
51564+ continue;
51565+
51566+#ifdef CONFIG_PAX_PT_PAX_FLAGS
51567+ case PT_PAX_FLAGS: {
51568+ const char *msg_mprotect = "", *msg_emutramp = "";
51569+ char *buffer_lib, *buffer_exe;
51570+
51571+ if (elf_p.p_flags & PF_NOMPROTECT)
51572+ msg_mprotect = "MPROTECT disabled";
51573+
51574+#ifdef CONFIG_PAX_EMUTRAMP
51575+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
51576+ msg_emutramp = "EMUTRAMP enabled";
51577+#endif
51578+
51579+ if (!msg_mprotect[0] && !msg_emutramp[0])
51580+ continue;
51581+
51582+ if (!printk_ratelimit())
51583+ continue;
51584+
51585+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
51586+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
51587+ if (buffer_lib && buffer_exe) {
51588+ char *path_lib, *path_exe;
51589+
51590+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
51591+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
51592+
51593+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
51594+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
51595+
51596+ }
51597+ free_page((unsigned long)buffer_exe);
51598+ free_page((unsigned long)buffer_lib);
51599+ continue;
51600+ }
51601+#endif
51602+
51603+ }
51604+ }
51605+}
51606+#endif
51607+
51608+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51609+
51610+extern int grsec_enable_log_rwxmaps;
51611+
51612+static void elf_handle_mmap(struct file *file)
51613+{
51614+ struct elfhdr elf_h;
51615+ struct elf_phdr elf_p;
51616+ unsigned long i;
51617+
51618+ if (!grsec_enable_log_rwxmaps)
51619+ return;
51620+
51621+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
51622+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
51623+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
51624+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
51625+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
51626+ return;
51627+
51628+ for (i = 0UL; i < elf_h.e_phnum; i++) {
51629+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
51630+ return;
51631+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
51632+ gr_log_ptgnustack(file);
51633+ }
51634+}
51635+#endif
51636+
51637 static int __init init_elf_binfmt(void)
51638 {
51639 register_binfmt(&elf_format);
51640diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
51641index d50bbe5..af3b649 100644
51642--- a/fs/binfmt_flat.c
51643+++ b/fs/binfmt_flat.c
51644@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
51645 realdatastart = (unsigned long) -ENOMEM;
51646 printk("Unable to allocate RAM for process data, errno %d\n",
51647 (int)-realdatastart);
51648+ down_write(&current->mm->mmap_sem);
51649 vm_munmap(textpos, text_len);
51650+ up_write(&current->mm->mmap_sem);
51651 ret = realdatastart;
51652 goto err;
51653 }
51654@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
51655 }
51656 if (IS_ERR_VALUE(result)) {
51657 printk("Unable to read data+bss, errno %d\n", (int)-result);
51658+ down_write(&current->mm->mmap_sem);
51659 vm_munmap(textpos, text_len);
51660 vm_munmap(realdatastart, len);
51661+ up_write(&current->mm->mmap_sem);
51662 ret = result;
51663 goto err;
51664 }
51665@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
51666 }
51667 if (IS_ERR_VALUE(result)) {
51668 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
51669+ down_write(&current->mm->mmap_sem);
51670 vm_munmap(textpos, text_len + data_len + extra +
51671 MAX_SHARED_LIBS * sizeof(unsigned long));
51672+ up_write(&current->mm->mmap_sem);
51673 ret = result;
51674 goto err;
51675 }
51676diff --git a/fs/bio.c b/fs/bio.c
51677index 94bbc04..6fe78a4 100644
51678--- a/fs/bio.c
51679+++ b/fs/bio.c
51680@@ -1096,7 +1096,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
51681 /*
51682 * Overflow, abort
51683 */
51684- if (end < start)
51685+ if (end < start || end - start > INT_MAX - nr_pages)
51686 return ERR_PTR(-EINVAL);
51687
51688 nr_pages += end - start;
51689@@ -1230,7 +1230,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
51690 /*
51691 * Overflow, abort
51692 */
51693- if (end < start)
51694+ if (end < start || end - start > INT_MAX - nr_pages)
51695 return ERR_PTR(-EINVAL);
51696
51697 nr_pages += end - start;
51698@@ -1492,7 +1492,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
51699 const int read = bio_data_dir(bio) == READ;
51700 struct bio_map_data *bmd = bio->bi_private;
51701 int i;
51702- char *p = bmd->sgvecs[0].iov_base;
51703+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
51704
51705 bio_for_each_segment_all(bvec, bio, i) {
51706 char *addr = page_address(bvec->bv_page);
51707diff --git a/fs/block_dev.c b/fs/block_dev.c
51708index 85f5c85..d6f0b1a 100644
51709--- a/fs/block_dev.c
51710+++ b/fs/block_dev.c
51711@@ -658,7 +658,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
51712 else if (bdev->bd_contains == bdev)
51713 return true; /* is a whole device which isn't held */
51714
51715- else if (whole->bd_holder == bd_may_claim)
51716+ else if (whole->bd_holder == (void *)bd_may_claim)
51717 return true; /* is a partition of a device that is being partitioned */
51718 else if (whole->bd_holder != NULL)
51719 return false; /* is a partition of a held device */
51720diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
51721index 7fb054b..ad36c67 100644
51722--- a/fs/btrfs/ctree.c
51723+++ b/fs/btrfs/ctree.c
51724@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
51725 free_extent_buffer(buf);
51726 add_root_to_dirty_list(root);
51727 } else {
51728- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
51729- parent_start = parent->start;
51730- else
51731+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
51732+ if (parent)
51733+ parent_start = parent->start;
51734+ else
51735+ parent_start = 0;
51736+ } else
51737 parent_start = 0;
51738
51739 WARN_ON(trans->transid != btrfs_header_generation(parent));
51740diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
51741index 0f81d67..0ad55fe 100644
51742--- a/fs/btrfs/ioctl.c
51743+++ b/fs/btrfs/ioctl.c
51744@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
51745 for (i = 0; i < num_types; i++) {
51746 struct btrfs_space_info *tmp;
51747
51748+ /* Don't copy in more than we allocated */
51749 if (!slot_count)
51750 break;
51751
51752+ slot_count--;
51753+
51754 info = NULL;
51755 rcu_read_lock();
51756 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
51757@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
51758 memcpy(dest, &space, sizeof(space));
51759 dest++;
51760 space_args.total_spaces++;
51761- slot_count--;
51762 }
51763- if (!slot_count)
51764- break;
51765 }
51766 up_read(&info->groups_sem);
51767 }
51768diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
51769index f0857e0..e7023c5 100644
51770--- a/fs/btrfs/super.c
51771+++ b/fs/btrfs/super.c
51772@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
51773 function, line, errstr);
51774 return;
51775 }
51776- ACCESS_ONCE(trans->transaction->aborted) = errno;
51777+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
51778 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
51779 }
51780 /*
51781diff --git a/fs/buffer.c b/fs/buffer.c
51782index d2a4d1b..df798ca 100644
51783--- a/fs/buffer.c
51784+++ b/fs/buffer.c
51785@@ -3367,7 +3367,7 @@ void __init buffer_init(void)
51786 bh_cachep = kmem_cache_create("buffer_head",
51787 sizeof(struct buffer_head), 0,
51788 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
51789- SLAB_MEM_SPREAD),
51790+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
51791 NULL);
51792
51793 /*
51794diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
51795index 622f469..e8d2d55 100644
51796--- a/fs/cachefiles/bind.c
51797+++ b/fs/cachefiles/bind.c
51798@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
51799 args);
51800
51801 /* start by checking things over */
51802- ASSERT(cache->fstop_percent >= 0 &&
51803- cache->fstop_percent < cache->fcull_percent &&
51804+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
51805 cache->fcull_percent < cache->frun_percent &&
51806 cache->frun_percent < 100);
51807
51808- ASSERT(cache->bstop_percent >= 0 &&
51809- cache->bstop_percent < cache->bcull_percent &&
51810+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
51811 cache->bcull_percent < cache->brun_percent &&
51812 cache->brun_percent < 100);
51813
51814diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
51815index 0a1467b..6a53245 100644
51816--- a/fs/cachefiles/daemon.c
51817+++ b/fs/cachefiles/daemon.c
51818@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
51819 if (n > buflen)
51820 return -EMSGSIZE;
51821
51822- if (copy_to_user(_buffer, buffer, n) != 0)
51823+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
51824 return -EFAULT;
51825
51826 return n;
51827@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
51828 if (test_bit(CACHEFILES_DEAD, &cache->flags))
51829 return -EIO;
51830
51831- if (datalen < 0 || datalen > PAGE_SIZE - 1)
51832+ if (datalen > PAGE_SIZE - 1)
51833 return -EOPNOTSUPP;
51834
51835 /* drag the command string into the kernel so we can parse it */
51836@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
51837 if (args[0] != '%' || args[1] != '\0')
51838 return -EINVAL;
51839
51840- if (fstop < 0 || fstop >= cache->fcull_percent)
51841+ if (fstop >= cache->fcull_percent)
51842 return cachefiles_daemon_range_error(cache, args);
51843
51844 cache->fstop_percent = fstop;
51845@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
51846 if (args[0] != '%' || args[1] != '\0')
51847 return -EINVAL;
51848
51849- if (bstop < 0 || bstop >= cache->bcull_percent)
51850+ if (bstop >= cache->bcull_percent)
51851 return cachefiles_daemon_range_error(cache, args);
51852
51853 cache->bstop_percent = bstop;
51854diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
51855index 4938251..7e01445 100644
51856--- a/fs/cachefiles/internal.h
51857+++ b/fs/cachefiles/internal.h
51858@@ -59,7 +59,7 @@ struct cachefiles_cache {
51859 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
51860 struct rb_root active_nodes; /* active nodes (can't be culled) */
51861 rwlock_t active_lock; /* lock for active_nodes */
51862- atomic_t gravecounter; /* graveyard uniquifier */
51863+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
51864 unsigned frun_percent; /* when to stop culling (% files) */
51865 unsigned fcull_percent; /* when to start culling (% files) */
51866 unsigned fstop_percent; /* when to stop allocating (% files) */
51867@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
51868 * proc.c
51869 */
51870 #ifdef CONFIG_CACHEFILES_HISTOGRAM
51871-extern atomic_t cachefiles_lookup_histogram[HZ];
51872-extern atomic_t cachefiles_mkdir_histogram[HZ];
51873-extern atomic_t cachefiles_create_histogram[HZ];
51874+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
51875+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
51876+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
51877
51878 extern int __init cachefiles_proc_init(void);
51879 extern void cachefiles_proc_cleanup(void);
51880 static inline
51881-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
51882+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
51883 {
51884 unsigned long jif = jiffies - start_jif;
51885 if (jif >= HZ)
51886 jif = HZ - 1;
51887- atomic_inc(&histogram[jif]);
51888+ atomic_inc_unchecked(&histogram[jif]);
51889 }
51890
51891 #else
51892diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
51893index 8c01c5fc..15f982e 100644
51894--- a/fs/cachefiles/namei.c
51895+++ b/fs/cachefiles/namei.c
51896@@ -317,7 +317,7 @@ try_again:
51897 /* first step is to make up a grave dentry in the graveyard */
51898 sprintf(nbuffer, "%08x%08x",
51899 (uint32_t) get_seconds(),
51900- (uint32_t) atomic_inc_return(&cache->gravecounter));
51901+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
51902
51903 /* do the multiway lock magic */
51904 trap = lock_rename(cache->graveyard, dir);
51905diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
51906index eccd339..4c1d995 100644
51907--- a/fs/cachefiles/proc.c
51908+++ b/fs/cachefiles/proc.c
51909@@ -14,9 +14,9 @@
51910 #include <linux/seq_file.h>
51911 #include "internal.h"
51912
51913-atomic_t cachefiles_lookup_histogram[HZ];
51914-atomic_t cachefiles_mkdir_histogram[HZ];
51915-atomic_t cachefiles_create_histogram[HZ];
51916+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
51917+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
51918+atomic_unchecked_t cachefiles_create_histogram[HZ];
51919
51920 /*
51921 * display the latency histogram
51922@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
51923 return 0;
51924 default:
51925 index = (unsigned long) v - 3;
51926- x = atomic_read(&cachefiles_lookup_histogram[index]);
51927- y = atomic_read(&cachefiles_mkdir_histogram[index]);
51928- z = atomic_read(&cachefiles_create_histogram[index]);
51929+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
51930+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
51931+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
51932 if (x == 0 && y == 0 && z == 0)
51933 return 0;
51934
51935diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
51936index 317f9ee..3d24511 100644
51937--- a/fs/cachefiles/rdwr.c
51938+++ b/fs/cachefiles/rdwr.c
51939@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
51940 old_fs = get_fs();
51941 set_fs(KERNEL_DS);
51942 ret = file->f_op->write(
51943- file, (const void __user *) data, len, &pos);
51944+ file, (const void __force_user *) data, len, &pos);
51945 set_fs(old_fs);
51946 kunmap(page);
51947 file_end_write(file);
51948diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
51949index f02d82b..2632cf86 100644
51950--- a/fs/ceph/dir.c
51951+++ b/fs/ceph/dir.c
51952@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
51953 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
51954 struct ceph_mds_client *mdsc = fsc->mdsc;
51955 unsigned frag = fpos_frag(filp->f_pos);
51956- int off = fpos_off(filp->f_pos);
51957+ unsigned int off = fpos_off(filp->f_pos);
51958 int err;
51959 u32 ftype;
51960 struct ceph_mds_reply_info_parsed *rinfo;
51961diff --git a/fs/ceph/super.c b/fs/ceph/super.c
51962index 7d377c9..3fb6559 100644
51963--- a/fs/ceph/super.c
51964+++ b/fs/ceph/super.c
51965@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
51966 /*
51967 * construct our own bdi so we can control readahead, etc.
51968 */
51969-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
51970+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
51971
51972 static int ceph_register_bdi(struct super_block *sb,
51973 struct ceph_fs_client *fsc)
51974@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
51975 default_backing_dev_info.ra_pages;
51976
51977 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
51978- atomic_long_inc_return(&bdi_seq));
51979+ atomic_long_inc_return_unchecked(&bdi_seq));
51980 if (!err)
51981 sb->s_bdi = &fsc->backing_dev_info;
51982 return err;
51983diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
51984index d597483..747901b 100644
51985--- a/fs/cifs/cifs_debug.c
51986+++ b/fs/cifs/cifs_debug.c
51987@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
51988
51989 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
51990 #ifdef CONFIG_CIFS_STATS2
51991- atomic_set(&totBufAllocCount, 0);
51992- atomic_set(&totSmBufAllocCount, 0);
51993+ atomic_set_unchecked(&totBufAllocCount, 0);
51994+ atomic_set_unchecked(&totSmBufAllocCount, 0);
51995 #endif /* CONFIG_CIFS_STATS2 */
51996 spin_lock(&cifs_tcp_ses_lock);
51997 list_for_each(tmp1, &cifs_tcp_ses_list) {
51998@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
51999 tcon = list_entry(tmp3,
52000 struct cifs_tcon,
52001 tcon_list);
52002- atomic_set(&tcon->num_smbs_sent, 0);
52003+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
52004 if (server->ops->clear_stats)
52005 server->ops->clear_stats(tcon);
52006 }
52007@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
52008 smBufAllocCount.counter, cifs_min_small);
52009 #ifdef CONFIG_CIFS_STATS2
52010 seq_printf(m, "Total Large %d Small %d Allocations\n",
52011- atomic_read(&totBufAllocCount),
52012- atomic_read(&totSmBufAllocCount));
52013+ atomic_read_unchecked(&totBufAllocCount),
52014+ atomic_read_unchecked(&totSmBufAllocCount));
52015 #endif /* CONFIG_CIFS_STATS2 */
52016
52017 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
52018@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
52019 if (tcon->need_reconnect)
52020 seq_puts(m, "\tDISCONNECTED ");
52021 seq_printf(m, "\nSMBs: %d",
52022- atomic_read(&tcon->num_smbs_sent));
52023+ atomic_read_unchecked(&tcon->num_smbs_sent));
52024 if (server->ops->print_stats)
52025 server->ops->print_stats(m, tcon);
52026 }
52027diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
52028index 3752b9f..8db5569 100644
52029--- a/fs/cifs/cifsfs.c
52030+++ b/fs/cifs/cifsfs.c
52031@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
52032 */
52033 cifs_req_cachep = kmem_cache_create("cifs_request",
52034 CIFSMaxBufSize + max_hdr_size, 0,
52035- SLAB_HWCACHE_ALIGN, NULL);
52036+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
52037 if (cifs_req_cachep == NULL)
52038 return -ENOMEM;
52039
52040@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
52041 efficient to alloc 1 per page off the slab compared to 17K (5page)
52042 alloc of large cifs buffers even when page debugging is on */
52043 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
52044- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
52045+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
52046 NULL);
52047 if (cifs_sm_req_cachep == NULL) {
52048 mempool_destroy(cifs_req_poolp);
52049@@ -1147,8 +1147,8 @@ init_cifs(void)
52050 atomic_set(&bufAllocCount, 0);
52051 atomic_set(&smBufAllocCount, 0);
52052 #ifdef CONFIG_CIFS_STATS2
52053- atomic_set(&totBufAllocCount, 0);
52054- atomic_set(&totSmBufAllocCount, 0);
52055+ atomic_set_unchecked(&totBufAllocCount, 0);
52056+ atomic_set_unchecked(&totSmBufAllocCount, 0);
52057 #endif /* CONFIG_CIFS_STATS2 */
52058
52059 atomic_set(&midCount, 0);
52060diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
52061index ea3a0b3..0194e39 100644
52062--- a/fs/cifs/cifsglob.h
52063+++ b/fs/cifs/cifsglob.h
52064@@ -752,35 +752,35 @@ struct cifs_tcon {
52065 __u16 Flags; /* optional support bits */
52066 enum statusEnum tidStatus;
52067 #ifdef CONFIG_CIFS_STATS
52068- atomic_t num_smbs_sent;
52069+ atomic_unchecked_t num_smbs_sent;
52070 union {
52071 struct {
52072- atomic_t num_writes;
52073- atomic_t num_reads;
52074- atomic_t num_flushes;
52075- atomic_t num_oplock_brks;
52076- atomic_t num_opens;
52077- atomic_t num_closes;
52078- atomic_t num_deletes;
52079- atomic_t num_mkdirs;
52080- atomic_t num_posixopens;
52081- atomic_t num_posixmkdirs;
52082- atomic_t num_rmdirs;
52083- atomic_t num_renames;
52084- atomic_t num_t2renames;
52085- atomic_t num_ffirst;
52086- atomic_t num_fnext;
52087- atomic_t num_fclose;
52088- atomic_t num_hardlinks;
52089- atomic_t num_symlinks;
52090- atomic_t num_locks;
52091- atomic_t num_acl_get;
52092- atomic_t num_acl_set;
52093+ atomic_unchecked_t num_writes;
52094+ atomic_unchecked_t num_reads;
52095+ atomic_unchecked_t num_flushes;
52096+ atomic_unchecked_t num_oplock_brks;
52097+ atomic_unchecked_t num_opens;
52098+ atomic_unchecked_t num_closes;
52099+ atomic_unchecked_t num_deletes;
52100+ atomic_unchecked_t num_mkdirs;
52101+ atomic_unchecked_t num_posixopens;
52102+ atomic_unchecked_t num_posixmkdirs;
52103+ atomic_unchecked_t num_rmdirs;
52104+ atomic_unchecked_t num_renames;
52105+ atomic_unchecked_t num_t2renames;
52106+ atomic_unchecked_t num_ffirst;
52107+ atomic_unchecked_t num_fnext;
52108+ atomic_unchecked_t num_fclose;
52109+ atomic_unchecked_t num_hardlinks;
52110+ atomic_unchecked_t num_symlinks;
52111+ atomic_unchecked_t num_locks;
52112+ atomic_unchecked_t num_acl_get;
52113+ atomic_unchecked_t num_acl_set;
52114 } cifs_stats;
52115 #ifdef CONFIG_CIFS_SMB2
52116 struct {
52117- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
52118- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
52119+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
52120+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
52121 } smb2_stats;
52122 #endif /* CONFIG_CIFS_SMB2 */
52123 } stats;
52124@@ -1081,7 +1081,7 @@ convert_delimiter(char *path, char delim)
52125 }
52126
52127 #ifdef CONFIG_CIFS_STATS
52128-#define cifs_stats_inc atomic_inc
52129+#define cifs_stats_inc atomic_inc_unchecked
52130
52131 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
52132 unsigned int bytes)
52133@@ -1446,8 +1446,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
52134 /* Various Debug counters */
52135 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
52136 #ifdef CONFIG_CIFS_STATS2
52137-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
52138-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
52139+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
52140+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
52141 #endif
52142 GLOBAL_EXTERN atomic_t smBufAllocCount;
52143 GLOBAL_EXTERN atomic_t midCount;
52144diff --git a/fs/cifs/link.c b/fs/cifs/link.c
52145index b83c3f5..6437caa 100644
52146--- a/fs/cifs/link.c
52147+++ b/fs/cifs/link.c
52148@@ -616,7 +616,7 @@ symlink_exit:
52149
52150 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
52151 {
52152- char *p = nd_get_link(nd);
52153+ const char *p = nd_get_link(nd);
52154 if (!IS_ERR(p))
52155 kfree(p);
52156 }
52157diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
52158index 1bec014..f329411 100644
52159--- a/fs/cifs/misc.c
52160+++ b/fs/cifs/misc.c
52161@@ -169,7 +169,7 @@ cifs_buf_get(void)
52162 memset(ret_buf, 0, buf_size + 3);
52163 atomic_inc(&bufAllocCount);
52164 #ifdef CONFIG_CIFS_STATS2
52165- atomic_inc(&totBufAllocCount);
52166+ atomic_inc_unchecked(&totBufAllocCount);
52167 #endif /* CONFIG_CIFS_STATS2 */
52168 }
52169
52170@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
52171 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
52172 atomic_inc(&smBufAllocCount);
52173 #ifdef CONFIG_CIFS_STATS2
52174- atomic_inc(&totSmBufAllocCount);
52175+ atomic_inc_unchecked(&totSmBufAllocCount);
52176 #endif /* CONFIG_CIFS_STATS2 */
52177
52178 }
52179diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
52180index 3efdb9d..e845a5e 100644
52181--- a/fs/cifs/smb1ops.c
52182+++ b/fs/cifs/smb1ops.c
52183@@ -591,27 +591,27 @@ static void
52184 cifs_clear_stats(struct cifs_tcon *tcon)
52185 {
52186 #ifdef CONFIG_CIFS_STATS
52187- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
52188- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
52189- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
52190- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
52191- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
52192- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
52193- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
52194- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
52195- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
52196- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
52197- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
52198- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
52199- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
52200- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
52201- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
52202- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
52203- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
52204- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
52205- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
52206- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
52207- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
52208+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
52209+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
52210+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
52211+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
52212+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
52213+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
52214+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
52215+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
52216+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
52217+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
52218+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
52219+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
52220+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
52221+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
52222+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
52223+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
52224+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
52225+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
52226+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
52227+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
52228+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
52229 #endif
52230 }
52231
52232@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
52233 {
52234 #ifdef CONFIG_CIFS_STATS
52235 seq_printf(m, " Oplocks breaks: %d",
52236- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
52237+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
52238 seq_printf(m, "\nReads: %d Bytes: %llu",
52239- atomic_read(&tcon->stats.cifs_stats.num_reads),
52240+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
52241 (long long)(tcon->bytes_read));
52242 seq_printf(m, "\nWrites: %d Bytes: %llu",
52243- atomic_read(&tcon->stats.cifs_stats.num_writes),
52244+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
52245 (long long)(tcon->bytes_written));
52246 seq_printf(m, "\nFlushes: %d",
52247- atomic_read(&tcon->stats.cifs_stats.num_flushes));
52248+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
52249 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
52250- atomic_read(&tcon->stats.cifs_stats.num_locks),
52251- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
52252- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
52253+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
52254+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
52255+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
52256 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
52257- atomic_read(&tcon->stats.cifs_stats.num_opens),
52258- atomic_read(&tcon->stats.cifs_stats.num_closes),
52259- atomic_read(&tcon->stats.cifs_stats.num_deletes));
52260+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
52261+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
52262+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
52263 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
52264- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
52265- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
52266+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
52267+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
52268 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
52269- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
52270- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
52271+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
52272+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
52273 seq_printf(m, "\nRenames: %d T2 Renames %d",
52274- atomic_read(&tcon->stats.cifs_stats.num_renames),
52275- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
52276+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
52277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
52278 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
52279- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
52280- atomic_read(&tcon->stats.cifs_stats.num_fnext),
52281- atomic_read(&tcon->stats.cifs_stats.num_fclose));
52282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
52283+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
52284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
52285 #endif
52286 }
52287
52288diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
52289index f2e76f3..c44fac7 100644
52290--- a/fs/cifs/smb2ops.c
52291+++ b/fs/cifs/smb2ops.c
52292@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
52293 #ifdef CONFIG_CIFS_STATS
52294 int i;
52295 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
52296- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
52297- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
52298+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
52299+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
52300 }
52301 #endif
52302 }
52303@@ -284,66 +284,66 @@ static void
52304 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
52305 {
52306 #ifdef CONFIG_CIFS_STATS
52307- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
52308- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
52309+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
52310+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
52311 seq_printf(m, "\nNegotiates: %d sent %d failed",
52312- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
52313- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
52314+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
52315+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
52316 seq_printf(m, "\nSessionSetups: %d sent %d failed",
52317- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
52318- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
52319+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
52320+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
52321 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
52322 seq_printf(m, "\nLogoffs: %d sent %d failed",
52323- atomic_read(&sent[SMB2_LOGOFF_HE]),
52324- atomic_read(&failed[SMB2_LOGOFF_HE]));
52325+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
52326+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
52327 seq_printf(m, "\nTreeConnects: %d sent %d failed",
52328- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
52329- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
52330+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
52331+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
52332 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
52333- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
52334- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
52335+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
52336+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
52337 seq_printf(m, "\nCreates: %d sent %d failed",
52338- atomic_read(&sent[SMB2_CREATE_HE]),
52339- atomic_read(&failed[SMB2_CREATE_HE]));
52340+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
52341+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
52342 seq_printf(m, "\nCloses: %d sent %d failed",
52343- atomic_read(&sent[SMB2_CLOSE_HE]),
52344- atomic_read(&failed[SMB2_CLOSE_HE]));
52345+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
52346+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
52347 seq_printf(m, "\nFlushes: %d sent %d failed",
52348- atomic_read(&sent[SMB2_FLUSH_HE]),
52349- atomic_read(&failed[SMB2_FLUSH_HE]));
52350+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
52351+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
52352 seq_printf(m, "\nReads: %d sent %d failed",
52353- atomic_read(&sent[SMB2_READ_HE]),
52354- atomic_read(&failed[SMB2_READ_HE]));
52355+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
52356+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
52357 seq_printf(m, "\nWrites: %d sent %d failed",
52358- atomic_read(&sent[SMB2_WRITE_HE]),
52359- atomic_read(&failed[SMB2_WRITE_HE]));
52360+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
52361+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
52362 seq_printf(m, "\nLocks: %d sent %d failed",
52363- atomic_read(&sent[SMB2_LOCK_HE]),
52364- atomic_read(&failed[SMB2_LOCK_HE]));
52365+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
52366+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
52367 seq_printf(m, "\nIOCTLs: %d sent %d failed",
52368- atomic_read(&sent[SMB2_IOCTL_HE]),
52369- atomic_read(&failed[SMB2_IOCTL_HE]));
52370+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
52371+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
52372 seq_printf(m, "\nCancels: %d sent %d failed",
52373- atomic_read(&sent[SMB2_CANCEL_HE]),
52374- atomic_read(&failed[SMB2_CANCEL_HE]));
52375+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
52376+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
52377 seq_printf(m, "\nEchos: %d sent %d failed",
52378- atomic_read(&sent[SMB2_ECHO_HE]),
52379- atomic_read(&failed[SMB2_ECHO_HE]));
52380+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
52381+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
52382 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
52383- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
52384- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
52385+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
52386+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
52387 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
52388- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
52389- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
52390+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
52391+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
52392 seq_printf(m, "\nQueryInfos: %d sent %d failed",
52393- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
52394- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
52395+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
52396+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
52397 seq_printf(m, "\nSetInfos: %d sent %d failed",
52398- atomic_read(&sent[SMB2_SET_INFO_HE]),
52399- atomic_read(&failed[SMB2_SET_INFO_HE]));
52400+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
52401+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
52402 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
52403- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
52404- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
52405+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
52406+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
52407 #endif
52408 }
52409
52410diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
52411index 2b95ce2..d079d75 100644
52412--- a/fs/cifs/smb2pdu.c
52413+++ b/fs/cifs/smb2pdu.c
52414@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
52415 default:
52416 cifs_dbg(VFS, "info level %u isn't supported\n",
52417 srch_inf->info_level);
52418- rc = -EINVAL;
52419- goto qdir_exit;
52420+ return -EINVAL;
52421 }
52422
52423 req->FileIndex = cpu_to_le32(index);
52424diff --git a/fs/coda/cache.c b/fs/coda/cache.c
52425index 1da168c..8bc7ff6 100644
52426--- a/fs/coda/cache.c
52427+++ b/fs/coda/cache.c
52428@@ -24,7 +24,7 @@
52429 #include "coda_linux.h"
52430 #include "coda_cache.h"
52431
52432-static atomic_t permission_epoch = ATOMIC_INIT(0);
52433+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
52434
52435 /* replace or extend an acl cache hit */
52436 void coda_cache_enter(struct inode *inode, int mask)
52437@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
52438 struct coda_inode_info *cii = ITOC(inode);
52439
52440 spin_lock(&cii->c_lock);
52441- cii->c_cached_epoch = atomic_read(&permission_epoch);
52442+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
52443 if (!uid_eq(cii->c_uid, current_fsuid())) {
52444 cii->c_uid = current_fsuid();
52445 cii->c_cached_perm = mask;
52446@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
52447 {
52448 struct coda_inode_info *cii = ITOC(inode);
52449 spin_lock(&cii->c_lock);
52450- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
52451+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
52452 spin_unlock(&cii->c_lock);
52453 }
52454
52455 /* remove all acl caches */
52456 void coda_cache_clear_all(struct super_block *sb)
52457 {
52458- atomic_inc(&permission_epoch);
52459+ atomic_inc_unchecked(&permission_epoch);
52460 }
52461
52462
52463@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
52464 spin_lock(&cii->c_lock);
52465 hit = (mask & cii->c_cached_perm) == mask &&
52466 uid_eq(cii->c_uid, current_fsuid()) &&
52467- cii->c_cached_epoch == atomic_read(&permission_epoch);
52468+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
52469 spin_unlock(&cii->c_lock);
52470
52471 return hit;
52472diff --git a/fs/compat.c b/fs/compat.c
52473index fc3b55d..7b568ae 100644
52474--- a/fs/compat.c
52475+++ b/fs/compat.c
52476@@ -54,7 +54,7 @@
52477 #include <asm/ioctls.h>
52478 #include "internal.h"
52479
52480-int compat_log = 1;
52481+int compat_log = 0;
52482
52483 int compat_printk(const char *fmt, ...)
52484 {
52485@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
52486
52487 set_fs(KERNEL_DS);
52488 /* The __user pointer cast is valid because of the set_fs() */
52489- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
52490+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
52491 set_fs(oldfs);
52492 /* truncating is ok because it's a user address */
52493 if (!ret)
52494@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
52495 goto out;
52496
52497 ret = -EINVAL;
52498- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
52499+ if (nr_segs > UIO_MAXIOV)
52500 goto out;
52501 if (nr_segs > fast_segs) {
52502 ret = -ENOMEM;
52503@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
52504
52505 struct compat_readdir_callback {
52506 struct compat_old_linux_dirent __user *dirent;
52507+ struct file * file;
52508 int result;
52509 };
52510
52511@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
52512 buf->result = -EOVERFLOW;
52513 return -EOVERFLOW;
52514 }
52515+
52516+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52517+ return 0;
52518+
52519 buf->result++;
52520 dirent = buf->dirent;
52521 if (!access_ok(VERIFY_WRITE, dirent,
52522@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
52523
52524 buf.result = 0;
52525 buf.dirent = dirent;
52526+ buf.file = f.file;
52527
52528 error = vfs_readdir(f.file, compat_fillonedir, &buf);
52529 if (buf.result)
52530@@ -899,6 +905,7 @@ struct compat_linux_dirent {
52531 struct compat_getdents_callback {
52532 struct compat_linux_dirent __user *current_dir;
52533 struct compat_linux_dirent __user *previous;
52534+ struct file * file;
52535 int count;
52536 int error;
52537 };
52538@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
52539 buf->error = -EOVERFLOW;
52540 return -EOVERFLOW;
52541 }
52542+
52543+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52544+ return 0;
52545+
52546 dirent = buf->previous;
52547 if (dirent) {
52548 if (__put_user(offset, &dirent->d_off))
52549@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
52550 buf.previous = NULL;
52551 buf.count = count;
52552 buf.error = 0;
52553+ buf.file = f.file;
52554
52555 error = vfs_readdir(f.file, compat_filldir, &buf);
52556 if (error >= 0)
52557@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
52558 struct compat_getdents_callback64 {
52559 struct linux_dirent64 __user *current_dir;
52560 struct linux_dirent64 __user *previous;
52561+ struct file * file;
52562 int count;
52563 int error;
52564 };
52565@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
52566 buf->error = -EINVAL; /* only used if we fail.. */
52567 if (reclen > buf->count)
52568 return -EINVAL;
52569+
52570+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52571+ return 0;
52572+
52573 dirent = buf->previous;
52574
52575 if (dirent) {
52576@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
52577 buf.previous = NULL;
52578 buf.count = count;
52579 buf.error = 0;
52580+ buf.file = f.file;
52581
52582 error = vfs_readdir(f.file, compat_filldir64, &buf);
52583 if (error >= 0)
52584 error = buf.error;
52585 lastdirent = buf.previous;
52586 if (lastdirent) {
52587- typeof(lastdirent->d_off) d_off = f.file->f_pos;
52588+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52589 if (__put_user_unaligned(d_off, &lastdirent->d_off))
52590 error = -EFAULT;
52591 else
52592diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
52593index a81147e..20bf2b5 100644
52594--- a/fs/compat_binfmt_elf.c
52595+++ b/fs/compat_binfmt_elf.c
52596@@ -30,11 +30,13 @@
52597 #undef elf_phdr
52598 #undef elf_shdr
52599 #undef elf_note
52600+#undef elf_dyn
52601 #undef elf_addr_t
52602 #define elfhdr elf32_hdr
52603 #define elf_phdr elf32_phdr
52604 #define elf_shdr elf32_shdr
52605 #define elf_note elf32_note
52606+#define elf_dyn Elf32_Dyn
52607 #define elf_addr_t Elf32_Addr
52608
52609 /*
52610diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
52611index 996cdc5..15e2f33 100644
52612--- a/fs/compat_ioctl.c
52613+++ b/fs/compat_ioctl.c
52614@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
52615 return -EFAULT;
52616 if (__get_user(udata, &ss32->iomem_base))
52617 return -EFAULT;
52618- ss.iomem_base = compat_ptr(udata);
52619+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
52620 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
52621 __get_user(ss.port_high, &ss32->port_high))
52622 return -EFAULT;
52623@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
52624 for (i = 0; i < nmsgs; i++) {
52625 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
52626 return -EFAULT;
52627- if (get_user(datap, &umsgs[i].buf) ||
52628- put_user(compat_ptr(datap), &tmsgs[i].buf))
52629+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
52630+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
52631 return -EFAULT;
52632 }
52633 return sys_ioctl(fd, cmd, (unsigned long)tdata);
52634@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
52635 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
52636 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
52637 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
52638- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
52639+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
52640 return -EFAULT;
52641
52642 return ioctl_preallocate(file, p);
52643@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
52644 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
52645 {
52646 unsigned int a, b;
52647- a = *(unsigned int *)p;
52648- b = *(unsigned int *)q;
52649+ a = *(const unsigned int *)p;
52650+ b = *(const unsigned int *)q;
52651 if (a > b)
52652 return 1;
52653 if (a < b)
52654diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
52655index 7aabc6a..34c1197 100644
52656--- a/fs/configfs/dir.c
52657+++ b/fs/configfs/dir.c
52658@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
52659 }
52660 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
52661 struct configfs_dirent *next;
52662- const char * name;
52663+ const unsigned char * name;
52664+ char d_name[sizeof(next->s_dentry->d_iname)];
52665 int len;
52666 struct inode *inode = NULL;
52667
52668@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
52669 continue;
52670
52671 name = configfs_get_name(next);
52672- len = strlen(name);
52673+ if (next->s_dentry && name == next->s_dentry->d_iname) {
52674+ len = next->s_dentry->d_name.len;
52675+ memcpy(d_name, name, len);
52676+ name = d_name;
52677+ } else
52678+ len = strlen(name);
52679
52680 /*
52681 * We'll have a dentry and an inode for
52682diff --git a/fs/coredump.c b/fs/coredump.c
52683index dafafba..10b3b27 100644
52684--- a/fs/coredump.c
52685+++ b/fs/coredump.c
52686@@ -52,7 +52,7 @@ struct core_name {
52687 char *corename;
52688 int used, size;
52689 };
52690-static atomic_t call_count = ATOMIC_INIT(1);
52691+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
52692
52693 /* The maximal length of core_pattern is also specified in sysctl.c */
52694
52695@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
52696 {
52697 char *old_corename = cn->corename;
52698
52699- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
52700+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
52701 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
52702
52703 if (!cn->corename) {
52704@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
52705 int pid_in_pattern = 0;
52706 int err = 0;
52707
52708- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
52709+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
52710 cn->corename = kmalloc(cn->size, GFP_KERNEL);
52711 cn->used = 0;
52712
52713@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
52714 struct pipe_inode_info *pipe = file->private_data;
52715
52716 pipe_lock(pipe);
52717- pipe->readers++;
52718- pipe->writers--;
52719+ atomic_inc(&pipe->readers);
52720+ atomic_dec(&pipe->writers);
52721 wake_up_interruptible_sync(&pipe->wait);
52722 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52723 pipe_unlock(pipe);
52724@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
52725 * We actually want wait_event_freezable() but then we need
52726 * to clear TIF_SIGPENDING and improve dump_interrupted().
52727 */
52728- wait_event_interruptible(pipe->wait, pipe->readers == 1);
52729+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
52730
52731 pipe_lock(pipe);
52732- pipe->readers--;
52733- pipe->writers++;
52734+ atomic_dec(&pipe->readers);
52735+ atomic_inc(&pipe->writers);
52736 pipe_unlock(pipe);
52737 }
52738
52739@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
52740 struct files_struct *displaced;
52741 bool need_nonrelative = false;
52742 bool core_dumped = false;
52743- static atomic_t core_dump_count = ATOMIC_INIT(0);
52744+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
52745+ long signr = siginfo->si_signo;
52746 struct coredump_params cprm = {
52747 .siginfo = siginfo,
52748 .regs = signal_pt_regs(),
52749@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
52750 .mm_flags = mm->flags,
52751 };
52752
52753- audit_core_dumps(siginfo->si_signo);
52754+ audit_core_dumps(signr);
52755+
52756+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
52757+ gr_handle_brute_attach(cprm.mm_flags);
52758
52759 binfmt = mm->binfmt;
52760 if (!binfmt || !binfmt->core_dump)
52761@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
52762 need_nonrelative = true;
52763 }
52764
52765- retval = coredump_wait(siginfo->si_signo, &core_state);
52766+ retval = coredump_wait(signr, &core_state);
52767 if (retval < 0)
52768 goto fail_creds;
52769
52770@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
52771 }
52772 cprm.limit = RLIM_INFINITY;
52773
52774- dump_count = atomic_inc_return(&core_dump_count);
52775+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
52776 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
52777 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
52778 task_tgid_vnr(current), current->comm);
52779@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
52780 } else {
52781 struct inode *inode;
52782
52783+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
52784+
52785 if (cprm.limit < binfmt->min_coredump)
52786 goto fail_unlock;
52787
52788@@ -666,7 +672,7 @@ close_fail:
52789 filp_close(cprm.file, NULL);
52790 fail_dropcount:
52791 if (ispipe)
52792- atomic_dec(&core_dump_count);
52793+ atomic_dec_unchecked(&core_dump_count);
52794 fail_unlock:
52795 kfree(cn.corename);
52796 fail_corename:
52797@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
52798 {
52799 return !dump_interrupted() &&
52800 access_ok(VERIFY_READ, addr, nr) &&
52801- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
52802+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
52803 }
52804 EXPORT_SYMBOL(dump_write);
52805
52806diff --git a/fs/dcache.c b/fs/dcache.c
52807index f09b908..04b9690 100644
52808--- a/fs/dcache.c
52809+++ b/fs/dcache.c
52810@@ -3086,7 +3086,8 @@ void __init vfs_caches_init(unsigned long mempages)
52811 mempages -= reserve;
52812
52813 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
52814- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
52815+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
52816+ SLAB_NO_SANITIZE, NULL);
52817
52818 dcache_init();
52819 inode_init();
52820diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
52821index c7c83ff..bda9461 100644
52822--- a/fs/debugfs/inode.c
52823+++ b/fs/debugfs/inode.c
52824@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
52825 */
52826 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
52827 {
52828+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52829+ return __create_file(name, S_IFDIR | S_IRWXU,
52830+#else
52831 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
52832+#endif
52833 parent, NULL, NULL);
52834 }
52835 EXPORT_SYMBOL_GPL(debugfs_create_dir);
52836diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
52837index 5eab400..810a3f5 100644
52838--- a/fs/ecryptfs/inode.c
52839+++ b/fs/ecryptfs/inode.c
52840@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
52841 old_fs = get_fs();
52842 set_fs(get_ds());
52843 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
52844- (char __user *)lower_buf,
52845+ (char __force_user *)lower_buf,
52846 PATH_MAX);
52847 set_fs(old_fs);
52848 if (rc < 0)
52849@@ -706,7 +706,7 @@ out:
52850 static void
52851 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
52852 {
52853- char *buf = nd_get_link(nd);
52854+ const char *buf = nd_get_link(nd);
52855 if (!IS_ERR(buf)) {
52856 /* Free the char* */
52857 kfree(buf);
52858diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
52859index e4141f2..d8263e8 100644
52860--- a/fs/ecryptfs/miscdev.c
52861+++ b/fs/ecryptfs/miscdev.c
52862@@ -304,7 +304,7 @@ check_list:
52863 goto out_unlock_msg_ctx;
52864 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
52865 if (msg_ctx->msg) {
52866- if (copy_to_user(&buf[i], packet_length, packet_length_size))
52867+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
52868 goto out_unlock_msg_ctx;
52869 i += packet_length_size;
52870 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
52871diff --git a/fs/exec.c b/fs/exec.c
52872index ffd7a81..3c84660 100644
52873--- a/fs/exec.c
52874+++ b/fs/exec.c
52875@@ -55,8 +55,20 @@
52876 #include <linux/pipe_fs_i.h>
52877 #include <linux/oom.h>
52878 #include <linux/compat.h>
52879+#include <linux/random.h>
52880+#include <linux/seq_file.h>
52881+#include <linux/coredump.h>
52882+#include <linux/mman.h>
52883+
52884+#ifdef CONFIG_PAX_REFCOUNT
52885+#include <linux/kallsyms.h>
52886+#include <linux/kdebug.h>
52887+#endif
52888+
52889+#include <trace/events/fs.h>
52890
52891 #include <asm/uaccess.h>
52892+#include <asm/sections.h>
52893 #include <asm/mmu_context.h>
52894 #include <asm/tlb.h>
52895
52896@@ -66,17 +78,32 @@
52897
52898 #include <trace/events/sched.h>
52899
52900+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52901+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
52902+{
52903+ 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");
52904+}
52905+#endif
52906+
52907+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
52908+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
52909+EXPORT_SYMBOL(pax_set_initial_flags_func);
52910+#endif
52911+
52912 int suid_dumpable = 0;
52913
52914 static LIST_HEAD(formats);
52915 static DEFINE_RWLOCK(binfmt_lock);
52916
52917+extern int gr_process_kernel_exec_ban(void);
52918+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
52919+
52920 void __register_binfmt(struct linux_binfmt * fmt, int insert)
52921 {
52922 BUG_ON(!fmt);
52923 write_lock(&binfmt_lock);
52924- insert ? list_add(&fmt->lh, &formats) :
52925- list_add_tail(&fmt->lh, &formats);
52926+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
52927+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
52928 write_unlock(&binfmt_lock);
52929 }
52930
52931@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
52932 void unregister_binfmt(struct linux_binfmt * fmt)
52933 {
52934 write_lock(&binfmt_lock);
52935- list_del(&fmt->lh);
52936+ pax_list_del((struct list_head *)&fmt->lh);
52937 write_unlock(&binfmt_lock);
52938 }
52939
52940@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
52941 int write)
52942 {
52943 struct page *page;
52944- int ret;
52945
52946-#ifdef CONFIG_STACK_GROWSUP
52947- if (write) {
52948- ret = expand_downwards(bprm->vma, pos);
52949- if (ret < 0)
52950- return NULL;
52951- }
52952-#endif
52953- ret = get_user_pages(current, bprm->mm, pos,
52954- 1, write, 1, &page, NULL);
52955- if (ret <= 0)
52956+ if (0 > expand_downwards(bprm->vma, pos))
52957+ return NULL;
52958+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
52959 return NULL;
52960
52961 if (write) {
52962@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
52963 if (size <= ARG_MAX)
52964 return page;
52965
52966+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52967+ // only allow 512KB for argv+env on suid/sgid binaries
52968+ // to prevent easy ASLR exhaustion
52969+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
52970+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
52971+ (size > (512 * 1024))) {
52972+ put_page(page);
52973+ return NULL;
52974+ }
52975+#endif
52976+
52977 /*
52978 * Limit to 1/4-th the stack size for the argv+env strings.
52979 * This ensures that:
52980@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
52981 vma->vm_end = STACK_TOP_MAX;
52982 vma->vm_start = vma->vm_end - PAGE_SIZE;
52983 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
52984+
52985+#ifdef CONFIG_PAX_SEGMEXEC
52986+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
52987+#endif
52988+
52989 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
52990 INIT_LIST_HEAD(&vma->anon_vma_chain);
52991
52992@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
52993 mm->stack_vm = mm->total_vm = 1;
52994 up_write(&mm->mmap_sem);
52995 bprm->p = vma->vm_end - sizeof(void *);
52996+
52997+#ifdef CONFIG_PAX_RANDUSTACK
52998+ if (randomize_va_space)
52999+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
53000+#endif
53001+
53002 return 0;
53003 err:
53004 up_write(&mm->mmap_sem);
53005@@ -396,7 +437,7 @@ struct user_arg_ptr {
53006 } ptr;
53007 };
53008
53009-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
53010+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
53011 {
53012 const char __user *native;
53013
53014@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
53015 compat_uptr_t compat;
53016
53017 if (get_user(compat, argv.ptr.compat + nr))
53018- return ERR_PTR(-EFAULT);
53019+ return (const char __force_user *)ERR_PTR(-EFAULT);
53020
53021 return compat_ptr(compat);
53022 }
53023 #endif
53024
53025 if (get_user(native, argv.ptr.native + nr))
53026- return ERR_PTR(-EFAULT);
53027+ return (const char __force_user *)ERR_PTR(-EFAULT);
53028
53029 return native;
53030 }
53031@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
53032 if (!p)
53033 break;
53034
53035- if (IS_ERR(p))
53036+ if (IS_ERR((const char __force_kernel *)p))
53037 return -EFAULT;
53038
53039 if (i >= max)
53040@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
53041
53042 ret = -EFAULT;
53043 str = get_user_arg_ptr(argv, argc);
53044- if (IS_ERR(str))
53045+ if (IS_ERR((const char __force_kernel *)str))
53046 goto out;
53047
53048 len = strnlen_user(str, MAX_ARG_STRLEN);
53049@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
53050 int r;
53051 mm_segment_t oldfs = get_fs();
53052 struct user_arg_ptr argv = {
53053- .ptr.native = (const char __user *const __user *)__argv,
53054+ .ptr.native = (const char __force_user * const __force_user *)__argv,
53055 };
53056
53057 set_fs(KERNEL_DS);
53058@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
53059 unsigned long new_end = old_end - shift;
53060 struct mmu_gather tlb;
53061
53062- BUG_ON(new_start > new_end);
53063+ if (new_start >= new_end || new_start < mmap_min_addr)
53064+ return -ENOMEM;
53065
53066 /*
53067 * ensure there are no vmas between where we want to go
53068@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
53069 if (vma != find_vma(mm, new_start))
53070 return -EFAULT;
53071
53072+#ifdef CONFIG_PAX_SEGMEXEC
53073+ BUG_ON(pax_find_mirror_vma(vma));
53074+#endif
53075+
53076 /*
53077 * cover the whole range: [new_start, old_end)
53078 */
53079@@ -607,7 +653,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
53080 return -ENOMEM;
53081
53082 lru_add_drain();
53083- tlb_gather_mmu(&tlb, mm, 0);
53084+ tlb_gather_mmu(&tlb, mm, old_start, old_end);
53085 if (new_end > old_start) {
53086 /*
53087 * when the old and new regions overlap clear from new_end.
53088@@ -624,7 +670,7 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
53089 free_pgd_range(&tlb, old_start, old_end, new_end,
53090 vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
53091 }
53092- tlb_finish_mmu(&tlb, new_end, old_end);
53093+ tlb_finish_mmu(&tlb, old_start, old_end);
53094
53095 /*
53096 * Shrink the vma to just the new range. Always succeeds.
53097@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
53098 stack_top = arch_align_stack(stack_top);
53099 stack_top = PAGE_ALIGN(stack_top);
53100
53101- if (unlikely(stack_top < mmap_min_addr) ||
53102- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
53103- return -ENOMEM;
53104-
53105 stack_shift = vma->vm_end - stack_top;
53106
53107 bprm->p -= stack_shift;
53108@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
53109 bprm->exec -= stack_shift;
53110
53111 down_write(&mm->mmap_sem);
53112+
53113+ /* Move stack pages down in memory. */
53114+ if (stack_shift) {
53115+ ret = shift_arg_pages(vma, stack_shift);
53116+ if (ret)
53117+ goto out_unlock;
53118+ }
53119+
53120 vm_flags = VM_STACK_FLAGS;
53121
53122+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53123+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53124+ vm_flags &= ~VM_EXEC;
53125+
53126+#ifdef CONFIG_PAX_MPROTECT
53127+ if (mm->pax_flags & MF_PAX_MPROTECT)
53128+ vm_flags &= ~VM_MAYEXEC;
53129+#endif
53130+
53131+ }
53132+#endif
53133+
53134 /*
53135 * Adjust stack execute permissions; explicitly enable for
53136 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
53137@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
53138 goto out_unlock;
53139 BUG_ON(prev != vma);
53140
53141- /* Move stack pages down in memory. */
53142- if (stack_shift) {
53143- ret = shift_arg_pages(vma, stack_shift);
53144- if (ret)
53145- goto out_unlock;
53146- }
53147-
53148 /* mprotect_fixup is overkill to remove the temporary stack flags */
53149 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
53150
53151@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
53152 #endif
53153 current->mm->start_stack = bprm->p;
53154 ret = expand_stack(vma, stack_base);
53155+
53156+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
53157+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
53158+ unsigned long size;
53159+ vm_flags_t vm_flags;
53160+
53161+ size = STACK_TOP - vma->vm_end;
53162+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
53163+
53164+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
53165+
53166+#ifdef CONFIG_X86
53167+ if (!ret) {
53168+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
53169+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
53170+ }
53171+#endif
53172+
53173+ }
53174+#endif
53175+
53176 if (ret)
53177 ret = -EFAULT;
53178
53179@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
53180
53181 fsnotify_open(file);
53182
53183+ trace_open_exec(name);
53184+
53185 err = deny_write_access(file);
53186 if (err)
53187 goto exit;
53188@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
53189 old_fs = get_fs();
53190 set_fs(get_ds());
53191 /* The cast to a user pointer is valid due to the set_fs() */
53192- result = vfs_read(file, (void __user *)addr, count, &pos);
53193+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
53194 set_fs(old_fs);
53195 return result;
53196 }
53197@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
53198 }
53199 rcu_read_unlock();
53200
53201- if (p->fs->users > n_fs) {
53202+ if (atomic_read(&p->fs->users) > n_fs) {
53203 bprm->unsafe |= LSM_UNSAFE_SHARE;
53204 } else {
53205 res = -EAGAIN;
53206@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
53207
53208 EXPORT_SYMBOL(search_binary_handler);
53209
53210+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53211+static DEFINE_PER_CPU(u64, exec_counter);
53212+static int __init init_exec_counters(void)
53213+{
53214+ unsigned int cpu;
53215+
53216+ for_each_possible_cpu(cpu) {
53217+ per_cpu(exec_counter, cpu) = (u64)cpu;
53218+ }
53219+
53220+ return 0;
53221+}
53222+early_initcall(init_exec_counters);
53223+static inline void increment_exec_counter(void)
53224+{
53225+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
53226+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
53227+}
53228+#else
53229+static inline void increment_exec_counter(void) {}
53230+#endif
53231+
53232+extern void gr_handle_exec_args(struct linux_binprm *bprm,
53233+ struct user_arg_ptr argv);
53234+
53235 /*
53236 * sys_execve() executes a new program.
53237 */
53238@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
53239 struct user_arg_ptr argv,
53240 struct user_arg_ptr envp)
53241 {
53242+#ifdef CONFIG_GRKERNSEC
53243+ struct file *old_exec_file;
53244+ struct acl_subject_label *old_acl;
53245+ struct rlimit old_rlim[RLIM_NLIMITS];
53246+#endif
53247 struct linux_binprm *bprm;
53248 struct file *file;
53249 struct files_struct *displaced;
53250@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
53251 int retval;
53252 const struct cred *cred = current_cred();
53253
53254+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
53255+
53256 /*
53257 * We move the actual failure in case of RLIMIT_NPROC excess from
53258 * set*uid() to execve() because too many poorly written programs
53259@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
53260 if (IS_ERR(file))
53261 goto out_unmark;
53262
53263+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
53264+ retval = -EPERM;
53265+ goto out_file;
53266+ }
53267+
53268 sched_exec();
53269
53270 bprm->file = file;
53271 bprm->filename = filename;
53272 bprm->interp = filename;
53273
53274+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
53275+ retval = -EACCES;
53276+ goto out_file;
53277+ }
53278+
53279 retval = bprm_mm_init(bprm);
53280 if (retval)
53281 goto out_file;
53282@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
53283 if (retval < 0)
53284 goto out;
53285
53286+#ifdef CONFIG_GRKERNSEC
53287+ old_acl = current->acl;
53288+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
53289+ old_exec_file = current->exec_file;
53290+ get_file(file);
53291+ current->exec_file = file;
53292+#endif
53293+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53294+ /* limit suid stack to 8MB
53295+ * we saved the old limits above and will restore them if this exec fails
53296+ */
53297+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
53298+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
53299+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
53300+#endif
53301+
53302+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
53303+ retval = -EPERM;
53304+ goto out_fail;
53305+ }
53306+
53307+ if (!gr_tpe_allow(file)) {
53308+ retval = -EACCES;
53309+ goto out_fail;
53310+ }
53311+
53312+ if (gr_check_crash_exec(file)) {
53313+ retval = -EACCES;
53314+ goto out_fail;
53315+ }
53316+
53317+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
53318+ bprm->unsafe);
53319+ if (retval < 0)
53320+ goto out_fail;
53321+
53322 retval = copy_strings_kernel(1, &bprm->filename, bprm);
53323 if (retval < 0)
53324- goto out;
53325+ goto out_fail;
53326
53327 bprm->exec = bprm->p;
53328 retval = copy_strings(bprm->envc, envp, bprm);
53329 if (retval < 0)
53330- goto out;
53331+ goto out_fail;
53332
53333 retval = copy_strings(bprm->argc, argv, bprm);
53334 if (retval < 0)
53335- goto out;
53336+ goto out_fail;
53337+
53338+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
53339+
53340+ gr_handle_exec_args(bprm, argv);
53341
53342 retval = search_binary_handler(bprm);
53343 if (retval < 0)
53344- goto out;
53345+ goto out_fail;
53346+#ifdef CONFIG_GRKERNSEC
53347+ if (old_exec_file)
53348+ fput(old_exec_file);
53349+#endif
53350
53351 /* execve succeeded */
53352+
53353+ increment_exec_counter();
53354 current->fs->in_exec = 0;
53355 current->in_execve = 0;
53356 acct_update_integrals(current);
53357@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
53358 put_files_struct(displaced);
53359 return retval;
53360
53361+out_fail:
53362+#ifdef CONFIG_GRKERNSEC
53363+ current->acl = old_acl;
53364+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
53365+ fput(current->exec_file);
53366+ current->exec_file = old_exec_file;
53367+#endif
53368+
53369 out:
53370 if (bprm->mm) {
53371 acct_arg_size(bprm, 0);
53372@@ -1701,3 +1875,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
53373 return error;
53374 }
53375 #endif
53376+
53377+int pax_check_flags(unsigned long *flags)
53378+{
53379+ int retval = 0;
53380+
53381+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
53382+ if (*flags & MF_PAX_SEGMEXEC)
53383+ {
53384+ *flags &= ~MF_PAX_SEGMEXEC;
53385+ retval = -EINVAL;
53386+ }
53387+#endif
53388+
53389+ if ((*flags & MF_PAX_PAGEEXEC)
53390+
53391+#ifdef CONFIG_PAX_PAGEEXEC
53392+ && (*flags & MF_PAX_SEGMEXEC)
53393+#endif
53394+
53395+ )
53396+ {
53397+ *flags &= ~MF_PAX_PAGEEXEC;
53398+ retval = -EINVAL;
53399+ }
53400+
53401+ if ((*flags & MF_PAX_MPROTECT)
53402+
53403+#ifdef CONFIG_PAX_MPROTECT
53404+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
53405+#endif
53406+
53407+ )
53408+ {
53409+ *flags &= ~MF_PAX_MPROTECT;
53410+ retval = -EINVAL;
53411+ }
53412+
53413+ if ((*flags & MF_PAX_EMUTRAMP)
53414+
53415+#ifdef CONFIG_PAX_EMUTRAMP
53416+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
53417+#endif
53418+
53419+ )
53420+ {
53421+ *flags &= ~MF_PAX_EMUTRAMP;
53422+ retval = -EINVAL;
53423+ }
53424+
53425+ return retval;
53426+}
53427+
53428+EXPORT_SYMBOL(pax_check_flags);
53429+
53430+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53431+char *pax_get_path(const struct path *path, char *buf, int buflen)
53432+{
53433+ char *pathname = d_path(path, buf, buflen);
53434+
53435+ if (IS_ERR(pathname))
53436+ goto toolong;
53437+
53438+ pathname = mangle_path(buf, pathname, "\t\n\\");
53439+ if (!pathname)
53440+ goto toolong;
53441+
53442+ *pathname = 0;
53443+ return buf;
53444+
53445+toolong:
53446+ return "<path too long>";
53447+}
53448+EXPORT_SYMBOL(pax_get_path);
53449+
53450+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
53451+{
53452+ struct task_struct *tsk = current;
53453+ struct mm_struct *mm = current->mm;
53454+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
53455+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
53456+ char *path_exec = NULL;
53457+ char *path_fault = NULL;
53458+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
53459+ siginfo_t info = { };
53460+
53461+ if (buffer_exec && buffer_fault) {
53462+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
53463+
53464+ down_read(&mm->mmap_sem);
53465+ vma = mm->mmap;
53466+ while (vma && (!vma_exec || !vma_fault)) {
53467+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
53468+ vma_exec = vma;
53469+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
53470+ vma_fault = vma;
53471+ vma = vma->vm_next;
53472+ }
53473+ if (vma_exec)
53474+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
53475+ if (vma_fault) {
53476+ start = vma_fault->vm_start;
53477+ end = vma_fault->vm_end;
53478+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
53479+ if (vma_fault->vm_file)
53480+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
53481+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
53482+ path_fault = "<heap>";
53483+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
53484+ path_fault = "<stack>";
53485+ else
53486+ path_fault = "<anonymous mapping>";
53487+ }
53488+ up_read(&mm->mmap_sem);
53489+ }
53490+ if (tsk->signal->curr_ip)
53491+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
53492+ else
53493+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
53494+ 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),
53495+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
53496+ free_page((unsigned long)buffer_exec);
53497+ free_page((unsigned long)buffer_fault);
53498+ pax_report_insns(regs, pc, sp);
53499+ info.si_signo = SIGKILL;
53500+ info.si_errno = 0;
53501+ info.si_code = SI_KERNEL;
53502+ info.si_pid = 0;
53503+ info.si_uid = 0;
53504+ do_coredump(&info);
53505+}
53506+#endif
53507+
53508+#ifdef CONFIG_PAX_REFCOUNT
53509+void pax_report_refcount_overflow(struct pt_regs *regs)
53510+{
53511+ if (current->signal->curr_ip)
53512+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
53513+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
53514+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
53515+ else
53516+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
53517+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
53518+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
53519+ preempt_disable();
53520+ show_regs(regs);
53521+ preempt_enable();
53522+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
53523+}
53524+#endif
53525+
53526+#ifdef CONFIG_PAX_USERCOPY
53527+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
53528+static noinline int check_stack_object(const void *obj, unsigned long len)
53529+{
53530+ const void * const stack = task_stack_page(current);
53531+ const void * const stackend = stack + THREAD_SIZE;
53532+
53533+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
53534+ const void *frame = NULL;
53535+ const void *oldframe;
53536+#endif
53537+
53538+ if (obj + len < obj)
53539+ return -1;
53540+
53541+ if (obj + len <= stack || stackend <= obj)
53542+ return 0;
53543+
53544+ if (obj < stack || stackend < obj + len)
53545+ return -1;
53546+
53547+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
53548+ oldframe = __builtin_frame_address(1);
53549+ if (oldframe)
53550+ frame = __builtin_frame_address(2);
53551+ /*
53552+ low ----------------------------------------------> high
53553+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
53554+ ^----------------^
53555+ allow copies only within here
53556+ */
53557+ while (stack <= frame && frame < stackend) {
53558+ /* if obj + len extends past the last frame, this
53559+ check won't pass and the next frame will be 0,
53560+ causing us to bail out and correctly report
53561+ the copy as invalid
53562+ */
53563+ if (obj + len <= frame)
53564+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
53565+ oldframe = frame;
53566+ frame = *(const void * const *)frame;
53567+ }
53568+ return -1;
53569+#else
53570+ return 1;
53571+#endif
53572+}
53573+
53574+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
53575+{
53576+ if (current->signal->curr_ip)
53577+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
53578+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
53579+ else
53580+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
53581+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
53582+ dump_stack();
53583+ gr_handle_kernel_exploit();
53584+ do_group_exit(SIGKILL);
53585+}
53586+#endif
53587+
53588+#ifdef CONFIG_PAX_USERCOPY
53589+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
53590+{
53591+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
53592+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
53593+#ifdef CONFIG_MODULES
53594+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
53595+#else
53596+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
53597+#endif
53598+
53599+#else
53600+ unsigned long textlow = (unsigned long)_stext;
53601+ unsigned long texthigh = (unsigned long)_etext;
53602+#endif
53603+
53604+ if (high <= textlow || low > texthigh)
53605+ return false;
53606+ else
53607+ return true;
53608+}
53609+#endif
53610+
53611+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
53612+{
53613+
53614+#ifdef CONFIG_PAX_USERCOPY
53615+ const char *type;
53616+
53617+ if (!n)
53618+ return;
53619+
53620+ type = check_heap_object(ptr, n);
53621+ if (!type) {
53622+ int ret = check_stack_object(ptr, n);
53623+ if (ret == 1 || ret == 2)
53624+ return;
53625+ if (ret == 0) {
53626+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
53627+ type = "<kernel text>";
53628+ else
53629+ return;
53630+ } else
53631+ type = "<process stack>";
53632+ }
53633+
53634+ pax_report_usercopy(ptr, n, to_user, type);
53635+#endif
53636+
53637+}
53638+EXPORT_SYMBOL(__check_object_size);
53639+
53640+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
53641+void pax_track_stack(void)
53642+{
53643+ unsigned long sp = (unsigned long)&sp;
53644+ if (sp < current_thread_info()->lowest_stack &&
53645+ sp > (unsigned long)task_stack_page(current))
53646+ current_thread_info()->lowest_stack = sp;
53647+}
53648+EXPORT_SYMBOL(pax_track_stack);
53649+#endif
53650+
53651+#ifdef CONFIG_PAX_SIZE_OVERFLOW
53652+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
53653+{
53654+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
53655+ dump_stack();
53656+ do_group_exit(SIGKILL);
53657+}
53658+EXPORT_SYMBOL(report_size_overflow);
53659+#endif
53660diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
53661index 9f9992b..8b59411 100644
53662--- a/fs/ext2/balloc.c
53663+++ b/fs/ext2/balloc.c
53664@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
53665
53666 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
53667 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
53668- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
53669+ if (free_blocks < root_blocks + 1 &&
53670 !uid_eq(sbi->s_resuid, current_fsuid()) &&
53671 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
53672- !in_group_p (sbi->s_resgid))) {
53673+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
53674 return 0;
53675 }
53676 return 1;
53677diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
53678index 22548f5..41521d8 100644
53679--- a/fs/ext3/balloc.c
53680+++ b/fs/ext3/balloc.c
53681@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
53682
53683 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
53684 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
53685- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
53686+ if (free_blocks < root_blocks + 1 &&
53687 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
53688 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
53689- !in_group_p (sbi->s_resgid))) {
53690+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
53691 return 0;
53692 }
53693 return 1;
53694diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
53695index 3742e4c..69a797f 100644
53696--- a/fs/ext4/balloc.c
53697+++ b/fs/ext4/balloc.c
53698@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
53699 /* Hm, nope. Are (enough) root reserved clusters available? */
53700 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
53701 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
53702- capable(CAP_SYS_RESOURCE) ||
53703- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
53704+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
53705+ capable_nolog(CAP_SYS_RESOURCE)) {
53706
53707 if (free_clusters >= (nclusters + dirty_clusters +
53708 resv_clusters))
53709diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
53710index 5aae3d1..b5da7f8 100644
53711--- a/fs/ext4/ext4.h
53712+++ b/fs/ext4/ext4.h
53713@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
53714 unsigned long s_mb_last_start;
53715
53716 /* stats for buddy allocator */
53717- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
53718- atomic_t s_bal_success; /* we found long enough chunks */
53719- atomic_t s_bal_allocated; /* in blocks */
53720- atomic_t s_bal_ex_scanned; /* total extents scanned */
53721- atomic_t s_bal_goals; /* goal hits */
53722- atomic_t s_bal_breaks; /* too long searches */
53723- atomic_t s_bal_2orders; /* 2^order hits */
53724+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
53725+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
53726+ atomic_unchecked_t s_bal_allocated; /* in blocks */
53727+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
53728+ atomic_unchecked_t s_bal_goals; /* goal hits */
53729+ atomic_unchecked_t s_bal_breaks; /* too long searches */
53730+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
53731 spinlock_t s_bal_lock;
53732 unsigned long s_mb_buddies_generated;
53733 unsigned long long s_mb_generation_time;
53734- atomic_t s_mb_lost_chunks;
53735- atomic_t s_mb_preallocated;
53736- atomic_t s_mb_discarded;
53737+ atomic_unchecked_t s_mb_lost_chunks;
53738+ atomic_unchecked_t s_mb_preallocated;
53739+ atomic_unchecked_t s_mb_discarded;
53740 atomic_t s_lock_busy;
53741
53742 /* locality groups */
53743diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
53744index 59c6750..a549154 100644
53745--- a/fs/ext4/mballoc.c
53746+++ b/fs/ext4/mballoc.c
53747@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
53748 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
53749
53750 if (EXT4_SB(sb)->s_mb_stats)
53751- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
53752+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
53753
53754 break;
53755 }
53756@@ -2170,7 +2170,7 @@ repeat:
53757 ac->ac_status = AC_STATUS_CONTINUE;
53758 ac->ac_flags |= EXT4_MB_HINT_FIRST;
53759 cr = 3;
53760- atomic_inc(&sbi->s_mb_lost_chunks);
53761+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
53762 goto repeat;
53763 }
53764 }
53765@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
53766 if (sbi->s_mb_stats) {
53767 ext4_msg(sb, KERN_INFO,
53768 "mballoc: %u blocks %u reqs (%u success)",
53769- atomic_read(&sbi->s_bal_allocated),
53770- atomic_read(&sbi->s_bal_reqs),
53771- atomic_read(&sbi->s_bal_success));
53772+ atomic_read_unchecked(&sbi->s_bal_allocated),
53773+ atomic_read_unchecked(&sbi->s_bal_reqs),
53774+ atomic_read_unchecked(&sbi->s_bal_success));
53775 ext4_msg(sb, KERN_INFO,
53776 "mballoc: %u extents scanned, %u goal hits, "
53777 "%u 2^N hits, %u breaks, %u lost",
53778- atomic_read(&sbi->s_bal_ex_scanned),
53779- atomic_read(&sbi->s_bal_goals),
53780- atomic_read(&sbi->s_bal_2orders),
53781- atomic_read(&sbi->s_bal_breaks),
53782- atomic_read(&sbi->s_mb_lost_chunks));
53783+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
53784+ atomic_read_unchecked(&sbi->s_bal_goals),
53785+ atomic_read_unchecked(&sbi->s_bal_2orders),
53786+ atomic_read_unchecked(&sbi->s_bal_breaks),
53787+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
53788 ext4_msg(sb, KERN_INFO,
53789 "mballoc: %lu generated and it took %Lu",
53790 sbi->s_mb_buddies_generated,
53791 sbi->s_mb_generation_time);
53792 ext4_msg(sb, KERN_INFO,
53793 "mballoc: %u preallocated, %u discarded",
53794- atomic_read(&sbi->s_mb_preallocated),
53795- atomic_read(&sbi->s_mb_discarded));
53796+ atomic_read_unchecked(&sbi->s_mb_preallocated),
53797+ atomic_read_unchecked(&sbi->s_mb_discarded));
53798 }
53799
53800 free_percpu(sbi->s_locality_groups);
53801@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
53802 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
53803
53804 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
53805- atomic_inc(&sbi->s_bal_reqs);
53806- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
53807+ atomic_inc_unchecked(&sbi->s_bal_reqs);
53808+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
53809 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
53810- atomic_inc(&sbi->s_bal_success);
53811- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
53812+ atomic_inc_unchecked(&sbi->s_bal_success);
53813+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
53814 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
53815 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
53816- atomic_inc(&sbi->s_bal_goals);
53817+ atomic_inc_unchecked(&sbi->s_bal_goals);
53818 if (ac->ac_found > sbi->s_mb_max_to_scan)
53819- atomic_inc(&sbi->s_bal_breaks);
53820+ atomic_inc_unchecked(&sbi->s_bal_breaks);
53821 }
53822
53823 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
53824@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
53825 trace_ext4_mb_new_inode_pa(ac, pa);
53826
53827 ext4_mb_use_inode_pa(ac, pa);
53828- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
53829+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
53830
53831 ei = EXT4_I(ac->ac_inode);
53832 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
53833@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
53834 trace_ext4_mb_new_group_pa(ac, pa);
53835
53836 ext4_mb_use_group_pa(ac, pa);
53837- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
53838+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
53839
53840 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
53841 lg = ac->ac_lg;
53842@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
53843 * from the bitmap and continue.
53844 */
53845 }
53846- atomic_add(free, &sbi->s_mb_discarded);
53847+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
53848
53849 return err;
53850 }
53851@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
53852 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
53853 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
53854 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
53855- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
53856+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
53857 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
53858
53859 return 0;
53860diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
53861index 214461e..3614c89 100644
53862--- a/fs/ext4/mmp.c
53863+++ b/fs/ext4/mmp.c
53864@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
53865 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
53866 const char *function, unsigned int line, const char *msg)
53867 {
53868- __ext4_warning(sb, function, line, msg);
53869+ __ext4_warning(sb, function, line, "%s", msg);
53870 __ext4_warning(sb, function, line,
53871 "MMP failure info: last update time: %llu, last update "
53872 "node: %s, last update device: %s\n",
53873diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
53874index 49d3c01..9579efd 100644
53875--- a/fs/ext4/resize.c
53876+++ b/fs/ext4/resize.c
53877@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
53878 ext4_fsblk_t end = start + input->blocks_count;
53879 ext4_group_t group = input->group;
53880 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
53881- unsigned overhead = ext4_group_overhead_blocks(sb, group);
53882- ext4_fsblk_t metaend = start + overhead;
53883+ unsigned overhead;
53884+ ext4_fsblk_t metaend;
53885 struct buffer_head *bh = NULL;
53886 ext4_grpblk_t free_blocks_count, offset;
53887 int err = -EINVAL;
53888
53889+ if (group != sbi->s_groups_count) {
53890+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
53891+ input->group, sbi->s_groups_count);
53892+ return -EINVAL;
53893+ }
53894+
53895+ overhead = ext4_group_overhead_blocks(sb, group);
53896+ metaend = start + overhead;
53897 input->free_blocks_count = free_blocks_count =
53898 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
53899
53900@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
53901 free_blocks_count, input->reserved_blocks);
53902
53903 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
53904- if (group != sbi->s_groups_count)
53905- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
53906- input->group, sbi->s_groups_count);
53907- else if (offset != 0)
53908+ if (offset != 0)
53909 ext4_warning(sb, "Last group not full");
53910 else if (input->reserved_blocks > input->blocks_count / 5)
53911 ext4_warning(sb, "Reserved blocks too high (%u)",
53912diff --git a/fs/ext4/super.c b/fs/ext4/super.c
53913index 3f7c39e..227f24f 100644
53914--- a/fs/ext4/super.c
53915+++ b/fs/ext4/super.c
53916@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
53917 }
53918
53919 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
53920-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
53921+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
53922 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
53923
53924 #ifdef CONFIG_QUOTA
53925@@ -2372,7 +2372,7 @@ struct ext4_attr {
53926 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
53927 const char *, size_t);
53928 int offset;
53929-};
53930+} __do_const;
53931
53932 static int parse_strtoull(const char *buf,
53933 unsigned long long max, unsigned long long *value)
53934diff --git a/fs/fcntl.c b/fs/fcntl.c
53935index 6599222..e7bf0de 100644
53936--- a/fs/fcntl.c
53937+++ b/fs/fcntl.c
53938@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
53939 if (err)
53940 return err;
53941
53942+ if (gr_handle_chroot_fowner(pid, type))
53943+ return -ENOENT;
53944+ if (gr_check_protected_task_fowner(pid, type))
53945+ return -EACCES;
53946+
53947 f_modown(filp, pid, type, force);
53948 return 0;
53949 }
53950diff --git a/fs/fhandle.c b/fs/fhandle.c
53951index 999ff5c..41f4109 100644
53952--- a/fs/fhandle.c
53953+++ b/fs/fhandle.c
53954@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
53955 } else
53956 retval = 0;
53957 /* copy the mount id */
53958- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
53959- sizeof(*mnt_id)) ||
53960+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
53961 copy_to_user(ufh, handle,
53962 sizeof(struct file_handle) + handle_bytes))
53963 retval = -EFAULT;
53964diff --git a/fs/file.c b/fs/file.c
53965index 4a78f98..9447397 100644
53966--- a/fs/file.c
53967+++ b/fs/file.c
53968@@ -16,6 +16,7 @@
53969 #include <linux/slab.h>
53970 #include <linux/vmalloc.h>
53971 #include <linux/file.h>
53972+#include <linux/security.h>
53973 #include <linux/fdtable.h>
53974 #include <linux/bitops.h>
53975 #include <linux/interrupt.h>
53976@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
53977 if (!file)
53978 return __close_fd(files, fd);
53979
53980+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
53981 if (fd >= rlimit(RLIMIT_NOFILE))
53982 return -EBADF;
53983
53984@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
53985 if (unlikely(oldfd == newfd))
53986 return -EINVAL;
53987
53988+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
53989 if (newfd >= rlimit(RLIMIT_NOFILE))
53990 return -EBADF;
53991
53992@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
53993 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
53994 {
53995 int err;
53996+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
53997 if (from >= rlimit(RLIMIT_NOFILE))
53998 return -EINVAL;
53999 err = alloc_fd(from, flags);
54000diff --git a/fs/filesystems.c b/fs/filesystems.c
54001index 92567d9..fcd8cbf 100644
54002--- a/fs/filesystems.c
54003+++ b/fs/filesystems.c
54004@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
54005 int len = dot ? dot - name : strlen(name);
54006
54007 fs = __get_fs_type(name, len);
54008+#ifdef CONFIG_GRKERNSEC_MODHARDEN
54009+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
54010+#else
54011 if (!fs && (request_module("fs-%.*s", len, name) == 0))
54012+#endif
54013 fs = __get_fs_type(name, len);
54014
54015 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
54016diff --git a/fs/fs_struct.c b/fs/fs_struct.c
54017index d8ac61d..79a36f0 100644
54018--- a/fs/fs_struct.c
54019+++ b/fs/fs_struct.c
54020@@ -4,6 +4,7 @@
54021 #include <linux/path.h>
54022 #include <linux/slab.h>
54023 #include <linux/fs_struct.h>
54024+#include <linux/grsecurity.h>
54025 #include "internal.h"
54026
54027 /*
54028@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
54029 write_seqcount_begin(&fs->seq);
54030 old_root = fs->root;
54031 fs->root = *path;
54032+ gr_set_chroot_entries(current, path);
54033 write_seqcount_end(&fs->seq);
54034 spin_unlock(&fs->lock);
54035 if (old_root.dentry)
54036@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
54037 int hits = 0;
54038 spin_lock(&fs->lock);
54039 write_seqcount_begin(&fs->seq);
54040+ /* this root replacement is only done by pivot_root,
54041+ leave grsec's chroot tagging alone for this task
54042+ so that a pivoted root isn't treated as a chroot
54043+ */
54044 hits += replace_path(&fs->root, old_root, new_root);
54045 hits += replace_path(&fs->pwd, old_root, new_root);
54046 write_seqcount_end(&fs->seq);
54047@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
54048 task_lock(tsk);
54049 spin_lock(&fs->lock);
54050 tsk->fs = NULL;
54051- kill = !--fs->users;
54052+ gr_clear_chroot_entries(tsk);
54053+ kill = !atomic_dec_return(&fs->users);
54054 spin_unlock(&fs->lock);
54055 task_unlock(tsk);
54056 if (kill)
54057@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
54058 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
54059 /* We don't need to lock fs - think why ;-) */
54060 if (fs) {
54061- fs->users = 1;
54062+ atomic_set(&fs->users, 1);
54063 fs->in_exec = 0;
54064 spin_lock_init(&fs->lock);
54065 seqcount_init(&fs->seq);
54066@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
54067 spin_lock(&old->lock);
54068 fs->root = old->root;
54069 path_get(&fs->root);
54070+ /* instead of calling gr_set_chroot_entries here,
54071+ we call it from every caller of this function
54072+ */
54073 fs->pwd = old->pwd;
54074 path_get(&fs->pwd);
54075 spin_unlock(&old->lock);
54076@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
54077
54078 task_lock(current);
54079 spin_lock(&fs->lock);
54080- kill = !--fs->users;
54081+ kill = !atomic_dec_return(&fs->users);
54082 current->fs = new_fs;
54083+ gr_set_chroot_entries(current, &new_fs->root);
54084 spin_unlock(&fs->lock);
54085 task_unlock(current);
54086
54087@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
54088
54089 int current_umask(void)
54090 {
54091- return current->fs->umask;
54092+ return current->fs->umask | gr_acl_umask();
54093 }
54094 EXPORT_SYMBOL(current_umask);
54095
54096 /* to be mentioned only in INIT_TASK */
54097 struct fs_struct init_fs = {
54098- .users = 1,
54099+ .users = ATOMIC_INIT(1),
54100 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
54101 .seq = SEQCNT_ZERO,
54102 .umask = 0022,
54103diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
54104index e2cba1f..17a25bb 100644
54105--- a/fs/fscache/cookie.c
54106+++ b/fs/fscache/cookie.c
54107@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
54108 parent ? (char *) parent->def->name : "<no-parent>",
54109 def->name, netfs_data);
54110
54111- fscache_stat(&fscache_n_acquires);
54112+ fscache_stat_unchecked(&fscache_n_acquires);
54113
54114 /* if there's no parent cookie, then we don't create one here either */
54115 if (!parent) {
54116- fscache_stat(&fscache_n_acquires_null);
54117+ fscache_stat_unchecked(&fscache_n_acquires_null);
54118 _leave(" [no parent]");
54119 return NULL;
54120 }
54121@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
54122 /* allocate and initialise a cookie */
54123 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
54124 if (!cookie) {
54125- fscache_stat(&fscache_n_acquires_oom);
54126+ fscache_stat_unchecked(&fscache_n_acquires_oom);
54127 _leave(" [ENOMEM]");
54128 return NULL;
54129 }
54130@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
54131
54132 switch (cookie->def->type) {
54133 case FSCACHE_COOKIE_TYPE_INDEX:
54134- fscache_stat(&fscache_n_cookie_index);
54135+ fscache_stat_unchecked(&fscache_n_cookie_index);
54136 break;
54137 case FSCACHE_COOKIE_TYPE_DATAFILE:
54138- fscache_stat(&fscache_n_cookie_data);
54139+ fscache_stat_unchecked(&fscache_n_cookie_data);
54140 break;
54141 default:
54142- fscache_stat(&fscache_n_cookie_special);
54143+ fscache_stat_unchecked(&fscache_n_cookie_special);
54144 break;
54145 }
54146
54147@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
54148 if (fscache_acquire_non_index_cookie(cookie) < 0) {
54149 atomic_dec(&parent->n_children);
54150 __fscache_cookie_put(cookie);
54151- fscache_stat(&fscache_n_acquires_nobufs);
54152+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
54153 _leave(" = NULL");
54154 return NULL;
54155 }
54156 }
54157
54158- fscache_stat(&fscache_n_acquires_ok);
54159+ fscache_stat_unchecked(&fscache_n_acquires_ok);
54160 _leave(" = %p", cookie);
54161 return cookie;
54162 }
54163@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
54164 cache = fscache_select_cache_for_object(cookie->parent);
54165 if (!cache) {
54166 up_read(&fscache_addremove_sem);
54167- fscache_stat(&fscache_n_acquires_no_cache);
54168+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
54169 _leave(" = -ENOMEDIUM [no cache]");
54170 return -ENOMEDIUM;
54171 }
54172@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
54173 object = cache->ops->alloc_object(cache, cookie);
54174 fscache_stat_d(&fscache_n_cop_alloc_object);
54175 if (IS_ERR(object)) {
54176- fscache_stat(&fscache_n_object_no_alloc);
54177+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
54178 ret = PTR_ERR(object);
54179 goto error;
54180 }
54181
54182- fscache_stat(&fscache_n_object_alloc);
54183+ fscache_stat_unchecked(&fscache_n_object_alloc);
54184
54185 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
54186
54187@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
54188
54189 _enter("{%s}", cookie->def->name);
54190
54191- fscache_stat(&fscache_n_invalidates);
54192+ fscache_stat_unchecked(&fscache_n_invalidates);
54193
54194 /* Only permit invalidation of data files. Invalidating an index will
54195 * require the caller to release all its attachments to the tree rooted
54196@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
54197 {
54198 struct fscache_object *object;
54199
54200- fscache_stat(&fscache_n_updates);
54201+ fscache_stat_unchecked(&fscache_n_updates);
54202
54203 if (!cookie) {
54204- fscache_stat(&fscache_n_updates_null);
54205+ fscache_stat_unchecked(&fscache_n_updates_null);
54206 _leave(" [no cookie]");
54207 return;
54208 }
54209@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
54210 struct fscache_object *object;
54211 unsigned long event;
54212
54213- fscache_stat(&fscache_n_relinquishes);
54214+ fscache_stat_unchecked(&fscache_n_relinquishes);
54215 if (retire)
54216- fscache_stat(&fscache_n_relinquishes_retire);
54217+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
54218
54219 if (!cookie) {
54220- fscache_stat(&fscache_n_relinquishes_null);
54221+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
54222 _leave(" [no cookie]");
54223 return;
54224 }
54225@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
54226
54227 /* wait for the cookie to finish being instantiated (or to fail) */
54228 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
54229- fscache_stat(&fscache_n_relinquishes_waitcrt);
54230+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
54231 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
54232 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
54233 }
54234diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
54235index ee38fef..0a326d4 100644
54236--- a/fs/fscache/internal.h
54237+++ b/fs/fscache/internal.h
54238@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
54239 * stats.c
54240 */
54241 #ifdef CONFIG_FSCACHE_STATS
54242-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
54243-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
54244+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
54245+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
54246
54247-extern atomic_t fscache_n_op_pend;
54248-extern atomic_t fscache_n_op_run;
54249-extern atomic_t fscache_n_op_enqueue;
54250-extern atomic_t fscache_n_op_deferred_release;
54251-extern atomic_t fscache_n_op_release;
54252-extern atomic_t fscache_n_op_gc;
54253-extern atomic_t fscache_n_op_cancelled;
54254-extern atomic_t fscache_n_op_rejected;
54255+extern atomic_unchecked_t fscache_n_op_pend;
54256+extern atomic_unchecked_t fscache_n_op_run;
54257+extern atomic_unchecked_t fscache_n_op_enqueue;
54258+extern atomic_unchecked_t fscache_n_op_deferred_release;
54259+extern atomic_unchecked_t fscache_n_op_release;
54260+extern atomic_unchecked_t fscache_n_op_gc;
54261+extern atomic_unchecked_t fscache_n_op_cancelled;
54262+extern atomic_unchecked_t fscache_n_op_rejected;
54263
54264-extern atomic_t fscache_n_attr_changed;
54265-extern atomic_t fscache_n_attr_changed_ok;
54266-extern atomic_t fscache_n_attr_changed_nobufs;
54267-extern atomic_t fscache_n_attr_changed_nomem;
54268-extern atomic_t fscache_n_attr_changed_calls;
54269+extern atomic_unchecked_t fscache_n_attr_changed;
54270+extern atomic_unchecked_t fscache_n_attr_changed_ok;
54271+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
54272+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
54273+extern atomic_unchecked_t fscache_n_attr_changed_calls;
54274
54275-extern atomic_t fscache_n_allocs;
54276-extern atomic_t fscache_n_allocs_ok;
54277-extern atomic_t fscache_n_allocs_wait;
54278-extern atomic_t fscache_n_allocs_nobufs;
54279-extern atomic_t fscache_n_allocs_intr;
54280-extern atomic_t fscache_n_allocs_object_dead;
54281-extern atomic_t fscache_n_alloc_ops;
54282-extern atomic_t fscache_n_alloc_op_waits;
54283+extern atomic_unchecked_t fscache_n_allocs;
54284+extern atomic_unchecked_t fscache_n_allocs_ok;
54285+extern atomic_unchecked_t fscache_n_allocs_wait;
54286+extern atomic_unchecked_t fscache_n_allocs_nobufs;
54287+extern atomic_unchecked_t fscache_n_allocs_intr;
54288+extern atomic_unchecked_t fscache_n_allocs_object_dead;
54289+extern atomic_unchecked_t fscache_n_alloc_ops;
54290+extern atomic_unchecked_t fscache_n_alloc_op_waits;
54291
54292-extern atomic_t fscache_n_retrievals;
54293-extern atomic_t fscache_n_retrievals_ok;
54294-extern atomic_t fscache_n_retrievals_wait;
54295-extern atomic_t fscache_n_retrievals_nodata;
54296-extern atomic_t fscache_n_retrievals_nobufs;
54297-extern atomic_t fscache_n_retrievals_intr;
54298-extern atomic_t fscache_n_retrievals_nomem;
54299-extern atomic_t fscache_n_retrievals_object_dead;
54300-extern atomic_t fscache_n_retrieval_ops;
54301-extern atomic_t fscache_n_retrieval_op_waits;
54302+extern atomic_unchecked_t fscache_n_retrievals;
54303+extern atomic_unchecked_t fscache_n_retrievals_ok;
54304+extern atomic_unchecked_t fscache_n_retrievals_wait;
54305+extern atomic_unchecked_t fscache_n_retrievals_nodata;
54306+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
54307+extern atomic_unchecked_t fscache_n_retrievals_intr;
54308+extern atomic_unchecked_t fscache_n_retrievals_nomem;
54309+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
54310+extern atomic_unchecked_t fscache_n_retrieval_ops;
54311+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
54312
54313-extern atomic_t fscache_n_stores;
54314-extern atomic_t fscache_n_stores_ok;
54315-extern atomic_t fscache_n_stores_again;
54316-extern atomic_t fscache_n_stores_nobufs;
54317-extern atomic_t fscache_n_stores_oom;
54318-extern atomic_t fscache_n_store_ops;
54319-extern atomic_t fscache_n_store_calls;
54320-extern atomic_t fscache_n_store_pages;
54321-extern atomic_t fscache_n_store_radix_deletes;
54322-extern atomic_t fscache_n_store_pages_over_limit;
54323+extern atomic_unchecked_t fscache_n_stores;
54324+extern atomic_unchecked_t fscache_n_stores_ok;
54325+extern atomic_unchecked_t fscache_n_stores_again;
54326+extern atomic_unchecked_t fscache_n_stores_nobufs;
54327+extern atomic_unchecked_t fscache_n_stores_oom;
54328+extern atomic_unchecked_t fscache_n_store_ops;
54329+extern atomic_unchecked_t fscache_n_store_calls;
54330+extern atomic_unchecked_t fscache_n_store_pages;
54331+extern atomic_unchecked_t fscache_n_store_radix_deletes;
54332+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
54333
54334-extern atomic_t fscache_n_store_vmscan_not_storing;
54335-extern atomic_t fscache_n_store_vmscan_gone;
54336-extern atomic_t fscache_n_store_vmscan_busy;
54337-extern atomic_t fscache_n_store_vmscan_cancelled;
54338-extern atomic_t fscache_n_store_vmscan_wait;
54339+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
54340+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
54341+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
54342+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
54343+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
54344
54345-extern atomic_t fscache_n_marks;
54346-extern atomic_t fscache_n_uncaches;
54347+extern atomic_unchecked_t fscache_n_marks;
54348+extern atomic_unchecked_t fscache_n_uncaches;
54349
54350-extern atomic_t fscache_n_acquires;
54351-extern atomic_t fscache_n_acquires_null;
54352-extern atomic_t fscache_n_acquires_no_cache;
54353-extern atomic_t fscache_n_acquires_ok;
54354-extern atomic_t fscache_n_acquires_nobufs;
54355-extern atomic_t fscache_n_acquires_oom;
54356+extern atomic_unchecked_t fscache_n_acquires;
54357+extern atomic_unchecked_t fscache_n_acquires_null;
54358+extern atomic_unchecked_t fscache_n_acquires_no_cache;
54359+extern atomic_unchecked_t fscache_n_acquires_ok;
54360+extern atomic_unchecked_t fscache_n_acquires_nobufs;
54361+extern atomic_unchecked_t fscache_n_acquires_oom;
54362
54363-extern atomic_t fscache_n_invalidates;
54364-extern atomic_t fscache_n_invalidates_run;
54365+extern atomic_unchecked_t fscache_n_invalidates;
54366+extern atomic_unchecked_t fscache_n_invalidates_run;
54367
54368-extern atomic_t fscache_n_updates;
54369-extern atomic_t fscache_n_updates_null;
54370-extern atomic_t fscache_n_updates_run;
54371+extern atomic_unchecked_t fscache_n_updates;
54372+extern atomic_unchecked_t fscache_n_updates_null;
54373+extern atomic_unchecked_t fscache_n_updates_run;
54374
54375-extern atomic_t fscache_n_relinquishes;
54376-extern atomic_t fscache_n_relinquishes_null;
54377-extern atomic_t fscache_n_relinquishes_waitcrt;
54378-extern atomic_t fscache_n_relinquishes_retire;
54379+extern atomic_unchecked_t fscache_n_relinquishes;
54380+extern atomic_unchecked_t fscache_n_relinquishes_null;
54381+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
54382+extern atomic_unchecked_t fscache_n_relinquishes_retire;
54383
54384-extern atomic_t fscache_n_cookie_index;
54385-extern atomic_t fscache_n_cookie_data;
54386-extern atomic_t fscache_n_cookie_special;
54387+extern atomic_unchecked_t fscache_n_cookie_index;
54388+extern atomic_unchecked_t fscache_n_cookie_data;
54389+extern atomic_unchecked_t fscache_n_cookie_special;
54390
54391-extern atomic_t fscache_n_object_alloc;
54392-extern atomic_t fscache_n_object_no_alloc;
54393-extern atomic_t fscache_n_object_lookups;
54394-extern atomic_t fscache_n_object_lookups_negative;
54395-extern atomic_t fscache_n_object_lookups_positive;
54396-extern atomic_t fscache_n_object_lookups_timed_out;
54397-extern atomic_t fscache_n_object_created;
54398-extern atomic_t fscache_n_object_avail;
54399-extern atomic_t fscache_n_object_dead;
54400+extern atomic_unchecked_t fscache_n_object_alloc;
54401+extern atomic_unchecked_t fscache_n_object_no_alloc;
54402+extern atomic_unchecked_t fscache_n_object_lookups;
54403+extern atomic_unchecked_t fscache_n_object_lookups_negative;
54404+extern atomic_unchecked_t fscache_n_object_lookups_positive;
54405+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
54406+extern atomic_unchecked_t fscache_n_object_created;
54407+extern atomic_unchecked_t fscache_n_object_avail;
54408+extern atomic_unchecked_t fscache_n_object_dead;
54409
54410-extern atomic_t fscache_n_checkaux_none;
54411-extern atomic_t fscache_n_checkaux_okay;
54412-extern atomic_t fscache_n_checkaux_update;
54413-extern atomic_t fscache_n_checkaux_obsolete;
54414+extern atomic_unchecked_t fscache_n_checkaux_none;
54415+extern atomic_unchecked_t fscache_n_checkaux_okay;
54416+extern atomic_unchecked_t fscache_n_checkaux_update;
54417+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
54418
54419 extern atomic_t fscache_n_cop_alloc_object;
54420 extern atomic_t fscache_n_cop_lookup_object;
54421@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
54422 atomic_inc(stat);
54423 }
54424
54425+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
54426+{
54427+ atomic_inc_unchecked(stat);
54428+}
54429+
54430 static inline void fscache_stat_d(atomic_t *stat)
54431 {
54432 atomic_dec(stat);
54433@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
54434
54435 #define __fscache_stat(stat) (NULL)
54436 #define fscache_stat(stat) do {} while (0)
54437+#define fscache_stat_unchecked(stat) do {} while (0)
54438 #define fscache_stat_d(stat) do {} while (0)
54439 #endif
54440
54441diff --git a/fs/fscache/object.c b/fs/fscache/object.c
54442index 50d41c1..10ee117 100644
54443--- a/fs/fscache/object.c
54444+++ b/fs/fscache/object.c
54445@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
54446 /* Invalidate an object on disk */
54447 case FSCACHE_OBJECT_INVALIDATING:
54448 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
54449- fscache_stat(&fscache_n_invalidates_run);
54450+ fscache_stat_unchecked(&fscache_n_invalidates_run);
54451 fscache_stat(&fscache_n_cop_invalidate_object);
54452 fscache_invalidate_object(object);
54453 fscache_stat_d(&fscache_n_cop_invalidate_object);
54454@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
54455 /* update the object metadata on disk */
54456 case FSCACHE_OBJECT_UPDATING:
54457 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
54458- fscache_stat(&fscache_n_updates_run);
54459+ fscache_stat_unchecked(&fscache_n_updates_run);
54460 fscache_stat(&fscache_n_cop_update_object);
54461 object->cache->ops->update_object(object);
54462 fscache_stat_d(&fscache_n_cop_update_object);
54463@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
54464 spin_lock(&object->lock);
54465 object->state = FSCACHE_OBJECT_DEAD;
54466 spin_unlock(&object->lock);
54467- fscache_stat(&fscache_n_object_dead);
54468+ fscache_stat_unchecked(&fscache_n_object_dead);
54469 goto terminal_transit;
54470
54471 /* handle the parent cache of this object being withdrawn from
54472@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
54473 spin_lock(&object->lock);
54474 object->state = FSCACHE_OBJECT_DEAD;
54475 spin_unlock(&object->lock);
54476- fscache_stat(&fscache_n_object_dead);
54477+ fscache_stat_unchecked(&fscache_n_object_dead);
54478 goto terminal_transit;
54479
54480 /* complain about the object being woken up once it is
54481@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
54482 parent->cookie->def->name, cookie->def->name,
54483 object->cache->tag->name);
54484
54485- fscache_stat(&fscache_n_object_lookups);
54486+ fscache_stat_unchecked(&fscache_n_object_lookups);
54487 fscache_stat(&fscache_n_cop_lookup_object);
54488 ret = object->cache->ops->lookup_object(object);
54489 fscache_stat_d(&fscache_n_cop_lookup_object);
54490@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
54491 if (ret == -ETIMEDOUT) {
54492 /* probably stuck behind another object, so move this one to
54493 * the back of the queue */
54494- fscache_stat(&fscache_n_object_lookups_timed_out);
54495+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
54496 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
54497 }
54498
54499@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
54500
54501 spin_lock(&object->lock);
54502 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
54503- fscache_stat(&fscache_n_object_lookups_negative);
54504+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
54505
54506 /* transit here to allow write requests to begin stacking up
54507 * and read requests to begin returning ENODATA */
54508@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
54509 * result, in which case there may be data available */
54510 spin_lock(&object->lock);
54511 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
54512- fscache_stat(&fscache_n_object_lookups_positive);
54513+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
54514
54515 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
54516
54517@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
54518 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
54519 } else {
54520 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
54521- fscache_stat(&fscache_n_object_created);
54522+ fscache_stat_unchecked(&fscache_n_object_created);
54523
54524 object->state = FSCACHE_OBJECT_AVAILABLE;
54525 spin_unlock(&object->lock);
54526@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
54527 fscache_enqueue_dependents(object);
54528
54529 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
54530- fscache_stat(&fscache_n_object_avail);
54531+ fscache_stat_unchecked(&fscache_n_object_avail);
54532
54533 _leave("");
54534 }
54535@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
54536 enum fscache_checkaux result;
54537
54538 if (!object->cookie->def->check_aux) {
54539- fscache_stat(&fscache_n_checkaux_none);
54540+ fscache_stat_unchecked(&fscache_n_checkaux_none);
54541 return FSCACHE_CHECKAUX_OKAY;
54542 }
54543
54544@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
54545 switch (result) {
54546 /* entry okay as is */
54547 case FSCACHE_CHECKAUX_OKAY:
54548- fscache_stat(&fscache_n_checkaux_okay);
54549+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
54550 break;
54551
54552 /* entry requires update */
54553 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
54554- fscache_stat(&fscache_n_checkaux_update);
54555+ fscache_stat_unchecked(&fscache_n_checkaux_update);
54556 break;
54557
54558 /* entry requires deletion */
54559 case FSCACHE_CHECKAUX_OBSOLETE:
54560- fscache_stat(&fscache_n_checkaux_obsolete);
54561+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
54562 break;
54563
54564 default:
54565diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
54566index 762a9ec..2023284 100644
54567--- a/fs/fscache/operation.c
54568+++ b/fs/fscache/operation.c
54569@@ -17,7 +17,7 @@
54570 #include <linux/slab.h>
54571 #include "internal.h"
54572
54573-atomic_t fscache_op_debug_id;
54574+atomic_unchecked_t fscache_op_debug_id;
54575 EXPORT_SYMBOL(fscache_op_debug_id);
54576
54577 /**
54578@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
54579 ASSERTCMP(atomic_read(&op->usage), >, 0);
54580 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
54581
54582- fscache_stat(&fscache_n_op_enqueue);
54583+ fscache_stat_unchecked(&fscache_n_op_enqueue);
54584 switch (op->flags & FSCACHE_OP_TYPE) {
54585 case FSCACHE_OP_ASYNC:
54586 _debug("queue async");
54587@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
54588 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
54589 if (op->processor)
54590 fscache_enqueue_operation(op);
54591- fscache_stat(&fscache_n_op_run);
54592+ fscache_stat_unchecked(&fscache_n_op_run);
54593 }
54594
54595 /*
54596@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
54597 if (object->n_in_progress > 0) {
54598 atomic_inc(&op->usage);
54599 list_add_tail(&op->pend_link, &object->pending_ops);
54600- fscache_stat(&fscache_n_op_pend);
54601+ fscache_stat_unchecked(&fscache_n_op_pend);
54602 } else if (!list_empty(&object->pending_ops)) {
54603 atomic_inc(&op->usage);
54604 list_add_tail(&op->pend_link, &object->pending_ops);
54605- fscache_stat(&fscache_n_op_pend);
54606+ fscache_stat_unchecked(&fscache_n_op_pend);
54607 fscache_start_operations(object);
54608 } else {
54609 ASSERTCMP(object->n_in_progress, ==, 0);
54610@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
54611 object->n_exclusive++; /* reads and writes must wait */
54612 atomic_inc(&op->usage);
54613 list_add_tail(&op->pend_link, &object->pending_ops);
54614- fscache_stat(&fscache_n_op_pend);
54615+ fscache_stat_unchecked(&fscache_n_op_pend);
54616 ret = 0;
54617 } else {
54618 /* If we're in any other state, there must have been an I/O
54619@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
54620 if (object->n_exclusive > 0) {
54621 atomic_inc(&op->usage);
54622 list_add_tail(&op->pend_link, &object->pending_ops);
54623- fscache_stat(&fscache_n_op_pend);
54624+ fscache_stat_unchecked(&fscache_n_op_pend);
54625 } else if (!list_empty(&object->pending_ops)) {
54626 atomic_inc(&op->usage);
54627 list_add_tail(&op->pend_link, &object->pending_ops);
54628- fscache_stat(&fscache_n_op_pend);
54629+ fscache_stat_unchecked(&fscache_n_op_pend);
54630 fscache_start_operations(object);
54631 } else {
54632 ASSERTCMP(object->n_exclusive, ==, 0);
54633@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
54634 object->n_ops++;
54635 atomic_inc(&op->usage);
54636 list_add_tail(&op->pend_link, &object->pending_ops);
54637- fscache_stat(&fscache_n_op_pend);
54638+ fscache_stat_unchecked(&fscache_n_op_pend);
54639 ret = 0;
54640 } else if (object->state == FSCACHE_OBJECT_DYING ||
54641 object->state == FSCACHE_OBJECT_LC_DYING ||
54642 object->state == FSCACHE_OBJECT_WITHDRAWING) {
54643- fscache_stat(&fscache_n_op_rejected);
54644+ fscache_stat_unchecked(&fscache_n_op_rejected);
54645 op->state = FSCACHE_OP_ST_CANCELLED;
54646 ret = -ENOBUFS;
54647 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
54648@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
54649 ret = -EBUSY;
54650 if (op->state == FSCACHE_OP_ST_PENDING) {
54651 ASSERT(!list_empty(&op->pend_link));
54652- fscache_stat(&fscache_n_op_cancelled);
54653+ fscache_stat_unchecked(&fscache_n_op_cancelled);
54654 list_del_init(&op->pend_link);
54655 if (do_cancel)
54656 do_cancel(op);
54657@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
54658 while (!list_empty(&object->pending_ops)) {
54659 op = list_entry(object->pending_ops.next,
54660 struct fscache_operation, pend_link);
54661- fscache_stat(&fscache_n_op_cancelled);
54662+ fscache_stat_unchecked(&fscache_n_op_cancelled);
54663 list_del_init(&op->pend_link);
54664
54665 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
54666@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
54667 op->state, ==, FSCACHE_OP_ST_CANCELLED);
54668 op->state = FSCACHE_OP_ST_DEAD;
54669
54670- fscache_stat(&fscache_n_op_release);
54671+ fscache_stat_unchecked(&fscache_n_op_release);
54672
54673 if (op->release) {
54674 op->release(op);
54675@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
54676 * lock, and defer it otherwise */
54677 if (!spin_trylock(&object->lock)) {
54678 _debug("defer put");
54679- fscache_stat(&fscache_n_op_deferred_release);
54680+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
54681
54682 cache = object->cache;
54683 spin_lock(&cache->op_gc_list_lock);
54684@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
54685
54686 _debug("GC DEFERRED REL OBJ%x OP%x",
54687 object->debug_id, op->debug_id);
54688- fscache_stat(&fscache_n_op_gc);
54689+ fscache_stat_unchecked(&fscache_n_op_gc);
54690
54691 ASSERTCMP(atomic_read(&op->usage), ==, 0);
54692 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
54693diff --git a/fs/fscache/page.c b/fs/fscache/page.c
54694index ff000e5..c44ec6d 100644
54695--- a/fs/fscache/page.c
54696+++ b/fs/fscache/page.c
54697@@ -61,7 +61,7 @@ try_again:
54698 val = radix_tree_lookup(&cookie->stores, page->index);
54699 if (!val) {
54700 rcu_read_unlock();
54701- fscache_stat(&fscache_n_store_vmscan_not_storing);
54702+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
54703 __fscache_uncache_page(cookie, page);
54704 return true;
54705 }
54706@@ -91,11 +91,11 @@ try_again:
54707 spin_unlock(&cookie->stores_lock);
54708
54709 if (xpage) {
54710- fscache_stat(&fscache_n_store_vmscan_cancelled);
54711- fscache_stat(&fscache_n_store_radix_deletes);
54712+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
54713+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
54714 ASSERTCMP(xpage, ==, page);
54715 } else {
54716- fscache_stat(&fscache_n_store_vmscan_gone);
54717+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
54718 }
54719
54720 wake_up_bit(&cookie->flags, 0);
54721@@ -110,11 +110,11 @@ page_busy:
54722 * sleeping on memory allocation, so we may need to impose a timeout
54723 * too. */
54724 if (!(gfp & __GFP_WAIT)) {
54725- fscache_stat(&fscache_n_store_vmscan_busy);
54726+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
54727 return false;
54728 }
54729
54730- fscache_stat(&fscache_n_store_vmscan_wait);
54731+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
54732 __fscache_wait_on_page_write(cookie, page);
54733 gfp &= ~__GFP_WAIT;
54734 goto try_again;
54735@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
54736 FSCACHE_COOKIE_STORING_TAG);
54737 if (!radix_tree_tag_get(&cookie->stores, page->index,
54738 FSCACHE_COOKIE_PENDING_TAG)) {
54739- fscache_stat(&fscache_n_store_radix_deletes);
54740+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
54741 xpage = radix_tree_delete(&cookie->stores, page->index);
54742 }
54743 spin_unlock(&cookie->stores_lock);
54744@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
54745
54746 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
54747
54748- fscache_stat(&fscache_n_attr_changed_calls);
54749+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
54750
54751 if (fscache_object_is_active(object)) {
54752 fscache_stat(&fscache_n_cop_attr_changed);
54753@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
54754
54755 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
54756
54757- fscache_stat(&fscache_n_attr_changed);
54758+ fscache_stat_unchecked(&fscache_n_attr_changed);
54759
54760 op = kzalloc(sizeof(*op), GFP_KERNEL);
54761 if (!op) {
54762- fscache_stat(&fscache_n_attr_changed_nomem);
54763+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
54764 _leave(" = -ENOMEM");
54765 return -ENOMEM;
54766 }
54767@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
54768 if (fscache_submit_exclusive_op(object, op) < 0)
54769 goto nobufs;
54770 spin_unlock(&cookie->lock);
54771- fscache_stat(&fscache_n_attr_changed_ok);
54772+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
54773 fscache_put_operation(op);
54774 _leave(" = 0");
54775 return 0;
54776@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
54777 nobufs:
54778 spin_unlock(&cookie->lock);
54779 kfree(op);
54780- fscache_stat(&fscache_n_attr_changed_nobufs);
54781+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
54782 _leave(" = %d", -ENOBUFS);
54783 return -ENOBUFS;
54784 }
54785@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
54786 /* allocate a retrieval operation and attempt to submit it */
54787 op = kzalloc(sizeof(*op), GFP_NOIO);
54788 if (!op) {
54789- fscache_stat(&fscache_n_retrievals_nomem);
54790+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
54791 return NULL;
54792 }
54793
54794@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
54795 return 0;
54796 }
54797
54798- fscache_stat(&fscache_n_retrievals_wait);
54799+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
54800
54801 jif = jiffies;
54802 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
54803 fscache_wait_bit_interruptible,
54804 TASK_INTERRUPTIBLE) != 0) {
54805- fscache_stat(&fscache_n_retrievals_intr);
54806+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
54807 _leave(" = -ERESTARTSYS");
54808 return -ERESTARTSYS;
54809 }
54810@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
54811 */
54812 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
54813 struct fscache_retrieval *op,
54814- atomic_t *stat_op_waits,
54815- atomic_t *stat_object_dead)
54816+ atomic_unchecked_t *stat_op_waits,
54817+ atomic_unchecked_t *stat_object_dead)
54818 {
54819 int ret;
54820
54821@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
54822 goto check_if_dead;
54823
54824 _debug(">>> WT");
54825- fscache_stat(stat_op_waits);
54826+ fscache_stat_unchecked(stat_op_waits);
54827 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
54828 fscache_wait_bit_interruptible,
54829 TASK_INTERRUPTIBLE) != 0) {
54830@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
54831
54832 check_if_dead:
54833 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
54834- fscache_stat(stat_object_dead);
54835+ fscache_stat_unchecked(stat_object_dead);
54836 _leave(" = -ENOBUFS [cancelled]");
54837 return -ENOBUFS;
54838 }
54839 if (unlikely(fscache_object_is_dead(object))) {
54840 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
54841 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
54842- fscache_stat(stat_object_dead);
54843+ fscache_stat_unchecked(stat_object_dead);
54844 return -ENOBUFS;
54845 }
54846 return 0;
54847@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
54848
54849 _enter("%p,%p,,,", cookie, page);
54850
54851- fscache_stat(&fscache_n_retrievals);
54852+ fscache_stat_unchecked(&fscache_n_retrievals);
54853
54854 if (hlist_empty(&cookie->backing_objects))
54855 goto nobufs;
54856@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
54857 goto nobufs_unlock_dec;
54858 spin_unlock(&cookie->lock);
54859
54860- fscache_stat(&fscache_n_retrieval_ops);
54861+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
54862
54863 /* pin the netfs read context in case we need to do the actual netfs
54864 * read because we've encountered a cache read failure */
54865@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
54866
54867 error:
54868 if (ret == -ENOMEM)
54869- fscache_stat(&fscache_n_retrievals_nomem);
54870+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
54871 else if (ret == -ERESTARTSYS)
54872- fscache_stat(&fscache_n_retrievals_intr);
54873+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
54874 else if (ret == -ENODATA)
54875- fscache_stat(&fscache_n_retrievals_nodata);
54876+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
54877 else if (ret < 0)
54878- fscache_stat(&fscache_n_retrievals_nobufs);
54879+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
54880 else
54881- fscache_stat(&fscache_n_retrievals_ok);
54882+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
54883
54884 fscache_put_retrieval(op);
54885 _leave(" = %d", ret);
54886@@ -467,7 +467,7 @@ nobufs_unlock:
54887 spin_unlock(&cookie->lock);
54888 kfree(op);
54889 nobufs:
54890- fscache_stat(&fscache_n_retrievals_nobufs);
54891+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
54892 _leave(" = -ENOBUFS");
54893 return -ENOBUFS;
54894 }
54895@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
54896
54897 _enter("%p,,%d,,,", cookie, *nr_pages);
54898
54899- fscache_stat(&fscache_n_retrievals);
54900+ fscache_stat_unchecked(&fscache_n_retrievals);
54901
54902 if (hlist_empty(&cookie->backing_objects))
54903 goto nobufs;
54904@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
54905 goto nobufs_unlock_dec;
54906 spin_unlock(&cookie->lock);
54907
54908- fscache_stat(&fscache_n_retrieval_ops);
54909+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
54910
54911 /* pin the netfs read context in case we need to do the actual netfs
54912 * read because we've encountered a cache read failure */
54913@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
54914
54915 error:
54916 if (ret == -ENOMEM)
54917- fscache_stat(&fscache_n_retrievals_nomem);
54918+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
54919 else if (ret == -ERESTARTSYS)
54920- fscache_stat(&fscache_n_retrievals_intr);
54921+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
54922 else if (ret == -ENODATA)
54923- fscache_stat(&fscache_n_retrievals_nodata);
54924+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
54925 else if (ret < 0)
54926- fscache_stat(&fscache_n_retrievals_nobufs);
54927+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
54928 else
54929- fscache_stat(&fscache_n_retrievals_ok);
54930+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
54931
54932 fscache_put_retrieval(op);
54933 _leave(" = %d", ret);
54934@@ -591,7 +591,7 @@ nobufs_unlock:
54935 spin_unlock(&cookie->lock);
54936 kfree(op);
54937 nobufs:
54938- fscache_stat(&fscache_n_retrievals_nobufs);
54939+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
54940 _leave(" = -ENOBUFS");
54941 return -ENOBUFS;
54942 }
54943@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
54944
54945 _enter("%p,%p,,,", cookie, page);
54946
54947- fscache_stat(&fscache_n_allocs);
54948+ fscache_stat_unchecked(&fscache_n_allocs);
54949
54950 if (hlist_empty(&cookie->backing_objects))
54951 goto nobufs;
54952@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
54953 goto nobufs_unlock;
54954 spin_unlock(&cookie->lock);
54955
54956- fscache_stat(&fscache_n_alloc_ops);
54957+ fscache_stat_unchecked(&fscache_n_alloc_ops);
54958
54959 ret = fscache_wait_for_retrieval_activation(
54960 object, op,
54961@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
54962
54963 error:
54964 if (ret == -ERESTARTSYS)
54965- fscache_stat(&fscache_n_allocs_intr);
54966+ fscache_stat_unchecked(&fscache_n_allocs_intr);
54967 else if (ret < 0)
54968- fscache_stat(&fscache_n_allocs_nobufs);
54969+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
54970 else
54971- fscache_stat(&fscache_n_allocs_ok);
54972+ fscache_stat_unchecked(&fscache_n_allocs_ok);
54973
54974 fscache_put_retrieval(op);
54975 _leave(" = %d", ret);
54976@@ -677,7 +677,7 @@ nobufs_unlock:
54977 spin_unlock(&cookie->lock);
54978 kfree(op);
54979 nobufs:
54980- fscache_stat(&fscache_n_allocs_nobufs);
54981+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
54982 _leave(" = -ENOBUFS");
54983 return -ENOBUFS;
54984 }
54985@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
54986
54987 spin_lock(&cookie->stores_lock);
54988
54989- fscache_stat(&fscache_n_store_calls);
54990+ fscache_stat_unchecked(&fscache_n_store_calls);
54991
54992 /* find a page to store */
54993 page = NULL;
54994@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
54995 page = results[0];
54996 _debug("gang %d [%lx]", n, page->index);
54997 if (page->index > op->store_limit) {
54998- fscache_stat(&fscache_n_store_pages_over_limit);
54999+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
55000 goto superseded;
55001 }
55002
55003@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
55004 spin_unlock(&cookie->stores_lock);
55005 spin_unlock(&object->lock);
55006
55007- fscache_stat(&fscache_n_store_pages);
55008+ fscache_stat_unchecked(&fscache_n_store_pages);
55009 fscache_stat(&fscache_n_cop_write_page);
55010 ret = object->cache->ops->write_page(op, page);
55011 fscache_stat_d(&fscache_n_cop_write_page);
55012@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
55013 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
55014 ASSERT(PageFsCache(page));
55015
55016- fscache_stat(&fscache_n_stores);
55017+ fscache_stat_unchecked(&fscache_n_stores);
55018
55019 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
55020 _leave(" = -ENOBUFS [invalidating]");
55021@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
55022 spin_unlock(&cookie->stores_lock);
55023 spin_unlock(&object->lock);
55024
55025- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
55026+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
55027 op->store_limit = object->store_limit;
55028
55029 if (fscache_submit_op(object, &op->op) < 0)
55030@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
55031
55032 spin_unlock(&cookie->lock);
55033 radix_tree_preload_end();
55034- fscache_stat(&fscache_n_store_ops);
55035- fscache_stat(&fscache_n_stores_ok);
55036+ fscache_stat_unchecked(&fscache_n_store_ops);
55037+ fscache_stat_unchecked(&fscache_n_stores_ok);
55038
55039 /* the work queue now carries its own ref on the object */
55040 fscache_put_operation(&op->op);
55041@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
55042 return 0;
55043
55044 already_queued:
55045- fscache_stat(&fscache_n_stores_again);
55046+ fscache_stat_unchecked(&fscache_n_stores_again);
55047 already_pending:
55048 spin_unlock(&cookie->stores_lock);
55049 spin_unlock(&object->lock);
55050 spin_unlock(&cookie->lock);
55051 radix_tree_preload_end();
55052 kfree(op);
55053- fscache_stat(&fscache_n_stores_ok);
55054+ fscache_stat_unchecked(&fscache_n_stores_ok);
55055 _leave(" = 0");
55056 return 0;
55057
55058@@ -959,14 +959,14 @@ nobufs:
55059 spin_unlock(&cookie->lock);
55060 radix_tree_preload_end();
55061 kfree(op);
55062- fscache_stat(&fscache_n_stores_nobufs);
55063+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
55064 _leave(" = -ENOBUFS");
55065 return -ENOBUFS;
55066
55067 nomem_free:
55068 kfree(op);
55069 nomem:
55070- fscache_stat(&fscache_n_stores_oom);
55071+ fscache_stat_unchecked(&fscache_n_stores_oom);
55072 _leave(" = -ENOMEM");
55073 return -ENOMEM;
55074 }
55075@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
55076 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
55077 ASSERTCMP(page, !=, NULL);
55078
55079- fscache_stat(&fscache_n_uncaches);
55080+ fscache_stat_unchecked(&fscache_n_uncaches);
55081
55082 /* cache withdrawal may beat us to it */
55083 if (!PageFsCache(page))
55084@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
55085 struct fscache_cookie *cookie = op->op.object->cookie;
55086
55087 #ifdef CONFIG_FSCACHE_STATS
55088- atomic_inc(&fscache_n_marks);
55089+ atomic_inc_unchecked(&fscache_n_marks);
55090 #endif
55091
55092 _debug("- mark %p{%lx}", page, page->index);
55093diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
55094index 40d13c7..ddf52b9 100644
55095--- a/fs/fscache/stats.c
55096+++ b/fs/fscache/stats.c
55097@@ -18,99 +18,99 @@
55098 /*
55099 * operation counters
55100 */
55101-atomic_t fscache_n_op_pend;
55102-atomic_t fscache_n_op_run;
55103-atomic_t fscache_n_op_enqueue;
55104-atomic_t fscache_n_op_requeue;
55105-atomic_t fscache_n_op_deferred_release;
55106-atomic_t fscache_n_op_release;
55107-atomic_t fscache_n_op_gc;
55108-atomic_t fscache_n_op_cancelled;
55109-atomic_t fscache_n_op_rejected;
55110+atomic_unchecked_t fscache_n_op_pend;
55111+atomic_unchecked_t fscache_n_op_run;
55112+atomic_unchecked_t fscache_n_op_enqueue;
55113+atomic_unchecked_t fscache_n_op_requeue;
55114+atomic_unchecked_t fscache_n_op_deferred_release;
55115+atomic_unchecked_t fscache_n_op_release;
55116+atomic_unchecked_t fscache_n_op_gc;
55117+atomic_unchecked_t fscache_n_op_cancelled;
55118+atomic_unchecked_t fscache_n_op_rejected;
55119
55120-atomic_t fscache_n_attr_changed;
55121-atomic_t fscache_n_attr_changed_ok;
55122-atomic_t fscache_n_attr_changed_nobufs;
55123-atomic_t fscache_n_attr_changed_nomem;
55124-atomic_t fscache_n_attr_changed_calls;
55125+atomic_unchecked_t fscache_n_attr_changed;
55126+atomic_unchecked_t fscache_n_attr_changed_ok;
55127+atomic_unchecked_t fscache_n_attr_changed_nobufs;
55128+atomic_unchecked_t fscache_n_attr_changed_nomem;
55129+atomic_unchecked_t fscache_n_attr_changed_calls;
55130
55131-atomic_t fscache_n_allocs;
55132-atomic_t fscache_n_allocs_ok;
55133-atomic_t fscache_n_allocs_wait;
55134-atomic_t fscache_n_allocs_nobufs;
55135-atomic_t fscache_n_allocs_intr;
55136-atomic_t fscache_n_allocs_object_dead;
55137-atomic_t fscache_n_alloc_ops;
55138-atomic_t fscache_n_alloc_op_waits;
55139+atomic_unchecked_t fscache_n_allocs;
55140+atomic_unchecked_t fscache_n_allocs_ok;
55141+atomic_unchecked_t fscache_n_allocs_wait;
55142+atomic_unchecked_t fscache_n_allocs_nobufs;
55143+atomic_unchecked_t fscache_n_allocs_intr;
55144+atomic_unchecked_t fscache_n_allocs_object_dead;
55145+atomic_unchecked_t fscache_n_alloc_ops;
55146+atomic_unchecked_t fscache_n_alloc_op_waits;
55147
55148-atomic_t fscache_n_retrievals;
55149-atomic_t fscache_n_retrievals_ok;
55150-atomic_t fscache_n_retrievals_wait;
55151-atomic_t fscache_n_retrievals_nodata;
55152-atomic_t fscache_n_retrievals_nobufs;
55153-atomic_t fscache_n_retrievals_intr;
55154-atomic_t fscache_n_retrievals_nomem;
55155-atomic_t fscache_n_retrievals_object_dead;
55156-atomic_t fscache_n_retrieval_ops;
55157-atomic_t fscache_n_retrieval_op_waits;
55158+atomic_unchecked_t fscache_n_retrievals;
55159+atomic_unchecked_t fscache_n_retrievals_ok;
55160+atomic_unchecked_t fscache_n_retrievals_wait;
55161+atomic_unchecked_t fscache_n_retrievals_nodata;
55162+atomic_unchecked_t fscache_n_retrievals_nobufs;
55163+atomic_unchecked_t fscache_n_retrievals_intr;
55164+atomic_unchecked_t fscache_n_retrievals_nomem;
55165+atomic_unchecked_t fscache_n_retrievals_object_dead;
55166+atomic_unchecked_t fscache_n_retrieval_ops;
55167+atomic_unchecked_t fscache_n_retrieval_op_waits;
55168
55169-atomic_t fscache_n_stores;
55170-atomic_t fscache_n_stores_ok;
55171-atomic_t fscache_n_stores_again;
55172-atomic_t fscache_n_stores_nobufs;
55173-atomic_t fscache_n_stores_oom;
55174-atomic_t fscache_n_store_ops;
55175-atomic_t fscache_n_store_calls;
55176-atomic_t fscache_n_store_pages;
55177-atomic_t fscache_n_store_radix_deletes;
55178-atomic_t fscache_n_store_pages_over_limit;
55179+atomic_unchecked_t fscache_n_stores;
55180+atomic_unchecked_t fscache_n_stores_ok;
55181+atomic_unchecked_t fscache_n_stores_again;
55182+atomic_unchecked_t fscache_n_stores_nobufs;
55183+atomic_unchecked_t fscache_n_stores_oom;
55184+atomic_unchecked_t fscache_n_store_ops;
55185+atomic_unchecked_t fscache_n_store_calls;
55186+atomic_unchecked_t fscache_n_store_pages;
55187+atomic_unchecked_t fscache_n_store_radix_deletes;
55188+atomic_unchecked_t fscache_n_store_pages_over_limit;
55189
55190-atomic_t fscache_n_store_vmscan_not_storing;
55191-atomic_t fscache_n_store_vmscan_gone;
55192-atomic_t fscache_n_store_vmscan_busy;
55193-atomic_t fscache_n_store_vmscan_cancelled;
55194-atomic_t fscache_n_store_vmscan_wait;
55195+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55196+atomic_unchecked_t fscache_n_store_vmscan_gone;
55197+atomic_unchecked_t fscache_n_store_vmscan_busy;
55198+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55199+atomic_unchecked_t fscache_n_store_vmscan_wait;
55200
55201-atomic_t fscache_n_marks;
55202-atomic_t fscache_n_uncaches;
55203+atomic_unchecked_t fscache_n_marks;
55204+atomic_unchecked_t fscache_n_uncaches;
55205
55206-atomic_t fscache_n_acquires;
55207-atomic_t fscache_n_acquires_null;
55208-atomic_t fscache_n_acquires_no_cache;
55209-atomic_t fscache_n_acquires_ok;
55210-atomic_t fscache_n_acquires_nobufs;
55211-atomic_t fscache_n_acquires_oom;
55212+atomic_unchecked_t fscache_n_acquires;
55213+atomic_unchecked_t fscache_n_acquires_null;
55214+atomic_unchecked_t fscache_n_acquires_no_cache;
55215+atomic_unchecked_t fscache_n_acquires_ok;
55216+atomic_unchecked_t fscache_n_acquires_nobufs;
55217+atomic_unchecked_t fscache_n_acquires_oom;
55218
55219-atomic_t fscache_n_invalidates;
55220-atomic_t fscache_n_invalidates_run;
55221+atomic_unchecked_t fscache_n_invalidates;
55222+atomic_unchecked_t fscache_n_invalidates_run;
55223
55224-atomic_t fscache_n_updates;
55225-atomic_t fscache_n_updates_null;
55226-atomic_t fscache_n_updates_run;
55227+atomic_unchecked_t fscache_n_updates;
55228+atomic_unchecked_t fscache_n_updates_null;
55229+atomic_unchecked_t fscache_n_updates_run;
55230
55231-atomic_t fscache_n_relinquishes;
55232-atomic_t fscache_n_relinquishes_null;
55233-atomic_t fscache_n_relinquishes_waitcrt;
55234-atomic_t fscache_n_relinquishes_retire;
55235+atomic_unchecked_t fscache_n_relinquishes;
55236+atomic_unchecked_t fscache_n_relinquishes_null;
55237+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
55238+atomic_unchecked_t fscache_n_relinquishes_retire;
55239
55240-atomic_t fscache_n_cookie_index;
55241-atomic_t fscache_n_cookie_data;
55242-atomic_t fscache_n_cookie_special;
55243+atomic_unchecked_t fscache_n_cookie_index;
55244+atomic_unchecked_t fscache_n_cookie_data;
55245+atomic_unchecked_t fscache_n_cookie_special;
55246
55247-atomic_t fscache_n_object_alloc;
55248-atomic_t fscache_n_object_no_alloc;
55249-atomic_t fscache_n_object_lookups;
55250-atomic_t fscache_n_object_lookups_negative;
55251-atomic_t fscache_n_object_lookups_positive;
55252-atomic_t fscache_n_object_lookups_timed_out;
55253-atomic_t fscache_n_object_created;
55254-atomic_t fscache_n_object_avail;
55255-atomic_t fscache_n_object_dead;
55256+atomic_unchecked_t fscache_n_object_alloc;
55257+atomic_unchecked_t fscache_n_object_no_alloc;
55258+atomic_unchecked_t fscache_n_object_lookups;
55259+atomic_unchecked_t fscache_n_object_lookups_negative;
55260+atomic_unchecked_t fscache_n_object_lookups_positive;
55261+atomic_unchecked_t fscache_n_object_lookups_timed_out;
55262+atomic_unchecked_t fscache_n_object_created;
55263+atomic_unchecked_t fscache_n_object_avail;
55264+atomic_unchecked_t fscache_n_object_dead;
55265
55266-atomic_t fscache_n_checkaux_none;
55267-atomic_t fscache_n_checkaux_okay;
55268-atomic_t fscache_n_checkaux_update;
55269-atomic_t fscache_n_checkaux_obsolete;
55270+atomic_unchecked_t fscache_n_checkaux_none;
55271+atomic_unchecked_t fscache_n_checkaux_okay;
55272+atomic_unchecked_t fscache_n_checkaux_update;
55273+atomic_unchecked_t fscache_n_checkaux_obsolete;
55274
55275 atomic_t fscache_n_cop_alloc_object;
55276 atomic_t fscache_n_cop_lookup_object;
55277@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
55278 seq_puts(m, "FS-Cache statistics\n");
55279
55280 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
55281- atomic_read(&fscache_n_cookie_index),
55282- atomic_read(&fscache_n_cookie_data),
55283- atomic_read(&fscache_n_cookie_special));
55284+ atomic_read_unchecked(&fscache_n_cookie_index),
55285+ atomic_read_unchecked(&fscache_n_cookie_data),
55286+ atomic_read_unchecked(&fscache_n_cookie_special));
55287
55288 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
55289- atomic_read(&fscache_n_object_alloc),
55290- atomic_read(&fscache_n_object_no_alloc),
55291- atomic_read(&fscache_n_object_avail),
55292- atomic_read(&fscache_n_object_dead));
55293+ atomic_read_unchecked(&fscache_n_object_alloc),
55294+ atomic_read_unchecked(&fscache_n_object_no_alloc),
55295+ atomic_read_unchecked(&fscache_n_object_avail),
55296+ atomic_read_unchecked(&fscache_n_object_dead));
55297 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
55298- atomic_read(&fscache_n_checkaux_none),
55299- atomic_read(&fscache_n_checkaux_okay),
55300- atomic_read(&fscache_n_checkaux_update),
55301- atomic_read(&fscache_n_checkaux_obsolete));
55302+ atomic_read_unchecked(&fscache_n_checkaux_none),
55303+ atomic_read_unchecked(&fscache_n_checkaux_okay),
55304+ atomic_read_unchecked(&fscache_n_checkaux_update),
55305+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
55306
55307 seq_printf(m, "Pages : mrk=%u unc=%u\n",
55308- atomic_read(&fscache_n_marks),
55309- atomic_read(&fscache_n_uncaches));
55310+ atomic_read_unchecked(&fscache_n_marks),
55311+ atomic_read_unchecked(&fscache_n_uncaches));
55312
55313 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
55314 " oom=%u\n",
55315- atomic_read(&fscache_n_acquires),
55316- atomic_read(&fscache_n_acquires_null),
55317- atomic_read(&fscache_n_acquires_no_cache),
55318- atomic_read(&fscache_n_acquires_ok),
55319- atomic_read(&fscache_n_acquires_nobufs),
55320- atomic_read(&fscache_n_acquires_oom));
55321+ atomic_read_unchecked(&fscache_n_acquires),
55322+ atomic_read_unchecked(&fscache_n_acquires_null),
55323+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
55324+ atomic_read_unchecked(&fscache_n_acquires_ok),
55325+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
55326+ atomic_read_unchecked(&fscache_n_acquires_oom));
55327
55328 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
55329- atomic_read(&fscache_n_object_lookups),
55330- atomic_read(&fscache_n_object_lookups_negative),
55331- atomic_read(&fscache_n_object_lookups_positive),
55332- atomic_read(&fscache_n_object_created),
55333- atomic_read(&fscache_n_object_lookups_timed_out));
55334+ atomic_read_unchecked(&fscache_n_object_lookups),
55335+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
55336+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
55337+ atomic_read_unchecked(&fscache_n_object_created),
55338+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
55339
55340 seq_printf(m, "Invals : n=%u run=%u\n",
55341- atomic_read(&fscache_n_invalidates),
55342- atomic_read(&fscache_n_invalidates_run));
55343+ atomic_read_unchecked(&fscache_n_invalidates),
55344+ atomic_read_unchecked(&fscache_n_invalidates_run));
55345
55346 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
55347- atomic_read(&fscache_n_updates),
55348- atomic_read(&fscache_n_updates_null),
55349- atomic_read(&fscache_n_updates_run));
55350+ atomic_read_unchecked(&fscache_n_updates),
55351+ atomic_read_unchecked(&fscache_n_updates_null),
55352+ atomic_read_unchecked(&fscache_n_updates_run));
55353
55354 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
55355- atomic_read(&fscache_n_relinquishes),
55356- atomic_read(&fscache_n_relinquishes_null),
55357- atomic_read(&fscache_n_relinquishes_waitcrt),
55358- atomic_read(&fscache_n_relinquishes_retire));
55359+ atomic_read_unchecked(&fscache_n_relinquishes),
55360+ atomic_read_unchecked(&fscache_n_relinquishes_null),
55361+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
55362+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
55363
55364 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
55365- atomic_read(&fscache_n_attr_changed),
55366- atomic_read(&fscache_n_attr_changed_ok),
55367- atomic_read(&fscache_n_attr_changed_nobufs),
55368- atomic_read(&fscache_n_attr_changed_nomem),
55369- atomic_read(&fscache_n_attr_changed_calls));
55370+ atomic_read_unchecked(&fscache_n_attr_changed),
55371+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
55372+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
55373+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
55374+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
55375
55376 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
55377- atomic_read(&fscache_n_allocs),
55378- atomic_read(&fscache_n_allocs_ok),
55379- atomic_read(&fscache_n_allocs_wait),
55380- atomic_read(&fscache_n_allocs_nobufs),
55381- atomic_read(&fscache_n_allocs_intr));
55382+ atomic_read_unchecked(&fscache_n_allocs),
55383+ atomic_read_unchecked(&fscache_n_allocs_ok),
55384+ atomic_read_unchecked(&fscache_n_allocs_wait),
55385+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
55386+ atomic_read_unchecked(&fscache_n_allocs_intr));
55387 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
55388- atomic_read(&fscache_n_alloc_ops),
55389- atomic_read(&fscache_n_alloc_op_waits),
55390- atomic_read(&fscache_n_allocs_object_dead));
55391+ atomic_read_unchecked(&fscache_n_alloc_ops),
55392+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
55393+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
55394
55395 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
55396 " int=%u oom=%u\n",
55397- atomic_read(&fscache_n_retrievals),
55398- atomic_read(&fscache_n_retrievals_ok),
55399- atomic_read(&fscache_n_retrievals_wait),
55400- atomic_read(&fscache_n_retrievals_nodata),
55401- atomic_read(&fscache_n_retrievals_nobufs),
55402- atomic_read(&fscache_n_retrievals_intr),
55403- atomic_read(&fscache_n_retrievals_nomem));
55404+ atomic_read_unchecked(&fscache_n_retrievals),
55405+ atomic_read_unchecked(&fscache_n_retrievals_ok),
55406+ atomic_read_unchecked(&fscache_n_retrievals_wait),
55407+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
55408+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
55409+ atomic_read_unchecked(&fscache_n_retrievals_intr),
55410+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
55411 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
55412- atomic_read(&fscache_n_retrieval_ops),
55413- atomic_read(&fscache_n_retrieval_op_waits),
55414- atomic_read(&fscache_n_retrievals_object_dead));
55415+ atomic_read_unchecked(&fscache_n_retrieval_ops),
55416+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
55417+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
55418
55419 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
55420- atomic_read(&fscache_n_stores),
55421- atomic_read(&fscache_n_stores_ok),
55422- atomic_read(&fscache_n_stores_again),
55423- atomic_read(&fscache_n_stores_nobufs),
55424- atomic_read(&fscache_n_stores_oom));
55425+ atomic_read_unchecked(&fscache_n_stores),
55426+ atomic_read_unchecked(&fscache_n_stores_ok),
55427+ atomic_read_unchecked(&fscache_n_stores_again),
55428+ atomic_read_unchecked(&fscache_n_stores_nobufs),
55429+ atomic_read_unchecked(&fscache_n_stores_oom));
55430 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
55431- atomic_read(&fscache_n_store_ops),
55432- atomic_read(&fscache_n_store_calls),
55433- atomic_read(&fscache_n_store_pages),
55434- atomic_read(&fscache_n_store_radix_deletes),
55435- atomic_read(&fscache_n_store_pages_over_limit));
55436+ atomic_read_unchecked(&fscache_n_store_ops),
55437+ atomic_read_unchecked(&fscache_n_store_calls),
55438+ atomic_read_unchecked(&fscache_n_store_pages),
55439+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
55440+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
55441
55442 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
55443- atomic_read(&fscache_n_store_vmscan_not_storing),
55444- atomic_read(&fscache_n_store_vmscan_gone),
55445- atomic_read(&fscache_n_store_vmscan_busy),
55446- atomic_read(&fscache_n_store_vmscan_cancelled),
55447- atomic_read(&fscache_n_store_vmscan_wait));
55448+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
55449+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
55450+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
55451+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
55452+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
55453
55454 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
55455- atomic_read(&fscache_n_op_pend),
55456- atomic_read(&fscache_n_op_run),
55457- atomic_read(&fscache_n_op_enqueue),
55458- atomic_read(&fscache_n_op_cancelled),
55459- atomic_read(&fscache_n_op_rejected));
55460+ atomic_read_unchecked(&fscache_n_op_pend),
55461+ atomic_read_unchecked(&fscache_n_op_run),
55462+ atomic_read_unchecked(&fscache_n_op_enqueue),
55463+ atomic_read_unchecked(&fscache_n_op_cancelled),
55464+ atomic_read_unchecked(&fscache_n_op_rejected));
55465 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
55466- atomic_read(&fscache_n_op_deferred_release),
55467- atomic_read(&fscache_n_op_release),
55468- atomic_read(&fscache_n_op_gc));
55469+ atomic_read_unchecked(&fscache_n_op_deferred_release),
55470+ atomic_read_unchecked(&fscache_n_op_release),
55471+ atomic_read_unchecked(&fscache_n_op_gc));
55472
55473 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
55474 atomic_read(&fscache_n_cop_alloc_object),
55475diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
55476index aef34b1..59bfd7b 100644
55477--- a/fs/fuse/cuse.c
55478+++ b/fs/fuse/cuse.c
55479@@ -600,10 +600,12 @@ static int __init cuse_init(void)
55480 INIT_LIST_HEAD(&cuse_conntbl[i]);
55481
55482 /* inherit and extend fuse_dev_operations */
55483- cuse_channel_fops = fuse_dev_operations;
55484- cuse_channel_fops.owner = THIS_MODULE;
55485- cuse_channel_fops.open = cuse_channel_open;
55486- cuse_channel_fops.release = cuse_channel_release;
55487+ pax_open_kernel();
55488+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
55489+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
55490+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
55491+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
55492+ pax_close_kernel();
55493
55494 cuse_class = class_create(THIS_MODULE, "cuse");
55495 if (IS_ERR(cuse_class))
55496diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
55497index 1d55f94..088da65 100644
55498--- a/fs/fuse/dev.c
55499+++ b/fs/fuse/dev.c
55500@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
55501 ret = 0;
55502 pipe_lock(pipe);
55503
55504- if (!pipe->readers) {
55505+ if (!atomic_read(&pipe->readers)) {
55506 send_sig(SIGPIPE, current, 0);
55507 if (!ret)
55508 ret = -EPIPE;
55509@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
55510 page_nr++;
55511 ret += buf->len;
55512
55513- if (pipe->files)
55514+ if (atomic_read(&pipe->files))
55515 do_wakeup = 1;
55516 }
55517
55518diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
55519index 5b12746..b481b03 100644
55520--- a/fs/fuse/dir.c
55521+++ b/fs/fuse/dir.c
55522@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
55523 return link;
55524 }
55525
55526-static void free_link(char *link)
55527+static void free_link(const char *link)
55528 {
55529 if (!IS_ERR(link))
55530 free_page((unsigned long) link);
55531diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
55532index 62b484e..0f9a140 100644
55533--- a/fs/gfs2/inode.c
55534+++ b/fs/gfs2/inode.c
55535@@ -1441,7 +1441,7 @@ out:
55536
55537 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55538 {
55539- char *s = nd_get_link(nd);
55540+ const char *s = nd_get_link(nd);
55541 if (!IS_ERR(s))
55542 kfree(s);
55543 }
55544diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
55545index a3f868a..bb308ae 100644
55546--- a/fs/hugetlbfs/inode.c
55547+++ b/fs/hugetlbfs/inode.c
55548@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
55549 struct mm_struct *mm = current->mm;
55550 struct vm_area_struct *vma;
55551 struct hstate *h = hstate_file(file);
55552+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
55553 struct vm_unmapped_area_info info;
55554
55555 if (len & ~huge_page_mask(h))
55556@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
55557 return addr;
55558 }
55559
55560+#ifdef CONFIG_PAX_RANDMMAP
55561+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
55562+#endif
55563+
55564 if (addr) {
55565 addr = ALIGN(addr, huge_page_size(h));
55566 vma = find_vma(mm, addr);
55567- if (TASK_SIZE - len >= addr &&
55568- (!vma || addr + len <= vma->vm_start))
55569+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
55570 return addr;
55571 }
55572
55573 info.flags = 0;
55574 info.length = len;
55575 info.low_limit = TASK_UNMAPPED_BASE;
55576+
55577+#ifdef CONFIG_PAX_RANDMMAP
55578+ if (mm->pax_flags & MF_PAX_RANDMMAP)
55579+ info.low_limit += mm->delta_mmap;
55580+#endif
55581+
55582 info.high_limit = TASK_SIZE;
55583 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
55584 info.align_offset = 0;
55585@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
55586 };
55587 MODULE_ALIAS_FS("hugetlbfs");
55588
55589-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
55590+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
55591
55592 static int can_do_hugetlb_shm(void)
55593 {
55594diff --git a/fs/inode.c b/fs/inode.c
55595index 00d5fc3..98ce7d7 100644
55596--- a/fs/inode.c
55597+++ b/fs/inode.c
55598@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
55599
55600 #ifdef CONFIG_SMP
55601 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
55602- static atomic_t shared_last_ino;
55603- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
55604+ static atomic_unchecked_t shared_last_ino;
55605+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
55606
55607 res = next - LAST_INO_BATCH;
55608 }
55609diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
55610index 4a6cf28..d3a29d3 100644
55611--- a/fs/jffs2/erase.c
55612+++ b/fs/jffs2/erase.c
55613@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
55614 struct jffs2_unknown_node marker = {
55615 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
55616 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
55617- .totlen = cpu_to_je32(c->cleanmarker_size)
55618+ .totlen = cpu_to_je32(c->cleanmarker_size),
55619+ .hdr_crc = cpu_to_je32(0)
55620 };
55621
55622 jffs2_prealloc_raw_node_refs(c, jeb, 1);
55623diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
55624index a6597d6..41b30ec 100644
55625--- a/fs/jffs2/wbuf.c
55626+++ b/fs/jffs2/wbuf.c
55627@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
55628 {
55629 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
55630 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
55631- .totlen = constant_cpu_to_je32(8)
55632+ .totlen = constant_cpu_to_je32(8),
55633+ .hdr_crc = constant_cpu_to_je32(0)
55634 };
55635
55636 /*
55637diff --git a/fs/jfs/super.c b/fs/jfs/super.c
55638index 788e0a9..8433098 100644
55639--- a/fs/jfs/super.c
55640+++ b/fs/jfs/super.c
55641@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
55642
55643 jfs_inode_cachep =
55644 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
55645- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
55646+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
55647 init_once);
55648 if (jfs_inode_cachep == NULL)
55649 return -ENOMEM;
55650diff --git a/fs/libfs.c b/fs/libfs.c
55651index 916da8c..1588998 100644
55652--- a/fs/libfs.c
55653+++ b/fs/libfs.c
55654@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
55655
55656 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
55657 struct dentry *next;
55658+ char d_name[sizeof(next->d_iname)];
55659+ const unsigned char *name;
55660+
55661 next = list_entry(p, struct dentry, d_u.d_child);
55662 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
55663 if (!simple_positive(next)) {
55664@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
55665
55666 spin_unlock(&next->d_lock);
55667 spin_unlock(&dentry->d_lock);
55668- if (filldir(dirent, next->d_name.name,
55669+ name = next->d_name.name;
55670+ if (name == next->d_iname) {
55671+ memcpy(d_name, name, next->d_name.len);
55672+ name = d_name;
55673+ }
55674+ if (filldir(dirent, name,
55675 next->d_name.len, filp->f_pos,
55676 next->d_inode->i_ino,
55677 dt_type(next->d_inode)) < 0)
55678diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
55679index acd3947..1f896e2 100644
55680--- a/fs/lockd/clntproc.c
55681+++ b/fs/lockd/clntproc.c
55682@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
55683 /*
55684 * Cookie counter for NLM requests
55685 */
55686-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
55687+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
55688
55689 void nlmclnt_next_cookie(struct nlm_cookie *c)
55690 {
55691- u32 cookie = atomic_inc_return(&nlm_cookie);
55692+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
55693
55694 memcpy(c->data, &cookie, 4);
55695 c->len=4;
55696diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
55697index a2aa97d..10d6c41 100644
55698--- a/fs/lockd/svc.c
55699+++ b/fs/lockd/svc.c
55700@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
55701 svc_sock_update_bufs(serv);
55702 serv->sv_maxconn = nlm_max_connections;
55703
55704- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
55705+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
55706 if (IS_ERR(nlmsvc_task)) {
55707 error = PTR_ERR(nlmsvc_task);
55708 printk(KERN_WARNING
55709diff --git a/fs/locks.c b/fs/locks.c
55710index cb424a4..850e4dd 100644
55711--- a/fs/locks.c
55712+++ b/fs/locks.c
55713@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
55714 return;
55715
55716 if (filp->f_op && filp->f_op->flock) {
55717- struct file_lock fl = {
55718+ struct file_lock flock = {
55719 .fl_pid = current->tgid,
55720 .fl_file = filp,
55721 .fl_flags = FL_FLOCK,
55722 .fl_type = F_UNLCK,
55723 .fl_end = OFFSET_MAX,
55724 };
55725- filp->f_op->flock(filp, F_SETLKW, &fl);
55726- if (fl.fl_ops && fl.fl_ops->fl_release_private)
55727- fl.fl_ops->fl_release_private(&fl);
55728+ filp->f_op->flock(filp, F_SETLKW, &flock);
55729+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
55730+ flock.fl_ops->fl_release_private(&flock);
55731 }
55732
55733 lock_flocks();
55734diff --git a/fs/namei.c b/fs/namei.c
55735index 9ed9361..2b72db1 100644
55736--- a/fs/namei.c
55737+++ b/fs/namei.c
55738@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
55739 if (ret != -EACCES)
55740 return ret;
55741
55742+#ifdef CONFIG_GRKERNSEC
55743+ /* we'll block if we have to log due to a denied capability use */
55744+ if (mask & MAY_NOT_BLOCK)
55745+ return -ECHILD;
55746+#endif
55747+
55748 if (S_ISDIR(inode->i_mode)) {
55749 /* DACs are overridable for directories */
55750- if (inode_capable(inode, CAP_DAC_OVERRIDE))
55751- return 0;
55752 if (!(mask & MAY_WRITE))
55753- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
55754+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
55755+ inode_capable(inode, CAP_DAC_READ_SEARCH))
55756 return 0;
55757+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
55758+ return 0;
55759 return -EACCES;
55760 }
55761 /*
55762+ * Searching includes executable on directories, else just read.
55763+ */
55764+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
55765+ if (mask == MAY_READ)
55766+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
55767+ inode_capable(inode, CAP_DAC_READ_SEARCH))
55768+ return 0;
55769+
55770+ /*
55771 * Read/write DACs are always overridable.
55772 * Executable DACs are overridable when there is
55773 * at least one exec bit set.
55774@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
55775 if (inode_capable(inode, CAP_DAC_OVERRIDE))
55776 return 0;
55777
55778- /*
55779- * Searching includes executable on directories, else just read.
55780- */
55781- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
55782- if (mask == MAY_READ)
55783- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
55784- return 0;
55785-
55786 return -EACCES;
55787 }
55788
55789@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
55790 {
55791 struct dentry *dentry = link->dentry;
55792 int error;
55793- char *s;
55794+ const char *s;
55795
55796 BUG_ON(nd->flags & LOOKUP_RCU);
55797
55798@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
55799 if (error)
55800 goto out_put_nd_path;
55801
55802+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
55803+ dentry->d_inode, dentry, nd->path.mnt)) {
55804+ error = -EACCES;
55805+ goto out_put_nd_path;
55806+ }
55807+
55808 nd->last_type = LAST_BIND;
55809 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
55810 error = PTR_ERR(*p);
55811@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
55812 if (res)
55813 break;
55814 res = walk_component(nd, path, LOOKUP_FOLLOW);
55815+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
55816+ res = -EACCES;
55817 put_link(nd, &link, cookie);
55818 } while (res > 0);
55819
55820@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
55821 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
55822 {
55823 unsigned long a, b, adata, bdata, mask, hash, len;
55824- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
55825+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
55826
55827 hash = a = 0;
55828 len = -sizeof(unsigned long);
55829@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
55830 if (err)
55831 break;
55832 err = lookup_last(nd, &path);
55833+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
55834+ err = -EACCES;
55835 put_link(nd, &link, cookie);
55836 }
55837 }
55838@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
55839 if (!err)
55840 err = complete_walk(nd);
55841
55842+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
55843+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
55844+ path_put(&nd->path);
55845+ err = -ENOENT;
55846+ }
55847+ }
55848+
55849 if (!err && nd->flags & LOOKUP_DIRECTORY) {
55850 if (!can_lookup(nd->inode)) {
55851 path_put(&nd->path);
55852@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
55853 retval = path_lookupat(dfd, name->name,
55854 flags | LOOKUP_REVAL, nd);
55855
55856- if (likely(!retval))
55857+ if (likely(!retval)) {
55858 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
55859+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
55860+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
55861+ path_put(&nd->path);
55862+ return -ENOENT;
55863+ }
55864+ }
55865+ }
55866 return retval;
55867 }
55868
55869@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
55870 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
55871 return -EPERM;
55872
55873+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
55874+ return -EPERM;
55875+ if (gr_handle_rawio(inode))
55876+ return -EPERM;
55877+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
55878+ return -EACCES;
55879+
55880 return 0;
55881 }
55882
55883@@ -2602,7 +2641,7 @@ looked_up:
55884 * cleared otherwise prior to returning.
55885 */
55886 static int lookup_open(struct nameidata *nd, struct path *path,
55887- struct file *file,
55888+ struct path *link, struct file *file,
55889 const struct open_flags *op,
55890 bool got_write, int *opened)
55891 {
55892@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
55893 /* Negative dentry, just create the file */
55894 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
55895 umode_t mode = op->mode;
55896+
55897+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
55898+ error = -EACCES;
55899+ goto out_dput;
55900+ }
55901+
55902+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
55903+ error = -EACCES;
55904+ goto out_dput;
55905+ }
55906+
55907 if (!IS_POSIXACL(dir->d_inode))
55908 mode &= ~current_umask();
55909 /*
55910@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
55911 nd->flags & LOOKUP_EXCL);
55912 if (error)
55913 goto out_dput;
55914+ else
55915+ gr_handle_create(dentry, nd->path.mnt);
55916 }
55917 out_no_open:
55918 path->dentry = dentry;
55919@@ -2672,7 +2724,7 @@ out_dput:
55920 /*
55921 * Handle the last step of open()
55922 */
55923-static int do_last(struct nameidata *nd, struct path *path,
55924+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
55925 struct file *file, const struct open_flags *op,
55926 int *opened, struct filename *name)
55927 {
55928@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
55929 error = complete_walk(nd);
55930 if (error)
55931 return error;
55932+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
55933+ error = -ENOENT;
55934+ goto out;
55935+ }
55936 audit_inode(name, nd->path.dentry, 0);
55937 if (open_flag & O_CREAT) {
55938 error = -EISDIR;
55939 goto out;
55940 }
55941+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
55942+ error = -EACCES;
55943+ goto out;
55944+ }
55945 goto finish_open;
55946 case LAST_BIND:
55947 error = complete_walk(nd);
55948 if (error)
55949 return error;
55950+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
55951+ error = -ENOENT;
55952+ goto out;
55953+ }
55954+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
55955+ error = -EACCES;
55956+ goto out;
55957+ }
55958 audit_inode(name, dir, 0);
55959 goto finish_open;
55960 }
55961@@ -2759,7 +2827,7 @@ retry_lookup:
55962 */
55963 }
55964 mutex_lock(&dir->d_inode->i_mutex);
55965- error = lookup_open(nd, path, file, op, got_write, opened);
55966+ error = lookup_open(nd, path, link, file, op, got_write, opened);
55967 mutex_unlock(&dir->d_inode->i_mutex);
55968
55969 if (error <= 0) {
55970@@ -2783,11 +2851,28 @@ retry_lookup:
55971 goto finish_open_created;
55972 }
55973
55974+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
55975+ error = -ENOENT;
55976+ goto exit_dput;
55977+ }
55978+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
55979+ error = -EACCES;
55980+ goto exit_dput;
55981+ }
55982+
55983 /*
55984 * create/update audit record if it already exists.
55985 */
55986- if (path->dentry->d_inode)
55987+ if (path->dentry->d_inode) {
55988+ /* only check if O_CREAT is specified, all other checks need to go
55989+ into may_open */
55990+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
55991+ error = -EACCES;
55992+ goto exit_dput;
55993+ }
55994+
55995 audit_inode(name, path->dentry, 0);
55996+ }
55997
55998 /*
55999 * If atomic_open() acquired write access it is dropped now due to
56000@@ -2828,6 +2913,11 @@ finish_lookup:
56001 }
56002 }
56003 BUG_ON(inode != path->dentry->d_inode);
56004+ /* if we're resolving a symlink to another symlink */
56005+ if (link && gr_handle_symlink_owner(link, inode)) {
56006+ error = -EACCES;
56007+ goto out;
56008+ }
56009 return 1;
56010 }
56011
56012@@ -2837,7 +2927,6 @@ finish_lookup:
56013 save_parent.dentry = nd->path.dentry;
56014 save_parent.mnt = mntget(path->mnt);
56015 nd->path.dentry = path->dentry;
56016-
56017 }
56018 nd->inode = inode;
56019 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
56020@@ -2846,6 +2935,16 @@ finish_lookup:
56021 path_put(&save_parent);
56022 return error;
56023 }
56024+
56025+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
56026+ error = -ENOENT;
56027+ goto out;
56028+ }
56029+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
56030+ error = -EACCES;
56031+ goto out;
56032+ }
56033+
56034 error = -EISDIR;
56035 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
56036 goto out;
56037@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
56038 if (unlikely(error))
56039 goto out;
56040
56041- error = do_last(nd, &path, file, op, &opened, pathname);
56042+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
56043 while (unlikely(error > 0)) { /* trailing symlink */
56044 struct path link = path;
56045 void *cookie;
56046@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
56047 error = follow_link(&link, nd, &cookie);
56048 if (unlikely(error))
56049 break;
56050- error = do_last(nd, &path, file, op, &opened, pathname);
56051+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
56052 put_link(nd, &link, cookie);
56053 }
56054 out:
56055@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
56056 goto unlock;
56057
56058 error = -EEXIST;
56059- if (dentry->d_inode)
56060+ if (dentry->d_inode) {
56061+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
56062+ error = -ENOENT;
56063+ }
56064 goto fail;
56065+ }
56066 /*
56067 * Special case - lookup gave negative, but... we had foo/bar/
56068 * From the vfs_mknod() POV we just have a negative dentry -
56069@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
56070 }
56071 EXPORT_SYMBOL(user_path_create);
56072
56073+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
56074+{
56075+ struct filename *tmp = getname(pathname);
56076+ struct dentry *res;
56077+ if (IS_ERR(tmp))
56078+ return ERR_CAST(tmp);
56079+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
56080+ if (IS_ERR(res))
56081+ putname(tmp);
56082+ else
56083+ *to = tmp;
56084+ return res;
56085+}
56086+
56087 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
56088 {
56089 int error = may_create(dir, dentry);
56090@@ -3177,6 +3294,17 @@ retry:
56091
56092 if (!IS_POSIXACL(path.dentry->d_inode))
56093 mode &= ~current_umask();
56094+
56095+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
56096+ error = -EPERM;
56097+ goto out;
56098+ }
56099+
56100+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
56101+ error = -EACCES;
56102+ goto out;
56103+ }
56104+
56105 error = security_path_mknod(&path, dentry, mode, dev);
56106 if (error)
56107 goto out;
56108@@ -3193,6 +3321,8 @@ retry:
56109 break;
56110 }
56111 out:
56112+ if (!error)
56113+ gr_handle_create(dentry, path.mnt);
56114 done_path_create(&path, dentry);
56115 if (retry_estale(error, lookup_flags)) {
56116 lookup_flags |= LOOKUP_REVAL;
56117@@ -3245,9 +3375,16 @@ retry:
56118
56119 if (!IS_POSIXACL(path.dentry->d_inode))
56120 mode &= ~current_umask();
56121+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
56122+ error = -EACCES;
56123+ goto out;
56124+ }
56125 error = security_path_mkdir(&path, dentry, mode);
56126 if (!error)
56127 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
56128+ if (!error)
56129+ gr_handle_create(dentry, path.mnt);
56130+out:
56131 done_path_create(&path, dentry);
56132 if (retry_estale(error, lookup_flags)) {
56133 lookup_flags |= LOOKUP_REVAL;
56134@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
56135 struct filename *name;
56136 struct dentry *dentry;
56137 struct nameidata nd;
56138+ ino_t saved_ino = 0;
56139+ dev_t saved_dev = 0;
56140 unsigned int lookup_flags = 0;
56141 retry:
56142 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
56143@@ -3360,10 +3499,21 @@ retry:
56144 error = -ENOENT;
56145 goto exit3;
56146 }
56147+
56148+ saved_ino = dentry->d_inode->i_ino;
56149+ saved_dev = gr_get_dev_from_dentry(dentry);
56150+
56151+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
56152+ error = -EACCES;
56153+ goto exit3;
56154+ }
56155+
56156 error = security_path_rmdir(&nd.path, dentry);
56157 if (error)
56158 goto exit3;
56159 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
56160+ if (!error && (saved_dev || saved_ino))
56161+ gr_handle_delete(saved_ino, saved_dev);
56162 exit3:
56163 dput(dentry);
56164 exit2:
56165@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
56166 struct dentry *dentry;
56167 struct nameidata nd;
56168 struct inode *inode = NULL;
56169+ ino_t saved_ino = 0;
56170+ dev_t saved_dev = 0;
56171 unsigned int lookup_flags = 0;
56172 retry:
56173 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
56174@@ -3455,10 +3607,22 @@ retry:
56175 if (!inode)
56176 goto slashes;
56177 ihold(inode);
56178+
56179+ if (inode->i_nlink <= 1) {
56180+ saved_ino = inode->i_ino;
56181+ saved_dev = gr_get_dev_from_dentry(dentry);
56182+ }
56183+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
56184+ error = -EACCES;
56185+ goto exit2;
56186+ }
56187+
56188 error = security_path_unlink(&nd.path, dentry);
56189 if (error)
56190 goto exit2;
56191 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
56192+ if (!error && (saved_ino || saved_dev))
56193+ gr_handle_delete(saved_ino, saved_dev);
56194 exit2:
56195 dput(dentry);
56196 }
56197@@ -3536,9 +3700,17 @@ retry:
56198 if (IS_ERR(dentry))
56199 goto out_putname;
56200
56201+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
56202+ error = -EACCES;
56203+ goto out;
56204+ }
56205+
56206 error = security_path_symlink(&path, dentry, from->name);
56207 if (!error)
56208 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
56209+ if (!error)
56210+ gr_handle_create(dentry, path.mnt);
56211+out:
56212 done_path_create(&path, dentry);
56213 if (retry_estale(error, lookup_flags)) {
56214 lookup_flags |= LOOKUP_REVAL;
56215@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
56216 {
56217 struct dentry *new_dentry;
56218 struct path old_path, new_path;
56219+ struct filename *to = NULL;
56220 int how = 0;
56221 int error;
56222
56223@@ -3635,7 +3808,7 @@ retry:
56224 if (error)
56225 return error;
56226
56227- new_dentry = user_path_create(newdfd, newname, &new_path,
56228+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
56229 (how & LOOKUP_REVAL));
56230 error = PTR_ERR(new_dentry);
56231 if (IS_ERR(new_dentry))
56232@@ -3647,11 +3820,28 @@ retry:
56233 error = may_linkat(&old_path);
56234 if (unlikely(error))
56235 goto out_dput;
56236+
56237+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
56238+ old_path.dentry->d_inode,
56239+ old_path.dentry->d_inode->i_mode, to)) {
56240+ error = -EACCES;
56241+ goto out_dput;
56242+ }
56243+
56244+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
56245+ old_path.dentry, old_path.mnt, to)) {
56246+ error = -EACCES;
56247+ goto out_dput;
56248+ }
56249+
56250 error = security_path_link(old_path.dentry, &new_path, new_dentry);
56251 if (error)
56252 goto out_dput;
56253 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
56254+ if (!error)
56255+ gr_handle_create(new_dentry, new_path.mnt);
56256 out_dput:
56257+ putname(to);
56258 done_path_create(&new_path, new_dentry);
56259 if (retry_estale(error, how)) {
56260 how |= LOOKUP_REVAL;
56261@@ -3897,12 +4087,21 @@ retry:
56262 if (new_dentry == trap)
56263 goto exit5;
56264
56265+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
56266+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
56267+ to);
56268+ if (error)
56269+ goto exit5;
56270+
56271 error = security_path_rename(&oldnd.path, old_dentry,
56272 &newnd.path, new_dentry);
56273 if (error)
56274 goto exit5;
56275 error = vfs_rename(old_dir->d_inode, old_dentry,
56276 new_dir->d_inode, new_dentry);
56277+ if (!error)
56278+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
56279+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
56280 exit5:
56281 dput(new_dentry);
56282 exit4:
56283@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
56284
56285 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
56286 {
56287+ char tmpbuf[64];
56288+ const char *newlink;
56289 int len;
56290
56291 len = PTR_ERR(link);
56292@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
56293 len = strlen(link);
56294 if (len > (unsigned) buflen)
56295 len = buflen;
56296- if (copy_to_user(buffer, link, len))
56297+
56298+ if (len < sizeof(tmpbuf)) {
56299+ memcpy(tmpbuf, link, len);
56300+ newlink = tmpbuf;
56301+ } else
56302+ newlink = link;
56303+
56304+ if (copy_to_user(buffer, newlink, len))
56305 len = -EFAULT;
56306 out:
56307 return len;
56308diff --git a/fs/namespace.c b/fs/namespace.c
56309index 7b1ca9b..6faeccf 100644
56310--- a/fs/namespace.c
56311+++ b/fs/namespace.c
56312@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
56313 if (!(sb->s_flags & MS_RDONLY))
56314 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
56315 up_write(&sb->s_umount);
56316+
56317+ gr_log_remount(mnt->mnt_devname, retval);
56318+
56319 return retval;
56320 }
56321
56322@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
56323 }
56324 br_write_unlock(&vfsmount_lock);
56325 namespace_unlock();
56326+
56327+ gr_log_unmount(mnt->mnt_devname, retval);
56328+
56329 return retval;
56330 }
56331
56332@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
56333 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
56334 */
56335
56336-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
56337+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
56338 {
56339 struct path path;
56340 struct mount *mnt;
56341@@ -1342,7 +1348,7 @@ out:
56342 /*
56343 * The 2.0 compatible umount. No flags.
56344 */
56345-SYSCALL_DEFINE1(oldumount, char __user *, name)
56346+SYSCALL_DEFINE1(oldumount, const char __user *, name)
56347 {
56348 return sys_umount(name, 0);
56349 }
56350@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
56351 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
56352 MS_STRICTATIME);
56353
56354+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
56355+ retval = -EPERM;
56356+ goto dput_out;
56357+ }
56358+
56359+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
56360+ retval = -EPERM;
56361+ goto dput_out;
56362+ }
56363+
56364 if (flags & MS_REMOUNT)
56365 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
56366 data_page);
56367@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
56368 dev_name, data_page);
56369 dput_out:
56370 path_put(&path);
56371+
56372+ gr_log_mount(dev_name, dir_name, retval);
56373+
56374 return retval;
56375 }
56376
56377@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
56378 }
56379 EXPORT_SYMBOL(mount_subtree);
56380
56381-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
56382- char __user *, type, unsigned long, flags, void __user *, data)
56383+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
56384+ const char __user *, type, unsigned long, flags, void __user *, data)
56385 {
56386 int ret;
56387 char *kernel_type;
56388@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
56389 if (error)
56390 goto out2;
56391
56392+ if (gr_handle_chroot_pivot()) {
56393+ error = -EPERM;
56394+ goto out2;
56395+ }
56396+
56397 get_fs_root(current->fs, &root);
56398 old_mp = lock_mount(&old);
56399 error = PTR_ERR(old_mp);
56400@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
56401 !nsown_capable(CAP_SYS_ADMIN))
56402 return -EPERM;
56403
56404- if (fs->users != 1)
56405+ if (atomic_read(&fs->users) != 1)
56406 return -EINVAL;
56407
56408 get_mnt_ns(mnt_ns);
56409diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
56410index cff089a..4c3d57a 100644
56411--- a/fs/nfs/callback.c
56412+++ b/fs/nfs/callback.c
56413@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
56414 struct svc_rqst *rqstp;
56415 int (*callback_svc)(void *vrqstp);
56416 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
56417- char svc_name[12];
56418 int ret;
56419
56420 nfs_callback_bc_serv(minorversion, xprt, serv);
56421@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
56422
56423 svc_sock_update_bufs(serv);
56424
56425- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
56426 cb_info->serv = serv;
56427 cb_info->rqst = rqstp;
56428- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
56429+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
56430 if (IS_ERR(cb_info->task)) {
56431 ret = PTR_ERR(cb_info->task);
56432 svc_exit_thread(cb_info->rqst);
56433diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
56434index a35582c..ebbdcd5 100644
56435--- a/fs/nfs/callback_xdr.c
56436+++ b/fs/nfs/callback_xdr.c
56437@@ -51,7 +51,7 @@ struct callback_op {
56438 callback_decode_arg_t decode_args;
56439 callback_encode_res_t encode_res;
56440 long res_maxsize;
56441-};
56442+} __do_const;
56443
56444 static struct callback_op callback_ops[];
56445
56446diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
56447index c1c7a9d..7afa0b8 100644
56448--- a/fs/nfs/inode.c
56449+++ b/fs/nfs/inode.c
56450@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
56451 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
56452 }
56453
56454-static atomic_long_t nfs_attr_generation_counter;
56455+static atomic_long_unchecked_t nfs_attr_generation_counter;
56456
56457 static unsigned long nfs_read_attr_generation_counter(void)
56458 {
56459- return atomic_long_read(&nfs_attr_generation_counter);
56460+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
56461 }
56462
56463 unsigned long nfs_inc_attr_generation_counter(void)
56464 {
56465- return atomic_long_inc_return(&nfs_attr_generation_counter);
56466+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
56467 }
56468
56469 void nfs_fattr_init(struct nfs_fattr *fattr)
56470diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
56471index 2c37442..9b9538b 100644
56472--- a/fs/nfs/nfs4state.c
56473+++ b/fs/nfs/nfs4state.c
56474@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
56475 snprintf(buf, sizeof(buf), "%s-manager",
56476 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
56477 rcu_read_unlock();
56478- task = kthread_run(nfs4_run_state_manager, clp, buf);
56479+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
56480 if (IS_ERR(task)) {
56481 printk(KERN_ERR "%s: kthread_run: %ld\n",
56482 __func__, PTR_ERR(task));
56483diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
56484index 27d74a2..c4c2a73 100644
56485--- a/fs/nfsd/nfs4proc.c
56486+++ b/fs/nfsd/nfs4proc.c
56487@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
56488 nfsd4op_rsize op_rsize_bop;
56489 stateid_getter op_get_currentstateid;
56490 stateid_setter op_set_currentstateid;
56491-};
56492+} __do_const;
56493
56494 static struct nfsd4_operation nfsd4_ops[];
56495
56496diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
56497index 582321a..0224663 100644
56498--- a/fs/nfsd/nfs4xdr.c
56499+++ b/fs/nfsd/nfs4xdr.c
56500@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
56501
56502 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
56503
56504-static nfsd4_dec nfsd4_dec_ops[] = {
56505+static const nfsd4_dec nfsd4_dec_ops[] = {
56506 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
56507 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
56508 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
56509@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
56510 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
56511 };
56512
56513-static nfsd4_dec nfsd41_dec_ops[] = {
56514+static const nfsd4_dec nfsd41_dec_ops[] = {
56515 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
56516 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
56517 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
56518@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
56519 };
56520
56521 struct nfsd4_minorversion_ops {
56522- nfsd4_dec *decoders;
56523+ const nfsd4_dec *decoders;
56524 int nops;
56525 };
56526
56527diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
56528index e76244e..9fe8f2f1 100644
56529--- a/fs/nfsd/nfscache.c
56530+++ b/fs/nfsd/nfscache.c
56531@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
56532 {
56533 struct svc_cacherep *rp = rqstp->rq_cacherep;
56534 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
56535- int len;
56536+ long len;
56537 size_t bufsize = 0;
56538
56539 if (!rp)
56540 return;
56541
56542- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
56543- len >>= 2;
56544+ if (statp) {
56545+ len = (char*)statp - (char*)resv->iov_base;
56546+ len = resv->iov_len - len;
56547+ len >>= 2;
56548+ }
56549
56550 /* Don't cache excessive amounts of data and XDR failures */
56551 if (!statp || len > (256 >> 2)) {
56552diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
56553index baf149a..76b86ad 100644
56554--- a/fs/nfsd/vfs.c
56555+++ b/fs/nfsd/vfs.c
56556@@ -940,7 +940,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
56557 } else {
56558 oldfs = get_fs();
56559 set_fs(KERNEL_DS);
56560- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
56561+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
56562 set_fs(oldfs);
56563 }
56564
56565@@ -1027,7 +1027,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
56566
56567 /* Write the data. */
56568 oldfs = get_fs(); set_fs(KERNEL_DS);
56569- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
56570+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
56571 set_fs(oldfs);
56572 if (host_err < 0)
56573 goto out_nfserr;
56574@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
56575 */
56576
56577 oldfs = get_fs(); set_fs(KERNEL_DS);
56578- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
56579+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
56580 set_fs(oldfs);
56581
56582 if (host_err < 0)
56583diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
56584index fea6bd5..8ee9d81 100644
56585--- a/fs/nls/nls_base.c
56586+++ b/fs/nls/nls_base.c
56587@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
56588
56589 int register_nls(struct nls_table * nls)
56590 {
56591- struct nls_table ** tmp = &tables;
56592+ struct nls_table *tmp = tables;
56593
56594 if (nls->next)
56595 return -EBUSY;
56596
56597 spin_lock(&nls_lock);
56598- while (*tmp) {
56599- if (nls == *tmp) {
56600+ while (tmp) {
56601+ if (nls == tmp) {
56602 spin_unlock(&nls_lock);
56603 return -EBUSY;
56604 }
56605- tmp = &(*tmp)->next;
56606+ tmp = tmp->next;
56607 }
56608- nls->next = tables;
56609+ pax_open_kernel();
56610+ *(struct nls_table **)&nls->next = tables;
56611+ pax_close_kernel();
56612 tables = nls;
56613 spin_unlock(&nls_lock);
56614 return 0;
56615@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
56616
56617 int unregister_nls(struct nls_table * nls)
56618 {
56619- struct nls_table ** tmp = &tables;
56620+ struct nls_table * const * tmp = &tables;
56621
56622 spin_lock(&nls_lock);
56623 while (*tmp) {
56624 if (nls == *tmp) {
56625- *tmp = nls->next;
56626+ pax_open_kernel();
56627+ *(struct nls_table **)tmp = nls->next;
56628+ pax_close_kernel();
56629 spin_unlock(&nls_lock);
56630 return 0;
56631 }
56632diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
56633index 7424929..35f6be5 100644
56634--- a/fs/nls/nls_euc-jp.c
56635+++ b/fs/nls/nls_euc-jp.c
56636@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
56637 p_nls = load_nls("cp932");
56638
56639 if (p_nls) {
56640- table.charset2upper = p_nls->charset2upper;
56641- table.charset2lower = p_nls->charset2lower;
56642+ pax_open_kernel();
56643+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
56644+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
56645+ pax_close_kernel();
56646 return register_nls(&table);
56647 }
56648
56649diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
56650index e7bc1d7..06bd4bb 100644
56651--- a/fs/nls/nls_koi8-ru.c
56652+++ b/fs/nls/nls_koi8-ru.c
56653@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
56654 p_nls = load_nls("koi8-u");
56655
56656 if (p_nls) {
56657- table.charset2upper = p_nls->charset2upper;
56658- table.charset2lower = p_nls->charset2lower;
56659+ pax_open_kernel();
56660+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
56661+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
56662+ pax_close_kernel();
56663 return register_nls(&table);
56664 }
56665
56666diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
56667index 77cc85d..a1e6299 100644
56668--- a/fs/notify/fanotify/fanotify_user.c
56669+++ b/fs/notify/fanotify/fanotify_user.c
56670@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
56671
56672 fd = fanotify_event_metadata.fd;
56673 ret = -EFAULT;
56674- if (copy_to_user(buf, &fanotify_event_metadata,
56675- fanotify_event_metadata.event_len))
56676+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
56677+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
56678 goto out_close_fd;
56679
56680 ret = prepare_for_access_response(group, event, fd);
56681diff --git a/fs/notify/notification.c b/fs/notify/notification.c
56682index 7b51b05..5ea5ef6 100644
56683--- a/fs/notify/notification.c
56684+++ b/fs/notify/notification.c
56685@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
56686 * get set to 0 so it will never get 'freed'
56687 */
56688 static struct fsnotify_event *q_overflow_event;
56689-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
56690+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
56691
56692 /**
56693 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
56694@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
56695 */
56696 u32 fsnotify_get_cookie(void)
56697 {
56698- return atomic_inc_return(&fsnotify_sync_cookie);
56699+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
56700 }
56701 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
56702
56703diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
56704index aa411c3..c260a84 100644
56705--- a/fs/ntfs/dir.c
56706+++ b/fs/ntfs/dir.c
56707@@ -1329,7 +1329,7 @@ find_next_index_buffer:
56708 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
56709 ~(s64)(ndir->itype.index.block_size - 1)));
56710 /* Bounds checks. */
56711- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
56712+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
56713 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
56714 "inode 0x%lx or driver bug.", vdir->i_ino);
56715 goto err_out;
56716diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
56717index c5670b8..01a3656 100644
56718--- a/fs/ntfs/file.c
56719+++ b/fs/ntfs/file.c
56720@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
56721 #endif /* NTFS_RW */
56722 };
56723
56724-const struct file_operations ntfs_empty_file_ops = {};
56725+const struct file_operations ntfs_empty_file_ops __read_only;
56726
56727-const struct inode_operations ntfs_empty_inode_ops = {};
56728+const struct inode_operations ntfs_empty_inode_ops __read_only;
56729diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
56730index 20dfec7..e238cb7 100644
56731--- a/fs/ocfs2/aops.c
56732+++ b/fs/ocfs2/aops.c
56733@@ -1756,7 +1756,7 @@ try_again:
56734 goto out;
56735 } else if (ret == 1) {
56736 clusters_need = wc->w_clen;
56737- ret = ocfs2_refcount_cow(inode, filp, di_bh,
56738+ ret = ocfs2_refcount_cow(inode, di_bh,
56739 wc->w_cpos, wc->w_clen, UINT_MAX);
56740 if (ret) {
56741 mlog_errno(ret);
56742diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
56743index ff54014..ff125fd 100644
56744--- a/fs/ocfs2/file.c
56745+++ b/fs/ocfs2/file.c
56746@@ -370,7 +370,7 @@ static int ocfs2_cow_file_pos(struct inode *inode,
56747 if (!(ext_flags & OCFS2_EXT_REFCOUNTED))
56748 goto out;
56749
56750- return ocfs2_refcount_cow(inode, NULL, fe_bh, cpos, 1, cpos+1);
56751+ return ocfs2_refcount_cow(inode, fe_bh, cpos, 1, cpos+1);
56752
56753 out:
56754 return status;
56755@@ -899,7 +899,7 @@ static int ocfs2_zero_extend_get_range(struct inode *inode,
56756 zero_clusters = last_cpos - zero_cpos;
56757
56758 if (needs_cow) {
56759- rc = ocfs2_refcount_cow(inode, NULL, di_bh, zero_cpos,
56760+ rc = ocfs2_refcount_cow(inode, di_bh, zero_cpos,
56761 zero_clusters, UINT_MAX);
56762 if (rc) {
56763 mlog_errno(rc);
56764@@ -2078,7 +2078,7 @@ static int ocfs2_prepare_inode_for_refcount(struct inode *inode,
56765
56766 *meta_level = 1;
56767
56768- ret = ocfs2_refcount_cow(inode, file, di_bh, cpos, clusters, UINT_MAX);
56769+ ret = ocfs2_refcount_cow(inode, di_bh, cpos, clusters, UINT_MAX);
56770 if (ret)
56771 mlog_errno(ret);
56772 out:
56773diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
56774index aebeacd..0dcdd26 100644
56775--- a/fs/ocfs2/localalloc.c
56776+++ b/fs/ocfs2/localalloc.c
56777@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
56778 goto bail;
56779 }
56780
56781- atomic_inc(&osb->alloc_stats.moves);
56782+ atomic_inc_unchecked(&osb->alloc_stats.moves);
56783
56784 bail:
56785 if (handle)
56786diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
56787index f1fc172..452068b 100644
56788--- a/fs/ocfs2/move_extents.c
56789+++ b/fs/ocfs2/move_extents.c
56790@@ -69,7 +69,7 @@ static int __ocfs2_move_extent(handle_t *handle,
56791 u64 ino = ocfs2_metadata_cache_owner(context->et.et_ci);
56792 u64 old_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cpos);
56793
56794- ret = ocfs2_duplicate_clusters_by_page(handle, context->file, cpos,
56795+ ret = ocfs2_duplicate_clusters_by_page(handle, inode, cpos,
56796 p_cpos, new_p_cpos, len);
56797 if (ret) {
56798 mlog_errno(ret);
56799diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
56800index d355e6e..578d905 100644
56801--- a/fs/ocfs2/ocfs2.h
56802+++ b/fs/ocfs2/ocfs2.h
56803@@ -235,11 +235,11 @@ enum ocfs2_vol_state
56804
56805 struct ocfs2_alloc_stats
56806 {
56807- atomic_t moves;
56808- atomic_t local_data;
56809- atomic_t bitmap_data;
56810- atomic_t bg_allocs;
56811- atomic_t bg_extends;
56812+ atomic_unchecked_t moves;
56813+ atomic_unchecked_t local_data;
56814+ atomic_unchecked_t bitmap_data;
56815+ atomic_unchecked_t bg_allocs;
56816+ atomic_unchecked_t bg_extends;
56817 };
56818
56819 enum ocfs2_local_alloc_state
56820diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
56821index 998b17e..aefe414 100644
56822--- a/fs/ocfs2/refcounttree.c
56823+++ b/fs/ocfs2/refcounttree.c
56824@@ -49,7 +49,6 @@
56825
56826 struct ocfs2_cow_context {
56827 struct inode *inode;
56828- struct file *file;
56829 u32 cow_start;
56830 u32 cow_len;
56831 struct ocfs2_extent_tree data_et;
56832@@ -66,7 +65,7 @@ struct ocfs2_cow_context {
56833 u32 *num_clusters,
56834 unsigned int *extent_flags);
56835 int (*cow_duplicate_clusters)(handle_t *handle,
56836- struct file *file,
56837+ struct inode *inode,
56838 u32 cpos, u32 old_cluster,
56839 u32 new_cluster, u32 new_len);
56840 };
56841@@ -2922,14 +2921,12 @@ static int ocfs2_clear_cow_buffer(handle_t *handle, struct buffer_head *bh)
56842 }
56843
56844 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
56845- struct file *file,
56846+ struct inode *inode,
56847 u32 cpos, u32 old_cluster,
56848 u32 new_cluster, u32 new_len)
56849 {
56850 int ret = 0, partial;
56851- struct inode *inode = file_inode(file);
56852- struct ocfs2_caching_info *ci = INODE_CACHE(inode);
56853- struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
56854+ struct super_block *sb = inode->i_sb;
56855 u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
56856 struct page *page;
56857 pgoff_t page_index;
56858@@ -2973,13 +2970,6 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
56859 if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize)
56860 BUG_ON(PageDirty(page));
56861
56862- if (PageReadahead(page)) {
56863- page_cache_async_readahead(mapping,
56864- &file->f_ra, file,
56865- page, page_index,
56866- readahead_pages);
56867- }
56868-
56869 if (!PageUptodate(page)) {
56870 ret = block_read_full_page(page, ocfs2_get_block);
56871 if (ret) {
56872@@ -2999,7 +2989,8 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
56873 }
56874 }
56875
56876- ocfs2_map_and_dirty_page(inode, handle, from, to,
56877+ ocfs2_map_and_dirty_page(inode,
56878+ handle, from, to,
56879 page, 0, &new_block);
56880 mark_page_accessed(page);
56881 unlock:
56882@@ -3015,12 +3006,11 @@ unlock:
56883 }
56884
56885 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
56886- struct file *file,
56887+ struct inode *inode,
56888 u32 cpos, u32 old_cluster,
56889 u32 new_cluster, u32 new_len)
56890 {
56891 int ret = 0;
56892- struct inode *inode = file_inode(file);
56893 struct super_block *sb = inode->i_sb;
56894 struct ocfs2_caching_info *ci = INODE_CACHE(inode);
56895 int i, blocks = ocfs2_clusters_to_blocks(sb, new_len);
56896@@ -3145,7 +3135,7 @@ static int ocfs2_replace_clusters(handle_t *handle,
56897
56898 /*If the old clusters is unwritten, no need to duplicate. */
56899 if (!(ext_flags & OCFS2_EXT_UNWRITTEN)) {
56900- ret = context->cow_duplicate_clusters(handle, context->file,
56901+ ret = context->cow_duplicate_clusters(handle, context->inode,
56902 cpos, old, new, len);
56903 if (ret) {
56904 mlog_errno(ret);
56905@@ -3423,35 +3413,12 @@ static int ocfs2_replace_cow(struct ocfs2_cow_context *context)
56906 return ret;
56907 }
56908
56909-static void ocfs2_readahead_for_cow(struct inode *inode,
56910- struct file *file,
56911- u32 start, u32 len)
56912-{
56913- struct address_space *mapping;
56914- pgoff_t index;
56915- unsigned long num_pages;
56916- int cs_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits;
56917-
56918- if (!file)
56919- return;
56920-
56921- mapping = file->f_mapping;
56922- num_pages = (len << cs_bits) >> PAGE_CACHE_SHIFT;
56923- if (!num_pages)
56924- num_pages = 1;
56925-
56926- index = ((loff_t)start << cs_bits) >> PAGE_CACHE_SHIFT;
56927- page_cache_sync_readahead(mapping, &file->f_ra, file,
56928- index, num_pages);
56929-}
56930-
56931 /*
56932 * Starting at cpos, try to CoW write_len clusters. Don't CoW
56933 * past max_cpos. This will stop when it runs into a hole or an
56934 * unrefcounted extent.
56935 */
56936 static int ocfs2_refcount_cow_hunk(struct inode *inode,
56937- struct file *file,
56938 struct buffer_head *di_bh,
56939 u32 cpos, u32 write_len, u32 max_cpos)
56940 {
56941@@ -3480,8 +3447,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
56942
56943 BUG_ON(cow_len == 0);
56944
56945- ocfs2_readahead_for_cow(inode, file, cow_start, cow_len);
56946-
56947 context = kzalloc(sizeof(struct ocfs2_cow_context), GFP_NOFS);
56948 if (!context) {
56949 ret = -ENOMEM;
56950@@ -3503,7 +3468,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
56951 context->ref_root_bh = ref_root_bh;
56952 context->cow_duplicate_clusters = ocfs2_duplicate_clusters_by_page;
56953 context->get_clusters = ocfs2_di_get_clusters;
56954- context->file = file;
56955
56956 ocfs2_init_dinode_extent_tree(&context->data_et,
56957 INODE_CACHE(inode), di_bh);
56958@@ -3532,7 +3496,6 @@ out:
56959 * clusters between cpos and cpos+write_len are safe to modify.
56960 */
56961 int ocfs2_refcount_cow(struct inode *inode,
56962- struct file *file,
56963 struct buffer_head *di_bh,
56964 u32 cpos, u32 write_len, u32 max_cpos)
56965 {
56966@@ -3552,7 +3515,7 @@ int ocfs2_refcount_cow(struct inode *inode,
56967 num_clusters = write_len;
56968
56969 if (ext_flags & OCFS2_EXT_REFCOUNTED) {
56970- ret = ocfs2_refcount_cow_hunk(inode, file, di_bh, cpos,
56971+ ret = ocfs2_refcount_cow_hunk(inode, di_bh, cpos,
56972 num_clusters, max_cpos);
56973 if (ret) {
56974 mlog_errno(ret);
56975diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h
56976index 7754608..6422bbcdb 100644
56977--- a/fs/ocfs2/refcounttree.h
56978+++ b/fs/ocfs2/refcounttree.h
56979@@ -53,7 +53,7 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
56980 int *credits,
56981 int *ref_blocks);
56982 int ocfs2_refcount_cow(struct inode *inode,
56983- struct file *filep, struct buffer_head *di_bh,
56984+ struct buffer_head *di_bh,
56985 u32 cpos, u32 write_len, u32 max_cpos);
56986
56987 typedef int (ocfs2_post_refcount_func)(struct inode *inode,
56988@@ -85,11 +85,11 @@ int ocfs2_refcount_cow_xattr(struct inode *inode,
56989 u32 cpos, u32 write_len,
56990 struct ocfs2_post_refcount *post);
56991 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
56992- struct file *file,
56993+ struct inode *inode,
56994 u32 cpos, u32 old_cluster,
56995 u32 new_cluster, u32 new_len);
56996 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
56997- struct file *file,
56998+ struct inode *inode,
56999 u32 cpos, u32 old_cluster,
57000 u32 new_cluster, u32 new_len);
57001 int ocfs2_cow_sync_writeback(struct super_block *sb,
57002diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
57003index b7e74b5..19c6536 100644
57004--- a/fs/ocfs2/suballoc.c
57005+++ b/fs/ocfs2/suballoc.c
57006@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
57007 mlog_errno(status);
57008 goto bail;
57009 }
57010- atomic_inc(&osb->alloc_stats.bg_extends);
57011+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
57012
57013 /* You should never ask for this much metadata */
57014 BUG_ON(bits_wanted >
57015@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
57016 mlog_errno(status);
57017 goto bail;
57018 }
57019- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57020+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57021
57022 *suballoc_loc = res.sr_bg_blkno;
57023 *suballoc_bit_start = res.sr_bit_offset;
57024@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
57025 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
57026 res->sr_bits);
57027
57028- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57029+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57030
57031 BUG_ON(res->sr_bits != 1);
57032
57033@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
57034 mlog_errno(status);
57035 goto bail;
57036 }
57037- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57038+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
57039
57040 BUG_ON(res.sr_bits != 1);
57041
57042@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
57043 cluster_start,
57044 num_clusters);
57045 if (!status)
57046- atomic_inc(&osb->alloc_stats.local_data);
57047+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
57048 } else {
57049 if (min_clusters > (osb->bitmap_cpg - 1)) {
57050 /* The only paths asking for contiguousness
57051@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
57052 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
57053 res.sr_bg_blkno,
57054 res.sr_bit_offset);
57055- atomic_inc(&osb->alloc_stats.bitmap_data);
57056+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
57057 *num_clusters = res.sr_bits;
57058 }
57059 }
57060diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
57061index 01b8516..579c4df 100644
57062--- a/fs/ocfs2/super.c
57063+++ b/fs/ocfs2/super.c
57064@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
57065 "%10s => GlobalAllocs: %d LocalAllocs: %d "
57066 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
57067 "Stats",
57068- atomic_read(&osb->alloc_stats.bitmap_data),
57069- atomic_read(&osb->alloc_stats.local_data),
57070- atomic_read(&osb->alloc_stats.bg_allocs),
57071- atomic_read(&osb->alloc_stats.moves),
57072- atomic_read(&osb->alloc_stats.bg_extends));
57073+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
57074+ atomic_read_unchecked(&osb->alloc_stats.local_data),
57075+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
57076+ atomic_read_unchecked(&osb->alloc_stats.moves),
57077+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
57078
57079 out += snprintf(buf + out, len - out,
57080 "%10s => State: %u Descriptor: %llu Size: %u bits "
57081@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
57082 spin_lock_init(&osb->osb_xattr_lock);
57083 ocfs2_init_steal_slots(osb);
57084
57085- atomic_set(&osb->alloc_stats.moves, 0);
57086- atomic_set(&osb->alloc_stats.local_data, 0);
57087- atomic_set(&osb->alloc_stats.bitmap_data, 0);
57088- atomic_set(&osb->alloc_stats.bg_allocs, 0);
57089- atomic_set(&osb->alloc_stats.bg_extends, 0);
57090+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
57091+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
57092+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
57093+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
57094+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
57095
57096 /* Copy the blockcheck stats from the superblock probe */
57097 osb->osb_ecc_stats = *stats;
57098diff --git a/fs/open.c b/fs/open.c
57099index 8c74100..4239c48 100644
57100--- a/fs/open.c
57101+++ b/fs/open.c
57102@@ -32,6 +32,8 @@
57103 #include <linux/dnotify.h>
57104 #include <linux/compat.h>
57105
57106+#define CREATE_TRACE_POINTS
57107+#include <trace/events/fs.h>
57108 #include "internal.h"
57109
57110 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
57111@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
57112 error = locks_verify_truncate(inode, NULL, length);
57113 if (!error)
57114 error = security_path_truncate(path);
57115+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
57116+ error = -EACCES;
57117 if (!error)
57118 error = do_truncate(path->dentry, length, 0, NULL);
57119
57120@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
57121 error = locks_verify_truncate(inode, f.file, length);
57122 if (!error)
57123 error = security_path_truncate(&f.file->f_path);
57124+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
57125+ error = -EACCES;
57126 if (!error)
57127 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
57128 sb_end_write(inode->i_sb);
57129@@ -360,6 +366,9 @@ retry:
57130 if (__mnt_is_readonly(path.mnt))
57131 res = -EROFS;
57132
57133+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
57134+ res = -EACCES;
57135+
57136 out_path_release:
57137 path_put(&path);
57138 if (retry_estale(res, lookup_flags)) {
57139@@ -391,6 +400,8 @@ retry:
57140 if (error)
57141 goto dput_and_out;
57142
57143+ gr_log_chdir(path.dentry, path.mnt);
57144+
57145 set_fs_pwd(current->fs, &path);
57146
57147 dput_and_out:
57148@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
57149 goto out_putf;
57150
57151 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
57152+
57153+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
57154+ error = -EPERM;
57155+
57156+ if (!error)
57157+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
57158+
57159 if (!error)
57160 set_fs_pwd(current->fs, &f.file->f_path);
57161 out_putf:
57162@@ -449,7 +467,13 @@ retry:
57163 if (error)
57164 goto dput_and_out;
57165
57166+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
57167+ goto dput_and_out;
57168+
57169 set_fs_root(current->fs, &path);
57170+
57171+ gr_handle_chroot_chdir(&path);
57172+
57173 error = 0;
57174 dput_and_out:
57175 path_put(&path);
57176@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
57177 if (error)
57178 return error;
57179 mutex_lock(&inode->i_mutex);
57180+
57181+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
57182+ error = -EACCES;
57183+ goto out_unlock;
57184+ }
57185+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
57186+ error = -EACCES;
57187+ goto out_unlock;
57188+ }
57189+
57190 error = security_path_chmod(path, mode);
57191 if (error)
57192 goto out_unlock;
57193@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
57194 uid = make_kuid(current_user_ns(), user);
57195 gid = make_kgid(current_user_ns(), group);
57196
57197+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
57198+ return -EACCES;
57199+
57200 newattrs.ia_valid = ATTR_CTIME;
57201 if (user != (uid_t) -1) {
57202 if (!uid_valid(uid))
57203@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
57204 } else {
57205 fsnotify_open(f);
57206 fd_install(fd, f);
57207+ trace_do_sys_open(tmp->name, flags, mode);
57208 }
57209 }
57210 putname(tmp);
57211diff --git a/fs/pipe.c b/fs/pipe.c
57212index d2c45e1..009fe1c 100644
57213--- a/fs/pipe.c
57214+++ b/fs/pipe.c
57215@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
57216
57217 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
57218 {
57219- if (pipe->files)
57220+ if (atomic_read(&pipe->files))
57221 mutex_lock_nested(&pipe->mutex, subclass);
57222 }
57223
57224@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
57225
57226 void pipe_unlock(struct pipe_inode_info *pipe)
57227 {
57228- if (pipe->files)
57229+ if (atomic_read(&pipe->files))
57230 mutex_unlock(&pipe->mutex);
57231 }
57232 EXPORT_SYMBOL(pipe_unlock);
57233@@ -449,9 +449,9 @@ redo:
57234 }
57235 if (bufs) /* More to do? */
57236 continue;
57237- if (!pipe->writers)
57238+ if (!atomic_read(&pipe->writers))
57239 break;
57240- if (!pipe->waiting_writers) {
57241+ if (!atomic_read(&pipe->waiting_writers)) {
57242 /* syscall merging: Usually we must not sleep
57243 * if O_NONBLOCK is set, or if we got some data.
57244 * But if a writer sleeps in kernel space, then
57245@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
57246 ret = 0;
57247 __pipe_lock(pipe);
57248
57249- if (!pipe->readers) {
57250+ if (!atomic_read(&pipe->readers)) {
57251 send_sig(SIGPIPE, current, 0);
57252 ret = -EPIPE;
57253 goto out;
57254@@ -562,7 +562,7 @@ redo1:
57255 for (;;) {
57256 int bufs;
57257
57258- if (!pipe->readers) {
57259+ if (!atomic_read(&pipe->readers)) {
57260 send_sig(SIGPIPE, current, 0);
57261 if (!ret)
57262 ret = -EPIPE;
57263@@ -653,9 +653,9 @@ redo2:
57264 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57265 do_wakeup = 0;
57266 }
57267- pipe->waiting_writers++;
57268+ atomic_inc(&pipe->waiting_writers);
57269 pipe_wait(pipe);
57270- pipe->waiting_writers--;
57271+ atomic_dec(&pipe->waiting_writers);
57272 }
57273 out:
57274 __pipe_unlock(pipe);
57275@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
57276 mask = 0;
57277 if (filp->f_mode & FMODE_READ) {
57278 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
57279- if (!pipe->writers && filp->f_version != pipe->w_counter)
57280+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
57281 mask |= POLLHUP;
57282 }
57283
57284@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
57285 * Most Unices do not set POLLERR for FIFOs but on Linux they
57286 * behave exactly like pipes for poll().
57287 */
57288- if (!pipe->readers)
57289+ if (!atomic_read(&pipe->readers))
57290 mask |= POLLERR;
57291 }
57292
57293@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
57294
57295 __pipe_lock(pipe);
57296 if (file->f_mode & FMODE_READ)
57297- pipe->readers--;
57298+ atomic_dec(&pipe->readers);
57299 if (file->f_mode & FMODE_WRITE)
57300- pipe->writers--;
57301+ atomic_dec(&pipe->writers);
57302
57303- if (pipe->readers || pipe->writers) {
57304+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
57305 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
57306 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57307 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
57308 }
57309 spin_lock(&inode->i_lock);
57310- if (!--pipe->files) {
57311+ if (atomic_dec_and_test(&pipe->files)) {
57312 inode->i_pipe = NULL;
57313 kill = 1;
57314 }
57315@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
57316 kfree(pipe);
57317 }
57318
57319-static struct vfsmount *pipe_mnt __read_mostly;
57320+struct vfsmount *pipe_mnt __read_mostly;
57321
57322 /*
57323 * pipefs_dname() is called from d_path().
57324@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
57325 goto fail_iput;
57326
57327 inode->i_pipe = pipe;
57328- pipe->files = 2;
57329- pipe->readers = pipe->writers = 1;
57330+ atomic_set(&pipe->files, 2);
57331+ atomic_set(&pipe->readers, 1);
57332+ atomic_set(&pipe->writers, 1);
57333 inode->i_fop = &pipefifo_fops;
57334
57335 /*
57336@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
57337 spin_lock(&inode->i_lock);
57338 if (inode->i_pipe) {
57339 pipe = inode->i_pipe;
57340- pipe->files++;
57341+ atomic_inc(&pipe->files);
57342 spin_unlock(&inode->i_lock);
57343 } else {
57344 spin_unlock(&inode->i_lock);
57345 pipe = alloc_pipe_info();
57346 if (!pipe)
57347 return -ENOMEM;
57348- pipe->files = 1;
57349+ atomic_set(&pipe->files, 1);
57350 spin_lock(&inode->i_lock);
57351 if (unlikely(inode->i_pipe)) {
57352- inode->i_pipe->files++;
57353+ atomic_inc(&inode->i_pipe->files);
57354 spin_unlock(&inode->i_lock);
57355 free_pipe_info(pipe);
57356 pipe = inode->i_pipe;
57357@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
57358 * opened, even when there is no process writing the FIFO.
57359 */
57360 pipe->r_counter++;
57361- if (pipe->readers++ == 0)
57362+ if (atomic_inc_return(&pipe->readers) == 1)
57363 wake_up_partner(pipe);
57364
57365- if (!is_pipe && !pipe->writers) {
57366+ if (!is_pipe && !atomic_read(&pipe->writers)) {
57367 if ((filp->f_flags & O_NONBLOCK)) {
57368 /* suppress POLLHUP until we have
57369 * seen a writer */
57370@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
57371 * errno=ENXIO when there is no process reading the FIFO.
57372 */
57373 ret = -ENXIO;
57374- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
57375+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
57376 goto err;
57377
57378 pipe->w_counter++;
57379- if (!pipe->writers++)
57380+ if (atomic_inc_return(&pipe->writers) == 1)
57381 wake_up_partner(pipe);
57382
57383- if (!is_pipe && !pipe->readers) {
57384+ if (!is_pipe && !atomic_read(&pipe->readers)) {
57385 if (wait_for_partner(pipe, &pipe->r_counter))
57386 goto err_wr;
57387 }
57388@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
57389 * the process can at least talk to itself.
57390 */
57391
57392- pipe->readers++;
57393- pipe->writers++;
57394+ atomic_inc(&pipe->readers);
57395+ atomic_inc(&pipe->writers);
57396 pipe->r_counter++;
57397 pipe->w_counter++;
57398- if (pipe->readers == 1 || pipe->writers == 1)
57399+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
57400 wake_up_partner(pipe);
57401 break;
57402
57403@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
57404 return 0;
57405
57406 err_rd:
57407- if (!--pipe->readers)
57408+ if (atomic_dec_and_test(&pipe->readers))
57409 wake_up_interruptible(&pipe->wait);
57410 ret = -ERESTARTSYS;
57411 goto err;
57412
57413 err_wr:
57414- if (!--pipe->writers)
57415+ if (atomic_dec_and_test(&pipe->writers))
57416 wake_up_interruptible(&pipe->wait);
57417 ret = -ERESTARTSYS;
57418 goto err;
57419
57420 err:
57421 spin_lock(&inode->i_lock);
57422- if (!--pipe->files) {
57423+ if (atomic_dec_and_test(&pipe->files)) {
57424 inode->i_pipe = NULL;
57425 kill = 1;
57426 }
57427diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
57428index 15af622..0e9f4467 100644
57429--- a/fs/proc/Kconfig
57430+++ b/fs/proc/Kconfig
57431@@ -30,12 +30,12 @@ config PROC_FS
57432
57433 config PROC_KCORE
57434 bool "/proc/kcore support" if !ARM
57435- depends on PROC_FS && MMU
57436+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
57437
57438 config PROC_VMCORE
57439 bool "/proc/vmcore support"
57440- depends on PROC_FS && CRASH_DUMP
57441- default y
57442+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
57443+ default n
57444 help
57445 Exports the dump image of crashed kernel in ELF format.
57446
57447@@ -59,8 +59,8 @@ config PROC_SYSCTL
57448 limited in memory.
57449
57450 config PROC_PAGE_MONITOR
57451- default y
57452- depends on PROC_FS && MMU
57453+ default n
57454+ depends on PROC_FS && MMU && !GRKERNSEC
57455 bool "Enable /proc page monitoring" if EXPERT
57456 help
57457 Various /proc files exist to monitor process memory utilization:
57458diff --git a/fs/proc/array.c b/fs/proc/array.c
57459index cbd0f1b..adec3f0 100644
57460--- a/fs/proc/array.c
57461+++ b/fs/proc/array.c
57462@@ -60,6 +60,7 @@
57463 #include <linux/tty.h>
57464 #include <linux/string.h>
57465 #include <linux/mman.h>
57466+#include <linux/grsecurity.h>
57467 #include <linux/proc_fs.h>
57468 #include <linux/ioport.h>
57469 #include <linux/uaccess.h>
57470@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
57471 seq_putc(m, '\n');
57472 }
57473
57474+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57475+static inline void task_pax(struct seq_file *m, struct task_struct *p)
57476+{
57477+ if (p->mm)
57478+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
57479+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
57480+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
57481+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
57482+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
57483+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
57484+ else
57485+ seq_printf(m, "PaX:\t-----\n");
57486+}
57487+#endif
57488+
57489 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
57490 struct pid *pid, struct task_struct *task)
57491 {
57492@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
57493 task_cpus_allowed(m, task);
57494 cpuset_task_status_allowed(m, task);
57495 task_context_switch_counts(m, task);
57496+
57497+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57498+ task_pax(m, task);
57499+#endif
57500+
57501+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
57502+ task_grsec_rbac(m, task);
57503+#endif
57504+
57505 return 0;
57506 }
57507
57508+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57509+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
57510+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
57511+ _mm->pax_flags & MF_PAX_SEGMEXEC))
57512+#endif
57513+
57514 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
57515 struct pid *pid, struct task_struct *task, int whole)
57516 {
57517@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
57518 char tcomm[sizeof(task->comm)];
57519 unsigned long flags;
57520
57521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57522+ if (current->exec_id != m->exec_id) {
57523+ gr_log_badprocpid("stat");
57524+ return 0;
57525+ }
57526+#endif
57527+
57528 state = *get_task_state(task);
57529 vsize = eip = esp = 0;
57530 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
57531@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
57532 gtime = task_gtime(task);
57533 }
57534
57535+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57536+ if (PAX_RAND_FLAGS(mm)) {
57537+ eip = 0;
57538+ esp = 0;
57539+ wchan = 0;
57540+ }
57541+#endif
57542+#ifdef CONFIG_GRKERNSEC_HIDESYM
57543+ wchan = 0;
57544+ eip =0;
57545+ esp =0;
57546+#endif
57547+
57548 /* scale priority and nice values from timeslices to -20..20 */
57549 /* to make it look like a "normal" Unix priority/nice value */
57550 priority = task_prio(task);
57551@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
57552 seq_put_decimal_ull(m, ' ', vsize);
57553 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
57554 seq_put_decimal_ull(m, ' ', rsslim);
57555+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57556+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
57557+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
57558+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
57559+#else
57560 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
57561 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
57562 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
57563+#endif
57564 seq_put_decimal_ull(m, ' ', esp);
57565 seq_put_decimal_ull(m, ' ', eip);
57566 /* The signal information here is obsolete.
57567@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
57568 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
57569 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
57570
57571- if (mm && permitted) {
57572+ if (mm && permitted
57573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57574+ && !PAX_RAND_FLAGS(mm)
57575+#endif
57576+ ) {
57577 seq_put_decimal_ull(m, ' ', mm->start_data);
57578 seq_put_decimal_ull(m, ' ', mm->end_data);
57579 seq_put_decimal_ull(m, ' ', mm->start_brk);
57580@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
57581 struct pid *pid, struct task_struct *task)
57582 {
57583 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
57584- struct mm_struct *mm = get_task_mm(task);
57585+ struct mm_struct *mm;
57586
57587+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57588+ if (current->exec_id != m->exec_id) {
57589+ gr_log_badprocpid("statm");
57590+ return 0;
57591+ }
57592+#endif
57593+ mm = get_task_mm(task);
57594 if (mm) {
57595 size = task_statm(mm, &shared, &text, &data, &resident);
57596 mmput(mm);
57597@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
57598 return 0;
57599 }
57600
57601+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
57602+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
57603+{
57604+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
57605+}
57606+#endif
57607+
57608 #ifdef CONFIG_CHECKPOINT_RESTORE
57609 static struct pid *
57610 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
57611diff --git a/fs/proc/base.c b/fs/proc/base.c
57612index c3834da..b402b2b 100644
57613--- a/fs/proc/base.c
57614+++ b/fs/proc/base.c
57615@@ -113,6 +113,14 @@ struct pid_entry {
57616 union proc_op op;
57617 };
57618
57619+struct getdents_callback {
57620+ struct linux_dirent __user * current_dir;
57621+ struct linux_dirent __user * previous;
57622+ struct file * file;
57623+ int count;
57624+ int error;
57625+};
57626+
57627 #define NOD(NAME, MODE, IOP, FOP, OP) { \
57628 .name = (NAME), \
57629 .len = sizeof(NAME) - 1, \
57630@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
57631 if (!mm->arg_end)
57632 goto out_mm; /* Shh! No looking before we're done */
57633
57634+ if (gr_acl_handle_procpidmem(task))
57635+ goto out_mm;
57636+
57637 len = mm->arg_end - mm->arg_start;
57638
57639 if (len > PAGE_SIZE)
57640@@ -237,12 +248,28 @@ out:
57641 return res;
57642 }
57643
57644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57645+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
57646+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
57647+ _mm->pax_flags & MF_PAX_SEGMEXEC))
57648+#endif
57649+
57650 static int proc_pid_auxv(struct task_struct *task, char *buffer)
57651 {
57652 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
57653 int res = PTR_ERR(mm);
57654 if (mm && !IS_ERR(mm)) {
57655 unsigned int nwords = 0;
57656+
57657+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57658+ /* allow if we're currently ptracing this task */
57659+ if (PAX_RAND_FLAGS(mm) &&
57660+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
57661+ mmput(mm);
57662+ return 0;
57663+ }
57664+#endif
57665+
57666 do {
57667 nwords += 2;
57668 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
57669@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
57670 }
57671
57672
57673-#ifdef CONFIG_KALLSYMS
57674+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
57675 /*
57676 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
57677 * Returns the resolved symbol. If that fails, simply return the address.
57678@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
57679 mutex_unlock(&task->signal->cred_guard_mutex);
57680 }
57681
57682-#ifdef CONFIG_STACKTRACE
57683+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
57684
57685 #define MAX_STACK_TRACE_DEPTH 64
57686
57687@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
57688 return count;
57689 }
57690
57691-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
57692+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
57693 static int proc_pid_syscall(struct task_struct *task, char *buffer)
57694 {
57695 long nr;
57696@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
57697 /************************************************************************/
57698
57699 /* permission checks */
57700-static int proc_fd_access_allowed(struct inode *inode)
57701+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
57702 {
57703 struct task_struct *task;
57704 int allowed = 0;
57705@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
57706 */
57707 task = get_proc_task(inode);
57708 if (task) {
57709- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
57710+ if (log)
57711+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
57712+ else
57713+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
57714 put_task_struct(task);
57715 }
57716 return allowed;
57717@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
57718 struct task_struct *task,
57719 int hide_pid_min)
57720 {
57721+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
57722+ return false;
57723+
57724+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57725+ rcu_read_lock();
57726+ {
57727+ const struct cred *tmpcred = current_cred();
57728+ const struct cred *cred = __task_cred(task);
57729+
57730+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
57731+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
57732+ || in_group_p(grsec_proc_gid)
57733+#endif
57734+ ) {
57735+ rcu_read_unlock();
57736+ return true;
57737+ }
57738+ }
57739+ rcu_read_unlock();
57740+
57741+ if (!pid->hide_pid)
57742+ return false;
57743+#endif
57744+
57745 if (pid->hide_pid < hide_pid_min)
57746 return true;
57747 if (in_group_p(pid->pid_gid))
57748 return true;
57749+
57750 return ptrace_may_access(task, PTRACE_MODE_READ);
57751 }
57752
57753@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
57754 put_task_struct(task);
57755
57756 if (!has_perms) {
57757+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57758+ {
57759+#else
57760 if (pid->hide_pid == 2) {
57761+#endif
57762 /*
57763 * Let's make getdents(), stat(), and open()
57764 * consistent with each other. If a process
57765@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
57766 if (!task)
57767 return -ESRCH;
57768
57769+ if (gr_acl_handle_procpidmem(task)) {
57770+ put_task_struct(task);
57771+ return -EPERM;
57772+ }
57773+
57774 mm = mm_access(task, mode);
57775 put_task_struct(task);
57776
57777@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
57778
57779 file->private_data = mm;
57780
57781+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57782+ file->f_version = current->exec_id;
57783+#endif
57784+
57785 return 0;
57786 }
57787
57788@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
57789 ssize_t copied;
57790 char *page;
57791
57792+#ifdef CONFIG_GRKERNSEC
57793+ if (write)
57794+ return -EPERM;
57795+#endif
57796+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57797+ if (file->f_version != current->exec_id) {
57798+ gr_log_badprocpid("mem");
57799+ return 0;
57800+ }
57801+#endif
57802+
57803 if (!mm)
57804 return 0;
57805
57806@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
57807 goto free;
57808
57809 while (count > 0) {
57810- int this_len = min_t(int, count, PAGE_SIZE);
57811+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
57812
57813 if (write && copy_from_user(page, buf, this_len)) {
57814 copied = -EFAULT;
57815@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
57816 if (!mm)
57817 return 0;
57818
57819+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57820+ if (file->f_version != current->exec_id) {
57821+ gr_log_badprocpid("environ");
57822+ return 0;
57823+ }
57824+#endif
57825+
57826 page = (char *)__get_free_page(GFP_TEMPORARY);
57827 if (!page)
57828 return -ENOMEM;
57829@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
57830 goto free;
57831 while (count > 0) {
57832 size_t this_len, max_len;
57833- int retval;
57834+ ssize_t retval;
57835
57836 if (src >= (mm->env_end - mm->env_start))
57837 break;
57838@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
57839 int error = -EACCES;
57840
57841 /* Are we allowed to snoop on the tasks file descriptors? */
57842- if (!proc_fd_access_allowed(inode))
57843+ if (!proc_fd_access_allowed(inode, 0))
57844 goto out;
57845
57846 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
57847@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
57848 struct path path;
57849
57850 /* Are we allowed to snoop on the tasks file descriptors? */
57851- if (!proc_fd_access_allowed(inode))
57852- goto out;
57853+ /* logging this is needed for learning on chromium to work properly,
57854+ but we don't want to flood the logs from 'ps' which does a readlink
57855+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
57856+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
57857+ */
57858+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
57859+ if (!proc_fd_access_allowed(inode,0))
57860+ goto out;
57861+ } else {
57862+ if (!proc_fd_access_allowed(inode,1))
57863+ goto out;
57864+ }
57865
57866 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
57867 if (error)
57868@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
57869 rcu_read_lock();
57870 cred = __task_cred(task);
57871 inode->i_uid = cred->euid;
57872+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
57873+ inode->i_gid = grsec_proc_gid;
57874+#else
57875 inode->i_gid = cred->egid;
57876+#endif
57877 rcu_read_unlock();
57878 }
57879 security_task_to_inode(task, inode);
57880@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
57881 return -ENOENT;
57882 }
57883 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
57884+#ifdef CONFIG_GRKERNSEC_PROC_USER
57885+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
57886+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57887+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
57888+#endif
57889 task_dumpable(task)) {
57890 cred = __task_cred(task);
57891 stat->uid = cred->euid;
57892+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
57893+ stat->gid = grsec_proc_gid;
57894+#else
57895 stat->gid = cred->egid;
57896+#endif
57897 }
57898 }
57899 rcu_read_unlock();
57900@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
57901
57902 if (task) {
57903 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
57904+#ifdef CONFIG_GRKERNSEC_PROC_USER
57905+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
57906+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57907+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
57908+#endif
57909 task_dumpable(task)) {
57910 rcu_read_lock();
57911 cred = __task_cred(task);
57912 inode->i_uid = cred->euid;
57913+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
57914+ inode->i_gid = grsec_proc_gid;
57915+#else
57916 inode->i_gid = cred->egid;
57917+#endif
57918 rcu_read_unlock();
57919 } else {
57920 inode->i_uid = GLOBAL_ROOT_UID;
57921@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
57922 if (!task)
57923 goto out_no_task;
57924
57925+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
57926+ goto out;
57927+
57928 /*
57929 * Yes, it does not scale. And it should not. Don't add
57930 * new entries into /proc/<tgid>/ without very good reasons.
57931@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
57932 if (!task)
57933 goto out_no_task;
57934
57935+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
57936+ goto out;
57937+
57938 ret = 0;
57939 i = filp->f_pos;
57940 switch (i) {
57941@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
57942 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
57943 #endif
57944 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
57945-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
57946+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
57947 INF("syscall", S_IRUGO, proc_pid_syscall),
57948 #endif
57949 INF("cmdline", S_IRUGO, proc_pid_cmdline),
57950@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
57951 #ifdef CONFIG_SECURITY
57952 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
57953 #endif
57954-#ifdef CONFIG_KALLSYMS
57955+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
57956 INF("wchan", S_IRUGO, proc_pid_wchan),
57957 #endif
57958-#ifdef CONFIG_STACKTRACE
57959+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
57960 ONE("stack", S_IRUGO, proc_pid_stack),
57961 #endif
57962 #ifdef CONFIG_SCHEDSTATS
57963@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
57964 #ifdef CONFIG_HARDWALL
57965 INF("hardwall", S_IRUGO, proc_pid_hardwall),
57966 #endif
57967+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
57968+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
57969+#endif
57970 #ifdef CONFIG_USER_NS
57971 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
57972 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
57973@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
57974 if (!inode)
57975 goto out;
57976
57977+#ifdef CONFIG_GRKERNSEC_PROC_USER
57978+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
57979+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57980+ inode->i_gid = grsec_proc_gid;
57981+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
57982+#else
57983 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
57984+#endif
57985 inode->i_op = &proc_tgid_base_inode_operations;
57986 inode->i_fop = &proc_tgid_base_operations;
57987 inode->i_flags|=S_IMMUTABLE;
57988@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
57989 if (!task)
57990 goto out;
57991
57992+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
57993+ goto out_put_task;
57994+
57995 result = proc_pid_instantiate(dir, dentry, task, NULL);
57996+out_put_task:
57997 put_task_struct(task);
57998 out:
57999 return result;
58000@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
58001 static int fake_filldir(void *buf, const char *name, int namelen,
58002 loff_t offset, u64 ino, unsigned d_type)
58003 {
58004+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
58005+ __buf->error = -EINVAL;
58006 return 0;
58007 }
58008
58009@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
58010 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
58011 #endif
58012 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
58013-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
58014+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
58015 INF("syscall", S_IRUGO, proc_pid_syscall),
58016 #endif
58017 INF("cmdline", S_IRUGO, proc_pid_cmdline),
58018@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
58019 #ifdef CONFIG_SECURITY
58020 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
58021 #endif
58022-#ifdef CONFIG_KALLSYMS
58023+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58024 INF("wchan", S_IRUGO, proc_pid_wchan),
58025 #endif
58026-#ifdef CONFIG_STACKTRACE
58027+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58028 ONE("stack", S_IRUGO, proc_pid_stack),
58029 #endif
58030 #ifdef CONFIG_SCHEDSTATS
58031diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
58032index 82676e3..5f8518a 100644
58033--- a/fs/proc/cmdline.c
58034+++ b/fs/proc/cmdline.c
58035@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
58036
58037 static int __init proc_cmdline_init(void)
58038 {
58039+#ifdef CONFIG_GRKERNSEC_PROC_ADD
58040+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
58041+#else
58042 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
58043+#endif
58044 return 0;
58045 }
58046 module_init(proc_cmdline_init);
58047diff --git a/fs/proc/devices.c b/fs/proc/devices.c
58048index b143471..bb105e5 100644
58049--- a/fs/proc/devices.c
58050+++ b/fs/proc/devices.c
58051@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
58052
58053 static int __init proc_devices_init(void)
58054 {
58055+#ifdef CONFIG_GRKERNSEC_PROC_ADD
58056+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
58057+#else
58058 proc_create("devices", 0, NULL, &proc_devinfo_operations);
58059+#endif
58060 return 0;
58061 }
58062 module_init(proc_devices_init);
58063diff --git a/fs/proc/fd.c b/fs/proc/fd.c
58064index d7a4a28..0201742 100644
58065--- a/fs/proc/fd.c
58066+++ b/fs/proc/fd.c
58067@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
58068 if (!task)
58069 return -ENOENT;
58070
58071- files = get_files_struct(task);
58072+ if (!gr_acl_handle_procpidmem(task))
58073+ files = get_files_struct(task);
58074 put_task_struct(task);
58075
58076 if (files) {
58077@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
58078 */
58079 int proc_fd_permission(struct inode *inode, int mask)
58080 {
58081+ struct task_struct *task;
58082 int rv = generic_permission(inode, mask);
58083- if (rv == 0)
58084- return 0;
58085+
58086 if (task_pid(current) == proc_pid(inode))
58087 rv = 0;
58088+
58089+ task = get_proc_task(inode);
58090+ if (task == NULL)
58091+ return rv;
58092+
58093+ if (gr_acl_handle_procpidmem(task))
58094+ rv = -EACCES;
58095+
58096+ put_task_struct(task);
58097+
58098 return rv;
58099 }
58100
58101diff --git a/fs/proc/inode.c b/fs/proc/inode.c
58102index 073aea6..0630370 100644
58103--- a/fs/proc/inode.c
58104+++ b/fs/proc/inode.c
58105@@ -23,11 +23,17 @@
58106 #include <linux/slab.h>
58107 #include <linux/mount.h>
58108 #include <linux/magic.h>
58109+#include <linux/grsecurity.h>
58110
58111 #include <asm/uaccess.h>
58112
58113 #include "internal.h"
58114
58115+#ifdef CONFIG_PROC_SYSCTL
58116+extern const struct inode_operations proc_sys_inode_operations;
58117+extern const struct inode_operations proc_sys_dir_operations;
58118+#endif
58119+
58120 static void proc_evict_inode(struct inode *inode)
58121 {
58122 struct proc_dir_entry *de;
58123@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
58124 ns = PROC_I(inode)->ns.ns;
58125 if (ns_ops && ns)
58126 ns_ops->put(ns);
58127+
58128+#ifdef CONFIG_PROC_SYSCTL
58129+ if (inode->i_op == &proc_sys_inode_operations ||
58130+ inode->i_op == &proc_sys_dir_operations)
58131+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
58132+#endif
58133+
58134 }
58135
58136 static struct kmem_cache * proc_inode_cachep;
58137@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
58138 if (de->mode) {
58139 inode->i_mode = de->mode;
58140 inode->i_uid = de->uid;
58141+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
58142+ inode->i_gid = grsec_proc_gid;
58143+#else
58144 inode->i_gid = de->gid;
58145+#endif
58146 }
58147 if (de->size)
58148 inode->i_size = de->size;
58149diff --git a/fs/proc/internal.h b/fs/proc/internal.h
58150index d600fb0..3b495fe 100644
58151--- a/fs/proc/internal.h
58152+++ b/fs/proc/internal.h
58153@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
58154 struct pid *, struct task_struct *);
58155 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
58156 struct pid *, struct task_struct *);
58157+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58158+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
58159+#endif
58160
58161 /*
58162 * base.c
58163diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
58164index 0a22194..a9fc8c1 100644
58165--- a/fs/proc/kcore.c
58166+++ b/fs/proc/kcore.c
58167@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
58168 * the addresses in the elf_phdr on our list.
58169 */
58170 start = kc_offset_to_vaddr(*fpos - elf_buflen);
58171- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
58172+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
58173+ if (tsz > buflen)
58174 tsz = buflen;
58175-
58176+
58177 while (buflen) {
58178 struct kcore_list *m;
58179
58180@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
58181 kfree(elf_buf);
58182 } else {
58183 if (kern_addr_valid(start)) {
58184- unsigned long n;
58185+ char *elf_buf;
58186+ mm_segment_t oldfs;
58187
58188- n = copy_to_user(buffer, (char *)start, tsz);
58189- /*
58190- * We cannot distinguish between fault on source
58191- * and fault on destination. When this happens
58192- * we clear too and hope it will trigger the
58193- * EFAULT again.
58194- */
58195- if (n) {
58196- if (clear_user(buffer + tsz - n,
58197- n))
58198+ elf_buf = kmalloc(tsz, GFP_KERNEL);
58199+ if (!elf_buf)
58200+ return -ENOMEM;
58201+ oldfs = get_fs();
58202+ set_fs(KERNEL_DS);
58203+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
58204+ set_fs(oldfs);
58205+ if (copy_to_user(buffer, elf_buf, tsz)) {
58206+ kfree(elf_buf);
58207 return -EFAULT;
58208+ }
58209 }
58210+ set_fs(oldfs);
58211+ kfree(elf_buf);
58212 } else {
58213 if (clear_user(buffer, tsz))
58214 return -EFAULT;
58215@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
58216
58217 static int open_kcore(struct inode *inode, struct file *filp)
58218 {
58219+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
58220+ return -EPERM;
58221+#endif
58222 if (!capable(CAP_SYS_RAWIO))
58223 return -EPERM;
58224 if (kcore_need_update)
58225diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
58226index 5aa847a..f77c8d4 100644
58227--- a/fs/proc/meminfo.c
58228+++ b/fs/proc/meminfo.c
58229@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
58230 vmi.used >> 10,
58231 vmi.largest_chunk >> 10
58232 #ifdef CONFIG_MEMORY_FAILURE
58233- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
58234+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
58235 #endif
58236 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
58237 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
58238diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
58239index ccfd99b..1b7e255 100644
58240--- a/fs/proc/nommu.c
58241+++ b/fs/proc/nommu.c
58242@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
58243 if (len < 1)
58244 len = 1;
58245 seq_printf(m, "%*c", len, ' ');
58246- seq_path(m, &file->f_path, "");
58247+ seq_path(m, &file->f_path, "\n\\");
58248 }
58249
58250 seq_putc(m, '\n');
58251diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
58252index 986e832..6e8e859 100644
58253--- a/fs/proc/proc_net.c
58254+++ b/fs/proc/proc_net.c
58255@@ -23,6 +23,7 @@
58256 #include <linux/nsproxy.h>
58257 #include <net/net_namespace.h>
58258 #include <linux/seq_file.h>
58259+#include <linux/grsecurity.h>
58260
58261 #include "internal.h"
58262
58263@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
58264 struct task_struct *task;
58265 struct nsproxy *ns;
58266 struct net *net = NULL;
58267+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58268+ const struct cred *cred = current_cred();
58269+#endif
58270+
58271+#ifdef CONFIG_GRKERNSEC_PROC_USER
58272+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
58273+ return net;
58274+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58275+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
58276+ return net;
58277+#endif
58278
58279 rcu_read_lock();
58280 task = pid_task(proc_pid(dir), PIDTYPE_PID);
58281diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
58282index ac05f33..1e6dc7e 100644
58283--- a/fs/proc/proc_sysctl.c
58284+++ b/fs/proc/proc_sysctl.c
58285@@ -13,11 +13,15 @@
58286 #include <linux/module.h>
58287 #include "internal.h"
58288
58289+extern int gr_handle_chroot_sysctl(const int op);
58290+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
58291+ const int op);
58292+
58293 static const struct dentry_operations proc_sys_dentry_operations;
58294 static const struct file_operations proc_sys_file_operations;
58295-static const struct inode_operations proc_sys_inode_operations;
58296+const struct inode_operations proc_sys_inode_operations;
58297 static const struct file_operations proc_sys_dir_file_operations;
58298-static const struct inode_operations proc_sys_dir_operations;
58299+const struct inode_operations proc_sys_dir_operations;
58300
58301 void proc_sys_poll_notify(struct ctl_table_poll *poll)
58302 {
58303@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
58304
58305 err = NULL;
58306 d_set_d_op(dentry, &proc_sys_dentry_operations);
58307+
58308+ gr_handle_proc_create(dentry, inode);
58309+
58310 d_add(dentry, inode);
58311
58312 out:
58313@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
58314 struct inode *inode = file_inode(filp);
58315 struct ctl_table_header *head = grab_header(inode);
58316 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
58317+ int op = write ? MAY_WRITE : MAY_READ;
58318 ssize_t error;
58319 size_t res;
58320
58321@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
58322 * and won't be until we finish.
58323 */
58324 error = -EPERM;
58325- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
58326+ if (sysctl_perm(head, table, op))
58327 goto out;
58328
58329 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
58330@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
58331 if (!table->proc_handler)
58332 goto out;
58333
58334+#ifdef CONFIG_GRKERNSEC
58335+ error = -EPERM;
58336+ if (gr_handle_chroot_sysctl(op))
58337+ goto out;
58338+ dget(filp->f_path.dentry);
58339+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
58340+ dput(filp->f_path.dentry);
58341+ goto out;
58342+ }
58343+ dput(filp->f_path.dentry);
58344+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
58345+ goto out;
58346+ if (write && !capable(CAP_SYS_ADMIN))
58347+ goto out;
58348+#endif
58349+
58350 /* careful: calling conventions are nasty here */
58351 res = count;
58352 error = table->proc_handler(table, write, buf, &res, ppos);
58353@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
58354 return -ENOMEM;
58355 } else {
58356 d_set_d_op(child, &proc_sys_dentry_operations);
58357+
58358+ gr_handle_proc_create(child, inode);
58359+
58360 d_add(child, inode);
58361 }
58362 } else {
58363@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
58364 if ((*pos)++ < file->f_pos)
58365 return 0;
58366
58367+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
58368+ return 0;
58369+
58370 if (unlikely(S_ISLNK(table->mode)))
58371 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
58372 else
58373@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
58374 if (IS_ERR(head))
58375 return PTR_ERR(head);
58376
58377+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
58378+ return -ENOENT;
58379+
58380 generic_fillattr(inode, stat);
58381 if (table)
58382 stat->mode = (stat->mode & S_IFMT) | table->mode;
58383@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
58384 .llseek = generic_file_llseek,
58385 };
58386
58387-static const struct inode_operations proc_sys_inode_operations = {
58388+const struct inode_operations proc_sys_inode_operations = {
58389 .permission = proc_sys_permission,
58390 .setattr = proc_sys_setattr,
58391 .getattr = proc_sys_getattr,
58392 };
58393
58394-static const struct inode_operations proc_sys_dir_operations = {
58395+const struct inode_operations proc_sys_dir_operations = {
58396 .lookup = proc_sys_lookup,
58397 .permission = proc_sys_permission,
58398 .setattr = proc_sys_setattr,
58399@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
58400 static struct ctl_dir *new_dir(struct ctl_table_set *set,
58401 const char *name, int namelen)
58402 {
58403- struct ctl_table *table;
58404+ ctl_table_no_const *table;
58405 struct ctl_dir *new;
58406 struct ctl_node *node;
58407 char *new_name;
58408@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
58409 return NULL;
58410
58411 node = (struct ctl_node *)(new + 1);
58412- table = (struct ctl_table *)(node + 1);
58413+ table = (ctl_table_no_const *)(node + 1);
58414 new_name = (char *)(table + 2);
58415 memcpy(new_name, name, namelen);
58416 new_name[namelen] = '\0';
58417@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
58418 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
58419 struct ctl_table_root *link_root)
58420 {
58421- struct ctl_table *link_table, *entry, *link;
58422+ ctl_table_no_const *link_table, *link;
58423+ struct ctl_table *entry;
58424 struct ctl_table_header *links;
58425 struct ctl_node *node;
58426 char *link_name;
58427@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
58428 return NULL;
58429
58430 node = (struct ctl_node *)(links + 1);
58431- link_table = (struct ctl_table *)(node + nr_entries);
58432+ link_table = (ctl_table_no_const *)(node + nr_entries);
58433 link_name = (char *)&link_table[nr_entries + 1];
58434
58435 for (link = link_table, entry = table; entry->procname; link++, entry++) {
58436@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
58437 struct ctl_table_header ***subheader, struct ctl_table_set *set,
58438 struct ctl_table *table)
58439 {
58440- struct ctl_table *ctl_table_arg = NULL;
58441- struct ctl_table *entry, *files;
58442+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
58443+ struct ctl_table *entry;
58444 int nr_files = 0;
58445 int nr_dirs = 0;
58446 int err = -ENOMEM;
58447@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
58448 nr_files++;
58449 }
58450
58451- files = table;
58452 /* If there are mixed files and directories we need a new table */
58453 if (nr_dirs && nr_files) {
58454- struct ctl_table *new;
58455+ ctl_table_no_const *new;
58456 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
58457 GFP_KERNEL);
58458 if (!files)
58459@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
58460 /* Register everything except a directory full of subdirectories */
58461 if (nr_files || !nr_dirs) {
58462 struct ctl_table_header *header;
58463- header = __register_sysctl_table(set, path, files);
58464+ header = __register_sysctl_table(set, path, files ? files : table);
58465 if (!header) {
58466 kfree(ctl_table_arg);
58467 goto out;
58468diff --git a/fs/proc/root.c b/fs/proc/root.c
58469index 41a6ea9..23eaa92 100644
58470--- a/fs/proc/root.c
58471+++ b/fs/proc/root.c
58472@@ -182,7 +182,15 @@ void __init proc_root_init(void)
58473 #ifdef CONFIG_PROC_DEVICETREE
58474 proc_device_tree_init();
58475 #endif
58476+#ifdef CONFIG_GRKERNSEC_PROC_ADD
58477+#ifdef CONFIG_GRKERNSEC_PROC_USER
58478+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
58479+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58480+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
58481+#endif
58482+#else
58483 proc_mkdir("bus", NULL);
58484+#endif
58485 proc_sys_init();
58486 }
58487
58488diff --git a/fs/proc/self.c b/fs/proc/self.c
58489index 6b6a993..807cccc 100644
58490--- a/fs/proc/self.c
58491+++ b/fs/proc/self.c
58492@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
58493 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
58494 void *cookie)
58495 {
58496- char *s = nd_get_link(nd);
58497+ const char *s = nd_get_link(nd);
58498 if (!IS_ERR(s))
58499 kfree(s);
58500 }
58501diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
58502index 3e636d8..350cc48 100644
58503--- a/fs/proc/task_mmu.c
58504+++ b/fs/proc/task_mmu.c
58505@@ -11,12 +11,19 @@
58506 #include <linux/rmap.h>
58507 #include <linux/swap.h>
58508 #include <linux/swapops.h>
58509+#include <linux/grsecurity.h>
58510
58511 #include <asm/elf.h>
58512 #include <asm/uaccess.h>
58513 #include <asm/tlbflush.h>
58514 #include "internal.h"
58515
58516+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58517+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58518+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58519+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58520+#endif
58521+
58522 void task_mem(struct seq_file *m, struct mm_struct *mm)
58523 {
58524 unsigned long data, text, lib, swap;
58525@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
58526 "VmExe:\t%8lu kB\n"
58527 "VmLib:\t%8lu kB\n"
58528 "VmPTE:\t%8lu kB\n"
58529- "VmSwap:\t%8lu kB\n",
58530- hiwater_vm << (PAGE_SHIFT-10),
58531+ "VmSwap:\t%8lu kB\n"
58532+
58533+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58534+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
58535+#endif
58536+
58537+ ,hiwater_vm << (PAGE_SHIFT-10),
58538 total_vm << (PAGE_SHIFT-10),
58539 mm->locked_vm << (PAGE_SHIFT-10),
58540 mm->pinned_vm << (PAGE_SHIFT-10),
58541@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
58542 data << (PAGE_SHIFT-10),
58543 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
58544 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
58545- swap << (PAGE_SHIFT-10));
58546+ swap << (PAGE_SHIFT-10)
58547+
58548+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58549+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58550+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
58551+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
58552+#else
58553+ , mm->context.user_cs_base
58554+ , mm->context.user_cs_limit
58555+#endif
58556+#endif
58557+
58558+ );
58559 }
58560
58561 unsigned long task_vsize(struct mm_struct *mm)
58562@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
58563 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
58564 }
58565
58566- /* We don't show the stack guard page in /proc/maps */
58567+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58568+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
58569+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
58570+#else
58571 start = vma->vm_start;
58572- if (stack_guard_page_start(vma, start))
58573- start += PAGE_SIZE;
58574 end = vma->vm_end;
58575- if (stack_guard_page_end(vma, end))
58576- end -= PAGE_SIZE;
58577+#endif
58578
58579 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
58580 start,
58581@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
58582 flags & VM_WRITE ? 'w' : '-',
58583 flags & VM_EXEC ? 'x' : '-',
58584 flags & VM_MAYSHARE ? 's' : 'p',
58585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58586+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
58587+#else
58588 pgoff,
58589+#endif
58590 MAJOR(dev), MINOR(dev), ino, &len);
58591
58592 /*
58593@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
58594 */
58595 if (file) {
58596 pad_len_spaces(m, len);
58597- seq_path(m, &file->f_path, "\n");
58598+ seq_path(m, &file->f_path, "\n\\");
58599 goto done;
58600 }
58601
58602@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
58603 * Thread stack in /proc/PID/task/TID/maps or
58604 * the main process stack.
58605 */
58606- if (!is_pid || (vma->vm_start <= mm->start_stack &&
58607- vma->vm_end >= mm->start_stack)) {
58608+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
58609+ (vma->vm_start <= mm->start_stack &&
58610+ vma->vm_end >= mm->start_stack)) {
58611 name = "[stack]";
58612 } else {
58613 /* Thread stack in /proc/PID/maps */
58614@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
58615 struct proc_maps_private *priv = m->private;
58616 struct task_struct *task = priv->task;
58617
58618+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58619+ if (current->exec_id != m->exec_id) {
58620+ gr_log_badprocpid("maps");
58621+ return 0;
58622+ }
58623+#endif
58624+
58625 show_map_vma(m, vma, is_pid);
58626
58627 if (m->count < m->size) /* vma is copied successfully */
58628@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
58629 .private = &mss,
58630 };
58631
58632+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58633+ if (current->exec_id != m->exec_id) {
58634+ gr_log_badprocpid("smaps");
58635+ return 0;
58636+ }
58637+#endif
58638 memset(&mss, 0, sizeof mss);
58639- mss.vma = vma;
58640- /* mmap_sem is held in m_start */
58641- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
58642- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
58643-
58644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58645+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
58646+#endif
58647+ mss.vma = vma;
58648+ /* mmap_sem is held in m_start */
58649+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
58650+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
58651+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58652+ }
58653+#endif
58654 show_map_vma(m, vma, is_pid);
58655
58656 seq_printf(m,
58657@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
58658 "KernelPageSize: %8lu kB\n"
58659 "MMUPageSize: %8lu kB\n"
58660 "Locked: %8lu kB\n",
58661+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58662+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
58663+#else
58664 (vma->vm_end - vma->vm_start) >> 10,
58665+#endif
58666 mss.resident >> 10,
58667 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
58668 mss.shared_clean >> 10,
58669@@ -792,14 +843,14 @@ typedef struct {
58670 } pagemap_entry_t;
58671
58672 struct pagemapread {
58673- int pos, len;
58674+ int pos, len; /* units: PM_ENTRY_BYTES, not bytes */
58675 pagemap_entry_t *buffer;
58676 };
58677
58678 #define PAGEMAP_WALK_SIZE (PMD_SIZE)
58679 #define PAGEMAP_WALK_MASK (PMD_MASK)
58680
58681-#define PM_ENTRY_BYTES sizeof(u64)
58682+#define PM_ENTRY_BYTES sizeof(pagemap_entry_t)
58683 #define PM_STATUS_BITS 3
58684 #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS)
58685 #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET)
58686@@ -1038,8 +1089,8 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
58687 if (!count)
58688 goto out_task;
58689
58690- pm.len = PM_ENTRY_BYTES * (PAGEMAP_WALK_SIZE >> PAGE_SHIFT);
58691- pm.buffer = kmalloc(pm.len, GFP_TEMPORARY);
58692+ pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT);
58693+ pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_TEMPORARY);
58694 ret = -ENOMEM;
58695 if (!pm.buffer)
58696 goto out_task;
58697@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
58698 int n;
58699 char buffer[50];
58700
58701+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58702+ if (current->exec_id != m->exec_id) {
58703+ gr_log_badprocpid("numa_maps");
58704+ return 0;
58705+ }
58706+#endif
58707+
58708 if (!mm)
58709 return 0;
58710
58711@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
58712 mpol_to_str(buffer, sizeof(buffer), pol);
58713 mpol_cond_put(pol);
58714
58715+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58716+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
58717+#else
58718 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
58719+#endif
58720
58721 if (file) {
58722 seq_printf(m, " file=");
58723- seq_path(m, &file->f_path, "\n\t= ");
58724+ seq_path(m, &file->f_path, "\n\t\\= ");
58725 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
58726 seq_printf(m, " heap");
58727 } else {
58728diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
58729index 56123a6..5a2f6ec 100644
58730--- a/fs/proc/task_nommu.c
58731+++ b/fs/proc/task_nommu.c
58732@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
58733 else
58734 bytes += kobjsize(mm);
58735
58736- if (current->fs && current->fs->users > 1)
58737+ if (current->fs && atomic_read(&current->fs->users) > 1)
58738 sbytes += kobjsize(current->fs);
58739 else
58740 bytes += kobjsize(current->fs);
58741@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
58742
58743 if (file) {
58744 pad_len_spaces(m, len);
58745- seq_path(m, &file->f_path, "");
58746+ seq_path(m, &file->f_path, "\n\\");
58747 } else if (mm) {
58748 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
58749
58750diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
58751index 17f7e08..e4b1529 100644
58752--- a/fs/proc/vmcore.c
58753+++ b/fs/proc/vmcore.c
58754@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
58755 nr_bytes = count;
58756
58757 /* If pfn is not ram, return zeros for sparse dump files */
58758- if (pfn_is_ram(pfn) == 0)
58759- memset(buf, 0, nr_bytes);
58760- else {
58761+ if (pfn_is_ram(pfn) == 0) {
58762+ if (userbuf) {
58763+ if (clear_user((char __force_user *)buf, nr_bytes))
58764+ return -EFAULT;
58765+ } else
58766+ memset(buf, 0, nr_bytes);
58767+ } else {
58768 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
58769 offset, userbuf);
58770 if (tmp < 0)
58771@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
58772 if (tsz > nr_bytes)
58773 tsz = nr_bytes;
58774
58775- tmp = read_from_oldmem(buffer, tsz, &start, 1);
58776+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
58777 if (tmp < 0)
58778 return tmp;
58779 buflen -= tsz;
58780diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
58781index b00fcc9..e0c6381 100644
58782--- a/fs/qnx6/qnx6.h
58783+++ b/fs/qnx6/qnx6.h
58784@@ -74,7 +74,7 @@ enum {
58785 BYTESEX_BE,
58786 };
58787
58788-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
58789+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
58790 {
58791 if (sbi->s_bytesex == BYTESEX_LE)
58792 return le64_to_cpu((__force __le64)n);
58793@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
58794 return (__force __fs64)cpu_to_be64(n);
58795 }
58796
58797-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
58798+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
58799 {
58800 if (sbi->s_bytesex == BYTESEX_LE)
58801 return le32_to_cpu((__force __le32)n);
58802diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
58803index 16e8abb..2dcf914 100644
58804--- a/fs/quota/netlink.c
58805+++ b/fs/quota/netlink.c
58806@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
58807 void quota_send_warning(struct kqid qid, dev_t dev,
58808 const char warntype)
58809 {
58810- static atomic_t seq;
58811+ static atomic_unchecked_t seq;
58812 struct sk_buff *skb;
58813 void *msg_head;
58814 int ret;
58815@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
58816 "VFS: Not enough memory to send quota warning.\n");
58817 return;
58818 }
58819- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
58820+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
58821 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
58822 if (!msg_head) {
58823 printk(KERN_ERR
58824diff --git a/fs/read_write.c b/fs/read_write.c
58825index 2cefa41..c7e2fe0 100644
58826--- a/fs/read_write.c
58827+++ b/fs/read_write.c
58828@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
58829
58830 old_fs = get_fs();
58831 set_fs(get_ds());
58832- p = (__force const char __user *)buf;
58833+ p = (const char __force_user *)buf;
58834 if (count > MAX_RW_COUNT)
58835 count = MAX_RW_COUNT;
58836 if (file->f_op->write)
58837diff --git a/fs/readdir.c b/fs/readdir.c
58838index fee38e0..12fdf47 100644
58839--- a/fs/readdir.c
58840+++ b/fs/readdir.c
58841@@ -17,6 +17,7 @@
58842 #include <linux/security.h>
58843 #include <linux/syscalls.h>
58844 #include <linux/unistd.h>
58845+#include <linux/namei.h>
58846
58847 #include <asm/uaccess.h>
58848
58849@@ -67,6 +68,7 @@ struct old_linux_dirent {
58850
58851 struct readdir_callback {
58852 struct old_linux_dirent __user * dirent;
58853+ struct file * file;
58854 int result;
58855 };
58856
58857@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
58858 buf->result = -EOVERFLOW;
58859 return -EOVERFLOW;
58860 }
58861+
58862+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58863+ return 0;
58864+
58865 buf->result++;
58866 dirent = buf->dirent;
58867 if (!access_ok(VERIFY_WRITE, dirent,
58868@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58869
58870 buf.result = 0;
58871 buf.dirent = dirent;
58872+ buf.file = f.file;
58873
58874 error = vfs_readdir(f.file, fillonedir, &buf);
58875 if (buf.result)
58876@@ -139,6 +146,7 @@ struct linux_dirent {
58877 struct getdents_callback {
58878 struct linux_dirent __user * current_dir;
58879 struct linux_dirent __user * previous;
58880+ struct file * file;
58881 int count;
58882 int error;
58883 };
58884@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
58885 buf->error = -EOVERFLOW;
58886 return -EOVERFLOW;
58887 }
58888+
58889+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58890+ return 0;
58891+
58892 dirent = buf->previous;
58893 if (dirent) {
58894 if (__put_user(offset, &dirent->d_off))
58895@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
58896 buf.previous = NULL;
58897 buf.count = count;
58898 buf.error = 0;
58899+ buf.file = f.file;
58900
58901 error = vfs_readdir(f.file, filldir, &buf);
58902 if (error >= 0)
58903@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
58904 struct getdents_callback64 {
58905 struct linux_dirent64 __user * current_dir;
58906 struct linux_dirent64 __user * previous;
58907+ struct file *file;
58908 int count;
58909 int error;
58910 };
58911@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
58912 buf->error = -EINVAL; /* only used if we fail.. */
58913 if (reclen > buf->count)
58914 return -EINVAL;
58915+
58916+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58917+ return 0;
58918+
58919 dirent = buf->previous;
58920 if (dirent) {
58921 if (__put_user(offset, &dirent->d_off))
58922@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58923
58924 buf.current_dir = dirent;
58925 buf.previous = NULL;
58926+ buf.file = f.file;
58927 buf.count = count;
58928 buf.error = 0;
58929
58930@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58931 error = buf.error;
58932 lastdirent = buf.previous;
58933 if (lastdirent) {
58934- typeof(lastdirent->d_off) d_off = f.file->f_pos;
58935+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
58936 if (__put_user(d_off, &lastdirent->d_off))
58937 error = -EFAULT;
58938 else
58939diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
58940index 2b7882b..1c5ef48 100644
58941--- a/fs/reiserfs/do_balan.c
58942+++ b/fs/reiserfs/do_balan.c
58943@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
58944 return;
58945 }
58946
58947- atomic_inc(&(fs_generation(tb->tb_sb)));
58948+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
58949 do_balance_starts(tb);
58950
58951 /* balance leaf returns 0 except if combining L R and S into
58952diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
58953index 1d48974..2f8f4e0 100644
58954--- a/fs/reiserfs/procfs.c
58955+++ b/fs/reiserfs/procfs.c
58956@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
58957 "SMALL_TAILS " : "NO_TAILS ",
58958 replay_only(sb) ? "REPLAY_ONLY " : "",
58959 convert_reiserfs(sb) ? "CONV " : "",
58960- atomic_read(&r->s_generation_counter),
58961+ atomic_read_unchecked(&r->s_generation_counter),
58962 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
58963 SF(s_do_balance), SF(s_unneeded_left_neighbor),
58964 SF(s_good_search_by_key_reada), SF(s_bmaps),
58965diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
58966index 157e474..65a6114 100644
58967--- a/fs/reiserfs/reiserfs.h
58968+++ b/fs/reiserfs/reiserfs.h
58969@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
58970 /* Comment? -Hans */
58971 wait_queue_head_t s_wait;
58972 /* To be obsoleted soon by per buffer seals.. -Hans */
58973- atomic_t s_generation_counter; // increased by one every time the
58974+ atomic_unchecked_t s_generation_counter; // increased by one every time the
58975 // tree gets re-balanced
58976 unsigned long s_properties; /* File system properties. Currently holds
58977 on-disk FS format */
58978@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
58979 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
58980
58981 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
58982-#define get_generation(s) atomic_read (&fs_generation(s))
58983+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
58984 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
58985 #define __fs_changed(gen,s) (gen != get_generation (s))
58986 #define fs_changed(gen,s) \
58987diff --git a/fs/select.c b/fs/select.c
58988index 8c1c96c..a0f9b6d 100644
58989--- a/fs/select.c
58990+++ b/fs/select.c
58991@@ -20,6 +20,7 @@
58992 #include <linux/export.h>
58993 #include <linux/slab.h>
58994 #include <linux/poll.h>
58995+#include <linux/security.h>
58996 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
58997 #include <linux/file.h>
58998 #include <linux/fdtable.h>
58999@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
59000 struct poll_list *walk = head;
59001 unsigned long todo = nfds;
59002
59003+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
59004 if (nfds > rlimit(RLIMIT_NOFILE))
59005 return -EINVAL;
59006
59007diff --git a/fs/seq_file.c b/fs/seq_file.c
59008index 774c1eb..b67582a 100644
59009--- a/fs/seq_file.c
59010+++ b/fs/seq_file.c
59011@@ -10,6 +10,7 @@
59012 #include <linux/seq_file.h>
59013 #include <linux/slab.h>
59014 #include <linux/cred.h>
59015+#include <linux/sched.h>
59016
59017 #include <asm/uaccess.h>
59018 #include <asm/page.h>
59019@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
59020 #ifdef CONFIG_USER_NS
59021 p->user_ns = file->f_cred->user_ns;
59022 #endif
59023+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59024+ p->exec_id = current->exec_id;
59025+#endif
59026
59027 /*
59028 * Wrappers around seq_open(e.g. swaps_open) need to be
59029@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
59030 return 0;
59031 }
59032 if (!m->buf) {
59033- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
59034+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
59035 if (!m->buf)
59036 return -ENOMEM;
59037 }
59038@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
59039 Eoverflow:
59040 m->op->stop(m, p);
59041 kfree(m->buf);
59042- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
59043+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
59044 return !m->buf ? -ENOMEM : -EAGAIN;
59045 }
59046
59047@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
59048
59049 /* grab buffer if we didn't have one */
59050 if (!m->buf) {
59051- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
59052+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
59053 if (!m->buf)
59054 goto Enomem;
59055 }
59056@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
59057 goto Fill;
59058 m->op->stop(m, p);
59059 kfree(m->buf);
59060- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
59061+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
59062 if (!m->buf)
59063 goto Enomem;
59064 m->count = 0;
59065@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
59066 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
59067 void *data)
59068 {
59069- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
59070+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
59071 int res = -ENOMEM;
59072
59073 if (op) {
59074diff --git a/fs/splice.c b/fs/splice.c
59075index d37431d..81c3044 100644
59076--- a/fs/splice.c
59077+++ b/fs/splice.c
59078@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
59079 pipe_lock(pipe);
59080
59081 for (;;) {
59082- if (!pipe->readers) {
59083+ if (!atomic_read(&pipe->readers)) {
59084 send_sig(SIGPIPE, current, 0);
59085 if (!ret)
59086 ret = -EPIPE;
59087@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
59088 page_nr++;
59089 ret += buf->len;
59090
59091- if (pipe->files)
59092+ if (atomic_read(&pipe->files))
59093 do_wakeup = 1;
59094
59095 if (!--spd->nr_pages)
59096@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
59097 do_wakeup = 0;
59098 }
59099
59100- pipe->waiting_writers++;
59101+ atomic_inc(&pipe->waiting_writers);
59102 pipe_wait(pipe);
59103- pipe->waiting_writers--;
59104+ atomic_dec(&pipe->waiting_writers);
59105 }
59106
59107 pipe_unlock(pipe);
59108@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
59109 old_fs = get_fs();
59110 set_fs(get_ds());
59111 /* The cast to a user pointer is valid due to the set_fs() */
59112- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
59113+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
59114 set_fs(old_fs);
59115
59116 return res;
59117@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
59118 old_fs = get_fs();
59119 set_fs(get_ds());
59120 /* The cast to a user pointer is valid due to the set_fs() */
59121- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
59122+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
59123 set_fs(old_fs);
59124
59125 return res;
59126@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
59127 goto err;
59128
59129 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
59130- vec[i].iov_base = (void __user *) page_address(page);
59131+ vec[i].iov_base = (void __force_user *) page_address(page);
59132 vec[i].iov_len = this_len;
59133 spd.pages[i] = page;
59134 spd.nr_pages++;
59135@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
59136 ops->release(pipe, buf);
59137 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
59138 pipe->nrbufs--;
59139- if (pipe->files)
59140+ if (atomic_read(&pipe->files))
59141 sd->need_wakeup = true;
59142 }
59143
59144@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
59145 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
59146 {
59147 while (!pipe->nrbufs) {
59148- if (!pipe->writers)
59149+ if (!atomic_read(&pipe->writers))
59150 return 0;
59151
59152- if (!pipe->waiting_writers && sd->num_spliced)
59153+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
59154 return 0;
59155
59156 if (sd->flags & SPLICE_F_NONBLOCK)
59157@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
59158 * out of the pipe right after the splice_to_pipe(). So set
59159 * PIPE_READERS appropriately.
59160 */
59161- pipe->readers = 1;
59162+ atomic_set(&pipe->readers, 1);
59163
59164 current->splice_pipe = pipe;
59165 }
59166@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
59167 ret = -ERESTARTSYS;
59168 break;
59169 }
59170- if (!pipe->writers)
59171+ if (!atomic_read(&pipe->writers))
59172 break;
59173- if (!pipe->waiting_writers) {
59174+ if (!atomic_read(&pipe->waiting_writers)) {
59175 if (flags & SPLICE_F_NONBLOCK) {
59176 ret = -EAGAIN;
59177 break;
59178@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
59179 pipe_lock(pipe);
59180
59181 while (pipe->nrbufs >= pipe->buffers) {
59182- if (!pipe->readers) {
59183+ if (!atomic_read(&pipe->readers)) {
59184 send_sig(SIGPIPE, current, 0);
59185 ret = -EPIPE;
59186 break;
59187@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
59188 ret = -ERESTARTSYS;
59189 break;
59190 }
59191- pipe->waiting_writers++;
59192+ atomic_inc(&pipe->waiting_writers);
59193 pipe_wait(pipe);
59194- pipe->waiting_writers--;
59195+ atomic_dec(&pipe->waiting_writers);
59196 }
59197
59198 pipe_unlock(pipe);
59199@@ -1854,14 +1854,14 @@ retry:
59200 pipe_double_lock(ipipe, opipe);
59201
59202 do {
59203- if (!opipe->readers) {
59204+ if (!atomic_read(&opipe->readers)) {
59205 send_sig(SIGPIPE, current, 0);
59206 if (!ret)
59207 ret = -EPIPE;
59208 break;
59209 }
59210
59211- if (!ipipe->nrbufs && !ipipe->writers)
59212+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
59213 break;
59214
59215 /*
59216@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
59217 pipe_double_lock(ipipe, opipe);
59218
59219 do {
59220- if (!opipe->readers) {
59221+ if (!atomic_read(&opipe->readers)) {
59222 send_sig(SIGPIPE, current, 0);
59223 if (!ret)
59224 ret = -EPIPE;
59225@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
59226 * return EAGAIN if we have the potential of some data in the
59227 * future, otherwise just return 0
59228 */
59229- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
59230+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
59231 ret = -EAGAIN;
59232
59233 pipe_unlock(ipipe);
59234diff --git a/fs/stat.c b/fs/stat.c
59235index 04ce1ac..a13dd1e 100644
59236--- a/fs/stat.c
59237+++ b/fs/stat.c
59238@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
59239 stat->gid = inode->i_gid;
59240 stat->rdev = inode->i_rdev;
59241 stat->size = i_size_read(inode);
59242- stat->atime = inode->i_atime;
59243- stat->mtime = inode->i_mtime;
59244+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
59245+ stat->atime = inode->i_ctime;
59246+ stat->mtime = inode->i_ctime;
59247+ } else {
59248+ stat->atime = inode->i_atime;
59249+ stat->mtime = inode->i_mtime;
59250+ }
59251 stat->ctime = inode->i_ctime;
59252 stat->blksize = (1 << inode->i_blkbits);
59253 stat->blocks = inode->i_blocks;
59254@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
59255 if (retval)
59256 return retval;
59257
59258- if (inode->i_op->getattr)
59259- return inode->i_op->getattr(path->mnt, path->dentry, stat);
59260+ if (inode->i_op->getattr) {
59261+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
59262+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
59263+ stat->atime = stat->ctime;
59264+ stat->mtime = stat->ctime;
59265+ }
59266+ return retval;
59267+ }
59268
59269 generic_fillattr(inode, stat);
59270 return 0;
59271diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
59272index 15c68f9..36a8b3e 100644
59273--- a/fs/sysfs/bin.c
59274+++ b/fs/sysfs/bin.c
59275@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
59276 return ret;
59277 }
59278
59279-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
59280- void *buf, int len, int write)
59281+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
59282+ void *buf, size_t len, int write)
59283 {
59284 struct file *file = vma->vm_file;
59285 struct bin_buffer *bb = file->private_data;
59286 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
59287- int ret;
59288+ ssize_t ret;
59289
59290 if (!bb->vm_ops)
59291 return -EINVAL;
59292diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
59293index e8e0e71..79c28ac5 100644
59294--- a/fs/sysfs/dir.c
59295+++ b/fs/sysfs/dir.c
59296@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
59297 *
59298 * Returns 31 bit hash of ns + name (so it fits in an off_t )
59299 */
59300-static unsigned int sysfs_name_hash(const void *ns, const char *name)
59301+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
59302 {
59303 unsigned long hash = init_name_hash();
59304 unsigned int len = strlen(name);
59305@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
59306 struct sysfs_dirent *sd;
59307 int rc;
59308
59309+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
59310+ const char *parent_name = parent_sd->s_name;
59311+
59312+ mode = S_IFDIR | S_IRWXU;
59313+
59314+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
59315+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
59316+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
59317+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
59318+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
59319+#endif
59320+
59321 /* allocate */
59322 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
59323 if (!sd)
59324diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
59325index 602f56d..6853db8 100644
59326--- a/fs/sysfs/file.c
59327+++ b/fs/sysfs/file.c
59328@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
59329
59330 struct sysfs_open_dirent {
59331 atomic_t refcnt;
59332- atomic_t event;
59333+ atomic_unchecked_t event;
59334 wait_queue_head_t poll;
59335 struct list_head buffers; /* goes through sysfs_buffer.list */
59336 };
59337@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
59338 if (!sysfs_get_active(attr_sd))
59339 return -ENODEV;
59340
59341- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
59342+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
59343 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
59344
59345 sysfs_put_active(attr_sd);
59346@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
59347 return -ENOMEM;
59348
59349 atomic_set(&new_od->refcnt, 0);
59350- atomic_set(&new_od->event, 1);
59351+ atomic_set_unchecked(&new_od->event, 1);
59352 init_waitqueue_head(&new_od->poll);
59353 INIT_LIST_HEAD(&new_od->buffers);
59354 goto retry;
59355@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
59356
59357 sysfs_put_active(attr_sd);
59358
59359- if (buffer->event != atomic_read(&od->event))
59360+ if (buffer->event != atomic_read_unchecked(&od->event))
59361 goto trigger;
59362
59363 return DEFAULT_POLLMASK;
59364@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
59365
59366 od = sd->s_attr.open;
59367 if (od) {
59368- atomic_inc(&od->event);
59369+ atomic_inc_unchecked(&od->event);
59370 wake_up_interruptible(&od->poll);
59371 }
59372
59373diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
59374index 8c940df..25b733e 100644
59375--- a/fs/sysfs/symlink.c
59376+++ b/fs/sysfs/symlink.c
59377@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59378
59379 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
59380 {
59381- char *page = nd_get_link(nd);
59382+ const char *page = nd_get_link(nd);
59383 if (!IS_ERR(page))
59384 free_page((unsigned long)page);
59385 }
59386diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
59387index 69d4889..a810bd4 100644
59388--- a/fs/sysv/sysv.h
59389+++ b/fs/sysv/sysv.h
59390@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
59391 #endif
59392 }
59393
59394-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
59395+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
59396 {
59397 if (sbi->s_bytesex == BYTESEX_PDP)
59398 return PDP_swab((__force __u32)n);
59399diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
59400index e18b988..f1d4ad0f 100644
59401--- a/fs/ubifs/io.c
59402+++ b/fs/ubifs/io.c
59403@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
59404 return err;
59405 }
59406
59407-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
59408+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
59409 {
59410 int err;
59411
59412diff --git a/fs/udf/misc.c b/fs/udf/misc.c
59413index c175b4d..8f36a16 100644
59414--- a/fs/udf/misc.c
59415+++ b/fs/udf/misc.c
59416@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
59417
59418 u8 udf_tag_checksum(const struct tag *t)
59419 {
59420- u8 *data = (u8 *)t;
59421+ const u8 *data = (const u8 *)t;
59422 u8 checksum = 0;
59423 int i;
59424 for (i = 0; i < sizeof(struct tag); ++i)
59425diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
59426index 8d974c4..b82f6ec 100644
59427--- a/fs/ufs/swab.h
59428+++ b/fs/ufs/swab.h
59429@@ -22,7 +22,7 @@ enum {
59430 BYTESEX_BE
59431 };
59432
59433-static inline u64
59434+static inline u64 __intentional_overflow(-1)
59435 fs64_to_cpu(struct super_block *sbp, __fs64 n)
59436 {
59437 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
59438@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
59439 return (__force __fs64)cpu_to_be64(n);
59440 }
59441
59442-static inline u32
59443+static inline u32 __intentional_overflow(-1)
59444 fs32_to_cpu(struct super_block *sbp, __fs32 n)
59445 {
59446 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
59447diff --git a/fs/utimes.c b/fs/utimes.c
59448index f4fb7ec..3fe03c0 100644
59449--- a/fs/utimes.c
59450+++ b/fs/utimes.c
59451@@ -1,6 +1,7 @@
59452 #include <linux/compiler.h>
59453 #include <linux/file.h>
59454 #include <linux/fs.h>
59455+#include <linux/security.h>
59456 #include <linux/linkage.h>
59457 #include <linux/mount.h>
59458 #include <linux/namei.h>
59459@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
59460 goto mnt_drop_write_and_out;
59461 }
59462 }
59463+
59464+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
59465+ error = -EACCES;
59466+ goto mnt_drop_write_and_out;
59467+ }
59468+
59469 mutex_lock(&inode->i_mutex);
59470 error = notify_change(path->dentry, &newattrs);
59471 mutex_unlock(&inode->i_mutex);
59472diff --git a/fs/xattr.c b/fs/xattr.c
59473index 3377dff..4d074d9 100644
59474--- a/fs/xattr.c
59475+++ b/fs/xattr.c
59476@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
59477 return rc;
59478 }
59479
59480+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59481+ssize_t
59482+pax_getxattr(struct dentry *dentry, void *value, size_t size)
59483+{
59484+ struct inode *inode = dentry->d_inode;
59485+ ssize_t error;
59486+
59487+ error = inode_permission(inode, MAY_EXEC);
59488+ if (error)
59489+ return error;
59490+
59491+ if (inode->i_op->getxattr)
59492+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
59493+ else
59494+ error = -EOPNOTSUPP;
59495+
59496+ return error;
59497+}
59498+EXPORT_SYMBOL(pax_getxattr);
59499+#endif
59500+
59501 ssize_t
59502 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
59503 {
59504@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
59505 * Extended attribute SET operations
59506 */
59507 static long
59508-setxattr(struct dentry *d, const char __user *name, const void __user *value,
59509+setxattr(struct path *path, const char __user *name, const void __user *value,
59510 size_t size, int flags)
59511 {
59512 int error;
59513@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
59514 posix_acl_fix_xattr_from_user(kvalue, size);
59515 }
59516
59517- error = vfs_setxattr(d, kname, kvalue, size, flags);
59518+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
59519+ error = -EACCES;
59520+ goto out;
59521+ }
59522+
59523+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
59524 out:
59525 if (vvalue)
59526 vfree(vvalue);
59527@@ -377,7 +403,7 @@ retry:
59528 return error;
59529 error = mnt_want_write(path.mnt);
59530 if (!error) {
59531- error = setxattr(path.dentry, name, value, size, flags);
59532+ error = setxattr(&path, name, value, size, flags);
59533 mnt_drop_write(path.mnt);
59534 }
59535 path_put(&path);
59536@@ -401,7 +427,7 @@ retry:
59537 return error;
59538 error = mnt_want_write(path.mnt);
59539 if (!error) {
59540- error = setxattr(path.dentry, name, value, size, flags);
59541+ error = setxattr(&path, name, value, size, flags);
59542 mnt_drop_write(path.mnt);
59543 }
59544 path_put(&path);
59545@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
59546 const void __user *,value, size_t, size, int, flags)
59547 {
59548 struct fd f = fdget(fd);
59549- struct dentry *dentry;
59550 int error = -EBADF;
59551
59552 if (!f.file)
59553 return error;
59554- dentry = f.file->f_path.dentry;
59555- audit_inode(NULL, dentry, 0);
59556+ audit_inode(NULL, f.file->f_path.dentry, 0);
59557 error = mnt_want_write_file(f.file);
59558 if (!error) {
59559- error = setxattr(dentry, name, value, size, flags);
59560+ error = setxattr(&f.file->f_path, name, value, size, flags);
59561 mnt_drop_write_file(f.file);
59562 }
59563 fdput(f);
59564diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
59565index 9fbea87..6b19972 100644
59566--- a/fs/xattr_acl.c
59567+++ b/fs/xattr_acl.c
59568@@ -76,8 +76,8 @@ struct posix_acl *
59569 posix_acl_from_xattr(struct user_namespace *user_ns,
59570 const void *value, size_t size)
59571 {
59572- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
59573- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
59574+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
59575+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
59576 int count;
59577 struct posix_acl *acl;
59578 struct posix_acl_entry *acl_e;
59579diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
59580index 8904284..ee0e14b 100644
59581--- a/fs/xfs/xfs_bmap.c
59582+++ b/fs/xfs/xfs_bmap.c
59583@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
59584
59585 #else
59586 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
59587-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
59588+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
59589 #endif /* DEBUG */
59590
59591 /*
59592diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
59593index 6157424..ac98f6d 100644
59594--- a/fs/xfs/xfs_dir2_sf.c
59595+++ b/fs/xfs/xfs_dir2_sf.c
59596@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
59597 }
59598
59599 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
59600- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
59601+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
59602+ char name[sfep->namelen];
59603+ memcpy(name, sfep->name, sfep->namelen);
59604+ if (filldir(dirent, name, sfep->namelen,
59605+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
59606+ *offset = off & 0x7fffffff;
59607+ return 0;
59608+ }
59609+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
59610 off & 0x7fffffff, ino, DT_UNKNOWN)) {
59611 *offset = off & 0x7fffffff;
59612 return 0;
59613diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
59614index 5e99968..45bd327 100644
59615--- a/fs/xfs/xfs_ioctl.c
59616+++ b/fs/xfs/xfs_ioctl.c
59617@@ -127,7 +127,7 @@ xfs_find_handle(
59618 }
59619
59620 error = -EFAULT;
59621- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
59622+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
59623 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
59624 goto out_put;
59625
59626diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
59627index ca9ecaa..60100c7 100644
59628--- a/fs/xfs/xfs_iops.c
59629+++ b/fs/xfs/xfs_iops.c
59630@@ -395,7 +395,7 @@ xfs_vn_put_link(
59631 struct nameidata *nd,
59632 void *p)
59633 {
59634- char *s = nd_get_link(nd);
59635+ const char *s = nd_get_link(nd);
59636
59637 if (!IS_ERR(s))
59638 kfree(s);
59639diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
59640new file mode 100644
59641index 0000000..712a85d
59642--- /dev/null
59643+++ b/grsecurity/Kconfig
59644@@ -0,0 +1,1043 @@
59645+#
59646+# grecurity configuration
59647+#
59648+menu "Memory Protections"
59649+depends on GRKERNSEC
59650+
59651+config GRKERNSEC_KMEM
59652+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
59653+ default y if GRKERNSEC_CONFIG_AUTO
59654+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
59655+ help
59656+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
59657+ be written to or read from to modify or leak the contents of the running
59658+ kernel. /dev/port will also not be allowed to be opened and support
59659+ for /dev/cpu/*/msr will be removed. If you have module
59660+ support disabled, enabling this will close up five ways that are
59661+ currently used to insert malicious code into the running kernel.
59662+
59663+ Even with all these features enabled, we still highly recommend that
59664+ you use the RBAC system, as it is still possible for an attacker to
59665+ modify the running kernel through privileged I/O granted by ioperm/iopl.
59666+
59667+ If you are not using XFree86, you may be able to stop this additional
59668+ case by enabling the 'Disable privileged I/O' option. Though nothing
59669+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
59670+ but only to video memory, which is the only writing we allow in this
59671+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
59672+ not be allowed to mprotect it with PROT_WRITE later.
59673+ Enabling this feature will prevent the "cpupower" and "powertop" tools
59674+ from working.
59675+
59676+ It is highly recommended that you say Y here if you meet all the
59677+ conditions above.
59678+
59679+config GRKERNSEC_VM86
59680+ bool "Restrict VM86 mode"
59681+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
59682+ depends on X86_32
59683+
59684+ help
59685+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
59686+ make use of a special execution mode on 32bit x86 processors called
59687+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
59688+ video cards and will still work with this option enabled. The purpose
59689+ of the option is to prevent exploitation of emulation errors in
59690+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
59691+ Nearly all users should be able to enable this option.
59692+
59693+config GRKERNSEC_IO
59694+ bool "Disable privileged I/O"
59695+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
59696+ depends on X86
59697+ select RTC_CLASS
59698+ select RTC_INTF_DEV
59699+ select RTC_DRV_CMOS
59700+
59701+ help
59702+ If you say Y here, all ioperm and iopl calls will return an error.
59703+ Ioperm and iopl can be used to modify the running kernel.
59704+ Unfortunately, some programs need this access to operate properly,
59705+ the most notable of which are XFree86 and hwclock. hwclock can be
59706+ remedied by having RTC support in the kernel, so real-time
59707+ clock support is enabled if this option is enabled, to ensure
59708+ that hwclock operates correctly. XFree86 still will not
59709+ operate correctly with this option enabled, so DO NOT CHOOSE Y
59710+ IF YOU USE XFree86. If you use XFree86 and you still want to
59711+ protect your kernel against modification, use the RBAC system.
59712+
59713+config GRKERNSEC_JIT_HARDEN
59714+ bool "Harden BPF JIT against spray attacks"
59715+ default y if GRKERNSEC_CONFIG_AUTO
59716+ depends on BPF_JIT
59717+ help
59718+ If you say Y here, the native code generated by the kernel's Berkeley
59719+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
59720+ attacks that attempt to fit attacker-beneficial instructions in
59721+ 32bit immediate fields of JIT-generated native instructions. The
59722+ attacker will generally aim to cause an unintended instruction sequence
59723+ of JIT-generated native code to execute by jumping into the middle of
59724+ a generated instruction. This feature effectively randomizes the 32bit
59725+ immediate constants present in the generated code to thwart such attacks.
59726+
59727+ If you're using KERNEXEC, it's recommended that you enable this option
59728+ to supplement the hardening of the kernel.
59729+
59730+config GRKERNSEC_PERF_HARDEN
59731+ bool "Disable unprivileged PERF_EVENTS usage by default"
59732+ default y if GRKERNSEC_CONFIG_AUTO
59733+ depends on PERF_EVENTS
59734+ help
59735+ If you say Y here, the range of acceptable values for the
59736+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
59737+ default to a new value: 3. When the sysctl is set to this value, no
59738+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
59739+
59740+ Though PERF_EVENTS can be used legitimately for performance monitoring
59741+ and low-level application profiling, it is forced on regardless of
59742+ configuration, has been at fault for several vulnerabilities, and
59743+ creates new opportunities for side channels and other information leaks.
59744+
59745+ This feature puts PERF_EVENTS into a secure default state and permits
59746+ the administrator to change out of it temporarily if unprivileged
59747+ application profiling is needed.
59748+
59749+config GRKERNSEC_RAND_THREADSTACK
59750+ bool "Insert random gaps between thread stacks"
59751+ default y if GRKERNSEC_CONFIG_AUTO
59752+ depends on PAX_RANDMMAP && !PPC
59753+ help
59754+ If you say Y here, a random-sized gap will be enforced between allocated
59755+ thread stacks. Glibc's NPTL and other threading libraries that
59756+ pass MAP_STACK to the kernel for thread stack allocation are supported.
59757+ The implementation currently provides 8 bits of entropy for the gap.
59758+
59759+ Many distributions do not compile threaded remote services with the
59760+ -fstack-check argument to GCC, causing the variable-sized stack-based
59761+ allocator, alloca(), to not probe the stack on allocation. This
59762+ permits an unbounded alloca() to skip over any guard page and potentially
59763+ modify another thread's stack reliably. An enforced random gap
59764+ reduces the reliability of such an attack and increases the chance
59765+ that such a read/write to another thread's stack instead lands in
59766+ an unmapped area, causing a crash and triggering grsecurity's
59767+ anti-bruteforcing logic.
59768+
59769+config GRKERNSEC_PROC_MEMMAP
59770+ bool "Harden ASLR against information leaks and entropy reduction"
59771+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
59772+ depends on PAX_NOEXEC || PAX_ASLR
59773+ help
59774+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
59775+ give no information about the addresses of its mappings if
59776+ PaX features that rely on random addresses are enabled on the task.
59777+ In addition to sanitizing this information and disabling other
59778+ dangerous sources of information, this option causes reads of sensitive
59779+ /proc/<pid> entries where the file descriptor was opened in a different
59780+ task than the one performing the read. Such attempts are logged.
59781+ This option also limits argv/env strings for suid/sgid binaries
59782+ to 512KB to prevent a complete exhaustion of the stack entropy provided
59783+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
59784+ binaries to prevent alternative mmap layouts from being abused.
59785+
59786+ If you use PaX it is essential that you say Y here as it closes up
59787+ several holes that make full ASLR useless locally.
59788+
59789+config GRKERNSEC_BRUTE
59790+ bool "Deter exploit bruteforcing"
59791+ default y if GRKERNSEC_CONFIG_AUTO
59792+ help
59793+ If you say Y here, attempts to bruteforce exploits against forking
59794+ daemons such as apache or sshd, as well as against suid/sgid binaries
59795+ will be deterred. When a child of a forking daemon is killed by PaX
59796+ or crashes due to an illegal instruction or other suspicious signal,
59797+ the parent process will be delayed 30 seconds upon every subsequent
59798+ fork until the administrator is able to assess the situation and
59799+ restart the daemon.
59800+ In the suid/sgid case, the attempt is logged, the user has all their
59801+ existing instances of the suid/sgid binary terminated and will
59802+ be unable to execute any suid/sgid binaries for 15 minutes.
59803+
59804+ It is recommended that you also enable signal logging in the auditing
59805+ section so that logs are generated when a process triggers a suspicious
59806+ signal.
59807+ If the sysctl option is enabled, a sysctl option with name
59808+ "deter_bruteforce" is created.
59809+
59810+
59811+config GRKERNSEC_MODHARDEN
59812+ bool "Harden module auto-loading"
59813+ default y if GRKERNSEC_CONFIG_AUTO
59814+ depends on MODULES
59815+ help
59816+ If you say Y here, module auto-loading in response to use of some
59817+ feature implemented by an unloaded module will be restricted to
59818+ root users. Enabling this option helps defend against attacks
59819+ by unprivileged users who abuse the auto-loading behavior to
59820+ cause a vulnerable module to load that is then exploited.
59821+
59822+ If this option prevents a legitimate use of auto-loading for a
59823+ non-root user, the administrator can execute modprobe manually
59824+ with the exact name of the module mentioned in the alert log.
59825+ Alternatively, the administrator can add the module to the list
59826+ of modules loaded at boot by modifying init scripts.
59827+
59828+ Modification of init scripts will most likely be needed on
59829+ Ubuntu servers with encrypted home directory support enabled,
59830+ as the first non-root user logging in will cause the ecb(aes),
59831+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
59832+
59833+config GRKERNSEC_HIDESYM
59834+ bool "Hide kernel symbols"
59835+ default y if GRKERNSEC_CONFIG_AUTO
59836+ select PAX_USERCOPY_SLABS
59837+ help
59838+ If you say Y here, getting information on loaded modules, and
59839+ displaying all kernel symbols through a syscall will be restricted
59840+ to users with CAP_SYS_MODULE. For software compatibility reasons,
59841+ /proc/kallsyms will be restricted to the root user. The RBAC
59842+ system can hide that entry even from root.
59843+
59844+ This option also prevents leaking of kernel addresses through
59845+ several /proc entries.
59846+
59847+ Note that this option is only effective provided the following
59848+ conditions are met:
59849+ 1) The kernel using grsecurity is not precompiled by some distribution
59850+ 2) You have also enabled GRKERNSEC_DMESG
59851+ 3) You are using the RBAC system and hiding other files such as your
59852+ kernel image and System.map. Alternatively, enabling this option
59853+ causes the permissions on /boot, /lib/modules, and the kernel
59854+ source directory to change at compile time to prevent
59855+ reading by non-root users.
59856+ If the above conditions are met, this option will aid in providing a
59857+ useful protection against local kernel exploitation of overflows
59858+ and arbitrary read/write vulnerabilities.
59859+
59860+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
59861+ in addition to this feature.
59862+
59863+config GRKERNSEC_KERN_LOCKOUT
59864+ bool "Active kernel exploit response"
59865+ default y if GRKERNSEC_CONFIG_AUTO
59866+ depends on X86 || ARM || PPC || SPARC
59867+ help
59868+ If you say Y here, when a PaX alert is triggered due to suspicious
59869+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
59870+ or an OOPS occurs due to bad memory accesses, instead of just
59871+ terminating the offending process (and potentially allowing
59872+ a subsequent exploit from the same user), we will take one of two
59873+ actions:
59874+ If the user was root, we will panic the system
59875+ If the user was non-root, we will log the attempt, terminate
59876+ all processes owned by the user, then prevent them from creating
59877+ any new processes until the system is restarted
59878+ This deters repeated kernel exploitation/bruteforcing attempts
59879+ and is useful for later forensics.
59880+
59881+endmenu
59882+menu "Role Based Access Control Options"
59883+depends on GRKERNSEC
59884+
59885+config GRKERNSEC_RBAC_DEBUG
59886+ bool
59887+
59888+config GRKERNSEC_NO_RBAC
59889+ bool "Disable RBAC system"
59890+ help
59891+ If you say Y here, the /dev/grsec device will be removed from the kernel,
59892+ preventing the RBAC system from being enabled. You should only say Y
59893+ here if you have no intention of using the RBAC system, so as to prevent
59894+ an attacker with root access from misusing the RBAC system to hide files
59895+ and processes when loadable module support and /dev/[k]mem have been
59896+ locked down.
59897+
59898+config GRKERNSEC_ACL_HIDEKERN
59899+ bool "Hide kernel processes"
59900+ help
59901+ If you say Y here, all kernel threads will be hidden to all
59902+ processes but those whose subject has the "view hidden processes"
59903+ flag.
59904+
59905+config GRKERNSEC_ACL_MAXTRIES
59906+ int "Maximum tries before password lockout"
59907+ default 3
59908+ help
59909+ This option enforces the maximum number of times a user can attempt
59910+ to authorize themselves with the grsecurity RBAC system before being
59911+ denied the ability to attempt authorization again for a specified time.
59912+ The lower the number, the harder it will be to brute-force a password.
59913+
59914+config GRKERNSEC_ACL_TIMEOUT
59915+ int "Time to wait after max password tries, in seconds"
59916+ default 30
59917+ help
59918+ This option specifies the time the user must wait after attempting to
59919+ authorize to the RBAC system with the maximum number of invalid
59920+ passwords. The higher the number, the harder it will be to brute-force
59921+ a password.
59922+
59923+endmenu
59924+menu "Filesystem Protections"
59925+depends on GRKERNSEC
59926+
59927+config GRKERNSEC_PROC
59928+ bool "Proc restrictions"
59929+ default y if GRKERNSEC_CONFIG_AUTO
59930+ help
59931+ If you say Y here, the permissions of the /proc filesystem
59932+ will be altered to enhance system security and privacy. You MUST
59933+ choose either a user only restriction or a user and group restriction.
59934+ Depending upon the option you choose, you can either restrict users to
59935+ see only the processes they themselves run, or choose a group that can
59936+ view all processes and files normally restricted to root if you choose
59937+ the "restrict to user only" option. NOTE: If you're running identd or
59938+ ntpd as a non-root user, you will have to run it as the group you
59939+ specify here.
59940+
59941+config GRKERNSEC_PROC_USER
59942+ bool "Restrict /proc to user only"
59943+ depends on GRKERNSEC_PROC
59944+ help
59945+ If you say Y here, non-root users will only be able to view their own
59946+ processes, and restricts them from viewing network-related information,
59947+ and viewing kernel symbol and module information.
59948+
59949+config GRKERNSEC_PROC_USERGROUP
59950+ bool "Allow special group"
59951+ default y if GRKERNSEC_CONFIG_AUTO
59952+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
59953+ help
59954+ If you say Y here, you will be able to select a group that will be
59955+ able to view all processes and network-related information. If you've
59956+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
59957+ remain hidden. This option is useful if you want to run identd as
59958+ a non-root user. The group you select may also be chosen at boot time
59959+ via "grsec_proc_gid=" on the kernel commandline.
59960+
59961+config GRKERNSEC_PROC_GID
59962+ int "GID for special group"
59963+ depends on GRKERNSEC_PROC_USERGROUP
59964+ default 1001
59965+
59966+config GRKERNSEC_PROC_ADD
59967+ bool "Additional restrictions"
59968+ default y if GRKERNSEC_CONFIG_AUTO
59969+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
59970+ help
59971+ If you say Y here, additional restrictions will be placed on
59972+ /proc that keep normal users from viewing device information and
59973+ slabinfo information that could be useful for exploits.
59974+
59975+config GRKERNSEC_LINK
59976+ bool "Linking restrictions"
59977+ default y if GRKERNSEC_CONFIG_AUTO
59978+ help
59979+ If you say Y here, /tmp race exploits will be prevented, since users
59980+ will no longer be able to follow symlinks owned by other users in
59981+ world-writable +t directories (e.g. /tmp), unless the owner of the
59982+ symlink is the owner of the directory. users will also not be
59983+ able to hardlink to files they do not own. If the sysctl option is
59984+ enabled, a sysctl option with name "linking_restrictions" is created.
59985+
59986+config GRKERNSEC_SYMLINKOWN
59987+ bool "Kernel-enforced SymlinksIfOwnerMatch"
59988+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
59989+ help
59990+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
59991+ that prevents it from being used as a security feature. As Apache
59992+ verifies the symlink by performing a stat() against the target of
59993+ the symlink before it is followed, an attacker can setup a symlink
59994+ to point to a same-owned file, then replace the symlink with one
59995+ that targets another user's file just after Apache "validates" the
59996+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
59997+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
59998+ will be in place for the group you specify. If the sysctl option
59999+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
60000+ created.
60001+
60002+config GRKERNSEC_SYMLINKOWN_GID
60003+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
60004+ depends on GRKERNSEC_SYMLINKOWN
60005+ default 1006
60006+ help
60007+ Setting this GID determines what group kernel-enforced
60008+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
60009+ is enabled, a sysctl option with name "symlinkown_gid" is created.
60010+
60011+config GRKERNSEC_FIFO
60012+ bool "FIFO restrictions"
60013+ default y if GRKERNSEC_CONFIG_AUTO
60014+ help
60015+ If you say Y here, users will not be able to write to FIFOs they don't
60016+ own in world-writable +t directories (e.g. /tmp), unless the owner of
60017+ the FIFO is the same owner of the directory it's held in. If the sysctl
60018+ option is enabled, a sysctl option with name "fifo_restrictions" is
60019+ created.
60020+
60021+config GRKERNSEC_SYSFS_RESTRICT
60022+ bool "Sysfs/debugfs restriction"
60023+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60024+ depends on SYSFS
60025+ help
60026+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60027+ any filesystem normally mounted under it (e.g. debugfs) will be
60028+ mostly accessible only by root. These filesystems generally provide access
60029+ to hardware and debug information that isn't appropriate for unprivileged
60030+ users of the system. Sysfs and debugfs have also become a large source
60031+ of new vulnerabilities, ranging from infoleaks to local compromise.
60032+ There has been very little oversight with an eye toward security involved
60033+ in adding new exporters of information to these filesystems, so their
60034+ use is discouraged.
60035+ For reasons of compatibility, a few directories have been whitelisted
60036+ for access by non-root users:
60037+ /sys/fs/selinux
60038+ /sys/fs/fuse
60039+ /sys/devices/system/cpu
60040+
60041+config GRKERNSEC_ROFS
60042+ bool "Runtime read-only mount protection"
60043+ help
60044+ If you say Y here, a sysctl option with name "romount_protect" will
60045+ be created. By setting this option to 1 at runtime, filesystems
60046+ will be protected in the following ways:
60047+ * No new writable mounts will be allowed
60048+ * Existing read-only mounts won't be able to be remounted read/write
60049+ * Write operations will be denied on all block devices
60050+ This option acts independently of grsec_lock: once it is set to 1,
60051+ it cannot be turned off. Therefore, please be mindful of the resulting
60052+ behavior if this option is enabled in an init script on a read-only
60053+ filesystem. This feature is mainly intended for secure embedded systems.
60054+
60055+config GRKERNSEC_DEVICE_SIDECHANNEL
60056+ bool "Eliminate stat/notify-based device sidechannels"
60057+ default y if GRKERNSEC_CONFIG_AUTO
60058+ help
60059+ If you say Y here, timing analyses on block or character
60060+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
60061+ will be thwarted for unprivileged users. If a process without
60062+ CAP_MKNOD stats such a device, the last access and last modify times
60063+ will match the device's create time. No access or modify events
60064+ will be triggered through inotify/dnotify/fanotify for such devices.
60065+ This feature will prevent attacks that may at a minimum
60066+ allow an attacker to determine the administrator's password length.
60067+
60068+config GRKERNSEC_CHROOT
60069+ bool "Chroot jail restrictions"
60070+ default y if GRKERNSEC_CONFIG_AUTO
60071+ help
60072+ If you say Y here, you will be able to choose several options that will
60073+ make breaking out of a chrooted jail much more difficult. If you
60074+ encounter no software incompatibilities with the following options, it
60075+ is recommended that you enable each one.
60076+
60077+config GRKERNSEC_CHROOT_MOUNT
60078+ bool "Deny mounts"
60079+ default y if GRKERNSEC_CONFIG_AUTO
60080+ depends on GRKERNSEC_CHROOT
60081+ help
60082+ If you say Y here, processes inside a chroot will not be able to
60083+ mount or remount filesystems. If the sysctl option is enabled, a
60084+ sysctl option with name "chroot_deny_mount" is created.
60085+
60086+config GRKERNSEC_CHROOT_DOUBLE
60087+ bool "Deny double-chroots"
60088+ default y if GRKERNSEC_CONFIG_AUTO
60089+ depends on GRKERNSEC_CHROOT
60090+ help
60091+ If you say Y here, processes inside a chroot will not be able to chroot
60092+ again outside the chroot. This is a widely used method of breaking
60093+ out of a chroot jail and should not be allowed. If the sysctl
60094+ option is enabled, a sysctl option with name
60095+ "chroot_deny_chroot" is created.
60096+
60097+config GRKERNSEC_CHROOT_PIVOT
60098+ bool "Deny pivot_root in chroot"
60099+ default y if GRKERNSEC_CONFIG_AUTO
60100+ depends on GRKERNSEC_CHROOT
60101+ help
60102+ If you say Y here, processes inside a chroot will not be able to use
60103+ a function called pivot_root() that was introduced in Linux 2.3.41. It
60104+ works similar to chroot in that it changes the root filesystem. This
60105+ function could be misused in a chrooted process to attempt to break out
60106+ of the chroot, and therefore should not be allowed. If the sysctl
60107+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
60108+ created.
60109+
60110+config GRKERNSEC_CHROOT_CHDIR
60111+ bool "Enforce chdir(\"/\") on all chroots"
60112+ default y if GRKERNSEC_CONFIG_AUTO
60113+ depends on GRKERNSEC_CHROOT
60114+ help
60115+ If you say Y here, the current working directory of all newly-chrooted
60116+ applications will be set to the the root directory of the chroot.
60117+ The man page on chroot(2) states:
60118+ Note that this call does not change the current working
60119+ directory, so that `.' can be outside the tree rooted at
60120+ `/'. In particular, the super-user can escape from a
60121+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60122+
60123+ It is recommended that you say Y here, since it's not known to break
60124+ any software. If the sysctl option is enabled, a sysctl option with
60125+ name "chroot_enforce_chdir" is created.
60126+
60127+config GRKERNSEC_CHROOT_CHMOD
60128+ bool "Deny (f)chmod +s"
60129+ default y if GRKERNSEC_CONFIG_AUTO
60130+ depends on GRKERNSEC_CHROOT
60131+ help
60132+ If you say Y here, processes inside a chroot will not be able to chmod
60133+ or fchmod files to make them have suid or sgid bits. This protects
60134+ against another published method of breaking a chroot. If the sysctl
60135+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
60136+ created.
60137+
60138+config GRKERNSEC_CHROOT_FCHDIR
60139+ bool "Deny fchdir out of chroot"
60140+ default y if GRKERNSEC_CONFIG_AUTO
60141+ depends on GRKERNSEC_CHROOT
60142+ help
60143+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
60144+ to a file descriptor of the chrooting process that points to a directory
60145+ outside the filesystem will be stopped. If the sysctl option
60146+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60147+
60148+config GRKERNSEC_CHROOT_MKNOD
60149+ bool "Deny mknod"
60150+ default y if GRKERNSEC_CONFIG_AUTO
60151+ depends on GRKERNSEC_CHROOT
60152+ help
60153+ If you say Y here, processes inside a chroot will not be allowed to
60154+ mknod. The problem with using mknod inside a chroot is that it
60155+ would allow an attacker to create a device entry that is the same
60156+ as one on the physical root of your system, which could range from
60157+ anything from the console device to a device for your harddrive (which
60158+ they could then use to wipe the drive or steal data). It is recommended
60159+ that you say Y here, unless you run into software incompatibilities.
60160+ If the sysctl option is enabled, a sysctl option with name
60161+ "chroot_deny_mknod" is created.
60162+
60163+config GRKERNSEC_CHROOT_SHMAT
60164+ bool "Deny shmat() out of chroot"
60165+ default y if GRKERNSEC_CONFIG_AUTO
60166+ depends on GRKERNSEC_CHROOT
60167+ help
60168+ If you say Y here, processes inside a chroot will not be able to attach
60169+ to shared memory segments that were created outside of the chroot jail.
60170+ It is recommended that you say Y here. If the sysctl option is enabled,
60171+ a sysctl option with name "chroot_deny_shmat" is created.
60172+
60173+config GRKERNSEC_CHROOT_UNIX
60174+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
60175+ default y if GRKERNSEC_CONFIG_AUTO
60176+ depends on GRKERNSEC_CHROOT
60177+ help
60178+ If you say Y here, processes inside a chroot will not be able to
60179+ connect to abstract (meaning not belonging to a filesystem) Unix
60180+ domain sockets that were bound outside of a chroot. It is recommended
60181+ that you say Y here. If the sysctl option is enabled, a sysctl option
60182+ with name "chroot_deny_unix" is created.
60183+
60184+config GRKERNSEC_CHROOT_FINDTASK
60185+ bool "Protect outside processes"
60186+ default y if GRKERNSEC_CONFIG_AUTO
60187+ depends on GRKERNSEC_CHROOT
60188+ help
60189+ If you say Y here, processes inside a chroot will not be able to
60190+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60191+ getsid, or view any process outside of the chroot. If the sysctl
60192+ option is enabled, a sysctl option with name "chroot_findtask" is
60193+ created.
60194+
60195+config GRKERNSEC_CHROOT_NICE
60196+ bool "Restrict priority changes"
60197+ default y if GRKERNSEC_CONFIG_AUTO
60198+ depends on GRKERNSEC_CHROOT
60199+ help
60200+ If you say Y here, processes inside a chroot will not be able to raise
60201+ the priority of processes in the chroot, or alter the priority of
60202+ processes outside the chroot. This provides more security than simply
60203+ removing CAP_SYS_NICE from the process' capability set. If the
60204+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60205+ is created.
60206+
60207+config GRKERNSEC_CHROOT_SYSCTL
60208+ bool "Deny sysctl writes"
60209+ default y if GRKERNSEC_CONFIG_AUTO
60210+ depends on GRKERNSEC_CHROOT
60211+ help
60212+ If you say Y here, an attacker in a chroot will not be able to
60213+ write to sysctl entries, either by sysctl(2) or through a /proc
60214+ interface. It is strongly recommended that you say Y here. If the
60215+ sysctl option is enabled, a sysctl option with name
60216+ "chroot_deny_sysctl" is created.
60217+
60218+config GRKERNSEC_CHROOT_CAPS
60219+ bool "Capability restrictions"
60220+ default y if GRKERNSEC_CONFIG_AUTO
60221+ depends on GRKERNSEC_CHROOT
60222+ help
60223+ If you say Y here, the capabilities on all processes within a
60224+ chroot jail will be lowered to stop module insertion, raw i/o,
60225+ system and net admin tasks, rebooting the system, modifying immutable
60226+ files, modifying IPC owned by another, and changing the system time.
60227+ This is left an option because it can break some apps. Disable this
60228+ if your chrooted apps are having problems performing those kinds of
60229+ tasks. If the sysctl option is enabled, a sysctl option with
60230+ name "chroot_caps" is created.
60231+
60232+config GRKERNSEC_CHROOT_INITRD
60233+ bool "Exempt initrd tasks from restrictions"
60234+ default y if GRKERNSEC_CONFIG_AUTO
60235+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
60236+ help
60237+ If you say Y here, tasks started prior to init will be exempted from
60238+ grsecurity's chroot restrictions. This option is mainly meant to
60239+ resolve Plymouth's performing privileged operations unnecessarily
60240+ in a chroot.
60241+
60242+endmenu
60243+menu "Kernel Auditing"
60244+depends on GRKERNSEC
60245+
60246+config GRKERNSEC_AUDIT_GROUP
60247+ bool "Single group for auditing"
60248+ help
60249+ If you say Y here, the exec and chdir logging features will only operate
60250+ on a group you specify. This option is recommended if you only want to
60251+ watch certain users instead of having a large amount of logs from the
60252+ entire system. If the sysctl option is enabled, a sysctl option with
60253+ name "audit_group" is created.
60254+
60255+config GRKERNSEC_AUDIT_GID
60256+ int "GID for auditing"
60257+ depends on GRKERNSEC_AUDIT_GROUP
60258+ default 1007
60259+
60260+config GRKERNSEC_EXECLOG
60261+ bool "Exec logging"
60262+ help
60263+ If you say Y here, all execve() calls will be logged (since the
60264+ other exec*() calls are frontends to execve(), all execution
60265+ will be logged). Useful for shell-servers that like to keep track
60266+ of their users. If the sysctl option is enabled, a sysctl option with
60267+ name "exec_logging" is created.
60268+ WARNING: This option when enabled will produce a LOT of logs, especially
60269+ on an active system.
60270+
60271+config GRKERNSEC_RESLOG
60272+ bool "Resource logging"
60273+ default y if GRKERNSEC_CONFIG_AUTO
60274+ help
60275+ If you say Y here, all attempts to overstep resource limits will
60276+ be logged with the resource name, the requested size, and the current
60277+ limit. It is highly recommended that you say Y here. If the sysctl
60278+ option is enabled, a sysctl option with name "resource_logging" is
60279+ created. If the RBAC system is enabled, the sysctl value is ignored.
60280+
60281+config GRKERNSEC_CHROOT_EXECLOG
60282+ bool "Log execs within chroot"
60283+ help
60284+ If you say Y here, all executions inside a chroot jail will be logged
60285+ to syslog. This can cause a large amount of logs if certain
60286+ applications (eg. djb's daemontools) are installed on the system, and
60287+ is therefore left as an option. If the sysctl option is enabled, a
60288+ sysctl option with name "chroot_execlog" is created.
60289+
60290+config GRKERNSEC_AUDIT_PTRACE
60291+ bool "Ptrace logging"
60292+ help
60293+ If you say Y here, all attempts to attach to a process via ptrace
60294+ will be logged. If the sysctl option is enabled, a sysctl option
60295+ with name "audit_ptrace" is created.
60296+
60297+config GRKERNSEC_AUDIT_CHDIR
60298+ bool "Chdir logging"
60299+ help
60300+ If you say Y here, all chdir() calls will be logged. If the sysctl
60301+ option is enabled, a sysctl option with name "audit_chdir" is created.
60302+
60303+config GRKERNSEC_AUDIT_MOUNT
60304+ bool "(Un)Mount logging"
60305+ help
60306+ If you say Y here, all mounts and unmounts will be logged. If the
60307+ sysctl option is enabled, a sysctl option with name "audit_mount" is
60308+ created.
60309+
60310+config GRKERNSEC_SIGNAL
60311+ bool "Signal logging"
60312+ default y if GRKERNSEC_CONFIG_AUTO
60313+ help
60314+ If you say Y here, certain important signals will be logged, such as
60315+ SIGSEGV, which will as a result inform you of when a error in a program
60316+ occurred, which in some cases could mean a possible exploit attempt.
60317+ If the sysctl option is enabled, a sysctl option with name
60318+ "signal_logging" is created.
60319+
60320+config GRKERNSEC_FORKFAIL
60321+ bool "Fork failure logging"
60322+ help
60323+ If you say Y here, all failed fork() attempts will be logged.
60324+ This could suggest a fork bomb, or someone attempting to overstep
60325+ their process limit. If the sysctl option is enabled, a sysctl option
60326+ with name "forkfail_logging" is created.
60327+
60328+config GRKERNSEC_TIME
60329+ bool "Time change logging"
60330+ default y if GRKERNSEC_CONFIG_AUTO
60331+ help
60332+ If you say Y here, any changes of the system clock will be logged.
60333+ If the sysctl option is enabled, a sysctl option with name
60334+ "timechange_logging" is created.
60335+
60336+config GRKERNSEC_PROC_IPADDR
60337+ bool "/proc/<pid>/ipaddr support"
60338+ default y if GRKERNSEC_CONFIG_AUTO
60339+ help
60340+ If you say Y here, a new entry will be added to each /proc/<pid>
60341+ directory that contains the IP address of the person using the task.
60342+ The IP is carried across local TCP and AF_UNIX stream sockets.
60343+ This information can be useful for IDS/IPSes to perform remote response
60344+ to a local attack. The entry is readable by only the owner of the
60345+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60346+ the RBAC system), and thus does not create privacy concerns.
60347+
60348+config GRKERNSEC_RWXMAP_LOG
60349+ bool 'Denied RWX mmap/mprotect logging'
60350+ default y if GRKERNSEC_CONFIG_AUTO
60351+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60352+ help
60353+ If you say Y here, calls to mmap() and mprotect() with explicit
60354+ usage of PROT_WRITE and PROT_EXEC together will be logged when
60355+ denied by the PAX_MPROTECT feature. This feature will also
60356+ log other problematic scenarios that can occur when PAX_MPROTECT
60357+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
60358+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
60359+ is created.
60360+
60361+endmenu
60362+
60363+menu "Executable Protections"
60364+depends on GRKERNSEC
60365+
60366+config GRKERNSEC_DMESG
60367+ bool "Dmesg(8) restriction"
60368+ default y if GRKERNSEC_CONFIG_AUTO
60369+ help
60370+ If you say Y here, non-root users will not be able to use dmesg(8)
60371+ to view the contents of the kernel's circular log buffer.
60372+ The kernel's log buffer often contains kernel addresses and other
60373+ identifying information useful to an attacker in fingerprinting a
60374+ system for a targeted exploit.
60375+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
60376+ created.
60377+
60378+config GRKERNSEC_HARDEN_PTRACE
60379+ bool "Deter ptrace-based process snooping"
60380+ default y if GRKERNSEC_CONFIG_AUTO
60381+ help
60382+ If you say Y here, TTY sniffers and other malicious monitoring
60383+ programs implemented through ptrace will be defeated. If you
60384+ have been using the RBAC system, this option has already been
60385+ enabled for several years for all users, with the ability to make
60386+ fine-grained exceptions.
60387+
60388+ This option only affects the ability of non-root users to ptrace
60389+ processes that are not a descendent of the ptracing process.
60390+ This means that strace ./binary and gdb ./binary will still work,
60391+ but attaching to arbitrary processes will not. If the sysctl
60392+ option is enabled, a sysctl option with name "harden_ptrace" is
60393+ created.
60394+
60395+config GRKERNSEC_PTRACE_READEXEC
60396+ bool "Require read access to ptrace sensitive binaries"
60397+ default y if GRKERNSEC_CONFIG_AUTO
60398+ help
60399+ If you say Y here, unprivileged users will not be able to ptrace unreadable
60400+ binaries. This option is useful in environments that
60401+ remove the read bits (e.g. file mode 4711) from suid binaries to
60402+ prevent infoleaking of their contents. This option adds
60403+ consistency to the use of that file mode, as the binary could normally
60404+ be read out when run without privileges while ptracing.
60405+
60406+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
60407+ is created.
60408+
60409+config GRKERNSEC_SETXID
60410+ bool "Enforce consistent multithreaded privileges"
60411+ default y if GRKERNSEC_CONFIG_AUTO
60412+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
60413+ help
60414+ If you say Y here, a change from a root uid to a non-root uid
60415+ in a multithreaded application will cause the resulting uids,
60416+ gids, supplementary groups, and capabilities in that thread
60417+ to be propagated to the other threads of the process. In most
60418+ cases this is unnecessary, as glibc will emulate this behavior
60419+ on behalf of the application. Other libcs do not act in the
60420+ same way, allowing the other threads of the process to continue
60421+ running with root privileges. If the sysctl option is enabled,
60422+ a sysctl option with name "consistent_setxid" is created.
60423+
60424+config GRKERNSEC_TPE
60425+ bool "Trusted Path Execution (TPE)"
60426+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
60427+ help
60428+ If you say Y here, you will be able to choose a gid to add to the
60429+ supplementary groups of users you want to mark as "untrusted."
60430+ These users will not be able to execute any files that are not in
60431+ root-owned directories writable only by root. If the sysctl option
60432+ is enabled, a sysctl option with name "tpe" is created.
60433+
60434+config GRKERNSEC_TPE_ALL
60435+ bool "Partially restrict all non-root users"
60436+ depends on GRKERNSEC_TPE
60437+ help
60438+ If you say Y here, all non-root users will be covered under
60439+ a weaker TPE restriction. This is separate from, and in addition to,
60440+ the main TPE options that you have selected elsewhere. Thus, if a
60441+ "trusted" GID is chosen, this restriction applies to even that GID.
60442+ Under this restriction, all non-root users will only be allowed to
60443+ execute files in directories they own that are not group or
60444+ world-writable, or in directories owned by root and writable only by
60445+ root. If the sysctl option is enabled, a sysctl option with name
60446+ "tpe_restrict_all" is created.
60447+
60448+config GRKERNSEC_TPE_INVERT
60449+ bool "Invert GID option"
60450+ depends on GRKERNSEC_TPE
60451+ help
60452+ If you say Y here, the group you specify in the TPE configuration will
60453+ decide what group TPE restrictions will be *disabled* for. This
60454+ option is useful if you want TPE restrictions to be applied to most
60455+ users on the system. If the sysctl option is enabled, a sysctl option
60456+ with name "tpe_invert" is created. Unlike other sysctl options, this
60457+ entry will default to on for backward-compatibility.
60458+
60459+config GRKERNSEC_TPE_GID
60460+ int
60461+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
60462+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
60463+
60464+config GRKERNSEC_TPE_UNTRUSTED_GID
60465+ int "GID for TPE-untrusted users"
60466+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60467+ default 1005
60468+ help
60469+ Setting this GID determines what group TPE restrictions will be
60470+ *enabled* for. If the sysctl option is enabled, a sysctl option
60471+ with name "tpe_gid" is created.
60472+
60473+config GRKERNSEC_TPE_TRUSTED_GID
60474+ int "GID for TPE-trusted users"
60475+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60476+ default 1005
60477+ help
60478+ Setting this GID determines what group TPE restrictions will be
60479+ *disabled* for. If the sysctl option is enabled, a sysctl option
60480+ with name "tpe_gid" is created.
60481+
60482+endmenu
60483+menu "Network Protections"
60484+depends on GRKERNSEC
60485+
60486+config GRKERNSEC_RANDNET
60487+ bool "Larger entropy pools"
60488+ default y if GRKERNSEC_CONFIG_AUTO
60489+ help
60490+ If you say Y here, the entropy pools used for many features of Linux
60491+ and grsecurity will be doubled in size. Since several grsecurity
60492+ features use additional randomness, it is recommended that you say Y
60493+ here. Saying Y here has a similar effect as modifying
60494+ /proc/sys/kernel/random/poolsize.
60495+
60496+config GRKERNSEC_BLACKHOLE
60497+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60498+ default y if GRKERNSEC_CONFIG_AUTO
60499+ depends on NET
60500+ help
60501+ If you say Y here, neither TCP resets nor ICMP
60502+ destination-unreachable packets will be sent in response to packets
60503+ sent to ports for which no associated listening process exists.
60504+ This feature supports both IPV4 and IPV6 and exempts the
60505+ loopback interface from blackholing. Enabling this feature
60506+ makes a host more resilient to DoS attacks and reduces network
60507+ visibility against scanners.
60508+
60509+ The blackhole feature as-implemented is equivalent to the FreeBSD
60510+ blackhole feature, as it prevents RST responses to all packets, not
60511+ just SYNs. Under most application behavior this causes no
60512+ problems, but applications (like haproxy) may not close certain
60513+ connections in a way that cleanly terminates them on the remote
60514+ end, leaving the remote host in LAST_ACK state. Because of this
60515+ side-effect and to prevent intentional LAST_ACK DoSes, this
60516+ feature also adds automatic mitigation against such attacks.
60517+ The mitigation drastically reduces the amount of time a socket
60518+ can spend in LAST_ACK state. If you're using haproxy and not
60519+ all servers it connects to have this option enabled, consider
60520+ disabling this feature on the haproxy host.
60521+
60522+ If the sysctl option is enabled, two sysctl options with names
60523+ "ip_blackhole" and "lastack_retries" will be created.
60524+ While "ip_blackhole" takes the standard zero/non-zero on/off
60525+ toggle, "lastack_retries" uses the same kinds of values as
60526+ "tcp_retries1" and "tcp_retries2". The default value of 4
60527+ prevents a socket from lasting more than 45 seconds in LAST_ACK
60528+ state.
60529+
60530+config GRKERNSEC_NO_SIMULT_CONNECT
60531+ bool "Disable TCP Simultaneous Connect"
60532+ default y if GRKERNSEC_CONFIG_AUTO
60533+ depends on NET
60534+ help
60535+ If you say Y here, a feature by Willy Tarreau will be enabled that
60536+ removes a weakness in Linux's strict implementation of TCP that
60537+ allows two clients to connect to each other without either entering
60538+ a listening state. The weakness allows an attacker to easily prevent
60539+ a client from connecting to a known server provided the source port
60540+ for the connection is guessed correctly.
60541+
60542+ As the weakness could be used to prevent an antivirus or IPS from
60543+ fetching updates, or prevent an SSL gateway from fetching a CRL,
60544+ it should be eliminated by enabling this option. Though Linux is
60545+ one of few operating systems supporting simultaneous connect, it
60546+ has no legitimate use in practice and is rarely supported by firewalls.
60547+
60548+config GRKERNSEC_SOCKET
60549+ bool "Socket restrictions"
60550+ depends on NET
60551+ help
60552+ If you say Y here, you will be able to choose from several options.
60553+ If you assign a GID on your system and add it to the supplementary
60554+ groups of users you want to restrict socket access to, this patch
60555+ will perform up to three things, based on the option(s) you choose.
60556+
60557+config GRKERNSEC_SOCKET_ALL
60558+ bool "Deny any sockets to group"
60559+ depends on GRKERNSEC_SOCKET
60560+ help
60561+ If you say Y here, you will be able to choose a GID of whose users will
60562+ be unable to connect to other hosts from your machine or run server
60563+ applications from your machine. If the sysctl option is enabled, a
60564+ sysctl option with name "socket_all" is created.
60565+
60566+config GRKERNSEC_SOCKET_ALL_GID
60567+ int "GID to deny all sockets for"
60568+ depends on GRKERNSEC_SOCKET_ALL
60569+ default 1004
60570+ help
60571+ Here you can choose the GID to disable socket access for. Remember to
60572+ add the users you want socket access disabled for to the GID
60573+ specified here. If the sysctl option is enabled, a sysctl option
60574+ with name "socket_all_gid" is created.
60575+
60576+config GRKERNSEC_SOCKET_CLIENT
60577+ bool "Deny client sockets to group"
60578+ depends on GRKERNSEC_SOCKET
60579+ help
60580+ If you say Y here, you will be able to choose a GID of whose users will
60581+ be unable to connect to other hosts from your machine, but will be
60582+ able to run servers. If this option is enabled, all users in the group
60583+ you specify will have to use passive mode when initiating ftp transfers
60584+ from the shell on your machine. If the sysctl option is enabled, a
60585+ sysctl option with name "socket_client" is created.
60586+
60587+config GRKERNSEC_SOCKET_CLIENT_GID
60588+ int "GID to deny client sockets for"
60589+ depends on GRKERNSEC_SOCKET_CLIENT
60590+ default 1003
60591+ help
60592+ Here you can choose the GID to disable client socket access for.
60593+ Remember to add the users you want client socket access disabled for to
60594+ the GID specified here. If the sysctl option is enabled, a sysctl
60595+ option with name "socket_client_gid" is created.
60596+
60597+config GRKERNSEC_SOCKET_SERVER
60598+ bool "Deny server sockets to group"
60599+ depends on GRKERNSEC_SOCKET
60600+ help
60601+ If you say Y here, you will be able to choose a GID of whose users will
60602+ be unable to run server applications from your machine. If the sysctl
60603+ option is enabled, a sysctl option with name "socket_server" is created.
60604+
60605+config GRKERNSEC_SOCKET_SERVER_GID
60606+ int "GID to deny server sockets for"
60607+ depends on GRKERNSEC_SOCKET_SERVER
60608+ default 1002
60609+ help
60610+ Here you can choose the GID to disable server socket access for.
60611+ Remember to add the users you want server socket access disabled for to
60612+ the GID specified here. If the sysctl option is enabled, a sysctl
60613+ option with name "socket_server_gid" is created.
60614+
60615+endmenu
60616+menu "Sysctl Support"
60617+depends on GRKERNSEC && SYSCTL
60618+
60619+config GRKERNSEC_SYSCTL
60620+ bool "Sysctl support"
60621+ default y if GRKERNSEC_CONFIG_AUTO
60622+ help
60623+ If you say Y here, you will be able to change the options that
60624+ grsecurity runs with at bootup, without having to recompile your
60625+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60626+ to enable (1) or disable (0) various features. All the sysctl entries
60627+ are mutable until the "grsec_lock" entry is set to a non-zero value.
60628+ All features enabled in the kernel configuration are disabled at boot
60629+ if you do not say Y to the "Turn on features by default" option.
60630+ All options should be set at startup, and the grsec_lock entry should
60631+ be set to a non-zero value after all the options are set.
60632+ *THIS IS EXTREMELY IMPORTANT*
60633+
60634+config GRKERNSEC_SYSCTL_DISTRO
60635+ bool "Extra sysctl support for distro makers (READ HELP)"
60636+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60637+ help
60638+ If you say Y here, additional sysctl options will be created
60639+ for features that affect processes running as root. Therefore,
60640+ it is critical when using this option that the grsec_lock entry be
60641+ enabled after boot. Only distros with prebuilt kernel packages
60642+ with this option enabled that can ensure grsec_lock is enabled
60643+ after boot should use this option.
60644+ *Failure to set grsec_lock after boot makes all grsec features
60645+ this option covers useless*
60646+
60647+ Currently this option creates the following sysctl entries:
60648+ "Disable Privileged I/O": "disable_priv_io"
60649+
60650+config GRKERNSEC_SYSCTL_ON
60651+ bool "Turn on features by default"
60652+ default y if GRKERNSEC_CONFIG_AUTO
60653+ depends on GRKERNSEC_SYSCTL
60654+ help
60655+ If you say Y here, instead of having all features enabled in the
60656+ kernel configuration disabled at boot time, the features will be
60657+ enabled at boot time. It is recommended you say Y here unless
60658+ there is some reason you would want all sysctl-tunable features to
60659+ be disabled by default. As mentioned elsewhere, it is important
60660+ to enable the grsec_lock entry once you have finished modifying
60661+ the sysctl entries.
60662+
60663+endmenu
60664+menu "Logging Options"
60665+depends on GRKERNSEC
60666+
60667+config GRKERNSEC_FLOODTIME
60668+ int "Seconds in between log messages (minimum)"
60669+ default 10
60670+ help
60671+ This option allows you to enforce the number of seconds between
60672+ grsecurity log messages. The default should be suitable for most
60673+ people, however, if you choose to change it, choose a value small enough
60674+ to allow informative logs to be produced, but large enough to
60675+ prevent flooding.
60676+
60677+config GRKERNSEC_FLOODBURST
60678+ int "Number of messages in a burst (maximum)"
60679+ default 6
60680+ help
60681+ This option allows you to choose the maximum number of messages allowed
60682+ within the flood time interval you chose in a separate option. The
60683+ default should be suitable for most people, however if you find that
60684+ many of your logs are being interpreted as flooding, you may want to
60685+ raise this value.
60686+
60687+endmenu
60688diff --git a/grsecurity/Makefile b/grsecurity/Makefile
60689new file mode 100644
60690index 0000000..36845aa
60691--- /dev/null
60692+++ b/grsecurity/Makefile
60693@@ -0,0 +1,42 @@
60694+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
60695+# during 2001-2009 it has been completely redesigned by Brad Spengler
60696+# into an RBAC system
60697+#
60698+# All code in this directory and various hooks inserted throughout the kernel
60699+# are copyright Brad Spengler - Open Source Security, Inc., and released
60700+# under the GPL v2 or higher
60701+
60702+KBUILD_CFLAGS += -Werror
60703+
60704+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
60705+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
60706+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
60707+
60708+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
60709+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
60710+ gracl_learn.o grsec_log.o
60711+ifdef CONFIG_COMPAT
60712+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
60713+endif
60714+
60715+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
60716+
60717+ifdef CONFIG_NET
60718+obj-y += grsec_sock.o
60719+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
60720+endif
60721+
60722+ifndef CONFIG_GRKERNSEC
60723+obj-y += grsec_disabled.o
60724+endif
60725+
60726+ifdef CONFIG_GRKERNSEC_HIDESYM
60727+extra-y := grsec_hidesym.o
60728+$(obj)/grsec_hidesym.o:
60729+ @-chmod -f 500 /boot
60730+ @-chmod -f 500 /lib/modules
60731+ @-chmod -f 500 /lib64/modules
60732+ @-chmod -f 500 /lib32/modules
60733+ @-chmod -f 700 .
60734+ @echo ' grsec: protected kernel image paths'
60735+endif
60736diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
60737new file mode 100644
60738index 0000000..c0793fd
60739--- /dev/null
60740+++ b/grsecurity/gracl.c
60741@@ -0,0 +1,4178 @@
60742+#include <linux/kernel.h>
60743+#include <linux/module.h>
60744+#include <linux/sched.h>
60745+#include <linux/mm.h>
60746+#include <linux/file.h>
60747+#include <linux/fs.h>
60748+#include <linux/namei.h>
60749+#include <linux/mount.h>
60750+#include <linux/tty.h>
60751+#include <linux/proc_fs.h>
60752+#include <linux/lglock.h>
60753+#include <linux/slab.h>
60754+#include <linux/vmalloc.h>
60755+#include <linux/types.h>
60756+#include <linux/sysctl.h>
60757+#include <linux/netdevice.h>
60758+#include <linux/ptrace.h>
60759+#include <linux/gracl.h>
60760+#include <linux/gralloc.h>
60761+#include <linux/security.h>
60762+#include <linux/grinternal.h>
60763+#include <linux/pid_namespace.h>
60764+#include <linux/stop_machine.h>
60765+#include <linux/fdtable.h>
60766+#include <linux/percpu.h>
60767+#include <linux/lglock.h>
60768+#include <linux/hugetlb.h>
60769+#include <linux/posix-timers.h>
60770+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
60771+#include <linux/magic.h>
60772+#include <linux/pagemap.h>
60773+#include "../fs/btrfs/async-thread.h"
60774+#include "../fs/btrfs/ctree.h"
60775+#include "../fs/btrfs/btrfs_inode.h"
60776+#endif
60777+#include "../fs/mount.h"
60778+
60779+#include <asm/uaccess.h>
60780+#include <asm/errno.h>
60781+#include <asm/mman.h>
60782+
60783+extern struct lglock vfsmount_lock;
60784+
60785+static struct acl_role_db acl_role_set;
60786+static struct name_db name_set;
60787+static struct inodev_db inodev_set;
60788+
60789+/* for keeping track of userspace pointers used for subjects, so we
60790+ can share references in the kernel as well
60791+*/
60792+
60793+static struct path real_root;
60794+
60795+static struct acl_subj_map_db subj_map_set;
60796+
60797+static struct acl_role_label *default_role;
60798+
60799+static struct acl_role_label *role_list;
60800+
60801+static u16 acl_sp_role_value;
60802+
60803+extern char *gr_shared_page[4];
60804+static DEFINE_MUTEX(gr_dev_mutex);
60805+DEFINE_RWLOCK(gr_inode_lock);
60806+
60807+struct gr_arg *gr_usermode;
60808+
60809+static unsigned int gr_status __read_only = GR_STATUS_INIT;
60810+
60811+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
60812+extern void gr_clear_learn_entries(void);
60813+
60814+unsigned char *gr_system_salt;
60815+unsigned char *gr_system_sum;
60816+
60817+static struct sprole_pw **acl_special_roles = NULL;
60818+static __u16 num_sprole_pws = 0;
60819+
60820+static struct acl_role_label *kernel_role = NULL;
60821+
60822+static unsigned int gr_auth_attempts = 0;
60823+static unsigned long gr_auth_expires = 0UL;
60824+
60825+#ifdef CONFIG_NET
60826+extern struct vfsmount *sock_mnt;
60827+#endif
60828+
60829+extern struct vfsmount *pipe_mnt;
60830+extern struct vfsmount *shm_mnt;
60831+
60832+#ifdef CONFIG_HUGETLBFS
60833+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60834+#endif
60835+
60836+static struct acl_object_label *fakefs_obj_rw;
60837+static struct acl_object_label *fakefs_obj_rwx;
60838+
60839+extern int gr_init_uidset(void);
60840+extern void gr_free_uidset(void);
60841+extern void gr_remove_uid(uid_t uid);
60842+extern int gr_find_uid(uid_t uid);
60843+
60844+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
60845+{
60846+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
60847+ return -EFAULT;
60848+
60849+ return 0;
60850+}
60851+
60852+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
60853+{
60854+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
60855+ return -EFAULT;
60856+
60857+ return 0;
60858+}
60859+
60860+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
60861+{
60862+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
60863+ return -EFAULT;
60864+
60865+ return 0;
60866+}
60867+
60868+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
60869+{
60870+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
60871+ return -EFAULT;
60872+
60873+ return 0;
60874+}
60875+
60876+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
60877+{
60878+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
60879+ return -EFAULT;
60880+
60881+ return 0;
60882+}
60883+
60884+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
60885+{
60886+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
60887+ return -EFAULT;
60888+
60889+ return 0;
60890+}
60891+
60892+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
60893+{
60894+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
60895+ return -EFAULT;
60896+
60897+ return 0;
60898+}
60899+
60900+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
60901+{
60902+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
60903+ return -EFAULT;
60904+
60905+ return 0;
60906+}
60907+
60908+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
60909+{
60910+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
60911+ return -EFAULT;
60912+
60913+ return 0;
60914+}
60915+
60916+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
60917+{
60918+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
60919+ return -EFAULT;
60920+
60921+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
60922+ return -EINVAL;
60923+
60924+ return 0;
60925+}
60926+
60927+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
60928+{
60929+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
60930+ return -EFAULT;
60931+
60932+ return 0;
60933+}
60934+
60935+static size_t get_gr_arg_wrapper_size_normal(void)
60936+{
60937+ return sizeof(struct gr_arg_wrapper);
60938+}
60939+
60940+#ifdef CONFIG_COMPAT
60941+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
60942+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
60943+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
60944+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
60945+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
60946+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
60947+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
60948+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
60949+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
60950+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
60951+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
60952+extern size_t get_gr_arg_wrapper_size_compat(void);
60953+
60954+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
60955+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
60956+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
60957+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
60958+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
60959+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
60960+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
60961+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
60962+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
60963+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
60964+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
60965+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
60966+
60967+#else
60968+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
60969+#define copy_gr_arg copy_gr_arg_normal
60970+#define copy_gr_hash_struct copy_gr_hash_struct_normal
60971+#define copy_acl_object_label copy_acl_object_label_normal
60972+#define copy_acl_subject_label copy_acl_subject_label_normal
60973+#define copy_acl_role_label copy_acl_role_label_normal
60974+#define copy_acl_ip_label copy_acl_ip_label_normal
60975+#define copy_pointer_from_array copy_pointer_from_array_normal
60976+#define copy_sprole_pw copy_sprole_pw_normal
60977+#define copy_role_transition copy_role_transition_normal
60978+#define copy_role_allowed_ip copy_role_allowed_ip_normal
60979+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
60980+#endif
60981+
60982+__inline__ int
60983+gr_acl_is_enabled(void)
60984+{
60985+ return (gr_status & GR_READY);
60986+}
60987+
60988+static inline dev_t __get_dev(const struct dentry *dentry)
60989+{
60990+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
60991+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
60992+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
60993+ else
60994+#endif
60995+ return dentry->d_sb->s_dev;
60996+}
60997+
60998+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60999+{
61000+ return __get_dev(dentry);
61001+}
61002+
61003+static char gr_task_roletype_to_char(struct task_struct *task)
61004+{
61005+ switch (task->role->roletype &
61006+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
61007+ GR_ROLE_SPECIAL)) {
61008+ case GR_ROLE_DEFAULT:
61009+ return 'D';
61010+ case GR_ROLE_USER:
61011+ return 'U';
61012+ case GR_ROLE_GROUP:
61013+ return 'G';
61014+ case GR_ROLE_SPECIAL:
61015+ return 'S';
61016+ }
61017+
61018+ return 'X';
61019+}
61020+
61021+char gr_roletype_to_char(void)
61022+{
61023+ return gr_task_roletype_to_char(current);
61024+}
61025+
61026+__inline__ int
61027+gr_acl_tpe_check(void)
61028+{
61029+ if (unlikely(!(gr_status & GR_READY)))
61030+ return 0;
61031+ if (current->role->roletype & GR_ROLE_TPE)
61032+ return 1;
61033+ else
61034+ return 0;
61035+}
61036+
61037+int
61038+gr_handle_rawio(const struct inode *inode)
61039+{
61040+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61041+ if (inode && S_ISBLK(inode->i_mode) &&
61042+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61043+ !capable(CAP_SYS_RAWIO))
61044+ return 1;
61045+#endif
61046+ return 0;
61047+}
61048+
61049+static int
61050+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
61051+{
61052+ if (likely(lena != lenb))
61053+ return 0;
61054+
61055+ return !memcmp(a, b, lena);
61056+}
61057+
61058+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
61059+{
61060+ *buflen -= namelen;
61061+ if (*buflen < 0)
61062+ return -ENAMETOOLONG;
61063+ *buffer -= namelen;
61064+ memcpy(*buffer, str, namelen);
61065+ return 0;
61066+}
61067+
61068+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
61069+{
61070+ return prepend(buffer, buflen, name->name, name->len);
61071+}
61072+
61073+static int prepend_path(const struct path *path, struct path *root,
61074+ char **buffer, int *buflen)
61075+{
61076+ struct dentry *dentry = path->dentry;
61077+ struct vfsmount *vfsmnt = path->mnt;
61078+ struct mount *mnt = real_mount(vfsmnt);
61079+ bool slash = false;
61080+ int error = 0;
61081+
61082+ while (dentry != root->dentry || vfsmnt != root->mnt) {
61083+ struct dentry * parent;
61084+
61085+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
61086+ /* Global root? */
61087+ if (!mnt_has_parent(mnt)) {
61088+ goto out;
61089+ }
61090+ dentry = mnt->mnt_mountpoint;
61091+ mnt = mnt->mnt_parent;
61092+ vfsmnt = &mnt->mnt;
61093+ continue;
61094+ }
61095+ parent = dentry->d_parent;
61096+ prefetch(parent);
61097+ spin_lock(&dentry->d_lock);
61098+ error = prepend_name(buffer, buflen, &dentry->d_name);
61099+ spin_unlock(&dentry->d_lock);
61100+ if (!error)
61101+ error = prepend(buffer, buflen, "/", 1);
61102+ if (error)
61103+ break;
61104+
61105+ slash = true;
61106+ dentry = parent;
61107+ }
61108+
61109+out:
61110+ if (!error && !slash)
61111+ error = prepend(buffer, buflen, "/", 1);
61112+
61113+ return error;
61114+}
61115+
61116+/* this must be called with vfsmount_lock and rename_lock held */
61117+
61118+static char *__our_d_path(const struct path *path, struct path *root,
61119+ char *buf, int buflen)
61120+{
61121+ char *res = buf + buflen;
61122+ int error;
61123+
61124+ prepend(&res, &buflen, "\0", 1);
61125+ error = prepend_path(path, root, &res, &buflen);
61126+ if (error)
61127+ return ERR_PTR(error);
61128+
61129+ return res;
61130+}
61131+
61132+static char *
61133+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
61134+{
61135+ char *retval;
61136+
61137+ retval = __our_d_path(path, root, buf, buflen);
61138+ if (unlikely(IS_ERR(retval)))
61139+ retval = strcpy(buf, "<path too long>");
61140+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
61141+ retval[1] = '\0';
61142+
61143+ return retval;
61144+}
61145+
61146+static char *
61147+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
61148+ char *buf, int buflen)
61149+{
61150+ struct path path;
61151+ char *res;
61152+
61153+ path.dentry = (struct dentry *)dentry;
61154+ path.mnt = (struct vfsmount *)vfsmnt;
61155+
61156+ /* we can use real_root.dentry, real_root.mnt, because this is only called
61157+ by the RBAC system */
61158+ res = gen_full_path(&path, &real_root, buf, buflen);
61159+
61160+ return res;
61161+}
61162+
61163+static char *
61164+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
61165+ char *buf, int buflen)
61166+{
61167+ char *res;
61168+ struct path path;
61169+ struct path root;
61170+ struct task_struct *reaper = init_pid_ns.child_reaper;
61171+
61172+ path.dentry = (struct dentry *)dentry;
61173+ path.mnt = (struct vfsmount *)vfsmnt;
61174+
61175+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
61176+ get_fs_root(reaper->fs, &root);
61177+
61178+ br_read_lock(&vfsmount_lock);
61179+ write_seqlock(&rename_lock);
61180+ res = gen_full_path(&path, &root, buf, buflen);
61181+ write_sequnlock(&rename_lock);
61182+ br_read_unlock(&vfsmount_lock);
61183+
61184+ path_put(&root);
61185+ return res;
61186+}
61187+
61188+static char *
61189+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
61190+{
61191+ char *ret;
61192+ br_read_lock(&vfsmount_lock);
61193+ write_seqlock(&rename_lock);
61194+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
61195+ PAGE_SIZE);
61196+ write_sequnlock(&rename_lock);
61197+ br_read_unlock(&vfsmount_lock);
61198+ return ret;
61199+}
61200+
61201+static char *
61202+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
61203+{
61204+ char *ret;
61205+ char *buf;
61206+ int buflen;
61207+
61208+ br_read_lock(&vfsmount_lock);
61209+ write_seqlock(&rename_lock);
61210+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
61211+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
61212+ buflen = (int)(ret - buf);
61213+ if (buflen >= 5)
61214+ prepend(&ret, &buflen, "/proc", 5);
61215+ else
61216+ ret = strcpy(buf, "<path too long>");
61217+ write_sequnlock(&rename_lock);
61218+ br_read_unlock(&vfsmount_lock);
61219+ return ret;
61220+}
61221+
61222+char *
61223+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
61224+{
61225+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
61226+ PAGE_SIZE);
61227+}
61228+
61229+char *
61230+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
61231+{
61232+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61233+ PAGE_SIZE);
61234+}
61235+
61236+char *
61237+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
61238+{
61239+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
61240+ PAGE_SIZE);
61241+}
61242+
61243+char *
61244+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
61245+{
61246+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
61247+ PAGE_SIZE);
61248+}
61249+
61250+char *
61251+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
61252+{
61253+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
61254+ PAGE_SIZE);
61255+}
61256+
61257+__inline__ __u32
61258+to_gr_audit(const __u32 reqmode)
61259+{
61260+ /* masks off auditable permission flags, then shifts them to create
61261+ auditing flags, and adds the special case of append auditing if
61262+ we're requesting write */
61263+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
61264+}
61265+
61266+struct acl_subject_label *
61267+lookup_subject_map(const struct acl_subject_label *userp)
61268+{
61269+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
61270+ struct subject_map *match;
61271+
61272+ match = subj_map_set.s_hash[index];
61273+
61274+ while (match && match->user != userp)
61275+ match = match->next;
61276+
61277+ if (match != NULL)
61278+ return match->kernel;
61279+ else
61280+ return NULL;
61281+}
61282+
61283+static void
61284+insert_subj_map_entry(struct subject_map *subjmap)
61285+{
61286+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
61287+ struct subject_map **curr;
61288+
61289+ subjmap->prev = NULL;
61290+
61291+ curr = &subj_map_set.s_hash[index];
61292+ if (*curr != NULL)
61293+ (*curr)->prev = subjmap;
61294+
61295+ subjmap->next = *curr;
61296+ *curr = subjmap;
61297+
61298+ return;
61299+}
61300+
61301+static struct acl_role_label *
61302+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
61303+ const gid_t gid)
61304+{
61305+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
61306+ struct acl_role_label *match;
61307+ struct role_allowed_ip *ipp;
61308+ unsigned int x;
61309+ u32 curr_ip = task->signal->curr_ip;
61310+
61311+ task->signal->saved_ip = curr_ip;
61312+
61313+ match = acl_role_set.r_hash[index];
61314+
61315+ while (match) {
61316+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
61317+ for (x = 0; x < match->domain_child_num; x++) {
61318+ if (match->domain_children[x] == uid)
61319+ goto found;
61320+ }
61321+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
61322+ break;
61323+ match = match->next;
61324+ }
61325+found:
61326+ if (match == NULL) {
61327+ try_group:
61328+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
61329+ match = acl_role_set.r_hash[index];
61330+
61331+ while (match) {
61332+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
61333+ for (x = 0; x < match->domain_child_num; x++) {
61334+ if (match->domain_children[x] == gid)
61335+ goto found2;
61336+ }
61337+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
61338+ break;
61339+ match = match->next;
61340+ }
61341+found2:
61342+ if (match == NULL)
61343+ match = default_role;
61344+ if (match->allowed_ips == NULL)
61345+ return match;
61346+ else {
61347+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
61348+ if (likely
61349+ ((ntohl(curr_ip) & ipp->netmask) ==
61350+ (ntohl(ipp->addr) & ipp->netmask)))
61351+ return match;
61352+ }
61353+ match = default_role;
61354+ }
61355+ } else if (match->allowed_ips == NULL) {
61356+ return match;
61357+ } else {
61358+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
61359+ if (likely
61360+ ((ntohl(curr_ip) & ipp->netmask) ==
61361+ (ntohl(ipp->addr) & ipp->netmask)))
61362+ return match;
61363+ }
61364+ goto try_group;
61365+ }
61366+
61367+ return match;
61368+}
61369+
61370+struct acl_subject_label *
61371+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
61372+ const struct acl_role_label *role)
61373+{
61374+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
61375+ struct acl_subject_label *match;
61376+
61377+ match = role->subj_hash[index];
61378+
61379+ while (match && (match->inode != ino || match->device != dev ||
61380+ (match->mode & GR_DELETED))) {
61381+ match = match->next;
61382+ }
61383+
61384+ if (match && !(match->mode & GR_DELETED))
61385+ return match;
61386+ else
61387+ return NULL;
61388+}
61389+
61390+struct acl_subject_label *
61391+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
61392+ const struct acl_role_label *role)
61393+{
61394+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
61395+ struct acl_subject_label *match;
61396+
61397+ match = role->subj_hash[index];
61398+
61399+ while (match && (match->inode != ino || match->device != dev ||
61400+ !(match->mode & GR_DELETED))) {
61401+ match = match->next;
61402+ }
61403+
61404+ if (match && (match->mode & GR_DELETED))
61405+ return match;
61406+ else
61407+ return NULL;
61408+}
61409+
61410+static struct acl_object_label *
61411+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
61412+ const struct acl_subject_label *subj)
61413+{
61414+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
61415+ struct acl_object_label *match;
61416+
61417+ match = subj->obj_hash[index];
61418+
61419+ while (match && (match->inode != ino || match->device != dev ||
61420+ (match->mode & GR_DELETED))) {
61421+ match = match->next;
61422+ }
61423+
61424+ if (match && !(match->mode & GR_DELETED))
61425+ return match;
61426+ else
61427+ return NULL;
61428+}
61429+
61430+static struct acl_object_label *
61431+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
61432+ const struct acl_subject_label *subj)
61433+{
61434+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
61435+ struct acl_object_label *match;
61436+
61437+ match = subj->obj_hash[index];
61438+
61439+ while (match && (match->inode != ino || match->device != dev ||
61440+ !(match->mode & GR_DELETED))) {
61441+ match = match->next;
61442+ }
61443+
61444+ if (match && (match->mode & GR_DELETED))
61445+ return match;
61446+
61447+ match = subj->obj_hash[index];
61448+
61449+ while (match && (match->inode != ino || match->device != dev ||
61450+ (match->mode & GR_DELETED))) {
61451+ match = match->next;
61452+ }
61453+
61454+ if (match && !(match->mode & GR_DELETED))
61455+ return match;
61456+ else
61457+ return NULL;
61458+}
61459+
61460+static struct name_entry *
61461+lookup_name_entry(const char *name)
61462+{
61463+ unsigned int len = strlen(name);
61464+ unsigned int key = full_name_hash(name, len);
61465+ unsigned int index = key % name_set.n_size;
61466+ struct name_entry *match;
61467+
61468+ match = name_set.n_hash[index];
61469+
61470+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
61471+ match = match->next;
61472+
61473+ return match;
61474+}
61475+
61476+static struct name_entry *
61477+lookup_name_entry_create(const char *name)
61478+{
61479+ unsigned int len = strlen(name);
61480+ unsigned int key = full_name_hash(name, len);
61481+ unsigned int index = key % name_set.n_size;
61482+ struct name_entry *match;
61483+
61484+ match = name_set.n_hash[index];
61485+
61486+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
61487+ !match->deleted))
61488+ match = match->next;
61489+
61490+ if (match && match->deleted)
61491+ return match;
61492+
61493+ match = name_set.n_hash[index];
61494+
61495+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
61496+ match->deleted))
61497+ match = match->next;
61498+
61499+ if (match && !match->deleted)
61500+ return match;
61501+ else
61502+ return NULL;
61503+}
61504+
61505+static struct inodev_entry *
61506+lookup_inodev_entry(const ino_t ino, const dev_t dev)
61507+{
61508+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
61509+ struct inodev_entry *match;
61510+
61511+ match = inodev_set.i_hash[index];
61512+
61513+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
61514+ match = match->next;
61515+
61516+ return match;
61517+}
61518+
61519+static void
61520+insert_inodev_entry(struct inodev_entry *entry)
61521+{
61522+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
61523+ inodev_set.i_size);
61524+ struct inodev_entry **curr;
61525+
61526+ entry->prev = NULL;
61527+
61528+ curr = &inodev_set.i_hash[index];
61529+ if (*curr != NULL)
61530+ (*curr)->prev = entry;
61531+
61532+ entry->next = *curr;
61533+ *curr = entry;
61534+
61535+ return;
61536+}
61537+
61538+static void
61539+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
61540+{
61541+ unsigned int index =
61542+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
61543+ struct acl_role_label **curr;
61544+ struct acl_role_label *tmp, *tmp2;
61545+
61546+ curr = &acl_role_set.r_hash[index];
61547+
61548+ /* simple case, slot is empty, just set it to our role */
61549+ if (*curr == NULL) {
61550+ *curr = role;
61551+ } else {
61552+ /* example:
61553+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
61554+ 2 -> 3
61555+ */
61556+ /* first check to see if we can already be reached via this slot */
61557+ tmp = *curr;
61558+ while (tmp && tmp != role)
61559+ tmp = tmp->next;
61560+ if (tmp == role) {
61561+ /* we don't need to add ourselves to this slot's chain */
61562+ return;
61563+ }
61564+ /* we need to add ourselves to this chain, two cases */
61565+ if (role->next == NULL) {
61566+ /* simple case, append the current chain to our role */
61567+ role->next = *curr;
61568+ *curr = role;
61569+ } else {
61570+ /* 1 -> 2 -> 3 -> 4
61571+ 2 -> 3 -> 4
61572+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
61573+ */
61574+ /* trickier case: walk our role's chain until we find
61575+ the role for the start of the current slot's chain */
61576+ tmp = role;
61577+ tmp2 = *curr;
61578+ while (tmp->next && tmp->next != tmp2)
61579+ tmp = tmp->next;
61580+ if (tmp->next == tmp2) {
61581+ /* from example above, we found 3, so just
61582+ replace this slot's chain with ours */
61583+ *curr = role;
61584+ } else {
61585+ /* we didn't find a subset of our role's chain
61586+ in the current slot's chain, so append their
61587+ chain to ours, and set us as the first role in
61588+ the slot's chain
61589+
61590+ we could fold this case with the case above,
61591+ but making it explicit for clarity
61592+ */
61593+ tmp->next = tmp2;
61594+ *curr = role;
61595+ }
61596+ }
61597+ }
61598+
61599+ return;
61600+}
61601+
61602+static void
61603+insert_acl_role_label(struct acl_role_label *role)
61604+{
61605+ int i;
61606+
61607+ if (role_list == NULL) {
61608+ role_list = role;
61609+ role->prev = NULL;
61610+ } else {
61611+ role->prev = role_list;
61612+ role_list = role;
61613+ }
61614+
61615+ /* used for hash chains */
61616+ role->next = NULL;
61617+
61618+ if (role->roletype & GR_ROLE_DOMAIN) {
61619+ for (i = 0; i < role->domain_child_num; i++)
61620+ __insert_acl_role_label(role, role->domain_children[i]);
61621+ } else
61622+ __insert_acl_role_label(role, role->uidgid);
61623+}
61624+
61625+static int
61626+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
61627+{
61628+ struct name_entry **curr, *nentry;
61629+ struct inodev_entry *ientry;
61630+ unsigned int len = strlen(name);
61631+ unsigned int key = full_name_hash(name, len);
61632+ unsigned int index = key % name_set.n_size;
61633+
61634+ curr = &name_set.n_hash[index];
61635+
61636+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
61637+ curr = &((*curr)->next);
61638+
61639+ if (*curr != NULL)
61640+ return 1;
61641+
61642+ nentry = acl_alloc(sizeof (struct name_entry));
61643+ if (nentry == NULL)
61644+ return 0;
61645+ ientry = acl_alloc(sizeof (struct inodev_entry));
61646+ if (ientry == NULL)
61647+ return 0;
61648+ ientry->nentry = nentry;
61649+
61650+ nentry->key = key;
61651+ nentry->name = name;
61652+ nentry->inode = inode;
61653+ nentry->device = device;
61654+ nentry->len = len;
61655+ nentry->deleted = deleted;
61656+
61657+ nentry->prev = NULL;
61658+ curr = &name_set.n_hash[index];
61659+ if (*curr != NULL)
61660+ (*curr)->prev = nentry;
61661+ nentry->next = *curr;
61662+ *curr = nentry;
61663+
61664+ /* insert us into the table searchable by inode/dev */
61665+ insert_inodev_entry(ientry);
61666+
61667+ return 1;
61668+}
61669+
61670+static void
61671+insert_acl_obj_label(struct acl_object_label *obj,
61672+ struct acl_subject_label *subj)
61673+{
61674+ unsigned int index =
61675+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
61676+ struct acl_object_label **curr;
61677+
61678+
61679+ obj->prev = NULL;
61680+
61681+ curr = &subj->obj_hash[index];
61682+ if (*curr != NULL)
61683+ (*curr)->prev = obj;
61684+
61685+ obj->next = *curr;
61686+ *curr = obj;
61687+
61688+ return;
61689+}
61690+
61691+static void
61692+insert_acl_subj_label(struct acl_subject_label *obj,
61693+ struct acl_role_label *role)
61694+{
61695+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
61696+ struct acl_subject_label **curr;
61697+
61698+ obj->prev = NULL;
61699+
61700+ curr = &role->subj_hash[index];
61701+ if (*curr != NULL)
61702+ (*curr)->prev = obj;
61703+
61704+ obj->next = *curr;
61705+ *curr = obj;
61706+
61707+ return;
61708+}
61709+
61710+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
61711+
61712+static void *
61713+create_table(__u32 * len, int elementsize)
61714+{
61715+ unsigned int table_sizes[] = {
61716+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
61717+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
61718+ 4194301, 8388593, 16777213, 33554393, 67108859
61719+ };
61720+ void *newtable = NULL;
61721+ unsigned int pwr = 0;
61722+
61723+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
61724+ table_sizes[pwr] <= *len)
61725+ pwr++;
61726+
61727+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
61728+ return newtable;
61729+
61730+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
61731+ newtable =
61732+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
61733+ else
61734+ newtable = vmalloc(table_sizes[pwr] * elementsize);
61735+
61736+ *len = table_sizes[pwr];
61737+
61738+ return newtable;
61739+}
61740+
61741+static int
61742+init_variables(const struct gr_arg *arg)
61743+{
61744+ struct task_struct *reaper = init_pid_ns.child_reaper;
61745+ unsigned int stacksize;
61746+
61747+ subj_map_set.s_size = arg->role_db.num_subjects;
61748+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
61749+ name_set.n_size = arg->role_db.num_objects;
61750+ inodev_set.i_size = arg->role_db.num_objects;
61751+
61752+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
61753+ !name_set.n_size || !inodev_set.i_size)
61754+ return 1;
61755+
61756+ if (!gr_init_uidset())
61757+ return 1;
61758+
61759+ /* set up the stack that holds allocation info */
61760+
61761+ stacksize = arg->role_db.num_pointers + 5;
61762+
61763+ if (!acl_alloc_stack_init(stacksize))
61764+ return 1;
61765+
61766+ /* grab reference for the real root dentry and vfsmount */
61767+ get_fs_root(reaper->fs, &real_root);
61768+
61769+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61770+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
61771+#endif
61772+
61773+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
61774+ if (fakefs_obj_rw == NULL)
61775+ return 1;
61776+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
61777+
61778+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
61779+ if (fakefs_obj_rwx == NULL)
61780+ return 1;
61781+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
61782+
61783+ subj_map_set.s_hash =
61784+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
61785+ acl_role_set.r_hash =
61786+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
61787+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
61788+ inodev_set.i_hash =
61789+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
61790+
61791+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
61792+ !name_set.n_hash || !inodev_set.i_hash)
61793+ return 1;
61794+
61795+ memset(subj_map_set.s_hash, 0,
61796+ sizeof(struct subject_map *) * subj_map_set.s_size);
61797+ memset(acl_role_set.r_hash, 0,
61798+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
61799+ memset(name_set.n_hash, 0,
61800+ sizeof (struct name_entry *) * name_set.n_size);
61801+ memset(inodev_set.i_hash, 0,
61802+ sizeof (struct inodev_entry *) * inodev_set.i_size);
61803+
61804+ return 0;
61805+}
61806+
61807+/* free information not needed after startup
61808+ currently contains user->kernel pointer mappings for subjects
61809+*/
61810+
61811+static void
61812+free_init_variables(void)
61813+{
61814+ __u32 i;
61815+
61816+ if (subj_map_set.s_hash) {
61817+ for (i = 0; i < subj_map_set.s_size; i++) {
61818+ if (subj_map_set.s_hash[i]) {
61819+ kfree(subj_map_set.s_hash[i]);
61820+ subj_map_set.s_hash[i] = NULL;
61821+ }
61822+ }
61823+
61824+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
61825+ PAGE_SIZE)
61826+ kfree(subj_map_set.s_hash);
61827+ else
61828+ vfree(subj_map_set.s_hash);
61829+ }
61830+
61831+ return;
61832+}
61833+
61834+static void
61835+free_variables(void)
61836+{
61837+ struct acl_subject_label *s;
61838+ struct acl_role_label *r;
61839+ struct task_struct *task, *task2;
61840+ unsigned int x;
61841+
61842+ gr_clear_learn_entries();
61843+
61844+ read_lock(&tasklist_lock);
61845+ do_each_thread(task2, task) {
61846+ task->acl_sp_role = 0;
61847+ task->acl_role_id = 0;
61848+ task->acl = NULL;
61849+ task->role = NULL;
61850+ } while_each_thread(task2, task);
61851+ read_unlock(&tasklist_lock);
61852+
61853+ /* release the reference to the real root dentry and vfsmount */
61854+ path_put(&real_root);
61855+ memset(&real_root, 0, sizeof(real_root));
61856+
61857+ /* free all object hash tables */
61858+
61859+ FOR_EACH_ROLE_START(r)
61860+ if (r->subj_hash == NULL)
61861+ goto next_role;
61862+ FOR_EACH_SUBJECT_START(r, s, x)
61863+ if (s->obj_hash == NULL)
61864+ break;
61865+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
61866+ kfree(s->obj_hash);
61867+ else
61868+ vfree(s->obj_hash);
61869+ FOR_EACH_SUBJECT_END(s, x)
61870+ FOR_EACH_NESTED_SUBJECT_START(r, s)
61871+ if (s->obj_hash == NULL)
61872+ break;
61873+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
61874+ kfree(s->obj_hash);
61875+ else
61876+ vfree(s->obj_hash);
61877+ FOR_EACH_NESTED_SUBJECT_END(s)
61878+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
61879+ kfree(r->subj_hash);
61880+ else
61881+ vfree(r->subj_hash);
61882+ r->subj_hash = NULL;
61883+next_role:
61884+ FOR_EACH_ROLE_END(r)
61885+
61886+ acl_free_all();
61887+
61888+ if (acl_role_set.r_hash) {
61889+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
61890+ PAGE_SIZE)
61891+ kfree(acl_role_set.r_hash);
61892+ else
61893+ vfree(acl_role_set.r_hash);
61894+ }
61895+ if (name_set.n_hash) {
61896+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
61897+ PAGE_SIZE)
61898+ kfree(name_set.n_hash);
61899+ else
61900+ vfree(name_set.n_hash);
61901+ }
61902+
61903+ if (inodev_set.i_hash) {
61904+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
61905+ PAGE_SIZE)
61906+ kfree(inodev_set.i_hash);
61907+ else
61908+ vfree(inodev_set.i_hash);
61909+ }
61910+
61911+ gr_free_uidset();
61912+
61913+ memset(&name_set, 0, sizeof (struct name_db));
61914+ memset(&inodev_set, 0, sizeof (struct inodev_db));
61915+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
61916+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
61917+
61918+ default_role = NULL;
61919+ kernel_role = NULL;
61920+ role_list = NULL;
61921+
61922+ return;
61923+}
61924+
61925+static struct acl_subject_label *
61926+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
61927+
61928+static int alloc_and_copy_string(char **name, unsigned int maxlen)
61929+{
61930+ unsigned int len = strnlen_user(*name, maxlen);
61931+ char *tmp;
61932+
61933+ if (!len || len >= maxlen)
61934+ return -EINVAL;
61935+
61936+ if ((tmp = (char *) acl_alloc(len)) == NULL)
61937+ return -ENOMEM;
61938+
61939+ if (copy_from_user(tmp, *name, len))
61940+ return -EFAULT;
61941+
61942+ tmp[len-1] = '\0';
61943+ *name = tmp;
61944+
61945+ return 0;
61946+}
61947+
61948+static int
61949+copy_user_glob(struct acl_object_label *obj)
61950+{
61951+ struct acl_object_label *g_tmp, **guser;
61952+ int error;
61953+
61954+ if (obj->globbed == NULL)
61955+ return 0;
61956+
61957+ guser = &obj->globbed;
61958+ while (*guser) {
61959+ g_tmp = (struct acl_object_label *)
61960+ acl_alloc(sizeof (struct acl_object_label));
61961+ if (g_tmp == NULL)
61962+ return -ENOMEM;
61963+
61964+ if (copy_acl_object_label(g_tmp, *guser))
61965+ return -EFAULT;
61966+
61967+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
61968+ if (error)
61969+ return error;
61970+
61971+ *guser = g_tmp;
61972+ guser = &(g_tmp->next);
61973+ }
61974+
61975+ return 0;
61976+}
61977+
61978+static int
61979+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
61980+ struct acl_role_label *role)
61981+{
61982+ struct acl_object_label *o_tmp;
61983+ int ret;
61984+
61985+ while (userp) {
61986+ if ((o_tmp = (struct acl_object_label *)
61987+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
61988+ return -ENOMEM;
61989+
61990+ if (copy_acl_object_label(o_tmp, userp))
61991+ return -EFAULT;
61992+
61993+ userp = o_tmp->prev;
61994+
61995+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
61996+ if (ret)
61997+ return ret;
61998+
61999+ insert_acl_obj_label(o_tmp, subj);
62000+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
62001+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
62002+ return -ENOMEM;
62003+
62004+ ret = copy_user_glob(o_tmp);
62005+ if (ret)
62006+ return ret;
62007+
62008+ if (o_tmp->nested) {
62009+ int already_copied;
62010+
62011+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
62012+ if (IS_ERR(o_tmp->nested))
62013+ return PTR_ERR(o_tmp->nested);
62014+
62015+ /* insert into nested subject list if we haven't copied this one yet
62016+ to prevent duplicate entries */
62017+ if (!already_copied) {
62018+ o_tmp->nested->next = role->hash->first;
62019+ role->hash->first = o_tmp->nested;
62020+ }
62021+ }
62022+ }
62023+
62024+ return 0;
62025+}
62026+
62027+static __u32
62028+count_user_subjs(struct acl_subject_label *userp)
62029+{
62030+ struct acl_subject_label s_tmp;
62031+ __u32 num = 0;
62032+
62033+ while (userp) {
62034+ if (copy_acl_subject_label(&s_tmp, userp))
62035+ break;
62036+
62037+ userp = s_tmp.prev;
62038+ }
62039+
62040+ return num;
62041+}
62042+
62043+static int
62044+copy_user_allowedips(struct acl_role_label *rolep)
62045+{
62046+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
62047+
62048+ ruserip = rolep->allowed_ips;
62049+
62050+ while (ruserip) {
62051+ rlast = rtmp;
62052+
62053+ if ((rtmp = (struct role_allowed_ip *)
62054+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
62055+ return -ENOMEM;
62056+
62057+ if (copy_role_allowed_ip(rtmp, ruserip))
62058+ return -EFAULT;
62059+
62060+ ruserip = rtmp->prev;
62061+
62062+ if (!rlast) {
62063+ rtmp->prev = NULL;
62064+ rolep->allowed_ips = rtmp;
62065+ } else {
62066+ rlast->next = rtmp;
62067+ rtmp->prev = rlast;
62068+ }
62069+
62070+ if (!ruserip)
62071+ rtmp->next = NULL;
62072+ }
62073+
62074+ return 0;
62075+}
62076+
62077+static int
62078+copy_user_transitions(struct acl_role_label *rolep)
62079+{
62080+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
62081+ int error;
62082+
62083+ rusertp = rolep->transitions;
62084+
62085+ while (rusertp) {
62086+ rlast = rtmp;
62087+
62088+ if ((rtmp = (struct role_transition *)
62089+ acl_alloc(sizeof (struct role_transition))) == NULL)
62090+ return -ENOMEM;
62091+
62092+ if (copy_role_transition(rtmp, rusertp))
62093+ return -EFAULT;
62094+
62095+ rusertp = rtmp->prev;
62096+
62097+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
62098+ if (error)
62099+ return error;
62100+
62101+ if (!rlast) {
62102+ rtmp->prev = NULL;
62103+ rolep->transitions = rtmp;
62104+ } else {
62105+ rlast->next = rtmp;
62106+ rtmp->prev = rlast;
62107+ }
62108+
62109+ if (!rusertp)
62110+ rtmp->next = NULL;
62111+ }
62112+
62113+ return 0;
62114+}
62115+
62116+static __u32 count_user_objs(const struct acl_object_label __user *userp)
62117+{
62118+ struct acl_object_label o_tmp;
62119+ __u32 num = 0;
62120+
62121+ while (userp) {
62122+ if (copy_acl_object_label(&o_tmp, userp))
62123+ break;
62124+
62125+ userp = o_tmp.prev;
62126+ num++;
62127+ }
62128+
62129+ return num;
62130+}
62131+
62132+static struct acl_subject_label *
62133+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
62134+{
62135+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
62136+ __u32 num_objs;
62137+ struct acl_ip_label **i_tmp, *i_utmp2;
62138+ struct gr_hash_struct ghash;
62139+ struct subject_map *subjmap;
62140+ unsigned int i_num;
62141+ int err;
62142+
62143+ if (already_copied != NULL)
62144+ *already_copied = 0;
62145+
62146+ s_tmp = lookup_subject_map(userp);
62147+
62148+ /* we've already copied this subject into the kernel, just return
62149+ the reference to it, and don't copy it over again
62150+ */
62151+ if (s_tmp) {
62152+ if (already_copied != NULL)
62153+ *already_copied = 1;
62154+ return(s_tmp);
62155+ }
62156+
62157+ if ((s_tmp = (struct acl_subject_label *)
62158+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
62159+ return ERR_PTR(-ENOMEM);
62160+
62161+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
62162+ if (subjmap == NULL)
62163+ return ERR_PTR(-ENOMEM);
62164+
62165+ subjmap->user = userp;
62166+ subjmap->kernel = s_tmp;
62167+ insert_subj_map_entry(subjmap);
62168+
62169+ if (copy_acl_subject_label(s_tmp, userp))
62170+ return ERR_PTR(-EFAULT);
62171+
62172+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
62173+ if (err)
62174+ return ERR_PTR(err);
62175+
62176+ if (!strcmp(s_tmp->filename, "/"))
62177+ role->root_label = s_tmp;
62178+
62179+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
62180+ return ERR_PTR(-EFAULT);
62181+
62182+ /* copy user and group transition tables */
62183+
62184+ if (s_tmp->user_trans_num) {
62185+ uid_t *uidlist;
62186+
62187+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
62188+ if (uidlist == NULL)
62189+ return ERR_PTR(-ENOMEM);
62190+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
62191+ return ERR_PTR(-EFAULT);
62192+
62193+ s_tmp->user_transitions = uidlist;
62194+ }
62195+
62196+ if (s_tmp->group_trans_num) {
62197+ gid_t *gidlist;
62198+
62199+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
62200+ if (gidlist == NULL)
62201+ return ERR_PTR(-ENOMEM);
62202+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
62203+ return ERR_PTR(-EFAULT);
62204+
62205+ s_tmp->group_transitions = gidlist;
62206+ }
62207+
62208+ /* set up object hash table */
62209+ num_objs = count_user_objs(ghash.first);
62210+
62211+ s_tmp->obj_hash_size = num_objs;
62212+ s_tmp->obj_hash =
62213+ (struct acl_object_label **)
62214+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
62215+
62216+ if (!s_tmp->obj_hash)
62217+ return ERR_PTR(-ENOMEM);
62218+
62219+ memset(s_tmp->obj_hash, 0,
62220+ s_tmp->obj_hash_size *
62221+ sizeof (struct acl_object_label *));
62222+
62223+ /* add in objects */
62224+ err = copy_user_objs(ghash.first, s_tmp, role);
62225+
62226+ if (err)
62227+ return ERR_PTR(err);
62228+
62229+ /* set pointer for parent subject */
62230+ if (s_tmp->parent_subject) {
62231+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
62232+
62233+ if (IS_ERR(s_tmp2))
62234+ return s_tmp2;
62235+
62236+ s_tmp->parent_subject = s_tmp2;
62237+ }
62238+
62239+ /* add in ip acls */
62240+
62241+ if (!s_tmp->ip_num) {
62242+ s_tmp->ips = NULL;
62243+ goto insert;
62244+ }
62245+
62246+ i_tmp =
62247+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
62248+ sizeof (struct acl_ip_label *));
62249+
62250+ if (!i_tmp)
62251+ return ERR_PTR(-ENOMEM);
62252+
62253+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
62254+ *(i_tmp + i_num) =
62255+ (struct acl_ip_label *)
62256+ acl_alloc(sizeof (struct acl_ip_label));
62257+ if (!*(i_tmp + i_num))
62258+ return ERR_PTR(-ENOMEM);
62259+
62260+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
62261+ return ERR_PTR(-EFAULT);
62262+
62263+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
62264+ return ERR_PTR(-EFAULT);
62265+
62266+ if ((*(i_tmp + i_num))->iface == NULL)
62267+ continue;
62268+
62269+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
62270+ if (err)
62271+ return ERR_PTR(err);
62272+ }
62273+
62274+ s_tmp->ips = i_tmp;
62275+
62276+insert:
62277+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
62278+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
62279+ return ERR_PTR(-ENOMEM);
62280+
62281+ return s_tmp;
62282+}
62283+
62284+static int
62285+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
62286+{
62287+ struct acl_subject_label s_pre;
62288+ struct acl_subject_label * ret;
62289+ int err;
62290+
62291+ while (userp) {
62292+ if (copy_acl_subject_label(&s_pre, userp))
62293+ return -EFAULT;
62294+
62295+ ret = do_copy_user_subj(userp, role, NULL);
62296+
62297+ err = PTR_ERR(ret);
62298+ if (IS_ERR(ret))
62299+ return err;
62300+
62301+ insert_acl_subj_label(ret, role);
62302+
62303+ userp = s_pre.prev;
62304+ }
62305+
62306+ return 0;
62307+}
62308+
62309+static int
62310+copy_user_acl(struct gr_arg *arg)
62311+{
62312+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
62313+ struct acl_subject_label *subj_list;
62314+ struct sprole_pw *sptmp;
62315+ struct gr_hash_struct *ghash;
62316+ uid_t *domainlist;
62317+ unsigned int r_num;
62318+ int err = 0;
62319+ __u16 i;
62320+ __u32 num_subjs;
62321+
62322+ /* we need a default and kernel role */
62323+ if (arg->role_db.num_roles < 2)
62324+ return -EINVAL;
62325+
62326+ /* copy special role authentication info from userspace */
62327+
62328+ num_sprole_pws = arg->num_sprole_pws;
62329+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
62330+
62331+ if (!acl_special_roles && num_sprole_pws)
62332+ return -ENOMEM;
62333+
62334+ for (i = 0; i < num_sprole_pws; i++) {
62335+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
62336+ if (!sptmp)
62337+ return -ENOMEM;
62338+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
62339+ return -EFAULT;
62340+
62341+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
62342+ if (err)
62343+ return err;
62344+
62345+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
62346+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
62347+#endif
62348+
62349+ acl_special_roles[i] = sptmp;
62350+ }
62351+
62352+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
62353+
62354+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
62355+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
62356+
62357+ if (!r_tmp)
62358+ return -ENOMEM;
62359+
62360+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
62361+ return -EFAULT;
62362+
62363+ if (copy_acl_role_label(r_tmp, r_utmp2))
62364+ return -EFAULT;
62365+
62366+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
62367+ if (err)
62368+ return err;
62369+
62370+ if (!strcmp(r_tmp->rolename, "default")
62371+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
62372+ default_role = r_tmp;
62373+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
62374+ kernel_role = r_tmp;
62375+ }
62376+
62377+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
62378+ return -ENOMEM;
62379+
62380+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
62381+ return -EFAULT;
62382+
62383+ r_tmp->hash = ghash;
62384+
62385+ num_subjs = count_user_subjs(r_tmp->hash->first);
62386+
62387+ r_tmp->subj_hash_size = num_subjs;
62388+ r_tmp->subj_hash =
62389+ (struct acl_subject_label **)
62390+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
62391+
62392+ if (!r_tmp->subj_hash)
62393+ return -ENOMEM;
62394+
62395+ err = copy_user_allowedips(r_tmp);
62396+ if (err)
62397+ return err;
62398+
62399+ /* copy domain info */
62400+ if (r_tmp->domain_children != NULL) {
62401+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
62402+ if (domainlist == NULL)
62403+ return -ENOMEM;
62404+
62405+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
62406+ return -EFAULT;
62407+
62408+ r_tmp->domain_children = domainlist;
62409+ }
62410+
62411+ err = copy_user_transitions(r_tmp);
62412+ if (err)
62413+ return err;
62414+
62415+ memset(r_tmp->subj_hash, 0,
62416+ r_tmp->subj_hash_size *
62417+ sizeof (struct acl_subject_label *));
62418+
62419+ /* acquire the list of subjects, then NULL out
62420+ the list prior to parsing the subjects for this role,
62421+ as during this parsing the list is replaced with a list
62422+ of *nested* subjects for the role
62423+ */
62424+ subj_list = r_tmp->hash->first;
62425+
62426+ /* set nested subject list to null */
62427+ r_tmp->hash->first = NULL;
62428+
62429+ err = copy_user_subjs(subj_list, r_tmp);
62430+
62431+ if (err)
62432+ return err;
62433+
62434+ insert_acl_role_label(r_tmp);
62435+ }
62436+
62437+ if (default_role == NULL || kernel_role == NULL)
62438+ return -EINVAL;
62439+
62440+ return err;
62441+}
62442+
62443+static int
62444+gracl_init(struct gr_arg *args)
62445+{
62446+ int error = 0;
62447+
62448+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
62449+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
62450+
62451+ if (init_variables(args)) {
62452+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
62453+ error = -ENOMEM;
62454+ free_variables();
62455+ goto out;
62456+ }
62457+
62458+ error = copy_user_acl(args);
62459+ free_init_variables();
62460+ if (error) {
62461+ free_variables();
62462+ goto out;
62463+ }
62464+
62465+ if ((error = gr_set_acls(0))) {
62466+ free_variables();
62467+ goto out;
62468+ }
62469+
62470+ pax_open_kernel();
62471+ gr_status |= GR_READY;
62472+ pax_close_kernel();
62473+
62474+ out:
62475+ return error;
62476+}
62477+
62478+/* derived from glibc fnmatch() 0: match, 1: no match*/
62479+
62480+static int
62481+glob_match(const char *p, const char *n)
62482+{
62483+ char c;
62484+
62485+ while ((c = *p++) != '\0') {
62486+ switch (c) {
62487+ case '?':
62488+ if (*n == '\0')
62489+ return 1;
62490+ else if (*n == '/')
62491+ return 1;
62492+ break;
62493+ case '\\':
62494+ if (*n != c)
62495+ return 1;
62496+ break;
62497+ case '*':
62498+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
62499+ if (*n == '/')
62500+ return 1;
62501+ else if (c == '?') {
62502+ if (*n == '\0')
62503+ return 1;
62504+ else
62505+ ++n;
62506+ }
62507+ }
62508+ if (c == '\0') {
62509+ return 0;
62510+ } else {
62511+ const char *endp;
62512+
62513+ if ((endp = strchr(n, '/')) == NULL)
62514+ endp = n + strlen(n);
62515+
62516+ if (c == '[') {
62517+ for (--p; n < endp; ++n)
62518+ if (!glob_match(p, n))
62519+ return 0;
62520+ } else if (c == '/') {
62521+ while (*n != '\0' && *n != '/')
62522+ ++n;
62523+ if (*n == '/' && !glob_match(p, n + 1))
62524+ return 0;
62525+ } else {
62526+ for (--p; n < endp; ++n)
62527+ if (*n == c && !glob_match(p, n))
62528+ return 0;
62529+ }
62530+
62531+ return 1;
62532+ }
62533+ case '[':
62534+ {
62535+ int not;
62536+ char cold;
62537+
62538+ if (*n == '\0' || *n == '/')
62539+ return 1;
62540+
62541+ not = (*p == '!' || *p == '^');
62542+ if (not)
62543+ ++p;
62544+
62545+ c = *p++;
62546+ for (;;) {
62547+ unsigned char fn = (unsigned char)*n;
62548+
62549+ if (c == '\0')
62550+ return 1;
62551+ else {
62552+ if (c == fn)
62553+ goto matched;
62554+ cold = c;
62555+ c = *p++;
62556+
62557+ if (c == '-' && *p != ']') {
62558+ unsigned char cend = *p++;
62559+
62560+ if (cend == '\0')
62561+ return 1;
62562+
62563+ if (cold <= fn && fn <= cend)
62564+ goto matched;
62565+
62566+ c = *p++;
62567+ }
62568+ }
62569+
62570+ if (c == ']')
62571+ break;
62572+ }
62573+ if (!not)
62574+ return 1;
62575+ break;
62576+ matched:
62577+ while (c != ']') {
62578+ if (c == '\0')
62579+ return 1;
62580+
62581+ c = *p++;
62582+ }
62583+ if (not)
62584+ return 1;
62585+ }
62586+ break;
62587+ default:
62588+ if (c != *n)
62589+ return 1;
62590+ }
62591+
62592+ ++n;
62593+ }
62594+
62595+ if (*n == '\0')
62596+ return 0;
62597+
62598+ if (*n == '/')
62599+ return 0;
62600+
62601+ return 1;
62602+}
62603+
62604+static struct acl_object_label *
62605+chk_glob_label(struct acl_object_label *globbed,
62606+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
62607+{
62608+ struct acl_object_label *tmp;
62609+
62610+ if (*path == NULL)
62611+ *path = gr_to_filename_nolock(dentry, mnt);
62612+
62613+ tmp = globbed;
62614+
62615+ while (tmp) {
62616+ if (!glob_match(tmp->filename, *path))
62617+ return tmp;
62618+ tmp = tmp->next;
62619+ }
62620+
62621+ return NULL;
62622+}
62623+
62624+static struct acl_object_label *
62625+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
62626+ const ino_t curr_ino, const dev_t curr_dev,
62627+ const struct acl_subject_label *subj, char **path, const int checkglob)
62628+{
62629+ struct acl_subject_label *tmpsubj;
62630+ struct acl_object_label *retval;
62631+ struct acl_object_label *retval2;
62632+
62633+ tmpsubj = (struct acl_subject_label *) subj;
62634+ read_lock(&gr_inode_lock);
62635+ do {
62636+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
62637+ if (retval) {
62638+ if (checkglob && retval->globbed) {
62639+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
62640+ if (retval2)
62641+ retval = retval2;
62642+ }
62643+ break;
62644+ }
62645+ } while ((tmpsubj = tmpsubj->parent_subject));
62646+ read_unlock(&gr_inode_lock);
62647+
62648+ return retval;
62649+}
62650+
62651+static __inline__ struct acl_object_label *
62652+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
62653+ struct dentry *curr_dentry,
62654+ const struct acl_subject_label *subj, char **path, const int checkglob)
62655+{
62656+ int newglob = checkglob;
62657+ ino_t inode;
62658+ dev_t device;
62659+
62660+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
62661+ as we don't want a / * rule to match instead of the / object
62662+ don't do this for create lookups that call this function though, since they're looking up
62663+ on the parent and thus need globbing checks on all paths
62664+ */
62665+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
62666+ newglob = GR_NO_GLOB;
62667+
62668+ spin_lock(&curr_dentry->d_lock);
62669+ inode = curr_dentry->d_inode->i_ino;
62670+ device = __get_dev(curr_dentry);
62671+ spin_unlock(&curr_dentry->d_lock);
62672+
62673+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
62674+}
62675+
62676+#ifdef CONFIG_HUGETLBFS
62677+static inline bool
62678+is_hugetlbfs_mnt(const struct vfsmount *mnt)
62679+{
62680+ int i;
62681+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
62682+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
62683+ return true;
62684+ }
62685+
62686+ return false;
62687+}
62688+#endif
62689+
62690+static struct acl_object_label *
62691+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
62692+ const struct acl_subject_label *subj, char *path, const int checkglob)
62693+{
62694+ struct dentry *dentry = (struct dentry *) l_dentry;
62695+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
62696+ struct mount *real_mnt = real_mount(mnt);
62697+ struct acl_object_label *retval;
62698+ struct dentry *parent;
62699+
62700+ br_read_lock(&vfsmount_lock);
62701+ write_seqlock(&rename_lock);
62702+
62703+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
62704+#ifdef CONFIG_NET
62705+ mnt == sock_mnt ||
62706+#endif
62707+#ifdef CONFIG_HUGETLBFS
62708+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
62709+#endif
62710+ /* ignore Eric Biederman */
62711+ IS_PRIVATE(l_dentry->d_inode))) {
62712+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
62713+ goto out;
62714+ }
62715+
62716+ for (;;) {
62717+ if (dentry == real_root.dentry && mnt == real_root.mnt)
62718+ break;
62719+
62720+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
62721+ if (!mnt_has_parent(real_mnt))
62722+ break;
62723+
62724+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
62725+ if (retval != NULL)
62726+ goto out;
62727+
62728+ dentry = real_mnt->mnt_mountpoint;
62729+ real_mnt = real_mnt->mnt_parent;
62730+ mnt = &real_mnt->mnt;
62731+ continue;
62732+ }
62733+
62734+ parent = dentry->d_parent;
62735+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
62736+ if (retval != NULL)
62737+ goto out;
62738+
62739+ dentry = parent;
62740+ }
62741+
62742+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
62743+
62744+ /* real_root is pinned so we don't have to hold a reference */
62745+ if (retval == NULL)
62746+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
62747+out:
62748+ write_sequnlock(&rename_lock);
62749+ br_read_unlock(&vfsmount_lock);
62750+
62751+ BUG_ON(retval == NULL);
62752+
62753+ return retval;
62754+}
62755+
62756+static __inline__ struct acl_object_label *
62757+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
62758+ const struct acl_subject_label *subj)
62759+{
62760+ char *path = NULL;
62761+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
62762+}
62763+
62764+static __inline__ struct acl_object_label *
62765+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
62766+ const struct acl_subject_label *subj)
62767+{
62768+ char *path = NULL;
62769+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
62770+}
62771+
62772+static __inline__ struct acl_object_label *
62773+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
62774+ const struct acl_subject_label *subj, char *path)
62775+{
62776+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
62777+}
62778+
62779+static struct acl_subject_label *
62780+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
62781+ const struct acl_role_label *role)
62782+{
62783+ struct dentry *dentry = (struct dentry *) l_dentry;
62784+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
62785+ struct mount *real_mnt = real_mount(mnt);
62786+ struct acl_subject_label *retval;
62787+ struct dentry *parent;
62788+
62789+ br_read_lock(&vfsmount_lock);
62790+ write_seqlock(&rename_lock);
62791+
62792+ for (;;) {
62793+ if (dentry == real_root.dentry && mnt == real_root.mnt)
62794+ break;
62795+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
62796+ if (!mnt_has_parent(real_mnt))
62797+ break;
62798+
62799+ spin_lock(&dentry->d_lock);
62800+ read_lock(&gr_inode_lock);
62801+ retval =
62802+ lookup_acl_subj_label(dentry->d_inode->i_ino,
62803+ __get_dev(dentry), role);
62804+ read_unlock(&gr_inode_lock);
62805+ spin_unlock(&dentry->d_lock);
62806+ if (retval != NULL)
62807+ goto out;
62808+
62809+ dentry = real_mnt->mnt_mountpoint;
62810+ real_mnt = real_mnt->mnt_parent;
62811+ mnt = &real_mnt->mnt;
62812+ continue;
62813+ }
62814+
62815+ spin_lock(&dentry->d_lock);
62816+ read_lock(&gr_inode_lock);
62817+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
62818+ __get_dev(dentry), role);
62819+ read_unlock(&gr_inode_lock);
62820+ parent = dentry->d_parent;
62821+ spin_unlock(&dentry->d_lock);
62822+
62823+ if (retval != NULL)
62824+ goto out;
62825+
62826+ dentry = parent;
62827+ }
62828+
62829+ spin_lock(&dentry->d_lock);
62830+ read_lock(&gr_inode_lock);
62831+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
62832+ __get_dev(dentry), role);
62833+ read_unlock(&gr_inode_lock);
62834+ spin_unlock(&dentry->d_lock);
62835+
62836+ if (unlikely(retval == NULL)) {
62837+ /* real_root is pinned, we don't need to hold a reference */
62838+ read_lock(&gr_inode_lock);
62839+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
62840+ __get_dev(real_root.dentry), role);
62841+ read_unlock(&gr_inode_lock);
62842+ }
62843+out:
62844+ write_sequnlock(&rename_lock);
62845+ br_read_unlock(&vfsmount_lock);
62846+
62847+ BUG_ON(retval == NULL);
62848+
62849+ return retval;
62850+}
62851+
62852+static void
62853+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
62854+{
62855+ struct task_struct *task = current;
62856+ const struct cred *cred = current_cred();
62857+
62858+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
62859+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
62860+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
62861+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
62862+
62863+ return;
62864+}
62865+
62866+static void
62867+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
62868+{
62869+ struct task_struct *task = current;
62870+ const struct cred *cred = current_cred();
62871+
62872+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
62873+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
62874+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
62875+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
62876+
62877+ return;
62878+}
62879+
62880+static void
62881+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
62882+{
62883+ struct task_struct *task = current;
62884+ const struct cred *cred = current_cred();
62885+
62886+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
62887+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
62888+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
62889+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
62890+
62891+ return;
62892+}
62893+
62894+__u32
62895+gr_search_file(const struct dentry * dentry, const __u32 mode,
62896+ const struct vfsmount * mnt)
62897+{
62898+ __u32 retval = mode;
62899+ struct acl_subject_label *curracl;
62900+ struct acl_object_label *currobj;
62901+
62902+ if (unlikely(!(gr_status & GR_READY)))
62903+ return (mode & ~GR_AUDITS);
62904+
62905+ curracl = current->acl;
62906+
62907+ currobj = chk_obj_label(dentry, mnt, curracl);
62908+ retval = currobj->mode & mode;
62909+
62910+ /* if we're opening a specified transfer file for writing
62911+ (e.g. /dev/initctl), then transfer our role to init
62912+ */
62913+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
62914+ current->role->roletype & GR_ROLE_PERSIST)) {
62915+ struct task_struct *task = init_pid_ns.child_reaper;
62916+
62917+ if (task->role != current->role) {
62918+ task->acl_sp_role = 0;
62919+ task->acl_role_id = current->acl_role_id;
62920+ task->role = current->role;
62921+ rcu_read_lock();
62922+ read_lock(&grsec_exec_file_lock);
62923+ gr_apply_subject_to_task(task);
62924+ read_unlock(&grsec_exec_file_lock);
62925+ rcu_read_unlock();
62926+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
62927+ }
62928+ }
62929+
62930+ if (unlikely
62931+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
62932+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
62933+ __u32 new_mode = mode;
62934+
62935+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
62936+
62937+ retval = new_mode;
62938+
62939+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
62940+ new_mode |= GR_INHERIT;
62941+
62942+ if (!(mode & GR_NOLEARN))
62943+ gr_log_learn(dentry, mnt, new_mode);
62944+ }
62945+
62946+ return retval;
62947+}
62948+
62949+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
62950+ const struct dentry *parent,
62951+ const struct vfsmount *mnt)
62952+{
62953+ struct name_entry *match;
62954+ struct acl_object_label *matchpo;
62955+ struct acl_subject_label *curracl;
62956+ char *path;
62957+
62958+ if (unlikely(!(gr_status & GR_READY)))
62959+ return NULL;
62960+
62961+ preempt_disable();
62962+ path = gr_to_filename_rbac(new_dentry, mnt);
62963+ match = lookup_name_entry_create(path);
62964+
62965+ curracl = current->acl;
62966+
62967+ if (match) {
62968+ read_lock(&gr_inode_lock);
62969+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
62970+ read_unlock(&gr_inode_lock);
62971+
62972+ if (matchpo) {
62973+ preempt_enable();
62974+ return matchpo;
62975+ }
62976+ }
62977+
62978+ // lookup parent
62979+
62980+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
62981+
62982+ preempt_enable();
62983+ return matchpo;
62984+}
62985+
62986+__u32
62987+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
62988+ const struct vfsmount * mnt, const __u32 mode)
62989+{
62990+ struct acl_object_label *matchpo;
62991+ __u32 retval;
62992+
62993+ if (unlikely(!(gr_status & GR_READY)))
62994+ return (mode & ~GR_AUDITS);
62995+
62996+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
62997+
62998+ retval = matchpo->mode & mode;
62999+
63000+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
63001+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
63002+ __u32 new_mode = mode;
63003+
63004+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
63005+
63006+ gr_log_learn(new_dentry, mnt, new_mode);
63007+ return new_mode;
63008+ }
63009+
63010+ return retval;
63011+}
63012+
63013+__u32
63014+gr_check_link(const struct dentry * new_dentry,
63015+ const struct dentry * parent_dentry,
63016+ const struct vfsmount * parent_mnt,
63017+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
63018+{
63019+ struct acl_object_label *obj;
63020+ __u32 oldmode, newmode;
63021+ __u32 needmode;
63022+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
63023+ GR_DELETE | GR_INHERIT;
63024+
63025+ if (unlikely(!(gr_status & GR_READY)))
63026+ return (GR_CREATE | GR_LINK);
63027+
63028+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
63029+ oldmode = obj->mode;
63030+
63031+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
63032+ newmode = obj->mode;
63033+
63034+ needmode = newmode & checkmodes;
63035+
63036+ // old name for hardlink must have at least the permissions of the new name
63037+ if ((oldmode & needmode) != needmode)
63038+ goto bad;
63039+
63040+ // if old name had restrictions/auditing, make sure the new name does as well
63041+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
63042+
63043+ // don't allow hardlinking of suid/sgid/fcapped files without permission
63044+ if (is_privileged_binary(old_dentry))
63045+ needmode |= GR_SETID;
63046+
63047+ if ((newmode & needmode) != needmode)
63048+ goto bad;
63049+
63050+ // enforce minimum permissions
63051+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
63052+ return newmode;
63053+bad:
63054+ needmode = oldmode;
63055+ if (is_privileged_binary(old_dentry))
63056+ needmode |= GR_SETID;
63057+
63058+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
63059+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
63060+ return (GR_CREATE | GR_LINK);
63061+ } else if (newmode & GR_SUPPRESS)
63062+ return GR_SUPPRESS;
63063+ else
63064+ return 0;
63065+}
63066+
63067+int
63068+gr_check_hidden_task(const struct task_struct *task)
63069+{
63070+ if (unlikely(!(gr_status & GR_READY)))
63071+ return 0;
63072+
63073+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
63074+ return 1;
63075+
63076+ return 0;
63077+}
63078+
63079+int
63080+gr_check_protected_task(const struct task_struct *task)
63081+{
63082+ if (unlikely(!(gr_status & GR_READY) || !task))
63083+ return 0;
63084+
63085+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
63086+ task->acl != current->acl)
63087+ return 1;
63088+
63089+ return 0;
63090+}
63091+
63092+int
63093+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63094+{
63095+ struct task_struct *p;
63096+ int ret = 0;
63097+
63098+ if (unlikely(!(gr_status & GR_READY) || !pid))
63099+ return ret;
63100+
63101+ read_lock(&tasklist_lock);
63102+ do_each_pid_task(pid, type, p) {
63103+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
63104+ p->acl != current->acl) {
63105+ ret = 1;
63106+ goto out;
63107+ }
63108+ } while_each_pid_task(pid, type, p);
63109+out:
63110+ read_unlock(&tasklist_lock);
63111+
63112+ return ret;
63113+}
63114+
63115+void
63116+gr_copy_label(struct task_struct *tsk)
63117+{
63118+ tsk->signal->used_accept = 0;
63119+ tsk->acl_sp_role = 0;
63120+ tsk->acl_role_id = current->acl_role_id;
63121+ tsk->acl = current->acl;
63122+ tsk->role = current->role;
63123+ tsk->signal->curr_ip = current->signal->curr_ip;
63124+ tsk->signal->saved_ip = current->signal->saved_ip;
63125+ if (current->exec_file)
63126+ get_file(current->exec_file);
63127+ tsk->exec_file = current->exec_file;
63128+ tsk->is_writable = current->is_writable;
63129+ if (unlikely(current->signal->used_accept)) {
63130+ current->signal->curr_ip = 0;
63131+ current->signal->saved_ip = 0;
63132+ }
63133+
63134+ return;
63135+}
63136+
63137+static void
63138+gr_set_proc_res(struct task_struct *task)
63139+{
63140+ struct acl_subject_label *proc;
63141+ unsigned short i;
63142+
63143+ proc = task->acl;
63144+
63145+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
63146+ return;
63147+
63148+ for (i = 0; i < RLIM_NLIMITS; i++) {
63149+ if (!(proc->resmask & (1U << i)))
63150+ continue;
63151+
63152+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
63153+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
63154+
63155+ if (i == RLIMIT_CPU)
63156+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
63157+ }
63158+
63159+ return;
63160+}
63161+
63162+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
63163+
63164+int
63165+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63166+{
63167+ unsigned int i;
63168+ __u16 num;
63169+ uid_t *uidlist;
63170+ uid_t curuid;
63171+ int realok = 0;
63172+ int effectiveok = 0;
63173+ int fsok = 0;
63174+ uid_t globalreal, globaleffective, globalfs;
63175+
63176+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
63177+ struct user_struct *user;
63178+
63179+ if (!uid_valid(real))
63180+ goto skipit;
63181+
63182+ /* find user based on global namespace */
63183+
63184+ globalreal = GR_GLOBAL_UID(real);
63185+
63186+ user = find_user(make_kuid(&init_user_ns, globalreal));
63187+ if (user == NULL)
63188+ goto skipit;
63189+
63190+ if (gr_process_kernel_setuid_ban(user)) {
63191+ /* for find_user */
63192+ free_uid(user);
63193+ return 1;
63194+ }
63195+
63196+ /* for find_user */
63197+ free_uid(user);
63198+
63199+skipit:
63200+#endif
63201+
63202+ if (unlikely(!(gr_status & GR_READY)))
63203+ return 0;
63204+
63205+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
63206+ gr_log_learn_uid_change(real, effective, fs);
63207+
63208+ num = current->acl->user_trans_num;
63209+ uidlist = current->acl->user_transitions;
63210+
63211+ if (uidlist == NULL)
63212+ return 0;
63213+
63214+ if (!uid_valid(real)) {
63215+ realok = 1;
63216+ globalreal = (uid_t)-1;
63217+ } else {
63218+ globalreal = GR_GLOBAL_UID(real);
63219+ }
63220+ if (!uid_valid(effective)) {
63221+ effectiveok = 1;
63222+ globaleffective = (uid_t)-1;
63223+ } else {
63224+ globaleffective = GR_GLOBAL_UID(effective);
63225+ }
63226+ if (!uid_valid(fs)) {
63227+ fsok = 1;
63228+ globalfs = (uid_t)-1;
63229+ } else {
63230+ globalfs = GR_GLOBAL_UID(fs);
63231+ }
63232+
63233+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
63234+ for (i = 0; i < num; i++) {
63235+ curuid = uidlist[i];
63236+ if (globalreal == curuid)
63237+ realok = 1;
63238+ if (globaleffective == curuid)
63239+ effectiveok = 1;
63240+ if (globalfs == curuid)
63241+ fsok = 1;
63242+ }
63243+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
63244+ for (i = 0; i < num; i++) {
63245+ curuid = uidlist[i];
63246+ if (globalreal == curuid)
63247+ break;
63248+ if (globaleffective == curuid)
63249+ break;
63250+ if (globalfs == curuid)
63251+ break;
63252+ }
63253+ /* not in deny list */
63254+ if (i == num) {
63255+ realok = 1;
63256+ effectiveok = 1;
63257+ fsok = 1;
63258+ }
63259+ }
63260+
63261+ if (realok && effectiveok && fsok)
63262+ return 0;
63263+ else {
63264+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
63265+ return 1;
63266+ }
63267+}
63268+
63269+int
63270+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63271+{
63272+ unsigned int i;
63273+ __u16 num;
63274+ gid_t *gidlist;
63275+ gid_t curgid;
63276+ int realok = 0;
63277+ int effectiveok = 0;
63278+ int fsok = 0;
63279+ gid_t globalreal, globaleffective, globalfs;
63280+
63281+ if (unlikely(!(gr_status & GR_READY)))
63282+ return 0;
63283+
63284+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
63285+ gr_log_learn_gid_change(real, effective, fs);
63286+
63287+ num = current->acl->group_trans_num;
63288+ gidlist = current->acl->group_transitions;
63289+
63290+ if (gidlist == NULL)
63291+ return 0;
63292+
63293+ if (!gid_valid(real)) {
63294+ realok = 1;
63295+ globalreal = (gid_t)-1;
63296+ } else {
63297+ globalreal = GR_GLOBAL_GID(real);
63298+ }
63299+ if (!gid_valid(effective)) {
63300+ effectiveok = 1;
63301+ globaleffective = (gid_t)-1;
63302+ } else {
63303+ globaleffective = GR_GLOBAL_GID(effective);
63304+ }
63305+ if (!gid_valid(fs)) {
63306+ fsok = 1;
63307+ globalfs = (gid_t)-1;
63308+ } else {
63309+ globalfs = GR_GLOBAL_GID(fs);
63310+ }
63311+
63312+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
63313+ for (i = 0; i < num; i++) {
63314+ curgid = gidlist[i];
63315+ if (globalreal == curgid)
63316+ realok = 1;
63317+ if (globaleffective == curgid)
63318+ effectiveok = 1;
63319+ if (globalfs == curgid)
63320+ fsok = 1;
63321+ }
63322+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
63323+ for (i = 0; i < num; i++) {
63324+ curgid = gidlist[i];
63325+ if (globalreal == curgid)
63326+ break;
63327+ if (globaleffective == curgid)
63328+ break;
63329+ if (globalfs == curgid)
63330+ break;
63331+ }
63332+ /* not in deny list */
63333+ if (i == num) {
63334+ realok = 1;
63335+ effectiveok = 1;
63336+ fsok = 1;
63337+ }
63338+ }
63339+
63340+ if (realok && effectiveok && fsok)
63341+ return 0;
63342+ else {
63343+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
63344+ return 1;
63345+ }
63346+}
63347+
63348+extern int gr_acl_is_capable(const int cap);
63349+
63350+void
63351+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
63352+{
63353+ struct acl_role_label *role = task->role;
63354+ struct acl_subject_label *subj = NULL;
63355+ struct acl_object_label *obj;
63356+ struct file *filp;
63357+ uid_t uid;
63358+ gid_t gid;
63359+
63360+ if (unlikely(!(gr_status & GR_READY)))
63361+ return;
63362+
63363+ uid = GR_GLOBAL_UID(kuid);
63364+ gid = GR_GLOBAL_GID(kgid);
63365+
63366+ filp = task->exec_file;
63367+
63368+ /* kernel process, we'll give them the kernel role */
63369+ if (unlikely(!filp)) {
63370+ task->role = kernel_role;
63371+ task->acl = kernel_role->root_label;
63372+ return;
63373+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
63374+ role = lookup_acl_role_label(task, uid, gid);
63375+
63376+ /* don't change the role if we're not a privileged process */
63377+ if (role && task->role != role &&
63378+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
63379+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
63380+ return;
63381+
63382+ /* perform subject lookup in possibly new role
63383+ we can use this result below in the case where role == task->role
63384+ */
63385+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
63386+
63387+ /* if we changed uid/gid, but result in the same role
63388+ and are using inheritance, don't lose the inherited subject
63389+ if current subject is other than what normal lookup
63390+ would result in, we arrived via inheritance, don't
63391+ lose subject
63392+ */
63393+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
63394+ (subj == task->acl)))
63395+ task->acl = subj;
63396+
63397+ task->role = role;
63398+
63399+ task->is_writable = 0;
63400+
63401+ /* ignore additional mmap checks for processes that are writable
63402+ by the default ACL */
63403+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
63404+ if (unlikely(obj->mode & GR_WRITE))
63405+ task->is_writable = 1;
63406+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
63407+ if (unlikely(obj->mode & GR_WRITE))
63408+ task->is_writable = 1;
63409+
63410+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63411+ 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);
63412+#endif
63413+
63414+ gr_set_proc_res(task);
63415+
63416+ return;
63417+}
63418+
63419+int
63420+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63421+ const int unsafe_flags)
63422+{
63423+ struct task_struct *task = current;
63424+ struct acl_subject_label *newacl;
63425+ struct acl_object_label *obj;
63426+ __u32 retmode;
63427+
63428+ if (unlikely(!(gr_status & GR_READY)))
63429+ return 0;
63430+
63431+ newacl = chk_subj_label(dentry, mnt, task->role);
63432+
63433+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
63434+ did an exec
63435+ */
63436+ rcu_read_lock();
63437+ read_lock(&tasklist_lock);
63438+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
63439+ (task->parent->acl->mode & GR_POVERRIDE))) {
63440+ read_unlock(&tasklist_lock);
63441+ rcu_read_unlock();
63442+ goto skip_check;
63443+ }
63444+ read_unlock(&tasklist_lock);
63445+ rcu_read_unlock();
63446+
63447+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
63448+ !(task->role->roletype & GR_ROLE_GOD) &&
63449+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
63450+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
63451+ if (unsafe_flags & LSM_UNSAFE_SHARE)
63452+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
63453+ else
63454+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
63455+ return -EACCES;
63456+ }
63457+
63458+skip_check:
63459+
63460+ obj = chk_obj_label(dentry, mnt, task->acl);
63461+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
63462+
63463+ if (!(task->acl->mode & GR_INHERITLEARN) &&
63464+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
63465+ if (obj->nested)
63466+ task->acl = obj->nested;
63467+ else
63468+ task->acl = newacl;
63469+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
63470+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
63471+
63472+ task->is_writable = 0;
63473+
63474+ /* ignore additional mmap checks for processes that are writable
63475+ by the default ACL */
63476+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
63477+ if (unlikely(obj->mode & GR_WRITE))
63478+ task->is_writable = 1;
63479+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
63480+ if (unlikely(obj->mode & GR_WRITE))
63481+ task->is_writable = 1;
63482+
63483+ gr_set_proc_res(task);
63484+
63485+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63486+ 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);
63487+#endif
63488+ return 0;
63489+}
63490+
63491+/* always called with valid inodev ptr */
63492+static void
63493+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
63494+{
63495+ struct acl_object_label *matchpo;
63496+ struct acl_subject_label *matchps;
63497+ struct acl_subject_label *subj;
63498+ struct acl_role_label *role;
63499+ unsigned int x;
63500+
63501+ FOR_EACH_ROLE_START(role)
63502+ FOR_EACH_SUBJECT_START(role, subj, x)
63503+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
63504+ matchpo->mode |= GR_DELETED;
63505+ FOR_EACH_SUBJECT_END(subj,x)
63506+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
63507+ /* nested subjects aren't in the role's subj_hash table */
63508+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
63509+ matchpo->mode |= GR_DELETED;
63510+ FOR_EACH_NESTED_SUBJECT_END(subj)
63511+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
63512+ matchps->mode |= GR_DELETED;
63513+ FOR_EACH_ROLE_END(role)
63514+
63515+ inodev->nentry->deleted = 1;
63516+
63517+ return;
63518+}
63519+
63520+void
63521+gr_handle_delete(const ino_t ino, const dev_t dev)
63522+{
63523+ struct inodev_entry *inodev;
63524+
63525+ if (unlikely(!(gr_status & GR_READY)))
63526+ return;
63527+
63528+ write_lock(&gr_inode_lock);
63529+ inodev = lookup_inodev_entry(ino, dev);
63530+ if (inodev != NULL)
63531+ do_handle_delete(inodev, ino, dev);
63532+ write_unlock(&gr_inode_lock);
63533+
63534+ return;
63535+}
63536+
63537+static void
63538+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
63539+ const ino_t newinode, const dev_t newdevice,
63540+ struct acl_subject_label *subj)
63541+{
63542+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
63543+ struct acl_object_label *match;
63544+
63545+ match = subj->obj_hash[index];
63546+
63547+ while (match && (match->inode != oldinode ||
63548+ match->device != olddevice ||
63549+ !(match->mode & GR_DELETED)))
63550+ match = match->next;
63551+
63552+ if (match && (match->inode == oldinode)
63553+ && (match->device == olddevice)
63554+ && (match->mode & GR_DELETED)) {
63555+ if (match->prev == NULL) {
63556+ subj->obj_hash[index] = match->next;
63557+ if (match->next != NULL)
63558+ match->next->prev = NULL;
63559+ } else {
63560+ match->prev->next = match->next;
63561+ if (match->next != NULL)
63562+ match->next->prev = match->prev;
63563+ }
63564+ match->prev = NULL;
63565+ match->next = NULL;
63566+ match->inode = newinode;
63567+ match->device = newdevice;
63568+ match->mode &= ~GR_DELETED;
63569+
63570+ insert_acl_obj_label(match, subj);
63571+ }
63572+
63573+ return;
63574+}
63575+
63576+static void
63577+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
63578+ const ino_t newinode, const dev_t newdevice,
63579+ struct acl_role_label *role)
63580+{
63581+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
63582+ struct acl_subject_label *match;
63583+
63584+ match = role->subj_hash[index];
63585+
63586+ while (match && (match->inode != oldinode ||
63587+ match->device != olddevice ||
63588+ !(match->mode & GR_DELETED)))
63589+ match = match->next;
63590+
63591+ if (match && (match->inode == oldinode)
63592+ && (match->device == olddevice)
63593+ && (match->mode & GR_DELETED)) {
63594+ if (match->prev == NULL) {
63595+ role->subj_hash[index] = match->next;
63596+ if (match->next != NULL)
63597+ match->next->prev = NULL;
63598+ } else {
63599+ match->prev->next = match->next;
63600+ if (match->next != NULL)
63601+ match->next->prev = match->prev;
63602+ }
63603+ match->prev = NULL;
63604+ match->next = NULL;
63605+ match->inode = newinode;
63606+ match->device = newdevice;
63607+ match->mode &= ~GR_DELETED;
63608+
63609+ insert_acl_subj_label(match, role);
63610+ }
63611+
63612+ return;
63613+}
63614+
63615+static void
63616+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
63617+ const ino_t newinode, const dev_t newdevice)
63618+{
63619+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
63620+ struct inodev_entry *match;
63621+
63622+ match = inodev_set.i_hash[index];
63623+
63624+ while (match && (match->nentry->inode != oldinode ||
63625+ match->nentry->device != olddevice || !match->nentry->deleted))
63626+ match = match->next;
63627+
63628+ if (match && (match->nentry->inode == oldinode)
63629+ && (match->nentry->device == olddevice) &&
63630+ match->nentry->deleted) {
63631+ if (match->prev == NULL) {
63632+ inodev_set.i_hash[index] = match->next;
63633+ if (match->next != NULL)
63634+ match->next->prev = NULL;
63635+ } else {
63636+ match->prev->next = match->next;
63637+ if (match->next != NULL)
63638+ match->next->prev = match->prev;
63639+ }
63640+ match->prev = NULL;
63641+ match->next = NULL;
63642+ match->nentry->inode = newinode;
63643+ match->nentry->device = newdevice;
63644+ match->nentry->deleted = 0;
63645+
63646+ insert_inodev_entry(match);
63647+ }
63648+
63649+ return;
63650+}
63651+
63652+static void
63653+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
63654+{
63655+ struct acl_subject_label *subj;
63656+ struct acl_role_label *role;
63657+ unsigned int x;
63658+
63659+ FOR_EACH_ROLE_START(role)
63660+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
63661+
63662+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
63663+ if ((subj->inode == ino) && (subj->device == dev)) {
63664+ subj->inode = ino;
63665+ subj->device = dev;
63666+ }
63667+ /* nested subjects aren't in the role's subj_hash table */
63668+ update_acl_obj_label(matchn->inode, matchn->device,
63669+ ino, dev, subj);
63670+ FOR_EACH_NESTED_SUBJECT_END(subj)
63671+ FOR_EACH_SUBJECT_START(role, subj, x)
63672+ update_acl_obj_label(matchn->inode, matchn->device,
63673+ ino, dev, subj);
63674+ FOR_EACH_SUBJECT_END(subj,x)
63675+ FOR_EACH_ROLE_END(role)
63676+
63677+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
63678+
63679+ return;
63680+}
63681+
63682+static void
63683+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
63684+ const struct vfsmount *mnt)
63685+{
63686+ ino_t ino = dentry->d_inode->i_ino;
63687+ dev_t dev = __get_dev(dentry);
63688+
63689+ __do_handle_create(matchn, ino, dev);
63690+
63691+ return;
63692+}
63693+
63694+void
63695+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63696+{
63697+ struct name_entry *matchn;
63698+
63699+ if (unlikely(!(gr_status & GR_READY)))
63700+ return;
63701+
63702+ preempt_disable();
63703+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
63704+
63705+ if (unlikely((unsigned long)matchn)) {
63706+ write_lock(&gr_inode_lock);
63707+ do_handle_create(matchn, dentry, mnt);
63708+ write_unlock(&gr_inode_lock);
63709+ }
63710+ preempt_enable();
63711+
63712+ return;
63713+}
63714+
63715+void
63716+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63717+{
63718+ struct name_entry *matchn;
63719+
63720+ if (unlikely(!(gr_status & GR_READY)))
63721+ return;
63722+
63723+ preempt_disable();
63724+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
63725+
63726+ if (unlikely((unsigned long)matchn)) {
63727+ write_lock(&gr_inode_lock);
63728+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
63729+ write_unlock(&gr_inode_lock);
63730+ }
63731+ preempt_enable();
63732+
63733+ return;
63734+}
63735+
63736+void
63737+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63738+ struct dentry *old_dentry,
63739+ struct dentry *new_dentry,
63740+ struct vfsmount *mnt, const __u8 replace)
63741+{
63742+ struct name_entry *matchn;
63743+ struct inodev_entry *inodev;
63744+ struct inode *inode = new_dentry->d_inode;
63745+ ino_t old_ino = old_dentry->d_inode->i_ino;
63746+ dev_t old_dev = __get_dev(old_dentry);
63747+
63748+ /* vfs_rename swaps the name and parent link for old_dentry and
63749+ new_dentry
63750+ at this point, old_dentry has the new name, parent link, and inode
63751+ for the renamed file
63752+ if a file is being replaced by a rename, new_dentry has the inode
63753+ and name for the replaced file
63754+ */
63755+
63756+ if (unlikely(!(gr_status & GR_READY)))
63757+ return;
63758+
63759+ preempt_disable();
63760+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
63761+
63762+ /* we wouldn't have to check d_inode if it weren't for
63763+ NFS silly-renaming
63764+ */
63765+
63766+ write_lock(&gr_inode_lock);
63767+ if (unlikely(replace && inode)) {
63768+ ino_t new_ino = inode->i_ino;
63769+ dev_t new_dev = __get_dev(new_dentry);
63770+
63771+ inodev = lookup_inodev_entry(new_ino, new_dev);
63772+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
63773+ do_handle_delete(inodev, new_ino, new_dev);
63774+ }
63775+
63776+ inodev = lookup_inodev_entry(old_ino, old_dev);
63777+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
63778+ do_handle_delete(inodev, old_ino, old_dev);
63779+
63780+ if (unlikely((unsigned long)matchn))
63781+ do_handle_create(matchn, old_dentry, mnt);
63782+
63783+ write_unlock(&gr_inode_lock);
63784+ preempt_enable();
63785+
63786+ return;
63787+}
63788+
63789+static int
63790+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
63791+ unsigned char **sum)
63792+{
63793+ struct acl_role_label *r;
63794+ struct role_allowed_ip *ipp;
63795+ struct role_transition *trans;
63796+ unsigned int i;
63797+ int found = 0;
63798+ u32 curr_ip = current->signal->curr_ip;
63799+
63800+ current->signal->saved_ip = curr_ip;
63801+
63802+ /* check transition table */
63803+
63804+ for (trans = current->role->transitions; trans; trans = trans->next) {
63805+ if (!strcmp(rolename, trans->rolename)) {
63806+ found = 1;
63807+ break;
63808+ }
63809+ }
63810+
63811+ if (!found)
63812+ return 0;
63813+
63814+ /* handle special roles that do not require authentication
63815+ and check ip */
63816+
63817+ FOR_EACH_ROLE_START(r)
63818+ if (!strcmp(rolename, r->rolename) &&
63819+ (r->roletype & GR_ROLE_SPECIAL)) {
63820+ found = 0;
63821+ if (r->allowed_ips != NULL) {
63822+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
63823+ if ((ntohl(curr_ip) & ipp->netmask) ==
63824+ (ntohl(ipp->addr) & ipp->netmask))
63825+ found = 1;
63826+ }
63827+ } else
63828+ found = 2;
63829+ if (!found)
63830+ return 0;
63831+
63832+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
63833+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
63834+ *salt = NULL;
63835+ *sum = NULL;
63836+ return 1;
63837+ }
63838+ }
63839+ FOR_EACH_ROLE_END(r)
63840+
63841+ for (i = 0; i < num_sprole_pws; i++) {
63842+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
63843+ *salt = acl_special_roles[i]->salt;
63844+ *sum = acl_special_roles[i]->sum;
63845+ return 1;
63846+ }
63847+ }
63848+
63849+ return 0;
63850+}
63851+
63852+static void
63853+assign_special_role(char *rolename)
63854+{
63855+ struct acl_object_label *obj;
63856+ struct acl_role_label *r;
63857+ struct acl_role_label *assigned = NULL;
63858+ struct task_struct *tsk;
63859+ struct file *filp;
63860+
63861+ FOR_EACH_ROLE_START(r)
63862+ if (!strcmp(rolename, r->rolename) &&
63863+ (r->roletype & GR_ROLE_SPECIAL)) {
63864+ assigned = r;
63865+ break;
63866+ }
63867+ FOR_EACH_ROLE_END(r)
63868+
63869+ if (!assigned)
63870+ return;
63871+
63872+ read_lock(&tasklist_lock);
63873+ read_lock(&grsec_exec_file_lock);
63874+
63875+ tsk = current->real_parent;
63876+ if (tsk == NULL)
63877+ goto out_unlock;
63878+
63879+ filp = tsk->exec_file;
63880+ if (filp == NULL)
63881+ goto out_unlock;
63882+
63883+ tsk->is_writable = 0;
63884+
63885+ tsk->acl_sp_role = 1;
63886+ tsk->acl_role_id = ++acl_sp_role_value;
63887+ tsk->role = assigned;
63888+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
63889+
63890+ /* ignore additional mmap checks for processes that are writable
63891+ by the default ACL */
63892+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
63893+ if (unlikely(obj->mode & GR_WRITE))
63894+ tsk->is_writable = 1;
63895+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
63896+ if (unlikely(obj->mode & GR_WRITE))
63897+ tsk->is_writable = 1;
63898+
63899+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63900+ 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));
63901+#endif
63902+
63903+out_unlock:
63904+ read_unlock(&grsec_exec_file_lock);
63905+ read_unlock(&tasklist_lock);
63906+ return;
63907+}
63908+
63909+int gr_check_secure_terminal(struct task_struct *task)
63910+{
63911+ struct task_struct *p, *p2, *p3;
63912+ struct files_struct *files;
63913+ struct fdtable *fdt;
63914+ struct file *our_file = NULL, *file;
63915+ int i;
63916+
63917+ if (task->signal->tty == NULL)
63918+ return 1;
63919+
63920+ files = get_files_struct(task);
63921+ if (files != NULL) {
63922+ rcu_read_lock();
63923+ fdt = files_fdtable(files);
63924+ for (i=0; i < fdt->max_fds; i++) {
63925+ file = fcheck_files(files, i);
63926+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
63927+ get_file(file);
63928+ our_file = file;
63929+ }
63930+ }
63931+ rcu_read_unlock();
63932+ put_files_struct(files);
63933+ }
63934+
63935+ if (our_file == NULL)
63936+ return 1;
63937+
63938+ read_lock(&tasklist_lock);
63939+ do_each_thread(p2, p) {
63940+ files = get_files_struct(p);
63941+ if (files == NULL ||
63942+ (p->signal && p->signal->tty == task->signal->tty)) {
63943+ if (files != NULL)
63944+ put_files_struct(files);
63945+ continue;
63946+ }
63947+ rcu_read_lock();
63948+ fdt = files_fdtable(files);
63949+ for (i=0; i < fdt->max_fds; i++) {
63950+ file = fcheck_files(files, i);
63951+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
63952+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
63953+ p3 = task;
63954+ while (task_pid_nr(p3) > 0) {
63955+ if (p3 == p)
63956+ break;
63957+ p3 = p3->real_parent;
63958+ }
63959+ if (p3 == p)
63960+ break;
63961+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
63962+ gr_handle_alertkill(p);
63963+ rcu_read_unlock();
63964+ put_files_struct(files);
63965+ read_unlock(&tasklist_lock);
63966+ fput(our_file);
63967+ return 0;
63968+ }
63969+ }
63970+ rcu_read_unlock();
63971+ put_files_struct(files);
63972+ } while_each_thread(p2, p);
63973+ read_unlock(&tasklist_lock);
63974+
63975+ fput(our_file);
63976+ return 1;
63977+}
63978+
63979+static int gr_rbac_disable(void *unused)
63980+{
63981+ pax_open_kernel();
63982+ gr_status &= ~GR_READY;
63983+ pax_close_kernel();
63984+
63985+ return 0;
63986+}
63987+
63988+ssize_t
63989+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
63990+{
63991+ struct gr_arg_wrapper uwrap;
63992+ unsigned char *sprole_salt = NULL;
63993+ unsigned char *sprole_sum = NULL;
63994+ int error = 0;
63995+ int error2 = 0;
63996+ size_t req_count = 0;
63997+
63998+ mutex_lock(&gr_dev_mutex);
63999+
64000+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
64001+ error = -EPERM;
64002+ goto out;
64003+ }
64004+
64005+#ifdef CONFIG_COMPAT
64006+ pax_open_kernel();
64007+ if (is_compat_task()) {
64008+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
64009+ copy_gr_arg = &copy_gr_arg_compat;
64010+ copy_acl_object_label = &copy_acl_object_label_compat;
64011+ copy_acl_subject_label = &copy_acl_subject_label_compat;
64012+ copy_acl_role_label = &copy_acl_role_label_compat;
64013+ copy_acl_ip_label = &copy_acl_ip_label_compat;
64014+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
64015+ copy_role_transition = &copy_role_transition_compat;
64016+ copy_sprole_pw = &copy_sprole_pw_compat;
64017+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
64018+ copy_pointer_from_array = &copy_pointer_from_array_compat;
64019+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
64020+ } else {
64021+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
64022+ copy_gr_arg = &copy_gr_arg_normal;
64023+ copy_acl_object_label = &copy_acl_object_label_normal;
64024+ copy_acl_subject_label = &copy_acl_subject_label_normal;
64025+ copy_acl_role_label = &copy_acl_role_label_normal;
64026+ copy_acl_ip_label = &copy_acl_ip_label_normal;
64027+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
64028+ copy_role_transition = &copy_role_transition_normal;
64029+ copy_sprole_pw = &copy_sprole_pw_normal;
64030+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
64031+ copy_pointer_from_array = &copy_pointer_from_array_normal;
64032+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
64033+ }
64034+ pax_close_kernel();
64035+#endif
64036+
64037+ req_count = get_gr_arg_wrapper_size();
64038+
64039+ if (count != req_count) {
64040+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
64041+ error = -EINVAL;
64042+ goto out;
64043+ }
64044+
64045+
64046+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
64047+ gr_auth_expires = 0;
64048+ gr_auth_attempts = 0;
64049+ }
64050+
64051+ error = copy_gr_arg_wrapper(buf, &uwrap);
64052+ if (error)
64053+ goto out;
64054+
64055+ error = copy_gr_arg(uwrap.arg, gr_usermode);
64056+ if (error)
64057+ goto out;
64058+
64059+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
64060+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
64061+ time_after(gr_auth_expires, get_seconds())) {
64062+ error = -EBUSY;
64063+ goto out;
64064+ }
64065+
64066+ /* if non-root trying to do anything other than use a special role,
64067+ do not attempt authentication, do not count towards authentication
64068+ locking
64069+ */
64070+
64071+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
64072+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
64073+ gr_is_global_nonroot(current_uid())) {
64074+ error = -EPERM;
64075+ goto out;
64076+ }
64077+
64078+ /* ensure pw and special role name are null terminated */
64079+
64080+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
64081+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
64082+
64083+ /* Okay.
64084+ * We have our enough of the argument structure..(we have yet
64085+ * to copy_from_user the tables themselves) . Copy the tables
64086+ * only if we need them, i.e. for loading operations. */
64087+
64088+ switch (gr_usermode->mode) {
64089+ case GR_STATUS:
64090+ if (gr_status & GR_READY) {
64091+ error = 1;
64092+ if (!gr_check_secure_terminal(current))
64093+ error = 3;
64094+ } else
64095+ error = 2;
64096+ goto out;
64097+ case GR_SHUTDOWN:
64098+ if ((gr_status & GR_READY)
64099+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
64100+ stop_machine(gr_rbac_disable, NULL, NULL);
64101+ free_variables();
64102+ memset(gr_usermode, 0, sizeof (struct gr_arg));
64103+ memset(gr_system_salt, 0, GR_SALT_LEN);
64104+ memset(gr_system_sum, 0, GR_SHA_LEN);
64105+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
64106+ } else if (gr_status & GR_READY) {
64107+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
64108+ error = -EPERM;
64109+ } else {
64110+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
64111+ error = -EAGAIN;
64112+ }
64113+ break;
64114+ case GR_ENABLE:
64115+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
64116+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
64117+ else {
64118+ if (gr_status & GR_READY)
64119+ error = -EAGAIN;
64120+ else
64121+ error = error2;
64122+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
64123+ }
64124+ break;
64125+ case GR_RELOAD:
64126+ if (!(gr_status & GR_READY)) {
64127+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
64128+ error = -EAGAIN;
64129+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
64130+ stop_machine(gr_rbac_disable, NULL, NULL);
64131+ free_variables();
64132+ error2 = gracl_init(gr_usermode);
64133+ if (!error2)
64134+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
64135+ else {
64136+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
64137+ error = error2;
64138+ }
64139+ } else {
64140+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
64141+ error = -EPERM;
64142+ }
64143+ break;
64144+ case GR_SEGVMOD:
64145+ if (unlikely(!(gr_status & GR_READY))) {
64146+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
64147+ error = -EAGAIN;
64148+ break;
64149+ }
64150+
64151+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
64152+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
64153+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
64154+ struct acl_subject_label *segvacl;
64155+ segvacl =
64156+ lookup_acl_subj_label(gr_usermode->segv_inode,
64157+ gr_usermode->segv_device,
64158+ current->role);
64159+ if (segvacl) {
64160+ segvacl->crashes = 0;
64161+ segvacl->expires = 0;
64162+ }
64163+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
64164+ gr_remove_uid(gr_usermode->segv_uid);
64165+ }
64166+ } else {
64167+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
64168+ error = -EPERM;
64169+ }
64170+ break;
64171+ case GR_SPROLE:
64172+ case GR_SPROLEPAM:
64173+ if (unlikely(!(gr_status & GR_READY))) {
64174+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
64175+ error = -EAGAIN;
64176+ break;
64177+ }
64178+
64179+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
64180+ current->role->expires = 0;
64181+ current->role->auth_attempts = 0;
64182+ }
64183+
64184+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
64185+ time_after(current->role->expires, get_seconds())) {
64186+ error = -EBUSY;
64187+ goto out;
64188+ }
64189+
64190+ if (lookup_special_role_auth
64191+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
64192+ && ((!sprole_salt && !sprole_sum)
64193+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
64194+ char *p = "";
64195+ assign_special_role(gr_usermode->sp_role);
64196+ read_lock(&tasklist_lock);
64197+ if (current->real_parent)
64198+ p = current->real_parent->role->rolename;
64199+ read_unlock(&tasklist_lock);
64200+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
64201+ p, acl_sp_role_value);
64202+ } else {
64203+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
64204+ error = -EPERM;
64205+ if(!(current->role->auth_attempts++))
64206+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
64207+
64208+ goto out;
64209+ }
64210+ break;
64211+ case GR_UNSPROLE:
64212+ if (unlikely(!(gr_status & GR_READY))) {
64213+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
64214+ error = -EAGAIN;
64215+ break;
64216+ }
64217+
64218+ if (current->role->roletype & GR_ROLE_SPECIAL) {
64219+ char *p = "";
64220+ int i = 0;
64221+
64222+ read_lock(&tasklist_lock);
64223+ if (current->real_parent) {
64224+ p = current->real_parent->role->rolename;
64225+ i = current->real_parent->acl_role_id;
64226+ }
64227+ read_unlock(&tasklist_lock);
64228+
64229+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
64230+ gr_set_acls(1);
64231+ } else {
64232+ error = -EPERM;
64233+ goto out;
64234+ }
64235+ break;
64236+ default:
64237+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
64238+ error = -EINVAL;
64239+ break;
64240+ }
64241+
64242+ if (error != -EPERM)
64243+ goto out;
64244+
64245+ if(!(gr_auth_attempts++))
64246+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
64247+
64248+ out:
64249+ mutex_unlock(&gr_dev_mutex);
64250+
64251+ if (!error)
64252+ error = req_count;
64253+
64254+ return error;
64255+}
64256+
64257+/* must be called with
64258+ rcu_read_lock();
64259+ read_lock(&tasklist_lock);
64260+ read_lock(&grsec_exec_file_lock);
64261+*/
64262+int gr_apply_subject_to_task(struct task_struct *task)
64263+{
64264+ struct acl_object_label *obj;
64265+ char *tmpname;
64266+ struct acl_subject_label *tmpsubj;
64267+ struct file *filp;
64268+ struct name_entry *nmatch;
64269+
64270+ filp = task->exec_file;
64271+ if (filp == NULL)
64272+ return 0;
64273+
64274+ /* the following is to apply the correct subject
64275+ on binaries running when the RBAC system
64276+ is enabled, when the binaries have been
64277+ replaced or deleted since their execution
64278+ -----
64279+ when the RBAC system starts, the inode/dev
64280+ from exec_file will be one the RBAC system
64281+ is unaware of. It only knows the inode/dev
64282+ of the present file on disk, or the absence
64283+ of it.
64284+ */
64285+ preempt_disable();
64286+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
64287+
64288+ nmatch = lookup_name_entry(tmpname);
64289+ preempt_enable();
64290+ tmpsubj = NULL;
64291+ if (nmatch) {
64292+ if (nmatch->deleted)
64293+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
64294+ else
64295+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
64296+ if (tmpsubj != NULL)
64297+ task->acl = tmpsubj;
64298+ }
64299+ if (tmpsubj == NULL)
64300+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
64301+ task->role);
64302+ if (task->acl) {
64303+ task->is_writable = 0;
64304+ /* ignore additional mmap checks for processes that are writable
64305+ by the default ACL */
64306+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64307+ if (unlikely(obj->mode & GR_WRITE))
64308+ task->is_writable = 1;
64309+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64310+ if (unlikely(obj->mode & GR_WRITE))
64311+ task->is_writable = 1;
64312+
64313+ gr_set_proc_res(task);
64314+
64315+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64316+ 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);
64317+#endif
64318+ } else {
64319+ return 1;
64320+ }
64321+
64322+ return 0;
64323+}
64324+
64325+int
64326+gr_set_acls(const int type)
64327+{
64328+ struct task_struct *task, *task2;
64329+ struct acl_role_label *role = current->role;
64330+ __u16 acl_role_id = current->acl_role_id;
64331+ const struct cred *cred;
64332+ int ret;
64333+
64334+ rcu_read_lock();
64335+ read_lock(&tasklist_lock);
64336+ read_lock(&grsec_exec_file_lock);
64337+ do_each_thread(task2, task) {
64338+ /* check to see if we're called from the exit handler,
64339+ if so, only replace ACLs that have inherited the admin
64340+ ACL */
64341+
64342+ if (type && (task->role != role ||
64343+ task->acl_role_id != acl_role_id))
64344+ continue;
64345+
64346+ task->acl_role_id = 0;
64347+ task->acl_sp_role = 0;
64348+
64349+ if (task->exec_file) {
64350+ cred = __task_cred(task);
64351+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
64352+ ret = gr_apply_subject_to_task(task);
64353+ if (ret) {
64354+ read_unlock(&grsec_exec_file_lock);
64355+ read_unlock(&tasklist_lock);
64356+ rcu_read_unlock();
64357+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
64358+ return ret;
64359+ }
64360+ } else {
64361+ // it's a kernel process
64362+ task->role = kernel_role;
64363+ task->acl = kernel_role->root_label;
64364+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
64365+ task->acl->mode &= ~GR_PROCFIND;
64366+#endif
64367+ }
64368+ } while_each_thread(task2, task);
64369+ read_unlock(&grsec_exec_file_lock);
64370+ read_unlock(&tasklist_lock);
64371+ rcu_read_unlock();
64372+
64373+ return 0;
64374+}
64375+
64376+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
64377+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
64378+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
64379+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
64380+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
64381+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
64382+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
64383+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
64384+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
64385+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
64386+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
64387+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
64388+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
64389+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
64390+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
64391+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
64392+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
64393+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
64394+};
64395+
64396+void
64397+gr_learn_resource(const struct task_struct *task,
64398+ const int res, const unsigned long wanted, const int gt)
64399+{
64400+ struct acl_subject_label *acl;
64401+ const struct cred *cred;
64402+
64403+ if (unlikely((gr_status & GR_READY) &&
64404+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
64405+ goto skip_reslog;
64406+
64407+ gr_log_resource(task, res, wanted, gt);
64408+skip_reslog:
64409+
64410+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
64411+ return;
64412+
64413+ acl = task->acl;
64414+
64415+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
64416+ !(acl->resmask & (1U << (unsigned short) res))))
64417+ return;
64418+
64419+ if (wanted >= acl->res[res].rlim_cur) {
64420+ unsigned long res_add;
64421+
64422+ res_add = wanted + res_learn_bumps[res];
64423+
64424+ acl->res[res].rlim_cur = res_add;
64425+
64426+ if (wanted > acl->res[res].rlim_max)
64427+ acl->res[res].rlim_max = res_add;
64428+
64429+ /* only log the subject filename, since resource logging is supported for
64430+ single-subject learning only */
64431+ rcu_read_lock();
64432+ cred = __task_cred(task);
64433+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
64434+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
64435+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
64436+ "", (unsigned long) res, &task->signal->saved_ip);
64437+ rcu_read_unlock();
64438+ }
64439+
64440+ return;
64441+}
64442+EXPORT_SYMBOL(gr_learn_resource);
64443+#endif
64444+
64445+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
64446+void
64447+pax_set_initial_flags(struct linux_binprm *bprm)
64448+{
64449+ struct task_struct *task = current;
64450+ struct acl_subject_label *proc;
64451+ unsigned long flags;
64452+
64453+ if (unlikely(!(gr_status & GR_READY)))
64454+ return;
64455+
64456+ flags = pax_get_flags(task);
64457+
64458+ proc = task->acl;
64459+
64460+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
64461+ flags &= ~MF_PAX_PAGEEXEC;
64462+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
64463+ flags &= ~MF_PAX_SEGMEXEC;
64464+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
64465+ flags &= ~MF_PAX_RANDMMAP;
64466+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
64467+ flags &= ~MF_PAX_EMUTRAMP;
64468+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
64469+ flags &= ~MF_PAX_MPROTECT;
64470+
64471+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
64472+ flags |= MF_PAX_PAGEEXEC;
64473+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
64474+ flags |= MF_PAX_SEGMEXEC;
64475+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
64476+ flags |= MF_PAX_RANDMMAP;
64477+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
64478+ flags |= MF_PAX_EMUTRAMP;
64479+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
64480+ flags |= MF_PAX_MPROTECT;
64481+
64482+ pax_set_flags(task, flags);
64483+
64484+ return;
64485+}
64486+#endif
64487+
64488+int
64489+gr_handle_proc_ptrace(struct task_struct *task)
64490+{
64491+ struct file *filp;
64492+ struct task_struct *tmp = task;
64493+ struct task_struct *curtemp = current;
64494+ __u32 retmode;
64495+
64496+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
64497+ if (unlikely(!(gr_status & GR_READY)))
64498+ return 0;
64499+#endif
64500+
64501+ read_lock(&tasklist_lock);
64502+ read_lock(&grsec_exec_file_lock);
64503+ filp = task->exec_file;
64504+
64505+ while (task_pid_nr(tmp) > 0) {
64506+ if (tmp == curtemp)
64507+ break;
64508+ tmp = tmp->real_parent;
64509+ }
64510+
64511+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
64512+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
64513+ read_unlock(&grsec_exec_file_lock);
64514+ read_unlock(&tasklist_lock);
64515+ return 1;
64516+ }
64517+
64518+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64519+ if (!(gr_status & GR_READY)) {
64520+ read_unlock(&grsec_exec_file_lock);
64521+ read_unlock(&tasklist_lock);
64522+ return 0;
64523+ }
64524+#endif
64525+
64526+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
64527+ read_unlock(&grsec_exec_file_lock);
64528+ read_unlock(&tasklist_lock);
64529+
64530+ if (retmode & GR_NOPTRACE)
64531+ return 1;
64532+
64533+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
64534+ && (current->acl != task->acl || (current->acl != current->role->root_label
64535+ && task_pid_nr(current) != task_pid_nr(task))))
64536+ return 1;
64537+
64538+ return 0;
64539+}
64540+
64541+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
64542+{
64543+ if (unlikely(!(gr_status & GR_READY)))
64544+ return;
64545+
64546+ if (!(current->role->roletype & GR_ROLE_GOD))
64547+ return;
64548+
64549+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
64550+ p->role->rolename, gr_task_roletype_to_char(p),
64551+ p->acl->filename);
64552+}
64553+
64554+int
64555+gr_handle_ptrace(struct task_struct *task, const long request)
64556+{
64557+ struct task_struct *tmp = task;
64558+ struct task_struct *curtemp = current;
64559+ __u32 retmode;
64560+
64561+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
64562+ if (unlikely(!(gr_status & GR_READY)))
64563+ return 0;
64564+#endif
64565+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
64566+ read_lock(&tasklist_lock);
64567+ while (task_pid_nr(tmp) > 0) {
64568+ if (tmp == curtemp)
64569+ break;
64570+ tmp = tmp->real_parent;
64571+ }
64572+
64573+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
64574+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
64575+ read_unlock(&tasklist_lock);
64576+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
64577+ return 1;
64578+ }
64579+ read_unlock(&tasklist_lock);
64580+ }
64581+
64582+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64583+ if (!(gr_status & GR_READY))
64584+ return 0;
64585+#endif
64586+
64587+ read_lock(&grsec_exec_file_lock);
64588+ if (unlikely(!task->exec_file)) {
64589+ read_unlock(&grsec_exec_file_lock);
64590+ return 0;
64591+ }
64592+
64593+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
64594+ read_unlock(&grsec_exec_file_lock);
64595+
64596+ if (retmode & GR_NOPTRACE) {
64597+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
64598+ return 1;
64599+ }
64600+
64601+ if (retmode & GR_PTRACERD) {
64602+ switch (request) {
64603+ case PTRACE_SEIZE:
64604+ case PTRACE_POKETEXT:
64605+ case PTRACE_POKEDATA:
64606+ case PTRACE_POKEUSR:
64607+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
64608+ case PTRACE_SETREGS:
64609+ case PTRACE_SETFPREGS:
64610+#endif
64611+#ifdef CONFIG_X86
64612+ case PTRACE_SETFPXREGS:
64613+#endif
64614+#ifdef CONFIG_ALTIVEC
64615+ case PTRACE_SETVRREGS:
64616+#endif
64617+ return 1;
64618+ default:
64619+ return 0;
64620+ }
64621+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
64622+ !(current->role->roletype & GR_ROLE_GOD) &&
64623+ (current->acl != task->acl)) {
64624+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
64625+ return 1;
64626+ }
64627+
64628+ return 0;
64629+}
64630+
64631+static int is_writable_mmap(const struct file *filp)
64632+{
64633+ struct task_struct *task = current;
64634+ struct acl_object_label *obj, *obj2;
64635+
64636+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
64637+ !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))) {
64638+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64639+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
64640+ task->role->root_label);
64641+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
64642+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
64643+ return 1;
64644+ }
64645+ }
64646+ return 0;
64647+}
64648+
64649+int
64650+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
64651+{
64652+ __u32 mode;
64653+
64654+ if (unlikely(!file || !(prot & PROT_EXEC)))
64655+ return 1;
64656+
64657+ if (is_writable_mmap(file))
64658+ return 0;
64659+
64660+ mode =
64661+ gr_search_file(file->f_path.dentry,
64662+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
64663+ file->f_path.mnt);
64664+
64665+ if (!gr_tpe_allow(file))
64666+ return 0;
64667+
64668+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
64669+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
64670+ return 0;
64671+ } else if (unlikely(!(mode & GR_EXEC))) {
64672+ return 0;
64673+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
64674+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
64675+ return 1;
64676+ }
64677+
64678+ return 1;
64679+}
64680+
64681+int
64682+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64683+{
64684+ __u32 mode;
64685+
64686+ if (unlikely(!file || !(prot & PROT_EXEC)))
64687+ return 1;
64688+
64689+ if (is_writable_mmap(file))
64690+ return 0;
64691+
64692+ mode =
64693+ gr_search_file(file->f_path.dentry,
64694+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
64695+ file->f_path.mnt);
64696+
64697+ if (!gr_tpe_allow(file))
64698+ return 0;
64699+
64700+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
64701+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
64702+ return 0;
64703+ } else if (unlikely(!(mode & GR_EXEC))) {
64704+ return 0;
64705+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
64706+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
64707+ return 1;
64708+ }
64709+
64710+ return 1;
64711+}
64712+
64713+void
64714+gr_acl_handle_psacct(struct task_struct *task, const long code)
64715+{
64716+ unsigned long runtime;
64717+ unsigned long cputime;
64718+ unsigned int wday, cday;
64719+ __u8 whr, chr;
64720+ __u8 wmin, cmin;
64721+ __u8 wsec, csec;
64722+ struct timespec timeval;
64723+
64724+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
64725+ !(task->acl->mode & GR_PROCACCT)))
64726+ return;
64727+
64728+ do_posix_clock_monotonic_gettime(&timeval);
64729+ runtime = timeval.tv_sec - task->start_time.tv_sec;
64730+ wday = runtime / (3600 * 24);
64731+ runtime -= wday * (3600 * 24);
64732+ whr = runtime / 3600;
64733+ runtime -= whr * 3600;
64734+ wmin = runtime / 60;
64735+ runtime -= wmin * 60;
64736+ wsec = runtime;
64737+
64738+ cputime = (task->utime + task->stime) / HZ;
64739+ cday = cputime / (3600 * 24);
64740+ cputime -= cday * (3600 * 24);
64741+ chr = cputime / 3600;
64742+ cputime -= chr * 3600;
64743+ cmin = cputime / 60;
64744+ cputime -= cmin * 60;
64745+ csec = cputime;
64746+
64747+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
64748+
64749+ return;
64750+}
64751+
64752+void gr_set_kernel_label(struct task_struct *task)
64753+{
64754+ if (gr_status & GR_READY) {
64755+ task->role = kernel_role;
64756+ task->acl = kernel_role->root_label;
64757+ }
64758+ return;
64759+}
64760+
64761+#ifdef CONFIG_TASKSTATS
64762+int gr_is_taskstats_denied(int pid)
64763+{
64764+ struct task_struct *task;
64765+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64766+ const struct cred *cred;
64767+#endif
64768+ int ret = 0;
64769+
64770+ /* restrict taskstats viewing to un-chrooted root users
64771+ who have the 'view' subject flag if the RBAC system is enabled
64772+ */
64773+
64774+ rcu_read_lock();
64775+ read_lock(&tasklist_lock);
64776+ task = find_task_by_vpid(pid);
64777+ if (task) {
64778+#ifdef CONFIG_GRKERNSEC_CHROOT
64779+ if (proc_is_chrooted(task))
64780+ ret = -EACCES;
64781+#endif
64782+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64783+ cred = __task_cred(task);
64784+#ifdef CONFIG_GRKERNSEC_PROC_USER
64785+ if (gr_is_global_nonroot(cred->uid))
64786+ ret = -EACCES;
64787+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64788+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
64789+ ret = -EACCES;
64790+#endif
64791+#endif
64792+ if (gr_status & GR_READY) {
64793+ if (!(task->acl->mode & GR_VIEW))
64794+ ret = -EACCES;
64795+ }
64796+ } else
64797+ ret = -ENOENT;
64798+
64799+ read_unlock(&tasklist_lock);
64800+ rcu_read_unlock();
64801+
64802+ return ret;
64803+}
64804+#endif
64805+
64806+/* AUXV entries are filled via a descendant of search_binary_handler
64807+ after we've already applied the subject for the target
64808+*/
64809+int gr_acl_enable_at_secure(void)
64810+{
64811+ if (unlikely(!(gr_status & GR_READY)))
64812+ return 0;
64813+
64814+ if (current->acl->mode & GR_ATSECURE)
64815+ return 1;
64816+
64817+ return 0;
64818+}
64819+
64820+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
64821+{
64822+ struct task_struct *task = current;
64823+ struct dentry *dentry = file->f_path.dentry;
64824+ struct vfsmount *mnt = file->f_path.mnt;
64825+ struct acl_object_label *obj, *tmp;
64826+ struct acl_subject_label *subj;
64827+ unsigned int bufsize;
64828+ int is_not_root;
64829+ char *path;
64830+ dev_t dev = __get_dev(dentry);
64831+
64832+ if (unlikely(!(gr_status & GR_READY)))
64833+ return 1;
64834+
64835+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64836+ return 1;
64837+
64838+ /* ignore Eric Biederman */
64839+ if (IS_PRIVATE(dentry->d_inode))
64840+ return 1;
64841+
64842+ subj = task->acl;
64843+ read_lock(&gr_inode_lock);
64844+ do {
64845+ obj = lookup_acl_obj_label(ino, dev, subj);
64846+ if (obj != NULL) {
64847+ read_unlock(&gr_inode_lock);
64848+ return (obj->mode & GR_FIND) ? 1 : 0;
64849+ }
64850+ } while ((subj = subj->parent_subject));
64851+ read_unlock(&gr_inode_lock);
64852+
64853+ /* this is purely an optimization since we're looking for an object
64854+ for the directory we're doing a readdir on
64855+ if it's possible for any globbed object to match the entry we're
64856+ filling into the directory, then the object we find here will be
64857+ an anchor point with attached globbed objects
64858+ */
64859+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
64860+ if (obj->globbed == NULL)
64861+ return (obj->mode & GR_FIND) ? 1 : 0;
64862+
64863+ is_not_root = ((obj->filename[0] == '/') &&
64864+ (obj->filename[1] == '\0')) ? 0 : 1;
64865+ bufsize = PAGE_SIZE - namelen - is_not_root;
64866+
64867+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
64868+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
64869+ return 1;
64870+
64871+ preempt_disable();
64872+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
64873+ bufsize);
64874+
64875+ bufsize = strlen(path);
64876+
64877+ /* if base is "/", don't append an additional slash */
64878+ if (is_not_root)
64879+ *(path + bufsize) = '/';
64880+ memcpy(path + bufsize + is_not_root, name, namelen);
64881+ *(path + bufsize + namelen + is_not_root) = '\0';
64882+
64883+ tmp = obj->globbed;
64884+ while (tmp) {
64885+ if (!glob_match(tmp->filename, path)) {
64886+ preempt_enable();
64887+ return (tmp->mode & GR_FIND) ? 1 : 0;
64888+ }
64889+ tmp = tmp->next;
64890+ }
64891+ preempt_enable();
64892+ return (obj->mode & GR_FIND) ? 1 : 0;
64893+}
64894+
64895+void gr_put_exec_file(struct task_struct *task)
64896+{
64897+ struct file *filp;
64898+
64899+ write_lock(&grsec_exec_file_lock);
64900+ filp = task->exec_file;
64901+ task->exec_file = NULL;
64902+ write_unlock(&grsec_exec_file_lock);
64903+
64904+ if (filp)
64905+ fput(filp);
64906+
64907+ return;
64908+}
64909+
64910+
64911+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
64912+EXPORT_SYMBOL(gr_acl_is_enabled);
64913+#endif
64914+EXPORT_SYMBOL(gr_set_kernel_label);
64915+#ifdef CONFIG_SECURITY
64916+EXPORT_SYMBOL(gr_check_user_change);
64917+EXPORT_SYMBOL(gr_check_group_change);
64918+#endif
64919+
64920diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
64921new file mode 100644
64922index 0000000..34fefda
64923--- /dev/null
64924+++ b/grsecurity/gracl_alloc.c
64925@@ -0,0 +1,105 @@
64926+#include <linux/kernel.h>
64927+#include <linux/mm.h>
64928+#include <linux/slab.h>
64929+#include <linux/vmalloc.h>
64930+#include <linux/gracl.h>
64931+#include <linux/grsecurity.h>
64932+
64933+static unsigned long alloc_stack_next = 1;
64934+static unsigned long alloc_stack_size = 1;
64935+static void **alloc_stack;
64936+
64937+static __inline__ int
64938+alloc_pop(void)
64939+{
64940+ if (alloc_stack_next == 1)
64941+ return 0;
64942+
64943+ kfree(alloc_stack[alloc_stack_next - 2]);
64944+
64945+ alloc_stack_next--;
64946+
64947+ return 1;
64948+}
64949+
64950+static __inline__ int
64951+alloc_push(void *buf)
64952+{
64953+ if (alloc_stack_next >= alloc_stack_size)
64954+ return 1;
64955+
64956+ alloc_stack[alloc_stack_next - 1] = buf;
64957+
64958+ alloc_stack_next++;
64959+
64960+ return 0;
64961+}
64962+
64963+void *
64964+acl_alloc(unsigned long len)
64965+{
64966+ void *ret = NULL;
64967+
64968+ if (!len || len > PAGE_SIZE)
64969+ goto out;
64970+
64971+ ret = kmalloc(len, GFP_KERNEL);
64972+
64973+ if (ret) {
64974+ if (alloc_push(ret)) {
64975+ kfree(ret);
64976+ ret = NULL;
64977+ }
64978+ }
64979+
64980+out:
64981+ return ret;
64982+}
64983+
64984+void *
64985+acl_alloc_num(unsigned long num, unsigned long len)
64986+{
64987+ if (!len || (num > (PAGE_SIZE / len)))
64988+ return NULL;
64989+
64990+ return acl_alloc(num * len);
64991+}
64992+
64993+void
64994+acl_free_all(void)
64995+{
64996+ if (gr_acl_is_enabled() || !alloc_stack)
64997+ return;
64998+
64999+ while (alloc_pop()) ;
65000+
65001+ if (alloc_stack) {
65002+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
65003+ kfree(alloc_stack);
65004+ else
65005+ vfree(alloc_stack);
65006+ }
65007+
65008+ alloc_stack = NULL;
65009+ alloc_stack_size = 1;
65010+ alloc_stack_next = 1;
65011+
65012+ return;
65013+}
65014+
65015+int
65016+acl_alloc_stack_init(unsigned long size)
65017+{
65018+ if ((size * sizeof (void *)) <= PAGE_SIZE)
65019+ alloc_stack =
65020+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
65021+ else
65022+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
65023+
65024+ alloc_stack_size = size;
65025+
65026+ if (!alloc_stack)
65027+ return 0;
65028+ else
65029+ return 1;
65030+}
65031diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
65032new file mode 100644
65033index 0000000..bdd51ea
65034--- /dev/null
65035+++ b/grsecurity/gracl_cap.c
65036@@ -0,0 +1,110 @@
65037+#include <linux/kernel.h>
65038+#include <linux/module.h>
65039+#include <linux/sched.h>
65040+#include <linux/gracl.h>
65041+#include <linux/grsecurity.h>
65042+#include <linux/grinternal.h>
65043+
65044+extern const char *captab_log[];
65045+extern int captab_log_entries;
65046+
65047+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65048+{
65049+ struct acl_subject_label *curracl;
65050+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65051+ kernel_cap_t cap_audit = __cap_empty_set;
65052+
65053+ if (!gr_acl_is_enabled())
65054+ return 1;
65055+
65056+ curracl = task->acl;
65057+
65058+ cap_drop = curracl->cap_lower;
65059+ cap_mask = curracl->cap_mask;
65060+ cap_audit = curracl->cap_invert_audit;
65061+
65062+ while ((curracl = curracl->parent_subject)) {
65063+ /* if the cap isn't specified in the current computed mask but is specified in the
65064+ current level subject, and is lowered in the current level subject, then add
65065+ it to the set of dropped capabilities
65066+ otherwise, add the current level subject's mask to the current computed mask
65067+ */
65068+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65069+ cap_raise(cap_mask, cap);
65070+ if (cap_raised(curracl->cap_lower, cap))
65071+ cap_raise(cap_drop, cap);
65072+ if (cap_raised(curracl->cap_invert_audit, cap))
65073+ cap_raise(cap_audit, cap);
65074+ }
65075+ }
65076+
65077+ if (!cap_raised(cap_drop, cap)) {
65078+ if (cap_raised(cap_audit, cap))
65079+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
65080+ return 1;
65081+ }
65082+
65083+ curracl = task->acl;
65084+
65085+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
65086+ && cap_raised(cred->cap_effective, cap)) {
65087+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65088+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
65089+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
65090+ gr_to_filename(task->exec_file->f_path.dentry,
65091+ task->exec_file->f_path.mnt) : curracl->filename,
65092+ curracl->filename, 0UL,
65093+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
65094+ return 1;
65095+ }
65096+
65097+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
65098+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
65099+
65100+ return 0;
65101+}
65102+
65103+int
65104+gr_acl_is_capable(const int cap)
65105+{
65106+ return gr_task_acl_is_capable(current, current_cred(), cap);
65107+}
65108+
65109+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
65110+{
65111+ struct acl_subject_label *curracl;
65112+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65113+
65114+ if (!gr_acl_is_enabled())
65115+ return 1;
65116+
65117+ curracl = task->acl;
65118+
65119+ cap_drop = curracl->cap_lower;
65120+ cap_mask = curracl->cap_mask;
65121+
65122+ while ((curracl = curracl->parent_subject)) {
65123+ /* if the cap isn't specified in the current computed mask but is specified in the
65124+ current level subject, and is lowered in the current level subject, then add
65125+ it to the set of dropped capabilities
65126+ otherwise, add the current level subject's mask to the current computed mask
65127+ */
65128+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65129+ cap_raise(cap_mask, cap);
65130+ if (cap_raised(curracl->cap_lower, cap))
65131+ cap_raise(cap_drop, cap);
65132+ }
65133+ }
65134+
65135+ if (!cap_raised(cap_drop, cap))
65136+ return 1;
65137+
65138+ return 0;
65139+}
65140+
65141+int
65142+gr_acl_is_capable_nolog(const int cap)
65143+{
65144+ return gr_task_acl_is_capable_nolog(current, cap);
65145+}
65146+
65147diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
65148new file mode 100644
65149index 0000000..a43dd06
65150--- /dev/null
65151+++ b/grsecurity/gracl_compat.c
65152@@ -0,0 +1,269 @@
65153+#include <linux/kernel.h>
65154+#include <linux/gracl.h>
65155+#include <linux/compat.h>
65156+#include <linux/gracl_compat.h>
65157+
65158+#include <asm/uaccess.h>
65159+
65160+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
65161+{
65162+ struct gr_arg_wrapper_compat uwrapcompat;
65163+
65164+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
65165+ return -EFAULT;
65166+
65167+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
65168+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
65169+ return -EINVAL;
65170+
65171+ uwrap->arg = compat_ptr(uwrapcompat.arg);
65172+ uwrap->version = uwrapcompat.version;
65173+ uwrap->size = sizeof(struct gr_arg);
65174+
65175+ return 0;
65176+}
65177+
65178+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
65179+{
65180+ struct gr_arg_compat argcompat;
65181+
65182+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
65183+ return -EFAULT;
65184+
65185+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
65186+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
65187+ arg->role_db.num_roles = argcompat.role_db.num_roles;
65188+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
65189+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
65190+ arg->role_db.num_objects = argcompat.role_db.num_objects;
65191+
65192+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
65193+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
65194+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
65195+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
65196+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
65197+ arg->segv_device = argcompat.segv_device;
65198+ arg->segv_inode = argcompat.segv_inode;
65199+ arg->segv_uid = argcompat.segv_uid;
65200+ arg->num_sprole_pws = argcompat.num_sprole_pws;
65201+ arg->mode = argcompat.mode;
65202+
65203+ return 0;
65204+}
65205+
65206+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
65207+{
65208+ struct acl_object_label_compat objcompat;
65209+
65210+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
65211+ return -EFAULT;
65212+
65213+ obj->filename = compat_ptr(objcompat.filename);
65214+ obj->inode = objcompat.inode;
65215+ obj->device = objcompat.device;
65216+ obj->mode = objcompat.mode;
65217+
65218+ obj->nested = compat_ptr(objcompat.nested);
65219+ obj->globbed = compat_ptr(objcompat.globbed);
65220+
65221+ obj->prev = compat_ptr(objcompat.prev);
65222+ obj->next = compat_ptr(objcompat.next);
65223+
65224+ return 0;
65225+}
65226+
65227+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
65228+{
65229+ unsigned int i;
65230+ struct acl_subject_label_compat subjcompat;
65231+
65232+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
65233+ return -EFAULT;
65234+
65235+ subj->filename = compat_ptr(subjcompat.filename);
65236+ subj->inode = subjcompat.inode;
65237+ subj->device = subjcompat.device;
65238+ subj->mode = subjcompat.mode;
65239+ subj->cap_mask = subjcompat.cap_mask;
65240+ subj->cap_lower = subjcompat.cap_lower;
65241+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
65242+
65243+ for (i = 0; i < GR_NLIMITS; i++) {
65244+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
65245+ subj->res[i].rlim_cur = RLIM_INFINITY;
65246+ else
65247+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
65248+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
65249+ subj->res[i].rlim_max = RLIM_INFINITY;
65250+ else
65251+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
65252+ }
65253+ subj->resmask = subjcompat.resmask;
65254+
65255+ subj->user_trans_type = subjcompat.user_trans_type;
65256+ subj->group_trans_type = subjcompat.group_trans_type;
65257+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
65258+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
65259+ subj->user_trans_num = subjcompat.user_trans_num;
65260+ subj->group_trans_num = subjcompat.group_trans_num;
65261+
65262+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
65263+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
65264+ subj->ip_type = subjcompat.ip_type;
65265+ subj->ips = compat_ptr(subjcompat.ips);
65266+ subj->ip_num = subjcompat.ip_num;
65267+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
65268+
65269+ subj->crashes = subjcompat.crashes;
65270+ subj->expires = subjcompat.expires;
65271+
65272+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
65273+ subj->hash = compat_ptr(subjcompat.hash);
65274+ subj->prev = compat_ptr(subjcompat.prev);
65275+ subj->next = compat_ptr(subjcompat.next);
65276+
65277+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
65278+ subj->obj_hash_size = subjcompat.obj_hash_size;
65279+ subj->pax_flags = subjcompat.pax_flags;
65280+
65281+ return 0;
65282+}
65283+
65284+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
65285+{
65286+ struct acl_role_label_compat rolecompat;
65287+
65288+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
65289+ return -EFAULT;
65290+
65291+ role->rolename = compat_ptr(rolecompat.rolename);
65292+ role->uidgid = rolecompat.uidgid;
65293+ role->roletype = rolecompat.roletype;
65294+
65295+ role->auth_attempts = rolecompat.auth_attempts;
65296+ role->expires = rolecompat.expires;
65297+
65298+ role->root_label = compat_ptr(rolecompat.root_label);
65299+ role->hash = compat_ptr(rolecompat.hash);
65300+
65301+ role->prev = compat_ptr(rolecompat.prev);
65302+ role->next = compat_ptr(rolecompat.next);
65303+
65304+ role->transitions = compat_ptr(rolecompat.transitions);
65305+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
65306+ role->domain_children = compat_ptr(rolecompat.domain_children);
65307+ role->domain_child_num = rolecompat.domain_child_num;
65308+
65309+ role->umask = rolecompat.umask;
65310+
65311+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
65312+ role->subj_hash_size = rolecompat.subj_hash_size;
65313+
65314+ return 0;
65315+}
65316+
65317+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
65318+{
65319+ struct role_allowed_ip_compat roleip_compat;
65320+
65321+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
65322+ return -EFAULT;
65323+
65324+ roleip->addr = roleip_compat.addr;
65325+ roleip->netmask = roleip_compat.netmask;
65326+
65327+ roleip->prev = compat_ptr(roleip_compat.prev);
65328+ roleip->next = compat_ptr(roleip_compat.next);
65329+
65330+ return 0;
65331+}
65332+
65333+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
65334+{
65335+ struct role_transition_compat trans_compat;
65336+
65337+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
65338+ return -EFAULT;
65339+
65340+ trans->rolename = compat_ptr(trans_compat.rolename);
65341+
65342+ trans->prev = compat_ptr(trans_compat.prev);
65343+ trans->next = compat_ptr(trans_compat.next);
65344+
65345+ return 0;
65346+
65347+}
65348+
65349+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
65350+{
65351+ struct gr_hash_struct_compat hash_compat;
65352+
65353+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
65354+ return -EFAULT;
65355+
65356+ hash->table = compat_ptr(hash_compat.table);
65357+ hash->nametable = compat_ptr(hash_compat.nametable);
65358+ hash->first = compat_ptr(hash_compat.first);
65359+
65360+ hash->table_size = hash_compat.table_size;
65361+ hash->used_size = hash_compat.used_size;
65362+
65363+ hash->type = hash_compat.type;
65364+
65365+ return 0;
65366+}
65367+
65368+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
65369+{
65370+ compat_uptr_t ptrcompat;
65371+
65372+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
65373+ return -EFAULT;
65374+
65375+ *(void **)ptr = compat_ptr(ptrcompat);
65376+
65377+ return 0;
65378+}
65379+
65380+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
65381+{
65382+ struct acl_ip_label_compat ip_compat;
65383+
65384+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
65385+ return -EFAULT;
65386+
65387+ ip->iface = compat_ptr(ip_compat.iface);
65388+ ip->addr = ip_compat.addr;
65389+ ip->netmask = ip_compat.netmask;
65390+ ip->low = ip_compat.low;
65391+ ip->high = ip_compat.high;
65392+ ip->mode = ip_compat.mode;
65393+ ip->type = ip_compat.type;
65394+
65395+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
65396+
65397+ ip->prev = compat_ptr(ip_compat.prev);
65398+ ip->next = compat_ptr(ip_compat.next);
65399+
65400+ return 0;
65401+}
65402+
65403+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
65404+{
65405+ struct sprole_pw_compat pw_compat;
65406+
65407+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
65408+ return -EFAULT;
65409+
65410+ pw->rolename = compat_ptr(pw_compat.rolename);
65411+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
65412+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
65413+
65414+ return 0;
65415+}
65416+
65417+size_t get_gr_arg_wrapper_size_compat(void)
65418+{
65419+ return sizeof(struct gr_arg_wrapper_compat);
65420+}
65421+
65422diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
65423new file mode 100644
65424index 0000000..a340c17
65425--- /dev/null
65426+++ b/grsecurity/gracl_fs.c
65427@@ -0,0 +1,431 @@
65428+#include <linux/kernel.h>
65429+#include <linux/sched.h>
65430+#include <linux/types.h>
65431+#include <linux/fs.h>
65432+#include <linux/file.h>
65433+#include <linux/stat.h>
65434+#include <linux/grsecurity.h>
65435+#include <linux/grinternal.h>
65436+#include <linux/gracl.h>
65437+
65438+umode_t
65439+gr_acl_umask(void)
65440+{
65441+ if (unlikely(!gr_acl_is_enabled()))
65442+ return 0;
65443+
65444+ return current->role->umask;
65445+}
65446+
65447+__u32
65448+gr_acl_handle_hidden_file(const struct dentry * dentry,
65449+ const struct vfsmount * mnt)
65450+{
65451+ __u32 mode;
65452+
65453+ if (unlikely(!dentry->d_inode))
65454+ return GR_FIND;
65455+
65456+ mode =
65457+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
65458+
65459+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
65460+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
65461+ return mode;
65462+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
65463+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
65464+ return 0;
65465+ } else if (unlikely(!(mode & GR_FIND)))
65466+ return 0;
65467+
65468+ return GR_FIND;
65469+}
65470+
65471+__u32
65472+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
65473+ int acc_mode)
65474+{
65475+ __u32 reqmode = GR_FIND;
65476+ __u32 mode;
65477+
65478+ if (unlikely(!dentry->d_inode))
65479+ return reqmode;
65480+
65481+ if (acc_mode & MAY_APPEND)
65482+ reqmode |= GR_APPEND;
65483+ else if (acc_mode & MAY_WRITE)
65484+ reqmode |= GR_WRITE;
65485+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
65486+ reqmode |= GR_READ;
65487+
65488+ mode =
65489+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
65490+ mnt);
65491+
65492+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
65493+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
65494+ reqmode & GR_READ ? " reading" : "",
65495+ reqmode & GR_WRITE ? " writing" : reqmode &
65496+ GR_APPEND ? " appending" : "");
65497+ return reqmode;
65498+ } else
65499+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
65500+ {
65501+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
65502+ reqmode & GR_READ ? " reading" : "",
65503+ reqmode & GR_WRITE ? " writing" : reqmode &
65504+ GR_APPEND ? " appending" : "");
65505+ return 0;
65506+ } else if (unlikely((mode & reqmode) != reqmode))
65507+ return 0;
65508+
65509+ return reqmode;
65510+}
65511+
65512+__u32
65513+gr_acl_handle_creat(const struct dentry * dentry,
65514+ const struct dentry * p_dentry,
65515+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
65516+ const int imode)
65517+{
65518+ __u32 reqmode = GR_WRITE | GR_CREATE;
65519+ __u32 mode;
65520+
65521+ if (acc_mode & MAY_APPEND)
65522+ reqmode |= GR_APPEND;
65523+ // if a directory was required or the directory already exists, then
65524+ // don't count this open as a read
65525+ if ((acc_mode & MAY_READ) &&
65526+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
65527+ reqmode |= GR_READ;
65528+ if ((open_flags & O_CREAT) &&
65529+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
65530+ reqmode |= GR_SETID;
65531+
65532+ mode =
65533+ gr_check_create(dentry, p_dentry, p_mnt,
65534+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
65535+
65536+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
65537+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
65538+ reqmode & GR_READ ? " reading" : "",
65539+ reqmode & GR_WRITE ? " writing" : reqmode &
65540+ GR_APPEND ? " appending" : "");
65541+ return reqmode;
65542+ } else
65543+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
65544+ {
65545+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
65546+ reqmode & GR_READ ? " reading" : "",
65547+ reqmode & GR_WRITE ? " writing" : reqmode &
65548+ GR_APPEND ? " appending" : "");
65549+ return 0;
65550+ } else if (unlikely((mode & reqmode) != reqmode))
65551+ return 0;
65552+
65553+ return reqmode;
65554+}
65555+
65556+__u32
65557+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
65558+ const int fmode)
65559+{
65560+ __u32 mode, reqmode = GR_FIND;
65561+
65562+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
65563+ reqmode |= GR_EXEC;
65564+ if (fmode & S_IWOTH)
65565+ reqmode |= GR_WRITE;
65566+ if (fmode & S_IROTH)
65567+ reqmode |= GR_READ;
65568+
65569+ mode =
65570+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
65571+ mnt);
65572+
65573+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
65574+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
65575+ reqmode & GR_READ ? " reading" : "",
65576+ reqmode & GR_WRITE ? " writing" : "",
65577+ reqmode & GR_EXEC ? " executing" : "");
65578+ return reqmode;
65579+ } else
65580+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
65581+ {
65582+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
65583+ reqmode & GR_READ ? " reading" : "",
65584+ reqmode & GR_WRITE ? " writing" : "",
65585+ reqmode & GR_EXEC ? " executing" : "");
65586+ return 0;
65587+ } else if (unlikely((mode & reqmode) != reqmode))
65588+ return 0;
65589+
65590+ return reqmode;
65591+}
65592+
65593+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
65594+{
65595+ __u32 mode;
65596+
65597+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
65598+
65599+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
65600+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
65601+ return mode;
65602+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
65603+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
65604+ return 0;
65605+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
65606+ return 0;
65607+
65608+ return (reqmode);
65609+}
65610+
65611+__u32
65612+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
65613+{
65614+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
65615+}
65616+
65617+__u32
65618+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
65619+{
65620+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
65621+}
65622+
65623+__u32
65624+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
65625+{
65626+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
65627+}
65628+
65629+__u32
65630+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
65631+{
65632+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
65633+}
65634+
65635+__u32
65636+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
65637+ umode_t *modeptr)
65638+{
65639+ umode_t mode;
65640+
65641+ *modeptr &= ~gr_acl_umask();
65642+ mode = *modeptr;
65643+
65644+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
65645+ return 1;
65646+
65647+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
65648+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
65649+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
65650+ GR_CHMOD_ACL_MSG);
65651+ } else {
65652+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
65653+ }
65654+}
65655+
65656+__u32
65657+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
65658+{
65659+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
65660+}
65661+
65662+__u32
65663+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
65664+{
65665+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
65666+}
65667+
65668+__u32
65669+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
65670+{
65671+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
65672+}
65673+
65674+__u32
65675+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
65676+{
65677+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
65678+ GR_UNIXCONNECT_ACL_MSG);
65679+}
65680+
65681+/* hardlinks require at minimum create and link permission,
65682+ any additional privilege required is based on the
65683+ privilege of the file being linked to
65684+*/
65685+__u32
65686+gr_acl_handle_link(const struct dentry * new_dentry,
65687+ const struct dentry * parent_dentry,
65688+ const struct vfsmount * parent_mnt,
65689+ const struct dentry * old_dentry,
65690+ const struct vfsmount * old_mnt, const struct filename *to)
65691+{
65692+ __u32 mode;
65693+ __u32 needmode = GR_CREATE | GR_LINK;
65694+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
65695+
65696+ mode =
65697+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
65698+ old_mnt);
65699+
65700+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
65701+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
65702+ return mode;
65703+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
65704+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
65705+ return 0;
65706+ } else if (unlikely((mode & needmode) != needmode))
65707+ return 0;
65708+
65709+ return 1;
65710+}
65711+
65712+__u32
65713+gr_acl_handle_symlink(const struct dentry * new_dentry,
65714+ const struct dentry * parent_dentry,
65715+ const struct vfsmount * parent_mnt, const struct filename *from)
65716+{
65717+ __u32 needmode = GR_WRITE | GR_CREATE;
65718+ __u32 mode;
65719+
65720+ mode =
65721+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
65722+ GR_CREATE | GR_AUDIT_CREATE |
65723+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
65724+
65725+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
65726+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
65727+ return mode;
65728+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
65729+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
65730+ return 0;
65731+ } else if (unlikely((mode & needmode) != needmode))
65732+ return 0;
65733+
65734+ return (GR_WRITE | GR_CREATE);
65735+}
65736+
65737+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)
65738+{
65739+ __u32 mode;
65740+
65741+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
65742+
65743+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
65744+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
65745+ return mode;
65746+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
65747+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
65748+ return 0;
65749+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
65750+ return 0;
65751+
65752+ return (reqmode);
65753+}
65754+
65755+__u32
65756+gr_acl_handle_mknod(const struct dentry * new_dentry,
65757+ const struct dentry * parent_dentry,
65758+ const struct vfsmount * parent_mnt,
65759+ const int mode)
65760+{
65761+ __u32 reqmode = GR_WRITE | GR_CREATE;
65762+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
65763+ reqmode |= GR_SETID;
65764+
65765+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
65766+ reqmode, GR_MKNOD_ACL_MSG);
65767+}
65768+
65769+__u32
65770+gr_acl_handle_mkdir(const struct dentry *new_dentry,
65771+ const struct dentry *parent_dentry,
65772+ const struct vfsmount *parent_mnt)
65773+{
65774+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
65775+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
65776+}
65777+
65778+#define RENAME_CHECK_SUCCESS(old, new) \
65779+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
65780+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
65781+
65782+int
65783+gr_acl_handle_rename(struct dentry *new_dentry,
65784+ struct dentry *parent_dentry,
65785+ const struct vfsmount *parent_mnt,
65786+ struct dentry *old_dentry,
65787+ struct inode *old_parent_inode,
65788+ struct vfsmount *old_mnt, const struct filename *newname)
65789+{
65790+ __u32 comp1, comp2;
65791+ int error = 0;
65792+
65793+ if (unlikely(!gr_acl_is_enabled()))
65794+ return 0;
65795+
65796+ if (!new_dentry->d_inode) {
65797+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
65798+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
65799+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
65800+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
65801+ GR_DELETE | GR_AUDIT_DELETE |
65802+ GR_AUDIT_READ | GR_AUDIT_WRITE |
65803+ GR_SUPPRESS, old_mnt);
65804+ } else {
65805+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
65806+ GR_CREATE | GR_DELETE |
65807+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
65808+ GR_AUDIT_READ | GR_AUDIT_WRITE |
65809+ GR_SUPPRESS, parent_mnt);
65810+ comp2 =
65811+ gr_search_file(old_dentry,
65812+ GR_READ | GR_WRITE | GR_AUDIT_READ |
65813+ GR_DELETE | GR_AUDIT_DELETE |
65814+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
65815+ }
65816+
65817+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
65818+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
65819+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
65820+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
65821+ && !(comp2 & GR_SUPPRESS)) {
65822+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
65823+ error = -EACCES;
65824+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
65825+ error = -EACCES;
65826+
65827+ return error;
65828+}
65829+
65830+void
65831+gr_acl_handle_exit(void)
65832+{
65833+ u16 id;
65834+ char *rolename;
65835+
65836+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
65837+ !(current->role->roletype & GR_ROLE_PERSIST))) {
65838+ id = current->acl_role_id;
65839+ rolename = current->role->rolename;
65840+ gr_set_acls(1);
65841+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
65842+ }
65843+
65844+ gr_put_exec_file(current);
65845+ return;
65846+}
65847+
65848+int
65849+gr_acl_handle_procpidmem(const struct task_struct *task)
65850+{
65851+ if (unlikely(!gr_acl_is_enabled()))
65852+ return 0;
65853+
65854+ if (task != current && task->acl->mode & GR_PROTPROCFD)
65855+ return -EACCES;
65856+
65857+ return 0;
65858+}
65859diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
65860new file mode 100644
65861index 0000000..8132048
65862--- /dev/null
65863+++ b/grsecurity/gracl_ip.c
65864@@ -0,0 +1,387 @@
65865+#include <linux/kernel.h>
65866+#include <asm/uaccess.h>
65867+#include <asm/errno.h>
65868+#include <net/sock.h>
65869+#include <linux/file.h>
65870+#include <linux/fs.h>
65871+#include <linux/net.h>
65872+#include <linux/in.h>
65873+#include <linux/skbuff.h>
65874+#include <linux/ip.h>
65875+#include <linux/udp.h>
65876+#include <linux/types.h>
65877+#include <linux/sched.h>
65878+#include <linux/netdevice.h>
65879+#include <linux/inetdevice.h>
65880+#include <linux/gracl.h>
65881+#include <linux/grsecurity.h>
65882+#include <linux/grinternal.h>
65883+
65884+#define GR_BIND 0x01
65885+#define GR_CONNECT 0x02
65886+#define GR_INVERT 0x04
65887+#define GR_BINDOVERRIDE 0x08
65888+#define GR_CONNECTOVERRIDE 0x10
65889+#define GR_SOCK_FAMILY 0x20
65890+
65891+static const char * gr_protocols[IPPROTO_MAX] = {
65892+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
65893+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
65894+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
65895+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
65896+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
65897+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
65898+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
65899+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
65900+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
65901+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
65902+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
65903+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
65904+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
65905+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
65906+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
65907+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
65908+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
65909+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
65910+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
65911+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
65912+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
65913+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
65914+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
65915+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
65916+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
65917+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
65918+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
65919+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
65920+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
65921+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
65922+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
65923+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
65924+ };
65925+
65926+static const char * gr_socktypes[SOCK_MAX] = {
65927+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
65928+ "unknown:7", "unknown:8", "unknown:9", "packet"
65929+ };
65930+
65931+static const char * gr_sockfamilies[AF_MAX+1] = {
65932+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
65933+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
65934+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
65935+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
65936+ };
65937+
65938+const char *
65939+gr_proto_to_name(unsigned char proto)
65940+{
65941+ return gr_protocols[proto];
65942+}
65943+
65944+const char *
65945+gr_socktype_to_name(unsigned char type)
65946+{
65947+ return gr_socktypes[type];
65948+}
65949+
65950+const char *
65951+gr_sockfamily_to_name(unsigned char family)
65952+{
65953+ return gr_sockfamilies[family];
65954+}
65955+
65956+int
65957+gr_search_socket(const int domain, const int type, const int protocol)
65958+{
65959+ struct acl_subject_label *curr;
65960+ const struct cred *cred = current_cred();
65961+
65962+ if (unlikely(!gr_acl_is_enabled()))
65963+ goto exit;
65964+
65965+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
65966+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
65967+ goto exit; // let the kernel handle it
65968+
65969+ curr = current->acl;
65970+
65971+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
65972+ /* the family is allowed, if this is PF_INET allow it only if
65973+ the extra sock type/protocol checks pass */
65974+ if (domain == PF_INET)
65975+ goto inet_check;
65976+ goto exit;
65977+ } else {
65978+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
65979+ __u32 fakeip = 0;
65980+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
65981+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
65982+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
65983+ gr_to_filename(current->exec_file->f_path.dentry,
65984+ current->exec_file->f_path.mnt) :
65985+ curr->filename, curr->filename,
65986+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
65987+ &current->signal->saved_ip);
65988+ goto exit;
65989+ }
65990+ goto exit_fail;
65991+ }
65992+
65993+inet_check:
65994+ /* the rest of this checking is for IPv4 only */
65995+ if (!curr->ips)
65996+ goto exit;
65997+
65998+ if ((curr->ip_type & (1U << type)) &&
65999+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
66000+ goto exit;
66001+
66002+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66003+ /* we don't place acls on raw sockets , and sometimes
66004+ dgram/ip sockets are opened for ioctl and not
66005+ bind/connect, so we'll fake a bind learn log */
66006+ if (type == SOCK_RAW || type == SOCK_PACKET) {
66007+ __u32 fakeip = 0;
66008+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66009+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66010+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66011+ gr_to_filename(current->exec_file->f_path.dentry,
66012+ current->exec_file->f_path.mnt) :
66013+ curr->filename, curr->filename,
66014+ &fakeip, 0, type,
66015+ protocol, GR_CONNECT, &current->signal->saved_ip);
66016+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
66017+ __u32 fakeip = 0;
66018+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66019+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66020+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66021+ gr_to_filename(current->exec_file->f_path.dentry,
66022+ current->exec_file->f_path.mnt) :
66023+ curr->filename, curr->filename,
66024+ &fakeip, 0, type,
66025+ protocol, GR_BIND, &current->signal->saved_ip);
66026+ }
66027+ /* we'll log when they use connect or bind */
66028+ goto exit;
66029+ }
66030+
66031+exit_fail:
66032+ if (domain == PF_INET)
66033+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
66034+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
66035+ else
66036+#ifndef CONFIG_IPV6
66037+ if (domain != PF_INET6)
66038+#endif
66039+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
66040+ gr_socktype_to_name(type), protocol);
66041+
66042+ return 0;
66043+exit:
66044+ return 1;
66045+}
66046+
66047+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)
66048+{
66049+ if ((ip->mode & mode) &&
66050+ (ip_port >= ip->low) &&
66051+ (ip_port <= ip->high) &&
66052+ ((ntohl(ip_addr) & our_netmask) ==
66053+ (ntohl(our_addr) & our_netmask))
66054+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
66055+ && (ip->type & (1U << type))) {
66056+ if (ip->mode & GR_INVERT)
66057+ return 2; // specifically denied
66058+ else
66059+ return 1; // allowed
66060+ }
66061+
66062+ return 0; // not specifically allowed, may continue parsing
66063+}
66064+
66065+static int
66066+gr_search_connectbind(const int full_mode, struct sock *sk,
66067+ struct sockaddr_in *addr, const int type)
66068+{
66069+ char iface[IFNAMSIZ] = {0};
66070+ struct acl_subject_label *curr;
66071+ struct acl_ip_label *ip;
66072+ struct inet_sock *isk;
66073+ struct net_device *dev;
66074+ struct in_device *idev;
66075+ unsigned long i;
66076+ int ret;
66077+ int mode = full_mode & (GR_BIND | GR_CONNECT);
66078+ __u32 ip_addr = 0;
66079+ __u32 our_addr;
66080+ __u32 our_netmask;
66081+ char *p;
66082+ __u16 ip_port = 0;
66083+ const struct cred *cred = current_cred();
66084+
66085+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
66086+ return 0;
66087+
66088+ curr = current->acl;
66089+ isk = inet_sk(sk);
66090+
66091+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
66092+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
66093+ addr->sin_addr.s_addr = curr->inaddr_any_override;
66094+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
66095+ struct sockaddr_in saddr;
66096+ int err;
66097+
66098+ saddr.sin_family = AF_INET;
66099+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
66100+ saddr.sin_port = isk->inet_sport;
66101+
66102+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66103+ if (err)
66104+ return err;
66105+
66106+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66107+ if (err)
66108+ return err;
66109+ }
66110+
66111+ if (!curr->ips)
66112+ return 0;
66113+
66114+ ip_addr = addr->sin_addr.s_addr;
66115+ ip_port = ntohs(addr->sin_port);
66116+
66117+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66118+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66119+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66120+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66121+ gr_to_filename(current->exec_file->f_path.dentry,
66122+ current->exec_file->f_path.mnt) :
66123+ curr->filename, curr->filename,
66124+ &ip_addr, ip_port, type,
66125+ sk->sk_protocol, mode, &current->signal->saved_ip);
66126+ return 0;
66127+ }
66128+
66129+ for (i = 0; i < curr->ip_num; i++) {
66130+ ip = *(curr->ips + i);
66131+ if (ip->iface != NULL) {
66132+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
66133+ p = strchr(iface, ':');
66134+ if (p != NULL)
66135+ *p = '\0';
66136+ dev = dev_get_by_name(sock_net(sk), iface);
66137+ if (dev == NULL)
66138+ continue;
66139+ idev = in_dev_get(dev);
66140+ if (idev == NULL) {
66141+ dev_put(dev);
66142+ continue;
66143+ }
66144+ rcu_read_lock();
66145+ for_ifa(idev) {
66146+ if (!strcmp(ip->iface, ifa->ifa_label)) {
66147+ our_addr = ifa->ifa_address;
66148+ our_netmask = 0xffffffff;
66149+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66150+ if (ret == 1) {
66151+ rcu_read_unlock();
66152+ in_dev_put(idev);
66153+ dev_put(dev);
66154+ return 0;
66155+ } else if (ret == 2) {
66156+ rcu_read_unlock();
66157+ in_dev_put(idev);
66158+ dev_put(dev);
66159+ goto denied;
66160+ }
66161+ }
66162+ } endfor_ifa(idev);
66163+ rcu_read_unlock();
66164+ in_dev_put(idev);
66165+ dev_put(dev);
66166+ } else {
66167+ our_addr = ip->addr;
66168+ our_netmask = ip->netmask;
66169+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66170+ if (ret == 1)
66171+ return 0;
66172+ else if (ret == 2)
66173+ goto denied;
66174+ }
66175+ }
66176+
66177+denied:
66178+ if (mode == GR_BIND)
66179+ 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));
66180+ else if (mode == GR_CONNECT)
66181+ 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));
66182+
66183+ return -EACCES;
66184+}
66185+
66186+int
66187+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
66188+{
66189+ /* always allow disconnection of dgram sockets with connect */
66190+ if (addr->sin_family == AF_UNSPEC)
66191+ return 0;
66192+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
66193+}
66194+
66195+int
66196+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
66197+{
66198+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
66199+}
66200+
66201+int gr_search_listen(struct socket *sock)
66202+{
66203+ struct sock *sk = sock->sk;
66204+ struct sockaddr_in addr;
66205+
66206+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66207+ addr.sin_port = inet_sk(sk)->inet_sport;
66208+
66209+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66210+}
66211+
66212+int gr_search_accept(struct socket *sock)
66213+{
66214+ struct sock *sk = sock->sk;
66215+ struct sockaddr_in addr;
66216+
66217+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66218+ addr.sin_port = inet_sk(sk)->inet_sport;
66219+
66220+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66221+}
66222+
66223+int
66224+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
66225+{
66226+ if (addr)
66227+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
66228+ else {
66229+ struct sockaddr_in sin;
66230+ const struct inet_sock *inet = inet_sk(sk);
66231+
66232+ sin.sin_addr.s_addr = inet->inet_daddr;
66233+ sin.sin_port = inet->inet_dport;
66234+
66235+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66236+ }
66237+}
66238+
66239+int
66240+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
66241+{
66242+ struct sockaddr_in sin;
66243+
66244+ if (unlikely(skb->len < sizeof (struct udphdr)))
66245+ return 0; // skip this packet
66246+
66247+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
66248+ sin.sin_port = udp_hdr(skb)->source;
66249+
66250+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66251+}
66252diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
66253new file mode 100644
66254index 0000000..25f54ef
66255--- /dev/null
66256+++ b/grsecurity/gracl_learn.c
66257@@ -0,0 +1,207 @@
66258+#include <linux/kernel.h>
66259+#include <linux/mm.h>
66260+#include <linux/sched.h>
66261+#include <linux/poll.h>
66262+#include <linux/string.h>
66263+#include <linux/file.h>
66264+#include <linux/types.h>
66265+#include <linux/vmalloc.h>
66266+#include <linux/grinternal.h>
66267+
66268+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
66269+ size_t count, loff_t *ppos);
66270+extern int gr_acl_is_enabled(void);
66271+
66272+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
66273+static int gr_learn_attached;
66274+
66275+/* use a 512k buffer */
66276+#define LEARN_BUFFER_SIZE (512 * 1024)
66277+
66278+static DEFINE_SPINLOCK(gr_learn_lock);
66279+static DEFINE_MUTEX(gr_learn_user_mutex);
66280+
66281+/* we need to maintain two buffers, so that the kernel context of grlearn
66282+ uses a semaphore around the userspace copying, and the other kernel contexts
66283+ use a spinlock when copying into the buffer, since they cannot sleep
66284+*/
66285+static char *learn_buffer;
66286+static char *learn_buffer_user;
66287+static int learn_buffer_len;
66288+static int learn_buffer_user_len;
66289+
66290+static ssize_t
66291+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
66292+{
66293+ DECLARE_WAITQUEUE(wait, current);
66294+ ssize_t retval = 0;
66295+
66296+ add_wait_queue(&learn_wait, &wait);
66297+ set_current_state(TASK_INTERRUPTIBLE);
66298+ do {
66299+ mutex_lock(&gr_learn_user_mutex);
66300+ spin_lock(&gr_learn_lock);
66301+ if (learn_buffer_len)
66302+ break;
66303+ spin_unlock(&gr_learn_lock);
66304+ mutex_unlock(&gr_learn_user_mutex);
66305+ if (file->f_flags & O_NONBLOCK) {
66306+ retval = -EAGAIN;
66307+ goto out;
66308+ }
66309+ if (signal_pending(current)) {
66310+ retval = -ERESTARTSYS;
66311+ goto out;
66312+ }
66313+
66314+ schedule();
66315+ } while (1);
66316+
66317+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
66318+ learn_buffer_user_len = learn_buffer_len;
66319+ retval = learn_buffer_len;
66320+ learn_buffer_len = 0;
66321+
66322+ spin_unlock(&gr_learn_lock);
66323+
66324+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
66325+ retval = -EFAULT;
66326+
66327+ mutex_unlock(&gr_learn_user_mutex);
66328+out:
66329+ set_current_state(TASK_RUNNING);
66330+ remove_wait_queue(&learn_wait, &wait);
66331+ return retval;
66332+}
66333+
66334+static unsigned int
66335+poll_learn(struct file * file, poll_table * wait)
66336+{
66337+ poll_wait(file, &learn_wait, wait);
66338+
66339+ if (learn_buffer_len)
66340+ return (POLLIN | POLLRDNORM);
66341+
66342+ return 0;
66343+}
66344+
66345+void
66346+gr_clear_learn_entries(void)
66347+{
66348+ char *tmp;
66349+
66350+ mutex_lock(&gr_learn_user_mutex);
66351+ spin_lock(&gr_learn_lock);
66352+ tmp = learn_buffer;
66353+ learn_buffer = NULL;
66354+ spin_unlock(&gr_learn_lock);
66355+ if (tmp)
66356+ vfree(tmp);
66357+ if (learn_buffer_user != NULL) {
66358+ vfree(learn_buffer_user);
66359+ learn_buffer_user = NULL;
66360+ }
66361+ learn_buffer_len = 0;
66362+ mutex_unlock(&gr_learn_user_mutex);
66363+
66364+ return;
66365+}
66366+
66367+void
66368+gr_add_learn_entry(const char *fmt, ...)
66369+{
66370+ va_list args;
66371+ unsigned int len;
66372+
66373+ if (!gr_learn_attached)
66374+ return;
66375+
66376+ spin_lock(&gr_learn_lock);
66377+
66378+ /* leave a gap at the end so we know when it's "full" but don't have to
66379+ compute the exact length of the string we're trying to append
66380+ */
66381+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
66382+ spin_unlock(&gr_learn_lock);
66383+ wake_up_interruptible(&learn_wait);
66384+ return;
66385+ }
66386+ if (learn_buffer == NULL) {
66387+ spin_unlock(&gr_learn_lock);
66388+ return;
66389+ }
66390+
66391+ va_start(args, fmt);
66392+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
66393+ va_end(args);
66394+
66395+ learn_buffer_len += len + 1;
66396+
66397+ spin_unlock(&gr_learn_lock);
66398+ wake_up_interruptible(&learn_wait);
66399+
66400+ return;
66401+}
66402+
66403+static int
66404+open_learn(struct inode *inode, struct file *file)
66405+{
66406+ if (file->f_mode & FMODE_READ && gr_learn_attached)
66407+ return -EBUSY;
66408+ if (file->f_mode & FMODE_READ) {
66409+ int retval = 0;
66410+ mutex_lock(&gr_learn_user_mutex);
66411+ if (learn_buffer == NULL)
66412+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
66413+ if (learn_buffer_user == NULL)
66414+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
66415+ if (learn_buffer == NULL) {
66416+ retval = -ENOMEM;
66417+ goto out_error;
66418+ }
66419+ if (learn_buffer_user == NULL) {
66420+ retval = -ENOMEM;
66421+ goto out_error;
66422+ }
66423+ learn_buffer_len = 0;
66424+ learn_buffer_user_len = 0;
66425+ gr_learn_attached = 1;
66426+out_error:
66427+ mutex_unlock(&gr_learn_user_mutex);
66428+ return retval;
66429+ }
66430+ return 0;
66431+}
66432+
66433+static int
66434+close_learn(struct inode *inode, struct file *file)
66435+{
66436+ if (file->f_mode & FMODE_READ) {
66437+ char *tmp = NULL;
66438+ mutex_lock(&gr_learn_user_mutex);
66439+ spin_lock(&gr_learn_lock);
66440+ tmp = learn_buffer;
66441+ learn_buffer = NULL;
66442+ spin_unlock(&gr_learn_lock);
66443+ if (tmp)
66444+ vfree(tmp);
66445+ if (learn_buffer_user != NULL) {
66446+ vfree(learn_buffer_user);
66447+ learn_buffer_user = NULL;
66448+ }
66449+ learn_buffer_len = 0;
66450+ learn_buffer_user_len = 0;
66451+ gr_learn_attached = 0;
66452+ mutex_unlock(&gr_learn_user_mutex);
66453+ }
66454+
66455+ return 0;
66456+}
66457+
66458+const struct file_operations grsec_fops = {
66459+ .read = read_learn,
66460+ .write = write_grsec_handler,
66461+ .open = open_learn,
66462+ .release = close_learn,
66463+ .poll = poll_learn,
66464+};
66465diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
66466new file mode 100644
66467index 0000000..39645c9
66468--- /dev/null
66469+++ b/grsecurity/gracl_res.c
66470@@ -0,0 +1,68 @@
66471+#include <linux/kernel.h>
66472+#include <linux/sched.h>
66473+#include <linux/gracl.h>
66474+#include <linux/grinternal.h>
66475+
66476+static const char *restab_log[] = {
66477+ [RLIMIT_CPU] = "RLIMIT_CPU",
66478+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
66479+ [RLIMIT_DATA] = "RLIMIT_DATA",
66480+ [RLIMIT_STACK] = "RLIMIT_STACK",
66481+ [RLIMIT_CORE] = "RLIMIT_CORE",
66482+ [RLIMIT_RSS] = "RLIMIT_RSS",
66483+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
66484+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
66485+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
66486+ [RLIMIT_AS] = "RLIMIT_AS",
66487+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
66488+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
66489+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
66490+ [RLIMIT_NICE] = "RLIMIT_NICE",
66491+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
66492+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
66493+ [GR_CRASH_RES] = "RLIMIT_CRASH"
66494+};
66495+
66496+void
66497+gr_log_resource(const struct task_struct *task,
66498+ const int res, const unsigned long wanted, const int gt)
66499+{
66500+ const struct cred *cred;
66501+ unsigned long rlim;
66502+
66503+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
66504+ return;
66505+
66506+ // not yet supported resource
66507+ if (unlikely(!restab_log[res]))
66508+ return;
66509+
66510+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
66511+ rlim = task_rlimit_max(task, res);
66512+ else
66513+ rlim = task_rlimit(task, res);
66514+
66515+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
66516+ return;
66517+
66518+ rcu_read_lock();
66519+ cred = __task_cred(task);
66520+
66521+ if (res == RLIMIT_NPROC &&
66522+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
66523+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
66524+ goto out_rcu_unlock;
66525+ else if (res == RLIMIT_MEMLOCK &&
66526+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
66527+ goto out_rcu_unlock;
66528+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
66529+ goto out_rcu_unlock;
66530+ rcu_read_unlock();
66531+
66532+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
66533+
66534+ return;
66535+out_rcu_unlock:
66536+ rcu_read_unlock();
66537+ return;
66538+}
66539diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
66540new file mode 100644
66541index 0000000..3c38bfe
66542--- /dev/null
66543+++ b/grsecurity/gracl_segv.c
66544@@ -0,0 +1,305 @@
66545+#include <linux/kernel.h>
66546+#include <linux/mm.h>
66547+#include <asm/uaccess.h>
66548+#include <asm/errno.h>
66549+#include <asm/mman.h>
66550+#include <net/sock.h>
66551+#include <linux/file.h>
66552+#include <linux/fs.h>
66553+#include <linux/net.h>
66554+#include <linux/in.h>
66555+#include <linux/slab.h>
66556+#include <linux/types.h>
66557+#include <linux/sched.h>
66558+#include <linux/timer.h>
66559+#include <linux/gracl.h>
66560+#include <linux/grsecurity.h>
66561+#include <linux/grinternal.h>
66562+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66563+#include <linux/magic.h>
66564+#include <linux/pagemap.h>
66565+#include "../fs/btrfs/async-thread.h"
66566+#include "../fs/btrfs/ctree.h"
66567+#include "../fs/btrfs/btrfs_inode.h"
66568+#endif
66569+
66570+static struct crash_uid *uid_set;
66571+static unsigned short uid_used;
66572+static DEFINE_SPINLOCK(gr_uid_lock);
66573+extern rwlock_t gr_inode_lock;
66574+extern struct acl_subject_label *
66575+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
66576+ struct acl_role_label *role);
66577+
66578+static inline dev_t __get_dev(const struct dentry *dentry)
66579+{
66580+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66581+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66582+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66583+ else
66584+#endif
66585+ return dentry->d_sb->s_dev;
66586+}
66587+
66588+int
66589+gr_init_uidset(void)
66590+{
66591+ uid_set =
66592+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
66593+ uid_used = 0;
66594+
66595+ return uid_set ? 1 : 0;
66596+}
66597+
66598+void
66599+gr_free_uidset(void)
66600+{
66601+ if (uid_set)
66602+ kfree(uid_set);
66603+
66604+ return;
66605+}
66606+
66607+int
66608+gr_find_uid(const uid_t uid)
66609+{
66610+ struct crash_uid *tmp = uid_set;
66611+ uid_t buid;
66612+ int low = 0, high = uid_used - 1, mid;
66613+
66614+ while (high >= low) {
66615+ mid = (low + high) >> 1;
66616+ buid = tmp[mid].uid;
66617+ if (buid == uid)
66618+ return mid;
66619+ if (buid > uid)
66620+ high = mid - 1;
66621+ if (buid < uid)
66622+ low = mid + 1;
66623+ }
66624+
66625+ return -1;
66626+}
66627+
66628+static __inline__ void
66629+gr_insertsort(void)
66630+{
66631+ unsigned short i, j;
66632+ struct crash_uid index;
66633+
66634+ for (i = 1; i < uid_used; i++) {
66635+ index = uid_set[i];
66636+ j = i;
66637+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
66638+ uid_set[j] = uid_set[j - 1];
66639+ j--;
66640+ }
66641+ uid_set[j] = index;
66642+ }
66643+
66644+ return;
66645+}
66646+
66647+static __inline__ void
66648+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
66649+{
66650+ int loc;
66651+ uid_t uid = GR_GLOBAL_UID(kuid);
66652+
66653+ if (uid_used == GR_UIDTABLE_MAX)
66654+ return;
66655+
66656+ loc = gr_find_uid(uid);
66657+
66658+ if (loc >= 0) {
66659+ uid_set[loc].expires = expires;
66660+ return;
66661+ }
66662+
66663+ uid_set[uid_used].uid = uid;
66664+ uid_set[uid_used].expires = expires;
66665+ uid_used++;
66666+
66667+ gr_insertsort();
66668+
66669+ return;
66670+}
66671+
66672+void
66673+gr_remove_uid(const unsigned short loc)
66674+{
66675+ unsigned short i;
66676+
66677+ for (i = loc + 1; i < uid_used; i++)
66678+ uid_set[i - 1] = uid_set[i];
66679+
66680+ uid_used--;
66681+
66682+ return;
66683+}
66684+
66685+int
66686+gr_check_crash_uid(const kuid_t kuid)
66687+{
66688+ int loc;
66689+ int ret = 0;
66690+ uid_t uid;
66691+
66692+ if (unlikely(!gr_acl_is_enabled()))
66693+ return 0;
66694+
66695+ uid = GR_GLOBAL_UID(kuid);
66696+
66697+ spin_lock(&gr_uid_lock);
66698+ loc = gr_find_uid(uid);
66699+
66700+ if (loc < 0)
66701+ goto out_unlock;
66702+
66703+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
66704+ gr_remove_uid(loc);
66705+ else
66706+ ret = 1;
66707+
66708+out_unlock:
66709+ spin_unlock(&gr_uid_lock);
66710+ return ret;
66711+}
66712+
66713+static __inline__ int
66714+proc_is_setxid(const struct cred *cred)
66715+{
66716+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
66717+ !uid_eq(cred->uid, cred->fsuid))
66718+ return 1;
66719+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
66720+ !gid_eq(cred->gid, cred->fsgid))
66721+ return 1;
66722+
66723+ return 0;
66724+}
66725+
66726+extern int gr_fake_force_sig(int sig, struct task_struct *t);
66727+
66728+void
66729+gr_handle_crash(struct task_struct *task, const int sig)
66730+{
66731+ struct acl_subject_label *curr;
66732+ struct task_struct *tsk, *tsk2;
66733+ const struct cred *cred;
66734+ const struct cred *cred2;
66735+
66736+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
66737+ return;
66738+
66739+ if (unlikely(!gr_acl_is_enabled()))
66740+ return;
66741+
66742+ curr = task->acl;
66743+
66744+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
66745+ return;
66746+
66747+ if (time_before_eq(curr->expires, get_seconds())) {
66748+ curr->expires = 0;
66749+ curr->crashes = 0;
66750+ }
66751+
66752+ curr->crashes++;
66753+
66754+ if (!curr->expires)
66755+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
66756+
66757+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
66758+ time_after(curr->expires, get_seconds())) {
66759+ rcu_read_lock();
66760+ cred = __task_cred(task);
66761+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
66762+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
66763+ spin_lock(&gr_uid_lock);
66764+ gr_insert_uid(cred->uid, curr->expires);
66765+ spin_unlock(&gr_uid_lock);
66766+ curr->expires = 0;
66767+ curr->crashes = 0;
66768+ read_lock(&tasklist_lock);
66769+ do_each_thread(tsk2, tsk) {
66770+ cred2 = __task_cred(tsk);
66771+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
66772+ gr_fake_force_sig(SIGKILL, tsk);
66773+ } while_each_thread(tsk2, tsk);
66774+ read_unlock(&tasklist_lock);
66775+ } else {
66776+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
66777+ read_lock(&tasklist_lock);
66778+ read_lock(&grsec_exec_file_lock);
66779+ do_each_thread(tsk2, tsk) {
66780+ if (likely(tsk != task)) {
66781+ // if this thread has the same subject as the one that triggered
66782+ // RES_CRASH and it's the same binary, kill it
66783+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
66784+ gr_fake_force_sig(SIGKILL, tsk);
66785+ }
66786+ } while_each_thread(tsk2, tsk);
66787+ read_unlock(&grsec_exec_file_lock);
66788+ read_unlock(&tasklist_lock);
66789+ }
66790+ rcu_read_unlock();
66791+ }
66792+
66793+ return;
66794+}
66795+
66796+int
66797+gr_check_crash_exec(const struct file *filp)
66798+{
66799+ struct acl_subject_label *curr;
66800+
66801+ if (unlikely(!gr_acl_is_enabled()))
66802+ return 0;
66803+
66804+ read_lock(&gr_inode_lock);
66805+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
66806+ __get_dev(filp->f_path.dentry),
66807+ current->role);
66808+ read_unlock(&gr_inode_lock);
66809+
66810+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
66811+ (!curr->crashes && !curr->expires))
66812+ return 0;
66813+
66814+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
66815+ time_after(curr->expires, get_seconds()))
66816+ return 1;
66817+ else if (time_before_eq(curr->expires, get_seconds())) {
66818+ curr->crashes = 0;
66819+ curr->expires = 0;
66820+ }
66821+
66822+ return 0;
66823+}
66824+
66825+void
66826+gr_handle_alertkill(struct task_struct *task)
66827+{
66828+ struct acl_subject_label *curracl;
66829+ __u32 curr_ip;
66830+ struct task_struct *p, *p2;
66831+
66832+ if (unlikely(!gr_acl_is_enabled()))
66833+ return;
66834+
66835+ curracl = task->acl;
66836+ curr_ip = task->signal->curr_ip;
66837+
66838+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
66839+ read_lock(&tasklist_lock);
66840+ do_each_thread(p2, p) {
66841+ if (p->signal->curr_ip == curr_ip)
66842+ gr_fake_force_sig(SIGKILL, p);
66843+ } while_each_thread(p2, p);
66844+ read_unlock(&tasklist_lock);
66845+ } else if (curracl->mode & GR_KILLPROC)
66846+ gr_fake_force_sig(SIGKILL, task);
66847+
66848+ return;
66849+}
66850diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
66851new file mode 100644
66852index 0000000..98011b0
66853--- /dev/null
66854+++ b/grsecurity/gracl_shm.c
66855@@ -0,0 +1,40 @@
66856+#include <linux/kernel.h>
66857+#include <linux/mm.h>
66858+#include <linux/sched.h>
66859+#include <linux/file.h>
66860+#include <linux/ipc.h>
66861+#include <linux/gracl.h>
66862+#include <linux/grsecurity.h>
66863+#include <linux/grinternal.h>
66864+
66865+int
66866+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66867+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
66868+{
66869+ struct task_struct *task;
66870+
66871+ if (!gr_acl_is_enabled())
66872+ return 1;
66873+
66874+ rcu_read_lock();
66875+ read_lock(&tasklist_lock);
66876+
66877+ task = find_task_by_vpid(shm_cprid);
66878+
66879+ if (unlikely(!task))
66880+ task = find_task_by_vpid(shm_lapid);
66881+
66882+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
66883+ (task_pid_nr(task) == shm_lapid)) &&
66884+ (task->acl->mode & GR_PROTSHM) &&
66885+ (task->acl != current->acl))) {
66886+ read_unlock(&tasklist_lock);
66887+ rcu_read_unlock();
66888+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
66889+ return 0;
66890+ }
66891+ read_unlock(&tasklist_lock);
66892+ rcu_read_unlock();
66893+
66894+ return 1;
66895+}
66896diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
66897new file mode 100644
66898index 0000000..bc0be01
66899--- /dev/null
66900+++ b/grsecurity/grsec_chdir.c
66901@@ -0,0 +1,19 @@
66902+#include <linux/kernel.h>
66903+#include <linux/sched.h>
66904+#include <linux/fs.h>
66905+#include <linux/file.h>
66906+#include <linux/grsecurity.h>
66907+#include <linux/grinternal.h>
66908+
66909+void
66910+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
66911+{
66912+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66913+ if ((grsec_enable_chdir && grsec_enable_group &&
66914+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
66915+ !grsec_enable_group)) {
66916+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
66917+ }
66918+#endif
66919+ return;
66920+}
66921diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
66922new file mode 100644
66923index 0000000..bd6e105
66924--- /dev/null
66925+++ b/grsecurity/grsec_chroot.c
66926@@ -0,0 +1,370 @@
66927+#include <linux/kernel.h>
66928+#include <linux/module.h>
66929+#include <linux/sched.h>
66930+#include <linux/file.h>
66931+#include <linux/fs.h>
66932+#include <linux/mount.h>
66933+#include <linux/types.h>
66934+#include "../fs/mount.h"
66935+#include <linux/grsecurity.h>
66936+#include <linux/grinternal.h>
66937+
66938+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
66939+static int gr_init_ran;
66940+#endif
66941+
66942+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
66943+{
66944+#ifdef CONFIG_GRKERNSEC
66945+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
66946+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
66947+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
66948+ && gr_init_ran
66949+#endif
66950+ )
66951+ task->gr_is_chrooted = 1;
66952+ else {
66953+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
66954+ if (task_pid_nr(task) == 1 && !gr_init_ran)
66955+ gr_init_ran = 1;
66956+#endif
66957+ task->gr_is_chrooted = 0;
66958+ }
66959+
66960+ task->gr_chroot_dentry = path->dentry;
66961+#endif
66962+ return;
66963+}
66964+
66965+void gr_clear_chroot_entries(struct task_struct *task)
66966+{
66967+#ifdef CONFIG_GRKERNSEC
66968+ task->gr_is_chrooted = 0;
66969+ task->gr_chroot_dentry = NULL;
66970+#endif
66971+ return;
66972+}
66973+
66974+int
66975+gr_handle_chroot_unix(const pid_t pid)
66976+{
66977+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66978+ struct task_struct *p;
66979+
66980+ if (unlikely(!grsec_enable_chroot_unix))
66981+ return 1;
66982+
66983+ if (likely(!proc_is_chrooted(current)))
66984+ return 1;
66985+
66986+ rcu_read_lock();
66987+ read_lock(&tasklist_lock);
66988+ p = find_task_by_vpid_unrestricted(pid);
66989+ if (unlikely(p && !have_same_root(current, p))) {
66990+ read_unlock(&tasklist_lock);
66991+ rcu_read_unlock();
66992+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
66993+ return 0;
66994+ }
66995+ read_unlock(&tasklist_lock);
66996+ rcu_read_unlock();
66997+#endif
66998+ return 1;
66999+}
67000+
67001+int
67002+gr_handle_chroot_nice(void)
67003+{
67004+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
67005+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
67006+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
67007+ return -EPERM;
67008+ }
67009+#endif
67010+ return 0;
67011+}
67012+
67013+int
67014+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
67015+{
67016+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
67017+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
67018+ && proc_is_chrooted(current)) {
67019+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
67020+ return -EACCES;
67021+ }
67022+#endif
67023+ return 0;
67024+}
67025+
67026+int
67027+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
67028+{
67029+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67030+ struct task_struct *p;
67031+ int ret = 0;
67032+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
67033+ return ret;
67034+
67035+ read_lock(&tasklist_lock);
67036+ do_each_pid_task(pid, type, p) {
67037+ if (!have_same_root(current, p)) {
67038+ ret = 1;
67039+ goto out;
67040+ }
67041+ } while_each_pid_task(pid, type, p);
67042+out:
67043+ read_unlock(&tasklist_lock);
67044+ return ret;
67045+#endif
67046+ return 0;
67047+}
67048+
67049+int
67050+gr_pid_is_chrooted(struct task_struct *p)
67051+{
67052+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67053+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
67054+ return 0;
67055+
67056+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
67057+ !have_same_root(current, p)) {
67058+ return 1;
67059+ }
67060+#endif
67061+ return 0;
67062+}
67063+
67064+EXPORT_SYMBOL(gr_pid_is_chrooted);
67065+
67066+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
67067+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
67068+{
67069+ struct path path, currentroot;
67070+ int ret = 0;
67071+
67072+ path.dentry = (struct dentry *)u_dentry;
67073+ path.mnt = (struct vfsmount *)u_mnt;
67074+ get_fs_root(current->fs, &currentroot);
67075+ if (path_is_under(&path, &currentroot))
67076+ ret = 1;
67077+ path_put(&currentroot);
67078+
67079+ return ret;
67080+}
67081+#endif
67082+
67083+int
67084+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
67085+{
67086+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
67087+ if (!grsec_enable_chroot_fchdir)
67088+ return 1;
67089+
67090+ if (!proc_is_chrooted(current))
67091+ return 1;
67092+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
67093+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
67094+ return 0;
67095+ }
67096+#endif
67097+ return 1;
67098+}
67099+
67100+int
67101+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67102+ const time_t shm_createtime)
67103+{
67104+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
67105+ struct task_struct *p;
67106+ time_t starttime;
67107+
67108+ if (unlikely(!grsec_enable_chroot_shmat))
67109+ return 1;
67110+
67111+ if (likely(!proc_is_chrooted(current)))
67112+ return 1;
67113+
67114+ rcu_read_lock();
67115+ read_lock(&tasklist_lock);
67116+
67117+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
67118+ starttime = p->start_time.tv_sec;
67119+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
67120+ if (have_same_root(current, p)) {
67121+ goto allow;
67122+ } else {
67123+ read_unlock(&tasklist_lock);
67124+ rcu_read_unlock();
67125+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
67126+ return 0;
67127+ }
67128+ }
67129+ /* creator exited, pid reuse, fall through to next check */
67130+ }
67131+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
67132+ if (unlikely(!have_same_root(current, p))) {
67133+ read_unlock(&tasklist_lock);
67134+ rcu_read_unlock();
67135+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
67136+ return 0;
67137+ }
67138+ }
67139+
67140+allow:
67141+ read_unlock(&tasklist_lock);
67142+ rcu_read_unlock();
67143+#endif
67144+ return 1;
67145+}
67146+
67147+void
67148+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
67149+{
67150+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
67151+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
67152+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
67153+#endif
67154+ return;
67155+}
67156+
67157+int
67158+gr_handle_chroot_mknod(const struct dentry *dentry,
67159+ const struct vfsmount *mnt, const int mode)
67160+{
67161+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
67162+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
67163+ proc_is_chrooted(current)) {
67164+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
67165+ return -EPERM;
67166+ }
67167+#endif
67168+ return 0;
67169+}
67170+
67171+int
67172+gr_handle_chroot_mount(const struct dentry *dentry,
67173+ const struct vfsmount *mnt, const char *dev_name)
67174+{
67175+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
67176+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
67177+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
67178+ return -EPERM;
67179+ }
67180+#endif
67181+ return 0;
67182+}
67183+
67184+int
67185+gr_handle_chroot_pivot(void)
67186+{
67187+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
67188+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
67189+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
67190+ return -EPERM;
67191+ }
67192+#endif
67193+ return 0;
67194+}
67195+
67196+int
67197+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
67198+{
67199+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
67200+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
67201+ !gr_is_outside_chroot(dentry, mnt)) {
67202+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
67203+ return -EPERM;
67204+ }
67205+#endif
67206+ return 0;
67207+}
67208+
67209+extern const char *captab_log[];
67210+extern int captab_log_entries;
67211+
67212+int
67213+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
67214+{
67215+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67216+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
67217+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
67218+ if (cap_raised(chroot_caps, cap)) {
67219+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
67220+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
67221+ }
67222+ return 0;
67223+ }
67224+ }
67225+#endif
67226+ return 1;
67227+}
67228+
67229+int
67230+gr_chroot_is_capable(const int cap)
67231+{
67232+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67233+ return gr_task_chroot_is_capable(current, current_cred(), cap);
67234+#endif
67235+ return 1;
67236+}
67237+
67238+int
67239+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
67240+{
67241+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67242+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
67243+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
67244+ if (cap_raised(chroot_caps, cap)) {
67245+ return 0;
67246+ }
67247+ }
67248+#endif
67249+ return 1;
67250+}
67251+
67252+int
67253+gr_chroot_is_capable_nolog(const int cap)
67254+{
67255+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67256+ return gr_task_chroot_is_capable_nolog(current, cap);
67257+#endif
67258+ return 1;
67259+}
67260+
67261+int
67262+gr_handle_chroot_sysctl(const int op)
67263+{
67264+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
67265+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
67266+ proc_is_chrooted(current))
67267+ return -EACCES;
67268+#endif
67269+ return 0;
67270+}
67271+
67272+void
67273+gr_handle_chroot_chdir(const struct path *path)
67274+{
67275+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
67276+ if (grsec_enable_chroot_chdir)
67277+ set_fs_pwd(current->fs, path);
67278+#endif
67279+ return;
67280+}
67281+
67282+int
67283+gr_handle_chroot_chmod(const struct dentry *dentry,
67284+ const struct vfsmount *mnt, const int mode)
67285+{
67286+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
67287+ /* allow chmod +s on directories, but not files */
67288+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
67289+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
67290+ proc_is_chrooted(current)) {
67291+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
67292+ return -EPERM;
67293+ }
67294+#endif
67295+ return 0;
67296+}
67297diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
67298new file mode 100644
67299index 0000000..ce65ceb
67300--- /dev/null
67301+++ b/grsecurity/grsec_disabled.c
67302@@ -0,0 +1,434 @@
67303+#include <linux/kernel.h>
67304+#include <linux/module.h>
67305+#include <linux/sched.h>
67306+#include <linux/file.h>
67307+#include <linux/fs.h>
67308+#include <linux/kdev_t.h>
67309+#include <linux/net.h>
67310+#include <linux/in.h>
67311+#include <linux/ip.h>
67312+#include <linux/skbuff.h>
67313+#include <linux/sysctl.h>
67314+
67315+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
67316+void
67317+pax_set_initial_flags(struct linux_binprm *bprm)
67318+{
67319+ return;
67320+}
67321+#endif
67322+
67323+#ifdef CONFIG_SYSCTL
67324+__u32
67325+gr_handle_sysctl(const struct ctl_table * table, const int op)
67326+{
67327+ return 0;
67328+}
67329+#endif
67330+
67331+#ifdef CONFIG_TASKSTATS
67332+int gr_is_taskstats_denied(int pid)
67333+{
67334+ return 0;
67335+}
67336+#endif
67337+
67338+int
67339+gr_acl_is_enabled(void)
67340+{
67341+ return 0;
67342+}
67343+
67344+void
67345+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67346+{
67347+ return;
67348+}
67349+
67350+int
67351+gr_handle_rawio(const struct inode *inode)
67352+{
67353+ return 0;
67354+}
67355+
67356+void
67357+gr_acl_handle_psacct(struct task_struct *task, const long code)
67358+{
67359+ return;
67360+}
67361+
67362+int
67363+gr_handle_ptrace(struct task_struct *task, const long request)
67364+{
67365+ return 0;
67366+}
67367+
67368+int
67369+gr_handle_proc_ptrace(struct task_struct *task)
67370+{
67371+ return 0;
67372+}
67373+
67374+int
67375+gr_set_acls(const int type)
67376+{
67377+ return 0;
67378+}
67379+
67380+int
67381+gr_check_hidden_task(const struct task_struct *tsk)
67382+{
67383+ return 0;
67384+}
67385+
67386+int
67387+gr_check_protected_task(const struct task_struct *task)
67388+{
67389+ return 0;
67390+}
67391+
67392+int
67393+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67394+{
67395+ return 0;
67396+}
67397+
67398+void
67399+gr_copy_label(struct task_struct *tsk)
67400+{
67401+ return;
67402+}
67403+
67404+void
67405+gr_set_pax_flags(struct task_struct *task)
67406+{
67407+ return;
67408+}
67409+
67410+int
67411+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67412+ const int unsafe_share)
67413+{
67414+ return 0;
67415+}
67416+
67417+void
67418+gr_handle_delete(const ino_t ino, const dev_t dev)
67419+{
67420+ return;
67421+}
67422+
67423+void
67424+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67425+{
67426+ return;
67427+}
67428+
67429+void
67430+gr_handle_crash(struct task_struct *task, const int sig)
67431+{
67432+ return;
67433+}
67434+
67435+int
67436+gr_check_crash_exec(const struct file *filp)
67437+{
67438+ return 0;
67439+}
67440+
67441+int
67442+gr_check_crash_uid(const kuid_t uid)
67443+{
67444+ return 0;
67445+}
67446+
67447+void
67448+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67449+ struct dentry *old_dentry,
67450+ struct dentry *new_dentry,
67451+ struct vfsmount *mnt, const __u8 replace)
67452+{
67453+ return;
67454+}
67455+
67456+int
67457+gr_search_socket(const int family, const int type, const int protocol)
67458+{
67459+ return 1;
67460+}
67461+
67462+int
67463+gr_search_connectbind(const int mode, const struct socket *sock,
67464+ const struct sockaddr_in *addr)
67465+{
67466+ return 0;
67467+}
67468+
67469+void
67470+gr_handle_alertkill(struct task_struct *task)
67471+{
67472+ return;
67473+}
67474+
67475+__u32
67476+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
67477+{
67478+ return 1;
67479+}
67480+
67481+__u32
67482+gr_acl_handle_hidden_file(const struct dentry * dentry,
67483+ const struct vfsmount * mnt)
67484+{
67485+ return 1;
67486+}
67487+
67488+__u32
67489+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
67490+ int acc_mode)
67491+{
67492+ return 1;
67493+}
67494+
67495+__u32
67496+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67497+{
67498+ return 1;
67499+}
67500+
67501+__u32
67502+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
67503+{
67504+ return 1;
67505+}
67506+
67507+int
67508+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
67509+ unsigned int *vm_flags)
67510+{
67511+ return 1;
67512+}
67513+
67514+__u32
67515+gr_acl_handle_truncate(const struct dentry * dentry,
67516+ const struct vfsmount * mnt)
67517+{
67518+ return 1;
67519+}
67520+
67521+__u32
67522+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
67523+{
67524+ return 1;
67525+}
67526+
67527+__u32
67528+gr_acl_handle_access(const struct dentry * dentry,
67529+ const struct vfsmount * mnt, const int fmode)
67530+{
67531+ return 1;
67532+}
67533+
67534+__u32
67535+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
67536+ umode_t *mode)
67537+{
67538+ return 1;
67539+}
67540+
67541+__u32
67542+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
67543+{
67544+ return 1;
67545+}
67546+
67547+__u32
67548+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
67549+{
67550+ return 1;
67551+}
67552+
67553+void
67554+grsecurity_init(void)
67555+{
67556+ return;
67557+}
67558+
67559+umode_t gr_acl_umask(void)
67560+{
67561+ return 0;
67562+}
67563+
67564+__u32
67565+gr_acl_handle_mknod(const struct dentry * new_dentry,
67566+ const struct dentry * parent_dentry,
67567+ const struct vfsmount * parent_mnt,
67568+ const int mode)
67569+{
67570+ return 1;
67571+}
67572+
67573+__u32
67574+gr_acl_handle_mkdir(const struct dentry * new_dentry,
67575+ const struct dentry * parent_dentry,
67576+ const struct vfsmount * parent_mnt)
67577+{
67578+ return 1;
67579+}
67580+
67581+__u32
67582+gr_acl_handle_symlink(const struct dentry * new_dentry,
67583+ const struct dentry * parent_dentry,
67584+ const struct vfsmount * parent_mnt, const struct filename *from)
67585+{
67586+ return 1;
67587+}
67588+
67589+__u32
67590+gr_acl_handle_link(const struct dentry * new_dentry,
67591+ const struct dentry * parent_dentry,
67592+ const struct vfsmount * parent_mnt,
67593+ const struct dentry * old_dentry,
67594+ const struct vfsmount * old_mnt, const struct filename *to)
67595+{
67596+ return 1;
67597+}
67598+
67599+int
67600+gr_acl_handle_rename(const struct dentry *new_dentry,
67601+ const struct dentry *parent_dentry,
67602+ const struct vfsmount *parent_mnt,
67603+ const struct dentry *old_dentry,
67604+ const struct inode *old_parent_inode,
67605+ const struct vfsmount *old_mnt, const struct filename *newname)
67606+{
67607+ return 0;
67608+}
67609+
67610+int
67611+gr_acl_handle_filldir(const struct file *file, const char *name,
67612+ const int namelen, const ino_t ino)
67613+{
67614+ return 1;
67615+}
67616+
67617+int
67618+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67619+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
67620+{
67621+ return 1;
67622+}
67623+
67624+int
67625+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
67626+{
67627+ return 0;
67628+}
67629+
67630+int
67631+gr_search_accept(const struct socket *sock)
67632+{
67633+ return 0;
67634+}
67635+
67636+int
67637+gr_search_listen(const struct socket *sock)
67638+{
67639+ return 0;
67640+}
67641+
67642+int
67643+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
67644+{
67645+ return 0;
67646+}
67647+
67648+__u32
67649+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
67650+{
67651+ return 1;
67652+}
67653+
67654+__u32
67655+gr_acl_handle_creat(const struct dentry * dentry,
67656+ const struct dentry * p_dentry,
67657+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
67658+ const int imode)
67659+{
67660+ return 1;
67661+}
67662+
67663+void
67664+gr_acl_handle_exit(void)
67665+{
67666+ return;
67667+}
67668+
67669+int
67670+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67671+{
67672+ return 1;
67673+}
67674+
67675+void
67676+gr_set_role_label(const kuid_t uid, const kgid_t gid)
67677+{
67678+ return;
67679+}
67680+
67681+int
67682+gr_acl_handle_procpidmem(const struct task_struct *task)
67683+{
67684+ return 0;
67685+}
67686+
67687+int
67688+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
67689+{
67690+ return 0;
67691+}
67692+
67693+int
67694+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
67695+{
67696+ return 0;
67697+}
67698+
67699+void
67700+gr_set_kernel_label(struct task_struct *task)
67701+{
67702+ return;
67703+}
67704+
67705+int
67706+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67707+{
67708+ return 0;
67709+}
67710+
67711+int
67712+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67713+{
67714+ return 0;
67715+}
67716+
67717+int gr_acl_enable_at_secure(void)
67718+{
67719+ return 0;
67720+}
67721+
67722+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67723+{
67724+ return dentry->d_sb->s_dev;
67725+}
67726+
67727+void gr_put_exec_file(struct task_struct *task)
67728+{
67729+ return;
67730+}
67731+
67732+EXPORT_SYMBOL(gr_set_kernel_label);
67733+#ifdef CONFIG_SECURITY
67734+EXPORT_SYMBOL(gr_check_user_change);
67735+EXPORT_SYMBOL(gr_check_group_change);
67736+#endif
67737diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
67738new file mode 100644
67739index 0000000..387032b
67740--- /dev/null
67741+++ b/grsecurity/grsec_exec.c
67742@@ -0,0 +1,187 @@
67743+#include <linux/kernel.h>
67744+#include <linux/sched.h>
67745+#include <linux/file.h>
67746+#include <linux/binfmts.h>
67747+#include <linux/fs.h>
67748+#include <linux/types.h>
67749+#include <linux/grdefs.h>
67750+#include <linux/grsecurity.h>
67751+#include <linux/grinternal.h>
67752+#include <linux/capability.h>
67753+#include <linux/module.h>
67754+#include <linux/compat.h>
67755+
67756+#include <asm/uaccess.h>
67757+
67758+#ifdef CONFIG_GRKERNSEC_EXECLOG
67759+static char gr_exec_arg_buf[132];
67760+static DEFINE_MUTEX(gr_exec_arg_mutex);
67761+#endif
67762+
67763+struct user_arg_ptr {
67764+#ifdef CONFIG_COMPAT
67765+ bool is_compat;
67766+#endif
67767+ union {
67768+ const char __user *const __user *native;
67769+#ifdef CONFIG_COMPAT
67770+ const compat_uptr_t __user *compat;
67771+#endif
67772+ } ptr;
67773+};
67774+
67775+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
67776+
67777+void
67778+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
67779+{
67780+#ifdef CONFIG_GRKERNSEC_EXECLOG
67781+ char *grarg = gr_exec_arg_buf;
67782+ unsigned int i, x, execlen = 0;
67783+ char c;
67784+
67785+ if (!((grsec_enable_execlog && grsec_enable_group &&
67786+ in_group_p(grsec_audit_gid))
67787+ || (grsec_enable_execlog && !grsec_enable_group)))
67788+ return;
67789+
67790+ mutex_lock(&gr_exec_arg_mutex);
67791+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
67792+
67793+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
67794+ const char __user *p;
67795+ unsigned int len;
67796+
67797+ p = get_user_arg_ptr(argv, i);
67798+ if (IS_ERR(p))
67799+ goto log;
67800+
67801+ len = strnlen_user(p, 128 - execlen);
67802+ if (len > 128 - execlen)
67803+ len = 128 - execlen;
67804+ else if (len > 0)
67805+ len--;
67806+ if (copy_from_user(grarg + execlen, p, len))
67807+ goto log;
67808+
67809+ /* rewrite unprintable characters */
67810+ for (x = 0; x < len; x++) {
67811+ c = *(grarg + execlen + x);
67812+ if (c < 32 || c > 126)
67813+ *(grarg + execlen + x) = ' ';
67814+ }
67815+
67816+ execlen += len;
67817+ *(grarg + execlen) = ' ';
67818+ *(grarg + execlen + 1) = '\0';
67819+ execlen++;
67820+ }
67821+
67822+ log:
67823+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
67824+ bprm->file->f_path.mnt, grarg);
67825+ mutex_unlock(&gr_exec_arg_mutex);
67826+#endif
67827+ return;
67828+}
67829+
67830+#ifdef CONFIG_GRKERNSEC
67831+extern int gr_acl_is_capable(const int cap);
67832+extern int gr_acl_is_capable_nolog(const int cap);
67833+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
67834+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
67835+extern int gr_chroot_is_capable(const int cap);
67836+extern int gr_chroot_is_capable_nolog(const int cap);
67837+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
67838+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
67839+#endif
67840+
67841+const char *captab_log[] = {
67842+ "CAP_CHOWN",
67843+ "CAP_DAC_OVERRIDE",
67844+ "CAP_DAC_READ_SEARCH",
67845+ "CAP_FOWNER",
67846+ "CAP_FSETID",
67847+ "CAP_KILL",
67848+ "CAP_SETGID",
67849+ "CAP_SETUID",
67850+ "CAP_SETPCAP",
67851+ "CAP_LINUX_IMMUTABLE",
67852+ "CAP_NET_BIND_SERVICE",
67853+ "CAP_NET_BROADCAST",
67854+ "CAP_NET_ADMIN",
67855+ "CAP_NET_RAW",
67856+ "CAP_IPC_LOCK",
67857+ "CAP_IPC_OWNER",
67858+ "CAP_SYS_MODULE",
67859+ "CAP_SYS_RAWIO",
67860+ "CAP_SYS_CHROOT",
67861+ "CAP_SYS_PTRACE",
67862+ "CAP_SYS_PACCT",
67863+ "CAP_SYS_ADMIN",
67864+ "CAP_SYS_BOOT",
67865+ "CAP_SYS_NICE",
67866+ "CAP_SYS_RESOURCE",
67867+ "CAP_SYS_TIME",
67868+ "CAP_SYS_TTY_CONFIG",
67869+ "CAP_MKNOD",
67870+ "CAP_LEASE",
67871+ "CAP_AUDIT_WRITE",
67872+ "CAP_AUDIT_CONTROL",
67873+ "CAP_SETFCAP",
67874+ "CAP_MAC_OVERRIDE",
67875+ "CAP_MAC_ADMIN",
67876+ "CAP_SYSLOG",
67877+ "CAP_WAKE_ALARM"
67878+};
67879+
67880+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
67881+
67882+int gr_is_capable(const int cap)
67883+{
67884+#ifdef CONFIG_GRKERNSEC
67885+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
67886+ return 1;
67887+ return 0;
67888+#else
67889+ return 1;
67890+#endif
67891+}
67892+
67893+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
67894+{
67895+#ifdef CONFIG_GRKERNSEC
67896+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
67897+ return 1;
67898+ return 0;
67899+#else
67900+ return 1;
67901+#endif
67902+}
67903+
67904+int gr_is_capable_nolog(const int cap)
67905+{
67906+#ifdef CONFIG_GRKERNSEC
67907+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
67908+ return 1;
67909+ return 0;
67910+#else
67911+ return 1;
67912+#endif
67913+}
67914+
67915+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
67916+{
67917+#ifdef CONFIG_GRKERNSEC
67918+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
67919+ return 1;
67920+ return 0;
67921+#else
67922+ return 1;
67923+#endif
67924+}
67925+
67926+EXPORT_SYMBOL(gr_is_capable);
67927+EXPORT_SYMBOL(gr_is_capable_nolog);
67928+EXPORT_SYMBOL(gr_task_is_capable);
67929+EXPORT_SYMBOL(gr_task_is_capable_nolog);
67930diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
67931new file mode 100644
67932index 0000000..06cc6ea
67933--- /dev/null
67934+++ b/grsecurity/grsec_fifo.c
67935@@ -0,0 +1,24 @@
67936+#include <linux/kernel.h>
67937+#include <linux/sched.h>
67938+#include <linux/fs.h>
67939+#include <linux/file.h>
67940+#include <linux/grinternal.h>
67941+
67942+int
67943+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
67944+ const struct dentry *dir, const int flag, const int acc_mode)
67945+{
67946+#ifdef CONFIG_GRKERNSEC_FIFO
67947+ const struct cred *cred = current_cred();
67948+
67949+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
67950+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
67951+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
67952+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
67953+ if (!inode_permission(dentry->d_inode, acc_mode))
67954+ 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));
67955+ return -EACCES;
67956+ }
67957+#endif
67958+ return 0;
67959+}
67960diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
67961new file mode 100644
67962index 0000000..8ca18bf
67963--- /dev/null
67964+++ b/grsecurity/grsec_fork.c
67965@@ -0,0 +1,23 @@
67966+#include <linux/kernel.h>
67967+#include <linux/sched.h>
67968+#include <linux/grsecurity.h>
67969+#include <linux/grinternal.h>
67970+#include <linux/errno.h>
67971+
67972+void
67973+gr_log_forkfail(const int retval)
67974+{
67975+#ifdef CONFIG_GRKERNSEC_FORKFAIL
67976+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
67977+ switch (retval) {
67978+ case -EAGAIN:
67979+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
67980+ break;
67981+ case -ENOMEM:
67982+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
67983+ break;
67984+ }
67985+ }
67986+#endif
67987+ return;
67988+}
67989diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
67990new file mode 100644
67991index 0000000..ab2d875
67992--- /dev/null
67993+++ b/grsecurity/grsec_init.c
67994@@ -0,0 +1,279 @@
67995+#include <linux/kernel.h>
67996+#include <linux/sched.h>
67997+#include <linux/mm.h>
67998+#include <linux/gracl.h>
67999+#include <linux/slab.h>
68000+#include <linux/vmalloc.h>
68001+#include <linux/percpu.h>
68002+#include <linux/module.h>
68003+
68004+int grsec_enable_ptrace_readexec;
68005+int grsec_enable_setxid;
68006+int grsec_enable_symlinkown;
68007+kgid_t grsec_symlinkown_gid;
68008+int grsec_enable_brute;
68009+int grsec_enable_link;
68010+int grsec_enable_dmesg;
68011+int grsec_enable_harden_ptrace;
68012+int grsec_enable_fifo;
68013+int grsec_enable_execlog;
68014+int grsec_enable_signal;
68015+int grsec_enable_forkfail;
68016+int grsec_enable_audit_ptrace;
68017+int grsec_enable_time;
68018+int grsec_enable_group;
68019+kgid_t grsec_audit_gid;
68020+int grsec_enable_chdir;
68021+int grsec_enable_mount;
68022+int grsec_enable_rofs;
68023+int grsec_enable_chroot_findtask;
68024+int grsec_enable_chroot_mount;
68025+int grsec_enable_chroot_shmat;
68026+int grsec_enable_chroot_fchdir;
68027+int grsec_enable_chroot_double;
68028+int grsec_enable_chroot_pivot;
68029+int grsec_enable_chroot_chdir;
68030+int grsec_enable_chroot_chmod;
68031+int grsec_enable_chroot_mknod;
68032+int grsec_enable_chroot_nice;
68033+int grsec_enable_chroot_execlog;
68034+int grsec_enable_chroot_caps;
68035+int grsec_enable_chroot_sysctl;
68036+int grsec_enable_chroot_unix;
68037+int grsec_enable_tpe;
68038+kgid_t grsec_tpe_gid;
68039+int grsec_enable_blackhole;
68040+#ifdef CONFIG_IPV6_MODULE
68041+EXPORT_SYMBOL(grsec_enable_blackhole);
68042+#endif
68043+int grsec_lastack_retries;
68044+int grsec_enable_tpe_all;
68045+int grsec_enable_tpe_invert;
68046+int grsec_enable_socket_all;
68047+kgid_t grsec_socket_all_gid;
68048+int grsec_enable_socket_client;
68049+kgid_t grsec_socket_client_gid;
68050+int grsec_enable_socket_server;
68051+kgid_t grsec_socket_server_gid;
68052+int grsec_resource_logging;
68053+int grsec_disable_privio;
68054+int grsec_enable_log_rwxmaps;
68055+int grsec_lock;
68056+
68057+DEFINE_SPINLOCK(grsec_alert_lock);
68058+unsigned long grsec_alert_wtime = 0;
68059+unsigned long grsec_alert_fyet = 0;
68060+
68061+DEFINE_SPINLOCK(grsec_audit_lock);
68062+
68063+DEFINE_RWLOCK(grsec_exec_file_lock);
68064+
68065+char *gr_shared_page[4];
68066+
68067+char *gr_alert_log_fmt;
68068+char *gr_audit_log_fmt;
68069+char *gr_alert_log_buf;
68070+char *gr_audit_log_buf;
68071+
68072+extern struct gr_arg *gr_usermode;
68073+extern unsigned char *gr_system_salt;
68074+extern unsigned char *gr_system_sum;
68075+
68076+void __init
68077+grsecurity_init(void)
68078+{
68079+ int j;
68080+ /* create the per-cpu shared pages */
68081+
68082+#ifdef CONFIG_X86
68083+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
68084+#endif
68085+
68086+ for (j = 0; j < 4; j++) {
68087+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
68088+ if (gr_shared_page[j] == NULL) {
68089+ panic("Unable to allocate grsecurity shared page");
68090+ return;
68091+ }
68092+ }
68093+
68094+ /* allocate log buffers */
68095+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
68096+ if (!gr_alert_log_fmt) {
68097+ panic("Unable to allocate grsecurity alert log format buffer");
68098+ return;
68099+ }
68100+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
68101+ if (!gr_audit_log_fmt) {
68102+ panic("Unable to allocate grsecurity audit log format buffer");
68103+ return;
68104+ }
68105+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
68106+ if (!gr_alert_log_buf) {
68107+ panic("Unable to allocate grsecurity alert log buffer");
68108+ return;
68109+ }
68110+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
68111+ if (!gr_audit_log_buf) {
68112+ panic("Unable to allocate grsecurity audit log buffer");
68113+ return;
68114+ }
68115+
68116+ /* allocate memory for authentication structure */
68117+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
68118+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
68119+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
68120+
68121+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
68122+ panic("Unable to allocate grsecurity authentication structure");
68123+ return;
68124+ }
68125+
68126+
68127+#ifdef CONFIG_GRKERNSEC_IO
68128+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
68129+ grsec_disable_privio = 1;
68130+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
68131+ grsec_disable_privio = 1;
68132+#else
68133+ grsec_disable_privio = 0;
68134+#endif
68135+#endif
68136+
68137+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
68138+ /* for backward compatibility, tpe_invert always defaults to on if
68139+ enabled in the kernel
68140+ */
68141+ grsec_enable_tpe_invert = 1;
68142+#endif
68143+
68144+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
68145+#ifndef CONFIG_GRKERNSEC_SYSCTL
68146+ grsec_lock = 1;
68147+#endif
68148+
68149+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
68150+ grsec_enable_log_rwxmaps = 1;
68151+#endif
68152+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
68153+ grsec_enable_group = 1;
68154+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
68155+#endif
68156+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
68157+ grsec_enable_ptrace_readexec = 1;
68158+#endif
68159+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68160+ grsec_enable_chdir = 1;
68161+#endif
68162+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68163+ grsec_enable_harden_ptrace = 1;
68164+#endif
68165+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
68166+ grsec_enable_mount = 1;
68167+#endif
68168+#ifdef CONFIG_GRKERNSEC_LINK
68169+ grsec_enable_link = 1;
68170+#endif
68171+#ifdef CONFIG_GRKERNSEC_BRUTE
68172+ grsec_enable_brute = 1;
68173+#endif
68174+#ifdef CONFIG_GRKERNSEC_DMESG
68175+ grsec_enable_dmesg = 1;
68176+#endif
68177+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68178+ grsec_enable_blackhole = 1;
68179+ grsec_lastack_retries = 4;
68180+#endif
68181+#ifdef CONFIG_GRKERNSEC_FIFO
68182+ grsec_enable_fifo = 1;
68183+#endif
68184+#ifdef CONFIG_GRKERNSEC_EXECLOG
68185+ grsec_enable_execlog = 1;
68186+#endif
68187+#ifdef CONFIG_GRKERNSEC_SETXID
68188+ grsec_enable_setxid = 1;
68189+#endif
68190+#ifdef CONFIG_GRKERNSEC_SIGNAL
68191+ grsec_enable_signal = 1;
68192+#endif
68193+#ifdef CONFIG_GRKERNSEC_FORKFAIL
68194+ grsec_enable_forkfail = 1;
68195+#endif
68196+#ifdef CONFIG_GRKERNSEC_TIME
68197+ grsec_enable_time = 1;
68198+#endif
68199+#ifdef CONFIG_GRKERNSEC_RESLOG
68200+ grsec_resource_logging = 1;
68201+#endif
68202+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68203+ grsec_enable_chroot_findtask = 1;
68204+#endif
68205+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68206+ grsec_enable_chroot_unix = 1;
68207+#endif
68208+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68209+ grsec_enable_chroot_mount = 1;
68210+#endif
68211+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68212+ grsec_enable_chroot_fchdir = 1;
68213+#endif
68214+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68215+ grsec_enable_chroot_shmat = 1;
68216+#endif
68217+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
68218+ grsec_enable_audit_ptrace = 1;
68219+#endif
68220+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68221+ grsec_enable_chroot_double = 1;
68222+#endif
68223+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68224+ grsec_enable_chroot_pivot = 1;
68225+#endif
68226+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68227+ grsec_enable_chroot_chdir = 1;
68228+#endif
68229+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68230+ grsec_enable_chroot_chmod = 1;
68231+#endif
68232+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68233+ grsec_enable_chroot_mknod = 1;
68234+#endif
68235+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68236+ grsec_enable_chroot_nice = 1;
68237+#endif
68238+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68239+ grsec_enable_chroot_execlog = 1;
68240+#endif
68241+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68242+ grsec_enable_chroot_caps = 1;
68243+#endif
68244+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68245+ grsec_enable_chroot_sysctl = 1;
68246+#endif
68247+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
68248+ grsec_enable_symlinkown = 1;
68249+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
68250+#endif
68251+#ifdef CONFIG_GRKERNSEC_TPE
68252+ grsec_enable_tpe = 1;
68253+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
68254+#ifdef CONFIG_GRKERNSEC_TPE_ALL
68255+ grsec_enable_tpe_all = 1;
68256+#endif
68257+#endif
68258+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
68259+ grsec_enable_socket_all = 1;
68260+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
68261+#endif
68262+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
68263+ grsec_enable_socket_client = 1;
68264+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
68265+#endif
68266+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
68267+ grsec_enable_socket_server = 1;
68268+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
68269+#endif
68270+#endif
68271+
68272+ return;
68273+}
68274diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
68275new file mode 100644
68276index 0000000..5e05e20
68277--- /dev/null
68278+++ b/grsecurity/grsec_link.c
68279@@ -0,0 +1,58 @@
68280+#include <linux/kernel.h>
68281+#include <linux/sched.h>
68282+#include <linux/fs.h>
68283+#include <linux/file.h>
68284+#include <linux/grinternal.h>
68285+
68286+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
68287+{
68288+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
68289+ const struct inode *link_inode = link->dentry->d_inode;
68290+
68291+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
68292+ /* ignore root-owned links, e.g. /proc/self */
68293+ gr_is_global_nonroot(link_inode->i_uid) && target &&
68294+ !uid_eq(link_inode->i_uid, target->i_uid)) {
68295+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
68296+ return 1;
68297+ }
68298+#endif
68299+ return 0;
68300+}
68301+
68302+int
68303+gr_handle_follow_link(const struct inode *parent,
68304+ const struct inode *inode,
68305+ const struct dentry *dentry, const struct vfsmount *mnt)
68306+{
68307+#ifdef CONFIG_GRKERNSEC_LINK
68308+ const struct cred *cred = current_cred();
68309+
68310+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
68311+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
68312+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
68313+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
68314+ return -EACCES;
68315+ }
68316+#endif
68317+ return 0;
68318+}
68319+
68320+int
68321+gr_handle_hardlink(const struct dentry *dentry,
68322+ const struct vfsmount *mnt,
68323+ struct inode *inode, const int mode, const struct filename *to)
68324+{
68325+#ifdef CONFIG_GRKERNSEC_LINK
68326+ const struct cred *cred = current_cred();
68327+
68328+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
68329+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
68330+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
68331+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
68332+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
68333+ return -EPERM;
68334+ }
68335+#endif
68336+ return 0;
68337+}
68338diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
68339new file mode 100644
68340index 0000000..dbe0a6b
68341--- /dev/null
68342+++ b/grsecurity/grsec_log.c
68343@@ -0,0 +1,341 @@
68344+#include <linux/kernel.h>
68345+#include <linux/sched.h>
68346+#include <linux/file.h>
68347+#include <linux/tty.h>
68348+#include <linux/fs.h>
68349+#include <linux/mm.h>
68350+#include <linux/grinternal.h>
68351+
68352+#ifdef CONFIG_TREE_PREEMPT_RCU
68353+#define DISABLE_PREEMPT() preempt_disable()
68354+#define ENABLE_PREEMPT() preempt_enable()
68355+#else
68356+#define DISABLE_PREEMPT()
68357+#define ENABLE_PREEMPT()
68358+#endif
68359+
68360+#define BEGIN_LOCKS(x) \
68361+ DISABLE_PREEMPT(); \
68362+ rcu_read_lock(); \
68363+ read_lock(&tasklist_lock); \
68364+ read_lock(&grsec_exec_file_lock); \
68365+ if (x != GR_DO_AUDIT) \
68366+ spin_lock(&grsec_alert_lock); \
68367+ else \
68368+ spin_lock(&grsec_audit_lock)
68369+
68370+#define END_LOCKS(x) \
68371+ if (x != GR_DO_AUDIT) \
68372+ spin_unlock(&grsec_alert_lock); \
68373+ else \
68374+ spin_unlock(&grsec_audit_lock); \
68375+ read_unlock(&grsec_exec_file_lock); \
68376+ read_unlock(&tasklist_lock); \
68377+ rcu_read_unlock(); \
68378+ ENABLE_PREEMPT(); \
68379+ if (x == GR_DONT_AUDIT) \
68380+ gr_handle_alertkill(current)
68381+
68382+enum {
68383+ FLOODING,
68384+ NO_FLOODING
68385+};
68386+
68387+extern char *gr_alert_log_fmt;
68388+extern char *gr_audit_log_fmt;
68389+extern char *gr_alert_log_buf;
68390+extern char *gr_audit_log_buf;
68391+
68392+static int gr_log_start(int audit)
68393+{
68394+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
68395+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
68396+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
68397+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
68398+ unsigned long curr_secs = get_seconds();
68399+
68400+ if (audit == GR_DO_AUDIT)
68401+ goto set_fmt;
68402+
68403+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
68404+ grsec_alert_wtime = curr_secs;
68405+ grsec_alert_fyet = 0;
68406+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
68407+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
68408+ grsec_alert_fyet++;
68409+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
68410+ grsec_alert_wtime = curr_secs;
68411+ grsec_alert_fyet++;
68412+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
68413+ return FLOODING;
68414+ }
68415+ else return FLOODING;
68416+
68417+set_fmt:
68418+#endif
68419+ memset(buf, 0, PAGE_SIZE);
68420+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
68421+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
68422+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
68423+ } else if (current->signal->curr_ip) {
68424+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
68425+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
68426+ } else if (gr_acl_is_enabled()) {
68427+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
68428+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
68429+ } else {
68430+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
68431+ strcpy(buf, fmt);
68432+ }
68433+
68434+ return NO_FLOODING;
68435+}
68436+
68437+static void gr_log_middle(int audit, const char *msg, va_list ap)
68438+ __attribute__ ((format (printf, 2, 0)));
68439+
68440+static void gr_log_middle(int audit, const char *msg, va_list ap)
68441+{
68442+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
68443+ unsigned int len = strlen(buf);
68444+
68445+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
68446+
68447+ return;
68448+}
68449+
68450+static void gr_log_middle_varargs(int audit, const char *msg, ...)
68451+ __attribute__ ((format (printf, 2, 3)));
68452+
68453+static void gr_log_middle_varargs(int audit, const char *msg, ...)
68454+{
68455+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
68456+ unsigned int len = strlen(buf);
68457+ va_list ap;
68458+
68459+ va_start(ap, msg);
68460+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
68461+ va_end(ap);
68462+
68463+ return;
68464+}
68465+
68466+static void gr_log_end(int audit, int append_default)
68467+{
68468+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
68469+ if (append_default) {
68470+ struct task_struct *task = current;
68471+ struct task_struct *parent = task->real_parent;
68472+ const struct cred *cred = __task_cred(task);
68473+ const struct cred *pcred = __task_cred(parent);
68474+ unsigned int len = strlen(buf);
68475+
68476+ 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));
68477+ }
68478+
68479+ printk("%s\n", buf);
68480+
68481+ return;
68482+}
68483+
68484+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
68485+{
68486+ int logtype;
68487+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
68488+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
68489+ void *voidptr = NULL;
68490+ int num1 = 0, num2 = 0;
68491+ unsigned long ulong1 = 0, ulong2 = 0;
68492+ struct dentry *dentry = NULL;
68493+ struct vfsmount *mnt = NULL;
68494+ struct file *file = NULL;
68495+ struct task_struct *task = NULL;
68496+ struct vm_area_struct *vma = NULL;
68497+ const struct cred *cred, *pcred;
68498+ va_list ap;
68499+
68500+ BEGIN_LOCKS(audit);
68501+ logtype = gr_log_start(audit);
68502+ if (logtype == FLOODING) {
68503+ END_LOCKS(audit);
68504+ return;
68505+ }
68506+ va_start(ap, argtypes);
68507+ switch (argtypes) {
68508+ case GR_TTYSNIFF:
68509+ task = va_arg(ap, struct task_struct *);
68510+ 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));
68511+ break;
68512+ case GR_SYSCTL_HIDDEN:
68513+ str1 = va_arg(ap, char *);
68514+ gr_log_middle_varargs(audit, msg, result, str1);
68515+ break;
68516+ case GR_RBAC:
68517+ dentry = va_arg(ap, struct dentry *);
68518+ mnt = va_arg(ap, struct vfsmount *);
68519+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
68520+ break;
68521+ case GR_RBAC_STR:
68522+ dentry = va_arg(ap, struct dentry *);
68523+ mnt = va_arg(ap, struct vfsmount *);
68524+ str1 = va_arg(ap, char *);
68525+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
68526+ break;
68527+ case GR_STR_RBAC:
68528+ str1 = va_arg(ap, char *);
68529+ dentry = va_arg(ap, struct dentry *);
68530+ mnt = va_arg(ap, struct vfsmount *);
68531+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
68532+ break;
68533+ case GR_RBAC_MODE2:
68534+ dentry = va_arg(ap, struct dentry *);
68535+ mnt = va_arg(ap, struct vfsmount *);
68536+ str1 = va_arg(ap, char *);
68537+ str2 = va_arg(ap, char *);
68538+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
68539+ break;
68540+ case GR_RBAC_MODE3:
68541+ dentry = va_arg(ap, struct dentry *);
68542+ mnt = va_arg(ap, struct vfsmount *);
68543+ str1 = va_arg(ap, char *);
68544+ str2 = va_arg(ap, char *);
68545+ str3 = va_arg(ap, char *);
68546+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
68547+ break;
68548+ case GR_FILENAME:
68549+ dentry = va_arg(ap, struct dentry *);
68550+ mnt = va_arg(ap, struct vfsmount *);
68551+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
68552+ break;
68553+ case GR_STR_FILENAME:
68554+ str1 = va_arg(ap, char *);
68555+ dentry = va_arg(ap, struct dentry *);
68556+ mnt = va_arg(ap, struct vfsmount *);
68557+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
68558+ break;
68559+ case GR_FILENAME_STR:
68560+ dentry = va_arg(ap, struct dentry *);
68561+ mnt = va_arg(ap, struct vfsmount *);
68562+ str1 = va_arg(ap, char *);
68563+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
68564+ break;
68565+ case GR_FILENAME_TWO_INT:
68566+ dentry = va_arg(ap, struct dentry *);
68567+ mnt = va_arg(ap, struct vfsmount *);
68568+ num1 = va_arg(ap, int);
68569+ num2 = va_arg(ap, int);
68570+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
68571+ break;
68572+ case GR_FILENAME_TWO_INT_STR:
68573+ dentry = va_arg(ap, struct dentry *);
68574+ mnt = va_arg(ap, struct vfsmount *);
68575+ num1 = va_arg(ap, int);
68576+ num2 = va_arg(ap, int);
68577+ str1 = va_arg(ap, char *);
68578+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
68579+ break;
68580+ case GR_TEXTREL:
68581+ file = va_arg(ap, struct file *);
68582+ ulong1 = va_arg(ap, unsigned long);
68583+ ulong2 = va_arg(ap, unsigned long);
68584+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
68585+ break;
68586+ case GR_PTRACE:
68587+ task = va_arg(ap, struct task_struct *);
68588+ 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));
68589+ break;
68590+ case GR_RESOURCE:
68591+ task = va_arg(ap, struct task_struct *);
68592+ cred = __task_cred(task);
68593+ pcred = __task_cred(task->real_parent);
68594+ ulong1 = va_arg(ap, unsigned long);
68595+ str1 = va_arg(ap, char *);
68596+ ulong2 = va_arg(ap, unsigned long);
68597+ 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));
68598+ break;
68599+ case GR_CAP:
68600+ task = va_arg(ap, struct task_struct *);
68601+ cred = __task_cred(task);
68602+ pcred = __task_cred(task->real_parent);
68603+ str1 = va_arg(ap, char *);
68604+ 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));
68605+ break;
68606+ case GR_SIG:
68607+ str1 = va_arg(ap, char *);
68608+ voidptr = va_arg(ap, void *);
68609+ gr_log_middle_varargs(audit, msg, str1, voidptr);
68610+ break;
68611+ case GR_SIG2:
68612+ task = va_arg(ap, struct task_struct *);
68613+ cred = __task_cred(task);
68614+ pcred = __task_cred(task->real_parent);
68615+ num1 = va_arg(ap, int);
68616+ 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));
68617+ break;
68618+ case GR_CRASH1:
68619+ task = va_arg(ap, struct task_struct *);
68620+ cred = __task_cred(task);
68621+ pcred = __task_cred(task->real_parent);
68622+ ulong1 = va_arg(ap, unsigned long);
68623+ 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);
68624+ break;
68625+ case GR_CRASH2:
68626+ task = va_arg(ap, struct task_struct *);
68627+ cred = __task_cred(task);
68628+ pcred = __task_cred(task->real_parent);
68629+ ulong1 = va_arg(ap, unsigned long);
68630+ 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);
68631+ break;
68632+ case GR_RWXMAP:
68633+ file = va_arg(ap, struct file *);
68634+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
68635+ break;
68636+ case GR_RWXMAPVMA:
68637+ vma = va_arg(ap, struct vm_area_struct *);
68638+ if (vma->vm_file)
68639+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
68640+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
68641+ str1 = "<stack>";
68642+ else if (vma->vm_start <= current->mm->brk &&
68643+ vma->vm_end >= current->mm->start_brk)
68644+ str1 = "<heap>";
68645+ else
68646+ str1 = "<anonymous mapping>";
68647+ gr_log_middle_varargs(audit, msg, str1);
68648+ break;
68649+ case GR_PSACCT:
68650+ {
68651+ unsigned int wday, cday;
68652+ __u8 whr, chr;
68653+ __u8 wmin, cmin;
68654+ __u8 wsec, csec;
68655+ char cur_tty[64] = { 0 };
68656+ char parent_tty[64] = { 0 };
68657+
68658+ task = va_arg(ap, struct task_struct *);
68659+ wday = va_arg(ap, unsigned int);
68660+ cday = va_arg(ap, unsigned int);
68661+ whr = va_arg(ap, int);
68662+ chr = va_arg(ap, int);
68663+ wmin = va_arg(ap, int);
68664+ cmin = va_arg(ap, int);
68665+ wsec = va_arg(ap, int);
68666+ csec = va_arg(ap, int);
68667+ ulong1 = va_arg(ap, unsigned long);
68668+ cred = __task_cred(task);
68669+ pcred = __task_cred(task->real_parent);
68670+
68671+ 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));
68672+ }
68673+ break;
68674+ default:
68675+ gr_log_middle(audit, msg, ap);
68676+ }
68677+ va_end(ap);
68678+ // these don't need DEFAULTSECARGS printed on the end
68679+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
68680+ gr_log_end(audit, 0);
68681+ else
68682+ gr_log_end(audit, 1);
68683+ END_LOCKS(audit);
68684+}
68685diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
68686new file mode 100644
68687index 0000000..f536303
68688--- /dev/null
68689+++ b/grsecurity/grsec_mem.c
68690@@ -0,0 +1,40 @@
68691+#include <linux/kernel.h>
68692+#include <linux/sched.h>
68693+#include <linux/mm.h>
68694+#include <linux/mman.h>
68695+#include <linux/grinternal.h>
68696+
68697+void
68698+gr_handle_ioperm(void)
68699+{
68700+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
68701+ return;
68702+}
68703+
68704+void
68705+gr_handle_iopl(void)
68706+{
68707+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
68708+ return;
68709+}
68710+
68711+void
68712+gr_handle_mem_readwrite(u64 from, u64 to)
68713+{
68714+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
68715+ return;
68716+}
68717+
68718+void
68719+gr_handle_vm86(void)
68720+{
68721+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
68722+ return;
68723+}
68724+
68725+void
68726+gr_log_badprocpid(const char *entry)
68727+{
68728+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
68729+ return;
68730+}
68731diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
68732new file mode 100644
68733index 0000000..2131422
68734--- /dev/null
68735+++ b/grsecurity/grsec_mount.c
68736@@ -0,0 +1,62 @@
68737+#include <linux/kernel.h>
68738+#include <linux/sched.h>
68739+#include <linux/mount.h>
68740+#include <linux/grsecurity.h>
68741+#include <linux/grinternal.h>
68742+
68743+void
68744+gr_log_remount(const char *devname, const int retval)
68745+{
68746+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
68747+ if (grsec_enable_mount && (retval >= 0))
68748+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
68749+#endif
68750+ return;
68751+}
68752+
68753+void
68754+gr_log_unmount(const char *devname, const int retval)
68755+{
68756+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
68757+ if (grsec_enable_mount && (retval >= 0))
68758+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
68759+#endif
68760+ return;
68761+}
68762+
68763+void
68764+gr_log_mount(const char *from, const char *to, const int retval)
68765+{
68766+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
68767+ if (grsec_enable_mount && (retval >= 0))
68768+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
68769+#endif
68770+ return;
68771+}
68772+
68773+int
68774+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
68775+{
68776+#ifdef CONFIG_GRKERNSEC_ROFS
68777+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
68778+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
68779+ return -EPERM;
68780+ } else
68781+ return 0;
68782+#endif
68783+ return 0;
68784+}
68785+
68786+int
68787+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
68788+{
68789+#ifdef CONFIG_GRKERNSEC_ROFS
68790+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
68791+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
68792+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
68793+ return -EPERM;
68794+ } else
68795+ return 0;
68796+#endif
68797+ return 0;
68798+}
68799diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
68800new file mode 100644
68801index 0000000..6ee9d50
68802--- /dev/null
68803+++ b/grsecurity/grsec_pax.c
68804@@ -0,0 +1,45 @@
68805+#include <linux/kernel.h>
68806+#include <linux/sched.h>
68807+#include <linux/mm.h>
68808+#include <linux/file.h>
68809+#include <linux/grinternal.h>
68810+#include <linux/grsecurity.h>
68811+
68812+void
68813+gr_log_textrel(struct vm_area_struct * vma)
68814+{
68815+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
68816+ if (grsec_enable_log_rwxmaps)
68817+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
68818+#endif
68819+ return;
68820+}
68821+
68822+void gr_log_ptgnustack(struct file *file)
68823+{
68824+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
68825+ if (grsec_enable_log_rwxmaps)
68826+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
68827+#endif
68828+ return;
68829+}
68830+
68831+void
68832+gr_log_rwxmmap(struct file *file)
68833+{
68834+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
68835+ if (grsec_enable_log_rwxmaps)
68836+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
68837+#endif
68838+ return;
68839+}
68840+
68841+void
68842+gr_log_rwxmprotect(struct vm_area_struct *vma)
68843+{
68844+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
68845+ if (grsec_enable_log_rwxmaps)
68846+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
68847+#endif
68848+ return;
68849+}
68850diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
68851new file mode 100644
68852index 0000000..f7f29aa
68853--- /dev/null
68854+++ b/grsecurity/grsec_ptrace.c
68855@@ -0,0 +1,30 @@
68856+#include <linux/kernel.h>
68857+#include <linux/sched.h>
68858+#include <linux/grinternal.h>
68859+#include <linux/security.h>
68860+
68861+void
68862+gr_audit_ptrace(struct task_struct *task)
68863+{
68864+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
68865+ if (grsec_enable_audit_ptrace)
68866+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
68867+#endif
68868+ return;
68869+}
68870+
68871+int
68872+gr_ptrace_readexec(struct file *file, int unsafe_flags)
68873+{
68874+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
68875+ const struct dentry *dentry = file->f_path.dentry;
68876+ const struct vfsmount *mnt = file->f_path.mnt;
68877+
68878+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
68879+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
68880+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
68881+ return -EACCES;
68882+ }
68883+#endif
68884+ return 0;
68885+}
68886diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
68887new file mode 100644
68888index 0000000..4e29cc7
68889--- /dev/null
68890+++ b/grsecurity/grsec_sig.c
68891@@ -0,0 +1,246 @@
68892+#include <linux/kernel.h>
68893+#include <linux/sched.h>
68894+#include <linux/fs.h>
68895+#include <linux/delay.h>
68896+#include <linux/grsecurity.h>
68897+#include <linux/grinternal.h>
68898+#include <linux/hardirq.h>
68899+
68900+char *signames[] = {
68901+ [SIGSEGV] = "Segmentation fault",
68902+ [SIGILL] = "Illegal instruction",
68903+ [SIGABRT] = "Abort",
68904+ [SIGBUS] = "Invalid alignment/Bus error"
68905+};
68906+
68907+void
68908+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
68909+{
68910+#ifdef CONFIG_GRKERNSEC_SIGNAL
68911+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
68912+ (sig == SIGABRT) || (sig == SIGBUS))) {
68913+ if (task_pid_nr(t) == task_pid_nr(current)) {
68914+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
68915+ } else {
68916+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
68917+ }
68918+ }
68919+#endif
68920+ return;
68921+}
68922+
68923+int
68924+gr_handle_signal(const struct task_struct *p, const int sig)
68925+{
68926+#ifdef CONFIG_GRKERNSEC
68927+ /* ignore the 0 signal for protected task checks */
68928+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
68929+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
68930+ return -EPERM;
68931+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
68932+ return -EPERM;
68933+ }
68934+#endif
68935+ return 0;
68936+}
68937+
68938+#ifdef CONFIG_GRKERNSEC
68939+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
68940+
68941+int gr_fake_force_sig(int sig, struct task_struct *t)
68942+{
68943+ unsigned long int flags;
68944+ int ret, blocked, ignored;
68945+ struct k_sigaction *action;
68946+
68947+ spin_lock_irqsave(&t->sighand->siglock, flags);
68948+ action = &t->sighand->action[sig-1];
68949+ ignored = action->sa.sa_handler == SIG_IGN;
68950+ blocked = sigismember(&t->blocked, sig);
68951+ if (blocked || ignored) {
68952+ action->sa.sa_handler = SIG_DFL;
68953+ if (blocked) {
68954+ sigdelset(&t->blocked, sig);
68955+ recalc_sigpending_and_wake(t);
68956+ }
68957+ }
68958+ if (action->sa.sa_handler == SIG_DFL)
68959+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
68960+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
68961+
68962+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
68963+
68964+ return ret;
68965+}
68966+#endif
68967+
68968+#ifdef CONFIG_GRKERNSEC_BRUTE
68969+#define GR_USER_BAN_TIME (15 * 60)
68970+#define GR_DAEMON_BRUTE_TIME (30 * 60)
68971+
68972+static int __get_dumpable(unsigned long mm_flags)
68973+{
68974+ int ret;
68975+
68976+ ret = mm_flags & MMF_DUMPABLE_MASK;
68977+ return (ret >= 2) ? 2 : ret;
68978+}
68979+#endif
68980+
68981+void gr_handle_brute_attach(unsigned long mm_flags)
68982+{
68983+#ifdef CONFIG_GRKERNSEC_BRUTE
68984+ struct task_struct *p = current;
68985+ kuid_t uid = GLOBAL_ROOT_UID;
68986+ int daemon = 0;
68987+
68988+ if (!grsec_enable_brute)
68989+ return;
68990+
68991+ rcu_read_lock();
68992+ read_lock(&tasklist_lock);
68993+ read_lock(&grsec_exec_file_lock);
68994+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
68995+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
68996+ p->real_parent->brute = 1;
68997+ daemon = 1;
68998+ } else {
68999+ const struct cred *cred = __task_cred(p), *cred2;
69000+ struct task_struct *tsk, *tsk2;
69001+
69002+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
69003+ struct user_struct *user;
69004+
69005+ uid = cred->uid;
69006+
69007+ /* this is put upon execution past expiration */
69008+ user = find_user(uid);
69009+ if (user == NULL)
69010+ goto unlock;
69011+ user->suid_banned = 1;
69012+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
69013+ if (user->suid_ban_expires == ~0UL)
69014+ user->suid_ban_expires--;
69015+
69016+ /* only kill other threads of the same binary, from the same user */
69017+ do_each_thread(tsk2, tsk) {
69018+ cred2 = __task_cred(tsk);
69019+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
69020+ gr_fake_force_sig(SIGKILL, tsk);
69021+ } while_each_thread(tsk2, tsk);
69022+ }
69023+ }
69024+unlock:
69025+ read_unlock(&grsec_exec_file_lock);
69026+ read_unlock(&tasklist_lock);
69027+ rcu_read_unlock();
69028+
69029+ if (gr_is_global_nonroot(uid))
69030+ 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);
69031+ else if (daemon)
69032+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
69033+
69034+#endif
69035+ return;
69036+}
69037+
69038+void gr_handle_brute_check(void)
69039+{
69040+#ifdef CONFIG_GRKERNSEC_BRUTE
69041+ struct task_struct *p = current;
69042+
69043+ if (unlikely(p->brute)) {
69044+ if (!grsec_enable_brute)
69045+ p->brute = 0;
69046+ else if (time_before(get_seconds(), p->brute_expires))
69047+ msleep(30 * 1000);
69048+ }
69049+#endif
69050+ return;
69051+}
69052+
69053+void gr_handle_kernel_exploit(void)
69054+{
69055+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
69056+ const struct cred *cred;
69057+ struct task_struct *tsk, *tsk2;
69058+ struct user_struct *user;
69059+ kuid_t uid;
69060+
69061+ if (in_irq() || in_serving_softirq() || in_nmi())
69062+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
69063+
69064+ uid = current_uid();
69065+
69066+ if (gr_is_global_root(uid))
69067+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
69068+ else {
69069+ /* kill all the processes of this user, hold a reference
69070+ to their creds struct, and prevent them from creating
69071+ another process until system reset
69072+ */
69073+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
69074+ GR_GLOBAL_UID(uid));
69075+ /* we intentionally leak this ref */
69076+ user = get_uid(current->cred->user);
69077+ if (user)
69078+ user->kernel_banned = 1;
69079+
69080+ /* kill all processes of this user */
69081+ read_lock(&tasklist_lock);
69082+ do_each_thread(tsk2, tsk) {
69083+ cred = __task_cred(tsk);
69084+ if (uid_eq(cred->uid, uid))
69085+ gr_fake_force_sig(SIGKILL, tsk);
69086+ } while_each_thread(tsk2, tsk);
69087+ read_unlock(&tasklist_lock);
69088+ }
69089+#endif
69090+}
69091+
69092+#ifdef CONFIG_GRKERNSEC_BRUTE
69093+static bool suid_ban_expired(struct user_struct *user)
69094+{
69095+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
69096+ user->suid_banned = 0;
69097+ user->suid_ban_expires = 0;
69098+ free_uid(user);
69099+ return true;
69100+ }
69101+
69102+ return false;
69103+}
69104+#endif
69105+
69106+int gr_process_kernel_exec_ban(void)
69107+{
69108+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
69109+ if (unlikely(current->cred->user->kernel_banned))
69110+ return -EPERM;
69111+#endif
69112+ return 0;
69113+}
69114+
69115+int gr_process_kernel_setuid_ban(struct user_struct *user)
69116+{
69117+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
69118+ if (unlikely(user->kernel_banned))
69119+ gr_fake_force_sig(SIGKILL, current);
69120+#endif
69121+ return 0;
69122+}
69123+
69124+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
69125+{
69126+#ifdef CONFIG_GRKERNSEC_BRUTE
69127+ struct user_struct *user = current->cred->user;
69128+ if (unlikely(user->suid_banned)) {
69129+ if (suid_ban_expired(user))
69130+ return 0;
69131+ /* disallow execution of suid binaries only */
69132+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
69133+ return -EPERM;
69134+ }
69135+#endif
69136+ return 0;
69137+}
69138diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
69139new file mode 100644
69140index 0000000..4030d57
69141--- /dev/null
69142+++ b/grsecurity/grsec_sock.c
69143@@ -0,0 +1,244 @@
69144+#include <linux/kernel.h>
69145+#include <linux/module.h>
69146+#include <linux/sched.h>
69147+#include <linux/file.h>
69148+#include <linux/net.h>
69149+#include <linux/in.h>
69150+#include <linux/ip.h>
69151+#include <net/sock.h>
69152+#include <net/inet_sock.h>
69153+#include <linux/grsecurity.h>
69154+#include <linux/grinternal.h>
69155+#include <linux/gracl.h>
69156+
69157+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
69158+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
69159+
69160+EXPORT_SYMBOL(gr_search_udp_recvmsg);
69161+EXPORT_SYMBOL(gr_search_udp_sendmsg);
69162+
69163+#ifdef CONFIG_UNIX_MODULE
69164+EXPORT_SYMBOL(gr_acl_handle_unix);
69165+EXPORT_SYMBOL(gr_acl_handle_mknod);
69166+EXPORT_SYMBOL(gr_handle_chroot_unix);
69167+EXPORT_SYMBOL(gr_handle_create);
69168+#endif
69169+
69170+#ifdef CONFIG_GRKERNSEC
69171+#define gr_conn_table_size 32749
69172+struct conn_table_entry {
69173+ struct conn_table_entry *next;
69174+ struct signal_struct *sig;
69175+};
69176+
69177+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
69178+DEFINE_SPINLOCK(gr_conn_table_lock);
69179+
69180+extern const char * gr_socktype_to_name(unsigned char type);
69181+extern const char * gr_proto_to_name(unsigned char proto);
69182+extern const char * gr_sockfamily_to_name(unsigned char family);
69183+
69184+static __inline__ int
69185+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
69186+{
69187+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
69188+}
69189+
69190+static __inline__ int
69191+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
69192+ __u16 sport, __u16 dport)
69193+{
69194+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
69195+ sig->gr_sport == sport && sig->gr_dport == dport))
69196+ return 1;
69197+ else
69198+ return 0;
69199+}
69200+
69201+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
69202+{
69203+ struct conn_table_entry **match;
69204+ unsigned int index;
69205+
69206+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
69207+ sig->gr_sport, sig->gr_dport,
69208+ gr_conn_table_size);
69209+
69210+ newent->sig = sig;
69211+
69212+ match = &gr_conn_table[index];
69213+ newent->next = *match;
69214+ *match = newent;
69215+
69216+ return;
69217+}
69218+
69219+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
69220+{
69221+ struct conn_table_entry *match, *last = NULL;
69222+ unsigned int index;
69223+
69224+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
69225+ sig->gr_sport, sig->gr_dport,
69226+ gr_conn_table_size);
69227+
69228+ match = gr_conn_table[index];
69229+ while (match && !conn_match(match->sig,
69230+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
69231+ sig->gr_dport)) {
69232+ last = match;
69233+ match = match->next;
69234+ }
69235+
69236+ if (match) {
69237+ if (last)
69238+ last->next = match->next;
69239+ else
69240+ gr_conn_table[index] = NULL;
69241+ kfree(match);
69242+ }
69243+
69244+ return;
69245+}
69246+
69247+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
69248+ __u16 sport, __u16 dport)
69249+{
69250+ struct conn_table_entry *match;
69251+ unsigned int index;
69252+
69253+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
69254+
69255+ match = gr_conn_table[index];
69256+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
69257+ match = match->next;
69258+
69259+ if (match)
69260+ return match->sig;
69261+ else
69262+ return NULL;
69263+}
69264+
69265+#endif
69266+
69267+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
69268+{
69269+#ifdef CONFIG_GRKERNSEC
69270+ struct signal_struct *sig = task->signal;
69271+ struct conn_table_entry *newent;
69272+
69273+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
69274+ if (newent == NULL)
69275+ return;
69276+ /* no bh lock needed since we are called with bh disabled */
69277+ spin_lock(&gr_conn_table_lock);
69278+ gr_del_task_from_ip_table_nolock(sig);
69279+ sig->gr_saddr = inet->inet_rcv_saddr;
69280+ sig->gr_daddr = inet->inet_daddr;
69281+ sig->gr_sport = inet->inet_sport;
69282+ sig->gr_dport = inet->inet_dport;
69283+ gr_add_to_task_ip_table_nolock(sig, newent);
69284+ spin_unlock(&gr_conn_table_lock);
69285+#endif
69286+ return;
69287+}
69288+
69289+void gr_del_task_from_ip_table(struct task_struct *task)
69290+{
69291+#ifdef CONFIG_GRKERNSEC
69292+ spin_lock_bh(&gr_conn_table_lock);
69293+ gr_del_task_from_ip_table_nolock(task->signal);
69294+ spin_unlock_bh(&gr_conn_table_lock);
69295+#endif
69296+ return;
69297+}
69298+
69299+void
69300+gr_attach_curr_ip(const struct sock *sk)
69301+{
69302+#ifdef CONFIG_GRKERNSEC
69303+ struct signal_struct *p, *set;
69304+ const struct inet_sock *inet = inet_sk(sk);
69305+
69306+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
69307+ return;
69308+
69309+ set = current->signal;
69310+
69311+ spin_lock_bh(&gr_conn_table_lock);
69312+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
69313+ inet->inet_dport, inet->inet_sport);
69314+ if (unlikely(p != NULL)) {
69315+ set->curr_ip = p->curr_ip;
69316+ set->used_accept = 1;
69317+ gr_del_task_from_ip_table_nolock(p);
69318+ spin_unlock_bh(&gr_conn_table_lock);
69319+ return;
69320+ }
69321+ spin_unlock_bh(&gr_conn_table_lock);
69322+
69323+ set->curr_ip = inet->inet_daddr;
69324+ set->used_accept = 1;
69325+#endif
69326+ return;
69327+}
69328+
69329+int
69330+gr_handle_sock_all(const int family, const int type, const int protocol)
69331+{
69332+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69333+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
69334+ (family != AF_UNIX)) {
69335+ if (family == AF_INET)
69336+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
69337+ else
69338+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
69339+ return -EACCES;
69340+ }
69341+#endif
69342+ return 0;
69343+}
69344+
69345+int
69346+gr_handle_sock_server(const struct sockaddr *sck)
69347+{
69348+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69349+ if (grsec_enable_socket_server &&
69350+ in_group_p(grsec_socket_server_gid) &&
69351+ sck && (sck->sa_family != AF_UNIX) &&
69352+ (sck->sa_family != AF_LOCAL)) {
69353+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
69354+ return -EACCES;
69355+ }
69356+#endif
69357+ return 0;
69358+}
69359+
69360+int
69361+gr_handle_sock_server_other(const struct sock *sck)
69362+{
69363+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69364+ if (grsec_enable_socket_server &&
69365+ in_group_p(grsec_socket_server_gid) &&
69366+ sck && (sck->sk_family != AF_UNIX) &&
69367+ (sck->sk_family != AF_LOCAL)) {
69368+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
69369+ return -EACCES;
69370+ }
69371+#endif
69372+ return 0;
69373+}
69374+
69375+int
69376+gr_handle_sock_client(const struct sockaddr *sck)
69377+{
69378+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69379+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
69380+ sck && (sck->sa_family != AF_UNIX) &&
69381+ (sck->sa_family != AF_LOCAL)) {
69382+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
69383+ return -EACCES;
69384+ }
69385+#endif
69386+ return 0;
69387+}
69388diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
69389new file mode 100644
69390index 0000000..7624d1c
69391--- /dev/null
69392+++ b/grsecurity/grsec_sysctl.c
69393@@ -0,0 +1,460 @@
69394+#include <linux/kernel.h>
69395+#include <linux/sched.h>
69396+#include <linux/sysctl.h>
69397+#include <linux/grsecurity.h>
69398+#include <linux/grinternal.h>
69399+
69400+int
69401+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
69402+{
69403+#ifdef CONFIG_GRKERNSEC_SYSCTL
69404+ if (dirname == NULL || name == NULL)
69405+ return 0;
69406+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
69407+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
69408+ return -EACCES;
69409+ }
69410+#endif
69411+ return 0;
69412+}
69413+
69414+#ifdef CONFIG_GRKERNSEC_ROFS
69415+static int __maybe_unused one = 1;
69416+#endif
69417+
69418+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69419+struct ctl_table grsecurity_table[] = {
69420+#ifdef CONFIG_GRKERNSEC_SYSCTL
69421+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
69422+#ifdef CONFIG_GRKERNSEC_IO
69423+ {
69424+ .procname = "disable_priv_io",
69425+ .data = &grsec_disable_privio,
69426+ .maxlen = sizeof(int),
69427+ .mode = 0600,
69428+ .proc_handler = &proc_dointvec,
69429+ },
69430+#endif
69431+#endif
69432+#ifdef CONFIG_GRKERNSEC_LINK
69433+ {
69434+ .procname = "linking_restrictions",
69435+ .data = &grsec_enable_link,
69436+ .maxlen = sizeof(int),
69437+ .mode = 0600,
69438+ .proc_handler = &proc_dointvec,
69439+ },
69440+#endif
69441+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69442+ {
69443+ .procname = "enforce_symlinksifowner",
69444+ .data = &grsec_enable_symlinkown,
69445+ .maxlen = sizeof(int),
69446+ .mode = 0600,
69447+ .proc_handler = &proc_dointvec,
69448+ },
69449+ {
69450+ .procname = "symlinkown_gid",
69451+ .data = &grsec_symlinkown_gid,
69452+ .maxlen = sizeof(int),
69453+ .mode = 0600,
69454+ .proc_handler = &proc_dointvec,
69455+ },
69456+#endif
69457+#ifdef CONFIG_GRKERNSEC_BRUTE
69458+ {
69459+ .procname = "deter_bruteforce",
69460+ .data = &grsec_enable_brute,
69461+ .maxlen = sizeof(int),
69462+ .mode = 0600,
69463+ .proc_handler = &proc_dointvec,
69464+ },
69465+#endif
69466+#ifdef CONFIG_GRKERNSEC_FIFO
69467+ {
69468+ .procname = "fifo_restrictions",
69469+ .data = &grsec_enable_fifo,
69470+ .maxlen = sizeof(int),
69471+ .mode = 0600,
69472+ .proc_handler = &proc_dointvec,
69473+ },
69474+#endif
69475+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69476+ {
69477+ .procname = "ptrace_readexec",
69478+ .data = &grsec_enable_ptrace_readexec,
69479+ .maxlen = sizeof(int),
69480+ .mode = 0600,
69481+ .proc_handler = &proc_dointvec,
69482+ },
69483+#endif
69484+#ifdef CONFIG_GRKERNSEC_SETXID
69485+ {
69486+ .procname = "consistent_setxid",
69487+ .data = &grsec_enable_setxid,
69488+ .maxlen = sizeof(int),
69489+ .mode = 0600,
69490+ .proc_handler = &proc_dointvec,
69491+ },
69492+#endif
69493+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69494+ {
69495+ .procname = "ip_blackhole",
69496+ .data = &grsec_enable_blackhole,
69497+ .maxlen = sizeof(int),
69498+ .mode = 0600,
69499+ .proc_handler = &proc_dointvec,
69500+ },
69501+ {
69502+ .procname = "lastack_retries",
69503+ .data = &grsec_lastack_retries,
69504+ .maxlen = sizeof(int),
69505+ .mode = 0600,
69506+ .proc_handler = &proc_dointvec,
69507+ },
69508+#endif
69509+#ifdef CONFIG_GRKERNSEC_EXECLOG
69510+ {
69511+ .procname = "exec_logging",
69512+ .data = &grsec_enable_execlog,
69513+ .maxlen = sizeof(int),
69514+ .mode = 0600,
69515+ .proc_handler = &proc_dointvec,
69516+ },
69517+#endif
69518+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69519+ {
69520+ .procname = "rwxmap_logging",
69521+ .data = &grsec_enable_log_rwxmaps,
69522+ .maxlen = sizeof(int),
69523+ .mode = 0600,
69524+ .proc_handler = &proc_dointvec,
69525+ },
69526+#endif
69527+#ifdef CONFIG_GRKERNSEC_SIGNAL
69528+ {
69529+ .procname = "signal_logging",
69530+ .data = &grsec_enable_signal,
69531+ .maxlen = sizeof(int),
69532+ .mode = 0600,
69533+ .proc_handler = &proc_dointvec,
69534+ },
69535+#endif
69536+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69537+ {
69538+ .procname = "forkfail_logging",
69539+ .data = &grsec_enable_forkfail,
69540+ .maxlen = sizeof(int),
69541+ .mode = 0600,
69542+ .proc_handler = &proc_dointvec,
69543+ },
69544+#endif
69545+#ifdef CONFIG_GRKERNSEC_TIME
69546+ {
69547+ .procname = "timechange_logging",
69548+ .data = &grsec_enable_time,
69549+ .maxlen = sizeof(int),
69550+ .mode = 0600,
69551+ .proc_handler = &proc_dointvec,
69552+ },
69553+#endif
69554+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69555+ {
69556+ .procname = "chroot_deny_shmat",
69557+ .data = &grsec_enable_chroot_shmat,
69558+ .maxlen = sizeof(int),
69559+ .mode = 0600,
69560+ .proc_handler = &proc_dointvec,
69561+ },
69562+#endif
69563+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69564+ {
69565+ .procname = "chroot_deny_unix",
69566+ .data = &grsec_enable_chroot_unix,
69567+ .maxlen = sizeof(int),
69568+ .mode = 0600,
69569+ .proc_handler = &proc_dointvec,
69570+ },
69571+#endif
69572+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69573+ {
69574+ .procname = "chroot_deny_mount",
69575+ .data = &grsec_enable_chroot_mount,
69576+ .maxlen = sizeof(int),
69577+ .mode = 0600,
69578+ .proc_handler = &proc_dointvec,
69579+ },
69580+#endif
69581+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69582+ {
69583+ .procname = "chroot_deny_fchdir",
69584+ .data = &grsec_enable_chroot_fchdir,
69585+ .maxlen = sizeof(int),
69586+ .mode = 0600,
69587+ .proc_handler = &proc_dointvec,
69588+ },
69589+#endif
69590+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69591+ {
69592+ .procname = "chroot_deny_chroot",
69593+ .data = &grsec_enable_chroot_double,
69594+ .maxlen = sizeof(int),
69595+ .mode = 0600,
69596+ .proc_handler = &proc_dointvec,
69597+ },
69598+#endif
69599+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69600+ {
69601+ .procname = "chroot_deny_pivot",
69602+ .data = &grsec_enable_chroot_pivot,
69603+ .maxlen = sizeof(int),
69604+ .mode = 0600,
69605+ .proc_handler = &proc_dointvec,
69606+ },
69607+#endif
69608+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69609+ {
69610+ .procname = "chroot_enforce_chdir",
69611+ .data = &grsec_enable_chroot_chdir,
69612+ .maxlen = sizeof(int),
69613+ .mode = 0600,
69614+ .proc_handler = &proc_dointvec,
69615+ },
69616+#endif
69617+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69618+ {
69619+ .procname = "chroot_deny_chmod",
69620+ .data = &grsec_enable_chroot_chmod,
69621+ .maxlen = sizeof(int),
69622+ .mode = 0600,
69623+ .proc_handler = &proc_dointvec,
69624+ },
69625+#endif
69626+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69627+ {
69628+ .procname = "chroot_deny_mknod",
69629+ .data = &grsec_enable_chroot_mknod,
69630+ .maxlen = sizeof(int),
69631+ .mode = 0600,
69632+ .proc_handler = &proc_dointvec,
69633+ },
69634+#endif
69635+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69636+ {
69637+ .procname = "chroot_restrict_nice",
69638+ .data = &grsec_enable_chroot_nice,
69639+ .maxlen = sizeof(int),
69640+ .mode = 0600,
69641+ .proc_handler = &proc_dointvec,
69642+ },
69643+#endif
69644+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69645+ {
69646+ .procname = "chroot_execlog",
69647+ .data = &grsec_enable_chroot_execlog,
69648+ .maxlen = sizeof(int),
69649+ .mode = 0600,
69650+ .proc_handler = &proc_dointvec,
69651+ },
69652+#endif
69653+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69654+ {
69655+ .procname = "chroot_caps",
69656+ .data = &grsec_enable_chroot_caps,
69657+ .maxlen = sizeof(int),
69658+ .mode = 0600,
69659+ .proc_handler = &proc_dointvec,
69660+ },
69661+#endif
69662+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69663+ {
69664+ .procname = "chroot_deny_sysctl",
69665+ .data = &grsec_enable_chroot_sysctl,
69666+ .maxlen = sizeof(int),
69667+ .mode = 0600,
69668+ .proc_handler = &proc_dointvec,
69669+ },
69670+#endif
69671+#ifdef CONFIG_GRKERNSEC_TPE
69672+ {
69673+ .procname = "tpe",
69674+ .data = &grsec_enable_tpe,
69675+ .maxlen = sizeof(int),
69676+ .mode = 0600,
69677+ .proc_handler = &proc_dointvec,
69678+ },
69679+ {
69680+ .procname = "tpe_gid",
69681+ .data = &grsec_tpe_gid,
69682+ .maxlen = sizeof(int),
69683+ .mode = 0600,
69684+ .proc_handler = &proc_dointvec,
69685+ },
69686+#endif
69687+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69688+ {
69689+ .procname = "tpe_invert",
69690+ .data = &grsec_enable_tpe_invert,
69691+ .maxlen = sizeof(int),
69692+ .mode = 0600,
69693+ .proc_handler = &proc_dointvec,
69694+ },
69695+#endif
69696+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69697+ {
69698+ .procname = "tpe_restrict_all",
69699+ .data = &grsec_enable_tpe_all,
69700+ .maxlen = sizeof(int),
69701+ .mode = 0600,
69702+ .proc_handler = &proc_dointvec,
69703+ },
69704+#endif
69705+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69706+ {
69707+ .procname = "socket_all",
69708+ .data = &grsec_enable_socket_all,
69709+ .maxlen = sizeof(int),
69710+ .mode = 0600,
69711+ .proc_handler = &proc_dointvec,
69712+ },
69713+ {
69714+ .procname = "socket_all_gid",
69715+ .data = &grsec_socket_all_gid,
69716+ .maxlen = sizeof(int),
69717+ .mode = 0600,
69718+ .proc_handler = &proc_dointvec,
69719+ },
69720+#endif
69721+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69722+ {
69723+ .procname = "socket_client",
69724+ .data = &grsec_enable_socket_client,
69725+ .maxlen = sizeof(int),
69726+ .mode = 0600,
69727+ .proc_handler = &proc_dointvec,
69728+ },
69729+ {
69730+ .procname = "socket_client_gid",
69731+ .data = &grsec_socket_client_gid,
69732+ .maxlen = sizeof(int),
69733+ .mode = 0600,
69734+ .proc_handler = &proc_dointvec,
69735+ },
69736+#endif
69737+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69738+ {
69739+ .procname = "socket_server",
69740+ .data = &grsec_enable_socket_server,
69741+ .maxlen = sizeof(int),
69742+ .mode = 0600,
69743+ .proc_handler = &proc_dointvec,
69744+ },
69745+ {
69746+ .procname = "socket_server_gid",
69747+ .data = &grsec_socket_server_gid,
69748+ .maxlen = sizeof(int),
69749+ .mode = 0600,
69750+ .proc_handler = &proc_dointvec,
69751+ },
69752+#endif
69753+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69754+ {
69755+ .procname = "audit_group",
69756+ .data = &grsec_enable_group,
69757+ .maxlen = sizeof(int),
69758+ .mode = 0600,
69759+ .proc_handler = &proc_dointvec,
69760+ },
69761+ {
69762+ .procname = "audit_gid",
69763+ .data = &grsec_audit_gid,
69764+ .maxlen = sizeof(int),
69765+ .mode = 0600,
69766+ .proc_handler = &proc_dointvec,
69767+ },
69768+#endif
69769+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69770+ {
69771+ .procname = "audit_chdir",
69772+ .data = &grsec_enable_chdir,
69773+ .maxlen = sizeof(int),
69774+ .mode = 0600,
69775+ .proc_handler = &proc_dointvec,
69776+ },
69777+#endif
69778+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69779+ {
69780+ .procname = "audit_mount",
69781+ .data = &grsec_enable_mount,
69782+ .maxlen = sizeof(int),
69783+ .mode = 0600,
69784+ .proc_handler = &proc_dointvec,
69785+ },
69786+#endif
69787+#ifdef CONFIG_GRKERNSEC_DMESG
69788+ {
69789+ .procname = "dmesg",
69790+ .data = &grsec_enable_dmesg,
69791+ .maxlen = sizeof(int),
69792+ .mode = 0600,
69793+ .proc_handler = &proc_dointvec,
69794+ },
69795+#endif
69796+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69797+ {
69798+ .procname = "chroot_findtask",
69799+ .data = &grsec_enable_chroot_findtask,
69800+ .maxlen = sizeof(int),
69801+ .mode = 0600,
69802+ .proc_handler = &proc_dointvec,
69803+ },
69804+#endif
69805+#ifdef CONFIG_GRKERNSEC_RESLOG
69806+ {
69807+ .procname = "resource_logging",
69808+ .data = &grsec_resource_logging,
69809+ .maxlen = sizeof(int),
69810+ .mode = 0600,
69811+ .proc_handler = &proc_dointvec,
69812+ },
69813+#endif
69814+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69815+ {
69816+ .procname = "audit_ptrace",
69817+ .data = &grsec_enable_audit_ptrace,
69818+ .maxlen = sizeof(int),
69819+ .mode = 0600,
69820+ .proc_handler = &proc_dointvec,
69821+ },
69822+#endif
69823+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69824+ {
69825+ .procname = "harden_ptrace",
69826+ .data = &grsec_enable_harden_ptrace,
69827+ .maxlen = sizeof(int),
69828+ .mode = 0600,
69829+ .proc_handler = &proc_dointvec,
69830+ },
69831+#endif
69832+ {
69833+ .procname = "grsec_lock",
69834+ .data = &grsec_lock,
69835+ .maxlen = sizeof(int),
69836+ .mode = 0600,
69837+ .proc_handler = &proc_dointvec,
69838+ },
69839+#endif
69840+#ifdef CONFIG_GRKERNSEC_ROFS
69841+ {
69842+ .procname = "romount_protect",
69843+ .data = &grsec_enable_rofs,
69844+ .maxlen = sizeof(int),
69845+ .mode = 0600,
69846+ .proc_handler = &proc_dointvec_minmax,
69847+ .extra1 = &one,
69848+ .extra2 = &one,
69849+ },
69850+#endif
69851+ { }
69852+};
69853+#endif
69854diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
69855new file mode 100644
69856index 0000000..0dc13c3
69857--- /dev/null
69858+++ b/grsecurity/grsec_time.c
69859@@ -0,0 +1,16 @@
69860+#include <linux/kernel.h>
69861+#include <linux/sched.h>
69862+#include <linux/grinternal.h>
69863+#include <linux/module.h>
69864+
69865+void
69866+gr_log_timechange(void)
69867+{
69868+#ifdef CONFIG_GRKERNSEC_TIME
69869+ if (grsec_enable_time)
69870+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
69871+#endif
69872+ return;
69873+}
69874+
69875+EXPORT_SYMBOL(gr_log_timechange);
69876diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
69877new file mode 100644
69878index 0000000..ee57dcf
69879--- /dev/null
69880+++ b/grsecurity/grsec_tpe.c
69881@@ -0,0 +1,73 @@
69882+#include <linux/kernel.h>
69883+#include <linux/sched.h>
69884+#include <linux/file.h>
69885+#include <linux/fs.h>
69886+#include <linux/grinternal.h>
69887+
69888+extern int gr_acl_tpe_check(void);
69889+
69890+int
69891+gr_tpe_allow(const struct file *file)
69892+{
69893+#ifdef CONFIG_GRKERNSEC
69894+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
69895+ const struct cred *cred = current_cred();
69896+ char *msg = NULL;
69897+ char *msg2 = NULL;
69898+
69899+ // never restrict root
69900+ if (gr_is_global_root(cred->uid))
69901+ return 1;
69902+
69903+ if (grsec_enable_tpe) {
69904+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69905+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
69906+ msg = "not being in trusted group";
69907+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
69908+ msg = "being in untrusted group";
69909+#else
69910+ if (in_group_p(grsec_tpe_gid))
69911+ msg = "being in untrusted group";
69912+#endif
69913+ }
69914+ if (!msg && gr_acl_tpe_check())
69915+ msg = "being in untrusted role";
69916+
69917+ // not in any affected group/role
69918+ if (!msg)
69919+ goto next_check;
69920+
69921+ if (gr_is_global_nonroot(inode->i_uid))
69922+ msg2 = "file in non-root-owned directory";
69923+ else if (inode->i_mode & S_IWOTH)
69924+ msg2 = "file in world-writable directory";
69925+ else if (inode->i_mode & S_IWGRP)
69926+ msg2 = "file in group-writable directory";
69927+
69928+ if (msg && msg2) {
69929+ char fullmsg[70] = {0};
69930+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
69931+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
69932+ return 0;
69933+ }
69934+ msg = NULL;
69935+next_check:
69936+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69937+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
69938+ return 1;
69939+
69940+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
69941+ msg = "directory not owned by user";
69942+ else if (inode->i_mode & S_IWOTH)
69943+ msg = "file in world-writable directory";
69944+ else if (inode->i_mode & S_IWGRP)
69945+ msg = "file in group-writable directory";
69946+
69947+ if (msg) {
69948+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
69949+ return 0;
69950+ }
69951+#endif
69952+#endif
69953+ return 1;
69954+}
69955diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
69956new file mode 100644
69957index 0000000..9f7b1ac
69958--- /dev/null
69959+++ b/grsecurity/grsum.c
69960@@ -0,0 +1,61 @@
69961+#include <linux/err.h>
69962+#include <linux/kernel.h>
69963+#include <linux/sched.h>
69964+#include <linux/mm.h>
69965+#include <linux/scatterlist.h>
69966+#include <linux/crypto.h>
69967+#include <linux/gracl.h>
69968+
69969+
69970+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
69971+#error "crypto and sha256 must be built into the kernel"
69972+#endif
69973+
69974+int
69975+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
69976+{
69977+ char *p;
69978+ struct crypto_hash *tfm;
69979+ struct hash_desc desc;
69980+ struct scatterlist sg;
69981+ unsigned char temp_sum[GR_SHA_LEN];
69982+ volatile int retval = 0;
69983+ volatile int dummy = 0;
69984+ unsigned int i;
69985+
69986+ sg_init_table(&sg, 1);
69987+
69988+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
69989+ if (IS_ERR(tfm)) {
69990+ /* should never happen, since sha256 should be built in */
69991+ return 1;
69992+ }
69993+
69994+ desc.tfm = tfm;
69995+ desc.flags = 0;
69996+
69997+ crypto_hash_init(&desc);
69998+
69999+ p = salt;
70000+ sg_set_buf(&sg, p, GR_SALT_LEN);
70001+ crypto_hash_update(&desc, &sg, sg.length);
70002+
70003+ p = entry->pw;
70004+ sg_set_buf(&sg, p, strlen(p));
70005+
70006+ crypto_hash_update(&desc, &sg, sg.length);
70007+
70008+ crypto_hash_final(&desc, temp_sum);
70009+
70010+ memset(entry->pw, 0, GR_PW_LEN);
70011+
70012+ for (i = 0; i < GR_SHA_LEN; i++)
70013+ if (sum[i] != temp_sum[i])
70014+ retval = 1;
70015+ else
70016+ dummy = 1; // waste a cycle
70017+
70018+ crypto_free_hash(tfm);
70019+
70020+ return retval;
70021+}
70022diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
70023index 77ff547..181834f 100644
70024--- a/include/asm-generic/4level-fixup.h
70025+++ b/include/asm-generic/4level-fixup.h
70026@@ -13,8 +13,10 @@
70027 #define pmd_alloc(mm, pud, address) \
70028 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
70029 NULL: pmd_offset(pud, address))
70030+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
70031
70032 #define pud_alloc(mm, pgd, address) (pgd)
70033+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
70034 #define pud_offset(pgd, start) (pgd)
70035 #define pud_none(pud) 0
70036 #define pud_bad(pud) 0
70037diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
70038index b7babf0..04ad282 100644
70039--- a/include/asm-generic/atomic-long.h
70040+++ b/include/asm-generic/atomic-long.h
70041@@ -22,6 +22,12 @@
70042
70043 typedef atomic64_t atomic_long_t;
70044
70045+#ifdef CONFIG_PAX_REFCOUNT
70046+typedef atomic64_unchecked_t atomic_long_unchecked_t;
70047+#else
70048+typedef atomic64_t atomic_long_unchecked_t;
70049+#endif
70050+
70051 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
70052
70053 static inline long atomic_long_read(atomic_long_t *l)
70054@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
70055 return (long)atomic64_read(v);
70056 }
70057
70058+#ifdef CONFIG_PAX_REFCOUNT
70059+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
70060+{
70061+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70062+
70063+ return (long)atomic64_read_unchecked(v);
70064+}
70065+#endif
70066+
70067 static inline void atomic_long_set(atomic_long_t *l, long i)
70068 {
70069 atomic64_t *v = (atomic64_t *)l;
70070@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
70071 atomic64_set(v, i);
70072 }
70073
70074+#ifdef CONFIG_PAX_REFCOUNT
70075+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
70076+{
70077+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70078+
70079+ atomic64_set_unchecked(v, i);
70080+}
70081+#endif
70082+
70083 static inline void atomic_long_inc(atomic_long_t *l)
70084 {
70085 atomic64_t *v = (atomic64_t *)l;
70086@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
70087 atomic64_inc(v);
70088 }
70089
70090+#ifdef CONFIG_PAX_REFCOUNT
70091+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
70092+{
70093+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70094+
70095+ atomic64_inc_unchecked(v);
70096+}
70097+#endif
70098+
70099 static inline void atomic_long_dec(atomic_long_t *l)
70100 {
70101 atomic64_t *v = (atomic64_t *)l;
70102@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
70103 atomic64_dec(v);
70104 }
70105
70106+#ifdef CONFIG_PAX_REFCOUNT
70107+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
70108+{
70109+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70110+
70111+ atomic64_dec_unchecked(v);
70112+}
70113+#endif
70114+
70115 static inline void atomic_long_add(long i, atomic_long_t *l)
70116 {
70117 atomic64_t *v = (atomic64_t *)l;
70118@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
70119 atomic64_add(i, v);
70120 }
70121
70122+#ifdef CONFIG_PAX_REFCOUNT
70123+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
70124+{
70125+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70126+
70127+ atomic64_add_unchecked(i, v);
70128+}
70129+#endif
70130+
70131 static inline void atomic_long_sub(long i, atomic_long_t *l)
70132 {
70133 atomic64_t *v = (atomic64_t *)l;
70134@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
70135 atomic64_sub(i, v);
70136 }
70137
70138+#ifdef CONFIG_PAX_REFCOUNT
70139+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
70140+{
70141+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70142+
70143+ atomic64_sub_unchecked(i, v);
70144+}
70145+#endif
70146+
70147 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
70148 {
70149 atomic64_t *v = (atomic64_t *)l;
70150@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
70151 return (long)atomic64_add_return(i, v);
70152 }
70153
70154+#ifdef CONFIG_PAX_REFCOUNT
70155+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
70156+{
70157+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70158+
70159+ return (long)atomic64_add_return_unchecked(i, v);
70160+}
70161+#endif
70162+
70163 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
70164 {
70165 atomic64_t *v = (atomic64_t *)l;
70166@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
70167 return (long)atomic64_inc_return(v);
70168 }
70169
70170+#ifdef CONFIG_PAX_REFCOUNT
70171+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
70172+{
70173+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
70174+
70175+ return (long)atomic64_inc_return_unchecked(v);
70176+}
70177+#endif
70178+
70179 static inline long atomic_long_dec_return(atomic_long_t *l)
70180 {
70181 atomic64_t *v = (atomic64_t *)l;
70182@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
70183
70184 typedef atomic_t atomic_long_t;
70185
70186+#ifdef CONFIG_PAX_REFCOUNT
70187+typedef atomic_unchecked_t atomic_long_unchecked_t;
70188+#else
70189+typedef atomic_t atomic_long_unchecked_t;
70190+#endif
70191+
70192 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
70193 static inline long atomic_long_read(atomic_long_t *l)
70194 {
70195@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
70196 return (long)atomic_read(v);
70197 }
70198
70199+#ifdef CONFIG_PAX_REFCOUNT
70200+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
70201+{
70202+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70203+
70204+ return (long)atomic_read_unchecked(v);
70205+}
70206+#endif
70207+
70208 static inline void atomic_long_set(atomic_long_t *l, long i)
70209 {
70210 atomic_t *v = (atomic_t *)l;
70211@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
70212 atomic_set(v, i);
70213 }
70214
70215+#ifdef CONFIG_PAX_REFCOUNT
70216+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
70217+{
70218+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70219+
70220+ atomic_set_unchecked(v, i);
70221+}
70222+#endif
70223+
70224 static inline void atomic_long_inc(atomic_long_t *l)
70225 {
70226 atomic_t *v = (atomic_t *)l;
70227@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
70228 atomic_inc(v);
70229 }
70230
70231+#ifdef CONFIG_PAX_REFCOUNT
70232+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
70233+{
70234+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70235+
70236+ atomic_inc_unchecked(v);
70237+}
70238+#endif
70239+
70240 static inline void atomic_long_dec(atomic_long_t *l)
70241 {
70242 atomic_t *v = (atomic_t *)l;
70243@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
70244 atomic_dec(v);
70245 }
70246
70247+#ifdef CONFIG_PAX_REFCOUNT
70248+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
70249+{
70250+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70251+
70252+ atomic_dec_unchecked(v);
70253+}
70254+#endif
70255+
70256 static inline void atomic_long_add(long i, atomic_long_t *l)
70257 {
70258 atomic_t *v = (atomic_t *)l;
70259@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
70260 atomic_add(i, v);
70261 }
70262
70263+#ifdef CONFIG_PAX_REFCOUNT
70264+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
70265+{
70266+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70267+
70268+ atomic_add_unchecked(i, v);
70269+}
70270+#endif
70271+
70272 static inline void atomic_long_sub(long i, atomic_long_t *l)
70273 {
70274 atomic_t *v = (atomic_t *)l;
70275@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
70276 atomic_sub(i, v);
70277 }
70278
70279+#ifdef CONFIG_PAX_REFCOUNT
70280+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
70281+{
70282+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70283+
70284+ atomic_sub_unchecked(i, v);
70285+}
70286+#endif
70287+
70288 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
70289 {
70290 atomic_t *v = (atomic_t *)l;
70291@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
70292 return (long)atomic_add_return(i, v);
70293 }
70294
70295+#ifdef CONFIG_PAX_REFCOUNT
70296+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
70297+{
70298+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70299+
70300+ return (long)atomic_add_return_unchecked(i, v);
70301+}
70302+
70303+#endif
70304+
70305 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
70306 {
70307 atomic_t *v = (atomic_t *)l;
70308@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
70309 return (long)atomic_inc_return(v);
70310 }
70311
70312+#ifdef CONFIG_PAX_REFCOUNT
70313+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
70314+{
70315+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
70316+
70317+ return (long)atomic_inc_return_unchecked(v);
70318+}
70319+#endif
70320+
70321 static inline long atomic_long_dec_return(atomic_long_t *l)
70322 {
70323 atomic_t *v = (atomic_t *)l;
70324@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
70325
70326 #endif /* BITS_PER_LONG == 64 */
70327
70328+#ifdef CONFIG_PAX_REFCOUNT
70329+static inline void pax_refcount_needs_these_functions(void)
70330+{
70331+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
70332+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
70333+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
70334+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
70335+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
70336+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
70337+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
70338+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
70339+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
70340+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
70341+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
70342+#ifdef CONFIG_X86
70343+ atomic_clear_mask_unchecked(0, NULL);
70344+ atomic_set_mask_unchecked(0, NULL);
70345+#endif
70346+
70347+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
70348+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
70349+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
70350+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
70351+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
70352+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
70353+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
70354+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
70355+}
70356+#else
70357+#define atomic_read_unchecked(v) atomic_read(v)
70358+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
70359+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
70360+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
70361+#define atomic_inc_unchecked(v) atomic_inc(v)
70362+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
70363+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
70364+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
70365+#define atomic_dec_unchecked(v) atomic_dec(v)
70366+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
70367+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
70368+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
70369+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
70370+
70371+#define atomic_long_read_unchecked(v) atomic_long_read(v)
70372+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
70373+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
70374+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
70375+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
70376+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
70377+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
70378+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
70379+#endif
70380+
70381 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
70382diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
70383index 33bd2de..f31bff97 100644
70384--- a/include/asm-generic/atomic.h
70385+++ b/include/asm-generic/atomic.h
70386@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
70387 * Atomically clears the bits set in @mask from @v
70388 */
70389 #ifndef atomic_clear_mask
70390-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
70391+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
70392 {
70393 unsigned long flags;
70394
70395diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
70396index b18ce4f..2ee2843 100644
70397--- a/include/asm-generic/atomic64.h
70398+++ b/include/asm-generic/atomic64.h
70399@@ -16,6 +16,8 @@ typedef struct {
70400 long long counter;
70401 } atomic64_t;
70402
70403+typedef atomic64_t atomic64_unchecked_t;
70404+
70405 #define ATOMIC64_INIT(i) { (i) }
70406
70407 extern long long atomic64_read(const atomic64_t *v);
70408@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
70409 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
70410 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
70411
70412+#define atomic64_read_unchecked(v) atomic64_read(v)
70413+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
70414+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
70415+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
70416+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
70417+#define atomic64_inc_unchecked(v) atomic64_inc(v)
70418+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
70419+#define atomic64_dec_unchecked(v) atomic64_dec(v)
70420+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
70421+
70422 #endif /* _ASM_GENERIC_ATOMIC64_H */
70423diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
70424index 1bfcfe5..e04c5c9 100644
70425--- a/include/asm-generic/cache.h
70426+++ b/include/asm-generic/cache.h
70427@@ -6,7 +6,7 @@
70428 * cache lines need to provide their own cache.h.
70429 */
70430
70431-#define L1_CACHE_SHIFT 5
70432-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
70433+#define L1_CACHE_SHIFT 5UL
70434+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
70435
70436 #endif /* __ASM_GENERIC_CACHE_H */
70437diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
70438index 0d68a1e..b74a761 100644
70439--- a/include/asm-generic/emergency-restart.h
70440+++ b/include/asm-generic/emergency-restart.h
70441@@ -1,7 +1,7 @@
70442 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
70443 #define _ASM_GENERIC_EMERGENCY_RESTART_H
70444
70445-static inline void machine_emergency_restart(void)
70446+static inline __noreturn void machine_emergency_restart(void)
70447 {
70448 machine_restart(NULL);
70449 }
70450diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
70451index 90f99c7..00ce236 100644
70452--- a/include/asm-generic/kmap_types.h
70453+++ b/include/asm-generic/kmap_types.h
70454@@ -2,9 +2,9 @@
70455 #define _ASM_GENERIC_KMAP_TYPES_H
70456
70457 #ifdef __WITH_KM_FENCE
70458-# define KM_TYPE_NR 41
70459+# define KM_TYPE_NR 42
70460 #else
70461-# define KM_TYPE_NR 20
70462+# define KM_TYPE_NR 21
70463 #endif
70464
70465 #endif
70466diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
70467index 9ceb03b..62b0b8f 100644
70468--- a/include/asm-generic/local.h
70469+++ b/include/asm-generic/local.h
70470@@ -23,24 +23,37 @@ typedef struct
70471 atomic_long_t a;
70472 } local_t;
70473
70474+typedef struct {
70475+ atomic_long_unchecked_t a;
70476+} local_unchecked_t;
70477+
70478 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
70479
70480 #define local_read(l) atomic_long_read(&(l)->a)
70481+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
70482 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
70483+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
70484 #define local_inc(l) atomic_long_inc(&(l)->a)
70485+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
70486 #define local_dec(l) atomic_long_dec(&(l)->a)
70487+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
70488 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
70489+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
70490 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
70491+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
70492
70493 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
70494 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
70495 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
70496 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
70497 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
70498+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
70499 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
70500 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
70501+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
70502
70503 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
70504+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
70505 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
70506 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
70507 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
70508diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
70509index 725612b..9cc513a 100644
70510--- a/include/asm-generic/pgtable-nopmd.h
70511+++ b/include/asm-generic/pgtable-nopmd.h
70512@@ -1,14 +1,19 @@
70513 #ifndef _PGTABLE_NOPMD_H
70514 #define _PGTABLE_NOPMD_H
70515
70516-#ifndef __ASSEMBLY__
70517-
70518 #include <asm-generic/pgtable-nopud.h>
70519
70520-struct mm_struct;
70521-
70522 #define __PAGETABLE_PMD_FOLDED
70523
70524+#define PMD_SHIFT PUD_SHIFT
70525+#define PTRS_PER_PMD 1
70526+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
70527+#define PMD_MASK (~(PMD_SIZE-1))
70528+
70529+#ifndef __ASSEMBLY__
70530+
70531+struct mm_struct;
70532+
70533 /*
70534 * Having the pmd type consist of a pud gets the size right, and allows
70535 * us to conceptually access the pud entry that this pmd is folded into
70536@@ -16,11 +21,6 @@ struct mm_struct;
70537 */
70538 typedef struct { pud_t pud; } pmd_t;
70539
70540-#define PMD_SHIFT PUD_SHIFT
70541-#define PTRS_PER_PMD 1
70542-#define PMD_SIZE (1UL << PMD_SHIFT)
70543-#define PMD_MASK (~(PMD_SIZE-1))
70544-
70545 /*
70546 * The "pud_xxx()" functions here are trivial for a folded two-level
70547 * setup: the pmd is never bad, and a pmd always exists (as it's folded
70548diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
70549index 810431d..0ec4804f 100644
70550--- a/include/asm-generic/pgtable-nopud.h
70551+++ b/include/asm-generic/pgtable-nopud.h
70552@@ -1,10 +1,15 @@
70553 #ifndef _PGTABLE_NOPUD_H
70554 #define _PGTABLE_NOPUD_H
70555
70556-#ifndef __ASSEMBLY__
70557-
70558 #define __PAGETABLE_PUD_FOLDED
70559
70560+#define PUD_SHIFT PGDIR_SHIFT
70561+#define PTRS_PER_PUD 1
70562+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
70563+#define PUD_MASK (~(PUD_SIZE-1))
70564+
70565+#ifndef __ASSEMBLY__
70566+
70567 /*
70568 * Having the pud type consist of a pgd gets the size right, and allows
70569 * us to conceptually access the pgd entry that this pud is folded into
70570@@ -12,11 +17,6 @@
70571 */
70572 typedef struct { pgd_t pgd; } pud_t;
70573
70574-#define PUD_SHIFT PGDIR_SHIFT
70575-#define PTRS_PER_PUD 1
70576-#define PUD_SIZE (1UL << PUD_SHIFT)
70577-#define PUD_MASK (~(PUD_SIZE-1))
70578-
70579 /*
70580 * The "pgd_xxx()" functions here are trivial for a folded two-level
70581 * setup: the pud is never bad, and a pud always exists (as it's folded
70582@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
70583 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
70584
70585 #define pgd_populate(mm, pgd, pud) do { } while (0)
70586+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
70587 /*
70588 * (puds are folded into pgds so this doesn't get actually called,
70589 * but the define is needed for a generic inline function.)
70590diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
70591index a59ff51..2594a70 100644
70592--- a/include/asm-generic/pgtable.h
70593+++ b/include/asm-generic/pgtable.h
70594@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
70595 }
70596 #endif /* CONFIG_NUMA_BALANCING */
70597
70598+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
70599+static inline unsigned long pax_open_kernel(void) { return 0; }
70600+#endif
70601+
70602+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
70603+static inline unsigned long pax_close_kernel(void) { return 0; }
70604+#endif
70605+
70606 #endif /* CONFIG_MMU */
70607
70608 #endif /* !__ASSEMBLY__ */
70609diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
70610index 13821c3..5672d7e 100644
70611--- a/include/asm-generic/tlb.h
70612+++ b/include/asm-generic/tlb.h
70613@@ -112,7 +112,7 @@ struct mmu_gather {
70614
70615 #define HAVE_GENERIC_MMU_GATHER
70616
70617-void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm);
70618+void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end);
70619 void tlb_flush_mmu(struct mmu_gather *tlb);
70620 void tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start,
70621 unsigned long end);
70622diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
70623index c184aa8..d049942 100644
70624--- a/include/asm-generic/uaccess.h
70625+++ b/include/asm-generic/uaccess.h
70626@@ -343,4 +343,12 @@ clear_user(void __user *to, unsigned long n)
70627 return __clear_user(to, n);
70628 }
70629
70630+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
70631+//static inline unsigned long pax_open_userland(void) { return 0; }
70632+#endif
70633+
70634+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
70635+//static inline unsigned long pax_close_userland(void) { return 0; }
70636+#endif
70637+
70638 #endif /* __ASM_GENERIC_UACCESS_H */
70639diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
70640index eb58d2d..df131bf 100644
70641--- a/include/asm-generic/vmlinux.lds.h
70642+++ b/include/asm-generic/vmlinux.lds.h
70643@@ -239,6 +239,7 @@
70644 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
70645 VMLINUX_SYMBOL(__start_rodata) = .; \
70646 *(.rodata) *(.rodata.*) \
70647+ *(.data..read_only) \
70648 *(__vermagic) /* Kernel version magic */ \
70649 . = ALIGN(8); \
70650 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
70651@@ -749,17 +750,18 @@
70652 * section in the linker script will go there too. @phdr should have
70653 * a leading colon.
70654 *
70655- * Note that this macros defines __per_cpu_load as an absolute symbol.
70656+ * Note that this macros defines per_cpu_load as an absolute symbol.
70657 * If there is no need to put the percpu section at a predetermined
70658 * address, use PERCPU_SECTION.
70659 */
70660 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
70661- VMLINUX_SYMBOL(__per_cpu_load) = .; \
70662- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
70663+ per_cpu_load = .; \
70664+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
70665 - LOAD_OFFSET) { \
70666+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
70667 PERCPU_INPUT(cacheline) \
70668 } phdr \
70669- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
70670+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
70671
70672 /**
70673 * PERCPU_SECTION - define output section for percpu area, simple version
70674diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
70675index 418d270..bfd2794 100644
70676--- a/include/crypto/algapi.h
70677+++ b/include/crypto/algapi.h
70678@@ -34,7 +34,7 @@ struct crypto_type {
70679 unsigned int maskclear;
70680 unsigned int maskset;
70681 unsigned int tfmsize;
70682-};
70683+} __do_const;
70684
70685 struct crypto_instance {
70686 struct crypto_alg alg;
70687diff --git a/include/drm/drmP.h b/include/drm/drmP.h
70688index 63d17ee..716de2b 100644
70689--- a/include/drm/drmP.h
70690+++ b/include/drm/drmP.h
70691@@ -72,6 +72,7 @@
70692 #include <linux/workqueue.h>
70693 #include <linux/poll.h>
70694 #include <asm/pgalloc.h>
70695+#include <asm/local.h>
70696 #include <drm/drm.h>
70697 #include <drm/drm_sarea.h>
70698
70699@@ -296,10 +297,12 @@ do { \
70700 * \param cmd command.
70701 * \param arg argument.
70702 */
70703-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
70704+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
70705+ struct drm_file *file_priv);
70706+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
70707 struct drm_file *file_priv);
70708
70709-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
70710+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
70711 unsigned long arg);
70712
70713 #define DRM_IOCTL_NR(n) _IOC_NR(n)
70714@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
70715 struct drm_ioctl_desc {
70716 unsigned int cmd;
70717 int flags;
70718- drm_ioctl_t *func;
70719+ drm_ioctl_t func;
70720 unsigned int cmd_drv;
70721 const char *name;
70722-};
70723+} __do_const;
70724
70725 /**
70726 * Creates a driver or general drm_ioctl_desc array entry for the given
70727@@ -1015,7 +1018,7 @@ struct drm_info_list {
70728 int (*show)(struct seq_file*, void*); /** show callback */
70729 u32 driver_features; /**< Required driver features for this entry */
70730 void *data;
70731-};
70732+} __do_const;
70733
70734 /**
70735 * debugfs node structure. This structure represents a debugfs file.
70736@@ -1088,7 +1091,7 @@ struct drm_device {
70737
70738 /** \name Usage Counters */
70739 /*@{ */
70740- int open_count; /**< Outstanding files open */
70741+ local_t open_count; /**< Outstanding files open */
70742 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
70743 atomic_t vma_count; /**< Outstanding vma areas open */
70744 int buf_use; /**< Buffers in use -- cannot alloc */
70745@@ -1099,7 +1102,7 @@ struct drm_device {
70746 /*@{ */
70747 unsigned long counters;
70748 enum drm_stat_type types[15];
70749- atomic_t counts[15];
70750+ atomic_unchecked_t counts[15];
70751 /*@} */
70752
70753 struct list_head filelist;
70754diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
70755index f43d556..94d9343 100644
70756--- a/include/drm/drm_crtc_helper.h
70757+++ b/include/drm/drm_crtc_helper.h
70758@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
70759 struct drm_connector *connector);
70760 /* disable encoder when not in use - more explicit than dpms off */
70761 void (*disable)(struct drm_encoder *encoder);
70762-};
70763+} __no_const;
70764
70765 /**
70766 * drm_connector_helper_funcs - helper operations for connectors
70767diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
70768index 72dcbe8..8db58d7 100644
70769--- a/include/drm/ttm/ttm_memory.h
70770+++ b/include/drm/ttm/ttm_memory.h
70771@@ -48,7 +48,7 @@
70772
70773 struct ttm_mem_shrink {
70774 int (*do_shrink) (struct ttm_mem_shrink *);
70775-};
70776+} __no_const;
70777
70778 /**
70779 * struct ttm_mem_global - Global memory accounting structure.
70780diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
70781index 4b840e8..155d235 100644
70782--- a/include/keys/asymmetric-subtype.h
70783+++ b/include/keys/asymmetric-subtype.h
70784@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
70785 /* Verify the signature on a key of this subtype (optional) */
70786 int (*verify_signature)(const struct key *key,
70787 const struct public_key_signature *sig);
70788-};
70789+} __do_const;
70790
70791 /**
70792 * asymmetric_key_subtype - Get the subtype from an asymmetric key
70793diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
70794index c1da539..1dcec55 100644
70795--- a/include/linux/atmdev.h
70796+++ b/include/linux/atmdev.h
70797@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
70798 #endif
70799
70800 struct k_atm_aal_stats {
70801-#define __HANDLE_ITEM(i) atomic_t i
70802+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70803 __AAL_STAT_ITEMS
70804 #undef __HANDLE_ITEM
70805 };
70806@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
70807 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
70808 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
70809 struct module *owner;
70810-};
70811+} __do_const ;
70812
70813 struct atmphy_ops {
70814 int (*start)(struct atm_dev *dev);
70815diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
70816index 70cf138..0418ee2 100644
70817--- a/include/linux/binfmts.h
70818+++ b/include/linux/binfmts.h
70819@@ -73,8 +73,10 @@ struct linux_binfmt {
70820 int (*load_binary)(struct linux_binprm *);
70821 int (*load_shlib)(struct file *);
70822 int (*core_dump)(struct coredump_params *cprm);
70823+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
70824+ void (*handle_mmap)(struct file *);
70825 unsigned long min_coredump; /* minimal dump size */
70826-};
70827+} __do_const;
70828
70829 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
70830
70831diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
70832index 2fdb4a4..54aad7e 100644
70833--- a/include/linux/blkdev.h
70834+++ b/include/linux/blkdev.h
70835@@ -1526,7 +1526,7 @@ struct block_device_operations {
70836 /* this callback is with swap_lock and sometimes page table lock held */
70837 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
70838 struct module *owner;
70839-};
70840+} __do_const;
70841
70842 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
70843 unsigned long);
70844diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
70845index 7c2e030..b72475d 100644
70846--- a/include/linux/blktrace_api.h
70847+++ b/include/linux/blktrace_api.h
70848@@ -23,7 +23,7 @@ struct blk_trace {
70849 struct dentry *dir;
70850 struct dentry *dropped_file;
70851 struct dentry *msg_file;
70852- atomic_t dropped;
70853+ atomic_unchecked_t dropped;
70854 };
70855
70856 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
70857diff --git a/include/linux/cache.h b/include/linux/cache.h
70858index 4c57065..4307975 100644
70859--- a/include/linux/cache.h
70860+++ b/include/linux/cache.h
70861@@ -16,6 +16,10 @@
70862 #define __read_mostly
70863 #endif
70864
70865+#ifndef __read_only
70866+#define __read_only __read_mostly
70867+#endif
70868+
70869 #ifndef ____cacheline_aligned
70870 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
70871 #endif
70872diff --git a/include/linux/capability.h b/include/linux/capability.h
70873index d9a4f7f4..19f77d6 100644
70874--- a/include/linux/capability.h
70875+++ b/include/linux/capability.h
70876@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
70877 extern bool nsown_capable(int cap);
70878 extern bool inode_capable(const struct inode *inode, int cap);
70879 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
70880+extern bool capable_nolog(int cap);
70881+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
70882+extern bool inode_capable_nolog(const struct inode *inode, int cap);
70883
70884 /* audit system wants to get cap info from files as well */
70885 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
70886
70887+extern int is_privileged_binary(const struct dentry *dentry);
70888+
70889 #endif /* !_LINUX_CAPABILITY_H */
70890diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
70891index 8609d57..86e4d79 100644
70892--- a/include/linux/cdrom.h
70893+++ b/include/linux/cdrom.h
70894@@ -87,7 +87,6 @@ struct cdrom_device_ops {
70895
70896 /* driver specifications */
70897 const int capability; /* capability flags */
70898- int n_minors; /* number of active minor devices */
70899 /* handle uniform packets for scsi type devices (scsi,atapi) */
70900 int (*generic_packet) (struct cdrom_device_info *,
70901 struct packet_command *);
70902diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
70903index 4ce9056..86caac6 100644
70904--- a/include/linux/cleancache.h
70905+++ b/include/linux/cleancache.h
70906@@ -31,7 +31,7 @@ struct cleancache_ops {
70907 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
70908 void (*invalidate_inode)(int, struct cleancache_filekey);
70909 void (*invalidate_fs)(int);
70910-};
70911+} __no_const;
70912
70913 extern struct cleancache_ops *
70914 cleancache_register_ops(struct cleancache_ops *ops);
70915diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
70916index 1186098..f87e53d 100644
70917--- a/include/linux/clk-provider.h
70918+++ b/include/linux/clk-provider.h
70919@@ -132,6 +132,7 @@ struct clk_ops {
70920 unsigned long);
70921 void (*init)(struct clk_hw *hw);
70922 };
70923+typedef struct clk_ops __no_const clk_ops_no_const;
70924
70925 /**
70926 * struct clk_init_data - holds init data that's common to all clocks and is
70927diff --git a/include/linux/compat.h b/include/linux/compat.h
70928index 7f0c1dd..206ac34 100644
70929--- a/include/linux/compat.h
70930+++ b/include/linux/compat.h
70931@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
70932 compat_size_t __user *len_ptr);
70933
70934 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
70935-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
70936+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
70937 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
70938 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
70939 compat_ssize_t msgsz, int msgflg);
70940@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
70941 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
70942 compat_ulong_t addr, compat_ulong_t data);
70943 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
70944- compat_long_t addr, compat_long_t data);
70945+ compat_ulong_t addr, compat_ulong_t data);
70946
70947 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
70948 /*
70949@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
70950
70951 int compat_restore_altstack(const compat_stack_t __user *uss);
70952 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
70953+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
70954
70955 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
70956 struct compat_timespec __user *interval);
70957diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
70958index 842de22..7f3a41f 100644
70959--- a/include/linux/compiler-gcc4.h
70960+++ b/include/linux/compiler-gcc4.h
70961@@ -39,9 +39,29 @@
70962 # define __compiletime_warning(message) __attribute__((warning(message)))
70963 # define __compiletime_error(message) __attribute__((error(message)))
70964 #endif /* __CHECKER__ */
70965+
70966+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
70967+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
70968+#define __bos0(ptr) __bos((ptr), 0)
70969+#define __bos1(ptr) __bos((ptr), 1)
70970 #endif /* GCC_VERSION >= 40300 */
70971
70972 #if GCC_VERSION >= 40500
70973+
70974+#ifdef CONSTIFY_PLUGIN
70975+#define __no_const __attribute__((no_const))
70976+#define __do_const __attribute__((do_const))
70977+#endif
70978+
70979+#ifdef SIZE_OVERFLOW_PLUGIN
70980+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
70981+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
70982+#endif
70983+
70984+#ifdef LATENT_ENTROPY_PLUGIN
70985+#define __latent_entropy __attribute__((latent_entropy))
70986+#endif
70987+
70988 /*
70989 * Mark a position in code as unreachable. This can be used to
70990 * suppress control flow warnings after asm blocks that transfer
70991diff --git a/include/linux/compiler.h b/include/linux/compiler.h
70992index 92669cd..1771a15 100644
70993--- a/include/linux/compiler.h
70994+++ b/include/linux/compiler.h
70995@@ -5,11 +5,14 @@
70996
70997 #ifdef __CHECKER__
70998 # define __user __attribute__((noderef, address_space(1)))
70999+# define __force_user __force __user
71000 # define __kernel __attribute__((address_space(0)))
71001+# define __force_kernel __force __kernel
71002 # define __safe __attribute__((safe))
71003 # define __force __attribute__((force))
71004 # define __nocast __attribute__((nocast))
71005 # define __iomem __attribute__((noderef, address_space(2)))
71006+# define __force_iomem __force __iomem
71007 # define __must_hold(x) __attribute__((context(x,1,1)))
71008 # define __acquires(x) __attribute__((context(x,0,1)))
71009 # define __releases(x) __attribute__((context(x,1,0)))
71010@@ -17,20 +20,37 @@
71011 # define __release(x) __context__(x,-1)
71012 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
71013 # define __percpu __attribute__((noderef, address_space(3)))
71014+# define __force_percpu __force __percpu
71015 #ifdef CONFIG_SPARSE_RCU_POINTER
71016 # define __rcu __attribute__((noderef, address_space(4)))
71017+# define __force_rcu __force __rcu
71018 #else
71019 # define __rcu
71020+# define __force_rcu
71021 #endif
71022 extern void __chk_user_ptr(const volatile void __user *);
71023 extern void __chk_io_ptr(const volatile void __iomem *);
71024 #else
71025-# define __user
71026-# define __kernel
71027+# ifdef CHECKER_PLUGIN
71028+//# define __user
71029+//# define __force_user
71030+//# define __kernel
71031+//# define __force_kernel
71032+# else
71033+# ifdef STRUCTLEAK_PLUGIN
71034+# define __user __attribute__((user))
71035+# else
71036+# define __user
71037+# endif
71038+# define __force_user
71039+# define __kernel
71040+# define __force_kernel
71041+# endif
71042 # define __safe
71043 # define __force
71044 # define __nocast
71045 # define __iomem
71046+# define __force_iomem
71047 # define __chk_user_ptr(x) (void)0
71048 # define __chk_io_ptr(x) (void)0
71049 # define __builtin_warning(x, y...) (1)
71050@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
71051 # define __release(x) (void)0
71052 # define __cond_lock(x,c) (c)
71053 # define __percpu
71054+# define __force_percpu
71055 # define __rcu
71056+# define __force_rcu
71057 #endif
71058
71059 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
71060@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
71061 # define __attribute_const__ /* unimplemented */
71062 #endif
71063
71064+#ifndef __no_const
71065+# define __no_const
71066+#endif
71067+
71068+#ifndef __do_const
71069+# define __do_const
71070+#endif
71071+
71072+#ifndef __size_overflow
71073+# define __size_overflow(...)
71074+#endif
71075+
71076+#ifndef __intentional_overflow
71077+# define __intentional_overflow(...)
71078+#endif
71079+
71080+#ifndef __latent_entropy
71081+# define __latent_entropy
71082+#endif
71083+
71084 /*
71085 * Tell gcc if a function is cold. The compiler will assume any path
71086 * directly leading to the call is unlikely.
71087@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
71088 #define __cold
71089 #endif
71090
71091+#ifndef __alloc_size
71092+#define __alloc_size(...)
71093+#endif
71094+
71095+#ifndef __bos
71096+#define __bos(ptr, arg)
71097+#endif
71098+
71099+#ifndef __bos0
71100+#define __bos0(ptr)
71101+#endif
71102+
71103+#ifndef __bos1
71104+#define __bos1(ptr)
71105+#endif
71106+
71107 /* Simple shorthand for a section definition */
71108 #ifndef __section
71109 # define __section(S) __attribute__ ((__section__(#S)))
71110@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
71111 * use is to mediate communication between process-level code and irq/NMI
71112 * handlers, all running on the same CPU.
71113 */
71114-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
71115+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
71116+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
71117
71118 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
71119 #ifdef CONFIG_KPROBES
71120diff --git a/include/linux/completion.h b/include/linux/completion.h
71121index 33f0280..35c6568 100644
71122--- a/include/linux/completion.h
71123+++ b/include/linux/completion.h
71124@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
71125 extern void wait_for_completion(struct completion *);
71126 extern void wait_for_completion_io(struct completion *);
71127 extern int wait_for_completion_interruptible(struct completion *x);
71128-extern int wait_for_completion_killable(struct completion *x);
71129+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
71130 extern unsigned long wait_for_completion_timeout(struct completion *x,
71131 unsigned long timeout);
71132 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
71133 unsigned long timeout);
71134 extern long wait_for_completion_interruptible_timeout(
71135- struct completion *x, unsigned long timeout);
71136+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
71137 extern long wait_for_completion_killable_timeout(
71138- struct completion *x, unsigned long timeout);
71139+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
71140 extern bool try_wait_for_completion(struct completion *x);
71141 extern bool completion_done(struct completion *x);
71142
71143diff --git a/include/linux/configfs.h b/include/linux/configfs.h
71144index 34025df..d94bbbc 100644
71145--- a/include/linux/configfs.h
71146+++ b/include/linux/configfs.h
71147@@ -125,7 +125,7 @@ struct configfs_attribute {
71148 const char *ca_name;
71149 struct module *ca_owner;
71150 umode_t ca_mode;
71151-};
71152+} __do_const;
71153
71154 /*
71155 * Users often need to create attribute structures for their configurable
71156diff --git a/include/linux/cpu.h b/include/linux/cpu.h
71157index 9f3c7e8..a18c7b6 100644
71158--- a/include/linux/cpu.h
71159+++ b/include/linux/cpu.h
71160@@ -115,7 +115,7 @@ enum {
71161 /* Need to know about CPUs going up/down? */
71162 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
71163 #define cpu_notifier(fn, pri) { \
71164- static struct notifier_block fn##_nb __cpuinitdata = \
71165+ static struct notifier_block fn##_nb = \
71166 { .notifier_call = fn, .priority = pri }; \
71167 register_cpu_notifier(&fn##_nb); \
71168 }
71169diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
71170index 037d36a..ca5fe6e 100644
71171--- a/include/linux/cpufreq.h
71172+++ b/include/linux/cpufreq.h
71173@@ -262,7 +262,7 @@ struct cpufreq_driver {
71174 int (*suspend) (struct cpufreq_policy *policy);
71175 int (*resume) (struct cpufreq_policy *policy);
71176 struct freq_attr **attr;
71177-};
71178+} __do_const;
71179
71180 /* flags */
71181
71182@@ -321,6 +321,7 @@ struct global_attr {
71183 ssize_t (*store)(struct kobject *a, struct attribute *b,
71184 const char *c, size_t count);
71185 };
71186+typedef struct global_attr __no_const global_attr_no_const;
71187
71188 #define define_one_global_ro(_name) \
71189 static struct global_attr _name = \
71190diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
71191index 8f04062..900239a 100644
71192--- a/include/linux/cpuidle.h
71193+++ b/include/linux/cpuidle.h
71194@@ -52,7 +52,8 @@ struct cpuidle_state {
71195 int index);
71196
71197 int (*enter_dead) (struct cpuidle_device *dev, int index);
71198-};
71199+} __do_const;
71200+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
71201
71202 /* Idle State Flags */
71203 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
71204@@ -191,7 +192,7 @@ struct cpuidle_governor {
71205 void (*reflect) (struct cpuidle_device *dev, int index);
71206
71207 struct module *owner;
71208-};
71209+} __do_const;
71210
71211 #ifdef CONFIG_CPU_IDLE
71212
71213diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
71214index d08e4d2..95fad61 100644
71215--- a/include/linux/cpumask.h
71216+++ b/include/linux/cpumask.h
71217@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
71218 }
71219
71220 /* Valid inputs for n are -1 and 0. */
71221-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
71222+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
71223 {
71224 return n+1;
71225 }
71226
71227-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
71228+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
71229 {
71230 return n+1;
71231 }
71232
71233-static inline unsigned int cpumask_next_and(int n,
71234+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
71235 const struct cpumask *srcp,
71236 const struct cpumask *andp)
71237 {
71238@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
71239 *
71240 * Returns >= nr_cpu_ids if no further cpus set.
71241 */
71242-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
71243+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
71244 {
71245 /* -1 is a legal arg here. */
71246 if (n != -1)
71247@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
71248 *
71249 * Returns >= nr_cpu_ids if no further cpus unset.
71250 */
71251-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
71252+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
71253 {
71254 /* -1 is a legal arg here. */
71255 if (n != -1)
71256@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
71257 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
71258 }
71259
71260-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
71261+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
71262 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
71263
71264 /**
71265diff --git a/include/linux/cred.h b/include/linux/cred.h
71266index 04421e8..6bce4ef 100644
71267--- a/include/linux/cred.h
71268+++ b/include/linux/cred.h
71269@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
71270 static inline void validate_process_creds(void)
71271 {
71272 }
71273+static inline void validate_task_creds(struct task_struct *task)
71274+{
71275+}
71276 #endif
71277
71278 /**
71279diff --git a/include/linux/crypto.h b/include/linux/crypto.h
71280index b92eadf..b4ecdc1 100644
71281--- a/include/linux/crypto.h
71282+++ b/include/linux/crypto.h
71283@@ -373,7 +373,7 @@ struct cipher_tfm {
71284 const u8 *key, unsigned int keylen);
71285 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
71286 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
71287-};
71288+} __no_const;
71289
71290 struct hash_tfm {
71291 int (*init)(struct hash_desc *desc);
71292@@ -394,13 +394,13 @@ struct compress_tfm {
71293 int (*cot_decompress)(struct crypto_tfm *tfm,
71294 const u8 *src, unsigned int slen,
71295 u8 *dst, unsigned int *dlen);
71296-};
71297+} __no_const;
71298
71299 struct rng_tfm {
71300 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
71301 unsigned int dlen);
71302 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
71303-};
71304+} __no_const;
71305
71306 #define crt_ablkcipher crt_u.ablkcipher
71307 #define crt_aead crt_u.aead
71308diff --git a/include/linux/ctype.h b/include/linux/ctype.h
71309index 653589e..4ef254a 100644
71310--- a/include/linux/ctype.h
71311+++ b/include/linux/ctype.h
71312@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
71313 * Fast implementation of tolower() for internal usage. Do not use in your
71314 * code.
71315 */
71316-static inline char _tolower(const char c)
71317+static inline unsigned char _tolower(const unsigned char c)
71318 {
71319 return c | 0x20;
71320 }
71321diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
71322index 7925bf0..d5143d2 100644
71323--- a/include/linux/decompress/mm.h
71324+++ b/include/linux/decompress/mm.h
71325@@ -77,7 +77,7 @@ static void free(void *where)
71326 * warnings when not needed (indeed large_malloc / large_free are not
71327 * needed by inflate */
71328
71329-#define malloc(a) kmalloc(a, GFP_KERNEL)
71330+#define malloc(a) kmalloc((a), GFP_KERNEL)
71331 #define free(a) kfree(a)
71332
71333 #define large_malloc(a) vmalloc(a)
71334diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
71335index fe8c447..bdc1f33 100644
71336--- a/include/linux/devfreq.h
71337+++ b/include/linux/devfreq.h
71338@@ -114,7 +114,7 @@ struct devfreq_governor {
71339 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
71340 int (*event_handler)(struct devfreq *devfreq,
71341 unsigned int event, void *data);
71342-};
71343+} __do_const;
71344
71345 /**
71346 * struct devfreq - Device devfreq structure
71347diff --git a/include/linux/device.h b/include/linux/device.h
71348index c0a1261..dba7569 100644
71349--- a/include/linux/device.h
71350+++ b/include/linux/device.h
71351@@ -290,7 +290,7 @@ struct subsys_interface {
71352 struct list_head node;
71353 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
71354 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
71355-};
71356+} __do_const;
71357
71358 int subsys_interface_register(struct subsys_interface *sif);
71359 void subsys_interface_unregister(struct subsys_interface *sif);
71360@@ -473,7 +473,7 @@ struct device_type {
71361 void (*release)(struct device *dev);
71362
71363 const struct dev_pm_ops *pm;
71364-};
71365+} __do_const;
71366
71367 /* interface for exporting device attributes */
71368 struct device_attribute {
71369@@ -483,11 +483,12 @@ struct device_attribute {
71370 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
71371 const char *buf, size_t count);
71372 };
71373+typedef struct device_attribute __no_const device_attribute_no_const;
71374
71375 struct dev_ext_attribute {
71376 struct device_attribute attr;
71377 void *var;
71378-};
71379+} __do_const;
71380
71381 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
71382 char *buf);
71383diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
71384index 94af418..b1ca7a2 100644
71385--- a/include/linux/dma-mapping.h
71386+++ b/include/linux/dma-mapping.h
71387@@ -54,7 +54,7 @@ struct dma_map_ops {
71388 u64 (*get_required_mask)(struct device *dev);
71389 #endif
71390 int is_phys;
71391-};
71392+} __do_const;
71393
71394 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
71395
71396diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
71397index 96d3e4a..dc36433 100644
71398--- a/include/linux/dmaengine.h
71399+++ b/include/linux/dmaengine.h
71400@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
71401 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
71402 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
71403
71404-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
71405+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
71406 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
71407-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
71408+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
71409 struct dma_pinned_list *pinned_list, struct page *page,
71410 unsigned int offset, size_t len);
71411
71412diff --git a/include/linux/efi.h b/include/linux/efi.h
71413index 2bc0ad7..3f7b006 100644
71414--- a/include/linux/efi.h
71415+++ b/include/linux/efi.h
71416@@ -745,6 +745,7 @@ struct efivar_operations {
71417 efi_set_variable_t *set_variable;
71418 efi_query_variable_store_t *query_variable_store;
71419 };
71420+typedef struct efivar_operations __no_const efivar_operations_no_const;
71421
71422 struct efivars {
71423 /*
71424diff --git a/include/linux/elf.h b/include/linux/elf.h
71425index 40a3c0e..4c45a38 100644
71426--- a/include/linux/elf.h
71427+++ b/include/linux/elf.h
71428@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
71429 #define elf_note elf32_note
71430 #define elf_addr_t Elf32_Off
71431 #define Elf_Half Elf32_Half
71432+#define elf_dyn Elf32_Dyn
71433
71434 #else
71435
71436@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
71437 #define elf_note elf64_note
71438 #define elf_addr_t Elf64_Off
71439 #define Elf_Half Elf64_Half
71440+#define elf_dyn Elf64_Dyn
71441
71442 #endif
71443
71444diff --git a/include/linux/err.h b/include/linux/err.h
71445index f2edce2..cc2082c 100644
71446--- a/include/linux/err.h
71447+++ b/include/linux/err.h
71448@@ -19,12 +19,12 @@
71449
71450 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
71451
71452-static inline void * __must_check ERR_PTR(long error)
71453+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
71454 {
71455 return (void *) error;
71456 }
71457
71458-static inline long __must_check PTR_ERR(const void *ptr)
71459+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
71460 {
71461 return (long) ptr;
71462 }
71463diff --git a/include/linux/extcon.h b/include/linux/extcon.h
71464index fcb51c8..bdafcf6 100644
71465--- a/include/linux/extcon.h
71466+++ b/include/linux/extcon.h
71467@@ -134,7 +134,7 @@ struct extcon_dev {
71468 /* /sys/class/extcon/.../mutually_exclusive/... */
71469 struct attribute_group attr_g_muex;
71470 struct attribute **attrs_muex;
71471- struct device_attribute *d_attrs_muex;
71472+ device_attribute_no_const *d_attrs_muex;
71473 };
71474
71475 /**
71476diff --git a/include/linux/fb.h b/include/linux/fb.h
71477index d49c60f..2834fbe 100644
71478--- a/include/linux/fb.h
71479+++ b/include/linux/fb.h
71480@@ -304,7 +304,7 @@ struct fb_ops {
71481 /* called at KDB enter and leave time to prepare the console */
71482 int (*fb_debug_enter)(struct fb_info *info);
71483 int (*fb_debug_leave)(struct fb_info *info);
71484-};
71485+} __do_const;
71486
71487 #ifdef CONFIG_FB_TILEBLITTING
71488 #define FB_TILE_CURSOR_NONE 0
71489diff --git a/include/linux/filter.h b/include/linux/filter.h
71490index f65f5a6..2f4f93a 100644
71491--- a/include/linux/filter.h
71492+++ b/include/linux/filter.h
71493@@ -20,6 +20,7 @@ struct compat_sock_fprog {
71494
71495 struct sk_buff;
71496 struct sock;
71497+struct bpf_jit_work;
71498
71499 struct sk_filter
71500 {
71501@@ -27,6 +28,9 @@ struct sk_filter
71502 unsigned int len; /* Number of filter blocks */
71503 unsigned int (*bpf_func)(const struct sk_buff *skb,
71504 const struct sock_filter *filter);
71505+#ifdef CONFIG_BPF_JIT
71506+ struct bpf_jit_work *work;
71507+#endif
71508 struct rcu_head rcu;
71509 struct sock_filter insns[0];
71510 };
71511diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
71512index 8293262..2b3b8bd 100644
71513--- a/include/linux/frontswap.h
71514+++ b/include/linux/frontswap.h
71515@@ -11,7 +11,7 @@ struct frontswap_ops {
71516 int (*load)(unsigned, pgoff_t, struct page *);
71517 void (*invalidate_page)(unsigned, pgoff_t);
71518 void (*invalidate_area)(unsigned);
71519-};
71520+} __no_const;
71521
71522 extern bool frontswap_enabled;
71523 extern struct frontswap_ops *
71524diff --git a/include/linux/fs.h b/include/linux/fs.h
71525index 65c2be2..4c53f6e 100644
71526--- a/include/linux/fs.h
71527+++ b/include/linux/fs.h
71528@@ -1543,7 +1543,8 @@ struct file_operations {
71529 long (*fallocate)(struct file *file, int mode, loff_t offset,
71530 loff_t len);
71531 int (*show_fdinfo)(struct seq_file *m, struct file *f);
71532-};
71533+} __do_const;
71534+typedef struct file_operations __no_const file_operations_no_const;
71535
71536 struct inode_operations {
71537 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
71538@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
71539 inode->i_flags |= S_NOSEC;
71540 }
71541
71542+static inline bool is_sidechannel_device(const struct inode *inode)
71543+{
71544+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
71545+ umode_t mode = inode->i_mode;
71546+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
71547+#else
71548+ return false;
71549+#endif
71550+}
71551+
71552 #endif /* _LINUX_FS_H */
71553diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
71554index 2b93a9a..855d94a 100644
71555--- a/include/linux/fs_struct.h
71556+++ b/include/linux/fs_struct.h
71557@@ -6,7 +6,7 @@
71558 #include <linux/seqlock.h>
71559
71560 struct fs_struct {
71561- int users;
71562+ atomic_t users;
71563 spinlock_t lock;
71564 seqcount_t seq;
71565 int umask;
71566diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
71567index 5dfa0aa..6acf322 100644
71568--- a/include/linux/fscache-cache.h
71569+++ b/include/linux/fscache-cache.h
71570@@ -112,7 +112,7 @@ struct fscache_operation {
71571 fscache_operation_release_t release;
71572 };
71573
71574-extern atomic_t fscache_op_debug_id;
71575+extern atomic_unchecked_t fscache_op_debug_id;
71576 extern void fscache_op_work_func(struct work_struct *work);
71577
71578 extern void fscache_enqueue_operation(struct fscache_operation *);
71579@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
71580 INIT_WORK(&op->work, fscache_op_work_func);
71581 atomic_set(&op->usage, 1);
71582 op->state = FSCACHE_OP_ST_INITIALISED;
71583- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
71584+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
71585 op->processor = processor;
71586 op->release = release;
71587 INIT_LIST_HEAD(&op->pend_link);
71588diff --git a/include/linux/fscache.h b/include/linux/fscache.h
71589index 7a08623..4c07b0f 100644
71590--- a/include/linux/fscache.h
71591+++ b/include/linux/fscache.h
71592@@ -152,7 +152,7 @@ struct fscache_cookie_def {
71593 * - this is mandatory for any object that may have data
71594 */
71595 void (*now_uncached)(void *cookie_netfs_data);
71596-};
71597+} __do_const;
71598
71599 /*
71600 * fscache cached network filesystem type
71601diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
71602index a78680a..87bd73e 100644
71603--- a/include/linux/fsnotify.h
71604+++ b/include/linux/fsnotify.h
71605@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
71606 struct inode *inode = path->dentry->d_inode;
71607 __u32 mask = FS_ACCESS;
71608
71609+ if (is_sidechannel_device(inode))
71610+ return;
71611+
71612 if (S_ISDIR(inode->i_mode))
71613 mask |= FS_ISDIR;
71614
71615@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
71616 struct inode *inode = path->dentry->d_inode;
71617 __u32 mask = FS_MODIFY;
71618
71619+ if (is_sidechannel_device(inode))
71620+ return;
71621+
71622 if (S_ISDIR(inode->i_mode))
71623 mask |= FS_ISDIR;
71624
71625@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
71626 */
71627 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
71628 {
71629- return kstrdup(name, GFP_KERNEL);
71630+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
71631 }
71632
71633 /*
71634diff --git a/include/linux/genhd.h b/include/linux/genhd.h
71635index 9f3c275..911b591 100644
71636--- a/include/linux/genhd.h
71637+++ b/include/linux/genhd.h
71638@@ -194,7 +194,7 @@ struct gendisk {
71639 struct kobject *slave_dir;
71640
71641 struct timer_rand_state *random;
71642- atomic_t sync_io; /* RAID */
71643+ atomic_unchecked_t sync_io; /* RAID */
71644 struct disk_events *ev;
71645 #ifdef CONFIG_BLK_DEV_INTEGRITY
71646 struct blk_integrity *integrity;
71647diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
71648index 023bc34..b02b46a 100644
71649--- a/include/linux/genl_magic_func.h
71650+++ b/include/linux/genl_magic_func.h
71651@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
71652 },
71653
71654 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
71655-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
71656+static struct genl_ops ZZZ_genl_ops[] = {
71657 #include GENL_MAGIC_INCLUDE_FILE
71658 };
71659
71660diff --git a/include/linux/gfp.h b/include/linux/gfp.h
71661index 0f615eb..5c3832f 100644
71662--- a/include/linux/gfp.h
71663+++ b/include/linux/gfp.h
71664@@ -35,6 +35,13 @@ struct vm_area_struct;
71665 #define ___GFP_NO_KSWAPD 0x400000u
71666 #define ___GFP_OTHER_NODE 0x800000u
71667 #define ___GFP_WRITE 0x1000000u
71668+
71669+#ifdef CONFIG_PAX_USERCOPY_SLABS
71670+#define ___GFP_USERCOPY 0x2000000u
71671+#else
71672+#define ___GFP_USERCOPY 0
71673+#endif
71674+
71675 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
71676
71677 /*
71678@@ -92,6 +99,7 @@ struct vm_area_struct;
71679 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
71680 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
71681 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
71682+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
71683
71684 /*
71685 * This may seem redundant, but it's a way of annotating false positives vs.
71686@@ -99,7 +107,7 @@ struct vm_area_struct;
71687 */
71688 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
71689
71690-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
71691+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
71692 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
71693
71694 /* This equals 0, but use constants in case they ever change */
71695@@ -153,6 +161,8 @@ struct vm_area_struct;
71696 /* 4GB DMA on some platforms */
71697 #define GFP_DMA32 __GFP_DMA32
71698
71699+#define GFP_USERCOPY __GFP_USERCOPY
71700+
71701 /* Convert GFP flags to their corresponding migrate type */
71702 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
71703 {
71704diff --git a/include/linux/gracl.h b/include/linux/gracl.h
71705new file mode 100644
71706index 0000000..ebe6d72
71707--- /dev/null
71708+++ b/include/linux/gracl.h
71709@@ -0,0 +1,319 @@
71710+#ifndef GR_ACL_H
71711+#define GR_ACL_H
71712+
71713+#include <linux/grdefs.h>
71714+#include <linux/resource.h>
71715+#include <linux/capability.h>
71716+#include <linux/dcache.h>
71717+#include <asm/resource.h>
71718+
71719+/* Major status information */
71720+
71721+#define GR_VERSION "grsecurity 2.9.1"
71722+#define GRSECURITY_VERSION 0x2901
71723+
71724+enum {
71725+ GR_SHUTDOWN = 0,
71726+ GR_ENABLE = 1,
71727+ GR_SPROLE = 2,
71728+ GR_RELOAD = 3,
71729+ GR_SEGVMOD = 4,
71730+ GR_STATUS = 5,
71731+ GR_UNSPROLE = 6,
71732+ GR_PASSSET = 7,
71733+ GR_SPROLEPAM = 8,
71734+};
71735+
71736+/* Password setup definitions
71737+ * kernel/grhash.c */
71738+enum {
71739+ GR_PW_LEN = 128,
71740+ GR_SALT_LEN = 16,
71741+ GR_SHA_LEN = 32,
71742+};
71743+
71744+enum {
71745+ GR_SPROLE_LEN = 64,
71746+};
71747+
71748+enum {
71749+ GR_NO_GLOB = 0,
71750+ GR_REG_GLOB,
71751+ GR_CREATE_GLOB
71752+};
71753+
71754+#define GR_NLIMITS 32
71755+
71756+/* Begin Data Structures */
71757+
71758+struct sprole_pw {
71759+ unsigned char *rolename;
71760+ unsigned char salt[GR_SALT_LEN];
71761+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
71762+};
71763+
71764+struct name_entry {
71765+ __u32 key;
71766+ ino_t inode;
71767+ dev_t device;
71768+ char *name;
71769+ __u16 len;
71770+ __u8 deleted;
71771+ struct name_entry *prev;
71772+ struct name_entry *next;
71773+};
71774+
71775+struct inodev_entry {
71776+ struct name_entry *nentry;
71777+ struct inodev_entry *prev;
71778+ struct inodev_entry *next;
71779+};
71780+
71781+struct acl_role_db {
71782+ struct acl_role_label **r_hash;
71783+ __u32 r_size;
71784+};
71785+
71786+struct inodev_db {
71787+ struct inodev_entry **i_hash;
71788+ __u32 i_size;
71789+};
71790+
71791+struct name_db {
71792+ struct name_entry **n_hash;
71793+ __u32 n_size;
71794+};
71795+
71796+struct crash_uid {
71797+ uid_t uid;
71798+ unsigned long expires;
71799+};
71800+
71801+struct gr_hash_struct {
71802+ void **table;
71803+ void **nametable;
71804+ void *first;
71805+ __u32 table_size;
71806+ __u32 used_size;
71807+ int type;
71808+};
71809+
71810+/* Userspace Grsecurity ACL data structures */
71811+
71812+struct acl_subject_label {
71813+ char *filename;
71814+ ino_t inode;
71815+ dev_t device;
71816+ __u32 mode;
71817+ kernel_cap_t cap_mask;
71818+ kernel_cap_t cap_lower;
71819+ kernel_cap_t cap_invert_audit;
71820+
71821+ struct rlimit res[GR_NLIMITS];
71822+ __u32 resmask;
71823+
71824+ __u8 user_trans_type;
71825+ __u8 group_trans_type;
71826+ uid_t *user_transitions;
71827+ gid_t *group_transitions;
71828+ __u16 user_trans_num;
71829+ __u16 group_trans_num;
71830+
71831+ __u32 sock_families[2];
71832+ __u32 ip_proto[8];
71833+ __u32 ip_type;
71834+ struct acl_ip_label **ips;
71835+ __u32 ip_num;
71836+ __u32 inaddr_any_override;
71837+
71838+ __u32 crashes;
71839+ unsigned long expires;
71840+
71841+ struct acl_subject_label *parent_subject;
71842+ struct gr_hash_struct *hash;
71843+ struct acl_subject_label *prev;
71844+ struct acl_subject_label *next;
71845+
71846+ struct acl_object_label **obj_hash;
71847+ __u32 obj_hash_size;
71848+ __u16 pax_flags;
71849+};
71850+
71851+struct role_allowed_ip {
71852+ __u32 addr;
71853+ __u32 netmask;
71854+
71855+ struct role_allowed_ip *prev;
71856+ struct role_allowed_ip *next;
71857+};
71858+
71859+struct role_transition {
71860+ char *rolename;
71861+
71862+ struct role_transition *prev;
71863+ struct role_transition *next;
71864+};
71865+
71866+struct acl_role_label {
71867+ char *rolename;
71868+ uid_t uidgid;
71869+ __u16 roletype;
71870+
71871+ __u16 auth_attempts;
71872+ unsigned long expires;
71873+
71874+ struct acl_subject_label *root_label;
71875+ struct gr_hash_struct *hash;
71876+
71877+ struct acl_role_label *prev;
71878+ struct acl_role_label *next;
71879+
71880+ struct role_transition *transitions;
71881+ struct role_allowed_ip *allowed_ips;
71882+ uid_t *domain_children;
71883+ __u16 domain_child_num;
71884+
71885+ umode_t umask;
71886+
71887+ struct acl_subject_label **subj_hash;
71888+ __u32 subj_hash_size;
71889+};
71890+
71891+struct user_acl_role_db {
71892+ struct acl_role_label **r_table;
71893+ __u32 num_pointers; /* Number of allocations to track */
71894+ __u32 num_roles; /* Number of roles */
71895+ __u32 num_domain_children; /* Number of domain children */
71896+ __u32 num_subjects; /* Number of subjects */
71897+ __u32 num_objects; /* Number of objects */
71898+};
71899+
71900+struct acl_object_label {
71901+ char *filename;
71902+ ino_t inode;
71903+ dev_t device;
71904+ __u32 mode;
71905+
71906+ struct acl_subject_label *nested;
71907+ struct acl_object_label *globbed;
71908+
71909+ /* next two structures not used */
71910+
71911+ struct acl_object_label *prev;
71912+ struct acl_object_label *next;
71913+};
71914+
71915+struct acl_ip_label {
71916+ char *iface;
71917+ __u32 addr;
71918+ __u32 netmask;
71919+ __u16 low, high;
71920+ __u8 mode;
71921+ __u32 type;
71922+ __u32 proto[8];
71923+
71924+ /* next two structures not used */
71925+
71926+ struct acl_ip_label *prev;
71927+ struct acl_ip_label *next;
71928+};
71929+
71930+struct gr_arg {
71931+ struct user_acl_role_db role_db;
71932+ unsigned char pw[GR_PW_LEN];
71933+ unsigned char salt[GR_SALT_LEN];
71934+ unsigned char sum[GR_SHA_LEN];
71935+ unsigned char sp_role[GR_SPROLE_LEN];
71936+ struct sprole_pw *sprole_pws;
71937+ dev_t segv_device;
71938+ ino_t segv_inode;
71939+ uid_t segv_uid;
71940+ __u16 num_sprole_pws;
71941+ __u16 mode;
71942+};
71943+
71944+struct gr_arg_wrapper {
71945+ struct gr_arg *arg;
71946+ __u32 version;
71947+ __u32 size;
71948+};
71949+
71950+struct subject_map {
71951+ struct acl_subject_label *user;
71952+ struct acl_subject_label *kernel;
71953+ struct subject_map *prev;
71954+ struct subject_map *next;
71955+};
71956+
71957+struct acl_subj_map_db {
71958+ struct subject_map **s_hash;
71959+ __u32 s_size;
71960+};
71961+
71962+/* End Data Structures Section */
71963+
71964+/* Hash functions generated by empirical testing by Brad Spengler
71965+ Makes good use of the low bits of the inode. Generally 0-1 times
71966+ in loop for successful match. 0-3 for unsuccessful match.
71967+ Shift/add algorithm with modulus of table size and an XOR*/
71968+
71969+static __inline__ unsigned int
71970+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
71971+{
71972+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
71973+}
71974+
71975+ static __inline__ unsigned int
71976+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
71977+{
71978+ return ((const unsigned long)userp % sz);
71979+}
71980+
71981+static __inline__ unsigned int
71982+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
71983+{
71984+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
71985+}
71986+
71987+static __inline__ unsigned int
71988+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
71989+{
71990+ return full_name_hash((const unsigned char *)name, len) % sz;
71991+}
71992+
71993+#define FOR_EACH_ROLE_START(role) \
71994+ role = role_list; \
71995+ while (role) {
71996+
71997+#define FOR_EACH_ROLE_END(role) \
71998+ role = role->prev; \
71999+ }
72000+
72001+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
72002+ subj = NULL; \
72003+ iter = 0; \
72004+ while (iter < role->subj_hash_size) { \
72005+ if (subj == NULL) \
72006+ subj = role->subj_hash[iter]; \
72007+ if (subj == NULL) { \
72008+ iter++; \
72009+ continue; \
72010+ }
72011+
72012+#define FOR_EACH_SUBJECT_END(subj,iter) \
72013+ subj = subj->next; \
72014+ if (subj == NULL) \
72015+ iter++; \
72016+ }
72017+
72018+
72019+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
72020+ subj = role->hash->first; \
72021+ while (subj != NULL) {
72022+
72023+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
72024+ subj = subj->next; \
72025+ }
72026+
72027+#endif
72028+
72029diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
72030new file mode 100644
72031index 0000000..33ebd1f
72032--- /dev/null
72033+++ b/include/linux/gracl_compat.h
72034@@ -0,0 +1,156 @@
72035+#ifndef GR_ACL_COMPAT_H
72036+#define GR_ACL_COMPAT_H
72037+
72038+#include <linux/resource.h>
72039+#include <asm/resource.h>
72040+
72041+struct sprole_pw_compat {
72042+ compat_uptr_t rolename;
72043+ unsigned char salt[GR_SALT_LEN];
72044+ unsigned char sum[GR_SHA_LEN];
72045+};
72046+
72047+struct gr_hash_struct_compat {
72048+ compat_uptr_t table;
72049+ compat_uptr_t nametable;
72050+ compat_uptr_t first;
72051+ __u32 table_size;
72052+ __u32 used_size;
72053+ int type;
72054+};
72055+
72056+struct acl_subject_label_compat {
72057+ compat_uptr_t filename;
72058+ compat_ino_t inode;
72059+ __u32 device;
72060+ __u32 mode;
72061+ kernel_cap_t cap_mask;
72062+ kernel_cap_t cap_lower;
72063+ kernel_cap_t cap_invert_audit;
72064+
72065+ struct compat_rlimit res[GR_NLIMITS];
72066+ __u32 resmask;
72067+
72068+ __u8 user_trans_type;
72069+ __u8 group_trans_type;
72070+ compat_uptr_t user_transitions;
72071+ compat_uptr_t group_transitions;
72072+ __u16 user_trans_num;
72073+ __u16 group_trans_num;
72074+
72075+ __u32 sock_families[2];
72076+ __u32 ip_proto[8];
72077+ __u32 ip_type;
72078+ compat_uptr_t ips;
72079+ __u32 ip_num;
72080+ __u32 inaddr_any_override;
72081+
72082+ __u32 crashes;
72083+ compat_ulong_t expires;
72084+
72085+ compat_uptr_t parent_subject;
72086+ compat_uptr_t hash;
72087+ compat_uptr_t prev;
72088+ compat_uptr_t next;
72089+
72090+ compat_uptr_t obj_hash;
72091+ __u32 obj_hash_size;
72092+ __u16 pax_flags;
72093+};
72094+
72095+struct role_allowed_ip_compat {
72096+ __u32 addr;
72097+ __u32 netmask;
72098+
72099+ compat_uptr_t prev;
72100+ compat_uptr_t next;
72101+};
72102+
72103+struct role_transition_compat {
72104+ compat_uptr_t rolename;
72105+
72106+ compat_uptr_t prev;
72107+ compat_uptr_t next;
72108+};
72109+
72110+struct acl_role_label_compat {
72111+ compat_uptr_t rolename;
72112+ uid_t uidgid;
72113+ __u16 roletype;
72114+
72115+ __u16 auth_attempts;
72116+ compat_ulong_t expires;
72117+
72118+ compat_uptr_t root_label;
72119+ compat_uptr_t hash;
72120+
72121+ compat_uptr_t prev;
72122+ compat_uptr_t next;
72123+
72124+ compat_uptr_t transitions;
72125+ compat_uptr_t allowed_ips;
72126+ compat_uptr_t domain_children;
72127+ __u16 domain_child_num;
72128+
72129+ umode_t umask;
72130+
72131+ compat_uptr_t subj_hash;
72132+ __u32 subj_hash_size;
72133+};
72134+
72135+struct user_acl_role_db_compat {
72136+ compat_uptr_t r_table;
72137+ __u32 num_pointers;
72138+ __u32 num_roles;
72139+ __u32 num_domain_children;
72140+ __u32 num_subjects;
72141+ __u32 num_objects;
72142+};
72143+
72144+struct acl_object_label_compat {
72145+ compat_uptr_t filename;
72146+ compat_ino_t inode;
72147+ __u32 device;
72148+ __u32 mode;
72149+
72150+ compat_uptr_t nested;
72151+ compat_uptr_t globbed;
72152+
72153+ compat_uptr_t prev;
72154+ compat_uptr_t next;
72155+};
72156+
72157+struct acl_ip_label_compat {
72158+ compat_uptr_t iface;
72159+ __u32 addr;
72160+ __u32 netmask;
72161+ __u16 low, high;
72162+ __u8 mode;
72163+ __u32 type;
72164+ __u32 proto[8];
72165+
72166+ compat_uptr_t prev;
72167+ compat_uptr_t next;
72168+};
72169+
72170+struct gr_arg_compat {
72171+ struct user_acl_role_db_compat role_db;
72172+ unsigned char pw[GR_PW_LEN];
72173+ unsigned char salt[GR_SALT_LEN];
72174+ unsigned char sum[GR_SHA_LEN];
72175+ unsigned char sp_role[GR_SPROLE_LEN];
72176+ compat_uptr_t sprole_pws;
72177+ __u32 segv_device;
72178+ compat_ino_t segv_inode;
72179+ uid_t segv_uid;
72180+ __u16 num_sprole_pws;
72181+ __u16 mode;
72182+};
72183+
72184+struct gr_arg_wrapper_compat {
72185+ compat_uptr_t arg;
72186+ __u32 version;
72187+ __u32 size;
72188+};
72189+
72190+#endif
72191diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
72192new file mode 100644
72193index 0000000..323ecf2
72194--- /dev/null
72195+++ b/include/linux/gralloc.h
72196@@ -0,0 +1,9 @@
72197+#ifndef __GRALLOC_H
72198+#define __GRALLOC_H
72199+
72200+void acl_free_all(void);
72201+int acl_alloc_stack_init(unsigned long size);
72202+void *acl_alloc(unsigned long len);
72203+void *acl_alloc_num(unsigned long num, unsigned long len);
72204+
72205+#endif
72206diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
72207new file mode 100644
72208index 0000000..be66033
72209--- /dev/null
72210+++ b/include/linux/grdefs.h
72211@@ -0,0 +1,140 @@
72212+#ifndef GRDEFS_H
72213+#define GRDEFS_H
72214+
72215+/* Begin grsecurity status declarations */
72216+
72217+enum {
72218+ GR_READY = 0x01,
72219+ GR_STATUS_INIT = 0x00 // disabled state
72220+};
72221+
72222+/* Begin ACL declarations */
72223+
72224+/* Role flags */
72225+
72226+enum {
72227+ GR_ROLE_USER = 0x0001,
72228+ GR_ROLE_GROUP = 0x0002,
72229+ GR_ROLE_DEFAULT = 0x0004,
72230+ GR_ROLE_SPECIAL = 0x0008,
72231+ GR_ROLE_AUTH = 0x0010,
72232+ GR_ROLE_NOPW = 0x0020,
72233+ GR_ROLE_GOD = 0x0040,
72234+ GR_ROLE_LEARN = 0x0080,
72235+ GR_ROLE_TPE = 0x0100,
72236+ GR_ROLE_DOMAIN = 0x0200,
72237+ GR_ROLE_PAM = 0x0400,
72238+ GR_ROLE_PERSIST = 0x0800
72239+};
72240+
72241+/* ACL Subject and Object mode flags */
72242+enum {
72243+ GR_DELETED = 0x80000000
72244+};
72245+
72246+/* ACL Object-only mode flags */
72247+enum {
72248+ GR_READ = 0x00000001,
72249+ GR_APPEND = 0x00000002,
72250+ GR_WRITE = 0x00000004,
72251+ GR_EXEC = 0x00000008,
72252+ GR_FIND = 0x00000010,
72253+ GR_INHERIT = 0x00000020,
72254+ GR_SETID = 0x00000040,
72255+ GR_CREATE = 0x00000080,
72256+ GR_DELETE = 0x00000100,
72257+ GR_LINK = 0x00000200,
72258+ GR_AUDIT_READ = 0x00000400,
72259+ GR_AUDIT_APPEND = 0x00000800,
72260+ GR_AUDIT_WRITE = 0x00001000,
72261+ GR_AUDIT_EXEC = 0x00002000,
72262+ GR_AUDIT_FIND = 0x00004000,
72263+ GR_AUDIT_INHERIT= 0x00008000,
72264+ GR_AUDIT_SETID = 0x00010000,
72265+ GR_AUDIT_CREATE = 0x00020000,
72266+ GR_AUDIT_DELETE = 0x00040000,
72267+ GR_AUDIT_LINK = 0x00080000,
72268+ GR_PTRACERD = 0x00100000,
72269+ GR_NOPTRACE = 0x00200000,
72270+ GR_SUPPRESS = 0x00400000,
72271+ GR_NOLEARN = 0x00800000,
72272+ GR_INIT_TRANSFER= 0x01000000
72273+};
72274+
72275+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
72276+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
72277+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
72278+
72279+/* ACL subject-only mode flags */
72280+enum {
72281+ GR_KILL = 0x00000001,
72282+ GR_VIEW = 0x00000002,
72283+ GR_PROTECTED = 0x00000004,
72284+ GR_LEARN = 0x00000008,
72285+ GR_OVERRIDE = 0x00000010,
72286+ /* just a placeholder, this mode is only used in userspace */
72287+ GR_DUMMY = 0x00000020,
72288+ GR_PROTSHM = 0x00000040,
72289+ GR_KILLPROC = 0x00000080,
72290+ GR_KILLIPPROC = 0x00000100,
72291+ /* just a placeholder, this mode is only used in userspace */
72292+ GR_NOTROJAN = 0x00000200,
72293+ GR_PROTPROCFD = 0x00000400,
72294+ GR_PROCACCT = 0x00000800,
72295+ GR_RELAXPTRACE = 0x00001000,
72296+ //GR_NESTED = 0x00002000,
72297+ GR_INHERITLEARN = 0x00004000,
72298+ GR_PROCFIND = 0x00008000,
72299+ GR_POVERRIDE = 0x00010000,
72300+ GR_KERNELAUTH = 0x00020000,
72301+ GR_ATSECURE = 0x00040000,
72302+ GR_SHMEXEC = 0x00080000
72303+};
72304+
72305+enum {
72306+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
72307+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
72308+ GR_PAX_ENABLE_MPROTECT = 0x0004,
72309+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
72310+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
72311+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
72312+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
72313+ GR_PAX_DISABLE_MPROTECT = 0x0400,
72314+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
72315+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
72316+};
72317+
72318+enum {
72319+ GR_ID_USER = 0x01,
72320+ GR_ID_GROUP = 0x02,
72321+};
72322+
72323+enum {
72324+ GR_ID_ALLOW = 0x01,
72325+ GR_ID_DENY = 0x02,
72326+};
72327+
72328+#define GR_CRASH_RES 31
72329+#define GR_UIDTABLE_MAX 500
72330+
72331+/* begin resource learning section */
72332+enum {
72333+ GR_RLIM_CPU_BUMP = 60,
72334+ GR_RLIM_FSIZE_BUMP = 50000,
72335+ GR_RLIM_DATA_BUMP = 10000,
72336+ GR_RLIM_STACK_BUMP = 1000,
72337+ GR_RLIM_CORE_BUMP = 10000,
72338+ GR_RLIM_RSS_BUMP = 500000,
72339+ GR_RLIM_NPROC_BUMP = 1,
72340+ GR_RLIM_NOFILE_BUMP = 5,
72341+ GR_RLIM_MEMLOCK_BUMP = 50000,
72342+ GR_RLIM_AS_BUMP = 500000,
72343+ GR_RLIM_LOCKS_BUMP = 2,
72344+ GR_RLIM_SIGPENDING_BUMP = 5,
72345+ GR_RLIM_MSGQUEUE_BUMP = 10000,
72346+ GR_RLIM_NICE_BUMP = 1,
72347+ GR_RLIM_RTPRIO_BUMP = 1,
72348+ GR_RLIM_RTTIME_BUMP = 1000000
72349+};
72350+
72351+#endif
72352diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
72353new file mode 100644
72354index 0000000..fd8598b
72355--- /dev/null
72356+++ b/include/linux/grinternal.h
72357@@ -0,0 +1,228 @@
72358+#ifndef __GRINTERNAL_H
72359+#define __GRINTERNAL_H
72360+
72361+#ifdef CONFIG_GRKERNSEC
72362+
72363+#include <linux/fs.h>
72364+#include <linux/mnt_namespace.h>
72365+#include <linux/nsproxy.h>
72366+#include <linux/gracl.h>
72367+#include <linux/grdefs.h>
72368+#include <linux/grmsg.h>
72369+
72370+void gr_add_learn_entry(const char *fmt, ...)
72371+ __attribute__ ((format (printf, 1, 2)));
72372+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
72373+ const struct vfsmount *mnt);
72374+__u32 gr_check_create(const struct dentry *new_dentry,
72375+ const struct dentry *parent,
72376+ const struct vfsmount *mnt, const __u32 mode);
72377+int gr_check_protected_task(const struct task_struct *task);
72378+__u32 to_gr_audit(const __u32 reqmode);
72379+int gr_set_acls(const int type);
72380+int gr_apply_subject_to_task(struct task_struct *task);
72381+int gr_acl_is_enabled(void);
72382+char gr_roletype_to_char(void);
72383+
72384+void gr_handle_alertkill(struct task_struct *task);
72385+char *gr_to_filename(const struct dentry *dentry,
72386+ const struct vfsmount *mnt);
72387+char *gr_to_filename1(const struct dentry *dentry,
72388+ const struct vfsmount *mnt);
72389+char *gr_to_filename2(const struct dentry *dentry,
72390+ const struct vfsmount *mnt);
72391+char *gr_to_filename3(const struct dentry *dentry,
72392+ const struct vfsmount *mnt);
72393+
72394+extern int grsec_enable_ptrace_readexec;
72395+extern int grsec_enable_harden_ptrace;
72396+extern int grsec_enable_link;
72397+extern int grsec_enable_fifo;
72398+extern int grsec_enable_execve;
72399+extern int grsec_enable_shm;
72400+extern int grsec_enable_execlog;
72401+extern int grsec_enable_signal;
72402+extern int grsec_enable_audit_ptrace;
72403+extern int grsec_enable_forkfail;
72404+extern int grsec_enable_time;
72405+extern int grsec_enable_rofs;
72406+extern int grsec_enable_chroot_shmat;
72407+extern int grsec_enable_chroot_mount;
72408+extern int grsec_enable_chroot_double;
72409+extern int grsec_enable_chroot_pivot;
72410+extern int grsec_enable_chroot_chdir;
72411+extern int grsec_enable_chroot_chmod;
72412+extern int grsec_enable_chroot_mknod;
72413+extern int grsec_enable_chroot_fchdir;
72414+extern int grsec_enable_chroot_nice;
72415+extern int grsec_enable_chroot_execlog;
72416+extern int grsec_enable_chroot_caps;
72417+extern int grsec_enable_chroot_sysctl;
72418+extern int grsec_enable_chroot_unix;
72419+extern int grsec_enable_symlinkown;
72420+extern kgid_t grsec_symlinkown_gid;
72421+extern int grsec_enable_tpe;
72422+extern kgid_t grsec_tpe_gid;
72423+extern int grsec_enable_tpe_all;
72424+extern int grsec_enable_tpe_invert;
72425+extern int grsec_enable_socket_all;
72426+extern kgid_t grsec_socket_all_gid;
72427+extern int grsec_enable_socket_client;
72428+extern kgid_t grsec_socket_client_gid;
72429+extern int grsec_enable_socket_server;
72430+extern kgid_t grsec_socket_server_gid;
72431+extern kgid_t grsec_audit_gid;
72432+extern int grsec_enable_group;
72433+extern int grsec_enable_log_rwxmaps;
72434+extern int grsec_enable_mount;
72435+extern int grsec_enable_chdir;
72436+extern int grsec_resource_logging;
72437+extern int grsec_enable_blackhole;
72438+extern int grsec_lastack_retries;
72439+extern int grsec_enable_brute;
72440+extern int grsec_lock;
72441+
72442+extern spinlock_t grsec_alert_lock;
72443+extern unsigned long grsec_alert_wtime;
72444+extern unsigned long grsec_alert_fyet;
72445+
72446+extern spinlock_t grsec_audit_lock;
72447+
72448+extern rwlock_t grsec_exec_file_lock;
72449+
72450+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
72451+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
72452+ (tsk)->exec_file->f_path.mnt) : "/")
72453+
72454+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
72455+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
72456+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
72457+
72458+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
72459+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
72460+ (tsk)->exec_file->f_path.mnt) : "/")
72461+
72462+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
72463+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
72464+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
72465+
72466+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
72467+
72468+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
72469+
72470+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
72471+{
72472+ if (file1 && file2) {
72473+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
72474+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
72475+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
72476+ return true;
72477+ }
72478+
72479+ return false;
72480+}
72481+
72482+#define GR_CHROOT_CAPS {{ \
72483+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
72484+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
72485+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
72486+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
72487+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
72488+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
72489+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
72490+
72491+#define security_learn(normal_msg,args...) \
72492+({ \
72493+ read_lock(&grsec_exec_file_lock); \
72494+ gr_add_learn_entry(normal_msg "\n", ## args); \
72495+ read_unlock(&grsec_exec_file_lock); \
72496+})
72497+
72498+enum {
72499+ GR_DO_AUDIT,
72500+ GR_DONT_AUDIT,
72501+ /* used for non-audit messages that we shouldn't kill the task on */
72502+ GR_DONT_AUDIT_GOOD
72503+};
72504+
72505+enum {
72506+ GR_TTYSNIFF,
72507+ GR_RBAC,
72508+ GR_RBAC_STR,
72509+ GR_STR_RBAC,
72510+ GR_RBAC_MODE2,
72511+ GR_RBAC_MODE3,
72512+ GR_FILENAME,
72513+ GR_SYSCTL_HIDDEN,
72514+ GR_NOARGS,
72515+ GR_ONE_INT,
72516+ GR_ONE_INT_TWO_STR,
72517+ GR_ONE_STR,
72518+ GR_STR_INT,
72519+ GR_TWO_STR_INT,
72520+ GR_TWO_INT,
72521+ GR_TWO_U64,
72522+ GR_THREE_INT,
72523+ GR_FIVE_INT_TWO_STR,
72524+ GR_TWO_STR,
72525+ GR_THREE_STR,
72526+ GR_FOUR_STR,
72527+ GR_STR_FILENAME,
72528+ GR_FILENAME_STR,
72529+ GR_FILENAME_TWO_INT,
72530+ GR_FILENAME_TWO_INT_STR,
72531+ GR_TEXTREL,
72532+ GR_PTRACE,
72533+ GR_RESOURCE,
72534+ GR_CAP,
72535+ GR_SIG,
72536+ GR_SIG2,
72537+ GR_CRASH1,
72538+ GR_CRASH2,
72539+ GR_PSACCT,
72540+ GR_RWXMAP,
72541+ GR_RWXMAPVMA
72542+};
72543+
72544+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
72545+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
72546+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
72547+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
72548+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
72549+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
72550+#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)
72551+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
72552+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
72553+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
72554+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
72555+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
72556+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
72557+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
72558+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
72559+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
72560+#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)
72561+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
72562+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
72563+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
72564+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
72565+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
72566+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
72567+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
72568+#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)
72569+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
72570+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
72571+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
72572+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
72573+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
72574+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
72575+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
72576+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
72577+#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)
72578+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
72579+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
72580+
72581+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
72582+
72583+#endif
72584+
72585+#endif
72586diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
72587new file mode 100644
72588index 0000000..a4396b5
72589--- /dev/null
72590+++ b/include/linux/grmsg.h
72591@@ -0,0 +1,113 @@
72592+#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"
72593+#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"
72594+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
72595+#define GR_STOPMOD_MSG "denied modification of module state by "
72596+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
72597+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
72598+#define GR_IOPERM_MSG "denied use of ioperm() by "
72599+#define GR_IOPL_MSG "denied use of iopl() by "
72600+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
72601+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
72602+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
72603+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
72604+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
72605+#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"
72606+#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"
72607+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
72608+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
72609+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
72610+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
72611+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
72612+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
72613+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
72614+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
72615+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
72616+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
72617+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
72618+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
72619+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
72620+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
72621+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
72622+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
72623+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
72624+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
72625+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
72626+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
72627+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
72628+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
72629+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
72630+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
72631+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
72632+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
72633+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
72634+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
72635+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
72636+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
72637+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
72638+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
72639+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
72640+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
72641+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
72642+#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"
72643+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
72644+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
72645+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
72646+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
72647+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
72648+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
72649+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
72650+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
72651+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
72652+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
72653+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
72654+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
72655+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
72656+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
72657+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
72658+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
72659+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
72660+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
72661+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
72662+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
72663+#define GR_FAILFORK_MSG "failed fork with errno %s by "
72664+#define GR_NICE_CHROOT_MSG "denied priority change by "
72665+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
72666+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
72667+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
72668+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
72669+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
72670+#define GR_TIME_MSG "time set by "
72671+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
72672+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
72673+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
72674+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
72675+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
72676+#define GR_BIND_MSG "denied bind() by "
72677+#define GR_CONNECT_MSG "denied connect() by "
72678+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
72679+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
72680+#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"
72681+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
72682+#define GR_CAP_ACL_MSG "use of %s denied for "
72683+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
72684+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
72685+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
72686+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
72687+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
72688+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
72689+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
72690+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
72691+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
72692+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
72693+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
72694+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
72695+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
72696+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
72697+#define GR_VM86_MSG "denied use of vm86 by "
72698+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
72699+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
72700+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
72701+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
72702+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
72703+#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 "
72704+#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 "
72705diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
72706new file mode 100644
72707index 0000000..3676b0b
72708--- /dev/null
72709+++ b/include/linux/grsecurity.h
72710@@ -0,0 +1,242 @@
72711+#ifndef GR_SECURITY_H
72712+#define GR_SECURITY_H
72713+#include <linux/fs.h>
72714+#include <linux/fs_struct.h>
72715+#include <linux/binfmts.h>
72716+#include <linux/gracl.h>
72717+
72718+/* notify of brain-dead configs */
72719+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72720+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
72721+#endif
72722+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
72723+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
72724+#endif
72725+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
72726+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
72727+#endif
72728+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
72729+#error "CONFIG_PAX enabled, but no PaX options are enabled."
72730+#endif
72731+
72732+void gr_handle_brute_attach(unsigned long mm_flags);
72733+void gr_handle_brute_check(void);
72734+void gr_handle_kernel_exploit(void);
72735+
72736+char gr_roletype_to_char(void);
72737+
72738+int gr_acl_enable_at_secure(void);
72739+
72740+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
72741+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
72742+
72743+void gr_del_task_from_ip_table(struct task_struct *p);
72744+
72745+int gr_pid_is_chrooted(struct task_struct *p);
72746+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
72747+int gr_handle_chroot_nice(void);
72748+int gr_handle_chroot_sysctl(const int op);
72749+int gr_handle_chroot_setpriority(struct task_struct *p,
72750+ const int niceval);
72751+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
72752+int gr_handle_chroot_chroot(const struct dentry *dentry,
72753+ const struct vfsmount *mnt);
72754+void gr_handle_chroot_chdir(const struct path *path);
72755+int gr_handle_chroot_chmod(const struct dentry *dentry,
72756+ const struct vfsmount *mnt, const int mode);
72757+int gr_handle_chroot_mknod(const struct dentry *dentry,
72758+ const struct vfsmount *mnt, const int mode);
72759+int gr_handle_chroot_mount(const struct dentry *dentry,
72760+ const struct vfsmount *mnt,
72761+ const char *dev_name);
72762+int gr_handle_chroot_pivot(void);
72763+int gr_handle_chroot_unix(const pid_t pid);
72764+
72765+int gr_handle_rawio(const struct inode *inode);
72766+
72767+void gr_handle_ioperm(void);
72768+void gr_handle_iopl(void);
72769+
72770+umode_t gr_acl_umask(void);
72771+
72772+int gr_tpe_allow(const struct file *file);
72773+
72774+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
72775+void gr_clear_chroot_entries(struct task_struct *task);
72776+
72777+void gr_log_forkfail(const int retval);
72778+void gr_log_timechange(void);
72779+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
72780+void gr_log_chdir(const struct dentry *dentry,
72781+ const struct vfsmount *mnt);
72782+void gr_log_chroot_exec(const struct dentry *dentry,
72783+ const struct vfsmount *mnt);
72784+void gr_log_remount(const char *devname, const int retval);
72785+void gr_log_unmount(const char *devname, const int retval);
72786+void gr_log_mount(const char *from, const char *to, const int retval);
72787+void gr_log_textrel(struct vm_area_struct *vma);
72788+void gr_log_ptgnustack(struct file *file);
72789+void gr_log_rwxmmap(struct file *file);
72790+void gr_log_rwxmprotect(struct vm_area_struct *vma);
72791+
72792+int gr_handle_follow_link(const struct inode *parent,
72793+ const struct inode *inode,
72794+ const struct dentry *dentry,
72795+ const struct vfsmount *mnt);
72796+int gr_handle_fifo(const struct dentry *dentry,
72797+ const struct vfsmount *mnt,
72798+ const struct dentry *dir, const int flag,
72799+ const int acc_mode);
72800+int gr_handle_hardlink(const struct dentry *dentry,
72801+ const struct vfsmount *mnt,
72802+ struct inode *inode,
72803+ const int mode, const struct filename *to);
72804+
72805+int gr_is_capable(const int cap);
72806+int gr_is_capable_nolog(const int cap);
72807+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72808+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
72809+
72810+void gr_copy_label(struct task_struct *tsk);
72811+void gr_handle_crash(struct task_struct *task, const int sig);
72812+int gr_handle_signal(const struct task_struct *p, const int sig);
72813+int gr_check_crash_uid(const kuid_t uid);
72814+int gr_check_protected_task(const struct task_struct *task);
72815+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
72816+int gr_acl_handle_mmap(const struct file *file,
72817+ const unsigned long prot);
72818+int gr_acl_handle_mprotect(const struct file *file,
72819+ const unsigned long prot);
72820+int gr_check_hidden_task(const struct task_struct *tsk);
72821+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
72822+ const struct vfsmount *mnt);
72823+__u32 gr_acl_handle_utime(const struct dentry *dentry,
72824+ const struct vfsmount *mnt);
72825+__u32 gr_acl_handle_access(const struct dentry *dentry,
72826+ const struct vfsmount *mnt, const int fmode);
72827+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
72828+ const struct vfsmount *mnt, umode_t *mode);
72829+__u32 gr_acl_handle_chown(const struct dentry *dentry,
72830+ const struct vfsmount *mnt);
72831+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
72832+ const struct vfsmount *mnt);
72833+int gr_handle_ptrace(struct task_struct *task, const long request);
72834+int gr_handle_proc_ptrace(struct task_struct *task);
72835+__u32 gr_acl_handle_execve(const struct dentry *dentry,
72836+ const struct vfsmount *mnt);
72837+int gr_check_crash_exec(const struct file *filp);
72838+int gr_acl_is_enabled(void);
72839+void gr_set_kernel_label(struct task_struct *task);
72840+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
72841+ const kgid_t gid);
72842+int gr_set_proc_label(const struct dentry *dentry,
72843+ const struct vfsmount *mnt,
72844+ const int unsafe_flags);
72845+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
72846+ const struct vfsmount *mnt);
72847+__u32 gr_acl_handle_open(const struct dentry *dentry,
72848+ const struct vfsmount *mnt, int acc_mode);
72849+__u32 gr_acl_handle_creat(const struct dentry *dentry,
72850+ const struct dentry *p_dentry,
72851+ const struct vfsmount *p_mnt,
72852+ int open_flags, int acc_mode, const int imode);
72853+void gr_handle_create(const struct dentry *dentry,
72854+ const struct vfsmount *mnt);
72855+void gr_handle_proc_create(const struct dentry *dentry,
72856+ const struct inode *inode);
72857+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
72858+ const struct dentry *parent_dentry,
72859+ const struct vfsmount *parent_mnt,
72860+ const int mode);
72861+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
72862+ const struct dentry *parent_dentry,
72863+ const struct vfsmount *parent_mnt);
72864+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
72865+ const struct vfsmount *mnt);
72866+void gr_handle_delete(const ino_t ino, const dev_t dev);
72867+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
72868+ const struct vfsmount *mnt);
72869+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
72870+ const struct dentry *parent_dentry,
72871+ const struct vfsmount *parent_mnt,
72872+ const struct filename *from);
72873+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
72874+ const struct dentry *parent_dentry,
72875+ const struct vfsmount *parent_mnt,
72876+ const struct dentry *old_dentry,
72877+ const struct vfsmount *old_mnt, const struct filename *to);
72878+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
72879+int gr_acl_handle_rename(struct dentry *new_dentry,
72880+ struct dentry *parent_dentry,
72881+ const struct vfsmount *parent_mnt,
72882+ struct dentry *old_dentry,
72883+ struct inode *old_parent_inode,
72884+ struct vfsmount *old_mnt, const struct filename *newname);
72885+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72886+ struct dentry *old_dentry,
72887+ struct dentry *new_dentry,
72888+ struct vfsmount *mnt, const __u8 replace);
72889+__u32 gr_check_link(const struct dentry *new_dentry,
72890+ const struct dentry *parent_dentry,
72891+ const struct vfsmount *parent_mnt,
72892+ const struct dentry *old_dentry,
72893+ const struct vfsmount *old_mnt);
72894+int gr_acl_handle_filldir(const struct file *file, const char *name,
72895+ const unsigned int namelen, const ino_t ino);
72896+
72897+__u32 gr_acl_handle_unix(const struct dentry *dentry,
72898+ const struct vfsmount *mnt);
72899+void gr_acl_handle_exit(void);
72900+void gr_acl_handle_psacct(struct task_struct *task, const long code);
72901+int gr_acl_handle_procpidmem(const struct task_struct *task);
72902+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
72903+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
72904+void gr_audit_ptrace(struct task_struct *task);
72905+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
72906+void gr_put_exec_file(struct task_struct *task);
72907+
72908+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
72909+
72910+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
72911+extern void gr_learn_resource(const struct task_struct *task, const int res,
72912+ const unsigned long wanted, const int gt);
72913+#else
72914+static inline void gr_learn_resource(const struct task_struct *task, const int res,
72915+ const unsigned long wanted, const int gt)
72916+{
72917+}
72918+#endif
72919+
72920+#ifdef CONFIG_GRKERNSEC_RESLOG
72921+extern void gr_log_resource(const struct task_struct *task, const int res,
72922+ const unsigned long wanted, const int gt);
72923+#else
72924+static inline void gr_log_resource(const struct task_struct *task, const int res,
72925+ const unsigned long wanted, const int gt)
72926+{
72927+}
72928+#endif
72929+
72930+#ifdef CONFIG_GRKERNSEC
72931+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
72932+void gr_handle_vm86(void);
72933+void gr_handle_mem_readwrite(u64 from, u64 to);
72934+
72935+void gr_log_badprocpid(const char *entry);
72936+
72937+extern int grsec_enable_dmesg;
72938+extern int grsec_disable_privio;
72939+
72940+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72941+extern kgid_t grsec_proc_gid;
72942+#endif
72943+
72944+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72945+extern int grsec_enable_chroot_findtask;
72946+#endif
72947+#ifdef CONFIG_GRKERNSEC_SETXID
72948+extern int grsec_enable_setxid;
72949+#endif
72950+#endif
72951+
72952+#endif
72953diff --git a/include/linux/grsock.h b/include/linux/grsock.h
72954new file mode 100644
72955index 0000000..e7ffaaf
72956--- /dev/null
72957+++ b/include/linux/grsock.h
72958@@ -0,0 +1,19 @@
72959+#ifndef __GRSOCK_H
72960+#define __GRSOCK_H
72961+
72962+extern void gr_attach_curr_ip(const struct sock *sk);
72963+extern int gr_handle_sock_all(const int family, const int type,
72964+ const int protocol);
72965+extern int gr_handle_sock_server(const struct sockaddr *sck);
72966+extern int gr_handle_sock_server_other(const struct sock *sck);
72967+extern int gr_handle_sock_client(const struct sockaddr *sck);
72968+extern int gr_search_connect(struct socket * sock,
72969+ struct sockaddr_in * addr);
72970+extern int gr_search_bind(struct socket * sock,
72971+ struct sockaddr_in * addr);
72972+extern int gr_search_listen(struct socket * sock);
72973+extern int gr_search_accept(struct socket * sock);
72974+extern int gr_search_socket(const int domain, const int type,
72975+ const int protocol);
72976+
72977+#endif
72978diff --git a/include/linux/highmem.h b/include/linux/highmem.h
72979index 7fb31da..08b5114 100644
72980--- a/include/linux/highmem.h
72981+++ b/include/linux/highmem.h
72982@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
72983 kunmap_atomic(kaddr);
72984 }
72985
72986+static inline void sanitize_highpage(struct page *page)
72987+{
72988+ void *kaddr;
72989+ unsigned long flags;
72990+
72991+ local_irq_save(flags);
72992+ kaddr = kmap_atomic(page);
72993+ clear_page(kaddr);
72994+ kunmap_atomic(kaddr);
72995+ local_irq_restore(flags);
72996+}
72997+
72998 static inline void zero_user_segments(struct page *page,
72999 unsigned start1, unsigned end1,
73000 unsigned start2, unsigned end2)
73001diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
73002index 1c7b89a..7f52502 100644
73003--- a/include/linux/hwmon-sysfs.h
73004+++ b/include/linux/hwmon-sysfs.h
73005@@ -25,7 +25,8 @@
73006 struct sensor_device_attribute{
73007 struct device_attribute dev_attr;
73008 int index;
73009-};
73010+} __do_const;
73011+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
73012 #define to_sensor_dev_attr(_dev_attr) \
73013 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
73014
73015@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
73016 struct device_attribute dev_attr;
73017 u8 index;
73018 u8 nr;
73019-};
73020+} __do_const;
73021 #define to_sensor_dev_attr_2(_dev_attr) \
73022 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
73023
73024diff --git a/include/linux/i2c.h b/include/linux/i2c.h
73025index e988fa9..ff9f17e 100644
73026--- a/include/linux/i2c.h
73027+++ b/include/linux/i2c.h
73028@@ -366,6 +366,7 @@ struct i2c_algorithm {
73029 /* To determine what the adapter supports */
73030 u32 (*functionality) (struct i2c_adapter *);
73031 };
73032+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
73033
73034 /**
73035 * struct i2c_bus_recovery_info - I2C bus recovery information
73036diff --git a/include/linux/i2o.h b/include/linux/i2o.h
73037index d23c3c2..eb63c81 100644
73038--- a/include/linux/i2o.h
73039+++ b/include/linux/i2o.h
73040@@ -565,7 +565,7 @@ struct i2o_controller {
73041 struct i2o_device *exec; /* Executive */
73042 #if BITS_PER_LONG == 64
73043 spinlock_t context_list_lock; /* lock for context_list */
73044- atomic_t context_list_counter; /* needed for unique contexts */
73045+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
73046 struct list_head context_list; /* list of context id's
73047 and pointers */
73048 #endif
73049diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
73050index aff7ad8..3942bbd 100644
73051--- a/include/linux/if_pppox.h
73052+++ b/include/linux/if_pppox.h
73053@@ -76,7 +76,7 @@ struct pppox_proto {
73054 int (*ioctl)(struct socket *sock, unsigned int cmd,
73055 unsigned long arg);
73056 struct module *owner;
73057-};
73058+} __do_const;
73059
73060 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
73061 extern void unregister_pppox_proto(int proto_num);
73062diff --git a/include/linux/init.h b/include/linux/init.h
73063index 8618147..0821126 100644
73064--- a/include/linux/init.h
73065+++ b/include/linux/init.h
73066@@ -39,9 +39,36 @@
73067 * Also note, that this data cannot be "const".
73068 */
73069
73070+#ifdef MODULE
73071+#define add_init_latent_entropy
73072+#define add_devinit_latent_entropy
73073+#define add_cpuinit_latent_entropy
73074+#define add_meminit_latent_entropy
73075+#else
73076+#define add_init_latent_entropy __latent_entropy
73077+
73078+#ifdef CONFIG_HOTPLUG
73079+#define add_devinit_latent_entropy
73080+#else
73081+#define add_devinit_latent_entropy __latent_entropy
73082+#endif
73083+
73084+#ifdef CONFIG_HOTPLUG_CPU
73085+#define add_cpuinit_latent_entropy
73086+#else
73087+#define add_cpuinit_latent_entropy __latent_entropy
73088+#endif
73089+
73090+#ifdef CONFIG_MEMORY_HOTPLUG
73091+#define add_meminit_latent_entropy
73092+#else
73093+#define add_meminit_latent_entropy __latent_entropy
73094+#endif
73095+#endif
73096+
73097 /* These are for everybody (although not all archs will actually
73098 discard it in modules) */
73099-#define __init __section(.init.text) __cold notrace
73100+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
73101 #define __initdata __section(.init.data)
73102 #define __initconst __constsection(.init.rodata)
73103 #define __exitdata __section(.exit.data)
73104@@ -94,7 +121,7 @@
73105 #define __exit __section(.exit.text) __exitused __cold notrace
73106
73107 /* Used for HOTPLUG_CPU */
73108-#define __cpuinit __section(.cpuinit.text) __cold notrace
73109+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
73110 #define __cpuinitdata __section(.cpuinit.data)
73111 #define __cpuinitconst __constsection(.cpuinit.rodata)
73112 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
73113@@ -102,7 +129,7 @@
73114 #define __cpuexitconst __constsection(.cpuexit.rodata)
73115
73116 /* Used for MEMORY_HOTPLUG */
73117-#define __meminit __section(.meminit.text) __cold notrace
73118+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
73119 #define __meminitdata __section(.meminit.data)
73120 #define __meminitconst __constsection(.meminit.rodata)
73121 #define __memexit __section(.memexit.text) __exitused __cold notrace
73122diff --git a/include/linux/init_task.h b/include/linux/init_task.h
73123index 5cd0f09..c9f67cc 100644
73124--- a/include/linux/init_task.h
73125+++ b/include/linux/init_task.h
73126@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
73127
73128 #define INIT_TASK_COMM "swapper"
73129
73130+#ifdef CONFIG_X86
73131+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
73132+#else
73133+#define INIT_TASK_THREAD_INFO
73134+#endif
73135+
73136 /*
73137 * INIT_TASK is used to set up the first task table, touch at
73138 * your own risk!. Base=0, limit=0x1fffff (=2MB)
73139@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
73140 RCU_POINTER_INITIALIZER(cred, &init_cred), \
73141 .comm = INIT_TASK_COMM, \
73142 .thread = INIT_THREAD, \
73143+ INIT_TASK_THREAD_INFO \
73144 .fs = &init_fs, \
73145 .files = &init_files, \
73146 .signal = &init_signals, \
73147diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
73148index 5fa5afe..ac55b25 100644
73149--- a/include/linux/interrupt.h
73150+++ b/include/linux/interrupt.h
73151@@ -430,7 +430,7 @@ enum
73152 /* map softirq index to softirq name. update 'softirq_to_name' in
73153 * kernel/softirq.c when adding a new softirq.
73154 */
73155-extern char *softirq_to_name[NR_SOFTIRQS];
73156+extern const char * const softirq_to_name[NR_SOFTIRQS];
73157
73158 /* softirq mask and active fields moved to irq_cpustat_t in
73159 * asm/hardirq.h to get better cache usage. KAO
73160@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
73161
73162 struct softirq_action
73163 {
73164- void (*action)(struct softirq_action *);
73165-};
73166+ void (*action)(void);
73167+} __no_const;
73168
73169 asmlinkage void do_softirq(void);
73170 asmlinkage void __do_softirq(void);
73171-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
73172+extern void open_softirq(int nr, void (*action)(void));
73173 extern void softirq_init(void);
73174 extern void __raise_softirq_irqoff(unsigned int nr);
73175
73176diff --git a/include/linux/iommu.h b/include/linux/iommu.h
73177index 3aeb730..2177f39 100644
73178--- a/include/linux/iommu.h
73179+++ b/include/linux/iommu.h
73180@@ -113,7 +113,7 @@ struct iommu_ops {
73181 u32 (*domain_get_windows)(struct iommu_domain *domain);
73182
73183 unsigned long pgsize_bitmap;
73184-};
73185+} __do_const;
73186
73187 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
73188 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
73189diff --git a/include/linux/ioport.h b/include/linux/ioport.h
73190index 89b7c24..382af74 100644
73191--- a/include/linux/ioport.h
73192+++ b/include/linux/ioport.h
73193@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
73194 int adjust_resource(struct resource *res, resource_size_t start,
73195 resource_size_t size);
73196 resource_size_t resource_alignment(struct resource *res);
73197-static inline resource_size_t resource_size(const struct resource *res)
73198+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
73199 {
73200 return res->end - res->start + 1;
73201 }
73202diff --git a/include/linux/irq.h b/include/linux/irq.h
73203index bc4e066..50468a9 100644
73204--- a/include/linux/irq.h
73205+++ b/include/linux/irq.h
73206@@ -328,7 +328,8 @@ struct irq_chip {
73207 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
73208
73209 unsigned long flags;
73210-};
73211+} __do_const;
73212+typedef struct irq_chip __no_const irq_chip_no_const;
73213
73214 /*
73215 * irq_chip specific flags
73216diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
73217index 3e203eb..3fe68d0 100644
73218--- a/include/linux/irqchip/arm-gic.h
73219+++ b/include/linux/irqchip/arm-gic.h
73220@@ -59,9 +59,11 @@
73221
73222 #ifndef __ASSEMBLY__
73223
73224+#include <linux/irq.h>
73225+
73226 struct device_node;
73227
73228-extern struct irq_chip gic_arch_extn;
73229+extern irq_chip_no_const gic_arch_extn;
73230
73231 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
73232 u32 offset, struct device_node *);
73233diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
73234index 6883e19..e854fcb 100644
73235--- a/include/linux/kallsyms.h
73236+++ b/include/linux/kallsyms.h
73237@@ -15,7 +15,8 @@
73238
73239 struct module;
73240
73241-#ifdef CONFIG_KALLSYMS
73242+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
73243+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
73244 /* Lookup the address for a symbol. Returns 0 if not found. */
73245 unsigned long kallsyms_lookup_name(const char *name);
73246
73247@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
73248 /* Stupid that this does nothing, but I didn't create this mess. */
73249 #define __print_symbol(fmt, addr)
73250 #endif /*CONFIG_KALLSYMS*/
73251+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
73252+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
73253+extern unsigned long kallsyms_lookup_name(const char *name);
73254+extern void __print_symbol(const char *fmt, unsigned long address);
73255+extern int sprint_backtrace(char *buffer, unsigned long address);
73256+extern int sprint_symbol(char *buffer, unsigned long address);
73257+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
73258+const char *kallsyms_lookup(unsigned long addr,
73259+ unsigned long *symbolsize,
73260+ unsigned long *offset,
73261+ char **modname, char *namebuf);
73262+extern int kallsyms_lookup_size_offset(unsigned long addr,
73263+ unsigned long *symbolsize,
73264+ unsigned long *offset);
73265+#endif
73266
73267 /* This macro allows us to keep printk typechecking */
73268 static __printf(1, 2)
73269diff --git a/include/linux/key-type.h b/include/linux/key-type.h
73270index 518a53a..5e28358 100644
73271--- a/include/linux/key-type.h
73272+++ b/include/linux/key-type.h
73273@@ -125,7 +125,7 @@ struct key_type {
73274 /* internal fields */
73275 struct list_head link; /* link in types list */
73276 struct lock_class_key lock_class; /* key->sem lock class */
73277-};
73278+} __do_const;
73279
73280 extern struct key_type key_type_keyring;
73281
73282diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
73283index c6e091b..a940adf 100644
73284--- a/include/linux/kgdb.h
73285+++ b/include/linux/kgdb.h
73286@@ -52,7 +52,7 @@ extern int kgdb_connected;
73287 extern int kgdb_io_module_registered;
73288
73289 extern atomic_t kgdb_setting_breakpoint;
73290-extern atomic_t kgdb_cpu_doing_single_step;
73291+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
73292
73293 extern struct task_struct *kgdb_usethread;
73294 extern struct task_struct *kgdb_contthread;
73295@@ -254,7 +254,7 @@ struct kgdb_arch {
73296 void (*correct_hw_break)(void);
73297
73298 void (*enable_nmi)(bool on);
73299-};
73300+} __do_const;
73301
73302 /**
73303 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
73304@@ -279,7 +279,7 @@ struct kgdb_io {
73305 void (*pre_exception) (void);
73306 void (*post_exception) (void);
73307 int is_console;
73308-};
73309+} __do_const;
73310
73311 extern struct kgdb_arch arch_kgdb_ops;
73312
73313diff --git a/include/linux/kmod.h b/include/linux/kmod.h
73314index 0555cc6..b16a7a4 100644
73315--- a/include/linux/kmod.h
73316+++ b/include/linux/kmod.h
73317@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
73318 * usually useless though. */
73319 extern __printf(2, 3)
73320 int __request_module(bool wait, const char *name, ...);
73321+extern __printf(3, 4)
73322+int ___request_module(bool wait, char *param_name, const char *name, ...);
73323 #define request_module(mod...) __request_module(true, mod)
73324 #define request_module_nowait(mod...) __request_module(false, mod)
73325 #define try_then_request_module(x, mod...) \
73326diff --git a/include/linux/kobject.h b/include/linux/kobject.h
73327index 939b112..ed6ed51 100644
73328--- a/include/linux/kobject.h
73329+++ b/include/linux/kobject.h
73330@@ -111,7 +111,7 @@ struct kobj_type {
73331 struct attribute **default_attrs;
73332 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
73333 const void *(*namespace)(struct kobject *kobj);
73334-};
73335+} __do_const;
73336
73337 struct kobj_uevent_env {
73338 char *envp[UEVENT_NUM_ENVP];
73339@@ -134,6 +134,7 @@ struct kobj_attribute {
73340 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
73341 const char *buf, size_t count);
73342 };
73343+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
73344
73345 extern const struct sysfs_ops kobj_sysfs_ops;
73346
73347diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
73348index f66b065..c2c29b4 100644
73349--- a/include/linux/kobject_ns.h
73350+++ b/include/linux/kobject_ns.h
73351@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
73352 const void *(*netlink_ns)(struct sock *sk);
73353 const void *(*initial_ns)(void);
73354 void (*drop_ns)(void *);
73355-};
73356+} __do_const;
73357
73358 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
73359 int kobj_ns_type_registered(enum kobj_ns_type type);
73360diff --git a/include/linux/kref.h b/include/linux/kref.h
73361index 484604d..0f6c5b6 100644
73362--- a/include/linux/kref.h
73363+++ b/include/linux/kref.h
73364@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
73365 static inline int kref_sub(struct kref *kref, unsigned int count,
73366 void (*release)(struct kref *kref))
73367 {
73368- WARN_ON(release == NULL);
73369+ BUG_ON(release == NULL);
73370
73371 if (atomic_sub_and_test((int) count, &kref->refcount)) {
73372 release(kref);
73373diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
73374index 8db53cf..c21121d 100644
73375--- a/include/linux/kvm_host.h
73376+++ b/include/linux/kvm_host.h
73377@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
73378 {
73379 }
73380 #endif
73381-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
73382+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
73383 struct module *module);
73384 void kvm_exit(void);
73385
73386@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
73387 struct kvm_guest_debug *dbg);
73388 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
73389
73390-int kvm_arch_init(void *opaque);
73391+int kvm_arch_init(const void *opaque);
73392 void kvm_arch_exit(void);
73393
73394 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
73395diff --git a/include/linux/libata.h b/include/linux/libata.h
73396index eae7a05..2cdd875 100644
73397--- a/include/linux/libata.h
73398+++ b/include/linux/libata.h
73399@@ -919,7 +919,7 @@ struct ata_port_operations {
73400 * fields must be pointers.
73401 */
73402 const struct ata_port_operations *inherits;
73403-};
73404+} __do_const;
73405
73406 struct ata_port_info {
73407 unsigned long flags;
73408diff --git a/include/linux/list.h b/include/linux/list.h
73409index b83e565..baa6c1d 100644
73410--- a/include/linux/list.h
73411+++ b/include/linux/list.h
73412@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
73413 extern void list_del(struct list_head *entry);
73414 #endif
73415
73416+extern void __pax_list_add(struct list_head *new,
73417+ struct list_head *prev,
73418+ struct list_head *next);
73419+static inline void pax_list_add(struct list_head *new, struct list_head *head)
73420+{
73421+ __pax_list_add(new, head, head->next);
73422+}
73423+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
73424+{
73425+ __pax_list_add(new, head->prev, head);
73426+}
73427+extern void pax_list_del(struct list_head *entry);
73428+
73429 /**
73430 * list_replace - replace old entry by new one
73431 * @old : the element to be replaced
73432@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
73433 INIT_LIST_HEAD(entry);
73434 }
73435
73436+extern void pax_list_del_init(struct list_head *entry);
73437+
73438 /**
73439 * list_move - delete from one list and add as another's head
73440 * @list: the entry to move
73441diff --git a/include/linux/math64.h b/include/linux/math64.h
73442index 2913b86..8dcbb1e 100644
73443--- a/include/linux/math64.h
73444+++ b/include/linux/math64.h
73445@@ -15,7 +15,7 @@
73446 * This is commonly provided by 32bit archs to provide an optimized 64bit
73447 * divide.
73448 */
73449-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
73450+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
73451 {
73452 *remainder = dividend % divisor;
73453 return dividend / divisor;
73454@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
73455 /**
73456 * div64_u64 - unsigned 64bit divide with 64bit divisor
73457 */
73458-static inline u64 div64_u64(u64 dividend, u64 divisor)
73459+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
73460 {
73461 return dividend / divisor;
73462 }
73463@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
73464 #define div64_ul(x, y) div_u64((x), (y))
73465
73466 #ifndef div_u64_rem
73467-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
73468+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
73469 {
73470 *remainder = do_div(dividend, divisor);
73471 return dividend;
73472@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
73473 * divide.
73474 */
73475 #ifndef div_u64
73476-static inline u64 div_u64(u64 dividend, u32 divisor)
73477+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
73478 {
73479 u32 remainder;
73480 return div_u64_rem(dividend, divisor, &remainder);
73481diff --git a/include/linux/mm.h b/include/linux/mm.h
73482index e0c8528..bcf0c29 100644
73483--- a/include/linux/mm.h
73484+++ b/include/linux/mm.h
73485@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
73486 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
73487 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
73488 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
73489+
73490+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73491+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
73492+#endif
73493+
73494 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
73495
73496 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
73497@@ -205,8 +210,8 @@ struct vm_operations_struct {
73498 /* called by access_process_vm when get_user_pages() fails, typically
73499 * for use by special VMAs that can switch between memory and hardware
73500 */
73501- int (*access)(struct vm_area_struct *vma, unsigned long addr,
73502- void *buf, int len, int write);
73503+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
73504+ void *buf, size_t len, int write);
73505 #ifdef CONFIG_NUMA
73506 /*
73507 * set_policy() op must add a reference to any non-NULL @new mempolicy
73508@@ -236,6 +241,7 @@ struct vm_operations_struct {
73509 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
73510 unsigned long size, pgoff_t pgoff);
73511 };
73512+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
73513
73514 struct mmu_gather;
73515 struct inode;
73516@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
73517 unsigned long *pfn);
73518 int follow_phys(struct vm_area_struct *vma, unsigned long address,
73519 unsigned int flags, unsigned long *prot, resource_size_t *phys);
73520-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
73521- void *buf, int len, int write);
73522+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
73523+ void *buf, size_t len, int write);
73524
73525 static inline void unmap_shared_mapping_range(struct address_space *mapping,
73526 loff_t const holebegin, loff_t const holelen)
73527@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
73528 }
73529 #endif
73530
73531-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
73532-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
73533- void *buf, int len, int write);
73534+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
73535+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
73536+ void *buf, size_t len, int write);
73537
73538 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
73539 unsigned long start, unsigned long nr_pages,
73540@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
73541 int set_page_dirty_lock(struct page *page);
73542 int clear_page_dirty_for_io(struct page *page);
73543
73544-/* Is the vma a continuation of the stack vma above it? */
73545-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
73546-{
73547- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
73548-}
73549-
73550-static inline int stack_guard_page_start(struct vm_area_struct *vma,
73551- unsigned long addr)
73552-{
73553- return (vma->vm_flags & VM_GROWSDOWN) &&
73554- (vma->vm_start == addr) &&
73555- !vma_growsdown(vma->vm_prev, addr);
73556-}
73557-
73558-/* Is the vma a continuation of the stack vma below it? */
73559-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
73560-{
73561- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
73562-}
73563-
73564-static inline int stack_guard_page_end(struct vm_area_struct *vma,
73565- unsigned long addr)
73566-{
73567- return (vma->vm_flags & VM_GROWSUP) &&
73568- (vma->vm_end == addr) &&
73569- !vma_growsup(vma->vm_next, addr);
73570-}
73571-
73572 extern pid_t
73573 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
73574
73575@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
73576 }
73577 #endif
73578
73579+#ifdef CONFIG_MMU
73580+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
73581+#else
73582+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73583+{
73584+ return __pgprot(0);
73585+}
73586+#endif
73587+
73588 int vma_wants_writenotify(struct vm_area_struct *vma);
73589
73590 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
73591@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
73592 {
73593 return 0;
73594 }
73595+
73596+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
73597+ unsigned long address)
73598+{
73599+ return 0;
73600+}
73601 #else
73602 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
73603+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
73604 #endif
73605
73606 #ifdef __PAGETABLE_PMD_FOLDED
73607@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
73608 {
73609 return 0;
73610 }
73611+
73612+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
73613+ unsigned long address)
73614+{
73615+ return 0;
73616+}
73617 #else
73618 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
73619+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
73620 #endif
73621
73622 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
73623@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
73624 NULL: pud_offset(pgd, address);
73625 }
73626
73627+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73628+{
73629+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
73630+ NULL: pud_offset(pgd, address);
73631+}
73632+
73633 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73634 {
73635 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
73636 NULL: pmd_offset(pud, address);
73637 }
73638+
73639+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73640+{
73641+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
73642+ NULL: pmd_offset(pud, address);
73643+}
73644 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
73645
73646 #if USE_SPLIT_PTLOCKS
73647@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73648 unsigned long len, unsigned long prot, unsigned long flags,
73649 unsigned long pgoff, unsigned long *populate);
73650 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
73651+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
73652
73653 #ifdef CONFIG_MMU
73654 extern int __mm_populate(unsigned long addr, unsigned long len,
73655@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
73656 unsigned long high_limit;
73657 unsigned long align_mask;
73658 unsigned long align_offset;
73659+ unsigned long threadstack_offset;
73660 };
73661
73662-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
73663-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
73664+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
73665+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
73666
73667 /*
73668 * Search for an unmapped address range.
73669@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
73670 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
73671 */
73672 static inline unsigned long
73673-vm_unmapped_area(struct vm_unmapped_area_info *info)
73674+vm_unmapped_area(const struct vm_unmapped_area_info *info)
73675 {
73676 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
73677 return unmapped_area(info);
73678@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
73679 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
73680 struct vm_area_struct **pprev);
73681
73682+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
73683+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
73684+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
73685+
73686 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
73687 NULL if none. Assume start_addr < end_addr. */
73688 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
73689@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
73690 return vma;
73691 }
73692
73693-#ifdef CONFIG_MMU
73694-pgprot_t vm_get_page_prot(unsigned long vm_flags);
73695-#else
73696-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
73697-{
73698- return __pgprot(0);
73699-}
73700-#endif
73701-
73702 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
73703 unsigned long change_prot_numa(struct vm_area_struct *vma,
73704 unsigned long start, unsigned long end);
73705@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
73706 static inline void vm_stat_account(struct mm_struct *mm,
73707 unsigned long flags, struct file *file, long pages)
73708 {
73709+
73710+#ifdef CONFIG_PAX_RANDMMAP
73711+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
73712+#endif
73713+
73714 mm->total_vm += pages;
73715 }
73716 #endif /* CONFIG_PROC_FS */
73717@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
73718 extern int sysctl_memory_failure_early_kill;
73719 extern int sysctl_memory_failure_recovery;
73720 extern void shake_page(struct page *p, int access);
73721-extern atomic_long_t num_poisoned_pages;
73722+extern atomic_long_unchecked_t num_poisoned_pages;
73723 extern int soft_offline_page(struct page *page, int flags);
73724
73725 extern void dump_page(struct page *page);
73726@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
73727 static inline void setup_nr_node_ids(void) {}
73728 #endif
73729
73730+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73731+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
73732+#else
73733+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
73734+#endif
73735+
73736 #endif /* __KERNEL__ */
73737 #endif /* _LINUX_MM_H */
73738diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
73739index ace9a5f..81bdb59 100644
73740--- a/include/linux/mm_types.h
73741+++ b/include/linux/mm_types.h
73742@@ -289,6 +289,8 @@ struct vm_area_struct {
73743 #ifdef CONFIG_NUMA
73744 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
73745 #endif
73746+
73747+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
73748 };
73749
73750 struct core_thread {
73751@@ -437,6 +439,24 @@ struct mm_struct {
73752 int first_nid;
73753 #endif
73754 struct uprobes_state uprobes_state;
73755+
73756+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
73757+ unsigned long pax_flags;
73758+#endif
73759+
73760+#ifdef CONFIG_PAX_DLRESOLVE
73761+ unsigned long call_dl_resolve;
73762+#endif
73763+
73764+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
73765+ unsigned long call_syscall;
73766+#endif
73767+
73768+#ifdef CONFIG_PAX_ASLR
73769+ unsigned long delta_mmap; /* randomized offset */
73770+ unsigned long delta_stack; /* randomized offset */
73771+#endif
73772+
73773 };
73774
73775 /* first nid will either be a valid NID or one of these values */
73776diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
73777index c5d5278..f0b68c8 100644
73778--- a/include/linux/mmiotrace.h
73779+++ b/include/linux/mmiotrace.h
73780@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
73781 /* Called from ioremap.c */
73782 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
73783 void __iomem *addr);
73784-extern void mmiotrace_iounmap(volatile void __iomem *addr);
73785+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
73786
73787 /* For anyone to insert markers. Remember trailing newline. */
73788 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
73789@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
73790 {
73791 }
73792
73793-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
73794+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
73795 {
73796 }
73797
73798diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
73799index 5c76737..61f518e 100644
73800--- a/include/linux/mmzone.h
73801+++ b/include/linux/mmzone.h
73802@@ -396,7 +396,7 @@ struct zone {
73803 unsigned long flags; /* zone flags, see below */
73804
73805 /* Zone statistics */
73806- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73807+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73808
73809 /*
73810 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
73811diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
73812index b508016..237cfe5 100644
73813--- a/include/linux/mod_devicetable.h
73814+++ b/include/linux/mod_devicetable.h
73815@@ -13,7 +13,7 @@
73816 typedef unsigned long kernel_ulong_t;
73817 #endif
73818
73819-#define PCI_ANY_ID (~0)
73820+#define PCI_ANY_ID ((__u16)~0)
73821
73822 struct pci_device_id {
73823 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
73824@@ -139,7 +139,7 @@ struct usb_device_id {
73825 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
73826 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
73827
73828-#define HID_ANY_ID (~0)
73829+#define HID_ANY_ID (~0U)
73830 #define HID_BUS_ANY 0xffff
73831 #define HID_GROUP_ANY 0x0000
73832
73833@@ -465,7 +465,7 @@ struct dmi_system_id {
73834 const char *ident;
73835 struct dmi_strmatch matches[4];
73836 void *driver_data;
73837-};
73838+} __do_const;
73839 /*
73840 * struct dmi_device_id appears during expansion of
73841 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
73842diff --git a/include/linux/module.h b/include/linux/module.h
73843index 46f1ea0..a34ca37 100644
73844--- a/include/linux/module.h
73845+++ b/include/linux/module.h
73846@@ -17,9 +17,11 @@
73847 #include <linux/moduleparam.h>
73848 #include <linux/tracepoint.h>
73849 #include <linux/export.h>
73850+#include <linux/fs.h>
73851
73852 #include <linux/percpu.h>
73853 #include <asm/module.h>
73854+#include <asm/pgtable.h>
73855
73856 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
73857 #define MODULE_SIG_STRING "~Module signature appended~\n"
73858@@ -54,12 +56,13 @@ struct module_attribute {
73859 int (*test)(struct module *);
73860 void (*free)(struct module *);
73861 };
73862+typedef struct module_attribute __no_const module_attribute_no_const;
73863
73864 struct module_version_attribute {
73865 struct module_attribute mattr;
73866 const char *module_name;
73867 const char *version;
73868-} __attribute__ ((__aligned__(sizeof(void *))));
73869+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
73870
73871 extern ssize_t __modver_version_show(struct module_attribute *,
73872 struct module_kobject *, char *);
73873@@ -232,7 +235,7 @@ struct module
73874
73875 /* Sysfs stuff. */
73876 struct module_kobject mkobj;
73877- struct module_attribute *modinfo_attrs;
73878+ module_attribute_no_const *modinfo_attrs;
73879 const char *version;
73880 const char *srcversion;
73881 struct kobject *holders_dir;
73882@@ -281,19 +284,16 @@ struct module
73883 int (*init)(void);
73884
73885 /* If this is non-NULL, vfree after init() returns */
73886- void *module_init;
73887+ void *module_init_rx, *module_init_rw;
73888
73889 /* Here is the actual code + data, vfree'd on unload. */
73890- void *module_core;
73891+ void *module_core_rx, *module_core_rw;
73892
73893 /* Here are the sizes of the init and core sections */
73894- unsigned int init_size, core_size;
73895+ unsigned int init_size_rw, core_size_rw;
73896
73897 /* The size of the executable code in each section. */
73898- unsigned int init_text_size, core_text_size;
73899-
73900- /* Size of RO sections of the module (text+rodata) */
73901- unsigned int init_ro_size, core_ro_size;
73902+ unsigned int init_size_rx, core_size_rx;
73903
73904 /* Arch-specific module values */
73905 struct mod_arch_specific arch;
73906@@ -349,6 +349,10 @@ struct module
73907 #ifdef CONFIG_EVENT_TRACING
73908 struct ftrace_event_call **trace_events;
73909 unsigned int num_trace_events;
73910+ struct file_operations trace_id;
73911+ struct file_operations trace_enable;
73912+ struct file_operations trace_format;
73913+ struct file_operations trace_filter;
73914 #endif
73915 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
73916 unsigned int num_ftrace_callsites;
73917@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
73918 bool is_module_percpu_address(unsigned long addr);
73919 bool is_module_text_address(unsigned long addr);
73920
73921+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
73922+{
73923+
73924+#ifdef CONFIG_PAX_KERNEXEC
73925+ if (ktla_ktva(addr) >= (unsigned long)start &&
73926+ ktla_ktva(addr) < (unsigned long)start + size)
73927+ return 1;
73928+#endif
73929+
73930+ return ((void *)addr >= start && (void *)addr < start + size);
73931+}
73932+
73933+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
73934+{
73935+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
73936+}
73937+
73938+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
73939+{
73940+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
73941+}
73942+
73943+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
73944+{
73945+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
73946+}
73947+
73948+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
73949+{
73950+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
73951+}
73952+
73953 static inline int within_module_core(unsigned long addr, const struct module *mod)
73954 {
73955- return (unsigned long)mod->module_core <= addr &&
73956- addr < (unsigned long)mod->module_core + mod->core_size;
73957+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
73958 }
73959
73960 static inline int within_module_init(unsigned long addr, const struct module *mod)
73961 {
73962- return (unsigned long)mod->module_init <= addr &&
73963- addr < (unsigned long)mod->module_init + mod->init_size;
73964+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
73965 }
73966
73967 /* Search for module by name: must hold module_mutex. */
73968diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
73969index 560ca53..ef621ef 100644
73970--- a/include/linux/moduleloader.h
73971+++ b/include/linux/moduleloader.h
73972@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
73973 sections. Returns NULL on failure. */
73974 void *module_alloc(unsigned long size);
73975
73976+#ifdef CONFIG_PAX_KERNEXEC
73977+void *module_alloc_exec(unsigned long size);
73978+#else
73979+#define module_alloc_exec(x) module_alloc(x)
73980+#endif
73981+
73982 /* Free memory returned from module_alloc. */
73983 void module_free(struct module *mod, void *module_region);
73984
73985+#ifdef CONFIG_PAX_KERNEXEC
73986+void module_free_exec(struct module *mod, void *module_region);
73987+#else
73988+#define module_free_exec(x, y) module_free((x), (y))
73989+#endif
73990+
73991 /*
73992 * Apply the given relocation to the (simplified) ELF. Return -error
73993 * or 0.
73994@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
73995 unsigned int relsec,
73996 struct module *me)
73997 {
73998+#ifdef CONFIG_MODULES
73999 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
74000+#endif
74001 return -ENOEXEC;
74002 }
74003 #endif
74004@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
74005 unsigned int relsec,
74006 struct module *me)
74007 {
74008+#ifdef CONFIG_MODULES
74009 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
74010+#endif
74011 return -ENOEXEC;
74012 }
74013 #endif
74014diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
74015index 137b419..fe663ec 100644
74016--- a/include/linux/moduleparam.h
74017+++ b/include/linux/moduleparam.h
74018@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
74019 * @len is usually just sizeof(string).
74020 */
74021 #define module_param_string(name, string, len, perm) \
74022- static const struct kparam_string __param_string_##name \
74023+ static const struct kparam_string __param_string_##name __used \
74024 = { len, string }; \
74025 __module_param_call(MODULE_PARAM_PREFIX, name, \
74026 &param_ops_string, \
74027@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
74028 */
74029 #define module_param_array_named(name, array, type, nump, perm) \
74030 param_check_##type(name, &(array)[0]); \
74031- static const struct kparam_array __param_arr_##name \
74032+ static const struct kparam_array __param_arr_##name __used \
74033 = { .max = ARRAY_SIZE(array), .num = nump, \
74034 .ops = &param_ops_##type, \
74035 .elemsize = sizeof(array[0]), .elem = array }; \
74036diff --git a/include/linux/namei.h b/include/linux/namei.h
74037index 5a5ff57..5ae5070 100644
74038--- a/include/linux/namei.h
74039+++ b/include/linux/namei.h
74040@@ -19,7 +19,7 @@ struct nameidata {
74041 unsigned seq;
74042 int last_type;
74043 unsigned depth;
74044- char *saved_names[MAX_NESTED_LINKS + 1];
74045+ const char *saved_names[MAX_NESTED_LINKS + 1];
74046 };
74047
74048 /*
74049@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
74050
74051 extern void nd_jump_link(struct nameidata *nd, struct path *path);
74052
74053-static inline void nd_set_link(struct nameidata *nd, char *path)
74054+static inline void nd_set_link(struct nameidata *nd, const char *path)
74055 {
74056 nd->saved_names[nd->depth] = path;
74057 }
74058
74059-static inline char *nd_get_link(struct nameidata *nd)
74060+static inline const char *nd_get_link(const struct nameidata *nd)
74061 {
74062 return nd->saved_names[nd->depth];
74063 }
74064diff --git a/include/linux/net.h b/include/linux/net.h
74065index 99c9f0c..e1cf296 100644
74066--- a/include/linux/net.h
74067+++ b/include/linux/net.h
74068@@ -183,7 +183,7 @@ struct net_proto_family {
74069 int (*create)(struct net *net, struct socket *sock,
74070 int protocol, int kern);
74071 struct module *owner;
74072-};
74073+} __do_const;
74074
74075 struct iovec;
74076 struct kvec;
74077diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
74078index 96e4c21..9cc8278 100644
74079--- a/include/linux/netdevice.h
74080+++ b/include/linux/netdevice.h
74081@@ -1026,6 +1026,7 @@ struct net_device_ops {
74082 int (*ndo_change_carrier)(struct net_device *dev,
74083 bool new_carrier);
74084 };
74085+typedef struct net_device_ops __no_const net_device_ops_no_const;
74086
74087 /*
74088 * The DEVICE structure.
74089@@ -1094,7 +1095,7 @@ struct net_device {
74090 int iflink;
74091
74092 struct net_device_stats stats;
74093- atomic_long_t rx_dropped; /* dropped packets by core network
74094+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
74095 * Do not use this in drivers.
74096 */
74097
74098diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
74099index 0060fde..481c6ae 100644
74100--- a/include/linux/netfilter.h
74101+++ b/include/linux/netfilter.h
74102@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
74103 #endif
74104 /* Use the module struct to lock set/get code in place */
74105 struct module *owner;
74106-};
74107+} __do_const;
74108
74109 /* Function to register/unregister hook points. */
74110 int nf_register_hook(struct nf_hook_ops *reg);
74111diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
74112index d80e275..c3510b8 100644
74113--- a/include/linux/netfilter/ipset/ip_set.h
74114+++ b/include/linux/netfilter/ipset/ip_set.h
74115@@ -124,7 +124,7 @@ struct ip_set_type_variant {
74116 /* Return true if "b" set is the same as "a"
74117 * according to the create set parameters */
74118 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
74119-};
74120+} __do_const;
74121
74122 /* The core set type structure */
74123 struct ip_set_type {
74124diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
74125index cadb740..d7c37c0 100644
74126--- a/include/linux/netfilter/nfnetlink.h
74127+++ b/include/linux/netfilter/nfnetlink.h
74128@@ -16,7 +16,7 @@ struct nfnl_callback {
74129 const struct nlattr * const cda[]);
74130 const struct nla_policy *policy; /* netlink attribute policy */
74131 const u_int16_t attr_count; /* number of nlattr's */
74132-};
74133+} __do_const;
74134
74135 struct nfnetlink_subsystem {
74136 const char *name;
74137diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
74138new file mode 100644
74139index 0000000..33f4af8
74140--- /dev/null
74141+++ b/include/linux/netfilter/xt_gradm.h
74142@@ -0,0 +1,9 @@
74143+#ifndef _LINUX_NETFILTER_XT_GRADM_H
74144+#define _LINUX_NETFILTER_XT_GRADM_H 1
74145+
74146+struct xt_gradm_mtinfo {
74147+ __u16 flags;
74148+ __u16 invflags;
74149+};
74150+
74151+#endif
74152diff --git a/include/linux/nls.h b/include/linux/nls.h
74153index 5dc635f..35f5e11 100644
74154--- a/include/linux/nls.h
74155+++ b/include/linux/nls.h
74156@@ -31,7 +31,7 @@ struct nls_table {
74157 const unsigned char *charset2upper;
74158 struct module *owner;
74159 struct nls_table *next;
74160-};
74161+} __do_const;
74162
74163 /* this value hold the maximum octet of charset */
74164 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
74165diff --git a/include/linux/notifier.h b/include/linux/notifier.h
74166index d14a4c3..a078786 100644
74167--- a/include/linux/notifier.h
74168+++ b/include/linux/notifier.h
74169@@ -54,7 +54,8 @@ struct notifier_block {
74170 notifier_fn_t notifier_call;
74171 struct notifier_block __rcu *next;
74172 int priority;
74173-};
74174+} __do_const;
74175+typedef struct notifier_block __no_const notifier_block_no_const;
74176
74177 struct atomic_notifier_head {
74178 spinlock_t lock;
74179diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
74180index a4c5624..79d6d88 100644
74181--- a/include/linux/oprofile.h
74182+++ b/include/linux/oprofile.h
74183@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
74184 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
74185 char const * name, ulong * val);
74186
74187-/** Create a file for read-only access to an atomic_t. */
74188+/** Create a file for read-only access to an atomic_unchecked_t. */
74189 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
74190- char const * name, atomic_t * val);
74191+ char const * name, atomic_unchecked_t * val);
74192
74193 /** create a directory */
74194 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
74195diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
74196index 8db71dc..a76bf2c 100644
74197--- a/include/linux/pci_hotplug.h
74198+++ b/include/linux/pci_hotplug.h
74199@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
74200 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
74201 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
74202 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
74203-};
74204+} __do_const;
74205+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
74206
74207 /**
74208 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
74209diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
74210index c5b6dbf..b124155 100644
74211--- a/include/linux/perf_event.h
74212+++ b/include/linux/perf_event.h
74213@@ -318,8 +318,8 @@ struct perf_event {
74214
74215 enum perf_event_active_state state;
74216 unsigned int attach_state;
74217- local64_t count;
74218- atomic64_t child_count;
74219+ local64_t count; /* PaX: fix it one day */
74220+ atomic64_unchecked_t child_count;
74221
74222 /*
74223 * These are the total time in nanoseconds that the event
74224@@ -370,8 +370,8 @@ struct perf_event {
74225 * These accumulate total time (in nanoseconds) that children
74226 * events have been enabled and running, respectively.
74227 */
74228- atomic64_t child_total_time_enabled;
74229- atomic64_t child_total_time_running;
74230+ atomic64_unchecked_t child_total_time_enabled;
74231+ atomic64_unchecked_t child_total_time_running;
74232
74233 /*
74234 * Protect attach/detach and child_list:
74235@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
74236 entry->ip[entry->nr++] = ip;
74237 }
74238
74239-extern int sysctl_perf_event_paranoid;
74240+extern int sysctl_perf_event_legitimately_concerned;
74241 extern int sysctl_perf_event_mlock;
74242 extern int sysctl_perf_event_sample_rate;
74243
74244@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
74245 void __user *buffer, size_t *lenp,
74246 loff_t *ppos);
74247
74248+static inline bool perf_paranoid_any(void)
74249+{
74250+ return sysctl_perf_event_legitimately_concerned > 2;
74251+}
74252+
74253 static inline bool perf_paranoid_tracepoint_raw(void)
74254 {
74255- return sysctl_perf_event_paranoid > -1;
74256+ return sysctl_perf_event_legitimately_concerned > -1;
74257 }
74258
74259 static inline bool perf_paranoid_cpu(void)
74260 {
74261- return sysctl_perf_event_paranoid > 0;
74262+ return sysctl_perf_event_legitimately_concerned > 0;
74263 }
74264
74265 static inline bool perf_paranoid_kernel(void)
74266 {
74267- return sysctl_perf_event_paranoid > 1;
74268+ return sysctl_perf_event_legitimately_concerned > 1;
74269 }
74270
74271 extern void perf_event_init(void);
74272@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
74273 */
74274 #define perf_cpu_notifier(fn) \
74275 do { \
74276- static struct notifier_block fn##_nb __cpuinitdata = \
74277+ static struct notifier_block fn##_nb = \
74278 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
74279 unsigned long cpu = smp_processor_id(); \
74280 unsigned long flags; \
74281@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
74282 struct device_attribute attr;
74283 u64 id;
74284 const char *event_str;
74285-};
74286+} __do_const;
74287
74288 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
74289 static struct perf_pmu_events_attr _var = { \
74290diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
74291index b8809fe..ae4ccd0 100644
74292--- a/include/linux/pipe_fs_i.h
74293+++ b/include/linux/pipe_fs_i.h
74294@@ -47,10 +47,10 @@ struct pipe_inode_info {
74295 struct mutex mutex;
74296 wait_queue_head_t wait;
74297 unsigned int nrbufs, curbuf, buffers;
74298- unsigned int readers;
74299- unsigned int writers;
74300- unsigned int files;
74301- unsigned int waiting_writers;
74302+ atomic_t readers;
74303+ atomic_t writers;
74304+ atomic_t files;
74305+ atomic_t waiting_writers;
74306 unsigned int r_counter;
74307 unsigned int w_counter;
74308 struct page *tmp_page;
74309diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
74310index 5f28cae..3d23723 100644
74311--- a/include/linux/platform_data/usb-ehci-s5p.h
74312+++ b/include/linux/platform_data/usb-ehci-s5p.h
74313@@ -14,7 +14,7 @@
74314 struct s5p_ehci_platdata {
74315 int (*phy_init)(struct platform_device *pdev, int type);
74316 int (*phy_exit)(struct platform_device *pdev, int type);
74317-};
74318+} __no_const;
74319
74320 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
74321
74322diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
74323index c256c59..8ea94c7 100644
74324--- a/include/linux/platform_data/usb-ohci-exynos.h
74325+++ b/include/linux/platform_data/usb-ohci-exynos.h
74326@@ -14,7 +14,7 @@
74327 struct exynos4_ohci_platdata {
74328 int (*phy_init)(struct platform_device *pdev, int type);
74329 int (*phy_exit)(struct platform_device *pdev, int type);
74330-};
74331+} __no_const;
74332
74333 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
74334
74335diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
74336index 7c1d252..c5c773e 100644
74337--- a/include/linux/pm_domain.h
74338+++ b/include/linux/pm_domain.h
74339@@ -48,7 +48,7 @@ struct gpd_dev_ops {
74340
74341 struct gpd_cpu_data {
74342 unsigned int saved_exit_latency;
74343- struct cpuidle_state *idle_state;
74344+ cpuidle_state_no_const *idle_state;
74345 };
74346
74347 struct generic_pm_domain {
74348diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
74349index 7d7e09e..8671ef8 100644
74350--- a/include/linux/pm_runtime.h
74351+++ b/include/linux/pm_runtime.h
74352@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
74353
74354 static inline void pm_runtime_mark_last_busy(struct device *dev)
74355 {
74356- ACCESS_ONCE(dev->power.last_busy) = jiffies;
74357+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
74358 }
74359
74360 #else /* !CONFIG_PM_RUNTIME */
74361diff --git a/include/linux/pnp.h b/include/linux/pnp.h
74362index 195aafc..49a7bc2 100644
74363--- a/include/linux/pnp.h
74364+++ b/include/linux/pnp.h
74365@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
74366 struct pnp_fixup {
74367 char id[7];
74368 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
74369-};
74370+} __do_const;
74371
74372 /* config parameters */
74373 #define PNP_CONFIG_NORMAL 0x0001
74374diff --git a/include/linux/poison.h b/include/linux/poison.h
74375index 2110a81..13a11bb 100644
74376--- a/include/linux/poison.h
74377+++ b/include/linux/poison.h
74378@@ -19,8 +19,8 @@
74379 * under normal circumstances, used to verify that nobody uses
74380 * non-initialized list entries.
74381 */
74382-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
74383-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
74384+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
74385+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
74386
74387 /********** include/linux/timer.h **********/
74388 /*
74389diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
74390index c0f44c2..1572583 100644
74391--- a/include/linux/power/smartreflex.h
74392+++ b/include/linux/power/smartreflex.h
74393@@ -238,7 +238,7 @@ struct omap_sr_class_data {
74394 int (*notify)(struct omap_sr *sr, u32 status);
74395 u8 notify_flags;
74396 u8 class_type;
74397-};
74398+} __do_const;
74399
74400 /**
74401 * struct omap_sr_nvalue_table - Smartreflex n-target value info
74402diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
74403index 4ea1d37..80f4b33 100644
74404--- a/include/linux/ppp-comp.h
74405+++ b/include/linux/ppp-comp.h
74406@@ -84,7 +84,7 @@ struct compressor {
74407 struct module *owner;
74408 /* Extra skb space needed by the compressor algorithm */
74409 unsigned int comp_extra;
74410-};
74411+} __do_const;
74412
74413 /*
74414 * The return value from decompress routine is the length of the
74415diff --git a/include/linux/preempt.h b/include/linux/preempt.h
74416index f5d4723..a6ea2fa 100644
74417--- a/include/linux/preempt.h
74418+++ b/include/linux/preempt.h
74419@@ -18,8 +18,13 @@
74420 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
74421 #endif
74422
74423+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
74424+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
74425+
74426 #define inc_preempt_count() add_preempt_count(1)
74427+#define raw_inc_preempt_count() raw_add_preempt_count(1)
74428 #define dec_preempt_count() sub_preempt_count(1)
74429+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
74430
74431 #define preempt_count() (current_thread_info()->preempt_count)
74432
74433@@ -64,6 +69,12 @@ do { \
74434 barrier(); \
74435 } while (0)
74436
74437+#define raw_preempt_disable() \
74438+do { \
74439+ raw_inc_preempt_count(); \
74440+ barrier(); \
74441+} while (0)
74442+
74443 #define sched_preempt_enable_no_resched() \
74444 do { \
74445 barrier(); \
74446@@ -72,6 +83,12 @@ do { \
74447
74448 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
74449
74450+#define raw_preempt_enable_no_resched() \
74451+do { \
74452+ barrier(); \
74453+ raw_dec_preempt_count(); \
74454+} while (0)
74455+
74456 #define preempt_enable() \
74457 do { \
74458 preempt_enable_no_resched(); \
74459@@ -116,8 +133,10 @@ do { \
74460 * region.
74461 */
74462 #define preempt_disable() barrier()
74463+#define raw_preempt_disable() barrier()
74464 #define sched_preempt_enable_no_resched() barrier()
74465 #define preempt_enable_no_resched() barrier()
74466+#define raw_preempt_enable_no_resched() barrier()
74467 #define preempt_enable() barrier()
74468
74469 #define preempt_disable_notrace() barrier()
74470diff --git a/include/linux/printk.h b/include/linux/printk.h
74471index 22c7052..ad3fa0a 100644
74472--- a/include/linux/printk.h
74473+++ b/include/linux/printk.h
74474@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
74475 void early_printk(const char *s, ...) { }
74476 #endif
74477
74478+extern int kptr_restrict;
74479+
74480 #ifdef CONFIG_PRINTK
74481 asmlinkage __printf(5, 0)
74482 int vprintk_emit(int facility, int level,
74483@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
74484
74485 extern int printk_delay_msec;
74486 extern int dmesg_restrict;
74487-extern int kptr_restrict;
74488
74489 extern void wake_up_klogd(void);
74490
74491diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
74492index 608e60a..c26f864 100644
74493--- a/include/linux/proc_fs.h
74494+++ b/include/linux/proc_fs.h
74495@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
74496 return proc_create_data(name, mode, parent, proc_fops, NULL);
74497 }
74498
74499+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
74500+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
74501+{
74502+#ifdef CONFIG_GRKERNSEC_PROC_USER
74503+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
74504+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74505+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
74506+#else
74507+ return proc_create_data(name, mode, parent, proc_fops, NULL);
74508+#endif
74509+}
74510+
74511+
74512 extern void proc_set_size(struct proc_dir_entry *, loff_t);
74513 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
74514 extern void *PDE_DATA(const struct inode *);
74515diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
74516index 34a1e10..03a6d03 100644
74517--- a/include/linux/proc_ns.h
74518+++ b/include/linux/proc_ns.h
74519@@ -14,7 +14,7 @@ struct proc_ns_operations {
74520 void (*put)(void *ns);
74521 int (*install)(struct nsproxy *nsproxy, void *ns);
74522 unsigned int (*inum)(void *ns);
74523-};
74524+} __do_const;
74525
74526 struct proc_ns {
74527 void *ns;
74528diff --git a/include/linux/random.h b/include/linux/random.h
74529index 3b9377d..61b506a 100644
74530--- a/include/linux/random.h
74531+++ b/include/linux/random.h
74532@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
74533 u32 prandom_u32_state(struct rnd_state *);
74534 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
74535
74536+static inline unsigned long pax_get_random_long(void)
74537+{
74538+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
74539+}
74540+
74541 /*
74542 * Handle minimum values for seeds
74543 */
74544diff --git a/include/linux/rculist.h b/include/linux/rculist.h
74545index f4b1001..8ddb2b6 100644
74546--- a/include/linux/rculist.h
74547+++ b/include/linux/rculist.h
74548@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
74549 struct list_head *prev, struct list_head *next);
74550 #endif
74551
74552+extern void __pax_list_add_rcu(struct list_head *new,
74553+ struct list_head *prev, struct list_head *next);
74554+
74555 /**
74556 * list_add_rcu - add a new entry to rcu-protected list
74557 * @new: new entry to be added
74558@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
74559 __list_add_rcu(new, head, head->next);
74560 }
74561
74562+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
74563+{
74564+ __pax_list_add_rcu(new, head, head->next);
74565+}
74566+
74567 /**
74568 * list_add_tail_rcu - add a new entry to rcu-protected list
74569 * @new: new entry to be added
74570@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
74571 __list_add_rcu(new, head->prev, head);
74572 }
74573
74574+static inline void pax_list_add_tail_rcu(struct list_head *new,
74575+ struct list_head *head)
74576+{
74577+ __pax_list_add_rcu(new, head->prev, head);
74578+}
74579+
74580 /**
74581 * list_del_rcu - deletes entry from list without re-initialization
74582 * @entry: the element to delete from the list.
74583@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
74584 entry->prev = LIST_POISON2;
74585 }
74586
74587+extern void pax_list_del_rcu(struct list_head *entry);
74588+
74589 /**
74590 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
74591 * @n: the element to delete from the hash list.
74592diff --git a/include/linux/reboot.h b/include/linux/reboot.h
74593index 23b3630..e1bc12b 100644
74594--- a/include/linux/reboot.h
74595+++ b/include/linux/reboot.h
74596@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
74597 * Architecture-specific implementations of sys_reboot commands.
74598 */
74599
74600-extern void machine_restart(char *cmd);
74601-extern void machine_halt(void);
74602-extern void machine_power_off(void);
74603+extern void machine_restart(char *cmd) __noreturn;
74604+extern void machine_halt(void) __noreturn;
74605+extern void machine_power_off(void) __noreturn;
74606
74607 extern void machine_shutdown(void);
74608 struct pt_regs;
74609@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
74610 */
74611
74612 extern void kernel_restart_prepare(char *cmd);
74613-extern void kernel_restart(char *cmd);
74614-extern void kernel_halt(void);
74615-extern void kernel_power_off(void);
74616+extern void kernel_restart(char *cmd) __noreturn;
74617+extern void kernel_halt(void) __noreturn;
74618+extern void kernel_power_off(void) __noreturn;
74619
74620 extern int C_A_D; /* for sysctl */
74621 void ctrl_alt_del(void);
74622@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
74623 * Emergency restart, callable from an interrupt handler.
74624 */
74625
74626-extern void emergency_restart(void);
74627+extern void emergency_restart(void) __noreturn;
74628 #include <asm/emergency-restart.h>
74629
74630 #endif /* _LINUX_REBOOT_H */
74631diff --git a/include/linux/regset.h b/include/linux/regset.h
74632index 8e0c9fe..ac4d221 100644
74633--- a/include/linux/regset.h
74634+++ b/include/linux/regset.h
74635@@ -161,7 +161,8 @@ struct user_regset {
74636 unsigned int align;
74637 unsigned int bias;
74638 unsigned int core_note_type;
74639-};
74640+} __do_const;
74641+typedef struct user_regset __no_const user_regset_no_const;
74642
74643 /**
74644 * struct user_regset_view - available regsets
74645diff --git a/include/linux/relay.h b/include/linux/relay.h
74646index d7c8359..818daf5 100644
74647--- a/include/linux/relay.h
74648+++ b/include/linux/relay.h
74649@@ -157,7 +157,7 @@ struct rchan_callbacks
74650 * The callback should return 0 if successful, negative if not.
74651 */
74652 int (*remove_buf_file)(struct dentry *dentry);
74653-};
74654+} __no_const;
74655
74656 /*
74657 * CONFIG_RELAY kernel API, kernel/relay.c
74658diff --git a/include/linux/rio.h b/include/linux/rio.h
74659index 18e0993..8ab5b21 100644
74660--- a/include/linux/rio.h
74661+++ b/include/linux/rio.h
74662@@ -345,7 +345,7 @@ struct rio_ops {
74663 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
74664 u64 rstart, u32 size, u32 flags);
74665 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
74666-};
74667+} __no_const;
74668
74669 #define RIO_RESOURCE_MEM 0x00000100
74670 #define RIO_RESOURCE_DOORBELL 0x00000200
74671diff --git a/include/linux/rmap.h b/include/linux/rmap.h
74672index 6dacb93..6174423 100644
74673--- a/include/linux/rmap.h
74674+++ b/include/linux/rmap.h
74675@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
74676 void anon_vma_init(void); /* create anon_vma_cachep */
74677 int anon_vma_prepare(struct vm_area_struct *);
74678 void unlink_anon_vmas(struct vm_area_struct *);
74679-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
74680-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
74681+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
74682+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
74683
74684 static inline void anon_vma_merge(struct vm_area_struct *vma,
74685 struct vm_area_struct *next)
74686diff --git a/include/linux/sched.h b/include/linux/sched.h
74687index 178a8d9..450bf11 100644
74688--- a/include/linux/sched.h
74689+++ b/include/linux/sched.h
74690@@ -62,6 +62,7 @@ struct bio_list;
74691 struct fs_struct;
74692 struct perf_event_context;
74693 struct blk_plug;
74694+struct linux_binprm;
74695
74696 /*
74697 * List of flags we want to share for kernel threads,
74698@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
74699 extern int in_sched_functions(unsigned long addr);
74700
74701 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
74702-extern signed long schedule_timeout(signed long timeout);
74703+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
74704 extern signed long schedule_timeout_interruptible(signed long timeout);
74705 extern signed long schedule_timeout_killable(signed long timeout);
74706 extern signed long schedule_timeout_uninterruptible(signed long timeout);
74707@@ -314,6 +315,19 @@ struct nsproxy;
74708 struct user_namespace;
74709
74710 #ifdef CONFIG_MMU
74711+
74712+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
74713+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
74714+#else
74715+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
74716+{
74717+ return 0;
74718+}
74719+#endif
74720+
74721+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
74722+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
74723+
74724 extern void arch_pick_mmap_layout(struct mm_struct *mm);
74725 extern unsigned long
74726 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
74727@@ -591,6 +605,17 @@ struct signal_struct {
74728 #ifdef CONFIG_TASKSTATS
74729 struct taskstats *stats;
74730 #endif
74731+
74732+#ifdef CONFIG_GRKERNSEC
74733+ u32 curr_ip;
74734+ u32 saved_ip;
74735+ u32 gr_saddr;
74736+ u32 gr_daddr;
74737+ u16 gr_sport;
74738+ u16 gr_dport;
74739+ u8 used_accept:1;
74740+#endif
74741+
74742 #ifdef CONFIG_AUDIT
74743 unsigned audit_tty;
74744 unsigned audit_tty_log_passwd;
74745@@ -671,6 +696,14 @@ struct user_struct {
74746 struct key *session_keyring; /* UID's default session keyring */
74747 #endif
74748
74749+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74750+ unsigned char kernel_banned;
74751+#endif
74752+#ifdef CONFIG_GRKERNSEC_BRUTE
74753+ unsigned char suid_banned;
74754+ unsigned long suid_ban_expires;
74755+#endif
74756+
74757 /* Hash table maintenance information */
74758 struct hlist_node uidhash_node;
74759 kuid_t uid;
74760@@ -1158,8 +1191,8 @@ struct task_struct {
74761 struct list_head thread_group;
74762
74763 struct completion *vfork_done; /* for vfork() */
74764- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
74765- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
74766+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
74767+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
74768
74769 cputime_t utime, stime, utimescaled, stimescaled;
74770 cputime_t gtime;
74771@@ -1184,11 +1217,6 @@ struct task_struct {
74772 struct task_cputime cputime_expires;
74773 struct list_head cpu_timers[3];
74774
74775-/* process credentials */
74776- const struct cred __rcu *real_cred; /* objective and real subjective task
74777- * credentials (COW) */
74778- const struct cred __rcu *cred; /* effective (overridable) subjective task
74779- * credentials (COW) */
74780 char comm[TASK_COMM_LEN]; /* executable name excluding path
74781 - access with [gs]et_task_comm (which lock
74782 it with task_lock())
74783@@ -1205,6 +1233,10 @@ struct task_struct {
74784 #endif
74785 /* CPU-specific state of this task */
74786 struct thread_struct thread;
74787+/* thread_info moved to task_struct */
74788+#ifdef CONFIG_X86
74789+ struct thread_info tinfo;
74790+#endif
74791 /* filesystem information */
74792 struct fs_struct *fs;
74793 /* open file information */
74794@@ -1278,6 +1310,10 @@ struct task_struct {
74795 gfp_t lockdep_reclaim_gfp;
74796 #endif
74797
74798+/* process credentials */
74799+ const struct cred __rcu *real_cred; /* objective and real subjective task
74800+ * credentials (COW) */
74801+
74802 /* journalling filesystem info */
74803 void *journal_info;
74804
74805@@ -1316,6 +1352,10 @@ struct task_struct {
74806 /* cg_list protected by css_set_lock and tsk->alloc_lock */
74807 struct list_head cg_list;
74808 #endif
74809+
74810+ const struct cred __rcu *cred; /* effective (overridable) subjective task
74811+ * credentials (COW) */
74812+
74813 #ifdef CONFIG_FUTEX
74814 struct robust_list_head __user *robust_list;
74815 #ifdef CONFIG_COMPAT
74816@@ -1416,8 +1456,76 @@ struct task_struct {
74817 unsigned int sequential_io;
74818 unsigned int sequential_io_avg;
74819 #endif
74820+
74821+#ifdef CONFIG_GRKERNSEC
74822+ /* grsecurity */
74823+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74824+ u64 exec_id;
74825+#endif
74826+#ifdef CONFIG_GRKERNSEC_SETXID
74827+ const struct cred *delayed_cred;
74828+#endif
74829+ struct dentry *gr_chroot_dentry;
74830+ struct acl_subject_label *acl;
74831+ struct acl_role_label *role;
74832+ struct file *exec_file;
74833+ unsigned long brute_expires;
74834+ u16 acl_role_id;
74835+ /* is this the task that authenticated to the special role */
74836+ u8 acl_sp_role;
74837+ u8 is_writable;
74838+ u8 brute;
74839+ u8 gr_is_chrooted;
74840+#endif
74841+
74842 };
74843
74844+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
74845+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
74846+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
74847+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
74848+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
74849+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
74850+
74851+#ifdef CONFIG_PAX_SOFTMODE
74852+extern int pax_softmode;
74853+#endif
74854+
74855+extern int pax_check_flags(unsigned long *);
74856+
74857+/* if tsk != current then task_lock must be held on it */
74858+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
74859+static inline unsigned long pax_get_flags(struct task_struct *tsk)
74860+{
74861+ if (likely(tsk->mm))
74862+ return tsk->mm->pax_flags;
74863+ else
74864+ return 0UL;
74865+}
74866+
74867+/* if tsk != current then task_lock must be held on it */
74868+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
74869+{
74870+ if (likely(tsk->mm)) {
74871+ tsk->mm->pax_flags = flags;
74872+ return 0;
74873+ }
74874+ return -EINVAL;
74875+}
74876+#endif
74877+
74878+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74879+extern void pax_set_initial_flags(struct linux_binprm *bprm);
74880+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
74881+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
74882+#endif
74883+
74884+struct path;
74885+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
74886+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
74887+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
74888+extern void pax_report_refcount_overflow(struct pt_regs *regs);
74889+
74890 /* Future-safe accessor for struct task_struct's cpus_allowed. */
74891 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
74892
74893@@ -1476,7 +1584,7 @@ struct pid_namespace;
74894 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
74895 struct pid_namespace *ns);
74896
74897-static inline pid_t task_pid_nr(struct task_struct *tsk)
74898+static inline pid_t task_pid_nr(const struct task_struct *tsk)
74899 {
74900 return tsk->pid;
74901 }
74902@@ -1919,7 +2027,9 @@ void yield(void);
74903 extern struct exec_domain default_exec_domain;
74904
74905 union thread_union {
74906+#ifndef CONFIG_X86
74907 struct thread_info thread_info;
74908+#endif
74909 unsigned long stack[THREAD_SIZE/sizeof(long)];
74910 };
74911
74912@@ -1952,6 +2062,7 @@ extern struct pid_namespace init_pid_ns;
74913 */
74914
74915 extern struct task_struct *find_task_by_vpid(pid_t nr);
74916+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
74917 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
74918 struct pid_namespace *ns);
74919
74920@@ -2118,7 +2229,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
74921 extern void exit_itimers(struct signal_struct *);
74922 extern void flush_itimer_signals(void);
74923
74924-extern void do_group_exit(int);
74925+extern __noreturn void do_group_exit(int);
74926
74927 extern int allow_signal(int);
74928 extern int disallow_signal(int);
74929@@ -2309,9 +2420,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
74930
74931 #endif
74932
74933-static inline int object_is_on_stack(void *obj)
74934+static inline int object_starts_on_stack(void *obj)
74935 {
74936- void *stack = task_stack_page(current);
74937+ const void *stack = task_stack_page(current);
74938
74939 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
74940 }
74941diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
74942index bf8086b..962b035 100644
74943--- a/include/linux/sched/sysctl.h
74944+++ b/include/linux/sched/sysctl.h
74945@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
74946 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
74947
74948 extern int sysctl_max_map_count;
74949+extern unsigned long sysctl_heap_stack_gap;
74950
74951 extern unsigned int sysctl_sched_latency;
74952 extern unsigned int sysctl_sched_min_granularity;
74953diff --git a/include/linux/security.h b/include/linux/security.h
74954index 4686491..2bd210e 100644
74955--- a/include/linux/security.h
74956+++ b/include/linux/security.h
74957@@ -26,6 +26,7 @@
74958 #include <linux/capability.h>
74959 #include <linux/slab.h>
74960 #include <linux/err.h>
74961+#include <linux/grsecurity.h>
74962
74963 struct linux_binprm;
74964 struct cred;
74965diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
74966index 2da29ac..aac448ec 100644
74967--- a/include/linux/seq_file.h
74968+++ b/include/linux/seq_file.h
74969@@ -26,6 +26,9 @@ struct seq_file {
74970 struct mutex lock;
74971 const struct seq_operations *op;
74972 int poll_event;
74973+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74974+ u64 exec_id;
74975+#endif
74976 #ifdef CONFIG_USER_NS
74977 struct user_namespace *user_ns;
74978 #endif
74979@@ -38,6 +41,7 @@ struct seq_operations {
74980 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
74981 int (*show) (struct seq_file *m, void *v);
74982 };
74983+typedef struct seq_operations __no_const seq_operations_no_const;
74984
74985 #define SEQ_SKIP 1
74986
74987diff --git a/include/linux/shm.h b/include/linux/shm.h
74988index 429c199..4d42e38 100644
74989--- a/include/linux/shm.h
74990+++ b/include/linux/shm.h
74991@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
74992
74993 /* The task created the shm object. NULL if the task is dead. */
74994 struct task_struct *shm_creator;
74995+#ifdef CONFIG_GRKERNSEC
74996+ time_t shm_createtime;
74997+ pid_t shm_lapid;
74998+#endif
74999 };
75000
75001 /* shm_mode upper byte flags */
75002diff --git a/include/linux/signal.h b/include/linux/signal.h
75003index d897484..323ba98 100644
75004--- a/include/linux/signal.h
75005+++ b/include/linux/signal.h
75006@@ -433,6 +433,7 @@ void signals_init(void);
75007
75008 int restore_altstack(const stack_t __user *);
75009 int __save_altstack(stack_t __user *, unsigned long);
75010+void __save_altstack_ex(stack_t __user *, unsigned long);
75011
75012 #ifdef CONFIG_PROC_FS
75013 struct seq_file;
75014diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
75015index dec1748..112c1f9 100644
75016--- a/include/linux/skbuff.h
75017+++ b/include/linux/skbuff.h
75018@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
75019 extern struct sk_buff *__alloc_skb(unsigned int size,
75020 gfp_t priority, int flags, int node);
75021 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
75022-static inline struct sk_buff *alloc_skb(unsigned int size,
75023+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
75024 gfp_t priority)
75025 {
75026 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
75027@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
75028 */
75029 static inline int skb_queue_empty(const struct sk_buff_head *list)
75030 {
75031- return list->next == (struct sk_buff *)list;
75032+ return list->next == (const struct sk_buff *)list;
75033 }
75034
75035 /**
75036@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
75037 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
75038 const struct sk_buff *skb)
75039 {
75040- return skb->next == (struct sk_buff *)list;
75041+ return skb->next == (const struct sk_buff *)list;
75042 }
75043
75044 /**
75045@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
75046 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
75047 const struct sk_buff *skb)
75048 {
75049- return skb->prev == (struct sk_buff *)list;
75050+ return skb->prev == (const struct sk_buff *)list;
75051 }
75052
75053 /**
75054@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
75055 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
75056 */
75057 #ifndef NET_SKB_PAD
75058-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
75059+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
75060 #endif
75061
75062 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
75063@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
75064 int noblock, int *err);
75065 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
75066 struct poll_table_struct *wait);
75067-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
75068+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
75069 int offset, struct iovec *to,
75070 int size);
75071 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
75072@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
75073 nf_bridge_put(skb->nf_bridge);
75074 skb->nf_bridge = NULL;
75075 #endif
75076+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
75077+ skb->nf_trace = 0;
75078+#endif
75079 }
75080
75081 static inline void nf_reset_trace(struct sk_buff *skb)
75082diff --git a/include/linux/slab.h b/include/linux/slab.h
75083index 0c62175..f016ac1 100644
75084--- a/include/linux/slab.h
75085+++ b/include/linux/slab.h
75086@@ -12,15 +12,29 @@
75087 #include <linux/gfp.h>
75088 #include <linux/types.h>
75089 #include <linux/workqueue.h>
75090-
75091+#include <linux/err.h>
75092
75093 /*
75094 * Flags to pass to kmem_cache_create().
75095 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
75096 */
75097 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
75098+
75099+#ifdef CONFIG_PAX_USERCOPY_SLABS
75100+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
75101+#else
75102+#define SLAB_USERCOPY 0x00000000UL
75103+#endif
75104+
75105 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
75106 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
75107+
75108+#ifdef CONFIG_PAX_MEMORY_SANITIZE
75109+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
75110+#else
75111+#define SLAB_NO_SANITIZE 0x00000000UL
75112+#endif
75113+
75114 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
75115 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
75116 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
75117@@ -89,10 +103,13 @@
75118 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
75119 * Both make kfree a no-op.
75120 */
75121-#define ZERO_SIZE_PTR ((void *)16)
75122+#define ZERO_SIZE_PTR \
75123+({ \
75124+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
75125+ (void *)(-MAX_ERRNO-1L); \
75126+})
75127
75128-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
75129- (unsigned long)ZERO_SIZE_PTR)
75130+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
75131
75132
75133 struct mem_cgroup;
75134@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
75135 void kfree(const void *);
75136 void kzfree(const void *);
75137 size_t ksize(const void *);
75138+const char *check_heap_object(const void *ptr, unsigned long n);
75139+bool is_usercopy_object(const void *ptr);
75140
75141 /*
75142 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
75143@@ -164,7 +183,7 @@ struct kmem_cache {
75144 unsigned int align; /* Alignment as calculated */
75145 unsigned long flags; /* Active flags on the slab */
75146 const char *name; /* Slab name for sysfs */
75147- int refcount; /* Use counter */
75148+ atomic_t refcount; /* Use counter */
75149 void (*ctor)(void *); /* Called on object slot creation */
75150 struct list_head list; /* List of all slab caches on the system */
75151 };
75152@@ -226,6 +245,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
75153 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
75154 #endif
75155
75156+#ifdef CONFIG_PAX_USERCOPY_SLABS
75157+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
75158+#endif
75159+
75160 /*
75161 * Figure out which kmalloc slab an allocation of a certain size
75162 * belongs to.
75163@@ -234,7 +257,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
75164 * 2 = 120 .. 192 bytes
75165 * n = 2^(n-1) .. 2^n -1
75166 */
75167-static __always_inline int kmalloc_index(size_t size)
75168+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
75169 {
75170 if (!size)
75171 return 0;
75172@@ -406,6 +429,7 @@ void print_slabinfo_header(struct seq_file *m);
75173 * for general use, and so are not documented here. For a full list of
75174 * potential flags, always refer to linux/gfp.h.
75175 */
75176+
75177 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
75178 {
75179 if (size != 0 && n > SIZE_MAX / size)
75180@@ -465,7 +489,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
75181 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
75182 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
75183 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
75184-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
75185+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
75186 #define kmalloc_track_caller(size, flags) \
75187 __kmalloc_track_caller(size, flags, _RET_IP_)
75188 #else
75189@@ -485,7 +509,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
75190 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
75191 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
75192 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
75193-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
75194+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
75195 #define kmalloc_node_track_caller(size, flags, node) \
75196 __kmalloc_node_track_caller(size, flags, node, \
75197 _RET_IP_)
75198diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
75199index cd40158..4e2f7af 100644
75200--- a/include/linux/slab_def.h
75201+++ b/include/linux/slab_def.h
75202@@ -50,7 +50,7 @@ struct kmem_cache {
75203 /* 4) cache creation/removal */
75204 const char *name;
75205 struct list_head list;
75206- int refcount;
75207+ atomic_t refcount;
75208 int object_size;
75209 int align;
75210
75211@@ -66,10 +66,14 @@ struct kmem_cache {
75212 unsigned long node_allocs;
75213 unsigned long node_frees;
75214 unsigned long node_overflow;
75215- atomic_t allochit;
75216- atomic_t allocmiss;
75217- atomic_t freehit;
75218- atomic_t freemiss;
75219+ atomic_unchecked_t allochit;
75220+ atomic_unchecked_t allocmiss;
75221+ atomic_unchecked_t freehit;
75222+ atomic_unchecked_t freemiss;
75223+#ifdef CONFIG_PAX_MEMORY_SANITIZE
75224+ atomic_unchecked_t sanitized;
75225+ atomic_unchecked_t not_sanitized;
75226+#endif
75227
75228 /*
75229 * If debugging is enabled, then the allocator can add additional
75230@@ -103,7 +107,7 @@ struct kmem_cache {
75231 };
75232
75233 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
75234-void *__kmalloc(size_t size, gfp_t flags);
75235+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
75236
75237 #ifdef CONFIG_TRACING
75238 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
75239@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
75240 cachep = kmalloc_dma_caches[i];
75241 else
75242 #endif
75243+
75244+#ifdef CONFIG_PAX_USERCOPY_SLABS
75245+ if (flags & GFP_USERCOPY)
75246+ cachep = kmalloc_usercopy_caches[i];
75247+ else
75248+#endif
75249+
75250 cachep = kmalloc_caches[i];
75251
75252 ret = kmem_cache_alloc_trace(cachep, flags, size);
75253@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
75254 }
75255
75256 #ifdef CONFIG_NUMA
75257-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
75258+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
75259 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
75260
75261 #ifdef CONFIG_TRACING
75262@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
75263 cachep = kmalloc_dma_caches[i];
75264 else
75265 #endif
75266+
75267+#ifdef CONFIG_PAX_USERCOPY_SLABS
75268+ if (flags & GFP_USERCOPY)
75269+ cachep = kmalloc_usercopy_caches[i];
75270+ else
75271+#endif
75272+
75273 cachep = kmalloc_caches[i];
75274
75275 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
75276diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
75277index f28e14a..7831211 100644
75278--- a/include/linux/slob_def.h
75279+++ b/include/linux/slob_def.h
75280@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
75281 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
75282 }
75283
75284-void *__kmalloc_node(size_t size, gfp_t flags, int node);
75285+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
75286
75287 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
75288 {
75289@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
75290 return __kmalloc_node(size, flags, NUMA_NO_NODE);
75291 }
75292
75293-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
75294+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
75295 {
75296 return kmalloc(size, flags);
75297 }
75298diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
75299index 027276f..092bfe8 100644
75300--- a/include/linux/slub_def.h
75301+++ b/include/linux/slub_def.h
75302@@ -80,7 +80,7 @@ struct kmem_cache {
75303 struct kmem_cache_order_objects max;
75304 struct kmem_cache_order_objects min;
75305 gfp_t allocflags; /* gfp flags to use on each alloc */
75306- int refcount; /* Refcount for slab cache destroy */
75307+ atomic_t refcount; /* Refcount for slab cache destroy */
75308 void (*ctor)(void *);
75309 int inuse; /* Offset to metadata */
75310 int align; /* Alignment */
75311@@ -105,7 +105,7 @@ struct kmem_cache {
75312 };
75313
75314 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
75315-void *__kmalloc(size_t size, gfp_t flags);
75316+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
75317
75318 static __always_inline void *
75319 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
75320@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
75321 }
75322 #endif
75323
75324-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
75325+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
75326 {
75327 unsigned int order = get_order(size);
75328 return kmalloc_order_trace(size, flags, order);
75329@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
75330 }
75331
75332 #ifdef CONFIG_NUMA
75333-void *__kmalloc_node(size_t size, gfp_t flags, int node);
75334+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
75335 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
75336
75337 #ifdef CONFIG_TRACING
75338diff --git a/include/linux/smp.h b/include/linux/smp.h
75339index c848876..11e8a84 100644
75340--- a/include/linux/smp.h
75341+++ b/include/linux/smp.h
75342@@ -221,7 +221,9 @@ static inline void kick_all_cpus_sync(void) { }
75343 #endif
75344
75345 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
75346+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
75347 #define put_cpu() preempt_enable()
75348+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
75349
75350 /*
75351 * Callback to arch code if there's nosmp or maxcpus=0 on the
75352diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
75353index 54f91d3..be2c379 100644
75354--- a/include/linux/sock_diag.h
75355+++ b/include/linux/sock_diag.h
75356@@ -11,7 +11,7 @@ struct sock;
75357 struct sock_diag_handler {
75358 __u8 family;
75359 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
75360-};
75361+} __do_const;
75362
75363 int sock_diag_register(const struct sock_diag_handler *h);
75364 void sock_diag_unregister(const struct sock_diag_handler *h);
75365diff --git a/include/linux/sonet.h b/include/linux/sonet.h
75366index 680f9a3..f13aeb0 100644
75367--- a/include/linux/sonet.h
75368+++ b/include/linux/sonet.h
75369@@ -7,7 +7,7 @@
75370 #include <uapi/linux/sonet.h>
75371
75372 struct k_sonet_stats {
75373-#define __HANDLE_ITEM(i) atomic_t i
75374+#define __HANDLE_ITEM(i) atomic_unchecked_t i
75375 __SONET_ITEMS
75376 #undef __HANDLE_ITEM
75377 };
75378diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
75379index 07d8e53..dc934c9 100644
75380--- a/include/linux/sunrpc/addr.h
75381+++ b/include/linux/sunrpc/addr.h
75382@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
75383 {
75384 switch (sap->sa_family) {
75385 case AF_INET:
75386- return ntohs(((struct sockaddr_in *)sap)->sin_port);
75387+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
75388 case AF_INET6:
75389- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
75390+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
75391 }
75392 return 0;
75393 }
75394@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
75395 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
75396 const struct sockaddr *src)
75397 {
75398- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
75399+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
75400 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
75401
75402 dsin->sin_family = ssin->sin_family;
75403@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
75404 if (sa->sa_family != AF_INET6)
75405 return 0;
75406
75407- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
75408+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
75409 }
75410
75411 #endif /* _LINUX_SUNRPC_ADDR_H */
75412diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
75413index bfe11be..12bc8c4 100644
75414--- a/include/linux/sunrpc/clnt.h
75415+++ b/include/linux/sunrpc/clnt.h
75416@@ -96,7 +96,7 @@ struct rpc_procinfo {
75417 unsigned int p_timer; /* Which RTT timer to use */
75418 u32 p_statidx; /* Which procedure to account */
75419 const char * p_name; /* name of procedure */
75420-};
75421+} __do_const;
75422
75423 #ifdef __KERNEL__
75424
75425diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
75426index 1f0216b..6a4fa50 100644
75427--- a/include/linux/sunrpc/svc.h
75428+++ b/include/linux/sunrpc/svc.h
75429@@ -411,7 +411,7 @@ struct svc_procedure {
75430 unsigned int pc_count; /* call count */
75431 unsigned int pc_cachetype; /* cache info (NFS) */
75432 unsigned int pc_xdrressize; /* maximum size of XDR reply */
75433-};
75434+} __do_const;
75435
75436 /*
75437 * Function prototypes.
75438diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
75439index 0b8e3e6..33e0a01 100644
75440--- a/include/linux/sunrpc/svc_rdma.h
75441+++ b/include/linux/sunrpc/svc_rdma.h
75442@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
75443 extern unsigned int svcrdma_max_requests;
75444 extern unsigned int svcrdma_max_req_size;
75445
75446-extern atomic_t rdma_stat_recv;
75447-extern atomic_t rdma_stat_read;
75448-extern atomic_t rdma_stat_write;
75449-extern atomic_t rdma_stat_sq_starve;
75450-extern atomic_t rdma_stat_rq_starve;
75451-extern atomic_t rdma_stat_rq_poll;
75452-extern atomic_t rdma_stat_rq_prod;
75453-extern atomic_t rdma_stat_sq_poll;
75454-extern atomic_t rdma_stat_sq_prod;
75455+extern atomic_unchecked_t rdma_stat_recv;
75456+extern atomic_unchecked_t rdma_stat_read;
75457+extern atomic_unchecked_t rdma_stat_write;
75458+extern atomic_unchecked_t rdma_stat_sq_starve;
75459+extern atomic_unchecked_t rdma_stat_rq_starve;
75460+extern atomic_unchecked_t rdma_stat_rq_poll;
75461+extern atomic_unchecked_t rdma_stat_rq_prod;
75462+extern atomic_unchecked_t rdma_stat_sq_poll;
75463+extern atomic_unchecked_t rdma_stat_sq_prod;
75464
75465 #define RPCRDMA_VERSION 1
75466
75467diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
75468index ff374ab..7fd2ecb 100644
75469--- a/include/linux/sunrpc/svcauth.h
75470+++ b/include/linux/sunrpc/svcauth.h
75471@@ -109,7 +109,7 @@ struct auth_ops {
75472 int (*release)(struct svc_rqst *rq);
75473 void (*domain_release)(struct auth_domain *);
75474 int (*set_client)(struct svc_rqst *rq);
75475-};
75476+} __do_const;
75477
75478 #define SVC_GARBAGE 1
75479 #define SVC_SYSERR 2
75480diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
75481index a5ffd32..0935dea 100644
75482--- a/include/linux/swiotlb.h
75483+++ b/include/linux/swiotlb.h
75484@@ -60,7 +60,8 @@ extern void
75485
75486 extern void
75487 swiotlb_free_coherent(struct device *hwdev, size_t size,
75488- void *vaddr, dma_addr_t dma_handle);
75489+ void *vaddr, dma_addr_t dma_handle,
75490+ struct dma_attrs *attrs);
75491
75492 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
75493 unsigned long offset, size_t size,
75494diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
75495index 4147d70..d356a10 100644
75496--- a/include/linux/syscalls.h
75497+++ b/include/linux/syscalls.h
75498@@ -97,8 +97,12 @@ struct sigaltstack;
75499 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
75500
75501 #define __SC_DECL(t, a) t a
75502-#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
75503-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
75504+#define __TYPE_IS_SL(t) (__same_type((t)0, 0L))
75505+#define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
75506+#define __TYPE_IS_SLL(t) (__same_type((t)0, 0LL))
75507+#define __TYPE_IS_ULL(t) (__same_type((t)0, 0ULL))
75508+#define __TYPE_IS_LL(t) (__TYPE_IS_SLL(t) || __TYPE_IS_ULL(t))
75509+#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), __builtin_choose_expr(__TYPE_IS_ULL(t), 0ULL, 0LL), __builtin_choose_expr(__TYPE_IS_UL(t), 0UL, 0L))) a
75510 #define __SC_CAST(t, a) (t) a
75511 #define __SC_ARGS(t, a) a
75512 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
75513@@ -362,11 +366,11 @@ asmlinkage long sys_sync(void);
75514 asmlinkage long sys_fsync(unsigned int fd);
75515 asmlinkage long sys_fdatasync(unsigned int fd);
75516 asmlinkage long sys_bdflush(int func, long data);
75517-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
75518- char __user *type, unsigned long flags,
75519+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
75520+ const char __user *type, unsigned long flags,
75521 void __user *data);
75522-asmlinkage long sys_umount(char __user *name, int flags);
75523-asmlinkage long sys_oldumount(char __user *name);
75524+asmlinkage long sys_umount(const char __user *name, int flags);
75525+asmlinkage long sys_oldumount(const char __user *name);
75526 asmlinkage long sys_truncate(const char __user *path, long length);
75527 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
75528 asmlinkage long sys_stat(const char __user *filename,
75529@@ -578,7 +582,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
75530 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
75531 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
75532 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
75533- struct sockaddr __user *, int);
75534+ struct sockaddr __user *, int) __intentional_overflow(0);
75535 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
75536 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
75537 unsigned int vlen, unsigned flags);
75538diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
75539index 27b3b0b..e093dd9 100644
75540--- a/include/linux/syscore_ops.h
75541+++ b/include/linux/syscore_ops.h
75542@@ -16,7 +16,7 @@ struct syscore_ops {
75543 int (*suspend)(void);
75544 void (*resume)(void);
75545 void (*shutdown)(void);
75546-};
75547+} __do_const;
75548
75549 extern void register_syscore_ops(struct syscore_ops *ops);
75550 extern void unregister_syscore_ops(struct syscore_ops *ops);
75551diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
75552index 14a8ff2..af52bad 100644
75553--- a/include/linux/sysctl.h
75554+++ b/include/linux/sysctl.h
75555@@ -34,13 +34,13 @@ struct ctl_table_root;
75556 struct ctl_table_header;
75557 struct ctl_dir;
75558
75559-typedef struct ctl_table ctl_table;
75560-
75561 typedef int proc_handler (struct ctl_table *ctl, int write,
75562 void __user *buffer, size_t *lenp, loff_t *ppos);
75563
75564 extern int proc_dostring(struct ctl_table *, int,
75565 void __user *, size_t *, loff_t *);
75566+extern int proc_dostring_modpriv(struct ctl_table *, int,
75567+ void __user *, size_t *, loff_t *);
75568 extern int proc_dointvec(struct ctl_table *, int,
75569 void __user *, size_t *, loff_t *);
75570 extern int proc_dointvec_minmax(struct ctl_table *, int,
75571@@ -115,7 +115,9 @@ struct ctl_table
75572 struct ctl_table_poll *poll;
75573 void *extra1;
75574 void *extra2;
75575-};
75576+} __do_const;
75577+typedef struct ctl_table __no_const ctl_table_no_const;
75578+typedef struct ctl_table ctl_table;
75579
75580 struct ctl_node {
75581 struct rb_node node;
75582diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
75583index e2cee22..3ddb921 100644
75584--- a/include/linux/sysfs.h
75585+++ b/include/linux/sysfs.h
75586@@ -31,7 +31,8 @@ struct attribute {
75587 struct lock_class_key *key;
75588 struct lock_class_key skey;
75589 #endif
75590-};
75591+} __do_const;
75592+typedef struct attribute __no_const attribute_no_const;
75593
75594 /**
75595 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
75596@@ -59,8 +60,8 @@ struct attribute_group {
75597 umode_t (*is_visible)(struct kobject *,
75598 struct attribute *, int);
75599 struct attribute **attrs;
75600-};
75601-
75602+} __do_const;
75603+typedef struct attribute_group __no_const attribute_group_no_const;
75604
75605
75606 /**
75607@@ -107,7 +108,8 @@ struct bin_attribute {
75608 char *, loff_t, size_t);
75609 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
75610 struct vm_area_struct *vma);
75611-};
75612+} __do_const;
75613+typedef struct bin_attribute __no_const bin_attribute_no_const;
75614
75615 /**
75616 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
75617diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
75618index 7faf933..9b85a0c 100644
75619--- a/include/linux/sysrq.h
75620+++ b/include/linux/sysrq.h
75621@@ -16,6 +16,7 @@
75622
75623 #include <linux/errno.h>
75624 #include <linux/types.h>
75625+#include <linux/compiler.h>
75626
75627 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
75628 #define SYSRQ_DEFAULT_ENABLE 1
75629@@ -36,7 +37,7 @@ struct sysrq_key_op {
75630 char *help_msg;
75631 char *action_msg;
75632 int enable_mask;
75633-};
75634+} __do_const;
75635
75636 #ifdef CONFIG_MAGIC_SYSRQ
75637
75638diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
75639index e7e0473..7989295 100644
75640--- a/include/linux/thread_info.h
75641+++ b/include/linux/thread_info.h
75642@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
75643 #error "no set_restore_sigmask() provided and default one won't work"
75644 #endif
75645
75646+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
75647+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
75648+{
75649+#ifndef CONFIG_PAX_USERCOPY_DEBUG
75650+ if (!__builtin_constant_p(n))
75651+#endif
75652+ __check_object_size(ptr, n, to_user);
75653+}
75654+
75655 #endif /* __KERNEL__ */
75656
75657 #endif /* _LINUX_THREAD_INFO_H */
75658diff --git a/include/linux/tty.h b/include/linux/tty.h
75659index 8780bd2..d1ae08b 100644
75660--- a/include/linux/tty.h
75661+++ b/include/linux/tty.h
75662@@ -194,7 +194,7 @@ struct tty_port {
75663 const struct tty_port_operations *ops; /* Port operations */
75664 spinlock_t lock; /* Lock protecting tty field */
75665 int blocked_open; /* Waiting to open */
75666- int count; /* Usage count */
75667+ atomic_t count; /* Usage count */
75668 wait_queue_head_t open_wait; /* Open waiters */
75669 wait_queue_head_t close_wait; /* Close waiters */
75670 wait_queue_head_t delta_msr_wait; /* Modem status change */
75671@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
75672 struct tty_struct *tty, struct file *filp);
75673 static inline int tty_port_users(struct tty_port *port)
75674 {
75675- return port->count + port->blocked_open;
75676+ return atomic_read(&port->count) + port->blocked_open;
75677 }
75678
75679 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
75680diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
75681index 756a609..b302dd6 100644
75682--- a/include/linux/tty_driver.h
75683+++ b/include/linux/tty_driver.h
75684@@ -285,7 +285,7 @@ struct tty_operations {
75685 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
75686 #endif
75687 const struct file_operations *proc_fops;
75688-};
75689+} __do_const;
75690
75691 struct tty_driver {
75692 int magic; /* magic number for this structure */
75693diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
75694index 58390c7..95e214c 100644
75695--- a/include/linux/tty_ldisc.h
75696+++ b/include/linux/tty_ldisc.h
75697@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
75698
75699 struct module *owner;
75700
75701- int refcount;
75702+ atomic_t refcount;
75703 };
75704
75705 struct tty_ldisc {
75706diff --git a/include/linux/types.h b/include/linux/types.h
75707index 4d118ba..c3ee9bf 100644
75708--- a/include/linux/types.h
75709+++ b/include/linux/types.h
75710@@ -176,10 +176,26 @@ typedef struct {
75711 int counter;
75712 } atomic_t;
75713
75714+#ifdef CONFIG_PAX_REFCOUNT
75715+typedef struct {
75716+ int counter;
75717+} atomic_unchecked_t;
75718+#else
75719+typedef atomic_t atomic_unchecked_t;
75720+#endif
75721+
75722 #ifdef CONFIG_64BIT
75723 typedef struct {
75724 long counter;
75725 } atomic64_t;
75726+
75727+#ifdef CONFIG_PAX_REFCOUNT
75728+typedef struct {
75729+ long counter;
75730+} atomic64_unchecked_t;
75731+#else
75732+typedef atomic64_t atomic64_unchecked_t;
75733+#endif
75734 #endif
75735
75736 struct list_head {
75737diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
75738index 5ca0951..ab496a5 100644
75739--- a/include/linux/uaccess.h
75740+++ b/include/linux/uaccess.h
75741@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
75742 long ret; \
75743 mm_segment_t old_fs = get_fs(); \
75744 \
75745- set_fs(KERNEL_DS); \
75746 pagefault_disable(); \
75747- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
75748- pagefault_enable(); \
75749+ set_fs(KERNEL_DS); \
75750+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
75751 set_fs(old_fs); \
75752+ pagefault_enable(); \
75753 ret; \
75754 })
75755
75756diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
75757index 8e522cbc..aa8572d 100644
75758--- a/include/linux/uidgid.h
75759+++ b/include/linux/uidgid.h
75760@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
75761
75762 #endif /* CONFIG_USER_NS */
75763
75764+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
75765+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
75766+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
75767+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
75768+
75769 #endif /* _LINUX_UIDGID_H */
75770diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
75771index 99c1b4d..562e6f3 100644
75772--- a/include/linux/unaligned/access_ok.h
75773+++ b/include/linux/unaligned/access_ok.h
75774@@ -4,34 +4,34 @@
75775 #include <linux/kernel.h>
75776 #include <asm/byteorder.h>
75777
75778-static inline u16 get_unaligned_le16(const void *p)
75779+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
75780 {
75781- return le16_to_cpup((__le16 *)p);
75782+ return le16_to_cpup((const __le16 *)p);
75783 }
75784
75785-static inline u32 get_unaligned_le32(const void *p)
75786+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
75787 {
75788- return le32_to_cpup((__le32 *)p);
75789+ return le32_to_cpup((const __le32 *)p);
75790 }
75791
75792-static inline u64 get_unaligned_le64(const void *p)
75793+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
75794 {
75795- return le64_to_cpup((__le64 *)p);
75796+ return le64_to_cpup((const __le64 *)p);
75797 }
75798
75799-static inline u16 get_unaligned_be16(const void *p)
75800+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
75801 {
75802- return be16_to_cpup((__be16 *)p);
75803+ return be16_to_cpup((const __be16 *)p);
75804 }
75805
75806-static inline u32 get_unaligned_be32(const void *p)
75807+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
75808 {
75809- return be32_to_cpup((__be32 *)p);
75810+ return be32_to_cpup((const __be32 *)p);
75811 }
75812
75813-static inline u64 get_unaligned_be64(const void *p)
75814+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
75815 {
75816- return be64_to_cpup((__be64 *)p);
75817+ return be64_to_cpup((const __be64 *)p);
75818 }
75819
75820 static inline void put_unaligned_le16(u16 val, void *p)
75821diff --git a/include/linux/usb.h b/include/linux/usb.h
75822index a0bee5a..5533a52 100644
75823--- a/include/linux/usb.h
75824+++ b/include/linux/usb.h
75825@@ -552,7 +552,7 @@ struct usb_device {
75826 int maxchild;
75827
75828 u32 quirks;
75829- atomic_t urbnum;
75830+ atomic_unchecked_t urbnum;
75831
75832 unsigned long active_duration;
75833
75834@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
75835
75836 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
75837 __u8 request, __u8 requesttype, __u16 value, __u16 index,
75838- void *data, __u16 size, int timeout);
75839+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
75840 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
75841 void *data, int len, int *actual_length, int timeout);
75842 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
75843diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
75844index e452ba6..78f8e80 100644
75845--- a/include/linux/usb/renesas_usbhs.h
75846+++ b/include/linux/usb/renesas_usbhs.h
75847@@ -39,7 +39,7 @@ enum {
75848 */
75849 struct renesas_usbhs_driver_callback {
75850 int (*notify_hotplug)(struct platform_device *pdev);
75851-};
75852+} __no_const;
75853
75854 /*
75855 * callback functions for platform
75856diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
75857index 6f8fbcf..8259001 100644
75858--- a/include/linux/vermagic.h
75859+++ b/include/linux/vermagic.h
75860@@ -25,9 +25,35 @@
75861 #define MODULE_ARCH_VERMAGIC ""
75862 #endif
75863
75864+#ifdef CONFIG_PAX_REFCOUNT
75865+#define MODULE_PAX_REFCOUNT "REFCOUNT "
75866+#else
75867+#define MODULE_PAX_REFCOUNT ""
75868+#endif
75869+
75870+#ifdef CONSTIFY_PLUGIN
75871+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
75872+#else
75873+#define MODULE_CONSTIFY_PLUGIN ""
75874+#endif
75875+
75876+#ifdef STACKLEAK_PLUGIN
75877+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
75878+#else
75879+#define MODULE_STACKLEAK_PLUGIN ""
75880+#endif
75881+
75882+#ifdef CONFIG_GRKERNSEC
75883+#define MODULE_GRSEC "GRSEC "
75884+#else
75885+#define MODULE_GRSEC ""
75886+#endif
75887+
75888 #define VERMAGIC_STRING \
75889 UTS_RELEASE " " \
75890 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
75891 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
75892- MODULE_ARCH_VERMAGIC
75893+ MODULE_ARCH_VERMAGIC \
75894+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
75895+ MODULE_GRSEC
75896
75897diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
75898index 7d5773a..541c01c 100644
75899--- a/include/linux/vmalloc.h
75900+++ b/include/linux/vmalloc.h
75901@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
75902 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
75903 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
75904 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
75905+
75906+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75907+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
75908+#endif
75909+
75910 /* bits [20..32] reserved for arch specific ioremap internals */
75911
75912 /*
75913@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
75914 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
75915 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
75916 unsigned long start, unsigned long end, gfp_t gfp_mask,
75917- pgprot_t prot, int node, const void *caller);
75918+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
75919 extern void vfree(const void *addr);
75920
75921 extern void *vmap(struct page **pages, unsigned int count,
75922@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
75923 extern void free_vm_area(struct vm_struct *area);
75924
75925 /* for /dev/kmem */
75926-extern long vread(char *buf, char *addr, unsigned long count);
75927-extern long vwrite(char *buf, char *addr, unsigned long count);
75928+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
75929+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
75930
75931 /*
75932 * Internals. Dont't use..
75933diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
75934index c586679..f06b389 100644
75935--- a/include/linux/vmstat.h
75936+++ b/include/linux/vmstat.h
75937@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
75938 /*
75939 * Zone based page accounting with per cpu differentials.
75940 */
75941-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75942+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75943
75944 static inline void zone_page_state_add(long x, struct zone *zone,
75945 enum zone_stat_item item)
75946 {
75947- atomic_long_add(x, &zone->vm_stat[item]);
75948- atomic_long_add(x, &vm_stat[item]);
75949+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
75950+ atomic_long_add_unchecked(x, &vm_stat[item]);
75951 }
75952
75953 static inline unsigned long global_page_state(enum zone_stat_item item)
75954 {
75955- long x = atomic_long_read(&vm_stat[item]);
75956+ long x = atomic_long_read_unchecked(&vm_stat[item]);
75957 #ifdef CONFIG_SMP
75958 if (x < 0)
75959 x = 0;
75960@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
75961 static inline unsigned long zone_page_state(struct zone *zone,
75962 enum zone_stat_item item)
75963 {
75964- long x = atomic_long_read(&zone->vm_stat[item]);
75965+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
75966 #ifdef CONFIG_SMP
75967 if (x < 0)
75968 x = 0;
75969@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
75970 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
75971 enum zone_stat_item item)
75972 {
75973- long x = atomic_long_read(&zone->vm_stat[item]);
75974+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
75975
75976 #ifdef CONFIG_SMP
75977 int cpu;
75978@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
75979
75980 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
75981 {
75982- atomic_long_inc(&zone->vm_stat[item]);
75983- atomic_long_inc(&vm_stat[item]);
75984+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
75985+ atomic_long_inc_unchecked(&vm_stat[item]);
75986 }
75987
75988 static inline void __inc_zone_page_state(struct page *page,
75989@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
75990
75991 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
75992 {
75993- atomic_long_dec(&zone->vm_stat[item]);
75994- atomic_long_dec(&vm_stat[item]);
75995+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
75996+ atomic_long_dec_unchecked(&vm_stat[item]);
75997 }
75998
75999 static inline void __dec_zone_page_state(struct page *page,
76000diff --git a/include/linux/xattr.h b/include/linux/xattr.h
76001index fdbafc6..49dfe4f 100644
76002--- a/include/linux/xattr.h
76003+++ b/include/linux/xattr.h
76004@@ -28,7 +28,7 @@ struct xattr_handler {
76005 size_t size, int handler_flags);
76006 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
76007 size_t size, int flags, int handler_flags);
76008-};
76009+} __do_const;
76010
76011 struct xattr {
76012 char *name;
76013@@ -37,6 +37,9 @@ struct xattr {
76014 };
76015
76016 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
76017+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76018+ssize_t pax_getxattr(struct dentry *, void *, size_t);
76019+#endif
76020 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
76021 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
76022 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
76023diff --git a/include/linux/zlib.h b/include/linux/zlib.h
76024index 9c5a6b4..09c9438 100644
76025--- a/include/linux/zlib.h
76026+++ b/include/linux/zlib.h
76027@@ -31,6 +31,7 @@
76028 #define _ZLIB_H
76029
76030 #include <linux/zconf.h>
76031+#include <linux/compiler.h>
76032
76033 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
76034 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
76035@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
76036
76037 /* basic functions */
76038
76039-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
76040+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
76041 /*
76042 Returns the number of bytes that needs to be allocated for a per-
76043 stream workspace with the specified parameters. A pointer to this
76044diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
76045index 95d1c91..6798cca 100644
76046--- a/include/media/v4l2-dev.h
76047+++ b/include/media/v4l2-dev.h
76048@@ -76,7 +76,7 @@ struct v4l2_file_operations {
76049 int (*mmap) (struct file *, struct vm_area_struct *);
76050 int (*open) (struct file *);
76051 int (*release) (struct file *);
76052-};
76053+} __do_const;
76054
76055 /*
76056 * Newer version of video_device, handled by videodev2.c
76057diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
76058index adcbb20..62c2559 100644
76059--- a/include/net/9p/transport.h
76060+++ b/include/net/9p/transport.h
76061@@ -57,7 +57,7 @@ struct p9_trans_module {
76062 int (*cancel) (struct p9_client *, struct p9_req_t *req);
76063 int (*zc_request)(struct p9_client *, struct p9_req_t *,
76064 char *, char *, int , int, int, int);
76065-};
76066+} __do_const;
76067
76068 void v9fs_register_trans(struct p9_trans_module *m);
76069 void v9fs_unregister_trans(struct p9_trans_module *m);
76070diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
76071index fb94cf1..7c0c987 100644
76072--- a/include/net/bluetooth/l2cap.h
76073+++ b/include/net/bluetooth/l2cap.h
76074@@ -551,7 +551,7 @@ struct l2cap_ops {
76075 void (*defer) (struct l2cap_chan *chan);
76076 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
76077 unsigned long len, int nb);
76078-};
76079+} __do_const;
76080
76081 struct l2cap_conn {
76082 struct hci_conn *hcon;
76083diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
76084index f2ae33d..c457cf0 100644
76085--- a/include/net/caif/cfctrl.h
76086+++ b/include/net/caif/cfctrl.h
76087@@ -52,7 +52,7 @@ struct cfctrl_rsp {
76088 void (*radioset_rsp)(void);
76089 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
76090 struct cflayer *client_layer);
76091-};
76092+} __no_const;
76093
76094 /* Link Setup Parameters for CAIF-Links. */
76095 struct cfctrl_link_param {
76096@@ -101,8 +101,8 @@ struct cfctrl_request_info {
76097 struct cfctrl {
76098 struct cfsrvl serv;
76099 struct cfctrl_rsp res;
76100- atomic_t req_seq_no;
76101- atomic_t rsp_seq_no;
76102+ atomic_unchecked_t req_seq_no;
76103+ atomic_unchecked_t rsp_seq_no;
76104 struct list_head list;
76105 /* Protects from simultaneous access to first_req list */
76106 spinlock_t info_list_lock;
76107diff --git a/include/net/flow.h b/include/net/flow.h
76108index 628e11b..4c475df 100644
76109--- a/include/net/flow.h
76110+++ b/include/net/flow.h
76111@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
76112
76113 extern void flow_cache_flush(void);
76114 extern void flow_cache_flush_deferred(void);
76115-extern atomic_t flow_cache_genid;
76116+extern atomic_unchecked_t flow_cache_genid;
76117
76118 #endif
76119diff --git a/include/net/genetlink.h b/include/net/genetlink.h
76120index 93024a4..eeb6b6e 100644
76121--- a/include/net/genetlink.h
76122+++ b/include/net/genetlink.h
76123@@ -119,7 +119,7 @@ struct genl_ops {
76124 struct netlink_callback *cb);
76125 int (*done)(struct netlink_callback *cb);
76126 struct list_head ops_list;
76127-};
76128+} __do_const;
76129
76130 extern int genl_register_family(struct genl_family *family);
76131 extern int genl_register_family_with_ops(struct genl_family *family,
76132diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
76133index 734d9b5..48a9a4b 100644
76134--- a/include/net/gro_cells.h
76135+++ b/include/net/gro_cells.h
76136@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
76137 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
76138
76139 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
76140- atomic_long_inc(&dev->rx_dropped);
76141+ atomic_long_inc_unchecked(&dev->rx_dropped);
76142 kfree_skb(skb);
76143 return;
76144 }
76145diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
76146index de2c785..0588a6b 100644
76147--- a/include/net/inet_connection_sock.h
76148+++ b/include/net/inet_connection_sock.h
76149@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
76150 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
76151 int (*bind_conflict)(const struct sock *sk,
76152 const struct inet_bind_bucket *tb, bool relax);
76153-};
76154+} __do_const;
76155
76156 /** inet_connection_sock - INET connection oriented sock
76157 *
76158diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
76159index 53f464d..ba76aaa 100644
76160--- a/include/net/inetpeer.h
76161+++ b/include/net/inetpeer.h
76162@@ -47,8 +47,8 @@ struct inet_peer {
76163 */
76164 union {
76165 struct {
76166- atomic_t rid; /* Frag reception counter */
76167- atomic_t ip_id_count; /* IP ID for the next packet */
76168+ atomic_unchecked_t rid; /* Frag reception counter */
76169+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
76170 };
76171 struct rcu_head rcu;
76172 struct inet_peer *gc_next;
76173@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
76174 more++;
76175 inet_peer_refcheck(p);
76176 do {
76177- old = atomic_read(&p->ip_id_count);
76178+ old = atomic_read_unchecked(&p->ip_id_count);
76179 new = old + more;
76180 if (!new)
76181 new = 1;
76182- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
76183+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
76184 return new;
76185 }
76186
76187diff --git a/include/net/ip.h b/include/net/ip.h
76188index a68f838..74518ab 100644
76189--- a/include/net/ip.h
76190+++ b/include/net/ip.h
76191@@ -202,7 +202,7 @@ extern struct local_ports {
76192 } sysctl_local_ports;
76193 extern void inet_get_local_port_range(int *low, int *high);
76194
76195-extern unsigned long *sysctl_local_reserved_ports;
76196+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
76197 static inline int inet_is_reserved_local_port(int port)
76198 {
76199 return test_bit(port, sysctl_local_reserved_ports);
76200diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
76201index e49db91..76a81de 100644
76202--- a/include/net/ip_fib.h
76203+++ b/include/net/ip_fib.h
76204@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
76205
76206 #define FIB_RES_SADDR(net, res) \
76207 ((FIB_RES_NH(res).nh_saddr_genid == \
76208- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
76209+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
76210 FIB_RES_NH(res).nh_saddr : \
76211 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
76212 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
76213diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
76214index 4c062cc..3562c31 100644
76215--- a/include/net/ip_vs.h
76216+++ b/include/net/ip_vs.h
76217@@ -612,7 +612,7 @@ struct ip_vs_conn {
76218 struct ip_vs_conn *control; /* Master control connection */
76219 atomic_t n_control; /* Number of controlled ones */
76220 struct ip_vs_dest *dest; /* real server */
76221- atomic_t in_pkts; /* incoming packet counter */
76222+ atomic_unchecked_t in_pkts; /* incoming packet counter */
76223
76224 /* packet transmitter for different forwarding methods. If it
76225 mangles the packet, it must return NF_DROP or better NF_STOLEN,
76226@@ -761,7 +761,7 @@ struct ip_vs_dest {
76227 __be16 port; /* port number of the server */
76228 union nf_inet_addr addr; /* IP address of the server */
76229 volatile unsigned int flags; /* dest status flags */
76230- atomic_t conn_flags; /* flags to copy to conn */
76231+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
76232 atomic_t weight; /* server weight */
76233
76234 atomic_t refcnt; /* reference counter */
76235@@ -1013,11 +1013,11 @@ struct netns_ipvs {
76236 /* ip_vs_lblc */
76237 int sysctl_lblc_expiration;
76238 struct ctl_table_header *lblc_ctl_header;
76239- struct ctl_table *lblc_ctl_table;
76240+ ctl_table_no_const *lblc_ctl_table;
76241 /* ip_vs_lblcr */
76242 int sysctl_lblcr_expiration;
76243 struct ctl_table_header *lblcr_ctl_header;
76244- struct ctl_table *lblcr_ctl_table;
76245+ ctl_table_no_const *lblcr_ctl_table;
76246 /* ip_vs_est */
76247 struct list_head est_list; /* estimator list */
76248 spinlock_t est_lock;
76249diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
76250index 80ffde3..968b0f4 100644
76251--- a/include/net/irda/ircomm_tty.h
76252+++ b/include/net/irda/ircomm_tty.h
76253@@ -35,6 +35,7 @@
76254 #include <linux/termios.h>
76255 #include <linux/timer.h>
76256 #include <linux/tty.h> /* struct tty_struct */
76257+#include <asm/local.h>
76258
76259 #include <net/irda/irias_object.h>
76260 #include <net/irda/ircomm_core.h>
76261diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
76262index 714cc9a..ea05f3e 100644
76263--- a/include/net/iucv/af_iucv.h
76264+++ b/include/net/iucv/af_iucv.h
76265@@ -149,7 +149,7 @@ struct iucv_skb_cb {
76266 struct iucv_sock_list {
76267 struct hlist_head head;
76268 rwlock_t lock;
76269- atomic_t autobind_name;
76270+ atomic_unchecked_t autobind_name;
76271 };
76272
76273 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
76274diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
76275index df83f69..9b640b8 100644
76276--- a/include/net/llc_c_ac.h
76277+++ b/include/net/llc_c_ac.h
76278@@ -87,7 +87,7 @@
76279 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
76280 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
76281
76282-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
76283+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
76284
76285 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
76286 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
76287diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
76288index 6ca3113..f8026dd 100644
76289--- a/include/net/llc_c_ev.h
76290+++ b/include/net/llc_c_ev.h
76291@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
76292 return (struct llc_conn_state_ev *)skb->cb;
76293 }
76294
76295-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
76296-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
76297+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
76298+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
76299
76300 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
76301 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
76302diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
76303index 0e79cfb..f46db31 100644
76304--- a/include/net/llc_c_st.h
76305+++ b/include/net/llc_c_st.h
76306@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
76307 u8 next_state;
76308 llc_conn_ev_qfyr_t *ev_qualifiers;
76309 llc_conn_action_t *ev_actions;
76310-};
76311+} __do_const;
76312
76313 struct llc_conn_state {
76314 u8 current_state;
76315diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
76316index 37a3bbd..55a4241 100644
76317--- a/include/net/llc_s_ac.h
76318+++ b/include/net/llc_s_ac.h
76319@@ -23,7 +23,7 @@
76320 #define SAP_ACT_TEST_IND 9
76321
76322 /* All action functions must look like this */
76323-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
76324+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
76325
76326 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
76327 struct sk_buff *skb);
76328diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
76329index 567c681..cd73ac0 100644
76330--- a/include/net/llc_s_st.h
76331+++ b/include/net/llc_s_st.h
76332@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
76333 llc_sap_ev_t ev;
76334 u8 next_state;
76335 llc_sap_action_t *ev_actions;
76336-};
76337+} __do_const;
76338
76339 struct llc_sap_state {
76340 u8 curr_state;
76341diff --git a/include/net/mac80211.h b/include/net/mac80211.h
76342index 885898a..cdace34 100644
76343--- a/include/net/mac80211.h
76344+++ b/include/net/mac80211.h
76345@@ -4205,7 +4205,7 @@ struct rate_control_ops {
76346 void (*add_sta_debugfs)(void *priv, void *priv_sta,
76347 struct dentry *dir);
76348 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
76349-};
76350+} __do_const;
76351
76352 static inline int rate_supported(struct ieee80211_sta *sta,
76353 enum ieee80211_band band,
76354diff --git a/include/net/neighbour.h b/include/net/neighbour.h
76355index 7e748ad..5c6229b 100644
76356--- a/include/net/neighbour.h
76357+++ b/include/net/neighbour.h
76358@@ -123,7 +123,7 @@ struct neigh_ops {
76359 void (*error_report)(struct neighbour *, struct sk_buff *);
76360 int (*output)(struct neighbour *, struct sk_buff *);
76361 int (*connected_output)(struct neighbour *, struct sk_buff *);
76362-};
76363+} __do_const;
76364
76365 struct pneigh_entry {
76366 struct pneigh_entry *next;
76367diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
76368index b176978..ea169f4 100644
76369--- a/include/net/net_namespace.h
76370+++ b/include/net/net_namespace.h
76371@@ -117,7 +117,7 @@ struct net {
76372 #endif
76373 struct netns_ipvs *ipvs;
76374 struct sock *diag_nlsk;
76375- atomic_t rt_genid;
76376+ atomic_unchecked_t rt_genid;
76377 };
76378
76379 /*
76380@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
76381 #define __net_init __init
76382 #define __net_exit __exit_refok
76383 #define __net_initdata __initdata
76384+#ifdef CONSTIFY_PLUGIN
76385 #define __net_initconst __initconst
76386+#else
76387+#define __net_initconst __initdata
76388+#endif
76389 #endif
76390
76391 struct pernet_operations {
76392@@ -284,7 +288,7 @@ struct pernet_operations {
76393 void (*exit_batch)(struct list_head *net_exit_list);
76394 int *id;
76395 size_t size;
76396-};
76397+} __do_const;
76398
76399 /*
76400 * Use these carefully. If you implement a network device and it
76401@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
76402
76403 static inline int rt_genid(struct net *net)
76404 {
76405- return atomic_read(&net->rt_genid);
76406+ return atomic_read_unchecked(&net->rt_genid);
76407 }
76408
76409 static inline void rt_genid_bump(struct net *net)
76410 {
76411- atomic_inc(&net->rt_genid);
76412+ atomic_inc_unchecked(&net->rt_genid);
76413 }
76414
76415 #endif /* __NET_NET_NAMESPACE_H */
76416diff --git a/include/net/netdma.h b/include/net/netdma.h
76417index 8ba8ce2..99b7fff 100644
76418--- a/include/net/netdma.h
76419+++ b/include/net/netdma.h
76420@@ -24,7 +24,7 @@
76421 #include <linux/dmaengine.h>
76422 #include <linux/skbuff.h>
76423
76424-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
76425+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
76426 struct sk_buff *skb, int offset, struct iovec *to,
76427 size_t len, struct dma_pinned_list *pinned_list);
76428
76429diff --git a/include/net/netlink.h b/include/net/netlink.h
76430index 9690b0f..87aded7 100644
76431--- a/include/net/netlink.h
76432+++ b/include/net/netlink.h
76433@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
76434 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
76435 {
76436 if (mark)
76437- skb_trim(skb, (unsigned char *) mark - skb->data);
76438+ skb_trim(skb, (const unsigned char *) mark - skb->data);
76439 }
76440
76441 /**
76442diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
76443index c9c0c53..53f24c3 100644
76444--- a/include/net/netns/conntrack.h
76445+++ b/include/net/netns/conntrack.h
76446@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
76447 struct nf_proto_net {
76448 #ifdef CONFIG_SYSCTL
76449 struct ctl_table_header *ctl_table_header;
76450- struct ctl_table *ctl_table;
76451+ ctl_table_no_const *ctl_table;
76452 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
76453 struct ctl_table_header *ctl_compat_header;
76454- struct ctl_table *ctl_compat_table;
76455+ ctl_table_no_const *ctl_compat_table;
76456 #endif
76457 #endif
76458 unsigned int users;
76459@@ -58,7 +58,7 @@ struct nf_ip_net {
76460 struct nf_icmp_net icmpv6;
76461 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
76462 struct ctl_table_header *ctl_table_header;
76463- struct ctl_table *ctl_table;
76464+ ctl_table_no_const *ctl_table;
76465 #endif
76466 };
76467
76468diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
76469index 2ba9de8..47bd6c7 100644
76470--- a/include/net/netns/ipv4.h
76471+++ b/include/net/netns/ipv4.h
76472@@ -67,7 +67,7 @@ struct netns_ipv4 {
76473 kgid_t sysctl_ping_group_range[2];
76474 long sysctl_tcp_mem[3];
76475
76476- atomic_t dev_addr_genid;
76477+ atomic_unchecked_t dev_addr_genid;
76478
76479 #ifdef CONFIG_IP_MROUTE
76480 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
76481diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
76482index 005e2c2..023d340 100644
76483--- a/include/net/netns/ipv6.h
76484+++ b/include/net/netns/ipv6.h
76485@@ -71,7 +71,7 @@ struct netns_ipv6 {
76486 struct fib_rules_ops *mr6_rules_ops;
76487 #endif
76488 #endif
76489- atomic_t dev_addr_genid;
76490+ atomic_unchecked_t dev_addr_genid;
76491 };
76492
76493 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
76494diff --git a/include/net/protocol.h b/include/net/protocol.h
76495index 047c047..b9dad15 100644
76496--- a/include/net/protocol.h
76497+++ b/include/net/protocol.h
76498@@ -44,7 +44,7 @@ struct net_protocol {
76499 void (*err_handler)(struct sk_buff *skb, u32 info);
76500 unsigned int no_policy:1,
76501 netns_ok:1;
76502-};
76503+} __do_const;
76504
76505 #if IS_ENABLED(CONFIG_IPV6)
76506 struct inet6_protocol {
76507@@ -57,7 +57,7 @@ struct inet6_protocol {
76508 u8 type, u8 code, int offset,
76509 __be32 info);
76510 unsigned int flags; /* INET6_PROTO_xxx */
76511-};
76512+} __do_const;
76513
76514 #define INET6_PROTO_NOPOLICY 0x1
76515 #define INET6_PROTO_FINAL 0x2
76516diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
76517index 7026648..584cc8c 100644
76518--- a/include/net/rtnetlink.h
76519+++ b/include/net/rtnetlink.h
76520@@ -81,7 +81,7 @@ struct rtnl_link_ops {
76521 const struct net_device *dev);
76522 unsigned int (*get_num_tx_queues)(void);
76523 unsigned int (*get_num_rx_queues)(void);
76524-};
76525+} __do_const;
76526
76527 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
76528 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
76529diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
76530index cd89510..d67810f 100644
76531--- a/include/net/sctp/sctp.h
76532+++ b/include/net/sctp/sctp.h
76533@@ -330,9 +330,9 @@ do { \
76534
76535 #else /* SCTP_DEBUG */
76536
76537-#define SCTP_DEBUG_PRINTK(whatever...)
76538-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
76539-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
76540+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
76541+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
76542+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
76543 #define SCTP_ENABLE_DEBUG
76544 #define SCTP_DISABLE_DEBUG
76545 #define SCTP_ASSERT(expr, str, func)
76546diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
76547index 2a82d13..62a31c2 100644
76548--- a/include/net/sctp/sm.h
76549+++ b/include/net/sctp/sm.h
76550@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
76551 typedef struct {
76552 sctp_state_fn_t *fn;
76553 const char *name;
76554-} sctp_sm_table_entry_t;
76555+} __do_const sctp_sm_table_entry_t;
76556
76557 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
76558 * currently in use.
76559@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
76560 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
76561
76562 /* Extern declarations for major data structures. */
76563-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
76564+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
76565
76566
76567 /* Get the size of a DATA chunk payload. */
76568diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
76569index 1bd4c41..9250b5b 100644
76570--- a/include/net/sctp/structs.h
76571+++ b/include/net/sctp/structs.h
76572@@ -516,7 +516,7 @@ struct sctp_pf {
76573 struct sctp_association *asoc);
76574 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
76575 struct sctp_af *af;
76576-};
76577+} __do_const;
76578
76579
76580 /* Structure to track chunk fragments that have been acked, but peer
76581diff --git a/include/net/sock.h b/include/net/sock.h
76582index 66772cf..25bc45b 100644
76583--- a/include/net/sock.h
76584+++ b/include/net/sock.h
76585@@ -325,7 +325,7 @@ struct sock {
76586 #ifdef CONFIG_RPS
76587 __u32 sk_rxhash;
76588 #endif
76589- atomic_t sk_drops;
76590+ atomic_unchecked_t sk_drops;
76591 int sk_rcvbuf;
76592
76593 struct sk_filter __rcu *sk_filter;
76594@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
76595 }
76596
76597 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
76598- char __user *from, char *to,
76599+ char __user *from, unsigned char *to,
76600 int copy, int offset)
76601 {
76602 if (skb->ip_summed == CHECKSUM_NONE) {
76603@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
76604 }
76605 }
76606
76607-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
76608+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
76609
76610 /**
76611 * sk_page_frag - return an appropriate page_frag
76612diff --git a/include/net/tcp.h b/include/net/tcp.h
76613index 5bba80f..8520a82 100644
76614--- a/include/net/tcp.h
76615+++ b/include/net/tcp.h
76616@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
76617 extern void tcp_xmit_retransmit_queue(struct sock *);
76618 extern void tcp_simple_retransmit(struct sock *);
76619 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
76620-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
76621+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
76622
76623 extern void tcp_send_probe0(struct sock *);
76624 extern void tcp_send_partial(struct sock *);
76625@@ -697,8 +697,8 @@ struct tcp_skb_cb {
76626 struct inet6_skb_parm h6;
76627 #endif
76628 } header; /* For incoming frames */
76629- __u32 seq; /* Starting sequence number */
76630- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
76631+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
76632+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
76633 __u32 when; /* used to compute rtt's */
76634 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
76635
76636@@ -712,7 +712,7 @@ struct tcp_skb_cb {
76637
76638 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
76639 /* 1 byte hole */
76640- __u32 ack_seq; /* Sequence number ACK'd */
76641+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
76642 };
76643
76644 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
76645diff --git a/include/net/xfrm.h b/include/net/xfrm.h
76646index 94ce082..62b278d 100644
76647--- a/include/net/xfrm.h
76648+++ b/include/net/xfrm.h
76649@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
76650 struct net_device *dev,
76651 const struct flowi *fl);
76652 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
76653-};
76654+} __do_const;
76655
76656 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
76657 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
76658@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
76659 struct sk_buff *skb);
76660 int (*transport_finish)(struct sk_buff *skb,
76661 int async);
76662-};
76663+} __do_const;
76664
76665 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
76666 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
76667@@ -424,7 +424,7 @@ struct xfrm_mode {
76668 struct module *owner;
76669 unsigned int encap;
76670 int flags;
76671-};
76672+} __do_const;
76673
76674 /* Flags for xfrm_mode. */
76675 enum {
76676@@ -521,7 +521,7 @@ struct xfrm_policy {
76677 struct timer_list timer;
76678
76679 struct flow_cache_object flo;
76680- atomic_t genid;
76681+ atomic_unchecked_t genid;
76682 u32 priority;
76683 u32 index;
76684 struct xfrm_mark mark;
76685diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
76686index 1a046b1..ee0bef0 100644
76687--- a/include/rdma/iw_cm.h
76688+++ b/include/rdma/iw_cm.h
76689@@ -122,7 +122,7 @@ struct iw_cm_verbs {
76690 int backlog);
76691
76692 int (*destroy_listen)(struct iw_cm_id *cm_id);
76693-};
76694+} __no_const;
76695
76696 /**
76697 * iw_create_cm_id - Create an IW CM identifier.
76698diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
76699index e1379b4..67eafbe 100644
76700--- a/include/scsi/libfc.h
76701+++ b/include/scsi/libfc.h
76702@@ -762,6 +762,7 @@ struct libfc_function_template {
76703 */
76704 void (*disc_stop_final) (struct fc_lport *);
76705 };
76706+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
76707
76708 /**
76709 * struct fc_disc - Discovery context
76710@@ -866,7 +867,7 @@ struct fc_lport {
76711 struct fc_vport *vport;
76712
76713 /* Operational Information */
76714- struct libfc_function_template tt;
76715+ libfc_function_template_no_const tt;
76716 u8 link_up;
76717 u8 qfull;
76718 enum fc_lport_state state;
76719diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
76720index cc64587..608f523 100644
76721--- a/include/scsi/scsi_device.h
76722+++ b/include/scsi/scsi_device.h
76723@@ -171,9 +171,9 @@ struct scsi_device {
76724 unsigned int max_device_blocked; /* what device_blocked counts down from */
76725 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
76726
76727- atomic_t iorequest_cnt;
76728- atomic_t iodone_cnt;
76729- atomic_t ioerr_cnt;
76730+ atomic_unchecked_t iorequest_cnt;
76731+ atomic_unchecked_t iodone_cnt;
76732+ atomic_unchecked_t ioerr_cnt;
76733
76734 struct device sdev_gendev,
76735 sdev_dev;
76736diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
76737index b797e8f..8e2c3aa 100644
76738--- a/include/scsi/scsi_transport_fc.h
76739+++ b/include/scsi/scsi_transport_fc.h
76740@@ -751,7 +751,8 @@ struct fc_function_template {
76741 unsigned long show_host_system_hostname:1;
76742
76743 unsigned long disable_target_scan:1;
76744-};
76745+} __do_const;
76746+typedef struct fc_function_template __no_const fc_function_template_no_const;
76747
76748
76749 /**
76750diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
76751index 9031a26..750d592 100644
76752--- a/include/sound/compress_driver.h
76753+++ b/include/sound/compress_driver.h
76754@@ -128,7 +128,7 @@ struct snd_compr_ops {
76755 struct snd_compr_caps *caps);
76756 int (*get_codec_caps) (struct snd_compr_stream *stream,
76757 struct snd_compr_codec_caps *codec);
76758-};
76759+} __no_const;
76760
76761 /**
76762 * struct snd_compr: Compressed device
76763diff --git a/include/sound/soc.h b/include/sound/soc.h
76764index 85c1522..f44bad1 100644
76765--- a/include/sound/soc.h
76766+++ b/include/sound/soc.h
76767@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
76768 /* probe ordering - for components with runtime dependencies */
76769 int probe_order;
76770 int remove_order;
76771-};
76772+} __do_const;
76773
76774 /* SoC platform interface */
76775 struct snd_soc_platform_driver {
76776@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
76777 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
76778 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
76779 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
76780-};
76781+} __do_const;
76782
76783 struct snd_soc_platform {
76784 const char *name;
76785diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
76786index 4ea4f98..a63629b 100644
76787--- a/include/target/target_core_base.h
76788+++ b/include/target/target_core_base.h
76789@@ -653,7 +653,7 @@ struct se_device {
76790 spinlock_t stats_lock;
76791 /* Active commands on this virtual SE device */
76792 atomic_t simple_cmds;
76793- atomic_t dev_ordered_id;
76794+ atomic_unchecked_t dev_ordered_id;
76795 atomic_t dev_ordered_sync;
76796 atomic_t dev_qf_count;
76797 int export_count;
76798diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
76799new file mode 100644
76800index 0000000..fb634b7
76801--- /dev/null
76802+++ b/include/trace/events/fs.h
76803@@ -0,0 +1,53 @@
76804+#undef TRACE_SYSTEM
76805+#define TRACE_SYSTEM fs
76806+
76807+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
76808+#define _TRACE_FS_H
76809+
76810+#include <linux/fs.h>
76811+#include <linux/tracepoint.h>
76812+
76813+TRACE_EVENT(do_sys_open,
76814+
76815+ TP_PROTO(const char *filename, int flags, int mode),
76816+
76817+ TP_ARGS(filename, flags, mode),
76818+
76819+ TP_STRUCT__entry(
76820+ __string( filename, filename )
76821+ __field( int, flags )
76822+ __field( int, mode )
76823+ ),
76824+
76825+ TP_fast_assign(
76826+ __assign_str(filename, filename);
76827+ __entry->flags = flags;
76828+ __entry->mode = mode;
76829+ ),
76830+
76831+ TP_printk("\"%s\" %x %o",
76832+ __get_str(filename), __entry->flags, __entry->mode)
76833+);
76834+
76835+TRACE_EVENT(open_exec,
76836+
76837+ TP_PROTO(const char *filename),
76838+
76839+ TP_ARGS(filename),
76840+
76841+ TP_STRUCT__entry(
76842+ __string( filename, filename )
76843+ ),
76844+
76845+ TP_fast_assign(
76846+ __assign_str(filename, filename);
76847+ ),
76848+
76849+ TP_printk("\"%s\"",
76850+ __get_str(filename))
76851+);
76852+
76853+#endif /* _TRACE_FS_H */
76854+
76855+/* This part must be outside protection */
76856+#include <trace/define_trace.h>
76857diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
76858index 1c09820..7f5ec79 100644
76859--- a/include/trace/events/irq.h
76860+++ b/include/trace/events/irq.h
76861@@ -36,7 +36,7 @@ struct softirq_action;
76862 */
76863 TRACE_EVENT(irq_handler_entry,
76864
76865- TP_PROTO(int irq, struct irqaction *action),
76866+ TP_PROTO(int irq, const struct irqaction *action),
76867
76868 TP_ARGS(irq, action),
76869
76870@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
76871 */
76872 TRACE_EVENT(irq_handler_exit,
76873
76874- TP_PROTO(int irq, struct irqaction *action, int ret),
76875+ TP_PROTO(int irq, const struct irqaction *action, int ret),
76876
76877 TP_ARGS(irq, action, ret),
76878
76879diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
76880index 7caf44c..23c6f27 100644
76881--- a/include/uapi/linux/a.out.h
76882+++ b/include/uapi/linux/a.out.h
76883@@ -39,6 +39,14 @@ enum machine_type {
76884 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
76885 };
76886
76887+/* Constants for the N_FLAGS field */
76888+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
76889+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
76890+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
76891+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
76892+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
76893+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
76894+
76895 #if !defined (N_MAGIC)
76896 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
76897 #endif
76898diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
76899index d876736..ccce5c0 100644
76900--- a/include/uapi/linux/byteorder/little_endian.h
76901+++ b/include/uapi/linux/byteorder/little_endian.h
76902@@ -42,51 +42,51 @@
76903
76904 static inline __le64 __cpu_to_le64p(const __u64 *p)
76905 {
76906- return (__force __le64)*p;
76907+ return (__force const __le64)*p;
76908 }
76909-static inline __u64 __le64_to_cpup(const __le64 *p)
76910+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
76911 {
76912- return (__force __u64)*p;
76913+ return (__force const __u64)*p;
76914 }
76915 static inline __le32 __cpu_to_le32p(const __u32 *p)
76916 {
76917- return (__force __le32)*p;
76918+ return (__force const __le32)*p;
76919 }
76920 static inline __u32 __le32_to_cpup(const __le32 *p)
76921 {
76922- return (__force __u32)*p;
76923+ return (__force const __u32)*p;
76924 }
76925 static inline __le16 __cpu_to_le16p(const __u16 *p)
76926 {
76927- return (__force __le16)*p;
76928+ return (__force const __le16)*p;
76929 }
76930 static inline __u16 __le16_to_cpup(const __le16 *p)
76931 {
76932- return (__force __u16)*p;
76933+ return (__force const __u16)*p;
76934 }
76935 static inline __be64 __cpu_to_be64p(const __u64 *p)
76936 {
76937- return (__force __be64)__swab64p(p);
76938+ return (__force const __be64)__swab64p(p);
76939 }
76940 static inline __u64 __be64_to_cpup(const __be64 *p)
76941 {
76942- return __swab64p((__u64 *)p);
76943+ return __swab64p((const __u64 *)p);
76944 }
76945 static inline __be32 __cpu_to_be32p(const __u32 *p)
76946 {
76947- return (__force __be32)__swab32p(p);
76948+ return (__force const __be32)__swab32p(p);
76949 }
76950-static inline __u32 __be32_to_cpup(const __be32 *p)
76951+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
76952 {
76953- return __swab32p((__u32 *)p);
76954+ return __swab32p((const __u32 *)p);
76955 }
76956 static inline __be16 __cpu_to_be16p(const __u16 *p)
76957 {
76958- return (__force __be16)__swab16p(p);
76959+ return (__force const __be16)__swab16p(p);
76960 }
76961 static inline __u16 __be16_to_cpup(const __be16 *p)
76962 {
76963- return __swab16p((__u16 *)p);
76964+ return __swab16p((const __u16 *)p);
76965 }
76966 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
76967 #define __le64_to_cpus(x) do { (void)(x); } while (0)
76968diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
76969index ef6103b..d4e65dd 100644
76970--- a/include/uapi/linux/elf.h
76971+++ b/include/uapi/linux/elf.h
76972@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
76973 #define PT_GNU_EH_FRAME 0x6474e550
76974
76975 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
76976+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
76977+
76978+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
76979+
76980+/* Constants for the e_flags field */
76981+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
76982+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
76983+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
76984+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
76985+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
76986+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
76987
76988 /*
76989 * Extended Numbering
76990@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
76991 #define DT_DEBUG 21
76992 #define DT_TEXTREL 22
76993 #define DT_JMPREL 23
76994+#define DT_FLAGS 30
76995+ #define DF_TEXTREL 0x00000004
76996 #define DT_ENCODING 32
76997 #define OLD_DT_LOOS 0x60000000
76998 #define DT_LOOS 0x6000000d
76999@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
77000 #define PF_W 0x2
77001 #define PF_X 0x1
77002
77003+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
77004+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
77005+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
77006+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
77007+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
77008+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
77009+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
77010+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
77011+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
77012+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
77013+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
77014+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
77015+
77016 typedef struct elf32_phdr{
77017 Elf32_Word p_type;
77018 Elf32_Off p_offset;
77019@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
77020 #define EI_OSABI 7
77021 #define EI_PAD 8
77022
77023+#define EI_PAX 14
77024+
77025 #define ELFMAG0 0x7f /* EI_MAG */
77026 #define ELFMAG1 'E'
77027 #define ELFMAG2 'L'
77028diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
77029index aa169c4..6a2771d 100644
77030--- a/include/uapi/linux/personality.h
77031+++ b/include/uapi/linux/personality.h
77032@@ -30,6 +30,7 @@ enum {
77033 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
77034 ADDR_NO_RANDOMIZE | \
77035 ADDR_COMPAT_LAYOUT | \
77036+ ADDR_LIMIT_3GB | \
77037 MMAP_PAGE_ZERO)
77038
77039 /*
77040diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
77041index 7530e74..e714828 100644
77042--- a/include/uapi/linux/screen_info.h
77043+++ b/include/uapi/linux/screen_info.h
77044@@ -43,7 +43,8 @@ struct screen_info {
77045 __u16 pages; /* 0x32 */
77046 __u16 vesa_attributes; /* 0x34 */
77047 __u32 capabilities; /* 0x36 */
77048- __u8 _reserved[6]; /* 0x3a */
77049+ __u16 vesapm_size; /* 0x3a */
77050+ __u8 _reserved[4]; /* 0x3c */
77051 } __attribute__((packed));
77052
77053 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
77054diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
77055index 0e011eb..82681b1 100644
77056--- a/include/uapi/linux/swab.h
77057+++ b/include/uapi/linux/swab.h
77058@@ -43,7 +43,7 @@
77059 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
77060 */
77061
77062-static inline __attribute_const__ __u16 __fswab16(__u16 val)
77063+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
77064 {
77065 #ifdef __HAVE_BUILTIN_BSWAP16__
77066 return __builtin_bswap16(val);
77067@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
77068 #endif
77069 }
77070
77071-static inline __attribute_const__ __u32 __fswab32(__u32 val)
77072+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
77073 {
77074 #ifdef __HAVE_BUILTIN_BSWAP32__
77075 return __builtin_bswap32(val);
77076@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
77077 #endif
77078 }
77079
77080-static inline __attribute_const__ __u64 __fswab64(__u64 val)
77081+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
77082 {
77083 #ifdef __HAVE_BUILTIN_BSWAP64__
77084 return __builtin_bswap64(val);
77085diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
77086index 6d67213..8dab561 100644
77087--- a/include/uapi/linux/sysctl.h
77088+++ b/include/uapi/linux/sysctl.h
77089@@ -155,7 +155,11 @@ enum
77090 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
77091 };
77092
77093-
77094+#ifdef CONFIG_PAX_SOFTMODE
77095+enum {
77096+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
77097+};
77098+#endif
77099
77100 /* CTL_VM names: */
77101 enum
77102diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
77103index e4629b9..6958086 100644
77104--- a/include/uapi/linux/xattr.h
77105+++ b/include/uapi/linux/xattr.h
77106@@ -63,5 +63,9 @@
77107 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
77108 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
77109
77110+/* User namespace */
77111+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
77112+#define XATTR_PAX_FLAGS_SUFFIX "flags"
77113+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
77114
77115 #endif /* _UAPI_LINUX_XATTR_H */
77116diff --git a/include/video/udlfb.h b/include/video/udlfb.h
77117index f9466fa..f4e2b81 100644
77118--- a/include/video/udlfb.h
77119+++ b/include/video/udlfb.h
77120@@ -53,10 +53,10 @@ struct dlfb_data {
77121 u32 pseudo_palette[256];
77122 int blank_mode; /*one of FB_BLANK_ */
77123 /* blit-only rendering path metrics, exposed through sysfs */
77124- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
77125- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
77126- atomic_t bytes_sent; /* to usb, after compression including overhead */
77127- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
77128+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
77129+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
77130+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
77131+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
77132 };
77133
77134 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
77135diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
77136index 1a91850..28573f8 100644
77137--- a/include/video/uvesafb.h
77138+++ b/include/video/uvesafb.h
77139@@ -122,6 +122,7 @@ struct uvesafb_par {
77140 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
77141 u8 pmi_setpal; /* PMI for palette changes */
77142 u16 *pmi_base; /* protected mode interface location */
77143+ u8 *pmi_code; /* protected mode code location */
77144 void *pmi_start;
77145 void *pmi_pal;
77146 u8 *vbe_state_orig; /*
77147diff --git a/init/Kconfig b/init/Kconfig
77148index 2d9b831..ae4c8ac 100644
77149--- a/init/Kconfig
77150+++ b/init/Kconfig
77151@@ -1029,6 +1029,7 @@ endif # CGROUPS
77152
77153 config CHECKPOINT_RESTORE
77154 bool "Checkpoint/restore support" if EXPERT
77155+ depends on !GRKERNSEC
77156 default n
77157 help
77158 Enables additional kernel features in a sake of checkpoint/restore.
77159@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
77160
77161 config COMPAT_BRK
77162 bool "Disable heap randomization"
77163- default y
77164+ default n
77165 help
77166 Randomizing heap placement makes heap exploits harder, but it
77167 also breaks ancient binaries (including anything libc5 based).
77168@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
77169 config STOP_MACHINE
77170 bool
77171 default y
77172- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
77173+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
77174 help
77175 Need stop_machine() primitive.
77176
77177diff --git a/init/Makefile b/init/Makefile
77178index 7bc47ee..6da2dc7 100644
77179--- a/init/Makefile
77180+++ b/init/Makefile
77181@@ -2,6 +2,9 @@
77182 # Makefile for the linux kernel.
77183 #
77184
77185+ccflags-y := $(GCC_PLUGINS_CFLAGS)
77186+asflags-y := $(GCC_PLUGINS_AFLAGS)
77187+
77188 obj-y := main.o version.o mounts.o
77189 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
77190 obj-y += noinitramfs.o
77191diff --git a/init/do_mounts.c b/init/do_mounts.c
77192index a2b49f2..03a0e17c 100644
77193--- a/init/do_mounts.c
77194+++ b/init/do_mounts.c
77195@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
77196 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
77197 {
77198 struct super_block *s;
77199- int err = sys_mount(name, "/root", fs, flags, data);
77200+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
77201 if (err)
77202 return err;
77203
77204- sys_chdir("/root");
77205+ sys_chdir((const char __force_user *)"/root");
77206 s = current->fs->pwd.dentry->d_sb;
77207 ROOT_DEV = s->s_dev;
77208 printk(KERN_INFO
77209@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
77210 va_start(args, fmt);
77211 vsprintf(buf, fmt, args);
77212 va_end(args);
77213- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
77214+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
77215 if (fd >= 0) {
77216 sys_ioctl(fd, FDEJECT, 0);
77217 sys_close(fd);
77218 }
77219 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
77220- fd = sys_open("/dev/console", O_RDWR, 0);
77221+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
77222 if (fd >= 0) {
77223 sys_ioctl(fd, TCGETS, (long)&termios);
77224 termios.c_lflag &= ~ICANON;
77225 sys_ioctl(fd, TCSETSF, (long)&termios);
77226- sys_read(fd, &c, 1);
77227+ sys_read(fd, (char __user *)&c, 1);
77228 termios.c_lflag |= ICANON;
77229 sys_ioctl(fd, TCSETSF, (long)&termios);
77230 sys_close(fd);
77231@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
77232 mount_root();
77233 out:
77234 devtmpfs_mount("dev");
77235- sys_mount(".", "/", NULL, MS_MOVE, NULL);
77236- sys_chroot(".");
77237+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
77238+ sys_chroot((const char __force_user *)".");
77239 }
77240diff --git a/init/do_mounts.h b/init/do_mounts.h
77241index f5b978a..69dbfe8 100644
77242--- a/init/do_mounts.h
77243+++ b/init/do_mounts.h
77244@@ -15,15 +15,15 @@ extern int root_mountflags;
77245
77246 static inline int create_dev(char *name, dev_t dev)
77247 {
77248- sys_unlink(name);
77249- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
77250+ sys_unlink((char __force_user *)name);
77251+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
77252 }
77253
77254 #if BITS_PER_LONG == 32
77255 static inline u32 bstat(char *name)
77256 {
77257 struct stat64 stat;
77258- if (sys_stat64(name, &stat) != 0)
77259+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
77260 return 0;
77261 if (!S_ISBLK(stat.st_mode))
77262 return 0;
77263@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
77264 static inline u32 bstat(char *name)
77265 {
77266 struct stat stat;
77267- if (sys_newstat(name, &stat) != 0)
77268+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
77269 return 0;
77270 if (!S_ISBLK(stat.st_mode))
77271 return 0;
77272diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
77273index 3e0878e..8a9d7a0 100644
77274--- a/init/do_mounts_initrd.c
77275+++ b/init/do_mounts_initrd.c
77276@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
77277 {
77278 sys_unshare(CLONE_FS | CLONE_FILES);
77279 /* stdin/stdout/stderr for /linuxrc */
77280- sys_open("/dev/console", O_RDWR, 0);
77281+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
77282 sys_dup(0);
77283 sys_dup(0);
77284 /* move initrd over / and chdir/chroot in initrd root */
77285- sys_chdir("/root");
77286- sys_mount(".", "/", NULL, MS_MOVE, NULL);
77287- sys_chroot(".");
77288+ sys_chdir((const char __force_user *)"/root");
77289+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
77290+ sys_chroot((const char __force_user *)".");
77291 sys_setsid();
77292 return 0;
77293 }
77294@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
77295 create_dev("/dev/root.old", Root_RAM0);
77296 /* mount initrd on rootfs' /root */
77297 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
77298- sys_mkdir("/old", 0700);
77299- sys_chdir("/old");
77300+ sys_mkdir((const char __force_user *)"/old", 0700);
77301+ sys_chdir((const char __force_user *)"/old");
77302
77303 /* try loading default modules from initrd */
77304 load_default_modules();
77305@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
77306 current->flags &= ~PF_FREEZER_SKIP;
77307
77308 /* move initrd to rootfs' /old */
77309- sys_mount("..", ".", NULL, MS_MOVE, NULL);
77310+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
77311 /* switch root and cwd back to / of rootfs */
77312- sys_chroot("..");
77313+ sys_chroot((const char __force_user *)"..");
77314
77315 if (new_decode_dev(real_root_dev) == Root_RAM0) {
77316- sys_chdir("/old");
77317+ sys_chdir((const char __force_user *)"/old");
77318 return;
77319 }
77320
77321- sys_chdir("/");
77322+ sys_chdir((const char __force_user *)"/");
77323 ROOT_DEV = new_decode_dev(real_root_dev);
77324 mount_root();
77325
77326 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
77327- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
77328+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
77329 if (!error)
77330 printk("okay\n");
77331 else {
77332- int fd = sys_open("/dev/root.old", O_RDWR, 0);
77333+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
77334 if (error == -ENOENT)
77335 printk("/initrd does not exist. Ignored.\n");
77336 else
77337 printk("failed\n");
77338 printk(KERN_NOTICE "Unmounting old root\n");
77339- sys_umount("/old", MNT_DETACH);
77340+ sys_umount((char __force_user *)"/old", MNT_DETACH);
77341 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
77342 if (fd < 0) {
77343 error = fd;
77344@@ -127,11 +127,11 @@ int __init initrd_load(void)
77345 * mounted in the normal path.
77346 */
77347 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
77348- sys_unlink("/initrd.image");
77349+ sys_unlink((const char __force_user *)"/initrd.image");
77350 handle_initrd();
77351 return 1;
77352 }
77353 }
77354- sys_unlink("/initrd.image");
77355+ sys_unlink((const char __force_user *)"/initrd.image");
77356 return 0;
77357 }
77358diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
77359index 8cb6db5..d729f50 100644
77360--- a/init/do_mounts_md.c
77361+++ b/init/do_mounts_md.c
77362@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
77363 partitioned ? "_d" : "", minor,
77364 md_setup_args[ent].device_names);
77365
77366- fd = sys_open(name, 0, 0);
77367+ fd = sys_open((char __force_user *)name, 0, 0);
77368 if (fd < 0) {
77369 printk(KERN_ERR "md: open failed - cannot start "
77370 "array %s\n", name);
77371@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
77372 * array without it
77373 */
77374 sys_close(fd);
77375- fd = sys_open(name, 0, 0);
77376+ fd = sys_open((char __force_user *)name, 0, 0);
77377 sys_ioctl(fd, BLKRRPART, 0);
77378 }
77379 sys_close(fd);
77380@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
77381
77382 wait_for_device_probe();
77383
77384- fd = sys_open("/dev/md0", 0, 0);
77385+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
77386 if (fd >= 0) {
77387 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
77388 sys_close(fd);
77389diff --git a/init/init_task.c b/init/init_task.c
77390index ba0a7f36..2bcf1d5 100644
77391--- a/init/init_task.c
77392+++ b/init/init_task.c
77393@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
77394 * Initial thread structure. Alignment of this is handled by a special
77395 * linker map entry.
77396 */
77397+#ifdef CONFIG_X86
77398+union thread_union init_thread_union __init_task_data;
77399+#else
77400 union thread_union init_thread_union __init_task_data =
77401 { INIT_THREAD_INFO(init_task) };
77402+#endif
77403diff --git a/init/initramfs.c b/init/initramfs.c
77404index a67ef9d..2d17ed9 100644
77405--- a/init/initramfs.c
77406+++ b/init/initramfs.c
77407@@ -84,7 +84,7 @@ static void __init free_hash(void)
77408 }
77409 }
77410
77411-static long __init do_utime(char *filename, time_t mtime)
77412+static long __init do_utime(char __force_user *filename, time_t mtime)
77413 {
77414 struct timespec t[2];
77415
77416@@ -119,7 +119,7 @@ static void __init dir_utime(void)
77417 struct dir_entry *de, *tmp;
77418 list_for_each_entry_safe(de, tmp, &dir_list, list) {
77419 list_del(&de->list);
77420- do_utime(de->name, de->mtime);
77421+ do_utime((char __force_user *)de->name, de->mtime);
77422 kfree(de->name);
77423 kfree(de);
77424 }
77425@@ -281,7 +281,7 @@ static int __init maybe_link(void)
77426 if (nlink >= 2) {
77427 char *old = find_link(major, minor, ino, mode, collected);
77428 if (old)
77429- return (sys_link(old, collected) < 0) ? -1 : 1;
77430+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
77431 }
77432 return 0;
77433 }
77434@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
77435 {
77436 struct stat st;
77437
77438- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
77439+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
77440 if (S_ISDIR(st.st_mode))
77441- sys_rmdir(path);
77442+ sys_rmdir((char __force_user *)path);
77443 else
77444- sys_unlink(path);
77445+ sys_unlink((char __force_user *)path);
77446 }
77447 }
77448
77449@@ -315,7 +315,7 @@ static int __init do_name(void)
77450 int openflags = O_WRONLY|O_CREAT;
77451 if (ml != 1)
77452 openflags |= O_TRUNC;
77453- wfd = sys_open(collected, openflags, mode);
77454+ wfd = sys_open((char __force_user *)collected, openflags, mode);
77455
77456 if (wfd >= 0) {
77457 sys_fchown(wfd, uid, gid);
77458@@ -327,17 +327,17 @@ static int __init do_name(void)
77459 }
77460 }
77461 } else if (S_ISDIR(mode)) {
77462- sys_mkdir(collected, mode);
77463- sys_chown(collected, uid, gid);
77464- sys_chmod(collected, mode);
77465+ sys_mkdir((char __force_user *)collected, mode);
77466+ sys_chown((char __force_user *)collected, uid, gid);
77467+ sys_chmod((char __force_user *)collected, mode);
77468 dir_add(collected, mtime);
77469 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
77470 S_ISFIFO(mode) || S_ISSOCK(mode)) {
77471 if (maybe_link() == 0) {
77472- sys_mknod(collected, mode, rdev);
77473- sys_chown(collected, uid, gid);
77474- sys_chmod(collected, mode);
77475- do_utime(collected, mtime);
77476+ sys_mknod((char __force_user *)collected, mode, rdev);
77477+ sys_chown((char __force_user *)collected, uid, gid);
77478+ sys_chmod((char __force_user *)collected, mode);
77479+ do_utime((char __force_user *)collected, mtime);
77480 }
77481 }
77482 return 0;
77483@@ -346,15 +346,15 @@ static int __init do_name(void)
77484 static int __init do_copy(void)
77485 {
77486 if (count >= body_len) {
77487- sys_write(wfd, victim, body_len);
77488+ sys_write(wfd, (char __force_user *)victim, body_len);
77489 sys_close(wfd);
77490- do_utime(vcollected, mtime);
77491+ do_utime((char __force_user *)vcollected, mtime);
77492 kfree(vcollected);
77493 eat(body_len);
77494 state = SkipIt;
77495 return 0;
77496 } else {
77497- sys_write(wfd, victim, count);
77498+ sys_write(wfd, (char __force_user *)victim, count);
77499 body_len -= count;
77500 eat(count);
77501 return 1;
77502@@ -365,9 +365,9 @@ static int __init do_symlink(void)
77503 {
77504 collected[N_ALIGN(name_len) + body_len] = '\0';
77505 clean_path(collected, 0);
77506- sys_symlink(collected + N_ALIGN(name_len), collected);
77507- sys_lchown(collected, uid, gid);
77508- do_utime(collected, mtime);
77509+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
77510+ sys_lchown((char __force_user *)collected, uid, gid);
77511+ do_utime((char __force_user *)collected, mtime);
77512 state = SkipIt;
77513 next_state = Reset;
77514 return 0;
77515@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
77516 {
77517 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
77518 if (err)
77519- panic(err); /* Failed to decompress INTERNAL initramfs */
77520+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
77521 if (initrd_start) {
77522 #ifdef CONFIG_BLK_DEV_RAM
77523 int fd;
77524diff --git a/init/main.c b/init/main.c
77525index 9484f4b..0eac7c3 100644
77526--- a/init/main.c
77527+++ b/init/main.c
77528@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
77529 extern void tc_init(void);
77530 #endif
77531
77532+extern void grsecurity_init(void);
77533+
77534 /*
77535 * Debug helper: via this flag we know that we are in 'early bootup code'
77536 * where only the boot processor is running with IRQ disabled. This means
77537@@ -153,6 +155,74 @@ static int __init set_reset_devices(char *str)
77538
77539 __setup("reset_devices", set_reset_devices);
77540
77541+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
77542+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
77543+static int __init setup_grsec_proc_gid(char *str)
77544+{
77545+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
77546+ return 1;
77547+}
77548+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
77549+#endif
77550+
77551+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
77552+unsigned long pax_user_shadow_base __read_only;
77553+EXPORT_SYMBOL(pax_user_shadow_base);
77554+extern char pax_enter_kernel_user[];
77555+extern char pax_exit_kernel_user[];
77556+#endif
77557+
77558+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
77559+static int __init setup_pax_nouderef(char *str)
77560+{
77561+#ifdef CONFIG_X86_32
77562+ unsigned int cpu;
77563+ struct desc_struct *gdt;
77564+
77565+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
77566+ gdt = get_cpu_gdt_table(cpu);
77567+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
77568+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
77569+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
77570+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
77571+ }
77572+ loadsegment(ds, __KERNEL_DS);
77573+ loadsegment(es, __KERNEL_DS);
77574+ loadsegment(ss, __KERNEL_DS);
77575+#else
77576+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
77577+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
77578+ clone_pgd_mask = ~(pgdval_t)0UL;
77579+ pax_user_shadow_base = 0UL;
77580+ setup_clear_cpu_cap(X86_FEATURE_PCID);
77581+#endif
77582+
77583+ return 0;
77584+}
77585+early_param("pax_nouderef", setup_pax_nouderef);
77586+
77587+#ifdef CONFIG_X86_64
77588+static int __init setup_pax_weakuderef(char *str)
77589+{
77590+ if (clone_pgd_mask != ~(pgdval_t)0UL)
77591+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
77592+ return 1;
77593+}
77594+__setup("pax_weakuderef", setup_pax_weakuderef);
77595+#endif
77596+#endif
77597+
77598+#ifdef CONFIG_PAX_SOFTMODE
77599+int pax_softmode;
77600+
77601+static int __init setup_pax_softmode(char *str)
77602+{
77603+ get_option(&str, &pax_softmode);
77604+ return 1;
77605+}
77606+__setup("pax_softmode=", setup_pax_softmode);
77607+#endif
77608+
77609 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
77610 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
77611 static const char *panic_later, *panic_param;
77612@@ -655,8 +725,6 @@ static void __init do_ctors(void)
77613 bool initcall_debug;
77614 core_param(initcall_debug, initcall_debug, bool, 0644);
77615
77616-static char msgbuf[64];
77617-
77618 static int __init_or_module do_one_initcall_debug(initcall_t fn)
77619 {
77620 ktime_t calltime, delta, rettime;
77621@@ -679,23 +747,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
77622 {
77623 int count = preempt_count();
77624 int ret;
77625+ const char *msg1 = "", *msg2 = "";
77626
77627 if (initcall_debug)
77628 ret = do_one_initcall_debug(fn);
77629 else
77630 ret = fn();
77631
77632- msgbuf[0] = 0;
77633-
77634 if (preempt_count() != count) {
77635- sprintf(msgbuf, "preemption imbalance ");
77636+ msg1 = " preemption imbalance";
77637 preempt_count() = count;
77638 }
77639 if (irqs_disabled()) {
77640- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
77641+ msg2 = " disabled interrupts";
77642 local_irq_enable();
77643 }
77644- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
77645+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
77646
77647 return ret;
77648 }
77649@@ -748,8 +815,14 @@ static void __init do_initcall_level(int level)
77650 level, level,
77651 &repair_env_string);
77652
77653- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
77654+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
77655 do_one_initcall(*fn);
77656+
77657+#ifdef LATENT_ENTROPY_PLUGIN
77658+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
77659+#endif
77660+
77661+ }
77662 }
77663
77664 static void __init do_initcalls(void)
77665@@ -783,8 +856,14 @@ static void __init do_pre_smp_initcalls(void)
77666 {
77667 initcall_t *fn;
77668
77669- for (fn = __initcall_start; fn < __initcall0_start; fn++)
77670+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
77671 do_one_initcall(*fn);
77672+
77673+#ifdef LATENT_ENTROPY_PLUGIN
77674+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
77675+#endif
77676+
77677+ }
77678 }
77679
77680 /*
77681@@ -802,8 +881,8 @@ static int run_init_process(const char *init_filename)
77682 {
77683 argv_init[0] = init_filename;
77684 return do_execve(init_filename,
77685- (const char __user *const __user *)argv_init,
77686- (const char __user *const __user *)envp_init);
77687+ (const char __user *const __force_user *)argv_init,
77688+ (const char __user *const __force_user *)envp_init);
77689 }
77690
77691 static noinline void __init kernel_init_freeable(void);
77692@@ -880,7 +959,7 @@ static noinline void __init kernel_init_freeable(void)
77693 do_basic_setup();
77694
77695 /* Open the /dev/console on the rootfs, this should never fail */
77696- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
77697+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
77698 pr_err("Warning: unable to open an initial console.\n");
77699
77700 (void) sys_dup(0);
77701@@ -893,11 +972,13 @@ static noinline void __init kernel_init_freeable(void)
77702 if (!ramdisk_execute_command)
77703 ramdisk_execute_command = "/init";
77704
77705- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
77706+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
77707 ramdisk_execute_command = NULL;
77708 prepare_namespace();
77709 }
77710
77711+ grsecurity_init();
77712+
77713 /*
77714 * Ok, we have completed the initial bootup, and
77715 * we're essentially up and running. Get rid of the
77716diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
77717index 130dfec..cc88451 100644
77718--- a/ipc/ipc_sysctl.c
77719+++ b/ipc/ipc_sysctl.c
77720@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
77721 static int proc_ipc_dointvec(ctl_table *table, int write,
77722 void __user *buffer, size_t *lenp, loff_t *ppos)
77723 {
77724- struct ctl_table ipc_table;
77725+ ctl_table_no_const ipc_table;
77726
77727 memcpy(&ipc_table, table, sizeof(ipc_table));
77728 ipc_table.data = get_ipc(table);
77729@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
77730 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
77731 void __user *buffer, size_t *lenp, loff_t *ppos)
77732 {
77733- struct ctl_table ipc_table;
77734+ ctl_table_no_const ipc_table;
77735
77736 memcpy(&ipc_table, table, sizeof(ipc_table));
77737 ipc_table.data = get_ipc(table);
77738@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
77739 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
77740 void __user *buffer, size_t *lenp, loff_t *ppos)
77741 {
77742- struct ctl_table ipc_table;
77743+ ctl_table_no_const ipc_table;
77744 size_t lenp_bef = *lenp;
77745 int rc;
77746
77747@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
77748 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
77749 void __user *buffer, size_t *lenp, loff_t *ppos)
77750 {
77751- struct ctl_table ipc_table;
77752+ ctl_table_no_const ipc_table;
77753 memcpy(&ipc_table, table, sizeof(ipc_table));
77754 ipc_table.data = get_ipc(table);
77755
77756@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
77757 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
77758 void __user *buffer, size_t *lenp, loff_t *ppos)
77759 {
77760- struct ctl_table ipc_table;
77761+ ctl_table_no_const ipc_table;
77762 size_t lenp_bef = *lenp;
77763 int oldval;
77764 int rc;
77765diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
77766index 383d638..943fdbb 100644
77767--- a/ipc/mq_sysctl.c
77768+++ b/ipc/mq_sysctl.c
77769@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
77770 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
77771 void __user *buffer, size_t *lenp, loff_t *ppos)
77772 {
77773- struct ctl_table mq_table;
77774+ ctl_table_no_const mq_table;
77775 memcpy(&mq_table, table, sizeof(mq_table));
77776 mq_table.data = get_mq(table);
77777
77778diff --git a/ipc/mqueue.c b/ipc/mqueue.c
77779index e4e47f6..a85e0ad 100644
77780--- a/ipc/mqueue.c
77781+++ b/ipc/mqueue.c
77782@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
77783 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
77784 info->attr.mq_msgsize);
77785
77786+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
77787 spin_lock(&mq_lock);
77788 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
77789 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
77790diff --git a/ipc/msg.c b/ipc/msg.c
77791index d0c6d96..69a893c 100644
77792--- a/ipc/msg.c
77793+++ b/ipc/msg.c
77794@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
77795 return security_msg_queue_associate(msq, msgflg);
77796 }
77797
77798+static struct ipc_ops msg_ops = {
77799+ .getnew = newque,
77800+ .associate = msg_security,
77801+ .more_checks = NULL
77802+};
77803+
77804 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
77805 {
77806 struct ipc_namespace *ns;
77807- struct ipc_ops msg_ops;
77808 struct ipc_params msg_params;
77809
77810 ns = current->nsproxy->ipc_ns;
77811
77812- msg_ops.getnew = newque;
77813- msg_ops.associate = msg_security;
77814- msg_ops.more_checks = NULL;
77815-
77816 msg_params.key = key;
77817 msg_params.flg = msgflg;
77818
77819diff --git a/ipc/sem.c b/ipc/sem.c
77820index 70480a3..f4e8262 100644
77821--- a/ipc/sem.c
77822+++ b/ipc/sem.c
77823@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
77824 return 0;
77825 }
77826
77827+static struct ipc_ops sem_ops = {
77828+ .getnew = newary,
77829+ .associate = sem_security,
77830+ .more_checks = sem_more_checks
77831+};
77832+
77833 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
77834 {
77835 struct ipc_namespace *ns;
77836- struct ipc_ops sem_ops;
77837 struct ipc_params sem_params;
77838
77839 ns = current->nsproxy->ipc_ns;
77840@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
77841 if (nsems < 0 || nsems > ns->sc_semmsl)
77842 return -EINVAL;
77843
77844- sem_ops.getnew = newary;
77845- sem_ops.associate = sem_security;
77846- sem_ops.more_checks = sem_more_checks;
77847-
77848 sem_params.key = key;
77849 sem_params.flg = semflg;
77850 sem_params.u.nsems = nsems;
77851diff --git a/ipc/shm.c b/ipc/shm.c
77852index 7e199fa..180a1ca 100644
77853--- a/ipc/shm.c
77854+++ b/ipc/shm.c
77855@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
77856 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
77857 #endif
77858
77859+#ifdef CONFIG_GRKERNSEC
77860+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77861+ const time_t shm_createtime, const kuid_t cuid,
77862+ const int shmid);
77863+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77864+ const time_t shm_createtime);
77865+#endif
77866+
77867 void shm_init_ns(struct ipc_namespace *ns)
77868 {
77869 ns->shm_ctlmax = SHMMAX;
77870@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
77871 shp->shm_lprid = 0;
77872 shp->shm_atim = shp->shm_dtim = 0;
77873 shp->shm_ctim = get_seconds();
77874+#ifdef CONFIG_GRKERNSEC
77875+ {
77876+ struct timespec timeval;
77877+ do_posix_clock_monotonic_gettime(&timeval);
77878+
77879+ shp->shm_createtime = timeval.tv_sec;
77880+ }
77881+#endif
77882 shp->shm_segsz = size;
77883 shp->shm_nattch = 0;
77884 shp->shm_file = file;
77885@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
77886 return 0;
77887 }
77888
77889+static struct ipc_ops shm_ops = {
77890+ .getnew = newseg,
77891+ .associate = shm_security,
77892+ .more_checks = shm_more_checks
77893+};
77894+
77895 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
77896 {
77897 struct ipc_namespace *ns;
77898- struct ipc_ops shm_ops;
77899 struct ipc_params shm_params;
77900
77901 ns = current->nsproxy->ipc_ns;
77902
77903- shm_ops.getnew = newseg;
77904- shm_ops.associate = shm_security;
77905- shm_ops.more_checks = shm_more_checks;
77906-
77907 shm_params.key = key;
77908 shm_params.flg = shmflg;
77909 shm_params.u.size = size;
77910@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
77911 f_mode = FMODE_READ | FMODE_WRITE;
77912 }
77913 if (shmflg & SHM_EXEC) {
77914+
77915+#ifdef CONFIG_PAX_MPROTECT
77916+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
77917+ goto out;
77918+#endif
77919+
77920 prot |= PROT_EXEC;
77921 acc_mode |= S_IXUGO;
77922 }
77923@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
77924 if (err)
77925 goto out_unlock;
77926
77927+#ifdef CONFIG_GRKERNSEC
77928+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
77929+ shp->shm_perm.cuid, shmid) ||
77930+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
77931+ err = -EACCES;
77932+ goto out_unlock;
77933+ }
77934+#endif
77935+
77936 path = shp->shm_file->f_path;
77937 path_get(&path);
77938 shp->shm_nattch++;
77939+#ifdef CONFIG_GRKERNSEC
77940+ shp->shm_lapid = current->pid;
77941+#endif
77942 size = i_size_read(path.dentry->d_inode);
77943 shm_unlock(shp);
77944
77945diff --git a/kernel/acct.c b/kernel/acct.c
77946index 8d6e145..33e0b1e 100644
77947--- a/kernel/acct.c
77948+++ b/kernel/acct.c
77949@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
77950 */
77951 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
77952 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
77953- file->f_op->write(file, (char *)&ac,
77954+ file->f_op->write(file, (char __force_user *)&ac,
77955 sizeof(acct_t), &file->f_pos);
77956 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
77957 set_fs(fs);
77958diff --git a/kernel/audit.c b/kernel/audit.c
77959index 91e53d0..d9e3ec4 100644
77960--- a/kernel/audit.c
77961+++ b/kernel/audit.c
77962@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
77963 3) suppressed due to audit_rate_limit
77964 4) suppressed due to audit_backlog_limit
77965 */
77966-static atomic_t audit_lost = ATOMIC_INIT(0);
77967+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
77968
77969 /* The netlink socket. */
77970 static struct sock *audit_sock;
77971@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
77972 unsigned long now;
77973 int print;
77974
77975- atomic_inc(&audit_lost);
77976+ atomic_inc_unchecked(&audit_lost);
77977
77978 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
77979
77980@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
77981 printk(KERN_WARNING
77982 "audit: audit_lost=%d audit_rate_limit=%d "
77983 "audit_backlog_limit=%d\n",
77984- atomic_read(&audit_lost),
77985+ atomic_read_unchecked(&audit_lost),
77986 audit_rate_limit,
77987 audit_backlog_limit);
77988 audit_panic(message);
77989@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
77990 status_set.pid = audit_pid;
77991 status_set.rate_limit = audit_rate_limit;
77992 status_set.backlog_limit = audit_backlog_limit;
77993- status_set.lost = atomic_read(&audit_lost);
77994+ status_set.lost = atomic_read_unchecked(&audit_lost);
77995 status_set.backlog = skb_queue_len(&audit_skb_queue);
77996 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
77997 &status_set, sizeof(status_set));
77998diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
77999index 6bd4a90..0ee9eff 100644
78000--- a/kernel/auditfilter.c
78001+++ b/kernel/auditfilter.c
78002@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
78003 f->lsm_rule = NULL;
78004
78005 /* Support legacy tests for a valid loginuid */
78006- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
78007+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
78008 f->type = AUDIT_LOGINUID_SET;
78009 f->val = 0;
78010 }
78011diff --git a/kernel/auditsc.c b/kernel/auditsc.c
78012index 3c8a601..3a416f6 100644
78013--- a/kernel/auditsc.c
78014+++ b/kernel/auditsc.c
78015@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
78016 }
78017
78018 /* global counter which is incremented every time something logs in */
78019-static atomic_t session_id = ATOMIC_INIT(0);
78020+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
78021
78022 /**
78023 * audit_set_loginuid - set current task's audit_context loginuid
78024@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
78025 return -EPERM;
78026 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
78027
78028- sessionid = atomic_inc_return(&session_id);
78029+ sessionid = atomic_inc_return_unchecked(&session_id);
78030 if (context && context->in_syscall) {
78031 struct audit_buffer *ab;
78032
78033diff --git a/kernel/capability.c b/kernel/capability.c
78034index f6c2ce5..982c0f9 100644
78035--- a/kernel/capability.c
78036+++ b/kernel/capability.c
78037@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
78038 * before modification is attempted and the application
78039 * fails.
78040 */
78041+ if (tocopy > ARRAY_SIZE(kdata))
78042+ return -EFAULT;
78043+
78044 if (copy_to_user(dataptr, kdata, tocopy
78045 * sizeof(struct __user_cap_data_struct))) {
78046 return -EFAULT;
78047@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
78048 int ret;
78049
78050 rcu_read_lock();
78051- ret = security_capable(__task_cred(t), ns, cap);
78052+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
78053+ gr_task_is_capable(t, __task_cred(t), cap);
78054 rcu_read_unlock();
78055
78056- return (ret == 0);
78057+ return ret;
78058 }
78059
78060 /**
78061@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
78062 int ret;
78063
78064 rcu_read_lock();
78065- ret = security_capable_noaudit(__task_cred(t), ns, cap);
78066+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
78067 rcu_read_unlock();
78068
78069- return (ret == 0);
78070+ return ret;
78071 }
78072
78073 /**
78074@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
78075 BUG();
78076 }
78077
78078- if (security_capable(current_cred(), ns, cap) == 0) {
78079+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
78080 current->flags |= PF_SUPERPRIV;
78081 return true;
78082 }
78083@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
78084 }
78085 EXPORT_SYMBOL(ns_capable);
78086
78087+bool ns_capable_nolog(struct user_namespace *ns, int cap)
78088+{
78089+ if (unlikely(!cap_valid(cap))) {
78090+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
78091+ BUG();
78092+ }
78093+
78094+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
78095+ current->flags |= PF_SUPERPRIV;
78096+ return true;
78097+ }
78098+ return false;
78099+}
78100+EXPORT_SYMBOL(ns_capable_nolog);
78101+
78102 /**
78103 * file_ns_capable - Determine if the file's opener had a capability in effect
78104 * @file: The file we want to check
78105@@ -432,6 +451,12 @@ bool capable(int cap)
78106 }
78107 EXPORT_SYMBOL(capable);
78108
78109+bool capable_nolog(int cap)
78110+{
78111+ return ns_capable_nolog(&init_user_ns, cap);
78112+}
78113+EXPORT_SYMBOL(capable_nolog);
78114+
78115 /**
78116 * nsown_capable - Check superior capability to one's own user_ns
78117 * @cap: The capability in question
78118@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
78119
78120 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
78121 }
78122+
78123+bool inode_capable_nolog(const struct inode *inode, int cap)
78124+{
78125+ struct user_namespace *ns = current_user_ns();
78126+
78127+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
78128+}
78129diff --git a/kernel/cgroup.c b/kernel/cgroup.c
78130index 2e9b387..61817b1 100644
78131--- a/kernel/cgroup.c
78132+++ b/kernel/cgroup.c
78133@@ -5398,7 +5398,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
78134 struct css_set *cg = link->cg;
78135 struct task_struct *task;
78136 int count = 0;
78137- seq_printf(seq, "css_set %p\n", cg);
78138+ seq_printf(seq, "css_set %pK\n", cg);
78139 list_for_each_entry(task, &cg->tasks, cg_list) {
78140 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
78141 seq_puts(seq, " ...\n");
78142diff --git a/kernel/compat.c b/kernel/compat.c
78143index 0a09e48..f44f3f0 100644
78144--- a/kernel/compat.c
78145+++ b/kernel/compat.c
78146@@ -13,6 +13,7 @@
78147
78148 #include <linux/linkage.h>
78149 #include <linux/compat.h>
78150+#include <linux/module.h>
78151 #include <linux/errno.h>
78152 #include <linux/time.h>
78153 #include <linux/signal.h>
78154@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
78155 mm_segment_t oldfs;
78156 long ret;
78157
78158- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
78159+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
78160 oldfs = get_fs();
78161 set_fs(KERNEL_DS);
78162 ret = hrtimer_nanosleep_restart(restart);
78163@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
78164 oldfs = get_fs();
78165 set_fs(KERNEL_DS);
78166 ret = hrtimer_nanosleep(&tu,
78167- rmtp ? (struct timespec __user *)&rmt : NULL,
78168+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
78169 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
78170 set_fs(oldfs);
78171
78172@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
78173 mm_segment_t old_fs = get_fs();
78174
78175 set_fs(KERNEL_DS);
78176- ret = sys_sigpending((old_sigset_t __user *) &s);
78177+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
78178 set_fs(old_fs);
78179 if (ret == 0)
78180 ret = put_user(s, set);
78181@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
78182 mm_segment_t old_fs = get_fs();
78183
78184 set_fs(KERNEL_DS);
78185- ret = sys_old_getrlimit(resource, &r);
78186+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
78187 set_fs(old_fs);
78188
78189 if (!ret) {
78190@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
78191 set_fs (KERNEL_DS);
78192 ret = sys_wait4(pid,
78193 (stat_addr ?
78194- (unsigned int __user *) &status : NULL),
78195- options, (struct rusage __user *) &r);
78196+ (unsigned int __force_user *) &status : NULL),
78197+ options, (struct rusage __force_user *) &r);
78198 set_fs (old_fs);
78199
78200 if (ret > 0) {
78201@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
78202 memset(&info, 0, sizeof(info));
78203
78204 set_fs(KERNEL_DS);
78205- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
78206- uru ? (struct rusage __user *)&ru : NULL);
78207+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
78208+ uru ? (struct rusage __force_user *)&ru : NULL);
78209 set_fs(old_fs);
78210
78211 if ((ret < 0) || (info.si_signo == 0))
78212@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
78213 oldfs = get_fs();
78214 set_fs(KERNEL_DS);
78215 err = sys_timer_settime(timer_id, flags,
78216- (struct itimerspec __user *) &newts,
78217- (struct itimerspec __user *) &oldts);
78218+ (struct itimerspec __force_user *) &newts,
78219+ (struct itimerspec __force_user *) &oldts);
78220 set_fs(oldfs);
78221 if (!err && old && put_compat_itimerspec(old, &oldts))
78222 return -EFAULT;
78223@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
78224 oldfs = get_fs();
78225 set_fs(KERNEL_DS);
78226 err = sys_timer_gettime(timer_id,
78227- (struct itimerspec __user *) &ts);
78228+ (struct itimerspec __force_user *) &ts);
78229 set_fs(oldfs);
78230 if (!err && put_compat_itimerspec(setting, &ts))
78231 return -EFAULT;
78232@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
78233 oldfs = get_fs();
78234 set_fs(KERNEL_DS);
78235 err = sys_clock_settime(which_clock,
78236- (struct timespec __user *) &ts);
78237+ (struct timespec __force_user *) &ts);
78238 set_fs(oldfs);
78239 return err;
78240 }
78241@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
78242 oldfs = get_fs();
78243 set_fs(KERNEL_DS);
78244 err = sys_clock_gettime(which_clock,
78245- (struct timespec __user *) &ts);
78246+ (struct timespec __force_user *) &ts);
78247 set_fs(oldfs);
78248 if (!err && put_compat_timespec(&ts, tp))
78249 return -EFAULT;
78250@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
78251
78252 oldfs = get_fs();
78253 set_fs(KERNEL_DS);
78254- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
78255+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
78256 set_fs(oldfs);
78257
78258 err = compat_put_timex(utp, &txc);
78259@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
78260 oldfs = get_fs();
78261 set_fs(KERNEL_DS);
78262 err = sys_clock_getres(which_clock,
78263- (struct timespec __user *) &ts);
78264+ (struct timespec __force_user *) &ts);
78265 set_fs(oldfs);
78266 if (!err && tp && put_compat_timespec(&ts, tp))
78267 return -EFAULT;
78268@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
78269 long err;
78270 mm_segment_t oldfs;
78271 struct timespec tu;
78272- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
78273+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
78274
78275- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
78276+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
78277 oldfs = get_fs();
78278 set_fs(KERNEL_DS);
78279 err = clock_nanosleep_restart(restart);
78280@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
78281 oldfs = get_fs();
78282 set_fs(KERNEL_DS);
78283 err = sys_clock_nanosleep(which_clock, flags,
78284- (struct timespec __user *) &in,
78285- (struct timespec __user *) &out);
78286+ (struct timespec __force_user *) &in,
78287+ (struct timespec __force_user *) &out);
78288 set_fs(oldfs);
78289
78290 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
78291diff --git a/kernel/configs.c b/kernel/configs.c
78292index c18b1f1..b9a0132 100644
78293--- a/kernel/configs.c
78294+++ b/kernel/configs.c
78295@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
78296 struct proc_dir_entry *entry;
78297
78298 /* create the current config file */
78299+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
78300+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
78301+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
78302+ &ikconfig_file_ops);
78303+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78304+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
78305+ &ikconfig_file_ops);
78306+#endif
78307+#else
78308 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
78309 &ikconfig_file_ops);
78310+#endif
78311+
78312 if (!entry)
78313 return -ENOMEM;
78314
78315diff --git a/kernel/cred.c b/kernel/cred.c
78316index e0573a4..3874e41 100644
78317--- a/kernel/cred.c
78318+++ b/kernel/cred.c
78319@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
78320 validate_creds(cred);
78321 alter_cred_subscribers(cred, -1);
78322 put_cred(cred);
78323+
78324+#ifdef CONFIG_GRKERNSEC_SETXID
78325+ cred = (struct cred *) tsk->delayed_cred;
78326+ if (cred != NULL) {
78327+ tsk->delayed_cred = NULL;
78328+ validate_creds(cred);
78329+ alter_cred_subscribers(cred, -1);
78330+ put_cred(cred);
78331+ }
78332+#endif
78333 }
78334
78335 /**
78336@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
78337 * Always returns 0 thus allowing this function to be tail-called at the end
78338 * of, say, sys_setgid().
78339 */
78340-int commit_creds(struct cred *new)
78341+static int __commit_creds(struct cred *new)
78342 {
78343 struct task_struct *task = current;
78344 const struct cred *old = task->real_cred;
78345@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
78346
78347 get_cred(new); /* we will require a ref for the subj creds too */
78348
78349+ gr_set_role_label(task, new->uid, new->gid);
78350+
78351 /* dumpability changes */
78352 if (!uid_eq(old->euid, new->euid) ||
78353 !gid_eq(old->egid, new->egid) ||
78354@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
78355 put_cred(old);
78356 return 0;
78357 }
78358+#ifdef CONFIG_GRKERNSEC_SETXID
78359+extern int set_user(struct cred *new);
78360+
78361+void gr_delayed_cred_worker(void)
78362+{
78363+ const struct cred *new = current->delayed_cred;
78364+ struct cred *ncred;
78365+
78366+ current->delayed_cred = NULL;
78367+
78368+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
78369+ // from doing get_cred on it when queueing this
78370+ put_cred(new);
78371+ return;
78372+ } else if (new == NULL)
78373+ return;
78374+
78375+ ncred = prepare_creds();
78376+ if (!ncred)
78377+ goto die;
78378+ // uids
78379+ ncred->uid = new->uid;
78380+ ncred->euid = new->euid;
78381+ ncred->suid = new->suid;
78382+ ncred->fsuid = new->fsuid;
78383+ // gids
78384+ ncred->gid = new->gid;
78385+ ncred->egid = new->egid;
78386+ ncred->sgid = new->sgid;
78387+ ncred->fsgid = new->fsgid;
78388+ // groups
78389+ if (set_groups(ncred, new->group_info) < 0) {
78390+ abort_creds(ncred);
78391+ goto die;
78392+ }
78393+ // caps
78394+ ncred->securebits = new->securebits;
78395+ ncred->cap_inheritable = new->cap_inheritable;
78396+ ncred->cap_permitted = new->cap_permitted;
78397+ ncred->cap_effective = new->cap_effective;
78398+ ncred->cap_bset = new->cap_bset;
78399+
78400+ if (set_user(ncred)) {
78401+ abort_creds(ncred);
78402+ goto die;
78403+ }
78404+
78405+ // from doing get_cred on it when queueing this
78406+ put_cred(new);
78407+
78408+ __commit_creds(ncred);
78409+ return;
78410+die:
78411+ // from doing get_cred on it when queueing this
78412+ put_cred(new);
78413+ do_group_exit(SIGKILL);
78414+}
78415+#endif
78416+
78417+int commit_creds(struct cred *new)
78418+{
78419+#ifdef CONFIG_GRKERNSEC_SETXID
78420+ int ret;
78421+ int schedule_it = 0;
78422+ struct task_struct *t;
78423+
78424+ /* we won't get called with tasklist_lock held for writing
78425+ and interrupts disabled as the cred struct in that case is
78426+ init_cred
78427+ */
78428+ if (grsec_enable_setxid && !current_is_single_threaded() &&
78429+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
78430+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
78431+ schedule_it = 1;
78432+ }
78433+ ret = __commit_creds(new);
78434+ if (schedule_it) {
78435+ rcu_read_lock();
78436+ read_lock(&tasklist_lock);
78437+ for (t = next_thread(current); t != current;
78438+ t = next_thread(t)) {
78439+ if (t->delayed_cred == NULL) {
78440+ t->delayed_cred = get_cred(new);
78441+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
78442+ set_tsk_need_resched(t);
78443+ }
78444+ }
78445+ read_unlock(&tasklist_lock);
78446+ rcu_read_unlock();
78447+ }
78448+ return ret;
78449+#else
78450+ return __commit_creds(new);
78451+#endif
78452+}
78453+
78454 EXPORT_SYMBOL(commit_creds);
78455
78456 /**
78457diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
78458index 0506d44..2c20034 100644
78459--- a/kernel/debug/debug_core.c
78460+++ b/kernel/debug/debug_core.c
78461@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
78462 */
78463 static atomic_t masters_in_kgdb;
78464 static atomic_t slaves_in_kgdb;
78465-static atomic_t kgdb_break_tasklet_var;
78466+static atomic_unchecked_t kgdb_break_tasklet_var;
78467 atomic_t kgdb_setting_breakpoint;
78468
78469 struct task_struct *kgdb_usethread;
78470@@ -133,7 +133,7 @@ int kgdb_single_step;
78471 static pid_t kgdb_sstep_pid;
78472
78473 /* to keep track of the CPU which is doing the single stepping*/
78474-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
78475+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
78476
78477 /*
78478 * If you are debugging a problem where roundup (the collection of
78479@@ -541,7 +541,7 @@ return_normal:
78480 * kernel will only try for the value of sstep_tries before
78481 * giving up and continuing on.
78482 */
78483- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
78484+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
78485 (kgdb_info[cpu].task &&
78486 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
78487 atomic_set(&kgdb_active, -1);
78488@@ -635,8 +635,8 @@ cpu_master_loop:
78489 }
78490
78491 kgdb_restore:
78492- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
78493- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
78494+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
78495+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
78496 if (kgdb_info[sstep_cpu].task)
78497 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
78498 else
78499@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
78500 static void kgdb_tasklet_bpt(unsigned long ing)
78501 {
78502 kgdb_breakpoint();
78503- atomic_set(&kgdb_break_tasklet_var, 0);
78504+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
78505 }
78506
78507 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
78508
78509 void kgdb_schedule_breakpoint(void)
78510 {
78511- if (atomic_read(&kgdb_break_tasklet_var) ||
78512+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
78513 atomic_read(&kgdb_active) != -1 ||
78514 atomic_read(&kgdb_setting_breakpoint))
78515 return;
78516- atomic_inc(&kgdb_break_tasklet_var);
78517+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
78518 tasklet_schedule(&kgdb_tasklet_breakpoint);
78519 }
78520 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
78521diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
78522index 00eb8f7..d7e3244 100644
78523--- a/kernel/debug/kdb/kdb_main.c
78524+++ b/kernel/debug/kdb/kdb_main.c
78525@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
78526 continue;
78527
78528 kdb_printf("%-20s%8u 0x%p ", mod->name,
78529- mod->core_size, (void *)mod);
78530+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
78531 #ifdef CONFIG_MODULE_UNLOAD
78532 kdb_printf("%4ld ", module_refcount(mod));
78533 #endif
78534@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
78535 kdb_printf(" (Loading)");
78536 else
78537 kdb_printf(" (Live)");
78538- kdb_printf(" 0x%p", mod->module_core);
78539+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
78540
78541 #ifdef CONFIG_MODULE_UNLOAD
78542 {
78543diff --git a/kernel/events/core.c b/kernel/events/core.c
78544index e76e495..cbfe63a 100644
78545--- a/kernel/events/core.c
78546+++ b/kernel/events/core.c
78547@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
78548 * 0 - disallow raw tracepoint access for unpriv
78549 * 1 - disallow cpu events for unpriv
78550 * 2 - disallow kernel profiling for unpriv
78551+ * 3 - disallow all unpriv perf event use
78552 */
78553-int sysctl_perf_event_paranoid __read_mostly = 1;
78554+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
78555+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
78556+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
78557+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
78558+#else
78559+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
78560+#endif
78561
78562 /* Minimum for 512 kiB + 1 user control page */
78563 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
78564@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
78565 return 0;
78566 }
78567
78568-static atomic64_t perf_event_id;
78569+static atomic64_unchecked_t perf_event_id;
78570
78571 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
78572 enum event_type_t event_type);
78573@@ -2747,7 +2754,7 @@ static void __perf_event_read(void *info)
78574
78575 static inline u64 perf_event_count(struct perf_event *event)
78576 {
78577- return local64_read(&event->count) + atomic64_read(&event->child_count);
78578+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
78579 }
78580
78581 static u64 perf_event_read(struct perf_event *event)
78582@@ -3093,9 +3100,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
78583 mutex_lock(&event->child_mutex);
78584 total += perf_event_read(event);
78585 *enabled += event->total_time_enabled +
78586- atomic64_read(&event->child_total_time_enabled);
78587+ atomic64_read_unchecked(&event->child_total_time_enabled);
78588 *running += event->total_time_running +
78589- atomic64_read(&event->child_total_time_running);
78590+ atomic64_read_unchecked(&event->child_total_time_running);
78591
78592 list_for_each_entry(child, &event->child_list, child_list) {
78593 total += perf_event_read(child);
78594@@ -3481,10 +3488,10 @@ void perf_event_update_userpage(struct perf_event *event)
78595 userpg->offset -= local64_read(&event->hw.prev_count);
78596
78597 userpg->time_enabled = enabled +
78598- atomic64_read(&event->child_total_time_enabled);
78599+ atomic64_read_unchecked(&event->child_total_time_enabled);
78600
78601 userpg->time_running = running +
78602- atomic64_read(&event->child_total_time_running);
78603+ atomic64_read_unchecked(&event->child_total_time_running);
78604
78605 arch_perf_update_userpage(userpg, now);
78606
78607@@ -4034,7 +4041,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
78608
78609 /* Data. */
78610 sp = perf_user_stack_pointer(regs);
78611- rem = __output_copy_user(handle, (void *) sp, dump_size);
78612+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
78613 dyn_size = dump_size - rem;
78614
78615 perf_output_skip(handle, rem);
78616@@ -4122,11 +4129,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
78617 values[n++] = perf_event_count(event);
78618 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
78619 values[n++] = enabled +
78620- atomic64_read(&event->child_total_time_enabled);
78621+ atomic64_read_unchecked(&event->child_total_time_enabled);
78622 }
78623 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
78624 values[n++] = running +
78625- atomic64_read(&event->child_total_time_running);
78626+ atomic64_read_unchecked(&event->child_total_time_running);
78627 }
78628 if (read_format & PERF_FORMAT_ID)
78629 values[n++] = primary_event_id(event);
78630@@ -4835,12 +4842,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
78631 * need to add enough zero bytes after the string to handle
78632 * the 64bit alignment we do later.
78633 */
78634- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
78635+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
78636 if (!buf) {
78637 name = strncpy(tmp, "//enomem", sizeof(tmp));
78638 goto got_name;
78639 }
78640- name = d_path(&file->f_path, buf, PATH_MAX);
78641+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
78642 if (IS_ERR(name)) {
78643 name = strncpy(tmp, "//toolong", sizeof(tmp));
78644 goto got_name;
78645@@ -6262,7 +6269,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
78646 event->parent = parent_event;
78647
78648 event->ns = get_pid_ns(task_active_pid_ns(current));
78649- event->id = atomic64_inc_return(&perf_event_id);
78650+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
78651
78652 event->state = PERF_EVENT_STATE_INACTIVE;
78653
78654@@ -6572,6 +6579,11 @@ SYSCALL_DEFINE5(perf_event_open,
78655 if (flags & ~PERF_FLAG_ALL)
78656 return -EINVAL;
78657
78658+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
78659+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
78660+ return -EACCES;
78661+#endif
78662+
78663 err = perf_copy_attr(attr_uptr, &attr);
78664 if (err)
78665 return err;
78666@@ -6904,10 +6916,10 @@ static void sync_child_event(struct perf_event *child_event,
78667 /*
78668 * Add back the child's count to the parent's count:
78669 */
78670- atomic64_add(child_val, &parent_event->child_count);
78671- atomic64_add(child_event->total_time_enabled,
78672+ atomic64_add_unchecked(child_val, &parent_event->child_count);
78673+ atomic64_add_unchecked(child_event->total_time_enabled,
78674 &parent_event->child_total_time_enabled);
78675- atomic64_add(child_event->total_time_running,
78676+ atomic64_add_unchecked(child_event->total_time_running,
78677 &parent_event->child_total_time_running);
78678
78679 /*
78680diff --git a/kernel/events/internal.h b/kernel/events/internal.h
78681index ca65997..cc8cee4 100644
78682--- a/kernel/events/internal.h
78683+++ b/kernel/events/internal.h
78684@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
78685 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
78686 }
78687
78688-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
78689+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
78690 static inline unsigned int \
78691 func_name(struct perf_output_handle *handle, \
78692- const void *buf, unsigned int len) \
78693+ const void user *buf, unsigned int len) \
78694 { \
78695 unsigned long size, written; \
78696 \
78697@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
78698 return n;
78699 }
78700
78701-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
78702+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
78703
78704 #define MEMCPY_SKIP(dst, src, n) (n)
78705
78706-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
78707+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
78708
78709 #ifndef arch_perf_out_copy_user
78710 #define arch_perf_out_copy_user __copy_from_user_inatomic
78711 #endif
78712
78713-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
78714+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
78715
78716 /* Callchain handling */
78717 extern struct perf_callchain_entry *
78718diff --git a/kernel/exit.c b/kernel/exit.c
78719index 7bb73f9..d7978ed 100644
78720--- a/kernel/exit.c
78721+++ b/kernel/exit.c
78722@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
78723 struct task_struct *leader;
78724 int zap_leader;
78725 repeat:
78726+#ifdef CONFIG_NET
78727+ gr_del_task_from_ip_table(p);
78728+#endif
78729+
78730 /* don't need to get the RCU readlock here - the process is dead and
78731 * can't be modifying its own credentials. But shut RCU-lockdep up */
78732 rcu_read_lock();
78733@@ -340,7 +344,7 @@ int allow_signal(int sig)
78734 * know it'll be handled, so that they don't get converted to
78735 * SIGKILL or just silently dropped.
78736 */
78737- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
78738+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
78739 recalc_sigpending();
78740 spin_unlock_irq(&current->sighand->siglock);
78741 return 0;
78742@@ -709,6 +713,8 @@ void do_exit(long code)
78743 struct task_struct *tsk = current;
78744 int group_dead;
78745
78746+ set_fs(USER_DS);
78747+
78748 profile_task_exit(tsk);
78749
78750 WARN_ON(blk_needs_flush_plug(tsk));
78751@@ -725,7 +731,6 @@ void do_exit(long code)
78752 * mm_release()->clear_child_tid() from writing to a user-controlled
78753 * kernel address.
78754 */
78755- set_fs(USER_DS);
78756
78757 ptrace_event(PTRACE_EVENT_EXIT, code);
78758
78759@@ -784,6 +789,9 @@ void do_exit(long code)
78760 tsk->exit_code = code;
78761 taskstats_exit(tsk, group_dead);
78762
78763+ gr_acl_handle_psacct(tsk, code);
78764+ gr_acl_handle_exit();
78765+
78766 exit_mm(tsk);
78767
78768 if (group_dead)
78769@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
78770 * Take down every thread in the group. This is called by fatal signals
78771 * as well as by sys_exit_group (below).
78772 */
78773-void
78774+__noreturn void
78775 do_group_exit(int exit_code)
78776 {
78777 struct signal_struct *sig = current->signal;
78778diff --git a/kernel/fork.c b/kernel/fork.c
78779index 987b28a..11ee8a5 100644
78780--- a/kernel/fork.c
78781+++ b/kernel/fork.c
78782@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
78783 *stackend = STACK_END_MAGIC; /* for overflow detection */
78784
78785 #ifdef CONFIG_CC_STACKPROTECTOR
78786- tsk->stack_canary = get_random_int();
78787+ tsk->stack_canary = pax_get_random_long();
78788 #endif
78789
78790 /*
78791@@ -345,13 +345,81 @@ free_tsk:
78792 }
78793
78794 #ifdef CONFIG_MMU
78795+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
78796+{
78797+ struct vm_area_struct *tmp;
78798+ unsigned long charge;
78799+ struct mempolicy *pol;
78800+ struct file *file;
78801+
78802+ charge = 0;
78803+ if (mpnt->vm_flags & VM_ACCOUNT) {
78804+ unsigned long len = vma_pages(mpnt);
78805+
78806+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
78807+ goto fail_nomem;
78808+ charge = len;
78809+ }
78810+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
78811+ if (!tmp)
78812+ goto fail_nomem;
78813+ *tmp = *mpnt;
78814+ tmp->vm_mm = mm;
78815+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
78816+ pol = mpol_dup(vma_policy(mpnt));
78817+ if (IS_ERR(pol))
78818+ goto fail_nomem_policy;
78819+ vma_set_policy(tmp, pol);
78820+ if (anon_vma_fork(tmp, mpnt))
78821+ goto fail_nomem_anon_vma_fork;
78822+ tmp->vm_flags &= ~VM_LOCKED;
78823+ tmp->vm_next = tmp->vm_prev = NULL;
78824+ tmp->vm_mirror = NULL;
78825+ file = tmp->vm_file;
78826+ if (file) {
78827+ struct inode *inode = file_inode(file);
78828+ struct address_space *mapping = file->f_mapping;
78829+
78830+ get_file(file);
78831+ if (tmp->vm_flags & VM_DENYWRITE)
78832+ atomic_dec(&inode->i_writecount);
78833+ mutex_lock(&mapping->i_mmap_mutex);
78834+ if (tmp->vm_flags & VM_SHARED)
78835+ mapping->i_mmap_writable++;
78836+ flush_dcache_mmap_lock(mapping);
78837+ /* insert tmp into the share list, just after mpnt */
78838+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
78839+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
78840+ else
78841+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
78842+ flush_dcache_mmap_unlock(mapping);
78843+ mutex_unlock(&mapping->i_mmap_mutex);
78844+ }
78845+
78846+ /*
78847+ * Clear hugetlb-related page reserves for children. This only
78848+ * affects MAP_PRIVATE mappings. Faults generated by the child
78849+ * are not guaranteed to succeed, even if read-only
78850+ */
78851+ if (is_vm_hugetlb_page(tmp))
78852+ reset_vma_resv_huge_pages(tmp);
78853+
78854+ return tmp;
78855+
78856+fail_nomem_anon_vma_fork:
78857+ mpol_put(pol);
78858+fail_nomem_policy:
78859+ kmem_cache_free(vm_area_cachep, tmp);
78860+fail_nomem:
78861+ vm_unacct_memory(charge);
78862+ return NULL;
78863+}
78864+
78865 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
78866 {
78867 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
78868 struct rb_node **rb_link, *rb_parent;
78869 int retval;
78870- unsigned long charge;
78871- struct mempolicy *pol;
78872
78873 uprobe_start_dup_mmap();
78874 down_write(&oldmm->mmap_sem);
78875@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
78876 mm->locked_vm = 0;
78877 mm->mmap = NULL;
78878 mm->mmap_cache = NULL;
78879- mm->free_area_cache = oldmm->mmap_base;
78880- mm->cached_hole_size = ~0UL;
78881+ mm->free_area_cache = oldmm->free_area_cache;
78882+ mm->cached_hole_size = oldmm->cached_hole_size;
78883 mm->map_count = 0;
78884 cpumask_clear(mm_cpumask(mm));
78885 mm->mm_rb = RB_ROOT;
78886@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
78887
78888 prev = NULL;
78889 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
78890- struct file *file;
78891-
78892 if (mpnt->vm_flags & VM_DONTCOPY) {
78893 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
78894 -vma_pages(mpnt));
78895 continue;
78896 }
78897- charge = 0;
78898- if (mpnt->vm_flags & VM_ACCOUNT) {
78899- unsigned long len = vma_pages(mpnt);
78900-
78901- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
78902- goto fail_nomem;
78903- charge = len;
78904- }
78905- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
78906- if (!tmp)
78907- goto fail_nomem;
78908- *tmp = *mpnt;
78909- INIT_LIST_HEAD(&tmp->anon_vma_chain);
78910- pol = mpol_dup(vma_policy(mpnt));
78911- retval = PTR_ERR(pol);
78912- if (IS_ERR(pol))
78913- goto fail_nomem_policy;
78914- vma_set_policy(tmp, pol);
78915- tmp->vm_mm = mm;
78916- if (anon_vma_fork(tmp, mpnt))
78917- goto fail_nomem_anon_vma_fork;
78918- tmp->vm_flags &= ~VM_LOCKED;
78919- tmp->vm_next = tmp->vm_prev = NULL;
78920- file = tmp->vm_file;
78921- if (file) {
78922- struct inode *inode = file_inode(file);
78923- struct address_space *mapping = file->f_mapping;
78924-
78925- get_file(file);
78926- if (tmp->vm_flags & VM_DENYWRITE)
78927- atomic_dec(&inode->i_writecount);
78928- mutex_lock(&mapping->i_mmap_mutex);
78929- if (tmp->vm_flags & VM_SHARED)
78930- mapping->i_mmap_writable++;
78931- flush_dcache_mmap_lock(mapping);
78932- /* insert tmp into the share list, just after mpnt */
78933- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
78934- vma_nonlinear_insert(tmp,
78935- &mapping->i_mmap_nonlinear);
78936- else
78937- vma_interval_tree_insert_after(tmp, mpnt,
78938- &mapping->i_mmap);
78939- flush_dcache_mmap_unlock(mapping);
78940- mutex_unlock(&mapping->i_mmap_mutex);
78941+ tmp = dup_vma(mm, oldmm, mpnt);
78942+ if (!tmp) {
78943+ retval = -ENOMEM;
78944+ goto out;
78945 }
78946
78947 /*
78948@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
78949 if (retval)
78950 goto out;
78951 }
78952+
78953+#ifdef CONFIG_PAX_SEGMEXEC
78954+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
78955+ struct vm_area_struct *mpnt_m;
78956+
78957+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
78958+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
78959+
78960+ if (!mpnt->vm_mirror)
78961+ continue;
78962+
78963+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
78964+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
78965+ mpnt->vm_mirror = mpnt_m;
78966+ } else {
78967+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
78968+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
78969+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
78970+ mpnt->vm_mirror->vm_mirror = mpnt;
78971+ }
78972+ }
78973+ BUG_ON(mpnt_m);
78974+ }
78975+#endif
78976+
78977 /* a new mm has just been created */
78978 arch_dup_mmap(oldmm, mm);
78979 retval = 0;
78980@@ -473,14 +524,6 @@ out:
78981 up_write(&oldmm->mmap_sem);
78982 uprobe_end_dup_mmap();
78983 return retval;
78984-fail_nomem_anon_vma_fork:
78985- mpol_put(pol);
78986-fail_nomem_policy:
78987- kmem_cache_free(vm_area_cachep, tmp);
78988-fail_nomem:
78989- retval = -ENOMEM;
78990- vm_unacct_memory(charge);
78991- goto out;
78992 }
78993
78994 static inline int mm_alloc_pgd(struct mm_struct *mm)
78995@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
78996 return ERR_PTR(err);
78997
78998 mm = get_task_mm(task);
78999- if (mm && mm != current->mm &&
79000- !ptrace_may_access(task, mode)) {
79001+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
79002+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
79003 mmput(mm);
79004 mm = ERR_PTR(-EACCES);
79005 }
79006@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
79007 spin_unlock(&fs->lock);
79008 return -EAGAIN;
79009 }
79010- fs->users++;
79011+ atomic_inc(&fs->users);
79012 spin_unlock(&fs->lock);
79013 return 0;
79014 }
79015 tsk->fs = copy_fs_struct(fs);
79016 if (!tsk->fs)
79017 return -ENOMEM;
79018+ /* Carry through gr_chroot_dentry and is_chrooted instead
79019+ of recomputing it here. Already copied when the task struct
79020+ is duplicated. This allows pivot_root to not be treated as
79021+ a chroot
79022+ */
79023+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
79024+
79025 return 0;
79026 }
79027
79028@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
79029 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
79030 #endif
79031 retval = -EAGAIN;
79032+
79033+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
79034+
79035 if (atomic_read(&p->real_cred->user->processes) >=
79036 task_rlimit(p, RLIMIT_NPROC)) {
79037- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
79038- p->real_cred->user != INIT_USER)
79039+ if (p->real_cred->user != INIT_USER &&
79040+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
79041 goto bad_fork_free;
79042 }
79043 current->flags &= ~PF_NPROC_EXCEEDED;
79044@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
79045 goto bad_fork_free_pid;
79046 }
79047
79048+ /* synchronizes with gr_set_acls()
79049+ we need to call this past the point of no return for fork()
79050+ */
79051+ gr_copy_label(p);
79052+
79053 if (clone_flags & CLONE_THREAD) {
79054 current->signal->nr_threads++;
79055 atomic_inc(&current->signal->live);
79056@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
79057 bad_fork_free:
79058 free_task(p);
79059 fork_out:
79060+ gr_log_forkfail(retval);
79061+
79062 return ERR_PTR(retval);
79063 }
79064
79065@@ -1613,6 +1673,8 @@ long do_fork(unsigned long clone_flags,
79066 if (clone_flags & CLONE_PARENT_SETTID)
79067 put_user(nr, parent_tidptr);
79068
79069+ gr_handle_brute_check();
79070+
79071 if (clone_flags & CLONE_VFORK) {
79072 p->vfork_done = &vfork;
79073 init_completion(&vfork);
79074@@ -1723,7 +1785,7 @@ void __init proc_caches_init(void)
79075 mm_cachep = kmem_cache_create("mm_struct",
79076 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
79077 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
79078- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
79079+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
79080 mmap_init();
79081 nsproxy_cache_init();
79082 }
79083@@ -1763,7 +1825,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
79084 return 0;
79085
79086 /* don't need lock here; in the worst case we'll do useless copy */
79087- if (fs->users == 1)
79088+ if (atomic_read(&fs->users) == 1)
79089 return 0;
79090
79091 *new_fsp = copy_fs_struct(fs);
79092@@ -1875,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
79093 fs = current->fs;
79094 spin_lock(&fs->lock);
79095 current->fs = new_fs;
79096- if (--fs->users)
79097+ gr_set_chroot_entries(current, &current->fs->root);
79098+ if (atomic_dec_return(&fs->users))
79099 new_fs = NULL;
79100 else
79101 new_fs = fs;
79102diff --git a/kernel/futex.c b/kernel/futex.c
79103index 49dacfb..5c6b450 100644
79104--- a/kernel/futex.c
79105+++ b/kernel/futex.c
79106@@ -54,6 +54,7 @@
79107 #include <linux/mount.h>
79108 #include <linux/pagemap.h>
79109 #include <linux/syscalls.h>
79110+#include <linux/ptrace.h>
79111 #include <linux/signal.h>
79112 #include <linux/export.h>
79113 #include <linux/magic.h>
79114@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
79115 struct page *page, *page_head;
79116 int err, ro = 0;
79117
79118+#ifdef CONFIG_PAX_SEGMEXEC
79119+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
79120+ return -EFAULT;
79121+#endif
79122+
79123 /*
79124 * The futex address must be "naturally" aligned.
79125 */
79126@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
79127 {
79128 u32 curval;
79129 int i;
79130+ mm_segment_t oldfs;
79131
79132 /*
79133 * This will fail and we want it. Some arch implementations do
79134@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
79135 * implementation, the non-functional ones will return
79136 * -ENOSYS.
79137 */
79138+ oldfs = get_fs();
79139+ set_fs(USER_DS);
79140 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
79141 futex_cmpxchg_enabled = 1;
79142+ set_fs(oldfs);
79143
79144 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
79145 plist_head_init(&futex_queues[i].chain);
79146diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
79147index f9f44fd..29885e4 100644
79148--- a/kernel/futex_compat.c
79149+++ b/kernel/futex_compat.c
79150@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
79151 return 0;
79152 }
79153
79154-static void __user *futex_uaddr(struct robust_list __user *entry,
79155+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
79156 compat_long_t futex_offset)
79157 {
79158 compat_uptr_t base = ptr_to_compat(entry);
79159diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
79160index 9b22d03..6295b62 100644
79161--- a/kernel/gcov/base.c
79162+++ b/kernel/gcov/base.c
79163@@ -102,11 +102,6 @@ void gcov_enable_events(void)
79164 }
79165
79166 #ifdef CONFIG_MODULES
79167-static inline int within(void *addr, void *start, unsigned long size)
79168-{
79169- return ((addr >= start) && (addr < start + size));
79170-}
79171-
79172 /* Update list and generate events when modules are unloaded. */
79173 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
79174 void *data)
79175@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
79176 prev = NULL;
79177 /* Remove entries located in module from linked list. */
79178 for (info = gcov_info_head; info; info = info->next) {
79179- if (within(info, mod->module_core, mod->core_size)) {
79180+ if (within_module_core_rw((unsigned long)info, mod)) {
79181 if (prev)
79182 prev->next = info->next;
79183 else
79184diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
79185index 2288fbd..0f3941f 100644
79186--- a/kernel/hrtimer.c
79187+++ b/kernel/hrtimer.c
79188@@ -1435,7 +1435,7 @@ void hrtimer_peek_ahead_timers(void)
79189 local_irq_restore(flags);
79190 }
79191
79192-static void run_hrtimer_softirq(struct softirq_action *h)
79193+static void run_hrtimer_softirq(void)
79194 {
79195 hrtimer_peek_ahead_timers();
79196 }
79197@@ -1770,7 +1770,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
79198 return NOTIFY_OK;
79199 }
79200
79201-static struct notifier_block __cpuinitdata hrtimers_nb = {
79202+static struct notifier_block hrtimers_nb = {
79203 .notifier_call = hrtimer_cpu_notify,
79204 };
79205
79206diff --git a/kernel/irq_work.c b/kernel/irq_work.c
79207index 55fcce6..0e4cf34 100644
79208--- a/kernel/irq_work.c
79209+++ b/kernel/irq_work.c
79210@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
79211 return NOTIFY_OK;
79212 }
79213
79214-static struct notifier_block cpu_notify;
79215+static struct notifier_block cpu_notify = {
79216+ .notifier_call = irq_work_cpu_notify,
79217+ .priority = 0,
79218+};
79219
79220 static __init int irq_work_init_cpu_notifier(void)
79221 {
79222- cpu_notify.notifier_call = irq_work_cpu_notify;
79223- cpu_notify.priority = 0;
79224 register_cpu_notifier(&cpu_notify);
79225 return 0;
79226 }
79227diff --git a/kernel/jump_label.c b/kernel/jump_label.c
79228index 60f48fa..7f3a770 100644
79229--- a/kernel/jump_label.c
79230+++ b/kernel/jump_label.c
79231@@ -13,6 +13,7 @@
79232 #include <linux/sort.h>
79233 #include <linux/err.h>
79234 #include <linux/static_key.h>
79235+#include <linux/mm.h>
79236
79237 #ifdef HAVE_JUMP_LABEL
79238
79239@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
79240
79241 size = (((unsigned long)stop - (unsigned long)start)
79242 / sizeof(struct jump_entry));
79243+ pax_open_kernel();
79244 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
79245+ pax_close_kernel();
79246 }
79247
79248 static void jump_label_update(struct static_key *key, int enable);
79249@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
79250 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
79251 struct jump_entry *iter;
79252
79253+ pax_open_kernel();
79254 for (iter = iter_start; iter < iter_stop; iter++) {
79255 if (within_module_init(iter->code, mod))
79256 iter->code = 0;
79257 }
79258+ pax_close_kernel();
79259 }
79260
79261 static int
79262diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
79263index 3127ad5..159d880 100644
79264--- a/kernel/kallsyms.c
79265+++ b/kernel/kallsyms.c
79266@@ -11,6 +11,9 @@
79267 * Changed the compression method from stem compression to "table lookup"
79268 * compression (see scripts/kallsyms.c for a more complete description)
79269 */
79270+#ifdef CONFIG_GRKERNSEC_HIDESYM
79271+#define __INCLUDED_BY_HIDESYM 1
79272+#endif
79273 #include <linux/kallsyms.h>
79274 #include <linux/module.h>
79275 #include <linux/init.h>
79276@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
79277
79278 static inline int is_kernel_inittext(unsigned long addr)
79279 {
79280+ if (system_state != SYSTEM_BOOTING)
79281+ return 0;
79282+
79283 if (addr >= (unsigned long)_sinittext
79284 && addr <= (unsigned long)_einittext)
79285 return 1;
79286 return 0;
79287 }
79288
79289+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79290+#ifdef CONFIG_MODULES
79291+static inline int is_module_text(unsigned long addr)
79292+{
79293+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
79294+ return 1;
79295+
79296+ addr = ktla_ktva(addr);
79297+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
79298+}
79299+#else
79300+static inline int is_module_text(unsigned long addr)
79301+{
79302+ return 0;
79303+}
79304+#endif
79305+#endif
79306+
79307 static inline int is_kernel_text(unsigned long addr)
79308 {
79309 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
79310@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
79311
79312 static inline int is_kernel(unsigned long addr)
79313 {
79314+
79315+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79316+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
79317+ return 1;
79318+
79319+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
79320+#else
79321 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
79322+#endif
79323+
79324 return 1;
79325 return in_gate_area_no_mm(addr);
79326 }
79327
79328 static int is_ksym_addr(unsigned long addr)
79329 {
79330+
79331+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79332+ if (is_module_text(addr))
79333+ return 0;
79334+#endif
79335+
79336 if (all_var)
79337 return is_kernel(addr);
79338
79339@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
79340
79341 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
79342 {
79343- iter->name[0] = '\0';
79344 iter->nameoff = get_symbol_offset(new_pos);
79345 iter->pos = new_pos;
79346 }
79347@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
79348 {
79349 struct kallsym_iter *iter = m->private;
79350
79351+#ifdef CONFIG_GRKERNSEC_HIDESYM
79352+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
79353+ return 0;
79354+#endif
79355+
79356 /* Some debugging symbols have no name. Ignore them. */
79357 if (!iter->name[0])
79358 return 0;
79359@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
79360 */
79361 type = iter->exported ? toupper(iter->type) :
79362 tolower(iter->type);
79363+
79364 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
79365 type, iter->name, iter->module_name);
79366 } else
79367@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
79368 struct kallsym_iter *iter;
79369 int ret;
79370
79371- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
79372+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
79373 if (!iter)
79374 return -ENOMEM;
79375 reset_iter(iter, 0);
79376diff --git a/kernel/kcmp.c b/kernel/kcmp.c
79377index e30ac0f..3528cac 100644
79378--- a/kernel/kcmp.c
79379+++ b/kernel/kcmp.c
79380@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
79381 struct task_struct *task1, *task2;
79382 int ret;
79383
79384+#ifdef CONFIG_GRKERNSEC
79385+ return -ENOSYS;
79386+#endif
79387+
79388 rcu_read_lock();
79389
79390 /*
79391diff --git a/kernel/kexec.c b/kernel/kexec.c
79392index 59f7b55..4022f65 100644
79393--- a/kernel/kexec.c
79394+++ b/kernel/kexec.c
79395@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
79396 unsigned long flags)
79397 {
79398 struct compat_kexec_segment in;
79399- struct kexec_segment out, __user *ksegments;
79400+ struct kexec_segment out;
79401+ struct kexec_segment __user *ksegments;
79402 unsigned long i, result;
79403
79404 /* Don't allow clients that don't understand the native
79405diff --git a/kernel/kmod.c b/kernel/kmod.c
79406index 8241906..d625f2c 100644
79407--- a/kernel/kmod.c
79408+++ b/kernel/kmod.c
79409@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
79410 kfree(info->argv);
79411 }
79412
79413-static int call_modprobe(char *module_name, int wait)
79414+static int call_modprobe(char *module_name, char *module_param, int wait)
79415 {
79416 struct subprocess_info *info;
79417 static char *envp[] = {
79418@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
79419 NULL
79420 };
79421
79422- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
79423+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
79424 if (!argv)
79425 goto out;
79426
79427@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
79428 argv[1] = "-q";
79429 argv[2] = "--";
79430 argv[3] = module_name; /* check free_modprobe_argv() */
79431- argv[4] = NULL;
79432+ argv[4] = module_param;
79433+ argv[5] = NULL;
79434
79435 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
79436 NULL, free_modprobe_argv, NULL);
79437@@ -129,9 +130,8 @@ out:
79438 * If module auto-loading support is disabled then this function
79439 * becomes a no-operation.
79440 */
79441-int __request_module(bool wait, const char *fmt, ...)
79442+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
79443 {
79444- va_list args;
79445 char module_name[MODULE_NAME_LEN];
79446 unsigned int max_modprobes;
79447 int ret;
79448@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
79449 */
79450 WARN_ON_ONCE(wait && current_is_async());
79451
79452- va_start(args, fmt);
79453- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
79454- va_end(args);
79455+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
79456 if (ret >= MODULE_NAME_LEN)
79457 return -ENAMETOOLONG;
79458
79459@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
79460 if (ret)
79461 return ret;
79462
79463+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79464+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
79465+ /* hack to workaround consolekit/udisks stupidity */
79466+ read_lock(&tasklist_lock);
79467+ if (!strcmp(current->comm, "mount") &&
79468+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
79469+ read_unlock(&tasklist_lock);
79470+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
79471+ return -EPERM;
79472+ }
79473+ read_unlock(&tasklist_lock);
79474+ }
79475+#endif
79476+
79477 /* If modprobe needs a service that is in a module, we get a recursive
79478 * loop. Limit the number of running kmod threads to max_threads/2 or
79479 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
79480@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
79481
79482 trace_module_request(module_name, wait, _RET_IP_);
79483
79484- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
79485+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
79486
79487 atomic_dec(&kmod_concurrent);
79488 return ret;
79489 }
79490+
79491+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
79492+{
79493+ va_list args;
79494+ int ret;
79495+
79496+ va_start(args, fmt);
79497+ ret = ____request_module(wait, module_param, fmt, args);
79498+ va_end(args);
79499+
79500+ return ret;
79501+}
79502+
79503+int __request_module(bool wait, const char *fmt, ...)
79504+{
79505+ va_list args;
79506+ int ret;
79507+
79508+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79509+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
79510+ char module_param[MODULE_NAME_LEN];
79511+
79512+ memset(module_param, 0, sizeof(module_param));
79513+
79514+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
79515+
79516+ va_start(args, fmt);
79517+ ret = ____request_module(wait, module_param, fmt, args);
79518+ va_end(args);
79519+
79520+ return ret;
79521+ }
79522+#endif
79523+
79524+ va_start(args, fmt);
79525+ ret = ____request_module(wait, NULL, fmt, args);
79526+ va_end(args);
79527+
79528+ return ret;
79529+}
79530+
79531 EXPORT_SYMBOL(__request_module);
79532 #endif /* CONFIG_MODULES */
79533
79534@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
79535 *
79536 * Thus the __user pointer cast is valid here.
79537 */
79538- sys_wait4(pid, (int __user *)&ret, 0, NULL);
79539+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
79540
79541 /*
79542 * If ret is 0, either ____call_usermodehelper failed and the
79543@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
79544 static int proc_cap_handler(struct ctl_table *table, int write,
79545 void __user *buffer, size_t *lenp, loff_t *ppos)
79546 {
79547- struct ctl_table t;
79548+ ctl_table_no_const t;
79549 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
79550 kernel_cap_t new_cap;
79551 int err, i;
79552diff --git a/kernel/kprobes.c b/kernel/kprobes.c
79553index bddf3b2..233bf40 100644
79554--- a/kernel/kprobes.c
79555+++ b/kernel/kprobes.c
79556@@ -31,6 +31,9 @@
79557 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
79558 * <prasanna@in.ibm.com> added function-return probes.
79559 */
79560+#ifdef CONFIG_GRKERNSEC_HIDESYM
79561+#define __INCLUDED_BY_HIDESYM 1
79562+#endif
79563 #include <linux/kprobes.h>
79564 #include <linux/hash.h>
79565 #include <linux/init.h>
79566@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
79567 * kernel image and loaded module images reside. This is required
79568 * so x86_64 can correctly handle the %rip-relative fixups.
79569 */
79570- kip->insns = module_alloc(PAGE_SIZE);
79571+ kip->insns = module_alloc_exec(PAGE_SIZE);
79572 if (!kip->insns) {
79573 kfree(kip);
79574 return NULL;
79575@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
79576 */
79577 if (!list_is_singular(&kip->list)) {
79578 list_del(&kip->list);
79579- module_free(NULL, kip->insns);
79580+ module_free_exec(NULL, kip->insns);
79581 kfree(kip);
79582 }
79583 return 1;
79584@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
79585 {
79586 int i, err = 0;
79587 unsigned long offset = 0, size = 0;
79588- char *modname, namebuf[128];
79589+ char *modname, namebuf[KSYM_NAME_LEN];
79590 const char *symbol_name;
79591 void *addr;
79592 struct kprobe_blackpoint *kb;
79593@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
79594 kprobe_type = "k";
79595
79596 if (sym)
79597- seq_printf(pi, "%p %s %s+0x%x %s ",
79598+ seq_printf(pi, "%pK %s %s+0x%x %s ",
79599 p->addr, kprobe_type, sym, offset,
79600 (modname ? modname : " "));
79601 else
79602- seq_printf(pi, "%p %s %p ",
79603+ seq_printf(pi, "%pK %s %pK ",
79604 p->addr, kprobe_type, p->addr);
79605
79606 if (!pp)
79607@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
79608 const char *sym = NULL;
79609 unsigned int i = *(loff_t *) v;
79610 unsigned long offset = 0;
79611- char *modname, namebuf[128];
79612+ char *modname, namebuf[KSYM_NAME_LEN];
79613
79614 head = &kprobe_table[i];
79615 preempt_disable();
79616diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
79617index 6ada93c..dce7d5d 100644
79618--- a/kernel/ksysfs.c
79619+++ b/kernel/ksysfs.c
79620@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
79621 {
79622 if (count+1 > UEVENT_HELPER_PATH_LEN)
79623 return -ENOENT;
79624+ if (!capable(CAP_SYS_ADMIN))
79625+ return -EPERM;
79626 memcpy(uevent_helper, buf, count);
79627 uevent_helper[count] = '\0';
79628 if (count && uevent_helper[count-1] == '\n')
79629@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
79630 return count;
79631 }
79632
79633-static struct bin_attribute notes_attr = {
79634+static bin_attribute_no_const notes_attr __read_only = {
79635 .attr = {
79636 .name = "notes",
79637 .mode = S_IRUGO,
79638diff --git a/kernel/lockdep.c b/kernel/lockdep.c
79639index 1f3186b..bb7dbc6 100644
79640--- a/kernel/lockdep.c
79641+++ b/kernel/lockdep.c
79642@@ -596,6 +596,10 @@ static int static_obj(void *obj)
79643 end = (unsigned long) &_end,
79644 addr = (unsigned long) obj;
79645
79646+#ifdef CONFIG_PAX_KERNEXEC
79647+ start = ktla_ktva(start);
79648+#endif
79649+
79650 /*
79651 * static variable?
79652 */
79653@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
79654 if (!static_obj(lock->key)) {
79655 debug_locks_off();
79656 printk("INFO: trying to register non-static key.\n");
79657+ printk("lock:%pS key:%pS.\n", lock, lock->key);
79658 printk("the code is fine but needs lockdep annotation.\n");
79659 printk("turning off the locking correctness validator.\n");
79660 dump_stack();
79661@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
79662 if (!class)
79663 return 0;
79664 }
79665- atomic_inc((atomic_t *)&class->ops);
79666+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
79667 if (very_verbose(class)) {
79668 printk("\nacquire class [%p] %s", class->key, class->name);
79669 if (class->name_version > 1)
79670diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
79671index b2c71c5..7b88d63 100644
79672--- a/kernel/lockdep_proc.c
79673+++ b/kernel/lockdep_proc.c
79674@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
79675 return 0;
79676 }
79677
79678- seq_printf(m, "%p", class->key);
79679+ seq_printf(m, "%pK", class->key);
79680 #ifdef CONFIG_DEBUG_LOCKDEP
79681 seq_printf(m, " OPS:%8ld", class->ops);
79682 #endif
79683@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
79684
79685 list_for_each_entry(entry, &class->locks_after, entry) {
79686 if (entry->distance == 1) {
79687- seq_printf(m, " -> [%p] ", entry->class->key);
79688+ seq_printf(m, " -> [%pK] ", entry->class->key);
79689 print_name(m, entry->class);
79690 seq_puts(m, "\n");
79691 }
79692@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
79693 if (!class->key)
79694 continue;
79695
79696- seq_printf(m, "[%p] ", class->key);
79697+ seq_printf(m, "[%pK] ", class->key);
79698 print_name(m, class);
79699 seq_puts(m, "\n");
79700 }
79701@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
79702 if (!i)
79703 seq_line(m, '-', 40-namelen, namelen);
79704
79705- snprintf(ip, sizeof(ip), "[<%p>]",
79706+ snprintf(ip, sizeof(ip), "[<%pK>]",
79707 (void *)class->contention_point[i]);
79708 seq_printf(m, "%40s %14lu %29s %pS\n",
79709 name, stats->contention_point[i],
79710@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
79711 if (!i)
79712 seq_line(m, '-', 40-namelen, namelen);
79713
79714- snprintf(ip, sizeof(ip), "[<%p>]",
79715+ snprintf(ip, sizeof(ip), "[<%pK>]",
79716 (void *)class->contending_point[i]);
79717 seq_printf(m, "%40s %14lu %29s %pS\n",
79718 name, stats->contending_point[i],
79719diff --git a/kernel/module.c b/kernel/module.c
79720index fa53db8..6f17200 100644
79721--- a/kernel/module.c
79722+++ b/kernel/module.c
79723@@ -61,6 +61,7 @@
79724 #include <linux/pfn.h>
79725 #include <linux/bsearch.h>
79726 #include <linux/fips.h>
79727+#include <linux/grsecurity.h>
79728 #include <uapi/linux/module.h>
79729 #include "module-internal.h"
79730
79731@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
79732
79733 /* Bounds of module allocation, for speeding __module_address.
79734 * Protected by module_mutex. */
79735-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
79736+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
79737+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
79738
79739 int register_module_notifier(struct notifier_block * nb)
79740 {
79741@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
79742 return true;
79743
79744 list_for_each_entry_rcu(mod, &modules, list) {
79745- struct symsearch arr[] = {
79746+ struct symsearch modarr[] = {
79747 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
79748 NOT_GPL_ONLY, false },
79749 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
79750@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
79751 if (mod->state == MODULE_STATE_UNFORMED)
79752 continue;
79753
79754- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
79755+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
79756 return true;
79757 }
79758 return false;
79759@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
79760 static int percpu_modalloc(struct module *mod,
79761 unsigned long size, unsigned long align)
79762 {
79763- if (align > PAGE_SIZE) {
79764+ if (align-1 >= PAGE_SIZE) {
79765 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
79766 mod->name, align, PAGE_SIZE);
79767 align = PAGE_SIZE;
79768@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
79769 static ssize_t show_coresize(struct module_attribute *mattr,
79770 struct module_kobject *mk, char *buffer)
79771 {
79772- return sprintf(buffer, "%u\n", mk->mod->core_size);
79773+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
79774 }
79775
79776 static struct module_attribute modinfo_coresize =
79777@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
79778 static ssize_t show_initsize(struct module_attribute *mattr,
79779 struct module_kobject *mk, char *buffer)
79780 {
79781- return sprintf(buffer, "%u\n", mk->mod->init_size);
79782+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
79783 }
79784
79785 static struct module_attribute modinfo_initsize =
79786@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
79787 */
79788 #ifdef CONFIG_SYSFS
79789
79790-#ifdef CONFIG_KALLSYMS
79791+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79792 static inline bool sect_empty(const Elf_Shdr *sect)
79793 {
79794 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
79795@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
79796 {
79797 unsigned int notes, loaded, i;
79798 struct module_notes_attrs *notes_attrs;
79799- struct bin_attribute *nattr;
79800+ bin_attribute_no_const *nattr;
79801
79802 /* failed to create section attributes, so can't create notes */
79803 if (!mod->sect_attrs)
79804@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
79805 static int module_add_modinfo_attrs(struct module *mod)
79806 {
79807 struct module_attribute *attr;
79808- struct module_attribute *temp_attr;
79809+ module_attribute_no_const *temp_attr;
79810 int error = 0;
79811 int i;
79812
79813@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
79814
79815 static void unset_module_core_ro_nx(struct module *mod)
79816 {
79817- set_page_attributes(mod->module_core + mod->core_text_size,
79818- mod->module_core + mod->core_size,
79819+ set_page_attributes(mod->module_core_rw,
79820+ mod->module_core_rw + mod->core_size_rw,
79821 set_memory_x);
79822- set_page_attributes(mod->module_core,
79823- mod->module_core + mod->core_ro_size,
79824+ set_page_attributes(mod->module_core_rx,
79825+ mod->module_core_rx + mod->core_size_rx,
79826 set_memory_rw);
79827 }
79828
79829 static void unset_module_init_ro_nx(struct module *mod)
79830 {
79831- set_page_attributes(mod->module_init + mod->init_text_size,
79832- mod->module_init + mod->init_size,
79833+ set_page_attributes(mod->module_init_rw,
79834+ mod->module_init_rw + mod->init_size_rw,
79835 set_memory_x);
79836- set_page_attributes(mod->module_init,
79837- mod->module_init + mod->init_ro_size,
79838+ set_page_attributes(mod->module_init_rx,
79839+ mod->module_init_rx + mod->init_size_rx,
79840 set_memory_rw);
79841 }
79842
79843@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
79844 list_for_each_entry_rcu(mod, &modules, list) {
79845 if (mod->state == MODULE_STATE_UNFORMED)
79846 continue;
79847- if ((mod->module_core) && (mod->core_text_size)) {
79848- set_page_attributes(mod->module_core,
79849- mod->module_core + mod->core_text_size,
79850+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
79851+ set_page_attributes(mod->module_core_rx,
79852+ mod->module_core_rx + mod->core_size_rx,
79853 set_memory_rw);
79854 }
79855- if ((mod->module_init) && (mod->init_text_size)) {
79856- set_page_attributes(mod->module_init,
79857- mod->module_init + mod->init_text_size,
79858+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
79859+ set_page_attributes(mod->module_init_rx,
79860+ mod->module_init_rx + mod->init_size_rx,
79861 set_memory_rw);
79862 }
79863 }
79864@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
79865 list_for_each_entry_rcu(mod, &modules, list) {
79866 if (mod->state == MODULE_STATE_UNFORMED)
79867 continue;
79868- if ((mod->module_core) && (mod->core_text_size)) {
79869- set_page_attributes(mod->module_core,
79870- mod->module_core + mod->core_text_size,
79871+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
79872+ set_page_attributes(mod->module_core_rx,
79873+ mod->module_core_rx + mod->core_size_rx,
79874 set_memory_ro);
79875 }
79876- if ((mod->module_init) && (mod->init_text_size)) {
79877- set_page_attributes(mod->module_init,
79878- mod->module_init + mod->init_text_size,
79879+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
79880+ set_page_attributes(mod->module_init_rx,
79881+ mod->module_init_rx + mod->init_size_rx,
79882 set_memory_ro);
79883 }
79884 }
79885@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
79886
79887 /* This may be NULL, but that's OK */
79888 unset_module_init_ro_nx(mod);
79889- module_free(mod, mod->module_init);
79890+ module_free(mod, mod->module_init_rw);
79891+ module_free_exec(mod, mod->module_init_rx);
79892 kfree(mod->args);
79893 percpu_modfree(mod);
79894
79895 /* Free lock-classes: */
79896- lockdep_free_key_range(mod->module_core, mod->core_size);
79897+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
79898+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
79899
79900 /* Finally, free the core (containing the module structure) */
79901 unset_module_core_ro_nx(mod);
79902- module_free(mod, mod->module_core);
79903+ module_free_exec(mod, mod->module_core_rx);
79904+ module_free(mod, mod->module_core_rw);
79905
79906 #ifdef CONFIG_MPU
79907 update_protections(current->mm);
79908@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
79909 int ret = 0;
79910 const struct kernel_symbol *ksym;
79911
79912+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79913+ int is_fs_load = 0;
79914+ int register_filesystem_found = 0;
79915+ char *p;
79916+
79917+ p = strstr(mod->args, "grsec_modharden_fs");
79918+ if (p) {
79919+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
79920+ /* copy \0 as well */
79921+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
79922+ is_fs_load = 1;
79923+ }
79924+#endif
79925+
79926 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
79927 const char *name = info->strtab + sym[i].st_name;
79928
79929+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79930+ /* it's a real shame this will never get ripped and copied
79931+ upstream! ;(
79932+ */
79933+ if (is_fs_load && !strcmp(name, "register_filesystem"))
79934+ register_filesystem_found = 1;
79935+#endif
79936+
79937 switch (sym[i].st_shndx) {
79938 case SHN_COMMON:
79939 /* We compiled with -fno-common. These are not
79940@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
79941 ksym = resolve_symbol_wait(mod, info, name);
79942 /* Ok if resolved. */
79943 if (ksym && !IS_ERR(ksym)) {
79944+ pax_open_kernel();
79945 sym[i].st_value = ksym->value;
79946+ pax_close_kernel();
79947 break;
79948 }
79949
79950@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
79951 secbase = (unsigned long)mod_percpu(mod);
79952 else
79953 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
79954+ pax_open_kernel();
79955 sym[i].st_value += secbase;
79956+ pax_close_kernel();
79957 break;
79958 }
79959 }
79960
79961+#ifdef CONFIG_GRKERNSEC_MODHARDEN
79962+ if (is_fs_load && !register_filesystem_found) {
79963+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
79964+ ret = -EPERM;
79965+ }
79966+#endif
79967+
79968 return ret;
79969 }
79970
79971@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
79972 || s->sh_entsize != ~0UL
79973 || strstarts(sname, ".init"))
79974 continue;
79975- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
79976+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
79977+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
79978+ else
79979+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
79980 pr_debug("\t%s\n", sname);
79981 }
79982- switch (m) {
79983- case 0: /* executable */
79984- mod->core_size = debug_align(mod->core_size);
79985- mod->core_text_size = mod->core_size;
79986- break;
79987- case 1: /* RO: text and ro-data */
79988- mod->core_size = debug_align(mod->core_size);
79989- mod->core_ro_size = mod->core_size;
79990- break;
79991- case 3: /* whole core */
79992- mod->core_size = debug_align(mod->core_size);
79993- break;
79994- }
79995 }
79996
79997 pr_debug("Init section allocation order:\n");
79998@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
79999 || s->sh_entsize != ~0UL
80000 || !strstarts(sname, ".init"))
80001 continue;
80002- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
80003- | INIT_OFFSET_MASK);
80004+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
80005+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
80006+ else
80007+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
80008+ s->sh_entsize |= INIT_OFFSET_MASK;
80009 pr_debug("\t%s\n", sname);
80010 }
80011- switch (m) {
80012- case 0: /* executable */
80013- mod->init_size = debug_align(mod->init_size);
80014- mod->init_text_size = mod->init_size;
80015- break;
80016- case 1: /* RO: text and ro-data */
80017- mod->init_size = debug_align(mod->init_size);
80018- mod->init_ro_size = mod->init_size;
80019- break;
80020- case 3: /* whole init */
80021- mod->init_size = debug_align(mod->init_size);
80022- break;
80023- }
80024 }
80025 }
80026
80027@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
80028
80029 /* Put symbol section at end of init part of module. */
80030 symsect->sh_flags |= SHF_ALLOC;
80031- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
80032+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
80033 info->index.sym) | INIT_OFFSET_MASK;
80034 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
80035
80036@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
80037 }
80038
80039 /* Append room for core symbols at end of core part. */
80040- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
80041- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
80042- mod->core_size += strtab_size;
80043+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
80044+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
80045+ mod->core_size_rx += strtab_size;
80046
80047 /* Put string table section at end of init part of module. */
80048 strsect->sh_flags |= SHF_ALLOC;
80049- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
80050+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
80051 info->index.str) | INIT_OFFSET_MASK;
80052 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
80053 }
80054@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
80055 /* Make sure we get permanent strtab: don't use info->strtab. */
80056 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
80057
80058+ pax_open_kernel();
80059+
80060 /* Set types up while we still have access to sections. */
80061 for (i = 0; i < mod->num_symtab; i++)
80062 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
80063
80064- mod->core_symtab = dst = mod->module_core + info->symoffs;
80065- mod->core_strtab = s = mod->module_core + info->stroffs;
80066+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
80067+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
80068 src = mod->symtab;
80069 for (ndst = i = 0; i < mod->num_symtab; i++) {
80070 if (i == 0 ||
80071@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
80072 }
80073 }
80074 mod->core_num_syms = ndst;
80075+
80076+ pax_close_kernel();
80077 }
80078 #else
80079 static inline void layout_symtab(struct module *mod, struct load_info *info)
80080@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
80081 return vmalloc_exec(size);
80082 }
80083
80084-static void *module_alloc_update_bounds(unsigned long size)
80085+static void *module_alloc_update_bounds_rw(unsigned long size)
80086 {
80087 void *ret = module_alloc(size);
80088
80089 if (ret) {
80090 mutex_lock(&module_mutex);
80091 /* Update module bounds. */
80092- if ((unsigned long)ret < module_addr_min)
80093- module_addr_min = (unsigned long)ret;
80094- if ((unsigned long)ret + size > module_addr_max)
80095- module_addr_max = (unsigned long)ret + size;
80096+ if ((unsigned long)ret < module_addr_min_rw)
80097+ module_addr_min_rw = (unsigned long)ret;
80098+ if ((unsigned long)ret + size > module_addr_max_rw)
80099+ module_addr_max_rw = (unsigned long)ret + size;
80100+ mutex_unlock(&module_mutex);
80101+ }
80102+ return ret;
80103+}
80104+
80105+static void *module_alloc_update_bounds_rx(unsigned long size)
80106+{
80107+ void *ret = module_alloc_exec(size);
80108+
80109+ if (ret) {
80110+ mutex_lock(&module_mutex);
80111+ /* Update module bounds. */
80112+ if ((unsigned long)ret < module_addr_min_rx)
80113+ module_addr_min_rx = (unsigned long)ret;
80114+ if ((unsigned long)ret + size > module_addr_max_rx)
80115+ module_addr_max_rx = (unsigned long)ret + size;
80116 mutex_unlock(&module_mutex);
80117 }
80118 return ret;
80119@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
80120 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
80121 {
80122 const char *modmagic = get_modinfo(info, "vermagic");
80123+ const char *license = get_modinfo(info, "license");
80124 int err;
80125
80126+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
80127+ if (!license || !license_is_gpl_compatible(license))
80128+ return -ENOEXEC;
80129+#endif
80130+
80131 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
80132 modmagic = NULL;
80133
80134@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
80135 }
80136
80137 /* Set up license info based on the info section */
80138- set_license(mod, get_modinfo(info, "license"));
80139+ set_license(mod, license);
80140
80141 return 0;
80142 }
80143@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
80144 void *ptr;
80145
80146 /* Do the allocs. */
80147- ptr = module_alloc_update_bounds(mod->core_size);
80148+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
80149 /*
80150 * The pointer to this block is stored in the module structure
80151 * which is inside the block. Just mark it as not being a
80152@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
80153 if (!ptr)
80154 return -ENOMEM;
80155
80156- memset(ptr, 0, mod->core_size);
80157- mod->module_core = ptr;
80158+ memset(ptr, 0, mod->core_size_rw);
80159+ mod->module_core_rw = ptr;
80160
80161- if (mod->init_size) {
80162- ptr = module_alloc_update_bounds(mod->init_size);
80163+ if (mod->init_size_rw) {
80164+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
80165 /*
80166 * The pointer to this block is stored in the module structure
80167 * which is inside the block. This block doesn't need to be
80168@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
80169 */
80170 kmemleak_ignore(ptr);
80171 if (!ptr) {
80172- module_free(mod, mod->module_core);
80173+ module_free(mod, mod->module_core_rw);
80174 return -ENOMEM;
80175 }
80176- memset(ptr, 0, mod->init_size);
80177- mod->module_init = ptr;
80178+ memset(ptr, 0, mod->init_size_rw);
80179+ mod->module_init_rw = ptr;
80180 } else
80181- mod->module_init = NULL;
80182+ mod->module_init_rw = NULL;
80183+
80184+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
80185+ kmemleak_not_leak(ptr);
80186+ if (!ptr) {
80187+ if (mod->module_init_rw)
80188+ module_free(mod, mod->module_init_rw);
80189+ module_free(mod, mod->module_core_rw);
80190+ return -ENOMEM;
80191+ }
80192+
80193+ pax_open_kernel();
80194+ memset(ptr, 0, mod->core_size_rx);
80195+ pax_close_kernel();
80196+ mod->module_core_rx = ptr;
80197+
80198+ if (mod->init_size_rx) {
80199+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
80200+ kmemleak_ignore(ptr);
80201+ if (!ptr && mod->init_size_rx) {
80202+ module_free_exec(mod, mod->module_core_rx);
80203+ if (mod->module_init_rw)
80204+ module_free(mod, mod->module_init_rw);
80205+ module_free(mod, mod->module_core_rw);
80206+ return -ENOMEM;
80207+ }
80208+
80209+ pax_open_kernel();
80210+ memset(ptr, 0, mod->init_size_rx);
80211+ pax_close_kernel();
80212+ mod->module_init_rx = ptr;
80213+ } else
80214+ mod->module_init_rx = NULL;
80215
80216 /* Transfer each section which specifies SHF_ALLOC */
80217 pr_debug("final section addresses:\n");
80218@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
80219 if (!(shdr->sh_flags & SHF_ALLOC))
80220 continue;
80221
80222- if (shdr->sh_entsize & INIT_OFFSET_MASK)
80223- dest = mod->module_init
80224- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
80225- else
80226- dest = mod->module_core + shdr->sh_entsize;
80227+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
80228+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
80229+ dest = mod->module_init_rw
80230+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
80231+ else
80232+ dest = mod->module_init_rx
80233+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
80234+ } else {
80235+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
80236+ dest = mod->module_core_rw + shdr->sh_entsize;
80237+ else
80238+ dest = mod->module_core_rx + shdr->sh_entsize;
80239+ }
80240+
80241+ if (shdr->sh_type != SHT_NOBITS) {
80242+
80243+#ifdef CONFIG_PAX_KERNEXEC
80244+#ifdef CONFIG_X86_64
80245+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
80246+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
80247+#endif
80248+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
80249+ pax_open_kernel();
80250+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
80251+ pax_close_kernel();
80252+ } else
80253+#endif
80254
80255- if (shdr->sh_type != SHT_NOBITS)
80256 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
80257+ }
80258 /* Update sh_addr to point to copy in image. */
80259- shdr->sh_addr = (unsigned long)dest;
80260+
80261+#ifdef CONFIG_PAX_KERNEXEC
80262+ if (shdr->sh_flags & SHF_EXECINSTR)
80263+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
80264+ else
80265+#endif
80266+
80267+ shdr->sh_addr = (unsigned long)dest;
80268 pr_debug("\t0x%lx %s\n",
80269 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
80270 }
80271@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
80272 * Do it before processing of module parameters, so the module
80273 * can provide parameter accessor functions of its own.
80274 */
80275- if (mod->module_init)
80276- flush_icache_range((unsigned long)mod->module_init,
80277- (unsigned long)mod->module_init
80278- + mod->init_size);
80279- flush_icache_range((unsigned long)mod->module_core,
80280- (unsigned long)mod->module_core + mod->core_size);
80281+ if (mod->module_init_rx)
80282+ flush_icache_range((unsigned long)mod->module_init_rx,
80283+ (unsigned long)mod->module_init_rx
80284+ + mod->init_size_rx);
80285+ flush_icache_range((unsigned long)mod->module_core_rx,
80286+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
80287
80288 set_fs(old_fs);
80289 }
80290@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
80291 static void module_deallocate(struct module *mod, struct load_info *info)
80292 {
80293 percpu_modfree(mod);
80294- module_free(mod, mod->module_init);
80295- module_free(mod, mod->module_core);
80296+ module_free_exec(mod, mod->module_init_rx);
80297+ module_free_exec(mod, mod->module_core_rx);
80298+ module_free(mod, mod->module_init_rw);
80299+ module_free(mod, mod->module_core_rw);
80300 }
80301
80302 int __weak module_finalize(const Elf_Ehdr *hdr,
80303@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
80304 static int post_relocation(struct module *mod, const struct load_info *info)
80305 {
80306 /* Sort exception table now relocations are done. */
80307+ pax_open_kernel();
80308 sort_extable(mod->extable, mod->extable + mod->num_exentries);
80309+ pax_close_kernel();
80310
80311 /* Copy relocated percpu area over. */
80312 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
80313@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
80314 MODULE_STATE_COMING, mod);
80315
80316 /* Set RO and NX regions for core */
80317- set_section_ro_nx(mod->module_core,
80318- mod->core_text_size,
80319- mod->core_ro_size,
80320- mod->core_size);
80321+ set_section_ro_nx(mod->module_core_rx,
80322+ mod->core_size_rx,
80323+ mod->core_size_rx,
80324+ mod->core_size_rx);
80325
80326 /* Set RO and NX regions for init */
80327- set_section_ro_nx(mod->module_init,
80328- mod->init_text_size,
80329- mod->init_ro_size,
80330- mod->init_size);
80331+ set_section_ro_nx(mod->module_init_rx,
80332+ mod->init_size_rx,
80333+ mod->init_size_rx,
80334+ mod->init_size_rx);
80335
80336 do_mod_ctors(mod);
80337 /* Start the module */
80338@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
80339 mod->strtab = mod->core_strtab;
80340 #endif
80341 unset_module_init_ro_nx(mod);
80342- module_free(mod, mod->module_init);
80343- mod->module_init = NULL;
80344- mod->init_size = 0;
80345- mod->init_ro_size = 0;
80346- mod->init_text_size = 0;
80347+ module_free(mod, mod->module_init_rw);
80348+ module_free_exec(mod, mod->module_init_rx);
80349+ mod->module_init_rw = NULL;
80350+ mod->module_init_rx = NULL;
80351+ mod->init_size_rw = 0;
80352+ mod->init_size_rx = 0;
80353 mutex_unlock(&module_mutex);
80354 wake_up_all(&module_wq);
80355
80356@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
80357 if (err)
80358 goto free_unload;
80359
80360+ /* Now copy in args */
80361+ mod->args = strndup_user(uargs, ~0UL >> 1);
80362+ if (IS_ERR(mod->args)) {
80363+ err = PTR_ERR(mod->args);
80364+ goto free_unload;
80365+ }
80366+
80367 /* Set up MODINFO_ATTR fields */
80368 setup_modinfo(mod, info);
80369
80370+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80371+ {
80372+ char *p, *p2;
80373+
80374+ if (strstr(mod->args, "grsec_modharden_netdev")) {
80375+ 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);
80376+ err = -EPERM;
80377+ goto free_modinfo;
80378+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
80379+ p += sizeof("grsec_modharden_normal") - 1;
80380+ p2 = strstr(p, "_");
80381+ if (p2) {
80382+ *p2 = '\0';
80383+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
80384+ *p2 = '_';
80385+ }
80386+ err = -EPERM;
80387+ goto free_modinfo;
80388+ }
80389+ }
80390+#endif
80391+
80392 /* Fix up syms, so that st_value is a pointer to location. */
80393 err = simplify_symbols(mod, info);
80394 if (err < 0)
80395@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
80396
80397 flush_module_icache(mod);
80398
80399- /* Now copy in args */
80400- mod->args = strndup_user(uargs, ~0UL >> 1);
80401- if (IS_ERR(mod->args)) {
80402- err = PTR_ERR(mod->args);
80403- goto free_arch_cleanup;
80404- }
80405-
80406 dynamic_debug_setup(info->debug, info->num_debug);
80407
80408 /* Finally it's fully formed, ready to start executing. */
80409@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
80410 ddebug_cleanup:
80411 dynamic_debug_remove(info->debug);
80412 synchronize_sched();
80413- kfree(mod->args);
80414- free_arch_cleanup:
80415 module_arch_cleanup(mod);
80416 free_modinfo:
80417 free_modinfo(mod);
80418+ kfree(mod->args);
80419 free_unload:
80420 module_unload_free(mod);
80421 unlink_mod:
80422@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
80423 unsigned long nextval;
80424
80425 /* At worse, next value is at end of module */
80426- if (within_module_init(addr, mod))
80427- nextval = (unsigned long)mod->module_init+mod->init_text_size;
80428+ if (within_module_init_rx(addr, mod))
80429+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
80430+ else if (within_module_init_rw(addr, mod))
80431+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
80432+ else if (within_module_core_rx(addr, mod))
80433+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
80434+ else if (within_module_core_rw(addr, mod))
80435+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
80436 else
80437- nextval = (unsigned long)mod->module_core+mod->core_text_size;
80438+ return NULL;
80439
80440 /* Scan for closest preceding symbol, and next symbol. (ELF
80441 starts real symbols at 1). */
80442@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
80443 return 0;
80444
80445 seq_printf(m, "%s %u",
80446- mod->name, mod->init_size + mod->core_size);
80447+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
80448 print_unload_info(m, mod);
80449
80450 /* Informative for users. */
80451@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
80452 mod->state == MODULE_STATE_COMING ? "Loading":
80453 "Live");
80454 /* Used by oprofile and other similar tools. */
80455- seq_printf(m, " 0x%pK", mod->module_core);
80456+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
80457
80458 /* Taints info */
80459 if (mod->taints)
80460@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
80461
80462 static int __init proc_modules_init(void)
80463 {
80464+#ifndef CONFIG_GRKERNSEC_HIDESYM
80465+#ifdef CONFIG_GRKERNSEC_PROC_USER
80466+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
80467+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80468+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
80469+#else
80470 proc_create("modules", 0, NULL, &proc_modules_operations);
80471+#endif
80472+#else
80473+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
80474+#endif
80475 return 0;
80476 }
80477 module_init(proc_modules_init);
80478@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
80479 {
80480 struct module *mod;
80481
80482- if (addr < module_addr_min || addr > module_addr_max)
80483+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
80484+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
80485 return NULL;
80486
80487 list_for_each_entry_rcu(mod, &modules, list) {
80488 if (mod->state == MODULE_STATE_UNFORMED)
80489 continue;
80490- if (within_module_core(addr, mod)
80491- || within_module_init(addr, mod))
80492+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
80493 return mod;
80494 }
80495 return NULL;
80496@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
80497 */
80498 struct module *__module_text_address(unsigned long addr)
80499 {
80500- struct module *mod = __module_address(addr);
80501+ struct module *mod;
80502+
80503+#ifdef CONFIG_X86_32
80504+ addr = ktla_ktva(addr);
80505+#endif
80506+
80507+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
80508+ return NULL;
80509+
80510+ mod = __module_address(addr);
80511+
80512 if (mod) {
80513 /* Make sure it's within the text section. */
80514- if (!within(addr, mod->module_init, mod->init_text_size)
80515- && !within(addr, mod->module_core, mod->core_text_size))
80516+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
80517 mod = NULL;
80518 }
80519 return mod;
80520diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
80521index 7e3443f..b2a1e6b 100644
80522--- a/kernel/mutex-debug.c
80523+++ b/kernel/mutex-debug.c
80524@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
80525 }
80526
80527 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
80528- struct thread_info *ti)
80529+ struct task_struct *task)
80530 {
80531 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
80532
80533 /* Mark the current thread as blocked on the lock: */
80534- ti->task->blocked_on = waiter;
80535+ task->blocked_on = waiter;
80536 }
80537
80538 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
80539- struct thread_info *ti)
80540+ struct task_struct *task)
80541 {
80542 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
80543- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
80544- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
80545- ti->task->blocked_on = NULL;
80546+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
80547+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
80548+ task->blocked_on = NULL;
80549
80550 list_del_init(&waiter->list);
80551 waiter->task = NULL;
80552diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
80553index 0799fd3..d06ae3b 100644
80554--- a/kernel/mutex-debug.h
80555+++ b/kernel/mutex-debug.h
80556@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
80557 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
80558 extern void debug_mutex_add_waiter(struct mutex *lock,
80559 struct mutex_waiter *waiter,
80560- struct thread_info *ti);
80561+ struct task_struct *task);
80562 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
80563- struct thread_info *ti);
80564+ struct task_struct *task);
80565 extern void debug_mutex_unlock(struct mutex *lock);
80566 extern void debug_mutex_init(struct mutex *lock, const char *name,
80567 struct lock_class_key *key);
80568diff --git a/kernel/mutex.c b/kernel/mutex.c
80569index ad53a66..f1bf8bc 100644
80570--- a/kernel/mutex.c
80571+++ b/kernel/mutex.c
80572@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
80573 node->locked = 1;
80574 return;
80575 }
80576- ACCESS_ONCE(prev->next) = node;
80577+ ACCESS_ONCE_RW(prev->next) = node;
80578 smp_wmb();
80579 /* Wait until the lock holder passes the lock down */
80580 while (!ACCESS_ONCE(node->locked))
80581@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
80582 while (!(next = ACCESS_ONCE(node->next)))
80583 arch_mutex_cpu_relax();
80584 }
80585- ACCESS_ONCE(next->locked) = 1;
80586+ ACCESS_ONCE_RW(next->locked) = 1;
80587 smp_wmb();
80588 }
80589
80590@@ -341,7 +341,7 @@ slowpath:
80591 spin_lock_mutex(&lock->wait_lock, flags);
80592
80593 debug_mutex_lock_common(lock, &waiter);
80594- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
80595+ debug_mutex_add_waiter(lock, &waiter, task);
80596
80597 /* add waiting tasks to the end of the waitqueue (FIFO): */
80598 list_add_tail(&waiter.list, &lock->wait_list);
80599@@ -371,8 +371,7 @@ slowpath:
80600 * TASK_UNINTERRUPTIBLE case.)
80601 */
80602 if (unlikely(signal_pending_state(state, task))) {
80603- mutex_remove_waiter(lock, &waiter,
80604- task_thread_info(task));
80605+ mutex_remove_waiter(lock, &waiter, task);
80606 mutex_release(&lock->dep_map, 1, ip);
80607 spin_unlock_mutex(&lock->wait_lock, flags);
80608
80609@@ -391,7 +390,7 @@ slowpath:
80610 done:
80611 lock_acquired(&lock->dep_map, ip);
80612 /* got the lock - rejoice! */
80613- mutex_remove_waiter(lock, &waiter, current_thread_info());
80614+ mutex_remove_waiter(lock, &waiter, task);
80615 mutex_set_owner(lock);
80616
80617 /* set it to 0 if there are no waiters left: */
80618diff --git a/kernel/notifier.c b/kernel/notifier.c
80619index 2d5cc4c..d9ea600 100644
80620--- a/kernel/notifier.c
80621+++ b/kernel/notifier.c
80622@@ -5,6 +5,7 @@
80623 #include <linux/rcupdate.h>
80624 #include <linux/vmalloc.h>
80625 #include <linux/reboot.h>
80626+#include <linux/mm.h>
80627
80628 /*
80629 * Notifier list for kernel code which wants to be called
80630@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
80631 while ((*nl) != NULL) {
80632 if (n->priority > (*nl)->priority)
80633 break;
80634- nl = &((*nl)->next);
80635+ nl = (struct notifier_block **)&((*nl)->next);
80636 }
80637- n->next = *nl;
80638+ pax_open_kernel();
80639+ *(const void **)&n->next = *nl;
80640 rcu_assign_pointer(*nl, n);
80641+ pax_close_kernel();
80642 return 0;
80643 }
80644
80645@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
80646 return 0;
80647 if (n->priority > (*nl)->priority)
80648 break;
80649- nl = &((*nl)->next);
80650+ nl = (struct notifier_block **)&((*nl)->next);
80651 }
80652- n->next = *nl;
80653+ pax_open_kernel();
80654+ *(const void **)&n->next = *nl;
80655 rcu_assign_pointer(*nl, n);
80656+ pax_close_kernel();
80657 return 0;
80658 }
80659
80660@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
80661 {
80662 while ((*nl) != NULL) {
80663 if ((*nl) == n) {
80664+ pax_open_kernel();
80665 rcu_assign_pointer(*nl, n->next);
80666+ pax_close_kernel();
80667 return 0;
80668 }
80669- nl = &((*nl)->next);
80670+ nl = (struct notifier_block **)&((*nl)->next);
80671 }
80672 return -ENOENT;
80673 }
80674diff --git a/kernel/panic.c b/kernel/panic.c
80675index 167ec09..0dda5f9 100644
80676--- a/kernel/panic.c
80677+++ b/kernel/panic.c
80678@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
80679 unsigned taint, struct slowpath_args *args)
80680 {
80681 printk(KERN_WARNING "------------[ cut here ]------------\n");
80682- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
80683+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
80684
80685 if (args)
80686 vprintk(args->fmt, args->args);
80687@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
80688 */
80689 void __stack_chk_fail(void)
80690 {
80691- panic("stack-protector: Kernel stack is corrupted in: %p\n",
80692+ dump_stack();
80693+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
80694 __builtin_return_address(0));
80695 }
80696 EXPORT_SYMBOL(__stack_chk_fail);
80697diff --git a/kernel/pid.c b/kernel/pid.c
80698index 0db3e79..95b9dc2 100644
80699--- a/kernel/pid.c
80700+++ b/kernel/pid.c
80701@@ -33,6 +33,7 @@
80702 #include <linux/rculist.h>
80703 #include <linux/bootmem.h>
80704 #include <linux/hash.h>
80705+#include <linux/security.h>
80706 #include <linux/pid_namespace.h>
80707 #include <linux/init_task.h>
80708 #include <linux/syscalls.h>
80709@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
80710
80711 int pid_max = PID_MAX_DEFAULT;
80712
80713-#define RESERVED_PIDS 300
80714+#define RESERVED_PIDS 500
80715
80716 int pid_max_min = RESERVED_PIDS + 1;
80717 int pid_max_max = PID_MAX_LIMIT;
80718@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
80719 */
80720 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
80721 {
80722+ struct task_struct *task;
80723+
80724 rcu_lockdep_assert(rcu_read_lock_held(),
80725 "find_task_by_pid_ns() needs rcu_read_lock()"
80726 " protection");
80727- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
80728+
80729+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
80730+
80731+ if (gr_pid_is_chrooted(task))
80732+ return NULL;
80733+
80734+ return task;
80735 }
80736
80737 struct task_struct *find_task_by_vpid(pid_t vnr)
80738@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
80739 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
80740 }
80741
80742+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
80743+{
80744+ rcu_lockdep_assert(rcu_read_lock_held(),
80745+ "find_task_by_pid_ns() needs rcu_read_lock()"
80746+ " protection");
80747+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
80748+}
80749+
80750 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
80751 {
80752 struct pid *pid;
80753diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
80754index 6917e8e..9909aeb 100644
80755--- a/kernel/pid_namespace.c
80756+++ b/kernel/pid_namespace.c
80757@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
80758 void __user *buffer, size_t *lenp, loff_t *ppos)
80759 {
80760 struct pid_namespace *pid_ns = task_active_pid_ns(current);
80761- struct ctl_table tmp = *table;
80762+ ctl_table_no_const tmp = *table;
80763
80764 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
80765 return -EPERM;
80766diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
80767index 42670e9..8719c2f 100644
80768--- a/kernel/posix-cpu-timers.c
80769+++ b/kernel/posix-cpu-timers.c
80770@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
80771
80772 static __init int init_posix_cpu_timers(void)
80773 {
80774- struct k_clock process = {
80775+ static struct k_clock process = {
80776 .clock_getres = process_cpu_clock_getres,
80777 .clock_get = process_cpu_clock_get,
80778 .timer_create = process_cpu_timer_create,
80779 .nsleep = process_cpu_nsleep,
80780 .nsleep_restart = process_cpu_nsleep_restart,
80781 };
80782- struct k_clock thread = {
80783+ static struct k_clock thread = {
80784 .clock_getres = thread_cpu_clock_getres,
80785 .clock_get = thread_cpu_clock_get,
80786 .timer_create = thread_cpu_timer_create,
80787diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
80788index 424c2d4..679242f 100644
80789--- a/kernel/posix-timers.c
80790+++ b/kernel/posix-timers.c
80791@@ -43,6 +43,7 @@
80792 #include <linux/hash.h>
80793 #include <linux/posix-clock.h>
80794 #include <linux/posix-timers.h>
80795+#include <linux/grsecurity.h>
80796 #include <linux/syscalls.h>
80797 #include <linux/wait.h>
80798 #include <linux/workqueue.h>
80799@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
80800 * which we beg off on and pass to do_sys_settimeofday().
80801 */
80802
80803-static struct k_clock posix_clocks[MAX_CLOCKS];
80804+static struct k_clock *posix_clocks[MAX_CLOCKS];
80805
80806 /*
80807 * These ones are defined below.
80808@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
80809 */
80810 static __init int init_posix_timers(void)
80811 {
80812- struct k_clock clock_realtime = {
80813+ static struct k_clock clock_realtime = {
80814 .clock_getres = hrtimer_get_res,
80815 .clock_get = posix_clock_realtime_get,
80816 .clock_set = posix_clock_realtime_set,
80817@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
80818 .timer_get = common_timer_get,
80819 .timer_del = common_timer_del,
80820 };
80821- struct k_clock clock_monotonic = {
80822+ static struct k_clock clock_monotonic = {
80823 .clock_getres = hrtimer_get_res,
80824 .clock_get = posix_ktime_get_ts,
80825 .nsleep = common_nsleep,
80826@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
80827 .timer_get = common_timer_get,
80828 .timer_del = common_timer_del,
80829 };
80830- struct k_clock clock_monotonic_raw = {
80831+ static struct k_clock clock_monotonic_raw = {
80832 .clock_getres = hrtimer_get_res,
80833 .clock_get = posix_get_monotonic_raw,
80834 };
80835- struct k_clock clock_realtime_coarse = {
80836+ static struct k_clock clock_realtime_coarse = {
80837 .clock_getres = posix_get_coarse_res,
80838 .clock_get = posix_get_realtime_coarse,
80839 };
80840- struct k_clock clock_monotonic_coarse = {
80841+ static struct k_clock clock_monotonic_coarse = {
80842 .clock_getres = posix_get_coarse_res,
80843 .clock_get = posix_get_monotonic_coarse,
80844 };
80845- struct k_clock clock_tai = {
80846+ static struct k_clock clock_tai = {
80847 .clock_getres = hrtimer_get_res,
80848 .clock_get = posix_get_tai,
80849 .nsleep = common_nsleep,
80850@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
80851 .timer_get = common_timer_get,
80852 .timer_del = common_timer_del,
80853 };
80854- struct k_clock clock_boottime = {
80855+ static struct k_clock clock_boottime = {
80856 .clock_getres = hrtimer_get_res,
80857 .clock_get = posix_get_boottime,
80858 .nsleep = common_nsleep,
80859@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
80860 return;
80861 }
80862
80863- posix_clocks[clock_id] = *new_clock;
80864+ posix_clocks[clock_id] = new_clock;
80865 }
80866 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
80867
80868@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
80869 return (id & CLOCKFD_MASK) == CLOCKFD ?
80870 &clock_posix_dynamic : &clock_posix_cpu;
80871
80872- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
80873+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
80874 return NULL;
80875- return &posix_clocks[id];
80876+ return posix_clocks[id];
80877 }
80878
80879 static int common_timer_create(struct k_itimer *new_timer)
80880@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
80881 struct k_clock *kc = clockid_to_kclock(which_clock);
80882 struct k_itimer *new_timer;
80883 int error, new_timer_id;
80884- sigevent_t event;
80885+ sigevent_t event = { };
80886 int it_id_set = IT_ID_NOT_SET;
80887
80888 if (!kc)
80889@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
80890 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
80891 return -EFAULT;
80892
80893+ /* only the CLOCK_REALTIME clock can be set, all other clocks
80894+ have their clock_set fptr set to a nosettime dummy function
80895+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
80896+ call common_clock_set, which calls do_sys_settimeofday, which
80897+ we hook
80898+ */
80899+
80900 return kc->clock_set(which_clock, &new_tp);
80901 }
80902
80903diff --git a/kernel/power/process.c b/kernel/power/process.c
80904index 98088e0..aaf95c0 100644
80905--- a/kernel/power/process.c
80906+++ b/kernel/power/process.c
80907@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
80908 u64 elapsed_csecs64;
80909 unsigned int elapsed_csecs;
80910 bool wakeup = false;
80911+ bool timedout = false;
80912
80913 do_gettimeofday(&start);
80914
80915@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
80916
80917 while (true) {
80918 todo = 0;
80919+ if (time_after(jiffies, end_time))
80920+ timedout = true;
80921 read_lock(&tasklist_lock);
80922 do_each_thread(g, p) {
80923 if (p == current || !freeze_task(p))
80924 continue;
80925
80926- if (!freezer_should_skip(p))
80927+ if (!freezer_should_skip(p)) {
80928 todo++;
80929+ if (timedout) {
80930+ printk(KERN_ERR "Task refusing to freeze:\n");
80931+ sched_show_task(p);
80932+ }
80933+ }
80934 } while_each_thread(g, p);
80935 read_unlock(&tasklist_lock);
80936
80937@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
80938 todo += wq_busy;
80939 }
80940
80941- if (!todo || time_after(jiffies, end_time))
80942+ if (!todo || timedout)
80943 break;
80944
80945 if (pm_wakeup_pending()) {
80946diff --git a/kernel/printk.c b/kernel/printk.c
80947index d37d45c..ab918b3 100644
80948--- a/kernel/printk.c
80949+++ b/kernel/printk.c
80950@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
80951 if (from_file && type != SYSLOG_ACTION_OPEN)
80952 return 0;
80953
80954+#ifdef CONFIG_GRKERNSEC_DMESG
80955+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
80956+ return -EPERM;
80957+#endif
80958+
80959 if (syslog_action_restricted(type)) {
80960 if (capable(CAP_SYSLOG))
80961 return 0;
80962diff --git a/kernel/profile.c b/kernel/profile.c
80963index 0bf4007..6234708 100644
80964--- a/kernel/profile.c
80965+++ b/kernel/profile.c
80966@@ -37,7 +37,7 @@ struct profile_hit {
80967 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
80968 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
80969
80970-static atomic_t *prof_buffer;
80971+static atomic_unchecked_t *prof_buffer;
80972 static unsigned long prof_len, prof_shift;
80973
80974 int prof_on __read_mostly;
80975@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
80976 hits[i].pc = 0;
80977 continue;
80978 }
80979- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
80980+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
80981 hits[i].hits = hits[i].pc = 0;
80982 }
80983 }
80984@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
80985 * Add the current hit(s) and flush the write-queue out
80986 * to the global buffer:
80987 */
80988- atomic_add(nr_hits, &prof_buffer[pc]);
80989+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
80990 for (i = 0; i < NR_PROFILE_HIT; ++i) {
80991- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
80992+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
80993 hits[i].pc = hits[i].hits = 0;
80994 }
80995 out:
80996@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
80997 {
80998 unsigned long pc;
80999 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
81000- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
81001+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
81002 }
81003 #endif /* !CONFIG_SMP */
81004
81005@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
81006 return -EFAULT;
81007 buf++; p++; count--; read++;
81008 }
81009- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
81010+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
81011 if (copy_to_user(buf, (void *)pnt, count))
81012 return -EFAULT;
81013 read += count;
81014@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
81015 }
81016 #endif
81017 profile_discard_flip_buffers();
81018- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
81019+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
81020 return count;
81021 }
81022
81023diff --git a/kernel/ptrace.c b/kernel/ptrace.c
81024index 335a7ae..3bbbceb 100644
81025--- a/kernel/ptrace.c
81026+++ b/kernel/ptrace.c
81027@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
81028 if (seize)
81029 flags |= PT_SEIZED;
81030 rcu_read_lock();
81031- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
81032+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
81033 flags |= PT_PTRACE_CAP;
81034 rcu_read_unlock();
81035 task->ptrace = flags;
81036@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
81037 break;
81038 return -EIO;
81039 }
81040- if (copy_to_user(dst, buf, retval))
81041+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
81042 return -EFAULT;
81043 copied += retval;
81044 src += retval;
81045@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
81046 bool seized = child->ptrace & PT_SEIZED;
81047 int ret = -EIO;
81048 siginfo_t siginfo, *si;
81049- void __user *datavp = (void __user *) data;
81050+ void __user *datavp = (__force void __user *) data;
81051 unsigned long __user *datalp = datavp;
81052 unsigned long flags;
81053
81054@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
81055 goto out;
81056 }
81057
81058+ if (gr_handle_ptrace(child, request)) {
81059+ ret = -EPERM;
81060+ goto out_put_task_struct;
81061+ }
81062+
81063 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
81064 ret = ptrace_attach(child, request, addr, data);
81065 /*
81066 * Some architectures need to do book-keeping after
81067 * a ptrace attach.
81068 */
81069- if (!ret)
81070+ if (!ret) {
81071 arch_ptrace_attach(child);
81072+ gr_audit_ptrace(child);
81073+ }
81074 goto out_put_task_struct;
81075 }
81076
81077@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
81078 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
81079 if (copied != sizeof(tmp))
81080 return -EIO;
81081- return put_user(tmp, (unsigned long __user *)data);
81082+ return put_user(tmp, (__force unsigned long __user *)data);
81083 }
81084
81085 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
81086@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
81087 }
81088
81089 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81090- compat_long_t addr, compat_long_t data)
81091+ compat_ulong_t addr, compat_ulong_t data)
81092 {
81093 struct task_struct *child;
81094 long ret;
81095@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81096 goto out;
81097 }
81098
81099+ if (gr_handle_ptrace(child, request)) {
81100+ ret = -EPERM;
81101+ goto out_put_task_struct;
81102+ }
81103+
81104 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
81105 ret = ptrace_attach(child, request, addr, data);
81106 /*
81107 * Some architectures need to do book-keeping after
81108 * a ptrace attach.
81109 */
81110- if (!ret)
81111+ if (!ret) {
81112 arch_ptrace_attach(child);
81113+ gr_audit_ptrace(child);
81114+ }
81115 goto out_put_task_struct;
81116 }
81117
81118diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
81119index 48ab703..07561d4 100644
81120--- a/kernel/rcupdate.c
81121+++ b/kernel/rcupdate.c
81122@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
81123 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
81124 */
81125 if (till_stall_check < 3) {
81126- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
81127+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
81128 till_stall_check = 3;
81129 } else if (till_stall_check > 300) {
81130- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
81131+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
81132 till_stall_check = 300;
81133 }
81134 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
81135diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
81136index a0714a5..2ab5e34 100644
81137--- a/kernel/rcutiny.c
81138+++ b/kernel/rcutiny.c
81139@@ -46,7 +46,7 @@
81140 struct rcu_ctrlblk;
81141 static void invoke_rcu_callbacks(void);
81142 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
81143-static void rcu_process_callbacks(struct softirq_action *unused);
81144+static void rcu_process_callbacks(void);
81145 static void __call_rcu(struct rcu_head *head,
81146 void (*func)(struct rcu_head *rcu),
81147 struct rcu_ctrlblk *rcp);
81148@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
81149 rcu_is_callbacks_kthread()));
81150 }
81151
81152-static void rcu_process_callbacks(struct softirq_action *unused)
81153+static void rcu_process_callbacks(void)
81154 {
81155 __rcu_process_callbacks(&rcu_sched_ctrlblk);
81156 __rcu_process_callbacks(&rcu_bh_ctrlblk);
81157diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
81158index 8a23300..4255818 100644
81159--- a/kernel/rcutiny_plugin.h
81160+++ b/kernel/rcutiny_plugin.h
81161@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
81162 have_rcu_kthread_work = morework;
81163 local_irq_restore(flags);
81164 if (work)
81165- rcu_process_callbacks(NULL);
81166+ rcu_process_callbacks();
81167 schedule_timeout_interruptible(1); /* Leave CPU for others. */
81168 }
81169
81170diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
81171index e1f3a8c..42c94a2 100644
81172--- a/kernel/rcutorture.c
81173+++ b/kernel/rcutorture.c
81174@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
81175 { 0 };
81176 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
81177 { 0 };
81178-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
81179-static atomic_t n_rcu_torture_alloc;
81180-static atomic_t n_rcu_torture_alloc_fail;
81181-static atomic_t n_rcu_torture_free;
81182-static atomic_t n_rcu_torture_mberror;
81183-static atomic_t n_rcu_torture_error;
81184+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
81185+static atomic_unchecked_t n_rcu_torture_alloc;
81186+static atomic_unchecked_t n_rcu_torture_alloc_fail;
81187+static atomic_unchecked_t n_rcu_torture_free;
81188+static atomic_unchecked_t n_rcu_torture_mberror;
81189+static atomic_unchecked_t n_rcu_torture_error;
81190 static long n_rcu_torture_barrier_error;
81191 static long n_rcu_torture_boost_ktrerror;
81192 static long n_rcu_torture_boost_rterror;
81193@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
81194
81195 spin_lock_bh(&rcu_torture_lock);
81196 if (list_empty(&rcu_torture_freelist)) {
81197- atomic_inc(&n_rcu_torture_alloc_fail);
81198+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
81199 spin_unlock_bh(&rcu_torture_lock);
81200 return NULL;
81201 }
81202- atomic_inc(&n_rcu_torture_alloc);
81203+ atomic_inc_unchecked(&n_rcu_torture_alloc);
81204 p = rcu_torture_freelist.next;
81205 list_del_init(p);
81206 spin_unlock_bh(&rcu_torture_lock);
81207@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
81208 static void
81209 rcu_torture_free(struct rcu_torture *p)
81210 {
81211- atomic_inc(&n_rcu_torture_free);
81212+ atomic_inc_unchecked(&n_rcu_torture_free);
81213 spin_lock_bh(&rcu_torture_lock);
81214 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
81215 spin_unlock_bh(&rcu_torture_lock);
81216@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
81217 i = rp->rtort_pipe_count;
81218 if (i > RCU_TORTURE_PIPE_LEN)
81219 i = RCU_TORTURE_PIPE_LEN;
81220- atomic_inc(&rcu_torture_wcount[i]);
81221+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
81222 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
81223 rp->rtort_mbtest = 0;
81224 rcu_torture_free(rp);
81225@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
81226 i = rp->rtort_pipe_count;
81227 if (i > RCU_TORTURE_PIPE_LEN)
81228 i = RCU_TORTURE_PIPE_LEN;
81229- atomic_inc(&rcu_torture_wcount[i]);
81230+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
81231 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
81232 rp->rtort_mbtest = 0;
81233 list_del(&rp->rtort_free);
81234@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
81235 i = old_rp->rtort_pipe_count;
81236 if (i > RCU_TORTURE_PIPE_LEN)
81237 i = RCU_TORTURE_PIPE_LEN;
81238- atomic_inc(&rcu_torture_wcount[i]);
81239+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
81240 old_rp->rtort_pipe_count++;
81241 cur_ops->deferred_free(old_rp);
81242 }
81243@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
81244 return;
81245 }
81246 if (p->rtort_mbtest == 0)
81247- atomic_inc(&n_rcu_torture_mberror);
81248+ atomic_inc_unchecked(&n_rcu_torture_mberror);
81249 spin_lock(&rand_lock);
81250 cur_ops->read_delay(&rand);
81251 n_rcu_torture_timers++;
81252@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
81253 continue;
81254 }
81255 if (p->rtort_mbtest == 0)
81256- atomic_inc(&n_rcu_torture_mberror);
81257+ atomic_inc_unchecked(&n_rcu_torture_mberror);
81258 cur_ops->read_delay(&rand);
81259 preempt_disable();
81260 pipe_count = p->rtort_pipe_count;
81261@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
81262 rcu_torture_current,
81263 rcu_torture_current_version,
81264 list_empty(&rcu_torture_freelist),
81265- atomic_read(&n_rcu_torture_alloc),
81266- atomic_read(&n_rcu_torture_alloc_fail),
81267- atomic_read(&n_rcu_torture_free));
81268+ atomic_read_unchecked(&n_rcu_torture_alloc),
81269+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
81270+ atomic_read_unchecked(&n_rcu_torture_free));
81271 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
81272- atomic_read(&n_rcu_torture_mberror),
81273+ atomic_read_unchecked(&n_rcu_torture_mberror),
81274 n_rcu_torture_boost_ktrerror,
81275 n_rcu_torture_boost_rterror);
81276 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
81277@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
81278 n_barrier_attempts,
81279 n_rcu_torture_barrier_error);
81280 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
81281- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
81282+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
81283 n_rcu_torture_barrier_error != 0 ||
81284 n_rcu_torture_boost_ktrerror != 0 ||
81285 n_rcu_torture_boost_rterror != 0 ||
81286 n_rcu_torture_boost_failure != 0 ||
81287 i > 1) {
81288 cnt += sprintf(&page[cnt], "!!! ");
81289- atomic_inc(&n_rcu_torture_error);
81290+ atomic_inc_unchecked(&n_rcu_torture_error);
81291 WARN_ON_ONCE(1);
81292 }
81293 cnt += sprintf(&page[cnt], "Reader Pipe: ");
81294@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
81295 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
81296 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
81297 cnt += sprintf(&page[cnt], " %d",
81298- atomic_read(&rcu_torture_wcount[i]));
81299+ atomic_read_unchecked(&rcu_torture_wcount[i]));
81300 }
81301 cnt += sprintf(&page[cnt], "\n");
81302 if (cur_ops->stats)
81303@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
81304
81305 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
81306
81307- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
81308+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
81309 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
81310 else if (n_online_successes != n_online_attempts ||
81311 n_offline_successes != n_offline_attempts)
81312@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
81313
81314 rcu_torture_current = NULL;
81315 rcu_torture_current_version = 0;
81316- atomic_set(&n_rcu_torture_alloc, 0);
81317- atomic_set(&n_rcu_torture_alloc_fail, 0);
81318- atomic_set(&n_rcu_torture_free, 0);
81319- atomic_set(&n_rcu_torture_mberror, 0);
81320- atomic_set(&n_rcu_torture_error, 0);
81321+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
81322+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
81323+ atomic_set_unchecked(&n_rcu_torture_free, 0);
81324+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
81325+ atomic_set_unchecked(&n_rcu_torture_error, 0);
81326 n_rcu_torture_barrier_error = 0;
81327 n_rcu_torture_boost_ktrerror = 0;
81328 n_rcu_torture_boost_rterror = 0;
81329 n_rcu_torture_boost_failure = 0;
81330 n_rcu_torture_boosts = 0;
81331 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
81332- atomic_set(&rcu_torture_wcount[i], 0);
81333+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
81334 for_each_possible_cpu(cpu) {
81335 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
81336 per_cpu(rcu_torture_count, cpu)[i] = 0;
81337diff --git a/kernel/rcutree.c b/kernel/rcutree.c
81338index 3538001..e379e0b 100644
81339--- a/kernel/rcutree.c
81340+++ b/kernel/rcutree.c
81341@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
81342 rcu_prepare_for_idle(smp_processor_id());
81343 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
81344 smp_mb__before_atomic_inc(); /* See above. */
81345- atomic_inc(&rdtp->dynticks);
81346+ atomic_inc_unchecked(&rdtp->dynticks);
81347 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
81348- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
81349+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
81350
81351 /*
81352 * It is illegal to enter an extended quiescent state while
81353@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
81354 int user)
81355 {
81356 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
81357- atomic_inc(&rdtp->dynticks);
81358+ atomic_inc_unchecked(&rdtp->dynticks);
81359 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
81360 smp_mb__after_atomic_inc(); /* See above. */
81361- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
81362+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
81363 rcu_cleanup_after_idle(smp_processor_id());
81364 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
81365 if (!user && !is_idle_task(current)) {
81366@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
81367 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
81368
81369 if (rdtp->dynticks_nmi_nesting == 0 &&
81370- (atomic_read(&rdtp->dynticks) & 0x1))
81371+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
81372 return;
81373 rdtp->dynticks_nmi_nesting++;
81374 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
81375- atomic_inc(&rdtp->dynticks);
81376+ atomic_inc_unchecked(&rdtp->dynticks);
81377 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
81378 smp_mb__after_atomic_inc(); /* See above. */
81379- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
81380+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
81381 }
81382
81383 /**
81384@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
81385 return;
81386 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
81387 smp_mb__before_atomic_inc(); /* See above. */
81388- atomic_inc(&rdtp->dynticks);
81389+ atomic_inc_unchecked(&rdtp->dynticks);
81390 smp_mb__after_atomic_inc(); /* Force delay to next write. */
81391- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
81392+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
81393 }
81394
81395 /**
81396@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
81397 int ret;
81398
81399 preempt_disable();
81400- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
81401+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
81402 preempt_enable();
81403 return ret;
81404 }
81405@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
81406 */
81407 static int dyntick_save_progress_counter(struct rcu_data *rdp)
81408 {
81409- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
81410+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
81411 return (rdp->dynticks_snap & 0x1) == 0;
81412 }
81413
81414@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
81415 unsigned int curr;
81416 unsigned int snap;
81417
81418- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
81419+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
81420 snap = (unsigned int)rdp->dynticks_snap;
81421
81422 /*
81423@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
81424 rdp = this_cpu_ptr(rsp->rda);
81425 rcu_preempt_check_blocked_tasks(rnp);
81426 rnp->qsmask = rnp->qsmaskinit;
81427- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
81428+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
81429 WARN_ON_ONCE(rnp->completed != rsp->completed);
81430- ACCESS_ONCE(rnp->completed) = rsp->completed;
81431+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
81432 if (rnp == rdp->mynode)
81433 rcu_start_gp_per_cpu(rsp, rnp, rdp);
81434 rcu_preempt_boost_start_gp(rnp);
81435@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
81436 */
81437 rcu_for_each_node_breadth_first(rsp, rnp) {
81438 raw_spin_lock_irq(&rnp->lock);
81439- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
81440+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
81441 rdp = this_cpu_ptr(rsp->rda);
81442 if (rnp == rdp->mynode)
81443 __rcu_process_gp_end(rsp, rnp, rdp);
81444@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
81445 rsp->qlen += rdp->qlen;
81446 rdp->n_cbs_orphaned += rdp->qlen;
81447 rdp->qlen_lazy = 0;
81448- ACCESS_ONCE(rdp->qlen) = 0;
81449+ ACCESS_ONCE_RW(rdp->qlen) = 0;
81450 }
81451
81452 /*
81453@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
81454 }
81455 smp_mb(); /* List handling before counting for rcu_barrier(). */
81456 rdp->qlen_lazy -= count_lazy;
81457- ACCESS_ONCE(rdp->qlen) -= count;
81458+ ACCESS_ONCE_RW(rdp->qlen) -= count;
81459 rdp->n_cbs_invoked += count;
81460
81461 /* Reinstate batch limit if we have worked down the excess. */
81462@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
81463 /*
81464 * Do RCU core processing for the current CPU.
81465 */
81466-static void rcu_process_callbacks(struct softirq_action *unused)
81467+static void rcu_process_callbacks(void)
81468 {
81469 struct rcu_state *rsp;
81470
81471@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
81472 local_irq_restore(flags);
81473 return;
81474 }
81475- ACCESS_ONCE(rdp->qlen)++;
81476+ ACCESS_ONCE_RW(rdp->qlen)++;
81477 if (lazy)
81478 rdp->qlen_lazy++;
81479 else
81480@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
81481 * counter wrap on a 32-bit system. Quite a few more CPUs would of
81482 * course be required on a 64-bit system.
81483 */
81484- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
81485+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
81486 (ulong)atomic_long_read(&rsp->expedited_done) +
81487 ULONG_MAX / 8)) {
81488 synchronize_sched();
81489- atomic_long_inc(&rsp->expedited_wrap);
81490+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
81491 return;
81492 }
81493
81494@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
81495 * Take a ticket. Note that atomic_inc_return() implies a
81496 * full memory barrier.
81497 */
81498- snap = atomic_long_inc_return(&rsp->expedited_start);
81499+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
81500 firstsnap = snap;
81501 get_online_cpus();
81502 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
81503@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
81504 synchronize_sched_expedited_cpu_stop,
81505 NULL) == -EAGAIN) {
81506 put_online_cpus();
81507- atomic_long_inc(&rsp->expedited_tryfail);
81508+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
81509
81510 /* Check to see if someone else did our work for us. */
81511 s = atomic_long_read(&rsp->expedited_done);
81512 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
81513 /* ensure test happens before caller kfree */
81514 smp_mb__before_atomic_inc(); /* ^^^ */
81515- atomic_long_inc(&rsp->expedited_workdone1);
81516+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
81517 return;
81518 }
81519
81520@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
81521 udelay(trycount * num_online_cpus());
81522 } else {
81523 wait_rcu_gp(call_rcu_sched);
81524- atomic_long_inc(&rsp->expedited_normal);
81525+ atomic_long_inc_unchecked(&rsp->expedited_normal);
81526 return;
81527 }
81528
81529@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
81530 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
81531 /* ensure test happens before caller kfree */
81532 smp_mb__before_atomic_inc(); /* ^^^ */
81533- atomic_long_inc(&rsp->expedited_workdone2);
81534+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
81535 return;
81536 }
81537
81538@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
81539 * period works for us.
81540 */
81541 get_online_cpus();
81542- snap = atomic_long_read(&rsp->expedited_start);
81543+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
81544 smp_mb(); /* ensure read is before try_stop_cpus(). */
81545 }
81546- atomic_long_inc(&rsp->expedited_stoppedcpus);
81547+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
81548
81549 /*
81550 * Everyone up to our most recent fetch is covered by our grace
81551@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
81552 * than we did already did their update.
81553 */
81554 do {
81555- atomic_long_inc(&rsp->expedited_done_tries);
81556+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
81557 s = atomic_long_read(&rsp->expedited_done);
81558 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
81559 /* ensure test happens before caller kfree */
81560 smp_mb__before_atomic_inc(); /* ^^^ */
81561- atomic_long_inc(&rsp->expedited_done_lost);
81562+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
81563 break;
81564 }
81565 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
81566- atomic_long_inc(&rsp->expedited_done_exit);
81567+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
81568
81569 put_online_cpus();
81570 }
81571@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
81572 * ACCESS_ONCE() to prevent the compiler from speculating
81573 * the increment to precede the early-exit check.
81574 */
81575- ACCESS_ONCE(rsp->n_barrier_done)++;
81576+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
81577 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
81578 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
81579 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
81580@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
81581
81582 /* Increment ->n_barrier_done to prevent duplicate work. */
81583 smp_mb(); /* Keep increment after above mechanism. */
81584- ACCESS_ONCE(rsp->n_barrier_done)++;
81585+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
81586 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
81587 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
81588 smp_mb(); /* Keep increment before caller's subsequent code. */
81589@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
81590 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
81591 init_callback_list(rdp);
81592 rdp->qlen_lazy = 0;
81593- ACCESS_ONCE(rdp->qlen) = 0;
81594+ ACCESS_ONCE_RW(rdp->qlen) = 0;
81595 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
81596 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
81597- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
81598+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
81599 rdp->cpu = cpu;
81600 rdp->rsp = rsp;
81601 rcu_boot_init_nocb_percpu_data(rdp);
81602@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
81603 rdp->blimit = blimit;
81604 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
81605 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
81606- atomic_set(&rdp->dynticks->dynticks,
81607- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
81608+ atomic_set_unchecked(&rdp->dynticks->dynticks,
81609+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
81610 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
81611
81612 /* Add CPU to rcu_node bitmasks. */
81613@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
81614 struct task_struct *t;
81615
81616 for_each_rcu_flavor(rsp) {
81617- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
81618+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
81619 BUG_ON(IS_ERR(t));
81620 rnp = rcu_get_root(rsp);
81621 raw_spin_lock_irqsave(&rnp->lock, flags);
81622diff --git a/kernel/rcutree.h b/kernel/rcutree.h
81623index 4df5034..5ee93f2 100644
81624--- a/kernel/rcutree.h
81625+++ b/kernel/rcutree.h
81626@@ -87,7 +87,7 @@ struct rcu_dynticks {
81627 long long dynticks_nesting; /* Track irq/process nesting level. */
81628 /* Process level is worth LLONG_MAX/2. */
81629 int dynticks_nmi_nesting; /* Track NMI nesting level. */
81630- atomic_t dynticks; /* Even value for idle, else odd. */
81631+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
81632 #ifdef CONFIG_RCU_FAST_NO_HZ
81633 bool all_lazy; /* Are all CPU's CBs lazy? */
81634 unsigned long nonlazy_posted;
81635@@ -414,17 +414,17 @@ struct rcu_state {
81636 /* _rcu_barrier(). */
81637 /* End of fields guarded by barrier_mutex. */
81638
81639- atomic_long_t expedited_start; /* Starting ticket. */
81640- atomic_long_t expedited_done; /* Done ticket. */
81641- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
81642- atomic_long_t expedited_tryfail; /* # acquisition failures. */
81643- atomic_long_t expedited_workdone1; /* # done by others #1. */
81644- atomic_long_t expedited_workdone2; /* # done by others #2. */
81645- atomic_long_t expedited_normal; /* # fallbacks to normal. */
81646- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
81647- atomic_long_t expedited_done_tries; /* # tries to update _done. */
81648- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
81649- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
81650+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
81651+ atomic_long_t expedited_done; /* Done ticket. */
81652+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
81653+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
81654+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
81655+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
81656+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
81657+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
81658+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
81659+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
81660+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
81661
81662 unsigned long jiffies_force_qs; /* Time at which to invoke */
81663 /* force_quiescent_state(). */
81664diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
81665index 3db5a37..b395fb35 100644
81666--- a/kernel/rcutree_plugin.h
81667+++ b/kernel/rcutree_plugin.h
81668@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
81669
81670 /* Clean up and exit. */
81671 smp_mb(); /* ensure expedited GP seen before counter increment. */
81672- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
81673+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
81674 unlock_mb_ret:
81675 mutex_unlock(&sync_rcu_preempt_exp_mutex);
81676 mb_ret:
81677@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
81678 free_cpumask_var(cm);
81679 }
81680
81681-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
81682+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
81683 .store = &rcu_cpu_kthread_task,
81684 .thread_should_run = rcu_cpu_kthread_should_run,
81685 .thread_fn = rcu_cpu_kthread,
81686@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
81687 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
81688 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
81689 cpu, ticks_value, ticks_title,
81690- atomic_read(&rdtp->dynticks) & 0xfff,
81691+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
81692 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
81693 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
81694 fast_no_hz);
81695@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
81696
81697 /* Enqueue the callback on the nocb list and update counts. */
81698 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
81699- ACCESS_ONCE(*old_rhpp) = rhp;
81700+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
81701 atomic_long_add(rhcount, &rdp->nocb_q_count);
81702 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
81703
81704@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
81705 * Extract queued callbacks, update counts, and wait
81706 * for a grace period to elapse.
81707 */
81708- ACCESS_ONCE(rdp->nocb_head) = NULL;
81709+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
81710 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
81711 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
81712 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
81713- ACCESS_ONCE(rdp->nocb_p_count) += c;
81714- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
81715+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
81716+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
81717 rcu_nocb_wait_gp(rdp);
81718
81719 /* Each pass through the following loop invokes a callback. */
81720@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
81721 list = next;
81722 }
81723 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
81724- ACCESS_ONCE(rdp->nocb_p_count) -= c;
81725- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
81726+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
81727+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
81728 rdp->n_nocbs_invoked += c;
81729 }
81730 return 0;
81731@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
81732 t = kthread_run(rcu_nocb_kthread, rdp,
81733 "rcuo%c/%d", rsp->abbr, cpu);
81734 BUG_ON(IS_ERR(t));
81735- ACCESS_ONCE(rdp->nocb_kthread) = t;
81736+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
81737 }
81738 }
81739
81740diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
81741index cf6c174..a8f4b50 100644
81742--- a/kernel/rcutree_trace.c
81743+++ b/kernel/rcutree_trace.c
81744@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
81745 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
81746 rdp->passed_quiesce, rdp->qs_pending);
81747 seq_printf(m, " dt=%d/%llx/%d df=%lu",
81748- atomic_read(&rdp->dynticks->dynticks),
81749+ atomic_read_unchecked(&rdp->dynticks->dynticks),
81750 rdp->dynticks->dynticks_nesting,
81751 rdp->dynticks->dynticks_nmi_nesting,
81752 rdp->dynticks_fqs);
81753@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
81754 struct rcu_state *rsp = (struct rcu_state *)m->private;
81755
81756 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",
81757- atomic_long_read(&rsp->expedited_start),
81758+ atomic_long_read_unchecked(&rsp->expedited_start),
81759 atomic_long_read(&rsp->expedited_done),
81760- atomic_long_read(&rsp->expedited_wrap),
81761- atomic_long_read(&rsp->expedited_tryfail),
81762- atomic_long_read(&rsp->expedited_workdone1),
81763- atomic_long_read(&rsp->expedited_workdone2),
81764- atomic_long_read(&rsp->expedited_normal),
81765- atomic_long_read(&rsp->expedited_stoppedcpus),
81766- atomic_long_read(&rsp->expedited_done_tries),
81767- atomic_long_read(&rsp->expedited_done_lost),
81768- atomic_long_read(&rsp->expedited_done_exit));
81769+ atomic_long_read_unchecked(&rsp->expedited_wrap),
81770+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
81771+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
81772+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
81773+ atomic_long_read_unchecked(&rsp->expedited_normal),
81774+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
81775+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
81776+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
81777+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
81778 return 0;
81779 }
81780
81781diff --git a/kernel/resource.c b/kernel/resource.c
81782index d738698..5f8e60a 100644
81783--- a/kernel/resource.c
81784+++ b/kernel/resource.c
81785@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
81786
81787 static int __init ioresources_init(void)
81788 {
81789+#ifdef CONFIG_GRKERNSEC_PROC_ADD
81790+#ifdef CONFIG_GRKERNSEC_PROC_USER
81791+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
81792+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
81793+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81794+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
81795+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
81796+#endif
81797+#else
81798 proc_create("ioports", 0, NULL, &proc_ioports_operations);
81799 proc_create("iomem", 0, NULL, &proc_iomem_operations);
81800+#endif
81801 return 0;
81802 }
81803 __initcall(ioresources_init);
81804diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
81805index 1d96dd0..994ff19 100644
81806--- a/kernel/rtmutex-tester.c
81807+++ b/kernel/rtmutex-tester.c
81808@@ -22,7 +22,7 @@
81809 #define MAX_RT_TEST_MUTEXES 8
81810
81811 static spinlock_t rttest_lock;
81812-static atomic_t rttest_event;
81813+static atomic_unchecked_t rttest_event;
81814
81815 struct test_thread_data {
81816 int opcode;
81817@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
81818
81819 case RTTEST_LOCKCONT:
81820 td->mutexes[td->opdata] = 1;
81821- td->event = atomic_add_return(1, &rttest_event);
81822+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81823 return 0;
81824
81825 case RTTEST_RESET:
81826@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
81827 return 0;
81828
81829 case RTTEST_RESETEVENT:
81830- atomic_set(&rttest_event, 0);
81831+ atomic_set_unchecked(&rttest_event, 0);
81832 return 0;
81833
81834 default:
81835@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
81836 return ret;
81837
81838 td->mutexes[id] = 1;
81839- td->event = atomic_add_return(1, &rttest_event);
81840+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81841 rt_mutex_lock(&mutexes[id]);
81842- td->event = atomic_add_return(1, &rttest_event);
81843+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81844 td->mutexes[id] = 4;
81845 return 0;
81846
81847@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
81848 return ret;
81849
81850 td->mutexes[id] = 1;
81851- td->event = atomic_add_return(1, &rttest_event);
81852+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81853 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
81854- td->event = atomic_add_return(1, &rttest_event);
81855+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81856 td->mutexes[id] = ret ? 0 : 4;
81857 return ret ? -EINTR : 0;
81858
81859@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
81860 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
81861 return ret;
81862
81863- td->event = atomic_add_return(1, &rttest_event);
81864+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81865 rt_mutex_unlock(&mutexes[id]);
81866- td->event = atomic_add_return(1, &rttest_event);
81867+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81868 td->mutexes[id] = 0;
81869 return 0;
81870
81871@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
81872 break;
81873
81874 td->mutexes[dat] = 2;
81875- td->event = atomic_add_return(1, &rttest_event);
81876+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81877 break;
81878
81879 default:
81880@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
81881 return;
81882
81883 td->mutexes[dat] = 3;
81884- td->event = atomic_add_return(1, &rttest_event);
81885+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81886 break;
81887
81888 case RTTEST_LOCKNOWAIT:
81889@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
81890 return;
81891
81892 td->mutexes[dat] = 1;
81893- td->event = atomic_add_return(1, &rttest_event);
81894+ td->event = atomic_add_return_unchecked(1, &rttest_event);
81895 return;
81896
81897 default:
81898diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
81899index 64de5f8..7735e12 100644
81900--- a/kernel/sched/auto_group.c
81901+++ b/kernel/sched/auto_group.c
81902@@ -11,7 +11,7 @@
81903
81904 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
81905 static struct autogroup autogroup_default;
81906-static atomic_t autogroup_seq_nr;
81907+static atomic_unchecked_t autogroup_seq_nr;
81908
81909 void __init autogroup_init(struct task_struct *init_task)
81910 {
81911@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
81912
81913 kref_init(&ag->kref);
81914 init_rwsem(&ag->lock);
81915- ag->id = atomic_inc_return(&autogroup_seq_nr);
81916+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
81917 ag->tg = tg;
81918 #ifdef CONFIG_RT_GROUP_SCHED
81919 /*
81920diff --git a/kernel/sched/core.c b/kernel/sched/core.c
81921index e8b3350..d83d44e 100644
81922--- a/kernel/sched/core.c
81923+++ b/kernel/sched/core.c
81924@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
81925 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
81926 * positive (at least 1, or number of jiffies left till timeout) if completed.
81927 */
81928-long __sched
81929+long __sched __intentional_overflow(-1)
81930 wait_for_completion_interruptible_timeout(struct completion *x,
81931 unsigned long timeout)
81932 {
81933@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
81934 *
81935 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
81936 */
81937-int __sched wait_for_completion_killable(struct completion *x)
81938+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
81939 {
81940 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
81941 if (t == -ERESTARTSYS)
81942@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
81943 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
81944 * positive (at least 1, or number of jiffies left till timeout) if completed.
81945 */
81946-long __sched
81947+long __sched __intentional_overflow(-1)
81948 wait_for_completion_killable_timeout(struct completion *x,
81949 unsigned long timeout)
81950 {
81951@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
81952 /* convert nice value [19,-20] to rlimit style value [1,40] */
81953 int nice_rlim = 20 - nice;
81954
81955+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
81956+
81957 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
81958 capable(CAP_SYS_NICE));
81959 }
81960@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
81961 if (nice > 19)
81962 nice = 19;
81963
81964- if (increment < 0 && !can_nice(current, nice))
81965+ if (increment < 0 && (!can_nice(current, nice) ||
81966+ gr_handle_chroot_nice()))
81967 return -EPERM;
81968
81969 retval = security_task_setnice(current, nice);
81970@@ -3891,6 +3894,7 @@ recheck:
81971 unsigned long rlim_rtprio =
81972 task_rlimit(p, RLIMIT_RTPRIO);
81973
81974+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
81975 /* can't set/change the rt policy */
81976 if (policy != p->policy && !rlim_rtprio)
81977 return -EPERM;
81978@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
81979
81980 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
81981
81982-static struct ctl_table sd_ctl_dir[] = {
81983+static ctl_table_no_const sd_ctl_dir[] __read_only = {
81984 {
81985 .procname = "sched_domain",
81986 .mode = 0555,
81987@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
81988 {}
81989 };
81990
81991-static struct ctl_table *sd_alloc_ctl_entry(int n)
81992+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
81993 {
81994- struct ctl_table *entry =
81995+ ctl_table_no_const *entry =
81996 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
81997
81998 return entry;
81999 }
82000
82001-static void sd_free_ctl_entry(struct ctl_table **tablep)
82002+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
82003 {
82004- struct ctl_table *entry;
82005+ ctl_table_no_const *entry;
82006
82007 /*
82008 * In the intermediate directories, both the child directory and
82009@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
82010 * will always be set. In the lowest directory the names are
82011 * static strings and all have proc handlers.
82012 */
82013- for (entry = *tablep; entry->mode; entry++) {
82014- if (entry->child)
82015- sd_free_ctl_entry(&entry->child);
82016+ for (entry = tablep; entry->mode; entry++) {
82017+ if (entry->child) {
82018+ sd_free_ctl_entry(entry->child);
82019+ pax_open_kernel();
82020+ entry->child = NULL;
82021+ pax_close_kernel();
82022+ }
82023 if (entry->proc_handler == NULL)
82024 kfree(entry->procname);
82025 }
82026
82027- kfree(*tablep);
82028- *tablep = NULL;
82029+ kfree(tablep);
82030 }
82031
82032 static int min_load_idx = 0;
82033 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
82034
82035 static void
82036-set_table_entry(struct ctl_table *entry,
82037+set_table_entry(ctl_table_no_const *entry,
82038 const char *procname, void *data, int maxlen,
82039 umode_t mode, proc_handler *proc_handler,
82040 bool load_idx)
82041@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
82042 static struct ctl_table *
82043 sd_alloc_ctl_domain_table(struct sched_domain *sd)
82044 {
82045- struct ctl_table *table = sd_alloc_ctl_entry(13);
82046+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
82047
82048 if (table == NULL)
82049 return NULL;
82050@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
82051 return table;
82052 }
82053
82054-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
82055+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
82056 {
82057- struct ctl_table *entry, *table;
82058+ ctl_table_no_const *entry, *table;
82059 struct sched_domain *sd;
82060 int domain_num = 0, i;
82061 char buf[32];
82062@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
82063 static void register_sched_domain_sysctl(void)
82064 {
82065 int i, cpu_num = num_possible_cpus();
82066- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
82067+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
82068 char buf[32];
82069
82070 WARN_ON(sd_ctl_dir[0].child);
82071+ pax_open_kernel();
82072 sd_ctl_dir[0].child = entry;
82073+ pax_close_kernel();
82074
82075 if (entry == NULL)
82076 return;
82077@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
82078 if (sd_sysctl_header)
82079 unregister_sysctl_table(sd_sysctl_header);
82080 sd_sysctl_header = NULL;
82081- if (sd_ctl_dir[0].child)
82082- sd_free_ctl_entry(&sd_ctl_dir[0].child);
82083+ if (sd_ctl_dir[0].child) {
82084+ sd_free_ctl_entry(sd_ctl_dir[0].child);
82085+ pax_open_kernel();
82086+ sd_ctl_dir[0].child = NULL;
82087+ pax_close_kernel();
82088+ }
82089 }
82090 #else
82091 static void register_sched_domain_sysctl(void)
82092@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
82093 * happens before everything else. This has to be lower priority than
82094 * the notifier in the perf_event subsystem, though.
82095 */
82096-static struct notifier_block __cpuinitdata migration_notifier = {
82097+static struct notifier_block migration_notifier = {
82098 .notifier_call = migration_call,
82099 .priority = CPU_PRI_MIGRATION,
82100 };
82101diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
82102index c61a614..d7f3d7e 100644
82103--- a/kernel/sched/fair.c
82104+++ b/kernel/sched/fair.c
82105@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
82106
82107 static void reset_ptenuma_scan(struct task_struct *p)
82108 {
82109- ACCESS_ONCE(p->mm->numa_scan_seq)++;
82110+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
82111 p->mm->numa_scan_offset = 0;
82112 }
82113
82114@@ -5686,7 +5686,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
82115 * run_rebalance_domains is triggered when needed from the scheduler tick.
82116 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
82117 */
82118-static void run_rebalance_domains(struct softirq_action *h)
82119+static void run_rebalance_domains(void)
82120 {
82121 int this_cpu = smp_processor_id();
82122 struct rq *this_rq = cpu_rq(this_cpu);
82123diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
82124index ce39224d..0e09343 100644
82125--- a/kernel/sched/sched.h
82126+++ b/kernel/sched/sched.h
82127@@ -1009,7 +1009,7 @@ struct sched_class {
82128 #ifdef CONFIG_FAIR_GROUP_SCHED
82129 void (*task_move_group) (struct task_struct *p, int on_rq);
82130 #endif
82131-};
82132+} __do_const;
82133
82134 #define sched_class_highest (&stop_sched_class)
82135 #define for_each_class(class) \
82136diff --git a/kernel/signal.c b/kernel/signal.c
82137index 113411b..20d0a99 100644
82138--- a/kernel/signal.c
82139+++ b/kernel/signal.c
82140@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
82141
82142 int print_fatal_signals __read_mostly;
82143
82144-static void __user *sig_handler(struct task_struct *t, int sig)
82145+static __sighandler_t sig_handler(struct task_struct *t, int sig)
82146 {
82147 return t->sighand->action[sig - 1].sa.sa_handler;
82148 }
82149
82150-static int sig_handler_ignored(void __user *handler, int sig)
82151+static int sig_handler_ignored(__sighandler_t handler, int sig)
82152 {
82153 /* Is it explicitly or implicitly ignored? */
82154 return handler == SIG_IGN ||
82155@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
82156
82157 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
82158 {
82159- void __user *handler;
82160+ __sighandler_t handler;
82161
82162 handler = sig_handler(t, sig);
82163
82164@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
82165 atomic_inc(&user->sigpending);
82166 rcu_read_unlock();
82167
82168+ if (!override_rlimit)
82169+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
82170+
82171 if (override_rlimit ||
82172 atomic_read(&user->sigpending) <=
82173 task_rlimit(t, RLIMIT_SIGPENDING)) {
82174@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
82175
82176 int unhandled_signal(struct task_struct *tsk, int sig)
82177 {
82178- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
82179+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
82180 if (is_global_init(tsk))
82181 return 1;
82182 if (handler != SIG_IGN && handler != SIG_DFL)
82183@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
82184 }
82185 }
82186
82187+ /* allow glibc communication via tgkill to other threads in our
82188+ thread group */
82189+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
82190+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
82191+ && gr_handle_signal(t, sig))
82192+ return -EPERM;
82193+
82194 return security_task_kill(t, info, sig, 0);
82195 }
82196
82197@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
82198 return send_signal(sig, info, p, 1);
82199 }
82200
82201-static int
82202+int
82203 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
82204 {
82205 return send_signal(sig, info, t, 0);
82206@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
82207 unsigned long int flags;
82208 int ret, blocked, ignored;
82209 struct k_sigaction *action;
82210+ int is_unhandled = 0;
82211
82212 spin_lock_irqsave(&t->sighand->siglock, flags);
82213 action = &t->sighand->action[sig-1];
82214@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
82215 }
82216 if (action->sa.sa_handler == SIG_DFL)
82217 t->signal->flags &= ~SIGNAL_UNKILLABLE;
82218+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
82219+ is_unhandled = 1;
82220 ret = specific_send_sig_info(sig, info, t);
82221 spin_unlock_irqrestore(&t->sighand->siglock, flags);
82222
82223+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
82224+ normal operation */
82225+ if (is_unhandled) {
82226+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
82227+ gr_handle_crash(t, sig);
82228+ }
82229+
82230 return ret;
82231 }
82232
82233@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
82234 ret = check_kill_permission(sig, info, p);
82235 rcu_read_unlock();
82236
82237- if (!ret && sig)
82238+ if (!ret && sig) {
82239 ret = do_send_sig_info(sig, info, p, true);
82240+ if (!ret)
82241+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
82242+ }
82243
82244 return ret;
82245 }
82246@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
82247 int error = -ESRCH;
82248
82249 rcu_read_lock();
82250- p = find_task_by_vpid(pid);
82251+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82252+ /* allow glibc communication via tgkill to other threads in our
82253+ thread group */
82254+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
82255+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
82256+ p = find_task_by_vpid_unrestricted(pid);
82257+ else
82258+#endif
82259+ p = find_task_by_vpid(pid);
82260 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
82261 error = check_kill_permission(sig, info, p);
82262 /*
82263@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
82264 __put_user(t->sas_ss_size, &uss->ss_size);
82265 }
82266
82267+#ifdef CONFIG_X86
82268+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
82269+{
82270+ struct task_struct *t = current;
82271+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
82272+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
82273+ put_user_ex(t->sas_ss_size, &uss->ss_size);
82274+}
82275+#endif
82276+
82277 #ifdef CONFIG_COMPAT
82278 COMPAT_SYSCALL_DEFINE2(sigaltstack,
82279 const compat_stack_t __user *, uss_ptr,
82280@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
82281 }
82282 seg = get_fs();
82283 set_fs(KERNEL_DS);
82284- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
82285- (stack_t __force __user *) &uoss,
82286+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
82287+ (stack_t __force_user *) &uoss,
82288 compat_user_stack_pointer());
82289 set_fs(seg);
82290 if (ret >= 0 && uoss_ptr) {
82291@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
82292 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
82293 __put_user(t->sas_ss_size, &uss->ss_size);
82294 }
82295+
82296+#ifdef CONFIG_X86
82297+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
82298+{
82299+ struct task_struct *t = current;
82300+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
82301+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
82302+ put_user_ex(t->sas_ss_size, &uss->ss_size);
82303+}
82304+#endif
82305 #endif
82306
82307 #ifdef __ARCH_WANT_SYS_SIGPENDING
82308diff --git a/kernel/smp.c b/kernel/smp.c
82309index 4dba0f7..fe9f773 100644
82310--- a/kernel/smp.c
82311+++ b/kernel/smp.c
82312@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
82313 return NOTIFY_OK;
82314 }
82315
82316-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
82317+static struct notifier_block hotplug_cfd_notifier = {
82318 .notifier_call = hotplug_cfd,
82319 };
82320
82321diff --git a/kernel/smpboot.c b/kernel/smpboot.c
82322index 02fc5c9..e54c335 100644
82323--- a/kernel/smpboot.c
82324+++ b/kernel/smpboot.c
82325@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
82326 }
82327 smpboot_unpark_thread(plug_thread, cpu);
82328 }
82329- list_add(&plug_thread->list, &hotplug_threads);
82330+ pax_list_add(&plug_thread->list, &hotplug_threads);
82331 out:
82332 mutex_unlock(&smpboot_threads_lock);
82333 return ret;
82334@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
82335 {
82336 get_online_cpus();
82337 mutex_lock(&smpboot_threads_lock);
82338- list_del(&plug_thread->list);
82339+ pax_list_del(&plug_thread->list);
82340 smpboot_destroy_threads(plug_thread);
82341 mutex_unlock(&smpboot_threads_lock);
82342 put_online_cpus();
82343diff --git a/kernel/softirq.c b/kernel/softirq.c
82344index 3d6833f..da6d93d 100644
82345--- a/kernel/softirq.c
82346+++ b/kernel/softirq.c
82347@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
82348 EXPORT_SYMBOL(irq_stat);
82349 #endif
82350
82351-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
82352+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
82353
82354 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
82355
82356-char *softirq_to_name[NR_SOFTIRQS] = {
82357+const char * const softirq_to_name[NR_SOFTIRQS] = {
82358 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
82359 "TASKLET", "SCHED", "HRTIMER", "RCU"
82360 };
82361@@ -250,7 +250,7 @@ restart:
82362 kstat_incr_softirqs_this_cpu(vec_nr);
82363
82364 trace_softirq_entry(vec_nr);
82365- h->action(h);
82366+ h->action();
82367 trace_softirq_exit(vec_nr);
82368 if (unlikely(prev_count != preempt_count())) {
82369 printk(KERN_ERR "huh, entered softirq %u %s %p"
82370@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
82371 or_softirq_pending(1UL << nr);
82372 }
82373
82374-void open_softirq(int nr, void (*action)(struct softirq_action *))
82375+void __init open_softirq(int nr, void (*action)(void))
82376 {
82377 softirq_vec[nr].action = action;
82378 }
82379@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
82380
82381 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
82382
82383-static void tasklet_action(struct softirq_action *a)
82384+static void tasklet_action(void)
82385 {
82386 struct tasklet_struct *list;
82387
82388@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
82389 }
82390 }
82391
82392-static void tasklet_hi_action(struct softirq_action *a)
82393+static void tasklet_hi_action(void)
82394 {
82395 struct tasklet_struct *list;
82396
82397@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
82398 return NOTIFY_OK;
82399 }
82400
82401-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
82402+static struct notifier_block remote_softirq_cpu_notifier = {
82403 .notifier_call = remote_softirq_cpu_notify,
82404 };
82405
82406@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
82407 return NOTIFY_OK;
82408 }
82409
82410-static struct notifier_block __cpuinitdata cpu_nfb = {
82411+static struct notifier_block cpu_nfb = {
82412 .notifier_call = cpu_callback
82413 };
82414
82415-static struct smp_hotplug_thread softirq_threads = {
82416+static struct smp_hotplug_thread softirq_threads __read_only = {
82417 .store = &ksoftirqd,
82418 .thread_should_run = ksoftirqd_should_run,
82419 .thread_fn = run_ksoftirqd,
82420diff --git a/kernel/srcu.c b/kernel/srcu.c
82421index 01d5ccb..cdcbee6 100644
82422--- a/kernel/srcu.c
82423+++ b/kernel/srcu.c
82424@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
82425
82426 idx = ACCESS_ONCE(sp->completed) & 0x1;
82427 preempt_disable();
82428- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
82429+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
82430 smp_mb(); /* B */ /* Avoid leaking the critical section. */
82431- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
82432+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
82433 preempt_enable();
82434 return idx;
82435 }
82436diff --git a/kernel/sys.c b/kernel/sys.c
82437index 2bbd9a7..0875671 100644
82438--- a/kernel/sys.c
82439+++ b/kernel/sys.c
82440@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
82441 error = -EACCES;
82442 goto out;
82443 }
82444+
82445+ if (gr_handle_chroot_setpriority(p, niceval)) {
82446+ error = -EACCES;
82447+ goto out;
82448+ }
82449+
82450 no_nice = security_task_setnice(p, niceval);
82451 if (no_nice) {
82452 error = no_nice;
82453@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
82454 goto error;
82455 }
82456
82457+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
82458+ goto error;
82459+
82460 if (rgid != (gid_t) -1 ||
82461 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
82462 new->sgid = new->egid;
82463@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
82464 old = current_cred();
82465
82466 retval = -EPERM;
82467+
82468+ if (gr_check_group_change(kgid, kgid, kgid))
82469+ goto error;
82470+
82471 if (nsown_capable(CAP_SETGID))
82472 new->gid = new->egid = new->sgid = new->fsgid = kgid;
82473 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
82474@@ -678,7 +691,7 @@ error:
82475 /*
82476 * change the user struct in a credentials set to match the new UID
82477 */
82478-static int set_user(struct cred *new)
82479+int set_user(struct cred *new)
82480 {
82481 struct user_struct *new_user;
82482
82483@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
82484 goto error;
82485 }
82486
82487+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
82488+ goto error;
82489+
82490 if (!uid_eq(new->uid, old->uid)) {
82491 retval = set_user(new);
82492 if (retval < 0)
82493@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
82494 old = current_cred();
82495
82496 retval = -EPERM;
82497+
82498+ if (gr_check_crash_uid(kuid))
82499+ goto error;
82500+ if (gr_check_user_change(kuid, kuid, kuid))
82501+ goto error;
82502+
82503 if (nsown_capable(CAP_SETUID)) {
82504 new->suid = new->uid = kuid;
82505 if (!uid_eq(kuid, old->uid)) {
82506@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
82507 goto error;
82508 }
82509
82510+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
82511+ goto error;
82512+
82513 if (ruid != (uid_t) -1) {
82514 new->uid = kruid;
82515 if (!uid_eq(kruid, old->uid)) {
82516@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
82517 goto error;
82518 }
82519
82520+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
82521+ goto error;
82522+
82523 if (rgid != (gid_t) -1)
82524 new->gid = krgid;
82525 if (egid != (gid_t) -1)
82526@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
82527 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
82528 nsown_capable(CAP_SETUID)) {
82529 if (!uid_eq(kuid, old->fsuid)) {
82530+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
82531+ goto error;
82532+
82533 new->fsuid = kuid;
82534 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
82535 goto change_okay;
82536 }
82537 }
82538
82539+error:
82540 abort_creds(new);
82541 return old_fsuid;
82542
82543@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
82544 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
82545 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
82546 nsown_capable(CAP_SETGID)) {
82547+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
82548+ goto error;
82549+
82550 if (!gid_eq(kgid, old->fsgid)) {
82551 new->fsgid = kgid;
82552 goto change_okay;
82553 }
82554 }
82555
82556+error:
82557 abort_creds(new);
82558 return old_fsgid;
82559
82560@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
82561 return -EFAULT;
82562
82563 down_read(&uts_sem);
82564- error = __copy_to_user(&name->sysname, &utsname()->sysname,
82565+ error = __copy_to_user(name->sysname, &utsname()->sysname,
82566 __OLD_UTS_LEN);
82567 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
82568- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
82569+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
82570 __OLD_UTS_LEN);
82571 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
82572- error |= __copy_to_user(&name->release, &utsname()->release,
82573+ error |= __copy_to_user(name->release, &utsname()->release,
82574 __OLD_UTS_LEN);
82575 error |= __put_user(0, name->release + __OLD_UTS_LEN);
82576- error |= __copy_to_user(&name->version, &utsname()->version,
82577+ error |= __copy_to_user(name->version, &utsname()->version,
82578 __OLD_UTS_LEN);
82579 error |= __put_user(0, name->version + __OLD_UTS_LEN);
82580- error |= __copy_to_user(&name->machine, &utsname()->machine,
82581+ error |= __copy_to_user(name->machine, &utsname()->machine,
82582 __OLD_UTS_LEN);
82583 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
82584 up_read(&uts_sem);
82585@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
82586 */
82587 new_rlim->rlim_cur = 1;
82588 }
82589+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
82590+ is changed to a lower value. Since tasks can be created by the same
82591+ user in between this limit change and an execve by this task, force
82592+ a recheck only for this task by setting PF_NPROC_EXCEEDED
82593+ */
82594+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
82595+ tsk->flags |= PF_NPROC_EXCEEDED;
82596 }
82597 if (!retval) {
82598 if (old_rlim)
82599diff --git a/kernel/sysctl.c b/kernel/sysctl.c
82600index 9edcf45..713c960 100644
82601--- a/kernel/sysctl.c
82602+++ b/kernel/sysctl.c
82603@@ -93,7 +93,6 @@
82604
82605
82606 #if defined(CONFIG_SYSCTL)
82607-
82608 /* External variables not in a header file. */
82609 extern int sysctl_overcommit_memory;
82610 extern int sysctl_overcommit_ratio;
82611@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
82612
82613 /* Constants used for minimum and maximum */
82614 #ifdef CONFIG_LOCKUP_DETECTOR
82615-static int sixty = 60;
82616-static int neg_one = -1;
82617+static int sixty __read_only = 60;
82618 #endif
82619
82620-static int zero;
82621-static int __maybe_unused one = 1;
82622-static int __maybe_unused two = 2;
82623-static int __maybe_unused three = 3;
82624-static unsigned long one_ul = 1;
82625-static int one_hundred = 100;
82626+static int neg_one __read_only = -1;
82627+static int zero __read_only = 0;
82628+static int __maybe_unused one __read_only = 1;
82629+static int __maybe_unused two __read_only = 2;
82630+static int __maybe_unused three __read_only = 3;
82631+static unsigned long one_ul __read_only = 1;
82632+static int one_hundred __read_only = 100;
82633 #ifdef CONFIG_PRINTK
82634-static int ten_thousand = 10000;
82635+static int ten_thousand __read_only = 10000;
82636 #endif
82637
82638 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
82639@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
82640 void __user *buffer, size_t *lenp, loff_t *ppos);
82641 #endif
82642
82643-#ifdef CONFIG_PRINTK
82644 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
82645 void __user *buffer, size_t *lenp, loff_t *ppos);
82646-#endif
82647
82648 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
82649 void __user *buffer, size_t *lenp, loff_t *ppos);
82650@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
82651
82652 #endif
82653
82654+extern struct ctl_table grsecurity_table[];
82655+
82656 static struct ctl_table kern_table[];
82657 static struct ctl_table vm_table[];
82658 static struct ctl_table fs_table[];
82659@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
82660 int sysctl_legacy_va_layout;
82661 #endif
82662
82663+#ifdef CONFIG_PAX_SOFTMODE
82664+static ctl_table pax_table[] = {
82665+ {
82666+ .procname = "softmode",
82667+ .data = &pax_softmode,
82668+ .maxlen = sizeof(unsigned int),
82669+ .mode = 0600,
82670+ .proc_handler = &proc_dointvec,
82671+ },
82672+
82673+ { }
82674+};
82675+#endif
82676+
82677 /* The default sysctl tables: */
82678
82679 static struct ctl_table sysctl_base_table[] = {
82680@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
82681 #endif
82682
82683 static struct ctl_table kern_table[] = {
82684+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
82685+ {
82686+ .procname = "grsecurity",
82687+ .mode = 0500,
82688+ .child = grsecurity_table,
82689+ },
82690+#endif
82691+
82692+#ifdef CONFIG_PAX_SOFTMODE
82693+ {
82694+ .procname = "pax",
82695+ .mode = 0500,
82696+ .child = pax_table,
82697+ },
82698+#endif
82699+
82700 {
82701 .procname = "sched_child_runs_first",
82702 .data = &sysctl_sched_child_runs_first,
82703@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
82704 .data = &modprobe_path,
82705 .maxlen = KMOD_PATH_LEN,
82706 .mode = 0644,
82707- .proc_handler = proc_dostring,
82708+ .proc_handler = proc_dostring_modpriv,
82709 },
82710 {
82711 .procname = "modules_disabled",
82712@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
82713 .extra1 = &zero,
82714 .extra2 = &one,
82715 },
82716+#endif
82717 {
82718 .procname = "kptr_restrict",
82719 .data = &kptr_restrict,
82720 .maxlen = sizeof(int),
82721 .mode = 0644,
82722 .proc_handler = proc_dointvec_minmax_sysadmin,
82723+#ifdef CONFIG_GRKERNSEC_HIDESYM
82724+ .extra1 = &two,
82725+#else
82726 .extra1 = &zero,
82727+#endif
82728 .extra2 = &two,
82729 },
82730-#endif
82731 {
82732 .procname = "ngroups_max",
82733 .data = &ngroups_max,
82734@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
82735 */
82736 {
82737 .procname = "perf_event_paranoid",
82738- .data = &sysctl_perf_event_paranoid,
82739- .maxlen = sizeof(sysctl_perf_event_paranoid),
82740+ .data = &sysctl_perf_event_legitimately_concerned,
82741+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
82742 .mode = 0644,
82743- .proc_handler = proc_dointvec,
82744+ /* go ahead, be a hero */
82745+ .proc_handler = proc_dointvec_minmax_sysadmin,
82746+ .extra1 = &neg_one,
82747+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
82748+ .extra2 = &three,
82749+#else
82750+ .extra2 = &two,
82751+#endif
82752 },
82753 {
82754 .procname = "perf_event_mlock_kb",
82755@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
82756 .proc_handler = proc_dointvec_minmax,
82757 .extra1 = &zero,
82758 },
82759+ {
82760+ .procname = "heap_stack_gap",
82761+ .data = &sysctl_heap_stack_gap,
82762+ .maxlen = sizeof(sysctl_heap_stack_gap),
82763+ .mode = 0644,
82764+ .proc_handler = proc_doulongvec_minmax,
82765+ },
82766 #else
82767 {
82768 .procname = "nr_trim_pages",
82769@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
82770 buffer, lenp, ppos);
82771 }
82772
82773+int proc_dostring_modpriv(struct ctl_table *table, int write,
82774+ void __user *buffer, size_t *lenp, loff_t *ppos)
82775+{
82776+ if (write && !capable(CAP_SYS_MODULE))
82777+ return -EPERM;
82778+
82779+ return _proc_do_string(table->data, table->maxlen, write,
82780+ buffer, lenp, ppos);
82781+}
82782+
82783 static size_t proc_skip_spaces(char **buf)
82784 {
82785 size_t ret;
82786@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
82787 len = strlen(tmp);
82788 if (len > *size)
82789 len = *size;
82790+ if (len > sizeof(tmp))
82791+ len = sizeof(tmp);
82792 if (copy_to_user(*buf, tmp, len))
82793 return -EFAULT;
82794 *size -= len;
82795@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
82796 static int proc_taint(struct ctl_table *table, int write,
82797 void __user *buffer, size_t *lenp, loff_t *ppos)
82798 {
82799- struct ctl_table t;
82800+ ctl_table_no_const t;
82801 unsigned long tmptaint = get_taint();
82802 int err;
82803
82804@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
82805 return err;
82806 }
82807
82808-#ifdef CONFIG_PRINTK
82809 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
82810 void __user *buffer, size_t *lenp, loff_t *ppos)
82811 {
82812@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
82813
82814 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
82815 }
82816-#endif
82817
82818 struct do_proc_dointvec_minmax_conv_param {
82819 int *min;
82820@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
82821 *i = val;
82822 } else {
82823 val = convdiv * (*i) / convmul;
82824- if (!first)
82825+ if (!first) {
82826 err = proc_put_char(&buffer, &left, '\t');
82827+ if (err)
82828+ break;
82829+ }
82830 err = proc_put_long(&buffer, &left, val, false);
82831 if (err)
82832 break;
82833@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
82834 return -ENOSYS;
82835 }
82836
82837+int proc_dostring_modpriv(struct ctl_table *table, int write,
82838+ void __user *buffer, size_t *lenp, loff_t *ppos)
82839+{
82840+ return -ENOSYS;
82841+}
82842+
82843 int proc_dointvec(struct ctl_table *table, int write,
82844 void __user *buffer, size_t *lenp, loff_t *ppos)
82845 {
82846@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
82847 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
82848 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
82849 EXPORT_SYMBOL(proc_dostring);
82850+EXPORT_SYMBOL(proc_dostring_modpriv);
82851 EXPORT_SYMBOL(proc_doulongvec_minmax);
82852 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
82853diff --git a/kernel/taskstats.c b/kernel/taskstats.c
82854index 145bb4d..b2aa969 100644
82855--- a/kernel/taskstats.c
82856+++ b/kernel/taskstats.c
82857@@ -28,9 +28,12 @@
82858 #include <linux/fs.h>
82859 #include <linux/file.h>
82860 #include <linux/pid_namespace.h>
82861+#include <linux/grsecurity.h>
82862 #include <net/genetlink.h>
82863 #include <linux/atomic.h>
82864
82865+extern int gr_is_taskstats_denied(int pid);
82866+
82867 /*
82868 * Maximum length of a cpumask that can be specified in
82869 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
82870@@ -570,6 +573,9 @@ err:
82871
82872 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
82873 {
82874+ if (gr_is_taskstats_denied(current->pid))
82875+ return -EACCES;
82876+
82877 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
82878 return cmd_attr_register_cpumask(info);
82879 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
82880diff --git a/kernel/time.c b/kernel/time.c
82881index d3617db..c98bbe9 100644
82882--- a/kernel/time.c
82883+++ b/kernel/time.c
82884@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
82885 return error;
82886
82887 if (tz) {
82888+ /* we log in do_settimeofday called below, so don't log twice
82889+ */
82890+ if (!tv)
82891+ gr_log_timechange();
82892+
82893 sys_tz = *tz;
82894 update_vsyscall_tz();
82895 if (firsttime) {
82896@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
82897 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
82898 * value to a scaled second value.
82899 */
82900-unsigned long
82901+unsigned long __intentional_overflow(-1)
82902 timespec_to_jiffies(const struct timespec *value)
82903 {
82904 unsigned long sec = value->tv_sec;
82905diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
82906index f11d83b..d016d91 100644
82907--- a/kernel/time/alarmtimer.c
82908+++ b/kernel/time/alarmtimer.c
82909@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
82910 struct platform_device *pdev;
82911 int error = 0;
82912 int i;
82913- struct k_clock alarm_clock = {
82914+ static struct k_clock alarm_clock = {
82915 .clock_getres = alarm_clock_getres,
82916 .clock_get = alarm_clock_get,
82917 .timer_create = alarm_timer_create,
82918diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
82919index baeeb5c..c22704a 100644
82920--- a/kernel/time/timekeeping.c
82921+++ b/kernel/time/timekeeping.c
82922@@ -15,6 +15,7 @@
82923 #include <linux/init.h>
82924 #include <linux/mm.h>
82925 #include <linux/sched.h>
82926+#include <linux/grsecurity.h>
82927 #include <linux/syscore_ops.h>
82928 #include <linux/clocksource.h>
82929 #include <linux/jiffies.h>
82930@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
82931 if (!timespec_valid_strict(tv))
82932 return -EINVAL;
82933
82934+ gr_log_timechange();
82935+
82936 raw_spin_lock_irqsave(&timekeeper_lock, flags);
82937 write_seqcount_begin(&timekeeper_seq);
82938
82939diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
82940index 3bdf283..cc68d83 100644
82941--- a/kernel/time/timer_list.c
82942+++ b/kernel/time/timer_list.c
82943@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
82944
82945 static void print_name_offset(struct seq_file *m, void *sym)
82946 {
82947+#ifdef CONFIG_GRKERNSEC_HIDESYM
82948+ SEQ_printf(m, "<%p>", NULL);
82949+#else
82950 char symname[KSYM_NAME_LEN];
82951
82952 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
82953 SEQ_printf(m, "<%pK>", sym);
82954 else
82955 SEQ_printf(m, "%s", symname);
82956+#endif
82957 }
82958
82959 static void
82960@@ -119,7 +123,11 @@ next_one:
82961 static void
82962 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
82963 {
82964+#ifdef CONFIG_GRKERNSEC_HIDESYM
82965+ SEQ_printf(m, " .base: %p\n", NULL);
82966+#else
82967 SEQ_printf(m, " .base: %pK\n", base);
82968+#endif
82969 SEQ_printf(m, " .index: %d\n",
82970 base->index);
82971 SEQ_printf(m, " .resolution: %Lu nsecs\n",
82972@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
82973 {
82974 struct proc_dir_entry *pe;
82975
82976+#ifdef CONFIG_GRKERNSEC_PROC_ADD
82977+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
82978+#else
82979 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
82980+#endif
82981 if (!pe)
82982 return -ENOMEM;
82983 return 0;
82984diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
82985index 0b537f2..40d6c20 100644
82986--- a/kernel/time/timer_stats.c
82987+++ b/kernel/time/timer_stats.c
82988@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
82989 static unsigned long nr_entries;
82990 static struct entry entries[MAX_ENTRIES];
82991
82992-static atomic_t overflow_count;
82993+static atomic_unchecked_t overflow_count;
82994
82995 /*
82996 * The entries are in a hash-table, for fast lookup:
82997@@ -140,7 +140,7 @@ static void reset_entries(void)
82998 nr_entries = 0;
82999 memset(entries, 0, sizeof(entries));
83000 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
83001- atomic_set(&overflow_count, 0);
83002+ atomic_set_unchecked(&overflow_count, 0);
83003 }
83004
83005 static struct entry *alloc_entry(void)
83006@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
83007 if (likely(entry))
83008 entry->count++;
83009 else
83010- atomic_inc(&overflow_count);
83011+ atomic_inc_unchecked(&overflow_count);
83012
83013 out_unlock:
83014 raw_spin_unlock_irqrestore(lock, flags);
83015@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
83016
83017 static void print_name_offset(struct seq_file *m, unsigned long addr)
83018 {
83019+#ifdef CONFIG_GRKERNSEC_HIDESYM
83020+ seq_printf(m, "<%p>", NULL);
83021+#else
83022 char symname[KSYM_NAME_LEN];
83023
83024 if (lookup_symbol_name(addr, symname) < 0)
83025- seq_printf(m, "<%p>", (void *)addr);
83026+ seq_printf(m, "<%pK>", (void *)addr);
83027 else
83028 seq_printf(m, "%s", symname);
83029+#endif
83030 }
83031
83032 static int tstats_show(struct seq_file *m, void *v)
83033@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
83034
83035 seq_puts(m, "Timer Stats Version: v0.2\n");
83036 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
83037- if (atomic_read(&overflow_count))
83038+ if (atomic_read_unchecked(&overflow_count))
83039 seq_printf(m, "Overflow: %d entries\n",
83040- atomic_read(&overflow_count));
83041+ atomic_read_unchecked(&overflow_count));
83042
83043 for (i = 0; i < nr_entries; i++) {
83044 entry = entries + i;
83045@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
83046 {
83047 struct proc_dir_entry *pe;
83048
83049+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83050+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
83051+#else
83052 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
83053+#endif
83054 if (!pe)
83055 return -ENOMEM;
83056 return 0;
83057diff --git a/kernel/timer.c b/kernel/timer.c
83058index 15bc1b4..32da49c 100644
83059--- a/kernel/timer.c
83060+++ b/kernel/timer.c
83061@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
83062 /*
83063 * This function runs timers and the timer-tq in bottom half context.
83064 */
83065-static void run_timer_softirq(struct softirq_action *h)
83066+static void run_timer_softirq(void)
83067 {
83068 struct tvec_base *base = __this_cpu_read(tvec_bases);
83069
83070@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
83071 *
83072 * In all cases the return value is guaranteed to be non-negative.
83073 */
83074-signed long __sched schedule_timeout(signed long timeout)
83075+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
83076 {
83077 struct timer_list timer;
83078 unsigned long expire;
83079@@ -1635,7 +1635,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
83080 return NOTIFY_OK;
83081 }
83082
83083-static struct notifier_block __cpuinitdata timers_nb = {
83084+static struct notifier_block timers_nb = {
83085 .notifier_call = timer_cpu_notify,
83086 };
83087
83088diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
83089index b8b8560..75b1a09 100644
83090--- a/kernel/trace/blktrace.c
83091+++ b/kernel/trace/blktrace.c
83092@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
83093 struct blk_trace *bt = filp->private_data;
83094 char buf[16];
83095
83096- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
83097+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
83098
83099 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
83100 }
83101@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
83102 return 1;
83103
83104 bt = buf->chan->private_data;
83105- atomic_inc(&bt->dropped);
83106+ atomic_inc_unchecked(&bt->dropped);
83107 return 0;
83108 }
83109
83110@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
83111
83112 bt->dir = dir;
83113 bt->dev = dev;
83114- atomic_set(&bt->dropped, 0);
83115+ atomic_set_unchecked(&bt->dropped, 0);
83116
83117 ret = -EIO;
83118 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
83119diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
83120index 6c508ff..ee55a13 100644
83121--- a/kernel/trace/ftrace.c
83122+++ b/kernel/trace/ftrace.c
83123@@ -1915,12 +1915,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
83124 if (unlikely(ftrace_disabled))
83125 return 0;
83126
83127+ ret = ftrace_arch_code_modify_prepare();
83128+ FTRACE_WARN_ON(ret);
83129+ if (ret)
83130+ return 0;
83131+
83132 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
83133+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
83134 if (ret) {
83135 ftrace_bug(ret, ip);
83136- return 0;
83137 }
83138- return 1;
83139+ return ret ? 0 : 1;
83140 }
83141
83142 /*
83143@@ -3931,8 +3936,10 @@ static int ftrace_process_locs(struct module *mod,
83144 if (!count)
83145 return 0;
83146
83147+ pax_open_kernel();
83148 sort(start, count, sizeof(*start),
83149 ftrace_cmp_ips, ftrace_swap_ips);
83150+ pax_close_kernel();
83151
83152 start_pg = ftrace_allocate_pages(count);
83153 if (!start_pg)
83154@@ -4655,8 +4662,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
83155 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
83156
83157 static int ftrace_graph_active;
83158-static struct notifier_block ftrace_suspend_notifier;
83159-
83160 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
83161 {
83162 return 0;
83163@@ -4800,6 +4805,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
83164 return NOTIFY_DONE;
83165 }
83166
83167+static struct notifier_block ftrace_suspend_notifier = {
83168+ .notifier_call = ftrace_suspend_notifier_call
83169+};
83170+
83171 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
83172 trace_func_graph_ent_t entryfunc)
83173 {
83174@@ -4813,7 +4822,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
83175 goto out;
83176 }
83177
83178- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
83179 register_pm_notifier(&ftrace_suspend_notifier);
83180
83181 ftrace_graph_active++;
83182diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
83183index e444ff8..438b8f4 100644
83184--- a/kernel/trace/ring_buffer.c
83185+++ b/kernel/trace/ring_buffer.c
83186@@ -352,9 +352,9 @@ struct buffer_data_page {
83187 */
83188 struct buffer_page {
83189 struct list_head list; /* list of buffer pages */
83190- local_t write; /* index for next write */
83191+ local_unchecked_t write; /* index for next write */
83192 unsigned read; /* index for next read */
83193- local_t entries; /* entries on this page */
83194+ local_unchecked_t entries; /* entries on this page */
83195 unsigned long real_end; /* real end of data */
83196 struct buffer_data_page *page; /* Actual data page */
83197 };
83198@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
83199 unsigned long last_overrun;
83200 local_t entries_bytes;
83201 local_t entries;
83202- local_t overrun;
83203- local_t commit_overrun;
83204+ local_unchecked_t overrun;
83205+ local_unchecked_t commit_overrun;
83206 local_t dropped_events;
83207 local_t committing;
83208 local_t commits;
83209@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
83210 *
83211 * We add a counter to the write field to denote this.
83212 */
83213- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
83214- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
83215+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
83216+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
83217
83218 /*
83219 * Just make sure we have seen our old_write and synchronize
83220@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
83221 * cmpxchg to only update if an interrupt did not already
83222 * do it for us. If the cmpxchg fails, we don't care.
83223 */
83224- (void)local_cmpxchg(&next_page->write, old_write, val);
83225- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
83226+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
83227+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
83228
83229 /*
83230 * No need to worry about races with clearing out the commit.
83231@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
83232
83233 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
83234 {
83235- return local_read(&bpage->entries) & RB_WRITE_MASK;
83236+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
83237 }
83238
83239 static inline unsigned long rb_page_write(struct buffer_page *bpage)
83240 {
83241- return local_read(&bpage->write) & RB_WRITE_MASK;
83242+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
83243 }
83244
83245 static int
83246@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
83247 * bytes consumed in ring buffer from here.
83248 * Increment overrun to account for the lost events.
83249 */
83250- local_add(page_entries, &cpu_buffer->overrun);
83251+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
83252 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
83253 }
83254
83255@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
83256 * it is our responsibility to update
83257 * the counters.
83258 */
83259- local_add(entries, &cpu_buffer->overrun);
83260+ local_add_unchecked(entries, &cpu_buffer->overrun);
83261 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
83262
83263 /*
83264@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
83265 if (tail == BUF_PAGE_SIZE)
83266 tail_page->real_end = 0;
83267
83268- local_sub(length, &tail_page->write);
83269+ local_sub_unchecked(length, &tail_page->write);
83270 return;
83271 }
83272
83273@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
83274 rb_event_set_padding(event);
83275
83276 /* Set the write back to the previous setting */
83277- local_sub(length, &tail_page->write);
83278+ local_sub_unchecked(length, &tail_page->write);
83279 return;
83280 }
83281
83282@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
83283
83284 /* Set write to end of buffer */
83285 length = (tail + length) - BUF_PAGE_SIZE;
83286- local_sub(length, &tail_page->write);
83287+ local_sub_unchecked(length, &tail_page->write);
83288 }
83289
83290 /*
83291@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
83292 * about it.
83293 */
83294 if (unlikely(next_page == commit_page)) {
83295- local_inc(&cpu_buffer->commit_overrun);
83296+ local_inc_unchecked(&cpu_buffer->commit_overrun);
83297 goto out_reset;
83298 }
83299
83300@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
83301 cpu_buffer->tail_page) &&
83302 (cpu_buffer->commit_page ==
83303 cpu_buffer->reader_page))) {
83304- local_inc(&cpu_buffer->commit_overrun);
83305+ local_inc_unchecked(&cpu_buffer->commit_overrun);
83306 goto out_reset;
83307 }
83308 }
83309@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
83310 length += RB_LEN_TIME_EXTEND;
83311
83312 tail_page = cpu_buffer->tail_page;
83313- write = local_add_return(length, &tail_page->write);
83314+ write = local_add_return_unchecked(length, &tail_page->write);
83315
83316 /* set write to only the index of the write */
83317 write &= RB_WRITE_MASK;
83318@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
83319 kmemcheck_annotate_bitfield(event, bitfield);
83320 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
83321
83322- local_inc(&tail_page->entries);
83323+ local_inc_unchecked(&tail_page->entries);
83324
83325 /*
83326 * If this is the first commit on the page, then update
83327@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
83328
83329 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
83330 unsigned long write_mask =
83331- local_read(&bpage->write) & ~RB_WRITE_MASK;
83332+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
83333 unsigned long event_length = rb_event_length(event);
83334 /*
83335 * This is on the tail page. It is possible that
83336@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
83337 */
83338 old_index += write_mask;
83339 new_index += write_mask;
83340- index = local_cmpxchg(&bpage->write, old_index, new_index);
83341+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
83342 if (index == old_index) {
83343 /* update counters */
83344 local_sub(event_length, &cpu_buffer->entries_bytes);
83345@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
83346
83347 /* Do the likely case first */
83348 if (likely(bpage->page == (void *)addr)) {
83349- local_dec(&bpage->entries);
83350+ local_dec_unchecked(&bpage->entries);
83351 return;
83352 }
83353
83354@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
83355 start = bpage;
83356 do {
83357 if (bpage->page == (void *)addr) {
83358- local_dec(&bpage->entries);
83359+ local_dec_unchecked(&bpage->entries);
83360 return;
83361 }
83362 rb_inc_page(cpu_buffer, &bpage);
83363@@ -3138,7 +3138,7 @@ static inline unsigned long
83364 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
83365 {
83366 return local_read(&cpu_buffer->entries) -
83367- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
83368+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
83369 }
83370
83371 /**
83372@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
83373 return 0;
83374
83375 cpu_buffer = buffer->buffers[cpu];
83376- ret = local_read(&cpu_buffer->overrun);
83377+ ret = local_read_unchecked(&cpu_buffer->overrun);
83378
83379 return ret;
83380 }
83381@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
83382 return 0;
83383
83384 cpu_buffer = buffer->buffers[cpu];
83385- ret = local_read(&cpu_buffer->commit_overrun);
83386+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
83387
83388 return ret;
83389 }
83390@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
83391 /* if you care about this being correct, lock the buffer */
83392 for_each_buffer_cpu(buffer, cpu) {
83393 cpu_buffer = buffer->buffers[cpu];
83394- overruns += local_read(&cpu_buffer->overrun);
83395+ overruns += local_read_unchecked(&cpu_buffer->overrun);
83396 }
83397
83398 return overruns;
83399@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
83400 /*
83401 * Reset the reader page to size zero.
83402 */
83403- local_set(&cpu_buffer->reader_page->write, 0);
83404- local_set(&cpu_buffer->reader_page->entries, 0);
83405+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
83406+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
83407 local_set(&cpu_buffer->reader_page->page->commit, 0);
83408 cpu_buffer->reader_page->real_end = 0;
83409
83410@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
83411 * want to compare with the last_overrun.
83412 */
83413 smp_mb();
83414- overwrite = local_read(&(cpu_buffer->overrun));
83415+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
83416
83417 /*
83418 * Here's the tricky part.
83419@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
83420
83421 cpu_buffer->head_page
83422 = list_entry(cpu_buffer->pages, struct buffer_page, list);
83423- local_set(&cpu_buffer->head_page->write, 0);
83424- local_set(&cpu_buffer->head_page->entries, 0);
83425+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
83426+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
83427 local_set(&cpu_buffer->head_page->page->commit, 0);
83428
83429 cpu_buffer->head_page->read = 0;
83430@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
83431
83432 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
83433 INIT_LIST_HEAD(&cpu_buffer->new_pages);
83434- local_set(&cpu_buffer->reader_page->write, 0);
83435- local_set(&cpu_buffer->reader_page->entries, 0);
83436+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
83437+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
83438 local_set(&cpu_buffer->reader_page->page->commit, 0);
83439 cpu_buffer->reader_page->read = 0;
83440
83441 local_set(&cpu_buffer->entries_bytes, 0);
83442- local_set(&cpu_buffer->overrun, 0);
83443- local_set(&cpu_buffer->commit_overrun, 0);
83444+ local_set_unchecked(&cpu_buffer->overrun, 0);
83445+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
83446 local_set(&cpu_buffer->dropped_events, 0);
83447 local_set(&cpu_buffer->entries, 0);
83448 local_set(&cpu_buffer->committing, 0);
83449@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
83450 rb_init_page(bpage);
83451 bpage = reader->page;
83452 reader->page = *data_page;
83453- local_set(&reader->write, 0);
83454- local_set(&reader->entries, 0);
83455+ local_set_unchecked(&reader->write, 0);
83456+ local_set_unchecked(&reader->entries, 0);
83457 reader->read = 0;
83458 *data_page = bpage;
83459
83460diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
83461index 06a5bce..53ad6e7 100644
83462--- a/kernel/trace/trace.c
83463+++ b/kernel/trace/trace.c
83464@@ -3347,7 +3347,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
83465 return 0;
83466 }
83467
83468-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
83469+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
83470 {
83471 /* do nothing if flag is already set */
83472 if (!!(trace_flags & mask) == !!enabled)
83473diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
83474index 51b4448..7be601f 100644
83475--- a/kernel/trace/trace.h
83476+++ b/kernel/trace/trace.h
83477@@ -1035,7 +1035,7 @@ extern const char *__stop___trace_bprintk_fmt[];
83478 void trace_printk_init_buffers(void);
83479 void trace_printk_start_comm(void);
83480 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
83481-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
83482+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
83483
83484 /*
83485 * Normal trace_printk() and friends allocates special buffers
83486diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
83487index 6953263..2004e16 100644
83488--- a/kernel/trace/trace_events.c
83489+++ b/kernel/trace/trace_events.c
83490@@ -1748,10 +1748,6 @@ static LIST_HEAD(ftrace_module_file_list);
83491 struct ftrace_module_file_ops {
83492 struct list_head list;
83493 struct module *mod;
83494- struct file_operations id;
83495- struct file_operations enable;
83496- struct file_operations format;
83497- struct file_operations filter;
83498 };
83499
83500 static struct ftrace_module_file_ops *
83501@@ -1792,17 +1788,12 @@ trace_create_file_ops(struct module *mod)
83502
83503 file_ops->mod = mod;
83504
83505- file_ops->id = ftrace_event_id_fops;
83506- file_ops->id.owner = mod;
83507-
83508- file_ops->enable = ftrace_enable_fops;
83509- file_ops->enable.owner = mod;
83510-
83511- file_ops->filter = ftrace_event_filter_fops;
83512- file_ops->filter.owner = mod;
83513-
83514- file_ops->format = ftrace_event_format_fops;
83515- file_ops->format.owner = mod;
83516+ pax_open_kernel();
83517+ mod->trace_id.owner = mod;
83518+ mod->trace_enable.owner = mod;
83519+ mod->trace_filter.owner = mod;
83520+ mod->trace_format.owner = mod;
83521+ pax_close_kernel();
83522
83523 list_add(&file_ops->list, &ftrace_module_file_list);
83524
83525@@ -1895,8 +1886,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
83526 struct ftrace_module_file_ops *file_ops)
83527 {
83528 return __trace_add_new_event(call, tr,
83529- &file_ops->id, &file_ops->enable,
83530- &file_ops->filter, &file_ops->format);
83531+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
83532+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
83533 }
83534
83535 #else
83536diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
83537index a5e8f48..a9690d2 100644
83538--- a/kernel/trace/trace_mmiotrace.c
83539+++ b/kernel/trace/trace_mmiotrace.c
83540@@ -24,7 +24,7 @@ struct header_iter {
83541 static struct trace_array *mmio_trace_array;
83542 static bool overrun_detected;
83543 static unsigned long prev_overruns;
83544-static atomic_t dropped_count;
83545+static atomic_unchecked_t dropped_count;
83546
83547 static void mmio_reset_data(struct trace_array *tr)
83548 {
83549@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
83550
83551 static unsigned long count_overruns(struct trace_iterator *iter)
83552 {
83553- unsigned long cnt = atomic_xchg(&dropped_count, 0);
83554+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
83555 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
83556
83557 if (over > prev_overruns)
83558@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
83559 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
83560 sizeof(*entry), 0, pc);
83561 if (!event) {
83562- atomic_inc(&dropped_count);
83563+ atomic_inc_unchecked(&dropped_count);
83564 return;
83565 }
83566 entry = ring_buffer_event_data(event);
83567@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
83568 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
83569 sizeof(*entry), 0, pc);
83570 if (!event) {
83571- atomic_inc(&dropped_count);
83572+ atomic_inc_unchecked(&dropped_count);
83573 return;
83574 }
83575 entry = ring_buffer_event_data(event);
83576diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
83577index bb922d9..2a54a257 100644
83578--- a/kernel/trace/trace_output.c
83579+++ b/kernel/trace/trace_output.c
83580@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
83581
83582 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
83583 if (!IS_ERR(p)) {
83584- p = mangle_path(s->buffer + s->len, p, "\n");
83585+ p = mangle_path(s->buffer + s->len, p, "\n\\");
83586 if (p) {
83587 s->len = p - s->buffer;
83588 return 1;
83589@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
83590 goto out;
83591 }
83592
83593+ pax_open_kernel();
83594 if (event->funcs->trace == NULL)
83595- event->funcs->trace = trace_nop_print;
83596+ *(void **)&event->funcs->trace = trace_nop_print;
83597 if (event->funcs->raw == NULL)
83598- event->funcs->raw = trace_nop_print;
83599+ *(void **)&event->funcs->raw = trace_nop_print;
83600 if (event->funcs->hex == NULL)
83601- event->funcs->hex = trace_nop_print;
83602+ *(void **)&event->funcs->hex = trace_nop_print;
83603 if (event->funcs->binary == NULL)
83604- event->funcs->binary = trace_nop_print;
83605+ *(void **)&event->funcs->binary = trace_nop_print;
83606+ pax_close_kernel();
83607
83608 key = event->type & (EVENT_HASHSIZE - 1);
83609
83610diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
83611index b20428c..4845a10 100644
83612--- a/kernel/trace/trace_stack.c
83613+++ b/kernel/trace/trace_stack.c
83614@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
83615 return;
83616
83617 /* we do not handle interrupt stacks yet */
83618- if (!object_is_on_stack(stack))
83619+ if (!object_starts_on_stack(stack))
83620 return;
83621
83622 local_irq_save(flags);
83623diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
83624index 9064b91..1f5d2f8 100644
83625--- a/kernel/user_namespace.c
83626+++ b/kernel/user_namespace.c
83627@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
83628 !kgid_has_mapping(parent_ns, group))
83629 return -EPERM;
83630
83631+#ifdef CONFIG_GRKERNSEC
83632+ /*
83633+ * This doesn't really inspire confidence:
83634+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
83635+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
83636+ * Increases kernel attack surface in areas developers
83637+ * previously cared little about ("low importance due
83638+ * to requiring "root" capability")
83639+ * To be removed when this code receives *proper* review
83640+ */
83641+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
83642+ !capable(CAP_SETGID))
83643+ return -EPERM;
83644+#endif
83645+
83646 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
83647 if (!ns)
83648 return -ENOMEM;
83649@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
83650 if (atomic_read(&current->mm->mm_users) > 1)
83651 return -EINVAL;
83652
83653- if (current->fs->users != 1)
83654+ if (atomic_read(&current->fs->users) != 1)
83655 return -EINVAL;
83656
83657 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
83658diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
83659index 4f69f9a..7c6f8f8 100644
83660--- a/kernel/utsname_sysctl.c
83661+++ b/kernel/utsname_sysctl.c
83662@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
83663 static int proc_do_uts_string(ctl_table *table, int write,
83664 void __user *buffer, size_t *lenp, loff_t *ppos)
83665 {
83666- struct ctl_table uts_table;
83667+ ctl_table_no_const uts_table;
83668 int r;
83669 memcpy(&uts_table, table, sizeof(uts_table));
83670 uts_table.data = get_uts(table, write);
83671diff --git a/kernel/watchdog.c b/kernel/watchdog.c
83672index 05039e3..17490c7 100644
83673--- a/kernel/watchdog.c
83674+++ b/kernel/watchdog.c
83675@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
83676 }
83677 #endif /* CONFIG_SYSCTL */
83678
83679-static struct smp_hotplug_thread watchdog_threads = {
83680+static struct smp_hotplug_thread watchdog_threads __read_only = {
83681 .store = &softlockup_watchdog,
83682 .thread_should_run = watchdog_should_run,
83683 .thread_fn = watchdog,
83684diff --git a/kernel/workqueue.c b/kernel/workqueue.c
83685index 6f01921..139869b 100644
83686--- a/kernel/workqueue.c
83687+++ b/kernel/workqueue.c
83688@@ -4596,7 +4596,7 @@ static void rebind_workers(struct worker_pool *pool)
83689 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
83690 worker_flags |= WORKER_REBOUND;
83691 worker_flags &= ~WORKER_UNBOUND;
83692- ACCESS_ONCE(worker->flags) = worker_flags;
83693+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
83694 }
83695
83696 spin_unlock_irq(&pool->lock);
83697diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
83698index 74fdc5c..3310593 100644
83699--- a/lib/Kconfig.debug
83700+++ b/lib/Kconfig.debug
83701@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
83702
83703 config DEBUG_LOCK_ALLOC
83704 bool "Lock debugging: detect incorrect freeing of live locks"
83705- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
83706+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
83707 select DEBUG_SPINLOCK
83708 select DEBUG_MUTEXES
83709 select LOCKDEP
83710@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
83711
83712 config PROVE_LOCKING
83713 bool "Lock debugging: prove locking correctness"
83714- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
83715+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
83716 select LOCKDEP
83717 select DEBUG_SPINLOCK
83718 select DEBUG_MUTEXES
83719@@ -614,7 +614,7 @@ config LOCKDEP
83720
83721 config LOCK_STAT
83722 bool "Lock usage statistics"
83723- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
83724+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
83725 select LOCKDEP
83726 select DEBUG_SPINLOCK
83727 select DEBUG_MUTEXES
83728@@ -1282,6 +1282,7 @@ config LATENCYTOP
83729 depends on DEBUG_KERNEL
83730 depends on STACKTRACE_SUPPORT
83731 depends on PROC_FS
83732+ depends on !GRKERNSEC_HIDESYM
83733 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
83734 select KALLSYMS
83735 select KALLSYMS_ALL
83736@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
83737 config DEBUG_STRICT_USER_COPY_CHECKS
83738 bool "Strict user copy size checks"
83739 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
83740- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
83741+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
83742 help
83743 Enabling this option turns a certain set of sanity checks for user
83744 copy operations into compile time failures.
83745@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
83746
83747 config PROVIDE_OHCI1394_DMA_INIT
83748 bool "Remote debugging over FireWire early on boot"
83749- depends on PCI && X86
83750+ depends on PCI && X86 && !GRKERNSEC
83751 help
83752 If you want to debug problems which hang or crash the kernel early
83753 on boot and the crashing machine has a FireWire port, you can use
83754@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
83755
83756 config FIREWIRE_OHCI_REMOTE_DMA
83757 bool "Remote debugging over FireWire with firewire-ohci"
83758- depends on FIREWIRE_OHCI
83759+ depends on FIREWIRE_OHCI && !GRKERNSEC
83760 help
83761 This option lets you use the FireWire bus for remote debugging
83762 with help of the firewire-ohci driver. It enables unfiltered
83763diff --git a/lib/Makefile b/lib/Makefile
83764index c55a037..fb46e3b 100644
83765--- a/lib/Makefile
83766+++ b/lib/Makefile
83767@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
83768
83769 obj-$(CONFIG_BTREE) += btree.o
83770 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
83771-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
83772+obj-y += list_debug.o
83773 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
83774
83775 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
83776diff --git a/lib/bitmap.c b/lib/bitmap.c
83777index 06f7e4f..f3cf2b0 100644
83778--- a/lib/bitmap.c
83779+++ b/lib/bitmap.c
83780@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
83781 {
83782 int c, old_c, totaldigits, ndigits, nchunks, nbits;
83783 u32 chunk;
83784- const char __user __force *ubuf = (const char __user __force *)buf;
83785+ const char __user *ubuf = (const char __force_user *)buf;
83786
83787 bitmap_zero(maskp, nmaskbits);
83788
83789@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
83790 {
83791 if (!access_ok(VERIFY_READ, ubuf, ulen))
83792 return -EFAULT;
83793- return __bitmap_parse((const char __force *)ubuf,
83794+ return __bitmap_parse((const char __force_kernel *)ubuf,
83795 ulen, 1, maskp, nmaskbits);
83796
83797 }
83798@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
83799 {
83800 unsigned a, b;
83801 int c, old_c, totaldigits;
83802- const char __user __force *ubuf = (const char __user __force *)buf;
83803+ const char __user *ubuf = (const char __force_user *)buf;
83804 int exp_digit, in_range;
83805
83806 totaldigits = c = 0;
83807@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
83808 {
83809 if (!access_ok(VERIFY_READ, ubuf, ulen))
83810 return -EFAULT;
83811- return __bitmap_parselist((const char __force *)ubuf,
83812+ return __bitmap_parselist((const char __force_kernel *)ubuf,
83813 ulen, 1, maskp, nmaskbits);
83814 }
83815 EXPORT_SYMBOL(bitmap_parselist_user);
83816diff --git a/lib/bug.c b/lib/bug.c
83817index 1686034..a9c00c8 100644
83818--- a/lib/bug.c
83819+++ b/lib/bug.c
83820@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
83821 return BUG_TRAP_TYPE_NONE;
83822
83823 bug = find_bug(bugaddr);
83824+ if (!bug)
83825+ return BUG_TRAP_TYPE_NONE;
83826
83827 file = NULL;
83828 line = 0;
83829diff --git a/lib/debugobjects.c b/lib/debugobjects.c
83830index 37061ed..da83f48 100644
83831--- a/lib/debugobjects.c
83832+++ b/lib/debugobjects.c
83833@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
83834 if (limit > 4)
83835 return;
83836
83837- is_on_stack = object_is_on_stack(addr);
83838+ is_on_stack = object_starts_on_stack(addr);
83839 if (is_on_stack == onstack)
83840 return;
83841
83842diff --git a/lib/devres.c b/lib/devres.c
83843index 8235331..5881053 100644
83844--- a/lib/devres.c
83845+++ b/lib/devres.c
83846@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
83847 void devm_iounmap(struct device *dev, void __iomem *addr)
83848 {
83849 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
83850- (void *)addr));
83851+ (void __force *)addr));
83852 iounmap(addr);
83853 }
83854 EXPORT_SYMBOL(devm_iounmap);
83855@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
83856 {
83857 ioport_unmap(addr);
83858 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
83859- devm_ioport_map_match, (void *)addr));
83860+ devm_ioport_map_match, (void __force *)addr));
83861 }
83862 EXPORT_SYMBOL(devm_ioport_unmap);
83863 #endif /* CONFIG_HAS_IOPORT */
83864diff --git a/lib/div64.c b/lib/div64.c
83865index a163b6c..9618fa5 100644
83866--- a/lib/div64.c
83867+++ b/lib/div64.c
83868@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
83869 EXPORT_SYMBOL(__div64_32);
83870
83871 #ifndef div_s64_rem
83872-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
83873+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
83874 {
83875 u64 quotient;
83876
83877@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
83878 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
83879 */
83880 #ifndef div64_u64
83881-u64 div64_u64(u64 dividend, u64 divisor)
83882+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83883 {
83884 u32 high = divisor >> 32;
83885 u64 quot;
83886diff --git a/lib/dma-debug.c b/lib/dma-debug.c
83887index d87a17a..ac0d79a 100644
83888--- a/lib/dma-debug.c
83889+++ b/lib/dma-debug.c
83890@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
83891
83892 void dma_debug_add_bus(struct bus_type *bus)
83893 {
83894- struct notifier_block *nb;
83895+ notifier_block_no_const *nb;
83896
83897 if (global_disable)
83898 return;
83899@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
83900
83901 static void check_for_stack(struct device *dev, void *addr)
83902 {
83903- if (object_is_on_stack(addr))
83904+ if (object_starts_on_stack(addr))
83905 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
83906 "stack [addr=%p]\n", addr);
83907 }
83908diff --git a/lib/inflate.c b/lib/inflate.c
83909index 013a761..c28f3fc 100644
83910--- a/lib/inflate.c
83911+++ b/lib/inflate.c
83912@@ -269,7 +269,7 @@ static void free(void *where)
83913 malloc_ptr = free_mem_ptr;
83914 }
83915 #else
83916-#define malloc(a) kmalloc(a, GFP_KERNEL)
83917+#define malloc(a) kmalloc((a), GFP_KERNEL)
83918 #define free(a) kfree(a)
83919 #endif
83920
83921diff --git a/lib/ioremap.c b/lib/ioremap.c
83922index 0c9216c..863bd89 100644
83923--- a/lib/ioremap.c
83924+++ b/lib/ioremap.c
83925@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
83926 unsigned long next;
83927
83928 phys_addr -= addr;
83929- pmd = pmd_alloc(&init_mm, pud, addr);
83930+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83931 if (!pmd)
83932 return -ENOMEM;
83933 do {
83934@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
83935 unsigned long next;
83936
83937 phys_addr -= addr;
83938- pud = pud_alloc(&init_mm, pgd, addr);
83939+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
83940 if (!pud)
83941 return -ENOMEM;
83942 do {
83943diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
83944index bd2bea9..6b3c95e 100644
83945--- a/lib/is_single_threaded.c
83946+++ b/lib/is_single_threaded.c
83947@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
83948 struct task_struct *p, *t;
83949 bool ret;
83950
83951+ if (!mm)
83952+ return true;
83953+
83954 if (atomic_read(&task->signal->live) != 1)
83955 return false;
83956
83957diff --git a/lib/kobject.c b/lib/kobject.c
83958index b7e29a6..2f3ca75 100644
83959--- a/lib/kobject.c
83960+++ b/lib/kobject.c
83961@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
83962 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
83963 if (!kset)
83964 return NULL;
83965- retval = kobject_set_name(&kset->kobj, name);
83966+ retval = kobject_set_name(&kset->kobj, "%s", name);
83967 if (retval) {
83968 kfree(kset);
83969 return NULL;
83970@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
83971
83972
83973 static DEFINE_SPINLOCK(kobj_ns_type_lock);
83974-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
83975+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
83976
83977-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
83978+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
83979 {
83980 enum kobj_ns_type type = ops->type;
83981 int error;
83982diff --git a/lib/list_debug.c b/lib/list_debug.c
83983index c24c2f7..06e070b 100644
83984--- a/lib/list_debug.c
83985+++ b/lib/list_debug.c
83986@@ -11,7 +11,9 @@
83987 #include <linux/bug.h>
83988 #include <linux/kernel.h>
83989 #include <linux/rculist.h>
83990+#include <linux/mm.h>
83991
83992+#ifdef CONFIG_DEBUG_LIST
83993 /*
83994 * Insert a new entry between two known consecutive entries.
83995 *
83996@@ -19,21 +21,32 @@
83997 * the prev/next entries already!
83998 */
83999
84000-void __list_add(struct list_head *new,
84001- struct list_head *prev,
84002- struct list_head *next)
84003+static bool __list_add_debug(struct list_head *new,
84004+ struct list_head *prev,
84005+ struct list_head *next)
84006 {
84007- WARN(next->prev != prev,
84008+ if (WARN(next->prev != prev,
84009 "list_add corruption. next->prev should be "
84010 "prev (%p), but was %p. (next=%p).\n",
84011- prev, next->prev, next);
84012- WARN(prev->next != next,
84013+ prev, next->prev, next) ||
84014+ WARN(prev->next != next,
84015 "list_add corruption. prev->next should be "
84016 "next (%p), but was %p. (prev=%p).\n",
84017- next, prev->next, prev);
84018- WARN(new == prev || new == next,
84019- "list_add double add: new=%p, prev=%p, next=%p.\n",
84020- new, prev, next);
84021+ next, prev->next, prev) ||
84022+ WARN(new == prev || new == next,
84023+ "list_add double add: new=%p, prev=%p, next=%p.\n",
84024+ new, prev, next))
84025+ return false;
84026+ return true;
84027+}
84028+
84029+void __list_add(struct list_head *new,
84030+ struct list_head *prev,
84031+ struct list_head *next)
84032+{
84033+ if (!__list_add_debug(new, prev, next))
84034+ return;
84035+
84036 next->prev = new;
84037 new->next = next;
84038 new->prev = prev;
84039@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
84040 }
84041 EXPORT_SYMBOL(__list_add);
84042
84043-void __list_del_entry(struct list_head *entry)
84044+static bool __list_del_entry_debug(struct list_head *entry)
84045 {
84046 struct list_head *prev, *next;
84047
84048@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
84049 WARN(next->prev != entry,
84050 "list_del corruption. next->prev should be %p, "
84051 "but was %p\n", entry, next->prev))
84052+ return false;
84053+ return true;
84054+}
84055+
84056+void __list_del_entry(struct list_head *entry)
84057+{
84058+ if (!__list_del_entry_debug(entry))
84059 return;
84060
84061- __list_del(prev, next);
84062+ __list_del(entry->prev, entry->next);
84063 }
84064 EXPORT_SYMBOL(__list_del_entry);
84065
84066@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
84067 void __list_add_rcu(struct list_head *new,
84068 struct list_head *prev, struct list_head *next)
84069 {
84070- WARN(next->prev != prev,
84071- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
84072- prev, next->prev, next);
84073- WARN(prev->next != next,
84074- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
84075- next, prev->next, prev);
84076+ if (!__list_add_debug(new, prev, next))
84077+ return;
84078+
84079 new->next = next;
84080 new->prev = prev;
84081 rcu_assign_pointer(list_next_rcu(prev), new);
84082 next->prev = new;
84083 }
84084 EXPORT_SYMBOL(__list_add_rcu);
84085+#endif
84086+
84087+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
84088+{
84089+#ifdef CONFIG_DEBUG_LIST
84090+ if (!__list_add_debug(new, prev, next))
84091+ return;
84092+#endif
84093+
84094+ pax_open_kernel();
84095+ next->prev = new;
84096+ new->next = next;
84097+ new->prev = prev;
84098+ prev->next = new;
84099+ pax_close_kernel();
84100+}
84101+EXPORT_SYMBOL(__pax_list_add);
84102+
84103+void pax_list_del(struct list_head *entry)
84104+{
84105+#ifdef CONFIG_DEBUG_LIST
84106+ if (!__list_del_entry_debug(entry))
84107+ return;
84108+#endif
84109+
84110+ pax_open_kernel();
84111+ __list_del(entry->prev, entry->next);
84112+ entry->next = LIST_POISON1;
84113+ entry->prev = LIST_POISON2;
84114+ pax_close_kernel();
84115+}
84116+EXPORT_SYMBOL(pax_list_del);
84117+
84118+void pax_list_del_init(struct list_head *entry)
84119+{
84120+ pax_open_kernel();
84121+ __list_del(entry->prev, entry->next);
84122+ INIT_LIST_HEAD(entry);
84123+ pax_close_kernel();
84124+}
84125+EXPORT_SYMBOL(pax_list_del_init);
84126+
84127+void __pax_list_add_rcu(struct list_head *new,
84128+ struct list_head *prev, struct list_head *next)
84129+{
84130+#ifdef CONFIG_DEBUG_LIST
84131+ if (!__list_add_debug(new, prev, next))
84132+ return;
84133+#endif
84134+
84135+ pax_open_kernel();
84136+ new->next = next;
84137+ new->prev = prev;
84138+ rcu_assign_pointer(list_next_rcu(prev), new);
84139+ next->prev = new;
84140+ pax_close_kernel();
84141+}
84142+EXPORT_SYMBOL(__pax_list_add_rcu);
84143+
84144+void pax_list_del_rcu(struct list_head *entry)
84145+{
84146+#ifdef CONFIG_DEBUG_LIST
84147+ if (!__list_del_entry_debug(entry))
84148+ return;
84149+#endif
84150+
84151+ pax_open_kernel();
84152+ __list_del(entry->prev, entry->next);
84153+ entry->next = LIST_POISON1;
84154+ entry->prev = LIST_POISON2;
84155+ pax_close_kernel();
84156+}
84157+EXPORT_SYMBOL(pax_list_del_rcu);
84158diff --git a/lib/radix-tree.c b/lib/radix-tree.c
84159index e796429..6e38f9f 100644
84160--- a/lib/radix-tree.c
84161+++ b/lib/radix-tree.c
84162@@ -92,7 +92,7 @@ struct radix_tree_preload {
84163 int nr;
84164 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
84165 };
84166-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
84167+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
84168
84169 static inline void *ptr_to_indirect(void *ptr)
84170 {
84171diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
84172index bb2b201..46abaf9 100644
84173--- a/lib/strncpy_from_user.c
84174+++ b/lib/strncpy_from_user.c
84175@@ -21,7 +21,7 @@
84176 */
84177 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
84178 {
84179- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
84180+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
84181 long res = 0;
84182
84183 /*
84184diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
84185index a28df52..3d55877 100644
84186--- a/lib/strnlen_user.c
84187+++ b/lib/strnlen_user.c
84188@@ -26,7 +26,7 @@
84189 */
84190 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
84191 {
84192- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
84193+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
84194 long align, res = 0;
84195 unsigned long c;
84196
84197diff --git a/lib/swiotlb.c b/lib/swiotlb.c
84198index d23762e..e21eab2 100644
84199--- a/lib/swiotlb.c
84200+++ b/lib/swiotlb.c
84201@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
84202
84203 void
84204 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
84205- dma_addr_t dev_addr)
84206+ dma_addr_t dev_addr, struct dma_attrs *attrs)
84207 {
84208 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
84209
84210diff --git a/lib/usercopy.c b/lib/usercopy.c
84211index 4f5b1dd..7cab418 100644
84212--- a/lib/usercopy.c
84213+++ b/lib/usercopy.c
84214@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
84215 WARN(1, "Buffer overflow detected!\n");
84216 }
84217 EXPORT_SYMBOL(copy_from_user_overflow);
84218+
84219+void copy_to_user_overflow(void)
84220+{
84221+ WARN(1, "Buffer overflow detected!\n");
84222+}
84223+EXPORT_SYMBOL(copy_to_user_overflow);
84224diff --git a/lib/vsprintf.c b/lib/vsprintf.c
84225index e149c64..24aa71a 100644
84226--- a/lib/vsprintf.c
84227+++ b/lib/vsprintf.c
84228@@ -16,6 +16,9 @@
84229 * - scnprintf and vscnprintf
84230 */
84231
84232+#ifdef CONFIG_GRKERNSEC_HIDESYM
84233+#define __INCLUDED_BY_HIDESYM 1
84234+#endif
84235 #include <stdarg.h>
84236 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
84237 #include <linux/types.h>
84238@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
84239 return number(buf, end, *(const netdev_features_t *)addr, spec);
84240 }
84241
84242+#ifdef CONFIG_GRKERNSEC_HIDESYM
84243+int kptr_restrict __read_mostly = 2;
84244+#else
84245 int kptr_restrict __read_mostly;
84246+#endif
84247
84248 /*
84249 * Show a '%p' thing. A kernel extension is that the '%p' is followed
84250@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
84251 * - 'f' For simple symbolic function names without offset
84252 * - 'S' For symbolic direct pointers with offset
84253 * - 's' For symbolic direct pointers without offset
84254+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
84255 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
84256 * - 'B' For backtraced symbolic direct pointers with offset
84257 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
84258@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
84259
84260 if (!ptr && *fmt != 'K') {
84261 /*
84262- * Print (null) with the same width as a pointer so it makes
84263+ * Print (nil) with the same width as a pointer so it makes
84264 * tabular output look nice.
84265 */
84266 if (spec.field_width == -1)
84267 spec.field_width = default_width;
84268- return string(buf, end, "(null)", spec);
84269+ return string(buf, end, "(nil)", spec);
84270 }
84271
84272 switch (*fmt) {
84273@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
84274 /* Fallthrough */
84275 case 'S':
84276 case 's':
84277+#ifdef CONFIG_GRKERNSEC_HIDESYM
84278+ break;
84279+#else
84280+ return symbol_string(buf, end, ptr, spec, fmt);
84281+#endif
84282+ case 'A':
84283 case 'B':
84284 return symbol_string(buf, end, ptr, spec, fmt);
84285 case 'R':
84286@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
84287 va_end(va);
84288 return buf;
84289 }
84290+ case 'P':
84291+ break;
84292 case 'K':
84293 /*
84294 * %pK cannot be used in IRQ context because its test
84295@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
84296 return number(buf, end,
84297 (unsigned long long) *((phys_addr_t *)ptr), spec);
84298 }
84299+
84300+#ifdef CONFIG_GRKERNSEC_HIDESYM
84301+ /* 'P' = approved pointers to copy to userland,
84302+ as in the /proc/kallsyms case, as we make it display nothing
84303+ for non-root users, and the real contents for root users
84304+ Also ignore 'K' pointers, since we force their NULLing for non-root users
84305+ above
84306+ */
84307+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
84308+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
84309+ dump_stack();
84310+ ptr = NULL;
84311+ }
84312+#endif
84313+
84314 spec.flags |= SMALL;
84315 if (spec.field_width == -1) {
84316 spec.field_width = default_width;
84317@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
84318 typeof(type) value; \
84319 if (sizeof(type) == 8) { \
84320 args = PTR_ALIGN(args, sizeof(u32)); \
84321- *(u32 *)&value = *(u32 *)args; \
84322- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
84323+ *(u32 *)&value = *(const u32 *)args; \
84324+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
84325 } else { \
84326 args = PTR_ALIGN(args, sizeof(type)); \
84327- value = *(typeof(type) *)args; \
84328+ value = *(const typeof(type) *)args; \
84329 } \
84330 args += sizeof(type); \
84331 value; \
84332@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
84333 case FORMAT_TYPE_STR: {
84334 const char *str_arg = args;
84335 args += strlen(str_arg) + 1;
84336- str = string(str, end, (char *)str_arg, spec);
84337+ str = string(str, end, str_arg, spec);
84338 break;
84339 }
84340
84341diff --git a/localversion-grsec b/localversion-grsec
84342new file mode 100644
84343index 0000000..7cd6065
84344--- /dev/null
84345+++ b/localversion-grsec
84346@@ -0,0 +1 @@
84347+-grsec
84348diff --git a/mm/Kconfig b/mm/Kconfig
84349index e742d06..c56fdd8 100644
84350--- a/mm/Kconfig
84351+++ b/mm/Kconfig
84352@@ -317,10 +317,10 @@ config KSM
84353 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
84354
84355 config DEFAULT_MMAP_MIN_ADDR
84356- int "Low address space to protect from user allocation"
84357+ int "Low address space to protect from user allocation"
84358 depends on MMU
84359- default 4096
84360- help
84361+ default 65536
84362+ help
84363 This is the portion of low virtual memory which should be protected
84364 from userspace allocation. Keeping a user from writing to low pages
84365 can help reduce the impact of kernel NULL pointer bugs.
84366@@ -351,7 +351,7 @@ config MEMORY_FAILURE
84367
84368 config HWPOISON_INJECT
84369 tristate "HWPoison pages injector"
84370- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
84371+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
84372 select PROC_PAGE_MONITOR
84373
84374 config NOMMU_INITIAL_TRIM_EXCESS
84375diff --git a/mm/backing-dev.c b/mm/backing-dev.c
84376index 5025174..9d67dcd 100644
84377--- a/mm/backing-dev.c
84378+++ b/mm/backing-dev.c
84379@@ -12,7 +12,7 @@
84380 #include <linux/device.h>
84381 #include <trace/events/writeback.h>
84382
84383-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
84384+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
84385
84386 struct backing_dev_info default_backing_dev_info = {
84387 .name = "default",
84388@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
84389 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
84390 unsigned int cap)
84391 {
84392- char tmp[32];
84393 int err;
84394
84395 bdi->name = name;
84396@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
84397 if (err)
84398 return err;
84399
84400- sprintf(tmp, "%.28s%s", name, "-%d");
84401- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
84402+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return_unchecked(&bdi_seq));
84403 if (err) {
84404 bdi_destroy(bdi);
84405 return err;
84406diff --git a/mm/filemap.c b/mm/filemap.c
84407index 7905fe7..e60faa8 100644
84408--- a/mm/filemap.c
84409+++ b/mm/filemap.c
84410@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
84411 struct address_space *mapping = file->f_mapping;
84412
84413 if (!mapping->a_ops->readpage)
84414- return -ENOEXEC;
84415+ return -ENODEV;
84416 file_accessed(file);
84417 vma->vm_ops = &generic_file_vm_ops;
84418 return 0;
84419@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
84420 *pos = i_size_read(inode);
84421
84422 if (limit != RLIM_INFINITY) {
84423+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
84424 if (*pos >= limit) {
84425 send_sig(SIGXFSZ, current, 0);
84426 return -EFBIG;
84427diff --git a/mm/fremap.c b/mm/fremap.c
84428index 87da359..3f41cb1 100644
84429--- a/mm/fremap.c
84430+++ b/mm/fremap.c
84431@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
84432 retry:
84433 vma = find_vma(mm, start);
84434
84435+#ifdef CONFIG_PAX_SEGMEXEC
84436+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
84437+ goto out;
84438+#endif
84439+
84440 /*
84441 * Make sure the vma is shared, that it supports prefaulting,
84442 * and that the remapped range is valid and fully within
84443diff --git a/mm/highmem.c b/mm/highmem.c
84444index b32b70c..e512eb0 100644
84445--- a/mm/highmem.c
84446+++ b/mm/highmem.c
84447@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
84448 * So no dangers, even with speculative execution.
84449 */
84450 page = pte_page(pkmap_page_table[i]);
84451+ pax_open_kernel();
84452 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
84453-
84454+ pax_close_kernel();
84455 set_page_address(page, NULL);
84456 need_flush = 1;
84457 }
84458@@ -198,9 +199,11 @@ start:
84459 }
84460 }
84461 vaddr = PKMAP_ADDR(last_pkmap_nr);
84462+
84463+ pax_open_kernel();
84464 set_pte_at(&init_mm, vaddr,
84465 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
84466-
84467+ pax_close_kernel();
84468 pkmap_count[last_pkmap_nr] = 1;
84469 set_page_address(page, (void *)vaddr);
84470
84471diff --git a/mm/hugetlb.c b/mm/hugetlb.c
84472index 5cf99bf..5c01c2f 100644
84473--- a/mm/hugetlb.c
84474+++ b/mm/hugetlb.c
84475@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
84476 struct hstate *h = &default_hstate;
84477 unsigned long tmp;
84478 int ret;
84479+ ctl_table_no_const hugetlb_table;
84480
84481 tmp = h->max_huge_pages;
84482
84483 if (write && h->order >= MAX_ORDER)
84484 return -EINVAL;
84485
84486- table->data = &tmp;
84487- table->maxlen = sizeof(unsigned long);
84488- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
84489+ hugetlb_table = *table;
84490+ hugetlb_table.data = &tmp;
84491+ hugetlb_table.maxlen = sizeof(unsigned long);
84492+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
84493 if (ret)
84494 goto out;
84495
84496@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
84497 struct hstate *h = &default_hstate;
84498 unsigned long tmp;
84499 int ret;
84500+ ctl_table_no_const hugetlb_table;
84501
84502 tmp = h->nr_overcommit_huge_pages;
84503
84504 if (write && h->order >= MAX_ORDER)
84505 return -EINVAL;
84506
84507- table->data = &tmp;
84508- table->maxlen = sizeof(unsigned long);
84509- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
84510+ hugetlb_table = *table;
84511+ hugetlb_table.data = &tmp;
84512+ hugetlb_table.maxlen = sizeof(unsigned long);
84513+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
84514 if (ret)
84515 goto out;
84516
84517@@ -2490,7 +2494,7 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
84518
84519 mm = vma->vm_mm;
84520
84521- tlb_gather_mmu(&tlb, mm, 0);
84522+ tlb_gather_mmu(&tlb, mm, start, end);
84523 __unmap_hugepage_range(&tlb, vma, start, end, ref_page);
84524 tlb_finish_mmu(&tlb, start, end);
84525 }
84526@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
84527 return 1;
84528 }
84529
84530+#ifdef CONFIG_PAX_SEGMEXEC
84531+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
84532+{
84533+ struct mm_struct *mm = vma->vm_mm;
84534+ struct vm_area_struct *vma_m;
84535+ unsigned long address_m;
84536+ pte_t *ptep_m;
84537+
84538+ vma_m = pax_find_mirror_vma(vma);
84539+ if (!vma_m)
84540+ return;
84541+
84542+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
84543+ address_m = address + SEGMEXEC_TASK_SIZE;
84544+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
84545+ get_page(page_m);
84546+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
84547+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
84548+}
84549+#endif
84550+
84551 /*
84552 * Hugetlb_cow() should be called with page lock of the original hugepage held.
84553 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
84554@@ -2663,6 +2688,11 @@ retry_avoidcopy:
84555 make_huge_pte(vma, new_page, 1));
84556 page_remove_rmap(old_page);
84557 hugepage_add_new_anon_rmap(new_page, vma, address);
84558+
84559+#ifdef CONFIG_PAX_SEGMEXEC
84560+ pax_mirror_huge_pte(vma, address, new_page);
84561+#endif
84562+
84563 /* Make the old page be freed below */
84564 new_page = old_page;
84565 }
84566@@ -2821,6 +2851,10 @@ retry:
84567 && (vma->vm_flags & VM_SHARED)));
84568 set_huge_pte_at(mm, address, ptep, new_pte);
84569
84570+#ifdef CONFIG_PAX_SEGMEXEC
84571+ pax_mirror_huge_pte(vma, address, page);
84572+#endif
84573+
84574 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
84575 /* Optimization, do the COW without a second fault */
84576 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
84577@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
84578 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
84579 struct hstate *h = hstate_vma(vma);
84580
84581+#ifdef CONFIG_PAX_SEGMEXEC
84582+ struct vm_area_struct *vma_m;
84583+#endif
84584+
84585 address &= huge_page_mask(h);
84586
84587 ptep = huge_pte_offset(mm, address);
84588@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
84589 VM_FAULT_SET_HINDEX(hstate_index(h));
84590 }
84591
84592+#ifdef CONFIG_PAX_SEGMEXEC
84593+ vma_m = pax_find_mirror_vma(vma);
84594+ if (vma_m) {
84595+ unsigned long address_m;
84596+
84597+ if (vma->vm_start > vma_m->vm_start) {
84598+ address_m = address;
84599+ address -= SEGMEXEC_TASK_SIZE;
84600+ vma = vma_m;
84601+ h = hstate_vma(vma);
84602+ } else
84603+ address_m = address + SEGMEXEC_TASK_SIZE;
84604+
84605+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
84606+ return VM_FAULT_OOM;
84607+ address_m &= HPAGE_MASK;
84608+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
84609+ }
84610+#endif
84611+
84612 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
84613 if (!ptep)
84614 return VM_FAULT_OOM;
84615diff --git a/mm/internal.h b/mm/internal.h
84616index 8562de0..92b2073 100644
84617--- a/mm/internal.h
84618+++ b/mm/internal.h
84619@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
84620 * in mm/page_alloc.c
84621 */
84622 extern void __free_pages_bootmem(struct page *page, unsigned int order);
84623+extern void free_compound_page(struct page *page);
84624 extern void prep_compound_page(struct page *page, unsigned long order);
84625 #ifdef CONFIG_MEMORY_FAILURE
84626 extern bool is_free_buddy_page(struct page *page);
84627@@ -355,7 +356,7 @@ extern u32 hwpoison_filter_enable;
84628
84629 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
84630 unsigned long, unsigned long,
84631- unsigned long, unsigned long);
84632+ unsigned long, unsigned long) __intentional_overflow(-1);
84633
84634 extern void set_pageblock_order(void);
84635 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
84636diff --git a/mm/kmemleak.c b/mm/kmemleak.c
84637index c8d7f31..2dbeffd 100644
84638--- a/mm/kmemleak.c
84639+++ b/mm/kmemleak.c
84640@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
84641
84642 for (i = 0; i < object->trace_len; i++) {
84643 void *ptr = (void *)object->trace[i];
84644- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
84645+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
84646 }
84647 }
84648
84649@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
84650 return -ENOMEM;
84651 }
84652
84653- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
84654+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
84655 &kmemleak_fops);
84656 if (!dentry)
84657 pr_warning("Failed to create the debugfs kmemleak file\n");
84658diff --git a/mm/maccess.c b/mm/maccess.c
84659index d53adf9..03a24bf 100644
84660--- a/mm/maccess.c
84661+++ b/mm/maccess.c
84662@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
84663 set_fs(KERNEL_DS);
84664 pagefault_disable();
84665 ret = __copy_from_user_inatomic(dst,
84666- (__force const void __user *)src, size);
84667+ (const void __force_user *)src, size);
84668 pagefault_enable();
84669 set_fs(old_fs);
84670
84671@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
84672
84673 set_fs(KERNEL_DS);
84674 pagefault_disable();
84675- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
84676+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
84677 pagefault_enable();
84678 set_fs(old_fs);
84679
84680diff --git a/mm/madvise.c b/mm/madvise.c
84681index 7055883..aafb1ed 100644
84682--- a/mm/madvise.c
84683+++ b/mm/madvise.c
84684@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
84685 pgoff_t pgoff;
84686 unsigned long new_flags = vma->vm_flags;
84687
84688+#ifdef CONFIG_PAX_SEGMEXEC
84689+ struct vm_area_struct *vma_m;
84690+#endif
84691+
84692 switch (behavior) {
84693 case MADV_NORMAL:
84694 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
84695@@ -126,6 +130,13 @@ success:
84696 /*
84697 * vm_flags is protected by the mmap_sem held in write mode.
84698 */
84699+
84700+#ifdef CONFIG_PAX_SEGMEXEC
84701+ vma_m = pax_find_mirror_vma(vma);
84702+ if (vma_m)
84703+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
84704+#endif
84705+
84706 vma->vm_flags = new_flags;
84707
84708 out:
84709@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
84710 struct vm_area_struct ** prev,
84711 unsigned long start, unsigned long end)
84712 {
84713+
84714+#ifdef CONFIG_PAX_SEGMEXEC
84715+ struct vm_area_struct *vma_m;
84716+#endif
84717+
84718 *prev = vma;
84719 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
84720 return -EINVAL;
84721@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
84722 zap_page_range(vma, start, end - start, &details);
84723 } else
84724 zap_page_range(vma, start, end - start, NULL);
84725+
84726+#ifdef CONFIG_PAX_SEGMEXEC
84727+ vma_m = pax_find_mirror_vma(vma);
84728+ if (vma_m) {
84729+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
84730+ struct zap_details details = {
84731+ .nonlinear_vma = vma_m,
84732+ .last_index = ULONG_MAX,
84733+ };
84734+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
84735+ } else
84736+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
84737+ }
84738+#endif
84739+
84740 return 0;
84741 }
84742
84743@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
84744 if (end < start)
84745 return error;
84746
84747+#ifdef CONFIG_PAX_SEGMEXEC
84748+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
84749+ if (end > SEGMEXEC_TASK_SIZE)
84750+ return error;
84751+ } else
84752+#endif
84753+
84754+ if (end > TASK_SIZE)
84755+ return error;
84756+
84757 error = 0;
84758 if (end == start)
84759 return error;
84760diff --git a/mm/memory-failure.c b/mm/memory-failure.c
84761index ceb0c7f..b2b8e94 100644
84762--- a/mm/memory-failure.c
84763+++ b/mm/memory-failure.c
84764@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
84765
84766 int sysctl_memory_failure_recovery __read_mostly = 1;
84767
84768-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
84769+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
84770
84771 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
84772
84773@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
84774 pfn, t->comm, t->pid);
84775 si.si_signo = SIGBUS;
84776 si.si_errno = 0;
84777- si.si_addr = (void *)addr;
84778+ si.si_addr = (void __user *)addr;
84779 #ifdef __ARCH_SI_TRAPNO
84780 si.si_trapno = trapno;
84781 #endif
84782@@ -760,7 +760,7 @@ static struct page_state {
84783 unsigned long res;
84784 char *msg;
84785 int (*action)(struct page *p, unsigned long pfn);
84786-} error_states[] = {
84787+} __do_const error_states[] = {
84788 { reserved, reserved, "reserved kernel", me_kernel },
84789 /*
84790 * free pages are specially detected outside this table:
84791@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
84792 nr_pages = 1 << compound_order(hpage);
84793 else /* normal page or thp */
84794 nr_pages = 1;
84795- atomic_long_add(nr_pages, &num_poisoned_pages);
84796+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
84797
84798 /*
84799 * We need/can do nothing about count=0 pages.
84800@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
84801 if (!PageHWPoison(hpage)
84802 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
84803 || (p != hpage && TestSetPageHWPoison(hpage))) {
84804- atomic_long_sub(nr_pages, &num_poisoned_pages);
84805+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
84806 return 0;
84807 }
84808 set_page_hwpoison_huge_page(hpage);
84809@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
84810 }
84811 if (hwpoison_filter(p)) {
84812 if (TestClearPageHWPoison(p))
84813- atomic_long_sub(nr_pages, &num_poisoned_pages);
84814+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
84815 unlock_page(hpage);
84816 put_page(hpage);
84817 return 0;
84818@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
84819 return 0;
84820 }
84821 if (TestClearPageHWPoison(p))
84822- atomic_long_sub(nr_pages, &num_poisoned_pages);
84823+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
84824 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
84825 return 0;
84826 }
84827@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
84828 */
84829 if (TestClearPageHWPoison(page)) {
84830 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
84831- atomic_long_sub(nr_pages, &num_poisoned_pages);
84832+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
84833 freeit = 1;
84834 if (PageHuge(page))
84835 clear_page_hwpoison_huge_page(page);
84836@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
84837 } else {
84838 set_page_hwpoison_huge_page(hpage);
84839 dequeue_hwpoisoned_huge_page(hpage);
84840- atomic_long_add(1 << compound_trans_order(hpage),
84841+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
84842 &num_poisoned_pages);
84843 }
84844 /* keep elevated page count for bad page */
84845@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
84846 if (PageHuge(page)) {
84847 set_page_hwpoison_huge_page(hpage);
84848 dequeue_hwpoisoned_huge_page(hpage);
84849- atomic_long_add(1 << compound_trans_order(hpage),
84850+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
84851 &num_poisoned_pages);
84852 } else {
84853 SetPageHWPoison(page);
84854- atomic_long_inc(&num_poisoned_pages);
84855+ atomic_long_inc_unchecked(&num_poisoned_pages);
84856 }
84857 }
84858 /* keep elevated page count for bad page */
84859@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
84860 put_page(page);
84861 pr_info("soft_offline: %#lx: invalidated\n", pfn);
84862 SetPageHWPoison(page);
84863- atomic_long_inc(&num_poisoned_pages);
84864+ atomic_long_inc_unchecked(&num_poisoned_pages);
84865 return 0;
84866 }
84867
84868@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
84869 ret = -EIO;
84870 } else {
84871 SetPageHWPoison(page);
84872- atomic_long_inc(&num_poisoned_pages);
84873+ atomic_long_inc_unchecked(&num_poisoned_pages);
84874 }
84875 } else {
84876 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
84877diff --git a/mm/memory.c b/mm/memory.c
84878index 5e50800..7c0340f 100644
84879--- a/mm/memory.c
84880+++ b/mm/memory.c
84881@@ -211,14 +211,15 @@ static int tlb_next_batch(struct mmu_gather *tlb)
84882 * tear-down from @mm. The @fullmm argument is used when @mm is without
84883 * users and we're going to destroy the full address space (exit/execve).
84884 */
84885-void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, bool fullmm)
84886+void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
84887 {
84888 tlb->mm = mm;
84889
84890- tlb->fullmm = fullmm;
84891+ /* Is it from 0 to ~0? */
84892+ tlb->fullmm = !(start | (end+1));
84893 tlb->need_flush_all = 0;
84894- tlb->start = -1UL;
84895- tlb->end = 0;
84896+ tlb->start = start;
84897+ tlb->end = end;
84898 tlb->need_flush = 0;
84899 tlb->local.next = NULL;
84900 tlb->local.nr = 0;
84901@@ -258,8 +259,6 @@ void tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long e
84902 {
84903 struct mmu_gather_batch *batch, *next;
84904
84905- tlb->start = start;
84906- tlb->end = end;
84907 tlb_flush_mmu(tlb);
84908
84909 /* keep the page table cache within bounds */
84910@@ -429,6 +428,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
84911 free_pte_range(tlb, pmd, addr);
84912 } while (pmd++, addr = next, addr != end);
84913
84914+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
84915 start &= PUD_MASK;
84916 if (start < floor)
84917 return;
84918@@ -443,6 +443,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
84919 pmd = pmd_offset(pud, start);
84920 pud_clear(pud);
84921 pmd_free_tlb(tlb, pmd, start);
84922+#endif
84923+
84924 }
84925
84926 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
84927@@ -462,6 +464,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
84928 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
84929 } while (pud++, addr = next, addr != end);
84930
84931+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
84932 start &= PGDIR_MASK;
84933 if (start < floor)
84934 return;
84935@@ -476,6 +479,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
84936 pud = pud_offset(pgd, start);
84937 pgd_clear(pgd);
84938 pud_free_tlb(tlb, pud, start);
84939+#endif
84940+
84941 }
84942
84943 /*
84944@@ -1101,7 +1106,6 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
84945 spinlock_t *ptl;
84946 pte_t *start_pte;
84947 pte_t *pte;
84948- unsigned long range_start = addr;
84949
84950 again:
84951 init_rss_vec(rss);
84952@@ -1204,17 +1208,25 @@ again:
84953 * and page-free while holding it.
84954 */
84955 if (force_flush) {
84956+ unsigned long old_end;
84957+
84958 force_flush = 0;
84959
84960-#ifdef HAVE_GENERIC_MMU_GATHER
84961- tlb->start = range_start;
84962+ /*
84963+ * Flush the TLB just for the previous segment,
84964+ * then update the range to be the remaining
84965+ * TLB range.
84966+ */
84967+ old_end = tlb->end;
84968 tlb->end = addr;
84969-#endif
84970+
84971 tlb_flush_mmu(tlb);
84972- if (addr != end) {
84973- range_start = addr;
84974+
84975+ tlb->start = addr;
84976+ tlb->end = old_end;
84977+
84978+ if (addr != end)
84979 goto again;
84980- }
84981 }
84982
84983 return addr;
84984@@ -1399,7 +1411,7 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long start,
84985 unsigned long end = start + size;
84986
84987 lru_add_drain();
84988- tlb_gather_mmu(&tlb, mm, 0);
84989+ tlb_gather_mmu(&tlb, mm, start, end);
84990 update_hiwater_rss(mm);
84991 mmu_notifier_invalidate_range_start(mm, start, end);
84992 for ( ; vma && vma->vm_start < end; vma = vma->vm_next)
84993@@ -1425,7 +1437,7 @@ static void zap_page_range_single(struct vm_area_struct *vma, unsigned long addr
84994 unsigned long end = address + size;
84995
84996 lru_add_drain();
84997- tlb_gather_mmu(&tlb, mm, 0);
84998+ tlb_gather_mmu(&tlb, mm, address, end);
84999 update_hiwater_rss(mm);
85000 mmu_notifier_invalidate_range_start(mm, address, end);
85001 unmap_single_vma(&tlb, vma, address, end, details);
85002@@ -1638,12 +1650,6 @@ no_page_table:
85003 return page;
85004 }
85005
85006-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
85007-{
85008- return stack_guard_page_start(vma, addr) ||
85009- stack_guard_page_end(vma, addr+PAGE_SIZE);
85010-}
85011-
85012 /**
85013 * __get_user_pages() - pin user pages in memory
85014 * @tsk: task_struct of target task
85015@@ -1730,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
85016
85017 i = 0;
85018
85019- do {
85020+ while (nr_pages) {
85021 struct vm_area_struct *vma;
85022
85023- vma = find_extend_vma(mm, start);
85024+ vma = find_vma(mm, start);
85025 if (!vma && in_gate_area(mm, start)) {
85026 unsigned long pg = start & PAGE_MASK;
85027 pgd_t *pgd;
85028@@ -1782,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
85029 goto next_page;
85030 }
85031
85032- if (!vma ||
85033+ if (!vma || start < vma->vm_start ||
85034 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
85035 !(vm_flags & vma->vm_flags))
85036 return i ? : -EFAULT;
85037@@ -1811,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
85038 int ret;
85039 unsigned int fault_flags = 0;
85040
85041- /* For mlock, just skip the stack guard page. */
85042- if (foll_flags & FOLL_MLOCK) {
85043- if (stack_guard_page(vma, start))
85044- goto next_page;
85045- }
85046 if (foll_flags & FOLL_WRITE)
85047 fault_flags |= FAULT_FLAG_WRITE;
85048 if (nonblocking)
85049@@ -1895,7 +1896,7 @@ next_page:
85050 start += page_increm * PAGE_SIZE;
85051 nr_pages -= page_increm;
85052 } while (nr_pages && start < vma->vm_end);
85053- } while (nr_pages);
85054+ }
85055 return i;
85056 }
85057 EXPORT_SYMBOL(__get_user_pages);
85058@@ -2102,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
85059 page_add_file_rmap(page);
85060 set_pte_at(mm, addr, pte, mk_pte(page, prot));
85061
85062+#ifdef CONFIG_PAX_SEGMEXEC
85063+ pax_mirror_file_pte(vma, addr, page, ptl);
85064+#endif
85065+
85066 retval = 0;
85067 pte_unmap_unlock(pte, ptl);
85068 return retval;
85069@@ -2146,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
85070 if (!page_count(page))
85071 return -EINVAL;
85072 if (!(vma->vm_flags & VM_MIXEDMAP)) {
85073+
85074+#ifdef CONFIG_PAX_SEGMEXEC
85075+ struct vm_area_struct *vma_m;
85076+#endif
85077+
85078 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
85079 BUG_ON(vma->vm_flags & VM_PFNMAP);
85080 vma->vm_flags |= VM_MIXEDMAP;
85081+
85082+#ifdef CONFIG_PAX_SEGMEXEC
85083+ vma_m = pax_find_mirror_vma(vma);
85084+ if (vma_m)
85085+ vma_m->vm_flags |= VM_MIXEDMAP;
85086+#endif
85087+
85088 }
85089 return insert_page(vma, addr, page, vma->vm_page_prot);
85090 }
85091@@ -2231,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
85092 unsigned long pfn)
85093 {
85094 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
85095+ BUG_ON(vma->vm_mirror);
85096
85097 if (addr < vma->vm_start || addr >= vma->vm_end)
85098 return -EFAULT;
85099@@ -2478,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
85100
85101 BUG_ON(pud_huge(*pud));
85102
85103- pmd = pmd_alloc(mm, pud, addr);
85104+ pmd = (mm == &init_mm) ?
85105+ pmd_alloc_kernel(mm, pud, addr) :
85106+ pmd_alloc(mm, pud, addr);
85107 if (!pmd)
85108 return -ENOMEM;
85109 do {
85110@@ -2498,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
85111 unsigned long next;
85112 int err;
85113
85114- pud = pud_alloc(mm, pgd, addr);
85115+ pud = (mm == &init_mm) ?
85116+ pud_alloc_kernel(mm, pgd, addr) :
85117+ pud_alloc(mm, pgd, addr);
85118 if (!pud)
85119 return -ENOMEM;
85120 do {
85121@@ -2586,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
85122 copy_user_highpage(dst, src, va, vma);
85123 }
85124
85125+#ifdef CONFIG_PAX_SEGMEXEC
85126+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
85127+{
85128+ struct mm_struct *mm = vma->vm_mm;
85129+ spinlock_t *ptl;
85130+ pte_t *pte, entry;
85131+
85132+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
85133+ entry = *pte;
85134+ if (!pte_present(entry)) {
85135+ if (!pte_none(entry)) {
85136+ BUG_ON(pte_file(entry));
85137+ free_swap_and_cache(pte_to_swp_entry(entry));
85138+ pte_clear_not_present_full(mm, address, pte, 0);
85139+ }
85140+ } else {
85141+ struct page *page;
85142+
85143+ flush_cache_page(vma, address, pte_pfn(entry));
85144+ entry = ptep_clear_flush(vma, address, pte);
85145+ BUG_ON(pte_dirty(entry));
85146+ page = vm_normal_page(vma, address, entry);
85147+ if (page) {
85148+ update_hiwater_rss(mm);
85149+ if (PageAnon(page))
85150+ dec_mm_counter_fast(mm, MM_ANONPAGES);
85151+ else
85152+ dec_mm_counter_fast(mm, MM_FILEPAGES);
85153+ page_remove_rmap(page);
85154+ page_cache_release(page);
85155+ }
85156+ }
85157+ pte_unmap_unlock(pte, ptl);
85158+}
85159+
85160+/* PaX: if vma is mirrored, synchronize the mirror's PTE
85161+ *
85162+ * the ptl of the lower mapped page is held on entry and is not released on exit
85163+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
85164+ */
85165+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
85166+{
85167+ struct mm_struct *mm = vma->vm_mm;
85168+ unsigned long address_m;
85169+ spinlock_t *ptl_m;
85170+ struct vm_area_struct *vma_m;
85171+ pmd_t *pmd_m;
85172+ pte_t *pte_m, entry_m;
85173+
85174+ BUG_ON(!page_m || !PageAnon(page_m));
85175+
85176+ vma_m = pax_find_mirror_vma(vma);
85177+ if (!vma_m)
85178+ return;
85179+
85180+ BUG_ON(!PageLocked(page_m));
85181+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85182+ address_m = address + SEGMEXEC_TASK_SIZE;
85183+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
85184+ pte_m = pte_offset_map(pmd_m, address_m);
85185+ ptl_m = pte_lockptr(mm, pmd_m);
85186+ if (ptl != ptl_m) {
85187+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
85188+ if (!pte_none(*pte_m))
85189+ goto out;
85190+ }
85191+
85192+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
85193+ page_cache_get(page_m);
85194+ page_add_anon_rmap(page_m, vma_m, address_m);
85195+ inc_mm_counter_fast(mm, MM_ANONPAGES);
85196+ set_pte_at(mm, address_m, pte_m, entry_m);
85197+ update_mmu_cache(vma_m, address_m, pte_m);
85198+out:
85199+ if (ptl != ptl_m)
85200+ spin_unlock(ptl_m);
85201+ pte_unmap(pte_m);
85202+ unlock_page(page_m);
85203+}
85204+
85205+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
85206+{
85207+ struct mm_struct *mm = vma->vm_mm;
85208+ unsigned long address_m;
85209+ spinlock_t *ptl_m;
85210+ struct vm_area_struct *vma_m;
85211+ pmd_t *pmd_m;
85212+ pte_t *pte_m, entry_m;
85213+
85214+ BUG_ON(!page_m || PageAnon(page_m));
85215+
85216+ vma_m = pax_find_mirror_vma(vma);
85217+ if (!vma_m)
85218+ return;
85219+
85220+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85221+ address_m = address + SEGMEXEC_TASK_SIZE;
85222+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
85223+ pte_m = pte_offset_map(pmd_m, address_m);
85224+ ptl_m = pte_lockptr(mm, pmd_m);
85225+ if (ptl != ptl_m) {
85226+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
85227+ if (!pte_none(*pte_m))
85228+ goto out;
85229+ }
85230+
85231+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
85232+ page_cache_get(page_m);
85233+ page_add_file_rmap(page_m);
85234+ inc_mm_counter_fast(mm, MM_FILEPAGES);
85235+ set_pte_at(mm, address_m, pte_m, entry_m);
85236+ update_mmu_cache(vma_m, address_m, pte_m);
85237+out:
85238+ if (ptl != ptl_m)
85239+ spin_unlock(ptl_m);
85240+ pte_unmap(pte_m);
85241+}
85242+
85243+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
85244+{
85245+ struct mm_struct *mm = vma->vm_mm;
85246+ unsigned long address_m;
85247+ spinlock_t *ptl_m;
85248+ struct vm_area_struct *vma_m;
85249+ pmd_t *pmd_m;
85250+ pte_t *pte_m, entry_m;
85251+
85252+ vma_m = pax_find_mirror_vma(vma);
85253+ if (!vma_m)
85254+ return;
85255+
85256+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85257+ address_m = address + SEGMEXEC_TASK_SIZE;
85258+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
85259+ pte_m = pte_offset_map(pmd_m, address_m);
85260+ ptl_m = pte_lockptr(mm, pmd_m);
85261+ if (ptl != ptl_m) {
85262+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
85263+ if (!pte_none(*pte_m))
85264+ goto out;
85265+ }
85266+
85267+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
85268+ set_pte_at(mm, address_m, pte_m, entry_m);
85269+out:
85270+ if (ptl != ptl_m)
85271+ spin_unlock(ptl_m);
85272+ pte_unmap(pte_m);
85273+}
85274+
85275+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
85276+{
85277+ struct page *page_m;
85278+ pte_t entry;
85279+
85280+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
85281+ goto out;
85282+
85283+ entry = *pte;
85284+ page_m = vm_normal_page(vma, address, entry);
85285+ if (!page_m)
85286+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
85287+ else if (PageAnon(page_m)) {
85288+ if (pax_find_mirror_vma(vma)) {
85289+ pte_unmap_unlock(pte, ptl);
85290+ lock_page(page_m);
85291+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
85292+ if (pte_same(entry, *pte))
85293+ pax_mirror_anon_pte(vma, address, page_m, ptl);
85294+ else
85295+ unlock_page(page_m);
85296+ }
85297+ } else
85298+ pax_mirror_file_pte(vma, address, page_m, ptl);
85299+
85300+out:
85301+ pte_unmap_unlock(pte, ptl);
85302+}
85303+#endif
85304+
85305 /*
85306 * This routine handles present pages, when users try to write
85307 * to a shared page. It is done by copying the page to a new address
85308@@ -2802,6 +3004,12 @@ gotten:
85309 */
85310 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
85311 if (likely(pte_same(*page_table, orig_pte))) {
85312+
85313+#ifdef CONFIG_PAX_SEGMEXEC
85314+ if (pax_find_mirror_vma(vma))
85315+ BUG_ON(!trylock_page(new_page));
85316+#endif
85317+
85318 if (old_page) {
85319 if (!PageAnon(old_page)) {
85320 dec_mm_counter_fast(mm, MM_FILEPAGES);
85321@@ -2853,6 +3061,10 @@ gotten:
85322 page_remove_rmap(old_page);
85323 }
85324
85325+#ifdef CONFIG_PAX_SEGMEXEC
85326+ pax_mirror_anon_pte(vma, address, new_page, ptl);
85327+#endif
85328+
85329 /* Free the old page.. */
85330 new_page = old_page;
85331 ret |= VM_FAULT_WRITE;
85332@@ -3128,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
85333 swap_free(entry);
85334 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
85335 try_to_free_swap(page);
85336+
85337+#ifdef CONFIG_PAX_SEGMEXEC
85338+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
85339+#endif
85340+
85341 unlock_page(page);
85342 if (page != swapcache) {
85343 /*
85344@@ -3151,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
85345
85346 /* No need to invalidate - it was non-present before */
85347 update_mmu_cache(vma, address, page_table);
85348+
85349+#ifdef CONFIG_PAX_SEGMEXEC
85350+ pax_mirror_anon_pte(vma, address, page, ptl);
85351+#endif
85352+
85353 unlock:
85354 pte_unmap_unlock(page_table, ptl);
85355 out:
85356@@ -3170,40 +3392,6 @@ out_release:
85357 }
85358
85359 /*
85360- * This is like a special single-page "expand_{down|up}wards()",
85361- * except we must first make sure that 'address{-|+}PAGE_SIZE'
85362- * doesn't hit another vma.
85363- */
85364-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
85365-{
85366- address &= PAGE_MASK;
85367- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
85368- struct vm_area_struct *prev = vma->vm_prev;
85369-
85370- /*
85371- * Is there a mapping abutting this one below?
85372- *
85373- * That's only ok if it's the same stack mapping
85374- * that has gotten split..
85375- */
85376- if (prev && prev->vm_end == address)
85377- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
85378-
85379- expand_downwards(vma, address - PAGE_SIZE);
85380- }
85381- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
85382- struct vm_area_struct *next = vma->vm_next;
85383-
85384- /* As VM_GROWSDOWN but s/below/above/ */
85385- if (next && next->vm_start == address + PAGE_SIZE)
85386- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
85387-
85388- expand_upwards(vma, address + PAGE_SIZE);
85389- }
85390- return 0;
85391-}
85392-
85393-/*
85394 * We enter with non-exclusive mmap_sem (to exclude vma changes,
85395 * but allow concurrent faults), and pte mapped but not yet locked.
85396 * We return with mmap_sem still held, but pte unmapped and unlocked.
85397@@ -3212,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
85398 unsigned long address, pte_t *page_table, pmd_t *pmd,
85399 unsigned int flags)
85400 {
85401- struct page *page;
85402+ struct page *page = NULL;
85403 spinlock_t *ptl;
85404 pte_t entry;
85405
85406- pte_unmap(page_table);
85407-
85408- /* Check if we need to add a guard page to the stack */
85409- if (check_stack_guard_page(vma, address) < 0)
85410- return VM_FAULT_SIGBUS;
85411-
85412- /* Use the zero-page for reads */
85413 if (!(flags & FAULT_FLAG_WRITE)) {
85414 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
85415 vma->vm_page_prot));
85416- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
85417+ ptl = pte_lockptr(mm, pmd);
85418+ spin_lock(ptl);
85419 if (!pte_none(*page_table))
85420 goto unlock;
85421 goto setpte;
85422 }
85423
85424 /* Allocate our own private page. */
85425+ pte_unmap(page_table);
85426+
85427 if (unlikely(anon_vma_prepare(vma)))
85428 goto oom;
85429 page = alloc_zeroed_user_highpage_movable(vma, address);
85430@@ -3256,6 +3440,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
85431 if (!pte_none(*page_table))
85432 goto release;
85433
85434+#ifdef CONFIG_PAX_SEGMEXEC
85435+ if (pax_find_mirror_vma(vma))
85436+ BUG_ON(!trylock_page(page));
85437+#endif
85438+
85439 inc_mm_counter_fast(mm, MM_ANONPAGES);
85440 page_add_new_anon_rmap(page, vma, address);
85441 setpte:
85442@@ -3263,6 +3452,12 @@ setpte:
85443
85444 /* No need to invalidate - it was non-present before */
85445 update_mmu_cache(vma, address, page_table);
85446+
85447+#ifdef CONFIG_PAX_SEGMEXEC
85448+ if (page)
85449+ pax_mirror_anon_pte(vma, address, page, ptl);
85450+#endif
85451+
85452 unlock:
85453 pte_unmap_unlock(page_table, ptl);
85454 return 0;
85455@@ -3406,6 +3601,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85456 */
85457 /* Only go through if we didn't race with anybody else... */
85458 if (likely(pte_same(*page_table, orig_pte))) {
85459+
85460+#ifdef CONFIG_PAX_SEGMEXEC
85461+ if (anon && pax_find_mirror_vma(vma))
85462+ BUG_ON(!trylock_page(page));
85463+#endif
85464+
85465 flush_icache_page(vma, page);
85466 entry = mk_pte(page, vma->vm_page_prot);
85467 if (flags & FAULT_FLAG_WRITE)
85468@@ -3425,6 +3626,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85469
85470 /* no need to invalidate: a not-present page won't be cached */
85471 update_mmu_cache(vma, address, page_table);
85472+
85473+#ifdef CONFIG_PAX_SEGMEXEC
85474+ if (anon)
85475+ pax_mirror_anon_pte(vma, address, page, ptl);
85476+ else
85477+ pax_mirror_file_pte(vma, address, page, ptl);
85478+#endif
85479+
85480 } else {
85481 if (cow_page)
85482 mem_cgroup_uncharge_page(cow_page);
85483@@ -3746,6 +3955,12 @@ int handle_pte_fault(struct mm_struct *mm,
85484 if (flags & FAULT_FLAG_WRITE)
85485 flush_tlb_fix_spurious_fault(vma, address);
85486 }
85487+
85488+#ifdef CONFIG_PAX_SEGMEXEC
85489+ pax_mirror_pte(vma, address, pte, pmd, ptl);
85490+ return 0;
85491+#endif
85492+
85493 unlock:
85494 pte_unmap_unlock(pte, ptl);
85495 return 0;
85496@@ -3762,6 +3977,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85497 pmd_t *pmd;
85498 pte_t *pte;
85499
85500+#ifdef CONFIG_PAX_SEGMEXEC
85501+ struct vm_area_struct *vma_m;
85502+#endif
85503+
85504 __set_current_state(TASK_RUNNING);
85505
85506 count_vm_event(PGFAULT);
85507@@ -3773,6 +3992,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85508 if (unlikely(is_vm_hugetlb_page(vma)))
85509 return hugetlb_fault(mm, vma, address, flags);
85510
85511+#ifdef CONFIG_PAX_SEGMEXEC
85512+ vma_m = pax_find_mirror_vma(vma);
85513+ if (vma_m) {
85514+ unsigned long address_m;
85515+ pgd_t *pgd_m;
85516+ pud_t *pud_m;
85517+ pmd_t *pmd_m;
85518+
85519+ if (vma->vm_start > vma_m->vm_start) {
85520+ address_m = address;
85521+ address -= SEGMEXEC_TASK_SIZE;
85522+ vma = vma_m;
85523+ } else
85524+ address_m = address + SEGMEXEC_TASK_SIZE;
85525+
85526+ pgd_m = pgd_offset(mm, address_m);
85527+ pud_m = pud_alloc(mm, pgd_m, address_m);
85528+ if (!pud_m)
85529+ return VM_FAULT_OOM;
85530+ pmd_m = pmd_alloc(mm, pud_m, address_m);
85531+ if (!pmd_m)
85532+ return VM_FAULT_OOM;
85533+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
85534+ return VM_FAULT_OOM;
85535+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
85536+ }
85537+#endif
85538+
85539 retry:
85540 pgd = pgd_offset(mm, address);
85541 pud = pud_alloc(mm, pgd, address);
85542@@ -3871,6 +4118,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
85543 spin_unlock(&mm->page_table_lock);
85544 return 0;
85545 }
85546+
85547+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
85548+{
85549+ pud_t *new = pud_alloc_one(mm, address);
85550+ if (!new)
85551+ return -ENOMEM;
85552+
85553+ smp_wmb(); /* See comment in __pte_alloc */
85554+
85555+ spin_lock(&mm->page_table_lock);
85556+ if (pgd_present(*pgd)) /* Another has populated it */
85557+ pud_free(mm, new);
85558+ else
85559+ pgd_populate_kernel(mm, pgd, new);
85560+ spin_unlock(&mm->page_table_lock);
85561+ return 0;
85562+}
85563 #endif /* __PAGETABLE_PUD_FOLDED */
85564
85565 #ifndef __PAGETABLE_PMD_FOLDED
85566@@ -3901,6 +4165,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
85567 spin_unlock(&mm->page_table_lock);
85568 return 0;
85569 }
85570+
85571+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
85572+{
85573+ pmd_t *new = pmd_alloc_one(mm, address);
85574+ if (!new)
85575+ return -ENOMEM;
85576+
85577+ smp_wmb(); /* See comment in __pte_alloc */
85578+
85579+ spin_lock(&mm->page_table_lock);
85580+#ifndef __ARCH_HAS_4LEVEL_HACK
85581+ if (pud_present(*pud)) /* Another has populated it */
85582+ pmd_free(mm, new);
85583+ else
85584+ pud_populate_kernel(mm, pud, new);
85585+#else
85586+ if (pgd_present(*pud)) /* Another has populated it */
85587+ pmd_free(mm, new);
85588+ else
85589+ pgd_populate_kernel(mm, pud, new);
85590+#endif /* __ARCH_HAS_4LEVEL_HACK */
85591+ spin_unlock(&mm->page_table_lock);
85592+ return 0;
85593+}
85594 #endif /* __PAGETABLE_PMD_FOLDED */
85595
85596 #if !defined(__HAVE_ARCH_GATE_AREA)
85597@@ -3914,7 +4202,7 @@ static int __init gate_vma_init(void)
85598 gate_vma.vm_start = FIXADDR_USER_START;
85599 gate_vma.vm_end = FIXADDR_USER_END;
85600 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
85601- gate_vma.vm_page_prot = __P101;
85602+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
85603
85604 return 0;
85605 }
85606@@ -4048,8 +4336,8 @@ out:
85607 return ret;
85608 }
85609
85610-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
85611- void *buf, int len, int write)
85612+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
85613+ void *buf, size_t len, int write)
85614 {
85615 resource_size_t phys_addr;
85616 unsigned long prot = 0;
85617@@ -4074,8 +4362,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
85618 * Access another process' address space as given in mm. If non-NULL, use the
85619 * given task for page fault accounting.
85620 */
85621-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
85622- unsigned long addr, void *buf, int len, int write)
85623+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
85624+ unsigned long addr, void *buf, size_t len, int write)
85625 {
85626 struct vm_area_struct *vma;
85627 void *old_buf = buf;
85628@@ -4083,7 +4371,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
85629 down_read(&mm->mmap_sem);
85630 /* ignore errors, just check how much was successfully transferred */
85631 while (len) {
85632- int bytes, ret, offset;
85633+ ssize_t bytes, ret, offset;
85634 void *maddr;
85635 struct page *page = NULL;
85636
85637@@ -4142,8 +4430,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
85638 *
85639 * The caller must hold a reference on @mm.
85640 */
85641-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
85642- void *buf, int len, int write)
85643+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
85644+ void *buf, size_t len, int write)
85645 {
85646 return __access_remote_vm(NULL, mm, addr, buf, len, write);
85647 }
85648@@ -4153,11 +4441,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
85649 * Source/target buffer must be kernel space,
85650 * Do not walk the page table directly, use get_user_pages
85651 */
85652-int access_process_vm(struct task_struct *tsk, unsigned long addr,
85653- void *buf, int len, int write)
85654+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
85655+ void *buf, size_t len, int write)
85656 {
85657 struct mm_struct *mm;
85658- int ret;
85659+ ssize_t ret;
85660
85661 mm = get_task_mm(tsk);
85662 if (!mm)
85663diff --git a/mm/mempolicy.c b/mm/mempolicy.c
85664index 4baf12e..5497066 100644
85665--- a/mm/mempolicy.c
85666+++ b/mm/mempolicy.c
85667@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
85668 unsigned long vmstart;
85669 unsigned long vmend;
85670
85671+#ifdef CONFIG_PAX_SEGMEXEC
85672+ struct vm_area_struct *vma_m;
85673+#endif
85674+
85675 vma = find_vma(mm, start);
85676 if (!vma || vma->vm_start > start)
85677 return -EFAULT;
85678@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
85679 err = vma_replace_policy(vma, new_pol);
85680 if (err)
85681 goto out;
85682+
85683+#ifdef CONFIG_PAX_SEGMEXEC
85684+ vma_m = pax_find_mirror_vma(vma);
85685+ if (vma_m) {
85686+ err = vma_replace_policy(vma_m, new_pol);
85687+ if (err)
85688+ goto out;
85689+ }
85690+#endif
85691+
85692 }
85693
85694 out:
85695@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
85696
85697 if (end < start)
85698 return -EINVAL;
85699+
85700+#ifdef CONFIG_PAX_SEGMEXEC
85701+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
85702+ if (end > SEGMEXEC_TASK_SIZE)
85703+ return -EINVAL;
85704+ } else
85705+#endif
85706+
85707+ if (end > TASK_SIZE)
85708+ return -EINVAL;
85709+
85710 if (end == start)
85711 return 0;
85712
85713@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
85714 */
85715 tcred = __task_cred(task);
85716 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
85717- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
85718- !capable(CAP_SYS_NICE)) {
85719+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
85720 rcu_read_unlock();
85721 err = -EPERM;
85722 goto out_put;
85723@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
85724 goto out;
85725 }
85726
85727+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85728+ if (mm != current->mm &&
85729+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
85730+ mmput(mm);
85731+ err = -EPERM;
85732+ goto out;
85733+ }
85734+#endif
85735+
85736 err = do_migrate_pages(mm, old, new,
85737 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
85738
85739diff --git a/mm/migrate.c b/mm/migrate.c
85740index 6f0c244..6d1ae32 100644
85741--- a/mm/migrate.c
85742+++ b/mm/migrate.c
85743@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
85744 */
85745 tcred = __task_cred(task);
85746 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
85747- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
85748- !capable(CAP_SYS_NICE)) {
85749+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
85750 rcu_read_unlock();
85751 err = -EPERM;
85752 goto out;
85753diff --git a/mm/mlock.c b/mm/mlock.c
85754index 79b7cf7..9944291 100644
85755--- a/mm/mlock.c
85756+++ b/mm/mlock.c
85757@@ -13,6 +13,7 @@
85758 #include <linux/pagemap.h>
85759 #include <linux/mempolicy.h>
85760 #include <linux/syscalls.h>
85761+#include <linux/security.h>
85762 #include <linux/sched.h>
85763 #include <linux/export.h>
85764 #include <linux/rmap.h>
85765@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
85766 {
85767 unsigned long nstart, end, tmp;
85768 struct vm_area_struct * vma, * prev;
85769- int error;
85770+ int error = 0;
85771
85772 VM_BUG_ON(start & ~PAGE_MASK);
85773 VM_BUG_ON(len != PAGE_ALIGN(len));
85774@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
85775 return -EINVAL;
85776 if (end == start)
85777 return 0;
85778+ if (end > TASK_SIZE)
85779+ return -EINVAL;
85780+
85781 vma = find_vma(current->mm, start);
85782 if (!vma || vma->vm_start > start)
85783 return -ENOMEM;
85784@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
85785 for (nstart = start ; ; ) {
85786 vm_flags_t newflags;
85787
85788+#ifdef CONFIG_PAX_SEGMEXEC
85789+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
85790+ break;
85791+#endif
85792+
85793 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
85794
85795 newflags = vma->vm_flags & ~VM_LOCKED;
85796@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
85797 lock_limit >>= PAGE_SHIFT;
85798
85799 /* check against resource limits */
85800+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
85801 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
85802 error = do_mlock(start, len, 1);
85803 up_write(&current->mm->mmap_sem);
85804@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
85805 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
85806 vm_flags_t newflags;
85807
85808+#ifdef CONFIG_PAX_SEGMEXEC
85809+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
85810+ break;
85811+#endif
85812+
85813 newflags = vma->vm_flags & ~VM_LOCKED;
85814 if (flags & MCL_CURRENT)
85815 newflags |= VM_LOCKED;
85816@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
85817 lock_limit >>= PAGE_SHIFT;
85818
85819 ret = -ENOMEM;
85820+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
85821 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
85822 capable(CAP_IPC_LOCK))
85823 ret = do_mlockall(flags);
85824diff --git a/mm/mmap.c b/mm/mmap.c
85825index 7dbe397..bfb7626 100644
85826--- a/mm/mmap.c
85827+++ b/mm/mmap.c
85828@@ -36,6 +36,7 @@
85829 #include <linux/sched/sysctl.h>
85830 #include <linux/notifier.h>
85831 #include <linux/memory.h>
85832+#include <linux/random.h>
85833
85834 #include <asm/uaccess.h>
85835 #include <asm/cacheflush.h>
85836@@ -52,6 +53,16 @@
85837 #define arch_rebalance_pgtables(addr, len) (addr)
85838 #endif
85839
85840+static inline void verify_mm_writelocked(struct mm_struct *mm)
85841+{
85842+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
85843+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
85844+ up_read(&mm->mmap_sem);
85845+ BUG();
85846+ }
85847+#endif
85848+}
85849+
85850 static void unmap_region(struct mm_struct *mm,
85851 struct vm_area_struct *vma, struct vm_area_struct *prev,
85852 unsigned long start, unsigned long end);
85853@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
85854 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
85855 *
85856 */
85857-pgprot_t protection_map[16] = {
85858+pgprot_t protection_map[16] __read_only = {
85859 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
85860 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
85861 };
85862
85863-pgprot_t vm_get_page_prot(unsigned long vm_flags)
85864+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
85865 {
85866- return __pgprot(pgprot_val(protection_map[vm_flags &
85867+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
85868 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
85869 pgprot_val(arch_vm_get_page_prot(vm_flags)));
85870+
85871+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
85872+ if (!(__supported_pte_mask & _PAGE_NX) &&
85873+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
85874+ (vm_flags & (VM_READ | VM_WRITE)))
85875+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
85876+#endif
85877+
85878+ return prot;
85879 }
85880 EXPORT_SYMBOL(vm_get_page_prot);
85881
85882@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
85883 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
85884 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
85885 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
85886+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
85887 /*
85888 * Make sure vm_committed_as in one cacheline and not cacheline shared with
85889 * other variables. It can be updated by several CPUs frequently.
85890@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
85891 struct vm_area_struct *next = vma->vm_next;
85892
85893 might_sleep();
85894+ BUG_ON(vma->vm_mirror);
85895 if (vma->vm_ops && vma->vm_ops->close)
85896 vma->vm_ops->close(vma);
85897 if (vma->vm_file)
85898@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
85899 * not page aligned -Ram Gupta
85900 */
85901 rlim = rlimit(RLIMIT_DATA);
85902+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
85903 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
85904 (mm->end_data - mm->start_data) > rlim)
85905 goto out;
85906@@ -933,6 +956,12 @@ static int
85907 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
85908 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
85909 {
85910+
85911+#ifdef CONFIG_PAX_SEGMEXEC
85912+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
85913+ return 0;
85914+#endif
85915+
85916 if (is_mergeable_vma(vma, file, vm_flags) &&
85917 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
85918 if (vma->vm_pgoff == vm_pgoff)
85919@@ -952,6 +981,12 @@ static int
85920 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
85921 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
85922 {
85923+
85924+#ifdef CONFIG_PAX_SEGMEXEC
85925+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
85926+ return 0;
85927+#endif
85928+
85929 if (is_mergeable_vma(vma, file, vm_flags) &&
85930 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
85931 pgoff_t vm_pglen;
85932@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
85933 struct vm_area_struct *vma_merge(struct mm_struct *mm,
85934 struct vm_area_struct *prev, unsigned long addr,
85935 unsigned long end, unsigned long vm_flags,
85936- struct anon_vma *anon_vma, struct file *file,
85937+ struct anon_vma *anon_vma, struct file *file,
85938 pgoff_t pgoff, struct mempolicy *policy)
85939 {
85940 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
85941 struct vm_area_struct *area, *next;
85942 int err;
85943
85944+#ifdef CONFIG_PAX_SEGMEXEC
85945+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
85946+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
85947+
85948+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
85949+#endif
85950+
85951 /*
85952 * We later require that vma->vm_flags == vm_flags,
85953 * so this tests vma->vm_flags & VM_SPECIAL, too.
85954@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
85955 if (next && next->vm_end == end) /* cases 6, 7, 8 */
85956 next = next->vm_next;
85957
85958+#ifdef CONFIG_PAX_SEGMEXEC
85959+ if (prev)
85960+ prev_m = pax_find_mirror_vma(prev);
85961+ if (area)
85962+ area_m = pax_find_mirror_vma(area);
85963+ if (next)
85964+ next_m = pax_find_mirror_vma(next);
85965+#endif
85966+
85967 /*
85968 * Can it merge with the predecessor?
85969 */
85970@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
85971 /* cases 1, 6 */
85972 err = vma_adjust(prev, prev->vm_start,
85973 next->vm_end, prev->vm_pgoff, NULL);
85974- } else /* cases 2, 5, 7 */
85975+
85976+#ifdef CONFIG_PAX_SEGMEXEC
85977+ if (!err && prev_m)
85978+ err = vma_adjust(prev_m, prev_m->vm_start,
85979+ next_m->vm_end, prev_m->vm_pgoff, NULL);
85980+#endif
85981+
85982+ } else { /* cases 2, 5, 7 */
85983 err = vma_adjust(prev, prev->vm_start,
85984 end, prev->vm_pgoff, NULL);
85985+
85986+#ifdef CONFIG_PAX_SEGMEXEC
85987+ if (!err && prev_m)
85988+ err = vma_adjust(prev_m, prev_m->vm_start,
85989+ end_m, prev_m->vm_pgoff, NULL);
85990+#endif
85991+
85992+ }
85993 if (err)
85994 return NULL;
85995 khugepaged_enter_vma_merge(prev);
85996@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
85997 mpol_equal(policy, vma_policy(next)) &&
85998 can_vma_merge_before(next, vm_flags,
85999 anon_vma, file, pgoff+pglen)) {
86000- if (prev && addr < prev->vm_end) /* case 4 */
86001+ if (prev && addr < prev->vm_end) { /* case 4 */
86002 err = vma_adjust(prev, prev->vm_start,
86003 addr, prev->vm_pgoff, NULL);
86004- else /* cases 3, 8 */
86005+
86006+#ifdef CONFIG_PAX_SEGMEXEC
86007+ if (!err && prev_m)
86008+ err = vma_adjust(prev_m, prev_m->vm_start,
86009+ addr_m, prev_m->vm_pgoff, NULL);
86010+#endif
86011+
86012+ } else { /* cases 3, 8 */
86013 err = vma_adjust(area, addr, next->vm_end,
86014 next->vm_pgoff - pglen, NULL);
86015+
86016+#ifdef CONFIG_PAX_SEGMEXEC
86017+ if (!err && area_m)
86018+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
86019+ next_m->vm_pgoff - pglen, NULL);
86020+#endif
86021+
86022+ }
86023 if (err)
86024 return NULL;
86025 khugepaged_enter_vma_merge(area);
86026@@ -1165,8 +1246,10 @@ none:
86027 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
86028 struct file *file, long pages)
86029 {
86030- const unsigned long stack_flags
86031- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
86032+
86033+#ifdef CONFIG_PAX_RANDMMAP
86034+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
86035+#endif
86036
86037 mm->total_vm += pages;
86038
86039@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
86040 mm->shared_vm += pages;
86041 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
86042 mm->exec_vm += pages;
86043- } else if (flags & stack_flags)
86044+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
86045 mm->stack_vm += pages;
86046 }
86047 #endif /* CONFIG_PROC_FS */
86048@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
86049 * (the exception is when the underlying filesystem is noexec
86050 * mounted, in which case we dont add PROT_EXEC.)
86051 */
86052- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
86053+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
86054 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
86055 prot |= PROT_EXEC;
86056
86057@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
86058 /* Obtain the address to map to. we verify (or select) it and ensure
86059 * that it represents a valid section of the address space.
86060 */
86061- addr = get_unmapped_area(file, addr, len, pgoff, flags);
86062+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
86063 if (addr & ~PAGE_MASK)
86064 return addr;
86065
86066@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
86067 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
86068 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
86069
86070+#ifdef CONFIG_PAX_MPROTECT
86071+ if (mm->pax_flags & MF_PAX_MPROTECT) {
86072+
86073+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
86074+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
86075+ mm->binfmt->handle_mmap)
86076+ mm->binfmt->handle_mmap(file);
86077+#endif
86078+
86079+#ifndef CONFIG_PAX_MPROTECT_COMPAT
86080+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
86081+ gr_log_rwxmmap(file);
86082+
86083+#ifdef CONFIG_PAX_EMUPLT
86084+ vm_flags &= ~VM_EXEC;
86085+#else
86086+ return -EPERM;
86087+#endif
86088+
86089+ }
86090+
86091+ if (!(vm_flags & VM_EXEC))
86092+ vm_flags &= ~VM_MAYEXEC;
86093+#else
86094+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
86095+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
86096+#endif
86097+ else
86098+ vm_flags &= ~VM_MAYWRITE;
86099+ }
86100+#endif
86101+
86102+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
86103+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
86104+ vm_flags &= ~VM_PAGEEXEC;
86105+#endif
86106+
86107 if (flags & MAP_LOCKED)
86108 if (!can_do_mlock())
86109 return -EPERM;
86110@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
86111 locked += mm->locked_vm;
86112 lock_limit = rlimit(RLIMIT_MEMLOCK);
86113 lock_limit >>= PAGE_SHIFT;
86114+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
86115 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
86116 return -EAGAIN;
86117 }
86118@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
86119 vm_flags |= VM_NORESERVE;
86120 }
86121
86122+ if (!gr_acl_handle_mmap(file, prot))
86123+ return -EACCES;
86124+
86125 addr = mmap_region(file, addr, len, vm_flags, pgoff);
86126 if (!IS_ERR_VALUE(addr) &&
86127 ((vm_flags & VM_LOCKED) ||
86128@@ -1432,7 +1556,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
86129 vm_flags_t vm_flags = vma->vm_flags;
86130
86131 /* If it was private or non-writable, the write bit is already clear */
86132- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
86133+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
86134 return 0;
86135
86136 /* The backer wishes to know when pages are first written to? */
86137@@ -1480,7 +1604,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
86138 unsigned long charged = 0;
86139 struct inode *inode = file ? file_inode(file) : NULL;
86140
86141+#ifdef CONFIG_PAX_SEGMEXEC
86142+ struct vm_area_struct *vma_m = NULL;
86143+#endif
86144+
86145+ /*
86146+ * mm->mmap_sem is required to protect against another thread
86147+ * changing the mappings in case we sleep.
86148+ */
86149+ verify_mm_writelocked(mm);
86150+
86151 /* Check against address space limit. */
86152+
86153+#ifdef CONFIG_PAX_RANDMMAP
86154+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
86155+#endif
86156+
86157 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
86158 unsigned long nr_pages;
86159
86160@@ -1499,11 +1638,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
86161
86162 /* Clear old maps */
86163 error = -ENOMEM;
86164-munmap_back:
86165 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
86166 if (do_munmap(mm, addr, len))
86167 return -ENOMEM;
86168- goto munmap_back;
86169+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
86170 }
86171
86172 /*
86173@@ -1534,6 +1672,16 @@ munmap_back:
86174 goto unacct_error;
86175 }
86176
86177+#ifdef CONFIG_PAX_SEGMEXEC
86178+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
86179+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
86180+ if (!vma_m) {
86181+ error = -ENOMEM;
86182+ goto free_vma;
86183+ }
86184+ }
86185+#endif
86186+
86187 vma->vm_mm = mm;
86188 vma->vm_start = addr;
86189 vma->vm_end = addr + len;
86190@@ -1558,6 +1706,13 @@ munmap_back:
86191 if (error)
86192 goto unmap_and_free_vma;
86193
86194+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
86195+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
86196+ vma->vm_flags |= VM_PAGEEXEC;
86197+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
86198+ }
86199+#endif
86200+
86201 /* Can addr have changed??
86202 *
86203 * Answer: Yes, several device drivers can do it in their
86204@@ -1596,6 +1751,11 @@ munmap_back:
86205 vma_link(mm, vma, prev, rb_link, rb_parent);
86206 file = vma->vm_file;
86207
86208+#ifdef CONFIG_PAX_SEGMEXEC
86209+ if (vma_m)
86210+ BUG_ON(pax_mirror_vma(vma_m, vma));
86211+#endif
86212+
86213 /* Once vma denies write, undo our temporary denial count */
86214 if (correct_wcount)
86215 atomic_inc(&inode->i_writecount);
86216@@ -1603,6 +1763,7 @@ out:
86217 perf_event_mmap(vma);
86218
86219 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
86220+ track_exec_limit(mm, addr, addr + len, vm_flags);
86221 if (vm_flags & VM_LOCKED) {
86222 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
86223 vma == get_gate_vma(current->mm)))
86224@@ -1626,6 +1787,12 @@ unmap_and_free_vma:
86225 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
86226 charged = 0;
86227 free_vma:
86228+
86229+#ifdef CONFIG_PAX_SEGMEXEC
86230+ if (vma_m)
86231+ kmem_cache_free(vm_area_cachep, vma_m);
86232+#endif
86233+
86234 kmem_cache_free(vm_area_cachep, vma);
86235 unacct_error:
86236 if (charged)
86237@@ -1633,7 +1800,63 @@ unacct_error:
86238 return error;
86239 }
86240
86241-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
86242+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
86243+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
86244+{
86245+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
86246+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
86247+
86248+ return 0;
86249+}
86250+#endif
86251+
86252+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
86253+{
86254+ if (!vma) {
86255+#ifdef CONFIG_STACK_GROWSUP
86256+ if (addr > sysctl_heap_stack_gap)
86257+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
86258+ else
86259+ vma = find_vma(current->mm, 0);
86260+ if (vma && (vma->vm_flags & VM_GROWSUP))
86261+ return false;
86262+#endif
86263+ return true;
86264+ }
86265+
86266+ if (addr + len > vma->vm_start)
86267+ return false;
86268+
86269+ if (vma->vm_flags & VM_GROWSDOWN)
86270+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
86271+#ifdef CONFIG_STACK_GROWSUP
86272+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
86273+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
86274+#endif
86275+ else if (offset)
86276+ return offset <= vma->vm_start - addr - len;
86277+
86278+ return true;
86279+}
86280+
86281+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
86282+{
86283+ if (vma->vm_start < len)
86284+ return -ENOMEM;
86285+
86286+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
86287+ if (offset <= vma->vm_start - len)
86288+ return vma->vm_start - len - offset;
86289+ else
86290+ return -ENOMEM;
86291+ }
86292+
86293+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
86294+ return vma->vm_start - len - sysctl_heap_stack_gap;
86295+ return -ENOMEM;
86296+}
86297+
86298+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
86299 {
86300 /*
86301 * We implement the search by looking for an rbtree node that
86302@@ -1681,11 +1904,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
86303 }
86304 }
86305
86306- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
86307+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
86308 check_current:
86309 /* Check if current node has a suitable gap */
86310 if (gap_start > high_limit)
86311 return -ENOMEM;
86312+
86313+ if (gap_end - gap_start > info->threadstack_offset)
86314+ gap_start += info->threadstack_offset;
86315+ else
86316+ gap_start = gap_end;
86317+
86318+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
86319+ if (gap_end - gap_start > sysctl_heap_stack_gap)
86320+ gap_start += sysctl_heap_stack_gap;
86321+ else
86322+ gap_start = gap_end;
86323+ }
86324+ if (vma->vm_flags & VM_GROWSDOWN) {
86325+ if (gap_end - gap_start > sysctl_heap_stack_gap)
86326+ gap_end -= sysctl_heap_stack_gap;
86327+ else
86328+ gap_end = gap_start;
86329+ }
86330 if (gap_end >= low_limit && gap_end - gap_start >= length)
86331 goto found;
86332
86333@@ -1735,7 +1976,7 @@ found:
86334 return gap_start;
86335 }
86336
86337-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
86338+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
86339 {
86340 struct mm_struct *mm = current->mm;
86341 struct vm_area_struct *vma;
86342@@ -1789,6 +2030,24 @@ check_current:
86343 gap_end = vma->vm_start;
86344 if (gap_end < low_limit)
86345 return -ENOMEM;
86346+
86347+ if (gap_end - gap_start > info->threadstack_offset)
86348+ gap_end -= info->threadstack_offset;
86349+ else
86350+ gap_end = gap_start;
86351+
86352+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
86353+ if (gap_end - gap_start > sysctl_heap_stack_gap)
86354+ gap_start += sysctl_heap_stack_gap;
86355+ else
86356+ gap_start = gap_end;
86357+ }
86358+ if (vma->vm_flags & VM_GROWSDOWN) {
86359+ if (gap_end - gap_start > sysctl_heap_stack_gap)
86360+ gap_end -= sysctl_heap_stack_gap;
86361+ else
86362+ gap_end = gap_start;
86363+ }
86364 if (gap_start <= high_limit && gap_end - gap_start >= length)
86365 goto found;
86366
86367@@ -1852,6 +2111,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
86368 struct mm_struct *mm = current->mm;
86369 struct vm_area_struct *vma;
86370 struct vm_unmapped_area_info info;
86371+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
86372
86373 if (len > TASK_SIZE)
86374 return -ENOMEM;
86375@@ -1859,29 +2119,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
86376 if (flags & MAP_FIXED)
86377 return addr;
86378
86379+#ifdef CONFIG_PAX_RANDMMAP
86380+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
86381+#endif
86382+
86383 if (addr) {
86384 addr = PAGE_ALIGN(addr);
86385 vma = find_vma(mm, addr);
86386- if (TASK_SIZE - len >= addr &&
86387- (!vma || addr + len <= vma->vm_start))
86388+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
86389 return addr;
86390 }
86391
86392 info.flags = 0;
86393 info.length = len;
86394 info.low_limit = TASK_UNMAPPED_BASE;
86395+
86396+#ifdef CONFIG_PAX_RANDMMAP
86397+ if (mm->pax_flags & MF_PAX_RANDMMAP)
86398+ info.low_limit += mm->delta_mmap;
86399+#endif
86400+
86401 info.high_limit = TASK_SIZE;
86402 info.align_mask = 0;
86403+ info.threadstack_offset = offset;
86404 return vm_unmapped_area(&info);
86405 }
86406 #endif
86407
86408 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
86409 {
86410+
86411+#ifdef CONFIG_PAX_SEGMEXEC
86412+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
86413+ return;
86414+#endif
86415+
86416 /*
86417 * Is this a new hole at the lowest possible address?
86418 */
86419- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
86420+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
86421 mm->free_area_cache = addr;
86422 }
86423
86424@@ -1899,6 +2175,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
86425 struct mm_struct *mm = current->mm;
86426 unsigned long addr = addr0;
86427 struct vm_unmapped_area_info info;
86428+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
86429
86430 /* requested length too big for entire address space */
86431 if (len > TASK_SIZE)
86432@@ -1907,12 +2184,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
86433 if (flags & MAP_FIXED)
86434 return addr;
86435
86436+#ifdef CONFIG_PAX_RANDMMAP
86437+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
86438+#endif
86439+
86440 /* requesting a specific address */
86441 if (addr) {
86442 addr = PAGE_ALIGN(addr);
86443 vma = find_vma(mm, addr);
86444- if (TASK_SIZE - len >= addr &&
86445- (!vma || addr + len <= vma->vm_start))
86446+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
86447 return addr;
86448 }
86449
86450@@ -1921,6 +2201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
86451 info.low_limit = PAGE_SIZE;
86452 info.high_limit = mm->mmap_base;
86453 info.align_mask = 0;
86454+ info.threadstack_offset = offset;
86455 addr = vm_unmapped_area(&info);
86456
86457 /*
86458@@ -1933,6 +2214,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
86459 VM_BUG_ON(addr != -ENOMEM);
86460 info.flags = 0;
86461 info.low_limit = TASK_UNMAPPED_BASE;
86462+
86463+#ifdef CONFIG_PAX_RANDMMAP
86464+ if (mm->pax_flags & MF_PAX_RANDMMAP)
86465+ info.low_limit += mm->delta_mmap;
86466+#endif
86467+
86468 info.high_limit = TASK_SIZE;
86469 addr = vm_unmapped_area(&info);
86470 }
86471@@ -1943,6 +2230,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
86472
86473 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
86474 {
86475+
86476+#ifdef CONFIG_PAX_SEGMEXEC
86477+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
86478+ return;
86479+#endif
86480+
86481 /*
86482 * Is this a new hole at the highest possible address?
86483 */
86484@@ -1950,8 +2243,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
86485 mm->free_area_cache = addr;
86486
86487 /* dont allow allocations above current base */
86488- if (mm->free_area_cache > mm->mmap_base)
86489+ if (mm->free_area_cache > mm->mmap_base) {
86490 mm->free_area_cache = mm->mmap_base;
86491+ mm->cached_hole_size = ~0UL;
86492+ }
86493 }
86494
86495 unsigned long
86496@@ -2047,6 +2342,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
86497 return vma;
86498 }
86499
86500+#ifdef CONFIG_PAX_SEGMEXEC
86501+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
86502+{
86503+ struct vm_area_struct *vma_m;
86504+
86505+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
86506+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
86507+ BUG_ON(vma->vm_mirror);
86508+ return NULL;
86509+ }
86510+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
86511+ vma_m = vma->vm_mirror;
86512+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
86513+ BUG_ON(vma->vm_file != vma_m->vm_file);
86514+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
86515+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
86516+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
86517+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
86518+ return vma_m;
86519+}
86520+#endif
86521+
86522 /*
86523 * Verify that the stack growth is acceptable and
86524 * update accounting. This is shared with both the
86525@@ -2063,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
86526 return -ENOMEM;
86527
86528 /* Stack limit test */
86529+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
86530 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
86531 return -ENOMEM;
86532
86533@@ -2073,6 +2391,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
86534 locked = mm->locked_vm + grow;
86535 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
86536 limit >>= PAGE_SHIFT;
86537+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
86538 if (locked > limit && !capable(CAP_IPC_LOCK))
86539 return -ENOMEM;
86540 }
86541@@ -2102,37 +2421,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
86542 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
86543 * vma is the last one with address > vma->vm_end. Have to extend vma.
86544 */
86545+#ifndef CONFIG_IA64
86546+static
86547+#endif
86548 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
86549 {
86550 int error;
86551+ bool locknext;
86552
86553 if (!(vma->vm_flags & VM_GROWSUP))
86554 return -EFAULT;
86555
86556+ /* Also guard against wrapping around to address 0. */
86557+ if (address < PAGE_ALIGN(address+1))
86558+ address = PAGE_ALIGN(address+1);
86559+ else
86560+ return -ENOMEM;
86561+
86562 /*
86563 * We must make sure the anon_vma is allocated
86564 * so that the anon_vma locking is not a noop.
86565 */
86566 if (unlikely(anon_vma_prepare(vma)))
86567 return -ENOMEM;
86568+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
86569+ if (locknext && anon_vma_prepare(vma->vm_next))
86570+ return -ENOMEM;
86571 vma_lock_anon_vma(vma);
86572+ if (locknext)
86573+ vma_lock_anon_vma(vma->vm_next);
86574
86575 /*
86576 * vma->vm_start/vm_end cannot change under us because the caller
86577 * is required to hold the mmap_sem in read mode. We need the
86578- * anon_vma lock to serialize against concurrent expand_stacks.
86579- * Also guard against wrapping around to address 0.
86580+ * anon_vma locks to serialize against concurrent expand_stacks
86581+ * and expand_upwards.
86582 */
86583- if (address < PAGE_ALIGN(address+4))
86584- address = PAGE_ALIGN(address+4);
86585- else {
86586- vma_unlock_anon_vma(vma);
86587- return -ENOMEM;
86588- }
86589 error = 0;
86590
86591 /* Somebody else might have raced and expanded it already */
86592- if (address > vma->vm_end) {
86593+ 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)
86594+ error = -ENOMEM;
86595+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
86596 unsigned long size, grow;
86597
86598 size = address - vma->vm_start;
86599@@ -2167,6 +2497,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
86600 }
86601 }
86602 }
86603+ if (locknext)
86604+ vma_unlock_anon_vma(vma->vm_next);
86605 vma_unlock_anon_vma(vma);
86606 khugepaged_enter_vma_merge(vma);
86607 validate_mm(vma->vm_mm);
86608@@ -2181,6 +2513,8 @@ int expand_downwards(struct vm_area_struct *vma,
86609 unsigned long address)
86610 {
86611 int error;
86612+ bool lockprev = false;
86613+ struct vm_area_struct *prev;
86614
86615 /*
86616 * We must make sure the anon_vma is allocated
86617@@ -2194,6 +2528,15 @@ int expand_downwards(struct vm_area_struct *vma,
86618 if (error)
86619 return error;
86620
86621+ prev = vma->vm_prev;
86622+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
86623+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
86624+#endif
86625+ if (lockprev && anon_vma_prepare(prev))
86626+ return -ENOMEM;
86627+ if (lockprev)
86628+ vma_lock_anon_vma(prev);
86629+
86630 vma_lock_anon_vma(vma);
86631
86632 /*
86633@@ -2203,9 +2546,17 @@ int expand_downwards(struct vm_area_struct *vma,
86634 */
86635
86636 /* Somebody else might have raced and expanded it already */
86637- if (address < vma->vm_start) {
86638+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
86639+ error = -ENOMEM;
86640+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
86641 unsigned long size, grow;
86642
86643+#ifdef CONFIG_PAX_SEGMEXEC
86644+ struct vm_area_struct *vma_m;
86645+
86646+ vma_m = pax_find_mirror_vma(vma);
86647+#endif
86648+
86649 size = vma->vm_end - address;
86650 grow = (vma->vm_start - address) >> PAGE_SHIFT;
86651
86652@@ -2230,13 +2581,27 @@ int expand_downwards(struct vm_area_struct *vma,
86653 vma->vm_pgoff -= grow;
86654 anon_vma_interval_tree_post_update_vma(vma);
86655 vma_gap_update(vma);
86656+
86657+#ifdef CONFIG_PAX_SEGMEXEC
86658+ if (vma_m) {
86659+ anon_vma_interval_tree_pre_update_vma(vma_m);
86660+ vma_m->vm_start -= grow << PAGE_SHIFT;
86661+ vma_m->vm_pgoff -= grow;
86662+ anon_vma_interval_tree_post_update_vma(vma_m);
86663+ vma_gap_update(vma_m);
86664+ }
86665+#endif
86666+
86667 spin_unlock(&vma->vm_mm->page_table_lock);
86668
86669+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
86670 perf_event_mmap(vma);
86671 }
86672 }
86673 }
86674 vma_unlock_anon_vma(vma);
86675+ if (lockprev)
86676+ vma_unlock_anon_vma(prev);
86677 khugepaged_enter_vma_merge(vma);
86678 validate_mm(vma->vm_mm);
86679 return error;
86680@@ -2334,6 +2699,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
86681 do {
86682 long nrpages = vma_pages(vma);
86683
86684+#ifdef CONFIG_PAX_SEGMEXEC
86685+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
86686+ vma = remove_vma(vma);
86687+ continue;
86688+ }
86689+#endif
86690+
86691 if (vma->vm_flags & VM_ACCOUNT)
86692 nr_accounted += nrpages;
86693 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
86694@@ -2356,7 +2728,7 @@ static void unmap_region(struct mm_struct *mm,
86695 struct mmu_gather tlb;
86696
86697 lru_add_drain();
86698- tlb_gather_mmu(&tlb, mm, 0);
86699+ tlb_gather_mmu(&tlb, mm, start, end);
86700 update_hiwater_rss(mm);
86701 unmap_vmas(&tlb, vma, start, end);
86702 free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS,
86703@@ -2379,6 +2751,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
86704 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
86705 vma->vm_prev = NULL;
86706 do {
86707+
86708+#ifdef CONFIG_PAX_SEGMEXEC
86709+ if (vma->vm_mirror) {
86710+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
86711+ vma->vm_mirror->vm_mirror = NULL;
86712+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
86713+ vma->vm_mirror = NULL;
86714+ }
86715+#endif
86716+
86717 vma_rb_erase(vma, &mm->mm_rb);
86718 mm->map_count--;
86719 tail_vma = vma;
86720@@ -2410,14 +2792,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
86721 struct vm_area_struct *new;
86722 int err = -ENOMEM;
86723
86724+#ifdef CONFIG_PAX_SEGMEXEC
86725+ struct vm_area_struct *vma_m, *new_m = NULL;
86726+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
86727+#endif
86728+
86729 if (is_vm_hugetlb_page(vma) && (addr &
86730 ~(huge_page_mask(hstate_vma(vma)))))
86731 return -EINVAL;
86732
86733+#ifdef CONFIG_PAX_SEGMEXEC
86734+ vma_m = pax_find_mirror_vma(vma);
86735+#endif
86736+
86737 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86738 if (!new)
86739 goto out_err;
86740
86741+#ifdef CONFIG_PAX_SEGMEXEC
86742+ if (vma_m) {
86743+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86744+ if (!new_m) {
86745+ kmem_cache_free(vm_area_cachep, new);
86746+ goto out_err;
86747+ }
86748+ }
86749+#endif
86750+
86751 /* most fields are the same, copy all, and then fixup */
86752 *new = *vma;
86753
86754@@ -2430,6 +2831,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
86755 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
86756 }
86757
86758+#ifdef CONFIG_PAX_SEGMEXEC
86759+ if (vma_m) {
86760+ *new_m = *vma_m;
86761+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
86762+ new_m->vm_mirror = new;
86763+ new->vm_mirror = new_m;
86764+
86765+ if (new_below)
86766+ new_m->vm_end = addr_m;
86767+ else {
86768+ new_m->vm_start = addr_m;
86769+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
86770+ }
86771+ }
86772+#endif
86773+
86774 pol = mpol_dup(vma_policy(vma));
86775 if (IS_ERR(pol)) {
86776 err = PTR_ERR(pol);
86777@@ -2452,6 +2869,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
86778 else
86779 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
86780
86781+#ifdef CONFIG_PAX_SEGMEXEC
86782+ if (!err && vma_m) {
86783+ if (anon_vma_clone(new_m, vma_m))
86784+ goto out_free_mpol;
86785+
86786+ mpol_get(pol);
86787+ vma_set_policy(new_m, pol);
86788+
86789+ if (new_m->vm_file)
86790+ get_file(new_m->vm_file);
86791+
86792+ if (new_m->vm_ops && new_m->vm_ops->open)
86793+ new_m->vm_ops->open(new_m);
86794+
86795+ if (new_below)
86796+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
86797+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
86798+ else
86799+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
86800+
86801+ if (err) {
86802+ if (new_m->vm_ops && new_m->vm_ops->close)
86803+ new_m->vm_ops->close(new_m);
86804+ if (new_m->vm_file)
86805+ fput(new_m->vm_file);
86806+ mpol_put(pol);
86807+ }
86808+ }
86809+#endif
86810+
86811 /* Success. */
86812 if (!err)
86813 return 0;
86814@@ -2461,10 +2908,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
86815 new->vm_ops->close(new);
86816 if (new->vm_file)
86817 fput(new->vm_file);
86818- unlink_anon_vmas(new);
86819 out_free_mpol:
86820 mpol_put(pol);
86821 out_free_vma:
86822+
86823+#ifdef CONFIG_PAX_SEGMEXEC
86824+ if (new_m) {
86825+ unlink_anon_vmas(new_m);
86826+ kmem_cache_free(vm_area_cachep, new_m);
86827+ }
86828+#endif
86829+
86830+ unlink_anon_vmas(new);
86831 kmem_cache_free(vm_area_cachep, new);
86832 out_err:
86833 return err;
86834@@ -2477,6 +2932,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
86835 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
86836 unsigned long addr, int new_below)
86837 {
86838+
86839+#ifdef CONFIG_PAX_SEGMEXEC
86840+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
86841+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
86842+ if (mm->map_count >= sysctl_max_map_count-1)
86843+ return -ENOMEM;
86844+ } else
86845+#endif
86846+
86847 if (mm->map_count >= sysctl_max_map_count)
86848 return -ENOMEM;
86849
86850@@ -2488,11 +2952,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
86851 * work. This now handles partial unmappings.
86852 * Jeremy Fitzhardinge <jeremy@goop.org>
86853 */
86854+#ifdef CONFIG_PAX_SEGMEXEC
86855 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
86856 {
86857+ int ret = __do_munmap(mm, start, len);
86858+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
86859+ return ret;
86860+
86861+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
86862+}
86863+
86864+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
86865+#else
86866+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
86867+#endif
86868+{
86869 unsigned long end;
86870 struct vm_area_struct *vma, *prev, *last;
86871
86872+ /*
86873+ * mm->mmap_sem is required to protect against another thread
86874+ * changing the mappings in case we sleep.
86875+ */
86876+ verify_mm_writelocked(mm);
86877+
86878 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
86879 return -EINVAL;
86880
86881@@ -2567,6 +3050,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
86882 /* Fix up all other VM information */
86883 remove_vma_list(mm, vma);
86884
86885+ track_exec_limit(mm, start, end, 0UL);
86886+
86887 return 0;
86888 }
86889
86890@@ -2575,6 +3060,13 @@ int vm_munmap(unsigned long start, size_t len)
86891 int ret;
86892 struct mm_struct *mm = current->mm;
86893
86894+
86895+#ifdef CONFIG_PAX_SEGMEXEC
86896+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
86897+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
86898+ return -EINVAL;
86899+#endif
86900+
86901 down_write(&mm->mmap_sem);
86902 ret = do_munmap(mm, start, len);
86903 up_write(&mm->mmap_sem);
86904@@ -2588,16 +3080,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
86905 return vm_munmap(addr, len);
86906 }
86907
86908-static inline void verify_mm_writelocked(struct mm_struct *mm)
86909-{
86910-#ifdef CONFIG_DEBUG_VM
86911- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
86912- WARN_ON(1);
86913- up_read(&mm->mmap_sem);
86914- }
86915-#endif
86916-}
86917-
86918 /*
86919 * this is really a simplified "do_mmap". it only handles
86920 * anonymous maps. eventually we may be able to do some
86921@@ -2611,6 +3093,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
86922 struct rb_node ** rb_link, * rb_parent;
86923 pgoff_t pgoff = addr >> PAGE_SHIFT;
86924 int error;
86925+ unsigned long charged;
86926
86927 len = PAGE_ALIGN(len);
86928 if (!len)
86929@@ -2618,16 +3101,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
86930
86931 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
86932
86933+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
86934+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
86935+ flags &= ~VM_EXEC;
86936+
86937+#ifdef CONFIG_PAX_MPROTECT
86938+ if (mm->pax_flags & MF_PAX_MPROTECT)
86939+ flags &= ~VM_MAYEXEC;
86940+#endif
86941+
86942+ }
86943+#endif
86944+
86945 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
86946 if (error & ~PAGE_MASK)
86947 return error;
86948
86949+ charged = len >> PAGE_SHIFT;
86950+
86951 /*
86952 * mlock MCL_FUTURE?
86953 */
86954 if (mm->def_flags & VM_LOCKED) {
86955 unsigned long locked, lock_limit;
86956- locked = len >> PAGE_SHIFT;
86957+ locked = charged;
86958 locked += mm->locked_vm;
86959 lock_limit = rlimit(RLIMIT_MEMLOCK);
86960 lock_limit >>= PAGE_SHIFT;
86961@@ -2644,21 +3141,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
86962 /*
86963 * Clear old maps. this also does some error checking for us
86964 */
86965- munmap_back:
86966 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
86967 if (do_munmap(mm, addr, len))
86968 return -ENOMEM;
86969- goto munmap_back;
86970+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
86971 }
86972
86973 /* Check against address space limits *after* clearing old maps... */
86974- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
86975+ if (!may_expand_vm(mm, charged))
86976 return -ENOMEM;
86977
86978 if (mm->map_count > sysctl_max_map_count)
86979 return -ENOMEM;
86980
86981- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
86982+ if (security_vm_enough_memory_mm(mm, charged))
86983 return -ENOMEM;
86984
86985 /* Can we just expand an old private anonymous mapping? */
86986@@ -2672,7 +3168,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
86987 */
86988 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
86989 if (!vma) {
86990- vm_unacct_memory(len >> PAGE_SHIFT);
86991+ vm_unacct_memory(charged);
86992 return -ENOMEM;
86993 }
86994
86995@@ -2686,9 +3182,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
86996 vma_link(mm, vma, prev, rb_link, rb_parent);
86997 out:
86998 perf_event_mmap(vma);
86999- mm->total_vm += len >> PAGE_SHIFT;
87000+ mm->total_vm += charged;
87001 if (flags & VM_LOCKED)
87002- mm->locked_vm += (len >> PAGE_SHIFT);
87003+ mm->locked_vm += charged;
87004+ track_exec_limit(mm, addr, addr + len, flags);
87005 return addr;
87006 }
87007
87008@@ -2735,7 +3232,7 @@ void exit_mmap(struct mm_struct *mm)
87009
87010 lru_add_drain();
87011 flush_cache_mm(mm);
87012- tlb_gather_mmu(&tlb, mm, 1);
87013+ tlb_gather_mmu(&tlb, mm, 0, -1);
87014 /* update_hiwater_rss(mm) here? but nobody should be looking */
87015 /* Use -1 here to ensure all VMAs in the mm are unmapped */
87016 unmap_vmas(&tlb, vma, 0, -1);
87017@@ -2750,6 +3247,7 @@ void exit_mmap(struct mm_struct *mm)
87018 while (vma) {
87019 if (vma->vm_flags & VM_ACCOUNT)
87020 nr_accounted += vma_pages(vma);
87021+ vma->vm_mirror = NULL;
87022 vma = remove_vma(vma);
87023 }
87024 vm_unacct_memory(nr_accounted);
87025@@ -2766,6 +3264,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
87026 struct vm_area_struct *prev;
87027 struct rb_node **rb_link, *rb_parent;
87028
87029+#ifdef CONFIG_PAX_SEGMEXEC
87030+ struct vm_area_struct *vma_m = NULL;
87031+#endif
87032+
87033+ if (security_mmap_addr(vma->vm_start))
87034+ return -EPERM;
87035+
87036 /*
87037 * The vm_pgoff of a purely anonymous vma should be irrelevant
87038 * until its first write fault, when page's anon_vma and index
87039@@ -2789,7 +3294,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
87040 security_vm_enough_memory_mm(mm, vma_pages(vma)))
87041 return -ENOMEM;
87042
87043+#ifdef CONFIG_PAX_SEGMEXEC
87044+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
87045+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87046+ if (!vma_m)
87047+ return -ENOMEM;
87048+ }
87049+#endif
87050+
87051 vma_link(mm, vma, prev, rb_link, rb_parent);
87052+
87053+#ifdef CONFIG_PAX_SEGMEXEC
87054+ if (vma_m)
87055+ BUG_ON(pax_mirror_vma(vma_m, vma));
87056+#endif
87057+
87058 return 0;
87059 }
87060
87061@@ -2809,6 +3328,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
87062 struct mempolicy *pol;
87063 bool faulted_in_anon_vma = true;
87064
87065+ BUG_ON(vma->vm_mirror);
87066+
87067 /*
87068 * If anonymous vma has not yet been faulted, update new pgoff
87069 * to match new location, to increase its chance of merging.
87070@@ -2875,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
87071 return NULL;
87072 }
87073
87074+#ifdef CONFIG_PAX_SEGMEXEC
87075+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
87076+{
87077+ struct vm_area_struct *prev_m;
87078+ struct rb_node **rb_link_m, *rb_parent_m;
87079+ struct mempolicy *pol_m;
87080+
87081+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
87082+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
87083+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
87084+ *vma_m = *vma;
87085+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
87086+ if (anon_vma_clone(vma_m, vma))
87087+ return -ENOMEM;
87088+ pol_m = vma_policy(vma_m);
87089+ mpol_get(pol_m);
87090+ vma_set_policy(vma_m, pol_m);
87091+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
87092+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
87093+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
87094+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
87095+ if (vma_m->vm_file)
87096+ get_file(vma_m->vm_file);
87097+ if (vma_m->vm_ops && vma_m->vm_ops->open)
87098+ vma_m->vm_ops->open(vma_m);
87099+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
87100+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
87101+ vma_m->vm_mirror = vma;
87102+ vma->vm_mirror = vma_m;
87103+ return 0;
87104+}
87105+#endif
87106+
87107 /*
87108 * Return true if the calling process may expand its vm space by the passed
87109 * number of pages
87110@@ -2886,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
87111
87112 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
87113
87114+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
87115 if (cur + npages > lim)
87116 return 0;
87117 return 1;
87118@@ -2956,6 +3511,22 @@ int install_special_mapping(struct mm_struct *mm,
87119 vma->vm_start = addr;
87120 vma->vm_end = addr + len;
87121
87122+#ifdef CONFIG_PAX_MPROTECT
87123+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87124+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87125+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
87126+ return -EPERM;
87127+ if (!(vm_flags & VM_EXEC))
87128+ vm_flags &= ~VM_MAYEXEC;
87129+#else
87130+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87131+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87132+#endif
87133+ else
87134+ vm_flags &= ~VM_MAYWRITE;
87135+ }
87136+#endif
87137+
87138 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
87139 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87140
87141diff --git a/mm/mprotect.c b/mm/mprotect.c
87142index 94722a4..e661e29 100644
87143--- a/mm/mprotect.c
87144+++ b/mm/mprotect.c
87145@@ -23,10 +23,18 @@
87146 #include <linux/mmu_notifier.h>
87147 #include <linux/migrate.h>
87148 #include <linux/perf_event.h>
87149+#include <linux/sched/sysctl.h>
87150+
87151+#ifdef CONFIG_PAX_MPROTECT
87152+#include <linux/elf.h>
87153+#include <linux/binfmts.h>
87154+#endif
87155+
87156 #include <asm/uaccess.h>
87157 #include <asm/pgtable.h>
87158 #include <asm/cacheflush.h>
87159 #include <asm/tlbflush.h>
87160+#include <asm/mmu_context.h>
87161
87162 #ifndef pgprot_modify
87163 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
87164@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
87165 return pages;
87166 }
87167
87168+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
87169+/* called while holding the mmap semaphor for writing except stack expansion */
87170+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
87171+{
87172+ unsigned long oldlimit, newlimit = 0UL;
87173+
87174+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
87175+ return;
87176+
87177+ spin_lock(&mm->page_table_lock);
87178+ oldlimit = mm->context.user_cs_limit;
87179+ if ((prot & VM_EXEC) && oldlimit < end)
87180+ /* USER_CS limit moved up */
87181+ newlimit = end;
87182+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
87183+ /* USER_CS limit moved down */
87184+ newlimit = start;
87185+
87186+ if (newlimit) {
87187+ mm->context.user_cs_limit = newlimit;
87188+
87189+#ifdef CONFIG_SMP
87190+ wmb();
87191+ cpus_clear(mm->context.cpu_user_cs_mask);
87192+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
87193+#endif
87194+
87195+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
87196+ }
87197+ spin_unlock(&mm->page_table_lock);
87198+ if (newlimit == end) {
87199+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
87200+
87201+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
87202+ if (is_vm_hugetlb_page(vma))
87203+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
87204+ else
87205+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
87206+ }
87207+}
87208+#endif
87209+
87210 int
87211 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
87212 unsigned long start, unsigned long end, unsigned long newflags)
87213@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
87214 int error;
87215 int dirty_accountable = 0;
87216
87217+#ifdef CONFIG_PAX_SEGMEXEC
87218+ struct vm_area_struct *vma_m = NULL;
87219+ unsigned long start_m, end_m;
87220+
87221+ start_m = start + SEGMEXEC_TASK_SIZE;
87222+ end_m = end + SEGMEXEC_TASK_SIZE;
87223+#endif
87224+
87225 if (newflags == oldflags) {
87226 *pprev = vma;
87227 return 0;
87228 }
87229
87230+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
87231+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
87232+
87233+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
87234+ return -ENOMEM;
87235+
87236+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
87237+ return -ENOMEM;
87238+ }
87239+
87240 /*
87241 * If we make a private mapping writable we increase our commit;
87242 * but (without finer accounting) cannot reduce our commit if we
87243@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
87244 }
87245 }
87246
87247+#ifdef CONFIG_PAX_SEGMEXEC
87248+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
87249+ if (start != vma->vm_start) {
87250+ error = split_vma(mm, vma, start, 1);
87251+ if (error)
87252+ goto fail;
87253+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
87254+ *pprev = (*pprev)->vm_next;
87255+ }
87256+
87257+ if (end != vma->vm_end) {
87258+ error = split_vma(mm, vma, end, 0);
87259+ if (error)
87260+ goto fail;
87261+ }
87262+
87263+ if (pax_find_mirror_vma(vma)) {
87264+ error = __do_munmap(mm, start_m, end_m - start_m);
87265+ if (error)
87266+ goto fail;
87267+ } else {
87268+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87269+ if (!vma_m) {
87270+ error = -ENOMEM;
87271+ goto fail;
87272+ }
87273+ vma->vm_flags = newflags;
87274+ error = pax_mirror_vma(vma_m, vma);
87275+ if (error) {
87276+ vma->vm_flags = oldflags;
87277+ goto fail;
87278+ }
87279+ }
87280+ }
87281+#endif
87282+
87283 /*
87284 * First try to merge with previous and/or next vma.
87285 */
87286@@ -296,9 +400,21 @@ success:
87287 * vm_flags and vm_page_prot are protected by the mmap_sem
87288 * held in write mode.
87289 */
87290+
87291+#ifdef CONFIG_PAX_SEGMEXEC
87292+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
87293+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
87294+#endif
87295+
87296 vma->vm_flags = newflags;
87297+
87298+#ifdef CONFIG_PAX_MPROTECT
87299+ if (mm->binfmt && mm->binfmt->handle_mprotect)
87300+ mm->binfmt->handle_mprotect(vma, newflags);
87301+#endif
87302+
87303 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
87304- vm_get_page_prot(newflags));
87305+ vm_get_page_prot(vma->vm_flags));
87306
87307 if (vma_wants_writenotify(vma)) {
87308 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
87309@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
87310 end = start + len;
87311 if (end <= start)
87312 return -ENOMEM;
87313+
87314+#ifdef CONFIG_PAX_SEGMEXEC
87315+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
87316+ if (end > SEGMEXEC_TASK_SIZE)
87317+ return -EINVAL;
87318+ } else
87319+#endif
87320+
87321+ if (end > TASK_SIZE)
87322+ return -EINVAL;
87323+
87324 if (!arch_validate_prot(prot))
87325 return -EINVAL;
87326
87327@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
87328 /*
87329 * Does the application expect PROT_READ to imply PROT_EXEC:
87330 */
87331- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87332+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87333 prot |= PROT_EXEC;
87334
87335 vm_flags = calc_vm_prot_bits(prot);
87336@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
87337 if (start > vma->vm_start)
87338 prev = vma;
87339
87340+#ifdef CONFIG_PAX_MPROTECT
87341+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
87342+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
87343+#endif
87344+
87345 for (nstart = start ; ; ) {
87346 unsigned long newflags;
87347
87348@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
87349
87350 /* newflags >> 4 shift VM_MAY% in place of VM_% */
87351 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
87352+ if (prot & (PROT_WRITE | PROT_EXEC))
87353+ gr_log_rwxmprotect(vma);
87354+
87355+ error = -EACCES;
87356+ goto out;
87357+ }
87358+
87359+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
87360 error = -EACCES;
87361 goto out;
87362 }
87363@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
87364 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
87365 if (error)
87366 goto out;
87367+
87368+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
87369+
87370 nstart = tmp;
87371
87372 if (nstart < prev->vm_end)
87373diff --git a/mm/mremap.c b/mm/mremap.c
87374index 463a257..c0c7a92 100644
87375--- a/mm/mremap.c
87376+++ b/mm/mremap.c
87377@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
87378 continue;
87379 pte = ptep_get_and_clear(mm, old_addr, old_pte);
87380 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
87381+
87382+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
87383+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
87384+ pte = pte_exprotect(pte);
87385+#endif
87386+
87387 set_pte_at(mm, new_addr, new_pte, pte);
87388 }
87389
87390@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
87391 if (is_vm_hugetlb_page(vma))
87392 goto Einval;
87393
87394+#ifdef CONFIG_PAX_SEGMEXEC
87395+ if (pax_find_mirror_vma(vma))
87396+ goto Einval;
87397+#endif
87398+
87399 /* We can't remap across vm area boundaries */
87400 if (old_len > vma->vm_end - addr)
87401 goto Efault;
87402@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
87403 unsigned long ret = -EINVAL;
87404 unsigned long charged = 0;
87405 unsigned long map_flags;
87406+ unsigned long pax_task_size = TASK_SIZE;
87407
87408 if (new_addr & ~PAGE_MASK)
87409 goto out;
87410
87411- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
87412+#ifdef CONFIG_PAX_SEGMEXEC
87413+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
87414+ pax_task_size = SEGMEXEC_TASK_SIZE;
87415+#endif
87416+
87417+ pax_task_size -= PAGE_SIZE;
87418+
87419+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
87420 goto out;
87421
87422 /* Check if the location we're moving into overlaps the
87423 * old location at all, and fail if it does.
87424 */
87425- if ((new_addr <= addr) && (new_addr+new_len) > addr)
87426- goto out;
87427-
87428- if ((addr <= new_addr) && (addr+old_len) > new_addr)
87429+ if (addr + old_len > new_addr && new_addr + new_len > addr)
87430 goto out;
87431
87432 ret = do_munmap(mm, new_addr, new_len);
87433@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
87434 unsigned long ret = -EINVAL;
87435 unsigned long charged = 0;
87436 bool locked = false;
87437+ unsigned long pax_task_size = TASK_SIZE;
87438
87439 down_write(&current->mm->mmap_sem);
87440
87441@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
87442 if (!new_len)
87443 goto out;
87444
87445+#ifdef CONFIG_PAX_SEGMEXEC
87446+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
87447+ pax_task_size = SEGMEXEC_TASK_SIZE;
87448+#endif
87449+
87450+ pax_task_size -= PAGE_SIZE;
87451+
87452+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
87453+ old_len > pax_task_size || addr > pax_task_size-old_len)
87454+ goto out;
87455+
87456 if (flags & MREMAP_FIXED) {
87457 if (flags & MREMAP_MAYMOVE)
87458 ret = mremap_to(addr, old_len, new_addr, new_len,
87459@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
87460 new_addr = addr;
87461 }
87462 ret = addr;
87463+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
87464 goto out;
87465 }
87466 }
87467@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
87468 goto out;
87469 }
87470
87471+ map_flags = vma->vm_flags;
87472 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
87473+ if (!(ret & ~PAGE_MASK)) {
87474+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
87475+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
87476+ }
87477 }
87478 out:
87479 if (ret & ~PAGE_MASK)
87480diff --git a/mm/nommu.c b/mm/nommu.c
87481index 298884d..5f74980 100644
87482--- a/mm/nommu.c
87483+++ b/mm/nommu.c
87484@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
87485 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
87486 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87487 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87488-int heap_stack_gap = 0;
87489
87490 atomic_long_t mmap_pages_allocated;
87491
87492@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
87493 EXPORT_SYMBOL(find_vma);
87494
87495 /*
87496- * find a VMA
87497- * - we don't extend stack VMAs under NOMMU conditions
87498- */
87499-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
87500-{
87501- return find_vma(mm, addr);
87502-}
87503-
87504-/*
87505 * expand a stack to a given address
87506 * - not supported under NOMMU conditions
87507 */
87508@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
87509
87510 /* most fields are the same, copy all, and then fixup */
87511 *new = *vma;
87512+ INIT_LIST_HEAD(&new->anon_vma_chain);
87513 *region = *vma->vm_region;
87514 new->vm_region = region;
87515
87516@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
87517 }
87518 EXPORT_SYMBOL(generic_file_remap_pages);
87519
87520-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87521- unsigned long addr, void *buf, int len, int write)
87522+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87523+ unsigned long addr, void *buf, size_t len, int write)
87524 {
87525 struct vm_area_struct *vma;
87526
87527@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87528 *
87529 * The caller must hold a reference on @mm.
87530 */
87531-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87532- void *buf, int len, int write)
87533+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87534+ void *buf, size_t len, int write)
87535 {
87536 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87537 }
87538@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87539 * Access another process' address space.
87540 * - source/target buffer must be kernel space
87541 */
87542-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
87543+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
87544 {
87545 struct mm_struct *mm;
87546
87547diff --git a/mm/page-writeback.c b/mm/page-writeback.c
87548index 4514ad7..92eaa1c 100644
87549--- a/mm/page-writeback.c
87550+++ b/mm/page-writeback.c
87551@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
87552 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
87553 * - the bdi dirty thresh drops quickly due to change of JBOD workload
87554 */
87555-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
87556+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
87557 unsigned long thresh,
87558 unsigned long bg_thresh,
87559 unsigned long dirty,
87560@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
87561 }
87562 }
87563
87564-static struct notifier_block __cpuinitdata ratelimit_nb = {
87565+static struct notifier_block ratelimit_nb = {
87566 .notifier_call = ratelimit_handler,
87567 .next = NULL,
87568 };
87569diff --git a/mm/page_alloc.c b/mm/page_alloc.c
87570index 2ee0fd3..6e2edfb 100644
87571--- a/mm/page_alloc.c
87572+++ b/mm/page_alloc.c
87573@@ -60,6 +60,7 @@
87574 #include <linux/page-debug-flags.h>
87575 #include <linux/hugetlb.h>
87576 #include <linux/sched/rt.h>
87577+#include <linux/random.h>
87578
87579 #include <asm/tlbflush.h>
87580 #include <asm/div64.h>
87581@@ -345,7 +346,7 @@ out:
87582 * This usage means that zero-order pages may not be compound.
87583 */
87584
87585-static void free_compound_page(struct page *page)
87586+void free_compound_page(struct page *page)
87587 {
87588 __free_pages_ok(page, compound_order(page));
87589 }
87590@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
87591 int i;
87592 int bad = 0;
87593
87594+#ifdef CONFIG_PAX_MEMORY_SANITIZE
87595+ unsigned long index = 1UL << order;
87596+#endif
87597+
87598 trace_mm_page_free(page, order);
87599 kmemcheck_free_shadow(page, order);
87600
87601@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
87602 debug_check_no_obj_freed(page_address(page),
87603 PAGE_SIZE << order);
87604 }
87605+
87606+#ifdef CONFIG_PAX_MEMORY_SANITIZE
87607+ for (; index; --index)
87608+ sanitize_highpage(page + index - 1);
87609+#endif
87610+
87611 arch_free_page(page, order);
87612 kernel_map_pages(page, 1 << order, 0);
87613
87614@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
87615 local_irq_restore(flags);
87616 }
87617
87618+#ifdef CONFIG_PAX_LATENT_ENTROPY
87619+bool __meminitdata extra_latent_entropy;
87620+
87621+static int __init setup_pax_extra_latent_entropy(char *str)
87622+{
87623+ extra_latent_entropy = true;
87624+ return 0;
87625+}
87626+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
87627+
87628+volatile u64 latent_entropy;
87629+#endif
87630+
87631 /*
87632 * Read access to zone->managed_pages is safe because it's unsigned long,
87633 * but we still need to serialize writers. Currently all callers of
87634@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
87635 set_page_count(p, 0);
87636 }
87637
87638+#ifdef CONFIG_PAX_LATENT_ENTROPY
87639+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
87640+ u64 hash = 0;
87641+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
87642+ const u64 *data = lowmem_page_address(page);
87643+
87644+ for (index = 0; index < end; index++)
87645+ hash ^= hash + data[index];
87646+ latent_entropy ^= hash;
87647+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
87648+ }
87649+#endif
87650+
87651 page_zone(page)->managed_pages += 1 << order;
87652 set_page_refcounted(page);
87653 __free_pages(page, order);
87654@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
87655 arch_alloc_page(page, order);
87656 kernel_map_pages(page, 1 << order, 1);
87657
87658+#ifndef CONFIG_PAX_MEMORY_SANITIZE
87659 if (gfp_flags & __GFP_ZERO)
87660 prep_zero_page(page, order, gfp_flags);
87661+#endif
87662
87663 if (order && (gfp_flags & __GFP_COMP))
87664 prep_compound_page(page, order);
87665diff --git a/mm/page_io.c b/mm/page_io.c
87666index a8a3ef4..7260a60 100644
87667--- a/mm/page_io.c
87668+++ b/mm/page_io.c
87669@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
87670 struct file *swap_file = sis->swap_file;
87671 struct address_space *mapping = swap_file->f_mapping;
87672 struct iovec iov = {
87673- .iov_base = kmap(page),
87674+ .iov_base = (void __force_user *)kmap(page),
87675 .iov_len = PAGE_SIZE,
87676 };
87677
87678diff --git a/mm/percpu.c b/mm/percpu.c
87679index 8c8e08f..73a5cda 100644
87680--- a/mm/percpu.c
87681+++ b/mm/percpu.c
87682@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
87683 static unsigned int pcpu_high_unit_cpu __read_mostly;
87684
87685 /* the address of the first chunk which starts with the kernel static area */
87686-void *pcpu_base_addr __read_mostly;
87687+void *pcpu_base_addr __read_only;
87688 EXPORT_SYMBOL_GPL(pcpu_base_addr);
87689
87690 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
87691diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
87692index fd26d04..0cea1b0 100644
87693--- a/mm/process_vm_access.c
87694+++ b/mm/process_vm_access.c
87695@@ -13,6 +13,7 @@
87696 #include <linux/uio.h>
87697 #include <linux/sched.h>
87698 #include <linux/highmem.h>
87699+#include <linux/security.h>
87700 #include <linux/ptrace.h>
87701 #include <linux/slab.h>
87702 #include <linux/syscalls.h>
87703@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
87704 size_t iov_l_curr_offset = 0;
87705 ssize_t iov_len;
87706
87707+ return -ENOSYS; // PaX: until properly audited
87708+
87709 /*
87710 * Work out how many pages of struct pages we're going to need
87711 * when eventually calling get_user_pages
87712 */
87713 for (i = 0; i < riovcnt; i++) {
87714 iov_len = rvec[i].iov_len;
87715- if (iov_len > 0) {
87716- nr_pages_iov = ((unsigned long)rvec[i].iov_base
87717- + iov_len)
87718- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
87719- / PAGE_SIZE + 1;
87720- nr_pages = max(nr_pages, nr_pages_iov);
87721- }
87722+ if (iov_len <= 0)
87723+ continue;
87724+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
87725+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
87726+ nr_pages = max(nr_pages, nr_pages_iov);
87727 }
87728
87729 if (nr_pages == 0)
87730@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
87731 goto free_proc_pages;
87732 }
87733
87734+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
87735+ rc = -EPERM;
87736+ goto put_task_struct;
87737+ }
87738+
87739 mm = mm_access(task, PTRACE_MODE_ATTACH);
87740 if (!mm || IS_ERR(mm)) {
87741 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
87742diff --git a/mm/rmap.c b/mm/rmap.c
87743index 6280da8..b5c090e 100644
87744--- a/mm/rmap.c
87745+++ b/mm/rmap.c
87746@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
87747 struct anon_vma *anon_vma = vma->anon_vma;
87748 struct anon_vma_chain *avc;
87749
87750+#ifdef CONFIG_PAX_SEGMEXEC
87751+ struct anon_vma_chain *avc_m = NULL;
87752+#endif
87753+
87754 might_sleep();
87755 if (unlikely(!anon_vma)) {
87756 struct mm_struct *mm = vma->vm_mm;
87757@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
87758 if (!avc)
87759 goto out_enomem;
87760
87761+#ifdef CONFIG_PAX_SEGMEXEC
87762+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
87763+ if (!avc_m)
87764+ goto out_enomem_free_avc;
87765+#endif
87766+
87767 anon_vma = find_mergeable_anon_vma(vma);
87768 allocated = NULL;
87769 if (!anon_vma) {
87770@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
87771 /* page_table_lock to protect against threads */
87772 spin_lock(&mm->page_table_lock);
87773 if (likely(!vma->anon_vma)) {
87774+
87775+#ifdef CONFIG_PAX_SEGMEXEC
87776+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
87777+
87778+ if (vma_m) {
87779+ BUG_ON(vma_m->anon_vma);
87780+ vma_m->anon_vma = anon_vma;
87781+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
87782+ avc_m = NULL;
87783+ }
87784+#endif
87785+
87786 vma->anon_vma = anon_vma;
87787 anon_vma_chain_link(vma, avc, anon_vma);
87788 allocated = NULL;
87789@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
87790
87791 if (unlikely(allocated))
87792 put_anon_vma(allocated);
87793+
87794+#ifdef CONFIG_PAX_SEGMEXEC
87795+ if (unlikely(avc_m))
87796+ anon_vma_chain_free(avc_m);
87797+#endif
87798+
87799 if (unlikely(avc))
87800 anon_vma_chain_free(avc);
87801 }
87802 return 0;
87803
87804 out_enomem_free_avc:
87805+
87806+#ifdef CONFIG_PAX_SEGMEXEC
87807+ if (avc_m)
87808+ anon_vma_chain_free(avc_m);
87809+#endif
87810+
87811 anon_vma_chain_free(avc);
87812 out_enomem:
87813 return -ENOMEM;
87814@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
87815 * Attach the anon_vmas from src to dst.
87816 * Returns 0 on success, -ENOMEM on failure.
87817 */
87818-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
87819+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
87820 {
87821 struct anon_vma_chain *avc, *pavc;
87822 struct anon_vma *root = NULL;
87823@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
87824 * the corresponding VMA in the parent process is attached to.
87825 * Returns 0 on success, non-zero on failure.
87826 */
87827-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
87828+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
87829 {
87830 struct anon_vma_chain *avc;
87831 struct anon_vma *anon_vma;
87832@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
87833 void __init anon_vma_init(void)
87834 {
87835 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
87836- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
87837- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
87838+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
87839+ anon_vma_ctor);
87840+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
87841+ SLAB_PANIC|SLAB_NO_SANITIZE);
87842 }
87843
87844 /*
87845diff --git a/mm/shmem.c b/mm/shmem.c
87846index 5e6a842..b41916e 100644
87847--- a/mm/shmem.c
87848+++ b/mm/shmem.c
87849@@ -33,7 +33,7 @@
87850 #include <linux/swap.h>
87851 #include <linux/aio.h>
87852
87853-static struct vfsmount *shm_mnt;
87854+struct vfsmount *shm_mnt;
87855
87856 #ifdef CONFIG_SHMEM
87857 /*
87858@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
87859 #define BOGO_DIRENT_SIZE 20
87860
87861 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
87862-#define SHORT_SYMLINK_LEN 128
87863+#define SHORT_SYMLINK_LEN 64
87864
87865 /*
87866 * shmem_fallocate and shmem_writepage communicate via inode->i_private
87867@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
87868 static int shmem_xattr_validate(const char *name)
87869 {
87870 struct { const char *prefix; size_t len; } arr[] = {
87871+
87872+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87873+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
87874+#endif
87875+
87876 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
87877 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
87878 };
87879@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
87880 if (err)
87881 return err;
87882
87883+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
87884+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
87885+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
87886+ return -EOPNOTSUPP;
87887+ if (size > 8)
87888+ return -EINVAL;
87889+ }
87890+#endif
87891+
87892 return simple_xattr_set(&info->xattrs, name, value, size, flags);
87893 }
87894
87895@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
87896 int err = -ENOMEM;
87897
87898 /* Round up to L1_CACHE_BYTES to resist false sharing */
87899- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
87900- L1_CACHE_BYTES), GFP_KERNEL);
87901+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
87902 if (!sbinfo)
87903 return -ENOMEM;
87904
87905diff --git a/mm/slab.c b/mm/slab.c
87906index bd88411..2d46fd6 100644
87907--- a/mm/slab.c
87908+++ b/mm/slab.c
87909@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
87910 if ((x)->max_freeable < i) \
87911 (x)->max_freeable = i; \
87912 } while (0)
87913-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
87914-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
87915-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
87916-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
87917+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
87918+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
87919+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
87920+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
87921+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
87922+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
87923 #else
87924 #define STATS_INC_ACTIVE(x) do { } while (0)
87925 #define STATS_DEC_ACTIVE(x) do { } while (0)
87926@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
87927 #define STATS_INC_ALLOCMISS(x) do { } while (0)
87928 #define STATS_INC_FREEHIT(x) do { } while (0)
87929 #define STATS_INC_FREEMISS(x) do { } while (0)
87930+#define STATS_INC_SANITIZED(x) do { } while (0)
87931+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
87932 #endif
87933
87934 #if DEBUG
87935@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
87936 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
87937 */
87938 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
87939- const struct slab *slab, void *obj)
87940+ const struct slab *slab, const void *obj)
87941 {
87942 u32 offset = (obj - slab->s_mem);
87943 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
87944@@ -1384,7 +1388,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
87945 return notifier_from_errno(err);
87946 }
87947
87948-static struct notifier_block __cpuinitdata cpucache_notifier = {
87949+static struct notifier_block cpucache_notifier = {
87950 &cpuup_callback, NULL, 0
87951 };
87952
87953@@ -1565,12 +1569,12 @@ void __init kmem_cache_init(void)
87954 */
87955
87956 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
87957- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
87958+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
87959
87960 if (INDEX_AC != INDEX_NODE)
87961 kmalloc_caches[INDEX_NODE] =
87962 create_kmalloc_cache("kmalloc-node",
87963- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
87964+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
87965
87966 slab_early_init = 0;
87967
87968@@ -3583,6 +3587,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
87969 struct array_cache *ac = cpu_cache_get(cachep);
87970
87971 check_irq_off();
87972+
87973+#ifdef CONFIG_PAX_MEMORY_SANITIZE
87974+ if (pax_sanitize_slab) {
87975+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
87976+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
87977+
87978+ if (cachep->ctor)
87979+ cachep->ctor(objp);
87980+
87981+ STATS_INC_SANITIZED(cachep);
87982+ } else
87983+ STATS_INC_NOT_SANITIZED(cachep);
87984+ }
87985+#endif
87986+
87987 kmemleak_free_recursive(objp, cachep->flags);
87988 objp = cache_free_debugcheck(cachep, objp, caller);
87989
87990@@ -3800,6 +3819,7 @@ void kfree(const void *objp)
87991
87992 if (unlikely(ZERO_OR_NULL_PTR(objp)))
87993 return;
87994+ VM_BUG_ON(!virt_addr_valid(objp));
87995 local_irq_save(flags);
87996 kfree_debugcheck(objp);
87997 c = virt_to_cache(objp);
87998@@ -4241,14 +4261,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
87999 }
88000 /* cpu stats */
88001 {
88002- unsigned long allochit = atomic_read(&cachep->allochit);
88003- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
88004- unsigned long freehit = atomic_read(&cachep->freehit);
88005- unsigned long freemiss = atomic_read(&cachep->freemiss);
88006+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
88007+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
88008+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
88009+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
88010
88011 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
88012 allochit, allocmiss, freehit, freemiss);
88013 }
88014+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88015+ {
88016+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
88017+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
88018+
88019+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
88020+ }
88021+#endif
88022 #endif
88023 }
88024
88025@@ -4476,13 +4504,71 @@ static const struct file_operations proc_slabstats_operations = {
88026 static int __init slab_proc_init(void)
88027 {
88028 #ifdef CONFIG_DEBUG_SLAB_LEAK
88029- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
88030+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
88031 #endif
88032 return 0;
88033 }
88034 module_init(slab_proc_init);
88035 #endif
88036
88037+bool is_usercopy_object(const void *ptr)
88038+{
88039+ struct page *page;
88040+ struct kmem_cache *cachep;
88041+
88042+ if (ZERO_OR_NULL_PTR(ptr))
88043+ return false;
88044+
88045+ if (!slab_is_available())
88046+ return false;
88047+
88048+ if (!virt_addr_valid(ptr))
88049+ return false;
88050+
88051+ page = virt_to_head_page(ptr);
88052+
88053+ if (!PageSlab(page))
88054+ return false;
88055+
88056+ cachep = page->slab_cache;
88057+ return cachep->flags & SLAB_USERCOPY;
88058+}
88059+
88060+#ifdef CONFIG_PAX_USERCOPY
88061+const char *check_heap_object(const void *ptr, unsigned long n)
88062+{
88063+ struct page *page;
88064+ struct kmem_cache *cachep;
88065+ struct slab *slabp;
88066+ unsigned int objnr;
88067+ unsigned long offset;
88068+
88069+ if (ZERO_OR_NULL_PTR(ptr))
88070+ return "<null>";
88071+
88072+ if (!virt_addr_valid(ptr))
88073+ return NULL;
88074+
88075+ page = virt_to_head_page(ptr);
88076+
88077+ if (!PageSlab(page))
88078+ return NULL;
88079+
88080+ cachep = page->slab_cache;
88081+ if (!(cachep->flags & SLAB_USERCOPY))
88082+ return cachep->name;
88083+
88084+ slabp = page->slab_page;
88085+ objnr = obj_to_index(cachep, slabp, ptr);
88086+ BUG_ON(objnr >= cachep->num);
88087+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
88088+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
88089+ return NULL;
88090+
88091+ return cachep->name;
88092+}
88093+#endif
88094+
88095 /**
88096 * ksize - get the actual amount of memory allocated for a given object
88097 * @objp: Pointer to the object
88098diff --git a/mm/slab.h b/mm/slab.h
88099index f96b49e..db1d204 100644
88100--- a/mm/slab.h
88101+++ b/mm/slab.h
88102@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
88103 /* The slab cache that manages slab cache information */
88104 extern struct kmem_cache *kmem_cache;
88105
88106+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88107+#ifdef CONFIG_X86_64
88108+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
88109+#else
88110+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
88111+#endif
88112+extern bool pax_sanitize_slab;
88113+#endif
88114+
88115 unsigned long calculate_alignment(unsigned long flags,
88116 unsigned long align, unsigned long size);
88117
88118@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
88119
88120 /* Legal flag mask for kmem_cache_create(), for various configurations */
88121 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
88122- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
88123+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
88124+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
88125
88126 #if defined(CONFIG_DEBUG_SLAB)
88127 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
88128@@ -229,6 +239,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
88129 return s;
88130
88131 page = virt_to_head_page(x);
88132+
88133+ BUG_ON(!PageSlab(page));
88134+
88135 cachep = page->slab_cache;
88136 if (slab_equal_or_root(cachep, s))
88137 return cachep;
88138diff --git a/mm/slab_common.c b/mm/slab_common.c
88139index 2d41450..4efe6ee 100644
88140--- a/mm/slab_common.c
88141+++ b/mm/slab_common.c
88142@@ -22,11 +22,22 @@
88143
88144 #include "slab.h"
88145
88146-enum slab_state slab_state;
88147+enum slab_state slab_state __read_only;
88148 LIST_HEAD(slab_caches);
88149 DEFINE_MUTEX(slab_mutex);
88150 struct kmem_cache *kmem_cache;
88151
88152+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88153+bool pax_sanitize_slab __read_only = true;
88154+static int __init pax_sanitize_slab_setup(char *str)
88155+{
88156+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
88157+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
88158+ return 1;
88159+}
88160+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
88161+#endif
88162+
88163 #ifdef CONFIG_DEBUG_VM
88164 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
88165 size_t size)
88166@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
88167
88168 err = __kmem_cache_create(s, flags);
88169 if (!err) {
88170- s->refcount = 1;
88171+ atomic_set(&s->refcount, 1);
88172 list_add(&s->list, &slab_caches);
88173 memcg_cache_list_add(memcg, s);
88174 } else {
88175@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
88176
88177 get_online_cpus();
88178 mutex_lock(&slab_mutex);
88179- s->refcount--;
88180- if (!s->refcount) {
88181+ if (atomic_dec_and_test(&s->refcount)) {
88182 list_del(&s->list);
88183
88184 if (!__kmem_cache_shutdown(s)) {
88185@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
88186 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
88187 name, size, err);
88188
88189- s->refcount = -1; /* Exempt from merging for now */
88190+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
88191 }
88192
88193 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
88194@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
88195
88196 create_boot_cache(s, name, size, flags);
88197 list_add(&s->list, &slab_caches);
88198- s->refcount = 1;
88199+ atomic_set(&s->refcount, 1);
88200 return s;
88201 }
88202
88203@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
88204 EXPORT_SYMBOL(kmalloc_dma_caches);
88205 #endif
88206
88207+#ifdef CONFIG_PAX_USERCOPY_SLABS
88208+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
88209+EXPORT_SYMBOL(kmalloc_usercopy_caches);
88210+#endif
88211+
88212 /*
88213 * Conversion table for small slabs sizes / 8 to the index in the
88214 * kmalloc array. This is necessary for slabs < 192 since we have non power
88215@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
88216 return kmalloc_dma_caches[index];
88217
88218 #endif
88219+
88220+#ifdef CONFIG_PAX_USERCOPY_SLABS
88221+ if (unlikely((flags & GFP_USERCOPY)))
88222+ return kmalloc_usercopy_caches[index];
88223+
88224+#endif
88225+
88226 return kmalloc_caches[index];
88227 }
88228
88229@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
88230 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
88231 if (!kmalloc_caches[i]) {
88232 kmalloc_caches[i] = create_kmalloc_cache(NULL,
88233- 1 << i, flags);
88234+ 1 << i, SLAB_USERCOPY | flags);
88235 }
88236
88237 /*
88238@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
88239 * earlier power of two caches
88240 */
88241 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
88242- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
88243+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
88244
88245 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
88246- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
88247+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
88248 }
88249
88250 /* Kmalloc array is now usable */
88251@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
88252 }
88253 }
88254 #endif
88255+
88256+#ifdef CONFIG_PAX_USERCOPY_SLABS
88257+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
88258+ struct kmem_cache *s = kmalloc_caches[i];
88259+
88260+ if (s) {
88261+ int size = kmalloc_size(i);
88262+ char *n = kasprintf(GFP_NOWAIT,
88263+ "usercopy-kmalloc-%d", size);
88264+
88265+ BUG_ON(!n);
88266+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
88267+ size, SLAB_USERCOPY | flags);
88268+ }
88269+ }
88270+#endif
88271+
88272 }
88273 #endif /* !CONFIG_SLOB */
88274
88275@@ -516,6 +555,9 @@ void print_slabinfo_header(struct seq_file *m)
88276 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
88277 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
88278 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
88279+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88280+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
88281+#endif
88282 #endif
88283 seq_putc(m, '\n');
88284 }
88285diff --git a/mm/slob.c b/mm/slob.c
88286index eeed4a0..bb0e9ab 100644
88287--- a/mm/slob.c
88288+++ b/mm/slob.c
88289@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
88290 /*
88291 * Return the size of a slob block.
88292 */
88293-static slobidx_t slob_units(slob_t *s)
88294+static slobidx_t slob_units(const slob_t *s)
88295 {
88296 if (s->units > 0)
88297 return s->units;
88298@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
88299 /*
88300 * Return the next free slob block pointer after this one.
88301 */
88302-static slob_t *slob_next(slob_t *s)
88303+static slob_t *slob_next(const slob_t *s)
88304 {
88305 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
88306 slobidx_t next;
88307@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
88308 /*
88309 * Returns true if s is the last free block in its page.
88310 */
88311-static int slob_last(slob_t *s)
88312+static int slob_last(const slob_t *s)
88313 {
88314 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
88315 }
88316
88317-static void *slob_new_pages(gfp_t gfp, int order, int node)
88318+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
88319 {
88320- void *page;
88321+ struct page *page;
88322
88323 #ifdef CONFIG_NUMA
88324 if (node != NUMA_NO_NODE)
88325@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
88326 if (!page)
88327 return NULL;
88328
88329- return page_address(page);
88330+ __SetPageSlab(page);
88331+ return page;
88332 }
88333
88334-static void slob_free_pages(void *b, int order)
88335+static void slob_free_pages(struct page *sp, int order)
88336 {
88337 if (current->reclaim_state)
88338 current->reclaim_state->reclaimed_slab += 1 << order;
88339- free_pages((unsigned long)b, order);
88340+ __ClearPageSlab(sp);
88341+ page_mapcount_reset(sp);
88342+ sp->private = 0;
88343+ __free_pages(sp, order);
88344 }
88345
88346 /*
88347@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
88348
88349 /* Not enough space: must allocate a new page */
88350 if (!b) {
88351- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
88352- if (!b)
88353+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
88354+ if (!sp)
88355 return NULL;
88356- sp = virt_to_page(b);
88357- __SetPageSlab(sp);
88358+ b = page_address(sp);
88359
88360 spin_lock_irqsave(&slob_lock, flags);
88361 sp->units = SLOB_UNITS(PAGE_SIZE);
88362 sp->freelist = b;
88363+ sp->private = 0;
88364 INIT_LIST_HEAD(&sp->list);
88365 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
88366 set_slob_page_free(sp, slob_list);
88367@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
88368 if (slob_page_free(sp))
88369 clear_slob_page_free(sp);
88370 spin_unlock_irqrestore(&slob_lock, flags);
88371- __ClearPageSlab(sp);
88372- page_mapcount_reset(sp);
88373- slob_free_pages(b, 0);
88374+ slob_free_pages(sp, 0);
88375 return;
88376 }
88377
88378+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88379+ if (pax_sanitize_slab)
88380+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
88381+#endif
88382+
88383 if (!slob_page_free(sp)) {
88384 /* This slob page is about to become partially free. Easy! */
88385 sp->units = units;
88386@@ -424,11 +431,10 @@ out:
88387 */
88388
88389 static __always_inline void *
88390-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
88391+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
88392 {
88393- unsigned int *m;
88394- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
88395- void *ret;
88396+ slob_t *m;
88397+ void *ret = NULL;
88398
88399 gfp &= gfp_allowed_mask;
88400
88401@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
88402
88403 if (!m)
88404 return NULL;
88405- *m = size;
88406+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
88407+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
88408+ m[0].units = size;
88409+ m[1].units = align;
88410 ret = (void *)m + align;
88411
88412 trace_kmalloc_node(caller, ret,
88413 size, size + align, gfp, node);
88414 } else {
88415 unsigned int order = get_order(size);
88416+ struct page *page;
88417
88418 if (likely(order))
88419 gfp |= __GFP_COMP;
88420- ret = slob_new_pages(gfp, order, node);
88421+ page = slob_new_pages(gfp, order, node);
88422+ if (page) {
88423+ ret = page_address(page);
88424+ page->private = size;
88425+ }
88426
88427 trace_kmalloc_node(caller, ret,
88428 size, PAGE_SIZE << order, gfp, node);
88429 }
88430
88431- kmemleak_alloc(ret, size, 1, gfp);
88432+ return ret;
88433+}
88434+
88435+static __always_inline void *
88436+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
88437+{
88438+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
88439+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
88440+
88441+ if (!ZERO_OR_NULL_PTR(ret))
88442+ kmemleak_alloc(ret, size, 1, gfp);
88443 return ret;
88444 }
88445
88446@@ -493,34 +517,112 @@ void kfree(const void *block)
88447 return;
88448 kmemleak_free(block);
88449
88450+ VM_BUG_ON(!virt_addr_valid(block));
88451 sp = virt_to_page(block);
88452- if (PageSlab(sp)) {
88453+ VM_BUG_ON(!PageSlab(sp));
88454+ if (!sp->private) {
88455 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
88456- unsigned int *m = (unsigned int *)(block - align);
88457- slob_free(m, *m + align);
88458- } else
88459+ slob_t *m = (slob_t *)(block - align);
88460+ slob_free(m, m[0].units + align);
88461+ } else {
88462+ __ClearPageSlab(sp);
88463+ page_mapcount_reset(sp);
88464+ sp->private = 0;
88465 __free_pages(sp, compound_order(sp));
88466+ }
88467 }
88468 EXPORT_SYMBOL(kfree);
88469
88470+bool is_usercopy_object(const void *ptr)
88471+{
88472+ if (!slab_is_available())
88473+ return false;
88474+
88475+ // PAX: TODO
88476+
88477+ return false;
88478+}
88479+
88480+#ifdef CONFIG_PAX_USERCOPY
88481+const char *check_heap_object(const void *ptr, unsigned long n)
88482+{
88483+ struct page *page;
88484+ const slob_t *free;
88485+ const void *base;
88486+ unsigned long flags;
88487+
88488+ if (ZERO_OR_NULL_PTR(ptr))
88489+ return "<null>";
88490+
88491+ if (!virt_addr_valid(ptr))
88492+ return NULL;
88493+
88494+ page = virt_to_head_page(ptr);
88495+ if (!PageSlab(page))
88496+ return NULL;
88497+
88498+ if (page->private) {
88499+ base = page;
88500+ if (base <= ptr && n <= page->private - (ptr - base))
88501+ return NULL;
88502+ return "<slob>";
88503+ }
88504+
88505+ /* some tricky double walking to find the chunk */
88506+ spin_lock_irqsave(&slob_lock, flags);
88507+ base = (void *)((unsigned long)ptr & PAGE_MASK);
88508+ free = page->freelist;
88509+
88510+ while (!slob_last(free) && (void *)free <= ptr) {
88511+ base = free + slob_units(free);
88512+ free = slob_next(free);
88513+ }
88514+
88515+ while (base < (void *)free) {
88516+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
88517+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
88518+ int offset;
88519+
88520+ if (ptr < base + align)
88521+ break;
88522+
88523+ offset = ptr - base - align;
88524+ if (offset >= m) {
88525+ base += size;
88526+ continue;
88527+ }
88528+
88529+ if (n > m - offset)
88530+ break;
88531+
88532+ spin_unlock_irqrestore(&slob_lock, flags);
88533+ return NULL;
88534+ }
88535+
88536+ spin_unlock_irqrestore(&slob_lock, flags);
88537+ return "<slob>";
88538+}
88539+#endif
88540+
88541 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
88542 size_t ksize(const void *block)
88543 {
88544 struct page *sp;
88545 int align;
88546- unsigned int *m;
88547+ slob_t *m;
88548
88549 BUG_ON(!block);
88550 if (unlikely(block == ZERO_SIZE_PTR))
88551 return 0;
88552
88553 sp = virt_to_page(block);
88554- if (unlikely(!PageSlab(sp)))
88555- return PAGE_SIZE << compound_order(sp);
88556+ VM_BUG_ON(!PageSlab(sp));
88557+ if (sp->private)
88558+ return sp->private;
88559
88560 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
88561- m = (unsigned int *)(block - align);
88562- return SLOB_UNITS(*m) * SLOB_UNIT;
88563+ m = (slob_t *)(block - align);
88564+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
88565 }
88566 EXPORT_SYMBOL(ksize);
88567
88568@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
88569
88570 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
88571 {
88572- void *b;
88573+ void *b = NULL;
88574
88575 flags &= gfp_allowed_mask;
88576
88577 lockdep_trace_alloc(flags);
88578
88579+#ifdef CONFIG_PAX_USERCOPY_SLABS
88580+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
88581+#else
88582 if (c->size < PAGE_SIZE) {
88583 b = slob_alloc(c->size, flags, c->align, node);
88584 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
88585 SLOB_UNITS(c->size) * SLOB_UNIT,
88586 flags, node);
88587 } else {
88588- b = slob_new_pages(flags, get_order(c->size), node);
88589+ struct page *sp;
88590+
88591+ sp = slob_new_pages(flags, get_order(c->size), node);
88592+ if (sp) {
88593+ b = page_address(sp);
88594+ sp->private = c->size;
88595+ }
88596 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
88597 PAGE_SIZE << get_order(c->size),
88598 flags, node);
88599 }
88600+#endif
88601
88602 if (c->ctor)
88603 c->ctor(b);
88604@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
88605
88606 static void __kmem_cache_free(void *b, int size)
88607 {
88608- if (size < PAGE_SIZE)
88609+ struct page *sp;
88610+
88611+ sp = virt_to_page(b);
88612+ BUG_ON(!PageSlab(sp));
88613+ if (!sp->private)
88614 slob_free(b, size);
88615 else
88616- slob_free_pages(b, get_order(size));
88617+ slob_free_pages(sp, get_order(size));
88618 }
88619
88620 static void kmem_rcu_free(struct rcu_head *head)
88621@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
88622
88623 void kmem_cache_free(struct kmem_cache *c, void *b)
88624 {
88625+ int size = c->size;
88626+
88627+#ifdef CONFIG_PAX_USERCOPY_SLABS
88628+ if (size + c->align < PAGE_SIZE) {
88629+ size += c->align;
88630+ b -= c->align;
88631+ }
88632+#endif
88633+
88634 kmemleak_free_recursive(b, c->flags);
88635 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
88636 struct slob_rcu *slob_rcu;
88637- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
88638- slob_rcu->size = c->size;
88639+ slob_rcu = b + (size - sizeof(struct slob_rcu));
88640+ slob_rcu->size = size;
88641 call_rcu(&slob_rcu->head, kmem_rcu_free);
88642 } else {
88643- __kmem_cache_free(b, c->size);
88644+ __kmem_cache_free(b, size);
88645 }
88646
88647+#ifdef CONFIG_PAX_USERCOPY_SLABS
88648+ trace_kfree(_RET_IP_, b);
88649+#else
88650 trace_kmem_cache_free(_RET_IP_, b);
88651+#endif
88652+
88653 }
88654 EXPORT_SYMBOL(kmem_cache_free);
88655
88656diff --git a/mm/slub.c b/mm/slub.c
88657index 57707f0..7857bd3 100644
88658--- a/mm/slub.c
88659+++ b/mm/slub.c
88660@@ -198,7 +198,7 @@ struct track {
88661
88662 enum track_item { TRACK_ALLOC, TRACK_FREE };
88663
88664-#ifdef CONFIG_SYSFS
88665+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88666 static int sysfs_slab_add(struct kmem_cache *);
88667 static int sysfs_slab_alias(struct kmem_cache *, const char *);
88668 static void sysfs_slab_remove(struct kmem_cache *);
88669@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
88670 if (!t->addr)
88671 return;
88672
88673- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
88674+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
88675 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
88676 #ifdef CONFIG_STACKTRACE
88677 {
88678@@ -2594,6 +2594,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
88679
88680 slab_free_hook(s, x);
88681
88682+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88683+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
88684+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
88685+ if (s->ctor)
88686+ s->ctor(x);
88687+ }
88688+#endif
88689+
88690 redo:
88691 /*
88692 * Determine the currently cpus per cpu slab.
88693@@ -2661,7 +2669,7 @@ static int slub_min_objects;
88694 * Merge control. If this is set then no merging of slab caches will occur.
88695 * (Could be removed. This was introduced to pacify the merge skeptics.)
88696 */
88697-static int slub_nomerge;
88698+static int slub_nomerge = 1;
88699
88700 /*
88701 * Calculate the order of allocation given an slab object size.
88702@@ -2938,6 +2946,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
88703 s->inuse = size;
88704
88705 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
88706+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88707+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
88708+#endif
88709 s->ctor)) {
88710 /*
88711 * Relocate free pointer after the object if it is not
88712@@ -3283,6 +3294,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
88713 EXPORT_SYMBOL(__kmalloc_node);
88714 #endif
88715
88716+bool is_usercopy_object(const void *ptr)
88717+{
88718+ struct page *page;
88719+ struct kmem_cache *s;
88720+
88721+ if (ZERO_OR_NULL_PTR(ptr))
88722+ return false;
88723+
88724+ if (!slab_is_available())
88725+ return false;
88726+
88727+ if (!virt_addr_valid(ptr))
88728+ return false;
88729+
88730+ page = virt_to_head_page(ptr);
88731+
88732+ if (!PageSlab(page))
88733+ return false;
88734+
88735+ s = page->slab_cache;
88736+ return s->flags & SLAB_USERCOPY;
88737+}
88738+
88739+#ifdef CONFIG_PAX_USERCOPY
88740+const char *check_heap_object(const void *ptr, unsigned long n)
88741+{
88742+ struct page *page;
88743+ struct kmem_cache *s;
88744+ unsigned long offset;
88745+
88746+ if (ZERO_OR_NULL_PTR(ptr))
88747+ return "<null>";
88748+
88749+ if (!virt_addr_valid(ptr))
88750+ return NULL;
88751+
88752+ page = virt_to_head_page(ptr);
88753+
88754+ if (!PageSlab(page))
88755+ return NULL;
88756+
88757+ s = page->slab_cache;
88758+ if (!(s->flags & SLAB_USERCOPY))
88759+ return s->name;
88760+
88761+ offset = (ptr - page_address(page)) % s->size;
88762+ if (offset <= s->object_size && n <= s->object_size - offset)
88763+ return NULL;
88764+
88765+ return s->name;
88766+}
88767+#endif
88768+
88769 size_t ksize(const void *object)
88770 {
88771 struct page *page;
88772@@ -3347,6 +3411,7 @@ void kfree(const void *x)
88773 if (unlikely(ZERO_OR_NULL_PTR(x)))
88774 return;
88775
88776+ VM_BUG_ON(!virt_addr_valid(x));
88777 page = virt_to_head_page(x);
88778 if (unlikely(!PageSlab(page))) {
88779 BUG_ON(!PageCompound(page));
88780@@ -3652,7 +3717,7 @@ static int slab_unmergeable(struct kmem_cache *s)
88781 /*
88782 * We may have set a slab to be unmergeable during bootstrap.
88783 */
88784- if (s->refcount < 0)
88785+ if (atomic_read(&s->refcount) < 0)
88786 return 1;
88787
88788 return 0;
88789@@ -3710,7 +3775,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
88790
88791 s = find_mergeable(memcg, size, align, flags, name, ctor);
88792 if (s) {
88793- s->refcount++;
88794+ atomic_inc(&s->refcount);
88795 /*
88796 * Adjust the object sizes so that we clear
88797 * the complete object on kzalloc.
88798@@ -3719,7 +3784,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
88799 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
88800
88801 if (sysfs_slab_alias(s, name)) {
88802- s->refcount--;
88803+ atomic_dec(&s->refcount);
88804 s = NULL;
88805 }
88806 }
88807@@ -3781,7 +3846,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
88808 return NOTIFY_OK;
88809 }
88810
88811-static struct notifier_block __cpuinitdata slab_notifier = {
88812+static struct notifier_block slab_notifier = {
88813 .notifier_call = slab_cpuup_callback
88814 };
88815
88816@@ -3839,7 +3904,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
88817 }
88818 #endif
88819
88820-#ifdef CONFIG_SYSFS
88821+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88822 static int count_inuse(struct page *page)
88823 {
88824 return page->inuse;
88825@@ -4226,12 +4291,12 @@ static void resiliency_test(void)
88826 validate_slab_cache(kmalloc_caches[9]);
88827 }
88828 #else
88829-#ifdef CONFIG_SYSFS
88830+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88831 static void resiliency_test(void) {};
88832 #endif
88833 #endif
88834
88835-#ifdef CONFIG_SYSFS
88836+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88837 enum slab_stat_type {
88838 SL_ALL, /* All slabs */
88839 SL_PARTIAL, /* Only partially allocated slabs */
88840@@ -4475,7 +4540,7 @@ SLAB_ATTR_RO(ctor);
88841
88842 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
88843 {
88844- return sprintf(buf, "%d\n", s->refcount - 1);
88845+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
88846 }
88847 SLAB_ATTR_RO(aliases);
88848
88849@@ -4563,6 +4628,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
88850 SLAB_ATTR_RO(cache_dma);
88851 #endif
88852
88853+#ifdef CONFIG_PAX_USERCOPY_SLABS
88854+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
88855+{
88856+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
88857+}
88858+SLAB_ATTR_RO(usercopy);
88859+#endif
88860+
88861 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
88862 {
88863 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
88864@@ -4897,6 +4970,9 @@ static struct attribute *slab_attrs[] = {
88865 #ifdef CONFIG_ZONE_DMA
88866 &cache_dma_attr.attr,
88867 #endif
88868+#ifdef CONFIG_PAX_USERCOPY_SLABS
88869+ &usercopy_attr.attr,
88870+#endif
88871 #ifdef CONFIG_NUMA
88872 &remote_node_defrag_ratio_attr.attr,
88873 #endif
88874@@ -5128,6 +5204,7 @@ static char *create_unique_id(struct kmem_cache *s)
88875 return name;
88876 }
88877
88878+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88879 static int sysfs_slab_add(struct kmem_cache *s)
88880 {
88881 int err;
88882@@ -5151,7 +5228,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
88883 }
88884
88885 s->kobj.kset = slab_kset;
88886- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
88887+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
88888 if (err) {
88889 kobject_put(&s->kobj);
88890 return err;
88891@@ -5185,6 +5262,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
88892 kobject_del(&s->kobj);
88893 kobject_put(&s->kobj);
88894 }
88895+#endif
88896
88897 /*
88898 * Need to buffer aliases during bootup until sysfs becomes
88899@@ -5198,6 +5276,7 @@ struct saved_alias {
88900
88901 static struct saved_alias *alias_list;
88902
88903+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
88904 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
88905 {
88906 struct saved_alias *al;
88907@@ -5220,6 +5299,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
88908 alias_list = al;
88909 return 0;
88910 }
88911+#endif
88912
88913 static int __init slab_sysfs_init(void)
88914 {
88915diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
88916index 27eeab3..7c3f7f2 100644
88917--- a/mm/sparse-vmemmap.c
88918+++ b/mm/sparse-vmemmap.c
88919@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
88920 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
88921 if (!p)
88922 return NULL;
88923- pud_populate(&init_mm, pud, p);
88924+ pud_populate_kernel(&init_mm, pud, p);
88925 }
88926 return pud;
88927 }
88928@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
88929 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
88930 if (!p)
88931 return NULL;
88932- pgd_populate(&init_mm, pgd, p);
88933+ pgd_populate_kernel(&init_mm, pgd, p);
88934 }
88935 return pgd;
88936 }
88937diff --git a/mm/sparse.c b/mm/sparse.c
88938index 1c91f0d3..485470a 100644
88939--- a/mm/sparse.c
88940+++ b/mm/sparse.c
88941@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
88942
88943 for (i = 0; i < PAGES_PER_SECTION; i++) {
88944 if (PageHWPoison(&memmap[i])) {
88945- atomic_long_sub(1, &num_poisoned_pages);
88946+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
88947 ClearPageHWPoison(&memmap[i]);
88948 }
88949 }
88950diff --git a/mm/swap.c b/mm/swap.c
88951index dfd7d71..ccdf688 100644
88952--- a/mm/swap.c
88953+++ b/mm/swap.c
88954@@ -31,6 +31,7 @@
88955 #include <linux/memcontrol.h>
88956 #include <linux/gfp.h>
88957 #include <linux/uio.h>
88958+#include <linux/hugetlb.h>
88959
88960 #include "internal.h"
88961
88962@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
88963
88964 __page_cache_release(page);
88965 dtor = get_compound_page_dtor(page);
88966+ if (!PageHuge(page))
88967+ BUG_ON(dtor != free_compound_page);
88968 (*dtor)(page);
88969 }
88970
88971diff --git a/mm/swapfile.c b/mm/swapfile.c
88972index 746af55b..7ac94ae 100644
88973--- a/mm/swapfile.c
88974+++ b/mm/swapfile.c
88975@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
88976
88977 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
88978 /* Activity counter to indicate that a swapon or swapoff has occurred */
88979-static atomic_t proc_poll_event = ATOMIC_INIT(0);
88980+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
88981
88982 static inline unsigned char swap_count(unsigned char ent)
88983 {
88984@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
88985 }
88986 filp_close(swap_file, NULL);
88987 err = 0;
88988- atomic_inc(&proc_poll_event);
88989+ atomic_inc_unchecked(&proc_poll_event);
88990 wake_up_interruptible(&proc_poll_wait);
88991
88992 out_dput:
88993@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
88994
88995 poll_wait(file, &proc_poll_wait, wait);
88996
88997- if (seq->poll_event != atomic_read(&proc_poll_event)) {
88998- seq->poll_event = atomic_read(&proc_poll_event);
88999+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
89000+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
89001 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
89002 }
89003
89004@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
89005 return ret;
89006
89007 seq = file->private_data;
89008- seq->poll_event = atomic_read(&proc_poll_event);
89009+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
89010 return 0;
89011 }
89012
89013@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
89014 (frontswap_map) ? "FS" : "");
89015
89016 mutex_unlock(&swapon_mutex);
89017- atomic_inc(&proc_poll_event);
89018+ atomic_inc_unchecked(&proc_poll_event);
89019 wake_up_interruptible(&proc_poll_wait);
89020
89021 if (S_ISREG(inode->i_mode))
89022diff --git a/mm/util.c b/mm/util.c
89023index ab1424d..7c5bd5a 100644
89024--- a/mm/util.c
89025+++ b/mm/util.c
89026@@ -294,6 +294,12 @@ done:
89027 void arch_pick_mmap_layout(struct mm_struct *mm)
89028 {
89029 mm->mmap_base = TASK_UNMAPPED_BASE;
89030+
89031+#ifdef CONFIG_PAX_RANDMMAP
89032+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89033+ mm->mmap_base += mm->delta_mmap;
89034+#endif
89035+
89036 mm->get_unmapped_area = arch_get_unmapped_area;
89037 mm->unmap_area = arch_unmap_area;
89038 }
89039diff --git a/mm/vmalloc.c b/mm/vmalloc.c
89040index d365724..6cae7c2 100644
89041--- a/mm/vmalloc.c
89042+++ b/mm/vmalloc.c
89043@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
89044
89045 pte = pte_offset_kernel(pmd, addr);
89046 do {
89047- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
89048- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
89049+
89050+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89051+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
89052+ BUG_ON(!pte_exec(*pte));
89053+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
89054+ continue;
89055+ }
89056+#endif
89057+
89058+ {
89059+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
89060+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
89061+ }
89062 } while (pte++, addr += PAGE_SIZE, addr != end);
89063 }
89064
89065@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
89066 pte = pte_alloc_kernel(pmd, addr);
89067 if (!pte)
89068 return -ENOMEM;
89069+
89070+ pax_open_kernel();
89071 do {
89072 struct page *page = pages[*nr];
89073
89074- if (WARN_ON(!pte_none(*pte)))
89075+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89076+ if (pgprot_val(prot) & _PAGE_NX)
89077+#endif
89078+
89079+ if (!pte_none(*pte)) {
89080+ pax_close_kernel();
89081+ WARN_ON(1);
89082 return -EBUSY;
89083- if (WARN_ON(!page))
89084+ }
89085+ if (!page) {
89086+ pax_close_kernel();
89087+ WARN_ON(1);
89088 return -ENOMEM;
89089+ }
89090 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
89091 (*nr)++;
89092 } while (pte++, addr += PAGE_SIZE, addr != end);
89093+ pax_close_kernel();
89094 return 0;
89095 }
89096
89097@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
89098 pmd_t *pmd;
89099 unsigned long next;
89100
89101- pmd = pmd_alloc(&init_mm, pud, addr);
89102+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89103 if (!pmd)
89104 return -ENOMEM;
89105 do {
89106@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
89107 pud_t *pud;
89108 unsigned long next;
89109
89110- pud = pud_alloc(&init_mm, pgd, addr);
89111+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
89112 if (!pud)
89113 return -ENOMEM;
89114 do {
89115@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
89116 if (addr >= MODULES_VADDR && addr < MODULES_END)
89117 return 1;
89118 #endif
89119+
89120+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89121+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
89122+ return 1;
89123+#endif
89124+
89125 return is_vmalloc_addr(x);
89126 }
89127
89128@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
89129
89130 if (!pgd_none(*pgd)) {
89131 pud_t *pud = pud_offset(pgd, addr);
89132+#ifdef CONFIG_X86
89133+ if (!pud_large(*pud))
89134+#endif
89135 if (!pud_none(*pud)) {
89136 pmd_t *pmd = pmd_offset(pud, addr);
89137+#ifdef CONFIG_X86
89138+ if (!pmd_large(*pmd))
89139+#endif
89140 if (!pmd_none(*pmd)) {
89141 pte_t *ptep, pte;
89142
89143@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
89144 * Allocate a region of KVA of the specified size and alignment, within the
89145 * vstart and vend.
89146 */
89147-static struct vmap_area *alloc_vmap_area(unsigned long size,
89148+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
89149 unsigned long align,
89150 unsigned long vstart, unsigned long vend,
89151 int node, gfp_t gfp_mask)
89152@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
89153 struct vm_struct *area;
89154
89155 BUG_ON(in_interrupt());
89156+
89157+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
89158+ if (flags & VM_KERNEXEC) {
89159+ if (start != VMALLOC_START || end != VMALLOC_END)
89160+ return NULL;
89161+ start = (unsigned long)MODULES_EXEC_VADDR;
89162+ end = (unsigned long)MODULES_EXEC_END;
89163+ }
89164+#endif
89165+
89166 if (flags & VM_IOREMAP) {
89167 int bit = fls(size);
89168
89169@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
89170 if (count > totalram_pages)
89171 return NULL;
89172
89173+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
89174+ if (!(pgprot_val(prot) & _PAGE_NX))
89175+ flags |= VM_KERNEXEC;
89176+#endif
89177+
89178 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
89179 __builtin_return_address(0));
89180 if (!area)
89181@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
89182 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
89183 goto fail;
89184
89185+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
89186+ if (!(pgprot_val(prot) & _PAGE_NX))
89187+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
89188+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
89189+ else
89190+#endif
89191+
89192 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
89193 start, end, node, gfp_mask, caller);
89194 if (!area)
89195@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
89196 * For tight control over page level allocator and protection flags
89197 * use __vmalloc() instead.
89198 */
89199-
89200 void *vmalloc_exec(unsigned long size)
89201 {
89202- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
89203+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
89204 NUMA_NO_NODE, __builtin_return_address(0));
89205 }
89206
89207@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
89208 unsigned long uaddr = vma->vm_start;
89209 unsigned long usize = vma->vm_end - vma->vm_start;
89210
89211+ BUG_ON(vma->vm_mirror);
89212+
89213 if ((PAGE_SIZE-1) & (unsigned long)addr)
89214 return -EINVAL;
89215
89216@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
89217 v->addr, v->addr + v->size, v->size);
89218
89219 if (v->caller)
89220+#ifdef CONFIG_GRKERNSEC_HIDESYM
89221+ seq_printf(m, " %pK", v->caller);
89222+#else
89223 seq_printf(m, " %pS", v->caller);
89224+#endif
89225
89226 if (v->nr_pages)
89227 seq_printf(m, " pages=%d", v->nr_pages);
89228diff --git a/mm/vmstat.c b/mm/vmstat.c
89229index f42745e..62f8346 100644
89230--- a/mm/vmstat.c
89231+++ b/mm/vmstat.c
89232@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
89233 *
89234 * vm_stat contains the global counters
89235 */
89236-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
89237+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
89238 EXPORT_SYMBOL(vm_stat);
89239
89240 #ifdef CONFIG_SMP
89241@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
89242 v = p->vm_stat_diff[i];
89243 p->vm_stat_diff[i] = 0;
89244 local_irq_restore(flags);
89245- atomic_long_add(v, &zone->vm_stat[i]);
89246+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
89247 global_diff[i] += v;
89248 #ifdef CONFIG_NUMA
89249 /* 3 seconds idle till flush */
89250@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
89251
89252 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
89253 if (global_diff[i])
89254- atomic_long_add(global_diff[i], &vm_stat[i]);
89255+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
89256 }
89257
89258 /*
89259@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
89260 if (pset->vm_stat_diff[i]) {
89261 int v = pset->vm_stat_diff[i];
89262 pset->vm_stat_diff[i] = 0;
89263- atomic_long_add(v, &zone->vm_stat[i]);
89264- atomic_long_add(v, &vm_stat[i]);
89265+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
89266+ atomic_long_add_unchecked(v, &vm_stat[i]);
89267 }
89268 }
89269 #endif
89270@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
89271 return NOTIFY_OK;
89272 }
89273
89274-static struct notifier_block __cpuinitdata vmstat_notifier =
89275+static struct notifier_block vmstat_notifier =
89276 { &vmstat_cpuup_callback, NULL, 0 };
89277 #endif
89278
89279@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
89280 start_cpu_timer(cpu);
89281 #endif
89282 #ifdef CONFIG_PROC_FS
89283- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
89284- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
89285- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
89286- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
89287+ {
89288+ mode_t gr_mode = S_IRUGO;
89289+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89290+ gr_mode = S_IRUSR;
89291+#endif
89292+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
89293+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
89294+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
89295+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
89296+#else
89297+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
89298+#endif
89299+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
89300+ }
89301 #endif
89302 return 0;
89303 }
89304diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
89305index 9424f37..6aabf19 100644
89306--- a/net/8021q/vlan.c
89307+++ b/net/8021q/vlan.c
89308@@ -469,7 +469,7 @@ out:
89309 return NOTIFY_DONE;
89310 }
89311
89312-static struct notifier_block vlan_notifier_block __read_mostly = {
89313+static struct notifier_block vlan_notifier_block = {
89314 .notifier_call = vlan_device_event,
89315 };
89316
89317@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
89318 err = -EPERM;
89319 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
89320 break;
89321- if ((args.u.name_type >= 0) &&
89322- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
89323+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
89324 struct vlan_net *vn;
89325
89326 vn = net_generic(net, vlan_net_id);
89327diff --git a/net/9p/mod.c b/net/9p/mod.c
89328index 6ab36ae..6f1841b 100644
89329--- a/net/9p/mod.c
89330+++ b/net/9p/mod.c
89331@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
89332 void v9fs_register_trans(struct p9_trans_module *m)
89333 {
89334 spin_lock(&v9fs_trans_lock);
89335- list_add_tail(&m->list, &v9fs_trans_list);
89336+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
89337 spin_unlock(&v9fs_trans_lock);
89338 }
89339 EXPORT_SYMBOL(v9fs_register_trans);
89340@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
89341 void v9fs_unregister_trans(struct p9_trans_module *m)
89342 {
89343 spin_lock(&v9fs_trans_lock);
89344- list_del_init(&m->list);
89345+ pax_list_del_init((struct list_head *)&m->list);
89346 spin_unlock(&v9fs_trans_lock);
89347 }
89348 EXPORT_SYMBOL(v9fs_unregister_trans);
89349diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
89350index 02efb25..41541a9 100644
89351--- a/net/9p/trans_fd.c
89352+++ b/net/9p/trans_fd.c
89353@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
89354 oldfs = get_fs();
89355 set_fs(get_ds());
89356 /* The cast to a user pointer is valid due to the set_fs() */
89357- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
89358+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
89359 set_fs(oldfs);
89360
89361 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
89362diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
89363index 876fbe8..8bbea9f 100644
89364--- a/net/atm/atm_misc.c
89365+++ b/net/atm/atm_misc.c
89366@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
89367 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
89368 return 1;
89369 atm_return(vcc, truesize);
89370- atomic_inc(&vcc->stats->rx_drop);
89371+ atomic_inc_unchecked(&vcc->stats->rx_drop);
89372 return 0;
89373 }
89374 EXPORT_SYMBOL(atm_charge);
89375@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
89376 }
89377 }
89378 atm_return(vcc, guess);
89379- atomic_inc(&vcc->stats->rx_drop);
89380+ atomic_inc_unchecked(&vcc->stats->rx_drop);
89381 return NULL;
89382 }
89383 EXPORT_SYMBOL(atm_alloc_charge);
89384@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
89385
89386 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
89387 {
89388-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
89389+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
89390 __SONET_ITEMS
89391 #undef __HANDLE_ITEM
89392 }
89393@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
89394
89395 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
89396 {
89397-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
89398+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
89399 __SONET_ITEMS
89400 #undef __HANDLE_ITEM
89401 }
89402diff --git a/net/atm/lec.h b/net/atm/lec.h
89403index 4149db1..f2ab682 100644
89404--- a/net/atm/lec.h
89405+++ b/net/atm/lec.h
89406@@ -48,7 +48,7 @@ struct lane2_ops {
89407 const u8 *tlvs, u32 sizeoftlvs);
89408 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
89409 const u8 *tlvs, u32 sizeoftlvs);
89410-};
89411+} __no_const;
89412
89413 /*
89414 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
89415diff --git a/net/atm/proc.c b/net/atm/proc.c
89416index bbb6461..cf04016 100644
89417--- a/net/atm/proc.c
89418+++ b/net/atm/proc.c
89419@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
89420 const struct k_atm_aal_stats *stats)
89421 {
89422 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
89423- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
89424- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
89425- atomic_read(&stats->rx_drop));
89426+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
89427+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
89428+ atomic_read_unchecked(&stats->rx_drop));
89429 }
89430
89431 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
89432diff --git a/net/atm/resources.c b/net/atm/resources.c
89433index 0447d5d..3cf4728 100644
89434--- a/net/atm/resources.c
89435+++ b/net/atm/resources.c
89436@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
89437 static void copy_aal_stats(struct k_atm_aal_stats *from,
89438 struct atm_aal_stats *to)
89439 {
89440-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
89441+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
89442 __AAL_STAT_ITEMS
89443 #undef __HANDLE_ITEM
89444 }
89445@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
89446 static void subtract_aal_stats(struct k_atm_aal_stats *from,
89447 struct atm_aal_stats *to)
89448 {
89449-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
89450+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
89451 __AAL_STAT_ITEMS
89452 #undef __HANDLE_ITEM
89453 }
89454diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
89455index d5744b7..506bae3 100644
89456--- a/net/ax25/sysctl_net_ax25.c
89457+++ b/net/ax25/sysctl_net_ax25.c
89458@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
89459 {
89460 char path[sizeof("net/ax25/") + IFNAMSIZ];
89461 int k;
89462- struct ctl_table *table;
89463+ ctl_table_no_const *table;
89464
89465 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
89466 if (!table)
89467diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
89468index f680ee1..97e3542 100644
89469--- a/net/batman-adv/bat_iv_ogm.c
89470+++ b/net/batman-adv/bat_iv_ogm.c
89471@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
89472
89473 /* randomize initial seqno to avoid collision */
89474 get_random_bytes(&random_seqno, sizeof(random_seqno));
89475- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
89476+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
89477
89478 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
89479 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
89480@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
89481 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
89482
89483 /* change sequence number to network order */
89484- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
89485+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
89486 batadv_ogm_packet->seqno = htonl(seqno);
89487- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
89488+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
89489
89490 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
89491 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
89492@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
89493 return;
89494
89495 /* could be changed by schedule_own_packet() */
89496- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
89497+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
89498
89499 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
89500 has_directlink_flag = 1;
89501diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
89502index de27b31..7058bfe 100644
89503--- a/net/batman-adv/bridge_loop_avoidance.c
89504+++ b/net/batman-adv/bridge_loop_avoidance.c
89505@@ -1522,6 +1522,8 @@ out:
89506 * in these cases, the skb is further handled by this function and
89507 * returns 1, otherwise it returns 0 and the caller shall further
89508 * process the skb.
89509+ *
89510+ * This call might reallocate skb data.
89511 */
89512 int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid)
89513 {
89514diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
89515index f105219..7614af3 100644
89516--- a/net/batman-adv/gateway_client.c
89517+++ b/net/batman-adv/gateway_client.c
89518@@ -508,6 +508,7 @@ out:
89519 return 0;
89520 }
89521
89522+/* this call might reallocate skb data */
89523 static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len)
89524 {
89525 int ret = false;
89526@@ -568,6 +569,7 @@ out:
89527 return ret;
89528 }
89529
89530+/* this call might reallocate skb data */
89531 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
89532 {
89533 struct ethhdr *ethhdr;
89534@@ -619,6 +621,12 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
89535
89536 if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr)))
89537 return false;
89538+
89539+ /* skb->data might have been reallocated by pskb_may_pull() */
89540+ ethhdr = (struct ethhdr *)skb->data;
89541+ if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
89542+ ethhdr = (struct ethhdr *)(skb->data + VLAN_HLEN);
89543+
89544 udphdr = (struct udphdr *)(skb->data + *header_len);
89545 *header_len += sizeof(*udphdr);
89546
89547@@ -634,12 +642,14 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
89548 return true;
89549 }
89550
89551+/* this call might reallocate skb data */
89552 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
89553- struct sk_buff *skb, struct ethhdr *ethhdr)
89554+ struct sk_buff *skb)
89555 {
89556 struct batadv_neigh_node *neigh_curr = NULL, *neigh_old = NULL;
89557 struct batadv_orig_node *orig_dst_node = NULL;
89558 struct batadv_gw_node *curr_gw = NULL;
89559+ struct ethhdr *ethhdr;
89560 bool ret, out_of_range = false;
89561 unsigned int header_len = 0;
89562 uint8_t curr_tq_avg;
89563@@ -648,6 +658,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
89564 if (!ret)
89565 goto out;
89566
89567+ ethhdr = (struct ethhdr *)skb->data;
89568 orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
89569 ethhdr->h_dest);
89570 if (!orig_dst_node)
89571diff --git a/net/batman-adv/gateway_client.h b/net/batman-adv/gateway_client.h
89572index 039902d..1037d75 100644
89573--- a/net/batman-adv/gateway_client.h
89574+++ b/net/batman-adv/gateway_client.h
89575@@ -34,7 +34,6 @@ void batadv_gw_node_delete(struct batadv_priv *bat_priv,
89576 void batadv_gw_node_purge(struct batadv_priv *bat_priv);
89577 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset);
89578 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len);
89579-bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
89580- struct sk_buff *skb, struct ethhdr *ethhdr);
89581+bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);
89582
89583 #endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
89584diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
89585index 522243a..b48c0ef 100644
89586--- a/net/batman-adv/hard-interface.c
89587+++ b/net/batman-adv/hard-interface.c
89588@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
89589 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
89590 dev_add_pack(&hard_iface->batman_adv_ptype);
89591
89592- atomic_set(&hard_iface->frag_seqno, 1);
89593+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
89594 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
89595 hard_iface->net_dev->name);
89596
89597@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
89598 /* This can't be called via a bat_priv callback because
89599 * we have no bat_priv yet.
89600 */
89601- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
89602+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
89603 hard_iface->bat_iv.ogm_buff = NULL;
89604
89605 return hard_iface;
89606diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
89607index 819dfb0..226bacd 100644
89608--- a/net/batman-adv/soft-interface.c
89609+++ b/net/batman-adv/soft-interface.c
89610@@ -180,6 +180,9 @@ static int batadv_interface_tx(struct sk_buff *skb,
89611 if (batadv_bla_tx(bat_priv, skb, vid))
89612 goto dropped;
89613
89614+ /* skb->data might have been reallocated by batadv_bla_tx() */
89615+ ethhdr = (struct ethhdr *)skb->data;
89616+
89617 /* Register the client MAC in the transtable */
89618 if (!is_multicast_ether_addr(ethhdr->h_source))
89619 batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
89620@@ -220,6 +223,10 @@ static int batadv_interface_tx(struct sk_buff *skb,
89621 default:
89622 break;
89623 }
89624+
89625+ /* reminder: ethhdr might have become unusable from here on
89626+ * (batadv_gw_is_dhcp_target() might have reallocated skb data)
89627+ */
89628 }
89629
89630 /* ethernet packet should be broadcasted */
89631@@ -253,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
89632 primary_if->net_dev->dev_addr, ETH_ALEN);
89633
89634 /* set broadcast sequence number */
89635- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
89636+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
89637 bcast_packet->seqno = htonl(seqno);
89638
89639 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
89640@@ -266,7 +273,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
89641 /* unicast packet */
89642 } else {
89643 if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
89644- ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
89645+ ret = batadv_gw_out_of_range(bat_priv, skb);
89646 if (ret)
89647 goto dropped;
89648 }
89649@@ -472,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
89650 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
89651
89652 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
89653- atomic_set(&bat_priv->bcast_seqno, 1);
89654+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
89655 atomic_set(&bat_priv->tt.vn, 0);
89656 atomic_set(&bat_priv->tt.local_changes, 0);
89657 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
89658diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
89659index aba8364..50fcbb8 100644
89660--- a/net/batman-adv/types.h
89661+++ b/net/batman-adv/types.h
89662@@ -51,7 +51,7 @@
89663 struct batadv_hard_iface_bat_iv {
89664 unsigned char *ogm_buff;
89665 int ogm_buff_len;
89666- atomic_t ogm_seqno;
89667+ atomic_unchecked_t ogm_seqno;
89668 };
89669
89670 /**
89671@@ -75,7 +75,7 @@ struct batadv_hard_iface {
89672 int16_t if_num;
89673 char if_status;
89674 struct net_device *net_dev;
89675- atomic_t frag_seqno;
89676+ atomic_unchecked_t frag_seqno;
89677 struct kobject *hardif_obj;
89678 atomic_t refcount;
89679 struct packet_type batman_adv_ptype;
89680@@ -558,7 +558,7 @@ struct batadv_priv {
89681 #ifdef CONFIG_BATMAN_ADV_DEBUG
89682 atomic_t log_level;
89683 #endif
89684- atomic_t bcast_seqno;
89685+ atomic_unchecked_t bcast_seqno;
89686 atomic_t bcast_queue_left;
89687 atomic_t batman_queue_left;
89688 char num_ifaces;
89689diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
89690index 0bb3b59..0e3052e 100644
89691--- a/net/batman-adv/unicast.c
89692+++ b/net/batman-adv/unicast.c
89693@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
89694 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
89695 frag2->flags = large_tail;
89696
89697- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
89698+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
89699 frag1->seqno = htons(seqno - 1);
89700 frag2->seqno = htons(seqno);
89701
89702@@ -326,7 +326,9 @@ static bool batadv_unicast_push_and_fill_skb(struct sk_buff *skb, int hdr_size,
89703 * @skb: the skb containing the payload to encapsulate
89704 * @orig_node: the destination node
89705 *
89706- * Returns false if the payload could not be encapsulated or true otherwise
89707+ * Returns false if the payload could not be encapsulated or true otherwise.
89708+ *
89709+ * This call might reallocate skb data.
89710 */
89711 static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
89712 struct batadv_orig_node *orig_node)
89713@@ -343,7 +345,9 @@ static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
89714 * @orig_node: the destination node
89715 * @packet_subtype: the batman 4addr packet subtype to use
89716 *
89717- * Returns false if the payload could not be encapsulated or true otherwise
89718+ * Returns false if the payload could not be encapsulated or true otherwise.
89719+ *
89720+ * This call might reallocate skb data.
89721 */
89722 bool batadv_unicast_4addr_prepare_skb(struct batadv_priv *bat_priv,
89723 struct sk_buff *skb,
89724@@ -401,7 +405,7 @@ int batadv_unicast_generic_send_skb(struct batadv_priv *bat_priv,
89725 struct batadv_neigh_node *neigh_node;
89726 int data_len = skb->len;
89727 int ret = NET_RX_DROP;
89728- unsigned int dev_mtu;
89729+ unsigned int dev_mtu, header_len;
89730
89731 /* get routing information */
89732 if (is_multicast_ether_addr(ethhdr->h_dest)) {
89733@@ -429,10 +433,12 @@ find_router:
89734 switch (packet_type) {
89735 case BATADV_UNICAST:
89736 batadv_unicast_prepare_skb(skb, orig_node);
89737+ header_len = sizeof(struct batadv_unicast_packet);
89738 break;
89739 case BATADV_UNICAST_4ADDR:
89740 batadv_unicast_4addr_prepare_skb(bat_priv, skb, orig_node,
89741 packet_subtype);
89742+ header_len = sizeof(struct batadv_unicast_4addr_packet);
89743 break;
89744 default:
89745 /* this function supports UNICAST and UNICAST_4ADDR only. It
89746@@ -441,6 +447,7 @@ find_router:
89747 goto out;
89748 }
89749
89750+ ethhdr = (struct ethhdr *)(skb->data + header_len);
89751 unicast_packet = (struct batadv_unicast_packet *)skb->data;
89752
89753 /* inform the destination node that we are still missing a correct route
89754diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
89755index ace5e55..a65a1c0 100644
89756--- a/net/bluetooth/hci_core.c
89757+++ b/net/bluetooth/hci_core.c
89758@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
89759 list_add(&hdev->list, &hci_dev_list);
89760 write_unlock(&hci_dev_list_lock);
89761
89762- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
89763- WQ_MEM_RECLAIM, 1);
89764+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
89765+ WQ_MEM_RECLAIM, 1, hdev->name);
89766 if (!hdev->workqueue) {
89767 error = -ENOMEM;
89768 goto err;
89769 }
89770
89771- hdev->req_workqueue = alloc_workqueue(hdev->name,
89772+ hdev->req_workqueue = alloc_workqueue("%s",
89773 WQ_HIGHPRI | WQ_UNBOUND |
89774- WQ_MEM_RECLAIM, 1);
89775+ WQ_MEM_RECLAIM, 1, hdev->name);
89776 if (!hdev->req_workqueue) {
89777 destroy_workqueue(hdev->workqueue);
89778 error = -ENOMEM;
89779diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
89780index 9bd7d95..6c4884f 100644
89781--- a/net/bluetooth/hci_sock.c
89782+++ b/net/bluetooth/hci_sock.c
89783@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
89784 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
89785 }
89786
89787- len = min_t(unsigned int, len, sizeof(uf));
89788+ len = min((size_t)len, sizeof(uf));
89789 if (copy_from_user(&uf, optval, len)) {
89790 err = -EFAULT;
89791 break;
89792diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
89793index 68843a2..30e9342 100644
89794--- a/net/bluetooth/l2cap_core.c
89795+++ b/net/bluetooth/l2cap_core.c
89796@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
89797 break;
89798
89799 case L2CAP_CONF_RFC:
89800- if (olen == sizeof(rfc))
89801- memcpy(&rfc, (void *)val, olen);
89802+ if (olen != sizeof(rfc))
89803+ break;
89804+
89805+ memcpy(&rfc, (void *)val, olen);
89806
89807 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
89808 rfc.mode != chan->mode)
89809diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
89810index 36fed40..be2eeb2 100644
89811--- a/net/bluetooth/l2cap_sock.c
89812+++ b/net/bluetooth/l2cap_sock.c
89813@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
89814 struct sock *sk = sock->sk;
89815 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
89816 struct l2cap_options opts;
89817- int len, err = 0;
89818+ int err = 0;
89819+ size_t len = optlen;
89820 u32 opt;
89821
89822 BT_DBG("sk %p", sk);
89823@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
89824 opts.max_tx = chan->max_tx;
89825 opts.txwin_size = chan->tx_win;
89826
89827- len = min_t(unsigned int, sizeof(opts), optlen);
89828+ len = min(sizeof(opts), len);
89829 if (copy_from_user((char *) &opts, optval, len)) {
89830 err = -EFAULT;
89831 break;
89832@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
89833 struct bt_security sec;
89834 struct bt_power pwr;
89835 struct l2cap_conn *conn;
89836- int len, err = 0;
89837+ int err = 0;
89838+ size_t len = optlen;
89839 u32 opt;
89840
89841 BT_DBG("sk %p", sk);
89842@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
89843
89844 sec.level = BT_SECURITY_LOW;
89845
89846- len = min_t(unsigned int, sizeof(sec), optlen);
89847+ len = min(sizeof(sec), len);
89848 if (copy_from_user((char *) &sec, optval, len)) {
89849 err = -EFAULT;
89850 break;
89851@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
89852
89853 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
89854
89855- len = min_t(unsigned int, sizeof(pwr), optlen);
89856+ len = min(sizeof(pwr), len);
89857 if (copy_from_user((char *) &pwr, optval, len)) {
89858 err = -EFAULT;
89859 break;
89860diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
89861index 30b3721..c1bd0a0 100644
89862--- a/net/bluetooth/rfcomm/sock.c
89863+++ b/net/bluetooth/rfcomm/sock.c
89864@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
89865 struct sock *sk = sock->sk;
89866 struct bt_security sec;
89867 int err = 0;
89868- size_t len;
89869+ size_t len = optlen;
89870 u32 opt;
89871
89872 BT_DBG("sk %p", sk);
89873@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
89874
89875 sec.level = BT_SECURITY_LOW;
89876
89877- len = min_t(unsigned int, sizeof(sec), optlen);
89878+ len = min(sizeof(sec), len);
89879 if (copy_from_user((char *) &sec, optval, len)) {
89880 err = -EFAULT;
89881 break;
89882diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
89883index b6e44ad..5b0d514 100644
89884--- a/net/bluetooth/rfcomm/tty.c
89885+++ b/net/bluetooth/rfcomm/tty.c
89886@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
89887 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
89888
89889 spin_lock_irqsave(&dev->port.lock, flags);
89890- if (dev->port.count > 0) {
89891+ if (atomic_read(&dev->port.count) > 0) {
89892 spin_unlock_irqrestore(&dev->port.lock, flags);
89893 return;
89894 }
89895@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
89896 return -ENODEV;
89897
89898 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
89899- dev->channel, dev->port.count);
89900+ dev->channel, atomic_read(&dev->port.count));
89901
89902 spin_lock_irqsave(&dev->port.lock, flags);
89903- if (++dev->port.count > 1) {
89904+ if (atomic_inc_return(&dev->port.count) > 1) {
89905 spin_unlock_irqrestore(&dev->port.lock, flags);
89906 return 0;
89907 }
89908@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
89909 return;
89910
89911 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
89912- dev->port.count);
89913+ atomic_read(&dev->port.count));
89914
89915 spin_lock_irqsave(&dev->port.lock, flags);
89916- if (!--dev->port.count) {
89917+ if (!atomic_dec_return(&dev->port.count)) {
89918 spin_unlock_irqrestore(&dev->port.lock, flags);
89919 if (dev->tty_dev->parent)
89920 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
89921diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
89922index 3d110c4..4e1b2eb 100644
89923--- a/net/bridge/netfilter/ebtables.c
89924+++ b/net/bridge/netfilter/ebtables.c
89925@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
89926 tmp.valid_hooks = t->table->valid_hooks;
89927 }
89928 mutex_unlock(&ebt_mutex);
89929- if (copy_to_user(user, &tmp, *len) != 0){
89930+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
89931 BUGPRINT("c2u Didn't work\n");
89932 ret = -EFAULT;
89933 break;
89934@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
89935 goto out;
89936 tmp.valid_hooks = t->valid_hooks;
89937
89938- if (copy_to_user(user, &tmp, *len) != 0) {
89939+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
89940 ret = -EFAULT;
89941 break;
89942 }
89943@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
89944 tmp.entries_size = t->table->entries_size;
89945 tmp.valid_hooks = t->table->valid_hooks;
89946
89947- if (copy_to_user(user, &tmp, *len) != 0) {
89948+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
89949 ret = -EFAULT;
89950 break;
89951 }
89952diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
89953index 2bd4b58..0dc30a1 100644
89954--- a/net/caif/cfctrl.c
89955+++ b/net/caif/cfctrl.c
89956@@ -10,6 +10,7 @@
89957 #include <linux/spinlock.h>
89958 #include <linux/slab.h>
89959 #include <linux/pkt_sched.h>
89960+#include <linux/sched.h>
89961 #include <net/caif/caif_layer.h>
89962 #include <net/caif/cfpkt.h>
89963 #include <net/caif/cfctrl.h>
89964@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
89965 memset(&dev_info, 0, sizeof(dev_info));
89966 dev_info.id = 0xff;
89967 cfsrvl_init(&this->serv, 0, &dev_info, false);
89968- atomic_set(&this->req_seq_no, 1);
89969- atomic_set(&this->rsp_seq_no, 1);
89970+ atomic_set_unchecked(&this->req_seq_no, 1);
89971+ atomic_set_unchecked(&this->rsp_seq_no, 1);
89972 this->serv.layer.receive = cfctrl_recv;
89973 sprintf(this->serv.layer.name, "ctrl");
89974 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
89975@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
89976 struct cfctrl_request_info *req)
89977 {
89978 spin_lock_bh(&ctrl->info_list_lock);
89979- atomic_inc(&ctrl->req_seq_no);
89980- req->sequence_no = atomic_read(&ctrl->req_seq_no);
89981+ atomic_inc_unchecked(&ctrl->req_seq_no);
89982+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
89983 list_add_tail(&req->list, &ctrl->list);
89984 spin_unlock_bh(&ctrl->info_list_lock);
89985 }
89986@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
89987 if (p != first)
89988 pr_warn("Requests are not received in order\n");
89989
89990- atomic_set(&ctrl->rsp_seq_no,
89991+ atomic_set_unchecked(&ctrl->rsp_seq_no,
89992 p->sequence_no);
89993 list_del(&p->list);
89994 goto out;
89995diff --git a/net/can/af_can.c b/net/can/af_can.c
89996index c4e5085..aa9efdf 100644
89997--- a/net/can/af_can.c
89998+++ b/net/can/af_can.c
89999@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
90000 };
90001
90002 /* notifier block for netdevice event */
90003-static struct notifier_block can_netdev_notifier __read_mostly = {
90004+static struct notifier_block can_netdev_notifier = {
90005 .notifier_call = can_notifier,
90006 };
90007
90008diff --git a/net/can/gw.c b/net/can/gw.c
90009index 3ee690e..00d581b 100644
90010--- a/net/can/gw.c
90011+++ b/net/can/gw.c
90012@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
90013 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
90014
90015 static HLIST_HEAD(cgw_list);
90016-static struct notifier_block notifier;
90017
90018 static struct kmem_cache *cgw_cache __read_mostly;
90019
90020@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
90021 return err;
90022 }
90023
90024+static struct notifier_block notifier = {
90025+ .notifier_call = cgw_notifier
90026+};
90027+
90028 static __init int cgw_module_init(void)
90029 {
90030 /* sanitize given module parameter */
90031@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
90032 return -ENOMEM;
90033
90034 /* set notifier */
90035- notifier.notifier_call = cgw_notifier;
90036 register_netdevice_notifier(&notifier);
90037
90038 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
90039diff --git a/net/compat.c b/net/compat.c
90040index f0a1ba6..0541331 100644
90041--- a/net/compat.c
90042+++ b/net/compat.c
90043@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
90044 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
90045 __get_user(kmsg->msg_flags, &umsg->msg_flags))
90046 return -EFAULT;
90047- kmsg->msg_name = compat_ptr(tmp1);
90048- kmsg->msg_iov = compat_ptr(tmp2);
90049- kmsg->msg_control = compat_ptr(tmp3);
90050+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
90051+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
90052+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
90053 return 0;
90054 }
90055
90056@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90057
90058 if (kern_msg->msg_namelen) {
90059 if (mode == VERIFY_READ) {
90060- int err = move_addr_to_kernel(kern_msg->msg_name,
90061+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
90062 kern_msg->msg_namelen,
90063 kern_address);
90064 if (err < 0)
90065@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90066 kern_msg->msg_name = NULL;
90067
90068 tot_len = iov_from_user_compat_to_kern(kern_iov,
90069- (struct compat_iovec __user *)kern_msg->msg_iov,
90070+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
90071 kern_msg->msg_iovlen);
90072 if (tot_len >= 0)
90073 kern_msg->msg_iov = kern_iov;
90074@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90075
90076 #define CMSG_COMPAT_FIRSTHDR(msg) \
90077 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
90078- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
90079+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
90080 (struct compat_cmsghdr __user *)NULL)
90081
90082 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
90083 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
90084 (ucmlen) <= (unsigned long) \
90085 ((mhdr)->msg_controllen - \
90086- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
90087+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
90088
90089 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
90090 struct compat_cmsghdr __user *cmsg, int cmsg_len)
90091 {
90092 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
90093- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
90094+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
90095 msg->msg_controllen)
90096 return NULL;
90097 return (struct compat_cmsghdr __user *)ptr;
90098@@ -219,7 +219,7 @@ Efault:
90099
90100 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
90101 {
90102- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
90103+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
90104 struct compat_cmsghdr cmhdr;
90105 struct compat_timeval ctv;
90106 struct compat_timespec cts[3];
90107@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
90108
90109 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
90110 {
90111- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
90112+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
90113 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
90114 int fdnum = scm->fp->count;
90115 struct file **fp = scm->fp->fp;
90116@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
90117 return -EFAULT;
90118 old_fs = get_fs();
90119 set_fs(KERNEL_DS);
90120- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
90121+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
90122 set_fs(old_fs);
90123
90124 return err;
90125@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
90126 len = sizeof(ktime);
90127 old_fs = get_fs();
90128 set_fs(KERNEL_DS);
90129- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
90130+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
90131 set_fs(old_fs);
90132
90133 if (!err) {
90134@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90135 case MCAST_JOIN_GROUP:
90136 case MCAST_LEAVE_GROUP:
90137 {
90138- struct compat_group_req __user *gr32 = (void *)optval;
90139+ struct compat_group_req __user *gr32 = (void __user *)optval;
90140 struct group_req __user *kgr =
90141 compat_alloc_user_space(sizeof(struct group_req));
90142 u32 interface;
90143@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90144 case MCAST_BLOCK_SOURCE:
90145 case MCAST_UNBLOCK_SOURCE:
90146 {
90147- struct compat_group_source_req __user *gsr32 = (void *)optval;
90148+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
90149 struct group_source_req __user *kgsr = compat_alloc_user_space(
90150 sizeof(struct group_source_req));
90151 u32 interface;
90152@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90153 }
90154 case MCAST_MSFILTER:
90155 {
90156- struct compat_group_filter __user *gf32 = (void *)optval;
90157+ struct compat_group_filter __user *gf32 = (void __user *)optval;
90158 struct group_filter __user *kgf;
90159 u32 interface, fmode, numsrc;
90160
90161@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
90162 char __user *optval, int __user *optlen,
90163 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
90164 {
90165- struct compat_group_filter __user *gf32 = (void *)optval;
90166+ struct compat_group_filter __user *gf32 = (void __user *)optval;
90167 struct group_filter __user *kgf;
90168 int __user *koptlen;
90169 u32 interface, fmode, numsrc;
90170@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
90171
90172 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
90173 return -EINVAL;
90174- if (copy_from_user(a, args, nas[call]))
90175+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
90176 return -EFAULT;
90177 a0 = a[0];
90178 a1 = a[1];
90179diff --git a/net/core/datagram.c b/net/core/datagram.c
90180index b71423d..0360434 100644
90181--- a/net/core/datagram.c
90182+++ b/net/core/datagram.c
90183@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
90184 }
90185
90186 kfree_skb(skb);
90187- atomic_inc(&sk->sk_drops);
90188+ atomic_inc_unchecked(&sk->sk_drops);
90189 sk_mem_reclaim_partial(sk);
90190
90191 return err;
90192diff --git a/net/core/dev.c b/net/core/dev.c
90193index 7ddbb31..3902452 100644
90194--- a/net/core/dev.c
90195+++ b/net/core/dev.c
90196@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
90197 {
90198 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
90199 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
90200- atomic_long_inc(&dev->rx_dropped);
90201+ atomic_long_inc_unchecked(&dev->rx_dropped);
90202 kfree_skb(skb);
90203 return NET_RX_DROP;
90204 }
90205@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
90206 skb_orphan(skb);
90207
90208 if (unlikely(!is_skb_forwardable(dev, skb))) {
90209- atomic_long_inc(&dev->rx_dropped);
90210+ atomic_long_inc_unchecked(&dev->rx_dropped);
90211 kfree_skb(skb);
90212 return NET_RX_DROP;
90213 }
90214@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
90215
90216 struct dev_gso_cb {
90217 void (*destructor)(struct sk_buff *skb);
90218-};
90219+} __no_const;
90220
90221 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
90222
90223@@ -3139,7 +3139,7 @@ enqueue:
90224
90225 local_irq_restore(flags);
90226
90227- atomic_long_inc(&skb->dev->rx_dropped);
90228+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
90229 kfree_skb(skb);
90230 return NET_RX_DROP;
90231 }
90232@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
90233 }
90234 EXPORT_SYMBOL(netif_rx_ni);
90235
90236-static void net_tx_action(struct softirq_action *h)
90237+static void net_tx_action(void)
90238 {
90239 struct softnet_data *sd = &__get_cpu_var(softnet_data);
90240
90241@@ -3545,7 +3545,7 @@ ncls:
90242 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
90243 } else {
90244 drop:
90245- atomic_long_inc(&skb->dev->rx_dropped);
90246+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
90247 kfree_skb(skb);
90248 /* Jamal, now you will not able to escape explaining
90249 * me how you were going to use this. :-)
90250@@ -4153,7 +4153,7 @@ void netif_napi_del(struct napi_struct *napi)
90251 }
90252 EXPORT_SYMBOL(netif_napi_del);
90253
90254-static void net_rx_action(struct softirq_action *h)
90255+static void net_rx_action(void)
90256 {
90257 struct softnet_data *sd = &__get_cpu_var(softnet_data);
90258 unsigned long time_limit = jiffies + 2;
90259@@ -5590,7 +5590,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
90260 } else {
90261 netdev_stats_to_stats64(storage, &dev->stats);
90262 }
90263- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
90264+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
90265 return storage;
90266 }
90267 EXPORT_SYMBOL(dev_get_stats);
90268diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
90269index 5b7d0e1..cb960fc 100644
90270--- a/net/core/dev_ioctl.c
90271+++ b/net/core/dev_ioctl.c
90272@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
90273 if (no_module && capable(CAP_NET_ADMIN))
90274 no_module = request_module("netdev-%s", name);
90275 if (no_module && capable(CAP_SYS_MODULE)) {
90276+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90277+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
90278+#else
90279 if (!request_module("%s", name))
90280 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
90281 name);
90282+#endif
90283 }
90284 }
90285 EXPORT_SYMBOL(dev_load);
90286diff --git a/net/core/ethtool.c b/net/core/ethtool.c
90287index ce91766..3b71cdb 100644
90288--- a/net/core/ethtool.c
90289+++ b/net/core/ethtool.c
90290@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
90291 if (ret)
90292 return ret;
90293
90294- len = (tmp.len > dump.len) ? dump.len : tmp.len;
90295+ len = min(tmp.len, dump.len);
90296 if (!len)
90297 return -EFAULT;
90298
90299+ /* Don't ever let the driver think there's more space available
90300+ * than it requested with .get_dump_flag().
90301+ */
90302+ dump.len = len;
90303+
90304+ /* Always allocate enough space to hold the whole thing so that the
90305+ * driver does not need to check the length and bother with partial
90306+ * dumping.
90307+ */
90308 data = vzalloc(tmp.len);
90309 if (!data)
90310 return -ENOMEM;
90311@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
90312 if (ret)
90313 goto out;
90314
90315+ /* There are two sane possibilities:
90316+ * 1. The driver's .get_dump_data() does not touch dump.len.
90317+ * 2. Or it may set dump.len to how much it really writes, which
90318+ * should be tmp.len (or len if it can do a partial dump).
90319+ * In any case respond to userspace with the actual length of data
90320+ * it's receiving.
90321+ */
90322+ WARN_ON(dump.len != len && dump.len != tmp.len);
90323+ dump.len = len;
90324+
90325 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
90326 ret = -EFAULT;
90327 goto out;
90328diff --git a/net/core/flow.c b/net/core/flow.c
90329index 7102f16..146b4bd 100644
90330--- a/net/core/flow.c
90331+++ b/net/core/flow.c
90332@@ -61,7 +61,7 @@ struct flow_cache {
90333 struct timer_list rnd_timer;
90334 };
90335
90336-atomic_t flow_cache_genid = ATOMIC_INIT(0);
90337+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
90338 EXPORT_SYMBOL(flow_cache_genid);
90339 static struct flow_cache flow_cache_global;
90340 static struct kmem_cache *flow_cachep __read_mostly;
90341@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
90342
90343 static int flow_entry_valid(struct flow_cache_entry *fle)
90344 {
90345- if (atomic_read(&flow_cache_genid) != fle->genid)
90346+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
90347 return 0;
90348 if (fle->object && !fle->object->ops->check(fle->object))
90349 return 0;
90350@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
90351 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
90352 fcp->hash_count++;
90353 }
90354- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
90355+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
90356 flo = fle->object;
90357 if (!flo)
90358 goto ret_object;
90359@@ -279,7 +279,7 @@ nocache:
90360 }
90361 flo = resolver(net, key, family, dir, flo, ctx);
90362 if (fle) {
90363- fle->genid = atomic_read(&flow_cache_genid);
90364+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
90365 if (!IS_ERR(flo))
90366 fle->object = flo;
90367 else
90368diff --git a/net/core/iovec.c b/net/core/iovec.c
90369index de178e4..1dabd8b 100644
90370--- a/net/core/iovec.c
90371+++ b/net/core/iovec.c
90372@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
90373 if (m->msg_namelen) {
90374 if (mode == VERIFY_READ) {
90375 void __user *namep;
90376- namep = (void __user __force *) m->msg_name;
90377+ namep = (void __force_user *) m->msg_name;
90378 err = move_addr_to_kernel(namep, m->msg_namelen,
90379 address);
90380 if (err < 0)
90381@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
90382 }
90383
90384 size = m->msg_iovlen * sizeof(struct iovec);
90385- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
90386+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
90387 return -EFAULT;
90388
90389 m->msg_iov = iov;
90390diff --git a/net/core/neighbour.c b/net/core/neighbour.c
90391index ce90b02..8752627 100644
90392--- a/net/core/neighbour.c
90393+++ b/net/core/neighbour.c
90394@@ -2771,7 +2771,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
90395 size_t *lenp, loff_t *ppos)
90396 {
90397 int size, ret;
90398- ctl_table tmp = *ctl;
90399+ ctl_table_no_const tmp = *ctl;
90400
90401 tmp.extra1 = &zero;
90402 tmp.extra2 = &unres_qlen_max;
90403diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
90404index 569d355..79cf2d0 100644
90405--- a/net/core/net-procfs.c
90406+++ b/net/core/net-procfs.c
90407@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
90408 else
90409 seq_printf(seq, "%04x", ntohs(pt->type));
90410
90411+#ifdef CONFIG_GRKERNSEC_HIDESYM
90412+ seq_printf(seq, " %-8s %pf\n",
90413+ pt->dev ? pt->dev->name : "", NULL);
90414+#else
90415 seq_printf(seq, " %-8s %pf\n",
90416 pt->dev ? pt->dev->name : "", pt->func);
90417+#endif
90418 }
90419
90420 return 0;
90421diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
90422index 981fed3..536af34 100644
90423--- a/net/core/net-sysfs.c
90424+++ b/net/core/net-sysfs.c
90425@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
90426 }
90427 EXPORT_SYMBOL(netdev_class_remove_file);
90428
90429-int netdev_kobject_init(void)
90430+int __init netdev_kobject_init(void)
90431 {
90432 kobj_ns_type_register(&net_ns_type_operations);
90433 return class_register(&net_class);
90434diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
90435index f9765203..9feaef8 100644
90436--- a/net/core/net_namespace.c
90437+++ b/net/core/net_namespace.c
90438@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
90439 int error;
90440 LIST_HEAD(net_exit_list);
90441
90442- list_add_tail(&ops->list, list);
90443+ pax_list_add_tail((struct list_head *)&ops->list, list);
90444 if (ops->init || (ops->id && ops->size)) {
90445 for_each_net(net) {
90446 error = ops_init(ops, net);
90447@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
90448
90449 out_undo:
90450 /* If I have an error cleanup all namespaces I initialized */
90451- list_del(&ops->list);
90452+ pax_list_del((struct list_head *)&ops->list);
90453 ops_exit_list(ops, &net_exit_list);
90454 ops_free_list(ops, &net_exit_list);
90455 return error;
90456@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
90457 struct net *net;
90458 LIST_HEAD(net_exit_list);
90459
90460- list_del(&ops->list);
90461+ pax_list_del((struct list_head *)&ops->list);
90462 for_each_net(net)
90463 list_add_tail(&net->exit_list, &net_exit_list);
90464 ops_exit_list(ops, &net_exit_list);
90465@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
90466 mutex_lock(&net_mutex);
90467 error = register_pernet_operations(&pernet_list, ops);
90468 if (!error && (first_device == &pernet_list))
90469- first_device = &ops->list;
90470+ first_device = (struct list_head *)&ops->list;
90471 mutex_unlock(&net_mutex);
90472 return error;
90473 }
90474diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
90475index a08bd2b..c59bd7c 100644
90476--- a/net/core/rtnetlink.c
90477+++ b/net/core/rtnetlink.c
90478@@ -58,7 +58,7 @@ struct rtnl_link {
90479 rtnl_doit_func doit;
90480 rtnl_dumpit_func dumpit;
90481 rtnl_calcit_func calcit;
90482-};
90483+} __no_const;
90484
90485 static DEFINE_MUTEX(rtnl_mutex);
90486
90487@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
90488 if (rtnl_link_ops_get(ops->kind))
90489 return -EEXIST;
90490
90491- if (!ops->dellink)
90492- ops->dellink = unregister_netdevice_queue;
90493+ if (!ops->dellink) {
90494+ pax_open_kernel();
90495+ *(void **)&ops->dellink = unregister_netdevice_queue;
90496+ pax_close_kernel();
90497+ }
90498
90499- list_add_tail(&ops->list, &link_ops);
90500+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
90501 return 0;
90502 }
90503 EXPORT_SYMBOL_GPL(__rtnl_link_register);
90504@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
90505 for_each_net(net) {
90506 __rtnl_kill_links(net, ops);
90507 }
90508- list_del(&ops->list);
90509+ pax_list_del((struct list_head *)&ops->list);
90510 }
90511 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
90512
90513@@ -2374,7 +2377,7 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
90514 struct nlattr *extfilt;
90515 u32 filter_mask = 0;
90516
90517- extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct rtgenmsg),
90518+ extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg),
90519 IFLA_EXT_MASK);
90520 if (extfilt)
90521 filter_mask = nla_get_u32(extfilt);
90522diff --git a/net/core/scm.c b/net/core/scm.c
90523index 03795d0..eaf7368 100644
90524--- a/net/core/scm.c
90525+++ b/net/core/scm.c
90526@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
90527 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
90528 {
90529 struct cmsghdr __user *cm
90530- = (__force struct cmsghdr __user *)msg->msg_control;
90531+ = (struct cmsghdr __force_user *)msg->msg_control;
90532 struct cmsghdr cmhdr;
90533 int cmlen = CMSG_LEN(len);
90534 int err;
90535@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
90536 err = -EFAULT;
90537 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
90538 goto out;
90539- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
90540+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
90541 goto out;
90542 cmlen = CMSG_SPACE(len);
90543 if (msg->msg_controllen < cmlen)
90544@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
90545 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
90546 {
90547 struct cmsghdr __user *cm
90548- = (__force struct cmsghdr __user*)msg->msg_control;
90549+ = (struct cmsghdr __force_user *)msg->msg_control;
90550
90551 int fdmax = 0;
90552 int fdnum = scm->fp->count;
90553@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
90554 if (fdnum < fdmax)
90555 fdmax = fdnum;
90556
90557- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
90558+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
90559 i++, cmfptr++)
90560 {
90561 struct socket *sock;
90562diff --git a/net/core/skbuff.c b/net/core/skbuff.c
90563index 1c1738c..4cab7f0 100644
90564--- a/net/core/skbuff.c
90565+++ b/net/core/skbuff.c
90566@@ -3087,13 +3087,15 @@ void __init skb_init(void)
90567 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
90568 sizeof(struct sk_buff),
90569 0,
90570- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
90571+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
90572+ SLAB_NO_SANITIZE,
90573 NULL);
90574 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
90575 (2*sizeof(struct sk_buff)) +
90576 sizeof(atomic_t),
90577 0,
90578- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
90579+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
90580+ SLAB_NO_SANITIZE,
90581 NULL);
90582 }
90583
90584diff --git a/net/core/sock.c b/net/core/sock.c
90585index d6d024c..6ea7ab4 100644
90586--- a/net/core/sock.c
90587+++ b/net/core/sock.c
90588@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
90589 struct sk_buff_head *list = &sk->sk_receive_queue;
90590
90591 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
90592- atomic_inc(&sk->sk_drops);
90593+ atomic_inc_unchecked(&sk->sk_drops);
90594 trace_sock_rcvqueue_full(sk, skb);
90595 return -ENOMEM;
90596 }
90597@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
90598 return err;
90599
90600 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
90601- atomic_inc(&sk->sk_drops);
90602+ atomic_inc_unchecked(&sk->sk_drops);
90603 return -ENOBUFS;
90604 }
90605
90606@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
90607 skb_dst_force(skb);
90608
90609 spin_lock_irqsave(&list->lock, flags);
90610- skb->dropcount = atomic_read(&sk->sk_drops);
90611+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
90612 __skb_queue_tail(list, skb);
90613 spin_unlock_irqrestore(&list->lock, flags);
90614
90615@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
90616 skb->dev = NULL;
90617
90618 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
90619- atomic_inc(&sk->sk_drops);
90620+ atomic_inc_unchecked(&sk->sk_drops);
90621 goto discard_and_relse;
90622 }
90623 if (nested)
90624@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
90625 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
90626 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
90627 bh_unlock_sock(sk);
90628- atomic_inc(&sk->sk_drops);
90629+ atomic_inc_unchecked(&sk->sk_drops);
90630 goto discard_and_relse;
90631 }
90632
90633@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
90634 struct timeval tm;
90635 } v;
90636
90637- int lv = sizeof(int);
90638- int len;
90639+ unsigned int lv = sizeof(int);
90640+ unsigned int len;
90641
90642 if (get_user(len, optlen))
90643 return -EFAULT;
90644- if (len < 0)
90645+ if (len > INT_MAX)
90646 return -EINVAL;
90647
90648 memset(&v, 0, sizeof(v));
90649@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
90650
90651 case SO_PEERNAME:
90652 {
90653- char address[128];
90654+ char address[_K_SS_MAXSIZE];
90655
90656 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
90657 return -ENOTCONN;
90658- if (lv < len)
90659+ if (lv < len || sizeof address < len)
90660 return -EINVAL;
90661 if (copy_to_user(optval, address, len))
90662 return -EFAULT;
90663@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
90664
90665 if (len > lv)
90666 len = lv;
90667- if (copy_to_user(optval, &v, len))
90668+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
90669 return -EFAULT;
90670 lenout:
90671 if (put_user(len, optlen))
90672@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
90673 */
90674 smp_wmb();
90675 atomic_set(&sk->sk_refcnt, 1);
90676- atomic_set(&sk->sk_drops, 0);
90677+ atomic_set_unchecked(&sk->sk_drops, 0);
90678 }
90679 EXPORT_SYMBOL(sock_init_data);
90680
90681diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
90682index a0e9cf6..ef7f9ed 100644
90683--- a/net/core/sock_diag.c
90684+++ b/net/core/sock_diag.c
90685@@ -9,26 +9,33 @@
90686 #include <linux/inet_diag.h>
90687 #include <linux/sock_diag.h>
90688
90689-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
90690+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
90691 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
90692 static DEFINE_MUTEX(sock_diag_table_mutex);
90693
90694 int sock_diag_check_cookie(void *sk, __u32 *cookie)
90695 {
90696+#ifndef CONFIG_GRKERNSEC_HIDESYM
90697 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
90698 cookie[1] != INET_DIAG_NOCOOKIE) &&
90699 ((u32)(unsigned long)sk != cookie[0] ||
90700 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
90701 return -ESTALE;
90702 else
90703+#endif
90704 return 0;
90705 }
90706 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
90707
90708 void sock_diag_save_cookie(void *sk, __u32 *cookie)
90709 {
90710+#ifdef CONFIG_GRKERNSEC_HIDESYM
90711+ cookie[0] = 0;
90712+ cookie[1] = 0;
90713+#else
90714 cookie[0] = (u32)(unsigned long)sk;
90715 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
90716+#endif
90717 }
90718 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
90719
90720@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
90721 mutex_lock(&sock_diag_table_mutex);
90722 if (sock_diag_handlers[hndl->family])
90723 err = -EBUSY;
90724- else
90725+ else {
90726+ pax_open_kernel();
90727 sock_diag_handlers[hndl->family] = hndl;
90728+ pax_close_kernel();
90729+ }
90730 mutex_unlock(&sock_diag_table_mutex);
90731
90732 return err;
90733@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
90734
90735 mutex_lock(&sock_diag_table_mutex);
90736 BUG_ON(sock_diag_handlers[family] != hnld);
90737+ pax_open_kernel();
90738 sock_diag_handlers[family] = NULL;
90739+ pax_close_kernel();
90740 mutex_unlock(&sock_diag_table_mutex);
90741 }
90742 EXPORT_SYMBOL_GPL(sock_diag_unregister);
90743diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
90744index cfdb46a..cef55e1 100644
90745--- a/net/core/sysctl_net_core.c
90746+++ b/net/core/sysctl_net_core.c
90747@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
90748 {
90749 unsigned int orig_size, size;
90750 int ret, i;
90751- ctl_table tmp = {
90752+ ctl_table_no_const tmp = {
90753 .data = &size,
90754 .maxlen = sizeof(size),
90755 .mode = table->mode
90756@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
90757
90758 static __net_init int sysctl_core_net_init(struct net *net)
90759 {
90760- struct ctl_table *tbl;
90761+ ctl_table_no_const *tbl = NULL;
90762
90763 net->core.sysctl_somaxconn = SOMAXCONN;
90764
90765- tbl = netns_core_table;
90766 if (!net_eq(net, &init_net)) {
90767- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
90768+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
90769 if (tbl == NULL)
90770 goto err_dup;
90771
90772@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
90773 if (net->user_ns != &init_user_ns) {
90774 tbl[0].procname = NULL;
90775 }
90776- }
90777-
90778- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
90779+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
90780+ } else
90781+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
90782 if (net->core.sysctl_hdr == NULL)
90783 goto err_reg;
90784
90785 return 0;
90786
90787 err_reg:
90788- if (tbl != netns_core_table)
90789- kfree(tbl);
90790+ kfree(tbl);
90791 err_dup:
90792 return -ENOMEM;
90793 }
90794@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
90795 kfree(tbl);
90796 }
90797
90798-static __net_initdata struct pernet_operations sysctl_core_ops = {
90799+static __net_initconst struct pernet_operations sysctl_core_ops = {
90800 .init = sysctl_core_net_init,
90801 .exit = sysctl_core_net_exit,
90802 };
90803diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
90804index c21f200..bc4565b 100644
90805--- a/net/decnet/af_decnet.c
90806+++ b/net/decnet/af_decnet.c
90807@@ -465,6 +465,7 @@ static struct proto dn_proto = {
90808 .sysctl_rmem = sysctl_decnet_rmem,
90809 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
90810 .obj_size = sizeof(struct dn_sock),
90811+ .slab_flags = SLAB_USERCOPY,
90812 };
90813
90814 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
90815diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
90816index a55eecc..dd8428c 100644
90817--- a/net/decnet/sysctl_net_decnet.c
90818+++ b/net/decnet/sysctl_net_decnet.c
90819@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
90820
90821 if (len > *lenp) len = *lenp;
90822
90823- if (copy_to_user(buffer, addr, len))
90824+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
90825 return -EFAULT;
90826
90827 *lenp = len;
90828@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
90829
90830 if (len > *lenp) len = *lenp;
90831
90832- if (copy_to_user(buffer, devname, len))
90833+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
90834 return -EFAULT;
90835
90836 *lenp = len;
90837diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
90838index d01be2a..8976537 100644
90839--- a/net/ipv4/af_inet.c
90840+++ b/net/ipv4/af_inet.c
90841@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
90842
90843 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
90844
90845- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
90846- if (!sysctl_local_reserved_ports)
90847- goto out;
90848-
90849 rc = proto_register(&tcp_prot, 1);
90850 if (rc)
90851- goto out_free_reserved_ports;
90852+ goto out;
90853
90854 rc = proto_register(&udp_prot, 1);
90855 if (rc)
90856@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
90857 proto_unregister(&udp_prot);
90858 out_unregister_tcp_proto:
90859 proto_unregister(&tcp_prot);
90860-out_free_reserved_ports:
90861- kfree(sysctl_local_reserved_ports);
90862 goto out;
90863 }
90864
90865diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
90866index 2e7f194..0fa4d6d 100644
90867--- a/net/ipv4/ah4.c
90868+++ b/net/ipv4/ah4.c
90869@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
90870 return;
90871
90872 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
90873- atomic_inc(&flow_cache_genid);
90874+ atomic_inc_unchecked(&flow_cache_genid);
90875 rt_genid_bump(net);
90876
90877 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
90878diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
90879index dfc39d4..0d4fa52 100644
90880--- a/net/ipv4/devinet.c
90881+++ b/net/ipv4/devinet.c
90882@@ -771,7 +771,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
90883 ci = nla_data(tb[IFA_CACHEINFO]);
90884 if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
90885 err = -EINVAL;
90886- goto errout;
90887+ goto errout_free;
90888 }
90889 *pvalid_lft = ci->ifa_valid;
90890 *pprefered_lft = ci->ifa_prefered;
90891@@ -779,6 +779,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
90892
90893 return ifa;
90894
90895+errout_free:
90896+ inet_free_ifa(ifa);
90897 errout:
90898 return ERR_PTR(err);
90899 }
90900@@ -1529,7 +1531,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
90901 idx = 0;
90902 head = &net->dev_index_head[h];
90903 rcu_read_lock();
90904- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
90905+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
90906 net->dev_base_seq;
90907 hlist_for_each_entry_rcu(dev, head, index_hlist) {
90908 if (idx < s_idx)
90909@@ -1840,7 +1842,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
90910 idx = 0;
90911 head = &net->dev_index_head[h];
90912 rcu_read_lock();
90913- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
90914+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
90915 net->dev_base_seq;
90916 hlist_for_each_entry_rcu(dev, head, index_hlist) {
90917 if (idx < s_idx)
90918@@ -2065,7 +2067,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
90919 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
90920 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
90921
90922-static struct devinet_sysctl_table {
90923+static const struct devinet_sysctl_table {
90924 struct ctl_table_header *sysctl_header;
90925 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
90926 } devinet_sysctl = {
90927@@ -2183,7 +2185,7 @@ static __net_init int devinet_init_net(struct net *net)
90928 int err;
90929 struct ipv4_devconf *all, *dflt;
90930 #ifdef CONFIG_SYSCTL
90931- struct ctl_table *tbl = ctl_forward_entry;
90932+ ctl_table_no_const *tbl = NULL;
90933 struct ctl_table_header *forw_hdr;
90934 #endif
90935
90936@@ -2201,7 +2203,7 @@ static __net_init int devinet_init_net(struct net *net)
90937 goto err_alloc_dflt;
90938
90939 #ifdef CONFIG_SYSCTL
90940- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
90941+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
90942 if (tbl == NULL)
90943 goto err_alloc_ctl;
90944
90945@@ -2221,7 +2223,10 @@ static __net_init int devinet_init_net(struct net *net)
90946 goto err_reg_dflt;
90947
90948 err = -ENOMEM;
90949- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
90950+ if (!net_eq(net, &init_net))
90951+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
90952+ else
90953+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
90954 if (forw_hdr == NULL)
90955 goto err_reg_ctl;
90956 net->ipv4.forw_hdr = forw_hdr;
90957@@ -2237,8 +2242,7 @@ err_reg_ctl:
90958 err_reg_dflt:
90959 __devinet_sysctl_unregister(all);
90960 err_reg_all:
90961- if (tbl != ctl_forward_entry)
90962- kfree(tbl);
90963+ kfree(tbl);
90964 err_alloc_ctl:
90965 #endif
90966 if (dflt != &ipv4_devconf_dflt)
90967diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
90968index 4cfe34d..d2fac8a 100644
90969--- a/net/ipv4/esp4.c
90970+++ b/net/ipv4/esp4.c
90971@@ -477,7 +477,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
90972 }
90973
90974 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
90975- net_adj) & ~(align - 1)) + (net_adj - 2);
90976+ net_adj) & ~(align - 1)) + net_adj - 2;
90977 }
90978
90979 static void esp4_err(struct sk_buff *skb, u32 info)
90980@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
90981 return;
90982
90983 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
90984- atomic_inc(&flow_cache_genid);
90985+ atomic_inc_unchecked(&flow_cache_genid);
90986 rt_genid_bump(net);
90987
90988 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
90989diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
90990index c7629a2..b62d139 100644
90991--- a/net/ipv4/fib_frontend.c
90992+++ b/net/ipv4/fib_frontend.c
90993@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
90994 #ifdef CONFIG_IP_ROUTE_MULTIPATH
90995 fib_sync_up(dev);
90996 #endif
90997- atomic_inc(&net->ipv4.dev_addr_genid);
90998+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
90999 rt_cache_flush(dev_net(dev));
91000 break;
91001 case NETDEV_DOWN:
91002 fib_del_ifaddr(ifa, NULL);
91003- atomic_inc(&net->ipv4.dev_addr_genid);
91004+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91005 if (ifa->ifa_dev->ifa_list == NULL) {
91006 /* Last address was deleted from this interface.
91007 * Disable IP.
91008@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
91009 #ifdef CONFIG_IP_ROUTE_MULTIPATH
91010 fib_sync_up(dev);
91011 #endif
91012- atomic_inc(&net->ipv4.dev_addr_genid);
91013+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91014 rt_cache_flush(net);
91015 break;
91016 case NETDEV_DOWN:
91017diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
91018index 8f6cb7a..34507f9 100644
91019--- a/net/ipv4/fib_semantics.c
91020+++ b/net/ipv4/fib_semantics.c
91021@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
91022 nh->nh_saddr = inet_select_addr(nh->nh_dev,
91023 nh->nh_gw,
91024 nh->nh_parent->fib_scope);
91025- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
91026+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
91027
91028 return nh->nh_saddr;
91029 }
91030diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
91031index 49616fe..6e8a13d 100644
91032--- a/net/ipv4/fib_trie.c
91033+++ b/net/ipv4/fib_trie.c
91034@@ -71,7 +71,6 @@
91035 #include <linux/init.h>
91036 #include <linux/list.h>
91037 #include <linux/slab.h>
91038-#include <linux/prefetch.h>
91039 #include <linux/export.h>
91040 #include <net/net_namespace.h>
91041 #include <net/ip.h>
91042@@ -1761,10 +1760,8 @@ static struct leaf *leaf_walk_rcu(struct tnode *p, struct rt_trie_node *c)
91043 if (!c)
91044 continue;
91045
91046- if (IS_LEAF(c)) {
91047- prefetch(rcu_dereference_rtnl(p->child[idx]));
91048+ if (IS_LEAF(c))
91049 return (struct leaf *) c;
91050- }
91051
91052 /* Rescan start scanning in new node */
91053 p = (struct tnode *) c;
91054diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
91055index 6acb541..9ea617d 100644
91056--- a/net/ipv4/inet_connection_sock.c
91057+++ b/net/ipv4/inet_connection_sock.c
91058@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
91059 .range = { 32768, 61000 },
91060 };
91061
91062-unsigned long *sysctl_local_reserved_ports;
91063+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
91064 EXPORT_SYMBOL(sysctl_local_reserved_ports);
91065
91066 void inet_get_local_port_range(int *low, int *high)
91067diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
91068index 6af375a..c493c74 100644
91069--- a/net/ipv4/inet_hashtables.c
91070+++ b/net/ipv4/inet_hashtables.c
91071@@ -18,12 +18,15 @@
91072 #include <linux/sched.h>
91073 #include <linux/slab.h>
91074 #include <linux/wait.h>
91075+#include <linux/security.h>
91076
91077 #include <net/inet_connection_sock.h>
91078 #include <net/inet_hashtables.h>
91079 #include <net/secure_seq.h>
91080 #include <net/ip.h>
91081
91082+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
91083+
91084 /*
91085 * Allocate and initialize a new local port bind bucket.
91086 * The bindhash mutex for snum's hash chain must be held here.
91087@@ -554,6 +557,8 @@ ok:
91088 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
91089 spin_unlock(&head->lock);
91090
91091+ gr_update_task_in_ip_table(current, inet_sk(sk));
91092+
91093 if (tw) {
91094 inet_twsk_deschedule(tw, death_row);
91095 while (twrefcnt) {
91096diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
91097index 000e3d2..5472da3 100644
91098--- a/net/ipv4/inetpeer.c
91099+++ b/net/ipv4/inetpeer.c
91100@@ -503,8 +503,8 @@ relookup:
91101 if (p) {
91102 p->daddr = *daddr;
91103 atomic_set(&p->refcnt, 1);
91104- atomic_set(&p->rid, 0);
91105- atomic_set(&p->ip_id_count,
91106+ atomic_set_unchecked(&p->rid, 0);
91107+ atomic_set_unchecked(&p->ip_id_count,
91108 (daddr->family == AF_INET) ?
91109 secure_ip_id(daddr->addr.a4) :
91110 secure_ipv6_id(daddr->addr.a6));
91111diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
91112index b66910a..cfe416e 100644
91113--- a/net/ipv4/ip_fragment.c
91114+++ b/net/ipv4/ip_fragment.c
91115@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
91116 return 0;
91117
91118 start = qp->rid;
91119- end = atomic_inc_return(&peer->rid);
91120+ end = atomic_inc_return_unchecked(&peer->rid);
91121 qp->rid = end;
91122
91123 rc = qp->q.fragments && (end - start) > max;
91124@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
91125
91126 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91127 {
91128- struct ctl_table *table;
91129+ ctl_table_no_const *table = NULL;
91130 struct ctl_table_header *hdr;
91131
91132- table = ip4_frags_ns_ctl_table;
91133 if (!net_eq(net, &init_net)) {
91134- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
91135+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
91136 if (table == NULL)
91137 goto err_alloc;
91138
91139@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91140 /* Don't export sysctls to unprivileged users */
91141 if (net->user_ns != &init_user_ns)
91142 table[0].procname = NULL;
91143- }
91144+ hdr = register_net_sysctl(net, "net/ipv4", table);
91145+ } else
91146+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
91147
91148- hdr = register_net_sysctl(net, "net/ipv4", table);
91149 if (hdr == NULL)
91150 goto err_reg;
91151
91152@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91153 return 0;
91154
91155 err_reg:
91156- if (!net_eq(net, &init_net))
91157- kfree(table);
91158+ kfree(table);
91159 err_alloc:
91160 return -ENOMEM;
91161 }
91162diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
91163index 855004f..9644112 100644
91164--- a/net/ipv4/ip_gre.c
91165+++ b/net/ipv4/ip_gre.c
91166@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
91167 module_param(log_ecn_error, bool, 0644);
91168 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
91169
91170-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
91171+static struct rtnl_link_ops ipgre_link_ops;
91172 static int ipgre_tunnel_init(struct net_device *dev);
91173
91174 static int ipgre_net_id __read_mostly;
91175@@ -572,7 +572,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
91176 if (daddr)
91177 memcpy(&iph->daddr, daddr, 4);
91178 if (iph->daddr)
91179- return t->hlen;
91180+ return t->hlen + sizeof(*iph);
91181
91182 return -(t->hlen + sizeof(*iph));
91183 }
91184@@ -919,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
91185 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
91186 };
91187
91188-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
91189+static struct rtnl_link_ops ipgre_link_ops = {
91190 .kind = "gre",
91191 .maxtype = IFLA_GRE_MAX,
91192 .policy = ipgre_policy,
91193@@ -933,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
91194 .fill_info = ipgre_fill_info,
91195 };
91196
91197-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
91198+static struct rtnl_link_ops ipgre_tap_ops = {
91199 .kind = "gretap",
91200 .maxtype = IFLA_GRE_MAX,
91201 .policy = ipgre_policy,
91202diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
91203index d9c4f11..02b82dbc 100644
91204--- a/net/ipv4/ip_sockglue.c
91205+++ b/net/ipv4/ip_sockglue.c
91206@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
91207 len = min_t(unsigned int, len, opt->optlen);
91208 if (put_user(len, optlen))
91209 return -EFAULT;
91210- if (copy_to_user(optval, opt->__data, len))
91211+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
91212+ copy_to_user(optval, opt->__data, len))
91213 return -EFAULT;
91214 return 0;
91215 }
91216@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
91217 if (sk->sk_type != SOCK_STREAM)
91218 return -ENOPROTOOPT;
91219
91220- msg.msg_control = optval;
91221+ msg.msg_control = (void __force_kernel *)optval;
91222 msg.msg_controllen = len;
91223 msg.msg_flags = flags;
91224
91225diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
91226index 17cc0ff..63856c4 100644
91227--- a/net/ipv4/ip_vti.c
91228+++ b/net/ipv4/ip_vti.c
91229@@ -47,7 +47,7 @@
91230 #define HASH_SIZE 16
91231 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
91232
91233-static struct rtnl_link_ops vti_link_ops __read_mostly;
91234+static struct rtnl_link_ops vti_link_ops;
91235
91236 static int vti_net_id __read_mostly;
91237 struct vti_net {
91238@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
91239 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
91240 };
91241
91242-static struct rtnl_link_ops vti_link_ops __read_mostly = {
91243+static struct rtnl_link_ops vti_link_ops = {
91244 .kind = "vti",
91245 .maxtype = IFLA_VTI_MAX,
91246 .policy = vti_policy,
91247diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
91248index 59cb8c7..a72160c 100644
91249--- a/net/ipv4/ipcomp.c
91250+++ b/net/ipv4/ipcomp.c
91251@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
91252 return;
91253
91254 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
91255- atomic_inc(&flow_cache_genid);
91256+ atomic_inc_unchecked(&flow_cache_genid);
91257 rt_genid_bump(net);
91258
91259 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
91260diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
91261index efa1138..20dbba0 100644
91262--- a/net/ipv4/ipconfig.c
91263+++ b/net/ipv4/ipconfig.c
91264@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
91265
91266 mm_segment_t oldfs = get_fs();
91267 set_fs(get_ds());
91268- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
91269+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
91270 set_fs(oldfs);
91271 return res;
91272 }
91273@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
91274
91275 mm_segment_t oldfs = get_fs();
91276 set_fs(get_ds());
91277- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
91278+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
91279 set_fs(oldfs);
91280 return res;
91281 }
91282@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
91283
91284 mm_segment_t oldfs = get_fs();
91285 set_fs(get_ds());
91286- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
91287+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
91288 set_fs(oldfs);
91289 return res;
91290 }
91291diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
91292index 7cfc456..e726868 100644
91293--- a/net/ipv4/ipip.c
91294+++ b/net/ipv4/ipip.c
91295@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
91296 static int ipip_net_id __read_mostly;
91297
91298 static int ipip_tunnel_init(struct net_device *dev);
91299-static struct rtnl_link_ops ipip_link_ops __read_mostly;
91300+static struct rtnl_link_ops ipip_link_ops;
91301
91302 static int ipip_err(struct sk_buff *skb, u32 info)
91303 {
91304@@ -406,7 +406,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
91305 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
91306 };
91307
91308-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
91309+static struct rtnl_link_ops ipip_link_ops = {
91310 .kind = "ipip",
91311 .maxtype = IFLA_IPTUN_MAX,
91312 .policy = ipip_policy,
91313diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
91314index 85a4f21..1beb1f5 100644
91315--- a/net/ipv4/netfilter/arp_tables.c
91316+++ b/net/ipv4/netfilter/arp_tables.c
91317@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
91318 #endif
91319
91320 static int get_info(struct net *net, void __user *user,
91321- const int *len, int compat)
91322+ int len, int compat)
91323 {
91324 char name[XT_TABLE_MAXNAMELEN];
91325 struct xt_table *t;
91326 int ret;
91327
91328- if (*len != sizeof(struct arpt_getinfo)) {
91329- duprintf("length %u != %Zu\n", *len,
91330+ if (len != sizeof(struct arpt_getinfo)) {
91331+ duprintf("length %u != %Zu\n", len,
91332 sizeof(struct arpt_getinfo));
91333 return -EINVAL;
91334 }
91335@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
91336 info.size = private->size;
91337 strcpy(info.name, name);
91338
91339- if (copy_to_user(user, &info, *len) != 0)
91340+ if (copy_to_user(user, &info, len) != 0)
91341 ret = -EFAULT;
91342 else
91343 ret = 0;
91344@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
91345
91346 switch (cmd) {
91347 case ARPT_SO_GET_INFO:
91348- ret = get_info(sock_net(sk), user, len, 1);
91349+ ret = get_info(sock_net(sk), user, *len, 1);
91350 break;
91351 case ARPT_SO_GET_ENTRIES:
91352 ret = compat_get_entries(sock_net(sk), user, len);
91353@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
91354
91355 switch (cmd) {
91356 case ARPT_SO_GET_INFO:
91357- ret = get_info(sock_net(sk), user, len, 0);
91358+ ret = get_info(sock_net(sk), user, *len, 0);
91359 break;
91360
91361 case ARPT_SO_GET_ENTRIES:
91362diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
91363index d23118d..6ad7277 100644
91364--- a/net/ipv4/netfilter/ip_tables.c
91365+++ b/net/ipv4/netfilter/ip_tables.c
91366@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
91367 #endif
91368
91369 static int get_info(struct net *net, void __user *user,
91370- const int *len, int compat)
91371+ int len, int compat)
91372 {
91373 char name[XT_TABLE_MAXNAMELEN];
91374 struct xt_table *t;
91375 int ret;
91376
91377- if (*len != sizeof(struct ipt_getinfo)) {
91378- duprintf("length %u != %zu\n", *len,
91379+ if (len != sizeof(struct ipt_getinfo)) {
91380+ duprintf("length %u != %zu\n", len,
91381 sizeof(struct ipt_getinfo));
91382 return -EINVAL;
91383 }
91384@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
91385 info.size = private->size;
91386 strcpy(info.name, name);
91387
91388- if (copy_to_user(user, &info, *len) != 0)
91389+ if (copy_to_user(user, &info, len) != 0)
91390 ret = -EFAULT;
91391 else
91392 ret = 0;
91393@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91394
91395 switch (cmd) {
91396 case IPT_SO_GET_INFO:
91397- ret = get_info(sock_net(sk), user, len, 1);
91398+ ret = get_info(sock_net(sk), user, *len, 1);
91399 break;
91400 case IPT_SO_GET_ENTRIES:
91401 ret = compat_get_entries(sock_net(sk), user, len);
91402@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91403
91404 switch (cmd) {
91405 case IPT_SO_GET_INFO:
91406- ret = get_info(sock_net(sk), user, len, 0);
91407+ ret = get_info(sock_net(sk), user, *len, 0);
91408 break;
91409
91410 case IPT_SO_GET_ENTRIES:
91411diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
91412index 7d93d62..cbbf2a3 100644
91413--- a/net/ipv4/ping.c
91414+++ b/net/ipv4/ping.c
91415@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
91416 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
91417 0, sock_i_ino(sp),
91418 atomic_read(&sp->sk_refcnt), sp,
91419- atomic_read(&sp->sk_drops), len);
91420+ atomic_read_unchecked(&sp->sk_drops), len);
91421 }
91422
91423 static int ping_seq_show(struct seq_file *seq, void *v)
91424diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
91425index dd44e0a..06dcca4 100644
91426--- a/net/ipv4/raw.c
91427+++ b/net/ipv4/raw.c
91428@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
91429 int raw_rcv(struct sock *sk, struct sk_buff *skb)
91430 {
91431 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
91432- atomic_inc(&sk->sk_drops);
91433+ atomic_inc_unchecked(&sk->sk_drops);
91434 kfree_skb(skb);
91435 return NET_RX_DROP;
91436 }
91437@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
91438
91439 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
91440 {
91441+ struct icmp_filter filter;
91442+
91443 if (optlen > sizeof(struct icmp_filter))
91444 optlen = sizeof(struct icmp_filter);
91445- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
91446+ if (copy_from_user(&filter, optval, optlen))
91447 return -EFAULT;
91448+ raw_sk(sk)->filter = filter;
91449 return 0;
91450 }
91451
91452 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
91453 {
91454 int len, ret = -EFAULT;
91455+ struct icmp_filter filter;
91456
91457 if (get_user(len, optlen))
91458 goto out;
91459@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
91460 if (len > sizeof(struct icmp_filter))
91461 len = sizeof(struct icmp_filter);
91462 ret = -EFAULT;
91463- if (put_user(len, optlen) ||
91464- copy_to_user(optval, &raw_sk(sk)->filter, len))
91465+ filter = raw_sk(sk)->filter;
91466+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
91467 goto out;
91468 ret = 0;
91469 out: return ret;
91470@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
91471 0, 0L, 0,
91472 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
91473 0, sock_i_ino(sp),
91474- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
91475+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
91476 }
91477
91478 static int raw_seq_show(struct seq_file *seq, void *v)
91479diff --git a/net/ipv4/route.c b/net/ipv4/route.c
91480index d35bbf0..faa3ab8 100644
91481--- a/net/ipv4/route.c
91482+++ b/net/ipv4/route.c
91483@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
91484 .maxlen = sizeof(int),
91485 .mode = 0200,
91486 .proc_handler = ipv4_sysctl_rtcache_flush,
91487+ .extra1 = &init_net,
91488 },
91489 { },
91490 };
91491
91492 static __net_init int sysctl_route_net_init(struct net *net)
91493 {
91494- struct ctl_table *tbl;
91495+ ctl_table_no_const *tbl = NULL;
91496
91497- tbl = ipv4_route_flush_table;
91498 if (!net_eq(net, &init_net)) {
91499- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
91500+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
91501 if (tbl == NULL)
91502 goto err_dup;
91503
91504 /* Don't export sysctls to unprivileged users */
91505 if (net->user_ns != &init_user_ns)
91506 tbl[0].procname = NULL;
91507- }
91508- tbl[0].extra1 = net;
91509+ tbl[0].extra1 = net;
91510+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
91511+ } else
91512+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
91513
91514- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
91515 if (net->ipv4.route_hdr == NULL)
91516 goto err_reg;
91517 return 0;
91518
91519 err_reg:
91520- if (tbl != ipv4_route_flush_table)
91521- kfree(tbl);
91522+ kfree(tbl);
91523 err_dup:
91524 return -ENOMEM;
91525 }
91526@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
91527
91528 static __net_init int rt_genid_init(struct net *net)
91529 {
91530- atomic_set(&net->rt_genid, 0);
91531+ atomic_set_unchecked(&net->rt_genid, 0);
91532 get_random_bytes(&net->ipv4.dev_addr_genid,
91533 sizeof(net->ipv4.dev_addr_genid));
91534 return 0;
91535diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
91536index 3f25e75..3ae0f4d 100644
91537--- a/net/ipv4/sysctl_net_ipv4.c
91538+++ b/net/ipv4/sysctl_net_ipv4.c
91539@@ -57,7 +57,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
91540 {
91541 int ret;
91542 int range[2];
91543- ctl_table tmp = {
91544+ ctl_table_no_const tmp = {
91545 .data = &range,
91546 .maxlen = sizeof(range),
91547 .mode = table->mode,
91548@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
91549 int ret;
91550 gid_t urange[2];
91551 kgid_t low, high;
91552- ctl_table tmp = {
91553+ ctl_table_no_const tmp = {
91554 .data = &urange,
91555 .maxlen = sizeof(urange),
91556 .mode = table->mode,
91557@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
91558 void __user *buffer, size_t *lenp, loff_t *ppos)
91559 {
91560 char val[TCP_CA_NAME_MAX];
91561- ctl_table tbl = {
91562+ ctl_table_no_const tbl = {
91563 .data = val,
91564 .maxlen = TCP_CA_NAME_MAX,
91565 };
91566@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
91567 void __user *buffer, size_t *lenp,
91568 loff_t *ppos)
91569 {
91570- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
91571+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
91572 int ret;
91573
91574 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
91575@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
91576 void __user *buffer, size_t *lenp,
91577 loff_t *ppos)
91578 {
91579- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
91580+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
91581 int ret;
91582
91583 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
91584@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
91585 struct mem_cgroup *memcg;
91586 #endif
91587
91588- ctl_table tmp = {
91589+ ctl_table_no_const tmp = {
91590 .data = &vec,
91591 .maxlen = sizeof(vec),
91592 .mode = ctl->mode,
91593 };
91594
91595 if (!write) {
91596- ctl->data = &net->ipv4.sysctl_tcp_mem;
91597- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
91598+ ctl_table_no_const tcp_mem = *ctl;
91599+
91600+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
91601+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
91602 }
91603
91604 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
91605@@ -238,7 +240,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
91606 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
91607 size_t *lenp, loff_t *ppos)
91608 {
91609- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
91610+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
91611 struct tcp_fastopen_context *ctxt;
91612 int ret;
91613 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
91614@@ -481,7 +483,7 @@ static struct ctl_table ipv4_table[] = {
91615 },
91616 {
91617 .procname = "ip_local_reserved_ports",
91618- .data = NULL, /* initialized in sysctl_ipv4_init */
91619+ .data = sysctl_local_reserved_ports,
91620 .maxlen = 65536,
91621 .mode = 0644,
91622 .proc_handler = proc_do_large_bitmap,
91623@@ -846,11 +848,10 @@ static struct ctl_table ipv4_net_table[] = {
91624
91625 static __net_init int ipv4_sysctl_init_net(struct net *net)
91626 {
91627- struct ctl_table *table;
91628+ ctl_table_no_const *table = NULL;
91629
91630- table = ipv4_net_table;
91631 if (!net_eq(net, &init_net)) {
91632- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
91633+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
91634 if (table == NULL)
91635 goto err_alloc;
91636
91637@@ -885,15 +886,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
91638
91639 tcp_init_mem(net);
91640
91641- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
91642+ if (!net_eq(net, &init_net))
91643+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
91644+ else
91645+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
91646 if (net->ipv4.ipv4_hdr == NULL)
91647 goto err_reg;
91648
91649 return 0;
91650
91651 err_reg:
91652- if (!net_eq(net, &init_net))
91653- kfree(table);
91654+ kfree(table);
91655 err_alloc:
91656 return -ENOMEM;
91657 }
91658@@ -915,16 +918,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
91659 static __init int sysctl_ipv4_init(void)
91660 {
91661 struct ctl_table_header *hdr;
91662- struct ctl_table *i;
91663-
91664- for (i = ipv4_table; i->procname; i++) {
91665- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
91666- i->data = sysctl_local_reserved_ports;
91667- break;
91668- }
91669- }
91670- if (!i->procname)
91671- return -EINVAL;
91672
91673 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
91674 if (hdr == NULL)
91675diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
91676index 9c62257..651cc27 100644
91677--- a/net/ipv4/tcp_input.c
91678+++ b/net/ipv4/tcp_input.c
91679@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
91680 * simplifies code)
91681 */
91682 static void
91683-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
91684+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
91685 struct sk_buff *head, struct sk_buff *tail,
91686 u32 start, u32 end)
91687 {
91688@@ -5522,6 +5522,7 @@ discard:
91689 tcp_paws_reject(&tp->rx_opt, 0))
91690 goto discard_and_undo;
91691
91692+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
91693 if (th->syn) {
91694 /* We see SYN without ACK. It is attempt of
91695 * simultaneous connect with crossed SYNs.
91696@@ -5572,6 +5573,7 @@ discard:
91697 goto discard;
91698 #endif
91699 }
91700+#endif
91701 /* "fifth, if neither of the SYN or RST bits is set then
91702 * drop the segment and return."
91703 */
91704@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
91705 goto discard;
91706
91707 if (th->syn) {
91708- if (th->fin)
91709+ if (th->fin || th->urg || th->psh)
91710 goto discard;
91711 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
91712 return 1;
91713diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
91714index 7999fc5..c812f42 100644
91715--- a/net/ipv4/tcp_ipv4.c
91716+++ b/net/ipv4/tcp_ipv4.c
91717@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
91718 EXPORT_SYMBOL(sysctl_tcp_low_latency);
91719
91720
91721+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91722+extern int grsec_enable_blackhole;
91723+#endif
91724+
91725 #ifdef CONFIG_TCP_MD5SIG
91726 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
91727 __be32 daddr, __be32 saddr, const struct tcphdr *th);
91728@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
91729 return 0;
91730
91731 reset:
91732+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91733+ if (!grsec_enable_blackhole)
91734+#endif
91735 tcp_v4_send_reset(rsk, skb);
91736 discard:
91737 kfree_skb(skb);
91738@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
91739 TCP_SKB_CB(skb)->sacked = 0;
91740
91741 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
91742- if (!sk)
91743+ if (!sk) {
91744+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91745+ ret = 1;
91746+#endif
91747 goto no_tcp_socket;
91748-
91749+ }
91750 process:
91751- if (sk->sk_state == TCP_TIME_WAIT)
91752+ if (sk->sk_state == TCP_TIME_WAIT) {
91753+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91754+ ret = 2;
91755+#endif
91756 goto do_time_wait;
91757+ }
91758
91759 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
91760 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
91761@@ -2058,6 +2072,10 @@ csum_error:
91762 bad_packet:
91763 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
91764 } else {
91765+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91766+ if (!grsec_enable_blackhole || (ret == 1 &&
91767+ (skb->dev->flags & IFF_LOOPBACK)))
91768+#endif
91769 tcp_v4_send_reset(NULL, skb);
91770 }
91771
91772diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
91773index 0f01788..d52a859 100644
91774--- a/net/ipv4/tcp_minisocks.c
91775+++ b/net/ipv4/tcp_minisocks.c
91776@@ -27,6 +27,10 @@
91777 #include <net/inet_common.h>
91778 #include <net/xfrm.h>
91779
91780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91781+extern int grsec_enable_blackhole;
91782+#endif
91783+
91784 int sysctl_tcp_syncookies __read_mostly = 1;
91785 EXPORT_SYMBOL(sysctl_tcp_syncookies);
91786
91787@@ -717,7 +721,10 @@ embryonic_reset:
91788 * avoid becoming vulnerable to outside attack aiming at
91789 * resetting legit local connections.
91790 */
91791- req->rsk_ops->send_reset(sk, skb);
91792+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91793+ if (!grsec_enable_blackhole)
91794+#endif
91795+ req->rsk_ops->send_reset(sk, skb);
91796 } else if (fastopen) { /* received a valid RST pkt */
91797 reqsk_fastopen_remove(sk, req, true);
91798 tcp_reset(sk);
91799diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
91800index d4943f6..e7a74a5 100644
91801--- a/net/ipv4/tcp_probe.c
91802+++ b/net/ipv4/tcp_probe.c
91803@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
91804 if (cnt + width >= len)
91805 break;
91806
91807- if (copy_to_user(buf + cnt, tbuf, width))
91808+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
91809 return -EFAULT;
91810 cnt += width;
91811 }
91812diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
91813index 4b85e6f..22f9ac9 100644
91814--- a/net/ipv4/tcp_timer.c
91815+++ b/net/ipv4/tcp_timer.c
91816@@ -22,6 +22,10 @@
91817 #include <linux/gfp.h>
91818 #include <net/tcp.h>
91819
91820+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91821+extern int grsec_lastack_retries;
91822+#endif
91823+
91824 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
91825 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
91826 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
91827@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
91828 }
91829 }
91830
91831+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91832+ if ((sk->sk_state == TCP_LAST_ACK) &&
91833+ (grsec_lastack_retries > 0) &&
91834+ (grsec_lastack_retries < retry_until))
91835+ retry_until = grsec_lastack_retries;
91836+#endif
91837+
91838 if (retransmits_timed_out(sk, retry_until,
91839 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
91840 /* Has it gone just too far? */
91841diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
91842index 93b731d..5a2dd92 100644
91843--- a/net/ipv4/udp.c
91844+++ b/net/ipv4/udp.c
91845@@ -87,6 +87,7 @@
91846 #include <linux/types.h>
91847 #include <linux/fcntl.h>
91848 #include <linux/module.h>
91849+#include <linux/security.h>
91850 #include <linux/socket.h>
91851 #include <linux/sockios.h>
91852 #include <linux/igmp.h>
91853@@ -111,6 +112,10 @@
91854 #include <trace/events/skb.h>
91855 #include "udp_impl.h"
91856
91857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91858+extern int grsec_enable_blackhole;
91859+#endif
91860+
91861 struct udp_table udp_table __read_mostly;
91862 EXPORT_SYMBOL(udp_table);
91863
91864@@ -594,6 +599,9 @@ found:
91865 return s;
91866 }
91867
91868+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
91869+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
91870+
91871 /*
91872 * This routine is called by the ICMP module when it gets some
91873 * sort of error condition. If err < 0 then the socket should
91874@@ -890,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
91875 dport = usin->sin_port;
91876 if (dport == 0)
91877 return -EINVAL;
91878+
91879+ err = gr_search_udp_sendmsg(sk, usin);
91880+ if (err)
91881+ return err;
91882 } else {
91883 if (sk->sk_state != TCP_ESTABLISHED)
91884 return -EDESTADDRREQ;
91885+
91886+ err = gr_search_udp_sendmsg(sk, NULL);
91887+ if (err)
91888+ return err;
91889+
91890 daddr = inet->inet_daddr;
91891 dport = inet->inet_dport;
91892 /* Open fast path for connected socket.
91893@@ -1136,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
91894 IS_UDPLITE(sk));
91895 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
91896 IS_UDPLITE(sk));
91897- atomic_inc(&sk->sk_drops);
91898+ atomic_inc_unchecked(&sk->sk_drops);
91899 __skb_unlink(skb, rcvq);
91900 __skb_queue_tail(&list_kill, skb);
91901 }
91902@@ -1222,6 +1239,10 @@ try_again:
91903 if (!skb)
91904 goto out;
91905
91906+ err = gr_search_udp_recvmsg(sk, skb);
91907+ if (err)
91908+ goto out_free;
91909+
91910 ulen = skb->len - sizeof(struct udphdr);
91911 copied = len;
91912 if (copied > ulen)
91913@@ -1255,7 +1276,7 @@ try_again:
91914 if (unlikely(err)) {
91915 trace_kfree_skb(skb, udp_recvmsg);
91916 if (!peeked) {
91917- atomic_inc(&sk->sk_drops);
91918+ atomic_inc_unchecked(&sk->sk_drops);
91919 UDP_INC_STATS_USER(sock_net(sk),
91920 UDP_MIB_INERRORS, is_udplite);
91921 }
91922@@ -1542,7 +1563,7 @@ csum_error:
91923 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
91924 drop:
91925 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
91926- atomic_inc(&sk->sk_drops);
91927+ atomic_inc_unchecked(&sk->sk_drops);
91928 kfree_skb(skb);
91929 return -1;
91930 }
91931@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
91932 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
91933
91934 if (!skb1) {
91935- atomic_inc(&sk->sk_drops);
91936+ atomic_inc_unchecked(&sk->sk_drops);
91937 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
91938 IS_UDPLITE(sk));
91939 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
91940@@ -1730,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
91941 goto csum_error;
91942
91943 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
91944+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
91945+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
91946+#endif
91947 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
91948
91949 /*
91950@@ -2160,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
91951 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
91952 0, sock_i_ino(sp),
91953 atomic_read(&sp->sk_refcnt), sp,
91954- atomic_read(&sp->sk_drops), len);
91955+ atomic_read_unchecked(&sp->sk_drops), len);
91956 }
91957
91958 int udp4_seq_show(struct seq_file *seq, void *v)
91959diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
91960index 9a459be..086b866 100644
91961--- a/net/ipv4/xfrm4_policy.c
91962+++ b/net/ipv4/xfrm4_policy.c
91963@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
91964
91965 static int __net_init xfrm4_net_init(struct net *net)
91966 {
91967- struct ctl_table *table;
91968+ ctl_table_no_const *table = NULL;
91969 struct ctl_table_header *hdr;
91970
91971- table = xfrm4_policy_table;
91972 if (!net_eq(net, &init_net)) {
91973- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
91974+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
91975 if (!table)
91976 goto err_alloc;
91977
91978 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
91979- }
91980-
91981- hdr = register_net_sysctl(net, "net/ipv4", table);
91982+ hdr = register_net_sysctl(net, "net/ipv4", table);
91983+ } else
91984+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
91985 if (!hdr)
91986 goto err_reg;
91987
91988@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
91989 return 0;
91990
91991 err_reg:
91992- if (!net_eq(net, &init_net))
91993- kfree(table);
91994+ kfree(table);
91995 err_alloc:
91996 return -ENOMEM;
91997 }
91998diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
91999index fb8c94c..fb18024 100644
92000--- a/net/ipv6/addrconf.c
92001+++ b/net/ipv6/addrconf.c
92002@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
92003 idx = 0;
92004 head = &net->dev_index_head[h];
92005 rcu_read_lock();
92006- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
92007+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
92008 net->dev_base_seq;
92009 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92010 if (idx < s_idx)
92011@@ -2380,7 +2380,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
92012 p.iph.ihl = 5;
92013 p.iph.protocol = IPPROTO_IPV6;
92014 p.iph.ttl = 64;
92015- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
92016+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
92017
92018 if (ops->ndo_do_ioctl) {
92019 mm_segment_t oldfs = get_fs();
92020@@ -4002,7 +4002,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
92021 s_ip_idx = ip_idx = cb->args[2];
92022
92023 rcu_read_lock();
92024- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
92025+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
92026 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
92027 idx = 0;
92028 head = &net->dev_index_head[h];
92029@@ -4587,7 +4587,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
92030 dst_free(&ifp->rt->dst);
92031 break;
92032 }
92033- atomic_inc(&net->ipv6.dev_addr_genid);
92034+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
92035 }
92036
92037 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
92038@@ -4607,7 +4607,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
92039 int *valp = ctl->data;
92040 int val = *valp;
92041 loff_t pos = *ppos;
92042- ctl_table lctl;
92043+ ctl_table_no_const lctl;
92044 int ret;
92045
92046 /*
92047@@ -4689,7 +4689,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
92048 int *valp = ctl->data;
92049 int val = *valp;
92050 loff_t pos = *ppos;
92051- ctl_table lctl;
92052+ ctl_table_no_const lctl;
92053 int ret;
92054
92055 /*
92056diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
92057index 40ffd72..aeac0dc 100644
92058--- a/net/ipv6/esp6.c
92059+++ b/net/ipv6/esp6.c
92060@@ -425,7 +425,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu)
92061 net_adj = 0;
92062
92063 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
92064- net_adj) & ~(align - 1)) + (net_adj - 2);
92065+ net_adj) & ~(align - 1)) + net_adj - 2;
92066 }
92067
92068 static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
92069diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
92070index b4ff0a4..db9b764 100644
92071--- a/net/ipv6/icmp.c
92072+++ b/net/ipv6/icmp.c
92073@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
92074
92075 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
92076 {
92077- struct ctl_table *table;
92078+ ctl_table_no_const *table;
92079
92080 table = kmemdup(ipv6_icmp_table_template,
92081 sizeof(ipv6_icmp_table_template),
92082diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
92083index ecd6073..58162ae 100644
92084--- a/net/ipv6/ip6_gre.c
92085+++ b/net/ipv6/ip6_gre.c
92086@@ -74,7 +74,7 @@ struct ip6gre_net {
92087 struct net_device *fb_tunnel_dev;
92088 };
92089
92090-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
92091+static struct rtnl_link_ops ip6gre_link_ops;
92092 static int ip6gre_tunnel_init(struct net_device *dev);
92093 static void ip6gre_tunnel_setup(struct net_device *dev);
92094 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
92095@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
92096 }
92097
92098
92099-static struct inet6_protocol ip6gre_protocol __read_mostly = {
92100+static struct inet6_protocol ip6gre_protocol = {
92101 .handler = ip6gre_rcv,
92102 .err_handler = ip6gre_err,
92103 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
92104@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
92105 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
92106 };
92107
92108-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
92109+static struct rtnl_link_ops ip6gre_link_ops = {
92110 .kind = "ip6gre",
92111 .maxtype = IFLA_GRE_MAX,
92112 .policy = ip6gre_policy,
92113@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
92114 .fill_info = ip6gre_fill_info,
92115 };
92116
92117-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
92118+static struct rtnl_link_ops ip6gre_tap_ops = {
92119 .kind = "ip6gretap",
92120 .maxtype = IFLA_GRE_MAX,
92121 .policy = ip6gre_policy,
92122diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
92123index 1e55866..b398dab 100644
92124--- a/net/ipv6/ip6_tunnel.c
92125+++ b/net/ipv6/ip6_tunnel.c
92126@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
92127
92128 static int ip6_tnl_dev_init(struct net_device *dev);
92129 static void ip6_tnl_dev_setup(struct net_device *dev);
92130-static struct rtnl_link_ops ip6_link_ops __read_mostly;
92131+static struct rtnl_link_ops ip6_link_ops;
92132
92133 static int ip6_tnl_net_id __read_mostly;
92134 struct ip6_tnl_net {
92135@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
92136 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
92137 };
92138
92139-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
92140+static struct rtnl_link_ops ip6_link_ops = {
92141 .kind = "ip6tnl",
92142 .maxtype = IFLA_IPTUN_MAX,
92143 .policy = ip6_tnl_policy,
92144diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
92145index d1e2e8e..51c19ae 100644
92146--- a/net/ipv6/ipv6_sockglue.c
92147+++ b/net/ipv6/ipv6_sockglue.c
92148@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
92149 if (sk->sk_type != SOCK_STREAM)
92150 return -ENOPROTOOPT;
92151
92152- msg.msg_control = optval;
92153+ msg.msg_control = (void __force_kernel *)optval;
92154 msg.msg_controllen = len;
92155 msg.msg_flags = flags;
92156
92157diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
92158index 44400c2..8e11f52 100644
92159--- a/net/ipv6/netfilter/ip6_tables.c
92160+++ b/net/ipv6/netfilter/ip6_tables.c
92161@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
92162 #endif
92163
92164 static int get_info(struct net *net, void __user *user,
92165- const int *len, int compat)
92166+ int len, int compat)
92167 {
92168 char name[XT_TABLE_MAXNAMELEN];
92169 struct xt_table *t;
92170 int ret;
92171
92172- if (*len != sizeof(struct ip6t_getinfo)) {
92173- duprintf("length %u != %zu\n", *len,
92174+ if (len != sizeof(struct ip6t_getinfo)) {
92175+ duprintf("length %u != %zu\n", len,
92176 sizeof(struct ip6t_getinfo));
92177 return -EINVAL;
92178 }
92179@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
92180 info.size = private->size;
92181 strcpy(info.name, name);
92182
92183- if (copy_to_user(user, &info, *len) != 0)
92184+ if (copy_to_user(user, &info, len) != 0)
92185 ret = -EFAULT;
92186 else
92187 ret = 0;
92188@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92189
92190 switch (cmd) {
92191 case IP6T_SO_GET_INFO:
92192- ret = get_info(sock_net(sk), user, len, 1);
92193+ ret = get_info(sock_net(sk), user, *len, 1);
92194 break;
92195 case IP6T_SO_GET_ENTRIES:
92196 ret = compat_get_entries(sock_net(sk), user, len);
92197@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92198
92199 switch (cmd) {
92200 case IP6T_SO_GET_INFO:
92201- ret = get_info(sock_net(sk), user, len, 0);
92202+ ret = get_info(sock_net(sk), user, *len, 0);
92203 break;
92204
92205 case IP6T_SO_GET_ENTRIES:
92206diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
92207index dffdc1a..ccc6678 100644
92208--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
92209+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
92210@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
92211
92212 static int nf_ct_frag6_sysctl_register(struct net *net)
92213 {
92214- struct ctl_table *table;
92215+ ctl_table_no_const *table = NULL;
92216 struct ctl_table_header *hdr;
92217
92218- table = nf_ct_frag6_sysctl_table;
92219 if (!net_eq(net, &init_net)) {
92220- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
92221+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
92222 GFP_KERNEL);
92223 if (table == NULL)
92224 goto err_alloc;
92225@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
92226 table[0].data = &net->nf_frag.frags.timeout;
92227 table[1].data = &net->nf_frag.frags.low_thresh;
92228 table[2].data = &net->nf_frag.frags.high_thresh;
92229- }
92230-
92231- hdr = register_net_sysctl(net, "net/netfilter", table);
92232+ hdr = register_net_sysctl(net, "net/netfilter", table);
92233+ } else
92234+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
92235 if (hdr == NULL)
92236 goto err_reg;
92237
92238@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
92239 return 0;
92240
92241 err_reg:
92242- if (!net_eq(net, &init_net))
92243- kfree(table);
92244+ kfree(table);
92245 err_alloc:
92246 return -ENOMEM;
92247 }
92248diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
92249index eedff8c..6e13a47 100644
92250--- a/net/ipv6/raw.c
92251+++ b/net/ipv6/raw.c
92252@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
92253 {
92254 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
92255 skb_checksum_complete(skb)) {
92256- atomic_inc(&sk->sk_drops);
92257+ atomic_inc_unchecked(&sk->sk_drops);
92258 kfree_skb(skb);
92259 return NET_RX_DROP;
92260 }
92261@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
92262 struct raw6_sock *rp = raw6_sk(sk);
92263
92264 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
92265- atomic_inc(&sk->sk_drops);
92266+ atomic_inc_unchecked(&sk->sk_drops);
92267 kfree_skb(skb);
92268 return NET_RX_DROP;
92269 }
92270@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
92271
92272 if (inet->hdrincl) {
92273 if (skb_checksum_complete(skb)) {
92274- atomic_inc(&sk->sk_drops);
92275+ atomic_inc_unchecked(&sk->sk_drops);
92276 kfree_skb(skb);
92277 return NET_RX_DROP;
92278 }
92279@@ -602,7 +602,7 @@ out:
92280 return err;
92281 }
92282
92283-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
92284+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
92285 struct flowi6 *fl6, struct dst_entry **dstp,
92286 unsigned int flags)
92287 {
92288@@ -914,12 +914,15 @@ do_confirm:
92289 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
92290 char __user *optval, int optlen)
92291 {
92292+ struct icmp6_filter filter;
92293+
92294 switch (optname) {
92295 case ICMPV6_FILTER:
92296 if (optlen > sizeof(struct icmp6_filter))
92297 optlen = sizeof(struct icmp6_filter);
92298- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
92299+ if (copy_from_user(&filter, optval, optlen))
92300 return -EFAULT;
92301+ raw6_sk(sk)->filter = filter;
92302 return 0;
92303 default:
92304 return -ENOPROTOOPT;
92305@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
92306 char __user *optval, int __user *optlen)
92307 {
92308 int len;
92309+ struct icmp6_filter filter;
92310
92311 switch (optname) {
92312 case ICMPV6_FILTER:
92313@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
92314 len = sizeof(struct icmp6_filter);
92315 if (put_user(len, optlen))
92316 return -EFAULT;
92317- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
92318+ filter = raw6_sk(sk)->filter;
92319+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
92320 return -EFAULT;
92321 return 0;
92322 default:
92323@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92324 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92325 0,
92326 sock_i_ino(sp),
92327- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92328+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92329 }
92330
92331 static int raw6_seq_show(struct seq_file *seq, void *v)
92332diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
92333index 790d9f4..68ae078 100644
92334--- a/net/ipv6/reassembly.c
92335+++ b/net/ipv6/reassembly.c
92336@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
92337
92338 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
92339 {
92340- struct ctl_table *table;
92341+ ctl_table_no_const *table = NULL;
92342 struct ctl_table_header *hdr;
92343
92344- table = ip6_frags_ns_ctl_table;
92345 if (!net_eq(net, &init_net)) {
92346- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
92347+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
92348 if (table == NULL)
92349 goto err_alloc;
92350
92351@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
92352 /* Don't export sysctls to unprivileged users */
92353 if (net->user_ns != &init_user_ns)
92354 table[0].procname = NULL;
92355- }
92356+ hdr = register_net_sysctl(net, "net/ipv6", table);
92357+ } else
92358+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
92359
92360- hdr = register_net_sysctl(net, "net/ipv6", table);
92361 if (hdr == NULL)
92362 goto err_reg;
92363
92364@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
92365 return 0;
92366
92367 err_reg:
92368- if (!net_eq(net, &init_net))
92369- kfree(table);
92370+ kfree(table);
92371 err_alloc:
92372 return -ENOMEM;
92373 }
92374diff --git a/net/ipv6/route.c b/net/ipv6/route.c
92375index bacce6c..9d1741a 100644
92376--- a/net/ipv6/route.c
92377+++ b/net/ipv6/route.c
92378@@ -2903,7 +2903,7 @@ ctl_table ipv6_route_table_template[] = {
92379
92380 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
92381 {
92382- struct ctl_table *table;
92383+ ctl_table_no_const *table;
92384
92385 table = kmemdup(ipv6_route_table_template,
92386 sizeof(ipv6_route_table_template),
92387diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
92388index 60df36d..f3ab7c8 100644
92389--- a/net/ipv6/sit.c
92390+++ b/net/ipv6/sit.c
92391@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
92392 static void ipip6_dev_free(struct net_device *dev);
92393 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
92394 __be32 *v4dst);
92395-static struct rtnl_link_ops sit_link_ops __read_mostly;
92396+static struct rtnl_link_ops sit_link_ops;
92397
92398 static int sit_net_id __read_mostly;
92399 struct sit_net {
92400@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
92401 #endif
92402 };
92403
92404-static struct rtnl_link_ops sit_link_ops __read_mostly = {
92405+static struct rtnl_link_ops sit_link_ops = {
92406 .kind = "sit",
92407 .maxtype = IFLA_IPTUN_MAX,
92408 .policy = ipip6_policy,
92409diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
92410index e85c48b..b8268d3 100644
92411--- a/net/ipv6/sysctl_net_ipv6.c
92412+++ b/net/ipv6/sysctl_net_ipv6.c
92413@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
92414
92415 static int __net_init ipv6_sysctl_net_init(struct net *net)
92416 {
92417- struct ctl_table *ipv6_table;
92418+ ctl_table_no_const *ipv6_table;
92419 struct ctl_table *ipv6_route_table;
92420 struct ctl_table *ipv6_icmp_table;
92421 int err;
92422diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
92423index 0a17ed9..2526cc3 100644
92424--- a/net/ipv6/tcp_ipv6.c
92425+++ b/net/ipv6/tcp_ipv6.c
92426@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
92427 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
92428 }
92429
92430+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92431+extern int grsec_enable_blackhole;
92432+#endif
92433+
92434 static void tcp_v6_hash(struct sock *sk)
92435 {
92436 if (sk->sk_state != TCP_CLOSE) {
92437@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
92438 return 0;
92439
92440 reset:
92441+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92442+ if (!grsec_enable_blackhole)
92443+#endif
92444 tcp_v6_send_reset(sk, skb);
92445 discard:
92446 if (opt_skb)
92447@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
92448 TCP_SKB_CB(skb)->sacked = 0;
92449
92450 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92451- if (!sk)
92452+ if (!sk) {
92453+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92454+ ret = 1;
92455+#endif
92456 goto no_tcp_socket;
92457+ }
92458
92459 process:
92460- if (sk->sk_state == TCP_TIME_WAIT)
92461+ if (sk->sk_state == TCP_TIME_WAIT) {
92462+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92463+ ret = 2;
92464+#endif
92465 goto do_time_wait;
92466+ }
92467
92468 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
92469 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92470@@ -1536,6 +1551,10 @@ csum_error:
92471 bad_packet:
92472 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92473 } else {
92474+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92475+ if (!grsec_enable_blackhole || (ret == 1 &&
92476+ (skb->dev->flags & IFF_LOOPBACK)))
92477+#endif
92478 tcp_v6_send_reset(NULL, skb);
92479 }
92480
92481diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
92482index e7b28f9..d09c290 100644
92483--- a/net/ipv6/udp.c
92484+++ b/net/ipv6/udp.c
92485@@ -52,6 +52,10 @@
92486 #include <trace/events/skb.h>
92487 #include "udp_impl.h"
92488
92489+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92490+extern int grsec_enable_blackhole;
92491+#endif
92492+
92493 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
92494 {
92495 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
92496@@ -419,7 +423,7 @@ try_again:
92497 if (unlikely(err)) {
92498 trace_kfree_skb(skb, udpv6_recvmsg);
92499 if (!peeked) {
92500- atomic_inc(&sk->sk_drops);
92501+ atomic_inc_unchecked(&sk->sk_drops);
92502 if (is_udp4)
92503 UDP_INC_STATS_USER(sock_net(sk),
92504 UDP_MIB_INERRORS,
92505@@ -665,7 +669,7 @@ csum_error:
92506 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
92507 drop:
92508 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
92509- atomic_inc(&sk->sk_drops);
92510+ atomic_inc_unchecked(&sk->sk_drops);
92511 kfree_skb(skb);
92512 return -1;
92513 }
92514@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
92515 if (likely(skb1 == NULL))
92516 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
92517 if (!skb1) {
92518- atomic_inc(&sk->sk_drops);
92519+ atomic_inc_unchecked(&sk->sk_drops);
92520 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
92521 IS_UDPLITE(sk));
92522 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92523@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
92524 goto csum_error;
92525
92526 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
92527+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92528+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
92529+#endif
92530 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
92531
92532 kfree_skb(skb);
92533@@ -1392,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
92534 0,
92535 sock_i_ino(sp),
92536 atomic_read(&sp->sk_refcnt), sp,
92537- atomic_read(&sp->sk_drops));
92538+ atomic_read_unchecked(&sp->sk_drops));
92539 }
92540
92541 int udp6_seq_show(struct seq_file *seq, void *v)
92542diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
92543index 23ed03d..465a71d 100644
92544--- a/net/ipv6/xfrm6_policy.c
92545+++ b/net/ipv6/xfrm6_policy.c
92546@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
92547
92548 static int __net_init xfrm6_net_init(struct net *net)
92549 {
92550- struct ctl_table *table;
92551+ ctl_table_no_const *table = NULL;
92552 struct ctl_table_header *hdr;
92553
92554- table = xfrm6_policy_table;
92555 if (!net_eq(net, &init_net)) {
92556- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
92557+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
92558 if (!table)
92559 goto err_alloc;
92560
92561 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
92562- }
92563+ hdr = register_net_sysctl(net, "net/ipv6", table);
92564+ } else
92565+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
92566
92567- hdr = register_net_sysctl(net, "net/ipv6", table);
92568 if (!hdr)
92569 goto err_reg;
92570
92571@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
92572 return 0;
92573
92574 err_reg:
92575- if (!net_eq(net, &init_net))
92576- kfree(table);
92577+ kfree(table);
92578 err_alloc:
92579 return -ENOMEM;
92580 }
92581diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
92582index 41ac7938..75e3bb1 100644
92583--- a/net/irda/ircomm/ircomm_tty.c
92584+++ b/net/irda/ircomm/ircomm_tty.c
92585@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
92586 add_wait_queue(&port->open_wait, &wait);
92587
92588 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
92589- __FILE__, __LINE__, tty->driver->name, port->count);
92590+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
92591
92592 spin_lock_irqsave(&port->lock, flags);
92593 if (!tty_hung_up_p(filp))
92594- port->count--;
92595+ atomic_dec(&port->count);
92596 port->blocked_open++;
92597 spin_unlock_irqrestore(&port->lock, flags);
92598
92599@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
92600 }
92601
92602 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
92603- __FILE__, __LINE__, tty->driver->name, port->count);
92604+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
92605
92606 schedule();
92607 }
92608@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
92609
92610 spin_lock_irqsave(&port->lock, flags);
92611 if (!tty_hung_up_p(filp))
92612- port->count++;
92613+ atomic_inc(&port->count);
92614 port->blocked_open--;
92615 spin_unlock_irqrestore(&port->lock, flags);
92616
92617 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
92618- __FILE__, __LINE__, tty->driver->name, port->count);
92619+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
92620
92621 if (!retval)
92622 port->flags |= ASYNC_NORMAL_ACTIVE;
92623@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
92624
92625 /* ++ is not atomic, so this should be protected - Jean II */
92626 spin_lock_irqsave(&self->port.lock, flags);
92627- self->port.count++;
92628+ atomic_inc(&self->port.count);
92629 spin_unlock_irqrestore(&self->port.lock, flags);
92630 tty_port_tty_set(&self->port, tty);
92631
92632 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
92633- self->line, self->port.count);
92634+ self->line, atomic_read(&self->port.count));
92635
92636 /* Not really used by us, but lets do it anyway */
92637 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
92638@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
92639 tty_kref_put(port->tty);
92640 }
92641 port->tty = NULL;
92642- port->count = 0;
92643+ atomic_set(&port->count, 0);
92644 spin_unlock_irqrestore(&port->lock, flags);
92645
92646 wake_up_interruptible(&port->open_wait);
92647@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
92648 seq_putc(m, '\n');
92649
92650 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
92651- seq_printf(m, "Open count: %d\n", self->port.count);
92652+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
92653 seq_printf(m, "Max data size: %d\n", self->max_data_size);
92654 seq_printf(m, "Max header size: %d\n", self->max_header_size);
92655
92656diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
92657index ae69165..c8b82d8 100644
92658--- a/net/iucv/af_iucv.c
92659+++ b/net/iucv/af_iucv.c
92660@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
92661
92662 write_lock_bh(&iucv_sk_list.lock);
92663
92664- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
92665+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
92666 while (__iucv_get_sock_by_name(name)) {
92667 sprintf(name, "%08x",
92668- atomic_inc_return(&iucv_sk_list.autobind_name));
92669+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
92670 }
92671
92672 write_unlock_bh(&iucv_sk_list.lock);
92673diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
92674index 4fe76ff..426a904 100644
92675--- a/net/iucv/iucv.c
92676+++ b/net/iucv/iucv.c
92677@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
92678 return NOTIFY_OK;
92679 }
92680
92681-static struct notifier_block __refdata iucv_cpu_notifier = {
92682+static struct notifier_block iucv_cpu_notifier = {
92683 .notifier_call = iucv_cpu_notify,
92684 };
92685
92686diff --git a/net/key/af_key.c b/net/key/af_key.c
92687index ab8bd2c..cd2d641 100644
92688--- a/net/key/af_key.c
92689+++ b/net/key/af_key.c
92690@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
92691 static u32 get_acqseq(void)
92692 {
92693 u32 res;
92694- static atomic_t acqseq;
92695+ static atomic_unchecked_t acqseq;
92696
92697 do {
92698- res = atomic_inc_return(&acqseq);
92699+ res = atomic_inc_return_unchecked(&acqseq);
92700 } while (!res);
92701 return res;
92702 }
92703diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
92704index ae36f8e..09d42ac 100644
92705--- a/net/mac80211/cfg.c
92706+++ b/net/mac80211/cfg.c
92707@@ -806,7 +806,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
92708 ret = ieee80211_vif_use_channel(sdata, chandef,
92709 IEEE80211_CHANCTX_EXCLUSIVE);
92710 }
92711- } else if (local->open_count == local->monitors) {
92712+ } else if (local_read(&local->open_count) == local->monitors) {
92713 local->_oper_chandef = *chandef;
92714 ieee80211_hw_config(local, 0);
92715 }
92716@@ -2922,7 +2922,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
92717 else
92718 local->probe_req_reg--;
92719
92720- if (!local->open_count)
92721+ if (!local_read(&local->open_count))
92722 break;
92723
92724 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
92725@@ -3385,8 +3385,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
92726 if (chanctx_conf) {
92727 *chandef = chanctx_conf->def;
92728 ret = 0;
92729- } else if (local->open_count > 0 &&
92730- local->open_count == local->monitors &&
92731+ } else if (local_read(&local->open_count) > 0 &&
92732+ local_read(&local->open_count) == local->monitors &&
92733 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
92734 if (local->use_chanctx)
92735 *chandef = local->monitor_chandef;
92736diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
92737index 9ca8e32..48e4a9b 100644
92738--- a/net/mac80211/ieee80211_i.h
92739+++ b/net/mac80211/ieee80211_i.h
92740@@ -28,6 +28,7 @@
92741 #include <net/ieee80211_radiotap.h>
92742 #include <net/cfg80211.h>
92743 #include <net/mac80211.h>
92744+#include <asm/local.h>
92745 #include "key.h"
92746 #include "sta_info.h"
92747 #include "debug.h"
92748@@ -891,7 +892,7 @@ struct ieee80211_local {
92749 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
92750 spinlock_t queue_stop_reason_lock;
92751
92752- int open_count;
92753+ local_t open_count;
92754 int monitors, cooked_mntrs;
92755 /* number of interfaces with corresponding FIF_ flags */
92756 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
92757diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
92758index 514e90f..56f22bf 100644
92759--- a/net/mac80211/iface.c
92760+++ b/net/mac80211/iface.c
92761@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
92762 break;
92763 }
92764
92765- if (local->open_count == 0) {
92766+ if (local_read(&local->open_count) == 0) {
92767 res = drv_start(local);
92768 if (res)
92769 goto err_del_bss;
92770@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
92771 break;
92772 }
92773
92774- if (local->monitors == 0 && local->open_count == 0) {
92775+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
92776 res = ieee80211_add_virtual_monitor(local);
92777 if (res)
92778 goto err_stop;
92779@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
92780 atomic_inc(&local->iff_promiscs);
92781
92782 if (coming_up)
92783- local->open_count++;
92784+ local_inc(&local->open_count);
92785
92786 if (hw_reconf_flags)
92787 ieee80211_hw_config(local, hw_reconf_flags);
92788@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
92789 err_del_interface:
92790 drv_remove_interface(local, sdata);
92791 err_stop:
92792- if (!local->open_count)
92793+ if (!local_read(&local->open_count))
92794 drv_stop(local);
92795 err_del_bss:
92796 sdata->bss = NULL;
92797@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
92798 }
92799
92800 if (going_down)
92801- local->open_count--;
92802+ local_dec(&local->open_count);
92803
92804 switch (sdata->vif.type) {
92805 case NL80211_IFTYPE_AP_VLAN:
92806@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
92807 }
92808 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
92809
92810- if (local->open_count == 0)
92811+ if (local_read(&local->open_count) == 0)
92812 ieee80211_clear_tx_pending(local);
92813
92814 /*
92815@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
92816
92817 ieee80211_recalc_ps(local, -1);
92818
92819- if (local->open_count == 0) {
92820+ if (local_read(&local->open_count) == 0) {
92821 ieee80211_stop_device(local);
92822
92823 /* no reconfiguring after stop! */
92824@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
92825 ieee80211_configure_filter(local);
92826 ieee80211_hw_config(local, hw_reconf_flags);
92827
92828- if (local->monitors == local->open_count)
92829+ if (local->monitors == local_read(&local->open_count))
92830 ieee80211_add_virtual_monitor(local);
92831 }
92832
92833diff --git a/net/mac80211/main.c b/net/mac80211/main.c
92834index 8a7bfc4..4407cd0 100644
92835--- a/net/mac80211/main.c
92836+++ b/net/mac80211/main.c
92837@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
92838 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
92839 IEEE80211_CONF_CHANGE_POWER);
92840
92841- if (changed && local->open_count) {
92842+ if (changed && local_read(&local->open_count)) {
92843 ret = drv_config(local, changed);
92844 /*
92845 * Goal:
92846diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
92847index 3401262..d5cd68d 100644
92848--- a/net/mac80211/pm.c
92849+++ b/net/mac80211/pm.c
92850@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
92851 struct ieee80211_sub_if_data *sdata;
92852 struct sta_info *sta;
92853
92854- if (!local->open_count)
92855+ if (!local_read(&local->open_count))
92856 goto suspend;
92857
92858 ieee80211_scan_cancel(local);
92859@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
92860 cancel_work_sync(&local->dynamic_ps_enable_work);
92861 del_timer_sync(&local->dynamic_ps_timer);
92862
92863- local->wowlan = wowlan && local->open_count;
92864+ local->wowlan = wowlan && local_read(&local->open_count);
92865 if (local->wowlan) {
92866 int err = drv_suspend(local, wowlan);
92867 if (err < 0) {
92868@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
92869 WARN_ON(!list_empty(&local->chanctx_list));
92870
92871 /* stop hardware - this must stop RX */
92872- if (local->open_count)
92873+ if (local_read(&local->open_count))
92874 ieee80211_stop_device(local);
92875
92876 suspend:
92877diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
92878index a02bef3..f2f38dd 100644
92879--- a/net/mac80211/rate.c
92880+++ b/net/mac80211/rate.c
92881@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
92882
92883 ASSERT_RTNL();
92884
92885- if (local->open_count)
92886+ if (local_read(&local->open_count))
92887 return -EBUSY;
92888
92889 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
92890diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
92891index c97a065..ff61928 100644
92892--- a/net/mac80211/rc80211_pid_debugfs.c
92893+++ b/net/mac80211/rc80211_pid_debugfs.c
92894@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
92895
92896 spin_unlock_irqrestore(&events->lock, status);
92897
92898- if (copy_to_user(buf, pb, p))
92899+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
92900 return -EFAULT;
92901
92902 return p;
92903diff --git a/net/mac80211/util.c b/net/mac80211/util.c
92904index 72e6292..e6319eb 100644
92905--- a/net/mac80211/util.c
92906+++ b/net/mac80211/util.c
92907@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
92908 }
92909 #endif
92910 /* everything else happens only if HW was up & running */
92911- if (!local->open_count)
92912+ if (!local_read(&local->open_count))
92913 goto wake_up;
92914
92915 /*
92916@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
92917 local->in_reconfig = false;
92918 barrier();
92919
92920- if (local->monitors == local->open_count && local->monitors > 0)
92921+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
92922 ieee80211_add_virtual_monitor(local);
92923
92924 /*
92925diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
92926index 56d22ca..87c778f 100644
92927--- a/net/netfilter/Kconfig
92928+++ b/net/netfilter/Kconfig
92929@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
92930
92931 To compile it as a module, choose M here. If unsure, say N.
92932
92933+config NETFILTER_XT_MATCH_GRADM
92934+ tristate '"gradm" match support'
92935+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
92936+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
92937+ ---help---
92938+ The gradm match allows to match on grsecurity RBAC being enabled.
92939+ It is useful when iptables rules are applied early on bootup to
92940+ prevent connections to the machine (except from a trusted host)
92941+ while the RBAC system is disabled.
92942+
92943 config NETFILTER_XT_MATCH_HASHLIMIT
92944 tristate '"hashlimit" match support'
92945 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
92946diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
92947index a1abf87..dbcb7ee 100644
92948--- a/net/netfilter/Makefile
92949+++ b/net/netfilter/Makefile
92950@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
92951 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
92952 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
92953 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
92954+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
92955 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
92956 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
92957 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
92958diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
92959index f771390..145b765 100644
92960--- a/net/netfilter/ipset/ip_set_core.c
92961+++ b/net/netfilter/ipset/ip_set_core.c
92962@@ -1820,7 +1820,7 @@ done:
92963 return ret;
92964 }
92965
92966-static struct nf_sockopt_ops so_set __read_mostly = {
92967+static struct nf_sockopt_ops so_set = {
92968 .pf = PF_INET,
92969 .get_optmin = SO_IP_SET,
92970 .get_optmax = SO_IP_SET + 1,
92971diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
92972index a083bda..da661c3 100644
92973--- a/net/netfilter/ipvs/ip_vs_conn.c
92974+++ b/net/netfilter/ipvs/ip_vs_conn.c
92975@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
92976 /* Increase the refcnt counter of the dest */
92977 ip_vs_dest_hold(dest);
92978
92979- conn_flags = atomic_read(&dest->conn_flags);
92980+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
92981 if (cp->protocol != IPPROTO_UDP)
92982 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
92983 flags = cp->flags;
92984@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
92985
92986 cp->control = NULL;
92987 atomic_set(&cp->n_control, 0);
92988- atomic_set(&cp->in_pkts, 0);
92989+ atomic_set_unchecked(&cp->in_pkts, 0);
92990
92991 cp->packet_xmit = NULL;
92992 cp->app = NULL;
92993@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
92994
92995 /* Don't drop the entry if its number of incoming packets is not
92996 located in [0, 8] */
92997- i = atomic_read(&cp->in_pkts);
92998+ i = atomic_read_unchecked(&cp->in_pkts);
92999 if (i > 8 || i < 0) return 0;
93000
93001 if (!todrop_rate[i]) return 0;
93002diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
93003index 23b8eb5..48a8959 100644
93004--- a/net/netfilter/ipvs/ip_vs_core.c
93005+++ b/net/netfilter/ipvs/ip_vs_core.c
93006@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
93007 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
93008 /* do not touch skb anymore */
93009
93010- atomic_inc(&cp->in_pkts);
93011+ atomic_inc_unchecked(&cp->in_pkts);
93012 ip_vs_conn_put(cp);
93013 return ret;
93014 }
93015@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
93016 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
93017 pkts = sysctl_sync_threshold(ipvs);
93018 else
93019- pkts = atomic_add_return(1, &cp->in_pkts);
93020+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
93021
93022 if (ipvs->sync_state & IP_VS_STATE_MASTER)
93023 ip_vs_sync_conn(net, cp, pkts);
93024diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
93025index 9e6c2a0..28552e2 100644
93026--- a/net/netfilter/ipvs/ip_vs_ctl.c
93027+++ b/net/netfilter/ipvs/ip_vs_ctl.c
93028@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
93029 */
93030 ip_vs_rs_hash(ipvs, dest);
93031 }
93032- atomic_set(&dest->conn_flags, conn_flags);
93033+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
93034
93035 /* bind the service */
93036 if (!dest->svc) {
93037@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
93038 * align with netns init in ip_vs_control_net_init()
93039 */
93040
93041-static struct ctl_table vs_vars[] = {
93042+static ctl_table_no_const vs_vars[] __read_only = {
93043 {
93044 .procname = "amemthresh",
93045 .maxlen = sizeof(int),
93046@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
93047 " %-7s %-6d %-10d %-10d\n",
93048 &dest->addr.in6,
93049 ntohs(dest->port),
93050- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
93051+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
93052 atomic_read(&dest->weight),
93053 atomic_read(&dest->activeconns),
93054 atomic_read(&dest->inactconns));
93055@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
93056 "%-7s %-6d %-10d %-10d\n",
93057 ntohl(dest->addr.ip),
93058 ntohs(dest->port),
93059- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
93060+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
93061 atomic_read(&dest->weight),
93062 atomic_read(&dest->activeconns),
93063 atomic_read(&dest->inactconns));
93064@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
93065
93066 entry.addr = dest->addr.ip;
93067 entry.port = dest->port;
93068- entry.conn_flags = atomic_read(&dest->conn_flags);
93069+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
93070 entry.weight = atomic_read(&dest->weight);
93071 entry.u_threshold = dest->u_threshold;
93072 entry.l_threshold = dest->l_threshold;
93073@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
93074 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
93075 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
93076 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
93077- (atomic_read(&dest->conn_flags) &
93078+ (atomic_read_unchecked(&dest->conn_flags) &
93079 IP_VS_CONN_F_FWD_MASK)) ||
93080 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
93081 atomic_read(&dest->weight)) ||
93082@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
93083 {
93084 int idx;
93085 struct netns_ipvs *ipvs = net_ipvs(net);
93086- struct ctl_table *tbl;
93087+ ctl_table_no_const *tbl;
93088
93089 atomic_set(&ipvs->dropentry, 0);
93090 spin_lock_init(&ipvs->dropentry_lock);
93091diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
93092index 5ea26bd..c9bc65f 100644
93093--- a/net/netfilter/ipvs/ip_vs_lblc.c
93094+++ b/net/netfilter/ipvs/ip_vs_lblc.c
93095@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
93096 * IPVS LBLC sysctl table
93097 */
93098 #ifdef CONFIG_SYSCTL
93099-static ctl_table vs_vars_table[] = {
93100+static ctl_table_no_const vs_vars_table[] __read_only = {
93101 {
93102 .procname = "lblc_expiration",
93103 .data = NULL,
93104diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
93105index 50123c2..067c773 100644
93106--- a/net/netfilter/ipvs/ip_vs_lblcr.c
93107+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
93108@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
93109 * IPVS LBLCR sysctl table
93110 */
93111
93112-static ctl_table vs_vars_table[] = {
93113+static ctl_table_no_const vs_vars_table[] __read_only = {
93114 {
93115 .procname = "lblcr_expiration",
93116 .data = NULL,
93117diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
93118index f6046d9..4f10cfd 100644
93119--- a/net/netfilter/ipvs/ip_vs_sync.c
93120+++ b/net/netfilter/ipvs/ip_vs_sync.c
93121@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
93122 cp = cp->control;
93123 if (cp) {
93124 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
93125- pkts = atomic_add_return(1, &cp->in_pkts);
93126+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
93127 else
93128 pkts = sysctl_sync_threshold(ipvs);
93129 ip_vs_sync_conn(net, cp->control, pkts);
93130@@ -758,7 +758,7 @@ control:
93131 if (!cp)
93132 return;
93133 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
93134- pkts = atomic_add_return(1, &cp->in_pkts);
93135+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
93136 else
93137 pkts = sysctl_sync_threshold(ipvs);
93138 goto sloop;
93139@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
93140
93141 if (opt)
93142 memcpy(&cp->in_seq, opt, sizeof(*opt));
93143- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
93144+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
93145 cp->state = state;
93146 cp->old_state = cp->state;
93147 /*
93148diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
93149index b75ff64..0c51bbe 100644
93150--- a/net/netfilter/ipvs/ip_vs_xmit.c
93151+++ b/net/netfilter/ipvs/ip_vs_xmit.c
93152@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
93153 else
93154 rc = NF_ACCEPT;
93155 /* do not touch skb anymore */
93156- atomic_inc(&cp->in_pkts);
93157+ atomic_inc_unchecked(&cp->in_pkts);
93158 goto out;
93159 }
93160
93161@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
93162 else
93163 rc = NF_ACCEPT;
93164 /* do not touch skb anymore */
93165- atomic_inc(&cp->in_pkts);
93166+ atomic_inc_unchecked(&cp->in_pkts);
93167 goto out;
93168 }
93169
93170diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
93171index 2d3030a..7ba1c0a 100644
93172--- a/net/netfilter/nf_conntrack_acct.c
93173+++ b/net/netfilter/nf_conntrack_acct.c
93174@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
93175 #ifdef CONFIG_SYSCTL
93176 static int nf_conntrack_acct_init_sysctl(struct net *net)
93177 {
93178- struct ctl_table *table;
93179+ ctl_table_no_const *table;
93180
93181 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
93182 GFP_KERNEL);
93183diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
93184index 0283bae..5febcb0 100644
93185--- a/net/netfilter/nf_conntrack_core.c
93186+++ b/net/netfilter/nf_conntrack_core.c
93187@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
93188 #define DYING_NULLS_VAL ((1<<30)+1)
93189 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
93190
93191+#ifdef CONFIG_GRKERNSEC_HIDESYM
93192+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
93193+#endif
93194+
93195 int nf_conntrack_init_net(struct net *net)
93196 {
93197 int ret;
93198@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
93199 goto err_stat;
93200 }
93201
93202+#ifdef CONFIG_GRKERNSEC_HIDESYM
93203+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
93204+#else
93205 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
93206+#endif
93207 if (!net->ct.slabname) {
93208 ret = -ENOMEM;
93209 goto err_slabname;
93210diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
93211index 1df1761..ce8b88a 100644
93212--- a/net/netfilter/nf_conntrack_ecache.c
93213+++ b/net/netfilter/nf_conntrack_ecache.c
93214@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
93215 #ifdef CONFIG_SYSCTL
93216 static int nf_conntrack_event_init_sysctl(struct net *net)
93217 {
93218- struct ctl_table *table;
93219+ ctl_table_no_const *table;
93220
93221 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
93222 GFP_KERNEL);
93223diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
93224index 974a2a4..52cc6ff 100644
93225--- a/net/netfilter/nf_conntrack_helper.c
93226+++ b/net/netfilter/nf_conntrack_helper.c
93227@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
93228
93229 static int nf_conntrack_helper_init_sysctl(struct net *net)
93230 {
93231- struct ctl_table *table;
93232+ ctl_table_no_const *table;
93233
93234 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
93235 GFP_KERNEL);
93236diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
93237index 0ab9636..cea3c6a 100644
93238--- a/net/netfilter/nf_conntrack_proto.c
93239+++ b/net/netfilter/nf_conntrack_proto.c
93240@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
93241
93242 static void
93243 nf_ct_unregister_sysctl(struct ctl_table_header **header,
93244- struct ctl_table **table,
93245+ ctl_table_no_const **table,
93246 unsigned int users)
93247 {
93248 if (users > 0)
93249diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
93250index a99b6c3..3841268 100644
93251--- a/net/netfilter/nf_conntrack_proto_dccp.c
93252+++ b/net/netfilter/nf_conntrack_proto_dccp.c
93253@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
93254 out_invalid:
93255 if (LOG_INVALID(net, IPPROTO_DCCP))
93256 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
93257- NULL, msg);
93258+ NULL, "%s", msg);
93259 return false;
93260 }
93261
93262@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
93263
93264 out_invalid:
93265 if (LOG_INVALID(net, IPPROTO_DCCP))
93266- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
93267+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
93268 return -NF_ACCEPT;
93269 }
93270
93271diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
93272index 4d4d8f1..e0f9a32 100644
93273--- a/net/netfilter/nf_conntrack_proto_tcp.c
93274+++ b/net/netfilter/nf_conntrack_proto_tcp.c
93275@@ -526,7 +526,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
93276 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
93277 __u32 seq, ack, sack, end, win, swin;
93278 s16 receiver_offset;
93279- bool res;
93280+ bool res, in_recv_win;
93281
93282 /*
93283 * Get the required data from the packet.
93284@@ -649,14 +649,18 @@ static bool tcp_in_window(const struct nf_conn *ct,
93285 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
93286 receiver->td_scale);
93287
93288+ /* Is the ending sequence in the receive window (if available)? */
93289+ in_recv_win = !receiver->td_maxwin ||
93290+ after(end, sender->td_end - receiver->td_maxwin - 1);
93291+
93292 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
93293 before(seq, sender->td_maxend + 1),
93294- after(end, sender->td_end - receiver->td_maxwin - 1),
93295+ (in_recv_win ? 1 : 0),
93296 before(sack, receiver->td_end + 1),
93297 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
93298
93299 if (before(seq, sender->td_maxend + 1) &&
93300- after(end, sender->td_end - receiver->td_maxwin - 1) &&
93301+ in_recv_win &&
93302 before(sack, receiver->td_end + 1) &&
93303 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
93304 /*
93305@@ -725,7 +729,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
93306 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
93307 "nf_ct_tcp: %s ",
93308 before(seq, sender->td_maxend + 1) ?
93309- after(end, sender->td_end - receiver->td_maxwin - 1) ?
93310+ in_recv_win ?
93311 before(sack, receiver->td_end + 1) ?
93312 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1) ? "BUG"
93313 : "ACK is under the lower bound (possible overly delayed ACK)"
93314diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
93315index bd700b4..4a3dc61 100644
93316--- a/net/netfilter/nf_conntrack_standalone.c
93317+++ b/net/netfilter/nf_conntrack_standalone.c
93318@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
93319
93320 static int nf_conntrack_standalone_init_sysctl(struct net *net)
93321 {
93322- struct ctl_table *table;
93323+ ctl_table_no_const *table;
93324
93325 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
93326 GFP_KERNEL);
93327diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
93328index 902fb0a..87f7fdb 100644
93329--- a/net/netfilter/nf_conntrack_timestamp.c
93330+++ b/net/netfilter/nf_conntrack_timestamp.c
93331@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
93332 #ifdef CONFIG_SYSCTL
93333 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
93334 {
93335- struct ctl_table *table;
93336+ ctl_table_no_const *table;
93337
93338 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
93339 GFP_KERNEL);
93340diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
93341index 3b18dd1..f79e0ca 100644
93342--- a/net/netfilter/nf_log.c
93343+++ b/net/netfilter/nf_log.c
93344@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
93345
93346 #ifdef CONFIG_SYSCTL
93347 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
93348-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
93349+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
93350
93351 static int nf_log_proc_dostring(ctl_table *table, int write,
93352 void __user *buffer, size_t *lenp, loff_t *ppos)
93353@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
93354 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
93355 mutex_unlock(&nf_log_mutex);
93356 } else {
93357+ ctl_table_no_const nf_log_table = *table;
93358+
93359 mutex_lock(&nf_log_mutex);
93360 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
93361 lockdep_is_held(&nf_log_mutex));
93362 if (!logger)
93363- table->data = "NONE";
93364+ nf_log_table.data = "NONE";
93365 else
93366- table->data = logger->name;
93367- r = proc_dostring(table, write, buffer, lenp, ppos);
93368+ nf_log_table.data = logger->name;
93369+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
93370 mutex_unlock(&nf_log_mutex);
93371 }
93372
93373diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
93374index f042ae5..30ea486 100644
93375--- a/net/netfilter/nf_sockopt.c
93376+++ b/net/netfilter/nf_sockopt.c
93377@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
93378 }
93379 }
93380
93381- list_add(&reg->list, &nf_sockopts);
93382+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
93383 out:
93384 mutex_unlock(&nf_sockopt_mutex);
93385 return ret;
93386@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
93387 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
93388 {
93389 mutex_lock(&nf_sockopt_mutex);
93390- list_del(&reg->list);
93391+ pax_list_del((struct list_head *)&reg->list);
93392 mutex_unlock(&nf_sockopt_mutex);
93393 }
93394 EXPORT_SYMBOL(nf_unregister_sockopt);
93395diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
93396index 962e979..e46f350 100644
93397--- a/net/netfilter/nfnetlink_log.c
93398+++ b/net/netfilter/nfnetlink_log.c
93399@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
93400 struct nfnl_log_net {
93401 spinlock_t instances_lock;
93402 struct hlist_head instance_table[INSTANCE_BUCKETS];
93403- atomic_t global_seq;
93404+ atomic_unchecked_t global_seq;
93405 };
93406
93407 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
93408@@ -419,6 +419,7 @@ __build_packet_message(struct nfnl_log_net *log,
93409 nfmsg->version = NFNETLINK_V0;
93410 nfmsg->res_id = htons(inst->group_num);
93411
93412+ memset(&pmsg, 0, sizeof(pmsg));
93413 pmsg.hw_protocol = skb->protocol;
93414 pmsg.hook = hooknum;
93415
93416@@ -498,7 +499,10 @@ __build_packet_message(struct nfnl_log_net *log,
93417 if (indev && skb->dev &&
93418 skb->mac_header != skb->network_header) {
93419 struct nfulnl_msg_packet_hw phw;
93420- int len = dev_parse_header(skb, phw.hw_addr);
93421+ int len;
93422+
93423+ memset(&phw, 0, sizeof(phw));
93424+ len = dev_parse_header(skb, phw.hw_addr);
93425 if (len > 0) {
93426 phw.hw_addrlen = htons(len);
93427 if (nla_put(inst->skb, NFULA_HWADDR, sizeof(phw), &phw))
93428@@ -559,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
93429 /* global sequence number */
93430 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
93431 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
93432- htonl(atomic_inc_return(&log->global_seq))))
93433+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
93434 goto nla_put_failure;
93435
93436 if (data_len) {
93437diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
93438index 5352b2d..e0083ce 100644
93439--- a/net/netfilter/nfnetlink_queue_core.c
93440+++ b/net/netfilter/nfnetlink_queue_core.c
93441@@ -444,7 +444,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
93442 if (indev && entskb->dev &&
93443 entskb->mac_header != entskb->network_header) {
93444 struct nfqnl_msg_packet_hw phw;
93445- int len = dev_parse_header(entskb, phw.hw_addr);
93446+ int len;
93447+
93448+ memset(&phw, 0, sizeof(phw));
93449+ len = dev_parse_header(entskb, phw.hw_addr);
93450 if (len) {
93451 phw.hw_addrlen = htons(len);
93452 if (nla_put(skb, NFQA_HWADDR, sizeof(phw), &phw))
93453diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
93454index 7011c71..6113cc7 100644
93455--- a/net/netfilter/xt_TCPMSS.c
93456+++ b/net/netfilter/xt_TCPMSS.c
93457@@ -52,7 +52,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
93458 {
93459 const struct xt_tcpmss_info *info = par->targinfo;
93460 struct tcphdr *tcph;
93461- unsigned int tcplen, i;
93462+ int len, tcp_hdrlen;
93463+ unsigned int i;
93464 __be16 oldval;
93465 u16 newmss;
93466 u8 *opt;
93467@@ -64,11 +65,14 @@ tcpmss_mangle_packet(struct sk_buff *skb,
93468 if (!skb_make_writable(skb, skb->len))
93469 return -1;
93470
93471- tcplen = skb->len - tcphoff;
93472+ len = skb->len - tcphoff;
93473+ if (len < (int)sizeof(struct tcphdr))
93474+ return -1;
93475+
93476 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
93477+ tcp_hdrlen = tcph->doff * 4;
93478
93479- /* Header cannot be larger than the packet */
93480- if (tcplen < tcph->doff*4)
93481+ if (len < tcp_hdrlen)
93482 return -1;
93483
93484 if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
93485@@ -87,9 +91,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
93486 newmss = info->mss;
93487
93488 opt = (u_int8_t *)tcph;
93489- for (i = sizeof(struct tcphdr); i < tcph->doff*4; i += optlen(opt, i)) {
93490- if (opt[i] == TCPOPT_MSS && tcph->doff*4 - i >= TCPOLEN_MSS &&
93491- opt[i+1] == TCPOLEN_MSS) {
93492+ for (i = sizeof(struct tcphdr); i <= tcp_hdrlen - TCPOLEN_MSS; i += optlen(opt, i)) {
93493+ if (opt[i] == TCPOPT_MSS && opt[i+1] == TCPOLEN_MSS) {
93494 u_int16_t oldmss;
93495
93496 oldmss = (opt[i+2] << 8) | opt[i+3];
93497@@ -112,9 +115,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
93498 }
93499
93500 /* There is data after the header so the option can't be added
93501- without moving it, and doing so may make the SYN packet
93502- itself too large. Accept the packet unmodified instead. */
93503- if (tcplen > tcph->doff*4)
93504+ * without moving it, and doing so may make the SYN packet
93505+ * itself too large. Accept the packet unmodified instead.
93506+ */
93507+ if (len > tcp_hdrlen)
93508 return 0;
93509
93510 /*
93511@@ -143,10 +147,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
93512 newmss = min(newmss, (u16)1220);
93513
93514 opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
93515- memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr));
93516+ memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr));
93517
93518 inet_proto_csum_replace2(&tcph->check, skb,
93519- htons(tcplen), htons(tcplen + TCPOLEN_MSS), 1);
93520+ htons(len), htons(len + TCPOLEN_MSS), 1);
93521 opt[0] = TCPOPT_MSS;
93522 opt[1] = TCPOLEN_MSS;
93523 opt[2] = (newmss & 0xff00) >> 8;
93524diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
93525index b68fa19..625fa1d 100644
93526--- a/net/netfilter/xt_TCPOPTSTRIP.c
93527+++ b/net/netfilter/xt_TCPOPTSTRIP.c
93528@@ -38,7 +38,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
93529 struct tcphdr *tcph;
93530 u_int16_t n, o;
93531 u_int8_t *opt;
93532- int len;
93533+ int len, tcp_hdrlen;
93534
93535 /* This is a fragment, no TCP header is available */
93536 if (par->fragoff != 0)
93537@@ -52,7 +52,9 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
93538 return NF_DROP;
93539
93540 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
93541- if (tcph->doff * 4 > len)
93542+ tcp_hdrlen = tcph->doff * 4;
93543+
93544+ if (len < tcp_hdrlen)
93545 return NF_DROP;
93546
93547 opt = (u_int8_t *)tcph;
93548@@ -61,10 +63,10 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
93549 * Walk through all TCP options - if we find some option to remove,
93550 * set all octets to %TCPOPT_NOP and adjust checksum.
93551 */
93552- for (i = sizeof(struct tcphdr); i < tcp_hdrlen(skb); i += optl) {
93553+ for (i = sizeof(struct tcphdr); i < tcp_hdrlen - 1; i += optl) {
93554 optl = optlen(opt, i);
93555
93556- if (i + optl > tcp_hdrlen(skb))
93557+ if (i + optl > tcp_hdrlen)
93558 break;
93559
93560 if (!tcpoptstrip_test_bit(info->strip_bmap, opt[i]))
93561diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
93562new file mode 100644
93563index 0000000..c566332
93564--- /dev/null
93565+++ b/net/netfilter/xt_gradm.c
93566@@ -0,0 +1,51 @@
93567+/*
93568+ * gradm match for netfilter
93569